1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Renesas RZ/G2L Pin Control and GPIO driver core 4 * 5 * Copyright (C) 2021 Renesas Electronics Corporation. 6 */ 7 8 #include <linux/bitfield.h> 9 #include <linux/bitops.h> 10 #include <linux/clk.h> 11 #include <linux/gpio/driver.h> 12 #include <linux/interrupt.h> 13 #include <linux/io.h> 14 #include <linux/module.h> 15 #include <linux/mutex.h> 16 #include <linux/of.h> 17 #include <linux/of_irq.h> 18 #include <linux/platform_device.h> 19 #include <linux/property.h> 20 #include <linux/seq_file.h> 21 #include <linux/spinlock.h> 22 23 #include <linux/pinctrl/consumer.h> 24 #include <linux/pinctrl/pinconf-generic.h> 25 #include <linux/pinctrl/pinconf.h> 26 #include <linux/pinctrl/pinctrl.h> 27 #include <linux/pinctrl/pinmux.h> 28 29 #include <dt-bindings/pinctrl/renesas,r9a09g047-pinctrl.h> 30 #include <dt-bindings/pinctrl/renesas,r9a09g057-pinctrl.h> 31 #include <dt-bindings/pinctrl/rzg2l-pinctrl.h> 32 33 #include "../core.h" 34 #include "../pinconf.h" 35 #include "../pinmux.h" 36 37 #define DRV_NAME "pinctrl-rzg2l" 38 39 /* 40 * Use 16 lower bits [15:0] for pin identifier 41 * Use 16 higher bits [31:16] for pin mux function 42 */ 43 #define MUX_PIN_ID_MASK GENMASK(15, 0) 44 #define MUX_FUNC_MASK GENMASK(31, 16) 45 46 /* PIN capabilities */ 47 #define PIN_CFG_IOLH_A BIT(0) 48 #define PIN_CFG_IOLH_B BIT(1) 49 #define PIN_CFG_SR BIT(2) 50 #define PIN_CFG_IEN BIT(3) 51 #define PIN_CFG_PUPD BIT(4) 52 #define PIN_CFG_IO_VMC_SD0 BIT(5) 53 #define PIN_CFG_IO_VMC_SD1 BIT(6) 54 #define PIN_CFG_IO_VMC_QSPI BIT(7) 55 #define PIN_CFG_IO_VMC_ETH0 BIT(8) 56 #define PIN_CFG_IO_VMC_ETH1 BIT(9) 57 #define PIN_CFG_NF BIT(10) /* Digital noise filter */ 58 #define PIN_CFG_IOLH_C BIT(11) 59 #define PIN_CFG_SOFT_PS BIT(12) 60 #define PIN_CFG_OEN BIT(13) 61 #define PIN_CFG_NOGPIO_INT BIT(14) 62 #define PIN_CFG_NOD BIT(15) /* N-ch Open Drain */ 63 #define PIN_CFG_SMT BIT(16) /* Schmitt-trigger input control */ 64 #define PIN_CFG_ELC BIT(17) 65 #define PIN_CFG_IOLH_RZV2H BIT(18) 66 67 #define RZG2L_SINGLE_PIN BIT_ULL(63) /* Dedicated pin */ 68 #define RZG2L_VARIABLE_CFG BIT_ULL(62) /* Variable cfg for port pins */ 69 70 #define RZG2L_MPXED_COMMON_PIN_FUNCS(group) \ 71 (PIN_CFG_IOLH_##group | \ 72 PIN_CFG_PUPD | \ 73 PIN_CFG_NF) 74 75 #define RZG2L_MPXED_PIN_FUNCS (RZG2L_MPXED_COMMON_PIN_FUNCS(A) | \ 76 PIN_CFG_SR) 77 78 #define RZG3S_MPXED_PIN_FUNCS(group) (RZG2L_MPXED_COMMON_PIN_FUNCS(group) | \ 79 PIN_CFG_SOFT_PS) 80 81 #define RZV2H_MPXED_PIN_FUNCS (RZG2L_MPXED_COMMON_PIN_FUNCS(RZV2H) | \ 82 PIN_CFG_NOD | \ 83 PIN_CFG_SR | \ 84 PIN_CFG_SMT) 85 86 #define RZG2L_MPXED_ETH_PIN_FUNCS(x) ((x) | PIN_CFG_NF) 87 88 #define PIN_CFG_PIN_MAP_MASK GENMASK_ULL(61, 54) 89 #define PIN_CFG_PIN_REG_MASK GENMASK_ULL(53, 46) 90 #define PIN_CFG_MASK GENMASK_ULL(31, 0) 91 92 /* 93 * m indicates the bitmap of supported pins, a is the register index 94 * and f is pin configuration capabilities supported. 95 */ 96 #define RZG2L_GPIO_PORT_SPARSE_PACK(m, a, f) (FIELD_PREP_CONST(PIN_CFG_PIN_MAP_MASK, (m)) | \ 97 FIELD_PREP_CONST(PIN_CFG_PIN_REG_MASK, (a)) | \ 98 FIELD_PREP_CONST(PIN_CFG_MASK, (f))) 99 #define RZG2L_GPIO_PORT_SPARSE_PACK_VARIABLE(m, a) \ 100 (RZG2L_VARIABLE_CFG | \ 101 RZG2L_GPIO_PORT_SPARSE_PACK(m, a, 0)) 102 103 /* 104 * n indicates number of pins in the port, a is the register index 105 * and f is pin configuration capabilities supported. 106 */ 107 #define RZG2L_GPIO_PORT_PACK(n, a, f) RZG2L_GPIO_PORT_SPARSE_PACK((1ULL << (n)) - 1, (a), (f)) 108 #define RZG2L_GPIO_PORT_PACK_VARIABLE(n, a) (RZG2L_VARIABLE_CFG | \ 109 RZG2L_GPIO_PORT_PACK(n, a, 0)) 110 111 #define RZG2L_SINGLE_PIN_INDEX_MASK GENMASK_ULL(62, 56) 112 #define RZG2L_SINGLE_PIN_BITS_MASK GENMASK_ULL(55, 53) 113 /* 114 * p is the register index while referencing to SR/IEN/IOLH/FILxx 115 * registers, b is the register bits (b * 8) and f is the pin 116 * configuration capabilities supported. 117 */ 118 #define RZG2L_SINGLE_PIN_PACK(p, b, f) (RZG2L_SINGLE_PIN | \ 119 FIELD_PREP_CONST(RZG2L_SINGLE_PIN_INDEX_MASK, (p)) | \ 120 FIELD_PREP_CONST(RZG2L_SINGLE_PIN_BITS_MASK, (b)) | \ 121 FIELD_PREP_CONST(PIN_CFG_MASK, (f))) 122 123 #define RZG2L_PIN_CFG_TO_PORT_OFFSET(cfg) ((cfg) & RZG2L_SINGLE_PIN ? \ 124 FIELD_GET(RZG2L_SINGLE_PIN_INDEX_MASK, (cfg)) : \ 125 FIELD_GET(PIN_CFG_PIN_REG_MASK, (cfg))) 126 127 #define VARIABLE_PIN_CFG_PIN_MASK GENMASK_ULL(54, 52) 128 #define VARIABLE_PIN_CFG_PORT_MASK GENMASK_ULL(51, 47) 129 #define RZG2L_VARIABLE_PIN_CFG_PACK(port, pin, cfg) \ 130 (FIELD_PREP_CONST(VARIABLE_PIN_CFG_PIN_MASK, (pin)) | \ 131 FIELD_PREP_CONST(VARIABLE_PIN_CFG_PORT_MASK, (port)) | \ 132 FIELD_PREP_CONST(PIN_CFG_MASK, (cfg))) 133 134 #define P(off) (0x0000 + (off)) 135 #define PM(off) (0x0100 + (off) * 2) 136 #define PMC(off) (0x0200 + (off)) 137 #define PFC(off) (0x0400 + (off) * 4) 138 #define PIN(off) (0x0800 + (off)) 139 #define IOLH(off) (0x1000 + (off) * 8) 140 #define SR(off) (0x1400 + (off) * 8) 141 #define IEN(off) (0x1800 + (off) * 8) 142 #define PUPD(off) (0x1C00 + (off) * 8) 143 #define ISEL(off) (0x2C00 + (off) * 8) 144 #define NOD(off) (0x3000 + (off) * 8) 145 #define SMT(off) (0x3400 + (off) * 8) 146 #define SD_CH(off, ch) ((off) + (ch) * 4) 147 #define ETH_POC(off, ch) ((off) + (ch) * 4) 148 #define QSPI (0x3008) 149 #define ETH_MODE (0x3018) 150 #define PFC_OEN (0x3C40) /* known on RZ/V2H(P) only */ 151 152 #define PVDD_2500 2 /* I/O domain voltage 2.5V */ 153 #define PVDD_1800 1 /* I/O domain voltage <= 1.8V */ 154 #define PVDD_3300 0 /* I/O domain voltage >= 3.3V */ 155 156 #define PWPR_B0WI BIT(7) /* Bit Write Disable */ 157 #define PWPR_PFCWE BIT(6) /* PFC Register Write Enable */ 158 #define PWPR_REGWE_A BIT(6) /* PFC and PMC Register Write Enable on RZ/V2H(P) */ 159 #define PWPR_REGWE_B BIT(5) /* OEN Register Write Enable, known only in RZ/V2H(P) */ 160 161 #define PM_MASK 0x03 162 #define PFC_MASK 0x0f 163 #define IEN_MASK 0x01 164 #define IOLH_MASK 0x03 165 #define SR_MASK 0x01 166 #define PUPD_MASK 0x03 167 #define NOD_MASK 0x01 168 #define SMT_MASK 0x01 169 170 #define PM_INPUT 0x1 171 #define PM_OUTPUT 0x2 172 173 #define RZG2L_PIN_ID_TO_PORT(id) ((id) / RZG2L_PINS_PER_PORT) 174 #define RZG2L_PIN_ID_TO_PIN(id) ((id) % RZG2L_PINS_PER_PORT) 175 176 #define RZG2L_TINT_MAX_INTERRUPT 32 177 #define RZG2L_PACK_HWIRQ(t, i) (((t) << 16) | (i)) 178 179 /* Custom pinconf parameters */ 180 #define RENESAS_RZV2H_PIN_CONFIG_OUTPUT_IMPEDANCE (PIN_CONFIG_END + 1) 181 182 static const struct pinconf_generic_params renesas_rzv2h_custom_bindings[] = { 183 { "renesas,output-impedance", RENESAS_RZV2H_PIN_CONFIG_OUTPUT_IMPEDANCE, 1 }, 184 }; 185 186 #ifdef CONFIG_DEBUG_FS 187 static const struct pin_config_item renesas_rzv2h_conf_items[] = { 188 PCONFDUMP(RENESAS_RZV2H_PIN_CONFIG_OUTPUT_IMPEDANCE, "output-impedance", "x", true), 189 }; 190 #endif 191 192 /* Read/write 8 bits register */ 193 #define RZG2L_PCTRL_REG_ACCESS8(_read, _addr, _val) \ 194 do { \ 195 if (_read) \ 196 _val = readb(_addr); \ 197 else \ 198 writeb(_val, _addr); \ 199 } while (0) 200 201 /* Read/write 16 bits register */ 202 #define RZG2L_PCTRL_REG_ACCESS16(_read, _addr, _val) \ 203 do { \ 204 if (_read) \ 205 _val = readw(_addr); \ 206 else \ 207 writew(_val, _addr); \ 208 } while (0) 209 210 /* Read/write 32 bits register */ 211 #define RZG2L_PCTRL_REG_ACCESS32(_read, _addr, _val) \ 212 do { \ 213 if (_read) \ 214 _val = readl(_addr); \ 215 else \ 216 writel(_val, _addr); \ 217 } while (0) 218 219 /** 220 * struct rzg2l_register_offsets - specific register offsets 221 * @pwpr: PWPR register offset 222 * @sd_ch: SD_CH register offset 223 * @eth_poc: ETH_POC register offset 224 */ 225 struct rzg2l_register_offsets { 226 u16 pwpr; 227 u16 sd_ch; 228 u16 eth_poc; 229 }; 230 231 /** 232 * enum rzg2l_iolh_index - starting indices in IOLH specific arrays 233 * @RZG2L_IOLH_IDX_1V8: starting index for 1V8 power source 234 * @RZG2L_IOLH_IDX_2V5: starting index for 2V5 power source 235 * @RZG2L_IOLH_IDX_3V3: starting index for 3V3 power source 236 * @RZG2L_IOLH_IDX_MAX: maximum index 237 */ 238 enum rzg2l_iolh_index { 239 RZG2L_IOLH_IDX_1V8 = 0, 240 RZG2L_IOLH_IDX_2V5 = 4, 241 RZG2L_IOLH_IDX_3V3 = 8, 242 RZG2L_IOLH_IDX_MAX = 12, 243 }; 244 245 /* Maximum number of driver strength entries per power source. */ 246 #define RZG2L_IOLH_MAX_DS_ENTRIES (4) 247 248 /** 249 * struct rzg2l_hwcfg - hardware configuration data structure 250 * @regs: hardware specific register offsets 251 * @iolh_groupa_ua: IOLH group A uA specific values 252 * @iolh_groupb_ua: IOLH group B uA specific values 253 * @iolh_groupc_ua: IOLH group C uA specific values 254 * @iolh_groupb_oi: IOLH group B output impedance specific values 255 * @tint_start_index: the start index for the TINT interrupts 256 * @drive_strength_ua: drive strength in uA is supported (otherwise mA is supported) 257 * @func_base: base number for port function (see register PFC) 258 * @oen_max_pin: the maximum pin number supporting output enable 259 * @oen_max_port: the maximum port number supporting output enable 260 */ 261 struct rzg2l_hwcfg { 262 const struct rzg2l_register_offsets regs; 263 u16 iolh_groupa_ua[RZG2L_IOLH_IDX_MAX]; 264 u16 iolh_groupb_ua[RZG2L_IOLH_IDX_MAX]; 265 u16 iolh_groupc_ua[RZG2L_IOLH_IDX_MAX]; 266 u16 iolh_groupb_oi[4]; 267 u16 tint_start_index; 268 bool drive_strength_ua; 269 u8 func_base; 270 u8 oen_max_pin; 271 u8 oen_max_port; 272 }; 273 274 struct rzg2l_dedicated_configs { 275 const char *name; 276 u64 config; 277 }; 278 279 struct rzg2l_pinctrl; 280 281 struct rzg2l_pinctrl_data { 282 const char * const *port_pins; 283 const u64 *port_pin_configs; 284 unsigned int n_ports; 285 const struct rzg2l_dedicated_configs *dedicated_pins; 286 unsigned int n_port_pins; 287 unsigned int n_dedicated_pins; 288 const struct rzg2l_hwcfg *hwcfg; 289 const u64 *variable_pin_cfg; 290 unsigned int n_variable_pin_cfg; 291 unsigned int num_custom_params; 292 const struct pinconf_generic_params *custom_params; 293 #ifdef CONFIG_DEBUG_FS 294 const struct pin_config_item *custom_conf_items; 295 #endif 296 void (*pwpr_pfc_lock_unlock)(struct rzg2l_pinctrl *pctrl, bool lock); 297 void (*pmc_writeb)(struct rzg2l_pinctrl *pctrl, u8 val, u16 offset); 298 u32 (*oen_read)(struct rzg2l_pinctrl *pctrl, unsigned int _pin); 299 int (*oen_write)(struct rzg2l_pinctrl *pctrl, unsigned int _pin, u8 oen); 300 int (*hw_to_bias_param)(unsigned int val); 301 int (*bias_param_to_hw)(enum pin_config_param param); 302 }; 303 304 /** 305 * struct rzg2l_pinctrl_pin_settings - pin data 306 * @power_source: power source 307 * @drive_strength_ua: drive strength (in micro amps) 308 */ 309 struct rzg2l_pinctrl_pin_settings { 310 u16 power_source; 311 u16 drive_strength_ua; 312 }; 313 314 /** 315 * struct rzg2l_pinctrl_reg_cache - register cache structure (to be used in suspend/resume) 316 * @p: P registers cache 317 * @pm: PM registers cache 318 * @pmc: PMC registers cache 319 * @pfc: PFC registers cache 320 * @iolh: IOLH registers cache 321 * @pupd: PUPD registers cache 322 * @ien: IEN registers cache 323 * @sd_ch: SD_CH registers cache 324 * @eth_poc: ET_POC registers cache 325 * @eth_mode: ETH_MODE register cache 326 * @qspi: QSPI registers cache 327 */ 328 struct rzg2l_pinctrl_reg_cache { 329 u8 *p; 330 u16 *pm; 331 u8 *pmc; 332 u32 *pfc; 333 u32 *iolh[2]; 334 u32 *ien[2]; 335 u32 *pupd[2]; 336 u8 sd_ch[2]; 337 u8 eth_poc[2]; 338 u8 eth_mode; 339 u8 qspi; 340 }; 341 342 struct rzg2l_pinctrl { 343 struct pinctrl_dev *pctl; 344 struct pinctrl_desc desc; 345 struct pinctrl_pin_desc *pins; 346 347 const struct rzg2l_pinctrl_data *data; 348 void __iomem *base; 349 struct device *dev; 350 351 struct clk *clk; 352 353 struct gpio_chip gpio_chip; 354 struct pinctrl_gpio_range gpio_range; 355 DECLARE_BITMAP(tint_slot, RZG2L_TINT_MAX_INTERRUPT); 356 spinlock_t bitmap_lock; /* protect tint_slot bitmap */ 357 unsigned int hwirq[RZG2L_TINT_MAX_INTERRUPT]; 358 359 spinlock_t lock; /* lock read/write registers */ 360 struct mutex mutex; /* serialize adding groups and functions */ 361 362 struct rzg2l_pinctrl_pin_settings *settings; 363 struct rzg2l_pinctrl_reg_cache *cache; 364 struct rzg2l_pinctrl_reg_cache *dedicated_cache; 365 atomic_t wakeup_path; 366 }; 367 368 static const u16 available_ps[] = { 1800, 2500, 3300 }; 369 370 static u64 rzg2l_pinctrl_get_variable_pin_cfg(struct rzg2l_pinctrl *pctrl, 371 u64 pincfg, 372 unsigned int port, 373 u8 pin) 374 { 375 unsigned int i; 376 377 for (i = 0; i < pctrl->data->n_variable_pin_cfg; i++) { 378 u64 cfg = pctrl->data->variable_pin_cfg[i]; 379 380 if (FIELD_GET(VARIABLE_PIN_CFG_PORT_MASK, cfg) == port && 381 FIELD_GET(VARIABLE_PIN_CFG_PIN_MASK, cfg) == pin) 382 return (pincfg & ~RZG2L_VARIABLE_CFG) | FIELD_GET(PIN_CFG_MASK, cfg); 383 } 384 385 return 0; 386 } 387 388 static const u64 r9a09g047_variable_pin_cfg[] = { 389 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PA, 0, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 390 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PA, 1, RZV2H_MPXED_PIN_FUNCS), 391 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PA, 2, RZV2H_MPXED_PIN_FUNCS), 392 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PA, 3, RZV2H_MPXED_PIN_FUNCS), 393 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PA, 4, RZV2H_MPXED_PIN_FUNCS), 394 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PA, 5, RZV2H_MPXED_PIN_FUNCS), 395 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PA, 6, RZV2H_MPXED_PIN_FUNCS), 396 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PA, 7, RZV2H_MPXED_PIN_FUNCS), 397 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PD, 0, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 398 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PD, 1, RZV2H_MPXED_PIN_FUNCS), 399 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PD, 2, RZV2H_MPXED_PIN_FUNCS), 400 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PD, 3, RZV2H_MPXED_PIN_FUNCS), 401 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PD, 4, RZV2H_MPXED_PIN_FUNCS), 402 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PD, 5, RZV2H_MPXED_PIN_FUNCS), 403 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PD, 6, RZV2H_MPXED_PIN_FUNCS), 404 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PD, 7, RZV2H_MPXED_PIN_FUNCS), 405 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PG, 0, RZV2H_MPXED_PIN_FUNCS), 406 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PG, 1, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 407 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PG, 2, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 408 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PG, 3, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 409 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PG, 4, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 410 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PG, 5, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 411 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PG, 6, RZV2H_MPXED_PIN_FUNCS), 412 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PG, 7, RZV2H_MPXED_PIN_FUNCS), 413 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PH, 0, RZV2H_MPXED_PIN_FUNCS), 414 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PH, 1, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 415 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PH, 2, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 416 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PH, 3, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 417 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PH, 4, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 418 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PH, 5, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 419 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PJ, 0, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 420 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PJ, 1, RZV2H_MPXED_PIN_FUNCS), 421 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PJ, 2, RZV2H_MPXED_PIN_FUNCS), 422 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PJ, 3, RZV2H_MPXED_PIN_FUNCS), 423 RZG2L_VARIABLE_PIN_CFG_PACK(RZG3E_PJ, 4, RZV2H_MPXED_PIN_FUNCS), 424 }; 425 426 static const u64 r9a09g057_variable_pin_cfg[] = { 427 RZG2L_VARIABLE_PIN_CFG_PACK(RZV2H_PB, 0, RZV2H_MPXED_PIN_FUNCS), 428 RZG2L_VARIABLE_PIN_CFG_PACK(RZV2H_PB, 1, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 429 RZG2L_VARIABLE_PIN_CFG_PACK(RZV2H_PB, 2, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 430 RZG2L_VARIABLE_PIN_CFG_PACK(RZV2H_PB, 3, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 431 RZG2L_VARIABLE_PIN_CFG_PACK(RZV2H_PB, 4, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 432 RZG2L_VARIABLE_PIN_CFG_PACK(RZV2H_PB, 5, RZV2H_MPXED_PIN_FUNCS | PIN_CFG_IEN), 433 }; 434 435 #ifdef CONFIG_RISCV 436 static const u64 r9a07g043f_variable_pin_cfg[] = { 437 RZG2L_VARIABLE_PIN_CFG_PACK(20, 0, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 438 PIN_CFG_NF | 439 PIN_CFG_IEN | PIN_CFG_NOGPIO_INT), 440 RZG2L_VARIABLE_PIN_CFG_PACK(20, 1, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 441 PIN_CFG_NF | 442 PIN_CFG_IEN | PIN_CFG_NOGPIO_INT), 443 RZG2L_VARIABLE_PIN_CFG_PACK(20, 2, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 444 PIN_CFG_NF | 445 PIN_CFG_IEN | PIN_CFG_NOGPIO_INT), 446 RZG2L_VARIABLE_PIN_CFG_PACK(20, 3, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 447 PIN_CFG_IEN | PIN_CFG_NOGPIO_INT), 448 RZG2L_VARIABLE_PIN_CFG_PACK(20, 4, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 449 PIN_CFG_IEN | PIN_CFG_NOGPIO_INT), 450 RZG2L_VARIABLE_PIN_CFG_PACK(20, 5, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 451 PIN_CFG_IEN | PIN_CFG_NOGPIO_INT), 452 RZG2L_VARIABLE_PIN_CFG_PACK(20, 6, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 453 PIN_CFG_IEN | PIN_CFG_NOGPIO_INT), 454 RZG2L_VARIABLE_PIN_CFG_PACK(20, 7, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 455 PIN_CFG_IEN | PIN_CFG_NOGPIO_INT), 456 RZG2L_VARIABLE_PIN_CFG_PACK(23, 1, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 457 PIN_CFG_NOGPIO_INT), 458 RZG2L_VARIABLE_PIN_CFG_PACK(23, 2, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 459 PIN_CFG_NOGPIO_INT), 460 RZG2L_VARIABLE_PIN_CFG_PACK(23, 3, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 461 PIN_CFG_NOGPIO_INT), 462 RZG2L_VARIABLE_PIN_CFG_PACK(23, 4, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 463 PIN_CFG_NOGPIO_INT), 464 RZG2L_VARIABLE_PIN_CFG_PACK(23, 5, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_NOGPIO_INT), 465 RZG2L_VARIABLE_PIN_CFG_PACK(24, 0, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_NOGPIO_INT), 466 RZG2L_VARIABLE_PIN_CFG_PACK(24, 1, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 467 PIN_CFG_NOGPIO_INT), 468 RZG2L_VARIABLE_PIN_CFG_PACK(24, 2, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 469 PIN_CFG_NOGPIO_INT), 470 RZG2L_VARIABLE_PIN_CFG_PACK(24, 3, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 471 PIN_CFG_NOGPIO_INT), 472 RZG2L_VARIABLE_PIN_CFG_PACK(24, 4, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 473 PIN_CFG_NOGPIO_INT), 474 RZG2L_VARIABLE_PIN_CFG_PACK(24, 5, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 475 PIN_CFG_NF | 476 PIN_CFG_NOGPIO_INT), 477 }; 478 #endif 479 480 static void rzg2l_pmc_writeb(struct rzg2l_pinctrl *pctrl, u8 val, u16 offset) 481 { 482 writeb(val, pctrl->base + offset); 483 } 484 485 static void rzv2h_pmc_writeb(struct rzg2l_pinctrl *pctrl, u8 val, u16 offset) 486 { 487 const struct rzg2l_register_offsets *regs = &pctrl->data->hwcfg->regs; 488 u8 pwpr; 489 490 pwpr = readb(pctrl->base + regs->pwpr); 491 writeb(pwpr | PWPR_REGWE_A, pctrl->base + regs->pwpr); 492 writeb(val, pctrl->base + offset); 493 writeb(pwpr & ~PWPR_REGWE_A, pctrl->base + regs->pwpr); 494 } 495 496 static void rzg2l_pinctrl_set_pfc_mode(struct rzg2l_pinctrl *pctrl, 497 u8 pin, u8 off, u8 func) 498 { 499 unsigned long flags; 500 u32 reg; 501 502 spin_lock_irqsave(&pctrl->lock, flags); 503 504 /* Set pin to 'Non-use (Hi-Z input protection)' */ 505 reg = readw(pctrl->base + PM(off)); 506 reg &= ~(PM_MASK << (pin * 2)); 507 writew(reg, pctrl->base + PM(off)); 508 509 pctrl->data->pwpr_pfc_lock_unlock(pctrl, false); 510 511 /* Temporarily switch to GPIO mode with PMC register */ 512 reg = readb(pctrl->base + PMC(off)); 513 writeb(reg & ~BIT(pin), pctrl->base + PMC(off)); 514 515 /* Select Pin function mode with PFC register */ 516 reg = readl(pctrl->base + PFC(off)); 517 reg &= ~(PFC_MASK << (pin * 4)); 518 writel(reg | (func << (pin * 4)), pctrl->base + PFC(off)); 519 520 /* Switch to Peripheral pin function with PMC register */ 521 reg = readb(pctrl->base + PMC(off)); 522 writeb(reg | BIT(pin), pctrl->base + PMC(off)); 523 524 pctrl->data->pwpr_pfc_lock_unlock(pctrl, true); 525 526 spin_unlock_irqrestore(&pctrl->lock, flags); 527 }; 528 529 static int rzg2l_pinctrl_set_mux(struct pinctrl_dev *pctldev, 530 unsigned int func_selector, 531 unsigned int group_selector) 532 { 533 struct rzg2l_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 534 const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg; 535 struct function_desc *func; 536 unsigned int i, *psel_val; 537 struct group_desc *group; 538 const unsigned int *pins; 539 540 func = pinmux_generic_get_function(pctldev, func_selector); 541 if (!func) 542 return -EINVAL; 543 group = pinctrl_generic_get_group(pctldev, group_selector); 544 if (!group) 545 return -EINVAL; 546 547 psel_val = func->data; 548 pins = group->grp.pins; 549 550 for (i = 0; i < group->grp.npins; i++) { 551 u64 *pin_data = pctrl->desc.pins[pins[i]].drv_data; 552 u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data); 553 u32 pin = RZG2L_PIN_ID_TO_PIN(pins[i]); 554 555 dev_dbg(pctrl->dev, "port:%u pin: %u off:%x PSEL:%u\n", 556 RZG2L_PIN_ID_TO_PORT(pins[i]), pin, off, psel_val[i] - hwcfg->func_base); 557 558 rzg2l_pinctrl_set_pfc_mode(pctrl, pin, off, psel_val[i] - hwcfg->func_base); 559 } 560 561 return 0; 562 }; 563 564 static int rzg2l_map_add_config(struct pinctrl_map *map, 565 const char *group_or_pin, 566 enum pinctrl_map_type type, 567 unsigned long *configs, 568 unsigned int num_configs) 569 { 570 unsigned long *cfgs; 571 572 cfgs = kmemdup_array(configs, num_configs, sizeof(*cfgs), GFP_KERNEL); 573 if (!cfgs) 574 return -ENOMEM; 575 576 map->type = type; 577 map->data.configs.group_or_pin = group_or_pin; 578 map->data.configs.configs = cfgs; 579 map->data.configs.num_configs = num_configs; 580 581 return 0; 582 } 583 584 static int rzg2l_dt_subnode_to_map(struct pinctrl_dev *pctldev, 585 struct device_node *np, 586 struct device_node *parent, 587 struct pinctrl_map **map, 588 unsigned int *num_maps, 589 unsigned int *index) 590 { 591 struct rzg2l_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 592 struct pinctrl_map *maps = *map; 593 unsigned int nmaps = *num_maps; 594 unsigned long *configs = NULL; 595 unsigned int *pins, *psel_val; 596 unsigned int num_pinmux = 0; 597 unsigned int idx = *index; 598 unsigned int num_pins, i; 599 unsigned int num_configs; 600 struct property *pinmux; 601 struct property *prop; 602 int ret, gsel, fsel; 603 const char **pin_fn; 604 const char *name; 605 const char *pin; 606 607 pinmux = of_find_property(np, "pinmux", NULL); 608 if (pinmux) 609 num_pinmux = pinmux->length / sizeof(u32); 610 611 ret = of_property_count_strings(np, "pins"); 612 if (ret == -EINVAL) { 613 num_pins = 0; 614 } else if (ret < 0) { 615 dev_err(pctrl->dev, "Invalid pins list in DT\n"); 616 return ret; 617 } else { 618 num_pins = ret; 619 } 620 621 if (!num_pinmux && !num_pins) 622 return 0; 623 624 if (num_pinmux && num_pins) { 625 dev_err(pctrl->dev, 626 "DT node must contain either a pinmux or pins and not both\n"); 627 return -EINVAL; 628 } 629 630 ret = pinconf_generic_parse_dt_config(np, pctldev, &configs, &num_configs); 631 if (ret < 0) 632 return ret; 633 634 if (num_pins && !num_configs) { 635 dev_err(pctrl->dev, "DT node must contain a config\n"); 636 ret = -ENODEV; 637 goto done; 638 } 639 640 if (num_pinmux) { 641 nmaps += 1; 642 if (num_configs) 643 nmaps += 1; 644 } 645 646 if (num_pins) 647 nmaps += num_pins; 648 649 maps = krealloc_array(maps, nmaps, sizeof(*maps), GFP_KERNEL); 650 if (!maps) { 651 ret = -ENOMEM; 652 goto done; 653 } 654 655 *map = maps; 656 *num_maps = nmaps; 657 if (num_pins) { 658 of_property_for_each_string(np, "pins", prop, pin) { 659 ret = rzg2l_map_add_config(&maps[idx], pin, 660 PIN_MAP_TYPE_CONFIGS_PIN, 661 configs, num_configs); 662 if (ret < 0) 663 goto done; 664 665 idx++; 666 } 667 ret = 0; 668 goto done; 669 } 670 671 pins = devm_kcalloc(pctrl->dev, num_pinmux, sizeof(*pins), GFP_KERNEL); 672 psel_val = devm_kcalloc(pctrl->dev, num_pinmux, sizeof(*psel_val), 673 GFP_KERNEL); 674 pin_fn = devm_kzalloc(pctrl->dev, sizeof(*pin_fn), GFP_KERNEL); 675 if (!pins || !psel_val || !pin_fn) { 676 ret = -ENOMEM; 677 goto done; 678 } 679 680 /* Collect pin locations and mux settings from DT properties */ 681 for (i = 0; i < num_pinmux; ++i) { 682 u32 value; 683 684 ret = of_property_read_u32_index(np, "pinmux", i, &value); 685 if (ret) 686 goto done; 687 pins[i] = FIELD_GET(MUX_PIN_ID_MASK, value); 688 psel_val[i] = FIELD_GET(MUX_FUNC_MASK, value); 689 } 690 691 if (parent) { 692 name = devm_kasprintf(pctrl->dev, GFP_KERNEL, "%pOFn.%pOFn", 693 parent, np); 694 if (!name) { 695 ret = -ENOMEM; 696 goto done; 697 } 698 } else { 699 name = np->name; 700 } 701 702 if (num_configs) { 703 ret = rzg2l_map_add_config(&maps[idx], name, 704 PIN_MAP_TYPE_CONFIGS_GROUP, 705 configs, num_configs); 706 if (ret < 0) 707 goto done; 708 709 idx++; 710 } 711 712 mutex_lock(&pctrl->mutex); 713 714 /* Register a single pin group listing all the pins we read from DT */ 715 gsel = pinctrl_generic_add_group(pctldev, name, pins, num_pinmux, NULL); 716 if (gsel < 0) { 717 ret = gsel; 718 goto unlock; 719 } 720 721 /* 722 * Register a single group function where the 'data' is an array PSEL 723 * register values read from DT. 724 */ 725 pin_fn[0] = name; 726 fsel = pinmux_generic_add_function(pctldev, name, pin_fn, 1, psel_val); 727 if (fsel < 0) { 728 ret = fsel; 729 goto remove_group; 730 } 731 732 mutex_unlock(&pctrl->mutex); 733 734 maps[idx].type = PIN_MAP_TYPE_MUX_GROUP; 735 maps[idx].data.mux.group = name; 736 maps[idx].data.mux.function = name; 737 idx++; 738 739 dev_dbg(pctrl->dev, "Parsed %pOF with %d pins\n", np, num_pinmux); 740 ret = 0; 741 goto done; 742 743 remove_group: 744 pinctrl_generic_remove_group(pctldev, gsel); 745 unlock: 746 mutex_unlock(&pctrl->mutex); 747 done: 748 *index = idx; 749 kfree(configs); 750 return ret; 751 } 752 753 static void rzg2l_dt_free_map(struct pinctrl_dev *pctldev, 754 struct pinctrl_map *map, 755 unsigned int num_maps) 756 { 757 unsigned int i; 758 759 if (!map) 760 return; 761 762 for (i = 0; i < num_maps; ++i) { 763 if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP || 764 map[i].type == PIN_MAP_TYPE_CONFIGS_PIN) 765 kfree(map[i].data.configs.configs); 766 } 767 kfree(map); 768 } 769 770 static int rzg2l_dt_node_to_map(struct pinctrl_dev *pctldev, 771 struct device_node *np, 772 struct pinctrl_map **map, 773 unsigned int *num_maps) 774 { 775 struct rzg2l_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 776 unsigned int index; 777 int ret; 778 779 *map = NULL; 780 *num_maps = 0; 781 index = 0; 782 783 for_each_child_of_node_scoped(np, child) { 784 ret = rzg2l_dt_subnode_to_map(pctldev, child, np, map, 785 num_maps, &index); 786 if (ret < 0) 787 goto done; 788 } 789 790 if (*num_maps == 0) { 791 ret = rzg2l_dt_subnode_to_map(pctldev, np, NULL, map, 792 num_maps, &index); 793 if (ret < 0) 794 goto done; 795 } 796 797 if (*num_maps) 798 return 0; 799 800 dev_err(pctrl->dev, "no mapping found in node %pOF\n", np); 801 ret = -EINVAL; 802 803 done: 804 rzg2l_dt_free_map(pctldev, *map, *num_maps); 805 806 return ret; 807 } 808 809 static int rzg2l_validate_gpio_pin(struct rzg2l_pinctrl *pctrl, 810 u64 cfg, u32 port, u8 bit) 811 { 812 u8 pinmap = FIELD_GET(PIN_CFG_PIN_MAP_MASK, cfg); 813 u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(cfg); 814 u64 data; 815 816 if (!(pinmap & BIT(bit)) || port >= pctrl->data->n_port_pins) 817 return -EINVAL; 818 819 data = pctrl->data->port_pin_configs[port]; 820 if (off != RZG2L_PIN_CFG_TO_PORT_OFFSET(data)) 821 return -EINVAL; 822 823 return 0; 824 } 825 826 static u32 rzg2l_read_pin_config(struct rzg2l_pinctrl *pctrl, u32 offset, 827 u8 bit, u32 mask) 828 { 829 void __iomem *addr = pctrl->base + offset; 830 831 /* handle _L/_H for 32-bit register read/write */ 832 if (bit >= 4) { 833 bit -= 4; 834 addr += 4; 835 } 836 837 return (readl(addr) >> (bit * 8)) & mask; 838 } 839 840 static void rzg2l_rmw_pin_config(struct rzg2l_pinctrl *pctrl, u32 offset, 841 u8 bit, u32 mask, u32 val) 842 { 843 void __iomem *addr = pctrl->base + offset; 844 unsigned long flags; 845 u32 reg; 846 847 /* handle _L/_H for 32-bit register read/write */ 848 if (bit >= 4) { 849 bit -= 4; 850 addr += 4; 851 } 852 853 spin_lock_irqsave(&pctrl->lock, flags); 854 reg = readl(addr) & ~(mask << (bit * 8)); 855 writel(reg | (val << (bit * 8)), addr); 856 spin_unlock_irqrestore(&pctrl->lock, flags); 857 } 858 859 static int rzg2l_caps_to_pwr_reg(const struct rzg2l_register_offsets *regs, u32 caps) 860 { 861 if (caps & PIN_CFG_IO_VMC_SD0) 862 return SD_CH(regs->sd_ch, 0); 863 if (caps & PIN_CFG_IO_VMC_SD1) 864 return SD_CH(regs->sd_ch, 1); 865 if (caps & PIN_CFG_IO_VMC_ETH0) 866 return ETH_POC(regs->eth_poc, 0); 867 if (caps & PIN_CFG_IO_VMC_ETH1) 868 return ETH_POC(regs->eth_poc, 1); 869 if (caps & PIN_CFG_IO_VMC_QSPI) 870 return QSPI; 871 872 return -EINVAL; 873 } 874 875 static int rzg2l_get_power_source(struct rzg2l_pinctrl *pctrl, u32 pin, u32 caps) 876 { 877 const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg; 878 const struct rzg2l_register_offsets *regs = &hwcfg->regs; 879 int pwr_reg; 880 u8 val; 881 882 if (caps & PIN_CFG_SOFT_PS) 883 return pctrl->settings[pin].power_source; 884 885 pwr_reg = rzg2l_caps_to_pwr_reg(regs, caps); 886 if (pwr_reg < 0) 887 return pwr_reg; 888 889 val = readb(pctrl->base + pwr_reg); 890 switch (val) { 891 case PVDD_1800: 892 return 1800; 893 case PVDD_2500: 894 return 2500; 895 case PVDD_3300: 896 return 3300; 897 default: 898 /* Should not happen. */ 899 return -EINVAL; 900 } 901 } 902 903 static int rzg2l_set_power_source(struct rzg2l_pinctrl *pctrl, u32 pin, u32 caps, u32 ps) 904 { 905 const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg; 906 const struct rzg2l_register_offsets *regs = &hwcfg->regs; 907 int pwr_reg; 908 u8 val; 909 910 if (caps & PIN_CFG_SOFT_PS) { 911 pctrl->settings[pin].power_source = ps; 912 return 0; 913 } 914 915 switch (ps) { 916 case 1800: 917 val = PVDD_1800; 918 break; 919 case 2500: 920 if (!(caps & (PIN_CFG_IO_VMC_ETH0 | PIN_CFG_IO_VMC_ETH1))) 921 return -EINVAL; 922 val = PVDD_2500; 923 break; 924 case 3300: 925 val = PVDD_3300; 926 break; 927 default: 928 return -EINVAL; 929 } 930 931 pwr_reg = rzg2l_caps_to_pwr_reg(regs, caps); 932 if (pwr_reg < 0) 933 return pwr_reg; 934 935 writeb(val, pctrl->base + pwr_reg); 936 pctrl->settings[pin].power_source = ps; 937 938 return 0; 939 } 940 941 static bool rzg2l_ps_is_supported(u16 ps) 942 { 943 unsigned int i; 944 945 for (i = 0; i < ARRAY_SIZE(available_ps); i++) { 946 if (available_ps[i] == ps) 947 return true; 948 } 949 950 return false; 951 } 952 953 static enum rzg2l_iolh_index rzg2l_ps_to_iolh_idx(u16 ps) 954 { 955 unsigned int i; 956 957 for (i = 0; i < ARRAY_SIZE(available_ps); i++) { 958 if (available_ps[i] == ps) 959 break; 960 } 961 962 /* 963 * We multiply with RZG2L_IOLH_MAX_DS_ENTRIES as we have 964 * RZG2L_IOLH_MAX_DS_ENTRIES DS values per power source 965 */ 966 return i * RZG2L_IOLH_MAX_DS_ENTRIES; 967 } 968 969 static u16 rzg2l_iolh_val_to_ua(const struct rzg2l_hwcfg *hwcfg, u32 caps, u8 val) 970 { 971 if (caps & PIN_CFG_IOLH_A) 972 return hwcfg->iolh_groupa_ua[val]; 973 974 if (caps & PIN_CFG_IOLH_B) 975 return hwcfg->iolh_groupb_ua[val]; 976 977 if (caps & PIN_CFG_IOLH_C) 978 return hwcfg->iolh_groupc_ua[val]; 979 980 /* Should not happen. */ 981 return 0; 982 } 983 984 static int rzg2l_iolh_ua_to_val(const struct rzg2l_hwcfg *hwcfg, u32 caps, 985 enum rzg2l_iolh_index ps_index, u16 ua) 986 { 987 const u16 *array = NULL; 988 unsigned int i; 989 990 if (caps & PIN_CFG_IOLH_A) 991 array = &hwcfg->iolh_groupa_ua[ps_index]; 992 993 if (caps & PIN_CFG_IOLH_B) 994 array = &hwcfg->iolh_groupb_ua[ps_index]; 995 996 if (caps & PIN_CFG_IOLH_C) 997 array = &hwcfg->iolh_groupc_ua[ps_index]; 998 999 if (!array) 1000 return -EINVAL; 1001 1002 for (i = 0; i < RZG2L_IOLH_MAX_DS_ENTRIES; i++) { 1003 if (array[i] == ua) 1004 return i; 1005 } 1006 1007 return -EINVAL; 1008 } 1009 1010 static bool rzg2l_ds_is_supported(struct rzg2l_pinctrl *pctrl, u32 caps, 1011 enum rzg2l_iolh_index iolh_idx, 1012 u16 ds) 1013 { 1014 const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg; 1015 const u16 *array = NULL; 1016 unsigned int i; 1017 1018 if (caps & PIN_CFG_IOLH_A) 1019 array = hwcfg->iolh_groupa_ua; 1020 1021 if (caps & PIN_CFG_IOLH_B) 1022 array = hwcfg->iolh_groupb_ua; 1023 1024 if (caps & PIN_CFG_IOLH_C) 1025 array = hwcfg->iolh_groupc_ua; 1026 1027 /* Should not happen. */ 1028 if (!array) 1029 return false; 1030 1031 if (!array[iolh_idx]) 1032 return false; 1033 1034 for (i = 0; i < RZG2L_IOLH_MAX_DS_ENTRIES; i++) { 1035 if (array[iolh_idx + i] == ds) 1036 return true; 1037 } 1038 1039 return false; 1040 } 1041 1042 static int rzg2l_pin_to_oen_bit(struct rzg2l_pinctrl *pctrl, unsigned int _pin) 1043 { 1044 u64 *pin_data = pctrl->desc.pins[_pin].drv_data; 1045 u64 caps = FIELD_GET(PIN_CFG_MASK, *pin_data); 1046 u8 pin = RZG2L_PIN_ID_TO_PIN(_pin); 1047 1048 if (pin > pctrl->data->hwcfg->oen_max_pin) 1049 return -EINVAL; 1050 1051 /* 1052 * We can determine which Ethernet interface we're dealing with from 1053 * the caps. 1054 */ 1055 if (caps & PIN_CFG_IO_VMC_ETH0) 1056 return 0; 1057 if (caps & PIN_CFG_IO_VMC_ETH1) 1058 return 1; 1059 1060 return -EINVAL; 1061 } 1062 1063 static u32 rzg2l_read_oen(struct rzg2l_pinctrl *pctrl, unsigned int _pin) 1064 { 1065 int bit; 1066 1067 bit = rzg2l_pin_to_oen_bit(pctrl, _pin); 1068 if (bit < 0) 1069 return 0; 1070 1071 return !(readb(pctrl->base + ETH_MODE) & BIT(bit)); 1072 } 1073 1074 static int rzg2l_write_oen(struct rzg2l_pinctrl *pctrl, unsigned int _pin, u8 oen) 1075 { 1076 unsigned long flags; 1077 int bit; 1078 u8 val; 1079 1080 bit = rzg2l_pin_to_oen_bit(pctrl, _pin); 1081 if (bit < 0) 1082 return bit; 1083 1084 spin_lock_irqsave(&pctrl->lock, flags); 1085 val = readb(pctrl->base + ETH_MODE); 1086 if (oen) 1087 val &= ~BIT(bit); 1088 else 1089 val |= BIT(bit); 1090 writeb(val, pctrl->base + ETH_MODE); 1091 spin_unlock_irqrestore(&pctrl->lock, flags); 1092 1093 return 0; 1094 } 1095 1096 static int rzg3s_pin_to_oen_bit(struct rzg2l_pinctrl *pctrl, unsigned int _pin) 1097 { 1098 u64 *pin_data = pctrl->desc.pins[_pin].drv_data; 1099 u8 port, pin, bit; 1100 1101 if (*pin_data & RZG2L_SINGLE_PIN) 1102 return -EINVAL; 1103 1104 port = RZG2L_PIN_ID_TO_PORT(_pin); 1105 pin = RZG2L_PIN_ID_TO_PIN(_pin); 1106 if (pin > pctrl->data->hwcfg->oen_max_pin) 1107 return -EINVAL; 1108 1109 bit = pin * 2; 1110 if (port == pctrl->data->hwcfg->oen_max_port) 1111 bit += 1; 1112 1113 return bit; 1114 } 1115 1116 static u32 rzg3s_oen_read(struct rzg2l_pinctrl *pctrl, unsigned int _pin) 1117 { 1118 int bit; 1119 1120 bit = rzg3s_pin_to_oen_bit(pctrl, _pin); 1121 if (bit < 0) 1122 return bit; 1123 1124 return !(readb(pctrl->base + ETH_MODE) & BIT(bit)); 1125 } 1126 1127 static int rzg3s_oen_write(struct rzg2l_pinctrl *pctrl, unsigned int _pin, u8 oen) 1128 { 1129 unsigned long flags; 1130 int bit; 1131 u8 val; 1132 1133 bit = rzg3s_pin_to_oen_bit(pctrl, _pin); 1134 if (bit < 0) 1135 return bit; 1136 1137 spin_lock_irqsave(&pctrl->lock, flags); 1138 val = readb(pctrl->base + ETH_MODE); 1139 if (oen) 1140 val &= ~BIT(bit); 1141 else 1142 val |= BIT(bit); 1143 writeb(val, pctrl->base + ETH_MODE); 1144 spin_unlock_irqrestore(&pctrl->lock, flags); 1145 1146 return 0; 1147 } 1148 1149 static int rzg2l_hw_to_bias_param(unsigned int bias) 1150 { 1151 switch (bias) { 1152 case 0: 1153 return PIN_CONFIG_BIAS_DISABLE; 1154 case 1: 1155 return PIN_CONFIG_BIAS_PULL_UP; 1156 case 2: 1157 return PIN_CONFIG_BIAS_PULL_DOWN; 1158 default: 1159 break; 1160 } 1161 1162 return -EINVAL; 1163 } 1164 1165 static int rzg2l_bias_param_to_hw(enum pin_config_param param) 1166 { 1167 switch (param) { 1168 case PIN_CONFIG_BIAS_DISABLE: 1169 return 0; 1170 case PIN_CONFIG_BIAS_PULL_UP: 1171 return 1; 1172 case PIN_CONFIG_BIAS_PULL_DOWN: 1173 return 2; 1174 default: 1175 break; 1176 } 1177 1178 return -EINVAL; 1179 } 1180 1181 static int rzv2h_hw_to_bias_param(unsigned int bias) 1182 { 1183 switch (bias) { 1184 case 0: 1185 case 1: 1186 return PIN_CONFIG_BIAS_DISABLE; 1187 case 2: 1188 return PIN_CONFIG_BIAS_PULL_DOWN; 1189 case 3: 1190 return PIN_CONFIG_BIAS_PULL_UP; 1191 default: 1192 break; 1193 } 1194 1195 return -EINVAL; 1196 } 1197 1198 static int rzv2h_bias_param_to_hw(enum pin_config_param param) 1199 { 1200 switch (param) { 1201 case PIN_CONFIG_BIAS_DISABLE: 1202 return 0; 1203 case PIN_CONFIG_BIAS_PULL_DOWN: 1204 return 2; 1205 case PIN_CONFIG_BIAS_PULL_UP: 1206 return 3; 1207 default: 1208 break; 1209 } 1210 1211 return -EINVAL; 1212 } 1213 1214 static u8 rzv2h_pin_to_oen_bit(struct rzg2l_pinctrl *pctrl, unsigned int _pin) 1215 { 1216 static const char * const pin_names[] = { "ET0_TXC_TXCLK", "ET1_TXC_TXCLK", 1217 "XSPI0_RESET0N", "XSPI0_CS0N", 1218 "XSPI0_CKN", "XSPI0_CKP" }; 1219 const struct pinctrl_pin_desc *pin_desc = &pctrl->desc.pins[_pin]; 1220 unsigned int i; 1221 1222 for (i = 0; i < ARRAY_SIZE(pin_names); i++) { 1223 if (!strcmp(pin_desc->name, pin_names[i])) 1224 return i; 1225 } 1226 1227 /* Should not happen. */ 1228 return 0; 1229 } 1230 1231 static u32 rzv2h_oen_read(struct rzg2l_pinctrl *pctrl, unsigned int _pin) 1232 { 1233 u8 bit; 1234 1235 bit = rzv2h_pin_to_oen_bit(pctrl, _pin); 1236 1237 return !(readb(pctrl->base + PFC_OEN) & BIT(bit)); 1238 } 1239 1240 static int rzv2h_oen_write(struct rzg2l_pinctrl *pctrl, unsigned int _pin, u8 oen) 1241 { 1242 const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg; 1243 const struct rzg2l_register_offsets *regs = &hwcfg->regs; 1244 unsigned long flags; 1245 u8 val, bit; 1246 u8 pwpr; 1247 1248 bit = rzv2h_pin_to_oen_bit(pctrl, _pin); 1249 spin_lock_irqsave(&pctrl->lock, flags); 1250 val = readb(pctrl->base + PFC_OEN); 1251 if (oen) 1252 val &= ~BIT(bit); 1253 else 1254 val |= BIT(bit); 1255 1256 pwpr = readb(pctrl->base + regs->pwpr); 1257 writeb(pwpr | PWPR_REGWE_B, pctrl->base + regs->pwpr); 1258 writeb(val, pctrl->base + PFC_OEN); 1259 writeb(pwpr & ~PWPR_REGWE_B, pctrl->base + regs->pwpr); 1260 spin_unlock_irqrestore(&pctrl->lock, flags); 1261 1262 return 0; 1263 } 1264 1265 static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev, 1266 unsigned int _pin, 1267 unsigned long *config) 1268 { 1269 struct rzg2l_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 1270 const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg; 1271 const struct pinctrl_pin_desc *pin = &pctrl->desc.pins[_pin]; 1272 u32 param = pinconf_to_config_param(*config); 1273 u64 *pin_data = pin->drv_data; 1274 unsigned int arg = 0; 1275 u32 off; 1276 u32 cfg; 1277 int ret; 1278 u8 bit; 1279 1280 if (!pin_data) 1281 return -EINVAL; 1282 1283 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data); 1284 cfg = FIELD_GET(PIN_CFG_MASK, *pin_data); 1285 if (*pin_data & RZG2L_SINGLE_PIN) { 1286 bit = FIELD_GET(RZG2L_SINGLE_PIN_BITS_MASK, *pin_data); 1287 } else { 1288 bit = RZG2L_PIN_ID_TO_PIN(_pin); 1289 1290 if (rzg2l_validate_gpio_pin(pctrl, *pin_data, RZG2L_PIN_ID_TO_PORT(_pin), bit)) 1291 return -EINVAL; 1292 } 1293 1294 switch (param) { 1295 case PIN_CONFIG_INPUT_ENABLE: 1296 if (!(cfg & PIN_CFG_IEN)) 1297 return -EINVAL; 1298 arg = rzg2l_read_pin_config(pctrl, IEN(off), bit, IEN_MASK); 1299 if (!arg) 1300 return -EINVAL; 1301 break; 1302 1303 case PIN_CONFIG_OUTPUT_ENABLE: 1304 if (!(cfg & PIN_CFG_OEN)) 1305 return -EINVAL; 1306 if (!pctrl->data->oen_read) 1307 return -EOPNOTSUPP; 1308 arg = pctrl->data->oen_read(pctrl, _pin); 1309 if (!arg) 1310 return -EINVAL; 1311 break; 1312 1313 case PIN_CONFIG_POWER_SOURCE: 1314 ret = rzg2l_get_power_source(pctrl, _pin, cfg); 1315 if (ret < 0) 1316 return ret; 1317 arg = ret; 1318 break; 1319 1320 case PIN_CONFIG_SLEW_RATE: 1321 if (!(cfg & PIN_CFG_SR)) 1322 return -EINVAL; 1323 1324 arg = rzg2l_read_pin_config(pctrl, SR(off), bit, SR_MASK); 1325 break; 1326 1327 case PIN_CONFIG_BIAS_DISABLE: 1328 case PIN_CONFIG_BIAS_PULL_UP: 1329 case PIN_CONFIG_BIAS_PULL_DOWN: 1330 if (!(cfg & PIN_CFG_PUPD)) 1331 return -EINVAL; 1332 1333 arg = rzg2l_read_pin_config(pctrl, PUPD(off), bit, PUPD_MASK); 1334 ret = pctrl->data->hw_to_bias_param(arg); 1335 if (ret < 0) 1336 return ret; 1337 1338 if (ret != param) 1339 return -EINVAL; 1340 /* for PIN_CONFIG_BIAS_PULL_UP/DOWN when enabled we just return 1 */ 1341 arg = 1; 1342 break; 1343 1344 case PIN_CONFIG_DRIVE_STRENGTH: { 1345 unsigned int index; 1346 1347 if (!(cfg & PIN_CFG_IOLH_A) || hwcfg->drive_strength_ua) 1348 return -EINVAL; 1349 1350 index = rzg2l_read_pin_config(pctrl, IOLH(off), bit, IOLH_MASK); 1351 /* 1352 * Drive strenght mA is supported only by group A and only 1353 * for 3V3 port source. 1354 */ 1355 arg = hwcfg->iolh_groupa_ua[index + RZG2L_IOLH_IDX_3V3] / 1000; 1356 break; 1357 } 1358 1359 case PIN_CONFIG_DRIVE_STRENGTH_UA: { 1360 enum rzg2l_iolh_index iolh_idx; 1361 u8 val; 1362 1363 if (!(cfg & (PIN_CFG_IOLH_A | PIN_CFG_IOLH_B | PIN_CFG_IOLH_C)) || 1364 !hwcfg->drive_strength_ua) 1365 return -EINVAL; 1366 1367 ret = rzg2l_get_power_source(pctrl, _pin, cfg); 1368 if (ret < 0) 1369 return ret; 1370 iolh_idx = rzg2l_ps_to_iolh_idx(ret); 1371 val = rzg2l_read_pin_config(pctrl, IOLH(off), bit, IOLH_MASK); 1372 arg = rzg2l_iolh_val_to_ua(hwcfg, cfg, iolh_idx + val); 1373 break; 1374 } 1375 1376 case PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS: { 1377 unsigned int index; 1378 1379 if (!(cfg & PIN_CFG_IOLH_B) || !hwcfg->iolh_groupb_oi[0]) 1380 return -EINVAL; 1381 1382 index = rzg2l_read_pin_config(pctrl, IOLH(off), bit, IOLH_MASK); 1383 arg = hwcfg->iolh_groupb_oi[index]; 1384 break; 1385 } 1386 1387 case PIN_CONFIG_DRIVE_OPEN_DRAIN: 1388 case PIN_CONFIG_DRIVE_PUSH_PULL: 1389 if (!(cfg & PIN_CFG_NOD)) 1390 return -EINVAL; 1391 1392 arg = rzg2l_read_pin_config(pctrl, NOD(off), bit, NOD_MASK); 1393 if (!arg && param != PIN_CONFIG_DRIVE_PUSH_PULL) 1394 return -EINVAL; 1395 if (arg && param != PIN_CONFIG_DRIVE_OPEN_DRAIN) 1396 return -EINVAL; 1397 break; 1398 1399 case PIN_CONFIG_INPUT_SCHMITT_ENABLE: 1400 if (!(cfg & PIN_CFG_SMT)) 1401 return -EINVAL; 1402 1403 arg = rzg2l_read_pin_config(pctrl, SMT(off), bit, SMT_MASK); 1404 if (!arg) 1405 return -EINVAL; 1406 break; 1407 1408 case RENESAS_RZV2H_PIN_CONFIG_OUTPUT_IMPEDANCE: 1409 if (!(cfg & PIN_CFG_IOLH_RZV2H)) 1410 return -EINVAL; 1411 1412 arg = rzg2l_read_pin_config(pctrl, IOLH(off), bit, IOLH_MASK); 1413 break; 1414 1415 default: 1416 return -ENOTSUPP; 1417 } 1418 1419 *config = pinconf_to_config_packed(param, arg); 1420 1421 return 0; 1422 }; 1423 1424 static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev, 1425 unsigned int _pin, 1426 unsigned long *_configs, 1427 unsigned int num_configs) 1428 { 1429 struct rzg2l_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 1430 const struct pinctrl_pin_desc *pin = &pctrl->desc.pins[_pin]; 1431 const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg; 1432 struct rzg2l_pinctrl_pin_settings settings = pctrl->settings[_pin]; 1433 u64 *pin_data = pin->drv_data; 1434 unsigned int i, arg, index; 1435 u32 off, param; 1436 u32 cfg; 1437 int ret; 1438 u8 bit; 1439 1440 if (!pin_data) 1441 return -EINVAL; 1442 1443 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data); 1444 cfg = FIELD_GET(PIN_CFG_MASK, *pin_data); 1445 if (*pin_data & RZG2L_SINGLE_PIN) { 1446 bit = FIELD_GET(RZG2L_SINGLE_PIN_BITS_MASK, *pin_data); 1447 } else { 1448 bit = RZG2L_PIN_ID_TO_PIN(_pin); 1449 1450 if (rzg2l_validate_gpio_pin(pctrl, *pin_data, RZG2L_PIN_ID_TO_PORT(_pin), bit)) 1451 return -EINVAL; 1452 } 1453 1454 for (i = 0; i < num_configs; i++) { 1455 param = pinconf_to_config_param(_configs[i]); 1456 arg = pinconf_to_config_argument(_configs[i]); 1457 switch (param) { 1458 case PIN_CONFIG_INPUT_ENABLE: 1459 1460 if (!(cfg & PIN_CFG_IEN)) 1461 return -EINVAL; 1462 1463 rzg2l_rmw_pin_config(pctrl, IEN(off), bit, IEN_MASK, !!arg); 1464 break; 1465 1466 case PIN_CONFIG_OUTPUT_ENABLE: 1467 if (!(cfg & PIN_CFG_OEN)) 1468 return -EINVAL; 1469 if (!pctrl->data->oen_write) 1470 return -EOPNOTSUPP; 1471 ret = pctrl->data->oen_write(pctrl, _pin, !!arg); 1472 if (ret) 1473 return ret; 1474 break; 1475 1476 case PIN_CONFIG_POWER_SOURCE: 1477 settings.power_source = arg; 1478 break; 1479 1480 case PIN_CONFIG_SLEW_RATE: 1481 if (!(cfg & PIN_CFG_SR) || arg > 1) 1482 return -EINVAL; 1483 1484 rzg2l_rmw_pin_config(pctrl, SR(off), bit, SR_MASK, arg); 1485 break; 1486 1487 case PIN_CONFIG_BIAS_DISABLE: 1488 case PIN_CONFIG_BIAS_PULL_UP: 1489 case PIN_CONFIG_BIAS_PULL_DOWN: 1490 if (!(cfg & PIN_CFG_PUPD)) 1491 return -EINVAL; 1492 1493 ret = pctrl->data->bias_param_to_hw(param); 1494 if (ret < 0) 1495 return ret; 1496 1497 rzg2l_rmw_pin_config(pctrl, PUPD(off), bit, PUPD_MASK, ret); 1498 break; 1499 1500 case PIN_CONFIG_DRIVE_STRENGTH: 1501 if (!(cfg & PIN_CFG_IOLH_A) || hwcfg->drive_strength_ua) 1502 return -EINVAL; 1503 1504 for (index = RZG2L_IOLH_IDX_3V3; 1505 index < RZG2L_IOLH_IDX_3V3 + RZG2L_IOLH_MAX_DS_ENTRIES; index++) { 1506 if (arg == (hwcfg->iolh_groupa_ua[index] / 1000)) 1507 break; 1508 } 1509 if (index == (RZG2L_IOLH_IDX_3V3 + RZG2L_IOLH_MAX_DS_ENTRIES)) 1510 return -EINVAL; 1511 1512 rzg2l_rmw_pin_config(pctrl, IOLH(off), bit, IOLH_MASK, index); 1513 break; 1514 1515 case PIN_CONFIG_DRIVE_STRENGTH_UA: 1516 if (!(cfg & (PIN_CFG_IOLH_A | PIN_CFG_IOLH_B | PIN_CFG_IOLH_C)) || 1517 !hwcfg->drive_strength_ua) 1518 return -EINVAL; 1519 1520 settings.drive_strength_ua = arg; 1521 break; 1522 1523 case PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS: 1524 if (!(cfg & PIN_CFG_IOLH_B) || !hwcfg->iolh_groupb_oi[0]) 1525 return -EINVAL; 1526 1527 for (index = 0; index < ARRAY_SIZE(hwcfg->iolh_groupb_oi); index++) { 1528 if (arg == hwcfg->iolh_groupb_oi[index]) 1529 break; 1530 } 1531 if (index == ARRAY_SIZE(hwcfg->iolh_groupb_oi)) 1532 return -EINVAL; 1533 1534 rzg2l_rmw_pin_config(pctrl, IOLH(off), bit, IOLH_MASK, index); 1535 break; 1536 1537 case PIN_CONFIG_DRIVE_OPEN_DRAIN: 1538 case PIN_CONFIG_DRIVE_PUSH_PULL: 1539 if (!(cfg & PIN_CFG_NOD)) 1540 return -EINVAL; 1541 1542 rzg2l_rmw_pin_config(pctrl, NOD(off), bit, NOD_MASK, 1543 param == PIN_CONFIG_DRIVE_OPEN_DRAIN ? 1 : 0); 1544 break; 1545 1546 case PIN_CONFIG_INPUT_SCHMITT_ENABLE: 1547 if (!(cfg & PIN_CFG_SMT)) 1548 return -EINVAL; 1549 1550 rzg2l_rmw_pin_config(pctrl, SMT(off), bit, SMT_MASK, arg); 1551 break; 1552 1553 case RENESAS_RZV2H_PIN_CONFIG_OUTPUT_IMPEDANCE: 1554 if (!(cfg & PIN_CFG_IOLH_RZV2H)) 1555 return -EINVAL; 1556 1557 if (arg > 3) 1558 return -EINVAL; 1559 rzg2l_rmw_pin_config(pctrl, IOLH(off), bit, IOLH_MASK, arg); 1560 break; 1561 1562 default: 1563 return -EOPNOTSUPP; 1564 } 1565 } 1566 1567 /* Apply power source. */ 1568 if (settings.power_source != pctrl->settings[_pin].power_source) { 1569 ret = rzg2l_ps_is_supported(settings.power_source); 1570 if (!ret) 1571 return -EINVAL; 1572 1573 /* Apply power source. */ 1574 ret = rzg2l_set_power_source(pctrl, _pin, cfg, settings.power_source); 1575 if (ret) 1576 return ret; 1577 } 1578 1579 /* Apply drive strength. */ 1580 if (settings.drive_strength_ua != pctrl->settings[_pin].drive_strength_ua) { 1581 enum rzg2l_iolh_index iolh_idx; 1582 int val; 1583 1584 iolh_idx = rzg2l_ps_to_iolh_idx(settings.power_source); 1585 ret = rzg2l_ds_is_supported(pctrl, cfg, iolh_idx, 1586 settings.drive_strength_ua); 1587 if (!ret) 1588 return -EINVAL; 1589 1590 /* Get register value for this PS/DS tuple. */ 1591 val = rzg2l_iolh_ua_to_val(hwcfg, cfg, iolh_idx, settings.drive_strength_ua); 1592 if (val < 0) 1593 return val; 1594 1595 /* Apply drive strength. */ 1596 rzg2l_rmw_pin_config(pctrl, IOLH(off), bit, IOLH_MASK, val); 1597 pctrl->settings[_pin].drive_strength_ua = settings.drive_strength_ua; 1598 } 1599 1600 return 0; 1601 } 1602 1603 static int rzg2l_pinctrl_pinconf_group_set(struct pinctrl_dev *pctldev, 1604 unsigned int group, 1605 unsigned long *configs, 1606 unsigned int num_configs) 1607 { 1608 const unsigned int *pins; 1609 unsigned int i, npins; 1610 int ret; 1611 1612 ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins); 1613 if (ret) 1614 return ret; 1615 1616 for (i = 0; i < npins; i++) { 1617 ret = rzg2l_pinctrl_pinconf_set(pctldev, pins[i], configs, 1618 num_configs); 1619 if (ret) 1620 return ret; 1621 } 1622 1623 return 0; 1624 }; 1625 1626 static int rzg2l_pinctrl_pinconf_group_get(struct pinctrl_dev *pctldev, 1627 unsigned int group, 1628 unsigned long *config) 1629 { 1630 const unsigned int *pins; 1631 unsigned int i, npins, prev_config = 0; 1632 int ret; 1633 1634 ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins); 1635 if (ret) 1636 return ret; 1637 1638 for (i = 0; i < npins; i++) { 1639 ret = rzg2l_pinctrl_pinconf_get(pctldev, pins[i], config); 1640 if (ret) 1641 return ret; 1642 1643 /* Check config matching between to pin */ 1644 if (i && prev_config != *config) 1645 return -EOPNOTSUPP; 1646 1647 prev_config = *config; 1648 } 1649 1650 return 0; 1651 }; 1652 1653 static const struct pinctrl_ops rzg2l_pinctrl_pctlops = { 1654 .get_groups_count = pinctrl_generic_get_group_count, 1655 .get_group_name = pinctrl_generic_get_group_name, 1656 .get_group_pins = pinctrl_generic_get_group_pins, 1657 .dt_node_to_map = rzg2l_dt_node_to_map, 1658 .dt_free_map = rzg2l_dt_free_map, 1659 }; 1660 1661 static const struct pinmux_ops rzg2l_pinctrl_pmxops = { 1662 .get_functions_count = pinmux_generic_get_function_count, 1663 .get_function_name = pinmux_generic_get_function_name, 1664 .get_function_groups = pinmux_generic_get_function_groups, 1665 .set_mux = rzg2l_pinctrl_set_mux, 1666 .strict = true, 1667 }; 1668 1669 static const struct pinconf_ops rzg2l_pinctrl_confops = { 1670 .is_generic = true, 1671 .pin_config_get = rzg2l_pinctrl_pinconf_get, 1672 .pin_config_set = rzg2l_pinctrl_pinconf_set, 1673 .pin_config_group_set = rzg2l_pinctrl_pinconf_group_set, 1674 .pin_config_group_get = rzg2l_pinctrl_pinconf_group_get, 1675 .pin_config_config_dbg_show = pinconf_generic_dump_config, 1676 }; 1677 1678 static int rzg2l_gpio_request(struct gpio_chip *chip, unsigned int offset) 1679 { 1680 struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 1681 const struct pinctrl_pin_desc *pin_desc = &pctrl->desc.pins[offset]; 1682 u64 *pin_data = pin_desc->drv_data; 1683 u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data); 1684 u32 port = RZG2L_PIN_ID_TO_PORT(offset); 1685 u8 bit = RZG2L_PIN_ID_TO_PIN(offset); 1686 unsigned long flags; 1687 u8 reg8; 1688 int ret; 1689 1690 ret = rzg2l_validate_gpio_pin(pctrl, *pin_data, port, bit); 1691 if (ret) 1692 return ret; 1693 1694 ret = pinctrl_gpio_request(chip, offset); 1695 if (ret) 1696 return ret; 1697 1698 spin_lock_irqsave(&pctrl->lock, flags); 1699 1700 /* Select GPIO mode in PMC Register */ 1701 reg8 = readb(pctrl->base + PMC(off)); 1702 reg8 &= ~BIT(bit); 1703 pctrl->data->pmc_writeb(pctrl, reg8, PMC(off)); 1704 1705 spin_unlock_irqrestore(&pctrl->lock, flags); 1706 1707 return 0; 1708 } 1709 1710 static void rzg2l_gpio_set_direction(struct rzg2l_pinctrl *pctrl, u32 offset, 1711 bool output) 1712 { 1713 const struct pinctrl_pin_desc *pin_desc = &pctrl->desc.pins[offset]; 1714 u64 *pin_data = pin_desc->drv_data; 1715 u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data); 1716 u8 bit = RZG2L_PIN_ID_TO_PIN(offset); 1717 unsigned long flags; 1718 u16 reg16; 1719 1720 spin_lock_irqsave(&pctrl->lock, flags); 1721 1722 reg16 = readw(pctrl->base + PM(off)); 1723 reg16 &= ~(PM_MASK << (bit * 2)); 1724 1725 reg16 |= (output ? PM_OUTPUT : PM_INPUT) << (bit * 2); 1726 writew(reg16, pctrl->base + PM(off)); 1727 1728 spin_unlock_irqrestore(&pctrl->lock, flags); 1729 } 1730 1731 static int rzg2l_gpio_get_direction(struct gpio_chip *chip, unsigned int offset) 1732 { 1733 struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 1734 const struct pinctrl_pin_desc *pin_desc = &pctrl->desc.pins[offset]; 1735 u64 *pin_data = pin_desc->drv_data; 1736 u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data); 1737 u8 bit = RZG2L_PIN_ID_TO_PIN(offset); 1738 1739 if (!(readb(pctrl->base + PMC(off)) & BIT(bit))) { 1740 u16 reg16; 1741 1742 reg16 = readw(pctrl->base + PM(off)); 1743 reg16 = (reg16 >> (bit * 2)) & PM_MASK; 1744 if (reg16 == PM_OUTPUT) 1745 return GPIO_LINE_DIRECTION_OUT; 1746 } 1747 1748 return GPIO_LINE_DIRECTION_IN; 1749 } 1750 1751 static int rzg2l_gpio_direction_input(struct gpio_chip *chip, 1752 unsigned int offset) 1753 { 1754 struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 1755 1756 rzg2l_gpio_set_direction(pctrl, offset, false); 1757 1758 return 0; 1759 } 1760 1761 static void rzg2l_gpio_set(struct gpio_chip *chip, unsigned int offset, 1762 int value) 1763 { 1764 struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 1765 const struct pinctrl_pin_desc *pin_desc = &pctrl->desc.pins[offset]; 1766 u64 *pin_data = pin_desc->drv_data; 1767 u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data); 1768 u8 bit = RZG2L_PIN_ID_TO_PIN(offset); 1769 unsigned long flags; 1770 u8 reg8; 1771 1772 spin_lock_irqsave(&pctrl->lock, flags); 1773 1774 reg8 = readb(pctrl->base + P(off)); 1775 1776 if (value) 1777 writeb(reg8 | BIT(bit), pctrl->base + P(off)); 1778 else 1779 writeb(reg8 & ~BIT(bit), pctrl->base + P(off)); 1780 1781 spin_unlock_irqrestore(&pctrl->lock, flags); 1782 } 1783 1784 static int rzg2l_gpio_direction_output(struct gpio_chip *chip, 1785 unsigned int offset, int value) 1786 { 1787 struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 1788 1789 rzg2l_gpio_set(chip, offset, value); 1790 rzg2l_gpio_set_direction(pctrl, offset, true); 1791 1792 return 0; 1793 } 1794 1795 static int rzg2l_gpio_get(struct gpio_chip *chip, unsigned int offset) 1796 { 1797 struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 1798 const struct pinctrl_pin_desc *pin_desc = &pctrl->desc.pins[offset]; 1799 u64 *pin_data = pin_desc->drv_data; 1800 u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data); 1801 u8 bit = RZG2L_PIN_ID_TO_PIN(offset); 1802 u16 reg16; 1803 1804 reg16 = readw(pctrl->base + PM(off)); 1805 reg16 = (reg16 >> (bit * 2)) & PM_MASK; 1806 1807 if (reg16 == PM_INPUT) 1808 return !!(readb(pctrl->base + PIN(off)) & BIT(bit)); 1809 else if (reg16 == PM_OUTPUT) 1810 return !!(readb(pctrl->base + P(off)) & BIT(bit)); 1811 else 1812 return -EINVAL; 1813 } 1814 1815 static void rzg2l_gpio_free(struct gpio_chip *chip, unsigned int offset) 1816 { 1817 unsigned int virq; 1818 1819 pinctrl_gpio_free(chip, offset); 1820 1821 virq = irq_find_mapping(chip->irq.domain, offset); 1822 if (virq) 1823 irq_dispose_mapping(virq); 1824 1825 /* 1826 * Set the GPIO as an input to ensure that the next GPIO request won't 1827 * drive the GPIO pin as an output. 1828 */ 1829 rzg2l_gpio_direction_input(chip, offset); 1830 } 1831 1832 static const char * const rzg2l_gpio_names[] = { 1833 "P0_0", "P0_1", "P0_2", "P0_3", "P0_4", "P0_5", "P0_6", "P0_7", 1834 "P1_0", "P1_1", "P1_2", "P1_3", "P1_4", "P1_5", "P1_6", "P1_7", 1835 "P2_0", "P2_1", "P2_2", "P2_3", "P2_4", "P2_5", "P2_6", "P2_7", 1836 "P3_0", "P3_1", "P3_2", "P3_3", "P3_4", "P3_5", "P3_6", "P3_7", 1837 "P4_0", "P4_1", "P4_2", "P4_3", "P4_4", "P4_5", "P4_6", "P4_7", 1838 "P5_0", "P5_1", "P5_2", "P5_3", "P5_4", "P5_5", "P5_6", "P5_7", 1839 "P6_0", "P6_1", "P6_2", "P6_3", "P6_4", "P6_5", "P6_6", "P6_7", 1840 "P7_0", "P7_1", "P7_2", "P7_3", "P7_4", "P7_5", "P7_6", "P7_7", 1841 "P8_0", "P8_1", "P8_2", "P8_3", "P8_4", "P8_5", "P8_6", "P8_7", 1842 "P9_0", "P9_1", "P9_2", "P9_3", "P9_4", "P9_5", "P9_6", "P9_7", 1843 "P10_0", "P10_1", "P10_2", "P10_3", "P10_4", "P10_5", "P10_6", "P10_7", 1844 "P11_0", "P11_1", "P11_2", "P11_3", "P11_4", "P11_5", "P11_6", "P11_7", 1845 "P12_0", "P12_1", "P12_2", "P12_3", "P12_4", "P12_5", "P12_6", "P12_7", 1846 "P13_0", "P13_1", "P13_2", "P13_3", "P13_4", "P13_5", "P13_6", "P13_7", 1847 "P14_0", "P14_1", "P14_2", "P14_3", "P14_4", "P14_5", "P14_6", "P14_7", 1848 "P15_0", "P15_1", "P15_2", "P15_3", "P15_4", "P15_5", "P15_6", "P15_7", 1849 "P16_0", "P16_1", "P16_2", "P16_3", "P16_4", "P16_5", "P16_6", "P16_7", 1850 "P17_0", "P17_1", "P17_2", "P17_3", "P17_4", "P17_5", "P17_6", "P17_7", 1851 "P18_0", "P18_1", "P18_2", "P18_3", "P18_4", "P18_5", "P18_6", "P18_7", 1852 "P19_0", "P19_1", "P19_2", "P19_3", "P19_4", "P19_5", "P19_6", "P19_7", 1853 "P20_0", "P20_1", "P20_2", "P20_3", "P20_4", "P20_5", "P20_6", "P20_7", 1854 "P21_0", "P21_1", "P21_2", "P21_3", "P21_4", "P21_5", "P21_6", "P21_7", 1855 "P22_0", "P22_1", "P22_2", "P22_3", "P22_4", "P22_5", "P22_6", "P22_7", 1856 "P23_0", "P23_1", "P23_2", "P23_3", "P23_4", "P23_5", "P23_6", "P23_7", 1857 "P24_0", "P24_1", "P24_2", "P24_3", "P24_4", "P24_5", "P24_6", "P24_7", 1858 "P25_0", "P25_1", "P25_2", "P25_3", "P25_4", "P25_5", "P25_6", "P25_7", 1859 "P26_0", "P26_1", "P26_2", "P26_3", "P26_4", "P26_5", "P26_6", "P26_7", 1860 "P27_0", "P27_1", "P27_2", "P27_3", "P27_4", "P27_5", "P27_6", "P27_7", 1861 "P28_0", "P28_1", "P28_2", "P28_3", "P28_4", "P28_5", "P28_6", "P28_7", 1862 "P29_0", "P29_1", "P29_2", "P29_3", "P29_4", "P29_5", "P29_6", "P29_7", 1863 "P30_0", "P30_1", "P30_2", "P30_3", "P30_4", "P30_5", "P30_6", "P30_7", 1864 "P31_0", "P31_1", "P31_2", "P31_3", "P31_4", "P31_5", "P31_6", "P31_7", 1865 "P32_0", "P32_1", "P32_2", "P32_3", "P32_4", "P32_5", "P32_6", "P32_7", 1866 "P33_0", "P33_1", "P33_2", "P33_3", "P33_4", "P33_5", "P33_6", "P33_7", 1867 "P34_0", "P34_1", "P34_2", "P34_3", "P34_4", "P34_5", "P34_6", "P34_7", 1868 "P35_0", "P35_1", "P35_2", "P35_3", "P35_4", "P35_5", "P35_6", "P35_7", 1869 "P36_0", "P36_1", "P36_2", "P36_3", "P36_4", "P36_5", "P36_6", "P36_7", 1870 "P37_0", "P37_1", "P37_2", "P37_3", "P37_4", "P37_5", "P37_6", "P37_7", 1871 "P38_0", "P38_1", "P38_2", "P38_3", "P38_4", "P38_5", "P38_6", "P38_7", 1872 "P39_0", "P39_1", "P39_2", "P39_3", "P39_4", "P39_5", "P39_6", "P39_7", 1873 "P40_0", "P40_1", "P40_2", "P40_3", "P40_4", "P40_5", "P40_6", "P40_7", 1874 "P41_0", "P41_1", "P41_2", "P41_3", "P41_4", "P41_5", "P41_6", "P41_7", 1875 "P42_0", "P42_1", "P42_2", "P42_3", "P42_4", "P42_5", "P42_6", "P42_7", 1876 "P43_0", "P43_1", "P43_2", "P43_3", "P43_4", "P43_5", "P43_6", "P43_7", 1877 "P44_0", "P44_1", "P44_2", "P44_3", "P44_4", "P44_5", "P44_6", "P44_7", 1878 "P45_0", "P45_1", "P45_2", "P45_3", "P45_4", "P45_5", "P45_6", "P45_7", 1879 "P46_0", "P46_1", "P46_2", "P46_3", "P46_4", "P46_5", "P46_6", "P46_7", 1880 "P47_0", "P47_1", "P47_2", "P47_3", "P47_4", "P47_5", "P47_6", "P47_7", 1881 "P48_0", "P48_1", "P48_2", "P48_3", "P48_4", "P48_5", "P48_6", "P48_7", 1882 }; 1883 1884 static const u64 r9a07g044_gpio_configs[] = { 1885 RZG2L_GPIO_PORT_PACK(2, 0x10, RZG2L_MPXED_PIN_FUNCS), 1886 RZG2L_GPIO_PORT_PACK(2, 0x11, RZG2L_MPXED_PIN_FUNCS), 1887 RZG2L_GPIO_PORT_PACK(2, 0x12, RZG2L_MPXED_PIN_FUNCS), 1888 RZG2L_GPIO_PORT_PACK(2, 0x13, RZG2L_MPXED_PIN_FUNCS), 1889 RZG2L_GPIO_PORT_PACK(2, 0x14, RZG2L_MPXED_PIN_FUNCS), 1890 RZG2L_GPIO_PORT_PACK(3, 0x15, RZG2L_MPXED_PIN_FUNCS), 1891 RZG2L_GPIO_PORT_PACK(2, 0x16, RZG2L_MPXED_PIN_FUNCS), 1892 RZG2L_GPIO_PORT_PACK(3, 0x17, RZG2L_MPXED_PIN_FUNCS), 1893 RZG2L_GPIO_PORT_PACK(3, 0x18, RZG2L_MPXED_PIN_FUNCS), 1894 RZG2L_GPIO_PORT_PACK(2, 0x19, RZG2L_MPXED_PIN_FUNCS), 1895 RZG2L_GPIO_PORT_PACK(2, 0x1a, RZG2L_MPXED_PIN_FUNCS), 1896 RZG2L_GPIO_PORT_PACK(2, 0x1b, RZG2L_MPXED_PIN_FUNCS), 1897 RZG2L_GPIO_PORT_PACK(2, 0x1c, RZG2L_MPXED_PIN_FUNCS), 1898 RZG2L_GPIO_PORT_PACK(3, 0x1d, RZG2L_MPXED_PIN_FUNCS), 1899 RZG2L_GPIO_PORT_PACK(2, 0x1e, RZG2L_MPXED_PIN_FUNCS), 1900 RZG2L_GPIO_PORT_PACK(2, 0x1f, RZG2L_MPXED_PIN_FUNCS), 1901 RZG2L_GPIO_PORT_PACK(2, 0x20, RZG2L_MPXED_PIN_FUNCS), 1902 RZG2L_GPIO_PORT_PACK(3, 0x21, RZG2L_MPXED_PIN_FUNCS), 1903 RZG2L_GPIO_PORT_PACK(2, 0x22, RZG2L_MPXED_PIN_FUNCS), 1904 RZG2L_GPIO_PORT_PACK(2, 0x23, RZG2L_MPXED_PIN_FUNCS), 1905 RZG2L_GPIO_PORT_PACK(3, 0x24, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0) | PIN_CFG_OEN), 1906 RZG2L_GPIO_PORT_PACK(2, 0x25, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 1907 RZG2L_GPIO_PORT_PACK(2, 0x26, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 1908 RZG2L_GPIO_PORT_PACK(2, 0x27, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 1909 RZG2L_GPIO_PORT_PACK(2, 0x28, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 1910 RZG2L_GPIO_PORT_PACK(2, 0x29, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 1911 RZG2L_GPIO_PORT_PACK(2, 0x2a, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 1912 RZG2L_GPIO_PORT_PACK(2, 0x2b, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 1913 RZG2L_GPIO_PORT_PACK(2, 0x2c, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 1914 RZG2L_GPIO_PORT_PACK(2, 0x2d, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1) | PIN_CFG_OEN), 1915 RZG2L_GPIO_PORT_PACK(2, 0x2e, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 1916 RZG2L_GPIO_PORT_PACK(2, 0x2f, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 1917 RZG2L_GPIO_PORT_PACK(2, 0x30, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 1918 RZG2L_GPIO_PORT_PACK(2, 0x31, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 1919 RZG2L_GPIO_PORT_PACK(2, 0x32, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 1920 RZG2L_GPIO_PORT_PACK(2, 0x33, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 1921 RZG2L_GPIO_PORT_PACK(2, 0x34, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 1922 RZG2L_GPIO_PORT_PACK(3, 0x35, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 1923 RZG2L_GPIO_PORT_PACK(2, 0x36, RZG2L_MPXED_PIN_FUNCS), 1924 RZG2L_GPIO_PORT_PACK(3, 0x37, RZG2L_MPXED_PIN_FUNCS), 1925 RZG2L_GPIO_PORT_PACK(3, 0x38, RZG2L_MPXED_PIN_FUNCS), 1926 RZG2L_GPIO_PORT_PACK(2, 0x39, RZG2L_MPXED_PIN_FUNCS), 1927 RZG2L_GPIO_PORT_PACK(5, 0x3a, RZG2L_MPXED_PIN_FUNCS), 1928 RZG2L_GPIO_PORT_PACK(4, 0x3b, RZG2L_MPXED_PIN_FUNCS), 1929 RZG2L_GPIO_PORT_PACK(4, 0x3c, RZG2L_MPXED_PIN_FUNCS), 1930 RZG2L_GPIO_PORT_PACK(4, 0x3d, RZG2L_MPXED_PIN_FUNCS), 1931 RZG2L_GPIO_PORT_PACK(4, 0x3e, RZG2L_MPXED_PIN_FUNCS), 1932 RZG2L_GPIO_PORT_PACK(4, 0x3f, RZG2L_MPXED_PIN_FUNCS), 1933 RZG2L_GPIO_PORT_PACK(5, 0x40, RZG2L_MPXED_PIN_FUNCS), 1934 }; 1935 1936 static const u64 r9a07g043_gpio_configs[] = { 1937 RZG2L_GPIO_PORT_PACK(4, 0x10, RZG2L_MPXED_PIN_FUNCS), 1938 RZG2L_GPIO_PORT_PACK(5, 0x11, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0) | PIN_CFG_OEN), 1939 RZG2L_GPIO_PORT_PACK(4, 0x12, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 1940 RZG2L_GPIO_PORT_PACK(4, 0x13, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 1941 RZG2L_GPIO_PORT_PACK(6, 0x14, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 1942 RZG2L_GPIO_PORT_PACK(5, 0x15, RZG2L_MPXED_PIN_FUNCS), 1943 RZG2L_GPIO_PORT_PACK(5, 0x16, RZG2L_MPXED_PIN_FUNCS), 1944 RZG2L_GPIO_PORT_PACK(5, 0x17, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1) | PIN_CFG_OEN), 1945 RZG2L_GPIO_PORT_PACK(5, 0x18, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 1946 RZG2L_GPIO_PORT_PACK(4, 0x19, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 1947 RZG2L_GPIO_PORT_PACK(5, 0x1a, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 1948 RZG2L_GPIO_PORT_PACK(4, 0x1b, RZG2L_MPXED_PIN_FUNCS), 1949 RZG2L_GPIO_PORT_PACK(2, 0x1c, RZG2L_MPXED_PIN_FUNCS), 1950 RZG2L_GPIO_PORT_PACK(5, 0x1d, RZG2L_MPXED_PIN_FUNCS), 1951 RZG2L_GPIO_PORT_PACK(3, 0x1e, RZG2L_MPXED_PIN_FUNCS), 1952 RZG2L_GPIO_PORT_PACK(4, 0x1f, RZG2L_MPXED_PIN_FUNCS), 1953 RZG2L_GPIO_PORT_PACK(2, 0x20, RZG2L_MPXED_PIN_FUNCS), 1954 RZG2L_GPIO_PORT_PACK(4, 0x21, RZG2L_MPXED_PIN_FUNCS), 1955 RZG2L_GPIO_PORT_PACK(6, 0x22, RZG2L_MPXED_PIN_FUNCS), 1956 #ifdef CONFIG_RISCV 1957 /* Below additional port pins (P19 - P28) are exclusively available on RZ/Five SoC only */ 1958 RZG2L_GPIO_PORT_SPARSE_PACK(0x2, 0x06, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 1959 PIN_CFG_NF | PIN_CFG_IEN | PIN_CFG_NOGPIO_INT), /* P19 */ 1960 RZG2L_GPIO_PORT_PACK_VARIABLE(8, 0x07), /* P20 */ 1961 RZG2L_GPIO_PORT_SPARSE_PACK(0x2, 0x08, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 1962 PIN_CFG_IEN | PIN_CFG_NOGPIO_INT), /* P21 */ 1963 RZG2L_GPIO_PORT_PACK(4, 0x09, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_PUPD | 1964 PIN_CFG_IEN | PIN_CFG_NOGPIO_INT), /* P22 */ 1965 RZG2L_GPIO_PORT_SPARSE_PACK_VARIABLE(0x3e, 0x0a), /* P23 */ 1966 RZG2L_GPIO_PORT_PACK_VARIABLE(6, 0x0b), /* P24 */ 1967 RZG2L_GPIO_PORT_SPARSE_PACK(0x2, 0x0c, PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_NF | 1968 PIN_CFG_NOGPIO_INT), /* P25 */ 1969 0x0, /* P26 */ 1970 0x0, /* P27 */ 1971 RZG2L_GPIO_PORT_PACK(6, 0x0f, RZG2L_MPXED_PIN_FUNCS | PIN_CFG_NOGPIO_INT), /* P28 */ 1972 #endif 1973 }; 1974 1975 static const u64 r9a08g045_gpio_configs[] = { 1976 RZG2L_GPIO_PORT_PACK(4, 0x20, RZG3S_MPXED_PIN_FUNCS(A)), /* P0 */ 1977 RZG2L_GPIO_PORT_PACK(5, 0x30, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | 1978 PIN_CFG_IO_VMC_ETH0)) | 1979 PIN_CFG_OEN | PIN_CFG_IEN, /* P1 */ 1980 RZG2L_GPIO_PORT_PACK(4, 0x31, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | 1981 PIN_CFG_IO_VMC_ETH0)), /* P2 */ 1982 RZG2L_GPIO_PORT_PACK(4, 0x32, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | 1983 PIN_CFG_IO_VMC_ETH0)), /* P3 */ 1984 RZG2L_GPIO_PORT_PACK(6, 0x33, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | 1985 PIN_CFG_IO_VMC_ETH0)), /* P4 */ 1986 RZG2L_GPIO_PORT_PACK(5, 0x21, RZG3S_MPXED_PIN_FUNCS(A)), /* P5 */ 1987 RZG2L_GPIO_PORT_PACK(5, 0x22, RZG3S_MPXED_PIN_FUNCS(A)), /* P6 */ 1988 RZG2L_GPIO_PORT_PACK(5, 0x34, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | 1989 PIN_CFG_IO_VMC_ETH1)) | 1990 PIN_CFG_OEN | PIN_CFG_IEN, /* P7 */ 1991 RZG2L_GPIO_PORT_PACK(5, 0x35, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | 1992 PIN_CFG_IO_VMC_ETH1)), /* P8 */ 1993 RZG2L_GPIO_PORT_PACK(4, 0x36, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | 1994 PIN_CFG_IO_VMC_ETH1)), /* P9 */ 1995 RZG2L_GPIO_PORT_PACK(5, 0x37, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IOLH_C | 1996 PIN_CFG_IO_VMC_ETH1)), /* P10 */ 1997 RZG2L_GPIO_PORT_PACK(4, 0x23, RZG3S_MPXED_PIN_FUNCS(B) | PIN_CFG_IEN), /* P11 */ 1998 RZG2L_GPIO_PORT_PACK(2, 0x24, RZG3S_MPXED_PIN_FUNCS(B) | PIN_CFG_IEN), /* P12 */ 1999 RZG2L_GPIO_PORT_PACK(5, 0x25, RZG3S_MPXED_PIN_FUNCS(A)), /* P13 */ 2000 RZG2L_GPIO_PORT_PACK(3, 0x26, RZG3S_MPXED_PIN_FUNCS(A)), /* P14 */ 2001 RZG2L_GPIO_PORT_PACK(4, 0x27, RZG3S_MPXED_PIN_FUNCS(A)), /* P15 */ 2002 RZG2L_GPIO_PORT_PACK(2, 0x28, RZG3S_MPXED_PIN_FUNCS(A)), /* P16 */ 2003 RZG2L_GPIO_PORT_PACK(4, 0x29, RZG3S_MPXED_PIN_FUNCS(A)), /* P17 */ 2004 RZG2L_GPIO_PORT_PACK(6, 0x2a, RZG3S_MPXED_PIN_FUNCS(A)), /* P18 */ 2005 }; 2006 2007 static const char * const rzg3e_gpio_names[] = { 2008 "P00", "P01", "P02", "P03", "P04", "P05", "P06", "P07", 2009 "P10", "P11", "P12", "P13", "P14", "P15", "P16", "P17", 2010 "P20", "P21", "P22", "P23", "P24", "P25", "P26", "P27", 2011 "P30", "P31", "P32", "P33", "P34", "P35", "P36", "P37", 2012 "P40", "P41", "P42", "P43", "P44", "P45", "P46", "P47", 2013 "P50", "P51", "P52", "P53", "P54", "P55", "P56", "P57", 2014 "P60", "P61", "P62", "P63", "P64", "P65", "P66", "P67", 2015 "P70", "P71", "P72", "P73", "P74", "P75", "P76", "P77", 2016 "P80", "P81", "P82", "P83", "P84", "P85", "P86", "P87", 2017 "", "", "", "", "", "", "", "", 2018 "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", 2019 "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", 2020 "PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", 2021 "PD0", "PD1", "PD2", "PD3", "PD4", "PD5", "PD6", "PD7", 2022 "PE0", "PE1", "PE2", "PE3", "PE4", "PE5", "PE6", "PE7", 2023 "PF0", "PF1", "PF2", "PF3", "PF4", "PF5", "PF6", "PF7", 2024 "PG0", "PG1", "PG2", "PG3", "PG4", "PG5", "PG6", "PG7", 2025 "PH0", "PH1", "PH2", "PH3", "PH4", "PH5", "PH6", "PH7", 2026 "", "", "", "", "", "", "", "", 2027 "PJ0", "PJ1", "PJ2", "PJ3", "PJ4", "PJ5", "PJ6", "PJ7", 2028 "PK0", "PK1", "PK2", "PK3", "PK4", "PK5", "PK6", "PK7", 2029 "PL0", "PL1", "PL2", "PL3", "PL4", "PL5", "PL6", "PL7", 2030 "PM0", "PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7", 2031 "", "", "", "", "", "", "", "", 2032 "", "", "", "", "", "", "", "", 2033 "", "", "", "", "", "", "", "", 2034 "", "", "", "", "", "", "", "", 2035 "", "", "", "", "", "", "", "", 2036 "PS0", "PS1", "PS2", "PS3", "PS4", "PS5", "PS6", "PS7", 2037 }; 2038 2039 static const u64 r9a09g047_gpio_configs[] = { 2040 RZG2L_GPIO_PORT_PACK(8, 0x20, RZV2H_MPXED_PIN_FUNCS), /* P0 */ 2041 RZG2L_GPIO_PORT_PACK(8, 0x21, RZV2H_MPXED_PIN_FUNCS | 2042 PIN_CFG_ELC), /* P1 */ 2043 RZG2L_GPIO_PORT_PACK(2, 0x22, RZG2L_MPXED_COMMON_PIN_FUNCS(RZV2H) | 2044 PIN_CFG_NOD), /* P2 */ 2045 RZG2L_GPIO_PORT_PACK(8, 0x23, RZV2H_MPXED_PIN_FUNCS), /* P3 */ 2046 RZG2L_GPIO_PORT_PACK(6, 0x24, RZV2H_MPXED_PIN_FUNCS), /* P4 */ 2047 RZG2L_GPIO_PORT_PACK(7, 0x25, RZV2H_MPXED_PIN_FUNCS), /* P5 */ 2048 RZG2L_GPIO_PORT_PACK(7, 0x26, RZV2H_MPXED_PIN_FUNCS), /* P6 */ 2049 RZG2L_GPIO_PORT_PACK(8, 0x27, RZV2H_MPXED_PIN_FUNCS | 2050 PIN_CFG_ELC), /* P7 */ 2051 RZG2L_GPIO_PORT_PACK(6, 0x28, RZV2H_MPXED_PIN_FUNCS), /* P8 */ 2052 0x0, 2053 RZG2L_GPIO_PORT_PACK_VARIABLE(8, 0x2a), /* PA */ 2054 RZG2L_GPIO_PORT_PACK(8, 0x2b, RZV2H_MPXED_PIN_FUNCS), /* PB */ 2055 RZG2L_GPIO_PORT_PACK(3, 0x2c, RZV2H_MPXED_PIN_FUNCS), /* PC */ 2056 RZG2L_GPIO_PORT_PACK_VARIABLE(8, 0x2d), /* PD */ 2057 RZG2L_GPIO_PORT_PACK(8, 0x2e, RZV2H_MPXED_PIN_FUNCS), /* PE */ 2058 RZG2L_GPIO_PORT_PACK(3, 0x2f, RZV2H_MPXED_PIN_FUNCS), /* PF */ 2059 RZG2L_GPIO_PORT_PACK_VARIABLE(8, 0x30), /* PG */ 2060 RZG2L_GPIO_PORT_PACK_VARIABLE(6, 0x31), /* PH */ 2061 0x0, 2062 RZG2L_GPIO_PORT_PACK_VARIABLE(5, 0x33), /* PJ */ 2063 RZG2L_GPIO_PORT_PACK(4, 0x34, RZV2H_MPXED_PIN_FUNCS), /* PK */ 2064 RZG2L_GPIO_PORT_PACK(8, 0x35, RZV2H_MPXED_PIN_FUNCS), /* PL */ 2065 RZG2L_GPIO_PORT_PACK(8, 0x36, RZV2H_MPXED_PIN_FUNCS), /* PM */ 2066 0x0, 2067 0x0, 2068 0x0, 2069 0x0, 2070 0x0, 2071 RZG2L_GPIO_PORT_PACK(4, 0x3c, RZV2H_MPXED_PIN_FUNCS), /* PS */ 2072 }; 2073 2074 static const char * const rzv2h_gpio_names[] = { 2075 "P00", "P01", "P02", "P03", "P04", "P05", "P06", "P07", 2076 "P10", "P11", "P12", "P13", "P14", "P15", "P16", "P17", 2077 "P20", "P21", "P22", "P23", "P24", "P25", "P26", "P27", 2078 "P30", "P31", "P32", "P33", "P34", "P35", "P36", "P37", 2079 "P40", "P41", "P42", "P43", "P44", "P45", "P46", "P47", 2080 "P50", "P51", "P52", "P53", "P54", "P55", "P56", "P57", 2081 "P60", "P61", "P62", "P63", "P64", "P65", "P66", "P67", 2082 "P70", "P71", "P72", "P73", "P74", "P75", "P76", "P77", 2083 "P80", "P81", "P82", "P83", "P84", "P85", "P86", "P87", 2084 "P90", "P91", "P92", "P93", "P94", "P95", "P96", "P97", 2085 "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", 2086 "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", 2087 }; 2088 2089 static const u64 r9a09g057_gpio_configs[] = { 2090 RZG2L_GPIO_PORT_PACK(8, 0x20, RZV2H_MPXED_PIN_FUNCS), /* P0 */ 2091 RZG2L_GPIO_PORT_PACK(6, 0x21, RZV2H_MPXED_PIN_FUNCS), /* P1 */ 2092 RZG2L_GPIO_PORT_PACK(2, 0x22, RZG2L_MPXED_COMMON_PIN_FUNCS(RZV2H) | 2093 PIN_CFG_NOD), /* P2 */ 2094 RZG2L_GPIO_PORT_PACK(8, 0x23, RZV2H_MPXED_PIN_FUNCS), /* P3 */ 2095 RZG2L_GPIO_PORT_PACK(8, 0x24, RZV2H_MPXED_PIN_FUNCS), /* P4 */ 2096 RZG2L_GPIO_PORT_PACK(8, 0x25, RZV2H_MPXED_PIN_FUNCS), /* P5 */ 2097 RZG2L_GPIO_PORT_PACK(8, 0x26, RZV2H_MPXED_PIN_FUNCS | 2098 PIN_CFG_ELC), /* P6 */ 2099 RZG2L_GPIO_PORT_PACK(8, 0x27, RZV2H_MPXED_PIN_FUNCS), /* P7 */ 2100 RZG2L_GPIO_PORT_PACK(8, 0x28, RZV2H_MPXED_PIN_FUNCS | 2101 PIN_CFG_ELC), /* P8 */ 2102 RZG2L_GPIO_PORT_PACK(8, 0x29, RZV2H_MPXED_PIN_FUNCS), /* P9 */ 2103 RZG2L_GPIO_PORT_PACK(8, 0x2a, RZV2H_MPXED_PIN_FUNCS), /* PA */ 2104 RZG2L_GPIO_PORT_PACK_VARIABLE(6, 0x2b), /* PB */ 2105 }; 2106 2107 static const struct { 2108 struct rzg2l_dedicated_configs common[35]; 2109 struct rzg2l_dedicated_configs rzg2l_pins[7]; 2110 } rzg2l_dedicated_pins = { 2111 .common = { 2112 { "NMI", RZG2L_SINGLE_PIN_PACK(0x1, 0, PIN_CFG_NF) }, 2113 { "TMS/SWDIO", RZG2L_SINGLE_PIN_PACK(0x2, 0, 2114 (PIN_CFG_IOLH_A | PIN_CFG_SR | PIN_CFG_IEN)) }, 2115 { "TDO", RZG2L_SINGLE_PIN_PACK(0x3, 0, 2116 (PIN_CFG_IOLH_A | PIN_CFG_SR | PIN_CFG_IEN)) }, 2117 { "AUDIO_CLK1", RZG2L_SINGLE_PIN_PACK(0x4, 0, PIN_CFG_IEN) }, 2118 { "AUDIO_CLK2", RZG2L_SINGLE_PIN_PACK(0x4, 1, PIN_CFG_IEN) }, 2119 { "SD0_CLK", RZG2L_SINGLE_PIN_PACK(0x6, 0, 2120 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_SD0)) }, 2121 { "SD0_CMD", RZG2L_SINGLE_PIN_PACK(0x6, 1, 2122 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 2123 { "SD0_RST#", RZG2L_SINGLE_PIN_PACK(0x6, 2, 2124 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_SD0)) }, 2125 { "SD0_DATA0", RZG2L_SINGLE_PIN_PACK(0x7, 0, 2126 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 2127 { "SD0_DATA1", RZG2L_SINGLE_PIN_PACK(0x7, 1, 2128 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 2129 { "SD0_DATA2", RZG2L_SINGLE_PIN_PACK(0x7, 2, 2130 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 2131 { "SD0_DATA3", RZG2L_SINGLE_PIN_PACK(0x7, 3, 2132 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 2133 { "SD0_DATA4", RZG2L_SINGLE_PIN_PACK(0x7, 4, 2134 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 2135 { "SD0_DATA5", RZG2L_SINGLE_PIN_PACK(0x7, 5, 2136 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 2137 { "SD0_DATA6", RZG2L_SINGLE_PIN_PACK(0x7, 6, 2138 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 2139 { "SD0_DATA7", RZG2L_SINGLE_PIN_PACK(0x7, 7, 2140 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 2141 { "SD1_CLK", RZG2L_SINGLE_PIN_PACK(0x8, 0, 2142 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_SD1)) }, 2143 { "SD1_CMD", RZG2L_SINGLE_PIN_PACK(0x8, 1, 2144 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD1)) }, 2145 { "SD1_DATA0", RZG2L_SINGLE_PIN_PACK(0x9, 0, 2146 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD1)) }, 2147 { "SD1_DATA1", RZG2L_SINGLE_PIN_PACK(0x9, 1, 2148 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD1)) }, 2149 { "SD1_DATA2", RZG2L_SINGLE_PIN_PACK(0x9, 2, 2150 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD1)) }, 2151 { "SD1_DATA3", RZG2L_SINGLE_PIN_PACK(0x9, 3, 2152 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD1)) }, 2153 { "QSPI0_SPCLK", RZG2L_SINGLE_PIN_PACK(0xa, 0, 2154 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2155 { "QSPI0_IO0", RZG2L_SINGLE_PIN_PACK(0xa, 1, 2156 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2157 { "QSPI0_IO1", RZG2L_SINGLE_PIN_PACK(0xa, 2, 2158 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2159 { "QSPI0_IO2", RZG2L_SINGLE_PIN_PACK(0xa, 3, 2160 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2161 { "QSPI0_IO3", RZG2L_SINGLE_PIN_PACK(0xa, 4, 2162 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2163 { "QSPI0_SSL", RZG2L_SINGLE_PIN_PACK(0xa, 5, 2164 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2165 { "QSPI_RESET#", RZG2L_SINGLE_PIN_PACK(0xc, 0, 2166 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2167 { "QSPI_WP#", RZG2L_SINGLE_PIN_PACK(0xc, 1, 2168 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2169 { "WDTOVF_PERROUT#", RZG2L_SINGLE_PIN_PACK(0xd, 0, (PIN_CFG_IOLH_A | PIN_CFG_SR)) }, 2170 { "RIIC0_SDA", RZG2L_SINGLE_PIN_PACK(0xe, 0, PIN_CFG_IEN) }, 2171 { "RIIC0_SCL", RZG2L_SINGLE_PIN_PACK(0xe, 1, PIN_CFG_IEN) }, 2172 { "RIIC1_SDA", RZG2L_SINGLE_PIN_PACK(0xe, 2, PIN_CFG_IEN) }, 2173 { "RIIC1_SCL", RZG2L_SINGLE_PIN_PACK(0xe, 3, PIN_CFG_IEN) }, 2174 }, 2175 .rzg2l_pins = { 2176 { "QSPI_INT#", RZG2L_SINGLE_PIN_PACK(0xc, 2, (PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2177 { "QSPI1_SPCLK", RZG2L_SINGLE_PIN_PACK(0xb, 0, 2178 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2179 { "QSPI1_IO0", RZG2L_SINGLE_PIN_PACK(0xb, 1, 2180 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2181 { "QSPI1_IO1", RZG2L_SINGLE_PIN_PACK(0xb, 2, 2182 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2183 { "QSPI1_IO2", RZG2L_SINGLE_PIN_PACK(0xb, 3, 2184 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2185 { "QSPI1_IO3", RZG2L_SINGLE_PIN_PACK(0xb, 4, 2186 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2187 { "QSPI1_SSL", RZG2L_SINGLE_PIN_PACK(0xb, 5, 2188 (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 2189 } 2190 }; 2191 2192 static const struct rzg2l_dedicated_configs rzg3s_dedicated_pins[] = { 2193 { "NMI", RZG2L_SINGLE_PIN_PACK(0x0, 0, PIN_CFG_NF) }, 2194 { "TMS/SWDIO", RZG2L_SINGLE_PIN_PACK(0x1, 0, (PIN_CFG_IOLH_A | PIN_CFG_IEN | 2195 PIN_CFG_SOFT_PS)) }, 2196 { "TDO", RZG2L_SINGLE_PIN_PACK(0x1, 1, (PIN_CFG_IOLH_A | PIN_CFG_SOFT_PS)) }, 2197 { "AUDIO_CLK1", RZG2L_SINGLE_PIN_PACK(0x2, 0, PIN_CFG_IEN) }, 2198 { "AUDIO_CLK2", RZG2L_SINGLE_PIN_PACK(0x2, 1, PIN_CFG_IEN) }, 2199 { "WDTOVF_PERROUT#", RZG2L_SINGLE_PIN_PACK(0x6, 0, PIN_CFG_IOLH_A | PIN_CFG_SOFT_PS) }, 2200 { "SD0_CLK", RZG2L_SINGLE_PIN_PACK(0x10, 0, (PIN_CFG_IOLH_B | PIN_CFG_IO_VMC_SD0)) }, 2201 { "SD0_CMD", RZG2L_SINGLE_PIN_PACK(0x10, 1, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2202 PIN_CFG_IO_VMC_SD0)) }, 2203 { "SD0_RST#", RZG2L_SINGLE_PIN_PACK(0x10, 2, (PIN_CFG_IOLH_B | PIN_CFG_IO_VMC_SD0)) }, 2204 { "SD0_DATA0", RZG2L_SINGLE_PIN_PACK(0x11, 0, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2205 PIN_CFG_IO_VMC_SD0)) }, 2206 { "SD0_DATA1", RZG2L_SINGLE_PIN_PACK(0x11, 1, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2207 PIN_CFG_IO_VMC_SD0)) }, 2208 { "SD0_DATA2", RZG2L_SINGLE_PIN_PACK(0x11, 2, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2209 PIN_CFG_IO_VMC_SD0)) }, 2210 { "SD0_DATA3", RZG2L_SINGLE_PIN_PACK(0x11, 3, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2211 PIN_CFG_IO_VMC_SD0)) }, 2212 { "SD0_DATA4", RZG2L_SINGLE_PIN_PACK(0x11, 4, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2213 PIN_CFG_IO_VMC_SD0)) }, 2214 { "SD0_DATA5", RZG2L_SINGLE_PIN_PACK(0x11, 5, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2215 PIN_CFG_IO_VMC_SD0)) }, 2216 { "SD0_DATA6", RZG2L_SINGLE_PIN_PACK(0x11, 6, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2217 PIN_CFG_IO_VMC_SD0)) }, 2218 { "SD0_DATA7", RZG2L_SINGLE_PIN_PACK(0x11, 7, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2219 PIN_CFG_IO_VMC_SD0)) }, 2220 { "SD1_CLK", RZG2L_SINGLE_PIN_PACK(0x12, 0, (PIN_CFG_IOLH_B | PIN_CFG_IO_VMC_SD1)) }, 2221 { "SD1_CMD", RZG2L_SINGLE_PIN_PACK(0x12, 1, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2222 PIN_CFG_IO_VMC_SD1)) }, 2223 { "SD1_DATA0", RZG2L_SINGLE_PIN_PACK(0x13, 0, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2224 PIN_CFG_IO_VMC_SD1)) }, 2225 { "SD1_DATA1", RZG2L_SINGLE_PIN_PACK(0x13, 1, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2226 PIN_CFG_IO_VMC_SD1)) }, 2227 { "SD1_DATA2", RZG2L_SINGLE_PIN_PACK(0x13, 2, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2228 PIN_CFG_IO_VMC_SD1)) }, 2229 { "SD1_DATA3", RZG2L_SINGLE_PIN_PACK(0x13, 3, (PIN_CFG_IOLH_B | PIN_CFG_IEN | 2230 PIN_CFG_IO_VMC_SD1)) }, 2231 }; 2232 2233 static struct rzg2l_dedicated_configs rzv2h_dedicated_pins[] = { 2234 { "NMI", RZG2L_SINGLE_PIN_PACK(0x1, 0, PIN_CFG_NF) }, 2235 { "TMS_SWDIO", RZG2L_SINGLE_PIN_PACK(0x3, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2236 PIN_CFG_IEN)) }, 2237 { "TDO", RZG2L_SINGLE_PIN_PACK(0x3, 2, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR)) }, 2238 { "WDTUDFCA", RZG2L_SINGLE_PIN_PACK(0x5, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2239 PIN_CFG_PUPD | PIN_CFG_NOD)) }, 2240 { "WDTUDFCM", RZG2L_SINGLE_PIN_PACK(0x5, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2241 PIN_CFG_PUPD | PIN_CFG_NOD)) }, 2242 { "SCIF_RXD", RZG2L_SINGLE_PIN_PACK(0x6, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2243 PIN_CFG_PUPD)) }, 2244 { "SCIF_TXD", RZG2L_SINGLE_PIN_PACK(0x6, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2245 PIN_CFG_PUPD)) }, 2246 { "XSPI0_CKP", RZG2L_SINGLE_PIN_PACK(0x7, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2247 PIN_CFG_PUPD | PIN_CFG_OEN)) }, 2248 { "XSPI0_CKN", RZG2L_SINGLE_PIN_PACK(0x7, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2249 PIN_CFG_PUPD | PIN_CFG_OEN)) }, 2250 { "XSPI0_CS0N", RZG2L_SINGLE_PIN_PACK(0x7, 2, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2251 PIN_CFG_PUPD | PIN_CFG_OEN)) }, 2252 { "XSPI0_DS", RZG2L_SINGLE_PIN_PACK(0x7, 3, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2253 PIN_CFG_PUPD)) }, 2254 { "XSPI0_RESET0N", RZG2L_SINGLE_PIN_PACK(0x7, 4, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2255 PIN_CFG_PUPD | PIN_CFG_OEN)) }, 2256 { "XSPI0_RSTO0N", RZG2L_SINGLE_PIN_PACK(0x7, 5, (PIN_CFG_PUPD)) }, 2257 { "XSPI0_INT0N", RZG2L_SINGLE_PIN_PACK(0x7, 6, (PIN_CFG_PUPD)) }, 2258 { "XSPI0_ECS0N", RZG2L_SINGLE_PIN_PACK(0x7, 7, (PIN_CFG_PUPD)) }, 2259 { "XSPI0_IO0", RZG2L_SINGLE_PIN_PACK(0x8, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2260 PIN_CFG_PUPD)) }, 2261 { "XSPI0_IO1", RZG2L_SINGLE_PIN_PACK(0x8, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2262 PIN_CFG_PUPD)) }, 2263 { "XSPI0_IO2", RZG2L_SINGLE_PIN_PACK(0x8, 2, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2264 PIN_CFG_PUPD)) }, 2265 { "XSPI0_IO3", RZG2L_SINGLE_PIN_PACK(0x8, 3, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2266 PIN_CFG_PUPD)) }, 2267 { "XSPI0_IO4", RZG2L_SINGLE_PIN_PACK(0x8, 4, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2268 PIN_CFG_PUPD)) }, 2269 { "XSPI0_IO5", RZG2L_SINGLE_PIN_PACK(0x8, 5, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2270 PIN_CFG_PUPD)) }, 2271 { "XSPI0_IO6", RZG2L_SINGLE_PIN_PACK(0x8, 6, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2272 PIN_CFG_PUPD)) }, 2273 { "XSPI0_IO7", RZG2L_SINGLE_PIN_PACK(0x8, 7, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2274 PIN_CFG_PUPD)) }, 2275 { "SD0CLK", RZG2L_SINGLE_PIN_PACK(0x9, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR)) }, 2276 { "SD0CMD", RZG2L_SINGLE_PIN_PACK(0x9, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2277 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2278 { "SD0RSTN", RZG2L_SINGLE_PIN_PACK(0x9, 2, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR)) }, 2279 { "SD0DAT0", RZG2L_SINGLE_PIN_PACK(0xa, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2280 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2281 { "SD0DAT1", RZG2L_SINGLE_PIN_PACK(0xa, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2282 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2283 { "SD0DAT2", RZG2L_SINGLE_PIN_PACK(0xa, 2, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2284 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2285 { "SD0DAT3", RZG2L_SINGLE_PIN_PACK(0xa, 3, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2286 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2287 { "SD0DAT4", RZG2L_SINGLE_PIN_PACK(0xa, 4, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2288 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2289 { "SD0DAT5", RZG2L_SINGLE_PIN_PACK(0xa, 5, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2290 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2291 { "SD0DAT6", RZG2L_SINGLE_PIN_PACK(0xa, 6, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2292 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2293 { "SD0DAT7", RZG2L_SINGLE_PIN_PACK(0xa, 7, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2294 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2295 { "SD1CLK", RZG2L_SINGLE_PIN_PACK(0xb, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR)) }, 2296 { "SD1CMD", RZG2L_SINGLE_PIN_PACK(0xb, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2297 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2298 { "SD1DAT0", RZG2L_SINGLE_PIN_PACK(0xc, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2299 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2300 { "SD1DAT1", RZG2L_SINGLE_PIN_PACK(0xc, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2301 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2302 { "SD1DAT2", RZG2L_SINGLE_PIN_PACK(0xc, 2, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2303 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2304 { "SD1DAT3", RZG2L_SINGLE_PIN_PACK(0xc, 3, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2305 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2306 { "PCIE0_RSTOUTB", RZG2L_SINGLE_PIN_PACK(0xe, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR)) }, 2307 { "PCIE1_RSTOUTB", RZG2L_SINGLE_PIN_PACK(0xe, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR)) }, 2308 { "ET0_MDIO", RZG2L_SINGLE_PIN_PACK(0xf, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2309 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2310 { "ET0_MDC", RZG2L_SINGLE_PIN_PACK(0xf, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2311 PIN_CFG_PUPD)) }, 2312 { "ET0_RXCTL_RXDV", RZG2L_SINGLE_PIN_PACK(0x10, 0, (PIN_CFG_PUPD)) }, 2313 { "ET0_TXCTL_TXEN", RZG2L_SINGLE_PIN_PACK(0x10, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2314 PIN_CFG_PUPD)) }, 2315 { "ET0_TXER", RZG2L_SINGLE_PIN_PACK(0x10, 2, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2316 PIN_CFG_PUPD)) }, 2317 { "ET0_RXER", RZG2L_SINGLE_PIN_PACK(0x10, 3, (PIN_CFG_PUPD)) }, 2318 { "ET0_RXC_RXCLK", RZG2L_SINGLE_PIN_PACK(0x10, 4, (PIN_CFG_PUPD)) }, 2319 { "ET0_TXC_TXCLK", RZG2L_SINGLE_PIN_PACK(0x10, 5, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2320 PIN_CFG_PUPD | PIN_CFG_OEN)) }, 2321 { "ET0_CRS", RZG2L_SINGLE_PIN_PACK(0x10, 6, (PIN_CFG_PUPD)) }, 2322 { "ET0_COL", RZG2L_SINGLE_PIN_PACK(0x10, 7, (PIN_CFG_PUPD)) }, 2323 { "ET0_TXD0", RZG2L_SINGLE_PIN_PACK(0x11, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2324 PIN_CFG_PUPD)) }, 2325 { "ET0_TXD1", RZG2L_SINGLE_PIN_PACK(0x11, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2326 PIN_CFG_PUPD)) }, 2327 { "ET0_TXD2", RZG2L_SINGLE_PIN_PACK(0x11, 2, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2328 PIN_CFG_PUPD)) }, 2329 { "ET0_TXD3", RZG2L_SINGLE_PIN_PACK(0x11, 3, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2330 PIN_CFG_PUPD)) }, 2331 { "ET0_RXD0", RZG2L_SINGLE_PIN_PACK(0x11, 4, (PIN_CFG_PUPD)) }, 2332 { "ET0_RXD1", RZG2L_SINGLE_PIN_PACK(0x11, 5, (PIN_CFG_PUPD)) }, 2333 { "ET0_RXD2", RZG2L_SINGLE_PIN_PACK(0x11, 6, (PIN_CFG_PUPD)) }, 2334 { "ET0_RXD3", RZG2L_SINGLE_PIN_PACK(0x11, 7, (PIN_CFG_PUPD)) }, 2335 { "ET1_MDIO", RZG2L_SINGLE_PIN_PACK(0x12, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2336 PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2337 { "ET1_MDC", RZG2L_SINGLE_PIN_PACK(0x12, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2338 PIN_CFG_PUPD)) }, 2339 { "ET1_RXCTL_RXDV", RZG2L_SINGLE_PIN_PACK(0x13, 0, (PIN_CFG_PUPD)) }, 2340 { "ET1_TXCTL_TXEN", RZG2L_SINGLE_PIN_PACK(0x13, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2341 PIN_CFG_PUPD)) }, 2342 { "ET1_TXER", RZG2L_SINGLE_PIN_PACK(0x13, 2, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2343 PIN_CFG_PUPD)) }, 2344 { "ET1_RXER", RZG2L_SINGLE_PIN_PACK(0x13, 3, (PIN_CFG_PUPD)) }, 2345 { "ET1_RXC_RXCLK", RZG2L_SINGLE_PIN_PACK(0x13, 4, (PIN_CFG_PUPD)) }, 2346 { "ET1_TXC_TXCLK", RZG2L_SINGLE_PIN_PACK(0x13, 5, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2347 PIN_CFG_PUPD | PIN_CFG_OEN)) }, 2348 { "ET1_CRS", RZG2L_SINGLE_PIN_PACK(0x13, 6, (PIN_CFG_PUPD)) }, 2349 { "ET1_COL", RZG2L_SINGLE_PIN_PACK(0x13, 7, (PIN_CFG_PUPD)) }, 2350 { "ET1_TXD0", RZG2L_SINGLE_PIN_PACK(0x14, 0, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2351 PIN_CFG_PUPD)) }, 2352 { "ET1_TXD1", RZG2L_SINGLE_PIN_PACK(0x14, 1, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2353 PIN_CFG_PUPD)) }, 2354 { "ET1_TXD2", RZG2L_SINGLE_PIN_PACK(0x14, 2, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2355 PIN_CFG_PUPD)) }, 2356 { "ET1_TXD3", RZG2L_SINGLE_PIN_PACK(0x14, 3, (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | 2357 PIN_CFG_PUPD)) }, 2358 { "ET1_RXD0", RZG2L_SINGLE_PIN_PACK(0x14, 4, (PIN_CFG_PUPD)) }, 2359 { "ET1_RXD1", RZG2L_SINGLE_PIN_PACK(0x14, 5, (PIN_CFG_PUPD)) }, 2360 { "ET1_RXD2", RZG2L_SINGLE_PIN_PACK(0x14, 6, (PIN_CFG_PUPD)) }, 2361 { "ET1_RXD3", RZG2L_SINGLE_PIN_PACK(0x14, 7, (PIN_CFG_PUPD)) }, 2362 }; 2363 2364 static struct rzg2l_dedicated_configs rzg3e_dedicated_pins[] = { 2365 { "WDTUDFCA", RZG2L_SINGLE_PIN_PACK(0x5, 0, 2366 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_PUPD | PIN_CFG_NOD)) }, 2367 { "WDTUDFCM", RZG2L_SINGLE_PIN_PACK(0x5, 1, 2368 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_PUPD | PIN_CFG_NOD)) }, 2369 { "SCIF_RXD", RZG2L_SINGLE_PIN_PACK(0x6, 0, 2370 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_PUPD)) }, 2371 { "SCIF_TXD", RZG2L_SINGLE_PIN_PACK(0x6, 1, 2372 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_PUPD)) }, 2373 { "SD0CLK", RZG2L_SINGLE_PIN_PACK(0x9, 0, 2374 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR)) }, 2375 { "SD0CMD", RZG2L_SINGLE_PIN_PACK(0x9, 1, 2376 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2377 { "SD0RSTN", RZG2L_SINGLE_PIN_PACK(0x9, 2, 2378 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR)) }, 2379 { "SD0PWEN", RZG2L_SINGLE_PIN_PACK(0x9, 3, 2380 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR)) }, 2381 { "SD0IOVS", RZG2L_SINGLE_PIN_PACK(0x9, 4, 2382 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR)) }, 2383 { "SD0DAT0", RZG2L_SINGLE_PIN_PACK(0xa, 0, 2384 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2385 { "SD0DAT1", RZG2L_SINGLE_PIN_PACK(0xa, 1, 2386 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2387 { "SD0DAT2", RZG2L_SINGLE_PIN_PACK(0xa, 2, 2388 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2389 { "SD0DAT3", RZG2L_SINGLE_PIN_PACK(0xa, 3, 2390 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2391 { "SD0DAT4", RZG2L_SINGLE_PIN_PACK(0xa, 4, 2392 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2393 { "SD0DAT5", RZG2L_SINGLE_PIN_PACK(0xa, 5, 2394 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2395 { "SD0DAT6", RZG2L_SINGLE_PIN_PACK(0xa, 6, 2396 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2397 { "SD0DAT7", RZG2L_SINGLE_PIN_PACK(0xa, 7, 2398 (PIN_CFG_IOLH_RZV2H | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_PUPD)) }, 2399 }; 2400 2401 static int rzg2l_gpio_get_gpioint(unsigned int virq, struct rzg2l_pinctrl *pctrl) 2402 { 2403 const struct pinctrl_pin_desc *pin_desc = &pctrl->desc.pins[virq]; 2404 const struct rzg2l_pinctrl_data *data = pctrl->data; 2405 u64 *pin_data = pin_desc->drv_data; 2406 unsigned int gpioint; 2407 unsigned int i; 2408 u32 port, bit; 2409 2410 if (*pin_data & PIN_CFG_NOGPIO_INT) 2411 return -EINVAL; 2412 2413 port = virq / 8; 2414 bit = virq % 8; 2415 2416 if (port >= data->n_ports || 2417 bit >= hweight8(FIELD_GET(PIN_CFG_PIN_MAP_MASK, data->port_pin_configs[port]))) 2418 return -EINVAL; 2419 2420 gpioint = bit; 2421 for (i = 0; i < port; i++) 2422 gpioint += hweight8(FIELD_GET(PIN_CFG_PIN_MAP_MASK, data->port_pin_configs[i])); 2423 2424 return gpioint; 2425 } 2426 2427 static void rzg2l_gpio_irq_endisable(struct rzg2l_pinctrl *pctrl, 2428 unsigned int hwirq, bool enable) 2429 { 2430 const struct pinctrl_pin_desc *pin_desc = &pctrl->desc.pins[hwirq]; 2431 u64 *pin_data = pin_desc->drv_data; 2432 u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data); 2433 u8 bit = RZG2L_PIN_ID_TO_PIN(hwirq); 2434 unsigned long flags; 2435 void __iomem *addr; 2436 2437 addr = pctrl->base + ISEL(off); 2438 if (bit >= 4) { 2439 bit -= 4; 2440 addr += 4; 2441 } 2442 2443 spin_lock_irqsave(&pctrl->lock, flags); 2444 if (enable) 2445 writel(readl(addr) | BIT(bit * 8), addr); 2446 else 2447 writel(readl(addr) & ~BIT(bit * 8), addr); 2448 spin_unlock_irqrestore(&pctrl->lock, flags); 2449 } 2450 2451 static void rzg2l_gpio_irq_disable(struct irq_data *d) 2452 { 2453 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 2454 unsigned int hwirq = irqd_to_hwirq(d); 2455 2456 irq_chip_disable_parent(d); 2457 gpiochip_disable_irq(gc, hwirq); 2458 } 2459 2460 static void rzg2l_gpio_irq_enable(struct irq_data *d) 2461 { 2462 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 2463 unsigned int hwirq = irqd_to_hwirq(d); 2464 2465 gpiochip_enable_irq(gc, hwirq); 2466 irq_chip_enable_parent(d); 2467 } 2468 2469 static int rzg2l_gpio_irq_set_type(struct irq_data *d, unsigned int type) 2470 { 2471 return irq_chip_set_type_parent(d, type); 2472 } 2473 2474 static void rzg2l_gpio_irqc_eoi(struct irq_data *d) 2475 { 2476 irq_chip_eoi_parent(d); 2477 } 2478 2479 static void rzg2l_gpio_irq_print_chip(struct irq_data *data, struct seq_file *p) 2480 { 2481 struct gpio_chip *gc = irq_data_get_irq_chip_data(data); 2482 2483 seq_puts(p, dev_name(gc->parent)); 2484 } 2485 2486 static int rzg2l_gpio_irq_set_wake(struct irq_data *data, unsigned int on) 2487 { 2488 struct gpio_chip *gc = irq_data_get_irq_chip_data(data); 2489 struct rzg2l_pinctrl *pctrl = container_of(gc, struct rzg2l_pinctrl, gpio_chip); 2490 int ret; 2491 2492 /* It should not happen. */ 2493 if (!data->parent_data) 2494 return -EOPNOTSUPP; 2495 2496 ret = irq_chip_set_wake_parent(data, on); 2497 if (ret) 2498 return ret; 2499 2500 if (on) 2501 atomic_inc(&pctrl->wakeup_path); 2502 else 2503 atomic_dec(&pctrl->wakeup_path); 2504 2505 return 0; 2506 } 2507 2508 static const struct irq_chip rzg2l_gpio_irqchip = { 2509 .name = "rzg2l-gpio", 2510 .irq_disable = rzg2l_gpio_irq_disable, 2511 .irq_enable = rzg2l_gpio_irq_enable, 2512 .irq_mask = irq_chip_mask_parent, 2513 .irq_unmask = irq_chip_unmask_parent, 2514 .irq_set_type = rzg2l_gpio_irq_set_type, 2515 .irq_eoi = rzg2l_gpio_irqc_eoi, 2516 .irq_print_chip = rzg2l_gpio_irq_print_chip, 2517 .irq_set_affinity = irq_chip_set_affinity_parent, 2518 .irq_set_wake = rzg2l_gpio_irq_set_wake, 2519 .flags = IRQCHIP_IMMUTABLE, 2520 GPIOCHIP_IRQ_RESOURCE_HELPERS, 2521 }; 2522 2523 static int rzg2l_gpio_interrupt_input_mode(struct gpio_chip *chip, unsigned int offset) 2524 { 2525 struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 2526 const struct pinctrl_pin_desc *pin_desc = &pctrl->desc.pins[offset]; 2527 u64 *pin_data = pin_desc->drv_data; 2528 u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data); 2529 u8 bit = RZG2L_PIN_ID_TO_PIN(offset); 2530 u8 reg8; 2531 int ret; 2532 2533 reg8 = readb(pctrl->base + PMC(off)); 2534 if (reg8 & BIT(bit)) { 2535 ret = rzg2l_gpio_request(chip, offset); 2536 if (ret) 2537 return ret; 2538 } 2539 2540 return rzg2l_gpio_direction_input(chip, offset); 2541 } 2542 2543 static int rzg2l_gpio_child_to_parent_hwirq(struct gpio_chip *gc, 2544 unsigned int child, 2545 unsigned int child_type, 2546 unsigned int *parent, 2547 unsigned int *parent_type) 2548 { 2549 struct rzg2l_pinctrl *pctrl = gpiochip_get_data(gc); 2550 unsigned long flags; 2551 int gpioint, irq; 2552 int ret; 2553 2554 gpioint = rzg2l_gpio_get_gpioint(child, pctrl); 2555 if (gpioint < 0) 2556 return gpioint; 2557 2558 ret = rzg2l_gpio_interrupt_input_mode(gc, child); 2559 if (ret) 2560 return ret; 2561 2562 spin_lock_irqsave(&pctrl->bitmap_lock, flags); 2563 irq = bitmap_find_free_region(pctrl->tint_slot, RZG2L_TINT_MAX_INTERRUPT, get_order(1)); 2564 spin_unlock_irqrestore(&pctrl->bitmap_lock, flags); 2565 if (irq < 0) { 2566 ret = -ENOSPC; 2567 goto err; 2568 } 2569 2570 rzg2l_gpio_irq_endisable(pctrl, child, true); 2571 pctrl->hwirq[irq] = child; 2572 irq += pctrl->data->hwcfg->tint_start_index; 2573 2574 /* All these interrupts are level high in the CPU */ 2575 *parent_type = IRQ_TYPE_LEVEL_HIGH; 2576 *parent = RZG2L_PACK_HWIRQ(gpioint, irq); 2577 return 0; 2578 2579 err: 2580 rzg2l_gpio_free(gc, child); 2581 return ret; 2582 } 2583 2584 static void rzg2l_gpio_irq_restore(struct rzg2l_pinctrl *pctrl) 2585 { 2586 struct irq_domain *domain = pctrl->gpio_chip.irq.domain; 2587 2588 for (unsigned int i = 0; i < RZG2L_TINT_MAX_INTERRUPT; i++) { 2589 struct irq_data *data; 2590 unsigned long flags; 2591 unsigned int virq; 2592 int ret; 2593 2594 if (!pctrl->hwirq[i]) 2595 continue; 2596 2597 virq = irq_find_mapping(domain, pctrl->hwirq[i]); 2598 if (!virq) { 2599 dev_crit(pctrl->dev, "Failed to find IRQ mapping for hwirq %u\n", 2600 pctrl->hwirq[i]); 2601 continue; 2602 } 2603 2604 data = irq_domain_get_irq_data(domain, virq); 2605 if (!data) { 2606 dev_crit(pctrl->dev, "Failed to get IRQ data for virq=%u\n", virq); 2607 continue; 2608 } 2609 2610 /* 2611 * This has to be atomically executed to protect against a concurrent 2612 * interrupt. 2613 */ 2614 spin_lock_irqsave(&pctrl->lock, flags); 2615 ret = rzg2l_gpio_irq_set_type(data, irqd_get_trigger_type(data)); 2616 if (!ret && !irqd_irq_disabled(data)) 2617 rzg2l_gpio_irq_enable(data); 2618 spin_unlock_irqrestore(&pctrl->lock, flags); 2619 2620 if (ret) 2621 dev_crit(pctrl->dev, "Failed to set IRQ type for virq=%u\n", virq); 2622 } 2623 } 2624 2625 static void rzg2l_gpio_irq_domain_free(struct irq_domain *domain, unsigned int virq, 2626 unsigned int nr_irqs) 2627 { 2628 struct irq_data *d; 2629 2630 d = irq_domain_get_irq_data(domain, virq); 2631 if (d) { 2632 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 2633 struct rzg2l_pinctrl *pctrl = container_of(gc, struct rzg2l_pinctrl, gpio_chip); 2634 irq_hw_number_t hwirq = irqd_to_hwirq(d); 2635 unsigned long flags; 2636 unsigned int i; 2637 2638 for (i = 0; i < RZG2L_TINT_MAX_INTERRUPT; i++) { 2639 if (pctrl->hwirq[i] == hwirq) { 2640 rzg2l_gpio_irq_endisable(pctrl, hwirq, false); 2641 rzg2l_gpio_free(gc, hwirq); 2642 spin_lock_irqsave(&pctrl->bitmap_lock, flags); 2643 bitmap_release_region(pctrl->tint_slot, i, get_order(1)); 2644 spin_unlock_irqrestore(&pctrl->bitmap_lock, flags); 2645 pctrl->hwirq[i] = 0; 2646 break; 2647 } 2648 } 2649 } 2650 irq_domain_free_irqs_common(domain, virq, nr_irqs); 2651 } 2652 2653 static void rzg2l_init_irq_valid_mask(struct gpio_chip *gc, 2654 unsigned long *valid_mask, 2655 unsigned int ngpios) 2656 { 2657 struct rzg2l_pinctrl *pctrl = gpiochip_get_data(gc); 2658 struct gpio_chip *chip = &pctrl->gpio_chip; 2659 unsigned int offset; 2660 2661 /* Forbid unused lines to be mapped as IRQs */ 2662 for (offset = 0; offset < chip->ngpio; offset++) { 2663 u32 port, bit; 2664 2665 port = offset / 8; 2666 bit = offset % 8; 2667 2668 if (port >= pctrl->data->n_ports || 2669 bit >= hweight8(FIELD_GET(PIN_CFG_PIN_MAP_MASK, 2670 pctrl->data->port_pin_configs[port]))) 2671 clear_bit(offset, valid_mask); 2672 } 2673 } 2674 2675 static int rzg2l_pinctrl_reg_cache_alloc(struct rzg2l_pinctrl *pctrl) 2676 { 2677 u32 nports = pctrl->data->n_port_pins / RZG2L_PINS_PER_PORT; 2678 struct rzg2l_pinctrl_reg_cache *cache, *dedicated_cache; 2679 2680 cache = devm_kzalloc(pctrl->dev, sizeof(*cache), GFP_KERNEL); 2681 if (!cache) 2682 return -ENOMEM; 2683 2684 dedicated_cache = devm_kzalloc(pctrl->dev, sizeof(*dedicated_cache), GFP_KERNEL); 2685 if (!dedicated_cache) 2686 return -ENOMEM; 2687 2688 cache->p = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->p), GFP_KERNEL); 2689 if (!cache->p) 2690 return -ENOMEM; 2691 2692 cache->pm = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->pm), GFP_KERNEL); 2693 if (!cache->pm) 2694 return -ENOMEM; 2695 2696 cache->pmc = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->pmc), GFP_KERNEL); 2697 if (!cache->pmc) 2698 return -ENOMEM; 2699 2700 cache->pfc = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->pfc), GFP_KERNEL); 2701 if (!cache->pfc) 2702 return -ENOMEM; 2703 2704 for (u8 i = 0; i < 2; i++) { 2705 u32 n_dedicated_pins = pctrl->data->n_dedicated_pins; 2706 2707 cache->iolh[i] = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->iolh[i]), 2708 GFP_KERNEL); 2709 if (!cache->iolh[i]) 2710 return -ENOMEM; 2711 2712 cache->ien[i] = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->ien[i]), 2713 GFP_KERNEL); 2714 if (!cache->ien[i]) 2715 return -ENOMEM; 2716 2717 cache->pupd[i] = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->pupd[i]), 2718 GFP_KERNEL); 2719 if (!cache->pupd[i]) 2720 return -ENOMEM; 2721 2722 /* Allocate dedicated cache. */ 2723 dedicated_cache->iolh[i] = devm_kcalloc(pctrl->dev, n_dedicated_pins, 2724 sizeof(*dedicated_cache->iolh[i]), 2725 GFP_KERNEL); 2726 if (!dedicated_cache->iolh[i]) 2727 return -ENOMEM; 2728 2729 dedicated_cache->ien[i] = devm_kcalloc(pctrl->dev, n_dedicated_pins, 2730 sizeof(*dedicated_cache->ien[i]), 2731 GFP_KERNEL); 2732 if (!dedicated_cache->ien[i]) 2733 return -ENOMEM; 2734 } 2735 2736 pctrl->cache = cache; 2737 pctrl->dedicated_cache = dedicated_cache; 2738 2739 return 0; 2740 } 2741 2742 static int rzg2l_gpio_register(struct rzg2l_pinctrl *pctrl) 2743 { 2744 struct device_node *np = pctrl->dev->of_node; 2745 struct gpio_chip *chip = &pctrl->gpio_chip; 2746 const char *name = dev_name(pctrl->dev); 2747 struct irq_domain *parent_domain; 2748 struct of_phandle_args of_args; 2749 struct device_node *parent_np; 2750 struct gpio_irq_chip *girq; 2751 int ret; 2752 2753 parent_np = of_irq_find_parent(np); 2754 if (!parent_np) 2755 return -ENXIO; 2756 2757 parent_domain = irq_find_host(parent_np); 2758 of_node_put(parent_np); 2759 if (!parent_domain) 2760 return -EPROBE_DEFER; 2761 2762 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &of_args); 2763 if (ret) 2764 return dev_err_probe(pctrl->dev, ret, "Unable to parse gpio-ranges\n"); 2765 2766 of_node_put(of_args.np); 2767 2768 if (of_args.args[0] != 0 || of_args.args[1] != 0 || 2769 of_args.args[2] != pctrl->data->n_port_pins) 2770 return dev_err_probe(pctrl->dev, -EINVAL, 2771 "gpio-ranges does not match selected SOC\n"); 2772 2773 chip->names = pctrl->data->port_pins; 2774 chip->request = rzg2l_gpio_request; 2775 chip->free = rzg2l_gpio_free; 2776 chip->get_direction = rzg2l_gpio_get_direction; 2777 chip->direction_input = rzg2l_gpio_direction_input; 2778 chip->direction_output = rzg2l_gpio_direction_output; 2779 chip->get = rzg2l_gpio_get; 2780 chip->set = rzg2l_gpio_set; 2781 chip->label = name; 2782 chip->parent = pctrl->dev; 2783 chip->owner = THIS_MODULE; 2784 chip->base = -1; 2785 chip->ngpio = of_args.args[2]; 2786 2787 girq = &chip->irq; 2788 gpio_irq_chip_set_chip(girq, &rzg2l_gpio_irqchip); 2789 girq->fwnode = dev_fwnode(pctrl->dev); 2790 girq->parent_domain = parent_domain; 2791 girq->child_to_parent_hwirq = rzg2l_gpio_child_to_parent_hwirq; 2792 girq->populate_parent_alloc_arg = gpiochip_populate_parent_fwspec_twocell; 2793 girq->child_irq_domain_ops.free = rzg2l_gpio_irq_domain_free; 2794 girq->init_valid_mask = rzg2l_init_irq_valid_mask; 2795 2796 pctrl->gpio_range.id = 0; 2797 pctrl->gpio_range.pin_base = 0; 2798 pctrl->gpio_range.base = 0; 2799 pctrl->gpio_range.npins = chip->ngpio; 2800 pctrl->gpio_range.name = chip->label; 2801 pctrl->gpio_range.gc = chip; 2802 ret = devm_gpiochip_add_data(pctrl->dev, chip, pctrl); 2803 if (ret) 2804 return dev_err_probe(pctrl->dev, ret, "failed to add GPIO controller\n"); 2805 2806 dev_dbg(pctrl->dev, "Registered gpio controller\n"); 2807 2808 return 0; 2809 } 2810 2811 static int rzg2l_pinctrl_register(struct rzg2l_pinctrl *pctrl) 2812 { 2813 const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg; 2814 struct pinctrl_pin_desc *pins; 2815 unsigned int i, j; 2816 u64 *pin_data; 2817 int ret; 2818 2819 pctrl->desc.name = DRV_NAME; 2820 pctrl->desc.npins = pctrl->data->n_port_pins + pctrl->data->n_dedicated_pins; 2821 pctrl->desc.pctlops = &rzg2l_pinctrl_pctlops; 2822 pctrl->desc.pmxops = &rzg2l_pinctrl_pmxops; 2823 pctrl->desc.confops = &rzg2l_pinctrl_confops; 2824 pctrl->desc.owner = THIS_MODULE; 2825 if (pctrl->data->num_custom_params) { 2826 pctrl->desc.num_custom_params = pctrl->data->num_custom_params; 2827 pctrl->desc.custom_params = pctrl->data->custom_params; 2828 #ifdef CONFIG_DEBUG_FS 2829 pctrl->desc.custom_conf_items = pctrl->data->custom_conf_items; 2830 #endif 2831 } 2832 2833 pins = devm_kcalloc(pctrl->dev, pctrl->desc.npins, sizeof(*pins), GFP_KERNEL); 2834 if (!pins) 2835 return -ENOMEM; 2836 2837 pin_data = devm_kcalloc(pctrl->dev, pctrl->desc.npins, 2838 sizeof(*pin_data), GFP_KERNEL); 2839 if (!pin_data) 2840 return -ENOMEM; 2841 2842 pctrl->pins = pins; 2843 pctrl->desc.pins = pins; 2844 2845 for (i = 0, j = 0; i < pctrl->data->n_port_pins; i++) { 2846 pins[i].number = i; 2847 pins[i].name = pctrl->data->port_pins[i]; 2848 if (i && !(i % RZG2L_PINS_PER_PORT)) 2849 j++; 2850 pin_data[i] = pctrl->data->port_pin_configs[j]; 2851 if (pin_data[i] & RZG2L_VARIABLE_CFG) 2852 pin_data[i] = rzg2l_pinctrl_get_variable_pin_cfg(pctrl, 2853 pin_data[i], 2854 j, 2855 i % RZG2L_PINS_PER_PORT); 2856 pins[i].drv_data = &pin_data[i]; 2857 } 2858 2859 for (i = 0; i < pctrl->data->n_dedicated_pins; i++) { 2860 unsigned int index = pctrl->data->n_port_pins + i; 2861 2862 pins[index].number = index; 2863 pins[index].name = pctrl->data->dedicated_pins[i].name; 2864 pin_data[index] = pctrl->data->dedicated_pins[i].config; 2865 pins[index].drv_data = &pin_data[index]; 2866 } 2867 2868 pctrl->settings = devm_kcalloc(pctrl->dev, pctrl->desc.npins, sizeof(*pctrl->settings), 2869 GFP_KERNEL); 2870 if (!pctrl->settings) 2871 return -ENOMEM; 2872 2873 for (i = 0; hwcfg->drive_strength_ua && i < pctrl->desc.npins; i++) { 2874 if (pin_data[i] & PIN_CFG_SOFT_PS) { 2875 pctrl->settings[i].power_source = 3300; 2876 } else { 2877 ret = rzg2l_get_power_source(pctrl, i, pin_data[i]); 2878 if (ret < 0) 2879 continue; 2880 pctrl->settings[i].power_source = ret; 2881 } 2882 } 2883 2884 ret = rzg2l_pinctrl_reg_cache_alloc(pctrl); 2885 if (ret) 2886 return ret; 2887 2888 ret = devm_pinctrl_register_and_init(pctrl->dev, &pctrl->desc, pctrl, 2889 &pctrl->pctl); 2890 if (ret) 2891 return dev_err_probe(pctrl->dev, ret, "pinctrl registration failed\n"); 2892 2893 ret = pinctrl_enable(pctrl->pctl); 2894 if (ret) 2895 return dev_err_probe(pctrl->dev, ret, "pinctrl enable failed\n"); 2896 2897 ret = rzg2l_gpio_register(pctrl); 2898 if (ret) 2899 return dev_err_probe(pctrl->dev, ret, "failed to add GPIO chip\n"); 2900 2901 return 0; 2902 } 2903 2904 static int rzg2l_pinctrl_probe(struct platform_device *pdev) 2905 { 2906 struct rzg2l_pinctrl *pctrl; 2907 int ret; 2908 2909 BUILD_BUG_ON(ARRAY_SIZE(r9a07g044_gpio_configs) * RZG2L_PINS_PER_PORT > 2910 ARRAY_SIZE(rzg2l_gpio_names)); 2911 2912 BUILD_BUG_ON(ARRAY_SIZE(r9a07g043_gpio_configs) * RZG2L_PINS_PER_PORT > 2913 ARRAY_SIZE(rzg2l_gpio_names)); 2914 2915 BUILD_BUG_ON(ARRAY_SIZE(r9a08g045_gpio_configs) * RZG2L_PINS_PER_PORT > 2916 ARRAY_SIZE(rzg2l_gpio_names)); 2917 2918 BUILD_BUG_ON(ARRAY_SIZE(r9a09g047_gpio_configs) * RZG2L_PINS_PER_PORT > 2919 ARRAY_SIZE(rzg3e_gpio_names)); 2920 2921 BUILD_BUG_ON(ARRAY_SIZE(r9a09g057_gpio_configs) * RZG2L_PINS_PER_PORT > 2922 ARRAY_SIZE(rzv2h_gpio_names)); 2923 2924 pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); 2925 if (!pctrl) 2926 return -ENOMEM; 2927 2928 pctrl->dev = &pdev->dev; 2929 2930 pctrl->data = of_device_get_match_data(&pdev->dev); 2931 if (!pctrl->data) 2932 return -EINVAL; 2933 2934 pctrl->base = devm_platform_ioremap_resource(pdev, 0); 2935 if (IS_ERR(pctrl->base)) 2936 return PTR_ERR(pctrl->base); 2937 2938 pctrl->clk = devm_clk_get_enabled(pctrl->dev, NULL); 2939 if (IS_ERR(pctrl->clk)) { 2940 return dev_err_probe(pctrl->dev, PTR_ERR(pctrl->clk), 2941 "failed to enable GPIO clk\n"); 2942 } 2943 2944 spin_lock_init(&pctrl->lock); 2945 spin_lock_init(&pctrl->bitmap_lock); 2946 mutex_init(&pctrl->mutex); 2947 atomic_set(&pctrl->wakeup_path, 0); 2948 2949 platform_set_drvdata(pdev, pctrl); 2950 2951 ret = rzg2l_pinctrl_register(pctrl); 2952 if (ret) 2953 return ret; 2954 2955 dev_info(pctrl->dev, "%s support registered\n", DRV_NAME); 2956 return 0; 2957 } 2958 2959 static void rzg2l_pinctrl_pm_setup_regs(struct rzg2l_pinctrl *pctrl, bool suspend) 2960 { 2961 u32 nports = pctrl->data->n_port_pins / RZG2L_PINS_PER_PORT; 2962 struct rzg2l_pinctrl_reg_cache *cache = pctrl->cache; 2963 2964 for (u32 port = 0; port < nports; port++) { 2965 bool has_iolh, has_ien, has_pupd; 2966 u32 off, caps; 2967 u8 pincnt; 2968 u64 cfg; 2969 2970 cfg = pctrl->data->port_pin_configs[port]; 2971 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(cfg); 2972 pincnt = hweight8(FIELD_GET(PIN_CFG_PIN_MAP_MASK, cfg)); 2973 2974 caps = FIELD_GET(PIN_CFG_MASK, cfg); 2975 has_iolh = !!(caps & (PIN_CFG_IOLH_A | PIN_CFG_IOLH_B | PIN_CFG_IOLH_C)); 2976 has_ien = !!(caps & PIN_CFG_IEN); 2977 has_pupd = !!(caps & PIN_CFG_PUPD); 2978 2979 if (suspend) 2980 RZG2L_PCTRL_REG_ACCESS32(suspend, pctrl->base + PFC(off), cache->pfc[port]); 2981 2982 /* 2983 * Now cache the registers or set them in the order suggested by 2984 * HW manual (section "Operation for GPIO Function"). 2985 */ 2986 RZG2L_PCTRL_REG_ACCESS8(suspend, pctrl->base + PMC(off), cache->pmc[port]); 2987 if (has_iolh) { 2988 RZG2L_PCTRL_REG_ACCESS32(suspend, pctrl->base + IOLH(off), 2989 cache->iolh[0][port]); 2990 if (pincnt >= 4) { 2991 RZG2L_PCTRL_REG_ACCESS32(suspend, pctrl->base + IOLH(off) + 4, 2992 cache->iolh[1][port]); 2993 } 2994 } 2995 2996 if (has_pupd) { 2997 RZG2L_PCTRL_REG_ACCESS32(suspend, pctrl->base + PUPD(off), 2998 cache->pupd[0][port]); 2999 if (pincnt >= 4) { 3000 RZG2L_PCTRL_REG_ACCESS32(suspend, pctrl->base + PUPD(off), 3001 cache->pupd[1][port]); 3002 } 3003 } 3004 3005 RZG2L_PCTRL_REG_ACCESS16(suspend, pctrl->base + PM(off), cache->pm[port]); 3006 RZG2L_PCTRL_REG_ACCESS8(suspend, pctrl->base + P(off), cache->p[port]); 3007 3008 if (has_ien) { 3009 RZG2L_PCTRL_REG_ACCESS32(suspend, pctrl->base + IEN(off), 3010 cache->ien[0][port]); 3011 if (pincnt >= 4) { 3012 RZG2L_PCTRL_REG_ACCESS32(suspend, pctrl->base + IEN(off) + 4, 3013 cache->ien[1][port]); 3014 } 3015 } 3016 } 3017 } 3018 3019 static void rzg2l_pinctrl_pm_setup_dedicated_regs(struct rzg2l_pinctrl *pctrl, bool suspend) 3020 { 3021 struct rzg2l_pinctrl_reg_cache *cache = pctrl->dedicated_cache; 3022 u32 caps; 3023 u32 i; 3024 3025 /* 3026 * Make sure entries in pctrl->data->n_dedicated_pins[] having the same 3027 * port offset are close together. 3028 */ 3029 for (i = 0, caps = 0; i < pctrl->data->n_dedicated_pins; i++) { 3030 bool has_iolh, has_ien; 3031 u32 off, next_off = 0; 3032 u64 cfg, next_cfg; 3033 u8 pincnt; 3034 3035 cfg = pctrl->data->dedicated_pins[i].config; 3036 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(cfg); 3037 if (i + 1 < pctrl->data->n_dedicated_pins) { 3038 next_cfg = pctrl->data->dedicated_pins[i + 1].config; 3039 next_off = RZG2L_PIN_CFG_TO_PORT_OFFSET(next_cfg); 3040 } 3041 3042 if (off == next_off) { 3043 /* Gather caps of all port pins. */ 3044 caps |= FIELD_GET(PIN_CFG_MASK, cfg); 3045 continue; 3046 } 3047 3048 /* And apply them in a single shot. */ 3049 has_iolh = !!(caps & (PIN_CFG_IOLH_A | PIN_CFG_IOLH_B | PIN_CFG_IOLH_C)); 3050 has_ien = !!(caps & PIN_CFG_IEN); 3051 pincnt = hweight8(FIELD_GET(RZG2L_SINGLE_PIN_BITS_MASK, cfg)); 3052 3053 if (has_iolh) { 3054 RZG2L_PCTRL_REG_ACCESS32(suspend, pctrl->base + IOLH(off), 3055 cache->iolh[0][i]); 3056 } 3057 if (has_ien) { 3058 RZG2L_PCTRL_REG_ACCESS32(suspend, pctrl->base + IEN(off), 3059 cache->ien[0][i]); 3060 } 3061 3062 if (pincnt >= 4) { 3063 if (has_iolh) { 3064 RZG2L_PCTRL_REG_ACCESS32(suspend, 3065 pctrl->base + IOLH(off) + 4, 3066 cache->iolh[1][i]); 3067 } 3068 if (has_ien) { 3069 RZG2L_PCTRL_REG_ACCESS32(suspend, 3070 pctrl->base + IEN(off) + 4, 3071 cache->ien[1][i]); 3072 } 3073 } 3074 caps = 0; 3075 } 3076 } 3077 3078 static void rzg2l_pinctrl_pm_setup_pfc(struct rzg2l_pinctrl *pctrl) 3079 { 3080 u32 nports = pctrl->data->n_port_pins / RZG2L_PINS_PER_PORT; 3081 unsigned long flags; 3082 3083 spin_lock_irqsave(&pctrl->lock, flags); 3084 pctrl->data->pwpr_pfc_lock_unlock(pctrl, false); 3085 3086 /* Restore port registers. */ 3087 for (u32 port = 0; port < nports; port++) { 3088 unsigned long pinmap; 3089 u8 pmc = 0, max_pin; 3090 u32 off, pfc = 0; 3091 u64 cfg; 3092 u16 pm; 3093 u8 pin; 3094 3095 cfg = pctrl->data->port_pin_configs[port]; 3096 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(cfg); 3097 pinmap = FIELD_GET(PIN_CFG_PIN_MAP_MASK, cfg); 3098 max_pin = fls(pinmap); 3099 3100 pm = readw(pctrl->base + PM(off)); 3101 for_each_set_bit(pin, &pinmap, max_pin) { 3102 struct rzg2l_pinctrl_reg_cache *cache = pctrl->cache; 3103 3104 /* Nothing to do if PFC was not configured before. */ 3105 if (!(cache->pmc[port] & BIT(pin))) 3106 continue; 3107 3108 /* Set pin to 'Non-use (Hi-Z input protection)' */ 3109 pm &= ~(PM_MASK << (pin * 2)); 3110 writew(pm, pctrl->base + PM(off)); 3111 3112 /* Temporarily switch to GPIO mode with PMC register */ 3113 pmc &= ~BIT(pin); 3114 writeb(pmc, pctrl->base + PMC(off)); 3115 3116 /* Select Pin function mode. */ 3117 pfc &= ~(PFC_MASK << (pin * 4)); 3118 pfc |= (cache->pfc[port] & (PFC_MASK << (pin * 4))); 3119 writel(pfc, pctrl->base + PFC(off)); 3120 3121 /* Switch to Peripheral pin function. */ 3122 pmc |= BIT(pin); 3123 writeb(pmc, pctrl->base + PMC(off)); 3124 } 3125 } 3126 3127 pctrl->data->pwpr_pfc_lock_unlock(pctrl, true); 3128 spin_unlock_irqrestore(&pctrl->lock, flags); 3129 } 3130 3131 static int rzg2l_pinctrl_suspend_noirq(struct device *dev) 3132 { 3133 struct rzg2l_pinctrl *pctrl = dev_get_drvdata(dev); 3134 const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg; 3135 const struct rzg2l_register_offsets *regs = &hwcfg->regs; 3136 struct rzg2l_pinctrl_reg_cache *cache = pctrl->cache; 3137 3138 rzg2l_pinctrl_pm_setup_regs(pctrl, true); 3139 rzg2l_pinctrl_pm_setup_dedicated_regs(pctrl, true); 3140 3141 for (u8 i = 0; i < 2; i++) { 3142 if (regs->sd_ch) 3143 cache->sd_ch[i] = readb(pctrl->base + SD_CH(regs->sd_ch, i)); 3144 if (regs->eth_poc) 3145 cache->eth_poc[i] = readb(pctrl->base + ETH_POC(regs->eth_poc, i)); 3146 } 3147 3148 cache->qspi = readb(pctrl->base + QSPI); 3149 cache->eth_mode = readb(pctrl->base + ETH_MODE); 3150 3151 if (!atomic_read(&pctrl->wakeup_path)) 3152 clk_disable_unprepare(pctrl->clk); 3153 else 3154 device_set_wakeup_path(dev); 3155 3156 return 0; 3157 } 3158 3159 static int rzg2l_pinctrl_resume_noirq(struct device *dev) 3160 { 3161 struct rzg2l_pinctrl *pctrl = dev_get_drvdata(dev); 3162 const struct rzg2l_hwcfg *hwcfg = pctrl->data->hwcfg; 3163 const struct rzg2l_register_offsets *regs = &hwcfg->regs; 3164 struct rzg2l_pinctrl_reg_cache *cache = pctrl->cache; 3165 int ret; 3166 3167 if (!atomic_read(&pctrl->wakeup_path)) { 3168 ret = clk_prepare_enable(pctrl->clk); 3169 if (ret) 3170 return ret; 3171 } 3172 3173 writeb(cache->qspi, pctrl->base + QSPI); 3174 writeb(cache->eth_mode, pctrl->base + ETH_MODE); 3175 for (u8 i = 0; i < 2; i++) { 3176 if (regs->sd_ch) 3177 writeb(cache->sd_ch[i], pctrl->base + SD_CH(regs->sd_ch, i)); 3178 if (regs->eth_poc) 3179 writeb(cache->eth_poc[i], pctrl->base + ETH_POC(regs->eth_poc, i)); 3180 } 3181 3182 rzg2l_pinctrl_pm_setup_pfc(pctrl); 3183 rzg2l_pinctrl_pm_setup_regs(pctrl, false); 3184 rzg2l_pinctrl_pm_setup_dedicated_regs(pctrl, false); 3185 rzg2l_gpio_irq_restore(pctrl); 3186 3187 return 0; 3188 } 3189 3190 static void rzg2l_pwpr_pfc_lock_unlock(struct rzg2l_pinctrl *pctrl, bool lock) 3191 { 3192 const struct rzg2l_register_offsets *regs = &pctrl->data->hwcfg->regs; 3193 3194 if (lock) { 3195 /* Set the PWPR register to be write-protected */ 3196 writel(0x0, pctrl->base + regs->pwpr); /* B0WI=0, PFCWE=0 */ 3197 writel(PWPR_B0WI, pctrl->base + regs->pwpr); /* B0WI=1, PFCWE=0 */ 3198 } else { 3199 /* Set the PWPR register to allow PFC register to write */ 3200 writel(0x0, pctrl->base + regs->pwpr); /* B0WI=0, PFCWE=0 */ 3201 writel(PWPR_PFCWE, pctrl->base + regs->pwpr); /* B0WI=0, PFCWE=1 */ 3202 } 3203 } 3204 3205 static void rzv2h_pwpr_pfc_lock_unlock(struct rzg2l_pinctrl *pctrl, bool lock) 3206 { 3207 const struct rzg2l_register_offsets *regs = &pctrl->data->hwcfg->regs; 3208 u8 pwpr; 3209 3210 if (lock) { 3211 /* Set the PWPR register to be write-protected */ 3212 pwpr = readb(pctrl->base + regs->pwpr); 3213 writeb(pwpr & ~PWPR_REGWE_A, pctrl->base + regs->pwpr); 3214 } else { 3215 /* Set the PWPR register to allow PFC and PMC register to write */ 3216 pwpr = readb(pctrl->base + regs->pwpr); 3217 writeb(PWPR_REGWE_A | pwpr, pctrl->base + regs->pwpr); 3218 } 3219 } 3220 3221 static const struct rzg2l_hwcfg rzg2l_hwcfg = { 3222 .regs = { 3223 .pwpr = 0x3014, 3224 .sd_ch = 0x3000, 3225 .eth_poc = 0x300c, 3226 }, 3227 .iolh_groupa_ua = { 3228 /* 3v3 power source */ 3229 [RZG2L_IOLH_IDX_3V3] = 2000, 4000, 8000, 12000, 3230 }, 3231 .iolh_groupb_oi = { 100, 66, 50, 33, }, 3232 .tint_start_index = 9, 3233 .oen_max_pin = 0, 3234 }; 3235 3236 static const struct rzg2l_hwcfg rzg3s_hwcfg = { 3237 .regs = { 3238 .pwpr = 0x3000, 3239 .sd_ch = 0x3004, 3240 .eth_poc = 0x3010, 3241 }, 3242 .iolh_groupa_ua = { 3243 /* 1v8 power source */ 3244 [RZG2L_IOLH_IDX_1V8] = 2200, 4400, 9000, 10000, 3245 /* 3v3 power source */ 3246 [RZG2L_IOLH_IDX_3V3] = 1900, 4000, 8000, 9000, 3247 }, 3248 .iolh_groupb_ua = { 3249 /* 1v8 power source */ 3250 [RZG2L_IOLH_IDX_1V8] = 7000, 8000, 9000, 10000, 3251 /* 3v3 power source */ 3252 [RZG2L_IOLH_IDX_3V3] = 4000, 6000, 8000, 9000, 3253 }, 3254 .iolh_groupc_ua = { 3255 /* 1v8 power source */ 3256 [RZG2L_IOLH_IDX_1V8] = 5200, 6000, 6550, 6800, 3257 /* 2v5 source */ 3258 [RZG2L_IOLH_IDX_2V5] = 4700, 5300, 5800, 6100, 3259 /* 3v3 power source */ 3260 [RZG2L_IOLH_IDX_3V3] = 4500, 5200, 5700, 6050, 3261 }, 3262 .tint_start_index = 9, 3263 .drive_strength_ua = true, 3264 .func_base = 1, 3265 .oen_max_pin = 1, /* Pin 1 of P0 and P7 is the maximum OEN pin. */ 3266 .oen_max_port = 7, /* P7_1 is the maximum OEN port. */ 3267 }; 3268 3269 static const struct rzg2l_hwcfg rzv2h_hwcfg = { 3270 .regs = { 3271 .pwpr = 0x3c04, 3272 }, 3273 .tint_start_index = 17, 3274 }; 3275 3276 static struct rzg2l_pinctrl_data r9a07g043_data = { 3277 .port_pins = rzg2l_gpio_names, 3278 .port_pin_configs = r9a07g043_gpio_configs, 3279 .n_ports = ARRAY_SIZE(r9a07g043_gpio_configs), 3280 .dedicated_pins = rzg2l_dedicated_pins.common, 3281 .n_port_pins = ARRAY_SIZE(r9a07g043_gpio_configs) * RZG2L_PINS_PER_PORT, 3282 .n_dedicated_pins = ARRAY_SIZE(rzg2l_dedicated_pins.common), 3283 .hwcfg = &rzg2l_hwcfg, 3284 #ifdef CONFIG_RISCV 3285 .variable_pin_cfg = r9a07g043f_variable_pin_cfg, 3286 .n_variable_pin_cfg = ARRAY_SIZE(r9a07g043f_variable_pin_cfg), 3287 #endif 3288 .pwpr_pfc_lock_unlock = &rzg2l_pwpr_pfc_lock_unlock, 3289 .pmc_writeb = &rzg2l_pmc_writeb, 3290 .oen_read = &rzg2l_read_oen, 3291 .oen_write = &rzg2l_write_oen, 3292 .hw_to_bias_param = &rzg2l_hw_to_bias_param, 3293 .bias_param_to_hw = &rzg2l_bias_param_to_hw, 3294 }; 3295 3296 static struct rzg2l_pinctrl_data r9a07g044_data = { 3297 .port_pins = rzg2l_gpio_names, 3298 .port_pin_configs = r9a07g044_gpio_configs, 3299 .n_ports = ARRAY_SIZE(r9a07g044_gpio_configs), 3300 .dedicated_pins = rzg2l_dedicated_pins.common, 3301 .n_port_pins = ARRAY_SIZE(r9a07g044_gpio_configs) * RZG2L_PINS_PER_PORT, 3302 .n_dedicated_pins = ARRAY_SIZE(rzg2l_dedicated_pins.common) + 3303 ARRAY_SIZE(rzg2l_dedicated_pins.rzg2l_pins), 3304 .hwcfg = &rzg2l_hwcfg, 3305 .pwpr_pfc_lock_unlock = &rzg2l_pwpr_pfc_lock_unlock, 3306 .pmc_writeb = &rzg2l_pmc_writeb, 3307 .oen_read = &rzg2l_read_oen, 3308 .oen_write = &rzg2l_write_oen, 3309 .hw_to_bias_param = &rzg2l_hw_to_bias_param, 3310 .bias_param_to_hw = &rzg2l_bias_param_to_hw, 3311 }; 3312 3313 static struct rzg2l_pinctrl_data r9a08g045_data = { 3314 .port_pins = rzg2l_gpio_names, 3315 .port_pin_configs = r9a08g045_gpio_configs, 3316 .n_ports = ARRAY_SIZE(r9a08g045_gpio_configs), 3317 .dedicated_pins = rzg3s_dedicated_pins, 3318 .n_port_pins = ARRAY_SIZE(r9a08g045_gpio_configs) * RZG2L_PINS_PER_PORT, 3319 .n_dedicated_pins = ARRAY_SIZE(rzg3s_dedicated_pins), 3320 .hwcfg = &rzg3s_hwcfg, 3321 .pwpr_pfc_lock_unlock = &rzg2l_pwpr_pfc_lock_unlock, 3322 .pmc_writeb = &rzg2l_pmc_writeb, 3323 .oen_read = &rzg3s_oen_read, 3324 .oen_write = &rzg3s_oen_write, 3325 .hw_to_bias_param = &rzg2l_hw_to_bias_param, 3326 .bias_param_to_hw = &rzg2l_bias_param_to_hw, 3327 }; 3328 3329 static struct rzg2l_pinctrl_data r9a09g047_data = { 3330 .port_pins = rzg3e_gpio_names, 3331 .port_pin_configs = r9a09g047_gpio_configs, 3332 .n_ports = ARRAY_SIZE(r9a09g047_gpio_configs), 3333 .dedicated_pins = rzg3e_dedicated_pins, 3334 .n_port_pins = ARRAY_SIZE(r9a09g047_gpio_configs) * RZG2L_PINS_PER_PORT, 3335 .n_dedicated_pins = ARRAY_SIZE(rzg3e_dedicated_pins), 3336 .hwcfg = &rzv2h_hwcfg, 3337 .variable_pin_cfg = r9a09g047_variable_pin_cfg, 3338 .n_variable_pin_cfg = ARRAY_SIZE(r9a09g047_variable_pin_cfg), 3339 .num_custom_params = ARRAY_SIZE(renesas_rzv2h_custom_bindings), 3340 .custom_params = renesas_rzv2h_custom_bindings, 3341 #ifdef CONFIG_DEBUG_FS 3342 .custom_conf_items = renesas_rzv2h_conf_items, 3343 #endif 3344 .pwpr_pfc_lock_unlock = &rzv2h_pwpr_pfc_lock_unlock, 3345 .pmc_writeb = &rzv2h_pmc_writeb, 3346 .oen_read = &rzv2h_oen_read, 3347 .oen_write = &rzv2h_oen_write, 3348 .hw_to_bias_param = &rzv2h_hw_to_bias_param, 3349 .bias_param_to_hw = &rzv2h_bias_param_to_hw, 3350 }; 3351 3352 static struct rzg2l_pinctrl_data r9a09g057_data = { 3353 .port_pins = rzv2h_gpio_names, 3354 .port_pin_configs = r9a09g057_gpio_configs, 3355 .n_ports = ARRAY_SIZE(r9a09g057_gpio_configs), 3356 .dedicated_pins = rzv2h_dedicated_pins, 3357 .n_port_pins = ARRAY_SIZE(r9a09g057_gpio_configs) * RZG2L_PINS_PER_PORT, 3358 .n_dedicated_pins = ARRAY_SIZE(rzv2h_dedicated_pins), 3359 .hwcfg = &rzv2h_hwcfg, 3360 .variable_pin_cfg = r9a09g057_variable_pin_cfg, 3361 .n_variable_pin_cfg = ARRAY_SIZE(r9a09g057_variable_pin_cfg), 3362 .num_custom_params = ARRAY_SIZE(renesas_rzv2h_custom_bindings), 3363 .custom_params = renesas_rzv2h_custom_bindings, 3364 #ifdef CONFIG_DEBUG_FS 3365 .custom_conf_items = renesas_rzv2h_conf_items, 3366 #endif 3367 .pwpr_pfc_lock_unlock = &rzv2h_pwpr_pfc_lock_unlock, 3368 .pmc_writeb = &rzv2h_pmc_writeb, 3369 .oen_read = &rzv2h_oen_read, 3370 .oen_write = &rzv2h_oen_write, 3371 .hw_to_bias_param = &rzv2h_hw_to_bias_param, 3372 .bias_param_to_hw = &rzv2h_bias_param_to_hw, 3373 }; 3374 3375 static const struct of_device_id rzg2l_pinctrl_of_table[] = { 3376 { 3377 .compatible = "renesas,r9a07g043-pinctrl", 3378 .data = &r9a07g043_data, 3379 }, 3380 { 3381 .compatible = "renesas,r9a07g044-pinctrl", 3382 .data = &r9a07g044_data, 3383 }, 3384 { 3385 .compatible = "renesas,r9a08g045-pinctrl", 3386 .data = &r9a08g045_data, 3387 }, 3388 { 3389 .compatible = "renesas,r9a09g047-pinctrl", 3390 .data = &r9a09g047_data, 3391 }, 3392 { 3393 .compatible = "renesas,r9a09g057-pinctrl", 3394 .data = &r9a09g057_data, 3395 }, 3396 { /* sentinel */ } 3397 }; 3398 3399 static const struct dev_pm_ops rzg2l_pinctrl_pm_ops = { 3400 NOIRQ_SYSTEM_SLEEP_PM_OPS(rzg2l_pinctrl_suspend_noirq, rzg2l_pinctrl_resume_noirq) 3401 }; 3402 3403 static struct platform_driver rzg2l_pinctrl_driver = { 3404 .driver = { 3405 .name = DRV_NAME, 3406 .of_match_table = of_match_ptr(rzg2l_pinctrl_of_table), 3407 .pm = pm_sleep_ptr(&rzg2l_pinctrl_pm_ops), 3408 .suppress_bind_attrs = true, 3409 }, 3410 .probe = rzg2l_pinctrl_probe, 3411 }; 3412 3413 static int __init rzg2l_pinctrl_init(void) 3414 { 3415 return platform_driver_register(&rzg2l_pinctrl_driver); 3416 } 3417 core_initcall(rzg2l_pinctrl_init); 3418 3419 MODULE_AUTHOR("Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>"); 3420 MODULE_DESCRIPTION("Pin and gpio controller driver for RZ/G2L family"); 3421