1 /* $NetBSD: sun9i_a80_mmcclk.c,v 1.1 2017/10/08 18:00:36 jmcneill Exp $ */ 2 3 /*- 4 * Copyright (c) 2017 Jared McNeill <jmcneill@invisible.ca> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 31 __KERNEL_RCSID(1, "$NetBSD: sun9i_a80_mmcclk.c,v 1.1 2017/10/08 18:00:36 jmcneill Exp $"); 32 33 #include <sys/param.h> 34 #include <sys/bus.h> 35 #include <sys/device.h> 36 #include <sys/systm.h> 37 38 #include <dev/fdt/fdtvar.h> 39 40 #include <arm/sunxi/sunxi_ccu.h> 41 42 #define SDC_COMM(port) (0x04 * (port)) 43 44 static int sun9i_a80_mmcclk_match(device_t, cfdata_t, void *); 45 static void sun9i_a80_mmcclk_attach(device_t, device_t, void *); 46 47 static const char * compatible[] = { 48 "allwinner,sun9i-a80-mmc-config-clk", 49 NULL 50 }; 51 52 CFATTACH_DECL_NEW(sunxi_a80_mmcclk, sizeof(struct sunxi_ccu_softc), 53 sun9i_a80_mmcclk_match, sun9i_a80_mmcclk_attach, NULL, NULL); 54 55 static struct sunxi_ccu_reset sun9i_a80_mmcclk_resets[] = { 56 SUNXI_CCU_RESET(0, SDC_COMM(0), 18), 57 SUNXI_CCU_RESET(1, SDC_COMM(1), 18), 58 SUNXI_CCU_RESET(2, SDC_COMM(2), 18), 59 SUNXI_CCU_RESET(3, SDC_COMM(3), 18), 60 }; 61 62 static struct sunxi_ccu_clk sun9i_a80_mmcclk_clks[] = { 63 SUNXI_CCU_GATE(0, "mmc0_config", "ahb", SDC_COMM(0), 16), 64 SUNXI_CCU_GATE(1, "mmc1_config", "ahb", SDC_COMM(1), 16), 65 SUNXI_CCU_GATE(2, "mmc2_config", "ahb", SDC_COMM(2), 16), 66 SUNXI_CCU_GATE(3, "mmc3_config", "ahb", SDC_COMM(3), 16), 67 }; 68 69 static int 70 sun9i_a80_mmcclk_match(device_t parent, cfdata_t cf, void *aux) 71 { 72 struct fdt_attach_args * const faa = aux; 73 74 return of_match_compatible(faa->faa_phandle, compatible); 75 } 76 77 static void 78 sun9i_a80_mmcclk_attach(device_t parent, device_t self, void *aux) 79 { 80 struct sunxi_ccu_softc * const sc = device_private(self); 81 struct fdt_attach_args * const faa = aux; 82 83 sc->sc_dev = self; 84 sc->sc_phandle = faa->faa_phandle; 85 sc->sc_bst = faa->faa_bst; 86 87 sc->sc_resets = sun9i_a80_mmcclk_resets; 88 sc->sc_nresets = __arraycount(sun9i_a80_mmcclk_resets); 89 90 sc->sc_clks = sun9i_a80_mmcclk_clks; 91 sc->sc_nclks = __arraycount(sun9i_a80_mmcclk_clks); 92 93 if (sunxi_ccu_attach(sc) != 0) 94 return; 95 96 aprint_naive("\n"); 97 aprint_normal(": A80 SD/MMC-COMM\n"); 98 99 sunxi_ccu_print(sc); 100 } 101