ite8181.c revision 1.3.2.3 1 1.3.2.3 bouyer /* $NetBSD: ite8181.c,v 1.3.2.3 2000/11/22 16:00:10 bouyer Exp $ */
2 1.3.2.2 bouyer
3 1.3.2.2 bouyer /*-
4 1.3.2.2 bouyer * Copyright (c) 2000 SATO Kazumi
5 1.3.2.2 bouyer * All rights reserved.
6 1.3.2.2 bouyer *
7 1.3.2.2 bouyer * Redistribution and use in source and binary forms, with or without
8 1.3.2.2 bouyer * modification, are permitted provided that the following conditions
9 1.3.2.2 bouyer * are met:
10 1.3.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
11 1.3.2.2 bouyer * notice, this list of conditions and the following disclaimer.
12 1.3.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
13 1.3.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
14 1.3.2.2 bouyer * documentation and/or other materials provided with the distribution.
15 1.3.2.2 bouyer *
16 1.3.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.3.2.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.3.2.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.3.2.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.3.2.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.3.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.3.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.3.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.3.2.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.3.2.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.3.2.2 bouyer * SUCH DAMAGE.
27 1.3.2.2 bouyer *
28 1.3.2.2 bouyer */
29 1.3.2.2 bouyer
30 1.3.2.2 bouyer #include <sys/param.h>
31 1.3.2.2 bouyer #include <sys/kernel.h>
32 1.3.2.2 bouyer #include <sys/device.h>
33 1.3.2.2 bouyer #include <sys/systm.h>
34 1.3.2.2 bouyer #include <sys/boot_flag.h>
35 1.3.2.2 bouyer #include <sys/buf.h>
36 1.3.2.2 bouyer
37 1.3.2.2 bouyer #include <uvm/uvm_extern.h>
38 1.3.2.2 bouyer
39 1.3.2.2 bouyer #include <dev/wscons/wsconsio.h>
40 1.3.2.2 bouyer
41 1.3.2.2 bouyer #include <machine/bootinfo.h>
42 1.3.2.2 bouyer #include <machine/bus.h>
43 1.3.2.2 bouyer #include <machine/autoconf.h>
44 1.3.2.2 bouyer #include <machine/config_hook.h>
45 1.3.2.2 bouyer #include <machine/platid.h>
46 1.3.2.2 bouyer #include <machine/platid_mask.h>
47 1.3.2.2 bouyer
48 1.3.2.2 bouyer #include <hpcmips/dev/ite8181reg.h>
49 1.3.2.2 bouyer #include <hpcmips/dev/ite8181var.h>
50 1.3.2.2 bouyer #include "bivideo.h"
51 1.3.2.2 bouyer #if NBIVIDEO > 0
52 1.3.2.2 bouyer #include <hpcmips/dev/bivideovar.h>
53 1.3.2.2 bouyer #endif
54 1.3.2.2 bouyer #include <hpcmips/dev/hpccmapvar.h>
55 1.3.2.2 bouyer
56 1.3.2.2 bouyer
57 1.3.2.2 bouyer #define ITE8181DEBUG
58 1.3.2.2 bouyer #ifdef ITE8181DEBUG
59 1.3.2.2 bouyer #ifndef ITE8181DEBUG_CONF
60 1.3.2.2 bouyer #define ITE8181DEBUG_CONF 0
61 1.3.2.2 bouyer #endif
62 1.3.2.2 bouyer int ite8181_debug = ITE8181DEBUG_CONF;
63 1.3.2.2 bouyer #define DPRINTF(arg) if (ite8181_debug) printf arg
64 1.3.2.2 bouyer #define DPRINTFN(n, arg) if (ite8181_debug > (n)) printf arg
65 1.3.2.2 bouyer #define VPRINTF(arg) if (bootverbose || ite8181_debug) printf arg
66 1.3.2.2 bouyer #define VPRINTFN(n, arg) if (bootverbose || ite8181_debug > (n)) printf arg
67 1.3.2.2 bouyer #else
68 1.3.2.2 bouyer #define DPRINTF(arg)
69 1.3.2.2 bouyer #define DPRINTFN(n, arg)
70 1.3.2.2 bouyer #define VPRINTF(arg) if (bootverbose) printf arg
71 1.3.2.2 bouyer #define VPRINTFN(n, arg) if (bootverbose) printf arg
72 1.3.2.2 bouyer #endif
73 1.3.2.2 bouyer
74 1.3.2.2 bouyer #ifndef ITE8181_LCD_CONTROL_ENABLE
75 1.3.2.2 bouyer int ite8181_lcd_control_disable = 1;
76 1.3.2.2 bouyer #else /* ITE8181_LCD_CONTROL_ENABLE */
77 1.3.2.2 bouyer int ite8181_lcd_control_disable = 0;
78 1.3.2.2 bouyer #endif /* ITE8181_LCD_CONTROL_ENABLE */
79 1.3.2.2 bouyer
80 1.3.2.2 bouyer #define ITE8181_WINCE_CMAP
81 1.3.2.2 bouyer
82 1.3.2.2 bouyer /*
83 1.3.2.2 bouyer * XXX:
84 1.3.2.2 bouyer * IBM WorkPad z50 power unit has too weak power.
85 1.3.2.2 bouyer * So we must wait too many times to access some device
86 1.3.2.2 bouyer * after LCD panel and BackLight on.
87 1.3.2.2 bouyer * Currently delay is not enough ??? FIXME
88 1.3.2.2 bouyer */
89 1.3.2.2 bouyer #ifndef ITE8181_LCD_ON_SELF_DELAY
90 1.3.2.3 bouyer #define ITE8181_LCD_ON_SELF_DELAY 1000
91 1.3.2.2 bouyer #endif /* ITE8181_LCD_ON__SELF_DELAY */
92 1.3.2.2 bouyer #ifndef ITE8181_LCD_ON_DELAY
93 1.3.2.2 bouyer #define ITE8181_LCD_ON_DELAY 2000
94 1.3.2.2 bouyer #endif /* ITE8181_LCD_ON_DELAY */
95 1.3.2.2 bouyer int ite8181_lcd_on_self_delay = ITE8181_LCD_ON_SELF_DELAY; /* msec */
96 1.3.2.2 bouyer int ite8181_lcd_on_delay = ITE8181_LCD_ON_DELAY; /* msec */
97 1.3.2.2 bouyer
98 1.3.2.2 bouyer #define MSEC 1000
99 1.3.2.2 bouyer /*
100 1.3.2.2 bouyer * function prototypes
101 1.3.2.2 bouyer */
102 1.3.2.2 bouyer static void ite8181_config_write_4 __P((bus_space_tag_t, bus_space_handle_t, int, int));
103 1.3.2.2 bouyer static int ite8181_config_read_4 __P((bus_space_tag_t, bus_space_handle_t, int));
104 1.3.2.2 bouyer
105 1.3.2.2 bouyer static void ite8181_gui_write_4 __P((struct ite8181_softc *, int, int));
106 1.3.2.2 bouyer static int ite8181_gui_read_4 __P((struct ite8181_softc *, int));
107 1.3.2.2 bouyer
108 1.3.2.2 bouyer static void ite8181_gui_write_1 __P((struct ite8181_softc *, int, int));
109 1.3.2.2 bouyer static int ite8181_gui_read_1 __P((struct ite8181_softc *, int));
110 1.3.2.2 bouyer
111 1.3.2.2 bouyer static void ite8181_graphics_write_1 __P((struct ite8181_softc *, int, int));
112 1.3.2.2 bouyer static int ite8181_graphics_read_1 __P((struct ite8181_softc *, int));
113 1.3.2.2 bouyer
114 1.3.2.2 bouyer static void ite8181_ema_write_1 __P((struct ite8181_softc *, int, int));
115 1.3.2.2 bouyer static int ite8181_ema_read_1 __P((struct ite8181_softc *, int));
116 1.3.2.2 bouyer
117 1.3.2.2 bouyer static void ite8181_power __P((int, void *));
118 1.3.2.2 bouyer static int ite8181_hardpower __P((void *, int, long, void *));
119 1.3.2.2 bouyer static int ite8181_fbinit __P((struct hpcfb_fbconf *));
120 1.3.2.2 bouyer static int ite8181_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
121 1.3.2.2 bouyer static paddr_t ite8181_mmap __P((void *, off_t offset, int));
122 1.3.2.2 bouyer static void ite8181_erase_cursor __P((struct ite8181_softc *));
123 1.3.2.2 bouyer static int ite8181_lcd_power __P((struct ite8181_softc *, int));
124 1.3.2.2 bouyer /*
125 1.3.2.2 bouyer * static variables
126 1.3.2.2 bouyer */
127 1.3.2.2 bouyer struct hpcfb_accessops ite8181_ha = {
128 1.3.2.2 bouyer ite8181_ioctl, ite8181_mmap
129 1.3.2.2 bouyer };
130 1.3.2.2 bouyer
131 1.3.2.2 bouyer inline int
132 1.3.2.2 bouyer ite8181_config_read_4(iot, ioh, byteoffset)
133 1.3.2.2 bouyer bus_space_tag_t iot;
134 1.3.2.2 bouyer bus_space_handle_t ioh;
135 1.3.2.2 bouyer int byteoffset;
136 1.3.2.2 bouyer {
137 1.3.2.2 bouyer return bus_space_read_4(iot, ioh, ITE8181_CONF_OFFSET + byteoffset);
138 1.3.2.2 bouyer }
139 1.3.2.2 bouyer
140 1.3.2.2 bouyer inline void
141 1.3.2.2 bouyer ite8181_config_write_4(iot, ioh, byteoffset, data)
142 1.3.2.2 bouyer bus_space_tag_t iot;
143 1.3.2.2 bouyer bus_space_handle_t ioh;
144 1.3.2.2 bouyer int byteoffset;
145 1.3.2.2 bouyer int data;
146 1.3.2.2 bouyer {
147 1.3.2.2 bouyer bus_space_write_4(iot, ioh, ITE8181_CONF_OFFSET + byteoffset, data);
148 1.3.2.2 bouyer }
149 1.3.2.2 bouyer
150 1.3.2.2 bouyer inline int
151 1.3.2.2 bouyer ite8181_gui_read_4(sc, byteoffset)
152 1.3.2.2 bouyer struct ite8181_softc *sc;
153 1.3.2.2 bouyer int byteoffset;
154 1.3.2.2 bouyer {
155 1.3.2.2 bouyer return bus_space_read_4(sc->sc_iot, sc->sc_ioh,
156 1.3.2.2 bouyer sc->sc_gba + byteoffset);
157 1.3.2.2 bouyer }
158 1.3.2.2 bouyer
159 1.3.2.2 bouyer inline void
160 1.3.2.2 bouyer ite8181_gui_write_4(sc, byteoffset, data)
161 1.3.2.2 bouyer struct ite8181_softc *sc;
162 1.3.2.2 bouyer int byteoffset;
163 1.3.2.2 bouyer int data;
164 1.3.2.2 bouyer {
165 1.3.2.2 bouyer bus_space_write_4(sc->sc_iot, sc->sc_ioh, sc->sc_gba + byteoffset, data);
166 1.3.2.2 bouyer }
167 1.3.2.2 bouyer
168 1.3.2.2 bouyer inline int
169 1.3.2.2 bouyer ite8181_gui_read_1(sc, byteoffset)
170 1.3.2.2 bouyer struct ite8181_softc *sc;
171 1.3.2.2 bouyer int byteoffset;
172 1.3.2.2 bouyer {
173 1.3.2.2 bouyer return bus_space_read_1(sc->sc_iot, sc->sc_ioh,
174 1.3.2.2 bouyer sc->sc_gba + byteoffset);
175 1.3.2.2 bouyer }
176 1.3.2.2 bouyer
177 1.3.2.2 bouyer inline void
178 1.3.2.2 bouyer ite8181_gui_write_1(sc, byteoffset, data)
179 1.3.2.2 bouyer struct ite8181_softc *sc;
180 1.3.2.2 bouyer int byteoffset;
181 1.3.2.2 bouyer int data;
182 1.3.2.2 bouyer {
183 1.3.2.2 bouyer bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->sc_gba + byteoffset, data);
184 1.3.2.2 bouyer }
185 1.3.2.2 bouyer
186 1.3.2.2 bouyer inline int
187 1.3.2.2 bouyer ite8181_graphics_read_1(sc, byteoffset)
188 1.3.2.2 bouyer struct ite8181_softc *sc;
189 1.3.2.2 bouyer int byteoffset;
190 1.3.2.2 bouyer {
191 1.3.2.2 bouyer return bus_space_read_1(sc->sc_iot, sc->sc_ioh,
192 1.3.2.2 bouyer sc->sc_sba + byteoffset);
193 1.3.2.2 bouyer }
194 1.3.2.2 bouyer
195 1.3.2.2 bouyer inline void
196 1.3.2.2 bouyer ite8181_graphics_write_1(sc, byteoffset, data)
197 1.3.2.2 bouyer struct ite8181_softc *sc;
198 1.3.2.2 bouyer int byteoffset;
199 1.3.2.2 bouyer int data;
200 1.3.2.2 bouyer {
201 1.3.2.2 bouyer bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->sc_sba + byteoffset, data);
202 1.3.2.2 bouyer }
203 1.3.2.2 bouyer
204 1.3.2.2 bouyer inline int
205 1.3.2.2 bouyer ite8181_ema_read_1(sc, byteoffset)
206 1.3.2.2 bouyer struct ite8181_softc *sc;
207 1.3.2.2 bouyer int byteoffset;
208 1.3.2.2 bouyer {
209 1.3.2.2 bouyer ite8181_graphics_write_1(sc, ITE8181_EMA_EXAX, byteoffset);
210 1.3.2.2 bouyer return ite8181_graphics_read_1(sc, ITE8181_EMA_EXADATA);
211 1.3.2.2 bouyer }
212 1.3.2.2 bouyer
213 1.3.2.2 bouyer inline void
214 1.3.2.2 bouyer ite8181_ema_write_1(sc, byteoffset, data)
215 1.3.2.2 bouyer struct ite8181_softc *sc;
216 1.3.2.2 bouyer int byteoffset;
217 1.3.2.2 bouyer int data;
218 1.3.2.2 bouyer {
219 1.3.2.2 bouyer ite8181_graphics_write_1(sc, ITE8181_EMA_EXAX, byteoffset);
220 1.3.2.2 bouyer ite8181_graphics_write_1(sc, ITE8181_EMA_EXADATA, data);
221 1.3.2.2 bouyer }
222 1.3.2.2 bouyer
223 1.3.2.2 bouyer int
224 1.3.2.2 bouyer ite8181_probe(iot, ioh)
225 1.3.2.2 bouyer bus_space_tag_t iot;
226 1.3.2.2 bouyer bus_space_handle_t ioh;
227 1.3.2.2 bouyer {
228 1.3.2.2 bouyer unsigned long regval;
229 1.3.2.2 bouyer
230 1.3.2.2 bouyer #if NBIVIDEO > 0
231 1.3.2.2 bouyer if (bivideo_dont_attach) /* some video driver already attached */
232 1.3.2.2 bouyer return (0);
233 1.3.2.2 bouyer #endif /* NBIVIDEO > 0 */
234 1.3.2.2 bouyer
235 1.3.2.2 bouyer regval = ite8181_config_read_4(iot, ioh, ITE8181_ID);
236 1.3.2.2 bouyer VPRINTF(("ite8181_probe: vendor id=%04lx product id=%04lx\n",
237 1.3.2.2 bouyer regval & 0xffff, (regval >> 16) & 0xffff));
238 1.3.2.2 bouyer if (regval != ((ITE8181_PRODUCT_ID << 16) | ITE8181_VENDER_ID))
239 1.3.2.2 bouyer return (0);
240 1.3.2.2 bouyer
241 1.3.2.2 bouyer return (1);
242 1.3.2.2 bouyer }
243 1.3.2.2 bouyer
244 1.3.2.2 bouyer void
245 1.3.2.2 bouyer ite8181_attach(sc)
246 1.3.2.2 bouyer struct ite8181_softc *sc;
247 1.3.2.2 bouyer {
248 1.3.2.2 bouyer unsigned long regval;
249 1.3.2.2 bouyer struct hpcfb_attach_args ha;
250 1.3.2.2 bouyer int console = (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) ? 0 : 1;
251 1.3.2.2 bouyer
252 1.3.2.2 bouyer regval = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_CLASS);
253 1.3.2.2 bouyer printf(": ITE8181 Rev.%02lx\n", regval & ITE8181_REV_MASK);
254 1.3.2.2 bouyer
255 1.3.2.2 bouyer /* set base offsets */
256 1.3.2.2 bouyer sc->sc_mba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_MBA);
257 1.3.2.2 bouyer DPRINTFN(1, ("ite8181: Memory base offset %08x\n", sc->sc_mba));
258 1.3.2.2 bouyer sc->sc_gba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_GBA);
259 1.3.2.2 bouyer DPRINTFN(1, ("ite8181: GUI base offset %08x\n", sc->sc_gba));
260 1.3.2.2 bouyer sc->sc_sba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_SBA);
261 1.3.2.2 bouyer DPRINTFN(1, ("ite8181: Graphics base offset %08x\n", sc->sc_sba));
262 1.3.2.2 bouyer
263 1.3.2.2 bouyer /* assume lcd is on */
264 1.3.2.2 bouyer sc->sc_lcd = 1;
265 1.3.2.2 bouyer
266 1.3.2.2 bouyer /* Add a power hook to power saving */
267 1.3.2.2 bouyer sc->sc_powerstate = ITE8181_POWERSTATE_D0;
268 1.3.2.2 bouyer sc->sc_powerhook = powerhook_establish(ite8181_power, sc);
269 1.3.2.2 bouyer if (sc->sc_powerhook == NULL)
270 1.3.2.2 bouyer printf("%s: WARNING: unable to establish power hook\n",
271 1.3.2.2 bouyer sc->sc_dev.dv_xname);
272 1.3.2.2 bouyer
273 1.3.2.2 bouyer /* Add a hard power hook to power saving */
274 1.3.2.2 bouyer sc->sc_hardpowerhook = config_hook(CONFIG_HOOK_PMEVENT,
275 1.3.2.2 bouyer CONFIG_HOOK_PMEVENT_HARDPOWER,
276 1.3.2.2 bouyer CONFIG_HOOK_SHARE,
277 1.3.2.2 bouyer ite8181_hardpower, sc);
278 1.3.2.2 bouyer if (sc->sc_hardpowerhook == NULL)
279 1.3.2.2 bouyer printf("%s: WARNING: unable to establish hard power hook\n",
280 1.3.2.2 bouyer sc->sc_dev.dv_xname);
281 1.3.2.2 bouyer
282 1.3.2.2 bouyer ite8181_fbinit(&sc->sc_fbconf);
283 1.3.2.2 bouyer
284 1.3.2.2 bouyer ite8181_erase_cursor(sc);
285 1.3.2.2 bouyer
286 1.3.2.2 bouyer if (console && hpcfb_cnattach(&sc->sc_fbconf) != 0) {
287 1.3.2.2 bouyer panic("ite8181_attach: can't init fb console");
288 1.3.2.2 bouyer }
289 1.3.2.2 bouyer
290 1.3.2.2 bouyer ha.ha_console = console;
291 1.3.2.2 bouyer ha.ha_accessops = &ite8181_ha;
292 1.3.2.2 bouyer ha.ha_accessctx = sc;
293 1.3.2.2 bouyer ha.ha_curfbconf = 0;
294 1.3.2.2 bouyer ha.ha_nfbconf = 1;
295 1.3.2.2 bouyer ha.ha_fbconflist = &sc->sc_fbconf;
296 1.3.2.2 bouyer ha.ha_curdspconf = 0;
297 1.3.2.2 bouyer ha.ha_ndspconf = 1;
298 1.3.2.2 bouyer ha.ha_dspconflist = &sc->sc_dspconf;
299 1.3.2.2 bouyer
300 1.3.2.2 bouyer config_found(&sc->sc_dev, &ha, hpcfbprint);
301 1.3.2.2 bouyer
302 1.3.2.2 bouyer #if NBIVIDEO > 0
303 1.3.2.2 bouyer /*
304 1.3.2.2 bouyer * bivideo is no longer need
305 1.3.2.2 bouyer */
306 1.3.2.2 bouyer bivideo_dont_attach = 1;
307 1.3.2.2 bouyer #endif /* NBIVIDEO > 0 */
308 1.3.2.2 bouyer }
309 1.3.2.2 bouyer
310 1.3.2.2 bouyer int ite8181_lcd_power(sc, on)
311 1.3.2.2 bouyer struct ite8181_softc *sc;
312 1.3.2.2 bouyer int on;
313 1.3.2.2 bouyer {
314 1.3.2.2 bouyer int lcd_p;
315 1.3.2.2 bouyer int lcd_s;
316 1.3.2.2 bouyer int lcd_seq;
317 1.3.2.2 bouyer int loop = 10;
318 1.3.2.2 bouyer
319 1.3.2.2 bouyer if (ite8181_lcd_control_disable) {
320 1.3.2.2 bouyer VPRINTF(("ite8171_lcd_control_disable!: %s\n", on?"on":"off"));
321 1.3.2.2 bouyer return 0;
322 1.3.2.2 bouyer }
323 1.3.2.2 bouyer
324 1.3.2.2 bouyer if (sc->sc_lcd != on) {
325 1.3.2.2 bouyer ite8181_ema_write_1(sc, ITE8181_EMA_ENABLEEMA,
326 1.3.2.2 bouyer ITE8181_EMA_ENABLEPASS);
327 1.3.2.2 bouyer lcd_p = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER);
328 1.3.2.2 bouyer lcd_s = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT);
329 1.3.2.2 bouyer lcd_seq = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ);
330 1.3.2.2 bouyer DPRINTFN(1,("ite8181_lcd_power(%d)< p=%x, s=%x, seq=%x\n",
331 1.3.2.2 bouyer on,
332 1.3.2.2 bouyer lcd_p, lcd_s, lcd_seq));
333 1.3.2.2 bouyer if (on) {
334 1.3.2.2 bouyer sc->sc_lcd = 1;
335 1.3.2.2 bouyer lcd_seq |= (ITE8181_PUP0|ITE8181_PUP1|ITE8181_PUP2);
336 1.3.2.2 bouyer ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWERSEQ, lcd_seq);
337 1.3.2.2 bouyer lcd_p &= ~ITE8181_LCDSTANDBY;
338 1.3.2.2 bouyer ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWER, lcd_p);
339 1.3.2.2 bouyer /*
340 1.3.2.2 bouyer * XXX:
341 1.3.2.2 bouyer * IBM WorkPad z50 power unit has too weak power.
342 1.3.2.2 bouyer * So we must wait too many times to access self device
343 1.3.2.2 bouyer * after LCD panel and BackLight on.
344 1.3.2.2 bouyer * Currently delay is not enough ??? FIXME
345 1.3.2.2 bouyer */
346 1.3.2.2 bouyer delay(ite8181_lcd_on_self_delay*MSEC);
347 1.3.2.2 bouyer while (loop--) {
348 1.3.2.2 bouyer lcd_p = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER);
349 1.3.2.2 bouyer lcd_s = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT);
350 1.3.2.2 bouyer lcd_seq = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ);
351 1.3.2.2 bouyer DPRINTFN(1,("ite8181_lcd_power(%d)%d| p=%x, s=%x, seq=%x\n",
352 1.3.2.2 bouyer on, loop,
353 1.3.2.2 bouyer lcd_p, lcd_s, lcd_seq));
354 1.3.2.2 bouyer /* XXX the states which are not described in manual.*/
355 1.3.2.2 bouyer if (!(lcd_s&ITE8181_LCDPSTANDBY) &&
356 1.3.2.2 bouyer !(lcd_s&ITE8181_LCDPUP) &&
357 1.3.2.2 bouyer (lcd_s&ITE8181_LCDPON))
358 1.3.2.2 bouyer break;
359 1.3.2.2 bouyer delay(100);
360 1.3.2.2 bouyer }
361 1.3.2.2 bouyer lcd_s |= ITE8181_PPTOBEON;
362 1.3.2.2 bouyer ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWERSTAT, lcd_s);
363 1.3.2.2 bouyer } else {
364 1.3.2.2 bouyer sc->sc_lcd = 0;
365 1.3.2.2 bouyer lcd_p |= ITE8181_LCDSTANDBY;
366 1.3.2.2 bouyer ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWER, lcd_p);
367 1.3.2.2 bouyer while (loop--) {
368 1.3.2.2 bouyer lcd_p = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER);
369 1.3.2.2 bouyer lcd_s = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT);
370 1.3.2.2 bouyer lcd_seq = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ);
371 1.3.2.2 bouyer DPRINTFN(1,("ite8181_lcd_power(%d)%d| p=%x, s=%x, seq=%x\n",
372 1.3.2.2 bouyer on, loop,
373 1.3.2.2 bouyer lcd_p, lcd_s, lcd_seq));
374 1.3.2.2 bouyer /* XXX the states which are not described in manual.*/
375 1.3.2.2 bouyer if ((lcd_s&ITE8181_LCDPSTANDBY) &&
376 1.3.2.2 bouyer !(lcd_s&ITE8181_LCDPDOWN) &&
377 1.3.2.2 bouyer !(lcd_s&ITE8181_LCDPON))
378 1.3.2.2 bouyer break;
379 1.3.2.2 bouyer delay(100);
380 1.3.2.2 bouyer }
381 1.3.2.2 bouyer lcd_s &= ~ITE8181_PPTOBEON;
382 1.3.2.2 bouyer ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWERSTAT, lcd_s);
383 1.3.2.2 bouyer }
384 1.3.2.2 bouyer DPRINTFN(1,("ite8181_lcd_power(%d)> p=%x, s=%x, seq=%x\n",
385 1.3.2.2 bouyer on,
386 1.3.2.2 bouyer ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER),
387 1.3.2.2 bouyer ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT),
388 1.3.2.2 bouyer ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ)));
389 1.3.2.2 bouyer ite8181_ema_write_1(sc, ITE8181_EMA_ENABLEEMA,
390 1.3.2.2 bouyer ITE8181_EMA_DISABLEPASS);
391 1.3.2.2 bouyer }
392 1.3.2.2 bouyer return 0;
393 1.3.2.2 bouyer }
394 1.3.2.2 bouyer
395 1.3.2.2 bouyer static void
396 1.3.2.2 bouyer ite8181_erase_cursor(sc)
397 1.3.2.2 bouyer struct ite8181_softc *sc;
398 1.3.2.2 bouyer {
399 1.3.2.2 bouyer ite8181_gui_write_1(sc, ITE8181_GUI_C1C, 0); /* Cursor 1 Control Reg. */
400 1.3.2.2 bouyer /* other ? */
401 1.3.2.2 bouyer }
402 1.3.2.2 bouyer
403 1.3.2.2 bouyer static void
404 1.3.2.2 bouyer ite8181_power(why, arg)
405 1.3.2.2 bouyer int why;
406 1.3.2.2 bouyer void *arg;
407 1.3.2.2 bouyer {
408 1.3.2.2 bouyer }
409 1.3.2.2 bouyer
410 1.3.2.2 bouyer static int
411 1.3.2.2 bouyer ite8181_hardpower(ctx, type, id, msg)
412 1.3.2.2 bouyer void *ctx;
413 1.3.2.2 bouyer int type;
414 1.3.2.2 bouyer long id;
415 1.3.2.2 bouyer void *msg;
416 1.3.2.2 bouyer {
417 1.3.2.2 bouyer struct ite8181_softc *sc = ctx;
418 1.3.2.2 bouyer int why = (int)msg;
419 1.3.2.2 bouyer
420 1.3.2.2 bouyer switch (why) {
421 1.3.2.2 bouyer case PWR_STANDBY:
422 1.3.2.2 bouyer sc->sc_powerstate = ITE8181_POWERSTATE_D3;
423 1.3.2.2 bouyer /* ite8181_lcd_power(sc, 0); */
424 1.3.2.2 bouyer delay(MSEC);
425 1.3.2.2 bouyer break;
426 1.3.2.2 bouyer case PWR_SUSPEND:
427 1.3.2.2 bouyer sc->sc_powerstate = ITE8181_POWERSTATE_D2;
428 1.3.2.2 bouyer ite8181_lcd_power(sc, 0);
429 1.3.2.2 bouyer delay(MSEC);
430 1.3.2.2 bouyer break;
431 1.3.2.2 bouyer case PWR_RESUME:
432 1.3.2.2 bouyer delay(MSEC);
433 1.3.2.2 bouyer sc->sc_powerstate = ITE8181_POWERSTATE_D0;
434 1.3.2.2 bouyer ite8181_lcd_power(sc, 1);
435 1.3.2.2 bouyer /*
436 1.3.2.2 bouyer * XXX:
437 1.3.2.2 bouyer * IBM WorkPad z50 power unit has too weak power.
438 1.3.2.2 bouyer * So we must wait too many times to access other devices
439 1.3.2.2 bouyer * after LCD panel and BackLight on.
440 1.3.2.2 bouyer */
441 1.3.2.2 bouyer delay(ite8181_lcd_on_delay*MSEC);
442 1.3.2.2 bouyer break;
443 1.3.2.2 bouyer }
444 1.3.2.2 bouyer
445 1.3.2.2 bouyer /*
446 1.3.2.2 bouyer * you should wait until the
447 1.3.2.2 bouyer * power state transit sequence will end.
448 1.3.2.2 bouyer */
449 1.3.2.2 bouyer
450 1.3.2.2 bouyer return (0);
451 1.3.2.2 bouyer }
452 1.3.2.2 bouyer
453 1.3.2.2 bouyer
454 1.3.2.2 bouyer static int
455 1.3.2.2 bouyer ite8181_fbinit(fb)
456 1.3.2.2 bouyer struct hpcfb_fbconf *fb;
457 1.3.2.2 bouyer {
458 1.3.2.2 bouyer
459 1.3.2.2 bouyer /*
460 1.3.2.2 bouyer * get fb settings from bootinfo
461 1.3.2.2 bouyer */
462 1.3.2.2 bouyer if (bootinfo == NULL ||
463 1.3.2.2 bouyer bootinfo->fb_addr == 0 ||
464 1.3.2.2 bouyer bootinfo->fb_line_bytes == 0 ||
465 1.3.2.2 bouyer bootinfo->fb_width == 0 ||
466 1.3.2.2 bouyer bootinfo->fb_height == 0) {
467 1.3.2.2 bouyer printf("no frame buffer infomation.\n");
468 1.3.2.2 bouyer return (-1);
469 1.3.2.2 bouyer }
470 1.3.2.2 bouyer
471 1.3.2.2 bouyer /* zero fill */
472 1.3.2.2 bouyer bzero(fb, sizeof(*fb));
473 1.3.2.2 bouyer
474 1.3.2.2 bouyer fb->hf_conf_index = 0; /* configuration index */
475 1.3.2.2 bouyer fb->hf_nconfs = 1; /* how many configurations */
476 1.3.2.2 bouyer strcpy(fb->hf_name, "built-in video");
477 1.3.2.2 bouyer /* frame buffer name */
478 1.3.2.2 bouyer strcpy(fb->hf_conf_name, "default");
479 1.3.2.2 bouyer /* configuration name */
480 1.3.2.2 bouyer fb->hf_height = bootinfo->fb_height;
481 1.3.2.2 bouyer fb->hf_width = bootinfo->fb_width;
482 1.3.2.2 bouyer fb->hf_baseaddr = mips_ptob(mips_btop(bootinfo->fb_addr));
483 1.3.2.2 bouyer fb->hf_offset = (u_long)bootinfo->fb_addr - fb->hf_baseaddr;
484 1.3.2.2 bouyer /* frame buffer start offset */
485 1.3.2.2 bouyer fb->hf_bytes_per_line = bootinfo->fb_line_bytes;
486 1.3.2.2 bouyer fb->hf_nplanes = 1;
487 1.3.2.2 bouyer fb->hf_bytes_per_plane = bootinfo->fb_height *
488 1.3.2.2 bouyer bootinfo->fb_line_bytes;
489 1.3.2.2 bouyer
490 1.3.2.2 bouyer fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
491 1.3.2.2 bouyer fb->hf_access_flags |= HPCFB_ACCESS_WORD;
492 1.3.2.2 bouyer fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
493 1.3.2.2 bouyer
494 1.3.2.2 bouyer switch (bootinfo->fb_type) {
495 1.3.2.2 bouyer /*
496 1.3.2.2 bouyer * gray scale
497 1.3.2.2 bouyer */
498 1.3.2.2 bouyer case BIFB_D2_M2L_3:
499 1.3.2.2 bouyer case BIFB_D2_M2L_3x2:
500 1.3.2.2 bouyer fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
501 1.3.2.2 bouyer /* fall through */
502 1.3.2.2 bouyer case BIFB_D2_M2L_0:
503 1.3.2.2 bouyer case BIFB_D2_M2L_0x2:
504 1.3.2.2 bouyer fb->hf_class = HPCFB_CLASS_GRAYSCALE;
505 1.3.2.2 bouyer fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
506 1.3.2.2 bouyer fb->hf_pack_width = 8;
507 1.3.2.2 bouyer fb->hf_pixels_per_pack = 4;
508 1.3.2.2 bouyer fb->hf_pixel_width = 2;
509 1.3.2.2 bouyer fb->hf_class_data_length = sizeof(struct hf_gray_tag);
510 1.3.2.2 bouyer fb->hf_u.hf_gray.hf_flags = 0; /* reserved for future use */
511 1.3.2.2 bouyer break;
512 1.3.2.2 bouyer
513 1.3.2.2 bouyer /*
514 1.3.2.2 bouyer * indexed color
515 1.3.2.2 bouyer */
516 1.3.2.2 bouyer case BIFB_D8_FF:
517 1.3.2.2 bouyer fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
518 1.3.2.2 bouyer /* fall through */
519 1.3.2.2 bouyer case BIFB_D8_00:
520 1.3.2.2 bouyer fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
521 1.3.2.2 bouyer fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
522 1.3.2.2 bouyer fb->hf_pack_width = 8;
523 1.3.2.2 bouyer fb->hf_pixels_per_pack = 1;
524 1.3.2.2 bouyer fb->hf_pixel_width = 8;
525 1.3.2.2 bouyer fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
526 1.3.2.2 bouyer fb->hf_u.hf_indexed.hf_flags = 0; /* reserved for future use */
527 1.3.2.2 bouyer break;
528 1.3.2.2 bouyer
529 1.3.2.2 bouyer /*
530 1.3.2.2 bouyer * RGB color
531 1.3.2.2 bouyer */
532 1.3.2.2 bouyer case BIFB_D16_FFFF:
533 1.3.2.2 bouyer fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
534 1.3.2.2 bouyer /* fall through */
535 1.3.2.2 bouyer case BIFB_D16_0000:
536 1.3.2.2 bouyer fb->hf_class = HPCFB_CLASS_RGBCOLOR;
537 1.3.2.2 bouyer fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
538 1.3.2.2 bouyer #if BYTE_ORDER == LITTLE_ENDIAN
539 1.3.2.2 bouyer fb->hf_swap_flags = HPCFB_SWAP_BYTE;
540 1.3.2.2 bouyer #endif
541 1.3.2.2 bouyer fb->hf_pack_width = 16;
542 1.3.2.2 bouyer fb->hf_pixels_per_pack = 1;
543 1.3.2.2 bouyer fb->hf_pixel_width = 16;
544 1.3.2.2 bouyer
545 1.3.2.2 bouyer fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
546 1.3.2.2 bouyer fb->hf_u.hf_rgb.hf_flags = 0; /* reserved for future use */
547 1.3.2.2 bouyer
548 1.3.2.2 bouyer fb->hf_u.hf_rgb.hf_red_width = 5;
549 1.3.2.2 bouyer fb->hf_u.hf_rgb.hf_red_shift = 11;
550 1.3.2.2 bouyer fb->hf_u.hf_rgb.hf_green_width = 6;
551 1.3.2.2 bouyer fb->hf_u.hf_rgb.hf_green_shift = 5;
552 1.3.2.2 bouyer fb->hf_u.hf_rgb.hf_blue_width = 5;
553 1.3.2.2 bouyer fb->hf_u.hf_rgb.hf_blue_shift = 0;
554 1.3.2.2 bouyer fb->hf_u.hf_rgb.hf_alpha_width = 0;
555 1.3.2.2 bouyer fb->hf_u.hf_rgb.hf_alpha_shift = 0;
556 1.3.2.2 bouyer break;
557 1.3.2.2 bouyer
558 1.3.2.2 bouyer default:
559 1.3.2.2 bouyer printf("unknown type (=%d).\n", bootinfo->fb_type);
560 1.3.2.2 bouyer return (-1);
561 1.3.2.2 bouyer break;
562 1.3.2.2 bouyer }
563 1.3.2.2 bouyer
564 1.3.2.2 bouyer return (0); /* no error */
565 1.3.2.2 bouyer }
566 1.3.2.2 bouyer
567 1.3.2.2 bouyer int
568 1.3.2.2 bouyer ite8181_ioctl(v, cmd, data, flag, p)
569 1.3.2.2 bouyer void *v;
570 1.3.2.2 bouyer u_long cmd;
571 1.3.2.2 bouyer caddr_t data;
572 1.3.2.2 bouyer int flag;
573 1.3.2.2 bouyer struct proc *p;
574 1.3.2.2 bouyer {
575 1.3.2.2 bouyer struct ite8181_softc *sc = (struct ite8181_softc *)v;
576 1.3.2.2 bouyer struct hpcfb_fbconf *fbconf;
577 1.3.2.2 bouyer struct hpcfb_dspconf *dspconf;
578 1.3.2.2 bouyer struct wsdisplay_cmap *cmap;
579 1.3.2.2 bouyer
580 1.3.2.2 bouyer switch (cmd) {
581 1.3.2.2 bouyer case WSDISPLAYIO_GETCMAP:
582 1.3.2.2 bouyer cmap = (struct wsdisplay_cmap*)data;
583 1.3.2.2 bouyer
584 1.3.2.2 bouyer if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
585 1.3.2.2 bouyer sc->sc_fbconf.hf_pack_width != 8 ||
586 1.3.2.2 bouyer 256 <= cmap->index ||
587 1.3.2.2 bouyer 256 < (cmap->index + cmap->count))
588 1.3.2.2 bouyer return (EINVAL);
589 1.3.2.2 bouyer
590 1.3.2.2 bouyer if (!uvm_useracc(cmap->red, cmap->count, B_WRITE) ||
591 1.3.2.2 bouyer !uvm_useracc(cmap->green, cmap->count, B_WRITE) ||
592 1.3.2.2 bouyer !uvm_useracc(cmap->blue, cmap->count, B_WRITE))
593 1.3.2.2 bouyer return (EFAULT);
594 1.3.2.2 bouyer
595 1.3.2.2 bouyer #ifdef ITE8181_WINCE_CMAP
596 1.3.2.2 bouyer copyout(&bivideo_cmap_r[cmap->index], cmap->red, cmap->count);
597 1.3.2.2 bouyer copyout(&bivideo_cmap_g[cmap->index], cmap->green,cmap->count);
598 1.3.2.2 bouyer copyout(&bivideo_cmap_b[cmap->index], cmap->blue, cmap->count);
599 1.3.2.2 bouyer return (0);
600 1.3.2.2 bouyer #else /* ITE8181_WINCE_CMAP */
601 1.3.2.2 bouyer return EINVAL;
602 1.3.2.2 bouyer #endif /* ITE8181_WINCE_CMAP */
603 1.3.2.2 bouyer
604 1.3.2.2 bouyer case WSDISPLAYIO_PUTCMAP:
605 1.3.2.2 bouyer /*
606 1.3.2.2 bouyer * This driver can't set color map.
607 1.3.2.2 bouyer */
608 1.3.2.2 bouyer return (EINVAL);
609 1.3.2.2 bouyer
610 1.3.2.2 bouyer case HPCFBIO_GCONF:
611 1.3.2.2 bouyer fbconf = (struct hpcfb_fbconf *)data;
612 1.3.2.2 bouyer if (fbconf->hf_conf_index != 0 &&
613 1.3.2.2 bouyer fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
614 1.3.2.2 bouyer return (EINVAL);
615 1.3.2.2 bouyer }
616 1.3.2.2 bouyer *fbconf = sc->sc_fbconf; /* structure assignment */
617 1.3.2.2 bouyer return (0);
618 1.3.2.2 bouyer case HPCFBIO_SCONF:
619 1.3.2.2 bouyer fbconf = (struct hpcfb_fbconf *)data;
620 1.3.2.2 bouyer if (fbconf->hf_conf_index != 0 &&
621 1.3.2.2 bouyer fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
622 1.3.2.2 bouyer return (EINVAL);
623 1.3.2.2 bouyer }
624 1.3.2.2 bouyer /*
625 1.3.2.2 bouyer * nothing to do because we have only one configration
626 1.3.2.2 bouyer */
627 1.3.2.2 bouyer return (0);
628 1.3.2.2 bouyer case HPCFBIO_GDSPCONF:
629 1.3.2.2 bouyer dspconf = (struct hpcfb_dspconf *)data;
630 1.3.2.2 bouyer if ((dspconf->hd_unit_index != 0 &&
631 1.3.2.2 bouyer dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
632 1.3.2.2 bouyer (dspconf->hd_conf_index != 0 &&
633 1.3.2.2 bouyer dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
634 1.3.2.2 bouyer return (EINVAL);
635 1.3.2.2 bouyer }
636 1.3.2.2 bouyer *dspconf = sc->sc_dspconf; /* structure assignment */
637 1.3.2.2 bouyer return (0);
638 1.3.2.2 bouyer case HPCFBIO_SDSPCONF:
639 1.3.2.2 bouyer dspconf = (struct hpcfb_dspconf *)data;
640 1.3.2.2 bouyer if ((dspconf->hd_unit_index != 0 &&
641 1.3.2.2 bouyer dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
642 1.3.2.2 bouyer (dspconf->hd_conf_index != 0 &&
643 1.3.2.2 bouyer dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
644 1.3.2.2 bouyer return (EINVAL);
645 1.3.2.2 bouyer }
646 1.3.2.2 bouyer /*
647 1.3.2.2 bouyer * nothing to do
648 1.3.2.2 bouyer * because we have only one unit and one configration
649 1.3.2.2 bouyer */
650 1.3.2.2 bouyer return (0);
651 1.3.2.2 bouyer case HPCFBIO_GOP:
652 1.3.2.2 bouyer case HPCFBIO_SOP:
653 1.3.2.2 bouyer /*
654 1.3.2.2 bouyer * curently not implemented...
655 1.3.2.2 bouyer */
656 1.3.2.2 bouyer return (EINVAL);
657 1.3.2.2 bouyer }
658 1.3.2.2 bouyer
659 1.3.2.2 bouyer return (ENOTTY);
660 1.3.2.2 bouyer }
661 1.3.2.2 bouyer
662 1.3.2.2 bouyer paddr_t
663 1.3.2.2 bouyer ite8181_mmap(ctx, offset, prot)
664 1.3.2.2 bouyer void *ctx;
665 1.3.2.2 bouyer off_t offset;
666 1.3.2.2 bouyer int prot;
667 1.3.2.2 bouyer {
668 1.3.2.2 bouyer struct ite8181_softc *sc = (struct ite8181_softc *)ctx;
669 1.3.2.2 bouyer
670 1.3.2.2 bouyer if (offset < 0 ||
671 1.3.2.2 bouyer (sc->sc_fbconf.hf_bytes_per_plane +
672 1.3.2.2 bouyer sc->sc_fbconf.hf_offset) < offset)
673 1.3.2.2 bouyer return -1;
674 1.3.2.2 bouyer
675 1.3.2.2 bouyer return mips_btop(sc->sc_fbconf.hf_baseaddr + offset);
676 1.3.2.2 bouyer }
677