blob: 5deedc648a41950461b6a468e4852fa0a5384207 [file] [log] [blame]
Jagan Teki7fc80642023-02-17 17:28:43 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2020 Rockchip Electronics Co., Ltd
4 */
5
Jagan Teki7fc80642023-02-17 17:28:43 +05306#include <dm.h>
7#include <dm/pinctrl.h>
8#include <regmap.h>
9#include <syscon.h>
10#include <dt-bindings/pinctrl/rockchip.h>
11
12#include "pinctrl-rockchip.h"
13
14static struct rockchip_mux_route_data rk3568_mux_route_data[] = {
Jonas Karlman3a8a2992023-04-17 19:07:23 +000015 MR_PMUGRF(RK_GPIO0, RK_PB7, RK_FUNC_1, 0x0110, RK_GENMASK_VAL(1, 0, 0)), /* PWM0 IO mux selection M0 */
16 MR_PMUGRF(RK_GPIO0, RK_PC7, RK_FUNC_2, 0x0110, RK_GENMASK_VAL(1, 0, 1)), /* PWM0 IO mux selection M1 */
17 MR_PMUGRF(RK_GPIO0, RK_PC0, RK_FUNC_1, 0x0110, RK_GENMASK_VAL(3, 2, 0)), /* PWM1 IO mux selection M0 */
18 MR_PMUGRF(RK_GPIO0, RK_PB5, RK_FUNC_4, 0x0110, RK_GENMASK_VAL(3, 2, 1)), /* PWM1 IO mux selection M1 */
19 MR_PMUGRF(RK_GPIO0, RK_PC1, RK_FUNC_1, 0x0110, RK_GENMASK_VAL(5, 4, 0)), /* PWM2 IO mux selection M0 */
20 MR_PMUGRF(RK_GPIO0, RK_PB6, RK_FUNC_4, 0x0110, RK_GENMASK_VAL(5, 4, 1)), /* PWM2 IO mux selection M1 */
Jagan Teki7fc80642023-02-17 17:28:43 +053021 MR_TOPGRF(RK_GPIO0, RK_PB3, RK_FUNC_2, 0x0300, RK_GENMASK_VAL(0, 0, 0)), /* CAN0 IO mux selection M0 */
22 MR_TOPGRF(RK_GPIO2, RK_PA1, RK_FUNC_4, 0x0300, RK_GENMASK_VAL(0, 0, 1)), /* CAN0 IO mux selection M1 */
23 MR_TOPGRF(RK_GPIO1, RK_PA1, RK_FUNC_3, 0x0300, RK_GENMASK_VAL(2, 2, 0)), /* CAN1 IO mux selection M0 */
24 MR_TOPGRF(RK_GPIO4, RK_PC3, RK_FUNC_3, 0x0300, RK_GENMASK_VAL(2, 2, 1)), /* CAN1 IO mux selection M1 */
25 MR_TOPGRF(RK_GPIO4, RK_PB5, RK_FUNC_3, 0x0300, RK_GENMASK_VAL(4, 4, 0)), /* CAN2 IO mux selection M0 */
26 MR_TOPGRF(RK_GPIO2, RK_PB2, RK_FUNC_4, 0x0300, RK_GENMASK_VAL(4, 4, 1)), /* CAN2 IO mux selection M1 */
27 MR_TOPGRF(RK_GPIO4, RK_PC4, RK_FUNC_1, 0x0300, RK_GENMASK_VAL(6, 6, 0)), /* EDPDP_HPDIN IO mux selection M0 */
28 MR_TOPGRF(RK_GPIO0, RK_PC2, RK_FUNC_2, 0x0300, RK_GENMASK_VAL(6, 6, 1)), /* EDPDP_HPDIN IO mux selection M1 */
29 MR_TOPGRF(RK_GPIO3, RK_PB1, RK_FUNC_3, 0x0300, RK_GENMASK_VAL(8, 8, 0)), /* GMAC1 IO mux selection M0 */
30 MR_TOPGRF(RK_GPIO4, RK_PA7, RK_FUNC_3, 0x0300, RK_GENMASK_VAL(8, 8, 1)), /* GMAC1 IO mux selection M1 */
31 MR_TOPGRF(RK_GPIO4, RK_PD1, RK_FUNC_1, 0x0300, RK_GENMASK_VAL(10, 10, 0)), /* HDMITX IO mux selection M0 */
32 MR_TOPGRF(RK_GPIO0, RK_PC7, RK_FUNC_1, 0x0300, RK_GENMASK_VAL(10, 10, 1)), /* HDMITX IO mux selection M1 */
33 MR_TOPGRF(RK_GPIO0, RK_PB6, RK_FUNC_1, 0x0300, RK_GENMASK_VAL(14, 14, 0)), /* I2C2 IO mux selection M0 */
34 MR_TOPGRF(RK_GPIO4, RK_PB4, RK_FUNC_1, 0x0300, RK_GENMASK_VAL(14, 14, 1)), /* I2C2 IO mux selection M1 */
35 MR_TOPGRF(RK_GPIO1, RK_PA0, RK_FUNC_1, 0x0304, RK_GENMASK_VAL(0, 0, 0)), /* I2C3 IO mux selection M0 */
36 MR_TOPGRF(RK_GPIO3, RK_PB6, RK_FUNC_4, 0x0304, RK_GENMASK_VAL(0, 0, 1)), /* I2C3 IO mux selection M1 */
37 MR_TOPGRF(RK_GPIO4, RK_PB2, RK_FUNC_1, 0x0304, RK_GENMASK_VAL(2, 2, 0)), /* I2C4 IO mux selection M0 */
38 MR_TOPGRF(RK_GPIO2, RK_PB1, RK_FUNC_2, 0x0304, RK_GENMASK_VAL(2, 2, 1)), /* I2C4 IO mux selection M1 */
39 MR_TOPGRF(RK_GPIO3, RK_PB4, RK_FUNC_4, 0x0304, RK_GENMASK_VAL(4, 4, 0)), /* I2C5 IO mux selection M0 */
40 MR_TOPGRF(RK_GPIO4, RK_PD0, RK_FUNC_2, 0x0304, RK_GENMASK_VAL(4, 4, 1)), /* I2C5 IO mux selection M1 */
Jonas Karlman3a8a2992023-04-17 19:07:23 +000041 MR_TOPGRF(RK_GPIO3, RK_PB1, RK_FUNC_5, 0x0304, RK_GENMASK_VAL(14, 14, 0)), /* PWM8 IO mux selection M0 */
42 MR_TOPGRF(RK_GPIO1, RK_PD5, RK_FUNC_4, 0x0304, RK_GENMASK_VAL(14, 14, 1)), /* PWM8 IO mux selection M1 */
43 MR_TOPGRF(RK_GPIO3, RK_PB2, RK_FUNC_5, 0x0308, RK_GENMASK_VAL(0, 0, 0)), /* PWM9 IO mux selection M0 */
44 MR_TOPGRF(RK_GPIO1, RK_PD6, RK_FUNC_4, 0x0308, RK_GENMASK_VAL(0, 0, 1)), /* PWM9 IO mux selection M1 */
45 MR_TOPGRF(RK_GPIO3, RK_PB5, RK_FUNC_5, 0x0308, RK_GENMASK_VAL(2, 2, 0)), /* PWM10 IO mux selection M0 */
46 MR_TOPGRF(RK_GPIO2, RK_PA1, RK_FUNC_2, 0x0308, RK_GENMASK_VAL(2, 2, 1)), /* PWM10 IO mux selection M1 */
47 MR_TOPGRF(RK_GPIO3, RK_PB6, RK_FUNC_5, 0x0308, RK_GENMASK_VAL(4, 4, 0)), /* PWM11 IO mux selection M0 */
48 MR_TOPGRF(RK_GPIO4, RK_PC0, RK_FUNC_3, 0x0308, RK_GENMASK_VAL(4, 4, 1)), /* PWM11 IO mux selection M1 */
49 MR_TOPGRF(RK_GPIO3, RK_PB7, RK_FUNC_2, 0x0308, RK_GENMASK_VAL(6, 6, 0)), /* PWM12 IO mux selection M0 */
50 MR_TOPGRF(RK_GPIO4, RK_PC5, RK_FUNC_1, 0x0308, RK_GENMASK_VAL(6, 6, 1)), /* PWM12 IO mux selection M1 */
51 MR_TOPGRF(RK_GPIO3, RK_PC0, RK_FUNC_2, 0x0308, RK_GENMASK_VAL(8, 8, 0)), /* PWM13 IO mux selection M0 */
52 MR_TOPGRF(RK_GPIO4, RK_PC6, RK_FUNC_1, 0x0308, RK_GENMASK_VAL(8, 8, 1)), /* PWM13 IO mux selection M1 */
53 MR_TOPGRF(RK_GPIO3, RK_PC4, RK_FUNC_1, 0x0308, RK_GENMASK_VAL(10, 10, 0)), /* PWM14 IO mux selection M0 */
54 MR_TOPGRF(RK_GPIO4, RK_PC2, RK_FUNC_1, 0x0308, RK_GENMASK_VAL(10, 10, 1)), /* PWM14 IO mux selection M1 */
55 MR_TOPGRF(RK_GPIO3, RK_PC5, RK_FUNC_1, 0x0308, RK_GENMASK_VAL(12, 12, 0)), /* PWM15 IO mux selection M0 */
56 MR_TOPGRF(RK_GPIO4, RK_PC3, RK_FUNC_1, 0x0308, RK_GENMASK_VAL(12, 12, 1)), /* PWM15 IO mux selection M1 */
Jagan Teki7fc80642023-02-17 17:28:43 +053057 MR_TOPGRF(RK_GPIO3, RK_PD2, RK_FUNC_3, 0x0308, RK_GENMASK_VAL(14, 14, 0)), /* SDMMC2 IO mux selection M0 */
58 MR_TOPGRF(RK_GPIO3, RK_PA5, RK_FUNC_5, 0x0308, RK_GENMASK_VAL(14, 14, 1)), /* SDMMC2 IO mux selection M1 */
59 MR_TOPGRF(RK_GPIO0, RK_PB5, RK_FUNC_2, 0x030c, RK_GENMASK_VAL(0, 0, 0)), /* SPI0 IO mux selection M0 */
60 MR_TOPGRF(RK_GPIO2, RK_PD3, RK_FUNC_3, 0x030c, RK_GENMASK_VAL(0, 0, 1)), /* SPI0 IO mux selection M1 */
61 MR_TOPGRF(RK_GPIO2, RK_PB5, RK_FUNC_3, 0x030c, RK_GENMASK_VAL(2, 2, 0)), /* SPI1 IO mux selection M0 */
62 MR_TOPGRF(RK_GPIO3, RK_PC3, RK_FUNC_3, 0x030c, RK_GENMASK_VAL(2, 2, 1)), /* SPI1 IO mux selection M1 */
63 MR_TOPGRF(RK_GPIO2, RK_PC1, RK_FUNC_4, 0x030c, RK_GENMASK_VAL(4, 4, 0)), /* SPI2 IO mux selection M0 */
64 MR_TOPGRF(RK_GPIO3, RK_PA0, RK_FUNC_3, 0x030c, RK_GENMASK_VAL(4, 4, 1)), /* SPI2 IO mux selection M1 */
65 MR_TOPGRF(RK_GPIO4, RK_PB3, RK_FUNC_4, 0x030c, RK_GENMASK_VAL(6, 6, 0)), /* SPI3 IO mux selection M0 */
66 MR_TOPGRF(RK_GPIO4, RK_PC2, RK_FUNC_2, 0x030c, RK_GENMASK_VAL(6, 6, 1)), /* SPI3 IO mux selection M1 */
67 MR_TOPGRF(RK_GPIO2, RK_PB4, RK_FUNC_2, 0x030c, RK_GENMASK_VAL(8, 8, 0)), /* UART1 IO mux selection M0 */
Jonas Karlman3a8a2992023-04-17 19:07:23 +000068 MR_TOPGRF(RK_GPIO3, RK_PD6, RK_FUNC_4, 0x030c, RK_GENMASK_VAL(8, 8, 1)), /* UART1 IO mux selection M1 */
Jagan Teki7fc80642023-02-17 17:28:43 +053069 MR_TOPGRF(RK_GPIO0, RK_PD1, RK_FUNC_1, 0x030c, RK_GENMASK_VAL(10, 10, 0)), /* UART2 IO mux selection M0 */
70 MR_TOPGRF(RK_GPIO1, RK_PD5, RK_FUNC_2, 0x030c, RK_GENMASK_VAL(10, 10, 1)), /* UART2 IO mux selection M1 */
71 MR_TOPGRF(RK_GPIO1, RK_PA1, RK_FUNC_2, 0x030c, RK_GENMASK_VAL(12, 12, 0)), /* UART3 IO mux selection M0 */
72 MR_TOPGRF(RK_GPIO3, RK_PB7, RK_FUNC_4, 0x030c, RK_GENMASK_VAL(12, 12, 1)), /* UART3 IO mux selection M1 */
73 MR_TOPGRF(RK_GPIO1, RK_PA6, RK_FUNC_2, 0x030c, RK_GENMASK_VAL(14, 14, 0)), /* UART4 IO mux selection M0 */
74 MR_TOPGRF(RK_GPIO3, RK_PB2, RK_FUNC_4, 0x030c, RK_GENMASK_VAL(14, 14, 1)), /* UART4 IO mux selection M1 */
75 MR_TOPGRF(RK_GPIO2, RK_PA2, RK_FUNC_3, 0x0310, RK_GENMASK_VAL(0, 0, 0)), /* UART5 IO mux selection M0 */
76 MR_TOPGRF(RK_GPIO3, RK_PC2, RK_FUNC_4, 0x0310, RK_GENMASK_VAL(0, 0, 1)), /* UART5 IO mux selection M1 */
77 MR_TOPGRF(RK_GPIO2, RK_PA4, RK_FUNC_3, 0x0310, RK_GENMASK_VAL(2, 2, 0)), /* UART6 IO mux selection M0 */
78 MR_TOPGRF(RK_GPIO1, RK_PD5, RK_FUNC_3, 0x0310, RK_GENMASK_VAL(2, 2, 1)), /* UART6 IO mux selection M1 */
79 MR_TOPGRF(RK_GPIO2, RK_PA6, RK_FUNC_3, 0x0310, RK_GENMASK_VAL(5, 4, 0)), /* UART7 IO mux selection M0 */
80 MR_TOPGRF(RK_GPIO3, RK_PC4, RK_FUNC_4, 0x0310, RK_GENMASK_VAL(5, 4, 1)), /* UART7 IO mux selection M1 */
Jonas Karlman3a8a2992023-04-17 19:07:23 +000081 MR_TOPGRF(RK_GPIO4, RK_PA2, RK_FUNC_4, 0x0310, RK_GENMASK_VAL(5, 4, 2)), /* UART7 IO mux selection M2 */
Jagan Teki7fc80642023-02-17 17:28:43 +053082 MR_TOPGRF(RK_GPIO2, RK_PC5, RK_FUNC_3, 0x0310, RK_GENMASK_VAL(6, 6, 0)), /* UART8 IO mux selection M0 */
83 MR_TOPGRF(RK_GPIO2, RK_PD7, RK_FUNC_4, 0x0310, RK_GENMASK_VAL(6, 6, 1)), /* UART8 IO mux selection M1 */
84 MR_TOPGRF(RK_GPIO2, RK_PB0, RK_FUNC_3, 0x0310, RK_GENMASK_VAL(9, 8, 0)), /* UART9 IO mux selection M0 */
85 MR_TOPGRF(RK_GPIO4, RK_PC5, RK_FUNC_4, 0x0310, RK_GENMASK_VAL(9, 8, 1)), /* UART9 IO mux selection M1 */
86 MR_TOPGRF(RK_GPIO4, RK_PA4, RK_FUNC_4, 0x0310, RK_GENMASK_VAL(9, 8, 2)), /* UART9 IO mux selection M2 */
87 MR_TOPGRF(RK_GPIO1, RK_PA2, RK_FUNC_1, 0x0310, RK_GENMASK_VAL(11, 10, 0)), /* I2S1 IO mux selection M0 */
88 MR_TOPGRF(RK_GPIO3, RK_PC6, RK_FUNC_4, 0x0310, RK_GENMASK_VAL(11, 10, 1)), /* I2S1 IO mux selection M1 */
89 MR_TOPGRF(RK_GPIO2, RK_PD0, RK_FUNC_5, 0x0310, RK_GENMASK_VAL(11, 10, 2)), /* I2S1 IO mux selection M2 */
90 MR_TOPGRF(RK_GPIO2, RK_PC1, RK_FUNC_1, 0x0310, RK_GENMASK_VAL(12, 12, 0)), /* I2S2 IO mux selection M0 */
91 MR_TOPGRF(RK_GPIO4, RK_PB6, RK_FUNC_5, 0x0310, RK_GENMASK_VAL(12, 12, 1)), /* I2S2 IO mux selection M1 */
92 MR_TOPGRF(RK_GPIO3, RK_PA2, RK_FUNC_4, 0x0310, RK_GENMASK_VAL(14, 14, 0)), /* I2S3 IO mux selection M0 */
93 MR_TOPGRF(RK_GPIO4, RK_PC2, RK_FUNC_5, 0x0310, RK_GENMASK_VAL(14, 14, 1)), /* I2S3 IO mux selection M1 */
Jonas Karlman3a8a2992023-04-17 19:07:23 +000094 MR_TOPGRF(RK_GPIO1, RK_PA4, RK_FUNC_3, 0x0314, RK_GENMASK_VAL(1, 0, 0)), /* PDM IO mux selection M0 */
95 MR_TOPGRF(RK_GPIO1, RK_PA6, RK_FUNC_3, 0x0314, RK_GENMASK_VAL(1, 0, 0)), /* PDM IO mux selection M0 */
96 MR_TOPGRF(RK_GPIO3, RK_PD6, RK_FUNC_5, 0x0314, RK_GENMASK_VAL(1, 0, 1)), /* PDM IO mux selection M1 */
97 MR_TOPGRF(RK_GPIO4, RK_PA0, RK_FUNC_4, 0x0314, RK_GENMASK_VAL(1, 0, 1)), /* PDM IO mux selection M1 */
98 MR_TOPGRF(RK_GPIO3, RK_PC4, RK_FUNC_5, 0x0314, RK_GENMASK_VAL(1, 0, 2)), /* PDM IO mux selection M2 */
Jagan Teki7fc80642023-02-17 17:28:43 +053099 MR_TOPGRF(RK_GPIO0, RK_PA5, RK_FUNC_3, 0x0314, RK_GENMASK_VAL(3, 2, 0)), /* PCIE20 IO mux selection M0 */
100 MR_TOPGRF(RK_GPIO2, RK_PD0, RK_FUNC_4, 0x0314, RK_GENMASK_VAL(3, 2, 1)), /* PCIE20 IO mux selection M1 */
101 MR_TOPGRF(RK_GPIO1, RK_PB0, RK_FUNC_4, 0x0314, RK_GENMASK_VAL(3, 2, 2)), /* PCIE20 IO mux selection M2 */
102 MR_TOPGRF(RK_GPIO0, RK_PA4, RK_FUNC_3, 0x0314, RK_GENMASK_VAL(5, 4, 0)), /* PCIE30X1 IO mux selection M0 */
103 MR_TOPGRF(RK_GPIO2, RK_PD2, RK_FUNC_4, 0x0314, RK_GENMASK_VAL(5, 4, 1)), /* PCIE30X1 IO mux selection M1 */
104 MR_TOPGRF(RK_GPIO1, RK_PA5, RK_FUNC_4, 0x0314, RK_GENMASK_VAL(5, 4, 2)), /* PCIE30X1 IO mux selection M2 */
105 MR_TOPGRF(RK_GPIO0, RK_PA6, RK_FUNC_2, 0x0314, RK_GENMASK_VAL(7, 6, 0)), /* PCIE30X2 IO mux selection M0 */
106 MR_TOPGRF(RK_GPIO2, RK_PD4, RK_FUNC_4, 0x0314, RK_GENMASK_VAL(7, 6, 1)), /* PCIE30X2 IO mux selection M1 */
107 MR_TOPGRF(RK_GPIO4, RK_PC2, RK_FUNC_4, 0x0314, RK_GENMASK_VAL(7, 6, 2)), /* PCIE30X2 IO mux selection M2 */
108};
109
110static int rk3568_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
111{
112 struct rockchip_pinctrl_priv *priv = bank->priv;
113 int iomux_num = (pin / 8);
114 struct regmap *regmap;
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000115 int reg, mask;
Jagan Teki7fc80642023-02-17 17:28:43 +0530116 u8 bit;
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000117 u32 data, rmask;
Jagan Teki7fc80642023-02-17 17:28:43 +0530118
119 if (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
120 regmap = priv->regmap_pmu;
121 else
122 regmap = priv->regmap_base;
123
124 reg = bank->iomux[iomux_num].offset;
125 if ((pin % 8) >= 4)
126 reg += 0x4;
127 bit = (pin % 4) * 4;
128 mask = 0xf;
129
130 data = (mask << (bit + 16));
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000131 rmask = data | (data >> 16);
Jagan Teki7fc80642023-02-17 17:28:43 +0530132 data |= (mux & mask) << bit;
Jagan Teki7fc80642023-02-17 17:28:43 +0530133
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000134 return regmap_update_bits(regmap, reg, rmask, data);
Jagan Teki7fc80642023-02-17 17:28:43 +0530135}
136
137#define RK3568_PULL_PMU_OFFSET 0x20
138#define RK3568_PULL_GRF_OFFSET 0x80
139#define RK3568_PULL_BITS_PER_PIN 2
140#define RK3568_PULL_PINS_PER_REG 8
141#define RK3568_PULL_BANK_STRIDE 0x10
142
143static void rk3568_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
144 int pin_num, struct regmap **regmap,
145 int *reg, u8 *bit)
146{
147 struct rockchip_pinctrl_priv *info = bank->priv;
148
149 if (bank->bank_num == 0) {
150 *regmap = info->regmap_pmu;
151 *reg = RK3568_PULL_PMU_OFFSET;
152 *reg += bank->bank_num * RK3568_PULL_BANK_STRIDE;
153 } else {
154 *regmap = info->regmap_base;
155 *reg = RK3568_PULL_GRF_OFFSET;
156 *reg += (bank->bank_num - 1) * RK3568_PULL_BANK_STRIDE;
157 }
158
159 *reg += ((pin_num / RK3568_PULL_PINS_PER_REG) * 4);
160 *bit = (pin_num % RK3568_PULL_PINS_PER_REG);
161 *bit *= RK3568_PULL_BITS_PER_PIN;
162}
163
164#define RK3568_DRV_PMU_OFFSET 0x70
165#define RK3568_DRV_GRF_OFFSET 0x200
166#define RK3568_DRV_BITS_PER_PIN 8
167#define RK3568_DRV_PINS_PER_REG 2
168#define RK3568_DRV_BANK_STRIDE 0x40
169
170static void rk3568_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
171 int pin_num, struct regmap **regmap,
172 int *reg, u8 *bit)
173{
174 struct rockchip_pinctrl_priv *info = bank->priv;
175
176 /* The first 32 pins of the first bank are located in PMU */
177 if (bank->bank_num == 0) {
178 *regmap = info->regmap_pmu;
179 *reg = RK3568_DRV_PMU_OFFSET;
180 } else {
181 *regmap = info->regmap_base;
182 *reg = RK3568_DRV_GRF_OFFSET;
183 *reg += (bank->bank_num - 1) * RK3568_DRV_BANK_STRIDE;
184 }
185
186 *reg += ((pin_num / RK3568_DRV_PINS_PER_REG) * 4);
187 *bit = (pin_num % RK3568_DRV_PINS_PER_REG);
188 *bit *= RK3568_DRV_BITS_PER_PIN;
189}
190
191#define RK3568_SCHMITT_BITS_PER_PIN 2
192#define RK3568_SCHMITT_PINS_PER_REG 8
193#define RK3568_SCHMITT_BANK_STRIDE 0x10
194#define RK3568_SCHMITT_GRF_OFFSET 0xc0
195#define RK3568_SCHMITT_PMUGRF_OFFSET 0x30
196
197static int rk3568_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
198 int pin_num, struct regmap **regmap,
199 int *reg, u8 *bit)
200{
201 struct rockchip_pinctrl_priv *info = bank->priv;
202
203 if (bank->bank_num == 0) {
204 *regmap = info->regmap_pmu;
205 *reg = RK3568_SCHMITT_PMUGRF_OFFSET;
206 } else {
207 *regmap = info->regmap_base;
208 *reg = RK3568_SCHMITT_GRF_OFFSET;
209 *reg += (bank->bank_num - 1) * RK3568_SCHMITT_BANK_STRIDE;
210 }
211
212 *reg += ((pin_num / RK3568_SCHMITT_PINS_PER_REG) * 4);
213 *bit = pin_num % RK3568_SCHMITT_PINS_PER_REG;
214 *bit *= RK3568_SCHMITT_BITS_PER_PIN;
215
216 return 0;
217}
218
219static int rk3568_set_pull(struct rockchip_pin_bank *bank,
220 int pin_num, int pull)
221{
222 struct regmap *regmap;
223 int reg, ret;
224 u8 bit, type;
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000225 u32 data, rmask;
Jagan Teki7fc80642023-02-17 17:28:43 +0530226
227 if (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT)
228 return -ENOTSUPP;
229
230 rk3568_calc_pull_reg_and_bit(bank, pin_num, &regmap, &reg, &bit);
231 type = bank->pull_type[pin_num / 8];
232 ret = rockchip_translate_pull_value(type, pull);
233 if (ret < 0) {
234 debug("unsupported pull setting %d\n", pull);
235 return ret;
236 }
237
Jonas Karlman3a8a2992023-04-17 19:07:23 +0000238 /*
239 * In the TRM, pull-up being 1 for everything except the GPIO0_D3-D6,
240 * where that pull up value becomes 3.
241 */
242 if (bank->bank_num == 0 && pin_num >= 27 && pin_num <= 30) {
243 if (ret == 1)
244 ret = 3;
245 }
246
Jagan Teki7fc80642023-02-17 17:28:43 +0530247 /* enable the write to the equivalent lower bits */
248 data = ((1 << ROCKCHIP_PULL_BITS_PER_PIN) - 1) << (bit + 16);
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000249 rmask = data | (data >> 16);
Jagan Teki7fc80642023-02-17 17:28:43 +0530250 data |= (ret << bit);
Jagan Teki7fc80642023-02-17 17:28:43 +0530251
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000252 return regmap_update_bits(regmap, reg, rmask, data);
Jagan Teki7fc80642023-02-17 17:28:43 +0530253}
254
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000255#define GRF_GPIO1C5_DS 0x0840
256#define GRF_GPIO2A2_DS 0x0844
257#define GRF_GPIO2B0_DS 0x0848
258#define GRF_GPIO3A0_DS 0x084c
259#define GRF_GPIO3A6_DS 0x0850
260#define GRF_GPIO4A0_DS 0x0854
261
Jagan Teki7fc80642023-02-17 17:28:43 +0530262static int rk3568_set_drive(struct rockchip_pin_bank *bank,
263 int pin_num, int strength)
264{
265 struct regmap *regmap;
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000266 int reg, ret;
267 u32 data, rmask;
Jagan Teki7fc80642023-02-17 17:28:43 +0530268 u8 bit;
269 int drv = (1 << (strength + 1)) - 1;
Jagan Teki7fc80642023-02-17 17:28:43 +0530270
271 rk3568_calc_drv_reg_and_bit(bank, pin_num, &regmap, &reg, &bit);
272
273 /* enable the write to the equivalent lower bits */
274 data = ((1 << RK3568_DRV_BITS_PER_PIN) - 1) << (bit + 16);
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000275 rmask = data | (data >> 16);
Jagan Teki7fc80642023-02-17 17:28:43 +0530276 data |= (drv << bit);
277
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000278 ret = regmap_update_bits(regmap, reg, rmask, data);
Jagan Teki7fc80642023-02-17 17:28:43 +0530279 if (ret)
280 return ret;
281
282 if (bank->bank_num == 1 && pin_num == 21)
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000283 reg = GRF_GPIO1C5_DS;
Jagan Teki7fc80642023-02-17 17:28:43 +0530284 else if (bank->bank_num == 2 && pin_num == 2)
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000285 reg = GRF_GPIO2A2_DS;
Jagan Teki7fc80642023-02-17 17:28:43 +0530286 else if (bank->bank_num == 2 && pin_num == 8)
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000287 reg = GRF_GPIO2B0_DS;
Jagan Teki7fc80642023-02-17 17:28:43 +0530288 else if (bank->bank_num == 3 && pin_num == 0)
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000289 reg = GRF_GPIO3A0_DS;
Jagan Teki7fc80642023-02-17 17:28:43 +0530290 else if (bank->bank_num == 3 && pin_num == 6)
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000291 reg = GRF_GPIO3A6_DS;
Jagan Teki7fc80642023-02-17 17:28:43 +0530292 else if (bank->bank_num == 4 && pin_num == 0)
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000293 reg = GRF_GPIO4A0_DS;
Jagan Teki7fc80642023-02-17 17:28:43 +0530294 else
295 return 0;
296
297 data = ((1 << RK3568_DRV_BITS_PER_PIN) - 1) << 16;
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000298 rmask = data | (data >> 16);
299 data |= drv >> 6;
Jagan Teki7fc80642023-02-17 17:28:43 +0530300
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000301 return regmap_update_bits(regmap, reg, rmask, data);
Jagan Teki7fc80642023-02-17 17:28:43 +0530302}
303
304static int rk3568_set_schmitt(struct rockchip_pin_bank *bank,
305 int pin_num, int enable)
306{
307 struct regmap *regmap;
308 int reg;
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000309 u32 data, rmask;
Jagan Teki7fc80642023-02-17 17:28:43 +0530310 u8 bit;
311
312 rk3568_calc_schmitt_reg_and_bit(bank, pin_num, &regmap, &reg, &bit);
313
314 /* enable the write to the equivalent lower bits */
315 data = ((1 << RK3568_SCHMITT_BITS_PER_PIN) - 1) << (bit + 16);
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000316 rmask = data | (data >> 16);
317 data |= ((enable ? 0x2 : 0x1) << bit);
Jagan Teki7fc80642023-02-17 17:28:43 +0530318
Jonas Karlmanc9bb9e32023-08-14 00:28:26 +0000319 return regmap_update_bits(regmap, reg, rmask, data);
Jagan Teki7fc80642023-02-17 17:28:43 +0530320}
321
322static struct rockchip_pin_bank rk3568_pin_banks[] = {
323 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
324 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
325 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
326 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT),
327 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT,
328 IOMUX_WIDTH_4BIT,
329 IOMUX_WIDTH_4BIT,
330 IOMUX_WIDTH_4BIT),
331 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT,
332 IOMUX_WIDTH_4BIT,
333 IOMUX_WIDTH_4BIT,
334 IOMUX_WIDTH_4BIT),
335 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT,
336 IOMUX_WIDTH_4BIT,
337 IOMUX_WIDTH_4BIT,
338 IOMUX_WIDTH_4BIT),
339 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
340 IOMUX_WIDTH_4BIT,
341 IOMUX_WIDTH_4BIT,
342 IOMUX_WIDTH_4BIT),
343};
344
345static const struct rockchip_pin_ctrl rk3568_pin_ctrl = {
346 .pin_banks = rk3568_pin_banks,
347 .nr_banks = ARRAY_SIZE(rk3568_pin_banks),
348 .nr_pins = 160,
349 .grf_mux_offset = 0x0,
350 .pmu_mux_offset = 0x0,
351 .iomux_routes = rk3568_mux_route_data,
352 .niomux_routes = ARRAY_SIZE(rk3568_mux_route_data),
353 .set_mux = rk3568_set_mux,
354 .set_pull = rk3568_set_pull,
355 .set_drive = rk3568_set_drive,
356 .set_schmitt = rk3568_set_schmitt,
357};
358
359static const struct udevice_id rk3568_pinctrl_ids[] = {
360 {
361 .compatible = "rockchip,rk3568-pinctrl",
362 .data = (ulong)&rk3568_pin_ctrl
363 },
364 { }
365};
366
367U_BOOT_DRIVER(pinctrl_rk3568) = {
368 .name = "rockchip_rk3568_pinctrl",
369 .id = UCLASS_PINCTRL,
370 .of_match = rk3568_pinctrl_ids,
371 .priv_auto = sizeof(struct rockchip_pinctrl_priv),
372 .ops = &rockchip_pinctrl_ops,
373#if CONFIG_IS_ENABLED(OF_REAL)
374 .bind = dm_scan_fdt_dev,
375#endif
376 .probe = rockchip_pinctrl_probe,
377};