ipaq_lcd.c revision 1.16.44.1 1 /* $NetBSD: ipaq_lcd.c,v 1.16.44.1 2008/05/16 02:22:27 yamt Exp $ */
2
3 /*
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: ipaq_lcd.c,v 1.16.44.1 2008/05/16 02:22:27 yamt Exp $");
34
35 #define IPAQ_LCD_DEBUG
36
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/time.h>
42 #include <sys/device.h>
43
44 #include <uvm/uvm_extern.h>
45
46 #include <dev/wscons/wsconsio.h>
47
48 #include <machine/bootinfo.h>
49 #include <machine/bus.h>
50 #include <machine/intr.h>
51 #include <arm/cpufunc.h>
52 #include <arm/arm32/katelib.h>
53
54 #include <arm/sa11x0/sa11x0_reg.h>
55 #include <arm/sa11x0/sa11x0_gpioreg.h>
56
57 #include <hpcarm/dev/ipaq_gpioreg.h>
58 #include <hpcarm/dev/ipaq_saipvar.h>
59 #include <hpcarm/dev/ipaq_lcdreg.h>
60 #include <hpcarm/dev/ipaq_lcdvar.h>
61
62 #ifdef IPAQ_LCD_DEBUG
63 #define DPRINTFN(n, x) if (ipaqlcddebug > (n)) printf x
64 int ipaqlcddebug = 0xff;
65 #else
66 #define DPRINTFN(n, x)
67 #endif
68 #define DPRINTF(x) DPRINTFN(0, x)
69
70 static int ipaqlcd_match(struct device *, struct cfdata *, void *);
71 static void ipaqlcd_attach(struct device *, struct device *, void *);
72 static void ipaqlcd_init(struct ipaqlcd_softc *);
73 static int ipaqlcd_fbinit(struct ipaqlcd_softc *);
74 static int ipaqlcd_ioctl(void *, u_long, void *, int, struct lwp *);
75 static paddr_t ipaqlcd_mmap(void *, off_t, int);
76
77 #if defined __mips__ || defined __sh__ || defined __arm__
78 #define __BTOP(x) ((paddr_t)(x) >> PGSHIFT)
79 #define __PTOB(x) ((paddr_t)(x) << PGSHIFT)
80 #else
81 #error "define btop, ptob."
82 #endif
83
84 CFATTACH_DECL(ipaqlcd, sizeof(struct ipaqlcd_softc),
85 ipaqlcd_match, ipaqlcd_attach, NULL, NULL);
86
87 struct hpcfb_accessops ipaqlcd_ha = {
88 ipaqlcd_ioctl, ipaqlcd_mmap
89 };
90 static int console_flag = 0;
91
92 static int
93 ipaqlcd_match(struct device *parent, struct cfdata *match, void *aux)
94 {
95 return (1);
96 }
97
98 void
99 ipaqlcd_attach(struct device *parent, struct device *self, void *aux)
100 {
101 struct ipaqlcd_softc *sc = (struct ipaqlcd_softc*)self;
102 struct hpcfb_attach_args ha;
103 struct ipaq_softc *psc = (struct ipaq_softc *)parent;
104
105 sc->sc_iot = psc->sc_iot;
106 sc->sc_parent = (struct ipaq_softc *)parent;
107
108 ipaqlcd_init(sc);
109 ipaqlcd_fbinit(sc);
110
111 printf("\n");
112 printf("%s: iPAQ internal LCD controller\n", sc->sc_dev.dv_xname);
113
114 DPRINTF(("framebuffer_baseaddr=%lx\n", (u_long)bootinfo->fb_addr));
115
116 ha.ha_console = console_flag;
117 ha.ha_accessops = &ipaqlcd_ha;
118 ha.ha_accessctx = sc;
119 ha.ha_curfbconf = 0;
120 ha.ha_nfbconf = 1;
121 ha.ha_fbconflist = &sc->sc_fbconf;
122 ha.ha_curdspconf = 0;
123 ha.ha_ndspconf = 1;
124 ha.ha_dspconflist = &sc->sc_dspconf;
125
126 config_found(&sc->sc_dev, &ha, hpcfbprint);
127 }
128
129 void
130 ipaqlcd_init(struct ipaqlcd_softc *sc)
131 {
132 /* Initialization of Extended GPIO */
133 sc->sc_parent->ipaq_egpio |= EGPIO_LCD_INIT;
134 bus_space_write_2(sc->sc_iot, sc->sc_parent->sc_egpioh,
135 0, sc->sc_parent->ipaq_egpio);
136
137 if (bus_space_map(sc->sc_iot, SALCD_BASE, SALCD_NPORTS,
138 0, &sc->sc_ioh))
139 panic("ipaqlcd_init:Cannot map registers");
140
141 bootinfo->fb_addr = (void *)
142 bus_space_read_4(sc->sc_iot, sc->sc_ioh, SALCD_BA1);
143
144 /*
145 * Initialize LCD Control Register 0 - 3
146 * must initialize DMA Channel Base Address Register
147 * before enabling LCD(LEN = 1)
148 */
149 bus_space_write_4(sc->sc_iot, sc->sc_ioh,
150 SALCD_CR1, IPAQ_LCCR1);
151 bus_space_write_4(sc->sc_iot, sc->sc_ioh,
152 SALCD_CR2, IPAQ_LCCR2);
153 bus_space_write_4(sc->sc_iot, sc->sc_ioh,
154 SALCD_CR3, IPAQ_LCCR3);
155 bus_space_write_4(sc->sc_iot, sc->sc_ioh,
156 SALCD_CR0, IPAQ_LCCR0);
157
158 DPRINTF(("\n"
159 "DMA_BASE= %08x : DMA_CUR = %08x \n"
160 "LCCR0 = %08x : LCCR1 = %08x \n"
161 "LCCR2 = %08x : LCCR3 = %08x",
162 bus_space_read_4(sc->sc_iot, sc->sc_ioh, SALCD_BA1),
163 bus_space_read_4(sc->sc_iot, sc->sc_ioh, SALCD_CA1),
164 bus_space_read_4(sc->sc_iot, sc->sc_ioh, SALCD_CR0),
165 bus_space_read_4(sc->sc_iot, sc->sc_ioh, SALCD_CR1),
166 bus_space_read_4(sc->sc_iot, sc->sc_ioh, SALCD_CR2),
167 bus_space_read_4(sc->sc_iot, sc->sc_ioh, SALCD_CR3)));
168
169 }
170
171 int
172 ipaqlcd_fbinit(struct ipaqlcd_softc *sc)
173 {
174 struct hpcfb_fbconf *fb;
175
176 fb = &sc->sc_fbconf;
177
178 /* Initialize fb */
179 memset(fb, 0, sizeof(*fb));
180
181 fb->hf_conf_index = 0; /* configuration index */
182 fb->hf_nconfs = 1;
183 strcpy(fb->hf_name, "built-in video");
184 strcpy(fb->hf_conf_name, "LCD");
185 /* configuration name */
186 fb->hf_height = bootinfo->fb_height;
187 fb->hf_width = bootinfo->fb_width;
188
189 if (bus_space_map(sc->sc_iot, (bus_addr_t)bootinfo->fb_addr,
190 bootinfo->fb_height * bootinfo->fb_line_bytes,
191 0, &fb->hf_baseaddr)) {
192 printf("unable to map framebuffer\n");
193 return (-1);
194 }
195
196 fb->hf_offset = (u_long)bootinfo->fb_addr -
197 __PTOB(__BTOP(bootinfo->fb_addr));
198 /* frame buffer start offset */
199 fb->hf_bytes_per_line = bootinfo->fb_line_bytes;
200 fb->hf_nplanes = 1;
201 fb->hf_bytes_per_plane = bootinfo->fb_height *
202 bootinfo->fb_line_bytes;
203
204 fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
205 fb->hf_access_flags |= HPCFB_ACCESS_WORD;
206 fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
207
208 switch (bootinfo->fb_type) {
209 /*
210 * gray scale
211 */
212 case BIFB_D2_M2L_3:
213 case BIFB_D2_M2L_3x2:
214 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
215 case BIFB_D2_M2L_0:
216 case BIFB_D2_M2L_0x2:
217 fb->hf_class = HPCFB_CLASS_GRAYSCALE;
218 break;
219 case BIFB_D4_M2L_F:
220 case BIFB_D4_M2L_Fx2:
221 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
222 case BIFB_D4_M2L_0:
223 case BIFB_D4_M2L_0x2:
224 fb->hf_class = HPCFB_CLASS_GRAYSCALE;
225 break;
226 /*
227 * indexed color
228 */
229 case BIFB_D8_FF:
230 case BIFB_D8_00:
231 fb->hf_offset = 0x200;
232 break;
233 /*
234 * RGB color
235 */
236 case BIFB_D16_FFFF:
237 case BIFB_D16_0000:
238 fb->hf_class = HPCFB_CLASS_RGBCOLOR;
239 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
240 fb->hf_order_flags = HPCFB_REVORDER_BYTE;
241 fb->hf_pack_width = 16;
242 fb->hf_pixels_per_pack = 1;
243 fb->hf_pixel_width = 16;
244
245 fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
246 fb->hf_u.hf_rgb.hf_flags = 0;
247 /* reserved for future use */
248 fb->hf_u.hf_rgb.hf_red_width = 5;
249 fb->hf_u.hf_rgb.hf_red_shift = 11;
250 fb->hf_u.hf_rgb.hf_green_width = 6;
251 fb->hf_u.hf_rgb.hf_green_shift = 5;
252 fb->hf_u.hf_rgb.hf_blue_width = 5;
253 fb->hf_u.hf_rgb.hf_blue_shift = 0;
254 fb->hf_u.hf_rgb.hf_alpha_width = 0;
255 fb->hf_u.hf_rgb.hf_alpha_shift = 0;
256 break;
257 default :
258 printf("unknown type (=%d).\n", bootinfo->fb_type);
259 return (-1);
260 break;
261 }
262
263 return(0);
264 }
265
266 int
267 ipaqlcd_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
268 {
269 struct ipaqlcd_softc *sc = (struct ipaqlcd_softc *)v;
270 struct hpcfb_fbconf *fbconf;
271 struct hpcfb_dspconf *dspconf;
272 struct wsdisplay_cmap *cmap;
273 struct wsdisplay_param *dispparam;
274
275 switch (cmd) {
276 case WSDISPLAYIO_GETCMAP:
277 cmap = (struct wsdisplay_cmap*)data;
278
279 if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
280 sc->sc_fbconf.hf_pack_width != 8 ||
281 256 <= cmap->index ||
282 256 < (cmap->index + cmap->count))
283 return (EINVAL);
284 return (0);
285 case WSDISPLAYIO_PUTCMAP:
286 return (EINVAL);
287 case WSDISPLAYIO_GETPARAM:
288 dispparam = (struct wsdisplay_param*)data;
289 switch (dispparam->param) {
290 case WSDISPLAYIO_PARAM_BACKLIGHT:
291 DPRINTF(("ipaqlcd_ioctl: GETPARAM:BACKLIGHT\n"));
292 return (EINVAL);
293 case WSDISPLAYIO_PARAM_CONTRAST:
294 DPRINTF(("ipaqlcd_ioctl: GETPARAM:CONTRAST\n"));
295 return (EINVAL);
296 case WSDISPLAYIO_PARAM_BRIGHTNESS:
297 DPRINTF(("ipaqlcd_ioctl: GETPARAM:BRIGHTNESS\n"));
298 return (EINVAL);
299 default:
300 return (EINVAL);
301 }
302 return (0);
303 case WSDISPLAYIO_SETPARAM:
304 dispparam = (struct wsdisplay_param*)data;
305 switch (dispparam->param) {
306 case WSDISPLAYIO_PARAM_BACKLIGHT:
307 DPRINTF(("ipaqlcd_ioctl: GETPARAM:BACKLIGHT\n"));
308 return (EINVAL);
309 case WSDISPLAYIO_PARAM_CONTRAST:
310 DPRINTF(("ipaqlcd_ioctl: GETPARAM:CONTRAST\n"));
311 return (EINVAL);
312 case WSDISPLAYIO_PARAM_BRIGHTNESS:
313 DPRINTF(("ipaqlcd_ioctl: GETPARAM:BRIGHTNESS\n"));
314 return (EINVAL);
315 default:
316 return (EINVAL);
317 }
318 return (0);
319
320 case HPCFBIO_GCONF:
321 fbconf = (struct hpcfb_fbconf *)data;
322 if (fbconf->hf_conf_index != 0 &&
323 fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
324 return (EINVAL);
325 }
326 *fbconf = sc->sc_fbconf; /* structure assignment */
327 return (0);
328 case HPCFBIO_SCONF:
329 fbconf = (struct hpcfb_fbconf *)data;
330 if (fbconf->hf_conf_index != 0 &&
331 fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
332 return (EINVAL);
333 }
334 /*
335 * nothing to do because we have only one configuration
336 */
337 return (0);
338 case HPCFBIO_GDSPCONF:
339 dspconf = (struct hpcfb_dspconf *)data;
340 if ((dspconf->hd_unit_index != 0 &&
341 dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
342 (dspconf->hd_conf_index != 0 &&
343 dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
344 return (EINVAL);
345 }
346 *dspconf = sc->sc_dspconf; /* structure assignment */
347 return (0);
348 case HPCFBIO_SDSPCONF:
349 dspconf = (struct hpcfb_dspconf *)data;
350 if ((dspconf->hd_unit_index != 0 &&
351 dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
352 (dspconf->hd_conf_index != 0 &&
353 dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
354 return (EINVAL);
355 }
356 /*
357 * nothing to do
358 * because we have only one unit and one configuration
359 */
360 return (0);
361
362 case HPCFBIO_GOP:
363 case HPCFBIO_SOP:
364 return (EINVAL);
365 }
366 return (EPASSTHROUGH);
367 }
368
369 paddr_t
370 ipaqlcd_mmap(void *ctx, off_t offset, int prot)
371 {
372 struct ipaqlcd_softc *sc = (struct ipaqlcd_softc *)ctx;
373
374 if (offset < 0 ||
375 (sc->sc_fbconf.hf_bytes_per_plane +
376 sc->sc_fbconf.hf_offset) < offset)
377 return -1;
378
379 return __BTOP((u_long)bootinfo->fb_addr + offset);
380 }
381