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