1 /* $NetBSD: epsonlcd.c,v 1.2 2011/11/20 11:20:32 kiyohara Exp $ */ 2 /* 3 * Copyright (c) 2011 KIYOHARA Takashi 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27 #include <sys/cdefs.h> 28 __KERNEL_RCSID(0, "$NetBSD: epsonlcd.c,v 1.2 2011/11/20 11:20:32 kiyohara Exp $"); 29 30 #include <sys/param.h> 31 #include <sys/bus.h> 32 #include <sys/device.h> 33 #include <sys/errno.h> 34 35 #include <machine/bootinfo.h> 36 #include <machine/platid.h> 37 #include <machine/platid_mask.h> 38 39 #include <dev/wscons/wsdisplayvar.h> 40 #include <dev/rasops/rasops.h> 41 #include <dev/hpc/hpcfbio.h> 42 #include <dev/hpc/hpcfbvar.h> 43 #include <dev/hpc/video_subr.h> 44 45 #include <arm/xscale/pxa2x0var.h> 46 47 #include <hpcarm/dev/s1d138xxreg.h> 48 49 50 struct epsonlcd_softc { 51 device_t sc_dev; 52 53 bus_space_tag_t sc_iot; 54 bus_space_handle_t sc_ioh; 55 56 bus_addr_t sc_fbaddr; 57 bus_space_tag_t sc_fbt; 58 bus_space_handle_t sc_fbh; 59 60 struct video_chip sc_vc; 61 struct hpcfb_fbconf sc_fb; 62 struct hpcfb_dspconf sc_dsp; 63 }; 64 65 static int epsonlcd_match(device_t, cfdata_t, void *); 66 static void epsonlcd_attach(device_t, device_t, void *); 67 68 static int epsonlcd_ioctl(void *, u_long, void *, int, struct lwp *); 69 static paddr_t epsonlcd_mmap(void *, off_t, int); 70 71 static void epsonlcd_setup_hpcfbif(struct epsonlcd_softc *, 72 struct hpcfb_fbconf *); 73 static void epsonlcd_get_video_chip(struct epsonlcd_softc *, 74 struct video_chip *); 75 76 CFATTACH_DECL_NEW(epsonlcd, sizeof(struct epsonlcd_softc), 77 epsonlcd_match, epsonlcd_attach, NULL, NULL); 78 79 80 static struct hpcfb_accessops epsonlcd_ha = { 81 .ioctl = epsonlcd_ioctl, 82 .mmap = epsonlcd_mmap, 83 }; 84 85 /* ARGSUSED */ 86 static int 87 epsonlcd_match(device_t parent, cfdata_t match, void *aux) 88 { 89 struct pxaip_attach_args *pxa = aux; 90 91 if (strcmp(pxa->pxa_name, match->cf_name) != 0 || 92 !platid_match(&platid, &platid_mask_MACH_PSIONTEKLOGIX_NETBOOK_PRO)) 93 return 0; 94 95 return 1; 96 } 97 98 /* ARGSUSED */ 99 static void 100 epsonlcd_attach(device_t parent, device_t self, void *aux) 101 { 102 struct epsonlcd_softc *sc = device_private(self); 103 struct pxaip_attach_args *pxa = aux; 104 struct hpcfb_attach_args haa; 105 int rv; 106 107 aprint_naive("\n"); 108 aprint_normal(": Epson S1D138xx LCD Controller\n"); 109 110 sc->sc_dev = self; 111 sc->sc_iot = pxa->pxa_iot; 112 sc->sc_fbt = pxa->pxa_iot; 113 114 /* NETBOOK PRO map Framebuffer here. */ 115 sc->sc_fbaddr = pxa->pxa_addr + 0x200000; 116 117 if (bus_space_map(sc->sc_iot, pxa->pxa_addr, 0x2000, 0, &sc->sc_fbh) != 0) { 118 aprint_error_dev(self, "can't map I/O space\n"); 119 return; 120 } 121 rv = bus_space_map(sc->sc_fbt, sc->sc_fbaddr, S1D138XX_FRAMEBUFFER_SIZE, 122 0, &sc->sc_fbh); 123 if (rv != 0) { 124 aprint_error_dev(self, "can't map Framebuffer\n"); 125 return; 126 } 127 128 epsonlcd_get_video_chip(sc, &sc->sc_vc); 129 epsonlcd_setup_hpcfbif(sc, &sc->sc_fb); 130 if (hpcfb_cnattach(&sc->sc_fb) != 0) 131 panic("%s: hpcfb_cnattach failed\n", __func__); 132 /* always console */ 133 aprint_normal_dev(self, "console\n"); 134 135 /* register interface to hpcfb */ 136 haa.ha_console = 1; /* Always console */ 137 haa.ha_accessops = &epsonlcd_ha; 138 haa.ha_accessctx = sc; 139 haa.ha_curfbconf = 0; 140 haa.ha_nfbconf = 1; 141 haa.ha_fbconflist = &sc->sc_fb; 142 haa.ha_curdspconf = 0; 143 haa.ha_ndspconf = 1; 144 haa.ha_dspconflist = &sc->sc_dsp; 145 146 config_found(self, &haa, hpcfbprint); 147 148 if (!pmf_device_register(self, NULL, NULL)) 149 aprint_error_dev(self, "unable to establish power handler\n"); 150 } 151 152 153 static int 154 epsonlcd_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l) 155 { 156 printf("%s: To Be Done...: cmd=0x%lx\n", __func__, cmd); 157 switch (cmd) { 158 } 159 return EPASSTHROUGH; 160 } 161 162 static paddr_t 163 epsonlcd_mmap(void *ctx, off_t offset, int prot) 164 { 165 struct epsonlcd_softc *sc = ctx; 166 struct hpcfb_fbconf *fb = &sc->sc_fb; 167 168 if (offset < 0 || (fb->hf_bytes_per_plane + fb->hf_offset) < offset) 169 return -1; 170 171 return arm_btop(sc->sc_fbaddr + offset); 172 } 173 174 static void 175 epsonlcd_setup_hpcfbif(struct epsonlcd_softc *sc, struct hpcfb_fbconf *fb) 176 { 177 struct video_chip *vc = &sc->sc_vc; 178 179 memset(fb, 0, sizeof(struct hpcfb_fbconf)); 180 fb->hf_conf_index = 0; /* configuration index */ 181 fb->hf_nconfs = 1; /* how many configurations */ 182 /* frame buffer name */ 183 strncpy(fb->hf_name, "Epson S1D138xx LCD Controller", HPCFB_MAXNAMELEN); 184 185 /* configuration name */ 186 strncpy(fb->hf_conf_name, "LCD", HPCFB_MAXNAMELEN); 187 188 fb->hf_height = vc->vc_fbheight; 189 fb->hf_width = vc->vc_fbwidth; 190 fb->hf_baseaddr = vc->vc_fbvaddr; 191 /* frame buffer start offset */ 192 fb->hf_offset = vc->vc_fbvaddr - arm_ptob(arm_btop(vc->vc_fbvaddr)); 193 194 fb->hf_bytes_per_line = (vc->vc_fbwidth * vc->vc_fbdepth) / NBBY; 195 fb->hf_nplanes = 1; 196 fb->hf_bytes_per_plane = vc->vc_fbheight * fb->hf_bytes_per_line; 197 198 fb->hf_access_flags |= HPCFB_ACCESS_BYTE; 199 fb->hf_access_flags |= HPCFB_ACCESS_WORD; 200 fb->hf_access_flags |= HPCFB_ACCESS_DWORD; 201 if (vc->vc_reverse) 202 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE; 203 204 switch (vc->vc_fbdepth) { 205 default: 206 panic("%s: not supported color depth %d\n", 207 __func__, vc->vc_fbdepth); 208 209 /* NOTREACHED */ 210 case 16: 211 fb->hf_class = HPCFB_CLASS_RGBCOLOR; 212 fb->hf_access_flags |= HPCFB_ACCESS_STATIC; 213 fb->hf_order_flags = HPCFB_REVORDER_BYTE; 214 fb->hf_pack_width = 16; 215 fb->hf_pixels_per_pack = 1; 216 fb->hf_pixel_width = 16; 217 218 fb->hf_class_data_length = sizeof(struct hf_rgb_tag); 219 /* reserved for future use */ 220 fb->hf_u.hf_rgb.hf_flags = 0; 221 222 fb->hf_u.hf_rgb.hf_red_width = 5; 223 fb->hf_u.hf_rgb.hf_red_shift = 11; 224 fb->hf_u.hf_rgb.hf_green_width = 6; 225 fb->hf_u.hf_rgb.hf_green_shift = 5; 226 fb->hf_u.hf_rgb.hf_blue_width = 5; 227 fb->hf_u.hf_rgb.hf_blue_shift = 0; 228 fb->hf_u.hf_rgb.hf_alpha_width = 0; 229 fb->hf_u.hf_rgb.hf_alpha_shift = 0; 230 break; 231 232 case 8: 233 fb->hf_class = HPCFB_CLASS_INDEXCOLOR; 234 fb->hf_access_flags |= HPCFB_ACCESS_STATIC; 235 fb->hf_pack_width = 8; 236 fb->hf_pixels_per_pack = 1; 237 fb->hf_pixel_width = 8; 238 239 fb->hf_class_data_length = sizeof(struct hf_indexed_tag); 240 /* reserved for future use */ 241 fb->hf_u.hf_indexed.hf_flags = 0; 242 break; 243 } 244 } 245 246 static void 247 epsonlcd_get_video_chip(struct epsonlcd_softc *sc, struct video_chip *vc) 248 { 249 250 #define BSH2VADDR(ioh) (ioh) 251 252 vc->vc_fbvaddr = BSH2VADDR(sc->sc_fbh); 253 vc->vc_fbpaddr = sc->sc_fbaddr; 254 vc->vc_fbsize = S1D138XX_FRAMEBUFFER_SIZE; 255 vc->vc_fbdepth = (bootinfo->fb_line_bytes / bootinfo->fb_width) * NBBY; 256 vc->vc_fbwidth = bootinfo->fb_width; 257 vc->vc_fbheight = bootinfo->fb_height; 258 vc->vc_reverse = video_reverse_color(); 259 } 260