mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] pinctrl: abx500: Fix pull up/down feature
@ 2013-05-24 12:06 patrice.chotard.st
  2013-05-24 12:06 ` [PATCH 1/3] pinctrl: abx500: fix abx500_config_pull_updown patrice.chotard.st
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: patrice.chotard.st @ 2013-05-24 12:06 UTC (permalink / raw)
  To: linux-kernel, Linus Walleij
  Cc: Olivier Clergeaud, Lee Jones, Fabio Baltieri, Patrice Chotard

From: Patrice Chotard <patrice.chotard@st.com>

This series fixes the pull up/down feature of ABx500 family ASIC.

Patrice Chotard (3):
  pinctrl: abx500: fix abx500_config_pull_updown
  pinctrl: abx500: allow to set pull up
  pinctrl: abx500: fix abx500_gpio_dbg_show_one() to show pull up/down

 drivers/pinctrl/pinctrl-abx500.c |  110 ++++++++++++++++++++++++++++++++------
 1 file changed, 93 insertions(+), 17 deletions(-)

-- 
1.7.10


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] pinctrl: abx500: fix abx500_config_pull_updown
  2013-05-24 12:06 [PATCH 0/3] pinctrl: abx500: Fix pull up/down feature patrice.chotard.st
@ 2013-05-24 12:06 ` patrice.chotard.st
  2013-05-24 12:06 ` [PATCH 2/3] pinctrl: abx500: allow to set pull up patrice.chotard.st
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: patrice.chotard.st @ 2013-05-24 12:06 UTC (permalink / raw)
  To: linux-kernel, Linus Walleij
  Cc: Olivier Clergeaud, Lee Jones, Fabio Baltieri, Patrice Chotard

From: Patrice Chotard <patrice.chotard@st.com>

Fix abx500_config_pull_updown() to set correct bit in
AB8540_GPIO_PULL_UPDOWN_REG.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---
 drivers/pinctrl/pinctrl-abx500.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-abx500.c b/drivers/pinctrl/pinctrl-abx500.c
index bbada4b..7d2e8d7 100644
--- a/drivers/pinctrl/pinctrl-abx500.c
+++ b/drivers/pinctrl/pinctrl-abx500.c
@@ -203,7 +203,7 @@ static int abx500_config_pull_updown(struct abx500_pinctrl *pct,
 		goto out;
 	}
 
-	pos = offset << 1;
+	pos = (offset - pullud->first_pin) << 1;
 
 	ret = abx500_mask_and_set_register_interruptible(pct->dev,
 			AB8500_MISC, AB8540_GPIO_PULL_UPDOWN_REG,
-- 
1.7.10


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] pinctrl: abx500: allow to set pull up
  2013-05-24 12:06 [PATCH 0/3] pinctrl: abx500: Fix pull up/down feature patrice.chotard.st
  2013-05-24 12:06 ` [PATCH 1/3] pinctrl: abx500: fix abx500_config_pull_updown patrice.chotard.st
