Home | History | Annotate | Line # | Download | only in dev
zlcd.c revision 1.5.4.1
      1  1.5.4.1       mjf /*	$NetBSD: zlcd.c,v 1.5.4.1 2007/07/11 20:03:41 mjf Exp $	*/
      2      1.1      ober /*	$OpenBSD: zaurus_lcd.c,v 1.20 2006/06/02 20:50:14 miod Exp $	*/
      3      1.1      ober /* NetBSD: lubbock_lcd.c,v 1.1 2003/08/09 19:38:53 bsh Exp */
      4      1.1      ober 
      5      1.1      ober /*
      6      1.1      ober  * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
      7      1.1      ober  * Written by Hiroyuki Bessho for Genetec Corporation.
      8      1.1      ober  *
      9      1.1      ober  * Redistribution and use in source and binary forms, with or without
     10      1.1      ober  * modification, are permitted provided that the following conditions
     11      1.1      ober  * are met:
     12      1.1      ober  * 1. Redistributions of source code must retain the above copyright
     13      1.1      ober  *    notice, this list of conditions and the following disclaimer.
     14      1.1      ober  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1      ober  *    notice, this list of conditions and the following disclaimer in the
     16      1.1      ober  *    documentation and/or other materials provided with the distribution.
     17      1.1      ober  * 3. The name of Genetec Corporation may not be used to endorse or
     18      1.1      ober  *    promote products derived from this software without specific prior
     19      1.1      ober  *    written permission.
     20      1.1      ober  *
     21      1.1      ober  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     22      1.1      ober  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23      1.1      ober  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24      1.1      ober  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     25      1.1      ober  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26      1.1      ober  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27      1.1      ober  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28      1.1      ober  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29      1.1      ober  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30      1.1      ober  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31      1.1      ober  * POSSIBILITY OF SUCH DAMAGE.
     32      1.1      ober  */
     33      1.1      ober 
     34      1.1      ober /*
     35      1.1      ober  * LCD driver for Sharp Zaurus (based on the Intel Lubbock driver).
     36      1.1      ober  *
     37      1.1      ober  * Controlling LCD is almost completely done through PXA2X0's
     38      1.1      ober  * integrated LCD controller.  Codes for it is arm/xscale/pxa2x0_lcd.c.
     39      1.1      ober  *
     40      1.1      ober  * Codes in this file provide platform specific things including:
     41      1.1      ober  *   LCD on/off switch and backlight brightness
     42      1.1      ober  *   LCD panel geometry
     43      1.1      ober  */
     44      1.1      ober 
     45      1.1      ober #include <sys/cdefs.h>
     46  1.5.4.1       mjf __KERNEL_RCSID(0, "$NetBSD: zlcd.c,v 1.5.4.1 2007/07/11 20:03:41 mjf Exp $");
     47      1.1      ober 
     48      1.1      ober #include <sys/param.h>
     49      1.1      ober #include <sys/systm.h>
     50      1.1      ober #include <sys/conf.h>
     51      1.1      ober #include <sys/uio.h>
     52      1.1      ober #include <sys/malloc.h>
     53      1.1      ober 
     54      1.1      ober #include <dev/cons.h>
     55      1.1      ober #include <dev/wscons/wsconsio.h>
     56      1.1      ober #include <dev/wscons/wsdisplayvar.h>
     57      1.1      ober #include <dev/wscons/wscons_callbacks.h>
     58      1.1      ober 
     59  1.5.4.1       mjf #include <dev/hpc/hpcfbio.h>
     60  1.5.4.1       mjf 
     61      1.1      ober #include <machine/bus.h>
     62      1.1      ober #include <arm/xscale/pxa2x0var.h>
     63      1.1      ober #include <arm/xscale/pxa2x0reg.h>
     64      1.1      ober #include <arm/xscale/pxa2x0_lcd.h>
     65      1.1      ober 
     66      1.1      ober #include <zaurus/dev/scoopvar.h>
     67      1.1      ober #include <zaurus/dev/zsspvar.h>
     68      1.1      ober #include <zaurus/zaurus/zaurus_var.h>
     69      1.1      ober 
     70      1.1      ober /*
     71      1.1      ober  * wsdisplay glue
     72      1.1      ober  */
     73      1.2     peter static struct pxa2x0_wsscreen_descr lcd_std_screen = {
     74      1.2     peter 	.c = {
     75      1.2     peter 		.name = "std",
     76      1.2     peter 		.textops = &pxa2x0_lcd_emulops,
     77      1.2     peter 		.fontwidth = 8,
     78      1.2     peter 		.fontheight = 16,
     79      1.2     peter 		.capabilities = WSSCREEN_WSCOLORS,
     80      1.1      ober 	},
     81      1.2     peter 	.depth = 16,			/* bits per pixel */
     82      1.4      ober 	.flags = RI_ROTATE_CW,		/* quarter clockwise rotation */
     83      1.1      ober };
     84      1.1      ober 
     85      1.1      ober static const struct wsscreen_descr *lcd_scr_descr[] = {
     86      1.2     peter 	&lcd_std_screen.c
     87      1.1      ober };
     88      1.1      ober 
     89      1.2     peter static const struct wsscreen_list lcd_screen_list = {
     90      1.2     peter 	.nscreens = __arraycount(lcd_scr_descr),
     91      1.2     peter 	.screens = lcd_scr_descr,
     92      1.1      ober };
     93      1.1      ober 
     94      1.5  christos static int	lcd_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     95      1.2     peter static int	lcd_param(struct pxa2x0_lcd_softc *, u_long,
     96      1.2     peter 		    struct wsdisplay_param *);
     97      1.2     peter static int	lcd_show_screen(void *, void *, int,
     98      1.2     peter 		    void (*)(void *, int, int), void *);
     99      1.1      ober 
    100      1.2     peter struct wsdisplay_accessops lcd_accessops = {
    101      1.1      ober 	lcd_ioctl,
    102      1.1      ober 	pxa2x0_lcd_mmap,
    103      1.1      ober 	pxa2x0_lcd_alloc_screen,
    104      1.1      ober 	pxa2x0_lcd_free_screen,
    105      1.1      ober 	lcd_show_screen,
    106      1.2     peter 	NULL,
    107      1.2     peter 	NULL,
    108      1.2     peter 	NULL,
    109      1.1      ober };
    110      1.1      ober 
    111      1.1      ober #define CURRENT_DISPLAY &sharp_zaurus_C3000
    112      1.1      ober 
    113      1.1      ober const struct lcd_panel_geometry sharp_zaurus_C3000 =
    114      1.1      ober {
    115      1.1      ober 	480,			/* Width */
    116      1.1      ober 	640,			/* Height */
    117      1.1      ober 	0,			/* No extra lines */
    118      1.1      ober 
    119      1.1      ober 	LCDPANEL_ACTIVE | LCDPANEL_VSP | LCDPANEL_HSP,
    120      1.1      ober 	1,			/* clock divider */
    121      1.1      ober 	0,			/* AC bias pin freq */
    122      1.1      ober 
    123      1.1      ober 	0x28,			/* horizontal sync pulse width */
    124      1.1      ober 	0x2e,			/* BLW */
    125      1.1      ober 	0x7d,			/* ELW */
    126      1.1      ober 
    127      1.1      ober 	2,			/* vertical sync pulse width */
    128      1.1      ober 	1,			/* BFW */
    129      1.1      ober 	0,			/* EFW */
    130      1.1      ober };
    131      1.1      ober 
    132      1.1      ober struct sharp_lcd_backlight {
    133      1.1      ober 	int	duty;		/* LZ9JG18 DAC value */
    134      1.1      ober 	int	cont;		/* BACKLIGHT_CONT signal */
    135      1.1      ober 	int	on;		/* BACKLIGHT_ON signal */
    136      1.1      ober };
    137      1.1      ober 
    138      1.1      ober #define CURRENT_BACKLIGHT sharp_zaurus_C3000_bl
    139      1.1      ober 
    140      1.1      ober const struct sharp_lcd_backlight sharp_zaurus_C3000_bl[] = {
    141      1.2     peter 	{ 0x00, 0,  0 },	/* 0:     Off */
    142      1.2     peter 	{ 0x00, 0,  1 },	/* 1:      0% */
    143      1.2     peter 	{ 0x01, 0,  1 },	/* 2:     20% */
    144      1.2     peter 	{ 0x07, 0,  1 },	/* 3:     40% */
    145      1.2     peter 	{ 0x01, 1,  1 },	/* 4:     60% */
    146      1.2     peter 	{ 0x07, 1,  1 },	/* 5:     80% */
    147      1.2     peter 	{ 0x11, 1,  1 },	/* 6:    100% */
    148      1.2     peter 	{  -1, -1, -1 },	/* 7: Invalid */
    149      1.1      ober };
    150      1.1      ober 
    151      1.1      ober static int	lcd_match(struct device *, struct cfdata *, void *);
    152      1.1      ober static void	lcd_attach(struct device *, struct device *, void *);
    153      1.1      ober 
    154      1.1      ober CFATTACH_DECL(zlcd, sizeof(struct pxa2x0_lcd_softc),
    155      1.1      ober 	lcd_match, lcd_attach, NULL, NULL);
    156      1.1      ober 
    157      1.3    nonaka void	lcd_cnattach(void);
    158      1.1      ober int	lcd_max_brightness(void);
    159      1.1      ober int	lcd_get_brightness(void);
    160      1.1      ober void	lcd_set_brightness(int);
    161      1.1      ober void	lcd_set_brightness_internal(int);
    162      1.1      ober int	lcd_get_backlight(void);
    163      1.1      ober void	lcd_set_backlight(int);
    164      1.1      ober void	lcd_blank(int);
    165      1.1      ober void	lcd_power(int, void *);
    166      1.1      ober 
    167      1.1      ober static int
    168      1.1      ober lcd_match(struct device *parent, struct cfdata *cf, void *aux)
    169      1.1      ober {
    170      1.1      ober 
    171      1.1      ober 	return 1;
    172      1.1      ober }
    173      1.1      ober 
    174      1.1      ober static void
    175      1.1      ober lcd_attach(struct device *parent, struct device *self, void *aux)
    176      1.1      ober {
    177      1.1      ober 	struct pxa2x0_lcd_softc *sc = (struct pxa2x0_lcd_softc *)self;
    178      1.1      ober 	struct wsemuldisplaydev_attach_args aa;
    179      1.1      ober 
    180      1.3    nonaka 	pxa2x0_lcd_attach_sub(sc, aux, CURRENT_DISPLAY);
    181      1.1      ober 
    182      1.1      ober 	aa.console = glass_console;
    183      1.1      ober 	aa.scrdata = &lcd_screen_list;
    184      1.1      ober 	aa.accessops = &lcd_accessops;
    185      1.1      ober 	aa.accesscookie = sc;
    186      1.1      ober 
    187      1.2     peter 	(void) config_found(self, &aa, wsemuldisplaydevprint);
    188      1.1      ober 
    189      1.1      ober 	/* Start with approximately 40% of full brightness. */
    190      1.1      ober 	lcd_set_brightness(3);
    191      1.1      ober 
    192      1.2     peter 	(void) powerhook_establish(sc->dev.dv_xname, lcd_power, sc);
    193      1.1      ober }
    194      1.1      ober 
    195      1.3    nonaka void
    196      1.3    nonaka lcd_cnattach(void)
    197      1.3    nonaka {
    198      1.3    nonaka 
    199      1.3    nonaka 	pxa2x0_lcd_cnattach(&lcd_std_screen, CURRENT_DISPLAY);
    200      1.3    nonaka }
    201      1.3    nonaka 
    202      1.1      ober /*
    203      1.1      ober  * wsdisplay accessops overrides
    204      1.1      ober  */
    205      1.2     peter static int
    206      1.5  christos lcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    207      1.1      ober {
    208      1.1      ober 	struct pxa2x0_lcd_softc *sc = (struct pxa2x0_lcd_softc *)v;
    209  1.5.4.1       mjf 	struct hpcfb_fbconf *fbconf;
    210  1.5.4.1       mjf 	struct hpcfb_dspconf *dspconf;
    211      1.1      ober 	int res = EINVAL;
    212      1.1      ober 
    213      1.1      ober 	switch (cmd) {
    214      1.1      ober 	case WSDISPLAYIO_GETPARAM:
    215      1.1      ober 	case WSDISPLAYIO_SETPARAM:
    216      1.1      ober 		res = lcd_param(sc, cmd, (struct wsdisplay_param *)data);
    217      1.1      ober 		break;
    218  1.5.4.1       mjf 
    219  1.5.4.1       mjf 	case HPCFBIO_GCONF:
    220  1.5.4.1       mjf 		fbconf = (struct hpcfb_fbconf *)data;
    221  1.5.4.1       mjf 		if (fbconf->hf_conf_index != 0 &&
    222  1.5.4.1       mjf 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    223  1.5.4.1       mjf 			break;
    224  1.5.4.1       mjf 		}
    225  1.5.4.1       mjf 
    226  1.5.4.1       mjf 		fbconf->hf_conf_index = 0;
    227  1.5.4.1       mjf 		fbconf->hf_nconfs = 1;
    228  1.5.4.1       mjf 		fbconf->hf_class = HPCFB_CLASS_RGBCOLOR;
    229  1.5.4.1       mjf 		strlcpy(fbconf->hf_name, "Sharp Zaurus frame buffer",
    230  1.5.4.1       mjf 		    sizeof(fbconf->hf_name));
    231  1.5.4.1       mjf 		strlcpy(fbconf->hf_conf_name, "default",
    232  1.5.4.1       mjf 		    sizeof(fbconf->hf_conf_name));
    233  1.5.4.1       mjf 		fbconf->hf_width = sc->geometry->panel_width;
    234  1.5.4.1       mjf 		fbconf->hf_height = sc->geometry->panel_height;
    235  1.5.4.1       mjf 		fbconf->hf_baseaddr = (u_long)sc->active->buf_va;
    236  1.5.4.1       mjf 		fbconf->hf_offset = 0;
    237  1.5.4.1       mjf 		fbconf->hf_bytes_per_line = sc->geometry->panel_width *
    238  1.5.4.1       mjf 		    sc->active->depth / 8;
    239  1.5.4.1       mjf 		fbconf->hf_nplanes = 1;
    240  1.5.4.1       mjf 		fbconf->hf_bytes_per_plane = sc->geometry->panel_width *
    241  1.5.4.1       mjf 		    sc->geometry->panel_height * sc->active->depth / 8;
    242  1.5.4.1       mjf 		fbconf->hf_pack_width = sc->active->depth;
    243  1.5.4.1       mjf 		fbconf->hf_pixels_per_pack = 1;
    244  1.5.4.1       mjf 		fbconf->hf_pixel_width = sc->active->depth;
    245  1.5.4.1       mjf 		fbconf->hf_access_flags = (0
    246  1.5.4.1       mjf 					   | HPCFB_ACCESS_BYTE
    247  1.5.4.1       mjf 					   | HPCFB_ACCESS_WORD
    248  1.5.4.1       mjf 					   | HPCFB_ACCESS_DWORD);
    249  1.5.4.1       mjf 		fbconf->hf_order_flags = 0;
    250  1.5.4.1       mjf 		fbconf->hf_reg_offset = 0;
    251  1.5.4.1       mjf 
    252  1.5.4.1       mjf 		fbconf->hf_class_data_length = sizeof(struct hf_rgb_tag);
    253  1.5.4.1       mjf 		fbconf->hf_u.hf_rgb.hf_flags = 0;
    254  1.5.4.1       mjf 		fbconf->hf_u.hf_rgb.hf_red_width = 5;
    255  1.5.4.1       mjf 		fbconf->hf_u.hf_rgb.hf_red_shift = 11;
    256  1.5.4.1       mjf 		fbconf->hf_u.hf_rgb.hf_green_width = 6;
    257  1.5.4.1       mjf 		fbconf->hf_u.hf_rgb.hf_green_shift = 5;
    258  1.5.4.1       mjf 		fbconf->hf_u.hf_rgb.hf_blue_width = 5;
    259  1.5.4.1       mjf 		fbconf->hf_u.hf_rgb.hf_blue_shift = 0;
    260  1.5.4.1       mjf 		fbconf->hf_u.hf_rgb.hf_alpha_width = 0;
    261  1.5.4.1       mjf 		fbconf->hf_u.hf_rgb.hf_alpha_shift = 0;
    262  1.5.4.1       mjf 
    263  1.5.4.1       mjf 		fbconf->hf_ext_size = 0;
    264  1.5.4.1       mjf 		fbconf->hf_ext_data = NULL;
    265  1.5.4.1       mjf 
    266  1.5.4.1       mjf 		res = 0;
    267  1.5.4.1       mjf 		break;
    268  1.5.4.1       mjf 
    269  1.5.4.1       mjf 	case HPCFBIO_SCONF:
    270  1.5.4.1       mjf 		fbconf = (struct hpcfb_fbconf *)data;
    271  1.5.4.1       mjf 		if (fbconf->hf_conf_index != 0 &&
    272  1.5.4.1       mjf 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    273  1.5.4.1       mjf 			break;
    274  1.5.4.1       mjf 		}
    275  1.5.4.1       mjf 		/* nothing to do because we have only one configuration */
    276  1.5.4.1       mjf 		res = 0;
    277  1.5.4.1       mjf 		break;
    278  1.5.4.1       mjf 
    279  1.5.4.1       mjf 	case HPCFBIO_GDSPCONF:
    280  1.5.4.1       mjf 		dspconf = (struct hpcfb_dspconf *)data;
    281  1.5.4.1       mjf 		if ((dspconf->hd_unit_index != 0 &&
    282  1.5.4.1       mjf 		     dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    283  1.5.4.1       mjf 		    (dspconf->hd_conf_index != 0 &&
    284  1.5.4.1       mjf 		     dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    285  1.5.4.1       mjf 			break;
    286  1.5.4.1       mjf 		}
    287  1.5.4.1       mjf 
    288  1.5.4.1       mjf 		dspconf->hd_unit_index = 0;
    289  1.5.4.1       mjf 		dspconf->hd_nunits = 1;
    290  1.5.4.1       mjf 		dspconf->hd_class = HPCFB_DSP_CLASS_COLORLCD;
    291  1.5.4.1       mjf 		strlcpy(dspconf->hd_name, "Sharp Zaurus LCD",
    292  1.5.4.1       mjf 		    sizeof(dspconf->hd_name));
    293  1.5.4.1       mjf 		dspconf->hd_op_flags = 0;
    294  1.5.4.1       mjf 		dspconf->hd_conf_index = 0;
    295  1.5.4.1       mjf 		dspconf->hd_nconfs = 1;
    296  1.5.4.1       mjf 		strlcpy(dspconf->hd_conf_name, "default",
    297  1.5.4.1       mjf 		    sizeof(dspconf->hd_conf_name));
    298  1.5.4.1       mjf 		dspconf->hd_width = sc->geometry->panel_width;
    299  1.5.4.1       mjf 		dspconf->hd_height = sc->geometry->panel_height;
    300  1.5.4.1       mjf 		dspconf->hd_xdpi = HPCFB_DSP_DPI_UNKNOWN;
    301  1.5.4.1       mjf 		dspconf->hd_ydpi = HPCFB_DSP_DPI_UNKNOWN;
    302  1.5.4.1       mjf 
    303  1.5.4.1       mjf 		res = 0;
    304  1.5.4.1       mjf 		break;
    305  1.5.4.1       mjf 
    306  1.5.4.1       mjf 	case HPCFBIO_SDSPCONF:
    307  1.5.4.1       mjf 		dspconf = (struct hpcfb_dspconf *)data;
    308  1.5.4.1       mjf 		if ((dspconf->hd_unit_index != 0 &&
    309  1.5.4.1       mjf 		     dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    310  1.5.4.1       mjf 		    (dspconf->hd_conf_index != 0 &&
    311  1.5.4.1       mjf 		     dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    312  1.5.4.1       mjf 			break;
    313  1.5.4.1       mjf 		}
    314  1.5.4.1       mjf 		/*
    315  1.5.4.1       mjf 		 * nothing to do
    316  1.5.4.1       mjf 		 * because we have only one unit and one configuration
    317  1.5.4.1       mjf 		 */
    318  1.5.4.1       mjf 		res = 0;
    319  1.5.4.1       mjf 		break;
    320  1.5.4.1       mjf 
    321  1.5.4.1       mjf 	case HPCFBIO_GOP:
    322  1.5.4.1       mjf 	case HPCFBIO_SOP:
    323  1.5.4.1       mjf 		/* curently not implemented...  */
    324  1.5.4.1       mjf 		break;
    325      1.1      ober 	}
    326      1.1      ober 
    327      1.1      ober 	if (res == EINVAL)
    328      1.1      ober 		res = pxa2x0_lcd_ioctl(v, vs, cmd, data, flag, l);
    329      1.1      ober 	return res;
    330      1.1      ober }
    331      1.1      ober 
    332      1.2     peter static int
    333      1.1      ober lcd_show_screen(void *v, void *cookie, int waitok,
    334      1.2     peter     void (*cb_func)(void *, int, int), void *cb_arg)
    335      1.1      ober {
    336      1.1      ober 	int error;
    337      1.1      ober 
    338      1.2     peter 	error = pxa2x0_lcd_show_screen(v, cookie, waitok, cb_func, cb_arg);
    339      1.1      ober 	if (error)
    340      1.1      ober 		return (error);
    341      1.1      ober 
    342      1.1      ober 	/* Turn on LCD */
    343      1.2     peter 	lcd_set_brightness(lcd_get_brightness());
    344      1.1      ober 
    345      1.1      ober 	return 0;
    346      1.1      ober }
    347      1.1      ober 
    348      1.1      ober /*
    349      1.1      ober  * wsdisplay I/O controls
    350      1.1      ober  */
    351      1.2     peter static int
    352  1.5.4.1       mjf lcd_param(struct pxa2x0_lcd_softc *sc, u_long cmd, struct wsdisplay_param *dp)
    353      1.1      ober {
    354      1.1      ober 	int res = EINVAL;
    355      1.1      ober 
    356      1.1      ober 	switch (dp->param) {
    357      1.1      ober 	case WSDISPLAYIO_PARAM_BACKLIGHT:
    358      1.1      ober 		if (cmd == WSDISPLAYIO_GETPARAM) {
    359      1.1      ober 			dp->min = 0;
    360      1.1      ober 			dp->max = 1;
    361      1.1      ober 			dp->curval = lcd_get_backlight();
    362      1.1      ober 			res = 0;
    363      1.1      ober 		} else if (cmd == WSDISPLAYIO_SETPARAM) {
    364      1.1      ober 			lcd_set_backlight(dp->curval);
    365      1.1      ober 			res = 0;
    366      1.1      ober 		}
    367      1.1      ober 		break;
    368      1.1      ober 
    369      1.1      ober 	case WSDISPLAYIO_PARAM_CONTRAST:
    370      1.1      ober 		/* unsupported */
    371      1.1      ober 		res = ENOTTY;
    372      1.1      ober 		break;
    373      1.1      ober 
    374      1.1      ober 	case WSDISPLAYIO_PARAM_BRIGHTNESS:
    375      1.1      ober 		if (cmd == WSDISPLAYIO_GETPARAM) {
    376      1.1      ober 			dp->min = 1;
    377      1.1      ober 			dp->max = lcd_max_brightness();
    378      1.1      ober 			dp->curval = lcd_get_brightness();
    379      1.1      ober 			res = 0;
    380      1.1      ober 		} else if (cmd == WSDISPLAYIO_SETPARAM) {
    381      1.1      ober 			lcd_set_brightness(dp->curval);
    382      1.1      ober 			res = 0;
    383      1.1      ober 		}
    384      1.1      ober 		break;
    385      1.1      ober 	}
    386      1.1      ober 
    387      1.1      ober 	return res;
    388      1.1      ober }
    389      1.1      ober 
    390      1.1      ober /*
    391      1.1      ober  * LCD backlight
    392      1.1      ober  */
    393      1.1      ober 
    394      1.1      ober static	int lcdbrightnesscurval = 1;
    395      1.1      ober static	int lcdislit = 1;
    396      1.1      ober static	int lcdisblank = 0;
    397      1.1      ober 
    398      1.1      ober int
    399      1.1      ober lcd_max_brightness(void)
    400      1.1      ober {
    401      1.1      ober 	int i;
    402      1.1      ober 
    403      1.1      ober 	for (i = 0; CURRENT_BACKLIGHT[i].duty != -1; i++)
    404      1.1      ober 		continue;
    405      1.1      ober 	return i - 1;
    406      1.1      ober }
    407      1.1      ober 
    408      1.1      ober int
    409      1.1      ober lcd_get_brightness(void)
    410      1.1      ober {
    411      1.1      ober 
    412      1.1      ober 	return lcdbrightnesscurval;
    413      1.1      ober }
    414      1.1      ober 
    415      1.1      ober void
    416      1.1      ober lcd_set_brightness(int newval)
    417      1.1      ober {
    418      1.1      ober 	int maxval;
    419      1.1      ober 
    420      1.1      ober 	maxval = lcd_max_brightness();
    421      1.1      ober 	if (newval < 0)
    422      1.1      ober 		newval = 0;
    423      1.1      ober 	else if (newval > maxval)
    424      1.1      ober 		newval = maxval;
    425      1.1      ober 
    426      1.1      ober 	if (lcd_get_backlight() && !lcdisblank)
    427      1.1      ober 		lcd_set_brightness_internal(newval);
    428      1.1      ober 
    429      1.1      ober 	if (newval > 0)
    430      1.1      ober 		lcdbrightnesscurval = newval;
    431      1.1      ober }
    432      1.1      ober 
    433      1.1      ober void
    434      1.1      ober lcd_set_brightness_internal(int newval)
    435      1.1      ober {
    436      1.1      ober 	static int curval = 1;
    437      1.1      ober 	int i;
    438      1.1      ober 
    439      1.1      ober 	/*
    440      1.1      ober 	 * It appears that the C3000 backlight can draw too much power if we
    441      1.1      ober 	 * switch it from a low to a high brightness.  Increasing brightness
    442      1.1      ober 	 * in steps avoids this issue.
    443      1.1      ober 	 */
    444      1.1      ober 	if (newval > curval) {
    445      1.1      ober 		for (i = curval + 1; i <= newval; i++) {
    446      1.1      ober 			(void)zssp_ic_send(ZSSP_IC_LZ9JG18,
    447      1.1      ober 			    CURRENT_BACKLIGHT[i].duty);
    448      1.1      ober 			scoop_set_backlight(CURRENT_BACKLIGHT[i].on,
    449      1.1      ober 			    CURRENT_BACKLIGHT[i].cont);
    450      1.1      ober 			delay(5000);
    451      1.1      ober 		}
    452      1.1      ober 	} else {
    453      1.1      ober 		(void)zssp_ic_send(ZSSP_IC_LZ9JG18,
    454      1.1      ober 		    CURRENT_BACKLIGHT[newval].duty);
    455      1.1      ober 		scoop_set_backlight(CURRENT_BACKLIGHT[newval].on,
    456      1.1      ober 		    CURRENT_BACKLIGHT[newval].cont);
    457      1.1      ober 	}
    458      1.1      ober 
    459      1.1      ober 	curval = newval;
    460      1.1      ober }
    461      1.1      ober 
    462      1.1      ober int
    463      1.1      ober lcd_get_backlight(void)
    464      1.1      ober {
    465      1.1      ober 
    466      1.1      ober 	return lcdislit;
    467      1.1      ober }
    468      1.1      ober 
    469      1.1      ober void
    470      1.2     peter lcd_set_backlight(int onoff)
    471      1.1      ober {
    472      1.1      ober 
    473      1.2     peter 	if (!onoff) {
    474      1.1      ober 		lcd_set_brightness(0);
    475      1.1      ober 		lcdislit = 0;
    476      1.1      ober 	} else {
    477      1.1      ober 		lcdislit = 1;
    478      1.1      ober 		lcd_set_brightness(lcd_get_brightness());
    479      1.1      ober 	}
    480      1.1      ober }
    481      1.1      ober 
    482      1.1      ober void
    483      1.1      ober lcd_blank(int blank)
    484      1.1      ober {
    485      1.1      ober 
    486      1.1      ober 	if (blank) {
    487      1.1      ober 		lcd_set_brightness(0);
    488      1.1      ober 		lcdisblank = 1;
    489      1.1      ober 	} else {
    490      1.1      ober 		lcdisblank = 0;
    491      1.1      ober 		lcd_set_brightness(lcd_get_brightness());
    492      1.1      ober 	}
    493      1.1      ober }
    494      1.1      ober 
    495      1.1      ober void
    496      1.1      ober lcd_power(int why, void *v)
    497      1.1      ober {
    498      1.1      ober 
    499      1.1      ober 	switch (why) {
    500      1.1      ober 	case PWR_SUSPEND:
    501      1.1      ober 	case PWR_STANDBY:
    502      1.1      ober 		lcd_set_brightness(0);
    503      1.1      ober 		pxa2x0_lcd_power(why, v);
    504      1.1      ober 		break;
    505      1.1      ober 
    506      1.1      ober 	case PWR_RESUME:
    507      1.1      ober 		pxa2x0_lcd_power(why, v);
    508      1.1      ober 		lcd_set_brightness(lcd_get_brightness());
    509      1.1      ober 		break;
    510      1.1      ober 	}
    511      1.1      ober }
    512