Paweł Jarosz | 5fa4dac | 2022-04-16 17:09:40 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2021 Rockchip Electronics Co., Ltd |
| 4 | */ |
| 5 | |
Paweł Jarosz | 5fa4dac | 2022-04-16 17:09:40 +0200 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <dm/pinctrl.h> |
| 8 | #include <regmap.h> |
| 9 | #include <syscon.h> |
| 10 | #include <linux/bitops.h> |
| 11 | |
| 12 | #include "pinctrl-rockchip.h" |
| 13 | |
| 14 | static int rk3066_pinctrl_set_mux(struct rockchip_pin_bank *bank, int pin, int mux) |
| 15 | { |
| 16 | struct rockchip_pinctrl_priv *priv = bank->priv; |
| 17 | int iomux_num = (pin / 8); |
| 18 | struct regmap *regmap; |
| 19 | int reg, ret, mask, mux_type; |
| 20 | u8 bit; |
| 21 | u32 data; |
| 22 | |
| 23 | regmap = priv->regmap_base; |
| 24 | |
| 25 | /* get basic quadrupel of mux registers and the correct reg inside */ |
| 26 | mux_type = bank->iomux[iomux_num].type; |
| 27 | reg = bank->iomux[iomux_num].offset; |
| 28 | reg += rockchip_get_mux_data(mux_type, pin, &bit, &mask); |
| 29 | |
| 30 | data = (mask << (bit + 16)); |
| 31 | data |= (mux & mask) << bit; |
| 32 | ret = regmap_write(regmap, reg, data); |
| 33 | |
| 34 | return ret; |
| 35 | } |
| 36 | |
| 37 | #define RK3066_PULL_OFFSET 0x118 |
| 38 | #define RK3066_PULL_PINS_PER_REG 16 |
| 39 | #define RK3066_PULL_BANK_STRIDE 8 |
| 40 | |
| 41 | static void rk3066_pinctrl_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, |
| 42 | int pin_num, struct regmap **regmap, |
| 43 | int *reg, u8 *bit) |
| 44 | { |
| 45 | struct rockchip_pinctrl_priv *priv = bank->priv; |
| 46 | |
| 47 | *regmap = priv->regmap_base; |
| 48 | *reg = RK3066_PULL_OFFSET; |
| 49 | *reg += bank->bank_num * RK3066_PULL_BANK_STRIDE; |
| 50 | *reg += (pin_num / RK3066_PULL_PINS_PER_REG) * 4; |
| 51 | |
| 52 | *bit = pin_num % RK3066_PULL_PINS_PER_REG; |
| 53 | }; |
| 54 | |
| 55 | static int rk3066_pinctrl_set_pull(struct rockchip_pin_bank *bank, |
| 56 | int pin_num, int pull) |
| 57 | { |
| 58 | struct regmap *regmap; |
| 59 | int reg, ret; |
| 60 | u8 bit; |
| 61 | u32 data; |
| 62 | |
| 63 | if (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT && |
| 64 | pull != PIN_CONFIG_BIAS_DISABLE) |
| 65 | return -EOPNOTSUPP; |
| 66 | |
| 67 | rk3066_pinctrl_calc_pull_reg_and_bit(bank, pin_num, ®map, ®, &bit); |
| 68 | data = BIT(bit + 16); |
| 69 | if (pull == PIN_CONFIG_BIAS_DISABLE) |
| 70 | data |= BIT(bit); |
| 71 | ret = regmap_write(regmap, reg, data); |
| 72 | |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | static struct rockchip_pin_bank rk3066_pin_banks[] = { |
| 77 | PIN_BANK(0, 32, "gpio0"), |
| 78 | PIN_BANK(1, 32, "gpio1"), |
| 79 | PIN_BANK(2, 32, "gpio2"), |
| 80 | PIN_BANK(3, 32, "gpio3"), |
| 81 | PIN_BANK(4, 32, "gpio4"), |
| 82 | PIN_BANK(6, 16, "gpio6"), |
| 83 | }; |
| 84 | |
| 85 | static struct rockchip_pin_ctrl rk3066_pin_ctrl = { |
| 86 | .pin_banks = rk3066_pin_banks, |
| 87 | .nr_banks = ARRAY_SIZE(rk3066_pin_banks), |
| 88 | .grf_mux_offset = 0xa8, |
| 89 | .set_mux = rk3066_pinctrl_set_mux, |
| 90 | .set_pull = rk3066_pinctrl_set_pull, |
| 91 | }; |
| 92 | |
| 93 | static const struct udevice_id rk3066_pinctrl_ids[] = { |
| 94 | { |
| 95 | .compatible = "rockchip,rk3066a-pinctrl", |
| 96 | .data = (ulong)&rk3066_pin_ctrl |
| 97 | }, |
| 98 | {} |
| 99 | }; |
| 100 | |
| 101 | U_BOOT_DRIVER(rockchip_rk3066a_pinctrl) = { |
| 102 | .name = "rockchip_rk3066a_pinctrl", |
| 103 | .id = UCLASS_PINCTRL, |
| 104 | .ops = &rockchip_pinctrl_ops, |
| 105 | .probe = rockchip_pinctrl_probe, |
| 106 | #if CONFIG_IS_ENABLED(OF_REAL) |
| 107 | .bind = dm_scan_fdt_dev, |
| 108 | #endif |
| 109 | .of_match = rk3066_pinctrl_ids, |
| 110 | .priv_auto = sizeof(struct rockchip_pinctrl_priv), |
| 111 | }; |