1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2019 Rockchip Electronics Co., Ltd
8 #include <dm/pinctrl.h>
12 #include "pinctrl-rockchip.h"
14 static struct rockchip_mux_route_data rk3228_mux_route_data[] = {
28 .route_val = BIT(16) | BIT(0),
35 .route_val = BIT(16 + 1),
42 .route_val = BIT(16 + 1) | BIT(1),
49 .route_val = BIT(16 + 2),
56 .route_val = BIT(16 + 2) | BIT(2),
63 .route_val = BIT(16 + 3),
70 .route_val = BIT(16 + 3) | BIT(3),
77 .route_val = BIT(16 + 4),
84 .route_val = BIT(16 + 4) | BIT(4),
91 .route_val = BIT(16 + 5),
98 .route_val = BIT(16 + 5) | BIT(5),
104 .route_offset = 0x50,
105 .route_val = BIT(16 + 7),
111 .route_offset = 0x50,
112 .route_val = BIT(16 + 7) | BIT(7),
118 .route_offset = 0x50,
119 .route_val = BIT(16 + 8),
125 .route_offset = 0x50,
126 .route_val = BIT(16 + 8) | BIT(8),
132 .route_offset = 0x50,
133 .route_val = BIT(16 + 11),
139 .route_offset = 0x50,
140 .route_val = BIT(16 + 11) | BIT(11),
144 #define RK3228_PULL_OFFSET 0x100
146 static void rk3228_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
147 int pin_num, struct regmap **regmap,
150 struct rockchip_pinctrl_priv *priv = bank->priv;
152 *regmap = priv->regmap_base;
153 *reg = RK3228_PULL_OFFSET;
154 *reg += bank->bank_num * ROCKCHIP_PULL_BANK_STRIDE;
155 *reg += ((pin_num / ROCKCHIP_PULL_PINS_PER_REG) * 4);
157 *bit = (pin_num % ROCKCHIP_PULL_PINS_PER_REG);
158 *bit *= ROCKCHIP_PULL_BITS_PER_PIN;
161 #define RK3228_DRV_GRF_OFFSET 0x200
163 static void rk3228_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
164 int pin_num, struct regmap **regmap,
167 struct rockchip_pinctrl_priv *priv = bank->priv;
169 *regmap = priv->regmap_base;
170 *reg = RK3228_DRV_GRF_OFFSET;
171 *reg += bank->bank_num * ROCKCHIP_DRV_BANK_STRIDE;
172 *reg += ((pin_num / ROCKCHIP_DRV_PINS_PER_REG) * 4);
174 *bit = (pin_num % ROCKCHIP_DRV_PINS_PER_REG);
175 *bit *= ROCKCHIP_DRV_BITS_PER_PIN;
178 static struct rockchip_pin_bank rk3228_pin_banks[] = {
179 PIN_BANK(0, 32, "gpio0"),
180 PIN_BANK(1, 32, "gpio1"),
181 PIN_BANK(2, 32, "gpio2"),
182 PIN_BANK(3, 32, "gpio3"),
185 static struct rockchip_pin_ctrl rk3228_pin_ctrl = {
186 .pin_banks = rk3228_pin_banks,
187 .nr_banks = ARRAY_SIZE(rk3228_pin_banks),
188 .label = "RK3228-GPIO",
190 .grf_mux_offset = 0x0,
191 .iomux_routes = rk3228_mux_route_data,
192 .niomux_routes = ARRAY_SIZE(rk3228_mux_route_data),
193 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
194 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
197 static const struct udevice_id rk3228_pinctrl_ids[] = {
199 .compatible = "rockchip,rk3228-pinctrl",
200 .data = (ulong)&rk3228_pin_ctrl
205 U_BOOT_DRIVER(pinctrl_rk3228) = {
206 .name = "rockchip_rk3228_pinctrl",
207 .id = UCLASS_PINCTRL,
208 .of_match = rk3228_pinctrl_ids,
209 .priv_auto_alloc_size = sizeof(struct rockchip_pinctrl_priv),
210 .ops = &rockchip_pinctrl_ops,
211 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
212 .bind = dm_scan_fdt_dev,
214 .probe = rockchip_pinctrl_probe,