sunxi_dep.c revision 1.3
1/*	$NetBSD: sunxi_dep.c,v 1.3 2018/04/07 18:09:33 bouyer 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.3 2018/04/07 18:09:33 bouyer 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 of_compat_data compat_data[] = {
55	{"allwinner,sun4i-a10-display-engine", 0},
56	{"allwinner,sun7i-a20-display-engine", 0},
57	{NULL}
58};
59
60static const char *fb_compat[] = {
61	"allwinner,simple-framebuffer",
62	NULL
63};
64
65static int sunxi_dep_match(device_t, cfdata_t, void *);
66static void sunxi_dep_attach(device_t, device_t, void *);
67
68CFATTACH_DECL_NEW(sunxi_dep, sizeof(struct sunxi_dep_softc),
69	sunxi_dep_match, sunxi_dep_attach, NULL, NULL);
70
71static int
72sunxi_dep_match(device_t parent, cfdata_t cf, void *aux)
73{
74#if NSUNXI_DEBE > 0
75	struct fdt_attach_args * const faa = aux;
76
77	return  of_match_compat_data(faa->faa_phandle, compat_data);
78#else
79	return 0;
80#endif
81}
82
83static void
84sunxi_dep_attach(device_t parent, device_t self, void *aux)
85{
86	struct sunxi_dep_softc * const sc = device_private(self);
87	struct fdt_attach_args * const faa = aux;
88	const int phandle = faa->faa_phandle;
89	int sunxi_dep_npipelines = 0;
90	int len;
91	const u_int *buf;
92	u_int ref;
93	int error;
94
95	sc->sc_dev = self;
96
97	buf = fdt_getprop(fdtbus_get_data(),
98	    fdtbus_phandle2offset(phandle), "allwinner,pipelines", &len);
99	if (buf == NULL || len < sizeof(ref) || (len % sizeof(ref)) != 0) {
100		aprint_error("bad/missing allwinner,pipelines property\n");
101		return;
102	}
103	aprint_normal(": ");
104#if NSUNXI_DEBE > 0
105	for (int i = 0; i < (len / sizeof(ref)); i++) {
106		if (i > 0)
107			aprint_normal_dev(self, "");
108		ref = be32dec(&buf[i]);
109		error = sunxi_debe_pipeline(
110		    fdtbus_get_phandle_from_native(ref), true);
111		if (error)
112			aprint_error("can't activate pipeline %d\n", i);
113		else
114			sunxi_dep_npipelines++;
115	}
116	aprint_naive("\n");
117	if (sunxi_dep_npipelines > 0)
118		fdt_remove_bycompat(fb_compat);
119#else
120	aprint_error("debe not configured\n");
121	return;
122#endif
123}
124