diff options
Diffstat (limited to 'drivers/pinctrl/pinctrl-rockchip.c')
-rw-r--r-- | drivers/pinctrl/pinctrl-rockchip.c | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c index 3924779f5578..1882713e68f9 100644 --- a/drivers/pinctrl/pinctrl-rockchip.c +++ b/drivers/pinctrl/pinctrl-rockchip.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #define GPIO_LS_SYNC 0x60 | 59 | #define GPIO_LS_SYNC 0x60 |
60 | 60 | ||
61 | enum rockchip_pinctrl_type { | 61 | enum rockchip_pinctrl_type { |
62 | PX30, | ||
62 | RV1108, | 63 | RV1108, |
63 | RK2928, | 64 | RK2928, |
64 | RK3066B, | 65 | RK3066B, |
@@ -701,6 +702,66 @@ static void rockchip_get_recalced_mux(struct rockchip_pin_bank *bank, int pin, | |||
701 | *bit = data->bit; | 702 | *bit = data->bit; |
702 | } | 703 | } |
703 | 704 | ||
705 | static struct rockchip_mux_route_data px30_mux_route_data[] = { | ||
706 | { | ||
707 | /* cif-d2m0 */ | ||
708 | .bank_num = 2, | ||
709 | .pin = 0, | ||
710 | .func = 1, | ||
711 | .route_offset = 0x184, | ||
712 | .route_val = BIT(16 + 7), | ||
713 | }, { | ||
714 | /* cif-d2m1 */ | ||
715 | .bank_num = 3, | ||
716 | .pin = 3, | ||
717 | .func = 3, | ||
718 | .route_offset = 0x184, | ||
719 | .route_val = BIT(16 + 7) | BIT(7), | ||
720 | }, { | ||
721 | /* pdm-m0 */ | ||
722 | .bank_num = 3, | ||
723 | .pin = 22, | ||
724 | .func = 2, | ||
725 | .route_offset = 0x184, | ||
726 | .route_val = BIT(16 + 8), | ||
727 | }, { | ||
728 | /* pdm-m1 */ | ||
729 | .bank_num = 2, | ||
730 | .pin = 22, | ||
731 | .func = 1, | ||
732 | .route_offset = 0x184, | ||
733 | .route_val = BIT(16 + 8) | BIT(8), | ||
734 | }, { | ||
735 | /* uart2-rxm0 */ | ||
736 | .bank_num = 1, | ||
737 | .pin = 27, | ||
738 | .func = 2, | ||
739 | .route_offset = 0x184, | ||
740 | .route_val = BIT(16 + 10), | ||
741 | }, { | ||
742 | /* uart2-rxm1 */ | ||
743 | .bank_num = 2, | ||
744 | .pin = 14, | ||
745 | .func = 2, | ||
746 | .route_offset = 0x184, | ||
747 | .route_val = BIT(16 + 10) | BIT(10), | ||
748 | }, { | ||
749 | /* uart3-rxm0 */ | ||
750 | .bank_num = 0, | ||
751 | .pin = 17, | ||
752 | .func = 2, | ||
753 | .route_offset = 0x184, | ||
754 | .route_val = BIT(16 + 9), | ||
755 | }, { | ||
756 | /* uart3-rxm1 */ | ||
757 | .bank_num = 1, | ||
758 | .pin = 15, | ||
759 | .func = 2, | ||
760 | .route_offset = 0x184, | ||
761 | .route_val = BIT(16 + 9) | BIT(9), | ||
762 | }, | ||
763 | }; | ||
764 | |||
704 | static struct rockchip_mux_route_data rk3128_mux_route_data[] = { | 765 | static struct rockchip_mux_route_data rk3128_mux_route_data[] = { |
705 | { | 766 | { |
706 | /* spi-0 */ | 767 | /* spi-0 */ |
@@ -1202,6 +1263,97 @@ static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux) | |||
1202 | return ret; | 1263 | return ret; |
1203 | } | 1264 | } |
1204 | 1265 | ||
1266 | #define PX30_PULL_PMU_OFFSET 0x10 | ||
1267 | #define PX30_PULL_GRF_OFFSET 0x60 | ||
1268 | #define PX30_PULL_BITS_PER_PIN 2 | ||
1269 | #define PX30_PULL_PINS_PER_REG 8 | ||
1270 | #define PX30_PULL_BANK_STRIDE 16 | ||
1271 | |||
1272 | static void px30_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, | ||
1273 | int pin_num, struct regmap **regmap, | ||
1274 | int *reg, u8 *bit) | ||
1275 | { | ||
1276 | struct rockchip_pinctrl *info = bank->drvdata; | ||
1277 | |||
1278 | /* The first 32 pins of the first bank are located in PMU */ | ||
1279 | if (bank->bank_num == 0) { | ||
1280 | *regmap = info->regmap_pmu; | ||
1281 | *reg = PX30_PULL_PMU_OFFSET; | ||
1282 | } else { | ||
1283 | *regmap = info->regmap_base; | ||
1284 | *reg = PX30_PULL_GRF_OFFSET; | ||
1285 | |||
1286 | /* correct the offset, as we're starting with the 2nd bank */ | ||
1287 | *reg -= 0x10; | ||
1288 | *reg += bank->bank_num * PX30_PULL_BANK_STRIDE; | ||
1289 | } | ||
1290 | |||
1291 | *reg += ((pin_num / PX30_PULL_PINS_PER_REG) * 4); | ||
1292 | *bit = (pin_num % PX30_PULL_PINS_PER_REG); | ||
1293 | *bit *= PX30_PULL_BITS_PER_PIN; | ||
1294 | } | ||
1295 | |||
1296 | #define PX30_DRV_PMU_OFFSET 0x20 | ||
1297 | #define PX30_DRV_GRF_OFFSET 0xf0 | ||
1298 | #define PX30_DRV_BITS_PER_PIN 2 | ||
1299 | #define PX30_DRV_PINS_PER_REG 8 | ||
1300 | #define PX30_DRV_BANK_STRIDE 16 | ||
1301 | |||
1302 | static void px30_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, | ||
1303 | int pin_num, struct regmap **regmap, | ||
1304 | int *reg, u8 *bit) | ||
1305 | { | ||
1306 | struct rockchip_pinctrl *info = bank->drvdata; | ||
1307 | |||
1308 | /* The first 32 pins of the first bank are located in PMU */ | ||
1309 | if (bank->bank_num == 0) { | ||
1310 | *regmap = info->regmap_pmu; | ||
1311 | *reg = PX30_DRV_PMU_OFFSET; | ||
1312 | } else { | ||
1313 | *regmap = info->regmap_base; | ||
1314 | *reg = PX30_DRV_GRF_OFFSET; | ||
1315 | |||
1316 | /* correct the offset, as we're starting with the 2nd bank */ | ||
1317 | *reg -= 0x10; | ||
1318 | *reg += bank->bank_num * PX30_DRV_BANK_STRIDE; | ||
1319 | } | ||
1320 | |||
1321 | *reg += ((pin_num / PX30_DRV_PINS_PER_REG) * 4); | ||
1322 | *bit = (pin_num % PX30_DRV_PINS_PER_REG); | ||
1323 | *bit *= PX30_DRV_BITS_PER_PIN; | ||
1324 | } | ||
1325 | |||
1326 | #define PX30_SCHMITT_PMU_OFFSET 0x38 | ||
1327 | #define PX30_SCHMITT_GRF_OFFSET 0xc0 | ||
1328 | #define PX30_SCHMITT_PINS_PER_PMU_REG 16 | ||
1329 | #define PX30_SCHMITT_BANK_STRIDE 16 | ||
1330 | #define PX30_SCHMITT_PINS_PER_GRF_REG 8 | ||
1331 | |||
1332 | static int px30_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank, | ||
1333 | int pin_num, | ||
1334 | struct regmap **regmap, | ||
1335 | int *reg, u8 *bit) | ||
1336 | { | ||
1337 | struct rockchip_pinctrl *info = bank->drvdata; | ||
1338 | int pins_per_reg; | ||
1339 | |||
1340 | if (bank->bank_num == 0) { | ||
1341 | *regmap = info->regmap_pmu; | ||
1342 | *reg = PX30_SCHMITT_PMU_OFFSET; | ||
1343 | pins_per_reg = PX30_SCHMITT_PINS_PER_PMU_REG; | ||
1344 | } else { | ||
1345 | *regmap = info->regmap_base; | ||
1346 | *reg = PX30_SCHMITT_GRF_OFFSET; | ||
1347 | pins_per_reg = PX30_SCHMITT_PINS_PER_GRF_REG; | ||
1348 | *reg += (bank->bank_num - 1) * PX30_SCHMITT_BANK_STRIDE; | ||
1349 | } | ||
1350 | |||
1351 | *reg += ((pin_num / pins_per_reg) * 4); | ||
1352 | *bit = pin_num % pins_per_reg; | ||
1353 | |||
1354 | return 0; | ||
1355 | } | ||
1356 | |||
1205 | #define RV1108_PULL_PMU_OFFSET 0x10 | 1357 | #define RV1108_PULL_PMU_OFFSET 0x10 |
1206 | #define RV1108_PULL_OFFSET 0x110 | 1358 | #define RV1108_PULL_OFFSET 0x110 |
1207 | #define RV1108_PULL_PINS_PER_REG 8 | 1359 | #define RV1108_PULL_PINS_PER_REG 8 |
@@ -1798,6 +1950,7 @@ static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num) | |||
1798 | return !(data & BIT(bit)) | 1950 | return !(data & BIT(bit)) |
1799 | ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT | 1951 | ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT |
1800 | : PIN_CONFIG_BIAS_DISABLE; | 1952 | : PIN_CONFIG_BIAS_DISABLE; |
1953 | case PX30: | ||
1801 | case RV1108: | 1954 | case RV1108: |
1802 | case RK3188: | 1955 | case RK3188: |
1803 | case RK3288: | 1956 | case RK3288: |
@@ -1841,6 +1994,7 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank, | |||
1841 | data |= BIT(bit); | 1994 | data |= BIT(bit); |
1842 | ret = regmap_write(regmap, reg, data); | 1995 | ret = regmap_write(regmap, reg, data); |
1843 | break; | 1996 | break; |
1997 | case PX30: | ||
1844 | case RV1108: | 1998 | case RV1108: |
1845 | case RK3188: | 1999 | case RK3188: |
1846 | case RK3288: | 2000 | case RK3288: |
@@ -2103,6 +2257,7 @@ static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl *ctrl, | |||
2103 | pull == PIN_CONFIG_BIAS_DISABLE); | 2257 | pull == PIN_CONFIG_BIAS_DISABLE); |
2104 | case RK3066B: | 2258 | case RK3066B: |
2105 | return pull ? false : true; | 2259 | return pull ? false : true; |
2260 | case PX30: | ||
2106 | case RV1108: | 2261 | case RV1108: |
2107 | case RK3188: | 2262 | case RK3188: |
2108 | case RK3288: | 2263 | case RK3288: |
@@ -2555,6 +2710,57 @@ static int rockchip_gpio_direction_output(struct gpio_chip *gc, | |||
2555 | return pinctrl_gpio_direction_output(gc->base + offset); | 2710 | return pinctrl_gpio_direction_output(gc->base + offset); |
2556 | } | 2711 | } |
2557 | 2712 | ||
2713 | static void rockchip_gpio_set_debounce(struct gpio_chip *gc, | ||
2714 | unsigned int offset, bool enable) | ||
2715 | { | ||
2716 | struct rockchip_pin_bank *bank = gpiochip_get_data(gc); | ||
2717 | void __iomem *reg = bank->reg_base + GPIO_DEBOUNCE; | ||
2718 | unsigned long flags; | ||
2719 | u32 data; | ||
2720 | |||
2721 | clk_enable(bank->clk); | ||
2722 | raw_spin_lock_irqsave(&bank->slock, flags); | ||
2723 | |||
2724 | data = readl(reg); | ||
2725 | if (enable) | ||
2726 | data |= BIT(offset); | ||
2727 | else | ||
2728 | data &= ~BIT(offset); | ||
2729 | writel(data, reg); | ||
2730 | |||
2731 | raw_spin_unlock_irqrestore(&bank->slock, flags); | ||
2732 | clk_disable(bank->clk); | ||
2733 | } | ||
2734 | |||
2735 | /* | ||
2736 | * gpiolib set_config callback function. The setting of the pin | ||
2737 | * mux function as 'gpio output' will be handled by the pinctrl subsystem | ||
2738 | * interface. | ||
2739 | */ | ||
2740 | static int rockchip_gpio_set_config(struct gpio_chip *gc, unsigned int offset, | ||
2741 | unsigned long config) | ||
2742 | { | ||
2743 | enum pin_config_param param = pinconf_to_config_param(config); | ||
2744 | |||
2745 | switch (param) { | ||
2746 | case PIN_CONFIG_INPUT_DEBOUNCE: | ||
2747 | rockchip_gpio_set_debounce(gc, offset, true); | ||
2748 | /* | ||
2749 | * Rockchip's gpio could only support up to one period | ||
2750 | * of the debounce clock(pclk), which is far away from | ||
2751 | * satisftying the requirement, as pclk is usually near | ||
2752 | * 100MHz shared by all peripherals. So the fact is it | ||
2753 | * has crippled debounce capability could only be useful | ||
2754 | * to prevent any spurious glitches from waking up the system | ||
2755 | * if the gpio is conguired as wakeup interrupt source. Let's | ||
2756 | * still return -ENOTSUPP as before, to make sure the caller | ||
2757 | * of gpiod_set_debounce won't change its behaviour. | ||
2758 | */ | ||
2759 | default: | ||
2760 | return -ENOTSUPP; | ||
2761 | } | ||
2762 | } | ||
2763 | |||
2558 | /* | 2764 | /* |
2559 | * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin | 2765 | * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin |
2560 | * and a virtual IRQ, if not already present. | 2766 | * and a virtual IRQ, if not already present. |
@@ -2580,6 +2786,7 @@ static const struct gpio_chip rockchip_gpiolib_chip = { | |||
2580 | .get_direction = rockchip_gpio_get_direction, | 2786 | .get_direction = rockchip_gpio_get_direction, |
2581 | .direction_input = rockchip_gpio_direction_input, | 2787 | .direction_input = rockchip_gpio_direction_input, |
2582 | .direction_output = rockchip_gpio_direction_output, | 2788 | .direction_output = rockchip_gpio_direction_output, |
2789 | .set_config = rockchip_gpio_set_config, | ||
2583 | .to_irq = rockchip_gpio_to_irq, | 2790 | .to_irq = rockchip_gpio_to_irq, |
2584 | .owner = THIS_MODULE, | 2791 | .owner = THIS_MODULE, |
2585 | }; | 2792 | }; |
@@ -3237,6 +3444,43 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev) | |||
3237 | return 0; | 3444 | return 0; |
3238 | } | 3445 | } |
3239 | 3446 | ||
3447 | static struct rockchip_pin_bank px30_pin_banks[] = { | ||
3448 | PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU, | ||
3449 | IOMUX_SOURCE_PMU, | ||
3450 | IOMUX_SOURCE_PMU, | ||
3451 | IOMUX_SOURCE_PMU | ||
3452 | ), | ||
3453 | PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT, | ||
3454 | IOMUX_WIDTH_4BIT, | ||
3455 | IOMUX_WIDTH_4BIT, | ||
3456 | IOMUX_WIDTH_4BIT | ||
3457 | ), | ||
3458 | PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT, | ||
3459 | IOMUX_WIDTH_4BIT, | ||
3460 | IOMUX_WIDTH_4BIT, | ||
3461 | IOMUX_WIDTH_4BIT | ||
3462 | ), | ||
3463 | PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT, | ||
3464 | IOMUX_WIDTH_4BIT, | ||
3465 | IOMUX_WIDTH_4BIT, | ||
3466 | IOMUX_WIDTH_4BIT | ||
3467 | ), | ||
3468 | }; | ||
3469 | |||
3470 | static struct rockchip_pin_ctrl px30_pin_ctrl = { | ||
3471 | .pin_banks = px30_pin_banks, | ||
3472 | .nr_banks = ARRAY_SIZE(px30_pin_banks), | ||
3473 | .label = "PX30-GPIO", | ||
3474 | .type = PX30, | ||
3475 | .grf_mux_offset = 0x0, | ||
3476 | .pmu_mux_offset = 0x0, | ||
3477 | .iomux_routes = px30_mux_route_data, | ||
3478 | .niomux_routes = ARRAY_SIZE(px30_mux_route_data), | ||
3479 | .pull_calc_reg = px30_calc_pull_reg_and_bit, | ||
3480 | .drv_calc_reg = px30_calc_drv_reg_and_bit, | ||
3481 | .schmitt_calc_reg = px30_calc_schmitt_reg_and_bit, | ||
3482 | }; | ||
3483 | |||
3240 | static struct rockchip_pin_bank rv1108_pin_banks[] = { | 3484 | static struct rockchip_pin_bank rv1108_pin_banks[] = { |
3241 | PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU, | 3485 | PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU, |
3242 | IOMUX_SOURCE_PMU, | 3486 | IOMUX_SOURCE_PMU, |
@@ -3545,6 +3789,8 @@ static struct rockchip_pin_ctrl rk3399_pin_ctrl = { | |||
3545 | }; | 3789 | }; |
3546 | 3790 | ||
3547 | static const struct of_device_id rockchip_pinctrl_dt_match[] = { | 3791 | static const struct of_device_id rockchip_pinctrl_dt_match[] = { |
3792 | { .compatible = "rockchip,px30-pinctrl", | ||
3793 | .data = &px30_pin_ctrl }, | ||
3548 | { .compatible = "rockchip,rv1108-pinctrl", | 3794 | { .compatible = "rockchip,rv1108-pinctrl", |
3549 | .data = &rv1108_pin_ctrl }, | 3795 | .data = &rv1108_pin_ctrl }, |
3550 | { .compatible = "rockchip,rk2928-pinctrl", | 3796 | { .compatible = "rockchip,rk2928-pinctrl", |