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