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 | #ifndef __DRIVERS_PINCTRL_ROCKCHIP_H |
| 7 | #define __DRIVERS_PINCTRL_ROCKCHIP_H |
| 8 | |
| 9 | #include <linux/types.h> |
| 10 | |
David Wu | e7ae4cf | 2019-01-02 21:00:55 +0800 | [diff] [blame] | 11 | /** |
| 12 | * Encode variants of iomux registers into a type variable |
| 13 | */ |
| 14 | #define IOMUX_GPIO_ONLY BIT(0) |
| 15 | #define IOMUX_WIDTH_4BIT BIT(1) |
| 16 | #define IOMUX_SOURCE_PMU BIT(2) |
| 17 | #define IOMUX_UNROUTED BIT(3) |
| 18 | #define IOMUX_WIDTH_3BIT BIT(4) |
| 19 | |
| 20 | /** |
| 21 | * Defined some common pins constants |
| 22 | */ |
| 23 | #define ROCKCHIP_PULL_BITS_PER_PIN 2 |
| 24 | #define ROCKCHIP_PULL_PINS_PER_REG 8 |
| 25 | #define ROCKCHIP_PULL_BANK_STRIDE 16 |
| 26 | #define ROCKCHIP_DRV_BITS_PER_PIN 2 |
| 27 | #define ROCKCHIP_DRV_PINS_PER_REG 8 |
| 28 | #define ROCKCHIP_DRV_BANK_STRIDE 16 |
| 29 | #define ROCKCHIP_DRV_3BITS_PER_PIN 3 |
| 30 | |
| 31 | /** |
| 32 | * @type: iomux variant using IOMUX_* constants |
| 33 | * @offset: if initialized to -1 it will be autocalculated, by specifying |
| 34 | * an initial offset value the relevant source offset can be reset |
| 35 | * to a new value for autocalculating the following iomux registers. |
| 36 | */ |
| 37 | struct rockchip_iomux { |
| 38 | int type; |
| 39 | int offset; |
| 40 | }; |
| 41 | |
| 42 | /** |
| 43 | * enum type index corresponding to rockchip_perpin_drv_list arrays index. |
| 44 | */ |
| 45 | enum rockchip_pin_drv_type { |
| 46 | DRV_TYPE_IO_DEFAULT = 0, |
| 47 | DRV_TYPE_IO_1V8_OR_3V0, |
| 48 | DRV_TYPE_IO_1V8_ONLY, |
| 49 | DRV_TYPE_IO_1V8_3V0_AUTO, |
| 50 | DRV_TYPE_IO_3V3_ONLY, |
| 51 | DRV_TYPE_MAX |
| 52 | }; |
| 53 | |
| 54 | /** |
| 55 | * enum type index corresponding to rockchip_pull_list arrays index. |
| 56 | */ |
| 57 | enum rockchip_pin_pull_type { |
| 58 | PULL_TYPE_IO_DEFAULT = 0, |
| 59 | PULL_TYPE_IO_1V8_ONLY, |
| 60 | PULL_TYPE_MAX |
| 61 | }; |
| 62 | |
| 63 | /** |
| 64 | * @drv_type: drive strength variant using rockchip_perpin_drv_type |
| 65 | * @offset: if initialized to -1 it will be autocalculated, by specifying |
| 66 | * an initial offset value the relevant source offset can be reset |
| 67 | * to a new value for autocalculating the following drive strength |
| 68 | * registers. if used chips own cal_drv func instead to calculate |
| 69 | * registers offset, the variant could be ignored. |
| 70 | */ |
| 71 | struct rockchip_drv { |
| 72 | enum rockchip_pin_drv_type drv_type; |
| 73 | int offset; |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * @priv: common pinctrl private basedata |
| 78 | * @pin_base: first pin number |
| 79 | * @nr_pins: number of pins in this bank |
| 80 | * @name: name of the bank |
| 81 | * @bank_num: number of the bank, to account for holes |
| 82 | * @iomux: array describing the 4 iomux sources of the bank |
| 83 | * @drv: array describing the 4 drive strength sources of the bank |
| 84 | * @pull_type: array describing the 4 pull type sources of the bank |
| 85 | * @recalced_mask: bits describing the mux recalced pins of per bank |
| 86 | * @route_mask: bits describing the routing pins of per bank |
| 87 | */ |
| 88 | struct rockchip_pin_bank { |
| 89 | struct rockchip_pinctrl_priv *priv; |
| 90 | u32 pin_base; |
| 91 | u8 nr_pins; |
| 92 | char *name; |
| 93 | u8 bank_num; |
| 94 | struct rockchip_iomux iomux[4]; |
| 95 | struct rockchip_drv drv[4]; |
| 96 | enum rockchip_pin_pull_type pull_type[4]; |
| 97 | u32 recalced_mask; |
| 98 | u32 route_mask; |
| 99 | }; |
| 100 | |
| 101 | #define PIN_BANK(id, pins, label) \ |
| 102 | { \ |
| 103 | .bank_num = id, \ |
| 104 | .nr_pins = pins, \ |
| 105 | .name = label, \ |
| 106 | .iomux = { \ |
| 107 | { .offset = -1 }, \ |
| 108 | { .offset = -1 }, \ |
| 109 | { .offset = -1 }, \ |
| 110 | { .offset = -1 }, \ |
| 111 | }, \ |
| 112 | } |
| 113 | |
| 114 | #define PIN_BANK_IOMUX_FLAGS(id, pins, label, iom0, iom1, iom2, iom3) \ |
| 115 | { \ |
| 116 | .bank_num = id, \ |
| 117 | .nr_pins = pins, \ |
| 118 | .name = label, \ |
| 119 | .iomux = { \ |
| 120 | { .type = iom0, .offset = -1 }, \ |
| 121 | { .type = iom1, .offset = -1 }, \ |
| 122 | { .type = iom2, .offset = -1 }, \ |
| 123 | { .type = iom3, .offset = -1 }, \ |
| 124 | }, \ |
| 125 | } |
| 126 | |
| 127 | #define PIN_BANK_DRV_FLAGS(id, pins, label, type0, type1, type2, type3) \ |
| 128 | { \ |
| 129 | .bank_num = id, \ |
| 130 | .nr_pins = pins, \ |
| 131 | .name = label, \ |
| 132 | .iomux = { \ |
| 133 | { .offset = -1 }, \ |
| 134 | { .offset = -1 }, \ |
| 135 | { .offset = -1 }, \ |
| 136 | { .offset = -1 }, \ |
| 137 | }, \ |
| 138 | .drv = { \ |
| 139 | { .drv_type = type0, .offset = -1 }, \ |
| 140 | { .drv_type = type1, .offset = -1 }, \ |
| 141 | { .drv_type = type2, .offset = -1 }, \ |
| 142 | { .drv_type = type3, .offset = -1 }, \ |
| 143 | }, \ |
| 144 | } |
| 145 | |
| 146 | #define PIN_BANK_DRV_FLAGS_PULL_FLAGS(id, pins, label, drv0, drv1, \ |
| 147 | drv2, drv3, pull0, pull1, \ |
| 148 | pull2, pull3) \ |
| 149 | { \ |
| 150 | .bank_num = id, \ |
| 151 | .nr_pins = pins, \ |
| 152 | .name = label, \ |
| 153 | .iomux = { \ |
| 154 | { .offset = -1 }, \ |
| 155 | { .offset = -1 }, \ |
| 156 | { .offset = -1 }, \ |
| 157 | { .offset = -1 }, \ |
| 158 | }, \ |
| 159 | .drv = { \ |
| 160 | { .drv_type = drv0, .offset = -1 }, \ |
| 161 | { .drv_type = drv1, .offset = -1 }, \ |
| 162 | { .drv_type = drv2, .offset = -1 }, \ |
| 163 | { .drv_type = drv3, .offset = -1 }, \ |
| 164 | }, \ |
| 165 | .pull_type[0] = pull0, \ |
| 166 | .pull_type[1] = pull1, \ |
| 167 | .pull_type[2] = pull2, \ |
| 168 | .pull_type[3] = pull3, \ |
| 169 | } |
| 170 | |
| 171 | #define PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(id, pins, label, iom0, iom1, \ |
| 172 | iom2, iom3, drv0, drv1, drv2, \ |
| 173 | drv3, offset0, offset1, \ |
| 174 | offset2, offset3) \ |
| 175 | { \ |
| 176 | .bank_num = id, \ |
| 177 | .nr_pins = pins, \ |
| 178 | .name = label, \ |
| 179 | .iomux = { \ |
| 180 | { .type = iom0, .offset = -1 }, \ |
| 181 | { .type = iom1, .offset = -1 }, \ |
| 182 | { .type = iom2, .offset = -1 }, \ |
| 183 | { .type = iom3, .offset = -1 }, \ |
| 184 | }, \ |
| 185 | .drv = { \ |
| 186 | { .drv_type = drv0, .offset = offset0 }, \ |
| 187 | { .drv_type = drv1, .offset = offset1 }, \ |
| 188 | { .drv_type = drv2, .offset = offset2 }, \ |
| 189 | { .drv_type = drv3, .offset = offset3 }, \ |
| 190 | }, \ |
| 191 | } |
| 192 | |
David Wu | e7ae4cf | 2019-01-02 21:00:55 +0800 | [diff] [blame] | 193 | #define PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(id, pins, \ |
| 194 | label, iom0, iom1, iom2, \ |
| 195 | iom3, drv0, drv1, drv2, \ |
| 196 | drv3, offset0, offset1, \ |
| 197 | offset2, offset3, pull0, \ |
| 198 | pull1, pull2, pull3) \ |
| 199 | { \ |
| 200 | .bank_num = id, \ |
| 201 | .nr_pins = pins, \ |
| 202 | .name = label, \ |
| 203 | .iomux = { \ |
| 204 | { .type = iom0, .offset = -1 }, \ |
| 205 | { .type = iom1, .offset = -1 }, \ |
| 206 | { .type = iom2, .offset = -1 }, \ |
| 207 | { .type = iom3, .offset = -1 }, \ |
| 208 | }, \ |
| 209 | .drv = { \ |
| 210 | { .drv_type = drv0, .offset = offset0 }, \ |
| 211 | { .drv_type = drv1, .offset = offset1 }, \ |
| 212 | { .drv_type = drv2, .offset = offset2 }, \ |
| 213 | { .drv_type = drv3, .offset = offset3 }, \ |
| 214 | }, \ |
| 215 | .pull_type[0] = pull0, \ |
| 216 | .pull_type[1] = pull1, \ |
| 217 | .pull_type[2] = pull2, \ |
| 218 | .pull_type[3] = pull3, \ |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * struct rockchip_mux_recalced_data: recalculate a pin iomux data. |
| 223 | * @num: bank number. |
| 224 | * @pin: pin number. |
| 225 | * @reg: register offset. |
| 226 | * @bit: index at register. |
| 227 | * @mask: mask bit |
| 228 | */ |
| 229 | struct rockchip_mux_recalced_data { |
| 230 | u8 num; |
| 231 | u8 pin; |
| 232 | u32 reg; |
| 233 | u8 bit; |
| 234 | u8 mask; |
| 235 | }; |
| 236 | |
| 237 | /** |
| 238 | * struct rockchip_mux_route_data: route a pin iomux data. |
| 239 | * @bank_num: bank number. |
| 240 | * @pin: index at register or used to calc index. |
| 241 | * @func: the min pin. |
| 242 | * @route_offset: the max pin. |
| 243 | * @route_val: the register offset. |
| 244 | */ |
| 245 | struct rockchip_mux_route_data { |
| 246 | u8 bank_num; |
| 247 | u8 pin; |
| 248 | u8 func; |
| 249 | u32 route_offset; |
| 250 | u32 route_val; |
| 251 | }; |
| 252 | |
| 253 | /** |
| 254 | */ |
| 255 | struct rockchip_pin_ctrl { |
| 256 | struct rockchip_pin_bank *pin_banks; |
| 257 | u32 nr_banks; |
| 258 | u32 nr_pins; |
David Wu | e7ae4cf | 2019-01-02 21:00:55 +0800 | [diff] [blame] | 259 | int grf_mux_offset; |
| 260 | int pmu_mux_offset; |
| 261 | int grf_drv_offset; |
| 262 | int pmu_drv_offset; |
| 263 | struct rockchip_mux_recalced_data *iomux_recalced; |
| 264 | u32 niomux_recalced; |
| 265 | struct rockchip_mux_route_data *iomux_routes; |
| 266 | u32 niomux_routes; |
| 267 | |
David Wu | 54e7570 | 2019-04-16 21:50:55 +0800 | [diff] [blame] | 268 | int (*set_mux)(struct rockchip_pin_bank *bank, |
| 269 | int pin, int mux); |
David Wu | 743a773 | 2019-04-16 21:57:05 +0800 | [diff] [blame] | 270 | int (*set_pull)(struct rockchip_pin_bank *bank, |
| 271 | int pin_num, int pull); |
David Wu | 625ab11 | 2019-04-16 21:55:26 +0800 | [diff] [blame] | 272 | int (*set_drive)(struct rockchip_pin_bank *bank, |
| 273 | int pin_num, int strength); |
David Wu | 79d16e4 | 2019-04-16 21:58:13 +0800 | [diff] [blame] | 274 | int (*set_schmitt)(struct rockchip_pin_bank *bank, |
| 275 | int pin_num, int enable); |
David Wu | e7ae4cf | 2019-01-02 21:00:55 +0800 | [diff] [blame] | 276 | }; |
| 277 | |
| 278 | /** |
| 279 | */ |
| 280 | struct rockchip_pinctrl_priv { |
| 281 | struct rockchip_pin_ctrl *ctrl; |
| 282 | struct regmap *regmap_base; |
| 283 | struct regmap *regmap_pmu; |
| 284 | }; |
| 285 | |
| 286 | extern const struct pinctrl_ops rockchip_pinctrl_ops; |
| 287 | int rockchip_pinctrl_probe(struct udevice *dev); |
David Wu | 54e7570 | 2019-04-16 21:50:55 +0800 | [diff] [blame] | 288 | void rockchip_get_recalced_mux(struct rockchip_pin_bank *bank, int pin, |
| 289 | int *reg, u8 *bit, int *mask); |
| 290 | bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin, |
| 291 | int mux, u32 *reg, u32 *value); |
| 292 | int rockchip_get_mux_data(int mux_type, int pin, u8 *bit, int *mask); |
David Wu | 625ab11 | 2019-04-16 21:55:26 +0800 | [diff] [blame] | 293 | int rockchip_translate_drive_value(int type, int strength); |
David Wu | 743a773 | 2019-04-16 21:57:05 +0800 | [diff] [blame] | 294 | int rockchip_translate_pull_value(int type, int pull); |
David Wu | e7ae4cf | 2019-01-02 21:00:55 +0800 | [diff] [blame] | 295 | |
| 296 | #endif /* __DRIVERS_PINCTRL_ROCKCHIP_H */ |