sunxi_dep.c revision 1.4
11.4Sthorpej/*	$NetBSD: sunxi_dep.c,v 1.4 2021/01/18 02:35:49 thorpej Exp $	*/
21.1Sbouyer
31.1Sbouyer/*-
41.1Sbouyer * Copyright (c) 2018 The NetBSD Foundation, Inc.
51.1Sbouyer * All rights reserved.
61.1Sbouyer *
71.1Sbouyer * This code is derived from software contributed to The NetBSD Foundation
81.1Sbouyer * by Manuel Bouyer.
91.1Sbouyer *
101.1Sbouyer * Redistribution and use in source and binary forms, with or without
111.1Sbouyer * modification, are permitted provided that the following conditions
121.1Sbouyer * are met:
131.1Sbouyer * 1. Redistributions of source code must retain the above copyright
141.1Sbouyer *    notice, this list of conditions and the following disclaimer.
151.1Sbouyer * 2. Redistributions in binary form must reproduce the above copyright
161.1Sbouyer *    notice, this list of conditions and the following disclaimer in the
171.1Sbouyer *    documentation and/or other materials provided with the distribution.
181.1Sbouyer *
191.1Sbouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Sbouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Sbouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Sbouyer * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Sbouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Sbouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Sbouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Sbouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Sbouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Sbouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Sbouyer * POSSIBILITY OF SUCH DAMAGE.
301.1Sbouyer */
311.1Sbouyer
321.1Sbouyer
331.1Sbouyer#include <sys/cdefs.h>
341.1Sbouyer
351.4Sthorpej__KERNEL_RCSID(1, "$NetBSD: sunxi_dep.c,v 1.4 2021/01/18 02:35:49 thorpej Exp $");
361.1Sbouyer
371.1Sbouyer#include <sys/param.h>
381.1Sbouyer#include <sys/bus.h>
391.1Sbouyer#include <sys/device.h>
401.1Sbouyer#include <sys/systm.h>
411.1Sbouyer
421.1Sbouyer#include <libfdt.h>
431.1Sbouyer
441.1Sbouyer#include <dev/fdt/fdtvar.h>
451.1Sbouyer#include <arm/sunxi/sunxi_display.h>
461.1Sbouyer
471.1Sbouyer#include "sunxi_debe.h"
481.1Sbouyer
491.1Sbouyerstruct sunxi_dep_softc {
501.1Sbouyer	device_t sc_dev;
511.1Sbouyer	int	sc_phandle;
521.1Sbouyer};
531.1Sbouyer
541.4Sthorpejstatic const struct device_compatible_entry compat_data[] = {
551.4Sthorpej	{ .compat = "allwinner,sun4i-a10-display-engine" },
561.4Sthorpej	{ .compat = "allwinner,sun7i-a20-display-engine" },
571.4Sthorpej
581.4Sthorpej	{ 0 }
591.1Sbouyer};
601.1Sbouyer
611.3Sbouyerstatic const char *fb_compat[] = {
621.3Sbouyer	"allwinner,simple-framebuffer",
631.3Sbouyer	NULL
641.3Sbouyer};
651.3Sbouyer
661.1Sbouyerstatic int sunxi_dep_match(device_t, cfdata_t, void *);
671.1Sbouyerstatic void sunxi_dep_attach(device_t, device_t, void *);
681.1Sbouyer
691.1SbouyerCFATTACH_DECL_NEW(sunxi_dep, sizeof(struct sunxi_dep_softc),
701.1Sbouyer	sunxi_dep_match, sunxi_dep_attach, NULL, NULL);
711.1Sbouyer
721.1Sbouyerstatic int
731.1Sbouyersunxi_dep_match(device_t parent, cfdata_t cf, void *aux)
741.1Sbouyer{
751.1Sbouyer#if NSUNXI_DEBE > 0
761.1Sbouyer	struct fdt_attach_args * const faa = aux;
771.3Sbouyer
781.3Sbouyer	return  of_match_compat_data(faa->faa_phandle, compat_data);
791.1Sbouyer#else
801.1Sbouyer	return 0;
811.1Sbouyer#endif
821.1Sbouyer}
831.1Sbouyer
841.1Sbouyerstatic void
851.1Sbouyersunxi_dep_attach(device_t parent, device_t self, void *aux)
861.1Sbouyer{
871.1Sbouyer	struct sunxi_dep_softc * const sc = device_private(self);
881.1Sbouyer	struct fdt_attach_args * const faa = aux;
891.1Sbouyer	const int phandle = faa->faa_phandle;
901.3Sbouyer	int sunxi_dep_npipelines = 0;
911.1Sbouyer	int len;
921.1Sbouyer	const u_int *buf;
931.1Sbouyer	u_int ref;
941.1Sbouyer	int error;
951.1Sbouyer
961.1Sbouyer	sc->sc_dev = self;
971.1Sbouyer
981.1Sbouyer	buf = fdt_getprop(fdtbus_get_data(),
991.1Sbouyer	    fdtbus_phandle2offset(phandle), "allwinner,pipelines", &len);
1001.1Sbouyer	if (buf == NULL || len < sizeof(ref) || (len % sizeof(ref)) != 0) {
1011.1Sbouyer		aprint_error("bad/missing allwinner,pipelines property\n");
1021.1Sbouyer		return;
1031.1Sbouyer	}
1041.1Sbouyer	aprint_normal(": ");
1051.1Sbouyer#if NSUNXI_DEBE > 0
1061.1Sbouyer	for (int i = 0; i < (len / sizeof(ref)); i++) {
1071.1Sbouyer		if (i > 0)
1081.1Sbouyer			aprint_normal_dev(self, "");
1091.1Sbouyer		ref = be32dec(&buf[i]);
1101.1Sbouyer		error = sunxi_debe_pipeline(
1111.1Sbouyer		    fdtbus_get_phandle_from_native(ref), true);
1121.1Sbouyer		if (error)
1131.1Sbouyer			aprint_error("can't activate pipeline %d\n", i);
1141.3Sbouyer		else
1151.3Sbouyer			sunxi_dep_npipelines++;
1161.1Sbouyer	}
1171.3Sbouyer	aprint_naive("\n");
1181.3Sbouyer	if (sunxi_dep_npipelines > 0)
1191.3Sbouyer		fdt_remove_bycompat(fb_compat);
1201.1Sbouyer#else
1211.1Sbouyer	aprint_error("debe not configured\n");
1221.1Sbouyer	return;
1231.1Sbouyer#endif
1241.1Sbouyer}
125