xref: /netbsd-src/sys/arch/evbarm/gumstix/gxlcd.c (revision 7433666e375b3ac4cc764df5a6726be98bc1cdd5)
1*7433666eSthorpej /*	$NetBSD: gxlcd.c,v 1.6 2023/12/20 13:55:17 thorpej Exp $	*/
21c10f508Skiyohara 
31c10f508Skiyohara /*
41c10f508Skiyohara  * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
51c10f508Skiyohara  * Written by Hiroyuki Bessho for Genetec Corporation.
61c10f508Skiyohara  *
71c10f508Skiyohara  * Redistribution and use in source and binary forms, with or without
81c10f508Skiyohara  * modification, are permitted provided that the following conditions
91c10f508Skiyohara  * are met:
101c10f508Skiyohara  * 1. Redistributions of source code must retain the above copyright
111c10f508Skiyohara  *    notice, this list of conditions and the following disclaimer.
121c10f508Skiyohara  * 2. Redistributions in binary form must reproduce the above copyright
131c10f508Skiyohara  *    notice, this list of conditions and the following disclaimer in the
141c10f508Skiyohara  *    documentation and/or other materials provided with the distribution.
151c10f508Skiyohara  * 3. The name of Genetec Corporation may not be used to endorse or
161c10f508Skiyohara  *    promote products derived from this software without specific prior
171c10f508Skiyohara  *    written permission.
181c10f508Skiyohara  *
191c10f508Skiyohara  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
201c10f508Skiyohara  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211c10f508Skiyohara  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221c10f508Skiyohara  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
231c10f508Skiyohara  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241c10f508Skiyohara  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251c10f508Skiyohara  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261c10f508Skiyohara  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271c10f508Skiyohara  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281c10f508Skiyohara  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291c10f508Skiyohara  * POSSIBILITY OF SUCH DAMAGE.
301c10f508Skiyohara  */
311c10f508Skiyohara 
321c10f508Skiyohara /*
331c10f508Skiyohara  * LCD driver for Gumstix consoleLCD-vx and compatible.
341c10f508Skiyohara  * (based on the Intel Lubbock driver).
351c10f508Skiyohara  *
361c10f508Skiyohara  * Controlling LCD is almost completely done through PXA2X0's
371c10f508Skiyohara  * integrated LCD controller.  Codes for it is arm/xscale/pxa2x0_lcd.c.
381c10f508Skiyohara  *
391c10f508Skiyohara  * Codes in this file provide platform specific things including:
401c10f508Skiyohara  *   LCD on/off switch and backlight
411c10f508Skiyohara  *   LCD panel geometry
421c10f508Skiyohara  */
431c10f508Skiyohara 
441c10f508Skiyohara #include <sys/cdefs.h>
45*7433666eSthorpej __KERNEL_RCSID(0, "$NetBSD: gxlcd.c,v 1.6 2023/12/20 13:55:17 thorpej Exp $");
461c10f508Skiyohara 
471c10f508Skiyohara #include <sys/param.h>
481c10f508Skiyohara #include <sys/systm.h>
491c10f508Skiyohara #include <sys/conf.h>
501c10f508Skiyohara #include <sys/uio.h>
511c10f508Skiyohara 
521c10f508Skiyohara #include <dev/cons.h>
531c10f508Skiyohara #include <dev/wscons/wsconsio.h>
541c10f508Skiyohara #include <dev/wscons/wsdisplayvar.h>
551c10f508Skiyohara #include <dev/wscons/wscons_callbacks.h>
561c10f508Skiyohara 
57fea15f47Sdyoung #include <sys/bus.h>
581c10f508Skiyohara 
591c10f508Skiyohara #include <arm/xscale/pxa2x0var.h>
601c10f508Skiyohara #include <arm/xscale/pxa2x0reg.h>
611c10f508Skiyohara #include <arm/xscale/pxa2x0_lcd.h>
621c10f508Skiyohara #include <arm/xscale/pxa2x0_gpio.h>
631c10f508Skiyohara 
641c10f508Skiyohara 
651c10f508Skiyohara #ifndef CURRENT_DISPLAY
661c10f508Skiyohara #define CURRENT_DISPLAY samsung_lte430wq_f0c
671c10f508Skiyohara #endif
681c10f508Skiyohara 
691c10f508Skiyohara 
701c10f508Skiyohara static int gxlcd_match(device_t, cfdata_t, void *);
711c10f508Skiyohara static void gxlcd_attach(device_t, device_t, void *);
721c10f508Skiyohara 
731c10f508Skiyohara void gxlcd_cnattach(void);
741c10f508Skiyohara 
751c10f508Skiyohara static int gxlcd_ioctl(void *, void *, u_long, void *, int, struct lwp *);
761c10f508Skiyohara static int gxlcd_show_screen(void *, void *, int,
771c10f508Skiyohara 			     void (*)(void *, int, int), void *);
781c10f508Skiyohara 
791c10f508Skiyohara 
801c10f508Skiyohara /*
811c10f508Skiyohara  * wsdisplay glue
821c10f508Skiyohara  */
831c10f508Skiyohara static struct pxa2x0_wsscreen_descr gxlcd_std_screen = {
841c10f508Skiyohara 	.c = {
851c10f508Skiyohara 		.name = "std",
861c10f508Skiyohara 		.textops = &pxa2x0_lcd_emulops,
871c10f508Skiyohara 		.fontwidth = 8,
881c10f508Skiyohara 		.fontheight = 16,
891c10f508Skiyohara 		.capabilities = WSSCREEN_WSCOLORS,
901c10f508Skiyohara 	},
911c10f508Skiyohara 	.depth = 16,			/* bits per pixel */
921c10f508Skiyohara };
931c10f508Skiyohara 
941c10f508Skiyohara static const struct wsscreen_descr *gxlcd_scr_descr[] = {
951c10f508Skiyohara 	&gxlcd_std_screen.c
961c10f508Skiyohara };
971c10f508Skiyohara 
981c10f508Skiyohara static const struct wsscreen_list gxlcd_screen_list = {
991c10f508Skiyohara 	.nscreens = __arraycount(gxlcd_scr_descr),
1001c10f508Skiyohara 	.screens = gxlcd_scr_descr,
1011c10f508Skiyohara };
1021c10f508Skiyohara 
1031c10f508Skiyohara struct wsdisplay_accessops gxlcd_accessops = {
1041c10f508Skiyohara 	gxlcd_ioctl,
1051c10f508Skiyohara 	pxa2x0_lcd_mmap,
1061c10f508Skiyohara 	pxa2x0_lcd_alloc_screen,
1071c10f508Skiyohara 	pxa2x0_lcd_free_screen,
1081c10f508Skiyohara 	gxlcd_show_screen,
1091c10f508Skiyohara 	NULL,
1101c10f508Skiyohara 	NULL,
1111c10f508Skiyohara 	NULL,
1121c10f508Skiyohara };
1131c10f508Skiyohara 
1141c10f508Skiyohara const struct lcd_panel_geometry samsung_lte430wq_f0c =
1151c10f508Skiyohara {
1161c10f508Skiyohara 	480,			/* Width */
1171c10f508Skiyohara 	272,			/* Height */
1181c10f508Skiyohara 	0,			/* No extra lines */
1191c10f508Skiyohara 
1201c10f508Skiyohara 	LCDPANEL_ACTIVE | LCDPANEL_PCP,
1211c10f508Skiyohara 	1,			/* clock divider */
1221c10f508Skiyohara 	0,			/* AC bias pin freq */
1231c10f508Skiyohara 
1241c10f508Skiyohara 	41,			/* horizontal sync pulse width */
1251c10f508Skiyohara 	4,			/* BLW */
1261c10f508Skiyohara 	8,			/* ELW */
1271c10f508Skiyohara 
1281c10f508Skiyohara 	10,			/* vertical sync pulse width */
1291c10f508Skiyohara 	2,			/* BFW */
1301c10f508Skiyohara 	4,			/* EFW */
1311c10f508Skiyohara };
1321c10f508Skiyohara 
1331c10f508Skiyohara static int gxlcd_console;
1341c10f508Skiyohara 
1351c10f508Skiyohara 
1361c10f508Skiyohara CFATTACH_DECL_NEW(gxlcd, sizeof(struct pxa2x0_lcd_softc),
1371c10f508Skiyohara     gxlcd_match, gxlcd_attach, NULL, NULL);
1381c10f508Skiyohara 
1391c10f508Skiyohara 
1401c10f508Skiyohara static int
gxlcd_match(device_t parent,cfdata_t match,void * aux)1411c10f508Skiyohara gxlcd_match(device_t parent, cfdata_t match, void *aux)
1421c10f508Skiyohara {
1431c10f508Skiyohara 	struct pxaip_attach_args *pxa = aux;
1441c10f508Skiyohara 
1451c10f508Skiyohara 	if (strcmp(pxa->pxa_name, match->cf_name) != 0)
1461c10f508Skiyohara 		return 0;
1471c10f508Skiyohara 
1481c10f508Skiyohara 	pxa->pxa_size = PXA2X0_LCDC_SIZE;
1491c10f508Skiyohara 	return 1;
1501c10f508Skiyohara }
1511c10f508Skiyohara 
1521c10f508Skiyohara static void
gxlcd_attach(device_t parent,device_t self,void * aux)1531c10f508Skiyohara gxlcd_attach(device_t parent, device_t self, void *aux)
1541c10f508Skiyohara {
155f97cdf80Skiyohara 	struct pxa2x0_lcd_softc *sc = device_private(self);
1561c10f508Skiyohara 	struct wsemuldisplaydev_attach_args aa;
1571c10f508Skiyohara 
158f97cdf80Skiyohara 	sc->dev = self;
1591c10f508Skiyohara 	pxa2x0_lcd_attach_sub(sc, aux, &CURRENT_DISPLAY);
1601c10f508Skiyohara 
1611c10f508Skiyohara 	aa.console = gxlcd_console;
1621c10f508Skiyohara 	aa.scrdata = &gxlcd_screen_list;
1631c10f508Skiyohara 	aa.accessops = &gxlcd_accessops;
1641c10f508Skiyohara 	aa.accesscookie = sc;
1651c10f508Skiyohara 
1661c10f508Skiyohara 	pxa2x0_lcd_setup_wsscreen(&gxlcd_std_screen, &CURRENT_DISPLAY, NULL);
1671c10f508Skiyohara 
168c7fb772bSthorpej 	(void) config_found(self, &aa, wsemuldisplaydevprint, CFARGS_NONE);
1691c10f508Skiyohara }
1701c10f508Skiyohara 
1711c10f508Skiyohara void
gxlcd_cnattach(void)1721c10f508Skiyohara gxlcd_cnattach(void)
1731c10f508Skiyohara {
1741c10f508Skiyohara 
1751c10f508Skiyohara 	pxa2x0_lcd_cnattach(&gxlcd_std_screen, &CURRENT_DISPLAY);
1761c10f508Skiyohara 
1771c10f508Skiyohara 	gxlcd_console = 1;
1781c10f508Skiyohara }
1791c10f508Skiyohara 
1801c10f508Skiyohara 
1811c10f508Skiyohara /*
1821c10f508Skiyohara  * wsdisplay accessops overrides
1831c10f508Skiyohara  */
1841c10f508Skiyohara static int
gxlcd_ioctl(void * v,void * vs,u_long cmd,void * data,int flag,struct lwp * l)1851c10f508Skiyohara gxlcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
1861c10f508Skiyohara {
1871c10f508Skiyohara 	int res = EINVAL;
1881c10f508Skiyohara 
1891c10f508Skiyohara 	switch (cmd) {
1901c10f508Skiyohara 	case WSDISPLAYIO_SVIDEO:
1911c10f508Skiyohara 		if (*(int *)data == WSDISPLAYIO_VIDEO_ON)
1921c10f508Skiyohara 			pxa2x0_gpio_set_function(17, GPIO_IN);
1931c10f508Skiyohara 		else
1941c10f508Skiyohara 			pxa2x0_gpio_set_function(17, GPIO_OUT | GPIO_CLR);
1951c10f508Skiyohara 		break;
1961c10f508Skiyohara 	}
1971c10f508Skiyohara 
1981c10f508Skiyohara 	if (res == EINVAL)
1991c10f508Skiyohara 		res = pxa2x0_lcd_ioctl(v, vs, cmd, data, flag, l);
2001c10f508Skiyohara 	return res;
2011c10f508Skiyohara }
2021c10f508Skiyohara 
2031c10f508Skiyohara static int
gxlcd_show_screen(void * v,void * cookie,int waitok,void (* cb_func)(void *,int,int),void * cb_arg)2041c10f508Skiyohara gxlcd_show_screen(void *v, void *cookie, int waitok,
2051c10f508Skiyohara 		  void (*cb_func)(void *, int, int), void *cb_arg)
2061c10f508Skiyohara {
2071c10f508Skiyohara 	int error;
2081c10f508Skiyohara 
2091c10f508Skiyohara 	error = pxa2x0_lcd_show_screen(v, cookie, waitok, cb_func, cb_arg);
2101c10f508Skiyohara 	if (error)
2111c10f508Skiyohara 		return (error);
2121c10f508Skiyohara 
2131c10f508Skiyohara 	/* Turn on LCD */
2141c10f508Skiyohara 	pxa2x0_gpio_set_function(17, GPIO_IN);
2151c10f508Skiyohara 
2161c10f508Skiyohara 	return 0;
2171c10f508Skiyohara }
218