bcm2835_genfb.c revision 1.4.6.2 1 1.4.6.2 tls /* $NetBSD: bcm2835_genfb.c,v 1.4.6.2 2013/02/25 00:28:25 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.2 2013/02/25 00:28:25 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.2 tls
62 1.4.6.2 tls CFATTACH_DECL_NEW(bcmgenfb, sizeof(struct bcmgenfb_softc),
63 1.4.6.2 tls bcmgenfb_match, bcmgenfb_attach, NULL, NULL);
64 1.4.6.2 tls
65 1.4.6.2 tls static int
66 1.4.6.2 tls bcmgenfb_match(device_t parent, cfdata_t match, void *aux)
67 1.4.6.2 tls {
68 1.4.6.2 tls struct amba_attach_args *aaa = aux;
69 1.4.6.2 tls
70 1.4.6.2 tls return !strcmp(aaa->aaa_name, "fb");
71 1.4.6.2 tls }
72 1.4.6.2 tls
73 1.4.6.2 tls static void
74 1.4.6.2 tls bcmgenfb_attach(device_t parent, device_t self, void *aux)
75 1.4.6.2 tls {
76 1.4.6.2 tls struct bcmgenfb_softc *sc = device_private(self);
77 1.4.6.2 tls struct amba_attach_args *aaa = aux;
78 1.4.6.2 tls prop_dictionary_t dict = device_properties(self);
79 1.4.6.2 tls struct genfb_ops ops;
80 1.4.6.2 tls bool is_console = false;
81 1.4.6.2 tls int error;
82 1.4.6.2 tls
83 1.4.6.2 tls sc->sc_gen.sc_dev = self;
84 1.4.6.2 tls sc->sc_iot = aaa->aaa_iot;
85 1.4.6.2 tls
86 1.4.6.2 tls sc->sc_wstype = WSDISPLAY_TYPE_VC4;
87 1.4.6.2 tls prop_dictionary_get_uint32(dict, "wsdisplay_type", &sc->sc_wstype);
88 1.4.6.2 tls prop_dictionary_get_bool(dict, "is_console", &is_console);
89 1.4.6.2 tls
90 1.4.6.2 tls genfb_init(&sc->sc_gen);
91 1.4.6.2 tls
92 1.4.6.2 tls if (sc->sc_gen.sc_width == 0 ||
93 1.4.6.2 tls sc->sc_gen.sc_fbsize == 0) {
94 1.4.6.2 tls aprint_normal(": disabled\n");
95 1.4.6.2 tls return;
96 1.4.6.2 tls }
97 1.4.6.2 tls
98 1.4.6.2 tls error = bus_space_map(sc->sc_iot, sc->sc_gen.sc_fboffset,
99 1.4.6.2 tls sc->sc_gen.sc_fbsize,
100 1.4.6.2 tls BUS_SPACE_MAP_LINEAR|BUS_SPACE_MAP_PREFETCHABLE, &sc->sc_ioh);
101 1.4.6.2 tls if (error) {
102 1.4.6.2 tls aprint_error_dev(self, "couldn't map framebuffer (%d)\n",
103 1.4.6.2 tls error);
104 1.4.6.2 tls return;
105 1.4.6.2 tls }
106 1.4.6.2 tls sc->sc_gen.sc_fbaddr = bus_space_vaddr(sc->sc_iot, sc->sc_ioh);
107 1.4.6.2 tls
108 1.4.6.2 tls memset(&ops, 0, sizeof(ops));
109 1.4.6.2 tls ops.genfb_ioctl = bcmgenfb_ioctl;
110 1.4.6.2 tls ops.genfb_mmap = bcmgenfb_mmap;
111 1.4.6.2 tls
112 1.4.6.2 tls aprint_naive("\n");
113 1.4.6.2 tls
114 1.4.6.2 tls if (is_console)
115 1.4.6.2 tls aprint_normal(": switching to framebuffer console\n");
116 1.4.6.2 tls else
117 1.4.6.2 tls aprint_normal("\n");
118 1.4.6.2 tls
119 1.4.6.2 tls genfb_attach(&sc->sc_gen, &ops);
120 1.4.6.2 tls }
121 1.4.6.2 tls
122 1.4.6.2 tls static int
123 1.4.6.2 tls bcmgenfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, lwp_t *l)
124 1.4.6.2 tls {
125 1.4.6.2 tls struct bcmgenfb_softc *sc = v;
126 1.4.6.2 tls struct wsdisplayio_bus_id *busid;
127 1.4.6.2 tls
128 1.4.6.2 tls switch (cmd) {
129 1.4.6.2 tls case WSDISPLAYIO_GTYPE:
130 1.4.6.2 tls *(u_int *)data = sc->sc_wstype;
131 1.4.6.2 tls return 0;
132 1.4.6.2 tls case WSDISPLAYIO_GET_BUSID:
133 1.4.6.2 tls busid = data;
134 1.4.6.2 tls busid->bus_type = WSDISPLAYIO_BUS_SOC;
135 1.4.6.2 tls return 0;
136 1.4.6.2 tls case WSDISPLAYIO_GET_FBINFO:
137 1.4.6.2 tls {
138 1.4.6.2 tls struct wsdisplayio_fbinfo *fbi = data;
139 1.4.6.2 tls struct rasops_info *ri = &sc->sc_gen.vd.active->scr_ri;
140 1.4.6.2 tls int ret;
141 1.4.6.2 tls
142 1.4.6.2 tls ret = wsdisplayio_get_fbinfo(ri, fbi);
143 1.4.6.2 tls fbi->fbi_flags |= WSFB_VRAM_IS_RAM;
144 1.4.6.2 tls return ret;
145 1.4.6.2 tls }
146 1.4.6.2 tls default:
147 1.4.6.2 tls return EPASSTHROUGH;
148 1.4.6.2 tls }
149 1.4.6.2 tls }
150 1.4.6.2 tls
151 1.4.6.2 tls static paddr_t
152 1.4.6.2 tls bcmgenfb_mmap(void *v, void *vs, off_t offset, int prot)
153 1.4.6.2 tls {
154 1.4.6.2 tls struct bcmgenfb_softc *sc = v;
155 1.4.6.2 tls
156 1.4.6.2 tls if (offset < 0 || offset >= sc->sc_gen.sc_fbsize)
157 1.4.6.2 tls return -1;
158 1.4.6.2 tls
159 1.4.6.2 tls return bus_space_mmap(sc->sc_iot, sc->sc_gen.sc_fboffset, offset,
160 1.4.6.2 tls prot, BUS_SPACE_MAP_LINEAR|BUS_SPACE_MAP_PREFETCHABLE);
161 1.4.6.2 tls }
162