1 /* $NetBSD: j720lcd.c,v 1.4 2008/04/28 20:23:21 martin Exp $ */
4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
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
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>
55 #define DPRINTF(arg) aprint_normal arg
57 #define DPRINTF(arg) /* nothing */
60 struct j720lcd_softc
{
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
);
77 j720lcd_match(device_t parent
, cfdata_t cf
, void *aux
)
80 if (!platid_match(&platid
, &platid_mask_MACH_HP_JORNADA_7XX
))
82 if (strcmp(cf
->cf_name
, "j720lcd") != 0)
89 j720lcd_attach(device_t parent
, device_t self
, void *aux
)
91 struct j720lcd_softc
*sc
= device_private(self
);
92 int brightness
, contrast
;
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. */
115 config_hook(CONFIG_HOOK_POWERCONTROL
,
116 CONFIG_HOOK_POWERCONTROL_LCDLIGHT
,
117 CONFIG_HOOK_SHARE
, j720lcd_power
, sc
);
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
);
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;
137 case CONFIG_HOOK_GET
:
139 case CONFIG_HOOK_BRIGHTNESS_MAX
:
140 case CONFIG_HOOK_CONTRAST_MAX
:
141 *(int *)msg
= maxval
;
143 case CONFIG_HOOK_BRIGHTNESS
:
148 case CONFIG_HOOK_CONTRAST
:
158 case CONFIG_HOOK_SET
:
160 case CONFIG_HOOK_BRIGHTNESS
:
161 if (*(int *)msg
>= 0) {
163 data
[1] = maxval
- *(int *)msg
;
171 case CONFIG_HOOK_CONTRAST
:
173 data
[1] = maxval
- *(int *)msg
;
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)
192 bus_space_write_4(ssp
->sc_iot
, ssp
->sc_gpioh
, SAGPIO_PSR
, 0x2000000);
195 if (type
== CONFIG_HOOK_SET
)
198 *(int *)msg
= maxval
- data
[1];
203 bus_space_write_4(ssp
->sc_iot
, ssp
->sc_gpioh
, SAGPIO_PSR
, 0x2000000);
206 bus_space_write_4(ssp
->sc_iot
, ssp
->sc_ssph
, SASSP_CR0
, 0x307);
208 bus_space_write_4(ssp
->sc_iot
, ssp
->sc_ssph
, SASSP_CR0
, 0x387);
212 DPRINTF(("j720lcd_param: error %x %x\n", data
[0], data
[1]));
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
;
225 if (type
!= CONFIG_HOOK_POWERCONTROL
||
226 id
!= CONFIG_HOOK_POWERCONTROL_LCDLIGHT
)
229 sed1356_init_brightness(sc
, 0);
230 sed1356_init_contrast(sc
, 0);
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
);
237 bus_space_write_4(psc
->sc_iot
, psc
->sc_ppch
, SAPPC_PSR
, reg
);
240 val
= sc
->sc_contrast
;
241 config_hook_call(CONFIG_HOOK_SET
, CONFIG_HOOK_CONTRAST
, &val
);
244 reg
= bus_space_read_4(psc
->sc_iot
, psc
->sc_ppch
, SAPPC_PSR
);
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
);
253 bus_space_write_4(psc
->sc_iot
, psc
->sc_ppch
, SAPPC_PSR
, reg
);
255 reg
= bus_space_read_4(psc
->sc_iot
, psc
->sc_ppch
, SAPPC_PSR
);
257 bus_space_write_4(psc
->sc_iot
, psc
->sc_ppch
, SAPPC_PSR
, reg
);
259 bus_space_write_4(psc
->sc_iot
, psc
->sc_ppch
, SAPPC_PSR
, reg
);
263 config_hook_call(CONFIG_HOOK_SET
, CONFIG_HOOK_BRIGHTNESS
, &val
);
265 bus_space_write_1(sc
->sc_iot
, sc
->sc_regh
, 0x1f0, 1);
268 reg
= bus_space_read_4(psc
->sc_iot
, psc
->sc_ppch
, SAPPC_PSR
);
270 bus_space_write_4(psc
->sc_iot
, psc
->sc_ppch
, SAPPC_PSR
, reg
);