Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0 OR MIT) |
| 2 | /* |
| 3 | * Microsemi SoCs pinctrl driver |
| 4 | * |
| 5 | * Author: <alexandre.belloni@free-electrons.com> |
| 6 | * License: Dual MIT/GPL |
| 7 | * Copyright (c) 2017 Microsemi Corporation |
| 8 | */ |
| 9 | |
| 10 | #include <linux/gpio/driver.h> |
| 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/io.h> |
| 13 | #include <linux/of_device.h> |
Quentin Schulz | be36abb | 2018-07-25 14:26:21 +0200 | [diff] [blame] | 14 | #include <linux/of_irq.h> |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 15 | #include <linux/of_platform.h> |
| 16 | #include <linux/pinctrl/pinctrl.h> |
| 17 | #include <linux/pinctrl/pinmux.h> |
| 18 | #include <linux/pinctrl/pinconf.h> |
| 19 | #include <linux/pinctrl/pinconf-generic.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/regmap.h> |
| 22 | #include <linux/slab.h> |
| 23 | |
| 24 | #include "core.h" |
| 25 | #include "pinconf.h" |
| 26 | #include "pinmux.h" |
| 27 | |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 28 | #define ocelot_clrsetbits(addr, clear, set) \ |
| 29 | writel((readl(addr) & ~(clear)) | (set), (addr)) |
| 30 | |
| 31 | /* PINCONFIG bits (sparx5 only) */ |
| 32 | enum { |
| 33 | PINCONF_BIAS, |
| 34 | PINCONF_SCHMITT, |
| 35 | PINCONF_DRIVE_STRENGTH, |
| 36 | }; |
| 37 | |
| 38 | #define BIAS_PD_BIT BIT(4) |
| 39 | #define BIAS_PU_BIT BIT(3) |
| 40 | #define BIAS_BITS (BIAS_PD_BIT|BIAS_PU_BIT) |
| 41 | #define SCHMITT_BIT BIT(2) |
| 42 | #define DRIVE_BITS GENMASK(1, 0) |
| 43 | |
| 44 | /* GPIO standard registers */ |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 45 | #define OCELOT_GPIO_OUT_SET 0x0 |
| 46 | #define OCELOT_GPIO_OUT_CLR 0x4 |
| 47 | #define OCELOT_GPIO_OUT 0x8 |
| 48 | #define OCELOT_GPIO_IN 0xc |
| 49 | #define OCELOT_GPIO_OE 0x10 |
| 50 | #define OCELOT_GPIO_INTR 0x14 |
| 51 | #define OCELOT_GPIO_INTR_ENA 0x18 |
| 52 | #define OCELOT_GPIO_INTR_IDENT 0x1c |
| 53 | #define OCELOT_GPIO_ALT0 0x20 |
| 54 | #define OCELOT_GPIO_ALT1 0x24 |
| 55 | #define OCELOT_GPIO_SD_MAP 0x28 |
| 56 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 57 | #define OCELOT_FUNC_PER_PIN 4 |
| 58 | |
| 59 | enum { |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 60 | FUNC_CAN0_a, |
| 61 | FUNC_CAN0_b, |
| 62 | FUNC_CAN1, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 63 | FUNC_NONE, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 64 | FUNC_FC0_a, |
| 65 | FUNC_FC0_b, |
| 66 | FUNC_FC0_c, |
| 67 | FUNC_FC1_a, |
| 68 | FUNC_FC1_b, |
| 69 | FUNC_FC1_c, |
| 70 | FUNC_FC2_a, |
| 71 | FUNC_FC2_b, |
| 72 | FUNC_FC3_a, |
| 73 | FUNC_FC3_b, |
| 74 | FUNC_FC3_c, |
| 75 | FUNC_FC4_a, |
| 76 | FUNC_FC4_b, |
| 77 | FUNC_FC4_c, |
| 78 | FUNC_FC_SHRD0, |
| 79 | FUNC_FC_SHRD1, |
| 80 | FUNC_FC_SHRD2, |
| 81 | FUNC_FC_SHRD3, |
| 82 | FUNC_FC_SHRD4, |
| 83 | FUNC_FC_SHRD5, |
| 84 | FUNC_FC_SHRD6, |
| 85 | FUNC_FC_SHRD7, |
| 86 | FUNC_FC_SHRD8, |
| 87 | FUNC_FC_SHRD9, |
| 88 | FUNC_FC_SHRD10, |
| 89 | FUNC_FC_SHRD11, |
| 90 | FUNC_FC_SHRD12, |
| 91 | FUNC_FC_SHRD13, |
| 92 | FUNC_FC_SHRD14, |
| 93 | FUNC_FC_SHRD15, |
| 94 | FUNC_FC_SHRD16, |
| 95 | FUNC_FC_SHRD17, |
| 96 | FUNC_FC_SHRD18, |
| 97 | FUNC_FC_SHRD19, |
| 98 | FUNC_FC_SHRD20, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 99 | FUNC_GPIO, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 100 | FUNC_IB_TRG_a, |
| 101 | FUNC_IB_TRG_b, |
| 102 | FUNC_IB_TRG_c, |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 103 | FUNC_IRQ0, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 104 | FUNC_IRQ_IN_a, |
| 105 | FUNC_IRQ_IN_b, |
| 106 | FUNC_IRQ_IN_c, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 107 | FUNC_IRQ0_IN, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 108 | FUNC_IRQ_OUT_a, |
| 109 | FUNC_IRQ_OUT_b, |
| 110 | FUNC_IRQ_OUT_c, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 111 | FUNC_IRQ0_OUT, |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 112 | FUNC_IRQ1, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 113 | FUNC_IRQ1_IN, |
| 114 | FUNC_IRQ1_OUT, |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 115 | FUNC_EXT_IRQ, |
Lars Povlsen | edc7254 | 2020-05-13 14:55:20 +0200 | [diff] [blame] | 116 | FUNC_MIIM, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 117 | FUNC_MIIM_a, |
| 118 | FUNC_MIIM_b, |
| 119 | FUNC_MIIM_c, |
| 120 | FUNC_MIIM_Sa, |
| 121 | FUNC_MIIM_Sb, |
| 122 | FUNC_OB_TRG, |
| 123 | FUNC_OB_TRG_a, |
| 124 | FUNC_OB_TRG_b, |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 125 | FUNC_PHY_LED, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 126 | FUNC_PCI_WAKE, |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 127 | FUNC_MD, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 128 | FUNC_PTP0, |
| 129 | FUNC_PTP1, |
| 130 | FUNC_PTP2, |
| 131 | FUNC_PTP3, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 132 | FUNC_PTPSYNC_1, |
| 133 | FUNC_PTPSYNC_2, |
| 134 | FUNC_PTPSYNC_3, |
| 135 | FUNC_PTPSYNC_4, |
| 136 | FUNC_PTPSYNC_5, |
| 137 | FUNC_PTPSYNC_6, |
| 138 | FUNC_PTPSYNC_7, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 139 | FUNC_PWM, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 140 | FUNC_QSPI1, |
| 141 | FUNC_QSPI2, |
| 142 | FUNC_R, |
| 143 | FUNC_RECO_a, |
| 144 | FUNC_RECO_b, |
Lars Povlsen | edc7254 | 2020-05-13 14:55:20 +0200 | [diff] [blame] | 145 | FUNC_RECO_CLK, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 146 | FUNC_SD, |
Lars Povlsen | edc7254 | 2020-05-13 14:55:20 +0200 | [diff] [blame] | 147 | FUNC_SFP, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 148 | FUNC_SFP_SD, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 149 | FUNC_SG0, |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 150 | FUNC_SG1, |
| 151 | FUNC_SG2, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 152 | FUNC_SGPIO_a, |
| 153 | FUNC_SGPIO_b, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 154 | FUNC_SI, |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 155 | FUNC_SI2, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 156 | FUNC_TACHO, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 157 | FUNC_TACHO_a, |
| 158 | FUNC_TACHO_b, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 159 | FUNC_TWI, |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 160 | FUNC_TWI2, |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 161 | FUNC_TWI3, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 162 | FUNC_TWI_SCL_M, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 163 | FUNC_TWI_SLC_GATE, |
| 164 | FUNC_TWI_SLC_GATE_AD, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 165 | FUNC_UART, |
| 166 | FUNC_UART2, |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 167 | FUNC_UART3, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 168 | FUNC_USB_H_a, |
| 169 | FUNC_USB_H_b, |
| 170 | FUNC_USB_H_c, |
| 171 | FUNC_USB_S_a, |
| 172 | FUNC_USB_S_b, |
| 173 | FUNC_USB_S_c, |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 174 | FUNC_PLL_STAT, |
| 175 | FUNC_EMMC, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 176 | FUNC_EMMC_SD, |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 177 | FUNC_REF_CLK, |
| 178 | FUNC_RCVRD_CLK, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 179 | FUNC_MAX |
| 180 | }; |
| 181 | |
| 182 | static const char *const ocelot_function_names[] = { |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 183 | [FUNC_CAN0_a] = "can0_a", |
| 184 | [FUNC_CAN0_b] = "can0_b", |
| 185 | [FUNC_CAN1] = "can1", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 186 | [FUNC_NONE] = "none", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 187 | [FUNC_FC0_a] = "fc0_a", |
| 188 | [FUNC_FC0_b] = "fc0_b", |
| 189 | [FUNC_FC0_c] = "fc0_c", |
| 190 | [FUNC_FC1_a] = "fc1_a", |
| 191 | [FUNC_FC1_b] = "fc1_b", |
| 192 | [FUNC_FC1_c] = "fc1_c", |
| 193 | [FUNC_FC2_a] = "fc2_a", |
| 194 | [FUNC_FC2_b] = "fc2_b", |
| 195 | [FUNC_FC3_a] = "fc3_a", |
| 196 | [FUNC_FC3_b] = "fc3_b", |
| 197 | [FUNC_FC3_c] = "fc3_c", |
| 198 | [FUNC_FC4_a] = "fc4_a", |
| 199 | [FUNC_FC4_b] = "fc4_b", |
| 200 | [FUNC_FC4_c] = "fc4_c", |
| 201 | [FUNC_FC_SHRD0] = "fc_shrd0", |
| 202 | [FUNC_FC_SHRD1] = "fc_shrd1", |
| 203 | [FUNC_FC_SHRD2] = "fc_shrd2", |
| 204 | [FUNC_FC_SHRD3] = "fc_shrd3", |
| 205 | [FUNC_FC_SHRD4] = "fc_shrd4", |
| 206 | [FUNC_FC_SHRD5] = "fc_shrd5", |
| 207 | [FUNC_FC_SHRD6] = "fc_shrd6", |
| 208 | [FUNC_FC_SHRD7] = "fc_shrd7", |
| 209 | [FUNC_FC_SHRD8] = "fc_shrd8", |
| 210 | [FUNC_FC_SHRD9] = "fc_shrd9", |
| 211 | [FUNC_FC_SHRD10] = "fc_shrd10", |
| 212 | [FUNC_FC_SHRD11] = "fc_shrd11", |
| 213 | [FUNC_FC_SHRD12] = "fc_shrd12", |
| 214 | [FUNC_FC_SHRD13] = "fc_shrd13", |
| 215 | [FUNC_FC_SHRD14] = "fc_shrd14", |
| 216 | [FUNC_FC_SHRD15] = "fc_shrd15", |
| 217 | [FUNC_FC_SHRD16] = "fc_shrd16", |
| 218 | [FUNC_FC_SHRD17] = "fc_shrd17", |
| 219 | [FUNC_FC_SHRD18] = "fc_shrd18", |
| 220 | [FUNC_FC_SHRD19] = "fc_shrd19", |
| 221 | [FUNC_FC_SHRD20] = "fc_shrd20", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 222 | [FUNC_GPIO] = "gpio", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 223 | [FUNC_IB_TRG_a] = "ib_trig_a", |
| 224 | [FUNC_IB_TRG_b] = "ib_trig_b", |
| 225 | [FUNC_IB_TRG_c] = "ib_trig_c", |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 226 | [FUNC_IRQ0] = "irq0", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 227 | [FUNC_IRQ_IN_a] = "irq_in_a", |
| 228 | [FUNC_IRQ_IN_b] = "irq_in_b", |
| 229 | [FUNC_IRQ_IN_c] = "irq_in_c", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 230 | [FUNC_IRQ0_IN] = "irq0_in", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 231 | [FUNC_IRQ_OUT_a] = "irq_out_a", |
| 232 | [FUNC_IRQ_OUT_b] = "irq_out_b", |
| 233 | [FUNC_IRQ_OUT_c] = "irq_out_c", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 234 | [FUNC_IRQ0_OUT] = "irq0_out", |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 235 | [FUNC_IRQ1] = "irq1", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 236 | [FUNC_IRQ1_IN] = "irq1_in", |
| 237 | [FUNC_IRQ1_OUT] = "irq1_out", |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 238 | [FUNC_EXT_IRQ] = "ext_irq", |
Lars Povlsen | edc7254 | 2020-05-13 14:55:20 +0200 | [diff] [blame] | 239 | [FUNC_MIIM] = "miim", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 240 | [FUNC_MIIM_a] = "miim_a", |
| 241 | [FUNC_MIIM_b] = "miim_b", |
| 242 | [FUNC_MIIM_c] = "miim_c", |
| 243 | [FUNC_MIIM_Sa] = "miim_slave_a", |
| 244 | [FUNC_MIIM_Sb] = "miim_slave_b", |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 245 | [FUNC_PHY_LED] = "phy_led", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 246 | [FUNC_PCI_WAKE] = "pci_wake", |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 247 | [FUNC_MD] = "md", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 248 | [FUNC_OB_TRG] = "ob_trig", |
| 249 | [FUNC_OB_TRG_a] = "ob_trig_a", |
| 250 | [FUNC_OB_TRG_b] = "ob_trig_b", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 251 | [FUNC_PTP0] = "ptp0", |
| 252 | [FUNC_PTP1] = "ptp1", |
| 253 | [FUNC_PTP2] = "ptp2", |
| 254 | [FUNC_PTP3] = "ptp3", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 255 | [FUNC_PTPSYNC_1] = "ptpsync_1", |
| 256 | [FUNC_PTPSYNC_2] = "ptpsync_2", |
| 257 | [FUNC_PTPSYNC_3] = "ptpsync_3", |
| 258 | [FUNC_PTPSYNC_4] = "ptpsync_4", |
| 259 | [FUNC_PTPSYNC_5] = "ptpsync_5", |
| 260 | [FUNC_PTPSYNC_6] = "ptpsync_6", |
| 261 | [FUNC_PTPSYNC_7] = "ptpsync_7", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 262 | [FUNC_PWM] = "pwm", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 263 | [FUNC_QSPI1] = "qspi1", |
| 264 | [FUNC_QSPI2] = "qspi2", |
| 265 | [FUNC_R] = "reserved", |
| 266 | [FUNC_RECO_a] = "reco_a", |
| 267 | [FUNC_RECO_b] = "reco_b", |
Lars Povlsen | edc7254 | 2020-05-13 14:55:20 +0200 | [diff] [blame] | 268 | [FUNC_RECO_CLK] = "reco_clk", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 269 | [FUNC_SD] = "sd", |
Lars Povlsen | edc7254 | 2020-05-13 14:55:20 +0200 | [diff] [blame] | 270 | [FUNC_SFP] = "sfp", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 271 | [FUNC_SFP_SD] = "sfp_sd", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 272 | [FUNC_SG0] = "sg0", |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 273 | [FUNC_SG1] = "sg1", |
| 274 | [FUNC_SG2] = "sg2", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 275 | [FUNC_SGPIO_a] = "sgpio_a", |
| 276 | [FUNC_SGPIO_b] = "sgpio_b", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 277 | [FUNC_SI] = "si", |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 278 | [FUNC_SI2] = "si2", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 279 | [FUNC_TACHO] = "tacho", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 280 | [FUNC_TACHO_a] = "tacho_a", |
| 281 | [FUNC_TACHO_b] = "tacho_b", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 282 | [FUNC_TWI] = "twi", |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 283 | [FUNC_TWI2] = "twi2", |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 284 | [FUNC_TWI3] = "twi3", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 285 | [FUNC_TWI_SCL_M] = "twi_scl_m", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 286 | [FUNC_TWI_SLC_GATE] = "twi_slc_gate", |
| 287 | [FUNC_TWI_SLC_GATE_AD] = "twi_slc_gate_ad", |
| 288 | [FUNC_USB_H_a] = "usb_host_a", |
| 289 | [FUNC_USB_H_b] = "usb_host_b", |
| 290 | [FUNC_USB_H_c] = "usb_host_c", |
| 291 | [FUNC_USB_S_a] = "usb_slave_a", |
| 292 | [FUNC_USB_S_b] = "usb_slave_b", |
| 293 | [FUNC_USB_S_c] = "usb_slave_c", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 294 | [FUNC_UART] = "uart", |
| 295 | [FUNC_UART2] = "uart2", |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 296 | [FUNC_UART3] = "uart3", |
| 297 | [FUNC_PLL_STAT] = "pll_stat", |
| 298 | [FUNC_EMMC] = "emmc", |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 299 | [FUNC_EMMC_SD] = "emmc_sd", |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 300 | [FUNC_REF_CLK] = "ref_clk", |
| 301 | [FUNC_RCVRD_CLK] = "rcvrd_clk", |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | struct ocelot_pmx_func { |
| 305 | const char **groups; |
| 306 | unsigned int ngroups; |
| 307 | }; |
| 308 | |
| 309 | struct ocelot_pin_caps { |
| 310 | unsigned int pin; |
| 311 | unsigned char functions[OCELOT_FUNC_PER_PIN]; |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 312 | unsigned char a_functions[OCELOT_FUNC_PER_PIN]; /* Additional functions */ |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | struct ocelot_pinctrl { |
| 316 | struct device *dev; |
| 317 | struct pinctrl_dev *pctl; |
| 318 | struct gpio_chip gpio_chip; |
| 319 | struct regmap *map; |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 320 | void __iomem *pincfg; |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 321 | struct pinctrl_desc *desc; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 322 | struct ocelot_pmx_func func[FUNC_MAX]; |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 323 | u8 stride; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 324 | }; |
| 325 | |
Lars Povlsen | 8f27440 | 2020-11-06 10:31:17 +0100 | [diff] [blame] | 326 | #define LUTON_P(p, f0, f1) \ |
| 327 | static struct ocelot_pin_caps luton_pin_##p = { \ |
| 328 | .pin = p, \ |
| 329 | .functions = { \ |
| 330 | FUNC_GPIO, FUNC_##f0, FUNC_##f1, FUNC_NONE, \ |
| 331 | }, \ |
| 332 | } |
| 333 | |
| 334 | LUTON_P(0, SG0, NONE); |
| 335 | LUTON_P(1, SG0, NONE); |
| 336 | LUTON_P(2, SG0, NONE); |
| 337 | LUTON_P(3, SG0, NONE); |
| 338 | LUTON_P(4, TACHO, NONE); |
| 339 | LUTON_P(5, TWI, PHY_LED); |
| 340 | LUTON_P(6, TWI, PHY_LED); |
| 341 | LUTON_P(7, NONE, PHY_LED); |
| 342 | LUTON_P(8, EXT_IRQ, PHY_LED); |
| 343 | LUTON_P(9, EXT_IRQ, PHY_LED); |
| 344 | LUTON_P(10, SFP, PHY_LED); |
| 345 | LUTON_P(11, SFP, PHY_LED); |
| 346 | LUTON_P(12, SFP, PHY_LED); |
| 347 | LUTON_P(13, SFP, PHY_LED); |
| 348 | LUTON_P(14, SI, PHY_LED); |
| 349 | LUTON_P(15, SI, PHY_LED); |
| 350 | LUTON_P(16, SI, PHY_LED); |
| 351 | LUTON_P(17, SFP, PHY_LED); |
| 352 | LUTON_P(18, SFP, PHY_LED); |
| 353 | LUTON_P(19, SFP, PHY_LED); |
| 354 | LUTON_P(20, SFP, PHY_LED); |
| 355 | LUTON_P(21, SFP, PHY_LED); |
| 356 | LUTON_P(22, SFP, PHY_LED); |
| 357 | LUTON_P(23, SFP, PHY_LED); |
| 358 | LUTON_P(24, SFP, PHY_LED); |
| 359 | LUTON_P(25, SFP, PHY_LED); |
| 360 | LUTON_P(26, SFP, PHY_LED); |
| 361 | LUTON_P(27, SFP, PHY_LED); |
| 362 | LUTON_P(28, SFP, PHY_LED); |
| 363 | LUTON_P(29, PWM, NONE); |
| 364 | LUTON_P(30, UART, NONE); |
| 365 | LUTON_P(31, UART, NONE); |
| 366 | |
| 367 | #define LUTON_PIN(n) { \ |
| 368 | .number = n, \ |
| 369 | .name = "GPIO_"#n, \ |
| 370 | .drv_data = &luton_pin_##n \ |
| 371 | } |
| 372 | |
| 373 | static const struct pinctrl_pin_desc luton_pins[] = { |
| 374 | LUTON_PIN(0), |
| 375 | LUTON_PIN(1), |
| 376 | LUTON_PIN(2), |
| 377 | LUTON_PIN(3), |
| 378 | LUTON_PIN(4), |
| 379 | LUTON_PIN(5), |
| 380 | LUTON_PIN(6), |
| 381 | LUTON_PIN(7), |
| 382 | LUTON_PIN(8), |
| 383 | LUTON_PIN(9), |
| 384 | LUTON_PIN(10), |
| 385 | LUTON_PIN(11), |
| 386 | LUTON_PIN(12), |
| 387 | LUTON_PIN(13), |
| 388 | LUTON_PIN(14), |
| 389 | LUTON_PIN(15), |
| 390 | LUTON_PIN(16), |
| 391 | LUTON_PIN(17), |
| 392 | LUTON_PIN(18), |
| 393 | LUTON_PIN(19), |
| 394 | LUTON_PIN(20), |
| 395 | LUTON_PIN(21), |
| 396 | LUTON_PIN(22), |
| 397 | LUTON_PIN(23), |
| 398 | LUTON_PIN(24), |
| 399 | LUTON_PIN(25), |
| 400 | LUTON_PIN(26), |
| 401 | LUTON_PIN(27), |
| 402 | LUTON_PIN(28), |
| 403 | LUTON_PIN(29), |
| 404 | LUTON_PIN(30), |
| 405 | LUTON_PIN(31), |
| 406 | }; |
| 407 | |
Lars Povlsen | 6e6347e | 2020-11-06 10:31:18 +0100 | [diff] [blame] | 408 | #define SERVAL_P(p, f0, f1, f2) \ |
| 409 | static struct ocelot_pin_caps serval_pin_##p = { \ |
| 410 | .pin = p, \ |
| 411 | .functions = { \ |
| 412 | FUNC_GPIO, FUNC_##f0, FUNC_##f1, FUNC_##f2, \ |
| 413 | }, \ |
| 414 | } |
| 415 | |
| 416 | SERVAL_P(0, SG0, NONE, NONE); |
| 417 | SERVAL_P(1, SG0, NONE, NONE); |
| 418 | SERVAL_P(2, SG0, NONE, NONE); |
| 419 | SERVAL_P(3, SG0, NONE, NONE); |
| 420 | SERVAL_P(4, TACHO, NONE, NONE); |
| 421 | SERVAL_P(5, PWM, NONE, NONE); |
| 422 | SERVAL_P(6, TWI, NONE, NONE); |
| 423 | SERVAL_P(7, TWI, NONE, NONE); |
| 424 | SERVAL_P(8, SI, NONE, NONE); |
| 425 | SERVAL_P(9, SI, MD, NONE); |
| 426 | SERVAL_P(10, SI, MD, NONE); |
| 427 | SERVAL_P(11, SFP, MD, TWI_SCL_M); |
| 428 | SERVAL_P(12, SFP, MD, TWI_SCL_M); |
| 429 | SERVAL_P(13, SFP, UART2, TWI_SCL_M); |
| 430 | SERVAL_P(14, SFP, UART2, TWI_SCL_M); |
| 431 | SERVAL_P(15, SFP, PTP0, TWI_SCL_M); |
| 432 | SERVAL_P(16, SFP, PTP0, TWI_SCL_M); |
| 433 | SERVAL_P(17, SFP, PCI_WAKE, TWI_SCL_M); |
| 434 | SERVAL_P(18, SFP, NONE, TWI_SCL_M); |
| 435 | SERVAL_P(19, SFP, NONE, TWI_SCL_M); |
| 436 | SERVAL_P(20, SFP, NONE, TWI_SCL_M); |
| 437 | SERVAL_P(21, SFP, NONE, TWI_SCL_M); |
| 438 | SERVAL_P(22, NONE, NONE, NONE); |
| 439 | SERVAL_P(23, NONE, NONE, NONE); |
| 440 | SERVAL_P(24, NONE, NONE, NONE); |
| 441 | SERVAL_P(25, NONE, NONE, NONE); |
| 442 | SERVAL_P(26, UART, NONE, NONE); |
| 443 | SERVAL_P(27, UART, NONE, NONE); |
| 444 | SERVAL_P(28, IRQ0, NONE, NONE); |
| 445 | SERVAL_P(29, IRQ1, NONE, NONE); |
| 446 | SERVAL_P(30, PTP0, NONE, NONE); |
| 447 | SERVAL_P(31, PTP0, NONE, NONE); |
| 448 | |
| 449 | #define SERVAL_PIN(n) { \ |
| 450 | .number = n, \ |
| 451 | .name = "GPIO_"#n, \ |
| 452 | .drv_data = &serval_pin_##n \ |
| 453 | } |
| 454 | |
| 455 | static const struct pinctrl_pin_desc serval_pins[] = { |
| 456 | SERVAL_PIN(0), |
| 457 | SERVAL_PIN(1), |
| 458 | SERVAL_PIN(2), |
| 459 | SERVAL_PIN(3), |
| 460 | SERVAL_PIN(4), |
| 461 | SERVAL_PIN(5), |
| 462 | SERVAL_PIN(6), |
| 463 | SERVAL_PIN(7), |
| 464 | SERVAL_PIN(8), |
| 465 | SERVAL_PIN(9), |
| 466 | SERVAL_PIN(10), |
| 467 | SERVAL_PIN(11), |
| 468 | SERVAL_PIN(12), |
| 469 | SERVAL_PIN(13), |
| 470 | SERVAL_PIN(14), |
| 471 | SERVAL_PIN(15), |
| 472 | SERVAL_PIN(16), |
| 473 | SERVAL_PIN(17), |
| 474 | SERVAL_PIN(18), |
| 475 | SERVAL_PIN(19), |
| 476 | SERVAL_PIN(20), |
| 477 | SERVAL_PIN(21), |
| 478 | SERVAL_PIN(22), |
| 479 | SERVAL_PIN(23), |
| 480 | SERVAL_PIN(24), |
| 481 | SERVAL_PIN(25), |
| 482 | SERVAL_PIN(26), |
| 483 | SERVAL_PIN(27), |
| 484 | SERVAL_PIN(28), |
| 485 | SERVAL_PIN(29), |
| 486 | SERVAL_PIN(30), |
| 487 | SERVAL_PIN(31), |
| 488 | }; |
| 489 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 490 | #define OCELOT_P(p, f0, f1, f2) \ |
| 491 | static struct ocelot_pin_caps ocelot_pin_##p = { \ |
| 492 | .pin = p, \ |
| 493 | .functions = { \ |
| 494 | FUNC_GPIO, FUNC_##f0, FUNC_##f1, FUNC_##f2, \ |
| 495 | }, \ |
| 496 | } |
| 497 | |
| 498 | OCELOT_P(0, SG0, NONE, NONE); |
| 499 | OCELOT_P(1, SG0, NONE, NONE); |
| 500 | OCELOT_P(2, SG0, NONE, NONE); |
| 501 | OCELOT_P(3, SG0, NONE, NONE); |
Alexandre Belloni | 17f7908 | 2018-07-11 15:01:26 +0200 | [diff] [blame] | 502 | OCELOT_P(4, IRQ0_IN, IRQ0_OUT, TWI_SCL_M); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 503 | OCELOT_P(5, IRQ1_IN, IRQ1_OUT, PCI_WAKE); |
| 504 | OCELOT_P(6, UART, TWI_SCL_M, NONE); |
| 505 | OCELOT_P(7, UART, TWI_SCL_M, NONE); |
| 506 | OCELOT_P(8, SI, TWI_SCL_M, IRQ0_OUT); |
| 507 | OCELOT_P(9, SI, TWI_SCL_M, IRQ1_OUT); |
Lars Povlsen | edc7254 | 2020-05-13 14:55:20 +0200 | [diff] [blame] | 508 | OCELOT_P(10, PTP2, TWI_SCL_M, SFP); |
| 509 | OCELOT_P(11, PTP3, TWI_SCL_M, SFP); |
| 510 | OCELOT_P(12, UART2, TWI_SCL_M, SFP); |
| 511 | OCELOT_P(13, UART2, TWI_SCL_M, SFP); |
| 512 | OCELOT_P(14, MIIM, TWI_SCL_M, SFP); |
| 513 | OCELOT_P(15, MIIM, TWI_SCL_M, SFP); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 514 | OCELOT_P(16, TWI, NONE, SI); |
| 515 | OCELOT_P(17, TWI, TWI_SCL_M, SI); |
| 516 | OCELOT_P(18, PTP0, TWI_SCL_M, NONE); |
| 517 | OCELOT_P(19, PTP1, TWI_SCL_M, NONE); |
Lars Povlsen | edc7254 | 2020-05-13 14:55:20 +0200 | [diff] [blame] | 518 | OCELOT_P(20, RECO_CLK, TACHO, TWI_SCL_M); |
| 519 | OCELOT_P(21, RECO_CLK, PWM, TWI_SCL_M); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 520 | |
| 521 | #define OCELOT_PIN(n) { \ |
| 522 | .number = n, \ |
| 523 | .name = "GPIO_"#n, \ |
| 524 | .drv_data = &ocelot_pin_##n \ |
| 525 | } |
| 526 | |
| 527 | static const struct pinctrl_pin_desc ocelot_pins[] = { |
| 528 | OCELOT_PIN(0), |
| 529 | OCELOT_PIN(1), |
| 530 | OCELOT_PIN(2), |
| 531 | OCELOT_PIN(3), |
| 532 | OCELOT_PIN(4), |
| 533 | OCELOT_PIN(5), |
| 534 | OCELOT_PIN(6), |
| 535 | OCELOT_PIN(7), |
| 536 | OCELOT_PIN(8), |
| 537 | OCELOT_PIN(9), |
| 538 | OCELOT_PIN(10), |
| 539 | OCELOT_PIN(11), |
| 540 | OCELOT_PIN(12), |
| 541 | OCELOT_PIN(13), |
| 542 | OCELOT_PIN(14), |
| 543 | OCELOT_PIN(15), |
| 544 | OCELOT_PIN(16), |
| 545 | OCELOT_PIN(17), |
| 546 | OCELOT_PIN(18), |
| 547 | OCELOT_PIN(19), |
| 548 | OCELOT_PIN(20), |
| 549 | OCELOT_PIN(21), |
| 550 | }; |
| 551 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 552 | #define JAGUAR2_P(p, f0, f1) \ |
| 553 | static struct ocelot_pin_caps jaguar2_pin_##p = { \ |
| 554 | .pin = p, \ |
| 555 | .functions = { \ |
| 556 | FUNC_GPIO, FUNC_##f0, FUNC_##f1, FUNC_NONE \ |
| 557 | }, \ |
| 558 | } |
| 559 | |
| 560 | JAGUAR2_P(0, SG0, NONE); |
| 561 | JAGUAR2_P(1, SG0, NONE); |
| 562 | JAGUAR2_P(2, SG0, NONE); |
| 563 | JAGUAR2_P(3, SG0, NONE); |
| 564 | JAGUAR2_P(4, SG1, NONE); |
| 565 | JAGUAR2_P(5, SG1, NONE); |
| 566 | JAGUAR2_P(6, IRQ0_IN, IRQ0_OUT); |
| 567 | JAGUAR2_P(7, IRQ1_IN, IRQ1_OUT); |
| 568 | JAGUAR2_P(8, PTP0, NONE); |
| 569 | JAGUAR2_P(9, PTP1, NONE); |
| 570 | JAGUAR2_P(10, UART, NONE); |
| 571 | JAGUAR2_P(11, UART, NONE); |
| 572 | JAGUAR2_P(12, SG1, NONE); |
| 573 | JAGUAR2_P(13, SG1, NONE); |
| 574 | JAGUAR2_P(14, TWI, TWI_SCL_M); |
| 575 | JAGUAR2_P(15, TWI, NONE); |
| 576 | JAGUAR2_P(16, SI, TWI_SCL_M); |
| 577 | JAGUAR2_P(17, SI, TWI_SCL_M); |
| 578 | JAGUAR2_P(18, SI, TWI_SCL_M); |
| 579 | JAGUAR2_P(19, PCI_WAKE, NONE); |
| 580 | JAGUAR2_P(20, IRQ0_OUT, TWI_SCL_M); |
| 581 | JAGUAR2_P(21, IRQ1_OUT, TWI_SCL_M); |
| 582 | JAGUAR2_P(22, TACHO, NONE); |
| 583 | JAGUAR2_P(23, PWM, NONE); |
| 584 | JAGUAR2_P(24, UART2, NONE); |
| 585 | JAGUAR2_P(25, UART2, SI); |
| 586 | JAGUAR2_P(26, PTP2, SI); |
| 587 | JAGUAR2_P(27, PTP3, SI); |
| 588 | JAGUAR2_P(28, TWI2, SI); |
| 589 | JAGUAR2_P(29, TWI2, SI); |
| 590 | JAGUAR2_P(30, SG2, SI); |
| 591 | JAGUAR2_P(31, SG2, SI); |
| 592 | JAGUAR2_P(32, SG2, SI); |
| 593 | JAGUAR2_P(33, SG2, SI); |
| 594 | JAGUAR2_P(34, NONE, TWI_SCL_M); |
| 595 | JAGUAR2_P(35, NONE, TWI_SCL_M); |
| 596 | JAGUAR2_P(36, NONE, TWI_SCL_M); |
| 597 | JAGUAR2_P(37, NONE, TWI_SCL_M); |
| 598 | JAGUAR2_P(38, NONE, TWI_SCL_M); |
| 599 | JAGUAR2_P(39, NONE, TWI_SCL_M); |
| 600 | JAGUAR2_P(40, NONE, TWI_SCL_M); |
| 601 | JAGUAR2_P(41, NONE, TWI_SCL_M); |
| 602 | JAGUAR2_P(42, NONE, TWI_SCL_M); |
| 603 | JAGUAR2_P(43, NONE, TWI_SCL_M); |
Lars Povlsen | edc7254 | 2020-05-13 14:55:20 +0200 | [diff] [blame] | 604 | JAGUAR2_P(44, NONE, SFP); |
| 605 | JAGUAR2_P(45, NONE, SFP); |
| 606 | JAGUAR2_P(46, NONE, SFP); |
| 607 | JAGUAR2_P(47, NONE, SFP); |
| 608 | JAGUAR2_P(48, SFP, NONE); |
| 609 | JAGUAR2_P(49, SFP, SI); |
| 610 | JAGUAR2_P(50, SFP, SI); |
| 611 | JAGUAR2_P(51, SFP, SI); |
| 612 | JAGUAR2_P(52, SFP, NONE); |
| 613 | JAGUAR2_P(53, SFP, NONE); |
| 614 | JAGUAR2_P(54, SFP, NONE); |
| 615 | JAGUAR2_P(55, SFP, NONE); |
| 616 | JAGUAR2_P(56, MIIM, SFP); |
| 617 | JAGUAR2_P(57, MIIM, SFP); |
| 618 | JAGUAR2_P(58, MIIM, SFP); |
| 619 | JAGUAR2_P(59, MIIM, SFP); |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 620 | JAGUAR2_P(60, NONE, NONE); |
| 621 | JAGUAR2_P(61, NONE, NONE); |
| 622 | JAGUAR2_P(62, NONE, NONE); |
| 623 | JAGUAR2_P(63, NONE, NONE); |
| 624 | |
| 625 | #define JAGUAR2_PIN(n) { \ |
| 626 | .number = n, \ |
| 627 | .name = "GPIO_"#n, \ |
| 628 | .drv_data = &jaguar2_pin_##n \ |
| 629 | } |
| 630 | |
| 631 | static const struct pinctrl_pin_desc jaguar2_pins[] = { |
| 632 | JAGUAR2_PIN(0), |
| 633 | JAGUAR2_PIN(1), |
| 634 | JAGUAR2_PIN(2), |
| 635 | JAGUAR2_PIN(3), |
| 636 | JAGUAR2_PIN(4), |
| 637 | JAGUAR2_PIN(5), |
| 638 | JAGUAR2_PIN(6), |
| 639 | JAGUAR2_PIN(7), |
| 640 | JAGUAR2_PIN(8), |
| 641 | JAGUAR2_PIN(9), |
| 642 | JAGUAR2_PIN(10), |
| 643 | JAGUAR2_PIN(11), |
| 644 | JAGUAR2_PIN(12), |
| 645 | JAGUAR2_PIN(13), |
| 646 | JAGUAR2_PIN(14), |
| 647 | JAGUAR2_PIN(15), |
| 648 | JAGUAR2_PIN(16), |
| 649 | JAGUAR2_PIN(17), |
| 650 | JAGUAR2_PIN(18), |
| 651 | JAGUAR2_PIN(19), |
| 652 | JAGUAR2_PIN(20), |
| 653 | JAGUAR2_PIN(21), |
| 654 | JAGUAR2_PIN(22), |
| 655 | JAGUAR2_PIN(23), |
| 656 | JAGUAR2_PIN(24), |
| 657 | JAGUAR2_PIN(25), |
| 658 | JAGUAR2_PIN(26), |
| 659 | JAGUAR2_PIN(27), |
| 660 | JAGUAR2_PIN(28), |
| 661 | JAGUAR2_PIN(29), |
| 662 | JAGUAR2_PIN(30), |
| 663 | JAGUAR2_PIN(31), |
| 664 | JAGUAR2_PIN(32), |
| 665 | JAGUAR2_PIN(33), |
| 666 | JAGUAR2_PIN(34), |
| 667 | JAGUAR2_PIN(35), |
| 668 | JAGUAR2_PIN(36), |
| 669 | JAGUAR2_PIN(37), |
| 670 | JAGUAR2_PIN(38), |
| 671 | JAGUAR2_PIN(39), |
| 672 | JAGUAR2_PIN(40), |
| 673 | JAGUAR2_PIN(41), |
| 674 | JAGUAR2_PIN(42), |
| 675 | JAGUAR2_PIN(43), |
| 676 | JAGUAR2_PIN(44), |
| 677 | JAGUAR2_PIN(45), |
| 678 | JAGUAR2_PIN(46), |
| 679 | JAGUAR2_PIN(47), |
| 680 | JAGUAR2_PIN(48), |
| 681 | JAGUAR2_PIN(49), |
| 682 | JAGUAR2_PIN(50), |
| 683 | JAGUAR2_PIN(51), |
| 684 | JAGUAR2_PIN(52), |
| 685 | JAGUAR2_PIN(53), |
| 686 | JAGUAR2_PIN(54), |
| 687 | JAGUAR2_PIN(55), |
| 688 | JAGUAR2_PIN(56), |
| 689 | JAGUAR2_PIN(57), |
| 690 | JAGUAR2_PIN(58), |
| 691 | JAGUAR2_PIN(59), |
| 692 | JAGUAR2_PIN(60), |
| 693 | JAGUAR2_PIN(61), |
| 694 | JAGUAR2_PIN(62), |
| 695 | JAGUAR2_PIN(63), |
| 696 | }; |
| 697 | |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 698 | #define SPARX5_P(p, f0, f1, f2) \ |
| 699 | static struct ocelot_pin_caps sparx5_pin_##p = { \ |
| 700 | .pin = p, \ |
| 701 | .functions = { \ |
| 702 | FUNC_GPIO, FUNC_##f0, FUNC_##f1, FUNC_##f2 \ |
| 703 | }, \ |
| 704 | } |
| 705 | |
| 706 | SPARX5_P(0, SG0, PLL_STAT, NONE); |
| 707 | SPARX5_P(1, SG0, NONE, NONE); |
| 708 | SPARX5_P(2, SG0, NONE, NONE); |
| 709 | SPARX5_P(3, SG0, NONE, NONE); |
| 710 | SPARX5_P(4, SG1, NONE, NONE); |
| 711 | SPARX5_P(5, SG1, NONE, NONE); |
| 712 | SPARX5_P(6, IRQ0_IN, IRQ0_OUT, SFP); |
| 713 | SPARX5_P(7, IRQ1_IN, IRQ1_OUT, SFP); |
| 714 | SPARX5_P(8, PTP0, NONE, SFP); |
| 715 | SPARX5_P(9, PTP1, SFP, TWI_SCL_M); |
| 716 | SPARX5_P(10, UART, NONE, NONE); |
| 717 | SPARX5_P(11, UART, NONE, NONE); |
| 718 | SPARX5_P(12, SG1, NONE, NONE); |
| 719 | SPARX5_P(13, SG1, NONE, NONE); |
| 720 | SPARX5_P(14, TWI, TWI_SCL_M, NONE); |
| 721 | SPARX5_P(15, TWI, NONE, NONE); |
| 722 | SPARX5_P(16, SI, TWI_SCL_M, SFP); |
| 723 | SPARX5_P(17, SI, TWI_SCL_M, SFP); |
| 724 | SPARX5_P(18, SI, TWI_SCL_M, SFP); |
| 725 | SPARX5_P(19, PCI_WAKE, TWI_SCL_M, SFP); |
| 726 | SPARX5_P(20, IRQ0_OUT, TWI_SCL_M, SFP); |
| 727 | SPARX5_P(21, IRQ1_OUT, TACHO, SFP); |
| 728 | SPARX5_P(22, TACHO, IRQ0_OUT, TWI_SCL_M); |
| 729 | SPARX5_P(23, PWM, UART3, TWI_SCL_M); |
| 730 | SPARX5_P(24, PTP2, UART3, TWI_SCL_M); |
| 731 | SPARX5_P(25, PTP3, SI, TWI_SCL_M); |
| 732 | SPARX5_P(26, UART2, SI, TWI_SCL_M); |
| 733 | SPARX5_P(27, UART2, SI, TWI_SCL_M); |
| 734 | SPARX5_P(28, TWI2, SI, SFP); |
| 735 | SPARX5_P(29, TWI2, SI, SFP); |
| 736 | SPARX5_P(30, SG2, SI, PWM); |
| 737 | SPARX5_P(31, SG2, SI, TWI_SCL_M); |
| 738 | SPARX5_P(32, SG2, SI, TWI_SCL_M); |
| 739 | SPARX5_P(33, SG2, SI, SFP); |
| 740 | SPARX5_P(34, NONE, TWI_SCL_M, EMMC); |
| 741 | SPARX5_P(35, SFP, TWI_SCL_M, EMMC); |
| 742 | SPARX5_P(36, SFP, TWI_SCL_M, EMMC); |
| 743 | SPARX5_P(37, SFP, NONE, EMMC); |
| 744 | SPARX5_P(38, NONE, TWI_SCL_M, EMMC); |
| 745 | SPARX5_P(39, SI2, TWI_SCL_M, EMMC); |
| 746 | SPARX5_P(40, SI2, TWI_SCL_M, EMMC); |
| 747 | SPARX5_P(41, SI2, TWI_SCL_M, EMMC); |
| 748 | SPARX5_P(42, SI2, TWI_SCL_M, EMMC); |
| 749 | SPARX5_P(43, SI2, TWI_SCL_M, EMMC); |
| 750 | SPARX5_P(44, SI, SFP, EMMC); |
| 751 | SPARX5_P(45, SI, SFP, EMMC); |
| 752 | SPARX5_P(46, NONE, SFP, EMMC); |
| 753 | SPARX5_P(47, NONE, SFP, EMMC); |
| 754 | SPARX5_P(48, TWI3, SI, SFP); |
| 755 | SPARX5_P(49, TWI3, NONE, SFP); |
| 756 | SPARX5_P(50, SFP, NONE, TWI_SCL_M); |
| 757 | SPARX5_P(51, SFP, SI, TWI_SCL_M); |
| 758 | SPARX5_P(52, SFP, MIIM, TWI_SCL_M); |
| 759 | SPARX5_P(53, SFP, MIIM, TWI_SCL_M); |
| 760 | SPARX5_P(54, SFP, PTP2, TWI_SCL_M); |
| 761 | SPARX5_P(55, SFP, PTP3, PCI_WAKE); |
| 762 | SPARX5_P(56, MIIM, SFP, TWI_SCL_M); |
| 763 | SPARX5_P(57, MIIM, SFP, TWI_SCL_M); |
| 764 | SPARX5_P(58, MIIM, SFP, TWI_SCL_M); |
| 765 | SPARX5_P(59, MIIM, SFP, NONE); |
| 766 | SPARX5_P(60, RECO_CLK, NONE, NONE); |
| 767 | SPARX5_P(61, RECO_CLK, NONE, NONE); |
| 768 | SPARX5_P(62, RECO_CLK, PLL_STAT, NONE); |
| 769 | SPARX5_P(63, RECO_CLK, NONE, NONE); |
| 770 | |
| 771 | #define SPARX5_PIN(n) { \ |
| 772 | .number = n, \ |
| 773 | .name = "GPIO_"#n, \ |
| 774 | .drv_data = &sparx5_pin_##n \ |
| 775 | } |
| 776 | |
| 777 | static const struct pinctrl_pin_desc sparx5_pins[] = { |
| 778 | SPARX5_PIN(0), |
| 779 | SPARX5_PIN(1), |
| 780 | SPARX5_PIN(2), |
| 781 | SPARX5_PIN(3), |
| 782 | SPARX5_PIN(4), |
| 783 | SPARX5_PIN(5), |
| 784 | SPARX5_PIN(6), |
| 785 | SPARX5_PIN(7), |
| 786 | SPARX5_PIN(8), |
| 787 | SPARX5_PIN(9), |
| 788 | SPARX5_PIN(10), |
| 789 | SPARX5_PIN(11), |
| 790 | SPARX5_PIN(12), |
| 791 | SPARX5_PIN(13), |
| 792 | SPARX5_PIN(14), |
| 793 | SPARX5_PIN(15), |
| 794 | SPARX5_PIN(16), |
| 795 | SPARX5_PIN(17), |
| 796 | SPARX5_PIN(18), |
| 797 | SPARX5_PIN(19), |
| 798 | SPARX5_PIN(20), |
| 799 | SPARX5_PIN(21), |
| 800 | SPARX5_PIN(22), |
| 801 | SPARX5_PIN(23), |
| 802 | SPARX5_PIN(24), |
| 803 | SPARX5_PIN(25), |
| 804 | SPARX5_PIN(26), |
| 805 | SPARX5_PIN(27), |
| 806 | SPARX5_PIN(28), |
| 807 | SPARX5_PIN(29), |
| 808 | SPARX5_PIN(30), |
| 809 | SPARX5_PIN(31), |
| 810 | SPARX5_PIN(32), |
| 811 | SPARX5_PIN(33), |
| 812 | SPARX5_PIN(34), |
| 813 | SPARX5_PIN(35), |
| 814 | SPARX5_PIN(36), |
| 815 | SPARX5_PIN(37), |
| 816 | SPARX5_PIN(38), |
| 817 | SPARX5_PIN(39), |
| 818 | SPARX5_PIN(40), |
| 819 | SPARX5_PIN(41), |
| 820 | SPARX5_PIN(42), |
| 821 | SPARX5_PIN(43), |
| 822 | SPARX5_PIN(44), |
| 823 | SPARX5_PIN(45), |
| 824 | SPARX5_PIN(46), |
| 825 | SPARX5_PIN(47), |
| 826 | SPARX5_PIN(48), |
| 827 | SPARX5_PIN(49), |
| 828 | SPARX5_PIN(50), |
| 829 | SPARX5_PIN(51), |
| 830 | SPARX5_PIN(52), |
| 831 | SPARX5_PIN(53), |
| 832 | SPARX5_PIN(54), |
| 833 | SPARX5_PIN(55), |
| 834 | SPARX5_PIN(56), |
| 835 | SPARX5_PIN(57), |
| 836 | SPARX5_PIN(58), |
| 837 | SPARX5_PIN(59), |
| 838 | SPARX5_PIN(60), |
| 839 | SPARX5_PIN(61), |
| 840 | SPARX5_PIN(62), |
| 841 | SPARX5_PIN(63), |
| 842 | }; |
| 843 | |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 844 | #define LAN966X_P(p, f0, f1, f2, f3, f4, f5, f6, f7) \ |
| 845 | static struct ocelot_pin_caps lan966x_pin_##p = { \ |
| 846 | .pin = p, \ |
| 847 | .functions = { \ |
| 848 | FUNC_##f0, FUNC_##f1, FUNC_##f2, \ |
| 849 | FUNC_##f3 \ |
| 850 | }, \ |
| 851 | .a_functions = { \ |
| 852 | FUNC_##f4, FUNC_##f5, FUNC_##f6, \ |
| 853 | FUNC_##f7 \ |
| 854 | }, \ |
| 855 | } |
| 856 | |
| 857 | /* Pinmuxing table taken from data sheet */ |
| 858 | /* Pin FUNC0 FUNC1 FUNC2 FUNC3 FUNC4 FUNC5 FUNC6 FUNC7 */ |
| 859 | LAN966X_P(0, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R); |
| 860 | LAN966X_P(1, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R); |
| 861 | LAN966X_P(2, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R); |
| 862 | LAN966X_P(3, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R); |
| 863 | LAN966X_P(4, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R); |
| 864 | LAN966X_P(5, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R); |
| 865 | LAN966X_P(6, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R); |
| 866 | LAN966X_P(7, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R); |
| 867 | LAN966X_P(8, GPIO, FC0_a, USB_H_b, NONE, USB_S_b, NONE, NONE, R); |
| 868 | LAN966X_P(9, GPIO, FC0_a, USB_H_b, NONE, NONE, NONE, NONE, R); |
| 869 | LAN966X_P(10, GPIO, FC0_a, NONE, NONE, NONE, NONE, NONE, R); |
| 870 | LAN966X_P(11, GPIO, FC1_a, NONE, NONE, NONE, NONE, NONE, R); |
| 871 | LAN966X_P(12, GPIO, FC1_a, NONE, NONE, NONE, NONE, NONE, R); |
| 872 | LAN966X_P(13, GPIO, FC1_a, NONE, NONE, NONE, NONE, NONE, R); |
| 873 | LAN966X_P(14, GPIO, FC2_a, NONE, NONE, NONE, NONE, NONE, R); |
| 874 | LAN966X_P(15, GPIO, FC2_a, NONE, NONE, NONE, NONE, NONE, R); |
| 875 | LAN966X_P(16, GPIO, FC2_a, IB_TRG_a, NONE, OB_TRG_a, IRQ_IN_c, IRQ_OUT_c, R); |
| 876 | LAN966X_P(17, GPIO, FC3_a, IB_TRG_a, NONE, OB_TRG_a, IRQ_IN_c, IRQ_OUT_c, R); |
| 877 | LAN966X_P(18, GPIO, FC3_a, IB_TRG_a, NONE, OB_TRG_a, IRQ_IN_c, IRQ_OUT_c, R); |
| 878 | LAN966X_P(19, GPIO, FC3_a, IB_TRG_a, NONE, OB_TRG_a, IRQ_IN_c, IRQ_OUT_c, R); |
| 879 | LAN966X_P(20, GPIO, FC4_a, IB_TRG_a, NONE, OB_TRG_a, IRQ_IN_c, NONE, R); |
| 880 | LAN966X_P(21, GPIO, FC4_a, NONE, NONE, OB_TRG_a, NONE, NONE, R); |
| 881 | LAN966X_P(22, GPIO, FC4_a, NONE, NONE, OB_TRG_a, NONE, NONE, R); |
| 882 | LAN966X_P(23, GPIO, NONE, NONE, NONE, OB_TRG_a, NONE, NONE, R); |
| 883 | LAN966X_P(24, GPIO, FC0_b, IB_TRG_a, USB_H_c, OB_TRG_a, IRQ_IN_c, TACHO_a, R); |
| 884 | LAN966X_P(25, GPIO, FC0_b, IB_TRG_a, USB_H_c, OB_TRG_a, IRQ_OUT_c, SFP_SD, R); |
| 885 | LAN966X_P(26, GPIO, FC0_b, IB_TRG_a, USB_S_c, OB_TRG_a, CAN0_a, SFP_SD, R); |
| 886 | LAN966X_P(27, GPIO, NONE, NONE, NONE, OB_TRG_a, CAN0_a, NONE, R); |
| 887 | LAN966X_P(28, GPIO, MIIM_a, NONE, NONE, OB_TRG_a, IRQ_OUT_c, SFP_SD, R); |
| 888 | LAN966X_P(29, GPIO, MIIM_a, NONE, NONE, OB_TRG_a, NONE, NONE, R); |
| 889 | LAN966X_P(30, GPIO, FC3_c, CAN1, NONE, OB_TRG, RECO_b, NONE, R); |
| 890 | LAN966X_P(31, GPIO, FC3_c, CAN1, NONE, OB_TRG, RECO_b, NONE, R); |
| 891 | LAN966X_P(32, GPIO, FC3_c, NONE, SGPIO_a, NONE, MIIM_Sa, NONE, R); |
| 892 | LAN966X_P(33, GPIO, FC1_b, NONE, SGPIO_a, NONE, MIIM_Sa, MIIM_b, R); |
| 893 | LAN966X_P(34, GPIO, FC1_b, NONE, SGPIO_a, NONE, MIIM_Sa, MIIM_b, R); |
| 894 | LAN966X_P(35, GPIO, FC1_b, NONE, SGPIO_a, CAN0_b, NONE, NONE, R); |
| 895 | LAN966X_P(36, GPIO, NONE, PTPSYNC_1, NONE, CAN0_b, NONE, NONE, R); |
| 896 | LAN966X_P(37, GPIO, FC_SHRD0, PTPSYNC_2, TWI_SLC_GATE_AD, NONE, NONE, NONE, R); |
| 897 | LAN966X_P(38, GPIO, NONE, PTPSYNC_3, NONE, NONE, NONE, NONE, R); |
| 898 | LAN966X_P(39, GPIO, NONE, PTPSYNC_4, NONE, NONE, NONE, NONE, R); |
| 899 | LAN966X_P(40, GPIO, FC_SHRD1, PTPSYNC_5, NONE, NONE, NONE, NONE, R); |
| 900 | LAN966X_P(41, GPIO, FC_SHRD2, PTPSYNC_6, TWI_SLC_GATE_AD, NONE, NONE, NONE, R); |
| 901 | LAN966X_P(42, GPIO, FC_SHRD3, PTPSYNC_7, TWI_SLC_GATE_AD, NONE, NONE, NONE, R); |
| 902 | LAN966X_P(43, GPIO, FC2_b, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, RECO_a, IRQ_IN_a, R); |
| 903 | LAN966X_P(44, GPIO, FC2_b, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, RECO_a, IRQ_IN_a, R); |
| 904 | LAN966X_P(45, GPIO, FC2_b, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, NONE, IRQ_IN_a, R); |
| 905 | LAN966X_P(46, GPIO, FC1_c, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, FC_SHRD4, IRQ_IN_a, R); |
| 906 | LAN966X_P(47, GPIO, FC1_c, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, FC_SHRD5, IRQ_IN_a, R); |
| 907 | LAN966X_P(48, GPIO, FC1_c, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, FC_SHRD6, IRQ_IN_a, R); |
| 908 | LAN966X_P(49, GPIO, FC_SHRD7, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, TWI_SLC_GATE, IRQ_IN_a, R); |
| 909 | LAN966X_P(50, GPIO, FC_SHRD16, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, TWI_SLC_GATE, NONE, R); |
| 910 | LAN966X_P(51, GPIO, FC3_b, OB_TRG_b, IB_TRG_c, IRQ_OUT_b, NONE, IRQ_IN_b, R); |
| 911 | LAN966X_P(52, GPIO, FC3_b, OB_TRG_b, IB_TRG_c, IRQ_OUT_b, TACHO_b, IRQ_IN_b, R); |
| 912 | LAN966X_P(53, GPIO, FC3_b, OB_TRG_b, IB_TRG_c, IRQ_OUT_b, NONE, IRQ_IN_b, R); |
| 913 | LAN966X_P(54, GPIO, FC_SHRD8, OB_TRG_b, IB_TRG_c, IRQ_OUT_b, TWI_SLC_GATE, IRQ_IN_b, R); |
| 914 | LAN966X_P(55, GPIO, FC_SHRD9, OB_TRG_b, IB_TRG_c, IRQ_OUT_b, TWI_SLC_GATE, IRQ_IN_b, R); |
| 915 | LAN966X_P(56, GPIO, FC4_b, OB_TRG_b, IB_TRG_c, IRQ_OUT_b, FC_SHRD10, IRQ_IN_b, R); |
| 916 | LAN966X_P(57, GPIO, FC4_b, TWI_SLC_GATE, IB_TRG_c, IRQ_OUT_b, FC_SHRD11, IRQ_IN_b, R); |
| 917 | LAN966X_P(58, GPIO, FC4_b, TWI_SLC_GATE, IB_TRG_c, IRQ_OUT_b, FC_SHRD12, IRQ_IN_b, R); |
| 918 | LAN966X_P(59, GPIO, QSPI1, MIIM_c, NONE, NONE, MIIM_Sb, NONE, R); |
| 919 | LAN966X_P(60, GPIO, QSPI1, MIIM_c, NONE, NONE, MIIM_Sb, NONE, R); |
| 920 | LAN966X_P(61, GPIO, QSPI1, NONE, SGPIO_b, FC0_c, MIIM_Sb, NONE, R); |
| 921 | LAN966X_P(62, GPIO, QSPI1, FC_SHRD13, SGPIO_b, FC0_c, TWI_SLC_GATE, SFP_SD, R); |
| 922 | LAN966X_P(63, GPIO, QSPI1, FC_SHRD14, SGPIO_b, FC0_c, TWI_SLC_GATE, SFP_SD, R); |
| 923 | LAN966X_P(64, GPIO, QSPI1, FC4_c, SGPIO_b, FC_SHRD15, TWI_SLC_GATE, SFP_SD, R); |
| 924 | LAN966X_P(65, GPIO, USB_H_a, FC4_c, NONE, IRQ_OUT_c, TWI_SLC_GATE_AD, NONE, R); |
| 925 | LAN966X_P(66, GPIO, USB_H_a, FC4_c, USB_S_a, IRQ_OUT_c, IRQ_IN_c, NONE, R); |
| 926 | LAN966X_P(67, GPIO, EMMC_SD, NONE, QSPI2, NONE, NONE, NONE, R); |
| 927 | LAN966X_P(68, GPIO, EMMC_SD, NONE, QSPI2, NONE, NONE, NONE, R); |
| 928 | LAN966X_P(69, GPIO, EMMC_SD, NONE, QSPI2, NONE, NONE, NONE, R); |
| 929 | LAN966X_P(70, GPIO, EMMC_SD, NONE, QSPI2, NONE, NONE, NONE, R); |
| 930 | LAN966X_P(71, GPIO, EMMC_SD, NONE, QSPI2, NONE, NONE, NONE, R); |
| 931 | LAN966X_P(72, GPIO, EMMC_SD, NONE, QSPI2, NONE, NONE, NONE, R); |
| 932 | LAN966X_P(73, GPIO, EMMC, NONE, NONE, SD, NONE, NONE, R); |
| 933 | LAN966X_P(74, GPIO, EMMC, NONE, FC_SHRD17, SD, TWI_SLC_GATE, NONE, R); |
| 934 | LAN966X_P(75, GPIO, EMMC, NONE, FC_SHRD18, SD, TWI_SLC_GATE, NONE, R); |
| 935 | LAN966X_P(76, GPIO, EMMC, NONE, FC_SHRD19, SD, TWI_SLC_GATE, NONE, R); |
| 936 | LAN966X_P(77, GPIO, EMMC_SD, NONE, FC_SHRD20, NONE, TWI_SLC_GATE, NONE, R); |
| 937 | |
| 938 | #define LAN966X_PIN(n) { \ |
| 939 | .number = n, \ |
| 940 | .name = "GPIO_"#n, \ |
| 941 | .drv_data = &lan966x_pin_##n \ |
| 942 | } |
| 943 | |
| 944 | static const struct pinctrl_pin_desc lan966x_pins[] = { |
| 945 | LAN966X_PIN(0), |
| 946 | LAN966X_PIN(1), |
| 947 | LAN966X_PIN(2), |
| 948 | LAN966X_PIN(3), |
| 949 | LAN966X_PIN(4), |
| 950 | LAN966X_PIN(5), |
| 951 | LAN966X_PIN(6), |
| 952 | LAN966X_PIN(7), |
| 953 | LAN966X_PIN(8), |
| 954 | LAN966X_PIN(9), |
| 955 | LAN966X_PIN(10), |
| 956 | LAN966X_PIN(11), |
| 957 | LAN966X_PIN(12), |
| 958 | LAN966X_PIN(13), |
| 959 | LAN966X_PIN(14), |
| 960 | LAN966X_PIN(15), |
| 961 | LAN966X_PIN(16), |
| 962 | LAN966X_PIN(17), |
| 963 | LAN966X_PIN(18), |
| 964 | LAN966X_PIN(19), |
| 965 | LAN966X_PIN(20), |
| 966 | LAN966X_PIN(21), |
| 967 | LAN966X_PIN(22), |
| 968 | LAN966X_PIN(23), |
| 969 | LAN966X_PIN(24), |
| 970 | LAN966X_PIN(25), |
| 971 | LAN966X_PIN(26), |
| 972 | LAN966X_PIN(27), |
| 973 | LAN966X_PIN(28), |
| 974 | LAN966X_PIN(29), |
| 975 | LAN966X_PIN(30), |
| 976 | LAN966X_PIN(31), |
| 977 | LAN966X_PIN(32), |
| 978 | LAN966X_PIN(33), |
| 979 | LAN966X_PIN(34), |
| 980 | LAN966X_PIN(35), |
| 981 | LAN966X_PIN(36), |
| 982 | LAN966X_PIN(37), |
| 983 | LAN966X_PIN(38), |
| 984 | LAN966X_PIN(39), |
| 985 | LAN966X_PIN(40), |
| 986 | LAN966X_PIN(41), |
| 987 | LAN966X_PIN(42), |
| 988 | LAN966X_PIN(43), |
| 989 | LAN966X_PIN(44), |
| 990 | LAN966X_PIN(45), |
| 991 | LAN966X_PIN(46), |
| 992 | LAN966X_PIN(47), |
| 993 | LAN966X_PIN(48), |
| 994 | LAN966X_PIN(49), |
| 995 | LAN966X_PIN(50), |
| 996 | LAN966X_PIN(51), |
| 997 | LAN966X_PIN(52), |
| 998 | LAN966X_PIN(53), |
| 999 | LAN966X_PIN(54), |
| 1000 | LAN966X_PIN(55), |
| 1001 | LAN966X_PIN(56), |
| 1002 | LAN966X_PIN(57), |
| 1003 | LAN966X_PIN(58), |
| 1004 | LAN966X_PIN(59), |
| 1005 | LAN966X_PIN(60), |
| 1006 | LAN966X_PIN(61), |
| 1007 | LAN966X_PIN(62), |
| 1008 | LAN966X_PIN(63), |
| 1009 | LAN966X_PIN(64), |
| 1010 | LAN966X_PIN(65), |
| 1011 | LAN966X_PIN(66), |
| 1012 | LAN966X_PIN(67), |
| 1013 | LAN966X_PIN(68), |
| 1014 | LAN966X_PIN(69), |
| 1015 | LAN966X_PIN(70), |
| 1016 | LAN966X_PIN(71), |
| 1017 | LAN966X_PIN(72), |
| 1018 | LAN966X_PIN(73), |
| 1019 | LAN966X_PIN(74), |
| 1020 | LAN966X_PIN(75), |
| 1021 | LAN966X_PIN(76), |
| 1022 | LAN966X_PIN(77), |
| 1023 | }; |
| 1024 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1025 | static int ocelot_get_functions_count(struct pinctrl_dev *pctldev) |
| 1026 | { |
| 1027 | return ARRAY_SIZE(ocelot_function_names); |
| 1028 | } |
| 1029 | |
| 1030 | static const char *ocelot_get_function_name(struct pinctrl_dev *pctldev, |
| 1031 | unsigned int function) |
| 1032 | { |
| 1033 | return ocelot_function_names[function]; |
| 1034 | } |
| 1035 | |
| 1036 | static int ocelot_get_function_groups(struct pinctrl_dev *pctldev, |
| 1037 | unsigned int function, |
| 1038 | const char *const **groups, |
| 1039 | unsigned *const num_groups) |
| 1040 | { |
| 1041 | struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); |
| 1042 | |
| 1043 | *groups = info->func[function].groups; |
| 1044 | *num_groups = info->func[function].ngroups; |
| 1045 | |
| 1046 | return 0; |
| 1047 | } |
| 1048 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1049 | static int ocelot_pin_function_idx(struct ocelot_pinctrl *info, |
| 1050 | unsigned int pin, unsigned int function) |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1051 | { |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1052 | struct ocelot_pin_caps *p = info->desc->pins[pin].drv_data; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1053 | int i; |
| 1054 | |
| 1055 | for (i = 0; i < OCELOT_FUNC_PER_PIN; i++) { |
| 1056 | if (function == p->functions[i]) |
| 1057 | return i; |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 1058 | |
| 1059 | if (function == p->a_functions[i]) |
| 1060 | return i + OCELOT_FUNC_PER_PIN; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | return -1; |
| 1064 | } |
| 1065 | |
Alexandre Belloni | 4b36082 | 2019-06-20 20:30:37 +0200 | [diff] [blame] | 1066 | #define REG_ALT(msb, info, p) (OCELOT_GPIO_ALT0 * (info)->stride + 4 * ((msb) + ((info)->stride * ((p) / 32)))) |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1067 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1068 | static int ocelot_pinmux_set_mux(struct pinctrl_dev *pctldev, |
| 1069 | unsigned int selector, unsigned int group) |
| 1070 | { |
| 1071 | struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1072 | struct ocelot_pin_caps *pin = info->desc->pins[group].drv_data; |
| 1073 | unsigned int p = pin->pin % 32; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1074 | int f; |
| 1075 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1076 | f = ocelot_pin_function_idx(info, group, selector); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1077 | if (f < 0) |
| 1078 | return -EINVAL; |
| 1079 | |
| 1080 | /* |
| 1081 | * f is encoded on two bits. |
Alexandre Belloni | 4b36082 | 2019-06-20 20:30:37 +0200 | [diff] [blame] | 1082 | * bit 0 of f goes in BIT(pin) of ALT[0], bit 1 of f goes in BIT(pin) of |
| 1083 | * ALT[1] |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1084 | * This is racy because both registers can't be updated at the same time |
| 1085 | * but it doesn't matter much for now. |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 1086 | * Note: ALT0/ALT1 are organized specially for 64 gpio targets |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1087 | */ |
Alexandre Belloni | 4b36082 | 2019-06-20 20:30:37 +0200 | [diff] [blame] | 1088 | regmap_update_bits(info->map, REG_ALT(0, info, pin->pin), |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1089 | BIT(p), f << p); |
Alexandre Belloni | 4b36082 | 2019-06-20 20:30:37 +0200 | [diff] [blame] | 1090 | regmap_update_bits(info->map, REG_ALT(1, info, pin->pin), |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1091 | BIT(p), f << (p - 1)); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1092 | |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 1096 | static int lan966x_pinmux_set_mux(struct pinctrl_dev *pctldev, |
| 1097 | unsigned int selector, unsigned int group) |
| 1098 | { |
| 1099 | struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); |
| 1100 | struct ocelot_pin_caps *pin = info->desc->pins[group].drv_data; |
| 1101 | unsigned int p = pin->pin % 32; |
| 1102 | int f; |
| 1103 | |
| 1104 | f = ocelot_pin_function_idx(info, group, selector); |
| 1105 | if (f < 0) |
| 1106 | return -EINVAL; |
| 1107 | |
| 1108 | /* |
| 1109 | * f is encoded on three bits. |
| 1110 | * bit 0 of f goes in BIT(pin) of ALT[0], bit 1 of f goes in BIT(pin) of |
| 1111 | * ALT[1], bit 2 of f goes in BIT(pin) of ALT[2] |
| 1112 | * This is racy because three registers can't be updated at the same time |
| 1113 | * but it doesn't matter much for now. |
| 1114 | * Note: ALT0/ALT1/ALT2 are organized specially for 78 gpio targets |
| 1115 | */ |
| 1116 | regmap_update_bits(info->map, REG_ALT(0, info, pin->pin), |
| 1117 | BIT(p), f << p); |
| 1118 | regmap_update_bits(info->map, REG_ALT(1, info, pin->pin), |
| 1119 | BIT(p), (f >> 1) << p); |
| 1120 | regmap_update_bits(info->map, REG_ALT(2, info, pin->pin), |
| 1121 | BIT(p), (f >> 2) << p); |
| 1122 | |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
Alexandre Belloni | 4b36082 | 2019-06-20 20:30:37 +0200 | [diff] [blame] | 1126 | #define REG(r, info, p) ((r) * (info)->stride + (4 * ((p) / 32))) |
| 1127 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1128 | static int ocelot_gpio_set_direction(struct pinctrl_dev *pctldev, |
| 1129 | struct pinctrl_gpio_range *range, |
| 1130 | unsigned int pin, bool input) |
| 1131 | { |
| 1132 | struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1133 | unsigned int p = pin % 32; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1134 | |
Alexandre Belloni | f2818ba | 2019-06-20 20:30:36 +0200 | [diff] [blame] | 1135 | regmap_update_bits(info->map, REG(OCELOT_GPIO_OE, info, pin), BIT(p), |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1136 | input ? 0 : BIT(p)); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1137 | |
| 1138 | return 0; |
| 1139 | } |
| 1140 | |
| 1141 | static int ocelot_gpio_request_enable(struct pinctrl_dev *pctldev, |
| 1142 | struct pinctrl_gpio_range *range, |
| 1143 | unsigned int offset) |
| 1144 | { |
| 1145 | struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1146 | unsigned int p = offset % 32; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1147 | |
Alexandre Belloni | 4b36082 | 2019-06-20 20:30:37 +0200 | [diff] [blame] | 1148 | regmap_update_bits(info->map, REG_ALT(0, info, offset), |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1149 | BIT(p), 0); |
Alexandre Belloni | 4b36082 | 2019-06-20 20:30:37 +0200 | [diff] [blame] | 1150 | regmap_update_bits(info->map, REG_ALT(1, info, offset), |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1151 | BIT(p), 0); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1152 | |
| 1153 | return 0; |
| 1154 | } |
| 1155 | |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 1156 | static int lan966x_gpio_request_enable(struct pinctrl_dev *pctldev, |
| 1157 | struct pinctrl_gpio_range *range, |
| 1158 | unsigned int offset) |
| 1159 | { |
| 1160 | struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); |
| 1161 | unsigned int p = offset % 32; |
| 1162 | |
| 1163 | regmap_update_bits(info->map, REG_ALT(0, info, offset), |
| 1164 | BIT(p), 0); |
| 1165 | regmap_update_bits(info->map, REG_ALT(1, info, offset), |
| 1166 | BIT(p), 0); |
| 1167 | regmap_update_bits(info->map, REG_ALT(2, info, offset), |
| 1168 | BIT(p), 0); |
| 1169 | |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1173 | static const struct pinmux_ops ocelot_pmx_ops = { |
| 1174 | .get_functions_count = ocelot_get_functions_count, |
| 1175 | .get_function_name = ocelot_get_function_name, |
| 1176 | .get_function_groups = ocelot_get_function_groups, |
| 1177 | .set_mux = ocelot_pinmux_set_mux, |
| 1178 | .gpio_set_direction = ocelot_gpio_set_direction, |
| 1179 | .gpio_request_enable = ocelot_gpio_request_enable, |
| 1180 | }; |
| 1181 | |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 1182 | static const struct pinmux_ops lan966x_pmx_ops = { |
| 1183 | .get_functions_count = ocelot_get_functions_count, |
| 1184 | .get_function_name = ocelot_get_function_name, |
| 1185 | .get_function_groups = ocelot_get_function_groups, |
| 1186 | .set_mux = lan966x_pinmux_set_mux, |
| 1187 | .gpio_set_direction = ocelot_gpio_set_direction, |
| 1188 | .gpio_request_enable = lan966x_gpio_request_enable, |
| 1189 | }; |
| 1190 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1191 | static int ocelot_pctl_get_groups_count(struct pinctrl_dev *pctldev) |
| 1192 | { |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1193 | struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); |
| 1194 | |
| 1195 | return info->desc->npins; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | static const char *ocelot_pctl_get_group_name(struct pinctrl_dev *pctldev, |
| 1199 | unsigned int group) |
| 1200 | { |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1201 | struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); |
| 1202 | |
| 1203 | return info->desc->pins[group].name; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | static int ocelot_pctl_get_group_pins(struct pinctrl_dev *pctldev, |
| 1207 | unsigned int group, |
| 1208 | const unsigned int **pins, |
| 1209 | unsigned int *num_pins) |
| 1210 | { |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1211 | struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); |
| 1212 | |
| 1213 | *pins = &info->desc->pins[group].number; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1214 | *num_pins = 1; |
| 1215 | |
| 1216 | return 0; |
| 1217 | } |
| 1218 | |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 1219 | static int ocelot_hw_get_value(struct ocelot_pinctrl *info, |
| 1220 | unsigned int pin, |
| 1221 | unsigned int reg, |
| 1222 | int *val) |
| 1223 | { |
| 1224 | int ret = -EOPNOTSUPP; |
| 1225 | |
| 1226 | if (info->pincfg) { |
| 1227 | u32 regcfg = readl(info->pincfg + (pin * sizeof(u32))); |
| 1228 | |
| 1229 | ret = 0; |
| 1230 | switch (reg) { |
| 1231 | case PINCONF_BIAS: |
| 1232 | *val = regcfg & BIAS_BITS; |
| 1233 | break; |
| 1234 | |
| 1235 | case PINCONF_SCHMITT: |
| 1236 | *val = regcfg & SCHMITT_BIT; |
| 1237 | break; |
| 1238 | |
| 1239 | case PINCONF_DRIVE_STRENGTH: |
| 1240 | *val = regcfg & DRIVE_BITS; |
| 1241 | break; |
| 1242 | |
| 1243 | default: |
| 1244 | ret = -EOPNOTSUPP; |
| 1245 | break; |
| 1246 | } |
| 1247 | } |
| 1248 | return ret; |
| 1249 | } |
| 1250 | |
| 1251 | static int ocelot_hw_set_value(struct ocelot_pinctrl *info, |
| 1252 | unsigned int pin, |
| 1253 | unsigned int reg, |
| 1254 | int val) |
| 1255 | { |
| 1256 | int ret = -EOPNOTSUPP; |
| 1257 | |
| 1258 | if (info->pincfg) { |
| 1259 | void __iomem *regaddr = info->pincfg + (pin * sizeof(u32)); |
| 1260 | |
| 1261 | ret = 0; |
| 1262 | switch (reg) { |
| 1263 | case PINCONF_BIAS: |
| 1264 | ocelot_clrsetbits(regaddr, BIAS_BITS, val); |
| 1265 | break; |
| 1266 | |
| 1267 | case PINCONF_SCHMITT: |
| 1268 | ocelot_clrsetbits(regaddr, SCHMITT_BIT, val); |
| 1269 | break; |
| 1270 | |
| 1271 | case PINCONF_DRIVE_STRENGTH: |
| 1272 | if (val <= 3) |
| 1273 | ocelot_clrsetbits(regaddr, DRIVE_BITS, val); |
| 1274 | else |
| 1275 | ret = -EINVAL; |
| 1276 | break; |
| 1277 | |
| 1278 | default: |
| 1279 | ret = -EOPNOTSUPP; |
| 1280 | break; |
| 1281 | } |
| 1282 | } |
| 1283 | return ret; |
| 1284 | } |
| 1285 | |
| 1286 | static int ocelot_pinconf_get(struct pinctrl_dev *pctldev, |
| 1287 | unsigned int pin, unsigned long *config) |
| 1288 | { |
| 1289 | struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); |
| 1290 | u32 param = pinconf_to_config_param(*config); |
| 1291 | int val, err; |
| 1292 | |
| 1293 | switch (param) { |
| 1294 | case PIN_CONFIG_BIAS_DISABLE: |
| 1295 | case PIN_CONFIG_BIAS_PULL_UP: |
| 1296 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 1297 | err = ocelot_hw_get_value(info, pin, PINCONF_BIAS, &val); |
| 1298 | if (err) |
| 1299 | return err; |
| 1300 | if (param == PIN_CONFIG_BIAS_DISABLE) |
Kaixu Xia | 5451525 | 2020-11-06 16:36:35 +0800 | [diff] [blame] | 1301 | val = (val == 0); |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 1302 | else if (param == PIN_CONFIG_BIAS_PULL_DOWN) |
| 1303 | val = (val & BIAS_PD_BIT ? true : false); |
| 1304 | else /* PIN_CONFIG_BIAS_PULL_UP */ |
| 1305 | val = (val & BIAS_PU_BIT ? true : false); |
| 1306 | break; |
| 1307 | |
| 1308 | case PIN_CONFIG_INPUT_SCHMITT_ENABLE: |
| 1309 | err = ocelot_hw_get_value(info, pin, PINCONF_SCHMITT, &val); |
| 1310 | if (err) |
| 1311 | return err; |
| 1312 | |
| 1313 | val = (val & SCHMITT_BIT ? true : false); |
| 1314 | break; |
| 1315 | |
| 1316 | case PIN_CONFIG_DRIVE_STRENGTH: |
| 1317 | err = ocelot_hw_get_value(info, pin, PINCONF_DRIVE_STRENGTH, |
| 1318 | &val); |
| 1319 | if (err) |
| 1320 | return err; |
| 1321 | break; |
| 1322 | |
| 1323 | case PIN_CONFIG_OUTPUT: |
| 1324 | err = regmap_read(info->map, REG(OCELOT_GPIO_OUT, info, pin), |
| 1325 | &val); |
| 1326 | if (err) |
| 1327 | return err; |
| 1328 | val = !!(val & BIT(pin % 32)); |
| 1329 | break; |
| 1330 | |
| 1331 | case PIN_CONFIG_INPUT_ENABLE: |
| 1332 | case PIN_CONFIG_OUTPUT_ENABLE: |
| 1333 | err = regmap_read(info->map, REG(OCELOT_GPIO_OE, info, pin), |
| 1334 | &val); |
| 1335 | if (err) |
| 1336 | return err; |
| 1337 | val = val & BIT(pin % 32); |
| 1338 | if (param == PIN_CONFIG_OUTPUT_ENABLE) |
| 1339 | val = !!val; |
| 1340 | else |
| 1341 | val = !val; |
| 1342 | break; |
| 1343 | |
| 1344 | default: |
| 1345 | return -EOPNOTSUPP; |
| 1346 | } |
| 1347 | |
| 1348 | *config = pinconf_to_config_packed(param, val); |
| 1349 | |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
| 1353 | static int ocelot_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin, |
| 1354 | unsigned long *configs, unsigned int num_configs) |
| 1355 | { |
| 1356 | struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); |
| 1357 | u32 param, arg, p; |
| 1358 | int cfg, err = 0; |
| 1359 | |
| 1360 | for (cfg = 0; cfg < num_configs; cfg++) { |
| 1361 | param = pinconf_to_config_param(configs[cfg]); |
| 1362 | arg = pinconf_to_config_argument(configs[cfg]); |
| 1363 | |
| 1364 | switch (param) { |
| 1365 | case PIN_CONFIG_BIAS_DISABLE: |
| 1366 | case PIN_CONFIG_BIAS_PULL_UP: |
| 1367 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 1368 | arg = (param == PIN_CONFIG_BIAS_DISABLE) ? 0 : |
| 1369 | (param == PIN_CONFIG_BIAS_PULL_UP) ? BIAS_PU_BIT : |
| 1370 | BIAS_PD_BIT; |
| 1371 | |
| 1372 | err = ocelot_hw_set_value(info, pin, PINCONF_BIAS, arg); |
| 1373 | if (err) |
| 1374 | goto err; |
| 1375 | |
| 1376 | break; |
| 1377 | |
| 1378 | case PIN_CONFIG_INPUT_SCHMITT_ENABLE: |
| 1379 | arg = arg ? SCHMITT_BIT : 0; |
| 1380 | err = ocelot_hw_set_value(info, pin, PINCONF_SCHMITT, |
| 1381 | arg); |
| 1382 | if (err) |
| 1383 | goto err; |
| 1384 | |
| 1385 | break; |
| 1386 | |
| 1387 | case PIN_CONFIG_DRIVE_STRENGTH: |
| 1388 | err = ocelot_hw_set_value(info, pin, |
| 1389 | PINCONF_DRIVE_STRENGTH, |
| 1390 | arg); |
| 1391 | if (err) |
| 1392 | goto err; |
| 1393 | |
| 1394 | break; |
| 1395 | |
| 1396 | case PIN_CONFIG_OUTPUT_ENABLE: |
| 1397 | case PIN_CONFIG_INPUT_ENABLE: |
| 1398 | case PIN_CONFIG_OUTPUT: |
| 1399 | p = pin % 32; |
| 1400 | if (arg) |
| 1401 | regmap_write(info->map, |
| 1402 | REG(OCELOT_GPIO_OUT_SET, info, |
| 1403 | pin), |
| 1404 | BIT(p)); |
| 1405 | else |
| 1406 | regmap_write(info->map, |
| 1407 | REG(OCELOT_GPIO_OUT_CLR, info, |
| 1408 | pin), |
| 1409 | BIT(p)); |
| 1410 | regmap_update_bits(info->map, |
| 1411 | REG(OCELOT_GPIO_OE, info, pin), |
| 1412 | BIT(p), |
| 1413 | param == PIN_CONFIG_INPUT_ENABLE ? |
| 1414 | 0 : BIT(p)); |
| 1415 | break; |
| 1416 | |
| 1417 | default: |
| 1418 | err = -EOPNOTSUPP; |
| 1419 | } |
| 1420 | } |
| 1421 | err: |
| 1422 | return err; |
| 1423 | } |
| 1424 | |
| 1425 | static const struct pinconf_ops ocelot_confops = { |
| 1426 | .is_generic = true, |
| 1427 | .pin_config_get = ocelot_pinconf_get, |
| 1428 | .pin_config_set = ocelot_pinconf_set, |
| 1429 | .pin_config_config_dbg_show = pinconf_generic_dump_config, |
| 1430 | }; |
| 1431 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1432 | static const struct pinctrl_ops ocelot_pctl_ops = { |
| 1433 | .get_groups_count = ocelot_pctl_get_groups_count, |
| 1434 | .get_group_name = ocelot_pctl_get_group_name, |
| 1435 | .get_group_pins = ocelot_pctl_get_group_pins, |
| 1436 | .dt_node_to_map = pinconf_generic_dt_node_to_map_pin, |
| 1437 | .dt_free_map = pinconf_generic_dt_free_map, |
| 1438 | }; |
| 1439 | |
Lars Povlsen | 8f27440 | 2020-11-06 10:31:17 +0100 | [diff] [blame] | 1440 | static struct pinctrl_desc luton_desc = { |
| 1441 | .name = "luton-pinctrl", |
| 1442 | .pins = luton_pins, |
| 1443 | .npins = ARRAY_SIZE(luton_pins), |
| 1444 | .pctlops = &ocelot_pctl_ops, |
| 1445 | .pmxops = &ocelot_pmx_ops, |
| 1446 | .owner = THIS_MODULE, |
| 1447 | }; |
| 1448 | |
Lars Povlsen | 6e6347e | 2020-11-06 10:31:18 +0100 | [diff] [blame] | 1449 | static struct pinctrl_desc serval_desc = { |
| 1450 | .name = "serval-pinctrl", |
| 1451 | .pins = serval_pins, |
| 1452 | .npins = ARRAY_SIZE(serval_pins), |
| 1453 | .pctlops = &ocelot_pctl_ops, |
| 1454 | .pmxops = &ocelot_pmx_ops, |
| 1455 | .owner = THIS_MODULE, |
| 1456 | }; |
| 1457 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1458 | static struct pinctrl_desc ocelot_desc = { |
| 1459 | .name = "ocelot-pinctrl", |
| 1460 | .pins = ocelot_pins, |
| 1461 | .npins = ARRAY_SIZE(ocelot_pins), |
| 1462 | .pctlops = &ocelot_pctl_ops, |
| 1463 | .pmxops = &ocelot_pmx_ops, |
| 1464 | .owner = THIS_MODULE, |
| 1465 | }; |
| 1466 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1467 | static struct pinctrl_desc jaguar2_desc = { |
| 1468 | .name = "jaguar2-pinctrl", |
| 1469 | .pins = jaguar2_pins, |
| 1470 | .npins = ARRAY_SIZE(jaguar2_pins), |
| 1471 | .pctlops = &ocelot_pctl_ops, |
| 1472 | .pmxops = &ocelot_pmx_ops, |
| 1473 | .owner = THIS_MODULE, |
| 1474 | }; |
| 1475 | |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 1476 | static struct pinctrl_desc sparx5_desc = { |
| 1477 | .name = "sparx5-pinctrl", |
| 1478 | .pins = sparx5_pins, |
| 1479 | .npins = ARRAY_SIZE(sparx5_pins), |
| 1480 | .pctlops = &ocelot_pctl_ops, |
| 1481 | .pmxops = &ocelot_pmx_ops, |
| 1482 | .confops = &ocelot_confops, |
| 1483 | .owner = THIS_MODULE, |
| 1484 | }; |
| 1485 | |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 1486 | static struct pinctrl_desc lan966x_desc = { |
| 1487 | .name = "lan966x-pinctrl", |
| 1488 | .pins = lan966x_pins, |
| 1489 | .npins = ARRAY_SIZE(lan966x_pins), |
| 1490 | .pctlops = &ocelot_pctl_ops, |
| 1491 | .pmxops = &lan966x_pmx_ops, |
| 1492 | .confops = &ocelot_confops, |
| 1493 | .owner = THIS_MODULE, |
| 1494 | }; |
| 1495 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1496 | static int ocelot_create_group_func_map(struct device *dev, |
| 1497 | struct ocelot_pinctrl *info) |
| 1498 | { |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1499 | int f, npins, i; |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1500 | u8 *pins = kcalloc(info->desc->npins, sizeof(u8), GFP_KERNEL); |
| 1501 | |
| 1502 | if (!pins) |
| 1503 | return -ENOMEM; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1504 | |
| 1505 | for (f = 0; f < FUNC_MAX; f++) { |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1506 | for (npins = 0, i = 0; i < info->desc->npins; i++) { |
| 1507 | if (ocelot_pin_function_idx(info, i, f) >= 0) |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1508 | pins[npins++] = i; |
| 1509 | } |
| 1510 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1511 | if (!npins) |
| 1512 | continue; |
| 1513 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1514 | info->func[f].ngroups = npins; |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1515 | info->func[f].groups = devm_kcalloc(dev, npins, sizeof(char *), |
| 1516 | GFP_KERNEL); |
| 1517 | if (!info->func[f].groups) { |
| 1518 | kfree(pins); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1519 | return -ENOMEM; |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1520 | } |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1521 | |
| 1522 | for (i = 0; i < npins; i++) |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 1523 | info->func[f].groups[i] = |
| 1524 | info->desc->pins[pins[i]].name; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1525 | } |
| 1526 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1527 | kfree(pins); |
| 1528 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1529 | return 0; |
| 1530 | } |
| 1531 | |
| 1532 | static int ocelot_pinctrl_register(struct platform_device *pdev, |
| 1533 | struct ocelot_pinctrl *info) |
| 1534 | { |
| 1535 | int ret; |
| 1536 | |
| 1537 | ret = ocelot_create_group_func_map(&pdev->dev, info); |
| 1538 | if (ret) { |
| 1539 | dev_err(&pdev->dev, "Unable to create group func map.\n"); |
| 1540 | return ret; |
| 1541 | } |
| 1542 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1543 | info->pctl = devm_pinctrl_register(&pdev->dev, info->desc, info); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1544 | if (IS_ERR(info->pctl)) { |
| 1545 | dev_err(&pdev->dev, "Failed to register pinctrl\n"); |
| 1546 | return PTR_ERR(info->pctl); |
| 1547 | } |
| 1548 | |
| 1549 | return 0; |
| 1550 | } |
| 1551 | |
| 1552 | static int ocelot_gpio_get(struct gpio_chip *chip, unsigned int offset) |
| 1553 | { |
| 1554 | struct ocelot_pinctrl *info = gpiochip_get_data(chip); |
| 1555 | unsigned int val; |
| 1556 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1557 | regmap_read(info->map, REG(OCELOT_GPIO_IN, info, offset), &val); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1558 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1559 | return !!(val & BIT(offset % 32)); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | static void ocelot_gpio_set(struct gpio_chip *chip, unsigned int offset, |
| 1563 | int value) |
| 1564 | { |
| 1565 | struct ocelot_pinctrl *info = gpiochip_get_data(chip); |
| 1566 | |
| 1567 | if (value) |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1568 | regmap_write(info->map, REG(OCELOT_GPIO_OUT_SET, info, offset), |
| 1569 | BIT(offset % 32)); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1570 | else |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1571 | regmap_write(info->map, REG(OCELOT_GPIO_OUT_CLR, info, offset), |
| 1572 | BIT(offset % 32)); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | static int ocelot_gpio_get_direction(struct gpio_chip *chip, |
| 1576 | unsigned int offset) |
| 1577 | { |
| 1578 | struct ocelot_pinctrl *info = gpiochip_get_data(chip); |
| 1579 | unsigned int val; |
| 1580 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1581 | regmap_read(info->map, REG(OCELOT_GPIO_OE, info, offset), &val); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1582 | |
Matti Vaittinen | 3c82787 | 2020-02-14 15:57:12 +0200 | [diff] [blame] | 1583 | if (val & BIT(offset % 32)) |
| 1584 | return GPIO_LINE_DIRECTION_OUT; |
| 1585 | |
| 1586 | return GPIO_LINE_DIRECTION_IN; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | static int ocelot_gpio_direction_input(struct gpio_chip *chip, |
| 1590 | unsigned int offset) |
| 1591 | { |
| 1592 | return pinctrl_gpio_direction_input(chip->base + offset); |
| 1593 | } |
| 1594 | |
| 1595 | static int ocelot_gpio_direction_output(struct gpio_chip *chip, |
| 1596 | unsigned int offset, int value) |
| 1597 | { |
| 1598 | struct ocelot_pinctrl *info = gpiochip_get_data(chip); |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1599 | unsigned int pin = BIT(offset % 32); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1600 | |
| 1601 | if (value) |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1602 | regmap_write(info->map, REG(OCELOT_GPIO_OUT_SET, info, offset), |
| 1603 | pin); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1604 | else |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1605 | regmap_write(info->map, REG(OCELOT_GPIO_OUT_CLR, info, offset), |
| 1606 | pin); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1607 | |
| 1608 | return pinctrl_gpio_direction_output(chip->base + offset); |
| 1609 | } |
| 1610 | |
| 1611 | static const struct gpio_chip ocelot_gpiolib_chip = { |
| 1612 | .request = gpiochip_generic_request, |
| 1613 | .free = gpiochip_generic_free, |
| 1614 | .set = ocelot_gpio_set, |
| 1615 | .get = ocelot_gpio_get, |
| 1616 | .get_direction = ocelot_gpio_get_direction, |
| 1617 | .direction_input = ocelot_gpio_direction_input, |
| 1618 | .direction_output = ocelot_gpio_direction_output, |
| 1619 | .owner = THIS_MODULE, |
| 1620 | }; |
| 1621 | |
Quentin Schulz | be36abb | 2018-07-25 14:26:21 +0200 | [diff] [blame] | 1622 | static void ocelot_irq_mask(struct irq_data *data) |
| 1623 | { |
| 1624 | struct gpio_chip *chip = irq_data_get_irq_chip_data(data); |
| 1625 | struct ocelot_pinctrl *info = gpiochip_get_data(chip); |
| 1626 | unsigned int gpio = irqd_to_hwirq(data); |
| 1627 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1628 | regmap_update_bits(info->map, REG(OCELOT_GPIO_INTR_ENA, info, gpio), |
| 1629 | BIT(gpio % 32), 0); |
Quentin Schulz | be36abb | 2018-07-25 14:26:21 +0200 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | static void ocelot_irq_unmask(struct irq_data *data) |
| 1633 | { |
| 1634 | struct gpio_chip *chip = irq_data_get_irq_chip_data(data); |
| 1635 | struct ocelot_pinctrl *info = gpiochip_get_data(chip); |
| 1636 | unsigned int gpio = irqd_to_hwirq(data); |
| 1637 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1638 | regmap_update_bits(info->map, REG(OCELOT_GPIO_INTR_ENA, info, gpio), |
| 1639 | BIT(gpio % 32), BIT(gpio % 32)); |
Quentin Schulz | be36abb | 2018-07-25 14:26:21 +0200 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | static void ocelot_irq_ack(struct irq_data *data) |
| 1643 | { |
| 1644 | struct gpio_chip *chip = irq_data_get_irq_chip_data(data); |
| 1645 | struct ocelot_pinctrl *info = gpiochip_get_data(chip); |
| 1646 | unsigned int gpio = irqd_to_hwirq(data); |
| 1647 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1648 | regmap_write_bits(info->map, REG(OCELOT_GPIO_INTR, info, gpio), |
| 1649 | BIT(gpio % 32), BIT(gpio % 32)); |
Quentin Schulz | be36abb | 2018-07-25 14:26:21 +0200 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | static int ocelot_irq_set_type(struct irq_data *data, unsigned int type); |
| 1653 | |
| 1654 | static struct irq_chip ocelot_eoi_irqchip = { |
| 1655 | .name = "gpio", |
| 1656 | .irq_mask = ocelot_irq_mask, |
| 1657 | .irq_eoi = ocelot_irq_ack, |
| 1658 | .irq_unmask = ocelot_irq_unmask, |
| 1659 | .flags = IRQCHIP_EOI_THREADED | IRQCHIP_EOI_IF_HANDLED, |
| 1660 | .irq_set_type = ocelot_irq_set_type, |
| 1661 | }; |
| 1662 | |
| 1663 | static struct irq_chip ocelot_irqchip = { |
| 1664 | .name = "gpio", |
| 1665 | .irq_mask = ocelot_irq_mask, |
| 1666 | .irq_ack = ocelot_irq_ack, |
| 1667 | .irq_unmask = ocelot_irq_unmask, |
| 1668 | .irq_set_type = ocelot_irq_set_type, |
| 1669 | }; |
| 1670 | |
| 1671 | static int ocelot_irq_set_type(struct irq_data *data, unsigned int type) |
| 1672 | { |
| 1673 | type &= IRQ_TYPE_SENSE_MASK; |
| 1674 | |
| 1675 | if (!(type & (IRQ_TYPE_EDGE_BOTH | IRQ_TYPE_LEVEL_HIGH))) |
| 1676 | return -EINVAL; |
| 1677 | |
| 1678 | if (type & IRQ_TYPE_LEVEL_HIGH) |
| 1679 | irq_set_chip_handler_name_locked(data, &ocelot_eoi_irqchip, |
| 1680 | handle_fasteoi_irq, NULL); |
| 1681 | if (type & IRQ_TYPE_EDGE_BOTH) |
| 1682 | irq_set_chip_handler_name_locked(data, &ocelot_irqchip, |
| 1683 | handle_edge_irq, NULL); |
| 1684 | |
| 1685 | return 0; |
| 1686 | } |
| 1687 | |
| 1688 | static void ocelot_irq_handler(struct irq_desc *desc) |
| 1689 | { |
| 1690 | struct irq_chip *parent_chip = irq_desc_get_chip(desc); |
| 1691 | struct gpio_chip *chip = irq_desc_get_handler_data(desc); |
| 1692 | struct ocelot_pinctrl *info = gpiochip_get_data(chip); |
Lars Povlsen | 0b47afc6 | 2020-05-13 14:55:21 +0200 | [diff] [blame] | 1693 | unsigned int id_reg = OCELOT_GPIO_INTR_IDENT * info->stride; |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1694 | unsigned int reg = 0, irq, i; |
Quentin Schulz | be36abb | 2018-07-25 14:26:21 +0200 | [diff] [blame] | 1695 | unsigned long irqs; |
| 1696 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1697 | for (i = 0; i < info->stride; i++) { |
Lars Povlsen | 0b47afc6 | 2020-05-13 14:55:21 +0200 | [diff] [blame] | 1698 | regmap_read(info->map, id_reg + 4 * i, ®); |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1699 | if (!reg) |
| 1700 | continue; |
Quentin Schulz | be36abb | 2018-07-25 14:26:21 +0200 | [diff] [blame] | 1701 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1702 | chained_irq_enter(parent_chip, desc); |
Quentin Schulz | be36abb | 2018-07-25 14:26:21 +0200 | [diff] [blame] | 1703 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1704 | irqs = reg; |
Quentin Schulz | be36abb | 2018-07-25 14:26:21 +0200 | [diff] [blame] | 1705 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1706 | for_each_set_bit(irq, &irqs, |
| 1707 | min(32U, info->desc->npins - 32 * i)) |
Marc Zyngier | a9cb09b | 2021-05-04 17:42:18 +0100 | [diff] [blame] | 1708 | generic_handle_domain_irq(chip->irq.domain, irq + 32 * i); |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1709 | |
| 1710 | chained_irq_exit(parent_chip, desc); |
Quentin Schulz | be36abb | 2018-07-25 14:26:21 +0200 | [diff] [blame] | 1711 | } |
Quentin Schulz | be36abb | 2018-07-25 14:26:21 +0200 | [diff] [blame] | 1712 | } |
| 1713 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1714 | static int ocelot_gpiochip_register(struct platform_device *pdev, |
| 1715 | struct ocelot_pinctrl *info) |
| 1716 | { |
| 1717 | struct gpio_chip *gc; |
Linus Walleij | d874bec | 2019-10-02 13:44:54 +0200 | [diff] [blame] | 1718 | struct gpio_irq_chip *girq; |
Qinglang Miao | 17f2c8d | 2020-09-21 21:10:57 +0800 | [diff] [blame] | 1719 | int irq; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1720 | |
| 1721 | info->gpio_chip = ocelot_gpiolib_chip; |
| 1722 | |
| 1723 | gc = &info->gpio_chip; |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1724 | gc->ngpio = info->desc->npins; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1725 | gc->parent = &pdev->dev; |
Colin Foster | a159c2b | 2021-11-19 11:59:26 -0800 | [diff] [blame^] | 1726 | gc->base = -1; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1727 | gc->of_node = info->dev->of_node; |
| 1728 | gc->label = "ocelot-gpio"; |
| 1729 | |
Lars Povlsen | 550713e | 2020-05-13 14:55:19 +0200 | [diff] [blame] | 1730 | irq = irq_of_parse_and_map(gc->of_node, 0); |
| 1731 | if (irq) { |
| 1732 | girq = &gc->irq; |
| 1733 | girq->chip = &ocelot_irqchip; |
| 1734 | girq->parent_handler = ocelot_irq_handler; |
| 1735 | girq->num_parents = 1; |
| 1736 | girq->parents = devm_kcalloc(&pdev->dev, 1, |
| 1737 | sizeof(*girq->parents), |
| 1738 | GFP_KERNEL); |
| 1739 | if (!girq->parents) |
| 1740 | return -ENOMEM; |
| 1741 | girq->parents[0] = irq; |
| 1742 | girq->default_type = IRQ_TYPE_NONE; |
| 1743 | girq->handler = handle_edge_irq; |
| 1744 | } |
Linus Walleij | d874bec | 2019-10-02 13:44:54 +0200 | [diff] [blame] | 1745 | |
Qinglang Miao | 17f2c8d | 2020-09-21 21:10:57 +0800 | [diff] [blame] | 1746 | return devm_gpiochip_add_data(&pdev->dev, gc, info); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1747 | } |
| 1748 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1749 | static const struct of_device_id ocelot_pinctrl_of_match[] = { |
Lars Povlsen | 8f27440 | 2020-11-06 10:31:17 +0100 | [diff] [blame] | 1750 | { .compatible = "mscc,luton-pinctrl", .data = &luton_desc }, |
Lars Povlsen | 6e6347e | 2020-11-06 10:31:18 +0100 | [diff] [blame] | 1751 | { .compatible = "mscc,serval-pinctrl", .data = &serval_desc }, |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1752 | { .compatible = "mscc,ocelot-pinctrl", .data = &ocelot_desc }, |
| 1753 | { .compatible = "mscc,jaguar2-pinctrl", .data = &jaguar2_desc }, |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 1754 | { .compatible = "microchip,sparx5-pinctrl", .data = &sparx5_desc }, |
Kavyasree Kotagiri | 531d6ab | 2021-11-18 16:55:48 +0530 | [diff] [blame] | 1755 | { .compatible = "microchip,lan966x-pinctrl", .data = &lan966x_desc }, |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1756 | {}, |
| 1757 | }; |
| 1758 | |
Colin Ian King | ce3e7f0 | 2018-02-08 14:24:37 +0000 | [diff] [blame] | 1759 | static int ocelot_pinctrl_probe(struct platform_device *pdev) |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1760 | { |
| 1761 | struct device *dev = &pdev->dev; |
| 1762 | struct ocelot_pinctrl *info; |
| 1763 | void __iomem *base; |
| 1764 | int ret; |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1765 | struct regmap_config regmap_config = { |
| 1766 | .reg_bits = 32, |
| 1767 | .val_bits = 32, |
| 1768 | .reg_stride = 4, |
| 1769 | }; |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1770 | |
| 1771 | info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); |
| 1772 | if (!info) |
| 1773 | return -ENOMEM; |
| 1774 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1775 | info->desc = (struct pinctrl_desc *)device_get_match_data(dev); |
| 1776 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1777 | base = devm_ioremap_resource(dev, |
| 1778 | platform_get_resource(pdev, IORESOURCE_MEM, 0)); |
Zhen Lei | 0f9facd | 2021-05-11 17:09:36 +0800 | [diff] [blame] | 1779 | if (IS_ERR(base)) |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1780 | return PTR_ERR(base); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1781 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1782 | info->stride = 1 + (info->desc->npins - 1) / 32; |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 1783 | |
Alexandre Belloni | da801ab | 2018-12-20 15:44:31 +0100 | [diff] [blame] | 1784 | regmap_config.max_register = OCELOT_GPIO_SD_MAP * info->stride + 15 * 4; |
| 1785 | |
| 1786 | info->map = devm_regmap_init_mmio(dev, base, ®map_config); |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1787 | if (IS_ERR(info->map)) { |
| 1788 | dev_err(dev, "Failed to create regmap\n"); |
| 1789 | return PTR_ERR(info->map); |
| 1790 | } |
| 1791 | dev_set_drvdata(dev, info->map); |
| 1792 | info->dev = dev; |
| 1793 | |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 1794 | /* Pinconf registers */ |
| 1795 | if (info->desc->confops) { |
Colin Foster | ad96111 | 2021-11-19 11:59:25 -0800 | [diff] [blame] | 1796 | base = devm_platform_ioremap_resource(pdev, 0); |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 1797 | if (IS_ERR(base)) |
| 1798 | dev_dbg(dev, "Failed to ioremap config registers (no extended pinconf)\n"); |
| 1799 | else |
| 1800 | info->pincfg = base; |
| 1801 | } |
| 1802 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1803 | ret = ocelot_pinctrl_register(pdev, info); |
| 1804 | if (ret) |
| 1805 | return ret; |
| 1806 | |
| 1807 | ret = ocelot_gpiochip_register(pdev, info); |
| 1808 | if (ret) |
| 1809 | return ret; |
| 1810 | |
Lars Povlsen | f8a7476 | 2020-06-15 15:32:37 +0200 | [diff] [blame] | 1811 | dev_info(dev, "driver registered\n"); |
| 1812 | |
Alexandre Belloni | ce8dc09 | 2018-01-06 01:09:26 +0100 | [diff] [blame] | 1813 | return 0; |
| 1814 | } |
| 1815 | |
| 1816 | static struct platform_driver ocelot_pinctrl_driver = { |
| 1817 | .driver = { |
| 1818 | .name = "pinctrl-ocelot", |
| 1819 | .of_match_table = of_match_ptr(ocelot_pinctrl_of_match), |
| 1820 | .suppress_bind_attrs = true, |
| 1821 | }, |
| 1822 | .probe = ocelot_pinctrl_probe, |
| 1823 | }; |
| 1824 | builtin_platform_driver(ocelot_pinctrl_driver); |