j720lcd.c revision 1.1.8.2 1 1.1.8.2 simonb /* $NetBSD: j720lcd.c,v 1.1.8.2 2006/04/22 11:37:28 simonb Exp $ */
2 1.1.8.2 simonb
3 1.1.8.2 simonb /*-
4 1.1.8.2 simonb * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 1.1.8.2 simonb * All rights reserved.
6 1.1.8.2 simonb *
7 1.1.8.2 simonb * This code is derived from software contributed to The NetBSD Foundation
8 1.1.8.2 simonb * by IWAMOTO Toshihiro.
9 1.1.8.2 simonb *
10 1.1.8.2 simonb * Redistribution and use in source and binary forms, with or without
11 1.1.8.2 simonb * modification, are permitted provided that the following conditions
12 1.1.8.2 simonb * are met:
13 1.1.8.2 simonb * 1. Redistributions of source code must retain the above copyright
14 1.1.8.2 simonb * notice, this list of conditions and the following disclaimer.
15 1.1.8.2 simonb * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.8.2 simonb * notice, this list of conditions and the following disclaimer in the
17 1.1.8.2 simonb * documentation and/or other materials provided with the distribution.
18 1.1.8.2 simonb * 3. All advertising materials mentioning features or use of this software
19 1.1.8.2 simonb * must display the following acknowledgement:
20 1.1.8.2 simonb * This product includes software developed by the NetBSD
21 1.1.8.2 simonb * Foundation, Inc. and its contributors.
22 1.1.8.2 simonb * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.8.2 simonb * contributors may be used to endorse or promote products derived
24 1.1.8.2 simonb * from this software without specific prior written permission.
25 1.1.8.2 simonb *
26 1.1.8.2 simonb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.8.2 simonb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.8.2 simonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.8.2 simonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.8.2 simonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.8.2 simonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.8.2 simonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.8.2 simonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.8.2 simonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.8.2 simonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.8.2 simonb * POSSIBILITY OF SUCH DAMAGE.
37 1.1.8.2 simonb */
38 1.1.8.2 simonb
39 1.1.8.2 simonb /* Jornada 720 LCD screen driver. */
40 1.1.8.2 simonb
41 1.1.8.2 simonb #include <sys/cdefs.h>
42 1.1.8.2 simonb __KERNEL_RCSID(0, "$NetBSD: j720lcd.c,v 1.1.8.2 2006/04/22 11:37:28 simonb Exp $");
43 1.1.8.2 simonb
44 1.1.8.2 simonb #include <sys/param.h>
45 1.1.8.2 simonb #include <sys/systm.h>
46 1.1.8.2 simonb #include <sys/device.h>
47 1.1.8.2 simonb #include <sys/kernel.h>
48 1.1.8.2 simonb
49 1.1.8.2 simonb #include <machine/config_hook.h>
50 1.1.8.2 simonb #include <machine/platid.h>
51 1.1.8.2 simonb #include <machine/platid_mask.h>
52 1.1.8.2 simonb
53 1.1.8.2 simonb #include <arm/sa11x0/sa11x0_var.h>
54 1.1.8.2 simonb #include <arm/sa11x0/sa11x0_gpioreg.h>
55 1.1.8.2 simonb #include <arm/sa11x0/sa11x0_ppcreg.h>
56 1.1.8.2 simonb #include <arm/sa11x0/sa11x0_sspreg.h>
57 1.1.8.2 simonb
58 1.1.8.2 simonb #include <hpcarm/dev/j720sspvar.h>
59 1.1.8.2 simonb #include <hpcarm/dev/sed1356var.h>
60 1.1.8.2 simonb
61 1.1.8.2 simonb #ifdef DEBUG
62 1.1.8.2 simonb #define DPRINTF(arg) printf arg
63 1.1.8.2 simonb #else
64 1.1.8.2 simonb #define DPRINTF(arg) /* nothing */
65 1.1.8.2 simonb #endif
66 1.1.8.2 simonb
67 1.1.8.2 simonb struct j720lcd_softc {
68 1.1.8.2 simonb struct device sc_dev;
69 1.1.8.2 simonb
70 1.1.8.2 simonb struct j720ssp_softc *sc_ssp;
71 1.1.8.2 simonb };
72 1.1.8.2 simonb
73 1.1.8.2 simonb static int j720lcd_match(struct device *, struct cfdata *, void *);
74 1.1.8.2 simonb static void j720lcd_attach(struct device *, struct device *, void *);
75 1.1.8.2 simonb
76 1.1.8.2 simonb static int j720lcd_param(void *, int, long, void *);
77 1.1.8.2 simonb int j720lcd_power(void *, int, long, void *);
78 1.1.8.2 simonb
79 1.1.8.2 simonb CFATTACH_DECL(j720lcd, sizeof(struct j720lcd_softc),
80 1.1.8.2 simonb j720lcd_match, j720lcd_attach, NULL, NULL);
81 1.1.8.2 simonb
82 1.1.8.2 simonb
83 1.1.8.2 simonb static int
84 1.1.8.2 simonb j720lcd_match(struct device *parent, struct cfdata *cf, void *aux)
85 1.1.8.2 simonb {
86 1.1.8.2 simonb
87 1.1.8.2 simonb if (!platid_match(&platid, &platid_mask_MACH_HP_JORNADA_7XX))
88 1.1.8.2 simonb return 0;
89 1.1.8.2 simonb if (strcmp(cf->cf_name, "j720lcd") != 0)
90 1.1.8.2 simonb return 0;
91 1.1.8.2 simonb
92 1.1.8.2 simonb return 1;
93 1.1.8.2 simonb }
94 1.1.8.2 simonb
95 1.1.8.2 simonb static void
96 1.1.8.2 simonb j720lcd_attach(struct device *parent, struct device *self, void *aux)
97 1.1.8.2 simonb {
98 1.1.8.2 simonb struct j720lcd_softc *sc = (struct j720lcd_softc *)self;
99 1.1.8.2 simonb int brightness, contrast;
100 1.1.8.2 simonb
101 1.1.8.2 simonb sc->sc_ssp = (struct j720ssp_softc *)parent;
102 1.1.8.2 simonb
103 1.1.8.2 simonb /* LCD brightness hooks. */
104 1.1.8.2 simonb config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS,
105 1.1.8.2 simonb CONFIG_HOOK_SHARE, j720lcd_param, sc);
106 1.1.8.2 simonb config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS,
107 1.1.8.2 simonb CONFIG_HOOK_SHARE, j720lcd_param, sc);
108 1.1.8.2 simonb config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS_MAX,
109 1.1.8.2 simonb CONFIG_HOOK_SHARE, j720lcd_param, sc);
110 1.1.8.2 simonb
111 1.1.8.2 simonb /* LCD contrast hooks. */
112 1.1.8.2 simonb config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST,
113 1.1.8.2 simonb CONFIG_HOOK_SHARE, j720lcd_param, sc);
114 1.1.8.2 simonb config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST,
115 1.1.8.2 simonb CONFIG_HOOK_SHARE, j720lcd_param, sc);
116 1.1.8.2 simonb config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST_MAX,
117 1.1.8.2 simonb CONFIG_HOOK_SHARE, j720lcd_param, sc);
118 1.1.8.2 simonb
119 1.1.8.2 simonb /* LCD power hook. */
120 1.1.8.2 simonb #if 0
121 1.1.8.2 simonb config_hook(CONFIG_HOOK_POWERCONTROL,
122 1.1.8.2 simonb CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
123 1.1.8.2 simonb CONFIG_HOOK_SHARE, j720lcd_power, sc);
124 1.1.8.2 simonb #endif
125 1.1.8.2 simonb
126 1.1.8.2 simonb /* Get default brightness/contrast values. */
127 1.1.8.2 simonb config_hook_call(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS, &brightness);
128 1.1.8.2 simonb config_hook_call(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST, &contrast);
129 1.1.8.2 simonb
130 1.1.8.2 simonb printf(": brightness %d, contrast %d\n", brightness, contrast);
131 1.1.8.2 simonb }
132 1.1.8.2 simonb
133 1.1.8.2 simonb static int
134 1.1.8.2 simonb j720lcd_param(void *ctx, int type, long id, void *msg)
135 1.1.8.2 simonb {
136 1.1.8.2 simonb struct j720lcd_softc *sc = ctx;
137 1.1.8.2 simonb struct j720ssp_softc *ssp = sc->sc_ssp;
138 1.1.8.2 simonb uint32_t data[2], len;
139 1.1.8.2 simonb int i, s;
140 1.1.8.2 simonb
141 1.1.8.2 simonb switch (type) {
142 1.1.8.2 simonb case CONFIG_HOOK_GET:
143 1.1.8.2 simonb switch (id) {
144 1.1.8.2 simonb case CONFIG_HOOK_BRIGHTNESS_MAX:
145 1.1.8.2 simonb case CONFIG_HOOK_CONTRAST_MAX:
146 1.1.8.2 simonb *(int *)msg = 255;
147 1.1.8.2 simonb return 1;
148 1.1.8.2 simonb case CONFIG_HOOK_BRIGHTNESS:
149 1.1.8.2 simonb data[0] = 0x6b00;
150 1.1.8.2 simonb data[1] = 0x8800;
151 1.1.8.2 simonb len = 2;
152 1.1.8.2 simonb break;
153 1.1.8.2 simonb case CONFIG_HOOK_CONTRAST:
154 1.1.8.2 simonb data[0] = 0x2b00;
155 1.1.8.2 simonb data[1] = 0x8800;
156 1.1.8.2 simonb len = 2;
157 1.1.8.2 simonb break;
158 1.1.8.2 simonb default:
159 1.1.8.2 simonb return 0;
160 1.1.8.2 simonb }
161 1.1.8.2 simonb break;
162 1.1.8.2 simonb
163 1.1.8.2 simonb case CONFIG_HOOK_SET:
164 1.1.8.2 simonb switch (id) {
165 1.1.8.2 simonb case CONFIG_HOOK_BRIGHTNESS:
166 1.1.8.2 simonb if (*(int *)msg >= 0) {
167 1.1.8.2 simonb data[0] = 0xcb00;
168 1.1.8.2 simonb data[1] = *(int *)msg;
169 1.1.8.2 simonb J720SSP_INVERT(data[1]);
170 1.1.8.2 simonb data[1] <<= 8;
171 1.1.8.2 simonb len = 2;
172 1.1.8.2 simonb } else {
173 1.1.8.2 simonb /* XXX hack */
174 1.1.8.2 simonb data[0] = 0xfb00;
175 1.1.8.2 simonb len = 1;
176 1.1.8.2 simonb }
177 1.1.8.2 simonb break;
178 1.1.8.2 simonb case CONFIG_HOOK_CONTRAST:
179 1.1.8.2 simonb data[0] = 0x8b00;
180 1.1.8.2 simonb data[1] = *(int *)msg;
181 1.1.8.2 simonb J720SSP_INVERT(data[1]);
182 1.1.8.2 simonb data[1] <<= 8;
183 1.1.8.2 simonb len = 2;
184 1.1.8.2 simonb break;
185 1.1.8.2 simonb default:
186 1.1.8.2 simonb return 0;
187 1.1.8.2 simonb }
188 1.1.8.2 simonb break;
189 1.1.8.2 simonb
190 1.1.8.2 simonb default:
191 1.1.8.2 simonb return 0;
192 1.1.8.2 simonb }
193 1.1.8.2 simonb
194 1.1.8.2 simonb s = splbio();
195 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PCR, 0x2000000);
196 1.1.8.2 simonb
197 1.1.8.2 simonb for (i = 0; i < len; i++) {
198 1.1.8.2 simonb if (j720ssp_readwrite(ssp, 1, data[i], &data[i], 500) < 0)
199 1.1.8.2 simonb goto out;
200 1.1.8.2 simonb }
201 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PSR, 0x2000000);
202 1.1.8.2 simonb splx(s);
203 1.1.8.2 simonb
204 1.1.8.2 simonb if (type == CONFIG_HOOK_SET)
205 1.1.8.2 simonb return 1;
206 1.1.8.2 simonb
207 1.1.8.2 simonb J720SSP_INVERT(data[1]);
208 1.1.8.2 simonb *(int *)msg = data[1];
209 1.1.8.2 simonb
210 1.1.8.2 simonb return 1;
211 1.1.8.2 simonb
212 1.1.8.2 simonb out:
213 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PSR, 0x2000000);
214 1.1.8.2 simonb
215 1.1.8.2 simonb /* reset SSP */
216 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_ssph, SASSP_CR0, 0x307);
217 1.1.8.2 simonb delay(100);
218 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_ssph, SASSP_CR0, 0x387);
219 1.1.8.2 simonb
220 1.1.8.2 simonb splx(s);
221 1.1.8.2 simonb
222 1.1.8.2 simonb DPRINTF(("j720lcd_param: error %x %x\n", data[0], data[1]));
223 1.1.8.2 simonb return 0;
224 1.1.8.2 simonb
225 1.1.8.2 simonb }
226 1.1.8.2 simonb
227 1.1.8.2 simonb int
228 1.1.8.2 simonb j720lcd_power(void *ctx, int type, long id, void *msg)
229 1.1.8.2 simonb {
230 1.1.8.2 simonb struct sed1356_softc *sc = ctx;
231 1.1.8.2 simonb struct sa11x0_softc *psc = sc->sc_parent;
232 1.1.8.2 simonb uint32_t reg;
233 1.1.8.2 simonb int val;
234 1.1.8.2 simonb
235 1.1.8.2 simonb if (type != CONFIG_HOOK_POWERCONTROL ||
236 1.1.8.2 simonb id != CONFIG_HOOK_POWERCONTROL_LCDLIGHT)
237 1.1.8.2 simonb return 0;
238 1.1.8.2 simonb
239 1.1.8.2 simonb sed1356_init_brightness(sc, 0);
240 1.1.8.2 simonb sed1356_init_contrast(sc, 0);
241 1.1.8.2 simonb
242 1.1.8.2 simonb if (msg) {
243 1.1.8.2 simonb bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 0);
244 1.1.8.2 simonb
245 1.1.8.2 simonb reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
246 1.1.8.2 simonb reg |= 0x1;
247 1.1.8.2 simonb bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
248 1.1.8.2 simonb delay(50000);
249 1.1.8.2 simonb
250 1.1.8.2 simonb val = sc->sc_contrast;
251 1.1.8.2 simonb config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
252 1.1.8.2 simonb delay(100000);
253 1.1.8.2 simonb
254 1.1.8.2 simonb reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
255 1.1.8.2 simonb reg |= 0x4;
256 1.1.8.2 simonb bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
257 1.1.8.2 simonb
258 1.1.8.2 simonb val = sc->sc_brightness;
259 1.1.8.2 simonb config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
260 1.1.8.2 simonb
261 1.1.8.2 simonb reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
262 1.1.8.2 simonb reg |= 0x2;
263 1.1.8.2 simonb bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
264 1.1.8.2 simonb } else {
265 1.1.8.2 simonb reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
266 1.1.8.2 simonb reg &= ~0x2;
267 1.1.8.2 simonb bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
268 1.1.8.2 simonb reg &= ~0x4;
269 1.1.8.2 simonb bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
270 1.1.8.2 simonb delay(100000);
271 1.1.8.2 simonb
272 1.1.8.2 simonb val = -2;
273 1.1.8.2 simonb config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
274 1.1.8.2 simonb
275 1.1.8.2 simonb bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 1);
276 1.1.8.2 simonb
277 1.1.8.2 simonb delay(100000);
278 1.1.8.2 simonb reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
279 1.1.8.2 simonb reg &= ~0x1;
280 1.1.8.2 simonb bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
281 1.1.8.2 simonb }
282 1.1.8.2 simonb
283 1.1.8.2 simonb return 1;
284 1.1.8.2 simonb }
285