Home | History | Annotate | Line # | Download | only in gumstix
gxlcd.c revision 1.3.68.1
      1  1.3.68.1   thorpej /*	$NetBSD: gxlcd.c,v 1.3.68.1 2021/03/21 21:08:58 thorpej Exp $	*/
      2       1.1  kiyohara 
      3       1.1  kiyohara /*
      4       1.1  kiyohara  * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
      5       1.1  kiyohara  * Written by Hiroyuki Bessho for Genetec Corporation.
      6       1.1  kiyohara  *
      7       1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
      8       1.1  kiyohara  * modification, are permitted provided that the following conditions
      9       1.1  kiyohara  * are met:
     10       1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     11       1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     12       1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     14       1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     15       1.1  kiyohara  * 3. The name of Genetec Corporation may not be used to endorse or
     16       1.1  kiyohara  *    promote products derived from this software without specific prior
     17       1.1  kiyohara  *    written permission.
     18       1.1  kiyohara  *
     19       1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     20       1.1  kiyohara  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1  kiyohara  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1  kiyohara  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     23       1.1  kiyohara  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1  kiyohara  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1  kiyohara  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1  kiyohara  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1  kiyohara  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1  kiyohara  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1  kiyohara  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1  kiyohara  */
     31       1.1  kiyohara 
     32       1.1  kiyohara /*
     33       1.1  kiyohara  * LCD driver for Gumstix consoleLCD-vx and compatible.
     34       1.1  kiyohara  * (based on the Intel Lubbock driver).
     35       1.1  kiyohara  *
     36       1.1  kiyohara  * Controlling LCD is almost completely done through PXA2X0's
     37       1.1  kiyohara  * integrated LCD controller.  Codes for it is arm/xscale/pxa2x0_lcd.c.
     38       1.1  kiyohara  *
     39       1.1  kiyohara  * Codes in this file provide platform specific things including:
     40       1.1  kiyohara  *   LCD on/off switch and backlight
     41       1.1  kiyohara  *   LCD panel geometry
     42       1.1  kiyohara  */
     43       1.1  kiyohara 
     44       1.1  kiyohara #include <sys/cdefs.h>
     45  1.3.68.1   thorpej __KERNEL_RCSID(0, "$NetBSD: gxlcd.c,v 1.3.68.1 2021/03/21 21:08:58 thorpej Exp $");
     46       1.1  kiyohara 
     47       1.1  kiyohara #include <sys/param.h>
     48       1.1  kiyohara #include <sys/systm.h>
     49       1.1  kiyohara #include <sys/conf.h>
     50       1.1  kiyohara #include <sys/uio.h>
     51       1.1  kiyohara #include <sys/malloc.h>
     52       1.1  kiyohara 
     53       1.1  kiyohara #include <dev/cons.h>
     54       1.1  kiyohara #include <dev/wscons/wsconsio.h>
     55       1.1  kiyohara #include <dev/wscons/wsdisplayvar.h>
     56       1.1  kiyohara #include <dev/wscons/wscons_callbacks.h>
     57       1.1  kiyohara 
     58       1.3    dyoung #include <sys/bus.h>
     59       1.1  kiyohara 
     60       1.1  kiyohara #include <arm/xscale/pxa2x0var.h>
     61       1.1  kiyohara #include <arm/xscale/pxa2x0reg.h>
     62       1.1  kiyohara #include <arm/xscale/pxa2x0_lcd.h>
     63       1.1  kiyohara #include <arm/xscale/pxa2x0_gpio.h>
     64       1.1  kiyohara 
     65       1.1  kiyohara 
     66       1.1  kiyohara #ifndef CURRENT_DISPLAY
     67       1.1  kiyohara #define CURRENT_DISPLAY samsung_lte430wq_f0c
     68       1.1  kiyohara #endif
     69       1.1  kiyohara 
     70       1.1  kiyohara 
     71       1.1  kiyohara static int gxlcd_match(device_t, cfdata_t, void *);
     72       1.1  kiyohara static void gxlcd_attach(device_t, device_t, void *);
     73       1.1  kiyohara 
     74       1.1  kiyohara void gxlcd_cnattach(void);
     75       1.1  kiyohara 
     76       1.1  kiyohara static int gxlcd_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     77       1.1  kiyohara static int gxlcd_show_screen(void *, void *, int,
     78       1.1  kiyohara 			     void (*)(void *, int, int), void *);
     79       1.1  kiyohara 
     80       1.1  kiyohara 
     81       1.1  kiyohara /*
     82       1.1  kiyohara  * wsdisplay glue
     83       1.1  kiyohara  */
     84       1.1  kiyohara static struct pxa2x0_wsscreen_descr gxlcd_std_screen = {
     85       1.1  kiyohara 	.c = {
     86       1.1  kiyohara 		.name = "std",
     87       1.1  kiyohara 		.textops = &pxa2x0_lcd_emulops,
     88       1.1  kiyohara 		.fontwidth = 8,
     89       1.1  kiyohara 		.fontheight = 16,
     90       1.1  kiyohara 		.capabilities = WSSCREEN_WSCOLORS,
     91       1.1  kiyohara 	},
     92       1.1  kiyohara 	.depth = 16,			/* bits per pixel */
     93       1.1  kiyohara };
     94       1.1  kiyohara 
     95       1.1  kiyohara static const struct wsscreen_descr *gxlcd_scr_descr[] = {
     96       1.1  kiyohara 	&gxlcd_std_screen.c
     97       1.1  kiyohara };
     98       1.1  kiyohara 
     99       1.1  kiyohara static const struct wsscreen_list gxlcd_screen_list = {
    100       1.1  kiyohara 	.nscreens = __arraycount(gxlcd_scr_descr),
    101       1.1  kiyohara 	.screens = gxlcd_scr_descr,
    102       1.1  kiyohara };
    103       1.1  kiyohara 
    104       1.1  kiyohara struct wsdisplay_accessops gxlcd_accessops = {
    105       1.1  kiyohara 	gxlcd_ioctl,
    106       1.1  kiyohara 	pxa2x0_lcd_mmap,
    107       1.1  kiyohara 	pxa2x0_lcd_alloc_screen,
    108       1.1  kiyohara 	pxa2x0_lcd_free_screen,
    109       1.1  kiyohara 	gxlcd_show_screen,
    110       1.1  kiyohara 	NULL,
    111       1.1  kiyohara 	NULL,
    112       1.1  kiyohara 	NULL,
    113       1.1  kiyohara };
    114       1.1  kiyohara 
    115       1.1  kiyohara const struct lcd_panel_geometry samsung_lte430wq_f0c =
    116       1.1  kiyohara {
    117       1.1  kiyohara 	480,			/* Width */
    118       1.1  kiyohara 	272,			/* Height */
    119       1.1  kiyohara 	0,			/* No extra lines */
    120       1.1  kiyohara 
    121       1.1  kiyohara 	LCDPANEL_ACTIVE | LCDPANEL_PCP,
    122       1.1  kiyohara 	1,			/* clock divider */
    123       1.1  kiyohara 	0,			/* AC bias pin freq */
    124       1.1  kiyohara 
    125       1.1  kiyohara 	41,			/* horizontal sync pulse width */
    126       1.1  kiyohara 	4,			/* BLW */
    127       1.1  kiyohara 	8,			/* ELW */
    128       1.1  kiyohara 
    129       1.1  kiyohara 	10,			/* vertical sync pulse width */
    130       1.1  kiyohara 	2,			/* BFW */
    131       1.1  kiyohara 	4,			/* EFW */
    132       1.1  kiyohara };
    133       1.1  kiyohara 
    134       1.1  kiyohara static int gxlcd_console;
    135       1.1  kiyohara 
    136       1.1  kiyohara 
    137       1.1  kiyohara CFATTACH_DECL_NEW(gxlcd, sizeof(struct pxa2x0_lcd_softc),
    138       1.1  kiyohara     gxlcd_match, gxlcd_attach, NULL, NULL);
    139       1.1  kiyohara 
    140       1.1  kiyohara 
    141       1.1  kiyohara static int
    142       1.1  kiyohara gxlcd_match(device_t parent, cfdata_t match, void *aux)
    143       1.1  kiyohara {
    144       1.1  kiyohara 	struct pxaip_attach_args *pxa = aux;
    145       1.1  kiyohara 
    146       1.1  kiyohara 	if (strcmp(pxa->pxa_name, match->cf_name) != 0)
    147       1.1  kiyohara 		return 0;
    148       1.1  kiyohara 
    149       1.1  kiyohara 	pxa->pxa_size = PXA2X0_LCDC_SIZE;
    150       1.1  kiyohara 	return 1;
    151       1.1  kiyohara }
    152       1.1  kiyohara 
    153       1.1  kiyohara static void
    154       1.1  kiyohara gxlcd_attach(device_t parent, device_t self, void *aux)
    155       1.1  kiyohara {
    156       1.2  kiyohara 	struct pxa2x0_lcd_softc *sc = device_private(self);
    157       1.1  kiyohara 	struct wsemuldisplaydev_attach_args aa;
    158       1.1  kiyohara 
    159       1.2  kiyohara 	sc->dev = self;
    160       1.1  kiyohara 	pxa2x0_lcd_attach_sub(sc, aux, &CURRENT_DISPLAY);
    161       1.1  kiyohara 
    162       1.1  kiyohara 	aa.console = gxlcd_console;
    163       1.1  kiyohara 	aa.scrdata = &gxlcd_screen_list;
    164       1.1  kiyohara 	aa.accessops = &gxlcd_accessops;
    165       1.1  kiyohara 	aa.accesscookie = sc;
    166       1.1  kiyohara 
    167       1.1  kiyohara 	pxa2x0_lcd_setup_wsscreen(&gxlcd_std_screen, &CURRENT_DISPLAY, NULL);
    168       1.1  kiyohara 
    169  1.3.68.1   thorpej 	(void) config_found(self, &aa, wsemuldisplaydevprint, CFARG_EOL);
    170       1.1  kiyohara }
    171       1.1  kiyohara 
    172       1.1  kiyohara void
    173       1.1  kiyohara gxlcd_cnattach(void)
    174       1.1  kiyohara {
    175       1.1  kiyohara 
    176       1.1  kiyohara 	pxa2x0_lcd_cnattach(&gxlcd_std_screen, &CURRENT_DISPLAY);
    177       1.1  kiyohara 
    178       1.1  kiyohara 	gxlcd_console = 1;
    179       1.1  kiyohara }
    180       1.1  kiyohara 
    181       1.1  kiyohara 
    182       1.1  kiyohara /*
    183       1.1  kiyohara  * wsdisplay accessops overrides
    184       1.1  kiyohara  */
    185       1.1  kiyohara static int
    186       1.1  kiyohara gxlcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    187       1.1  kiyohara {
    188       1.1  kiyohara 	int res = EINVAL;
    189       1.1  kiyohara 
    190       1.1  kiyohara 	switch (cmd) {
    191       1.1  kiyohara 	case WSDISPLAYIO_SVIDEO:
    192       1.1  kiyohara 		if (*(int *)data == WSDISPLAYIO_VIDEO_ON)
    193       1.1  kiyohara 			pxa2x0_gpio_set_function(17, GPIO_IN);
    194       1.1  kiyohara 		else
    195       1.1  kiyohara 			pxa2x0_gpio_set_function(17, GPIO_OUT | GPIO_CLR);
    196       1.1  kiyohara 		break;
    197       1.1  kiyohara 	}
    198       1.1  kiyohara 
    199       1.1  kiyohara 	if (res == EINVAL)
    200       1.1  kiyohara 		res = pxa2x0_lcd_ioctl(v, vs, cmd, data, flag, l);
    201       1.1  kiyohara 	return res;
    202       1.1  kiyohara }
    203       1.1  kiyohara 
    204       1.1  kiyohara static int
    205       1.1  kiyohara gxlcd_show_screen(void *v, void *cookie, int waitok,
    206       1.1  kiyohara 		  void (*cb_func)(void *, int, int), void *cb_arg)
    207       1.1  kiyohara {
    208       1.1  kiyohara 	int error;
    209       1.1  kiyohara 
    210       1.1  kiyohara 	error = pxa2x0_lcd_show_screen(v, cookie, waitok, cb_func, cb_arg);
    211       1.1  kiyohara 	if (error)
    212       1.1  kiyohara 		return (error);
    213       1.1  kiyohara 
    214       1.1  kiyohara 	/* Turn on LCD */
    215       1.1  kiyohara 	pxa2x0_gpio_set_function(17, GPIO_IN);
    216       1.1  kiyohara 
    217       1.1  kiyohara 	return 0;
    218       1.1  kiyohara }
    219