From: Eric Ernst <[email protected]>
For Baytrail, you should never set a GPIO set to direct_irq
to output mode. When direct_irq_en is set for a GPIO, it is
tied directly to an APIC internally, and making the pad output
does not make any sense. Assert a WARN() in the event this happens.
Signed-off-by: Eric Ernst <[email protected]>
---
drivers/pinctrl/pinctrl-baytrail.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-baytrail.c b/drivers/pinctrl/pinctrl-baytrail.c
index e59983423991..fde3767df254 100644
--- a/drivers/pinctrl/pinctrl-baytrail.c
+++ b/drivers/pinctrl/pinctrl-baytrail.c
@@ -47,6 +47,7 @@
#define BYT_TRIG_POS BIT(25)
#define BYT_TRIG_LVL BIT(24)
#define BYT_PIN_MUX 0x07
+#define BYT_DIRECTIRQ BIT(27)
/* BYT_VAL_REG register bits */
#define BYT_INPUT_EN BIT(2) /* 0: input enabled (active low)*/
@@ -256,19 +257,29 @@ static int byt_gpio_direction_output(struct gpio_chip *chip,
unsigned gpio, int value)
{
struct byt_gpio *vg = to_byt_gpio(chip);
- void __iomem *reg = byt_gpio_reg(chip, gpio, BYT_VAL_REG);
+ void __iomem *conf_reg = byt_gpio_reg(chip, gpio, BYT_CONF0_REG);
+ void __iomem *value_reg = byt_gpio_reg(chip, gpio, BYT_VAL_REG);
unsigned long flags;
u32 reg_val;
spin_lock_irqsave(&vg->lock, flags);
- reg_val = readl(reg) | BYT_DIR_MASK;
+ /*
+ * Before making any direction modifications, do a check if gpio
+ * is set for direct IRQ. On baytrail, setting GPIO to output does
+ * not make sense, so let's at least warn the caller before they shoot
+ * themselves in the foot.
+ */
+ WARN((readl(conf_reg) & BYT_DIRECTIRQ),
+ "Potential Error: Setting GPIO with direct_irq_en to output");
+
+ reg_val = readl(value_reg) | BYT_DIR_MASK;
reg_val &= ~BYT_OUTPUT_EN;
if (value)
- writel(reg_val | BYT_LEVEL, reg);
+ writel(reg_val | BYT_LEVEL, value_reg);
else
- writel(reg_val & ~BYT_LEVEL, reg);
+ writel(reg_val & ~BYT_LEVEL, value_reg);
spin_unlock_irqrestore(&vg->lock, flags);
--
1.7.9.5
On Mon, Jun 02, 2014 at 02:12:07PM -0700, [email protected] wrote:
> From: Eric Ernst <[email protected]>
>
> For Baytrail, you should never set a GPIO set to direct_irq
> to output mode. When direct_irq_en is set for a GPIO, it is
> tied directly to an APIC internally, and making the pad output
> does not make any sense. Assert a WARN() in the event this happens.
Subject should probably be:
pinctrl: baytrail: Warn if direct IRQ GPIO is set to output
> Signed-off-by: Eric Ernst <[email protected]>
> ---
> drivers/pinctrl/pinctrl-baytrail.c | 19 +++++++++++++++----
> 1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pinctrl/pinctrl-baytrail.c b/drivers/pinctrl/pinctrl-baytrail.c
> index e59983423991..fde3767df254 100644
> --- a/drivers/pinctrl/pinctrl-baytrail.c
> +++ b/drivers/pinctrl/pinctrl-baytrail.c
> @@ -47,6 +47,7 @@
> #define BYT_TRIG_POS BIT(25)
> #define BYT_TRIG_LVL BIT(24)
> #define BYT_PIN_MUX 0x07
> +#define BYT_DIRECTIRQ BIT(27)
Please move this definition to be first, like:
/* BYT_CONF0_REG register bits */
#define BYT_DIRECT_IRQ_EN BIT(27)
#define BYT_TRIG_NEG BIT(26)
#define BYT_TRIG_POS BIT(25)
and I would call it BYT_DIRECT_IRQ_EN since it's name in datasheet is
"direct_irq_en".
>
> /* BYT_VAL_REG register bits */
> #define BYT_INPUT_EN BIT(2) /* 0: input enabled (active low)*/
> @@ -256,19 +257,29 @@ static int byt_gpio_direction_output(struct gpio_chip *chip,
> unsigned gpio, int value)
> {
> struct byt_gpio *vg = to_byt_gpio(chip);
> - void __iomem *reg = byt_gpio_reg(chip, gpio, BYT_VAL_REG);
> + void __iomem *conf_reg = byt_gpio_reg(chip, gpio, BYT_CONF0_REG);
> + void __iomem *value_reg = byt_gpio_reg(chip, gpio, BYT_VAL_REG);
Not sure if it is necessary to rename reg -> value_reg. It just makes
the patch bigger than it has to be since you also need to rename stuff
below.
Otherwise looks good.
> unsigned long flags;
> u32 reg_val;
>
> spin_lock_irqsave(&vg->lock, flags);
>
> - reg_val = readl(reg) | BYT_DIR_MASK;
> + /*
> + * Before making any direction modifications, do a check if gpio
> + * is set for direct IRQ. On baytrail, setting GPIO to output does
> + * not make sense, so let's at least warn the caller before they shoot
> + * themselves in the foot.
> + */
> + WARN((readl(conf_reg) & BYT_DIRECTIRQ),
> + "Potential Error: Setting GPIO with direct_irq_en to output");
> +
> + reg_val = readl(value_reg) | BYT_DIR_MASK;
> reg_val &= ~BYT_OUTPUT_EN;
>
> if (value)
> - writel(reg_val | BYT_LEVEL, reg);
> + writel(reg_val | BYT_LEVEL, value_reg);
> else
> - writel(reg_val & ~BYT_LEVEL, reg);
> + writel(reg_val & ~BYT_LEVEL, value_reg);
>
> spin_unlock_irqrestore(&vg->lock, flags);
>
> --
> 1.7.9.5
On Mon, Jun 02, 2014 at 02:12:07PM -0700, [email protected] wrote:
> + WARN((readl(conf_reg) & BYT_DIRECTIRQ),
> + "Potential Error: Setting GPIO with direct_irq_en to output");
Also you don't need parentheses here.
From: Eric Ernst <[email protected]>
For Baytrail, you should never set a GPIO set to direct_irq
to output mode. When direct_irq_en is set for a GPIO, it is
tied directly to an APIC internally, and making the pad output
does not make any sense. Assert a WARN() in the event this happens.
Signed-off-by: Eric Ernst <[email protected]>
---
drivers/pinctrl/pinctrl-baytrail.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-baytrail.c b/drivers/pinctrl/pinctrl-baytrail.c
index e59983423991..7f0a2bac7c82 100644
--- a/drivers/pinctrl/pinctrl-baytrail.c
+++ b/drivers/pinctrl/pinctrl-baytrail.c
@@ -43,6 +43,7 @@
#define BYT_INT_STAT_REG 0x800
/* BYT_CONF0_REG register bits */
+#define BYT_DIRECT_IRQ_EN BIT(27)
#define BYT_TRIG_NEG BIT(26)
#define BYT_TRIG_POS BIT(25)
#define BYT_TRIG_LVL BIT(24)
@@ -256,12 +257,22 @@ static int byt_gpio_direction_output(struct gpio_chip *chip,
unsigned gpio, int value)
{
struct byt_gpio *vg = to_byt_gpio(chip);
+ void __iomem *conf_reg = byt_gpio_reg(chip, gpio, BYT_CONF0_REG);
void __iomem *reg = byt_gpio_reg(chip, gpio, BYT_VAL_REG);
unsigned long flags;
u32 reg_val;
spin_lock_irqsave(&vg->lock, flags);
+ /*
+ * Before making any direction modifications, do a check if gpio
+ * is set for direct IRQ. On baytrail, setting GPIO to output does
+ * not make sense, so let's at least warn the caller before they shoot
+ * themselves in the foot.
+ */
+ WARN(readl(conf_reg) & BYT_DIRECT_IRQ_EN,
+ "Potential Error: Setting GPIO with direct_irq_en to output");
+
reg_val = readl(reg) | BYT_DIR_MASK;
reg_val &= ~BYT_OUTPUT_EN;
--
1.7.9.5
On Tue, Jun 03, 2014 at 03:25:16PM -0700, [email protected] wrote:
> From: Eric Ernst <[email protected]>
>
> For Baytrail, you should never set a GPIO set to direct_irq
> to output mode. When direct_irq_en is set for a GPIO, it is
> tied directly to an APIC internally, and making the pad output
> does not make any sense. Assert a WARN() in the event this happens.
>
> Signed-off-by: Eric Ernst <[email protected]>
Looks good now thanks,
Acked-by: Mika Westerberg <[email protected]>
On Wed, Jun 4, 2014 at 12:25 AM, <[email protected]> wrote:
> From: Eric Ernst <[email protected]>
>
> For Baytrail, you should never set a GPIO set to direct_irq
> to output mode. When direct_irq_en is set for a GPIO, it is
> tied directly to an APIC internally, and making the pad output
> does not make any sense. Assert a WARN() in the event this happens.
>
> Signed-off-by: Eric Ernst <[email protected]>
This does not apply to my devel branch or Torvald's HEAD.
Please rebase and repost, and include Mika's ACK.
Yours,
Linus Walleij
From: Eric Ernst <[email protected]>
For Baytrail, you should never set a GPIO set to direct_irq
to output mode. When direct_irq_en is set for a GPIO, it is
tied directly to an APIC internally, and making the pad output
does not make any sense. Assert a WARN() in the event this happens.
Signed-off-by: Eric Ernst <[email protected]>
Acked-by: Mika Westerberg <[email protected]>
---
drivers/pinctrl/pinctrl-baytrail.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-baytrail.c b/drivers/pinctrl/pinctrl-baytrail.c
index 975572e2f260..c34add934216 100644
--- a/drivers/pinctrl/pinctrl-baytrail.c
+++ b/drivers/pinctrl/pinctrl-baytrail.c
@@ -303,12 +303,22 @@ static int byt_gpio_direction_output(struct gpio_chip *chip,
unsigned gpio, int value)
{
struct byt_gpio *vg = to_byt_gpio(chip);
+ void __iomem *conf_reg = byt_gpio_reg(chip, gpio, BYT_CONF0_REG);
void __iomem *reg = byt_gpio_reg(chip, gpio, BYT_VAL_REG);
unsigned long flags;
u32 reg_val;
spin_lock_irqsave(&vg->lock, flags);
+ /*
+ * Before making any direction modifications, do a check if gpio
+ * is set for direct IRQ. On baytrail, setting GPIO to output does
+ * not make sense, so let's at least warn the caller before they shoot
+ * themselves in the foot.
+ */
+ WARN(readl(conf_reg) & BYT_DIRECT_IRQ_EN,
+ "Potential Error: Setting GPIO with direct_irq_en to output");
+
reg_val = readl(reg) | BYT_DIR_MASK;
reg_val &= ~BYT_OUTPUT_EN;
--
1.7.9.5
On Thu, Jun 12, 2014 at 8:06 PM, <[email protected]> wrote:
> From: Eric Ernst <[email protected]>
>
> For Baytrail, you should never set a GPIO set to direct_irq
> to output mode. When direct_irq_en is set for a GPIO, it is
> tied directly to an APIC internally, and making the pad output
> does not make any sense. Assert a WARN() in the event this happens.
>
> Signed-off-by: Eric Ernst <[email protected]>
> Acked-by: Mika Westerberg <[email protected]>
Patch applied.
Sorry for the delay.
Yours,
Linus Walleij
On Thu, Jun 12, 2014 at 8:06 PM, <[email protected]> wrote:
> + WARN(readl(conf_reg) & BYT_DIRECT_IRQ_EN,
> + "Potential Error: Setting GPIO with direct_irq_en to output");
Hm in the v4 version you somehow managed to drop the definition
of BYT_DIRECT_IRQ_EN...
I patched it back in. Let's hope it compiles now.
Yours,
Linus Walleij
Mea culpa - thanks Linus. I saw a note from kbuild test
robot indicating an issue, but given your response, I am
assuming it was from your first build attempt. Thanks.
On 14-07-07 02:14 PM, Linus Walleij wrote:
> On Thu, Jun 12, 2014 at 8:06 PM, <[email protected]> wrote:
>
>> + WARN(readl(conf_reg) & BYT_DIRECT_IRQ_EN,
>> + "Potential Error: Setting GPIO with direct_irq_en to output");
> Hm in the v4 version you somehow managed to drop the definition
> of BYT_DIRECT_IRQ_EN...
>
> I patched it back in. Let's hope it compiles now.
>
> Yours,
> Linus Walleij