sunxi_dep.c revision 1.7
11.7Sthorpej/* $NetBSD: sunxi_dep.c,v 1.7 2021/01/27 03:10:20 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.7Sthorpej__KERNEL_RCSID(1, "$NetBSD: sunxi_dep.c,v 1.7 2021/01/27 03:10:20 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.6Sthorpej DEVICE_COMPAT_EOL 581.1Sbouyer}; 591.1Sbouyer 601.3Sbouyerstatic const char *fb_compat[] = { 611.3Sbouyer "allwinner,simple-framebuffer", 621.3Sbouyer NULL 631.3Sbouyer}; 641.3Sbouyer 651.1Sbouyerstatic int sunxi_dep_match(device_t, cfdata_t, void *); 661.1Sbouyerstatic void sunxi_dep_attach(device_t, device_t, void *); 671.1Sbouyer 681.1SbouyerCFATTACH_DECL_NEW(sunxi_dep, sizeof(struct sunxi_dep_softc), 691.1Sbouyer sunxi_dep_match, sunxi_dep_attach, NULL, NULL); 701.1Sbouyer 711.1Sbouyerstatic int 721.1Sbouyersunxi_dep_match(device_t parent, cfdata_t cf, void *aux) 731.1Sbouyer{ 741.1Sbouyer#if NSUNXI_DEBE > 0 751.1Sbouyer struct fdt_attach_args * const faa = aux; 761.3Sbouyer 771.7Sthorpej return of_compatible_match(faa->faa_phandle, compat_data); 781.1Sbouyer#else 791.1Sbouyer return 0; 801.1Sbouyer#endif 811.1Sbouyer} 821.1Sbouyer 831.1Sbouyerstatic void 841.1Sbouyersunxi_dep_attach(device_t parent, device_t self, void *aux) 851.1Sbouyer{ 861.1Sbouyer struct sunxi_dep_softc * const sc = device_private(self); 871.1Sbouyer struct fdt_attach_args * const faa = aux; 881.1Sbouyer const int phandle = faa->faa_phandle; 891.3Sbouyer int sunxi_dep_npipelines = 0; 901.1Sbouyer int len; 911.1Sbouyer const u_int *buf; 921.1Sbouyer u_int ref; 931.1Sbouyer int error; 941.1Sbouyer 951.1Sbouyer sc->sc_dev = self; 961.1Sbouyer 971.1Sbouyer buf = fdt_getprop(fdtbus_get_data(), 981.1Sbouyer fdtbus_phandle2offset(phandle), "allwinner,pipelines", &len); 991.1Sbouyer if (buf == NULL || len < sizeof(ref) || (len % sizeof(ref)) != 0) { 1001.1Sbouyer aprint_error("bad/missing allwinner,pipelines property\n"); 1011.1Sbouyer return; 1021.1Sbouyer } 1031.1Sbouyer aprint_normal(": "); 1041.1Sbouyer#if NSUNXI_DEBE > 0 1051.1Sbouyer for (int i = 0; i < (len / sizeof(ref)); i++) { 1061.1Sbouyer if (i > 0) 1071.1Sbouyer aprint_normal_dev(self, ""); 1081.1Sbouyer ref = be32dec(&buf[i]); 1091.1Sbouyer error = sunxi_debe_pipeline( 1101.1Sbouyer fdtbus_get_phandle_from_native(ref), true); 1111.1Sbouyer if (error) 1121.1Sbouyer aprint_error("can't activate pipeline %d\n", i); 1131.3Sbouyer else 1141.3Sbouyer sunxi_dep_npipelines++; 1151.1Sbouyer } 1161.3Sbouyer aprint_naive("\n"); 1171.3Sbouyer if (sunxi_dep_npipelines > 0) 1181.3Sbouyer fdt_remove_bycompat(fb_compat); 1191.1Sbouyer#else 1201.1Sbouyer aprint_error("debe not configured\n"); 1211.1Sbouyer return; 1221.1Sbouyer#endif 1231.1Sbouyer} 124