@ 2013-05-24 12:06 ` patrice.chotard.st
  2013-05-24 12:06 ` [PATCH 3/3] pinctrl: abx500: fix abx500_gpio_dbg_show_one() to show pull up/down patrice.chotard.st
  2013-05-28  7:06 ` [PATCH 0/3] pinctrl: abx500: Fix pull up/down feature Linus Walleij
  3 siblings, 0 replies; 5+ messages in thread
From: patrice.chotard.st @ 2013-05-24 12:06 UTC (permalink / raw)
  To: linux-kernel, Linus Walleij
  Cc: Olivier Clergeaud, Lee Jones, Fabio Baltieri, Patrice Chotard

From: Patrice Chotard <patrice.chotard@st.com>

On ABx500 chip family, all pins support only pull down except for
AB8540 which supports pull up/down on some pins.
Rework abx500_pin_config_set to be able to set pull up on
pins which support this feature.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---
 drivers/pinctrl/pinctrl-abx500.c |   24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-abx500.c b/drivers/pinctrl/pinctrl-abx500.c
index 7d2e8d7..7f2202a 100644
--- a/drivers/pinctrl/pinctrl-abx500.c
+++ b/drivers/pinctrl/pinctrl-abx500.c
@@ -725,7 +725,7 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev,
 	struct pullud *pullud = pct->soc->pullud;
 	struct gpio_chip *chip = &pct->chip;
 	unsigned offset;
-	int ret;
+	int ret = 0;
 	enum pin_config_param param = pinconf_to_config_param(config);
 	enum pin_config_param argument = pinconf_to_config_argument(config);
 
@@ -763,6 +763,28 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev,
 				offset, argument ? 0 : 1);
 		break;
 
+	case PIN_CONFIG_BIAS_PULL_UP:
+		/*
+		 * if argument = 1 set the pull up
+		 * else clear the pull up
+		 */
+		ret = abx500_gpio_direction_input(chip, offset);
+		/*
+		 * Some chips only support pull down, while some actually
+		 * support both pull up and pull down. Such chips have
+		 * a "pullud" range specified for the pins that support
+		 * both features. If the pin is not within that range, do
+		 * nothing
+		 */
+		if (pullud &&
+		    pin >= pullud->first_pin &&
+		    pin <= pullud->last_pin) {
+			ret = abx500_config_pull_updown(pct,
+				pin,
+				argument ? ABX500_GPIO_PULL_UP : ABX500_GPIO_PULL_NONE);
+		}
+		break;
+
 	case PIN_CONFIG_OUTPUT:
 		ret = abx500_gpio_direction_output(chip, offset, argument);
 
-- 
1.7.10


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] pinctrl: abx500: fix abx500_gpio_dbg_show_one() to show pull up/down
  2013-05-24 12:06 [PATCH 0/3] pinctrl: abx500: Fix pull up/down feature patrice.chotard.st
  2013-05-24 12:06 ` [PATCH 1/3] pinctrl: abx500: fix abx500_config_pull_updown patrice.chotard.st
  2013-05-24 12:06 ` [PATCH 2/3] pinctrl: abx500: allow to set pull up patrice.chotard.st
@ 2013-05-24 12:06 ` patrice.chotard.st
  2013-05-28  7:06 ` [PATCH 0/3] pinctrl: abx500: Fix pull up/down feature Linus Walleij
  3 siblings, 0 replies; 5+ messages in thread
From: patrice.chotard.st @ 2013-05-24 12:06 UTC (permalink / raw)
  To: linux-kernel, Linus Walleij
  Cc: Olivier Clergeaud, Lee Jones, Fabio Baltieri, Patrice Chotard

From: Patrice Chotard <patrice.chotard@st.com>

_ rework abx500_gpio_dbg_show_one() to take in account pull up/down
  feature available on AB8540 only.
_ add abx500_get_pull_updown() needed by abx500_gpio_dbg_show_one()
_ rename abx500_config_pull_updown() to abx500_set_pull_updown()

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---
 drivers/pinctrl/pinctrl-abx500.c |   86 +++++++++++++++++++++++++++++++-------
 1 file changed, 70 insertions(+), 16 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-abx500.c b/drivers/pinctrl/pinctrl-abx500.c
index 7f2202a..0157fd3 100644
--- a/drivers/pinctrl/pinctrl-abx500.c
+++ b/drivers/pinctrl/pinctrl-abx500.c
@@ -181,10 +181,11 @@ static void abx500_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
 		dev_err(pct->dev, "%s write failed\n", __func__);
 }
 
-static int abx500_config_pull_updown(struct abx500_pinctrl *pct,
-				     int offset, enum abx500_gpio_pull_updown val)
+static int abx500_get_pull_updown(struct abx500_pinctrl *pct, int offset,
+				  enum abx500_gpio_pull_updown *pull_updown)
 {
 	u8 pos;
+	u8 val;
 	int ret;
 	struct pullud *pullud;
 
@@ -203,6 +204,40 @@ static int abx500_config_pull_updown(struct abx500_pinctrl *pct,
 		goto out;
 	}
 
+	ret = abx500_get_register_interruptible(pct->dev,
+			AB8500_MISC, AB8540_GPIO_PULL_UPDOWN_REG, &val);
+
+	pos = (offset - pullud->first_pin) << 1;
+	*pull_updown = (val >> pos) & AB8540_GPIO_PULL_UPDOWN_MASK;
+
+out:
+	if (ret < 0)
+		dev_err(pct->dev, "%s failed (%d)\n", __func__, ret);
+
+	return ret;
+}
+
+static int abx500_set_pull_updown(struct abx500_pinctrl *pct,
+				  int offset, enum abx500_gpio_pull_updown val)
+{
+	u8 pos;
+	int ret;
+	struct pullud *pullud;
+
+	if (!pct->soc->pullud) {
+		dev_err(pct->dev, "%s AB chip doesn't support pull up/down feature",
+				__func__);
+		ret = -EPERM;
+		goto out;
+	}
+
+	pullud = pct->soc->pullud;
+
+	if ((offset < pullud->first_pin)
+		|| (offset > pullud->last_pin)) {
+		ret = -EINVAL;
+		goto out;
+	}
 	pos = (offset - pullud->first_pin) << 1;
 
 	ret = abx500_mask_and_set_register_interruptible(pct->dev,
@@ -238,7 +273,7 @@ static int abx500_gpio_direction_output(struct gpio_chip *chip,
 	/* if supported, disable both pull down and pull up */
 	gpio = offset + 1;
 	if (pullud && gpio >= pullud->first_pin && gpio <= pullud->last_pin) {
-		ret = abx500_config_pull_updown(pct,
+		ret = abx500_set_pull_updown(pct,
 				gpio,
 				ABX500_GPIO_PULL_NONE);
 		if (ret < 0)
@@ -462,11 +497,14 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s,
 				     struct gpio_chip *chip,
 				     unsigned offset, unsigned gpio)
 {
+	struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
+	struct pullud *pullud = pct->soc->pullud;
 	const char *label = gpiochip_is_requested(chip, offset - 1);
 	u8 gpio_offset = offset - 1;
 	int mode = -1;
 	bool is_out;
-	bool pull;
+	bool pd;
+	enum abx500_gpio_pull_updown pud;
 
 	const char *modes[] = {
 		[ABX500_DEFAULT]	= "default",
@@ -475,21 +513,37 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s,
 		[ABX500_ALT_C]		= "altC",
 	};
 
+	const char *pull_up_down[] = {
+		[ABX500_GPIO_PULL_DOWN]		= "pull down",
+		[ABX500_GPIO_PULL_NONE]		= "pull none",
+		[ABX500_GPIO_PULL_NONE + 1]	= "pull none",
+		[ABX500_GPIO_PULL_UP]		= "pull up",
+	};
+
 	abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG, gpio_offset, &is_out);
-	abx500_gpio_get_bit(chip, AB8500_GPIO_PUD1_REG, gpio_offset, &pull);
+
+	seq_printf(s, " gpio-%-3d (%-20.20s) %-3s",
+		   gpio, label ?: "(none)",
+		   is_out ? "out" : "in ");
+
+	if (!is_out) {
+		if (pullud &&
+		   (offset >= pullud->first_pin) &&
+		   (offset <= pullud->last_pin)) {
+			abx500_get_pull_updown(pct, offset, &pud);
+			seq_printf(s, " %-9s", pull_up_down[pud]);
+		} else {
+			abx500_gpio_get_bit(chip, AB8500_GPIO_PUD1_REG,
+					    gpio_offset, &pd);
+			seq_printf(s, " %-9s", pull_up_down[pd]);
+		}
+	} else
+		seq_printf(s, " %-9s", chip->get(chip, offset) ? "hi" : "lo");
 
 	if (pctldev)
 		mode = abx500_get_mode(pctldev, chip, offset);
 
-	seq_printf(s, " gpio-%-3d (%-20.20s) %-3s %-9s %s",
-		   gpio, label ?: "(none)",
-		   is_out ? "out" : "in ",
-		   is_out ?
-		   (chip->get
-		   ? (chip->get(chip, offset) ? "hi" : "lo")
-		   : "?  ")
-		   : (pull ? "pull up" : "pull down"),
-		   (mode < 0) ? "unknown" : modes[mode]);
+	seq_printf(s, " %s", (mode < 0) ? "unknown" : modes[mode]);
 }
 
 static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
@@ -754,7 +808,7 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev,
 		if (pullud &&
 		    pin >= pullud->first_pin &&
 		    pin <= pullud->last_pin)
-			ret = abx500_config_pull_updown(pct,
+			ret = abx500_set_pull_updown(pct,
 				pin,
 				argument ? ABX500_GPIO_PULL_DOWN : ABX500_GPIO_PULL_NONE);
 		else
@@ -779,7 +833,7 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev,
 		if (pullud &&
 		    pin >= pullud->first_pin &&
 		    pin <= pullud->last_pin) {
-			ret = abx500_config_pull_updown(pct,
+			ret = abx500_set_pull_updown(pct,
 				pin,
 				argument ? ABX500_GPIO_PULL_UP : ABX500_GPIO_PULL_NONE);
 		}
-- 
1.7.10


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] pinctrl: abx500: Fix pull up/down feature
  2013-05-24 12:06 [PATCH 0/3] pinctrl: abx500: Fix pull up/down feature patrice.chotard.st
                   ` (2 preceding siblings ...)
  2013-05-24 12:06 ` [PATCH 3/3] pinctrl: abx500: fix abx500_gpio_dbg_show_one() to show pull up/down patrice.chotard.st
@ 2013-05-28  7:06 ` Linus Walleij
  3 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2013-05-28  7:06 UTC (permalink / raw)
  To: Patrice Chotard
  Cc: linux-kernel, Olivier Clergeaud, Lee Jones, Fabio Baltieri,
	Patrice Chotard

