1 1.6 andvar /* $NetBSD: w100lcd.c,v 1.6 2022/05/28 10:36:23 andvar Exp $ */ 2 1.1 tsutsui /* 3 1.1 tsutsui * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved. 4 1.1 tsutsui * Written by Hiroyuki Bessho for Genetec Corporation. 5 1.1 tsutsui * 6 1.1 tsutsui * Redistribution and use in source and binary forms, with or without 7 1.1 tsutsui * modification, are permitted provided that the following conditions 8 1.1 tsutsui * are met: 9 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright 10 1.1 tsutsui * notice, this list of conditions and the following disclaimer. 11 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright 12 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the 13 1.1 tsutsui * documentation and/or other materials provided with the distribution. 14 1.1 tsutsui * 3. The name of Genetec Corporation may not be used to endorse or 15 1.1 tsutsui * promote products derived from this software without specific prior 16 1.1 tsutsui * written permission. 17 1.1 tsutsui * 18 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND 19 1.1 tsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 1.1 tsutsui * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 1.1 tsutsui * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION 22 1.1 tsutsui * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 1.1 tsutsui * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 1.1 tsutsui * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 1.1 tsutsui * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 1.1 tsutsui * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 1.1 tsutsui * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 1.1 tsutsui * POSSIBILITY OF SUCH DAMAGE. 29 1.1 tsutsui */ 30 1.1 tsutsui 31 1.1 tsutsui /* 32 1.1 tsutsui * LCD driver for Sharp Zaurus SL-C7x0/860, based on zlcd.c. 33 1.1 tsutsui * 34 1.1 tsutsui * Controlling LCD is done in w100.c. 35 1.1 tsutsui * 36 1.1 tsutsui * Codes in this file provide platform specific things including: 37 1.1 tsutsui * LCD panel geometry 38 1.1 tsutsui * 39 1.1 tsutsui * LCD on/off switch and backlight brightness are done in lcdctl.c. 40 1.1 tsutsui */ 41 1.1 tsutsui #include <sys/cdefs.h> 42 1.6 andvar __KERNEL_RCSID(0, "$NetBSD: w100lcd.c,v 1.6 2022/05/28 10:36:23 andvar Exp $"); 43 1.3 tsutsui 44 1.3 tsutsui #include "lcdctl.h" 45 1.1 tsutsui 46 1.1 tsutsui #include <sys/param.h> 47 1.1 tsutsui #include <sys/systm.h> 48 1.1 tsutsui #include <sys/bus.h> 49 1.1 tsutsui 50 1.1 tsutsui #include <dev/cons.h> 51 1.1 tsutsui #include <dev/wscons/wsconsio.h> 52 1.1 tsutsui #include <dev/wscons/wsdisplayvar.h> 53 1.1 tsutsui #include <dev/rasops/rasops.h> 54 1.1 tsutsui #include <dev/wsfont/wsfont.h> 55 1.1 tsutsui 56 1.2 tsutsui #include <dev/hpc/hpcfbio.h> 57 1.2 tsutsui 58 1.1 tsutsui #include <arm/xscale/pxa2x0var.h> 59 1.1 tsutsui #include <zaurus/dev/w100var.h> 60 1.1 tsutsui 61 1.1 tsutsui #include <zaurus/zaurus/zaurus_var.h> 62 1.1 tsutsui #include <zaurus/dev/w100lcdvar.h> 63 1.3 tsutsui #if NLCDCTL > 0 64 1.3 tsutsui #include <zaurus/dev/lcdctlvar.h> 65 1.3 tsutsui #endif 66 1.1 tsutsui 67 1.1 tsutsui /* 68 1.1 tsutsui * wsdisplay glue 69 1.1 tsutsui */ 70 1.1 tsutsui static struct w100_wsscreen_descr w100lcd_std_screen = { 71 1.1 tsutsui .c = { 72 1.1 tsutsui .name = "std", 73 1.1 tsutsui .textops = &w100_emulops, 74 1.1 tsutsui .fontwidth = 8, 75 1.1 tsutsui .fontheight = 16, 76 1.1 tsutsui .capabilities = WSSCREEN_WSCOLORS, 77 1.1 tsutsui }, 78 1.1 tsutsui .depth = 16, /* bits per pixel */ 79 1.1 tsutsui .flags = 0, 80 1.1 tsutsui }; 81 1.1 tsutsui 82 1.1 tsutsui static const struct wsscreen_descr *w100lcd_scr_descr[] = { 83 1.1 tsutsui &w100lcd_std_screen.c 84 1.1 tsutsui }; 85 1.1 tsutsui 86 1.1 tsutsui static const struct wsscreen_list w100lcd_screen_list = { 87 1.1 tsutsui .nscreens = __arraycount(w100lcd_scr_descr), 88 1.1 tsutsui .screens = w100lcd_scr_descr, 89 1.1 tsutsui }; 90 1.1 tsutsui 91 1.1 tsutsui static int w100lcd_ioctl(void *, void *, u_long, void *, int, 92 1.1 tsutsui struct lwp *); 93 1.1 tsutsui static int w100lcd_show_screen(void *, void *, int, 94 1.1 tsutsui void (*)(void *, int, int), void *); 95 1.1 tsutsui 96 1.1 tsutsui struct wsdisplay_accessops w100lcd_accessops = { 97 1.1 tsutsui w100lcd_ioctl, 98 1.1 tsutsui w100_mmap, 99 1.1 tsutsui w100_alloc_screen, 100 1.1 tsutsui w100_free_screen, 101 1.1 tsutsui w100lcd_show_screen, 102 1.1 tsutsui NULL, 103 1.1 tsutsui NULL, 104 1.1 tsutsui NULL, 105 1.1 tsutsui }; 106 1.1 tsutsui 107 1.1 tsutsui const struct w100_panel_geometry lcd_panel_geometry_c700 = 108 1.1 tsutsui { 109 1.1 tsutsui 480, /* Width */ 110 1.1 tsutsui 640, /* Height */ 111 1.1 tsutsui W100_PANEL_ROTATE_CW, /* Rotate */ 112 1.1 tsutsui }; 113 1.1 tsutsui 114 1.1 tsutsui static int w100lcd_match(device_t, cfdata_t, void *); 115 1.1 tsutsui static void w100lcd_attach(device_t, device_t, void *); 116 1.1 tsutsui 117 1.1 tsutsui CFATTACH_DECL_NEW(w100lcd, sizeof(struct w100_softc), 118 1.1 tsutsui w100lcd_match, w100lcd_attach, NULL, NULL); 119 1.1 tsutsui 120 1.1 tsutsui static bool w100lcd_suspend(device_t, const pmf_qual_t *); 121 1.1 tsutsui static bool w100lcd_resume(device_t, const pmf_qual_t *); 122 1.1 tsutsui 123 1.1 tsutsui static int 124 1.1 tsutsui w100lcd_match(device_t parent, cfdata_t cf, void *aux) 125 1.1 tsutsui { 126 1.1 tsutsui 127 1.1 tsutsui if (ZAURUS_ISC860) 128 1.1 tsutsui return 1; 129 1.1 tsutsui return 0; 130 1.1 tsutsui } 131 1.1 tsutsui 132 1.1 tsutsui static void 133 1.1 tsutsui w100lcd_attach(device_t parent, device_t self, void *aux) 134 1.1 tsutsui { 135 1.1 tsutsui struct w100_softc *sc = device_private(self); 136 1.1 tsutsui struct pxaip_attach_args *pxa = (struct pxaip_attach_args *)aux; 137 1.1 tsutsui struct wsemuldisplaydev_attach_args aa; 138 1.1 tsutsui 139 1.1 tsutsui sc->dev = self; 140 1.1 tsutsui 141 1.1 tsutsui w100_attach_subr(sc, pxa->pxa_iot, &lcd_panel_geometry_c700); 142 1.1 tsutsui 143 1.1 tsutsui aa.console = glass_console; 144 1.1 tsutsui aa.scrdata = &w100lcd_screen_list; 145 1.1 tsutsui aa.accessops = &w100lcd_accessops; 146 1.1 tsutsui aa.accesscookie = sc; 147 1.1 tsutsui 148 1.5 thorpej (void)config_found(self, &aa, wsemuldisplaydevprint, CFARGS_NONE); 149 1.1 tsutsui 150 1.1 tsutsui if (!pmf_device_register(self, w100lcd_suspend, w100lcd_resume)) 151 1.1 tsutsui aprint_error_dev(self, "couldn't establish power handler\n"); 152 1.1 tsutsui } 153 1.1 tsutsui 154 1.1 tsutsui void 155 1.1 tsutsui w100lcd_cnattach(void) 156 1.1 tsutsui { 157 1.1 tsutsui 158 1.1 tsutsui if (ZAURUS_ISC860) 159 1.1 tsutsui w100_cnattach(&w100lcd_std_screen, &lcd_panel_geometry_c700); 160 1.1 tsutsui } 161 1.1 tsutsui 162 1.1 tsutsui /* 163 1.1 tsutsui * power management 164 1.1 tsutsui */ 165 1.1 tsutsui static bool 166 1.1 tsutsui w100lcd_suspend(device_t dv, const pmf_qual_t *qual) 167 1.1 tsutsui { 168 1.1 tsutsui struct w100_softc *sc = device_private(dv); 169 1.1 tsutsui 170 1.1 tsutsui #if NLCDCTL > 0 171 1.1 tsutsui lcdctl_onoff(false); 172 1.1 tsutsui #endif 173 1.1 tsutsui w100_suspend(sc); 174 1.1 tsutsui 175 1.1 tsutsui return true; 176 1.1 tsutsui } 177 1.1 tsutsui 178 1.1 tsutsui static bool 179 1.1 tsutsui w100lcd_resume(device_t dv, const pmf_qual_t *qual) 180 1.1 tsutsui { 181 1.1 tsutsui struct w100_softc *sc = device_private(dv); 182 1.1 tsutsui 183 1.1 tsutsui w100_resume(sc); 184 1.1 tsutsui #if NLCDCTL > 0 185 1.1 tsutsui lcdctl_onoff(true); 186 1.1 tsutsui #endif 187 1.1 tsutsui 188 1.1 tsutsui return true; 189 1.1 tsutsui } 190 1.1 tsutsui 191 1.1 tsutsui /* 192 1.1 tsutsui * wsdisplay accessops overrides 193 1.1 tsutsui */ 194 1.1 tsutsui static int 195 1.1 tsutsui w100lcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, 196 1.1 tsutsui struct lwp *l) 197 1.1 tsutsui { 198 1.2 tsutsui struct w100_softc *sc = (struct w100_softc *)v; 199 1.2 tsutsui struct hpcfb_fbconf *fbconf; 200 1.2 tsutsui struct hpcfb_dspconf *dspconf; 201 1.1 tsutsui int res = EINVAL; 202 1.1 tsutsui 203 1.1 tsutsui switch (cmd) { 204 1.1 tsutsui #if NLCDCTL > 0 205 1.1 tsutsui case WSDISPLAYIO_GETPARAM: 206 1.1 tsutsui case WSDISPLAYIO_SETPARAM: 207 1.1 tsutsui res = lcdctl_param(cmd, (struct wsdisplay_param *)data); 208 1.1 tsutsui break; 209 1.1 tsutsui #endif 210 1.2 tsutsui case HPCFBIO_GCONF: 211 1.2 tsutsui fbconf = (struct hpcfb_fbconf *)data; 212 1.2 tsutsui if (fbconf->hf_conf_index != 0 && 213 1.2 tsutsui fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) { 214 1.2 tsutsui break; 215 1.2 tsutsui } 216 1.2 tsutsui 217 1.2 tsutsui fbconf->hf_conf_index = 0; 218 1.2 tsutsui fbconf->hf_nconfs = 1; 219 1.2 tsutsui fbconf->hf_class = HPCFB_CLASS_RGBCOLOR; 220 1.2 tsutsui strlcpy(fbconf->hf_name, "Sharp Zaurus frame buffer", 221 1.2 tsutsui sizeof(fbconf->hf_name)); 222 1.2 tsutsui strlcpy(fbconf->hf_conf_name, "default", 223 1.2 tsutsui sizeof(fbconf->hf_conf_name)); 224 1.2 tsutsui fbconf->hf_width = sc->display_width; 225 1.2 tsutsui fbconf->hf_height = sc->display_height; 226 1.2 tsutsui fbconf->hf_baseaddr = (u_long)sc->active->buf_va; 227 1.2 tsutsui fbconf->hf_offset = 0; 228 1.2 tsutsui fbconf->hf_bytes_per_line = sc->display_width * 229 1.2 tsutsui sc->active->depth / 8; 230 1.2 tsutsui fbconf->hf_nplanes = 1; 231 1.2 tsutsui fbconf->hf_bytes_per_plane = sc->display_width * 232 1.2 tsutsui sc->display_height * sc->active->depth / 8; 233 1.2 tsutsui fbconf->hf_pack_width = sc->active->depth; 234 1.2 tsutsui fbconf->hf_pixels_per_pack = 1; 235 1.2 tsutsui fbconf->hf_pixel_width = sc->active->depth; 236 1.2 tsutsui fbconf->hf_access_flags = (0 237 1.2 tsutsui | HPCFB_ACCESS_BYTE 238 1.2 tsutsui | HPCFB_ACCESS_WORD 239 1.2 tsutsui | HPCFB_ACCESS_DWORD); 240 1.2 tsutsui fbconf->hf_order_flags = 0; 241 1.2 tsutsui fbconf->hf_reg_offset = 0; 242 1.2 tsutsui 243 1.2 tsutsui fbconf->hf_class_data_length = sizeof(struct hf_rgb_tag); 244 1.2 tsutsui fbconf->hf_u.hf_rgb.hf_flags = 0; 245 1.2 tsutsui fbconf->hf_u.hf_rgb.hf_red_width = 5; 246 1.2 tsutsui fbconf->hf_u.hf_rgb.hf_red_shift = 11; 247 1.2 tsutsui fbconf->hf_u.hf_rgb.hf_green_width = 6; 248 1.2 tsutsui fbconf->hf_u.hf_rgb.hf_green_shift = 5; 249 1.2 tsutsui fbconf->hf_u.hf_rgb.hf_blue_width = 5; 250 1.2 tsutsui fbconf->hf_u.hf_rgb.hf_blue_shift = 0; 251 1.2 tsutsui fbconf->hf_u.hf_rgb.hf_alpha_width = 0; 252 1.2 tsutsui fbconf->hf_u.hf_rgb.hf_alpha_shift = 0; 253 1.2 tsutsui 254 1.2 tsutsui fbconf->hf_ext_size = 0; 255 1.2 tsutsui fbconf->hf_ext_data = NULL; 256 1.2 tsutsui 257 1.2 tsutsui res = 0; 258 1.2 tsutsui break; 259 1.2 tsutsui 260 1.2 tsutsui case HPCFBIO_SCONF: 261 1.2 tsutsui fbconf = (struct hpcfb_fbconf *)data; 262 1.2 tsutsui if (fbconf->hf_conf_index != 0 && 263 1.2 tsutsui fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) { 264 1.2 tsutsui break; 265 1.2 tsutsui } 266 1.2 tsutsui /* nothing to do because we have only one configuration */ 267 1.2 tsutsui res = 0; 268 1.2 tsutsui break; 269 1.2 tsutsui 270 1.2 tsutsui case HPCFBIO_GDSPCONF: 271 1.2 tsutsui dspconf = (struct hpcfb_dspconf *)data; 272 1.2 tsutsui if ((dspconf->hd_unit_index != 0 && 273 1.2 tsutsui dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) || 274 1.2 tsutsui (dspconf->hd_conf_index != 0 && 275 1.2 tsutsui dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) { 276 1.2 tsutsui break; 277 1.2 tsutsui } 278 1.2 tsutsui 279 1.2 tsutsui dspconf->hd_unit_index = 0; 280 1.2 tsutsui dspconf->hd_nunits = 1; 281 1.2 tsutsui dspconf->hd_class = HPCFB_DSP_CLASS_COLORLCD; 282 1.2 tsutsui strlcpy(dspconf->hd_name, "Sharp Zaurus LCD", 283 1.2 tsutsui sizeof(dspconf->hd_name)); 284 1.2 tsutsui dspconf->hd_op_flags = 0; 285 1.2 tsutsui dspconf->hd_conf_index = 0; 286 1.2 tsutsui dspconf->hd_nconfs = 1; 287 1.2 tsutsui strlcpy(dspconf->hd_conf_name, "default", 288 1.2 tsutsui sizeof(dspconf->hd_conf_name)); 289 1.2 tsutsui dspconf->hd_width = sc->display_width; 290 1.2 tsutsui dspconf->hd_height = sc->display_height; 291 1.2 tsutsui dspconf->hd_xdpi = HPCFB_DSP_DPI_UNKNOWN; 292 1.2 tsutsui dspconf->hd_ydpi = HPCFB_DSP_DPI_UNKNOWN; 293 1.2 tsutsui 294 1.2 tsutsui res = 0; 295 1.2 tsutsui break; 296 1.2 tsutsui 297 1.2 tsutsui case HPCFBIO_SDSPCONF: 298 1.2 tsutsui dspconf = (struct hpcfb_dspconf *)data; 299 1.2 tsutsui if ((dspconf->hd_unit_index != 0 && 300 1.2 tsutsui dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) || 301 1.2 tsutsui (dspconf->hd_conf_index != 0 && 302 1.2 tsutsui dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) { 303 1.2 tsutsui break; 304 1.2 tsutsui } 305 1.2 tsutsui /* 306 1.2 tsutsui * nothing to do 307 1.2 tsutsui * because we have only one unit and one configuration 308 1.2 tsutsui */ 309 1.2 tsutsui res = 0; 310 1.2 tsutsui break; 311 1.2 tsutsui 312 1.2 tsutsui case HPCFBIO_GOP: 313 1.2 tsutsui case HPCFBIO_SOP: 314 1.6 andvar /* currently not implemented... */ 315 1.2 tsutsui break; 316 1.1 tsutsui 317 1.1 tsutsui default: 318 1.1 tsutsui break; 319 1.1 tsutsui } 320 1.1 tsutsui 321 1.1 tsutsui if (res == EINVAL) 322 1.1 tsutsui res = w100_ioctl(v, vs, cmd, data, flag, l); 323 1.1 tsutsui 324 1.1 tsutsui return res; 325 1.1 tsutsui } 326 1.1 tsutsui 327 1.1 tsutsui static int 328 1.1 tsutsui w100lcd_show_screen(void *v, void *cookie, int waitok, 329 1.1 tsutsui void (*cb_func)(void *, int, int), void *cb_arg) 330 1.1 tsutsui { 331 1.1 tsutsui int error; 332 1.1 tsutsui 333 1.1 tsutsui error = w100_show_screen(v, cookie, waitok, cb_func, cb_arg); 334 1.1 tsutsui if (error) 335 1.1 tsutsui return (error); 336 1.1 tsutsui 337 1.1 tsutsui /* Turn on LCD */ 338 1.1 tsutsui #if NLCDCTL > 0 339 1.1 tsutsui lcdctl_onoff(true); 340 1.1 tsutsui #endif 341 1.1 tsutsui 342 1.1 tsutsui return 0; 343 1.1 tsutsui } 344