sunxi_dep.c revision 1.2
11.2Sbouyer/* $NetBSD: sunxi_dep.c,v 1.2 2018/04/03 13:38:13 bouyer 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.2Sbouyer__KERNEL_RCSID(1, "$NetBSD: sunxi_dep.c,v 1.2 2018/04/03 13:38:13 bouyer 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.1Sbouyerstatic const struct of_compat_data compat_data[] = { 551.2Sbouyer {"allwinner,sun4i-a10-display-engine", 0}, 561.1Sbouyer {"allwinner,sun7i-a20-display-engine", 0}, 571.1Sbouyer {NULL} 581.1Sbouyer}; 591.1Sbouyer 601.1Sbouyerstatic int sunxi_dep_match(device_t, cfdata_t, void *); 611.1Sbouyerstatic void sunxi_dep_attach(device_t, device_t, void *); 621.1Sbouyer 631.1SbouyerCFATTACH_DECL_NEW(sunxi_dep, sizeof(struct sunxi_dep_softc), 641.1Sbouyer sunxi_dep_match, sunxi_dep_attach, NULL, NULL); 651.1Sbouyer 661.1Sbouyerstatic int 671.1Sbouyersunxi_dep_match(device_t parent, cfdata_t cf, void *aux) 681.1Sbouyer{ 691.1Sbouyer#if NSUNXI_DEBE > 0 701.1Sbouyer struct fdt_attach_args * const faa = aux; 711.1Sbouyer if (!of_match_compat_data(faa->faa_phandle, compat_data)) 721.1Sbouyer return 0; 731.1Sbouyer return 1; 741.1Sbouyer#else 751.1Sbouyer return 0; 761.1Sbouyer#endif 771.1Sbouyer} 781.1Sbouyer 791.1Sbouyerstatic void 801.1Sbouyersunxi_dep_attach(device_t parent, device_t self, void *aux) 811.1Sbouyer{ 821.1Sbouyer struct sunxi_dep_softc * const sc = device_private(self); 831.1Sbouyer struct fdt_attach_args * const faa = aux; 841.1Sbouyer const int phandle = faa->faa_phandle; 851.1Sbouyer int len; 861.1Sbouyer const u_int *buf; 871.1Sbouyer u_int ref; 881.1Sbouyer int error; 891.1Sbouyer 901.1Sbouyer sc->sc_dev = self; 911.1Sbouyer 921.1Sbouyer buf = fdt_getprop(fdtbus_get_data(), 931.1Sbouyer fdtbus_phandle2offset(phandle), "allwinner,pipelines", &len); 941.1Sbouyer if (buf == NULL || len < sizeof(ref) || (len % sizeof(ref)) != 0) { 951.1Sbouyer aprint_error("bad/missing allwinner,pipelines property\n"); 961.1Sbouyer return; 971.1Sbouyer } 981.1Sbouyer aprint_naive("\n"); 991.1Sbouyer aprint_normal(": "); 1001.1Sbouyer#if NSUNXI_DEBE > 0 1011.1Sbouyer for (int i = 0; i < (len / sizeof(ref)); i++) { 1021.1Sbouyer if (i > 0) 1031.1Sbouyer aprint_normal_dev(self, ""); 1041.1Sbouyer ref = be32dec(&buf[i]); 1051.1Sbouyer error = sunxi_debe_pipeline( 1061.1Sbouyer fdtbus_get_phandle_from_native(ref), true); 1071.1Sbouyer if (error) 1081.1Sbouyer aprint_error("can't activate pipeline %d\n", i); 1091.1Sbouyer } 1101.1Sbouyer#else 1111.1Sbouyer aprint_error("debe not configured\n"); 1121.1Sbouyer return; 1131.1Sbouyer#endif 1141.1Sbouyer} 115