On Fri, May 24, 2013 at 2:06 PM,  <patrice.chotard.st@gmail.com> wrote:

> From: Patrice Chotard <patrice.chotard@st.com>
>
> This series fixes the pull up/down feature of ABx500 family ASIC.
>
> Patrice Chotard (3):
>   pinctrl: abx500: fix abx500_config_pull_updown
>   pinctrl: abx500: allow to set pull up
>   pinctrl: abx500: fix abx500_gpio_dbg_show_one() to show pull up/down
>
>  drivers/pinctrl/pinctrl-abx500.c |  110 ++++++++++++++++++++++++++++++++------
>  1 file changed, 93 insertions(+), 17 deletions(-)

All three patches applied, thanks!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-05-28  7:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-24 12:06 [PATCH 0/3] pinctrl: abx500: Fix pull up/down feature patrice.chotard.st
2013-05-24 12:06 ` [PATCH 1/3] pinctrl: abx500: fix abx500_config_pull_updown patrice.chotard.st
2013-05-24 12:06 ` [PATCH 2/3] pinctrl: abx500: allow to set pull up patrice.chotard.st
2013-05-24 12:06 ` [PATCH 3/3] pinctrl: abx500: fix abx500_gpio_dbg_show_one() to show pull up/down patrice.chotard.st
2013-05-28  7:06 ` [PATCH 0/3] pinctrl: abx500: Fix pull up/down feature Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®