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