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