No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hpcarm / dev / j720lcd.c
blob98def4ae8b81cd5a2d2cb1f5d06c9db4d7e1fbaf
1 /* $NetBSD: j720lcd.c,v 1.4 2008/04/28 20:23:21 martin Exp $ */
3 /*-
4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by IWAMOTO Toshihiro.
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.
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.
32 /* Jornada 720 LCD screen driver. */
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: j720lcd.c,v 1.4 2008/04/28 20:23:21 martin Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 #include <sys/kernel.h>
42 #include <machine/config_hook.h>
43 #include <machine/platid.h>
44 #include <machine/platid_mask.h>
46 #include <arm/sa11x0/sa11x0_var.h>
47 #include <arm/sa11x0/sa11x0_gpioreg.h>
48 #include <arm/sa11x0/sa11x0_ppcreg.h>
49 #include <arm/sa11x0/sa11x0_sspreg.h>
51 #include <hpcarm/dev/j720sspvar.h>
52 #include <hpcarm/dev/sed1356var.h>
54 #ifdef DEBUG
55 #define DPRINTF(arg) aprint_normal arg
56 #else
57 #define DPRINTF(arg) /* nothing */
58 #endif
60 struct j720lcd_softc {
61 device_t sc_dev;
63 struct j720ssp_softc *sc_ssp;
66 static int j720lcd_match(device_t, cfdata_t, void *);
67 static void j720lcd_attach(device_t, device_t, void *);
69 static int j720lcd_param(void *, int, long, void *);
70 int j720lcd_power(void *, int, long, void *);
72 CFATTACH_DECL_NEW(j720lcd, sizeof(struct j720lcd_softc),
73 j720lcd_match, j720lcd_attach, NULL, NULL);
76 static int
77 j720lcd_match(device_t parent, cfdata_t cf, void *aux)
80 if (!platid_match(&platid, &platid_mask_MACH_HP_JORNADA_7XX))
81 return 0;
82 if (strcmp(cf->cf_name, "j720lcd") != 0)
83 return 0;
85 return 1;
88 static void
89 j720lcd_attach(device_t parent, device_t self, void *aux)
91 struct j720lcd_softc *sc = device_private(self);
92 int brightness, contrast;
94 sc->sc_dev = self;
95 sc->sc_ssp = device_private(parent);
97 /* LCD brightness hooks. */
98 config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS,
99 CONFIG_HOOK_SHARE, j720lcd_param, sc);
100 config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS,
101 CONFIG_HOOK_SHARE, j720lcd_param, sc);
102 config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS_MAX,
103 CONFIG_HOOK_SHARE, j720lcd_param, sc);
105 /* LCD contrast hooks. */
106 config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST,
107 CONFIG_HOOK_SHARE, j720lcd_param, sc);
108 config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST,
109 CONFIG_HOOK_SHARE, j720lcd_param, sc);
110 config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST_MAX,
111 CONFIG_HOOK_SHARE, j720lcd_param, sc);
113 /* LCD power hook. */
114 #if 0
115 config_hook(CONFIG_HOOK_POWERCONTROL,
116 CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
117 CONFIG_HOOK_SHARE, j720lcd_power, sc);
118 #endif
120 /* Get default brightness/contrast values. */
121 config_hook_call(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS, &brightness);
122 config_hook_call(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST, &contrast);
124 aprint_normal(": brightness %d, contrast %d\n", brightness, contrast);
127 static int
128 j720lcd_param(void *ctx, int type, long id, void *msg)
130 struct j720lcd_softc *sc = ctx;
131 struct j720ssp_softc *ssp = sc->sc_ssp;
132 uint32_t data[2], len;
133 const int maxval = 255;
134 int i, s;
136 switch (type) {
137 case CONFIG_HOOK_GET:
138 switch (id) {
139 case CONFIG_HOOK_BRIGHTNESS_MAX:
140 case CONFIG_HOOK_CONTRAST_MAX:
141 *(int *)msg = maxval;
142 return 1;
143 case CONFIG_HOOK_BRIGHTNESS:
144 data[0] = 0xd6;
145 data[1] = 0x11;
146 len = 2;
147 break;
148 case CONFIG_HOOK_CONTRAST:
149 data[0] = 0xd4;
150 data[1] = 0x11;
151 len = 2;
152 break;
153 default:
154 return 0;
156 break;
158 case CONFIG_HOOK_SET:
159 switch (id) {
160 case CONFIG_HOOK_BRIGHTNESS:
161 if (*(int *)msg >= 0) {
162 data[0] = 0xd3;
163 data[1] = maxval - *(int *)msg;
164 len = 2;
165 } else {
166 /* XXX hack */
167 data[0] = 0xdf;
168 len = 1;
170 break;
171 case CONFIG_HOOK_CONTRAST:
172 data[0] = 0xd1;
173 data[1] = maxval - *(int *)msg;
174 len = 2;
175 break;
176 default:
177 return 0;
179 break;
181 default:
182 return 0;
185 s = splbio();
186 bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PCR, 0x2000000);
188 for (i = 0; i < len; i++) {
189 if (j720ssp_readwrite(ssp, 1, data[i], &data[i], 500) < 0)
190 goto out;
192 bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PSR, 0x2000000);
193 splx(s);
195 if (type == CONFIG_HOOK_SET)
196 return 1;
198 *(int *)msg = maxval - data[1];
200 return 1;
202 out:
203 bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PSR, 0x2000000);
205 /* reset SSP */
206 bus_space_write_4(ssp->sc_iot, ssp->sc_ssph, SASSP_CR0, 0x307);
207 delay(100);
208 bus_space_write_4(ssp->sc_iot, ssp->sc_ssph, SASSP_CR0, 0x387);
210 splx(s);
212 DPRINTF(("j720lcd_param: error %x %x\n", data[0], data[1]));
213 return 0;
218 j720lcd_power(void *ctx, int type, long id, void *msg)
220 struct sed1356_softc *sc = ctx;
221 struct sa11x0_softc *psc = sc->sc_parent;
222 uint32_t reg;
223 int val;
225 if (type != CONFIG_HOOK_POWERCONTROL ||
226 id != CONFIG_HOOK_POWERCONTROL_LCDLIGHT)
227 return 0;
229 sed1356_init_brightness(sc, 0);
230 sed1356_init_contrast(sc, 0);
232 if (msg) {
233 bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 0);
235 reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
236 reg |= 0x1;
237 bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
238 delay(50000);
240 val = sc->sc_contrast;
241 config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
242 delay(100000);
244 reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
245 reg |= 0x4;
246 bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
248 val = sc->sc_brightness;
249 config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
251 reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
252 reg |= 0x2;
253 bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
254 } else {
255 reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
256 reg &= ~0x2;
257 bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
258 reg &= ~0x4;
259 bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
260 delay(100000);
262 val = -2;
263 config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
265 bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 1);
267 delay(100000);
268 reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
269 reg &= ~0x1;
270 bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
273 return 1;