David Wu | e7ae4cf | 2019-01-02 21:00:55 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2019 Rockchip Electronics Co., Ltd |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <dm/pinctrl.h> |
| 9 | #include <regmap.h> |
David Wu | e7ae4cf | 2019-01-02 21:00:55 +0800 | [diff] [blame] | 10 | |
| 11 | #include "pinctrl-rockchip.h" |
| 12 | |
| 13 | static struct rockchip_mux_route_data rk3288_mux_route_data[] = { |
| 14 | { |
| 15 | /* edphdmi_cecinoutt1 */ |
| 16 | .bank_num = 7, |
| 17 | .pin = 16, |
| 18 | .func = 2, |
| 19 | .route_offset = 0x264, |
| 20 | .route_val = BIT(16 + 12) | BIT(12), |
| 21 | }, { |
| 22 | /* edphdmi_cecinout */ |
| 23 | .bank_num = 7, |
| 24 | .pin = 23, |
| 25 | .func = 4, |
| 26 | .route_offset = 0x264, |
| 27 | .route_val = BIT(16 + 12), |
| 28 | }, |
| 29 | }; |
| 30 | |
David Wu | 54e7570 | 2019-04-16 21:50:55 +0800 | [diff] [blame^] | 31 | static int rk3288_set_mux(struct rockchip_pin_bank *bank, int pin, int mux) |
| 32 | { |
| 33 | struct rockchip_pinctrl_priv *priv = bank->priv; |
| 34 | int iomux_num = (pin / 8); |
| 35 | struct regmap *regmap; |
| 36 | int reg, ret, mask, mux_type; |
| 37 | u8 bit; |
| 38 | u32 data, route_reg, route_val; |
| 39 | |
| 40 | regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU) |
| 41 | ? priv->regmap_pmu : priv->regmap_base; |
| 42 | |
| 43 | /* get basic quadrupel of mux registers and the correct reg inside */ |
| 44 | mux_type = bank->iomux[iomux_num].type; |
| 45 | reg = bank->iomux[iomux_num].offset; |
| 46 | reg += rockchip_get_mux_data(mux_type, pin, &bit, &mask); |
| 47 | |
| 48 | if (bank->route_mask & BIT(pin)) { |
| 49 | if (rockchip_get_mux_route(bank, pin, mux, &route_reg, |
| 50 | &route_val)) { |
| 51 | ret = regmap_write(regmap, route_reg, route_val); |
| 52 | if (ret) |
| 53 | return ret; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | data = (mask << (bit + 16)); |
| 58 | data |= (mux & mask) << bit; |
| 59 | ret = regmap_write(regmap, reg, data); |
| 60 | |
| 61 | return ret; |
| 62 | } |
| 63 | |
David Wu | e7ae4cf | 2019-01-02 21:00:55 +0800 | [diff] [blame] | 64 | #define RK3288_PULL_OFFSET 0x140 |
| 65 | #define RK3288_PULL_PMU_OFFSET 0x64 |
| 66 | |
| 67 | static void rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, |
| 68 | int pin_num, struct regmap **regmap, |
| 69 | int *reg, u8 *bit) |
| 70 | { |
| 71 | struct rockchip_pinctrl_priv *priv = bank->priv; |
| 72 | |
| 73 | /* The first 24 pins of the first bank are located in PMU */ |
| 74 | if (bank->bank_num == 0) { |
| 75 | *regmap = priv->regmap_pmu; |
| 76 | *reg = RK3288_PULL_PMU_OFFSET; |
| 77 | |
| 78 | *reg += ((pin_num / ROCKCHIP_PULL_PINS_PER_REG) * 4); |
| 79 | *bit = pin_num % ROCKCHIP_PULL_PINS_PER_REG; |
| 80 | *bit *= ROCKCHIP_PULL_BITS_PER_PIN; |
| 81 | } else { |
| 82 | *regmap = priv->regmap_base; |
| 83 | *reg = RK3288_PULL_OFFSET; |
| 84 | |
| 85 | /* correct the offset, as we're starting with the 2nd bank */ |
| 86 | *reg -= 0x10; |
| 87 | *reg += bank->bank_num * ROCKCHIP_PULL_BANK_STRIDE; |
| 88 | *reg += ((pin_num / ROCKCHIP_PULL_PINS_PER_REG) * 4); |
| 89 | |
| 90 | *bit = (pin_num % ROCKCHIP_PULL_PINS_PER_REG); |
| 91 | *bit *= ROCKCHIP_PULL_BITS_PER_PIN; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | #define RK3288_DRV_PMU_OFFSET 0x70 |
| 96 | #define RK3288_DRV_GRF_OFFSET 0x1c0 |
| 97 | |
| 98 | static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, |
| 99 | int pin_num, struct regmap **regmap, |
| 100 | int *reg, u8 *bit) |
| 101 | { |
| 102 | struct rockchip_pinctrl_priv *priv = bank->priv; |
| 103 | |
| 104 | /* The first 24 pins of the first bank are located in PMU */ |
| 105 | if (bank->bank_num == 0) { |
| 106 | *regmap = priv->regmap_pmu; |
| 107 | *reg = RK3288_DRV_PMU_OFFSET; |
| 108 | |
| 109 | *reg += ((pin_num / ROCKCHIP_DRV_PINS_PER_REG) * 4); |
| 110 | *bit = pin_num % ROCKCHIP_DRV_PINS_PER_REG; |
| 111 | *bit *= ROCKCHIP_DRV_BITS_PER_PIN; |
| 112 | } else { |
| 113 | *regmap = priv->regmap_base; |
| 114 | *reg = RK3288_DRV_GRF_OFFSET; |
| 115 | |
| 116 | /* correct the offset, as we're starting with the 2nd bank */ |
| 117 | *reg -= 0x10; |
| 118 | *reg += bank->bank_num * ROCKCHIP_DRV_BANK_STRIDE; |
| 119 | *reg += ((pin_num / ROCKCHIP_DRV_PINS_PER_REG) * 4); |
| 120 | |
| 121 | *bit = (pin_num % ROCKCHIP_DRV_PINS_PER_REG); |
| 122 | *bit *= ROCKCHIP_DRV_BITS_PER_PIN; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | static struct rockchip_pin_bank rk3288_pin_banks[] = { |
Kever Yang | cc325e4 | 2019-05-07 09:36:32 +0800 | [diff] [blame] | 127 | PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU, |
| 128 | IOMUX_SOURCE_PMU, |
| 129 | IOMUX_SOURCE_PMU, |
| 130 | IOMUX_UNROUTED |
David Wu | e7ae4cf | 2019-01-02 21:00:55 +0800 | [diff] [blame] | 131 | ), |
| 132 | PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED, |
| 133 | IOMUX_UNROUTED, |
| 134 | IOMUX_UNROUTED, |
| 135 | 0 |
| 136 | ), |
| 137 | PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED), |
| 138 | PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT), |
| 139 | PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT, |
| 140 | IOMUX_WIDTH_4BIT, |
| 141 | 0, |
| 142 | 0 |
| 143 | ), |
| 144 | PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED, |
| 145 | 0, |
| 146 | 0, |
| 147 | IOMUX_UNROUTED |
| 148 | ), |
| 149 | PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED), |
| 150 | PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0, |
| 151 | 0, |
| 152 | IOMUX_WIDTH_4BIT, |
| 153 | IOMUX_UNROUTED |
| 154 | ), |
| 155 | PIN_BANK(8, 16, "gpio8"), |
| 156 | }; |
| 157 | |
| 158 | static struct rockchip_pin_ctrl rk3288_pin_ctrl = { |
David Wu | 8541beb | 2019-04-16 21:50:54 +0800 | [diff] [blame] | 159 | .pin_banks = rk3288_pin_banks, |
| 160 | .nr_banks = ARRAY_SIZE(rk3288_pin_banks), |
| 161 | .label = "RK3288-GPIO", |
| 162 | .type = RK3288, |
| 163 | .grf_mux_offset = 0x0, |
| 164 | .pmu_mux_offset = 0x84, |
| 165 | .iomux_routes = rk3288_mux_route_data, |
| 166 | .niomux_routes = ARRAY_SIZE(rk3288_mux_route_data), |
David Wu | 54e7570 | 2019-04-16 21:50:55 +0800 | [diff] [blame^] | 167 | .set_mux = rk3288_set_mux, |
David Wu | 8541beb | 2019-04-16 21:50:54 +0800 | [diff] [blame] | 168 | .pull_calc_reg = rk3288_calc_pull_reg_and_bit, |
| 169 | .drv_calc_reg = rk3288_calc_drv_reg_and_bit, |
David Wu | e7ae4cf | 2019-01-02 21:00:55 +0800 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | static const struct udevice_id rk3288_pinctrl_ids[] = { |
| 173 | { |
| 174 | .compatible = "rockchip,rk3288-pinctrl", |
| 175 | .data = (ulong)&rk3288_pin_ctrl |
| 176 | }, |
| 177 | { } |
| 178 | }; |
| 179 | |
| 180 | U_BOOT_DRIVER(pinctrl_rk3288) = { |
| 181 | .name = "rockchip_rk3288_pinctrl", |
| 182 | .id = UCLASS_PINCTRL, |
| 183 | .of_match = rk3288_pinctrl_ids, |
| 184 | .priv_auto_alloc_size = sizeof(struct rockchip_pinctrl_priv), |
| 185 | .ops = &rockchip_pinctrl_ops, |
| 186 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
| 187 | .bind = dm_scan_fdt_dev, |
| 188 | #endif |
| 189 | .probe = rockchip_pinctrl_probe, |
| 190 | }; |