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