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