sunxi_dep.c revision 1.4
1/*	$NetBSD: sunxi_dep.c,v 1.4 2021/01/18 02:35:49 thorpej Exp $	*/
2
3/*-
4 * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Manuel Bouyer.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32
33#include <sys/cdefs.h>
34
35__KERNEL_RCSID(1, "$NetBSD: sunxi_dep.c,v 1.4 2021/01/18 02:35:49 thorpej Exp $");
36
37#include <sys/param.h>
38#include <sys/bus.h>
39#include <sys/device.h>
40#include <sys/systm.h>
41
42#include <libfdt.h>
43
44#include <dev/fdt/fdtvar.h>
45#include <arm/sunxi/sunxi_display.h>
46
47#include "sunxi_debe.h"
48
49struct sunxi_dep_softc {
50	device_t sc_dev;
51	int	sc_phandle;
52};
53
54static const struct device_compatible_entry compat_data[] = {
55	{ .compat = "allwinner,sun4i-a10-display-engine" },
56	{ .compat = "allwinner,sun7i-a20-display-engine" },
57
58	{ 0 }
59};
60
61static const char *fb_compat[] = {
62	"allwinner,simple-framebuffer",
63	NULL
64};
65
66static int sunxi_dep_match(device_t, cfdata_t, void *);
67static void sunxi_dep_attach(device_t, device_t, void *);
68
69CFATTACH_DECL_NEW(sunxi_dep, sizeof(struct sunxi_dep_softc),
70	sunxi_dep_match, sunxi_dep_attach, NULL, NULL);
71
72static int
73sunxi_dep_match(device_t parent, cfdata_t cf, void *aux)
74{
75#if NSUNXI_DEBE > 0
76	struct fdt_attach_args * const faa = aux;
77
78	return  of_match_compat_data(faa->faa_phandle, compat_data);
79#else
80	return 0;
81#endif
82}
83
84static void
85sunxi_dep_attach(device_t parent, device_t self, void *aux)
86{
87	struct sunxi_dep_softc * const sc = device_private(self);
88	struct fdt_attach_args * const faa = aux;
89	const int phandle = faa->faa_phandle;
90	int sunxi_dep_npipelines = 0;
91	int len;
92	const u_int *buf;
93	u_int ref;
94	int error;
95
96	sc->sc_dev = self;
97
98	buf = fdt_getprop(fdtbus_get_data(),
99	    fdtbus_phandle2offset(phandle), "allwinner,pipelines", &len);
100	if (buf == NULL || len < sizeof(ref) || (len % sizeof(ref)) != 0) {
101		aprint_error("bad/missing allwinner,pipelines property\n");
102		return;
103	}
104	aprint_normal(": ");
105#if NSUNXI_DEBE > 0
106	for (int i = 0; i < (len / sizeof(ref)); i++) {
107		if (i > 0)
108			aprint_normal_dev(self, "");
109		ref = be32dec(&buf[i]);
110		error = sunxi_debe_pipeline(
111		    fdtbus_get_phandle_from_native(ref), true);
112		if (error)
113			aprint_error("can't activate pipeline %d\n", i);
114		else
115			sunxi_dep_npipelines++;
116	}
117	aprint_naive("\n");
118	if (sunxi_dep_npipelines > 0)
119		fdt_remove_bycompat(fb_compat);
120#else
121	aprint_error("debe not configured\n");
122	return;
123#endif
124}
125