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