diff mbox

[v1,1/2] pinctrl: rockchip:Add input schmitt support

Message ID 1487068541-14120-2-git-send-email-david.wu@rock-chips.com (mailing list archive)
State New, archived
Headers show

Commit Message

David Wu Feb. 14, 2017, 10:35 a.m. UTC
From: "david.wu" <david.wu@rock-chips.com>

To prevent external noise crosstalk, some pins need to
enable input schmitt, like i2c pins, 32k-input pin and so on.

Signed-off-by: david.wu <david.wu@rock-chips.com>
---
 drivers/pinctrl/pinctrl-rockchip.c | 69 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

Comments

Heiko Stübner Feb. 23, 2017, 4:51 p.m. UTC | #1
Hi David,

Am Dienstag, 14. Februar 2017, 18:35:40 CET schrieb David Wu:
> From: "david.wu" <david.wu@rock-chips.com>
> 
> To prevent external noise crosstalk, some pins need to
> enable input schmitt, like i2c pins, 32k-input pin and so on.
> 
> Signed-off-by: david.wu <david.wu@rock-chips.com>
> ---
>  drivers/pinctrl/pinctrl-rockchip.c | 69
> ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
> 
> diff --git a/drivers/pinctrl/pinctrl-rockchip.c
> b/drivers/pinctrl/pinctrl-rockchip.c index a20ce9f..6a071b1 100644
> --- a/drivers/pinctrl/pinctrl-rockchip.c
> +++ b/drivers/pinctrl/pinctrl-rockchip.c
> @@ -308,6 +308,9 @@ struct rockchip_pin_ctrl {
>  				    int *reg, u8 *bit);
>  	void	(*iomux_recalc)(u8 bank_num, int pin, int *reg,
>  				u8 *bit, int *mask);
> +	void	(*schmitt_calc_reg)(struct rockchip_pin_bank *bank,
> +				    int pin_num, struct regmap **regmap,
> +				    int *reg, u8 *bit);
>  };
> 
>  struct rockchip_pin_config {
> @@ -1355,6 +1358,53 @@ static int rockchip_set_pull(struct rockchip_pin_bank
> *bank, return ret;
>  }
> 
> +static int rockchip_get_schmitt(struct rockchip_pin_bank *bank, int
> pin_num) +{
> +	struct rockchip_pinctrl *info = bank->drvdata;
> +	struct rockchip_pin_ctrl *ctrl = info->ctrl;
> +	struct regmap *regmap;
> +	int reg, ret;
> +	u8 bit;
> +	u32 data;
> +
> +	ctrl->schmitt_calc_reg(bank, pin_num, &regmap, &reg, &bit);

we might want to have and check an actual return value here.
On things like the rk3288 only some special pins have these schmitt triggers 
it seems, so we might want to abort if something tries to access an 
unsupported one.

> +
> +	ret = regmap_read(regmap, reg, &data);
> +	if (ret)
> +		return ret;
> +
> +	data >>= bit;
> +	return data & 0x1;

The mask seems to also be variable, for example on the rk3399 there seem to be 
multiple "levels" for at least gpio2. So your calc-callback might want to also 
set the right mask.

Otherwise looks good.


Heiko
David Wu Feb. 28, 2017, 11:12 a.m. UTC | #2
Hi Heiko,

在 2017/2/24 0:51, Heiko Stuebner 写道:
> Hi David,
>
> Am Dienstag, 14. Februar 2017, 18:35:40 CET schrieb David Wu:
>> From: "david.wu" <david.wu@rock-chips.com>
>>
>>  struct rockchip_pin_config {
>> @@ -1355,6 +1358,53 @@ static int rockchip_set_pull(struct rockchip_pin_bank
>> *bank, return ret;
>>  }
>>
>> +static int rockchip_get_schmitt(struct rockchip_pin_bank *bank, int
>> pin_num) +{
>> +	struct rockchip_pinctrl *info = bank->drvdata;
>> +	struct rockchip_pin_ctrl *ctrl = info->ctrl;
>> +	struct regmap *regmap;
>> +	int reg, ret;
>> +	u8 bit;
>> +	u32 data;
>> +
>> +	ctrl->schmitt_calc_reg(bank, pin_num, &regmap, &reg, &bit);
>
> we might want to have and check an actual return value here.
> On things like the rk3288 only some special pins have these schmitt triggers
> it seems, so we might want to abort if something tries to access an
> unsupported one.

Thanks, i forget to check the return value.
>
>> +
>> +	ret = regmap_read(regmap, reg, &data);
>> +	if (ret)
>> +		return ret;
>> +
>> +	data >>= bit;
>> +	return data & 0x1;
>
> The mask seems to also be variable, for example on the rk3399 there seem to be
> multiple "levels" for at least gpio2. So your calc-callback might want to also
> set the right mask.

To the multiple "levels", i think we can use the 
"PIN_CONFIG_INPUT_SCHMITT" pin config, which described at pinconf-generic.h.

  * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in
  *	schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis,
  *	the threshold value is given on a custom format as argument when
  *	setting pins to this mode.

>
> Otherwise looks good.
>
>
> Heiko
>
>
>
>
diff mbox

Patch

diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
index a20ce9f..6a071b1 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -308,6 +308,9 @@  struct rockchip_pin_ctrl {
 				    int *reg, u8 *bit);
 	void	(*iomux_recalc)(u8 bank_num, int pin, int *reg,
 				u8 *bit, int *mask);
+	void	(*schmitt_calc_reg)(struct rockchip_pin_bank *bank,
+				    int pin_num, struct regmap **regmap,
+				    int *reg, u8 *bit);
 };
 
 struct rockchip_pin_config {
@@ -1355,6 +1358,53 @@  static int rockchip_set_pull(struct rockchip_pin_bank *bank,
 	return ret;
 }
 
+static int rockchip_get_schmitt(struct rockchip_pin_bank *bank, int pin_num)
+{
+	struct rockchip_pinctrl *info = bank->drvdata;
+	struct rockchip_pin_ctrl *ctrl = info->ctrl;
+	struct regmap *regmap;
+	int reg, ret;
+	u8 bit;
+	u32 data;
+
+	ctrl->schmitt_calc_reg(bank, pin_num, &regmap, &reg, &bit);
+
+	ret = regmap_read(regmap, reg, &data);
+	if (ret)
+		return ret;
+
+	data >>= bit;
+	return data & 0x1;
+}
+
+static int rockchip_set_schmitt(struct rockchip_pin_bank *bank,
+				int pin_num, int enable)
+{
+	struct rockchip_pinctrl *info = bank->drvdata;
+	struct rockchip_pin_ctrl *ctrl = info->ctrl;
+	struct regmap *regmap;
+	int reg, ret;
+	unsigned long flags;
+	u8 bit;
+	u32 data, rmask;
+
+	dev_dbg(info->dev, "setting input schmitt of GPIO%d-%d to %d\n",
+		bank->bank_num, pin_num, enable);
+
+	ctrl->schmitt_calc_reg(bank, pin_num, &regmap, &reg, &bit);
+
+	spin_lock_irqsave(&bank->slock, flags);
+
+	/* enable the write to the equivalent lower bits */
+	data = BIT(bit + 16) | (enable << bit);
+	rmask = BIT(bit + 16) | BIT(bit);
+
+	ret = regmap_update_bits(regmap, reg, rmask, data);
+	spin_unlock_irqrestore(&bank->slock, flags);
+
+	return ret;
+}
+
 /*
  * Pinmux_ops handling
  */
@@ -1574,6 +1624,15 @@  static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			if (rc < 0)
 				return rc;
 			break;
+		case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
+			if (!info->ctrl->schmitt_calc_reg)
+				return -ENOTSUPP;
+
+			rc = rockchip_set_schmitt(bank,
+						  pin - bank->pin_base, arg);
+			if (rc < 0)
+				return rc;
+			break;
 		default:
 			return -ENOTSUPP;
 			break;
@@ -1634,6 +1693,16 @@  static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
 
 		arg = rc;
 		break;
+	case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
+		if (!info->ctrl->schmitt_calc_reg)
+			return -ENOTSUPP;
+
+		rc = rockchip_get_schmitt(bank, pin - bank->pin_base);
+		if (rc < 0)
+			return rc;
+
+		arg = rc;
+		break;
 	default:
 		return -ENOTSUPP;
 		break;