Paul Barker | 6b8b56e | 2023-10-16 10:25:32 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * RZ/G2L Pin Function Controller |
| 4 | * |
| 5 | * Copyright (C) 2021-2023 Renesas Electronics Corp. |
| 6 | */ |
| 7 | |
| 8 | #ifndef RENESAS_RZG2L_PFC_H |
| 9 | #define RENESAS_RZG2L_PFC_H |
| 10 | |
| 11 | /* PIN capabilities */ |
| 12 | #define PIN_CFG_IOLH_A BIT(0) |
| 13 | #define PIN_CFG_IOLH_B BIT(1) |
| 14 | #define PIN_CFG_SR BIT(2) |
| 15 | #define PIN_CFG_IEN BIT(3) |
| 16 | #define PIN_CFG_PUPD BIT(4) |
| 17 | #define PIN_CFG_IO_VMC_SD0 BIT(5) |
| 18 | #define PIN_CFG_IO_VMC_SD1 BIT(6) |
| 19 | #define PIN_CFG_IO_VMC_QSPI BIT(7) |
| 20 | #define PIN_CFG_IO_VMC_ETH0 BIT(8) |
| 21 | #define PIN_CFG_IO_VMC_ETH1 BIT(9) |
| 22 | #define PIN_CFG_FILONOFF BIT(10) |
| 23 | #define PIN_CFG_FILNUM BIT(11) |
| 24 | #define PIN_CFG_FILCLKSEL BIT(12) |
Paul Barker | 27a7a16 | 2024-11-20 09:48:29 +0000 | [diff] [blame] | 25 | #define PIN_CFG_OEN BIT(13) |
Paul Barker | 6b8b56e | 2023-10-16 10:25:32 +0100 | [diff] [blame] | 26 | |
| 27 | #define RZG2L_MPXED_PIN_FUNCS (PIN_CFG_IOLH_A | \ |
| 28 | PIN_CFG_SR | \ |
| 29 | PIN_CFG_PUPD | \ |
| 30 | PIN_CFG_FILONOFF | \ |
| 31 | PIN_CFG_FILNUM | \ |
| 32 | PIN_CFG_FILCLKSEL) |
| 33 | |
| 34 | #define RZG2L_MPXED_ETH_PIN_FUNCS(x) ((x) | \ |
| 35 | PIN_CFG_FILONOFF | \ |
| 36 | PIN_CFG_FILNUM | \ |
| 37 | PIN_CFG_FILCLKSEL) |
| 38 | |
| 39 | /* GPIO port data macros: |
| 40 | * n indicates number of pins in the port, a is the register index |
| 41 | * and f is pin configuration capabilities supported. |
| 42 | */ |
| 43 | #define RZG2L_GPIO_PORT_PACK(n, a, f) (((n) << 28) | ((a) << 20) | (f)) |
| 44 | #define RZG2L_GPIO_PORT_GET_PINCNT(x) (((x) & GENMASK(30, 28)) >> 28) |
| 45 | #define RZG2L_GPIO_PORT_GET_INDEX(x) (((x) & GENMASK(26, 20)) >> 20) |
| 46 | #define RZG2L_GPIO_PORT_GET_CFGS(x) ((x) & GENMASK(19, 0)) |
| 47 | |
| 48 | /* Dedicated pin data macros: |
| 49 | * BIT(31) indicates dedicated pin, p is the register index while |
| 50 | * referencing to SR/IEN/IOLH/FILxx registers, b is the register bits |
| 51 | * (b * 8) and f is the pin configuration capabilities supported. |
| 52 | */ |
| 53 | #define RZG2L_SINGLE_PIN BIT(31) |
| 54 | #define RZG2L_SINGLE_PIN_PACK(p, b, f) (RZG2L_SINGLE_PIN | \ |
| 55 | ((p) << 24) | ((b) << 20) | (f)) |
| 56 | #define RZG2L_SINGLE_PIN_GET_PORT_OFFSET(x) (((x) & GENMASK(30, 24)) >> 24) |
| 57 | #define RZG2L_SINGLE_PIN_GET_BIT(x) (((x) & GENMASK(22, 20)) >> 20) |
| 58 | #define RZG2L_SINGLE_PIN_GET_CFGS(x) ((x) & GENMASK(19, 0)) |
| 59 | |
| 60 | /* Pinmux data encoded in the device tree uses: |
| 61 | * 16 lower bits [15:0] for pin identifier |
| 62 | * 16 higher bits [31:16] for pin mux function |
| 63 | */ |
| 64 | #define MUX_PIN_ID_MASK GENMASK(15, 0) |
| 65 | #define MUX_FUNC_MASK GENMASK(31, 16) |
| 66 | #define RZG2L_PINS_PER_PORT 8 |
| 67 | #define RZG2L_PINMUX_TO_PORT(conf) (((conf) & MUX_PIN_ID_MASK) / RZG2L_PINS_PER_PORT) |
| 68 | #define RZG2L_PINMUX_TO_PIN(conf) (((conf) & MUX_PIN_ID_MASK) % RZG2L_PINS_PER_PORT) |
| 69 | #define RZG2L_PINMUX_TO_FUNC(conf) (((conf) & MUX_FUNC_MASK) >> 16) |
| 70 | |
| 71 | /* Register offsets and values. */ |
| 72 | #define P(n) (0x0000 + 0x10 + (n)) |
| 73 | #define PM(n) (0x0100 + 0x20 + (n) * 2) |
| 74 | #define PMC(n) (0x0200 + 0x10 + (n)) |
| 75 | #define PFC(n) (0x0400 + 0x40 + (n) * 4) |
| 76 | #define PIN(n) (0x0800 + 0x10 + (n)) |
| 77 | #define IOLH(n) (0x1000 + (n) * 8) |
| 78 | #define IEN(n) (0x1800 + (n) * 8) |
| 79 | #define PWPR 0x3014 |
| 80 | #define SD_CH(n) (0x3000 + (n) * 4) |
Paul Barker | d4dc510 | 2024-11-20 09:48:28 +0000 | [diff] [blame] | 81 | #define ETH_POC(ch) (0x300c + (ch) * 4) |
Paul Barker | 6b8b56e | 2023-10-16 10:25:32 +0100 | [diff] [blame] | 82 | #define QSPI 0x3008 |
Paul Barker | 27a7a16 | 2024-11-20 09:48:29 +0000 | [diff] [blame] | 83 | #define ETH_MODE 0x3018 |
Paul Barker | 6b8b56e | 2023-10-16 10:25:32 +0100 | [diff] [blame] | 84 | |
| 85 | #define PVDD_1800 1 /* I/O domain voltage <= 1.8V */ |
Paul Barker | d4dc510 | 2024-11-20 09:48:28 +0000 | [diff] [blame] | 86 | #define PVDD_2500 2 /* I/O domain voltage 2.5V */ |
Paul Barker | 6b8b56e | 2023-10-16 10:25:32 +0100 | [diff] [blame] | 87 | #define PVDD_3300 0 /* I/O domain voltage >= 3.3V */ |
| 88 | |
| 89 | #define PWPR_B0WI BIT(7) /* Bit Write Disable */ |
| 90 | #define PWPR_PFCWE BIT(6) /* PFC Register Write Enable */ |
| 91 | |
| 92 | #define PM_MASK 0x03 |
| 93 | #define PVDD_MASK 0x01 |
| 94 | #define PFC_MASK 0x07 |
| 95 | #define IEN_MASK 0x01 |
| 96 | #define IOLH_MASK 0x03 |
| 97 | |
| 98 | #define PM_HIGH_Z 0x0 |
| 99 | #define PM_INPUT 0x1 |
| 100 | #define PM_OUTPUT 0x2 |
| 101 | #define PM_OUTPUT_IEN 0x3 |
| 102 | |
| 103 | struct rzg2l_pfc_data { |
| 104 | void __iomem *base; |
| 105 | uint num_dedicated_pins; |
| 106 | uint num_ports; |
| 107 | uint num_pins; |
| 108 | const u32 *gpio_configs; |
| 109 | }; |
| 110 | |
| 111 | int rzg2l_pfc_enable(struct udevice *dev); |
| 112 | bool rzg2l_port_validate(const struct rzg2l_pfc_data *data, u32 port, u8 pin); |
| 113 | |
| 114 | #endif /* RENESAS_RZG2L_PFC_H */ |