#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: gxlcd.c,v 1.6 2023/12/20 13:55:17 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/uio.h>
#include <dev/cons.h>
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsdisplayvar.h>
#include <dev/wscons/wscons_callbacks.h>
#include <sys/bus.h>
#include <arm/xscale/pxa2x0var.h>
#include <arm/xscale/pxa2x0reg.h>
#include <arm/xscale/pxa2x0_lcd.h>
#include <arm/xscale/pxa2x0_gpio.h>
#ifndef CURRENT_DISPLAY
#define CURRENT_DISPLAY samsung_lte430wq_f0c
#endif
static int gxlcd_match(device_t, cfdata_t, void *);
static void gxlcd_attach(device_t, device_t, void *);
void gxlcd_cnattach(void);
static int gxlcd_ioctl(void *, void *, u_long, void *, int, struct lwp *);
static int gxlcd_show_screen(void *, void *, int,
void (*)(void *, int, int), void *);
static struct pxa2x0_wsscreen_descr gxlcd_std_screen = {
.c = {
.name = "std",
.textops = &pxa2x0_lcd_emulops,
.fontwidth = 8,
.fontheight = 16,
.capabilities = WSSCREEN_WSCOLORS,
},
.depth = 16,
};
static const struct wsscreen_descr *gxlcd_scr_descr[] = {
&gxlcd_std_screen.c
};
static const struct wsscreen_list gxlcd_screen_list = {
.nscreens = __arraycount(gxlcd_scr_descr),
.screens = gxlcd_scr_descr,
};
struct wsdisplay_accessops gxlcd_accessops = {
gxlcd_ioctl,
pxa2x0_lcd_mmap,
pxa2x0_lcd_alloc_screen,
pxa2x0_lcd_free_screen,
gxlcd_show_screen,
NULL,
NULL,
NULL,
};
const struct lcd_panel_geometry samsung_lte430wq_f0c =
{
480,
272,
0,
LCDPANEL_ACTIVE | LCDPANEL_PCP,
1,
0,
41,
4,
8,
10,
2,
4,
};
static int gxlcd_console;
CFATTACH_DECL_NEW(gxlcd, sizeof(struct pxa2x0_lcd_softc),
gxlcd_match, gxlcd_attach, NULL, NULL);
static int
gxlcd_match(device_t parent, cfdata_t match, void *aux)
{
struct pxaip_attach_args *pxa = aux;
if (strcmp(pxa->pxa_name, match->cf_name) != 0)
return 0;
pxa->pxa_size = PXA2X0_LCDC_SIZE;
return 1;
}
static void
gxlcd_attach(device_t parent, device_t self, void *aux)
{
struct pxa2x0_lcd_softc *sc = device_private(self);
struct wsemuldisplaydev_attach_args aa;
sc->dev = self;
pxa2x0_lcd_attach_sub(sc, aux, &CURRENT_DISPLAY);
aa.console = gxlcd_console;
aa.scrdata = &gxlcd_screen_list;
aa.accessops = &gxlcd_accessops;
aa.accesscookie = sc;
pxa2x0_lcd_setup_wsscreen(&gxlcd_std_screen, &CURRENT_DISPLAY, NULL);
(void) config_found(self, &aa, wsemuldisplaydevprint, CFARGS_NONE);
}
void
gxlcd_cnattach(void)
{
pxa2x0_lcd_cnattach(&gxlcd_std_screen, &CURRENT_DISPLAY);
gxlcd_console = 1;
}
static int
gxlcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
{
int res = EINVAL;
switch (cmd) {
case WSDISPLAYIO_SVIDEO:
if (*(int *)data == WSDISPLAYIO_VIDEO_ON)
pxa2x0_gpio_set_function(17, GPIO_IN);
else
pxa2x0_gpio_set_function(17, GPIO_OUT | GPIO_CLR);
break;
}
if (res == EINVAL)
res = pxa2x0_lcd_ioctl(v, vs, cmd, data, flag, l);
return res;
}
static int
gxlcd_show_screen(void *v, void *cookie, int waitok,
void (*cb_func)(void *, int, int), void *cb_arg)
{
int error;
error = pxa2x0_lcd_show_screen(v, cookie, waitok, cb_func, cb_arg);
if (error)
return (error);
pxa2x0_gpio_set_function(17, GPIO_IN);
return 0;
}