Commit ef17f69f authored by Heiko Stübner's avatar Heiko Stübner Committed by Linus Walleij

pinctrl: rockchip: generalize perpin driver-strength setting

The upcoming support for the RK3368 ARM64 SoC also supports perpin
drive strength settings (at different register positions), so generalize
the register and offset calculation to easily support this one too.
Signed-off-by: default avatarHeiko Stuebner <heiko@sntech.de>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 7ac91bda
...@@ -163,6 +163,9 @@ struct rockchip_pin_ctrl { ...@@ -163,6 +163,9 @@ struct rockchip_pin_ctrl {
void (*pull_calc_reg)(struct rockchip_pin_bank *bank, void (*pull_calc_reg)(struct rockchip_pin_bank *bank,
int pin_num, struct regmap **regmap, int pin_num, struct regmap **regmap,
int *reg, u8 *bit); int *reg, u8 *bit);
void (*drv_calc_reg)(struct rockchip_pin_bank *bank,
int pin_num, struct regmap **regmap,
int *reg, u8 *bit);
}; };
struct rockchip_pin_config { struct rockchip_pin_config {
...@@ -581,7 +584,6 @@ static void rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, ...@@ -581,7 +584,6 @@ static void rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
#define RK3288_DRV_BITS_PER_PIN 2 #define RK3288_DRV_BITS_PER_PIN 2
#define RK3288_DRV_PINS_PER_REG 8 #define RK3288_DRV_PINS_PER_REG 8
#define RK3288_DRV_BANK_STRIDE 16 #define RK3288_DRV_BANK_STRIDE 16
static int rk3288_drv_list[] = { 2, 4, 8, 12 };
static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
int pin_num, struct regmap **regmap, int pin_num, struct regmap **regmap,
...@@ -611,14 +613,19 @@ static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank, ...@@ -611,14 +613,19 @@ static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
} }
} }
static int rk3288_get_drive(struct rockchip_pin_bank *bank, int pin_num) static int rockchip_perpin_drv_list[] = { 2, 4, 8, 12 };
static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank,
int pin_num)
{ {
struct rockchip_pinctrl *info = bank->drvdata;
struct rockchip_pin_ctrl *ctrl = info->ctrl;
struct regmap *regmap; struct regmap *regmap;
int reg, ret; int reg, ret;
u32 data; u32 data;
u8 bit; u8 bit;
rk3288_calc_drv_reg_and_bit(bank, pin_num, &regmap, &reg, &bit); ctrl->drv_calc_reg(bank, pin_num, &regmap, &reg, &bit);
ret = regmap_read(regmap, reg, &data); ret = regmap_read(regmap, reg, &data);
if (ret) if (ret)
...@@ -627,24 +634,25 @@ static int rk3288_get_drive(struct rockchip_pin_bank *bank, int pin_num) ...@@ -627,24 +634,25 @@ static int rk3288_get_drive(struct rockchip_pin_bank *bank, int pin_num)
data >>= bit; data >>= bit;
data &= (1 << RK3288_DRV_BITS_PER_PIN) - 1; data &= (1 << RK3288_DRV_BITS_PER_PIN) - 1;
return rk3288_drv_list[data]; return rockchip_perpin_drv_list[data];
} }
static int rk3288_set_drive(struct rockchip_pin_bank *bank, int pin_num, static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
int strength) int pin_num, int strength)
{ {
struct rockchip_pinctrl *info = bank->drvdata; struct rockchip_pinctrl *info = bank->drvdata;
struct rockchip_pin_ctrl *ctrl = info->ctrl;
struct regmap *regmap; struct regmap *regmap;
unsigned long flags; unsigned long flags;
int reg, ret, i; int reg, ret, i;
u32 data, rmask; u32 data, rmask;
u8 bit; u8 bit;
rk3288_calc_drv_reg_and_bit(bank, pin_num, &regmap, &reg, &bit); ctrl->drv_calc_reg(bank, pin_num, &regmap, &reg, &bit);
ret = -EINVAL; ret = -EINVAL;
for (i = 0; i < ARRAY_SIZE(rk3288_drv_list); i++) { for (i = 0; i < ARRAY_SIZE(rockchip_perpin_drv_list); i++) {
if (rk3288_drv_list[i] == strength) { if (rockchip_perpin_drv_list[i] == strength) {
ret = i; ret = i;
break; break;
} }
...@@ -983,10 +991,11 @@ static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin, ...@@ -983,10 +991,11 @@ static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
break; break;
case PIN_CONFIG_DRIVE_STRENGTH: case PIN_CONFIG_DRIVE_STRENGTH:
/* rk3288 is the first with per-pin drive-strength */ /* rk3288 is the first with per-pin drive-strength */
if (info->ctrl->type != RK3288) if (!info->ctrl->drv_calc_reg)
return -ENOTSUPP; return -ENOTSUPP;
rc = rk3288_set_drive(bank, pin - bank->pin_base, arg); rc = rockchip_set_drive_perpin(bank,
pin - bank->pin_base, arg);
if (rc < 0) if (rc < 0)
return rc; return rc;
break; break;
...@@ -1041,10 +1050,10 @@ static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin, ...@@ -1041,10 +1050,10 @@ static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
break; break;
case PIN_CONFIG_DRIVE_STRENGTH: case PIN_CONFIG_DRIVE_STRENGTH:
/* rk3288 is the first with per-pin drive-strength */ /* rk3288 is the first with per-pin drive-strength */
if (info->ctrl->type != RK3288) if (!info->ctrl->drv_calc_reg)
return -ENOTSUPP; return -ENOTSUPP;
rc = rk3288_get_drive(bank, pin - bank->pin_base); rc = rockchip_get_drive_perpin(bank, pin - bank->pin_base);
if (rc < 0) if (rc < 0)
return rc; return rc;
...@@ -2056,6 +2065,7 @@ static struct rockchip_pin_ctrl rk3288_pin_ctrl = { ...@@ -2056,6 +2065,7 @@ static struct rockchip_pin_ctrl rk3288_pin_ctrl = {
.grf_mux_offset = 0x0, .grf_mux_offset = 0x0,
.pmu_mux_offset = 0x84, .pmu_mux_offset = 0x84,
.pull_calc_reg = rk3288_calc_pull_reg_and_bit, .pull_calc_reg = rk3288_calc_pull_reg_and_bit,
.drv_calc_reg = rk3288_calc_drv_reg_and_bit,
}; };
static const struct of_device_id rockchip_pinctrl_dt_match[] = { static const struct of_device_id rockchip_pinctrl_dt_match[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment