1 1.6 thorpej /* $NetBSD: gxlcd.c,v 1.6 2023/12/20 13:55:17 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.6 thorpej __KERNEL_RCSID(0, "$NetBSD: gxlcd.c,v 1.6 2023/12/20 13:55:17 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 52 1.1 kiyohara #include <dev/cons.h> 53 1.1 kiyohara #include <dev/wscons/wsconsio.h> 54 1.1 kiyohara #include <dev/wscons/wsdisplayvar.h> 55 1.1 kiyohara #include <dev/wscons/wscons_callbacks.h> 56 1.1 kiyohara 57 1.3 dyoung #include <sys/bus.h> 58 1.1 kiyohara 59 1.1 kiyohara #include <arm/xscale/pxa2x0var.h> 60 1.1 kiyohara #include <arm/xscale/pxa2x0reg.h> 61 1.1 kiyohara #include <arm/xscale/pxa2x0_lcd.h> 62 1.1 kiyohara #include <arm/xscale/pxa2x0_gpio.h> 63 1.1 kiyohara 64 1.1 kiyohara 65 1.1 kiyohara #ifndef CURRENT_DISPLAY 66 1.1 kiyohara #define CURRENT_DISPLAY samsung_lte430wq_f0c 67 1.1 kiyohara #endif 68 1.1 kiyohara 69 1.1 kiyohara 70 1.1 kiyohara static int gxlcd_match(device_t, cfdata_t, void *); 71 1.1 kiyohara static void gxlcd_attach(device_t, device_t, void *); 72 1.1 kiyohara 73 1.1 kiyohara void gxlcd_cnattach(void); 74 1.1 kiyohara 75 1.1 kiyohara static int gxlcd_ioctl(void *, void *, u_long, void *, int, struct lwp *); 76 1.1 kiyohara static int gxlcd_show_screen(void *, void *, int, 77 1.1 kiyohara void (*)(void *, int, int), void *); 78 1.1 kiyohara 79 1.1 kiyohara 80 1.1 kiyohara /* 81 1.1 kiyohara * wsdisplay glue 82 1.1 kiyohara */ 83 1.1 kiyohara static struct pxa2x0_wsscreen_descr gxlcd_std_screen = { 84 1.1 kiyohara .c = { 85 1.1 kiyohara .name = "std", 86 1.1 kiyohara .textops = &pxa2x0_lcd_emulops, 87 1.1 kiyohara .fontwidth = 8, 88 1.1 kiyohara .fontheight = 16, 89 1.1 kiyohara .capabilities = WSSCREEN_WSCOLORS, 90 1.1 kiyohara }, 91 1.1 kiyohara .depth = 16, /* bits per pixel */ 92 1.1 kiyohara }; 93 1.1 kiyohara 94 1.1 kiyohara static const struct wsscreen_descr *gxlcd_scr_descr[] = { 95 1.1 kiyohara &gxlcd_std_screen.c 96 1.1 kiyohara }; 97 1.1 kiyohara 98 1.1 kiyohara static const struct wsscreen_list gxlcd_screen_list = { 99 1.1 kiyohara .nscreens = __arraycount(gxlcd_scr_descr), 100 1.1 kiyohara .screens = gxlcd_scr_descr, 101 1.1 kiyohara }; 102 1.1 kiyohara 103 1.1 kiyohara struct wsdisplay_accessops gxlcd_accessops = { 104 1.1 kiyohara gxlcd_ioctl, 105 1.1 kiyohara pxa2x0_lcd_mmap, 106 1.1 kiyohara pxa2x0_lcd_alloc_screen, 107 1.1 kiyohara pxa2x0_lcd_free_screen, 108 1.1 kiyohara gxlcd_show_screen, 109 1.1 kiyohara NULL, 110 1.1 kiyohara NULL, 111 1.1 kiyohara NULL, 112 1.1 kiyohara }; 113 1.1 kiyohara 114 1.1 kiyohara const struct lcd_panel_geometry samsung_lte430wq_f0c = 115 1.1 kiyohara { 116 1.1 kiyohara 480, /* Width */ 117 1.1 kiyohara 272, /* Height */ 118 1.1 kiyohara 0, /* No extra lines */ 119 1.1 kiyohara 120 1.1 kiyohara LCDPANEL_ACTIVE | LCDPANEL_PCP, 121 1.1 kiyohara 1, /* clock divider */ 122 1.1 kiyohara 0, /* AC bias pin freq */ 123 1.1 kiyohara 124 1.1 kiyohara 41, /* horizontal sync pulse width */ 125 1.1 kiyohara 4, /* BLW */ 126 1.1 kiyohara 8, /* ELW */ 127 1.1 kiyohara 128 1.1 kiyohara 10, /* vertical sync pulse width */ 129 1.1 kiyohara 2, /* BFW */ 130 1.1 kiyohara 4, /* EFW */ 131 1.1 kiyohara }; 132 1.1 kiyohara 133 1.1 kiyohara static int gxlcd_console; 134 1.1 kiyohara 135 1.1 kiyohara 136 1.1 kiyohara CFATTACH_DECL_NEW(gxlcd, sizeof(struct pxa2x0_lcd_softc), 137 1.1 kiyohara gxlcd_match, gxlcd_attach, NULL, NULL); 138 1.1 kiyohara 139 1.1 kiyohara 140 1.1 kiyohara static int 141 1.1 kiyohara gxlcd_match(device_t parent, cfdata_t match, void *aux) 142 1.1 kiyohara { 143 1.1 kiyohara struct pxaip_attach_args *pxa = aux; 144 1.1 kiyohara 145 1.1 kiyohara if (strcmp(pxa->pxa_name, match->cf_name) != 0) 146 1.1 kiyohara return 0; 147 1.1 kiyohara 148 1.1 kiyohara pxa->pxa_size = PXA2X0_LCDC_SIZE; 149 1.1 kiyohara return 1; 150 1.1 kiyohara } 151 1.1 kiyohara 152 1.1 kiyohara static void 153 1.1 kiyohara gxlcd_attach(device_t parent, device_t self, void *aux) 154 1.1 kiyohara { 155 1.2 kiyohara struct pxa2x0_lcd_softc *sc = device_private(self); 156 1.1 kiyohara struct wsemuldisplaydev_attach_args aa; 157 1.1 kiyohara 158 1.2 kiyohara sc->dev = self; 159 1.1 kiyohara pxa2x0_lcd_attach_sub(sc, aux, &CURRENT_DISPLAY); 160 1.1 kiyohara 161 1.1 kiyohara aa.console = gxlcd_console; 162 1.1 kiyohara aa.scrdata = &gxlcd_screen_list; 163 1.1 kiyohara aa.accessops = &gxlcd_accessops; 164 1.1 kiyohara aa.accesscookie = sc; 165 1.1 kiyohara 166 1.1 kiyohara pxa2x0_lcd_setup_wsscreen(&gxlcd_std_screen, &CURRENT_DISPLAY, NULL); 167 1.1 kiyohara 168 1.5 thorpej (void) config_found(self, &aa, wsemuldisplaydevprint, CFARGS_NONE); 169 1.1 kiyohara } 170 1.1 kiyohara 171 1.1 kiyohara void 172 1.1 kiyohara gxlcd_cnattach(void) 173 1.1 kiyohara { 174 1.1 kiyohara 175 1.1 kiyohara pxa2x0_lcd_cnattach(&gxlcd_std_screen, &CURRENT_DISPLAY); 176 1.1 kiyohara 177 1.1 kiyohara gxlcd_console = 1; 178 1.1 kiyohara } 179 1.1 kiyohara 180 1.1 kiyohara 181 1.1 kiyohara /* 182 1.1 kiyohara * wsdisplay accessops overrides 183 1.1 kiyohara */ 184 1.1 kiyohara static int 185 1.1 kiyohara gxlcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l) 186 1.1 kiyohara { 187 1.1 kiyohara int res = EINVAL; 188 1.1 kiyohara 189 1.1 kiyohara switch (cmd) { 190 1.1 kiyohara case WSDISPLAYIO_SVIDEO: 191 1.1 kiyohara if (*(int *)data == WSDISPLAYIO_VIDEO_ON) 192 1.1 kiyohara pxa2x0_gpio_set_function(17, GPIO_IN); 193 1.1 kiyohara else 194 1.1 kiyohara pxa2x0_gpio_set_function(17, GPIO_OUT | GPIO_CLR); 195 1.1 kiyohara break; 196 1.1 kiyohara } 197 1.1 kiyohara 198 1.1 kiyohara if (res == EINVAL) 199 1.1 kiyohara res = pxa2x0_lcd_ioctl(v, vs, cmd, data, flag, l); 200 1.1 kiyohara return res; 201 1.1 kiyohara } 202 1.1 kiyohara 203 1.1 kiyohara static int 204 1.1 kiyohara gxlcd_show_screen(void *v, void *cookie, int waitok, 205 1.1 kiyohara void (*cb_func)(void *, int, int), void *cb_arg) 206 1.1 kiyohara { 207 1.1 kiyohara int error; 208 1.1 kiyohara 209 1.1 kiyohara error = pxa2x0_lcd_show_screen(v, cookie, waitok, cb_func, cb_arg); 210 1.1 kiyohara if (error) 211 1.1 kiyohara return (error); 212 1.1 kiyohara 213 1.1 kiyohara /* Turn on LCD */ 214 1.1 kiyohara pxa2x0_gpio_set_function(17, GPIO_IN); 215 1.1 kiyohara 216 1.1 kiyohara return 0; 217 1.1 kiyohara } 218