Home | History | Annotate | Line # | Download | only in broadcom
bcm2835_genfb.c revision 1.4.6.3
      1  1.4.6.2  tls /* $NetBSD: bcm2835_genfb.c,v 1.4.6.3 2013/06/23 06:20:00 tls Exp $ */
      2  1.4.6.2  tls 
      3  1.4.6.2  tls /*-
      4  1.4.6.2  tls  * Copyright (c) 2013 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  1.4.6.2  tls  * All rights reserved.
      6  1.4.6.2  tls  *
      7  1.4.6.2  tls  * Redistribution and use in source and binary forms, with or without
      8  1.4.6.2  tls  * modification, are permitted provided that the following conditions
      9  1.4.6.2  tls  * are met:
     10  1.4.6.2  tls  * 1. Redistributions of source code must retain the above copyright
     11  1.4.6.2  tls  *    notice, this list of conditions and the following disclaimer.
     12  1.4.6.2  tls  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.4.6.2  tls  *    notice, this list of conditions and the following disclaimer in the
     14  1.4.6.2  tls  *    documentation and/or other materials provided with the distribution.
     15  1.4.6.2  tls  *
     16  1.4.6.2  tls  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.4.6.2  tls  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.4.6.2  tls  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.4.6.2  tls  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.4.6.2  tls  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.4.6.2  tls  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.4.6.2  tls  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.4.6.2  tls  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.4.6.2  tls  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.4.6.2  tls  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.4.6.2  tls  * POSSIBILITY OF SUCH DAMAGE.
     27  1.4.6.2  tls  */
     28  1.4.6.2  tls 
     29  1.4.6.2  tls /*
     30  1.4.6.2  tls  * Generic framebuffer console driver
     31  1.4.6.2  tls  */
     32  1.4.6.2  tls 
     33  1.4.6.2  tls #include <sys/cdefs.h>
     34  1.4.6.2  tls __KERNEL_RCSID(0, "$NetBSD: bcm2835_genfb.c,v 1.4.6.3 2013/06/23 06:20:00 tls Exp $");
     35  1.4.6.2  tls 
     36  1.4.6.2  tls #include <sys/param.h>
     37  1.4.6.2  tls #include <sys/types.h>
     38  1.4.6.2  tls #include <sys/systm.h>
     39  1.4.6.2  tls #include <sys/device.h>
     40  1.4.6.2  tls #include <sys/conf.h>
     41  1.4.6.2  tls #include <sys/bus.h>
     42  1.4.6.2  tls #include <sys/kmem.h>
     43  1.4.6.2  tls 
     44  1.4.6.2  tls #include <arm/broadcom/bcm_amba.h>
     45  1.4.6.2  tls 
     46  1.4.6.2  tls #include <dev/wsfb/genfbvar.h>
     47  1.4.6.2  tls 
     48  1.4.6.2  tls struct bcmgenfb_softc {
     49  1.4.6.2  tls 	struct genfb_softc	sc_gen;
     50  1.4.6.2  tls 	bus_space_tag_t		sc_iot;
     51  1.4.6.2  tls 	bus_space_handle_t	sc_ioh;
     52  1.4.6.2  tls 
     53  1.4.6.2  tls 	uint32_t		sc_wstype;
     54  1.4.6.2  tls };
     55  1.4.6.2  tls 
     56  1.4.6.2  tls static int	bcmgenfb_match(device_t, cfdata_t, void *);
     57  1.4.6.2  tls static void	bcmgenfb_attach(device_t, device_t, void *);
     58  1.4.6.2  tls 
     59  1.4.6.2  tls static int	bcmgenfb_ioctl(void *, void *, u_long, void *, int, lwp_t *);
     60  1.4.6.2  tls static paddr_t	bcmgenfb_mmap(void *, void *, off_t, int);
     61  1.4.6.3  tls static bool	bcmgenfb_shutdown(device_t, int);
     62  1.4.6.3  tls 
     63  1.4.6.3  tls void		bcmgenfb_set_console_dev(device_t);
     64  1.4.6.3  tls void		bcmgenfb_ddb_trap_callback(int);
     65  1.4.6.3  tls 
     66  1.4.6.3  tls static device_t bcmgenfb_console_dev = NULL;
     67  1.4.6.2  tls 
     68  1.4.6.2  tls CFATTACH_DECL_NEW(bcmgenfb, sizeof(struct bcmgenfb_softc),
     69  1.4.6.2  tls     bcmgenfb_match, bcmgenfb_attach, NULL, NULL);
     70  1.4.6.2  tls 
     71  1.4.6.2  tls static int
     72  1.4.6.2  tls bcmgenfb_match(device_t parent, cfdata_t match, void *aux)
     73  1.4.6.2  tls {
     74  1.4.6.2  tls 	struct amba_attach_args *aaa = aux;
     75  1.4.6.2  tls 
     76  1.4.6.2  tls 	return !strcmp(aaa->aaa_name, "fb");
     77  1.4.6.2  tls }
     78  1.4.6.2  tls 
     79  1.4.6.2  tls static void
     80  1.4.6.2  tls bcmgenfb_attach(device_t parent, device_t self, void *aux)
     81  1.4.6.2  tls {
     82  1.4.6.2  tls 	struct bcmgenfb_softc *sc = device_private(self);
     83  1.4.6.2  tls 	struct amba_attach_args *aaa = aux;
     84  1.4.6.2  tls 	prop_dictionary_t dict = device_properties(self);
     85  1.4.6.2  tls 	struct genfb_ops ops;
     86  1.4.6.2  tls 	bool is_console = false;
     87  1.4.6.2  tls 	int error;
     88  1.4.6.2  tls 
     89  1.4.6.2  tls 	sc->sc_gen.sc_dev = self;
     90  1.4.6.2  tls 	sc->sc_iot = aaa->aaa_iot;
     91  1.4.6.2  tls 
     92  1.4.6.2  tls 	sc->sc_wstype = WSDISPLAY_TYPE_VC4;
     93  1.4.6.2  tls 	prop_dictionary_get_uint32(dict, "wsdisplay_type", &sc->sc_wstype);
     94  1.4.6.2  tls 	prop_dictionary_get_bool(dict, "is_console", &is_console);
     95  1.4.6.2  tls 
     96  1.4.6.2  tls 	genfb_init(&sc->sc_gen);
     97  1.4.6.2  tls 
     98  1.4.6.2  tls 	if (sc->sc_gen.sc_width == 0 ||
     99  1.4.6.2  tls 	    sc->sc_gen.sc_fbsize == 0) {
    100  1.4.6.2  tls 		aprint_normal(": disabled\n");
    101  1.4.6.2  tls 		return;
    102  1.4.6.2  tls 	}
    103  1.4.6.2  tls 
    104  1.4.6.3  tls 	pmf_device_register1(self, NULL, NULL, bcmgenfb_shutdown);
    105  1.4.6.3  tls 
    106  1.4.6.2  tls 	error = bus_space_map(sc->sc_iot, sc->sc_gen.sc_fboffset,
    107  1.4.6.2  tls 	    sc->sc_gen.sc_fbsize,
    108  1.4.6.2  tls 	    BUS_SPACE_MAP_LINEAR|BUS_SPACE_MAP_PREFETCHABLE, &sc->sc_ioh);
    109  1.4.6.2  tls 	if (error) {
    110  1.4.6.2  tls 		aprint_error_dev(self, "couldn't map framebuffer (%d)\n",
    111  1.4.6.2  tls 		    error);
    112  1.4.6.2  tls 		return;
    113  1.4.6.2  tls 	}
    114  1.4.6.2  tls 	sc->sc_gen.sc_fbaddr = bus_space_vaddr(sc->sc_iot, sc->sc_ioh);
    115  1.4.6.2  tls 
    116  1.4.6.2  tls 	memset(&ops, 0, sizeof(ops));
    117  1.4.6.2  tls 	ops.genfb_ioctl = bcmgenfb_ioctl;
    118  1.4.6.2  tls 	ops.genfb_mmap = bcmgenfb_mmap;
    119  1.4.6.2  tls 
    120  1.4.6.2  tls 	aprint_naive("\n");
    121  1.4.6.2  tls 
    122  1.4.6.2  tls 	if (is_console)
    123  1.4.6.2  tls 		aprint_normal(": switching to framebuffer console\n");
    124  1.4.6.2  tls 	else
    125  1.4.6.2  tls 		aprint_normal("\n");
    126  1.4.6.2  tls 
    127  1.4.6.2  tls 	genfb_attach(&sc->sc_gen, &ops);
    128  1.4.6.2  tls }
    129  1.4.6.2  tls 
    130  1.4.6.2  tls static int
    131  1.4.6.2  tls bcmgenfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, lwp_t *l)
    132  1.4.6.2  tls {
    133  1.4.6.2  tls 	struct bcmgenfb_softc *sc = v;
    134  1.4.6.2  tls 	struct wsdisplayio_bus_id *busid;
    135  1.4.6.2  tls 
    136  1.4.6.2  tls 	switch (cmd) {
    137  1.4.6.2  tls 	case WSDISPLAYIO_GTYPE:
    138  1.4.6.2  tls 		*(u_int *)data = sc->sc_wstype;
    139  1.4.6.2  tls 		return 0;
    140  1.4.6.2  tls 	case WSDISPLAYIO_GET_BUSID:
    141  1.4.6.2  tls 		busid = data;
    142  1.4.6.2  tls 		busid->bus_type = WSDISPLAYIO_BUS_SOC;
    143  1.4.6.2  tls 		return 0;
    144  1.4.6.2  tls 	case WSDISPLAYIO_GET_FBINFO:
    145  1.4.6.2  tls 		{
    146  1.4.6.2  tls 			struct wsdisplayio_fbinfo *fbi = data;
    147  1.4.6.2  tls 			struct rasops_info *ri = &sc->sc_gen.vd.active->scr_ri;
    148  1.4.6.2  tls 			int ret;
    149  1.4.6.2  tls 
    150  1.4.6.2  tls 			ret = wsdisplayio_get_fbinfo(ri, fbi);
    151  1.4.6.2  tls 			fbi->fbi_flags |= WSFB_VRAM_IS_RAM;
    152  1.4.6.2  tls 			return ret;
    153  1.4.6.2  tls 		}
    154  1.4.6.2  tls 	default:
    155  1.4.6.2  tls 		return EPASSTHROUGH;
    156  1.4.6.2  tls 	}
    157  1.4.6.2  tls }
    158  1.4.6.2  tls 
    159  1.4.6.2  tls static paddr_t
    160  1.4.6.2  tls bcmgenfb_mmap(void *v, void *vs, off_t offset, int prot)
    161  1.4.6.2  tls {
    162  1.4.6.2  tls 	struct bcmgenfb_softc *sc = v;
    163  1.4.6.2  tls 
    164  1.4.6.2  tls 	if (offset < 0 || offset >= sc->sc_gen.sc_fbsize)
    165  1.4.6.2  tls 		return -1;
    166  1.4.6.2  tls 
    167  1.4.6.2  tls 	return bus_space_mmap(sc->sc_iot, sc->sc_gen.sc_fboffset, offset,
    168  1.4.6.2  tls 	    prot, BUS_SPACE_MAP_LINEAR|BUS_SPACE_MAP_PREFETCHABLE);
    169  1.4.6.2  tls }
    170  1.4.6.3  tls 
    171  1.4.6.3  tls static bool
    172  1.4.6.3  tls bcmgenfb_shutdown(device_t self, int flags)
    173  1.4.6.3  tls {
    174  1.4.6.3  tls 	genfb_enable_polling(self);
    175  1.4.6.3  tls 	return true;
    176  1.4.6.3  tls }
    177  1.4.6.3  tls void
    178  1.4.6.3  tls bcmgenfb_set_console_dev(device_t dev)
    179  1.4.6.3  tls {
    180  1.4.6.3  tls 	KASSERT(bcmgenfb_console_dev == NULL);
    181  1.4.6.3  tls 	bcmgenfb_console_dev = dev;
    182  1.4.6.3  tls }
    183  1.4.6.3  tls 
    184  1.4.6.3  tls void
    185  1.4.6.3  tls bcmgenfb_ddb_trap_callback(int where)
    186  1.4.6.3  tls {
    187  1.4.6.3  tls 	if (bcmgenfb_console_dev == NULL)
    188  1.4.6.3  tls 		return;
    189  1.4.6.3  tls 
    190  1.4.6.3  tls 	if (where) {
    191  1.4.6.3  tls 		genfb_enable_polling(bcmgenfb_console_dev);
    192  1.4.6.3  tls 	} else {
    193  1.4.6.3  tls 		genfb_disable_polling(bcmgenfb_console_dev);
    194  1.4.6.3  tls 	}
    195  1.4.6.3  tls }
    196