1*155cca1bSÁlvaro Fernández Rojas // SPDX-License-Identifier: GPL-2.0+ 2*155cca1bSÁlvaro Fernández Rojas /* 3*155cca1bSÁlvaro Fernández Rojas * Driver for BCM63268 GPIO unit (pinctrl + GPIO) 4*155cca1bSÁlvaro Fernández Rojas * 5*155cca1bSÁlvaro Fernández Rojas * Copyright (C) 2021 Álvaro Fernández Rojas <noltari@gmail.com> 6*155cca1bSÁlvaro Fernández Rojas * Copyright (C) 2016 Jonas Gorski <jonas.gorski@gmail.com> 7*155cca1bSÁlvaro Fernández Rojas */ 8*155cca1bSÁlvaro Fernández Rojas 9*155cca1bSÁlvaro Fernández Rojas #include <linux/bits.h> 10*155cca1bSÁlvaro Fernández Rojas #include <linux/gpio/driver.h> 11*155cca1bSÁlvaro Fernández Rojas #include <linux/kernel.h> 12*155cca1bSÁlvaro Fernández Rojas #include <linux/of.h> 13*155cca1bSÁlvaro Fernández Rojas #include <linux/pinctrl/pinmux.h> 14*155cca1bSÁlvaro Fernández Rojas #include <linux/platform_device.h> 15*155cca1bSÁlvaro Fernández Rojas #include <linux/regmap.h> 16*155cca1bSÁlvaro Fernández Rojas 17*155cca1bSÁlvaro Fernández Rojas #include "../pinctrl-utils.h" 18*155cca1bSÁlvaro Fernández Rojas 19*155cca1bSÁlvaro Fernández Rojas #include "pinctrl-bcm63xx.h" 20*155cca1bSÁlvaro Fernández Rojas 21*155cca1bSÁlvaro Fernández Rojas #define BCM63268_NUM_GPIOS 52 22*155cca1bSÁlvaro Fernández Rojas #define BCM63268_NUM_LEDS 24 23*155cca1bSÁlvaro Fernández Rojas 24*155cca1bSÁlvaro Fernández Rojas #define BCM63268_LED_REG 0x10 25*155cca1bSÁlvaro Fernández Rojas #define BCM63268_MODE_REG 0x18 26*155cca1bSÁlvaro Fernández Rojas #define BCM63268_CTRL_REG 0x1c 27*155cca1bSÁlvaro Fernández Rojas #define BCM63268_BASEMODE_REG 0x38 28*155cca1bSÁlvaro Fernández Rojas #define BCM63268_BASEMODE_NAND BIT(2) /* GPIOs 2-7, 24-31 */ 29*155cca1bSÁlvaro Fernández Rojas #define BCM63268_BASEMODE_GPIO35 BIT(4) /* GPIO 35 */ 30*155cca1bSÁlvaro Fernández Rojas #define BCM63268_BASEMODE_DECTPD BIT(5) /* GPIOs 8/9 */ 31*155cca1bSÁlvaro Fernández Rojas #define BCM63268_BASEMODE_VDSL_PHY_0 BIT(6) /* GPIOs 10/11 */ 32*155cca1bSÁlvaro Fernández Rojas #define BCM63268_BASEMODE_VDSL_PHY_1 BIT(7) /* GPIOs 12/13 */ 33*155cca1bSÁlvaro Fernández Rojas #define BCM63268_BASEMODE_VDSL_PHY_2 BIT(8) /* GPIOs 24/25 */ 34*155cca1bSÁlvaro Fernández Rojas #define BCM63268_BASEMODE_VDSL_PHY_3 BIT(9) /* GPIOs 26/27 */ 35*155cca1bSÁlvaro Fernández Rojas 36*155cca1bSÁlvaro Fernández Rojas enum bcm63268_pinctrl_reg { 37*155cca1bSÁlvaro Fernández Rojas BCM63268_LEDCTRL, 38*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE, 39*155cca1bSÁlvaro Fernández Rojas BCM63268_CTRL, 40*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE, 41*155cca1bSÁlvaro Fernández Rojas }; 42*155cca1bSÁlvaro Fernández Rojas 43*155cca1bSÁlvaro Fernández Rojas struct bcm63268_pingroup { 44*155cca1bSÁlvaro Fernández Rojas const char *name; 45*155cca1bSÁlvaro Fernández Rojas const unsigned * const pins; 46*155cca1bSÁlvaro Fernández Rojas const unsigned num_pins; 47*155cca1bSÁlvaro Fernández Rojas }; 48*155cca1bSÁlvaro Fernández Rojas 49*155cca1bSÁlvaro Fernández Rojas struct bcm63268_function { 50*155cca1bSÁlvaro Fernández Rojas const char *name; 51*155cca1bSÁlvaro Fernández Rojas const char * const *groups; 52*155cca1bSÁlvaro Fernández Rojas const unsigned num_groups; 53*155cca1bSÁlvaro Fernández Rojas 54*155cca1bSÁlvaro Fernández Rojas enum bcm63268_pinctrl_reg reg; 55*155cca1bSÁlvaro Fernández Rojas uint32_t mask; 56*155cca1bSÁlvaro Fernández Rojas }; 57*155cca1bSÁlvaro Fernández Rojas 58*155cca1bSÁlvaro Fernández Rojas #define BCM63268_PIN(a, b, basemode) \ 59*155cca1bSÁlvaro Fernández Rojas { \ 60*155cca1bSÁlvaro Fernández Rojas .number = a, \ 61*155cca1bSÁlvaro Fernández Rojas .name = b, \ 62*155cca1bSÁlvaro Fernández Rojas .drv_data = (void *)(basemode) \ 63*155cca1bSÁlvaro Fernández Rojas } 64*155cca1bSÁlvaro Fernández Rojas 65*155cca1bSÁlvaro Fernández Rojas static const struct pinctrl_pin_desc bcm63268_pins[] = { 66*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(0, "gpio0"), 67*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(1, "gpio1"), 68*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(2, "gpio2", BCM63268_BASEMODE_NAND), 69*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(3, "gpio3", BCM63268_BASEMODE_NAND), 70*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(4, "gpio4", BCM63268_BASEMODE_NAND), 71*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(5, "gpio5", BCM63268_BASEMODE_NAND), 72*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(6, "gpio6", BCM63268_BASEMODE_NAND), 73*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(7, "gpio7", BCM63268_BASEMODE_NAND), 74*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(8, "gpio8", BCM63268_BASEMODE_DECTPD), 75*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(9, "gpio9", BCM63268_BASEMODE_DECTPD), 76*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(10, "gpio10", BCM63268_BASEMODE_VDSL_PHY_0), 77*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(11, "gpio11", BCM63268_BASEMODE_VDSL_PHY_0), 78*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(12, "gpio12", BCM63268_BASEMODE_VDSL_PHY_1), 79*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(13, "gpio13", BCM63268_BASEMODE_VDSL_PHY_1), 80*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(14, "gpio14"), 81*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(15, "gpio15"), 82*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(16, "gpio16"), 83*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(17, "gpio17"), 84*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(18, "gpio18"), 85*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(19, "gpio19"), 86*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(20, "gpio20"), 87*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(21, "gpio21"), 88*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(22, "gpio22"), 89*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(23, "gpio23"), 90*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(24, "gpio24", 91*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_NAND | BCM63268_BASEMODE_VDSL_PHY_2), 92*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(25, "gpio25", 93*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_NAND | BCM63268_BASEMODE_VDSL_PHY_2), 94*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(26, "gpio26", 95*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_NAND | BCM63268_BASEMODE_VDSL_PHY_3), 96*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(27, "gpio27", 97*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_NAND | BCM63268_BASEMODE_VDSL_PHY_3), 98*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(28, "gpio28", BCM63268_BASEMODE_NAND), 99*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(29, "gpio29", BCM63268_BASEMODE_NAND), 100*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(30, "gpio30", BCM63268_BASEMODE_NAND), 101*155cca1bSÁlvaro Fernández Rojas BCM63268_PIN(31, "gpio31", BCM63268_BASEMODE_NAND), 102*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(32, "gpio32"), 103*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(33, "gpio33"), 104*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(34, "gpio34"), 105*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(35, "gpio35"), 106*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(36, "gpio36"), 107*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(37, "gpio37"), 108*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(38, "gpio38"), 109*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(39, "gpio39"), 110*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(40, "gpio40"), 111*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(41, "gpio41"), 112*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(42, "gpio42"), 113*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(43, "gpio43"), 114*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(44, "gpio44"), 115*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(45, "gpio45"), 116*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(46, "gpio46"), 117*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(47, "gpio47"), 118*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(48, "gpio48"), 119*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(49, "gpio49"), 120*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(50, "gpio50"), 121*155cca1bSÁlvaro Fernández Rojas PINCTRL_PIN(51, "gpio51"), 122*155cca1bSÁlvaro Fernández Rojas }; 123*155cca1bSÁlvaro Fernández Rojas 124*155cca1bSÁlvaro Fernández Rojas static unsigned gpio0_pins[] = { 0 }; 125*155cca1bSÁlvaro Fernández Rojas static unsigned gpio1_pins[] = { 1 }; 126*155cca1bSÁlvaro Fernández Rojas static unsigned gpio2_pins[] = { 2 }; 127*155cca1bSÁlvaro Fernández Rojas static unsigned gpio3_pins[] = { 3 }; 128*155cca1bSÁlvaro Fernández Rojas static unsigned gpio4_pins[] = { 4 }; 129*155cca1bSÁlvaro Fernández Rojas static unsigned gpio5_pins[] = { 5 }; 130*155cca1bSÁlvaro Fernández Rojas static unsigned gpio6_pins[] = { 6 }; 131*155cca1bSÁlvaro Fernández Rojas static unsigned gpio7_pins[] = { 7 }; 132*155cca1bSÁlvaro Fernández Rojas static unsigned gpio8_pins[] = { 8 }; 133*155cca1bSÁlvaro Fernández Rojas static unsigned gpio9_pins[] = { 9 }; 134*155cca1bSÁlvaro Fernández Rojas static unsigned gpio10_pins[] = { 10 }; 135*155cca1bSÁlvaro Fernández Rojas static unsigned gpio11_pins[] = { 11 }; 136*155cca1bSÁlvaro Fernández Rojas static unsigned gpio12_pins[] = { 12 }; 137*155cca1bSÁlvaro Fernández Rojas static unsigned gpio13_pins[] = { 13 }; 138*155cca1bSÁlvaro Fernández Rojas static unsigned gpio14_pins[] = { 14 }; 139*155cca1bSÁlvaro Fernández Rojas static unsigned gpio15_pins[] = { 15 }; 140*155cca1bSÁlvaro Fernández Rojas static unsigned gpio16_pins[] = { 16 }; 141*155cca1bSÁlvaro Fernández Rojas static unsigned gpio17_pins[] = { 17 }; 142*155cca1bSÁlvaro Fernández Rojas static unsigned gpio18_pins[] = { 18 }; 143*155cca1bSÁlvaro Fernández Rojas static unsigned gpio19_pins[] = { 19 }; 144*155cca1bSÁlvaro Fernández Rojas static unsigned gpio20_pins[] = { 20 }; 145*155cca1bSÁlvaro Fernández Rojas static unsigned gpio21_pins[] = { 21 }; 146*155cca1bSÁlvaro Fernández Rojas static unsigned gpio22_pins[] = { 22 }; 147*155cca1bSÁlvaro Fernández Rojas static unsigned gpio23_pins[] = { 23 }; 148*155cca1bSÁlvaro Fernández Rojas static unsigned gpio24_pins[] = { 24 }; 149*155cca1bSÁlvaro Fernández Rojas static unsigned gpio25_pins[] = { 25 }; 150*155cca1bSÁlvaro Fernández Rojas static unsigned gpio26_pins[] = { 26 }; 151*155cca1bSÁlvaro Fernández Rojas static unsigned gpio27_pins[] = { 27 }; 152*155cca1bSÁlvaro Fernández Rojas static unsigned gpio28_pins[] = { 28 }; 153*155cca1bSÁlvaro Fernández Rojas static unsigned gpio29_pins[] = { 29 }; 154*155cca1bSÁlvaro Fernández Rojas static unsigned gpio30_pins[] = { 30 }; 155*155cca1bSÁlvaro Fernández Rojas static unsigned gpio31_pins[] = { 31 }; 156*155cca1bSÁlvaro Fernández Rojas static unsigned gpio32_pins[] = { 32 }; 157*155cca1bSÁlvaro Fernández Rojas static unsigned gpio33_pins[] = { 33 }; 158*155cca1bSÁlvaro Fernández Rojas static unsigned gpio34_pins[] = { 34 }; 159*155cca1bSÁlvaro Fernández Rojas static unsigned gpio35_pins[] = { 35 }; 160*155cca1bSÁlvaro Fernández Rojas static unsigned gpio36_pins[] = { 36 }; 161*155cca1bSÁlvaro Fernández Rojas static unsigned gpio37_pins[] = { 37 }; 162*155cca1bSÁlvaro Fernández Rojas static unsigned gpio38_pins[] = { 38 }; 163*155cca1bSÁlvaro Fernández Rojas static unsigned gpio39_pins[] = { 39 }; 164*155cca1bSÁlvaro Fernández Rojas static unsigned gpio40_pins[] = { 40 }; 165*155cca1bSÁlvaro Fernández Rojas static unsigned gpio41_pins[] = { 41 }; 166*155cca1bSÁlvaro Fernández Rojas static unsigned gpio42_pins[] = { 42 }; 167*155cca1bSÁlvaro Fernández Rojas static unsigned gpio43_pins[] = { 43 }; 168*155cca1bSÁlvaro Fernández Rojas static unsigned gpio44_pins[] = { 44 }; 169*155cca1bSÁlvaro Fernández Rojas static unsigned gpio45_pins[] = { 45 }; 170*155cca1bSÁlvaro Fernández Rojas static unsigned gpio46_pins[] = { 46 }; 171*155cca1bSÁlvaro Fernández Rojas static unsigned gpio47_pins[] = { 47 }; 172*155cca1bSÁlvaro Fernández Rojas static unsigned gpio48_pins[] = { 48 }; 173*155cca1bSÁlvaro Fernández Rojas static unsigned gpio49_pins[] = { 49 }; 174*155cca1bSÁlvaro Fernández Rojas static unsigned gpio50_pins[] = { 50 }; 175*155cca1bSÁlvaro Fernández Rojas static unsigned gpio51_pins[] = { 51 }; 176*155cca1bSÁlvaro Fernández Rojas 177*155cca1bSÁlvaro Fernández Rojas static unsigned nand_grp_pins[] = { 178*155cca1bSÁlvaro Fernández Rojas 2, 3, 4, 5, 6, 7, 24, 179*155cca1bSÁlvaro Fernández Rojas 25, 26, 27, 28, 29, 30, 31, 180*155cca1bSÁlvaro Fernández Rojas }; 181*155cca1bSÁlvaro Fernández Rojas 182*155cca1bSÁlvaro Fernández Rojas static unsigned dectpd_grp_pins[] = { 8, 9 }; 183*155cca1bSÁlvaro Fernández Rojas static unsigned vdsl_phy0_grp_pins[] = { 10, 11 }; 184*155cca1bSÁlvaro Fernández Rojas static unsigned vdsl_phy1_grp_pins[] = { 12, 13 }; 185*155cca1bSÁlvaro Fernández Rojas static unsigned vdsl_phy2_grp_pins[] = { 24, 25 }; 186*155cca1bSÁlvaro Fernández Rojas static unsigned vdsl_phy3_grp_pins[] = { 26, 27 }; 187*155cca1bSÁlvaro Fernández Rojas 188*155cca1bSÁlvaro Fernández Rojas #define BCM63268_GROUP(n) \ 189*155cca1bSÁlvaro Fernández Rojas { \ 190*155cca1bSÁlvaro Fernández Rojas .name = #n, \ 191*155cca1bSÁlvaro Fernández Rojas .pins = n##_pins, \ 192*155cca1bSÁlvaro Fernández Rojas .num_pins = ARRAY_SIZE(n##_pins), \ 193*155cca1bSÁlvaro Fernández Rojas } 194*155cca1bSÁlvaro Fernández Rojas 195*155cca1bSÁlvaro Fernández Rojas static struct bcm63268_pingroup bcm63268_groups[] = { 196*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio0), 197*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio1), 198*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio2), 199*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio3), 200*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio4), 201*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio5), 202*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio6), 203*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio7), 204*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio8), 205*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio9), 206*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio10), 207*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio11), 208*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio12), 209*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio13), 210*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio14), 211*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio15), 212*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio16), 213*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio17), 214*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio18), 215*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio19), 216*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio20), 217*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio21), 218*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio22), 219*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio23), 220*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio24), 221*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio25), 222*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio26), 223*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio27), 224*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio28), 225*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio29), 226*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio30), 227*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio31), 228*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio32), 229*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio33), 230*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio34), 231*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio35), 232*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio36), 233*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio37), 234*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio38), 235*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio39), 236*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio40), 237*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio41), 238*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio42), 239*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio43), 240*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio44), 241*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio45), 242*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio46), 243*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio47), 244*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio48), 245*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio49), 246*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio50), 247*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(gpio51), 248*155cca1bSÁlvaro Fernández Rojas 249*155cca1bSÁlvaro Fernández Rojas /* multi pin groups */ 250*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(nand_grp), 251*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(dectpd_grp), 252*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(vdsl_phy0_grp), 253*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(vdsl_phy1_grp), 254*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(vdsl_phy2_grp), 255*155cca1bSÁlvaro Fernández Rojas BCM63268_GROUP(vdsl_phy3_grp), 256*155cca1bSÁlvaro Fernández Rojas }; 257*155cca1bSÁlvaro Fernández Rojas 258*155cca1bSÁlvaro Fernández Rojas static const char * const led_groups[] = { 259*155cca1bSÁlvaro Fernández Rojas "gpio0", 260*155cca1bSÁlvaro Fernández Rojas "gpio1", 261*155cca1bSÁlvaro Fernández Rojas "gpio2", 262*155cca1bSÁlvaro Fernández Rojas "gpio3", 263*155cca1bSÁlvaro Fernández Rojas "gpio4", 264*155cca1bSÁlvaro Fernández Rojas "gpio5", 265*155cca1bSÁlvaro Fernández Rojas "gpio6", 266*155cca1bSÁlvaro Fernández Rojas "gpio7", 267*155cca1bSÁlvaro Fernández Rojas "gpio8", 268*155cca1bSÁlvaro Fernández Rojas "gpio9", 269*155cca1bSÁlvaro Fernández Rojas "gpio10", 270*155cca1bSÁlvaro Fernández Rojas "gpio11", 271*155cca1bSÁlvaro Fernández Rojas "gpio12", 272*155cca1bSÁlvaro Fernández Rojas "gpio13", 273*155cca1bSÁlvaro Fernández Rojas "gpio14", 274*155cca1bSÁlvaro Fernández Rojas "gpio15", 275*155cca1bSÁlvaro Fernández Rojas "gpio16", 276*155cca1bSÁlvaro Fernández Rojas "gpio17", 277*155cca1bSÁlvaro Fernández Rojas "gpio18", 278*155cca1bSÁlvaro Fernández Rojas "gpio19", 279*155cca1bSÁlvaro Fernández Rojas "gpio20", 280*155cca1bSÁlvaro Fernández Rojas "gpio21", 281*155cca1bSÁlvaro Fernández Rojas "gpio22", 282*155cca1bSÁlvaro Fernández Rojas "gpio23", 283*155cca1bSÁlvaro Fernández Rojas }; 284*155cca1bSÁlvaro Fernández Rojas 285*155cca1bSÁlvaro Fernández Rojas static const char * const serial_led_clk_groups[] = { 286*155cca1bSÁlvaro Fernández Rojas "gpio0", 287*155cca1bSÁlvaro Fernández Rojas }; 288*155cca1bSÁlvaro Fernández Rojas 289*155cca1bSÁlvaro Fernández Rojas static const char * const serial_led_data_groups[] = { 290*155cca1bSÁlvaro Fernández Rojas "gpio1", 291*155cca1bSÁlvaro Fernández Rojas }; 292*155cca1bSÁlvaro Fernández Rojas 293*155cca1bSÁlvaro Fernández Rojas static const char * const hsspi_cs4_groups[] = { 294*155cca1bSÁlvaro Fernández Rojas "gpio16", 295*155cca1bSÁlvaro Fernández Rojas }; 296*155cca1bSÁlvaro Fernández Rojas 297*155cca1bSÁlvaro Fernández Rojas static const char * const hsspi_cs5_groups[] = { 298*155cca1bSÁlvaro Fernández Rojas "gpio17", 299*155cca1bSÁlvaro Fernández Rojas }; 300*155cca1bSÁlvaro Fernández Rojas 301*155cca1bSÁlvaro Fernández Rojas static const char * const hsspi_cs6_groups[] = { 302*155cca1bSÁlvaro Fernández Rojas "gpio8", 303*155cca1bSÁlvaro Fernández Rojas }; 304*155cca1bSÁlvaro Fernández Rojas 305*155cca1bSÁlvaro Fernández Rojas static const char * const hsspi_cs7_groups[] = { 306*155cca1bSÁlvaro Fernández Rojas "gpio9", 307*155cca1bSÁlvaro Fernández Rojas }; 308*155cca1bSÁlvaro Fernández Rojas 309*155cca1bSÁlvaro Fernández Rojas static const char * const uart1_scts_groups[] = { 310*155cca1bSÁlvaro Fernández Rojas "gpio10", 311*155cca1bSÁlvaro Fernández Rojas "gpio24", 312*155cca1bSÁlvaro Fernández Rojas }; 313*155cca1bSÁlvaro Fernández Rojas 314*155cca1bSÁlvaro Fernández Rojas static const char * const uart1_srts_groups[] = { 315*155cca1bSÁlvaro Fernández Rojas "gpio11", 316*155cca1bSÁlvaro Fernández Rojas "gpio25", 317*155cca1bSÁlvaro Fernández Rojas }; 318*155cca1bSÁlvaro Fernández Rojas 319*155cca1bSÁlvaro Fernández Rojas static const char * const uart1_sdin_groups[] = { 320*155cca1bSÁlvaro Fernández Rojas "gpio12", 321*155cca1bSÁlvaro Fernández Rojas "gpio26", 322*155cca1bSÁlvaro Fernández Rojas }; 323*155cca1bSÁlvaro Fernández Rojas 324*155cca1bSÁlvaro Fernández Rojas static const char * const uart1_sdout_groups[] = { 325*155cca1bSÁlvaro Fernández Rojas "gpio13", 326*155cca1bSÁlvaro Fernández Rojas "gpio27", 327*155cca1bSÁlvaro Fernández Rojas }; 328*155cca1bSÁlvaro Fernández Rojas 329*155cca1bSÁlvaro Fernández Rojas static const char * const ntr_pulse_in_groups[] = { 330*155cca1bSÁlvaro Fernández Rojas "gpio14", 331*155cca1bSÁlvaro Fernández Rojas "gpio28", 332*155cca1bSÁlvaro Fernández Rojas }; 333*155cca1bSÁlvaro Fernández Rojas 334*155cca1bSÁlvaro Fernández Rojas static const char * const dsl_ntr_pulse_out_groups[] = { 335*155cca1bSÁlvaro Fernández Rojas "gpio15", 336*155cca1bSÁlvaro Fernández Rojas "gpio29", 337*155cca1bSÁlvaro Fernández Rojas }; 338*155cca1bSÁlvaro Fernández Rojas 339*155cca1bSÁlvaro Fernández Rojas static const char * const adsl_spi_miso_groups[] = { 340*155cca1bSÁlvaro Fernández Rojas "gpio18", 341*155cca1bSÁlvaro Fernández Rojas }; 342*155cca1bSÁlvaro Fernández Rojas 343*155cca1bSÁlvaro Fernández Rojas static const char * const adsl_spi_mosi_groups[] = { 344*155cca1bSÁlvaro Fernández Rojas "gpio19", 345*155cca1bSÁlvaro Fernández Rojas }; 346*155cca1bSÁlvaro Fernández Rojas 347*155cca1bSÁlvaro Fernández Rojas static const char * const vreg_clk_groups[] = { 348*155cca1bSÁlvaro Fernández Rojas "gpio22", 349*155cca1bSÁlvaro Fernández Rojas }; 350*155cca1bSÁlvaro Fernández Rojas 351*155cca1bSÁlvaro Fernández Rojas static const char * const pcie_clkreq_b_groups[] = { 352*155cca1bSÁlvaro Fernández Rojas "gpio23", 353*155cca1bSÁlvaro Fernández Rojas }; 354*155cca1bSÁlvaro Fernández Rojas 355*155cca1bSÁlvaro Fernández Rojas static const char * const switch_led_clk_groups[] = { 356*155cca1bSÁlvaro Fernández Rojas "gpio30", 357*155cca1bSÁlvaro Fernández Rojas }; 358*155cca1bSÁlvaro Fernández Rojas 359*155cca1bSÁlvaro Fernández Rojas static const char * const switch_led_data_groups[] = { 360*155cca1bSÁlvaro Fernández Rojas "gpio31", 361*155cca1bSÁlvaro Fernández Rojas }; 362*155cca1bSÁlvaro Fernández Rojas 363*155cca1bSÁlvaro Fernández Rojas static const char * const wifi_groups[] = { 364*155cca1bSÁlvaro Fernández Rojas "gpio32", 365*155cca1bSÁlvaro Fernández Rojas "gpio33", 366*155cca1bSÁlvaro Fernández Rojas "gpio34", 367*155cca1bSÁlvaro Fernández Rojas "gpio35", 368*155cca1bSÁlvaro Fernández Rojas "gpio36", 369*155cca1bSÁlvaro Fernández Rojas "gpio37", 370*155cca1bSÁlvaro Fernández Rojas "gpio38", 371*155cca1bSÁlvaro Fernández Rojas "gpio39", 372*155cca1bSÁlvaro Fernández Rojas "gpio40", 373*155cca1bSÁlvaro Fernández Rojas "gpio41", 374*155cca1bSÁlvaro Fernández Rojas "gpio42", 375*155cca1bSÁlvaro Fernández Rojas "gpio43", 376*155cca1bSÁlvaro Fernández Rojas "gpio44", 377*155cca1bSÁlvaro Fernández Rojas "gpio45", 378*155cca1bSÁlvaro Fernández Rojas "gpio46", 379*155cca1bSÁlvaro Fernández Rojas "gpio47", 380*155cca1bSÁlvaro Fernández Rojas "gpio48", 381*155cca1bSÁlvaro Fernández Rojas "gpio49", 382*155cca1bSÁlvaro Fernández Rojas "gpio50", 383*155cca1bSÁlvaro Fernández Rojas "gpio51", 384*155cca1bSÁlvaro Fernández Rojas }; 385*155cca1bSÁlvaro Fernández Rojas 386*155cca1bSÁlvaro Fernández Rojas static const char * const nand_groups[] = { 387*155cca1bSÁlvaro Fernández Rojas "nand_grp", 388*155cca1bSÁlvaro Fernández Rojas }; 389*155cca1bSÁlvaro Fernández Rojas 390*155cca1bSÁlvaro Fernández Rojas static const char * const dectpd_groups[] = { 391*155cca1bSÁlvaro Fernández Rojas "dectpd_grp", 392*155cca1bSÁlvaro Fernández Rojas }; 393*155cca1bSÁlvaro Fernández Rojas 394*155cca1bSÁlvaro Fernández Rojas static const char * const vdsl_phy_override_0_groups[] = { 395*155cca1bSÁlvaro Fernández Rojas "vdsl_phy_override_0_grp", 396*155cca1bSÁlvaro Fernández Rojas }; 397*155cca1bSÁlvaro Fernández Rojas 398*155cca1bSÁlvaro Fernández Rojas static const char * const vdsl_phy_override_1_groups[] = { 399*155cca1bSÁlvaro Fernández Rojas "vdsl_phy_override_1_grp", 400*155cca1bSÁlvaro Fernández Rojas }; 401*155cca1bSÁlvaro Fernández Rojas 402*155cca1bSÁlvaro Fernández Rojas static const char * const vdsl_phy_override_2_groups[] = { 403*155cca1bSÁlvaro Fernández Rojas "vdsl_phy_override_2_grp", 404*155cca1bSÁlvaro Fernández Rojas }; 405*155cca1bSÁlvaro Fernández Rojas 406*155cca1bSÁlvaro Fernández Rojas static const char * const vdsl_phy_override_3_groups[] = { 407*155cca1bSÁlvaro Fernández Rojas "vdsl_phy_override_3_grp", 408*155cca1bSÁlvaro Fernández Rojas }; 409*155cca1bSÁlvaro Fernández Rojas 410*155cca1bSÁlvaro Fernández Rojas #define BCM63268_LED_FUN(n) \ 411*155cca1bSÁlvaro Fernández Rojas { \ 412*155cca1bSÁlvaro Fernández Rojas .name = #n, \ 413*155cca1bSÁlvaro Fernández Rojas .groups = n##_groups, \ 414*155cca1bSÁlvaro Fernández Rojas .num_groups = ARRAY_SIZE(n##_groups), \ 415*155cca1bSÁlvaro Fernández Rojas .reg = BCM63268_LEDCTRL, \ 416*155cca1bSÁlvaro Fernández Rojas } 417*155cca1bSÁlvaro Fernández Rojas 418*155cca1bSÁlvaro Fernández Rojas #define BCM63268_MODE_FUN(n) \ 419*155cca1bSÁlvaro Fernández Rojas { \ 420*155cca1bSÁlvaro Fernández Rojas .name = #n, \ 421*155cca1bSÁlvaro Fernández Rojas .groups = n##_groups, \ 422*155cca1bSÁlvaro Fernández Rojas .num_groups = ARRAY_SIZE(n##_groups), \ 423*155cca1bSÁlvaro Fernández Rojas .reg = BCM63268_MODE, \ 424*155cca1bSÁlvaro Fernández Rojas } 425*155cca1bSÁlvaro Fernández Rojas 426*155cca1bSÁlvaro Fernández Rojas #define BCM63268_CTRL_FUN(n) \ 427*155cca1bSÁlvaro Fernández Rojas { \ 428*155cca1bSÁlvaro Fernández Rojas .name = #n, \ 429*155cca1bSÁlvaro Fernández Rojas .groups = n##_groups, \ 430*155cca1bSÁlvaro Fernández Rojas .num_groups = ARRAY_SIZE(n##_groups), \ 431*155cca1bSÁlvaro Fernández Rojas .reg = BCM63268_CTRL, \ 432*155cca1bSÁlvaro Fernández Rojas } 433*155cca1bSÁlvaro Fernández Rojas 434*155cca1bSÁlvaro Fernández Rojas #define BCM63268_BASEMODE_FUN(n, val) \ 435*155cca1bSÁlvaro Fernández Rojas { \ 436*155cca1bSÁlvaro Fernández Rojas .name = #n, \ 437*155cca1bSÁlvaro Fernández Rojas .groups = n##_groups, \ 438*155cca1bSÁlvaro Fernández Rojas .num_groups = ARRAY_SIZE(n##_groups), \ 439*155cca1bSÁlvaro Fernández Rojas .reg = BCM63268_BASEMODE, \ 440*155cca1bSÁlvaro Fernández Rojas .mask = val, \ 441*155cca1bSÁlvaro Fernández Rojas } 442*155cca1bSÁlvaro Fernández Rojas 443*155cca1bSÁlvaro Fernández Rojas static const struct bcm63268_function bcm63268_funcs[] = { 444*155cca1bSÁlvaro Fernández Rojas BCM63268_LED_FUN(led), 445*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(serial_led_clk), 446*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(serial_led_data), 447*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(hsspi_cs6), 448*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(hsspi_cs7), 449*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(uart1_scts), 450*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(uart1_srts), 451*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(uart1_sdin), 452*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(uart1_sdout), 453*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(ntr_pulse_in), 454*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(dsl_ntr_pulse_out), 455*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(hsspi_cs4), 456*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(hsspi_cs5), 457*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(adsl_spi_miso), 458*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(adsl_spi_mosi), 459*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(vreg_clk), 460*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(pcie_clkreq_b), 461*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(switch_led_clk), 462*155cca1bSÁlvaro Fernández Rojas BCM63268_MODE_FUN(switch_led_data), 463*155cca1bSÁlvaro Fernández Rojas BCM63268_CTRL_FUN(wifi), 464*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_FUN(nand, BCM63268_BASEMODE_NAND), 465*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_FUN(dectpd, BCM63268_BASEMODE_DECTPD), 466*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_FUN(vdsl_phy_override_0, 467*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_VDSL_PHY_0), 468*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_FUN(vdsl_phy_override_1, 469*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_VDSL_PHY_1), 470*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_FUN(vdsl_phy_override_2, 471*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_VDSL_PHY_2), 472*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_FUN(vdsl_phy_override_3, 473*155cca1bSÁlvaro Fernández Rojas BCM63268_BASEMODE_VDSL_PHY_3), 474*155cca1bSÁlvaro Fernández Rojas }; 475*155cca1bSÁlvaro Fernández Rojas 476*155cca1bSÁlvaro Fernández Rojas static int bcm63268_pinctrl_get_group_count(struct pinctrl_dev *pctldev) 477*155cca1bSÁlvaro Fernández Rojas { 478*155cca1bSÁlvaro Fernández Rojas return ARRAY_SIZE(bcm63268_groups); 479*155cca1bSÁlvaro Fernández Rojas } 480*155cca1bSÁlvaro Fernández Rojas 481*155cca1bSÁlvaro Fernández Rojas static const char *bcm63268_pinctrl_get_group_name(struct pinctrl_dev *pctldev, 482*155cca1bSÁlvaro Fernández Rojas unsigned group) 483*155cca1bSÁlvaro Fernández Rojas { 484*155cca1bSÁlvaro Fernández Rojas return bcm63268_groups[group].name; 485*155cca1bSÁlvaro Fernández Rojas } 486*155cca1bSÁlvaro Fernández Rojas 487*155cca1bSÁlvaro Fernández Rojas static int bcm63268_pinctrl_get_group_pins(struct pinctrl_dev *pctldev, 488*155cca1bSÁlvaro Fernández Rojas unsigned group, 489*155cca1bSÁlvaro Fernández Rojas const unsigned **pins, 490*155cca1bSÁlvaro Fernández Rojas unsigned *num_pins) 491*155cca1bSÁlvaro Fernández Rojas { 492*155cca1bSÁlvaro Fernández Rojas *pins = bcm63268_groups[group].pins; 493*155cca1bSÁlvaro Fernández Rojas *num_pins = bcm63268_groups[group].num_pins; 494*155cca1bSÁlvaro Fernández Rojas 495*155cca1bSÁlvaro Fernández Rojas return 0; 496*155cca1bSÁlvaro Fernández Rojas } 497*155cca1bSÁlvaro Fernández Rojas 498*155cca1bSÁlvaro Fernández Rojas static int bcm63268_pinctrl_get_func_count(struct pinctrl_dev *pctldev) 499*155cca1bSÁlvaro Fernández Rojas { 500*155cca1bSÁlvaro Fernández Rojas return ARRAY_SIZE(bcm63268_funcs); 501*155cca1bSÁlvaro Fernández Rojas } 502*155cca1bSÁlvaro Fernández Rojas 503*155cca1bSÁlvaro Fernández Rojas static const char *bcm63268_pinctrl_get_func_name(struct pinctrl_dev *pctldev, 504*155cca1bSÁlvaro Fernández Rojas unsigned selector) 505*155cca1bSÁlvaro Fernández Rojas { 506*155cca1bSÁlvaro Fernández Rojas return bcm63268_funcs[selector].name; 507*155cca1bSÁlvaro Fernández Rojas } 508*155cca1bSÁlvaro Fernández Rojas 509*155cca1bSÁlvaro Fernández Rojas static int bcm63268_pinctrl_get_groups(struct pinctrl_dev *pctldev, 510*155cca1bSÁlvaro Fernández Rojas unsigned selector, 511*155cca1bSÁlvaro Fernández Rojas const char * const **groups, 512*155cca1bSÁlvaro Fernández Rojas unsigned * const num_groups) 513*155cca1bSÁlvaro Fernández Rojas { 514*155cca1bSÁlvaro Fernández Rojas *groups = bcm63268_funcs[selector].groups; 515*155cca1bSÁlvaro Fernández Rojas *num_groups = bcm63268_funcs[selector].num_groups; 516*155cca1bSÁlvaro Fernández Rojas 517*155cca1bSÁlvaro Fernández Rojas return 0; 518*155cca1bSÁlvaro Fernández Rojas } 519*155cca1bSÁlvaro Fernández Rojas 520*155cca1bSÁlvaro Fernández Rojas static void bcm63268_set_gpio(struct bcm63xx_pinctrl *pc, unsigned pin) 521*155cca1bSÁlvaro Fernández Rojas { 522*155cca1bSÁlvaro Fernández Rojas const struct pinctrl_pin_desc *desc = &bcm63268_pins[pin]; 523*155cca1bSÁlvaro Fernández Rojas unsigned int basemode = (unsigned long) desc->drv_data; 524*155cca1bSÁlvaro Fernández Rojas unsigned int mask = BIT(bcm63xx_bank_pin(pin)); 525*155cca1bSÁlvaro Fernández Rojas 526*155cca1bSÁlvaro Fernández Rojas if (basemode) 527*155cca1bSÁlvaro Fernández Rojas regmap_update_bits(pc->regs, BCM63268_BASEMODE_REG, basemode, 528*155cca1bSÁlvaro Fernández Rojas 0); 529*155cca1bSÁlvaro Fernández Rojas 530*155cca1bSÁlvaro Fernández Rojas if (pin < BCM63XX_BANK_GPIOS) { 531*155cca1bSÁlvaro Fernández Rojas /* base mode: 0 => gpio, 1 => mux function */ 532*155cca1bSÁlvaro Fernández Rojas regmap_update_bits(pc->regs, BCM63268_MODE_REG, mask, 0); 533*155cca1bSÁlvaro Fernández Rojas 534*155cca1bSÁlvaro Fernández Rojas /* pins 0-23 might be muxed to led */ 535*155cca1bSÁlvaro Fernández Rojas if (pin < BCM63268_NUM_LEDS) 536*155cca1bSÁlvaro Fernández Rojas regmap_update_bits(pc->regs, BCM63268_LED_REG, mask, 537*155cca1bSÁlvaro Fernández Rojas 0); 538*155cca1bSÁlvaro Fernández Rojas } else if (pin < BCM63268_NUM_GPIOS) { 539*155cca1bSÁlvaro Fernández Rojas /* ctrl reg: 0 => wifi function, 1 => gpio */ 540*155cca1bSÁlvaro Fernández Rojas regmap_update_bits(pc->regs, BCM63268_CTRL_REG, mask, mask); 541*155cca1bSÁlvaro Fernández Rojas } 542*155cca1bSÁlvaro Fernández Rojas } 543*155cca1bSÁlvaro Fernández Rojas 544*155cca1bSÁlvaro Fernández Rojas static int bcm63268_pinctrl_set_mux(struct pinctrl_dev *pctldev, 545*155cca1bSÁlvaro Fernández Rojas unsigned selector, unsigned group) 546*155cca1bSÁlvaro Fernández Rojas { 547*155cca1bSÁlvaro Fernández Rojas struct bcm63xx_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); 548*155cca1bSÁlvaro Fernández Rojas const struct bcm63268_pingroup *pg = &bcm63268_groups[group]; 549*155cca1bSÁlvaro Fernández Rojas const struct bcm63268_function *f = &bcm63268_funcs[selector]; 550*155cca1bSÁlvaro Fernández Rojas unsigned i; 551*155cca1bSÁlvaro Fernández Rojas unsigned int reg; 552*155cca1bSÁlvaro Fernández Rojas unsigned int val, mask; 553*155cca1bSÁlvaro Fernández Rojas 554*155cca1bSÁlvaro Fernández Rojas for (i = 0; i < pg->num_pins; i++) 555*155cca1bSÁlvaro Fernández Rojas bcm63268_set_gpio(pc, pg->pins[i]); 556*155cca1bSÁlvaro Fernández Rojas 557*155cca1bSÁlvaro Fernández Rojas switch (f->reg) { 558*155cca1bSÁlvaro Fernández Rojas case BCM63268_LEDCTRL: 559*155cca1bSÁlvaro Fernández Rojas reg = BCM63268_LED_REG; 560*155cca1bSÁlvaro Fernández Rojas mask = BIT(pg->pins[0]); 561*155cca1bSÁlvaro Fernández Rojas val = BIT(pg->pins[0]); 562*155cca1bSÁlvaro Fernández Rojas break; 563*155cca1bSÁlvaro Fernández Rojas case BCM63268_MODE: 564*155cca1bSÁlvaro Fernández Rojas reg = BCM63268_MODE_REG; 565*155cca1bSÁlvaro Fernández Rojas mask = BIT(pg->pins[0]); 566*155cca1bSÁlvaro Fernández Rojas val = BIT(pg->pins[0]); 567*155cca1bSÁlvaro Fernández Rojas break; 568*155cca1bSÁlvaro Fernández Rojas case BCM63268_CTRL: 569*155cca1bSÁlvaro Fernández Rojas reg = BCM63268_CTRL_REG; 570*155cca1bSÁlvaro Fernández Rojas mask = BIT(pg->pins[0]); 571*155cca1bSÁlvaro Fernández Rojas val = 0; 572*155cca1bSÁlvaro Fernández Rojas break; 573*155cca1bSÁlvaro Fernández Rojas case BCM63268_BASEMODE: 574*155cca1bSÁlvaro Fernández Rojas reg = BCM63268_BASEMODE_REG; 575*155cca1bSÁlvaro Fernández Rojas mask = f->mask; 576*155cca1bSÁlvaro Fernández Rojas val = f->mask; 577*155cca1bSÁlvaro Fernández Rojas break; 578*155cca1bSÁlvaro Fernández Rojas default: 579*155cca1bSÁlvaro Fernández Rojas WARN_ON(1); 580*155cca1bSÁlvaro Fernández Rojas return -EINVAL; 581*155cca1bSÁlvaro Fernández Rojas } 582*155cca1bSÁlvaro Fernández Rojas 583*155cca1bSÁlvaro Fernández Rojas regmap_update_bits(pc->regs, reg, mask, val); 584*155cca1bSÁlvaro Fernández Rojas 585*155cca1bSÁlvaro Fernández Rojas return 0; 586*155cca1bSÁlvaro Fernández Rojas } 587*155cca1bSÁlvaro Fernández Rojas 588*155cca1bSÁlvaro Fernández Rojas static int bcm63268_gpio_request_enable(struct pinctrl_dev *pctldev, 589*155cca1bSÁlvaro Fernández Rojas struct pinctrl_gpio_range *range, 590*155cca1bSÁlvaro Fernández Rojas unsigned offset) 591*155cca1bSÁlvaro Fernández Rojas { 592*155cca1bSÁlvaro Fernández Rojas struct bcm63xx_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); 593*155cca1bSÁlvaro Fernández Rojas 594*155cca1bSÁlvaro Fernández Rojas /* disable all functions using this pin */ 595*155cca1bSÁlvaro Fernández Rojas bcm63268_set_gpio(pc, offset); 596*155cca1bSÁlvaro Fernández Rojas 597*155cca1bSÁlvaro Fernández Rojas return 0; 598*155cca1bSÁlvaro Fernández Rojas } 599*155cca1bSÁlvaro Fernández Rojas 600*155cca1bSÁlvaro Fernández Rojas static struct pinctrl_ops bcm63268_pctl_ops = { 601*155cca1bSÁlvaro Fernández Rojas .dt_free_map = pinctrl_utils_free_map, 602*155cca1bSÁlvaro Fernández Rojas .dt_node_to_map = pinconf_generic_dt_node_to_map_pin, 603*155cca1bSÁlvaro Fernández Rojas .get_group_name = bcm63268_pinctrl_get_group_name, 604*155cca1bSÁlvaro Fernández Rojas .get_group_pins = bcm63268_pinctrl_get_group_pins, 605*155cca1bSÁlvaro Fernández Rojas .get_groups_count = bcm63268_pinctrl_get_group_count, 606*155cca1bSÁlvaro Fernández Rojas }; 607*155cca1bSÁlvaro Fernández Rojas 608*155cca1bSÁlvaro Fernández Rojas static struct pinmux_ops bcm63268_pmx_ops = { 609*155cca1bSÁlvaro Fernández Rojas .get_function_groups = bcm63268_pinctrl_get_groups, 610*155cca1bSÁlvaro Fernández Rojas .get_function_name = bcm63268_pinctrl_get_func_name, 611*155cca1bSÁlvaro Fernández Rojas .get_functions_count = bcm63268_pinctrl_get_func_count, 612*155cca1bSÁlvaro Fernández Rojas .gpio_request_enable = bcm63268_gpio_request_enable, 613*155cca1bSÁlvaro Fernández Rojas .set_mux = bcm63268_pinctrl_set_mux, 614*155cca1bSÁlvaro Fernández Rojas .strict = true, 615*155cca1bSÁlvaro Fernández Rojas }; 616*155cca1bSÁlvaro Fernández Rojas 617*155cca1bSÁlvaro Fernández Rojas static const struct bcm63xx_pinctrl_soc bcm63268_soc = { 618*155cca1bSÁlvaro Fernández Rojas .ngpios = BCM63268_NUM_GPIOS, 619*155cca1bSÁlvaro Fernández Rojas .npins = ARRAY_SIZE(bcm63268_pins), 620*155cca1bSÁlvaro Fernández Rojas .pctl_ops = &bcm63268_pctl_ops, 621*155cca1bSÁlvaro Fernández Rojas .pins = bcm63268_pins, 622*155cca1bSÁlvaro Fernández Rojas .pmx_ops = &bcm63268_pmx_ops, 623*155cca1bSÁlvaro Fernández Rojas }; 624*155cca1bSÁlvaro Fernández Rojas 625*155cca1bSÁlvaro Fernández Rojas static int bcm63268_pinctrl_probe(struct platform_device *pdev) 626*155cca1bSÁlvaro Fernández Rojas { 627*155cca1bSÁlvaro Fernández Rojas return bcm63xx_pinctrl_probe(pdev, &bcm63268_soc, NULL); 628*155cca1bSÁlvaro Fernández Rojas } 629*155cca1bSÁlvaro Fernández Rojas 630*155cca1bSÁlvaro Fernández Rojas static const struct of_device_id bcm63268_pinctrl_match[] = { 631*155cca1bSÁlvaro Fernández Rojas { .compatible = "brcm,bcm63268-pinctrl", }, 632*155cca1bSÁlvaro Fernández Rojas { /* sentinel */ } 633*155cca1bSÁlvaro Fernández Rojas }; 634*155cca1bSÁlvaro Fernández Rojas 635*155cca1bSÁlvaro Fernández Rojas static struct platform_driver bcm63268_pinctrl_driver = { 636*155cca1bSÁlvaro Fernández Rojas .probe = bcm63268_pinctrl_probe, 637*155cca1bSÁlvaro Fernández Rojas .driver = { 638*155cca1bSÁlvaro Fernández Rojas .name = "bcm63268-pinctrl", 639*155cca1bSÁlvaro Fernández Rojas .of_match_table = bcm63268_pinctrl_match, 640*155cca1bSÁlvaro Fernández Rojas }, 641*155cca1bSÁlvaro Fernández Rojas }; 642*155cca1bSÁlvaro Fernández Rojas 643*155cca1bSÁlvaro Fernández Rojas builtin_platform_driver(bcm63268_pinctrl_driver); 644