1 /* $NetBSD: sun9i_a80_gpio.c,v 1.3 2019/05/27 23:26:42 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 * $FreeBSD$ 29 */ 30 31 #include <sys/cdefs.h> 32 __KERNEL_RCSID(0, "$NetBSD: sun9i_a80_gpio.c,v 1.3 2019/05/27 23:26:42 jmcneill Exp $"); 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/kernel.h> 37 #include <sys/types.h> 38 39 #include <arm/sunxi/sunxi_gpio.h> 40 41 static const struct sunxi_gpio_pins a80_pins[] = { 42 { "PA0", 0, 0, { "gpio_in", "gpio_out", "gmac", NULL, "uart1", NULL, "irq" }, 6, 0, 0 }, 43 { "PA1", 0, 1, { "gpio_in", "gpio_out", "gmac", NULL, "uart1", NULL, "irq" }, 6, 1, 0 }, 44 { "PA2", 0, 2, { "gpio_in", "gpio_out", "gmac", NULL, "uart1", NULL, "irq" }, 6, 2, 0 }, 45 { "PA3", 0, 3, { "gpio_in", "gpio_out", "gmac", NULL, "uart1", NULL, "irq" }, 6, 3, 0 }, 46 { "PA4", 0, 4, { "gpio_in", "gpio_out", "gmac", NULL, "uart1", NULL, "irq" }, 6, 4, 0 }, 47 { "PA5", 0, 5, { "gpio_in", "gpio_out", "gmac", NULL, "uart1", NULL, "irq" }, 6, 5, 0 }, 48 { "PA6", 0, 6, { "gpio_in", "gpio_out", "gmac", NULL, "uart1", NULL, "irq" }, 6, 6, 0 }, 49 { "PA7", 0, 7, { "gpio_in", "gpio_out", "gmac", NULL, "uart1", NULL, "irq" }, 6, 7, 0 }, 50 { "PA8", 0, 8, { "gpio_in", "gpio_out", "gmac", NULL, "eclk", NULL, "irq" }, 6, 8, 0 }, 51 { "PA9", 0, 9, { "gpio_in", "gpio_out", "gmac", NULL, "eclk", NULL, "irq" }, 6, 9, 0 }, 52 { "PA10", 0, 10, { "gpio_in", "gpio_out", "gmac", NULL, "clk_out_a", NULL, "irq" }, 6, 10, 0 }, 53 { "PA11", 0, 11, { "gpio_in", "gpio_out", "gmac", NULL, "clk_out_b", NULL, "irq" }, 6, 11, 0 }, 54 { "PA12", 0, 12, { "gpio_in", "gpio_out", "gmac", NULL, "pwm3", NULL, "irq" }, 6, 12, 0 }, 55 { "PA13", 0, 13, { "gpio_in", "gpio_out", "gmac", NULL, "pwm3", NULL, "irq" }, 6, 13, 0 }, 56 { "PA14", 0, 14, { "gpio_in", "gpio_out", "gmac", NULL, "spi1", NULL, "irq" }, 6, 14, 0 }, 57 { "PA15", 0, 15, { "gpio_in", "gpio_out", "gmac", NULL, "spi1", NULL, "irq" }, 6, 15, 0 }, 58 { "PA16", 0, 16, { "gpio_in", "gpio_out", "gmac", NULL, "spi1", NULL, "irq" }, 6, 16, 0 }, 59 { "PA17", 0, 17, { "gpio_in", "gpio_out", "gmac", NULL, "spi1", NULL, "irq" }, 6, 17, 0 }, 60 61 { "PB5", 1, 5, { "gpio_in", "gpio_out", NULL, "uart3", NULL, NULL, "irq" }, 6, 5, 1 }, 62 { "PB6", 1, 6, { "gpio_in", "gpio_out", NULL, "uart3", NULL, NULL, "irq" }, 6, 6, 1 }, 63 { "PB14", 1, 14, { "gpio_in", "gpio_out", NULL, "mcsi", NULL, NULL, "irq" }, 6, 14, 1 }, 64 { "PB15", 1, 15, { "gpio_in", "gpio_out", NULL, "mcsi", "i2c4", NULL, "irq" }, 6, 15, 1 }, 65 { "PB16", 1, 16, { "gpio_in", "gpio_out", NULL, "mcsi", "i2c4", NULL, "irq" }, 6, 16, 1 }, 66 67 { "PC0", 2, 0, { "gpio_in", "gpio_out", "nand0", "spi0" } }, 68 { "PC1", 2, 1, { "gpio_in", "gpio_out", "nand0", "spi0" } }, 69 { "PC2", 2, 2, { "gpio_in", "gpio_out", "nand0", "spi0" } }, 70 { "PC3", 2, 3, { "gpio_in", "gpio_out", "nand0" } }, 71 { "PC4", 2, 4, { "gpio_in", "gpio_out", "nand0" } }, 72 { "PC5", 2, 5, { "gpio_in", "gpio_out", "nand0" } }, 73 { "PC6", 2, 6, { "gpio_in", "gpio_out", "nand0", "mmc2" } }, 74 { "PC7", 2, 7, { "gpio_in", "gpio_out", "nand0", "mmc2" } }, 75 { "PC8", 2, 8, { "gpio_in", "gpio_out", "nand0", "mmc2" } }, 76 { "PC9", 2, 9, { "gpio_in", "gpio_out", "nand0", "mmc2" } }, 77 { "PC10", 2, 10, { "gpio_in", "gpio_out", "nand0", "mmc2" } }, 78 { "PC11", 2, 11, { "gpio_in", "gpio_out", "nand0", "mmc2" } }, 79 { "PC12", 2, 12, { "gpio_in", "gpio_out", "nand0", "mmc2" } }, 80 { "PC13", 2, 13, { "gpio_in", "gpio_out", "nand0", "mmc2" } }, 81 { "PC14", 2, 14, { "gpio_in", "gpio_out", "nand0", "mmc2" } }, 82 { "PC15", 2, 15, { "gpio_in", "gpio_out", "nand0", "mmc2" } }, 83 { "PC16", 2, 16, { "gpio_in", "gpio_out", "nand0", "mmc2" } }, 84 { "PC17", 2, 17, { "gpio_in", "gpio_out", "nand0", "nand0_b" } }, 85 { "PC18", 2, 18, { "gpio_in", "gpio_out", "nand0", "nand0_b" } }, 86 { "PC19", 2, 19, { "gpio_in", "gpio_out", NULL, "spi0" } }, 87 88 { "PD0", 3, 0, { "gpio_in", "gpio_out", "lcd0", "lvds0" } }, 89 { "PD1", 3, 1, { "gpio_in", "gpio_out", "lcd0", "lvds0" } }, 90 { "PD2", 3, 2, { "gpio_in", "gpio_out", "lcd0", "lvds0" } }, 91 { "PD3", 3, 3, { "gpio_in", "gpio_out", "lcd0", "lvds0" } }, 92 { "PD4", 3, 4, { "gpio_in", "gpio_out", "lcd0", "lvds0" } }, 93 { "PD5", 3, 5, { "gpio_in", "gpio_out", "lcd0", "lvds0" } }, 94 { "PD6", 3, 6, { "gpio_in", "gpio_out", "lcd0", "lvds0" } }, 95 { "PD7", 3, 7, { "gpio_in", "gpio_out", "lcd0", "lvds0" } }, 96 { "PD8", 3, 8, { "gpio_in", "gpio_out", "lcd0", "lvds0" } }, 97 { "PD9", 3, 9, { "gpio_in", "gpio_out", "lcd0", "lvds0" } }, 98 { "PD10", 3, 10, { "gpio_in", "gpio_out", "lcd0", "lvds1" } }, 99 { "PD11", 3, 11, { "gpio_in", "gpio_out", "lcd0", "lvds1" } }, 100 { "PD12", 3, 12, { "gpio_in", "gpio_out", "lcd0", "lvds1" } }, 101 { "PD13", 3, 13, { "gpio_in", "gpio_out", "lcd0", "lvds1" } }, 102 { "PD14", 3, 14, { "gpio_in", "gpio_out", "lcd0", "lvds1" } }, 103 { "PD15", 3, 15, { "gpio_in", "gpio_out", "lcd0", "lvds1" } }, 104 { "PD16", 3, 16, { "gpio_in", "gpio_out", "lcd0", "lvds1" } }, 105 { "PD17", 3, 17, { "gpio_in", "gpio_out", "lcd0", "lvds1" } }, 106 { "PD18", 3, 18, { "gpio_in", "gpio_out", "lcd0", "lvds1" } }, 107 { "PD19", 3, 19, { "gpio_in", "gpio_out", "lcd0", "lvds1" } }, 108 { "PD20", 3, 20, { "gpio_in", "gpio_out", "lcd0" } }, 109 { "PD21", 3, 21, { "gpio_in", "gpio_out", "lcd0" } }, 110 { "PD22", 3, 22, { "gpio_in", "gpio_out", "lcd0" } }, 111 { "PD23", 3, 23, { "gpio_in", "gpio_out", "lcd0" } }, 112 { "PD24", 3, 24, { "gpio_in", "gpio_out", "lcd0" } }, 113 { "PD25", 3, 25, { "gpio_in", "gpio_out", "lcd0" } }, 114 { "PD26", 3, 26, { "gpio_in", "gpio_out", "lcd0" } }, 115 { "PD27", 3, 27, { "gpio_in", "gpio_out", "lcd0" } }, 116 117 { "PE0", 4, 0, { "gpio_in", "gpio_out", "csi", "ts", NULL, NULL, "irq" }, 6, 0, 2 }, 118 { "PE1", 4, 1, { "gpio_in", "gpio_out", "csi", "ts", NULL, NULL, "irq" }, 6, 1, 2 }, 119 { "PE2", 4, 2, { "gpio_in", "gpio_out", "csi", "ts", NULL, NULL, "irq" }, 6, 2, 2 }, 120 { "PE3", 4, 3, { "gpio_in", "gpio_out", "csi", "ts", NULL, NULL, "irq" }, 6, 3, 2 }, 121 { "PE4", 4, 4, { "gpio_in", "gpio_out", "csi", "spi2", "uart5", NULL, "irq" }, 6, 4, 2 }, 122 { "PE5", 4, 5, { "gpio_in", "gpio_out", "csi", "spi2", "uart5", NULL, "irq" }, 6, 5, 2 }, 123 { "PE6", 4, 6, { "gpio_in", "gpio_out", "csi", "spi2", "uart5", NULL, "irq" }, 6, 6, 2 }, 124 { "PE7", 4, 7, { "gpio_in", "gpio_out", "csi", "spi2", "uart5", NULL, "irq" }, 6, 7, 2 }, 125 { "PE8", 4, 8, { "gpio_in", "gpio_out", "csi", "ts", NULL, NULL, "irq" }, 6, 8, 2 }, 126 { "PE9", 4, 9, { "gpio_in", "gpio_out", "csi", "ts", NULL, NULL, "irq" }, 6, 9, 2 }, 127 { "PE10", 4, 10, { "gpio_in", "gpio_out", "csi", "ts", NULL, NULL, "irq" }, 6, 10, 2 }, 128 { "PE11", 4, 11, { "gpio_in", "gpio_out", "csi", "ts", NULL, NULL, "irq" }, 6, 11, 2 }, 129 { "PE12", 4, 12, { "gpio_in", "gpio_out", "csi", "ts", NULL, NULL, "irq" }, 6, 12, 2 }, 130 { "PE13", 4, 13, { "gpio_in", "gpio_out", "csi", "ts", NULL, NULL, "irq" }, 6, 13, 2 }, 131 { "PE14", 4, 14, { "gpio_in", "gpio_out", "csi", "ts", NULL, NULL, "irq" }, 6, 14, 2 }, 132 { "PE15", 4, 15, { "gpio_in", "gpio_out", "csi", "ts", NULL, NULL, "irq" }, 6, 15, 2 }, 133 { "PE16", 4, 16, { "gpio_in", "gpio_out", "csi", "i2c4", NULL, NULL, "irq" }, 6, 16, 2 }, 134 { "PE17", 4, 17, { "gpio_in", "gpio_out", "csi", "i2c4", NULL, NULL, "irq" }, 6, 17, 2 }, 135 136 { "PF0", 5, 0, { "gpio_in", "gpio_out", "mmc0" } }, 137 { "PF1", 5, 1, { "gpio_in", "gpio_out", "mmc0" } }, 138 { "PF2", 5, 2, { "gpio_in", "gpio_out", "mmc0", "uart0" } }, 139 { "PF3", 5, 3, { "gpio_in", "gpio_out", "mmc0" } }, 140 { "PF4", 5, 4, { "gpio_in", "gpio_out", "mmc0", "uart0" } }, 141 { "PF5", 5, 5, { "gpio_in", "gpio_out", "mmc0" } }, 142 143 { "PG0", 6, 0, { "gpio_in", "gpio_out", "mmc1", NULL, NULL, NULL, "irq" }, 6, 0, 3 }, 144 { "PG1", 6, 1, { "gpio_in", "gpio_out", "mmc1", NULL, NULL, NULL, "irq" }, 6, 1, 3 }, 145 { "PG2", 6, 2, { "gpio_in", "gpio_out", "mmc1", NULL, NULL, NULL, "irq" }, 6, 2, 3 }, 146 { "PG3", 6, 3, { "gpio_in", "gpio_out", "mmc1", NULL, NULL, NULL, "irq" }, 6, 3, 3 }, 147 { "PG4", 6, 4, { "gpio_in", "gpio_out", "mmc1", NULL, NULL, NULL, "irq" }, 6, 4, 3 }, 148 { "PG5", 6, 5, { "gpio_in", "gpio_out", "mmc1", NULL, NULL, NULL, "irq" }, 6, 5, 3 }, 149 { "PG6", 6, 6, { "gpio_in", "gpio_out", "uart2", NULL, NULL, NULL, "irq" }, 6, 6, 3 }, 150 { "PG7", 6, 7, { "gpio_in", "gpio_out", "uart2", NULL, NULL, NULL, "irq" }, 6, 7, 3 }, 151 { "PG8", 6, 8, { "gpio_in", "gpio_out", "uart2", NULL, NULL, NULL, "irq" }, 6, 8, 3 }, 152 { "PG9", 6, 9, { "gpio_in", "gpio_out", "uart2", NULL, NULL, NULL, "irq" }, 6, 9, 3 }, 153 { "PG10", 6, 10, { "gpio_in", "gpio_out", "i2c3", NULL, NULL, NULL, "irq" }, 6, 10, 3 }, 154 { "PG11", 6, 11, { "gpio_in", "gpio_out", "i2c3", NULL, NULL, NULL, "irq" }, 6, 11, 3 }, 155 { "PG12", 6, 12, { "gpio_in", "gpio_out", "uart4", NULL, NULL, NULL, "irq" }, 6, 12, 3 }, 156 { "PG13", 6, 13, { "gpio_in", "gpio_out", "uart4", NULL, NULL, NULL, "irq" }, 6, 13, 3 }, 157 { "PG14", 6, 14, { "gpio_in", "gpio_out", "uart4", NULL, NULL, NULL, "irq" }, 6, 14, 3 }, 158 { "PG15", 6, 15, { "gpio_in", "gpio_out", "uart4", NULL, NULL, NULL, "irq" }, 6, 15, 3 }, 159 160 { "PH0", 7, 0, { "gpio_in", "gpio_out", "i2c0" } }, 161 { "PH1", 7, 1, { "gpio_in", "gpio_out", "i2c0" } }, 162 { "PH2", 7, 2, { "gpio_in", "gpio_out", "i2c1" } }, 163 { "PH3", 7, 3, { "gpio_in", "gpio_out", "i2c1" } }, 164 { "PH4", 7, 4, { "gpio_in", "gpio_out", "i2c2" } }, 165 { "PH5", 7, 5, { "gpio_in", "gpio_out", "i2c2" } }, 166 { "PH6", 7, 6, { "gpio_in", "gpio_out", "pwm0" } }, 167 { "PH8", 7, 8, { "gpio_in", "gpio_out", NULL, "pwm1", NULL, NULL, "irq" }, 6, 8, 4 }, 168 { "PH9", 7, 9, { "gpio_in", "gpio_out", NULL, "pwm1", NULL, NULL, "irq" }, 6, 9, 4 }, 169 { "PH10", 7, 10, { "gpio_in", "gpio_out", NULL, "pwm2", NULL, NULL, "irq" }, 6, 10, 4 }, 170 { "PH11", 7, 11, { "gpio_in", "gpio_out", NULL, "pwm2", NULL, NULL, "irq" }, 6, 11, 4 }, 171 { "PH12", 7, 12, { "gpio_in", "gpio_out", "uart0", "spi3", NULL, NULL, "irq" }, 6, 12, 4 }, 172 { "PH13", 7, 13, { "gpio_in", "gpio_out", "uart0", "spi3", NULL, NULL, "irq" }, 6, 13, 4 }, 173 { "PH14", 7, 14, { "gpio_in", "gpio_out", "spi3", NULL, NULL, NULL, "irq" }, 6, 14, 4 }, 174 { "PH15", 7, 15, { "gpio_in", "gpio_out", "spi3", NULL, NULL, NULL, "irq" }, 6, 15, 4 }, 175 { "PH16", 7, 16, { "gpio_in", "gpio_out", "spi3", NULL, NULL, NULL, "irq" }, 6, 16, 4 }, 176 { "PH17", 7, 17, { "gpio_in", "gpio_out", "spi3", NULL, NULL, NULL, "irq" }, 6, 17, 4 }, 177 { "PH18", 7, 18, { "gpio_in", "gpio_out", "spi3", NULL, NULL, NULL, "irq" }, 6, 18, 4 }, 178 { "PH19", 7, 19, { "gpio_in", "gpio_out", "hdmi" } }, 179 { "PH20", 7, 20, { "gpio_in", "gpio_out", "hdmi" } }, 180 { "PH21", 7, 21, { "gpio_in", "gpio_out", "hdmi" } }, 181 }; 182 183 static const struct sunxi_gpio_pins a80_r_pins[] = { 184 { "PL0", 0, 0, { "gpio_in", "gpio_out", NULL, "s_uart", NULL, NULL, "irq" }, 6, 0, 0 }, 185 { "PL1", 0, 1, { "gpio_in", "gpio_out", NULL, "s_uart", NULL, NULL, "irq" }, 6, 1, 0 }, 186 { "PL2", 0, 2, { "gpio_in", "gpio_out", NULL, "s_jtag", NULL, NULL, "irq" }, 6, 2, 0 }, 187 { "PL3", 0, 3, { "gpio_in", "gpio_out", NULL, "s_jtag", NULL, NULL, "irq" }, 6, 3, 0 }, 188 { "PL4", 0, 4, { "gpio_in", "gpio_out", NULL, "s_jtag", NULL, NULL, "irq" }, 6, 4, 0 }, 189 { "PL5", 0, 5, { "gpio_in", "gpio_out", NULL, "s_jtag", NULL, NULL, "irq" }, 6, 5, 0 }, 190 { "PL6", 0, 6, { "gpio_in", "gpio_out", NULL, "s_cir_rx", NULL, NULL, "irq" }, 6, 6, 0 }, 191 { "PL7", 0, 7, { "gpio_in", "gpio_out", NULL, "1wire", NULL, NULL, "irq" }, 6, 7, 0 }, 192 { "PL8", 0, 8, { "gpio_in", "gpio_out", "s_ps2", NULL, NULL, NULL, "irq" }, 6, 8, 0 }, 193 { "PL9", 0, 9, { "gpio_in", "gpio_out", "s_ps2", NULL, NULL, NULL, "irq" }, 6, 9, 0 }, 194 195 { "PM0", 1, 0, { "gpio_in", "gpio_out", NULL, NULL, NULL, NULL, "irq" }, 6, 0, 1 }, 196 { "PM1", 1, 1, { "gpio_in", "gpio_out", NULL, NULL, NULL, NULL, "irq" }, 6, 1, 1 }, 197 { "PM2", 1, 2, { "gpio_in", "gpio_out", NULL, NULL, NULL, NULL, "irq" }, 6, 2, 1 }, 198 { "PM3", 1, 3, { "gpio_in", "gpio_out", NULL, NULL, NULL, NULL, "irq" }, 6, 3, 1 }, 199 { "PM4", 1, 4, { "gpio_in", "gpio_out", NULL, "s_i2s1", NULL, NULL, "irq" }, 6, 4, 1 }, 200 { "PM8", 1, 8, { "gpio_in", "gpio_out", NULL, "s_i2c1", NULL, NULL, "irq" }, 6, 8, 1 }, 201 { "PM9", 1, 9, { "gpio_in", "gpio_out", NULL, "s_i2c1", NULL, NULL, "irq" }, 6, 9, 1 }, 202 { "PM10", 1, 10, { "gpio_in", "gpio_out", "s_i2s0", "s_i2s1" } }, 203 { "PM11", 1, 11, { "gpio_in", "gpio_out", "s_i2s0", "s_i2s1" } }, 204 { "PM12", 1, 12, { "gpio_in", "gpio_out", "s_i2s0", "s_i2s1" } }, 205 { "PM13", 1, 13, { "gpio_in", "gpio_out", "s_i2s0", "s_i2s1" } }, 206 { "PM14", 1, 14, { "gpio_in", "gpio_out", "s_i2s0", "s_i2s1" } }, 207 { "PM15", 1, 15, { "gpio_in", "gpio_out", NULL, NULL, NULL, NULL, "irq" }, 6, 15, 1 }, 208 209 { "PN0", 2, 0, { "gpio_in", "gpio_out", "s_i2c0", "s_rsb" } }, 210 { "PN1", 2, 1, { "gpio_in", "gpio_out", "s_i2c0", "s_rsb" } }, 211 }; 212 213 const struct sunxi_gpio_padconf sun9i_a80_padconf = { 214 .npins = __arraycount(a80_pins), 215 .pins = a80_pins, 216 .has_io_bias_config = true, 217 }; 218 219 const struct sunxi_gpio_padconf sun9i_a80_r_padconf = { 220 .npins = __arraycount(a80_r_pins), 221 .pins = a80_r_pins, 222 .has_io_bias_config = true, 223 }; 224