ite8181.c revision 1.21 1 1.21 abs /* $NetBSD: ite8181.c,v 1.21 2004/12/12 21:03:06 abs Exp $ */
2 1.1 sato
3 1.1 sato /*-
4 1.8 sato * Copyright (c) 2000,2001 SATO Kazumi
5 1.1 sato * All rights reserved.
6 1.1 sato *
7 1.1 sato * Redistribution and use in source and binary forms, with or without
8 1.1 sato * modification, are permitted provided that the following conditions
9 1.1 sato * are met:
10 1.1 sato * 1. Redistributions of source code must retain the above copyright
11 1.1 sato * notice, this list of conditions and the following disclaimer.
12 1.1 sato * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 sato * notice, this list of conditions and the following disclaimer in the
14 1.1 sato * documentation and/or other materials provided with the distribution.
15 1.1 sato *
16 1.1 sato * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1 sato * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 sato * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 sato * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1 sato * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 sato * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 sato * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 sato * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 sato * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 sato * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 sato * SUCH DAMAGE.
27 1.1 sato *
28 1.1 sato */
29 1.19 lukem
30 1.19 lukem #include <sys/cdefs.h>
31 1.21 abs __KERNEL_RCSID(0, "$NetBSD: ite8181.c,v 1.21 2004/12/12 21:03:06 abs Exp $");
32 1.1 sato
33 1.1 sato #include <sys/param.h>
34 1.1 sato #include <sys/kernel.h>
35 1.1 sato #include <sys/device.h>
36 1.1 sato #include <sys/systm.h>
37 1.1 sato #include <sys/boot_flag.h>
38 1.2 sato #include <sys/buf.h>
39 1.1 sato
40 1.1 sato #include <uvm/uvm_extern.h>
41 1.1 sato
42 1.1 sato #include <dev/wscons/wsconsio.h>
43 1.1 sato
44 1.1 sato #include <machine/bootinfo.h>
45 1.1 sato #include <machine/bus.h>
46 1.1 sato #include <machine/autoconf.h>
47 1.1 sato #include <machine/config_hook.h>
48 1.1 sato #include <machine/platid.h>
49 1.1 sato #include <machine/platid_mask.h>
50 1.1 sato
51 1.1 sato #include <hpcmips/dev/ite8181reg.h>
52 1.1 sato #include <hpcmips/dev/ite8181var.h>
53 1.1 sato #include "bivideo.h"
54 1.1 sato #if NBIVIDEO > 0
55 1.7 uch #include <dev/hpc/bivideovar.h>
56 1.1 sato #endif
57 1.7 uch #include <dev/hpc/hpccmapvar.h>
58 1.1 sato
59 1.1 sato #define ITE8181DEBUG
60 1.1 sato #ifdef ITE8181DEBUG
61 1.1 sato #ifndef ITE8181DEBUG_CONF
62 1.1 sato #define ITE8181DEBUG_CONF 0
63 1.1 sato #endif
64 1.1 sato int ite8181_debug = ITE8181DEBUG_CONF;
65 1.1 sato #define DPRINTF(arg) if (ite8181_debug) printf arg
66 1.1 sato #define DPRINTFN(n, arg) if (ite8181_debug > (n)) printf arg
67 1.1 sato #define VPRINTF(arg) if (bootverbose || ite8181_debug) printf arg
68 1.1 sato #define VPRINTFN(n, arg) if (bootverbose || ite8181_debug > (n)) printf arg
69 1.1 sato #else
70 1.1 sato #define DPRINTF(arg)
71 1.1 sato #define DPRINTFN(n, arg)
72 1.1 sato #define VPRINTF(arg) if (bootverbose) printf arg
73 1.1 sato #define VPRINTFN(n, arg) if (bootverbose) printf arg
74 1.1 sato #endif
75 1.1 sato
76 1.1 sato #ifndef ITE8181_LCD_CONTROL_ENABLE
77 1.1 sato int ite8181_lcd_control_disable = 1;
78 1.1 sato #else /* ITE8181_LCD_CONTROL_ENABLE */
79 1.1 sato int ite8181_lcd_control_disable = 0;
80 1.1 sato #endif /* ITE8181_LCD_CONTROL_ENABLE */
81 1.1 sato
82 1.2 sato #define ITE8181_WINCE_CMAP
83 1.2 sato
84 1.2 sato /*
85 1.2 sato * XXX:
86 1.2 sato * IBM WorkPad z50 power unit has too weak power.
87 1.2 sato * So we must wait too many times to access some device
88 1.2 sato * after LCD panel and BackLight on.
89 1.2 sato * Currently delay is not enough ??? FIXME
90 1.2 sato */
91 1.2 sato #ifndef ITE8181_LCD_ON_SELF_DELAY
92 1.3 sato #define ITE8181_LCD_ON_SELF_DELAY 1000
93 1.2 sato #endif /* ITE8181_LCD_ON__SELF_DELAY */
94 1.2 sato #ifndef ITE8181_LCD_ON_DELAY
95 1.2 sato #define ITE8181_LCD_ON_DELAY 2000
96 1.2 sato #endif /* ITE8181_LCD_ON_DELAY */
97 1.2 sato int ite8181_lcd_on_self_delay = ITE8181_LCD_ON_SELF_DELAY; /* msec */
98 1.2 sato int ite8181_lcd_on_delay = ITE8181_LCD_ON_DELAY; /* msec */
99 1.2 sato
100 1.1 sato #define MSEC 1000
101 1.1 sato /*
102 1.1 sato * function prototypes
103 1.1 sato */
104 1.15 uch static void ite8181_config_write_4(bus_space_tag_t, bus_space_handle_t,
105 1.15 uch int, int);
106 1.15 uch static int ite8181_config_read_4(bus_space_tag_t, bus_space_handle_t,
107 1.15 uch int);
108 1.15 uch static void ite8181_gui_write_4(struct ite8181_softc *, int, int);
109 1.15 uch static int ite8181_gui_read_4(struct ite8181_softc *, int);
110 1.15 uch
111 1.15 uch static void ite8181_gui_write_1(struct ite8181_softc *, int, int);
112 1.15 uch static int ite8181_gui_read_1(struct ite8181_softc *, int);
113 1.15 uch
114 1.15 uch static void ite8181_graphics_write_1(struct ite8181_softc *, int, int);
115 1.15 uch static int ite8181_graphics_read_1(struct ite8181_softc *, int);
116 1.15 uch
117 1.15 uch static void ite8181_ema_write_1(struct ite8181_softc *, int, int);
118 1.15 uch static int ite8181_ema_read_1(struct ite8181_softc *, int);
119 1.15 uch
120 1.15 uch static void ite8181_power(int, void *);
121 1.15 uch static int ite8181_hardpower(void *, int, long, void *);
122 1.15 uch static int ite8181_fbinit(struct hpcfb_fbconf *);
123 1.15 uch static int ite8181_ioctl(void *, u_long, caddr_t, int, struct proc *);
124 1.15 uch static paddr_t ite8181_mmap(void *, off_t offset, int);
125 1.15 uch static void ite8181_erase_cursor(struct ite8181_softc *);
126 1.15 uch static int ite8181_lcd_power(struct ite8181_softc *, int);
127 1.15 uch
128 1.15 uch static void ite8181_update_powerstate(struct ite8181_softc *, int);
129 1.15 uch void ite8181_init_backlight(struct ite8181_softc *, int);
130 1.15 uch void ite8181_init_brightness(struct ite8181_softc *, int);
131 1.15 uch void ite8181_init_contrast(struct ite8181_softc *, int);
132 1.15 uch void ite8181_set_brightness(struct ite8181_softc *, int);
133 1.15 uch void ite8181_set_contrast(struct ite8181_softc *, int);
134 1.8 sato
135 1.1 sato /*
136 1.1 sato * static variables
137 1.1 sato */
138 1.1 sato struct hpcfb_accessops ite8181_ha = {
139 1.1 sato ite8181_ioctl, ite8181_mmap
140 1.1 sato };
141 1.1 sato
142 1.1 sato inline int
143 1.15 uch ite8181_config_read_4(bus_space_tag_t iot, bus_space_handle_t ioh,
144 1.15 uch int byteoffset)
145 1.1 sato {
146 1.15 uch
147 1.15 uch return (bus_space_read_4(iot, ioh, ITE8181_CONF_OFFSET + byteoffset));
148 1.1 sato }
149 1.1 sato
150 1.1 sato inline void
151 1.15 uch ite8181_config_write_4(bus_space_tag_t iot, bus_space_handle_t ioh,
152 1.15 uch int byteoffset, int data)
153 1.1 sato {
154 1.15 uch
155 1.1 sato bus_space_write_4(iot, ioh, ITE8181_CONF_OFFSET + byteoffset, data);
156 1.1 sato }
157 1.1 sato
158 1.1 sato inline int
159 1.15 uch ite8181_gui_read_4(struct ite8181_softc *sc, int byteoffset)
160 1.1 sato {
161 1.15 uch
162 1.15 uch return (bus_space_read_4(sc->sc_iot, sc->sc_ioh,
163 1.15 uch sc->sc_gba + byteoffset));
164 1.1 sato }
165 1.1 sato
166 1.1 sato inline void
167 1.15 uch ite8181_gui_write_4(struct ite8181_softc *sc, int byteoffset, int data)
168 1.1 sato {
169 1.15 uch
170 1.15 uch bus_space_write_4(sc->sc_iot, sc->sc_ioh, sc->sc_gba + byteoffset,
171 1.15 uch data);
172 1.1 sato }
173 1.1 sato
174 1.1 sato inline int
175 1.15 uch ite8181_gui_read_1(struct ite8181_softc *sc, int byteoffset)
176 1.1 sato {
177 1.15 uch
178 1.15 uch return (bus_space_read_1(sc->sc_iot, sc->sc_ioh,
179 1.15 uch sc->sc_gba + byteoffset));
180 1.1 sato }
181 1.1 sato
182 1.1 sato inline void
183 1.15 uch ite8181_gui_write_1(struct ite8181_softc *sc, int byteoffset, int data)
184 1.1 sato {
185 1.15 uch
186 1.15 uch bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->sc_gba + byteoffset,
187 1.15 uch data);
188 1.1 sato }
189 1.1 sato
190 1.1 sato inline int
191 1.15 uch ite8181_graphics_read_1(struct ite8181_softc *sc, int byteoffset)
192 1.1 sato {
193 1.15 uch
194 1.15 uch return (bus_space_read_1(sc->sc_iot, sc->sc_ioh,
195 1.15 uch sc->sc_sba + byteoffset));
196 1.1 sato }
197 1.1 sato
198 1.1 sato inline void
199 1.15 uch ite8181_graphics_write_1(struct ite8181_softc *sc, int byteoffset, int data)
200 1.1 sato {
201 1.15 uch
202 1.15 uch bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->sc_sba + byteoffset,
203 1.15 uch data);
204 1.1 sato }
205 1.1 sato
206 1.1 sato inline int
207 1.15 uch ite8181_ema_read_1(struct ite8181_softc *sc, int byteoffset)
208 1.1 sato {
209 1.15 uch
210 1.1 sato ite8181_graphics_write_1(sc, ITE8181_EMA_EXAX, byteoffset);
211 1.15 uch return (ite8181_graphics_read_1(sc, ITE8181_EMA_EXADATA));
212 1.1 sato }
213 1.1 sato
214 1.1 sato inline void
215 1.15 uch ite8181_ema_write_1(struct ite8181_softc *sc, int byteoffset, int data)
216 1.1 sato {
217 1.15 uch
218 1.1 sato ite8181_graphics_write_1(sc, ITE8181_EMA_EXAX, byteoffset);
219 1.1 sato ite8181_graphics_write_1(sc, ITE8181_EMA_EXADATA, data);
220 1.1 sato }
221 1.1 sato
222 1.1 sato int
223 1.15 uch ite8181_probe(bus_space_tag_t iot, bus_space_handle_t ioh)
224 1.1 sato {
225 1.1 sato unsigned long regval;
226 1.1 sato
227 1.1 sato #if NBIVIDEO > 0
228 1.15 uch if (bivideo_dont_attach) /* some video driver already attached */
229 1.1 sato return (0);
230 1.1 sato #endif /* NBIVIDEO > 0 */
231 1.1 sato
232 1.1 sato regval = ite8181_config_read_4(iot, ioh, ITE8181_ID);
233 1.1 sato VPRINTF(("ite8181_probe: vendor id=%04lx product id=%04lx\n",
234 1.15 uch regval & 0xffff, (regval >> 16) & 0xffff));
235 1.1 sato if (regval != ((ITE8181_PRODUCT_ID << 16) | ITE8181_VENDER_ID))
236 1.1 sato return (0);
237 1.1 sato
238 1.1 sato return (1);
239 1.1 sato }
240 1.1 sato
241 1.1 sato void
242 1.15 uch ite8181_attach(struct ite8181_softc *sc)
243 1.1 sato {
244 1.1 sato unsigned long regval;
245 1.1 sato struct hpcfb_attach_args ha;
246 1.1 sato int console = (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) ? 0 : 1;
247 1.1 sato
248 1.6 sato printf(": ");
249 1.6 sato if (ite8181_fbinit(&sc->sc_fbconf) != 0) {
250 1.6 sato /* just return so that hpcfb will not be attached */
251 1.6 sato return;
252 1.6 sato }
253 1.6 sato
254 1.1 sato regval = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_CLASS);
255 1.6 sato printf("ITE8181 Rev.%02lx", regval & ITE8181_REV_MASK);
256 1.6 sato if (console) {
257 1.6 sato printf(", console");
258 1.6 sato }
259 1.6 sato printf("\n");
260 1.6 sato printf("%s: framebuffer address: 0x%08lx\n",
261 1.15 uch sc->sc_dev.dv_xname, (u_long)bootinfo->fb_addr);
262 1.10 sato if (ite8181_lcd_control_disable)
263 1.18 wiz printf("%s: ite8181 lcd control is DISABLED.\n",
264 1.15 uch sc->sc_dev.dv_xname);
265 1.1 sato
266 1.1 sato /* set base offsets */
267 1.1 sato sc->sc_mba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_MBA);
268 1.1 sato DPRINTFN(1, ("ite8181: Memory base offset %08x\n", sc->sc_mba));
269 1.1 sato sc->sc_gba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_GBA);
270 1.1 sato DPRINTFN(1, ("ite8181: GUI base offset %08x\n", sc->sc_gba));
271 1.1 sato sc->sc_sba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_SBA);
272 1.1 sato DPRINTFN(1, ("ite8181: Graphics base offset %08x\n", sc->sc_sba));
273 1.1 sato
274 1.1 sato /* assume lcd is on */
275 1.1 sato sc->sc_lcd = 1;
276 1.11 sato /* erase wince cursor */
277 1.11 sato ite8181_erase_cursor(sc);
278 1.1 sato
279 1.1 sato /* Add a power hook to power saving */
280 1.1 sato sc->sc_powerhook = powerhook_establish(ite8181_power, sc);
281 1.1 sato if (sc->sc_powerhook == NULL)
282 1.1 sato printf("%s: WARNING: unable to establish power hook\n",
283 1.15 uch sc->sc_dev.dv_xname);
284 1.1 sato
285 1.1 sato /* Add a hard power hook to power saving */
286 1.1 sato sc->sc_hardpowerhook = config_hook(CONFIG_HOOK_PMEVENT,
287 1.15 uch CONFIG_HOOK_PMEVENT_HARDPOWER,
288 1.15 uch CONFIG_HOOK_SHARE,
289 1.15 uch ite8181_hardpower, sc);
290 1.1 sato if (sc->sc_hardpowerhook == NULL)
291 1.1 sato printf("%s: WARNING: unable to establish hard power hook\n",
292 1.15 uch sc->sc_dev.dv_xname);
293 1.1 sato
294 1.8 sato /* initialize backlight brightness and lcd contrast */
295 1.11 sato sc->sc_lcd_inited = 0;
296 1.11 sato ite8181_init_brightness(sc, 1);
297 1.11 sato ite8181_init_contrast(sc, 1);
298 1.11 sato ite8181_init_backlight(sc, 1);
299 1.8 sato
300 1.1 sato if (console && hpcfb_cnattach(&sc->sc_fbconf) != 0) {
301 1.1 sato panic("ite8181_attach: can't init fb console");
302 1.1 sato }
303 1.1 sato
304 1.1 sato ha.ha_console = console;
305 1.1 sato ha.ha_accessops = &ite8181_ha;
306 1.1 sato ha.ha_accessctx = sc;
307 1.1 sato ha.ha_curfbconf = 0;
308 1.1 sato ha.ha_nfbconf = 1;
309 1.1 sato ha.ha_fbconflist = &sc->sc_fbconf;
310 1.1 sato ha.ha_curdspconf = 0;
311 1.1 sato ha.ha_ndspconf = 1;
312 1.1 sato ha.ha_dspconflist = &sc->sc_dspconf;
313 1.1 sato
314 1.1 sato config_found(&sc->sc_dev, &ha, hpcfbprint);
315 1.1 sato
316 1.1 sato #if NBIVIDEO > 0
317 1.1 sato /*
318 1.1 sato * bivideo is no longer need
319 1.1 sato */
320 1.1 sato bivideo_dont_attach = 1;
321 1.1 sato #endif /* NBIVIDEO > 0 */
322 1.1 sato }
323 1.1 sato
324 1.15 uch int
325 1.15 uch ite8181_lcd_power(struct ite8181_softc *sc, int on)
326 1.1 sato {
327 1.1 sato int lcd_p;
328 1.1 sato int lcd_s;
329 1.1 sato int lcd_seq;
330 1.1 sato int loop = 10;
331 1.1 sato
332 1.1 sato if (ite8181_lcd_control_disable) {
333 1.1 sato VPRINTF(("ite8171_lcd_control_disable!: %s\n", on?"on":"off"));
334 1.1 sato return 0;
335 1.1 sato }
336 1.1 sato
337 1.1 sato if (sc->sc_lcd != on) {
338 1.1 sato ite8181_ema_write_1(sc, ITE8181_EMA_ENABLEEMA,
339 1.15 uch ITE8181_EMA_ENABLEPASS);
340 1.1 sato lcd_p = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER);
341 1.1 sato lcd_s = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT);
342 1.1 sato lcd_seq = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ);
343 1.1 sato DPRINTFN(1,("ite8181_lcd_power(%d)< p=%x, s=%x, seq=%x\n",
344 1.15 uch on,
345 1.15 uch lcd_p, lcd_s, lcd_seq));
346 1.1 sato if (on) {
347 1.1 sato sc->sc_lcd = 1;
348 1.1 sato lcd_seq |= (ITE8181_PUP0|ITE8181_PUP1|ITE8181_PUP2);
349 1.15 uch ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWERSEQ,
350 1.15 uch lcd_seq);
351 1.1 sato lcd_p &= ~ITE8181_LCDSTANDBY;
352 1.1 sato ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWER, lcd_p);
353 1.1 sato /*
354 1.1 sato * XXX:
355 1.1 sato * IBM WorkPad z50 power unit has too weak power.
356 1.1 sato * So we must wait too many times to access self device
357 1.1 sato * after LCD panel and BackLight on.
358 1.1 sato * Currently delay is not enough ??? FIXME
359 1.1 sato */
360 1.2 sato delay(ite8181_lcd_on_self_delay*MSEC);
361 1.1 sato while (loop--) {
362 1.15 uch lcd_p = ite8181_ema_read_1(sc,
363 1.15 uch ITE8181_EMA_LCDPOWER);
364 1.15 uch lcd_s = ite8181_ema_read_1(sc,
365 1.15 uch ITE8181_EMA_LCDPOWERSTAT);
366 1.15 uch lcd_seq = ite8181_ema_read_1(sc,
367 1.15 uch ITE8181_EMA_LCDPOWERSEQ);
368 1.15 uch DPRINTFN(1,("ite8181_lcd_power(%d)%d| p=%x,"
369 1.15 uch " s=%x, seq=%x\n", on, loop, lcd_p, lcd_s,
370 1.15 uch lcd_seq));
371 1.15 uch /*
372 1.15 uch * XXX the states which are not described
373 1.15 uch * XXX in manual.
374 1.15 uch */
375 1.1 sato if (!(lcd_s&ITE8181_LCDPSTANDBY) &&
376 1.15 uch !(lcd_s&ITE8181_LCDPUP) &&
377 1.15 uch (lcd_s&ITE8181_LCDPON))
378 1.1 sato break;
379 1.1 sato delay(100);
380 1.1 sato }
381 1.1 sato lcd_s |= ITE8181_PPTOBEON;
382 1.15 uch ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWERSTAT,
383 1.15 uch lcd_s);
384 1.1 sato } else {
385 1.1 sato sc->sc_lcd = 0;
386 1.1 sato lcd_p |= ITE8181_LCDSTANDBY;
387 1.1 sato ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWER, lcd_p);
388 1.1 sato while (loop--) {
389 1.15 uch lcd_p = ite8181_ema_read_1(sc,
390 1.15 uch ITE8181_EMA_LCDPOWER);
391 1.15 uch lcd_s = ite8181_ema_read_1(sc,
392 1.15 uch ITE8181_EMA_LCDPOWERSTAT);
393 1.15 uch lcd_seq = ite8181_ema_read_1(sc,
394 1.15 uch ITE8181_EMA_LCDPOWERSEQ);
395 1.15 uch DPRINTFN(1,("ite8181_lcd_power(%d)%d| p=%x,"
396 1.15 uch " s=%x, seq=%x\n", on, loop, lcd_p, lcd_s,
397 1.15 uch lcd_seq));
398 1.15 uch /*
399 1.15 uch * XXX the states which are not described
400 1.15 uch * XXX in manual.
401 1.15 uch */
402 1.1 sato if ((lcd_s&ITE8181_LCDPSTANDBY) &&
403 1.15 uch !(lcd_s&ITE8181_LCDPDOWN) &&
404 1.15 uch !(lcd_s&ITE8181_LCDPON))
405 1.1 sato break;
406 1.1 sato delay(100);
407 1.1 sato }
408 1.1 sato lcd_s &= ~ITE8181_PPTOBEON;
409 1.15 uch ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWERSTAT,
410 1.15 uch lcd_s);
411 1.1 sato }
412 1.1 sato DPRINTFN(1,("ite8181_lcd_power(%d)> p=%x, s=%x, seq=%x\n",
413 1.15 uch on,
414 1.15 uch ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER),
415 1.15 uch ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT),
416 1.15 uch ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ)));
417 1.1 sato ite8181_ema_write_1(sc, ITE8181_EMA_ENABLEEMA,
418 1.15 uch ITE8181_EMA_DISABLEPASS);
419 1.1 sato }
420 1.1 sato return 0;
421 1.1 sato }
422 1.1 sato
423 1.1 sato static void
424 1.15 uch ite8181_erase_cursor(struct ite8181_softc *sc)
425 1.1 sato {
426 1.1 sato ite8181_gui_write_1(sc, ITE8181_GUI_C1C, 0); /* Cursor 1 Control Reg. */
427 1.1 sato /* other ? */
428 1.1 sato }
429 1.1 sato
430 1.8 sato static void
431 1.15 uch ite8181_update_powerstate(struct ite8181_softc *sc, int updates)
432 1.8 sato {
433 1.8 sato if (updates & PWRSTAT_LCD)
434 1.8 sato config_hook_call(CONFIG_HOOK_POWERCONTROL,
435 1.8 sato CONFIG_HOOK_POWERCONTROL_LCD,
436 1.9 sato (void*)!(sc->sc_powerstate &
437 1.15 uch (PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)));
438 1.8 sato
439 1.8 sato if (updates & PWRSTAT_BACKLIGHT)
440 1.8 sato config_hook_call(CONFIG_HOOK_POWERCONTROL,
441 1.8 sato CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
442 1.9 sato (void*)(!(sc->sc_powerstate &
443 1.15 uch (PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)) &&
444 1.15 uch (sc->sc_powerstate & PWRSTAT_BACKLIGHT)));
445 1.8 sato }
446 1.8 sato
447 1.1 sato static void
448 1.15 uch ite8181_power(int why, void *arg)
449 1.1 sato {
450 1.10 sato struct ite8181_softc *sc = arg;
451 1.10 sato
452 1.10 sato switch (why) {
453 1.10 sato case PWR_STANDBY:
454 1.10 sato sc->sc_powerstate |= PWRSTAT_SUSPEND;
455 1.10 sato ite8181_update_powerstate(sc, PWRSTAT_ALL);
456 1.10 sato break;
457 1.10 sato case PWR_SUSPEND:
458 1.10 sato sc->sc_powerstate |= PWRSTAT_SUSPEND;
459 1.10 sato ite8181_update_powerstate(sc, PWRSTAT_ALL);
460 1.10 sato break;
461 1.10 sato case PWR_RESUME:
462 1.10 sato sc->sc_powerstate &= ~PWRSTAT_SUSPEND;
463 1.10 sato ite8181_update_powerstate(sc, PWRSTAT_ALL);
464 1.10 sato break;
465 1.10 sato }
466 1.1 sato }
467 1.1 sato
468 1.1 sato static int
469 1.15 uch ite8181_hardpower(void *ctx, int type, long id, void *msg)
470 1.1 sato {
471 1.1 sato struct ite8181_softc *sc = ctx;
472 1.1 sato int why = (int)msg;
473 1.1 sato
474 1.1 sato switch (why) {
475 1.1 sato case PWR_STANDBY:
476 1.1 sato /* ite8181_lcd_power(sc, 0); */
477 1.1 sato delay(MSEC);
478 1.1 sato break;
479 1.1 sato case PWR_SUSPEND:
480 1.1 sato ite8181_lcd_power(sc, 0);
481 1.1 sato delay(MSEC);
482 1.1 sato break;
483 1.1 sato case PWR_RESUME:
484 1.1 sato delay(MSEC);
485 1.1 sato ite8181_lcd_power(sc, 1);
486 1.1 sato /*
487 1.1 sato * XXX:
488 1.1 sato * IBM WorkPad z50 power unit has too weak power.
489 1.1 sato * So we must wait too many times to access other devices
490 1.1 sato * after LCD panel and BackLight on.
491 1.1 sato */
492 1.2 sato delay(ite8181_lcd_on_delay*MSEC);
493 1.1 sato break;
494 1.1 sato }
495 1.1 sato
496 1.1 sato /*
497 1.1 sato * you should wait until the
498 1.1 sato * power state transit sequence will end.
499 1.1 sato */
500 1.1 sato
501 1.1 sato return (0);
502 1.1 sato }
503 1.1 sato
504 1.1 sato static int
505 1.15 uch ite8181_fbinit(struct hpcfb_fbconf *fb)
506 1.1 sato {
507 1.1 sato
508 1.1 sato /*
509 1.1 sato * get fb settings from bootinfo
510 1.1 sato */
511 1.1 sato if (bootinfo == NULL ||
512 1.1 sato bootinfo->fb_addr == 0 ||
513 1.1 sato bootinfo->fb_line_bytes == 0 ||
514 1.1 sato bootinfo->fb_width == 0 ||
515 1.1 sato bootinfo->fb_height == 0) {
516 1.13 toshii printf("no frame buffer information.\n");
517 1.1 sato return (-1);
518 1.1 sato }
519 1.1 sato
520 1.1 sato /* zero fill */
521 1.1 sato bzero(fb, sizeof(*fb));
522 1.1 sato
523 1.1 sato fb->hf_conf_index = 0; /* configuration index */
524 1.1 sato fb->hf_nconfs = 1; /* how many configurations */
525 1.1 sato strcpy(fb->hf_name, "built-in video");
526 1.1 sato /* frame buffer name */
527 1.1 sato strcpy(fb->hf_conf_name, "default");
528 1.1 sato /* configuration name */
529 1.1 sato fb->hf_height = bootinfo->fb_height;
530 1.1 sato fb->hf_width = bootinfo->fb_width;
531 1.4 takemura fb->hf_baseaddr = (u_long)bootinfo->fb_addr;
532 1.4 takemura fb->hf_offset = (u_long)bootinfo->fb_addr -
533 1.15 uch mips_ptob(mips_btop(bootinfo->fb_addr));
534 1.1 sato /* frame buffer start offset */
535 1.1 sato fb->hf_bytes_per_line = bootinfo->fb_line_bytes;
536 1.1 sato fb->hf_nplanes = 1;
537 1.1 sato fb->hf_bytes_per_plane = bootinfo->fb_height *
538 1.15 uch bootinfo->fb_line_bytes;
539 1.1 sato
540 1.1 sato fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
541 1.1 sato fb->hf_access_flags |= HPCFB_ACCESS_WORD;
542 1.1 sato fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
543 1.1 sato
544 1.1 sato switch (bootinfo->fb_type) {
545 1.1 sato /*
546 1.1 sato * gray scale
547 1.1 sato */
548 1.1 sato case BIFB_D2_M2L_3:
549 1.1 sato case BIFB_D2_M2L_3x2:
550 1.1 sato fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
551 1.1 sato /* fall through */
552 1.1 sato case BIFB_D2_M2L_0:
553 1.1 sato case BIFB_D2_M2L_0x2:
554 1.1 sato fb->hf_class = HPCFB_CLASS_GRAYSCALE;
555 1.1 sato fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
556 1.1 sato fb->hf_pack_width = 8;
557 1.1 sato fb->hf_pixels_per_pack = 4;
558 1.1 sato fb->hf_pixel_width = 2;
559 1.5 sato fb->hf_class_data_length = sizeof(struct hf_gray_tag);
560 1.5 sato fb->hf_u.hf_gray.hf_flags = 0; /* reserved for future use */
561 1.5 sato break;
562 1.5 sato
563 1.5 sato case BIFB_D4_M2L_F:
564 1.5 sato case BIFB_D4_M2L_Fx2:
565 1.5 sato fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
566 1.5 sato /* fall through */
567 1.5 sato case BIFB_D4_M2L_0:
568 1.5 sato case BIFB_D4_M2L_0x2:
569 1.5 sato fb->hf_class = HPCFB_CLASS_GRAYSCALE;
570 1.5 sato fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
571 1.5 sato fb->hf_pack_width = 8;
572 1.5 sato fb->hf_pixels_per_pack = 2;
573 1.5 sato fb->hf_pixel_width = 4;
574 1.1 sato fb->hf_class_data_length = sizeof(struct hf_gray_tag);
575 1.1 sato fb->hf_u.hf_gray.hf_flags = 0; /* reserved for future use */
576 1.1 sato break;
577 1.1 sato
578 1.1 sato /*
579 1.1 sato * indexed color
580 1.1 sato */
581 1.1 sato case BIFB_D8_FF:
582 1.1 sato fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
583 1.1 sato /* fall through */
584 1.1 sato case BIFB_D8_00:
585 1.1 sato fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
586 1.1 sato fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
587 1.1 sato fb->hf_pack_width = 8;
588 1.1 sato fb->hf_pixels_per_pack = 1;
589 1.1 sato fb->hf_pixel_width = 8;
590 1.1 sato fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
591 1.1 sato fb->hf_u.hf_indexed.hf_flags = 0; /* reserved for future use */
592 1.1 sato break;
593 1.1 sato
594 1.1 sato /*
595 1.1 sato * RGB color
596 1.1 sato */
597 1.1 sato case BIFB_D16_FFFF:
598 1.1 sato fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
599 1.1 sato /* fall through */
600 1.1 sato case BIFB_D16_0000:
601 1.1 sato fb->hf_class = HPCFB_CLASS_RGBCOLOR;
602 1.1 sato fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
603 1.14 takemura fb->hf_order_flags = HPCFB_REVORDER_BYTE;
604 1.1 sato fb->hf_pack_width = 16;
605 1.1 sato fb->hf_pixels_per_pack = 1;
606 1.1 sato fb->hf_pixel_width = 16;
607 1.1 sato
608 1.1 sato fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
609 1.1 sato fb->hf_u.hf_rgb.hf_flags = 0; /* reserved for future use */
610 1.1 sato
611 1.1 sato fb->hf_u.hf_rgb.hf_red_width = 5;
612 1.1 sato fb->hf_u.hf_rgb.hf_red_shift = 11;
613 1.1 sato fb->hf_u.hf_rgb.hf_green_width = 6;
614 1.1 sato fb->hf_u.hf_rgb.hf_green_shift = 5;
615 1.1 sato fb->hf_u.hf_rgb.hf_blue_width = 5;
616 1.1 sato fb->hf_u.hf_rgb.hf_blue_shift = 0;
617 1.1 sato fb->hf_u.hf_rgb.hf_alpha_width = 0;
618 1.1 sato fb->hf_u.hf_rgb.hf_alpha_shift = 0;
619 1.1 sato break;
620 1.1 sato
621 1.1 sato default:
622 1.1 sato printf("unknown type (=%d).\n", bootinfo->fb_type);
623 1.1 sato return (-1);
624 1.1 sato break;
625 1.1 sato }
626 1.1 sato
627 1.1 sato return (0); /* no error */
628 1.1 sato }
629 1.1 sato
630 1.1 sato int
631 1.1 sato ite8181_ioctl(v, cmd, data, flag, p)
632 1.1 sato void *v;
633 1.1 sato u_long cmd;
634 1.1 sato caddr_t data;
635 1.1 sato int flag;
636 1.1 sato struct proc *p;
637 1.1 sato {
638 1.1 sato struct ite8181_softc *sc = (struct ite8181_softc *)v;
639 1.1 sato struct hpcfb_fbconf *fbconf;
640 1.1 sato struct hpcfb_dspconf *dspconf;
641 1.1 sato struct wsdisplay_cmap *cmap;
642 1.8 sato struct wsdisplay_param *dispparam;
643 1.20 chs int error;
644 1.1 sato
645 1.1 sato switch (cmd) {
646 1.1 sato case WSDISPLAYIO_GETCMAP:
647 1.20 chs cmap = (struct wsdisplay_cmap *)data;
648 1.1 sato
649 1.1 sato if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
650 1.1 sato sc->sc_fbconf.hf_pack_width != 8 ||
651 1.1 sato 256 <= cmap->index ||
652 1.17 itojun 256 - cmap->index < cmap->count)
653 1.1 sato return (EINVAL);
654 1.1 sato
655 1.2 sato #ifdef ITE8181_WINCE_CMAP
656 1.20 chs error = copyout(&bivideo_cmap_r[cmap->index], cmap->red,
657 1.20 chs cmap->count);
658 1.20 chs if (error)
659 1.20 chs return error;
660 1.20 chs error = copyout(&bivideo_cmap_g[cmap->index], cmap->green,
661 1.20 chs cmap->count);
662 1.20 chs if (error)
663 1.20 chs return error;
664 1.20 chs error = copyout(&bivideo_cmap_b[cmap->index], cmap->blue,
665 1.20 chs cmap->count);
666 1.20 chs return error;
667 1.2 sato #else /* ITE8181_WINCE_CMAP */
668 1.2 sato return EINVAL;
669 1.2 sato #endif /* ITE8181_WINCE_CMAP */
670 1.1 sato
671 1.1 sato case WSDISPLAYIO_PUTCMAP:
672 1.1 sato /*
673 1.1 sato * This driver can't set color map.
674 1.1 sato */
675 1.1 sato return (EINVAL);
676 1.9 sato
677 1.9 sato case WSDISPLAYIO_SVIDEO:
678 1.9 sato if (*(int *)data == WSDISPLAYIO_VIDEO_OFF)
679 1.9 sato sc->sc_powerstate |= PWRSTAT_VIDEOOFF;
680 1.9 sato else
681 1.9 sato sc->sc_powerstate &= ~PWRSTAT_VIDEOOFF;
682 1.9 sato ite8181_update_powerstate(sc, PWRSTAT_ALL);
683 1.9 sato return 0;
684 1.9 sato
685 1.9 sato case WSDISPLAYIO_GVIDEO:
686 1.9 sato *(int *)data = (sc->sc_powerstate&PWRSTAT_VIDEOOFF) ?
687 1.15 uch WSDISPLAYIO_VIDEO_OFF:WSDISPLAYIO_VIDEO_ON;
688 1.9 sato return 0;
689 1.1 sato
690 1.8 sato
691 1.8 sato case WSDISPLAYIO_GETPARAM:
692 1.8 sato dispparam = (struct wsdisplay_param*)data;
693 1.8 sato switch (dispparam->param) {
694 1.8 sato case WSDISPLAYIO_PARAM_BACKLIGHT:
695 1.11 sato VPRINTF(("ite8181_ioctl: GET:BACKLIGHT\n"));
696 1.11 sato ite8181_init_brightness(sc, 0);
697 1.11 sato ite8181_init_backlight(sc, 0);
698 1.11 sato VPRINTF(("ite8181_ioctl: GET:(real)BACKLIGHT %d\n",
699 1.15 uch (sc->sc_powerstate&PWRSTAT_BACKLIGHT)? 1: 0));
700 1.8 sato dispparam->min = 0;
701 1.8 sato dispparam->max = 1;
702 1.8 sato if (sc->sc_max_brightness > 0)
703 1.15 uch dispparam->curval =
704 1.15 uch sc->sc_brightness > 0 ? 1: 0;
705 1.8 sato else
706 1.8 sato dispparam->curval =
707 1.15 uch (sc->sc_powerstate & PWRSTAT_BACKLIGHT)
708 1.15 uch ? 1: 0;
709 1.11 sato VPRINTF(("ite8181_ioctl: GET:BACKLIGHT:%d(%s)\n",
710 1.15 uch dispparam->curval,
711 1.15 uch sc->sc_max_brightness > 0? "brightness": "light"));
712 1.8 sato return 0;
713 1.8 sato break;
714 1.8 sato case WSDISPLAYIO_PARAM_CONTRAST:
715 1.11 sato VPRINTF(("ite8181_ioctl: GET:CONTRAST\n"));
716 1.11 sato ite8181_init_contrast(sc, 0);
717 1.8 sato if (sc->sc_max_contrast > 0) {
718 1.8 sato dispparam->min = 0;
719 1.8 sato dispparam->max = sc->sc_max_contrast;
720 1.8 sato dispparam->curval = sc->sc_contrast;
721 1.15 uch VPRINTF(("ite8181_ioctl: GET:CONTRAST max=%d,"
722 1.15 uch " current=%d\n", sc->sc_max_contrast,
723 1.15 uch sc->sc_contrast));
724 1.8 sato return 0;
725 1.8 sato } else {
726 1.15 uch VPRINTF(("ite8181_ioctl: "
727 1.15 uch "GET:CONTRAST EINVAL\n"));
728 1.8 sato return (EINVAL);
729 1.8 sato }
730 1.8 sato break;
731 1.8 sato case WSDISPLAYIO_PARAM_BRIGHTNESS:
732 1.11 sato VPRINTF(("ite8181_ioctl: GET:BRIGHTNESS\n"));
733 1.11 sato ite8181_init_brightness(sc, 0);
734 1.8 sato if (sc->sc_max_brightness > 0) {
735 1.8 sato dispparam->min = 0;
736 1.8 sato dispparam->max = sc->sc_max_brightness;
737 1.8 sato dispparam->curval = sc->sc_brightness;
738 1.15 uch VPRINTF(("ite8181_ioctl: GET:BRIGHTNESS"
739 1.15 uch " max=%d, current=%d\n",
740 1.15 uch sc->sc_max_brightness, sc->sc_brightness));
741 1.8 sato return 0;
742 1.8 sato } else {
743 1.15 uch VPRINTF(("ite8181_ioctl: GET:BRIGHTNESS"
744 1.15 uch " EINVAL\n"));
745 1.8 sato return (EINVAL);
746 1.8 sato }
747 1.8 sato return (EINVAL);
748 1.8 sato default:
749 1.8 sato return (EINVAL);
750 1.8 sato }
751 1.8 sato return (0);
752 1.8 sato
753 1.8 sato case WSDISPLAYIO_SETPARAM:
754 1.8 sato dispparam = (struct wsdisplay_param*)data;
755 1.8 sato switch (dispparam->param) {
756 1.8 sato case WSDISPLAYIO_PARAM_BACKLIGHT:
757 1.11 sato VPRINTF(("ite8181_ioctl: SET:BACKLIGHT\n"));
758 1.8 sato if (dispparam->curval < 0 ||
759 1.8 sato 1 < dispparam->curval)
760 1.8 sato return (EINVAL);
761 1.11 sato ite8181_init_brightness(sc, 0);
762 1.15 uch VPRINTF(("ite8181_ioctl: SET:max brightness=%d\n",
763 1.15 uch sc->sc_max_brightness));
764 1.8 sato if (sc->sc_max_brightness > 0) { /* dimmer */
765 1.8 sato if (dispparam->curval == 0){
766 1.15 uch sc->sc_brightness_save =
767 1.15 uch sc->sc_brightness;
768 1.15 uch ite8181_set_brightness(sc, 0);/* min */
769 1.8 sato } else {
770 1.8 sato if (sc->sc_brightness_save == 0)
771 1.15 uch sc->sc_brightness_save =
772 1.15 uch sc->sc_max_brightness;
773 1.15 uch ite8181_set_brightness(sc,
774 1.15 uch sc->sc_brightness_save);
775 1.8 sato }
776 1.15 uch VPRINTF(("ite8181_ioctl: SET:BACKLIGHT:"
777 1.15 uch "brightness=%d\n", sc->sc_brightness));
778 1.8 sato } else { /* off */
779 1.8 sato if (dispparam->curval == 0)
780 1.8 sato sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
781 1.8 sato else
782 1.8 sato sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
783 1.15 uch VPRINTF(("ite8181_ioctl: SET:BACKLIGHT:"
784 1.15 uch "powerstate %d\n",
785 1.15 uch (sc->sc_powerstate & PWRSTAT_BACKLIGHT)
786 1.15 uch ? 1 : 0));
787 1.15 uch ite8181_update_powerstate(sc,
788 1.15 uch PWRSTAT_BACKLIGHT);
789 1.11 sato VPRINTF(("ite8181_ioctl: SET:BACKLIGHT:%d\n",
790 1.15 uch (sc->sc_powerstate & PWRSTAT_BACKLIGHT)
791 1.15 uch ? 1 : 0));
792 1.8 sato }
793 1.8 sato return 0;
794 1.8 sato break;
795 1.8 sato case WSDISPLAYIO_PARAM_CONTRAST:
796 1.11 sato VPRINTF(("ite8181_ioctl: SET:CONTRAST\n"));
797 1.11 sato ite8181_init_contrast(sc, 0);
798 1.8 sato if (dispparam->curval < 0 ||
799 1.8 sato sc->sc_max_contrast < dispparam->curval)
800 1.8 sato return (EINVAL);
801 1.8 sato if (sc->sc_max_contrast > 0) {
802 1.8 sato int org = sc->sc_contrast;
803 1.15 uch ite8181_set_contrast(sc, dispparam->curval);
804 1.15 uch VPRINTF(("ite8181_ioctl: SET:CONTRAST"
805 1.15 uch " org=%d, current=%d\n", org,
806 1.15 uch sc->sc_contrast));
807 1.8 sato return 0;
808 1.8 sato } else {
809 1.15 uch VPRINTF(("ite8181_ioctl: SET:CONTRAST"
810 1.15 uch " EINVAL\n"));
811 1.8 sato return (EINVAL);
812 1.8 sato }
813 1.8 sato break;
814 1.8 sato case WSDISPLAYIO_PARAM_BRIGHTNESS:
815 1.11 sato VPRINTF(("ite8181_ioctl: SET:BRIGHTNESS\n"));
816 1.11 sato ite8181_init_brightness(sc, 0);
817 1.8 sato if (dispparam->curval < 0 ||
818 1.8 sato sc->sc_max_brightness < dispparam->curval)
819 1.8 sato return (EINVAL);
820 1.8 sato if (sc->sc_max_brightness > 0) {
821 1.8 sato int org = sc->sc_brightness;
822 1.15 uch ite8181_set_brightness(sc, dispparam->curval);
823 1.15 uch VPRINTF(("ite8181_ioctl: SET:BRIGHTNESS"
824 1.15 uch " org=%d, current=%d\n", org,
825 1.15 uch sc->sc_brightness));
826 1.8 sato return 0;
827 1.8 sato } else {
828 1.15 uch VPRINTF(("ite8181_ioctl: SET:BRIGHTNESS"
829 1.15 uch " EINVAL\n"));
830 1.8 sato return (EINVAL);
831 1.8 sato }
832 1.8 sato break;
833 1.8 sato default:
834 1.8 sato return (EINVAL);
835 1.8 sato }
836 1.8 sato return (0);
837 1.8 sato
838 1.1 sato case HPCFBIO_GCONF:
839 1.1 sato fbconf = (struct hpcfb_fbconf *)data;
840 1.1 sato if (fbconf->hf_conf_index != 0 &&
841 1.1 sato fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
842 1.1 sato return (EINVAL);
843 1.1 sato }
844 1.1 sato *fbconf = sc->sc_fbconf; /* structure assignment */
845 1.1 sato return (0);
846 1.1 sato case HPCFBIO_SCONF:
847 1.1 sato fbconf = (struct hpcfb_fbconf *)data;
848 1.1 sato if (fbconf->hf_conf_index != 0 &&
849 1.1 sato fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
850 1.1 sato return (EINVAL);
851 1.1 sato }
852 1.1 sato /*
853 1.21 abs * nothing to do because we have only one configuration
854 1.1 sato */
855 1.1 sato return (0);
856 1.1 sato case HPCFBIO_GDSPCONF:
857 1.1 sato dspconf = (struct hpcfb_dspconf *)data;
858 1.1 sato if ((dspconf->hd_unit_index != 0 &&
859 1.15 uch dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
860 1.1 sato (dspconf->hd_conf_index != 0 &&
861 1.15 uch dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
862 1.1 sato return (EINVAL);
863 1.1 sato }
864 1.1 sato *dspconf = sc->sc_dspconf; /* structure assignment */
865 1.1 sato return (0);
866 1.1 sato case HPCFBIO_SDSPCONF:
867 1.1 sato dspconf = (struct hpcfb_dspconf *)data;
868 1.1 sato if ((dspconf->hd_unit_index != 0 &&
869 1.15 uch dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
870 1.1 sato (dspconf->hd_conf_index != 0 &&
871 1.15 uch dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
872 1.1 sato return (EINVAL);
873 1.1 sato }
874 1.1 sato /*
875 1.1 sato * nothing to do
876 1.21 abs * because we have only one unit and one configuration
877 1.1 sato */
878 1.1 sato return (0);
879 1.1 sato case HPCFBIO_GOP:
880 1.1 sato case HPCFBIO_SOP:
881 1.1 sato /*
882 1.1 sato * curently not implemented...
883 1.1 sato */
884 1.1 sato return (EINVAL);
885 1.1 sato }
886 1.1 sato
887 1.16 atatat return (EPASSTHROUGH);
888 1.1 sato }
889 1.1 sato
890 1.1 sato paddr_t
891 1.15 uch ite8181_mmap(void *ctx, off_t offset, int prot)
892 1.1 sato {
893 1.1 sato struct ite8181_softc *sc = (struct ite8181_softc *)ctx;
894 1.1 sato
895 1.1 sato if (offset < 0 ||
896 1.1 sato (sc->sc_fbconf.hf_bytes_per_plane +
897 1.1 sato sc->sc_fbconf.hf_offset) < offset)
898 1.1 sato return -1;
899 1.1 sato
900 1.4 takemura return mips_btop((u_long)bootinfo->fb_addr + offset);
901 1.8 sato }
902 1.8 sato
903 1.11 sato
904 1.8 sato void
905 1.15 uch ite8181_init_backlight(struct ite8181_softc *sc, int inattach)
906 1.8 sato {
907 1.8 sato int val = -1;
908 1.8 sato
909 1.11 sato if (sc->sc_lcd_inited&BACKLIGHT_INITED)
910 1.11 sato return;
911 1.11 sato
912 1.10 sato if (config_hook_call(CONFIG_HOOK_GET,
913 1.15 uch CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
914 1.11 sato /* we can get real light state */
915 1.11 sato VPRINTF(("ite8181_init_backlight: real backlight=%d\n", val));
916 1.10 sato if (val == 0)
917 1.10 sato sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
918 1.10 sato else
919 1.10 sato sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
920 1.11 sato sc->sc_lcd_inited |= BACKLIGHT_INITED;
921 1.11 sato } else if (inattach) {
922 1.11 sato /*
923 1.11 sato we cannot get real light state in attach time
924 1.11 sato because light device not yet attached.
925 1.11 sato we will retry in !inattach.
926 1.11 sato temporary assume light is on.
927 1.15 uch */
928 1.10 sato sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
929 1.11 sato } else {
930 1.11 sato /* we cannot get real light state, so work by myself state */
931 1.11 sato sc->sc_lcd_inited |= BACKLIGHT_INITED;
932 1.11 sato }
933 1.8 sato }
934 1.8 sato
935 1.8 sato void
936 1.15 uch ite8181_init_brightness(struct ite8181_softc *sc, int inattach)
937 1.8 sato {
938 1.8 sato int val = -1;
939 1.8 sato
940 1.11 sato if (sc->sc_lcd_inited&BRIGHTNESS_INITED)
941 1.11 sato return;
942 1.11 sato
943 1.11 sato VPRINTF(("ite8181_init_brightness\n"));
944 1.8 sato if (config_hook_call(CONFIG_HOOK_GET,
945 1.15 uch CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
946 1.11 sato /* we can get real brightness max */
947 1.15 uch VPRINTF(("ite8181_init_brightness: real brightness max=%d\n",
948 1.15 uch val));
949 1.11 sato sc->sc_max_brightness = val;
950 1.11 sato val = -1;
951 1.11 sato if (config_hook_call(CONFIG_HOOK_GET,
952 1.15 uch CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
953 1.11 sato /* we can get real brightness */
954 1.15 uch VPRINTF(("ite8181_init_brightness:"
955 1.15 uch " real brightness=%d\n", val));
956 1.11 sato sc->sc_brightness_save = sc->sc_brightness = val;
957 1.11 sato } else {
958 1.11 sato sc->sc_brightness_save =
959 1.15 uch sc->sc_brightness = sc->sc_max_brightness;
960 1.11 sato }
961 1.11 sato sc->sc_lcd_inited |= BRIGHTNESS_INITED;
962 1.11 sato } else if (inattach) {
963 1.11 sato /*
964 1.11 sato we cannot get real brightness in attach time
965 1.11 sato because brightness device not yet attached.
966 1.11 sato we will retry in !inattach.
967 1.15 uch */
968 1.11 sato sc->sc_max_brightness = -1;
969 1.11 sato sc->sc_brightness = -1;
970 1.11 sato sc->sc_brightness_save = -1;
971 1.11 sato } else {
972 1.11 sato /* we cannot get real brightness */
973 1.11 sato sc->sc_lcd_inited |= BRIGHTNESS_INITED;
974 1.8 sato }
975 1.11 sato
976 1.8 sato return;
977 1.8 sato }
978 1.8 sato
979 1.8 sato void
980 1.15 uch ite8181_init_contrast(struct ite8181_softc *sc, int inattach)
981 1.8 sato {
982 1.8 sato int val = -1;
983 1.8 sato
984 1.11 sato if (sc->sc_lcd_inited&CONTRAST_INITED)
985 1.11 sato return;
986 1.11 sato
987 1.11 sato VPRINTF(("ite8181_init_contrast\n"));
988 1.8 sato if (config_hook_call(CONFIG_HOOK_GET,
989 1.15 uch CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
990 1.11 sato /* we can get real contrast max */
991 1.11 sato VPRINTF(("ite8181_init_contrast: real contrast max=%d\n", val));
992 1.8 sato sc->sc_max_contrast = val;
993 1.11 sato val = -1;
994 1.11 sato if (config_hook_call(CONFIG_HOOK_GET,
995 1.15 uch CONFIG_HOOK_CONTRAST, &val) != -1) {
996 1.11 sato /* we can get real contrast */
997 1.15 uch VPRINTF(("ite8181_init_contrast: real contrast=%d\n",
998 1.15 uch val));
999 1.11 sato sc->sc_contrast = val;
1000 1.11 sato } else {
1001 1.11 sato sc->sc_contrast = sc->sc_max_contrast;
1002 1.11 sato }
1003 1.11 sato sc->sc_lcd_inited |= CONTRAST_INITED;
1004 1.11 sato } else if (inattach) {
1005 1.11 sato /*
1006 1.11 sato we cannot get real contrast in attach time
1007 1.11 sato because contrast device not yet attached.
1008 1.11 sato we will retry in !inattach.
1009 1.15 uch */
1010 1.11 sato sc->sc_max_contrast = -1;
1011 1.11 sato sc->sc_contrast = -1;
1012 1.11 sato } else {
1013 1.11 sato /* we cannot get real contrast */
1014 1.11 sato sc->sc_lcd_inited |= CONTRAST_INITED;
1015 1.8 sato }
1016 1.11 sato
1017 1.8 sato return;
1018 1.8 sato }
1019 1.11 sato
1020 1.8 sato
1021 1.8 sato void
1022 1.15 uch ite8181_set_brightness(struct ite8181_softc *sc, int val)
1023 1.8 sato {
1024 1.15 uch
1025 1.8 sato sc->sc_brightness = val;
1026 1.8 sato
1027 1.8 sato config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
1028 1.8 sato if (config_hook_call(CONFIG_HOOK_GET,
1029 1.15 uch CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
1030 1.8 sato sc->sc_brightness = val;
1031 1.8 sato }
1032 1.8 sato }
1033 1.8 sato
1034 1.8 sato void
1035 1.15 uch ite8181_set_contrast(struct ite8181_softc *sc, int val)
1036 1.8 sato {
1037 1.15 uch
1038 1.8 sato sc->sc_contrast = val;
1039 1.8 sato
1040 1.8 sato config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
1041 1.8 sato if (config_hook_call(CONFIG_HOOK_GET,
1042 1.15 uch CONFIG_HOOK_CONTRAST, &val) != -1) {
1043 1.8 sato sc->sc_contrast = val;
1044 1.8 sato }
1045 1.1 sato }
1046