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