meson_genfb.c revision 1.1.2.2 1 1.1.2.2 pgoyette /* $NetBSD: meson_genfb.c,v 1.1.2.2 2019/01/26 21:59:59 pgoyette Exp $ */
2 1.1.2.2 pgoyette
3 1.1.2.2 pgoyette /*-
4 1.1.2.2 pgoyette * Copyright (c) 2015-2019 Jared McNeill <jmcneill (at) invisible.ca>
5 1.1.2.2 pgoyette * All rights reserved.
6 1.1.2.2 pgoyette *
7 1.1.2.2 pgoyette * Redistribution and use in source and binary forms, with or without
8 1.1.2.2 pgoyette * modification, are permitted provided that the following conditions
9 1.1.2.2 pgoyette * are met:
10 1.1.2.2 pgoyette * 1. Redistributions of source code must retain the above copyright
11 1.1.2.2 pgoyette * notice, this list of conditions and the following disclaimer.
12 1.1.2.2 pgoyette * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.2.2 pgoyette * notice, this list of conditions and the following disclaimer in the
14 1.1.2.2 pgoyette * documentation and/or other materials provided with the distribution.
15 1.1.2.2 pgoyette *
16 1.1.2.2 pgoyette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1.2.2 pgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1.2.2 pgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1.2.2 pgoyette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1.2.2 pgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1.2.2 pgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1.2.2 pgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1.2.2 pgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1.2.2 pgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1.2.2 pgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1.2.2 pgoyette * POSSIBILITY OF SUCH DAMAGE.
27 1.1.2.2 pgoyette */
28 1.1.2.2 pgoyette
29 1.1.2.2 pgoyette /*
30 1.1.2.2 pgoyette * Generic framebuffer console driver
31 1.1.2.2 pgoyette */
32 1.1.2.2 pgoyette
33 1.1.2.2 pgoyette #include "opt_wsdisplay_compat.h"
34 1.1.2.2 pgoyette
35 1.1.2.2 pgoyette #include <sys/cdefs.h>
36 1.1.2.2 pgoyette __KERNEL_RCSID(0, "$NetBSD: meson_genfb.c,v 1.1.2.2 2019/01/26 21:59:59 pgoyette Exp $");
37 1.1.2.2 pgoyette
38 1.1.2.2 pgoyette #include <sys/param.h>
39 1.1.2.2 pgoyette #include <sys/types.h>
40 1.1.2.2 pgoyette #include <sys/systm.h>
41 1.1.2.2 pgoyette #include <sys/device.h>
42 1.1.2.2 pgoyette #include <sys/conf.h>
43 1.1.2.2 pgoyette #include <sys/bus.h>
44 1.1.2.2 pgoyette #include <sys/kmem.h>
45 1.1.2.2 pgoyette #include <sys/sysctl.h>
46 1.1.2.2 pgoyette
47 1.1.2.2 pgoyette #include <dev/fdt/fdtvar.h>
48 1.1.2.2 pgoyette
49 1.1.2.2 pgoyette #include <arm/amlogic/meson_canvasreg.h>
50 1.1.2.2 pgoyette #include <arm/amlogic/meson_vpureg.h>
51 1.1.2.2 pgoyette #include <arm/amlogic/meson_hdmireg.h>
52 1.1.2.2 pgoyette
53 1.1.2.2 pgoyette #include <dev/wsfb/genfbvar.h>
54 1.1.2.2 pgoyette
55 1.1.2.2 pgoyette static const char * const compatible[] = {
56 1.1.2.2 pgoyette "amlogic,meson8b-fb",
57 1.1.2.2 pgoyette NULL
58 1.1.2.2 pgoyette };
59 1.1.2.2 pgoyette
60 1.1.2.2 pgoyette #define AMLOGIC_GENFB_DEFAULT_DEPTH 16
61 1.1.2.2 pgoyette
62 1.1.2.2 pgoyette /* Map CEA-861-D video code (VIC) to framebuffer dimensions */
63 1.1.2.2 pgoyette static const struct meson_genfb_vic2mode {
64 1.1.2.2 pgoyette u_int vic;
65 1.1.2.2 pgoyette u_int width;
66 1.1.2.2 pgoyette u_int height;
67 1.1.2.2 pgoyette u_int flags;
68 1.1.2.2 pgoyette #define INTERLACE __BIT(0)
69 1.1.2.2 pgoyette #define DBLSCAN __BIT(1)
70 1.1.2.2 pgoyette } meson_genfb_modes[] = {
71 1.1.2.2 pgoyette { 1, 640, 480 },
72 1.1.2.2 pgoyette { 2, 720, 480 },
73 1.1.2.2 pgoyette { 3, 720, 480 },
74 1.1.2.2 pgoyette { 4, 1280, 720 },
75 1.1.2.2 pgoyette { 5, 1920, 1080, INTERLACE },
76 1.1.2.2 pgoyette { 6, 720, 480, DBLSCAN | INTERLACE },
77 1.1.2.2 pgoyette { 7, 720, 480, DBLSCAN | INTERLACE },
78 1.1.2.2 pgoyette { 8, 720, 240, DBLSCAN },
79 1.1.2.2 pgoyette { 9, 720, 240, DBLSCAN },
80 1.1.2.2 pgoyette { 16, 1920, 1080 },
81 1.1.2.2 pgoyette { 17, 720, 576 },
82 1.1.2.2 pgoyette { 18, 720, 576 },
83 1.1.2.2 pgoyette { 19, 1280, 720 },
84 1.1.2.2 pgoyette { 20, 1920, 1080, INTERLACE },
85 1.1.2.2 pgoyette { 31, 1920, 1080 },
86 1.1.2.2 pgoyette { 32, 1920, 1080 },
87 1.1.2.2 pgoyette { 33, 1920, 1080 },
88 1.1.2.2 pgoyette { 34, 1920, 1080 },
89 1.1.2.2 pgoyette { 39, 1920, 1080, INTERLACE },
90 1.1.2.2 pgoyette };
91 1.1.2.2 pgoyette
92 1.1.2.2 pgoyette struct meson_genfb_softc {
93 1.1.2.2 pgoyette struct genfb_softc sc_gen;
94 1.1.2.2 pgoyette bus_space_tag_t sc_bst;
95 1.1.2.2 pgoyette bus_space_handle_t sc_cav_bsh;
96 1.1.2.2 pgoyette bus_space_handle_t sc_hdmi_bsh;
97 1.1.2.2 pgoyette bus_space_handle_t sc_vpu_bsh;
98 1.1.2.2 pgoyette bus_dma_tag_t sc_dmat;
99 1.1.2.2 pgoyette
100 1.1.2.2 pgoyette kmutex_t sc_lock;
101 1.1.2.2 pgoyette
102 1.1.2.2 pgoyette u_int sc_scale;
103 1.1.2.2 pgoyette
104 1.1.2.2 pgoyette bus_dma_segment_t sc_dmasegs[1];
105 1.1.2.2 pgoyette bus_size_t sc_dmasize;
106 1.1.2.2 pgoyette bus_dmamap_t sc_dmamap;
107 1.1.2.2 pgoyette void *sc_dmap;
108 1.1.2.2 pgoyette
109 1.1.2.2 pgoyette uint32_t sc_wstype;
110 1.1.2.2 pgoyette
111 1.1.2.2 pgoyette struct sysctllog *sc_sysctllog;
112 1.1.2.2 pgoyette int sc_node_scale;
113 1.1.2.2 pgoyette };
114 1.1.2.2 pgoyette
115 1.1.2.2 pgoyette static int meson_genfb_match(device_t, cfdata_t, void *);
116 1.1.2.2 pgoyette static void meson_genfb_attach(device_t, device_t, void *);
117 1.1.2.2 pgoyette
118 1.1.2.2 pgoyette static int meson_genfb_ioctl(void *, void *, u_long, void *, int, lwp_t *);
119 1.1.2.2 pgoyette static paddr_t meson_genfb_mmap(void *, void *, off_t, int);
120 1.1.2.2 pgoyette static bool meson_genfb_shutdown(device_t, int);
121 1.1.2.2 pgoyette
122 1.1.2.2 pgoyette static void meson_genfb_canvas_config(struct meson_genfb_softc *);
123 1.1.2.2 pgoyette static void meson_genfb_osd_config(struct meson_genfb_softc *);
124 1.1.2.2 pgoyette static void meson_genfb_scaler_config(struct meson_genfb_softc *);
125 1.1.2.2 pgoyette
126 1.1.2.2 pgoyette static void meson_genfb_init(struct meson_genfb_softc *);
127 1.1.2.2 pgoyette static int meson_genfb_alloc_videomem(struct meson_genfb_softc *);
128 1.1.2.2 pgoyette
129 1.1.2.2 pgoyette static int meson_genfb_scale_helper(SYSCTLFN_PROTO);
130 1.1.2.2 pgoyette
131 1.1.2.2 pgoyette void meson_genfb_set_console_dev(device_t);
132 1.1.2.2 pgoyette void meson_genfb_ddb_trap_callback(int);
133 1.1.2.2 pgoyette
134 1.1.2.2 pgoyette static int meson_genfb_console_phandle = -1;
135 1.1.2.2 pgoyette static device_t meson_genfb_console_dev = NULL;
136 1.1.2.2 pgoyette
137 1.1.2.2 pgoyette CFATTACH_DECL_NEW(meson_genfb, sizeof(struct meson_genfb_softc),
138 1.1.2.2 pgoyette meson_genfb_match, meson_genfb_attach, NULL, NULL);
139 1.1.2.2 pgoyette
140 1.1.2.2 pgoyette static inline uint32_t
141 1.1.2.2 pgoyette meson_genfb_hdmi_read_4(struct meson_genfb_softc *sc, uint32_t addr)
142 1.1.2.2 pgoyette {
143 1.1.2.2 pgoyette bus_space_write_4(sc->sc_bst, sc->sc_hdmi_bsh, HDMI_ADDR_REG, addr);
144 1.1.2.2 pgoyette bus_space_write_4(sc->sc_bst, sc->sc_hdmi_bsh, HDMI_ADDR_REG, addr);
145 1.1.2.2 pgoyette return bus_space_read_4(sc->sc_bst, sc->sc_hdmi_bsh, HDMI_DATA_REG);
146 1.1.2.2 pgoyette }
147 1.1.2.2 pgoyette
148 1.1.2.2 pgoyette static __unused inline void
149 1.1.2.2 pgoyette meson_genfb_hdmi_write_4(struct meson_genfb_softc *sc, uint32_t addr,
150 1.1.2.2 pgoyette uint32_t data)
151 1.1.2.2 pgoyette {
152 1.1.2.2 pgoyette bus_space_write_4(sc->sc_bst, sc->sc_hdmi_bsh, HDMI_ADDR_REG, addr);
153 1.1.2.2 pgoyette bus_space_write_4(sc->sc_bst, sc->sc_hdmi_bsh, HDMI_ADDR_REG, addr);
154 1.1.2.2 pgoyette bus_space_write_4(sc->sc_bst, sc->sc_hdmi_bsh, HDMI_DATA_REG, data);
155 1.1.2.2 pgoyette }
156 1.1.2.2 pgoyette
157 1.1.2.2 pgoyette #define HDMI_READ meson_genfb_hdmi_read_4
158 1.1.2.2 pgoyette #define HDMI_WRITE meson_genfb_hdmi_write_4
159 1.1.2.2 pgoyette
160 1.1.2.2 pgoyette #define VPU_READ(sc, reg) \
161 1.1.2.2 pgoyette bus_space_read_4((sc)->sc_bst, (sc)->sc_vpu_bsh, (reg))
162 1.1.2.2 pgoyette #define VPU_WRITE(sc, reg, val) \
163 1.1.2.2 pgoyette bus_space_write_4((sc)->sc_bst, (sc)->sc_vpu_bsh, (reg), (val))
164 1.1.2.2 pgoyette
165 1.1.2.2 pgoyette #define CAV_READ(sc, reg) \
166 1.1.2.2 pgoyette bus_space_read_4((sc)->sc_bst, (sc)->sc_cav_bsh, (reg))
167 1.1.2.2 pgoyette #define CAV_WRITE(sc, reg, val) \
168 1.1.2.2 pgoyette bus_space_write_4((sc)->sc_bst, (sc)->sc_cav_bsh, (reg), (val))
169 1.1.2.2 pgoyette
170 1.1.2.2 pgoyette static int
171 1.1.2.2 pgoyette meson_genfb_match(device_t parent, cfdata_t match, void *aux)
172 1.1.2.2 pgoyette {
173 1.1.2.2 pgoyette struct fdt_attach_args * const faa = aux;
174 1.1.2.2 pgoyette
175 1.1.2.2 pgoyette return of_match_compatible(faa->faa_phandle, compatible);
176 1.1.2.2 pgoyette }
177 1.1.2.2 pgoyette
178 1.1.2.2 pgoyette static void
179 1.1.2.2 pgoyette meson_genfb_attach(device_t parent, device_t self, void *aux)
180 1.1.2.2 pgoyette {
181 1.1.2.2 pgoyette struct meson_genfb_softc *sc = device_private(self);
182 1.1.2.2 pgoyette struct fdt_attach_args * const faa = aux;
183 1.1.2.2 pgoyette const int phandle = faa->faa_phandle;
184 1.1.2.2 pgoyette prop_dictionary_t dict = device_properties(self);
185 1.1.2.2 pgoyette static const struct genfb_ops zero_ops;
186 1.1.2.2 pgoyette struct genfb_ops ops = zero_ops;
187 1.1.2.2 pgoyette bus_addr_t addr[3];
188 1.1.2.2 pgoyette bus_size_t size[3];
189 1.1.2.2 pgoyette
190 1.1.2.2 pgoyette for (int i = 0; i < 3; i++) {
191 1.1.2.2 pgoyette if (fdtbus_get_reg(phandle, i, &addr[i], &size[i]) != 0) {
192 1.1.2.2 pgoyette aprint_error(": couldn't get register #%d\n", i);
193 1.1.2.2 pgoyette return;
194 1.1.2.2 pgoyette }
195 1.1.2.2 pgoyette }
196 1.1.2.2 pgoyette
197 1.1.2.2 pgoyette sc->sc_gen.sc_dev = self;
198 1.1.2.2 pgoyette sc->sc_bst = faa->faa_bst;
199 1.1.2.2 pgoyette sc->sc_dmat = faa->faa_dmat;
200 1.1.2.2 pgoyette if (bus_space_map(sc->sc_bst, addr[0], size[0], 0, &sc->sc_cav_bsh) != 0 ||
201 1.1.2.2 pgoyette bus_space_map(sc->sc_bst, addr[1], size[1], 0, &sc->sc_hdmi_bsh) != 0 ||
202 1.1.2.2 pgoyette bus_space_map(sc->sc_bst, addr[2], size[2], 0, &sc->sc_vpu_bsh) != 0) {
203 1.1.2.2 pgoyette aprint_error(": couldn't map registers\n");
204 1.1.2.2 pgoyette return;
205 1.1.2.2 pgoyette }
206 1.1.2.2 pgoyette mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
207 1.1.2.2 pgoyette
208 1.1.2.2 pgoyette meson_genfb_init(sc);
209 1.1.2.2 pgoyette
210 1.1.2.2 pgoyette sc->sc_wstype = WSDISPLAY_TYPE_MESON;
211 1.1.2.2 pgoyette
212 1.1.2.2 pgoyette aprint_naive("\n");
213 1.1.2.2 pgoyette aprint_normal("\n");
214 1.1.2.2 pgoyette
215 1.1.2.2 pgoyette genfb_init(&sc->sc_gen);
216 1.1.2.2 pgoyette
217 1.1.2.2 pgoyette if (sc->sc_gen.sc_width == 0 ||
218 1.1.2.2 pgoyette sc->sc_gen.sc_fbsize == 0) {
219 1.1.2.2 pgoyette aprint_normal_dev(self, "disabled\n");
220 1.1.2.2 pgoyette return;
221 1.1.2.2 pgoyette }
222 1.1.2.2 pgoyette
223 1.1.2.2 pgoyette pmf_device_register1(self, NULL, NULL, meson_genfb_shutdown);
224 1.1.2.2 pgoyette
225 1.1.2.2 pgoyette #ifdef WSDISPLAY_MULTICONS
226 1.1.2.2 pgoyette const bool is_console = true;
227 1.1.2.2 pgoyette #else
228 1.1.2.2 pgoyette const bool is_console = phandle == meson_genfb_console_phandle;
229 1.1.2.2 pgoyette if (is_console)
230 1.1.2.2 pgoyette aprint_normal_dev(self, "switching to framebuffer console\n");
231 1.1.2.2 pgoyette #endif
232 1.1.2.2 pgoyette prop_dictionary_set_bool(dict, "is_console", is_console);
233 1.1.2.2 pgoyette
234 1.1.2.2 pgoyette memset(&ops, 0, sizeof(ops));
235 1.1.2.2 pgoyette ops.genfb_ioctl = meson_genfb_ioctl;
236 1.1.2.2 pgoyette ops.genfb_mmap = meson_genfb_mmap;
237 1.1.2.2 pgoyette
238 1.1.2.2 pgoyette genfb_attach(&sc->sc_gen, &ops);
239 1.1.2.2 pgoyette }
240 1.1.2.2 pgoyette
241 1.1.2.2 pgoyette static int
242 1.1.2.2 pgoyette meson_genfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, lwp_t *l)
243 1.1.2.2 pgoyette {
244 1.1.2.2 pgoyette struct meson_genfb_softc *sc = v;
245 1.1.2.2 pgoyette struct wsdisplayio_bus_id *busid;
246 1.1.2.2 pgoyette
247 1.1.2.2 pgoyette switch (cmd) {
248 1.1.2.2 pgoyette case WSDISPLAYIO_GTYPE:
249 1.1.2.2 pgoyette *(u_int *)data = sc->sc_wstype;
250 1.1.2.2 pgoyette return 0;
251 1.1.2.2 pgoyette case WSDISPLAYIO_GET_BUSID:
252 1.1.2.2 pgoyette busid = data;
253 1.1.2.2 pgoyette busid->bus_type = WSDISPLAYIO_BUS_SOC;
254 1.1.2.2 pgoyette return 0;
255 1.1.2.2 pgoyette case WSDISPLAYIO_GET_FBINFO:
256 1.1.2.2 pgoyette {
257 1.1.2.2 pgoyette struct wsdisplayio_fbinfo *fbi = data;
258 1.1.2.2 pgoyette struct rasops_info *ri = &sc->sc_gen.vd.active->scr_ri;
259 1.1.2.2 pgoyette int ret;
260 1.1.2.2 pgoyette
261 1.1.2.2 pgoyette ret = wsdisplayio_get_fbinfo(ri, fbi);
262 1.1.2.2 pgoyette fbi->fbi_flags |= WSFB_VRAM_IS_RAM;
263 1.1.2.2 pgoyette return ret;
264 1.1.2.2 pgoyette }
265 1.1.2.2 pgoyette default:
266 1.1.2.2 pgoyette return EPASSTHROUGH;
267 1.1.2.2 pgoyette }
268 1.1.2.2 pgoyette }
269 1.1.2.2 pgoyette
270 1.1.2.2 pgoyette static paddr_t
271 1.1.2.2 pgoyette meson_genfb_mmap(void *v, void *vs, off_t offset, int prot)
272 1.1.2.2 pgoyette {
273 1.1.2.2 pgoyette struct meson_genfb_softc *sc = v;
274 1.1.2.2 pgoyette
275 1.1.2.2 pgoyette if (offset < 0 || offset >= sc->sc_dmasegs[0].ds_len)
276 1.1.2.2 pgoyette return -1;
277 1.1.2.2 pgoyette
278 1.1.2.2 pgoyette return bus_dmamem_mmap(sc->sc_dmat, sc->sc_dmasegs, 1,
279 1.1.2.2 pgoyette offset, prot, BUS_DMA_PREFETCHABLE);
280 1.1.2.2 pgoyette }
281 1.1.2.2 pgoyette
282 1.1.2.2 pgoyette static bool
283 1.1.2.2 pgoyette meson_genfb_shutdown(device_t self, int flags)
284 1.1.2.2 pgoyette {
285 1.1.2.2 pgoyette genfb_enable_polling(self);
286 1.1.2.2 pgoyette return true;
287 1.1.2.2 pgoyette }
288 1.1.2.2 pgoyette
289 1.1.2.2 pgoyette static void
290 1.1.2.2 pgoyette meson_genfb_canvas_config(struct meson_genfb_softc *sc)
291 1.1.2.2 pgoyette {
292 1.1.2.2 pgoyette prop_dictionary_t cfg = device_properties(sc->sc_gen.sc_dev);
293 1.1.2.2 pgoyette const paddr_t pa = sc->sc_dmamap->dm_segs[0].ds_addr;
294 1.1.2.2 pgoyette uint32_t datal, datah, addr;
295 1.1.2.2 pgoyette u_int width, height, depth;
296 1.1.2.2 pgoyette
297 1.1.2.2 pgoyette prop_dictionary_get_uint32(cfg, "width", &width);
298 1.1.2.2 pgoyette prop_dictionary_get_uint32(cfg, "height", &height);
299 1.1.2.2 pgoyette prop_dictionary_get_uint32(cfg, "depth", &depth);
300 1.1.2.2 pgoyette
301 1.1.2.2 pgoyette const uint32_t w = (width * (depth/8)) >> 3;
302 1.1.2.2 pgoyette const uint32_t h = height;
303 1.1.2.2 pgoyette
304 1.1.2.2 pgoyette datal = CAV_READ(sc, DC_CAV_LUT_DATAL_REG);
305 1.1.2.2 pgoyette datah = CAV_READ(sc, DC_CAV_LUT_DATAH_REG);
306 1.1.2.2 pgoyette addr = CAV_READ(sc, DC_CAV_LUT_ADDR_REG);
307 1.1.2.2 pgoyette
308 1.1.2.2 pgoyette datal &= ~DC_CAV_LUT_DATAL_WIDTH_L;
309 1.1.2.2 pgoyette datal |= __SHIFTIN(w & 7, DC_CAV_LUT_DATAL_WIDTH_L);
310 1.1.2.2 pgoyette datal &= ~DC_CAV_LUT_DATAL_FBADDR;
311 1.1.2.2 pgoyette datal |= __SHIFTIN(pa >> 3, DC_CAV_LUT_DATAL_FBADDR);
312 1.1.2.2 pgoyette CAV_WRITE(sc, DC_CAV_LUT_DATAL_REG, datal);
313 1.1.2.2 pgoyette
314 1.1.2.2 pgoyette datah &= ~DC_CAV_LUT_DATAH_BLKMODE;
315 1.1.2.2 pgoyette datah |= __SHIFTIN(DC_CAV_LUT_DATAH_BLKMODE_LINEAR,
316 1.1.2.2 pgoyette DC_CAV_LUT_DATAH_BLKMODE);
317 1.1.2.2 pgoyette datah &= ~DC_CAV_LUT_DATAH_WIDTH_H;
318 1.1.2.2 pgoyette datah |= __SHIFTIN(w >> 3, DC_CAV_LUT_DATAH_WIDTH_H);
319 1.1.2.2 pgoyette datah &= ~DC_CAV_LUT_DATAH_HEIGHT;
320 1.1.2.2 pgoyette datah |= __SHIFTIN(h, DC_CAV_LUT_DATAH_HEIGHT);
321 1.1.2.2 pgoyette CAV_WRITE(sc, DC_CAV_LUT_DATAH_REG, datah);
322 1.1.2.2 pgoyette
323 1.1.2.2 pgoyette addr |= DC_CAV_LUT_ADDR_WR_EN;
324 1.1.2.2 pgoyette CAV_WRITE(sc, DC_CAV_LUT_ADDR_REG, addr);
325 1.1.2.2 pgoyette }
326 1.1.2.2 pgoyette
327 1.1.2.2 pgoyette static void
328 1.1.2.2 pgoyette meson_genfb_osd_config(struct meson_genfb_softc *sc)
329 1.1.2.2 pgoyette {
330 1.1.2.2 pgoyette prop_dictionary_t cfg = device_properties(sc->sc_gen.sc_dev);
331 1.1.2.2 pgoyette uint32_t cs, tc, w0, w1, w2, w3, w4;
332 1.1.2.2 pgoyette u_int width, height, depth;
333 1.1.2.2 pgoyette bool interlace_p;
334 1.1.2.2 pgoyette
335 1.1.2.2 pgoyette prop_dictionary_get_uint32(cfg, "width", &width);
336 1.1.2.2 pgoyette prop_dictionary_get_uint32(cfg, "height", &height);
337 1.1.2.2 pgoyette prop_dictionary_get_uint32(cfg, "depth", &depth);
338 1.1.2.2 pgoyette prop_dictionary_get_bool(cfg, "interlace", &interlace_p);
339 1.1.2.2 pgoyette
340 1.1.2.2 pgoyette cs = VPU_READ(sc, VIU_OSD2_CTRL_STAT_REG);
341 1.1.2.2 pgoyette cs |= VIU_OSD_CTRL_STAT_ENABLE;
342 1.1.2.2 pgoyette cs &= ~VIU_OSD_CTRL_STAT_GLOBAL_ALPHA;
343 1.1.2.2 pgoyette cs |= __SHIFTIN(0xff, VIU_OSD_CTRL_STAT_GLOBAL_ALPHA);
344 1.1.2.2 pgoyette cs |= VIU_OSD_CTRL_STAT_BLK0_ENABLE;
345 1.1.2.2 pgoyette cs &= ~VIU_OSD_CTRL_STAT_BLK1_ENABLE;
346 1.1.2.2 pgoyette cs &= ~VIU_OSD_CTRL_STAT_BLK2_ENABLE;
347 1.1.2.2 pgoyette cs &= ~VIU_OSD_CTRL_STAT_BLK3_ENABLE;
348 1.1.2.2 pgoyette VPU_WRITE(sc, VIU_OSD2_CTRL_STAT_REG, cs);
349 1.1.2.2 pgoyette
350 1.1.2.2 pgoyette tc = __SHIFTIN(0, VIU_OSD_TCOLOR_R) |
351 1.1.2.2 pgoyette __SHIFTIN(0, VIU_OSD_TCOLOR_G) |
352 1.1.2.2 pgoyette __SHIFTIN(0, VIU_OSD_TCOLOR_B) |
353 1.1.2.2 pgoyette __SHIFTIN(255, VIU_OSD_TCOLOR_A);
354 1.1.2.2 pgoyette VPU_WRITE(sc, VIU_OSD2_TCOLOR_AG0_REG, tc);
355 1.1.2.2 pgoyette
356 1.1.2.2 pgoyette w0 = VPU_READ(sc, VIU_OSD2_BLK0_CFG_W0_REG);
357 1.1.2.2 pgoyette w0 |= VIU_OSD_BLK_CFG_W0_RGB_EN;
358 1.1.2.2 pgoyette w0 &= ~VIU_OSD_BLK_CFG_W0_TC_ALPHA_EN;
359 1.1.2.2 pgoyette w0 &= ~VIU_OSD_BLK_CFG_W0_OSD_BLK_MODE;
360 1.1.2.2 pgoyette w0 &= ~VIU_OSD_BLK_CFG_W0_COLOR_MATRIX;
361 1.1.2.2 pgoyette switch (depth) {
362 1.1.2.2 pgoyette case 32:
363 1.1.2.2 pgoyette w0 |= __SHIFTIN(VIU_OSD_BLK_CFG_W0_OSD_BLK_MODE_32BPP,
364 1.1.2.2 pgoyette VIU_OSD_BLK_CFG_W0_OSD_BLK_MODE);
365 1.1.2.2 pgoyette w0 |= __SHIFTIN(VIU_OSD_BLK_CFG_W0_COLOR_MATRIX_ARGB,
366 1.1.2.2 pgoyette VIU_OSD_BLK_CFG_W0_COLOR_MATRIX);
367 1.1.2.2 pgoyette break;
368 1.1.2.2 pgoyette case 24:
369 1.1.2.2 pgoyette w0 |= __SHIFTIN(VIU_OSD_BLK_CFG_W0_OSD_BLK_MODE_24BPP,
370 1.1.2.2 pgoyette VIU_OSD_BLK_CFG_W0_OSD_BLK_MODE);
371 1.1.2.2 pgoyette w0 |= __SHIFTIN(VIU_OSD_BLK_CFG_W0_COLOR_MATRIX_RGB,
372 1.1.2.2 pgoyette VIU_OSD_BLK_CFG_W0_COLOR_MATRIX);
373 1.1.2.2 pgoyette break;
374 1.1.2.2 pgoyette case 16:
375 1.1.2.2 pgoyette w0 |= __SHIFTIN(VIU_OSD_BLK_CFG_W0_OSD_BLK_MODE_16BPP,
376 1.1.2.2 pgoyette VIU_OSD_BLK_CFG_W0_OSD_BLK_MODE);
377 1.1.2.2 pgoyette w0 |= __SHIFTIN(VIU_OSD_BLK_CFG_W0_COLOR_MATRIX_RGB565,
378 1.1.2.2 pgoyette VIU_OSD_BLK_CFG_W0_COLOR_MATRIX);
379 1.1.2.2 pgoyette break;
380 1.1.2.2 pgoyette }
381 1.1.2.2 pgoyette w0 |= VIU_OSD_BLK_CFG_W0_LITTLE_ENDIAN;
382 1.1.2.2 pgoyette w0 &= ~VIU_OSD_BLK_CFG_W0_RPT_Y;
383 1.1.2.2 pgoyette w0 &= ~VIU_OSD_BLK_CFG_W0_INTERP_CTRL;
384 1.1.2.2 pgoyette if (interlace_p) {
385 1.1.2.2 pgoyette w0 |= VIU_OSD_BLK_CFG_W0_INTERLACE_EN;
386 1.1.2.2 pgoyette } else {
387 1.1.2.2 pgoyette w0 &= ~VIU_OSD_BLK_CFG_W0_INTERLACE_EN;
388 1.1.2.2 pgoyette }
389 1.1.2.2 pgoyette VPU_WRITE(sc, VIU_OSD2_BLK0_CFG_W0_REG, w0);
390 1.1.2.2 pgoyette
391 1.1.2.2 pgoyette w1 = __SHIFTIN(width - 1, VIU_OSD_BLK_CFG_W1_X_END) |
392 1.1.2.2 pgoyette __SHIFTIN(0, VIU_OSD_BLK_CFG_W1_X_START);
393 1.1.2.2 pgoyette w2 = __SHIFTIN(height - 1, VIU_OSD_BLK_CFG_W2_Y_END) |
394 1.1.2.2 pgoyette __SHIFTIN(0, VIU_OSD_BLK_CFG_W2_Y_START);
395 1.1.2.2 pgoyette w3 = __SHIFTIN(width - 1, VIU_OSD_BLK_CFG_W3_H_END) |
396 1.1.2.2 pgoyette __SHIFTIN(0, VIU_OSD_BLK_CFG_W3_H_START);
397 1.1.2.2 pgoyette w4 = __SHIFTIN(height - 1, VIU_OSD_BLK_CFG_W4_V_END) |
398 1.1.2.2 pgoyette __SHIFTIN(0, VIU_OSD_BLK_CFG_W4_V_START);
399 1.1.2.2 pgoyette
400 1.1.2.2 pgoyette VPU_WRITE(sc, VIU_OSD2_BLK0_CFG_W1_REG, w1);
401 1.1.2.2 pgoyette VPU_WRITE(sc, VIU_OSD2_BLK0_CFG_W2_REG, w2);
402 1.1.2.2 pgoyette VPU_WRITE(sc, VIU_OSD2_BLK0_CFG_W3_REG, w3);
403 1.1.2.2 pgoyette VPU_WRITE(sc, VIU_OSD2_BLK0_CFG_W4_REG, w4);
404 1.1.2.2 pgoyette }
405 1.1.2.2 pgoyette
406 1.1.2.2 pgoyette static void
407 1.1.2.2 pgoyette meson_genfb_scaler_config(struct meson_genfb_softc *sc)
408 1.1.2.2 pgoyette {
409 1.1.2.2 pgoyette prop_dictionary_t cfg = device_properties(sc->sc_gen.sc_dev);
410 1.1.2.2 pgoyette uint32_t scctl, sci_wh, sco_h, sco_v, hsc, vsc, hps, vps, hip, vip;
411 1.1.2.2 pgoyette u_int width, height;
412 1.1.2.2 pgoyette bool interlace_p;
413 1.1.2.2 pgoyette
414 1.1.2.2 pgoyette prop_dictionary_get_uint32(cfg, "width", &width);
415 1.1.2.2 pgoyette prop_dictionary_get_uint32(cfg, "height", &height);
416 1.1.2.2 pgoyette prop_dictionary_get_bool(cfg, "interlace", &interlace_p);
417 1.1.2.2 pgoyette
418 1.1.2.2 pgoyette const u_int scale = sc->sc_scale;
419 1.1.2.2 pgoyette const u_int dst_w = (width * scale) / 100;
420 1.1.2.2 pgoyette const u_int dst_h = (height * scale) / 100;
421 1.1.2.2 pgoyette const u_int margin_w = (width - dst_w) / 2;
422 1.1.2.2 pgoyette const u_int margin_h = (height - dst_h) / 2;
423 1.1.2.2 pgoyette const bool scale_p = scale != 100;
424 1.1.2.2 pgoyette
425 1.1.2.2 pgoyette VPU_WRITE(sc, VPP_OSD_SC_DUMMY_DATA_REG, 0x00808000);
426 1.1.2.2 pgoyette
427 1.1.2.2 pgoyette scctl = VPU_READ(sc, VPP_OSD_SC_CTRL0_REG);
428 1.1.2.2 pgoyette scctl |= VPP_OSD_SC_CTRL0_OSD_SC_PATH_EN;
429 1.1.2.2 pgoyette scctl &= ~VPP_OSD_SC_CTRL0_OSD_SC_SEL;
430 1.1.2.2 pgoyette scctl |= __SHIFTIN(1, VPP_OSD_SC_CTRL0_OSD_SC_SEL); /* OSD2 */
431 1.1.2.2 pgoyette scctl &= ~VPP_OSD_SC_CTRL0_DEFAULT_ALPHA;
432 1.1.2.2 pgoyette scctl |= __SHIFTIN(0, VPP_OSD_SC_CTRL0_DEFAULT_ALPHA);
433 1.1.2.2 pgoyette VPU_WRITE(sc, VPP_OSD_SC_CTRL0_REG, scctl);
434 1.1.2.2 pgoyette
435 1.1.2.2 pgoyette sci_wh = __SHIFTIN(width - 1, VPP_OSD_SCI_WH_M1_WIDTH) |
436 1.1.2.2 pgoyette __SHIFTIN((height >> interlace_p) - 1, VPP_OSD_SCI_WH_M1_HEIGHT);
437 1.1.2.2 pgoyette sco_h = __SHIFTIN(margin_w, VPP_OSD_SCO_H_START) |
438 1.1.2.2 pgoyette __SHIFTIN(width - margin_w - 1, VPP_OSD_SCO_H_END);
439 1.1.2.2 pgoyette sco_v = __SHIFTIN(margin_h >> interlace_p, VPP_OSD_SCO_V_START) |
440 1.1.2.2 pgoyette __SHIFTIN(((height - margin_h) >> interlace_p) - 1,
441 1.1.2.2 pgoyette VPP_OSD_SCO_V_END);
442 1.1.2.2 pgoyette
443 1.1.2.2 pgoyette VPU_WRITE(sc, VPP_OSD_SCI_WH_M1_REG, sci_wh);
444 1.1.2.2 pgoyette VPU_WRITE(sc, VPP_OSD_SCO_H_REG, sco_h);
445 1.1.2.2 pgoyette VPU_WRITE(sc, VPP_OSD_SCO_V_REG, sco_v);
446 1.1.2.2 pgoyette
447 1.1.2.2 pgoyette /* horizontal scaling */
448 1.1.2.2 pgoyette hsc = VPU_READ(sc, VPP_OSD_HSC_CTRL0_REG);
449 1.1.2.2 pgoyette if (scale_p) {
450 1.1.2.2 pgoyette hsc &= ~VPP_OSD_HSC_CTRL0_BANK_LENGTH;
451 1.1.2.2 pgoyette hsc |= __SHIFTIN(4, VPP_OSD_HSC_CTRL0_BANK_LENGTH);
452 1.1.2.2 pgoyette hsc &= ~VPP_OSD_HSC_CTRL0_INI_RCV_NUM0;
453 1.1.2.2 pgoyette hsc |= __SHIFTIN(4, VPP_OSD_HSC_CTRL0_INI_RCV_NUM0);
454 1.1.2.2 pgoyette hsc &= ~VPP_OSD_HSC_CTRL0_RPT_P0_NUM0;
455 1.1.2.2 pgoyette hsc |= __SHIFTIN(1, VPP_OSD_HSC_CTRL0_RPT_P0_NUM0);
456 1.1.2.2 pgoyette hsc |= VPP_OSD_HSC_CTRL0_HSCALE_EN;
457 1.1.2.2 pgoyette } else {
458 1.1.2.2 pgoyette hsc &= ~VPP_OSD_HSC_CTRL0_HSCALE_EN;
459 1.1.2.2 pgoyette }
460 1.1.2.2 pgoyette VPU_WRITE(sc, VPP_OSD_HSC_CTRL0_REG, hsc);
461 1.1.2.2 pgoyette
462 1.1.2.2 pgoyette /* vertical scaling */
463 1.1.2.2 pgoyette vsc = VPU_READ(sc, VPP_OSD_VSC_CTRL0_REG);
464 1.1.2.2 pgoyette if (scale_p) {
465 1.1.2.2 pgoyette vsc &= ~VPP_OSD_VSC_CTRL0_BANK_LENGTH;
466 1.1.2.2 pgoyette vsc |= __SHIFTIN(4, VPP_OSD_VSC_CTRL0_BANK_LENGTH);
467 1.1.2.2 pgoyette vsc &= ~VPP_OSD_VSC_CTRL0_TOP_INI_RCV_NUM0;
468 1.1.2.2 pgoyette vsc |= __SHIFTIN(4, VPP_OSD_VSC_CTRL0_TOP_INI_RCV_NUM0);
469 1.1.2.2 pgoyette vsc &= ~VPP_OSD_VSC_CTRL0_TOP_RPT_P0_NUM0;
470 1.1.2.2 pgoyette vsc |= __SHIFTIN(1, VPP_OSD_VSC_CTRL0_TOP_RPT_P0_NUM0);
471 1.1.2.2 pgoyette vsc &= ~VPP_OSD_VSC_CTRL0_BOT_INI_RCV_NUM0;
472 1.1.2.2 pgoyette vsc &= ~VPP_OSD_VSC_CTRL0_BOT_RPT_P0_NUM0;
473 1.1.2.2 pgoyette vsc &= ~VPP_OSC_VSC_CTRL0_INTERLACE;
474 1.1.2.2 pgoyette if (interlace_p) {
475 1.1.2.2 pgoyette /* interlace */
476 1.1.2.2 pgoyette vsc |= VPP_OSC_VSC_CTRL0_INTERLACE;
477 1.1.2.2 pgoyette vsc |= __SHIFTIN(6, VPP_OSD_VSC_CTRL0_BOT_INI_RCV_NUM0);
478 1.1.2.2 pgoyette vsc |= __SHIFTIN(2, VPP_OSD_VSC_CTRL0_BOT_RPT_P0_NUM0);
479 1.1.2.2 pgoyette }
480 1.1.2.2 pgoyette vsc |= VPP_OSD_VSC_CTRL0_VSCALE_EN;
481 1.1.2.2 pgoyette } else {
482 1.1.2.2 pgoyette vsc &= ~VPP_OSD_VSC_CTRL0_VSCALE_EN;
483 1.1.2.2 pgoyette }
484 1.1.2.2 pgoyette VPU_WRITE(sc, VPP_OSD_VSC_CTRL0_REG, vsc);
485 1.1.2.2 pgoyette
486 1.1.2.2 pgoyette /* free scale enable */
487 1.1.2.2 pgoyette if (scale_p) {
488 1.1.2.2 pgoyette const u_int hf_phase_step = ((width << 18) / dst_w) << 6;
489 1.1.2.2 pgoyette const u_int vf_phase_step = ((height << 20) / dst_h) << 4;
490 1.1.2.2 pgoyette const u_int bot_ini_phase =
491 1.1.2.2 pgoyette interlace_p ? ((vf_phase_step / 2) >> 8) : 0;
492 1.1.2.2 pgoyette
493 1.1.2.2 pgoyette hps = VPU_READ(sc, VPP_OSD_HSC_PHASE_STEP_REG);
494 1.1.2.2 pgoyette hps &= ~VPP_OSD_HSC_PHASE_STEP_FORMAT;
495 1.1.2.2 pgoyette hps |= __SHIFTIN(hf_phase_step, VPP_OSD_HSC_PHASE_STEP_FORMAT);
496 1.1.2.2 pgoyette VPU_WRITE(sc, VPP_OSD_HSC_PHASE_STEP_REG, hps);
497 1.1.2.2 pgoyette
498 1.1.2.2 pgoyette hip = VPU_READ(sc, VPP_OSD_HSC_INI_PHASE_REG);
499 1.1.2.2 pgoyette hip &= ~VPP_OSD_HSC_INI_PHASE_1;
500 1.1.2.2 pgoyette VPU_WRITE(sc, VPP_OSD_HSC_INI_PHASE_REG, hip);
501 1.1.2.2 pgoyette
502 1.1.2.2 pgoyette vps = VPU_READ(sc, VPP_OSD_VSC_PHASE_STEP_REG);
503 1.1.2.2 pgoyette vps &= ~VPP_OSD_VSC_PHASE_STEP_FORMAT;
504 1.1.2.2 pgoyette vps |= __SHIFTIN(hf_phase_step, VPP_OSD_VSC_PHASE_STEP_FORMAT);
505 1.1.2.2 pgoyette VPU_WRITE(sc, VPP_OSD_VSC_PHASE_STEP_REG, vps);
506 1.1.2.2 pgoyette
507 1.1.2.2 pgoyette vip = VPU_READ(sc, VPP_OSD_VSC_INI_PHASE_REG);
508 1.1.2.2 pgoyette vip &= ~VPP_OSD_VSC_INI_PHASE_1;
509 1.1.2.2 pgoyette vip |= __SHIFTIN(0, VPP_OSD_VSC_INI_PHASE_1);
510 1.1.2.2 pgoyette vip &= ~VPP_OSD_VSC_INI_PHASE_0;
511 1.1.2.2 pgoyette vip |= __SHIFTIN(bot_ini_phase, VPP_OSD_VSC_INI_PHASE_0);
512 1.1.2.2 pgoyette VPU_WRITE(sc, VPP_OSD_VSC_INI_PHASE_REG, vip);
513 1.1.2.2 pgoyette }
514 1.1.2.2 pgoyette }
515 1.1.2.2 pgoyette
516 1.1.2.2 pgoyette static void
517 1.1.2.2 pgoyette meson_genfb_init(struct meson_genfb_softc *sc)
518 1.1.2.2 pgoyette {
519 1.1.2.2 pgoyette prop_dictionary_t cfg = device_properties(sc->sc_gen.sc_dev);
520 1.1.2.2 pgoyette const struct sysctlnode *node, *devnode;
521 1.1.2.2 pgoyette u_int width = 0, height = 0, depth, flags, i, scale = 100;
522 1.1.2.2 pgoyette int error;
523 1.1.2.2 pgoyette
524 1.1.2.2 pgoyette /*
525 1.1.2.2 pgoyette * Firmware has (maybe) setup HDMI TX for us. Read the VIC from
526 1.1.2.2 pgoyette * the HDMI AVI InfoFrame (bits 6:0 in PB4) and map that to a
527 1.1.2.2 pgoyette * framebuffer geometry.
528 1.1.2.2 pgoyette */
529 1.1.2.2 pgoyette const uint32_t vic = HDMI_READ(sc, HDMITX_AVI_INFO_ADDR + 4) & 0x7f;
530 1.1.2.2 pgoyette for (i = 0; i < __arraycount(meson_genfb_modes); i++) {
531 1.1.2.2 pgoyette if (meson_genfb_modes[i].vic == vic) {
532 1.1.2.2 pgoyette aprint_debug(" [HDMI VIC %d]", vic);
533 1.1.2.2 pgoyette width = meson_genfb_modes[i].width;
534 1.1.2.2 pgoyette height = meson_genfb_modes[i].height;
535 1.1.2.2 pgoyette flags = meson_genfb_modes[i].flags;
536 1.1.2.2 pgoyette break;
537 1.1.2.2 pgoyette }
538 1.1.2.2 pgoyette }
539 1.1.2.2 pgoyette if (width == 0 || height == 0) {
540 1.1.2.2 pgoyette aprint_error(" [UNSUPPORTED HDMI VIC %d]", vic);
541 1.1.2.2 pgoyette return;
542 1.1.2.2 pgoyette }
543 1.1.2.2 pgoyette
544 1.1.2.2 pgoyette depth = AMLOGIC_GENFB_DEFAULT_DEPTH;
545 1.1.2.2 pgoyette prop_dictionary_get_uint32(cfg, "depth", &depth);
546 1.1.2.2 pgoyette switch (depth) {
547 1.1.2.2 pgoyette case 16:
548 1.1.2.2 pgoyette case 24:
549 1.1.2.2 pgoyette break;
550 1.1.2.2 pgoyette default:
551 1.1.2.2 pgoyette aprint_error_dev(sc->sc_gen.sc_dev,
552 1.1.2.2 pgoyette "unsupported depth %d, using %d\n", depth,
553 1.1.2.2 pgoyette AMLOGIC_GENFB_DEFAULT_DEPTH);
554 1.1.2.2 pgoyette depth = AMLOGIC_GENFB_DEFAULT_DEPTH;
555 1.1.2.2 pgoyette break;
556 1.1.2.2 pgoyette }
557 1.1.2.2 pgoyette prop_dictionary_set_uint8(cfg, "depth", depth);
558 1.1.2.2 pgoyette
559 1.1.2.2 pgoyette const uint32_t fbsize = width * height * (depth / 8);
560 1.1.2.2 pgoyette sc->sc_dmasize = (fbsize + 3) & ~3;
561 1.1.2.2 pgoyette
562 1.1.2.2 pgoyette error = meson_genfb_alloc_videomem(sc);
563 1.1.2.2 pgoyette if (error) {
564 1.1.2.2 pgoyette aprint_error_dev(sc->sc_gen.sc_dev,
565 1.1.2.2 pgoyette "failed to allocate %u bytes of video memory: %d\n",
566 1.1.2.2 pgoyette (u_int)sc->sc_dmasize, error);
567 1.1.2.2 pgoyette return;
568 1.1.2.2 pgoyette }
569 1.1.2.2 pgoyette
570 1.1.2.2 pgoyette prop_dictionary_get_uint32(cfg, "scale", &scale);
571 1.1.2.2 pgoyette if (scale > 100) {
572 1.1.2.2 pgoyette scale = 100;
573 1.1.2.2 pgoyette } else if (scale < 10) {
574 1.1.2.2 pgoyette scale = 10;
575 1.1.2.2 pgoyette }
576 1.1.2.2 pgoyette sc->sc_scale = scale;
577 1.1.2.2 pgoyette
578 1.1.2.2 pgoyette prop_dictionary_set_uint32(cfg, "width", width);
579 1.1.2.2 pgoyette prop_dictionary_set_uint32(cfg, "height", height);
580 1.1.2.2 pgoyette prop_dictionary_set_bool(cfg, "dblscan", !!(flags & DBLSCAN));
581 1.1.2.2 pgoyette prop_dictionary_set_bool(cfg, "interlace", !!(flags & INTERLACE));
582 1.1.2.2 pgoyette prop_dictionary_set_uint16(cfg, "linebytes", width * (depth / 8));
583 1.1.2.2 pgoyette prop_dictionary_set_uint32(cfg, "address", 0);
584 1.1.2.2 pgoyette prop_dictionary_set_uint32(cfg, "virtual_address",
585 1.1.2.2 pgoyette (uintptr_t)sc->sc_dmap);
586 1.1.2.2 pgoyette
587 1.1.2.2 pgoyette meson_genfb_canvas_config(sc);
588 1.1.2.2 pgoyette meson_genfb_osd_config(sc);
589 1.1.2.2 pgoyette meson_genfb_scaler_config(sc);
590 1.1.2.2 pgoyette
591 1.1.2.2 pgoyette /* sysctl setup */
592 1.1.2.2 pgoyette error = sysctl_createv(&sc->sc_sysctllog, 0, NULL, &node,
593 1.1.2.2 pgoyette CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw", NULL,
594 1.1.2.2 pgoyette NULL, 0, NULL, 0, CTL_HW, CTL_EOL);
595 1.1.2.2 pgoyette if (error)
596 1.1.2.2 pgoyette goto sysctl_failed;
597 1.1.2.2 pgoyette error = sysctl_createv(&sc->sc_sysctllog, 0, &node, &devnode,
598 1.1.2.2 pgoyette 0, CTLTYPE_NODE, device_xname(sc->sc_gen.sc_dev), NULL,
599 1.1.2.2 pgoyette NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
600 1.1.2.2 pgoyette if (error)
601 1.1.2.2 pgoyette goto sysctl_failed;
602 1.1.2.2 pgoyette error = sysctl_createv(&sc->sc_sysctllog, 0, &devnode, &node,
603 1.1.2.2 pgoyette CTLFLAG_READWRITE, CTLTYPE_INT, "scale", NULL,
604 1.1.2.2 pgoyette meson_genfb_scale_helper, 0, (void *)sc, 0,
605 1.1.2.2 pgoyette CTL_CREATE, CTL_EOL);
606 1.1.2.2 pgoyette if (error)
607 1.1.2.2 pgoyette goto sysctl_failed;
608 1.1.2.2 pgoyette sc->sc_node_scale = node->sysctl_num;
609 1.1.2.2 pgoyette
610 1.1.2.2 pgoyette return;
611 1.1.2.2 pgoyette
612 1.1.2.2 pgoyette sysctl_failed:
613 1.1.2.2 pgoyette aprint_error_dev(sc->sc_gen.sc_dev,
614 1.1.2.2 pgoyette "couldn't create sysctl nodes (%d)\n", error);
615 1.1.2.2 pgoyette sysctl_teardown(&sc->sc_sysctllog);
616 1.1.2.2 pgoyette }
617 1.1.2.2 pgoyette
618 1.1.2.2 pgoyette static int
619 1.1.2.2 pgoyette meson_genfb_scale_helper(SYSCTLFN_ARGS)
620 1.1.2.2 pgoyette {
621 1.1.2.2 pgoyette struct meson_genfb_softc *sc;
622 1.1.2.2 pgoyette struct sysctlnode node;
623 1.1.2.2 pgoyette int scale, oldscale, error;
624 1.1.2.2 pgoyette
625 1.1.2.2 pgoyette node = *rnode;
626 1.1.2.2 pgoyette sc = node.sysctl_data;
627 1.1.2.2 pgoyette scale = oldscale = sc->sc_scale;
628 1.1.2.2 pgoyette node.sysctl_data = &scale;
629 1.1.2.2 pgoyette error = sysctl_lookup(SYSCTLFN_CALL(&node));
630 1.1.2.2 pgoyette if (error || newp == NULL)
631 1.1.2.2 pgoyette return error;
632 1.1.2.2 pgoyette
633 1.1.2.2 pgoyette if (scale > 100) {
634 1.1.2.2 pgoyette scale = 100;
635 1.1.2.2 pgoyette } else if (scale < 10) {
636 1.1.2.2 pgoyette scale = 10;
637 1.1.2.2 pgoyette }
638 1.1.2.2 pgoyette
639 1.1.2.2 pgoyette if (scale == oldscale) {
640 1.1.2.2 pgoyette return 0;
641 1.1.2.2 pgoyette }
642 1.1.2.2 pgoyette
643 1.1.2.2 pgoyette mutex_enter(&sc->sc_lock);
644 1.1.2.2 pgoyette sc->sc_scale = scale;
645 1.1.2.2 pgoyette meson_genfb_scaler_config(sc);
646 1.1.2.2 pgoyette mutex_exit(&sc->sc_lock);
647 1.1.2.2 pgoyette
648 1.1.2.2 pgoyette return 0;
649 1.1.2.2 pgoyette }
650 1.1.2.2 pgoyette
651 1.1.2.2 pgoyette static int
652 1.1.2.2 pgoyette meson_genfb_alloc_videomem(struct meson_genfb_softc *sc)
653 1.1.2.2 pgoyette {
654 1.1.2.2 pgoyette int error, nsegs;
655 1.1.2.2 pgoyette
656 1.1.2.2 pgoyette error = bus_dmamem_alloc(sc->sc_dmat, sc->sc_dmasize, 0x1000, 0,
657 1.1.2.2 pgoyette sc->sc_dmasegs, 1, &nsegs, BUS_DMA_WAITOK);
658 1.1.2.2 pgoyette if (error)
659 1.1.2.2 pgoyette return error;
660 1.1.2.2 pgoyette error = bus_dmamem_map(sc->sc_dmat, sc->sc_dmasegs, nsegs,
661 1.1.2.2 pgoyette sc->sc_dmasize, &sc->sc_dmap, BUS_DMA_WAITOK | BUS_DMA_COHERENT);
662 1.1.2.2 pgoyette if (error)
663 1.1.2.2 pgoyette goto free;
664 1.1.2.2 pgoyette error = bus_dmamap_create(sc->sc_dmat, sc->sc_dmasize, 1,
665 1.1.2.2 pgoyette sc->sc_dmasize, 0, BUS_DMA_WAITOK, &sc->sc_dmamap);
666 1.1.2.2 pgoyette if (error)
667 1.1.2.2 pgoyette goto unmap;
668 1.1.2.2 pgoyette error = bus_dmamap_load(sc->sc_dmat, sc->sc_dmamap, sc->sc_dmap,
669 1.1.2.2 pgoyette sc->sc_dmasize, NULL, BUS_DMA_WAITOK);
670 1.1.2.2 pgoyette if (error)
671 1.1.2.2 pgoyette goto destroy;
672 1.1.2.2 pgoyette
673 1.1.2.2 pgoyette memset(sc->sc_dmap, 0, sc->sc_dmasize);
674 1.1.2.2 pgoyette
675 1.1.2.2 pgoyette return 0;
676 1.1.2.2 pgoyette
677 1.1.2.2 pgoyette destroy:
678 1.1.2.2 pgoyette bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmamap);
679 1.1.2.2 pgoyette unmap:
680 1.1.2.2 pgoyette bus_dmamem_unmap(sc->sc_dmat, sc->sc_dmap, sc->sc_dmasize);
681 1.1.2.2 pgoyette free:
682 1.1.2.2 pgoyette bus_dmamem_free(sc->sc_dmat, sc->sc_dmasegs, nsegs);
683 1.1.2.2 pgoyette
684 1.1.2.2 pgoyette sc->sc_dmasize = 0;
685 1.1.2.2 pgoyette sc->sc_dmap = NULL;
686 1.1.2.2 pgoyette
687 1.1.2.2 pgoyette return error;
688 1.1.2.2 pgoyette }
689 1.1.2.2 pgoyette
690 1.1.2.2 pgoyette void
691 1.1.2.2 pgoyette meson_genfb_set_console_dev(device_t dev)
692 1.1.2.2 pgoyette {
693 1.1.2.2 pgoyette KASSERT(meson_genfb_console_dev == NULL);
694 1.1.2.2 pgoyette meson_genfb_console_dev = dev;
695 1.1.2.2 pgoyette }
696 1.1.2.2 pgoyette
697 1.1.2.2 pgoyette void
698 1.1.2.2 pgoyette meson_genfb_ddb_trap_callback(int where)
699 1.1.2.2 pgoyette {
700 1.1.2.2 pgoyette if (meson_genfb_console_dev == NULL)
701 1.1.2.2 pgoyette return;
702 1.1.2.2 pgoyette
703 1.1.2.2 pgoyette if (where) {
704 1.1.2.2 pgoyette genfb_enable_polling(meson_genfb_console_dev);
705 1.1.2.2 pgoyette } else {
706 1.1.2.2 pgoyette genfb_disable_polling(meson_genfb_console_dev);
707 1.1.2.2 pgoyette }
708 1.1.2.2 pgoyette }
709 1.1.2.2 pgoyette
710 1.1.2.2 pgoyette static int
711 1.1.2.2 pgoyette meson_genfb_console_match(int phandle)
712 1.1.2.2 pgoyette {
713 1.1.2.2 pgoyette return of_match_compatible(phandle, compatible);
714 1.1.2.2 pgoyette }
715 1.1.2.2 pgoyette
716 1.1.2.2 pgoyette static void
717 1.1.2.2 pgoyette meson_genfb_console_consinit(struct fdt_attach_args *faa, u_int uart_freq)
718 1.1.2.2 pgoyette {
719 1.1.2.2 pgoyette meson_genfb_console_phandle = faa->faa_phandle;
720 1.1.2.2 pgoyette genfb_cnattach();
721 1.1.2.2 pgoyette }
722 1.1.2.2 pgoyette
723 1.1.2.2 pgoyette static const struct fdt_console meson_genfb_fdt_console = {
724 1.1.2.2 pgoyette .match = meson_genfb_console_match,
725 1.1.2.2 pgoyette .consinit = meson_genfb_console_consinit,
726 1.1.2.2 pgoyette };
727 1.1.2.2 pgoyette
728 1.1.2.2 pgoyette FDT_CONSOLE(meson_genfb, &meson_genfb_fdt_console);
729