xref: /netbsd-src/sys/arch/arm/sunxi/sun8i_h3_gpio.c (revision ae9a338900c356abb10dd6e267ed8e45440bc723)
1*ae9a3389Sjmcneill /* $NetBSD: sun8i_h3_gpio.c,v 1.3 2019/01/31 00:27:52 jmcneill Exp $ */
249f361a5Sjmcneill 
349f361a5Sjmcneill /*-
449f361a5Sjmcneill  * Copyright (c) 2016 Emmanuel Vadot <manu@freebsd.org>
549f361a5Sjmcneill  * All rights reserved.
649f361a5Sjmcneill  *
749f361a5Sjmcneill  * Redistribution and use in source and binary forms, with or without
849f361a5Sjmcneill  * modification, are permitted provided that the following conditions
949f361a5Sjmcneill  * are met:
1049f361a5Sjmcneill  * 1. Redistributions of source code must retain the above copyright
1149f361a5Sjmcneill  *    notice, this list of conditions and the following disclaimer.
1249f361a5Sjmcneill  * 2. Redistributions in binary form must reproduce the above copyright
1349f361a5Sjmcneill  *    notice, this list of conditions and the following disclaimer in the
1449f361a5Sjmcneill  *    documentation and/or other materials provided with the distribution.
1549f361a5Sjmcneill  *
1649f361a5Sjmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1749f361a5Sjmcneill  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1849f361a5Sjmcneill  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1949f361a5Sjmcneill  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2049f361a5Sjmcneill  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2149f361a5Sjmcneill  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2249f361a5Sjmcneill  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2349f361a5Sjmcneill  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2449f361a5Sjmcneill  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2549f361a5Sjmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2649f361a5Sjmcneill  * SUCH DAMAGE.
2749f361a5Sjmcneill  *
2849f361a5Sjmcneill  */
2949f361a5Sjmcneill 
3049f361a5Sjmcneill #include <sys/cdefs.h>
31*ae9a3389Sjmcneill __KERNEL_RCSID(0, "$NetBSD: sun8i_h3_gpio.c,v 1.3 2019/01/31 00:27:52 jmcneill Exp $");
3249f361a5Sjmcneill 
3349f361a5Sjmcneill #include <sys/param.h>
3449f361a5Sjmcneill #include <sys/systm.h>
3549f361a5Sjmcneill #include <sys/kernel.h>
3649f361a5Sjmcneill #include <sys/types.h>
3749f361a5Sjmcneill 
3849f361a5Sjmcneill #include <arm/sunxi/sunxi_gpio.h>
3949f361a5Sjmcneill 
4049f361a5Sjmcneill static const struct sunxi_gpio_pins h3_pins[] = {
41943dba72Sbouyer 	{"PA0",  0, 0,  {"gpio_in", "gpio_out", "uart2", "jtag", NULL, NULL, "irq", NULL}, 6, 0},
42943dba72Sbouyer 	{"PA1",  0, 1,  {"gpio_in", "gpio_out", "uart2", "jtag", NULL, NULL, "irq", NULL}, 6, 1},
43943dba72Sbouyer 	{"PA2",  0, 2,  {"gpio_in", "gpio_out", "uart2", "jtag", NULL, NULL, "irq", NULL}, 6, 2},
44943dba72Sbouyer 	{"PA3",  0, 3,  {"gpio_in", "gpio_out", "uart2", "jtag", NULL, NULL, "irq", NULL}, 6, 3},
45943dba72Sbouyer 	{"PA4",  0, 4,  {"gpio_in", "gpio_out", "uart0", NULL, NULL, NULL, "irq", NULL}, 6, 4},
46943dba72Sbouyer 	{"PA5",  0, 5,  {"gpio_in", "gpio_out", "uart0", "pwm0", NULL, NULL, "irq", NULL}, 6, 5},
47943dba72Sbouyer 	{"PA6",  0, 6,  {"gpio_in", "gpio_out", "sim", NULL, NULL, NULL, "irq", NULL}, 6, 6},
48943dba72Sbouyer 	{"PA7",  0, 7,  {"gpio_in", "gpio_out", "sim", NULL, NULL, NULL, "irq", NULL}, 6, 7},
49943dba72Sbouyer 	{"PA8",  0, 8,  {"gpio_in", "gpio_out", "sim", NULL, NULL, NULL, "irq", NULL}, 6, 8},
50943dba72Sbouyer 	{"PA9",  0, 9,  {"gpio_in", "gpio_out", "sim", NULL, NULL, NULL, "irq", NULL}, 6, 9},
51943dba72Sbouyer 	{"PA10", 0, 10, {"gpio_in", "gpio_out", "sim", NULL, NULL, NULL, "irq", NULL}, 6, 10},
52943dba72Sbouyer 	{"PA11", 0, 11, {"gpio_in", "gpio_out", "i2c0", "di", NULL, NULL, "irq", NULL}, 6, 11},
53943dba72Sbouyer 	{"PA12", 0, 12, {"gpio_in", "gpio_out", "i2c0", "di", NULL, NULL, "irq", NULL}, 6, 12},
54943dba72Sbouyer 	{"PA13", 0, 13, {"gpio_in", "gpio_out", "spi1", "uart3", NULL, NULL, "irq", NULL}, 6, 13},
55943dba72Sbouyer 	{"PA14", 0, 14, {"gpio_in", "gpio_out", "spi1", "uart3", NULL, NULL, "irq", NULL}, 6, 14},
56943dba72Sbouyer 	{"PA15", 0, 15, {"gpio_in", "gpio_out", "spi1", "uart3", NULL, NULL, "irq", NULL}, 6, 15},
57943dba72Sbouyer 	{"PA16", 0, 16, {"gpio_in", "gpio_out", "spi1", "uart3", NULL, NULL, "irq", NULL}, 6, 16},
58943dba72Sbouyer 	{"PA17", 0, 17, {"gpio_in", "gpio_out", "spdif", NULL, NULL, NULL, "irq", NULL}, 6, 17},
59943dba72Sbouyer 	{"PA18", 0, 18, {"gpio_in", "gpio_out", "i2s0", "i2c1", NULL, NULL, "irq", NULL}, 6, 18},
60943dba72Sbouyer 	{"PA19", 0, 19, {"gpio_in", "gpio_out", "i2s0", "i2c1", NULL, NULL, "irq", NULL}, 6, 19},
61943dba72Sbouyer 	{"PA20", 0, 20, {"gpio_in", "gpio_out", "i2s0", "sim", NULL, NULL, "irq", NULL}, 6, 20},
62943dba72Sbouyer 	{"PA21", 0, 21, {"gpio_in", "gpio_out", "i2s0", "sim", NULL, NULL, "irq", NULL}, 6, 21},
6349f361a5Sjmcneill 
6449f361a5Sjmcneill 	{"PC0",  2, 0,  {"gpio_in", "gpio_out", "nand", "spi0", NULL, NULL, NULL, NULL}},
6549f361a5Sjmcneill 	{"PC1",  2, 1,  {"gpio_in", "gpio_out", "nand", "spi0", NULL, NULL, NULL, NULL}},
6649f361a5Sjmcneill 	{"PC2",  2, 2,  {"gpio_in", "gpio_out", "nand", "spi0", NULL, NULL, NULL, NULL}},
6749f361a5Sjmcneill 	{"PC3",  2, 3,  {"gpio_in", "gpio_out", "nand", "spi0", NULL, NULL, NULL, NULL}},
6849f361a5Sjmcneill 	{"PC4",  2, 4,  {"gpio_in", "gpio_out", "nand", NULL, NULL, NULL, NULL, NULL}},
6949f361a5Sjmcneill 	{"PC5",  2, 5,  {"gpio_in", "gpio_out", "nand", "mmc2", NULL, NULL, NULL, NULL}},
7049f361a5Sjmcneill 	{"PC6",  2, 6,  {"gpio_in", "gpio_out", "nand", "mmc2", NULL, NULL, NULL, NULL}},
7149f361a5Sjmcneill 	{"PC7",  2, 7,  {"gpio_in", "gpio_out", "nand", NULL, NULL, NULL, NULL, NULL}},
7249f361a5Sjmcneill 	{"PC8",  2, 8,  {"gpio_in", "gpio_out", "nand", "mmc2", NULL, NULL, NULL, NULL}},
7349f361a5Sjmcneill 	{"PC9",  2, 9,  {"gpio_in", "gpio_out", "nand", "mmc2", NULL, NULL, NULL, NULL}},
7449f361a5Sjmcneill 	{"PC10", 2, 10, {"gpio_in", "gpio_out", "nand", "mmc2", NULL, NULL, NULL, NULL}},
7549f361a5Sjmcneill 	{"PC11", 2, 11, {"gpio_in", "gpio_out", "nand", "mmc2", NULL, NULL, NULL, NULL}},
7649f361a5Sjmcneill 	{"PC12", 2, 12, {"gpio_in", "gpio_out", "nand", "mmc2", NULL, NULL, NULL, NULL}},
7749f361a5Sjmcneill 	{"PC13", 2, 13, {"gpio_in", "gpio_out", "nand", "mmc2", NULL, NULL, NULL, NULL}},
7849f361a5Sjmcneill 	{"PC14", 2, 14, {"gpio_in", "gpio_out", "nand", "mmc2", NULL, NULL, NULL, NULL}},
7949f361a5Sjmcneill 	{"PC15", 2, 15, {"gpio_in", "gpio_out", "nand", "mmc2", NULL, NULL, NULL, NULL}},
8049f361a5Sjmcneill 	{"PC16", 2, 16, {"gpio_in", "gpio_out", "nand", "mmc2", NULL, NULL, NULL, NULL}},
8149f361a5Sjmcneill 
8249f361a5Sjmcneill 	{"PD0",  3, 0,  {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
8349f361a5Sjmcneill 	{"PD1",  3, 1,  {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
8449f361a5Sjmcneill 	{"PD2",  3, 2,  {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
8549f361a5Sjmcneill 	{"PD3",  3, 3,  {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
8649f361a5Sjmcneill 	{"PD4",  3, 4,  {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
8749f361a5Sjmcneill 	{"PD5",  3, 5,  {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
8849f361a5Sjmcneill 	{"PD6",  3, 6,  {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
8949f361a5Sjmcneill 	{"PD7",  3, 7,  {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
9049f361a5Sjmcneill 	{"PD8",  3, 8,  {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
9149f361a5Sjmcneill 	{"PD9",  3, 9,  {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
9249f361a5Sjmcneill 	{"PD10", 3, 10, {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
9349f361a5Sjmcneill 	{"PD11", 3, 11, {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
9449f361a5Sjmcneill 	{"PD12", 3, 12, {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
9549f361a5Sjmcneill 	{"PD13", 3, 13, {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
9649f361a5Sjmcneill 	{"PD14", 3, 14, {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
9749f361a5Sjmcneill 	{"PD15", 3, 15, {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
9849f361a5Sjmcneill 	{"PD16", 3, 16, {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
9949f361a5Sjmcneill 	{"PD17", 3, 17, {"gpio_in", "gpio_out", "emac", NULL, NULL, NULL, NULL, NULL}},
10049f361a5Sjmcneill 
10149f361a5Sjmcneill 	{"PE0",  4, 0,  {"gpio_in", "gpio_out", "csi", "ts", NULL, NULL, NULL, NULL}},
10249f361a5Sjmcneill 	{"PE1",  4, 1,  {"gpio_in", "gpio_out", "csi", "ts", NULL, NULL, NULL, NULL}},
10349f361a5Sjmcneill 	{"PE2",  4, 2,  {"gpio_in", "gpio_out", "csi", "ts", NULL, NULL, NULL, NULL}},
10449f361a5Sjmcneill 	{"PE3",  4, 3,  {"gpio_in", "gpio_out", "csi", "ts", NULL, NULL, NULL, NULL}},
10549f361a5Sjmcneill 	{"PE4",  4, 4,  {"gpio_in", "gpio_out", "csi", "ts", NULL, NULL, NULL, NULL}},
10649f361a5Sjmcneill 	{"PE5",  4, 5,  {"gpio_in", "gpio_out", "csi", "ts", NULL, NULL, NULL, NULL}},
10749f361a5Sjmcneill 	{"PE6",  4, 6,  {"gpio_in", "gpio_out", "csi", "ts", NULL, NULL, NULL, NULL}},
10849f361a5Sjmcneill 	{"PE7",  4, 7,  {"gpio_in", "gpio_out", "csi", "ts", NULL, NULL, NULL, NULL}},
10949f361a5Sjmcneill 	{"PE8",  4, 8,  {"gpio_in", "gpio_out", "csi", "ts", NULL, NULL, NULL, NULL}},
11049f361a5Sjmcneill 	{"PE9",  4, 9,  {"gpio_in", "gpio_out", "csi", "ts", NULL, NULL, NULL, NULL}},
11149f361a5Sjmcneill 	{"PE10", 4, 10, {"gpio_in", "gpio_out", "csi", "ts", NULL, NULL, NULL, NULL}},
11249f361a5Sjmcneill 	{"PE11", 4, 11, {"gpio_in", "gpio_out", "csi", "ts", NULL, NULL, NULL, NULL}},
11349f361a5Sjmcneill 	{"PE12", 4, 12, {"gpio_in", "gpio_out", "csi", "i2c2", NULL, NULL, NULL, NULL}},
11449f361a5Sjmcneill 	{"PE13", 4, 13, {"gpio_in", "gpio_out", "csi", "i2c2", NULL, NULL, NULL, NULL}},
11549f361a5Sjmcneill 	{"PE14", 4, 14, {"gpio_in", "gpio_out", NULL, NULL, NULL, NULL, NULL, NULL}},
11649f361a5Sjmcneill 	{"PE15", 4, 15, {"gpio_in", "gpio_out", NULL, NULL, NULL, NULL, NULL, NULL}},
11749f361a5Sjmcneill 
11849f361a5Sjmcneill 	{"PF0",  5, 0,  {"gpio_in", "gpio_out", "mmc0", "jtag", NULL, NULL, NULL, NULL}},
11949f361a5Sjmcneill 	{"PF1",  5, 1,  {"gpio_in", "gpio_out", "mmc0", "jtag", NULL, NULL, NULL, NULL}},
12049f361a5Sjmcneill 	{"PF2",  5, 2,  {"gpio_in", "gpio_out", "mmc0", "uart0", NULL, NULL, NULL, NULL}},
12149f361a5Sjmcneill 	{"PF3",  5, 3,  {"gpio_in", "gpio_out", "mmc0", "jtag", NULL, NULL, NULL, NULL}},
12249f361a5Sjmcneill 	{"PF4",  5, 4,  {"gpio_in", "gpio_out", "mmc0", "uart0", NULL, NULL, NULL, NULL}},
12349f361a5Sjmcneill 	{"PF5",  5, 5,  {"gpio_in", "gpio_out", "mmc0", "jtag", NULL, NULL, NULL, NULL}},
12449f361a5Sjmcneill 	{"PF6",  5, 6,  {"gpio_in", "gpio_out", NULL, NULL, NULL, NULL, NULL, NULL}},
12549f361a5Sjmcneill 
126943dba72Sbouyer 	{"PG0",  6, 0,  {"gpio_in", "gpio_out", "mmc1", NULL, NULL, NULL, "irq", NULL}, 6, 0},
127943dba72Sbouyer 	{"PG1",  6, 1,  {"gpio_in", "gpio_out", "mmc1", NULL, NULL, NULL, "irq", NULL}, 6, 1},
128943dba72Sbouyer 	{"PG2",  6, 2,  {"gpio_in", "gpio_out", "mmc1", NULL, NULL, NULL, "irq", NULL}, 6, 2},
129943dba72Sbouyer 	{"PG3",  6, 3,  {"gpio_in", "gpio_out", "mmc1", NULL, NULL, NULL, "irq", NULL}, 6, 3},
130943dba72Sbouyer 	{"PG4",  6, 4,  {"gpio_in", "gpio_out", "mmc1", NULL, NULL, NULL, "irq", NULL}, 6, 4},
131943dba72Sbouyer 	{"PG5",  6, 5,  {"gpio_in", "gpio_out", "mmc1", NULL, NULL, NULL, "irq", NULL}, 6, 5},
132943dba72Sbouyer 	{"PG6",  6, 6,  {"gpio_in", "gpio_out", "uart1", NULL, NULL, NULL, "irq", NULL}, 6, 6},
133943dba72Sbouyer 	{"PG7",  6, 7,  {"gpio_in", "gpio_out", "uart1", NULL, NULL, NULL, "irq", NULL}, 6, 7},
134943dba72Sbouyer 	{"PG8",  6, 8,  {"gpio_in", "gpio_out", "uart1", NULL, NULL, NULL, "irq", NULL}, 6, 8},
135943dba72Sbouyer 	{"PG9",  6, 9,  {"gpio_in", "gpio_out", "uart1", NULL, NULL, NULL, "irq", NULL}, 6, 9},
136943dba72Sbouyer 	{"PG10", 6, 10, {"gpio_in", "gpio_out", "i2s1", NULL, NULL, NULL, "irq", NULL}, 6, 10},
137943dba72Sbouyer 	{"PG11", 6, 11, {"gpio_in", "gpio_out", "i2s1", NULL, NULL, NULL, "irq", NULL}, 6, 11},
138943dba72Sbouyer 	{"PG12", 6, 12, {"gpio_in", "gpio_out", "i2s1", NULL, NULL, NULL, "irq", NULL}, 6, 12},
139943dba72Sbouyer 	{"PG13", 6, 13, {"gpio_in", "gpio_out", "i2s1", NULL, NULL, NULL, "irq", NULL}, 6, 13},
14049f361a5Sjmcneill };
14149f361a5Sjmcneill 
14249f361a5Sjmcneill static const struct sunxi_gpio_pins h3_r_pins[] = {
143*ae9a3389Sjmcneill 	{"PL0",  0, 0,  {"gpio_in", "gpio_out", "s_i2c", NULL, NULL, NULL, "irq", NULL}, 6, 0},
144*ae9a3389Sjmcneill 	{"PL1",  0, 1,  {"gpio_in", "gpio_out", "s_i2c", NULL, NULL, NULL, "irq", NULL}, 6, 1},
145943dba72Sbouyer 	{"PL2",  0, 2,  {"gpio_in", "gpio_out", "s_uart", NULL, NULL, NULL, "irq", NULL}, 6, 2},
146943dba72Sbouyer 	{"PL3",  0, 3,  {"gpio_in", "gpio_out", "s_uart", NULL, NULL, NULL, "irq", NULL}, 6, 3},
147943dba72Sbouyer 	{"PL4",  0, 4,  {"gpio_in", "gpio_out", "s_jtag", NULL, NULL, NULL, "irq", NULL}, 6, 4},
148943dba72Sbouyer 	{"PL5",  0, 5,  {"gpio_in", "gpio_out", "s_jtag", NULL, NULL, NULL, "irq", NULL}, 6, 5},
149943dba72Sbouyer 	{"PL6",  0, 6,  {"gpio_in", "gpio_out", "s_jtag", NULL, NULL, NULL, "irq", NULL}, 6, 6},
150943dba72Sbouyer 	{"PL7",  0, 7,  {"gpio_in", "gpio_out", "s_jtag", NULL, NULL, NULL, "irq", NULL}, 6, 7},
151943dba72Sbouyer 	{"PL8",  0, 8,  {"gpio_in", "gpio_out", NULL, NULL, NULL, NULL, "irq", NULL}, 6, 8},
152943dba72Sbouyer 	{"PL9",  0, 9,  {"gpio_in", "gpio_out", NULL, NULL, NULL, NULL, "irq", NULL}, 6, 9},
153943dba72Sbouyer 	{"PL10", 0, 10, {"gpio_in", "gpio_out", "s_pwm", NULL, NULL, NULL, "irq", NULL}, 6, 10},
154943dba72Sbouyer 	{"PL11", 0, 11, {"gpio_in", "gpio_out", "s_cir_rx", NULL, NULL, NULL, "irq", NULL}, 6, 11},
15549f361a5Sjmcneill };
15649f361a5Sjmcneill 
15749f361a5Sjmcneill const struct sunxi_gpio_padconf sun8i_h3_padconf = {
15849f361a5Sjmcneill 	.npins = __arraycount(h3_pins),
15949f361a5Sjmcneill 	.pins = h3_pins,
16049f361a5Sjmcneill };
16149f361a5Sjmcneill 
16249f361a5Sjmcneill const struct sunxi_gpio_padconf sun8i_h3_r_padconf = {
16349f361a5Sjmcneill 	.npins = __arraycount(h3_r_pins),
16449f361a5Sjmcneill 	.pins = h3_r_pins,
16549f361a5Sjmcneill };
166