w100lcd.c revision 1.1 1 1.1 tsutsui /* $NetBSD: w100lcd.c,v 1.1 2012/01/29 10:12:42 tsutsui Exp $ */
2 1.1 tsutsui /*
3 1.1 tsutsui * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
4 1.1 tsutsui * Written by Hiroyuki Bessho for Genetec Corporation.
5 1.1 tsutsui *
6 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
7 1.1 tsutsui * modification, are permitted provided that the following conditions
8 1.1 tsutsui * are met:
9 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
10 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
11 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
13 1.1 tsutsui * documentation and/or other materials provided with the distribution.
14 1.1 tsutsui * 3. The name of Genetec Corporation may not be used to endorse or
15 1.1 tsutsui * promote products derived from this software without specific prior
16 1.1 tsutsui * written permission.
17 1.1 tsutsui *
18 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
19 1.1 tsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 1.1 tsutsui * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.1 tsutsui * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
22 1.1 tsutsui * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.1 tsutsui * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 1.1 tsutsui * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.1 tsutsui * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 1.1 tsutsui * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 1.1 tsutsui * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1.1 tsutsui * POSSIBILITY OF SUCH DAMAGE.
29 1.1 tsutsui */
30 1.1 tsutsui
31 1.1 tsutsui /*
32 1.1 tsutsui * LCD driver for Sharp Zaurus SL-C7x0/860, based on zlcd.c.
33 1.1 tsutsui *
34 1.1 tsutsui * Controlling LCD is done in w100.c.
35 1.1 tsutsui *
36 1.1 tsutsui * Codes in this file provide platform specific things including:
37 1.1 tsutsui * LCD panel geometry
38 1.1 tsutsui *
39 1.1 tsutsui * LCD on/off switch and backlight brightness are done in lcdctl.c.
40 1.1 tsutsui */
41 1.1 tsutsui #include <sys/cdefs.h>
42 1.1 tsutsui __KERNEL_RCSID(0, "$NetBSD: w100lcd.c,v 1.1 2012/01/29 10:12:42 tsutsui Exp $");
43 1.1 tsutsui
44 1.1 tsutsui #include <sys/param.h>
45 1.1 tsutsui #include <sys/systm.h>
46 1.1 tsutsui #include <sys/bus.h>
47 1.1 tsutsui
48 1.1 tsutsui #include <dev/cons.h>
49 1.1 tsutsui #include <dev/wscons/wsconsio.h>
50 1.1 tsutsui #include <dev/wscons/wsdisplayvar.h>
51 1.1 tsutsui #include <dev/rasops/rasops.h>
52 1.1 tsutsui #include <dev/wsfont/wsfont.h>
53 1.1 tsutsui
54 1.1 tsutsui #include <arm/xscale/pxa2x0var.h>
55 1.1 tsutsui #include <zaurus/dev/w100var.h>
56 1.1 tsutsui
57 1.1 tsutsui #include <zaurus/zaurus/zaurus_var.h>
58 1.1 tsutsui #include <zaurus/dev/w100lcdvar.h>
59 1.1 tsutsui
60 1.1 tsutsui /*
61 1.1 tsutsui * wsdisplay glue
62 1.1 tsutsui */
63 1.1 tsutsui static struct w100_wsscreen_descr w100lcd_std_screen = {
64 1.1 tsutsui .c = {
65 1.1 tsutsui .name = "std",
66 1.1 tsutsui .textops = &w100_emulops,
67 1.1 tsutsui .fontwidth = 8,
68 1.1 tsutsui .fontheight = 16,
69 1.1 tsutsui .capabilities = WSSCREEN_WSCOLORS,
70 1.1 tsutsui },
71 1.1 tsutsui .depth = 16, /* bits per pixel */
72 1.1 tsutsui .flags = 0,
73 1.1 tsutsui };
74 1.1 tsutsui
75 1.1 tsutsui static const struct wsscreen_descr *w100lcd_scr_descr[] = {
76 1.1 tsutsui &w100lcd_std_screen.c
77 1.1 tsutsui };
78 1.1 tsutsui
79 1.1 tsutsui static const struct wsscreen_list w100lcd_screen_list = {
80 1.1 tsutsui .nscreens = __arraycount(w100lcd_scr_descr),
81 1.1 tsutsui .screens = w100lcd_scr_descr,
82 1.1 tsutsui };
83 1.1 tsutsui
84 1.1 tsutsui static int w100lcd_ioctl(void *, void *, u_long, void *, int,
85 1.1 tsutsui struct lwp *);
86 1.1 tsutsui static int w100lcd_show_screen(void *, void *, int,
87 1.1 tsutsui void (*)(void *, int, int), void *);
88 1.1 tsutsui
89 1.1 tsutsui struct wsdisplay_accessops w100lcd_accessops = {
90 1.1 tsutsui w100lcd_ioctl,
91 1.1 tsutsui w100_mmap,
92 1.1 tsutsui w100_alloc_screen,
93 1.1 tsutsui w100_free_screen,
94 1.1 tsutsui w100lcd_show_screen,
95 1.1 tsutsui NULL,
96 1.1 tsutsui NULL,
97 1.1 tsutsui NULL,
98 1.1 tsutsui };
99 1.1 tsutsui
100 1.1 tsutsui const struct w100_panel_geometry lcd_panel_geometry_c700 =
101 1.1 tsutsui {
102 1.1 tsutsui 480, /* Width */
103 1.1 tsutsui 640, /* Height */
104 1.1 tsutsui W100_PANEL_ROTATE_CW, /* Rotate */
105 1.1 tsutsui };
106 1.1 tsutsui
107 1.1 tsutsui static int w100lcd_match(device_t, cfdata_t, void *);
108 1.1 tsutsui static void w100lcd_attach(device_t, device_t, void *);
109 1.1 tsutsui
110 1.1 tsutsui CFATTACH_DECL_NEW(w100lcd, sizeof(struct w100_softc),
111 1.1 tsutsui w100lcd_match, w100lcd_attach, NULL, NULL);
112 1.1 tsutsui
113 1.1 tsutsui static bool w100lcd_suspend(device_t, const pmf_qual_t *);
114 1.1 tsutsui static bool w100lcd_resume(device_t, const pmf_qual_t *);
115 1.1 tsutsui
116 1.1 tsutsui static int
117 1.1 tsutsui w100lcd_match(device_t parent, cfdata_t cf, void *aux)
118 1.1 tsutsui {
119 1.1 tsutsui
120 1.1 tsutsui if (ZAURUS_ISC860)
121 1.1 tsutsui return 1;
122 1.1 tsutsui return 0;
123 1.1 tsutsui }
124 1.1 tsutsui
125 1.1 tsutsui static void
126 1.1 tsutsui w100lcd_attach(device_t parent, device_t self, void *aux)
127 1.1 tsutsui {
128 1.1 tsutsui struct w100_softc *sc = device_private(self);
129 1.1 tsutsui struct pxaip_attach_args *pxa = (struct pxaip_attach_args *)aux;
130 1.1 tsutsui struct wsemuldisplaydev_attach_args aa;
131 1.1 tsutsui
132 1.1 tsutsui sc->dev = self;
133 1.1 tsutsui
134 1.1 tsutsui w100_attach_subr(sc, pxa->pxa_iot, &lcd_panel_geometry_c700);
135 1.1 tsutsui
136 1.1 tsutsui aa.console = glass_console;
137 1.1 tsutsui aa.scrdata = &w100lcd_screen_list;
138 1.1 tsutsui aa.accessops = &w100lcd_accessops;
139 1.1 tsutsui aa.accesscookie = sc;
140 1.1 tsutsui
141 1.1 tsutsui (void)config_found(self, &aa, wsemuldisplaydevprint);
142 1.1 tsutsui
143 1.1 tsutsui if (!pmf_device_register(self, w100lcd_suspend, w100lcd_resume))
144 1.1 tsutsui aprint_error_dev(self, "couldn't establish power handler\n");
145 1.1 tsutsui }
146 1.1 tsutsui
147 1.1 tsutsui void
148 1.1 tsutsui w100lcd_cnattach(void)
149 1.1 tsutsui {
150 1.1 tsutsui
151 1.1 tsutsui if (ZAURUS_ISC860)
152 1.1 tsutsui w100_cnattach(&w100lcd_std_screen, &lcd_panel_geometry_c700);
153 1.1 tsutsui }
154 1.1 tsutsui
155 1.1 tsutsui /*
156 1.1 tsutsui * power management
157 1.1 tsutsui */
158 1.1 tsutsui static bool
159 1.1 tsutsui w100lcd_suspend(device_t dv, const pmf_qual_t *qual)
160 1.1 tsutsui {
161 1.1 tsutsui struct w100_softc *sc = device_private(dv);
162 1.1 tsutsui
163 1.1 tsutsui #if NLCDCTL > 0
164 1.1 tsutsui lcdctl_onoff(false);
165 1.1 tsutsui #endif
166 1.1 tsutsui w100_suspend(sc);
167 1.1 tsutsui
168 1.1 tsutsui return true;
169 1.1 tsutsui }
170 1.1 tsutsui
171 1.1 tsutsui static bool
172 1.1 tsutsui w100lcd_resume(device_t dv, const pmf_qual_t *qual)
173 1.1 tsutsui {
174 1.1 tsutsui struct w100_softc *sc = device_private(dv);
175 1.1 tsutsui
176 1.1 tsutsui w100_resume(sc);
177 1.1 tsutsui #if NLCDCTL > 0
178 1.1 tsutsui lcdctl_onoff(true);
179 1.1 tsutsui #endif
180 1.1 tsutsui
181 1.1 tsutsui return true;
182 1.1 tsutsui }
183 1.1 tsutsui
184 1.1 tsutsui /*
185 1.1 tsutsui * wsdisplay accessops overrides
186 1.1 tsutsui */
187 1.1 tsutsui static int
188 1.1 tsutsui w100lcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
189 1.1 tsutsui struct lwp *l)
190 1.1 tsutsui {
191 1.1 tsutsui int res = EINVAL;
192 1.1 tsutsui
193 1.1 tsutsui switch (cmd) {
194 1.1 tsutsui #if NLCDCTL > 0
195 1.1 tsutsui case WSDISPLAYIO_GETPARAM:
196 1.1 tsutsui case WSDISPLAYIO_SETPARAM:
197 1.1 tsutsui res = lcdctl_param(cmd, (struct wsdisplay_param *)data);
198 1.1 tsutsui break;
199 1.1 tsutsui #endif
200 1.1 tsutsui
201 1.1 tsutsui default:
202 1.1 tsutsui break;
203 1.1 tsutsui }
204 1.1 tsutsui
205 1.1 tsutsui if (res == EINVAL)
206 1.1 tsutsui res = w100_ioctl(v, vs, cmd, data, flag, l);
207 1.1 tsutsui
208 1.1 tsutsui return res;
209 1.1 tsutsui }
210 1.1 tsutsui
211 1.1 tsutsui static int
212 1.1 tsutsui w100lcd_show_screen(void *v, void *cookie, int waitok,
213 1.1 tsutsui void (*cb_func)(void *, int, int), void *cb_arg)
214 1.1 tsutsui {
215 1.1 tsutsui int error;
216 1.1 tsutsui
217 1.1 tsutsui error = w100_show_screen(v, cookie, waitok, cb_func, cb_arg);
218 1.1 tsutsui if (error)
219 1.1 tsutsui return (error);
220 1.1 tsutsui
221 1.1 tsutsui /* Turn on LCD */
222 1.1 tsutsui #if NLCDCTL > 0
223 1.1 tsutsui lcdctl_onoff(true);
224 1.1 tsutsui #endif
225 1.1 tsutsui
226 1.1 tsutsui return 0;
227 1.1 tsutsui }
228