linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFT 1/2] gpio: gpio-ml-ioh: Use spinlock for register access protection
@ 2012-07-29  2:54 Axel Lin
  2012-07-29  2:55 ` [PATCH RFT 2/2] gpio: gpio-pch: " Axel Lin
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Axel Lin @ 2012-07-29  2:54 UTC (permalink / raw)
  To: linux-kernel; +Cc: Feng Tang, Tomoya MORINAGA, Grant Likely, Linus Walleij

gpio_chip.can_sleep is 0, but current code uses mutex in ioh_gpio_set,
ioh_gpio_get and ioh_gpio_direction_input functions.
Thus those functions are not callable from interrupt context.
This patch converts mutex into spinlock.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/gpio/gpio-ml-ioh.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpio-ml-ioh.c b/drivers/gpio/gpio-ml-ioh.c
index db01f15..6a29ee1 100644
--- a/drivers/gpio/gpio-ml-ioh.c
+++ b/drivers/gpio/gpio-ml-ioh.c
@@ -87,8 +87,7 @@ struct ioh_gpio_reg_data {
  * @gpio_use_sel:		Save GPIO_USE_SEL1~4 register for PM
  * @ch:				Indicate GPIO channel
  * @irq_base:		Save base of IRQ number for interrupt
- * @spinlock:		Used for register access protection in
- *				interrupt context ioh_irq_type and PM;
+ * @spinlock:		Used for register access protection
  */
 struct ioh_gpio {
 	void __iomem *base;
@@ -97,7 +96,6 @@ struct ioh_gpio {
 	struct gpio_chip gpio;
 	struct ioh_gpio_reg_data ioh_gpio_reg;
 	u32 gpio_use_sel;
-	struct mutex lock;
 	int ch;
 	int irq_base;
 	spinlock_t spinlock;
@@ -109,8 +107,9 @@ static void ioh_gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
 {
 	u32 reg_val;
 	struct ioh_gpio *chip =	container_of(gpio, struct ioh_gpio, gpio);
+	unsigned long flags;
 
-	mutex_lock(&chip->lock);
+	spin_lock_irqsave(&chip->spinlock, flags);
 	reg_val = ioread32(&chip->reg->regs[chip->ch].po);
 	if (val)
 		reg_val |= (1 << nr);
@@ -118,7 +117,7 @@ static void ioh_gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
 		reg_val &= ~(1 << nr);
 
 	iowrite32(reg_val, &chip->reg->regs[chip->ch].po);
-	mutex_unlock(&chip->lock);
+	spin_unlock_irqrestore(&chip->spinlock, flags);
 }
 
 static int ioh_gpio_get(struct gpio_chip *gpio, unsigned nr)
@@ -134,8 +133,9 @@ static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr,
 	struct ioh_gpio *chip =	container_of(gpio, struct ioh_gpio, gpio);
 	u32 pm;
 	u32 reg_val;
+	unsigned long flags;
 
-	mutex_lock(&chip->lock);
+	spin_lock_irqsave(&chip->spinlock, flags);
 	pm = ioread32(&chip->reg->regs[chip->ch].pm) &
 					((1 << num_ports[chip->ch]) - 1);
 	pm |= (1 << nr);
@@ -148,7 +148,7 @@ static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr,
 		reg_val &= ~(1 << nr);
 	iowrite32(reg_val, &chip->reg->regs[chip->ch].po);
 
-	mutex_unlock(&chip->lock);
+	spin_unlock_irqrestore(&chip->spinlock, flags);
 
 	return 0;
 }
@@ -157,13 +157,14 @@ static int ioh_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
 {
 	struct ioh_gpio *chip =	container_of(gpio, struct ioh_gpio, gpio);
 	u32 pm;
+	unsigned long flags;
 
-	mutex_lock(&chip->lock);
+	spin_lock_irqsave(&chip->spinlock, flags);
 	pm = ioread32(&chip->reg->regs[chip->ch].pm) &
 				((1 << num_ports[chip->ch]) - 1);
 	pm &= ~(1 << nr);
 	iowrite32(pm, &chip->reg->regs[chip->ch].pm);
-	mutex_unlock(&chip->lock);
+	spin_unlock_irqrestore(&chip->spinlock, flags);
 
 	return 0;
 }
@@ -447,7 +448,6 @@ static int __devinit ioh_gpio_probe(struct pci_dev *pdev,
 		chip->base = base;
 		chip->reg = chip->base;
 		chip->ch = i;
-		mutex_init(&chip->lock);
 		spin_lock_init(&chip->spinlock);
 		ioh_gpio_setup(chip, num_ports[i]);
 		ret = gpiochip_add(&chip->gpio);
-- 
1.7.9.5




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

* [PATCH RFT 2/2] gpio: gpio-pch: Use spinlock for register access protection
  2012-07-29  2:54 [PATCH RFT 1/2] gpio: gpio-ml-ioh: Use spinlock for register access protection Axel Lin
@ 2012-07-29  2:55 ` Axel Lin
  2012-08-13 12:02   ` Linus Walleij
  2012-08-14 22:20   ` Linus Walleij
  2012-08-13 12:01 ` [PATCH RFT 1/2] gpio: gpio-ml-ioh: " Linus Walleij
  2012-08-14 22:18 ` Linus Walleij
  2 siblings, 2 replies; 7+ messages in thread
From: Axel Lin @ 2012-07-29  2:55 UTC (permalink / raw)
  To: linux-kernel; +Cc: Feng Tang, Tomoya MORINAGA, Grant Likely, Linus Walleij

gpio_chip.can_sleep is 0, but current code uses mutex in pch_gpio_set
pch_gpio_get and pch_gpio_direction_input functions.
Thus those functions are not callable from interrupt context.
This patch converts mutex into spinlock.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/gpio/gpio-pch.c |   22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/gpio/gpio-pch.c b/drivers/gpio/gpio-pch.c
index 139ad3e..4ad0c4f 100644
--- a/drivers/gpio/gpio-pch.c
+++ b/drivers/gpio/gpio-pch.c
@@ -92,9 +92,7 @@ struct pch_gpio_reg_data {
  * @lock:			Used for register access protection
  * @irq_base:		Save base of IRQ number for interrupt
  * @ioh:		IOH ID
- * @spinlock:		Used for register access protection in
- *				interrupt context pch_irq_mask,
- *				pch_irq_unmask and pch_irq_type;
+ * @spinlock:		Used for register access protection
  */
 struct pch_gpio {
 	void __iomem *base;
@@ -102,7 +100,6 @@ struct pch_gpio {
 	struct device *dev;
 	struct gpio_chip gpio;
 	struct pch_gpio_reg_data pch_gpio_reg;
-	struct mutex lock;
 	int irq_base;
 	enum pch_type_t ioh;
 	spinlock_t spinlock;
@@ -112,8 +109,9 @@ static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
 {
 	u32 reg_val;
 	struct pch_gpio *chip =	container_of(gpio, struct pch_gpio, gpio);
+	unsigned long flags;
 
-	mutex_lock(&chip->lock);
+	spin_lock_irqsave(&chip->spinlock, flags);
 	reg_val = ioread32(&chip->reg->po);
 	if (val)
 		reg_val |= (1 << nr);
@@ -121,7 +119,7 @@ static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
 		reg_val &= ~(1 << nr);
 
 	iowrite32(reg_val, &chip->reg->po);
-	mutex_unlock(&chip->lock);
+	spin_unlock_irqrestore(&chip->spinlock, flags);
 }
 
 static int pch_gpio_get(struct gpio_chip *gpio, unsigned nr)
@@ -137,8 +135,9 @@ static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr,
 	struct pch_gpio *chip =	container_of(gpio, struct pch_gpio, gpio);
 	u32 pm;
 	u32 reg_val;
+	unsigned long flags;
 
-	mutex_lock(&chip->lock);
+	spin_lock_irqsave(&chip->spinlock, flags);
 	pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1);
 	pm |= (1 << nr);
 	iowrite32(pm, &chip->reg->pm);
@@ -149,8 +148,7 @@ static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr,
 	else
 		reg_val &= ~(1 << nr);
 	iowrite32(reg_val, &chip->reg->po);
-
-	mutex_unlock(&chip->lock);
+	spin_unlock_irqrestore(&chip->spinlock, flags);
 
 	return 0;
 }
@@ -159,12 +157,13 @@ static int pch_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
 {
 	struct pch_gpio *chip =	container_of(gpio, struct pch_gpio, gpio);
 	u32 pm;
+	unsigned long flags;
 
-	mutex_lock(&chip->lock);
+	spin_lock_irqsave(&chip->spinlock, flags);
 	pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1);
 	pm &= ~(1 << nr);
 	iowrite32(pm, &chip->reg->pm);
-	mutex_unlock(&chip->lock);
+	spin_unlock_irqrestore(&chip->spinlock, flags);
 
 	return 0;
 }
@@ -387,7 +386,6 @@ static int __devinit pch_gpio_probe(struct pci_dev *pdev,
 
 	chip->reg = chip->base;
 	pci_set_drvdata(pdev, chip);
-	mutex_init(&chip->lock);
 	spin_lock_init(&chip->spinlock);
 	pch_gpio_setup(chip);
 	ret = gpiochip_add(&chip->gpio);
-- 
1.7.9.5




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

* Re: [PATCH RFT 1/2] gpio: gpio-ml-ioh: Use spinlock for register access protection
  2012-07-29  2:54 [PATCH RFT 1/2] gpio: gpio-ml-ioh: Use spinlock for register access protection Axel Lin
  2012-07-29  2:55 ` [PATCH RFT 2/2] gpio: gpio-pch: " Axel Lin
@ 2012-08-13 12:01 ` Linus Walleij
  2012-08-14  1:25   ` Feng Tang
  2012-08-14 22:18 ` Linus Walleij
  2 siblings, 1 reply; 7+ messages in thread
From: Linus Walleij @ 2012-08-13 12:01 UTC (permalink / raw)
  To: Feng Tang, Tomoya MORINAGA; +Cc: linux-kernel, Grant Likely, Axel Lin

On Sun, Jul 29, 2012 at 4:54 AM, Axel Lin <axel.lin@gmail.com> wrote:

> gpio_chip.can_sleep is 0, but current code uses mutex in ioh_gpio_set,
> ioh_gpio_get and ioh_gpio_direction_input functions.
> Thus those functions are not callable from interrupt context.
> This patch converts mutex into spinlock.
>
> Signed-off-by: Axel Lin <axel.lin@gmail.com>

So IOH guys what are you saying about this?

If you say nothing I will apply these patches.

Yours,
Linus Walleij

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

* Re: [PATCH RFT 2/2] gpio: gpio-pch: Use spinlock for register access protection
  2012-07-29  2:55 ` [PATCH RFT 2/2] gpio: gpio-pch: " Axel Lin
@ 2012-08-13 12:02   ` Linus Walleij
  2012-08-14 22:20   ` Linus Walleij
  1 sibling, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2012-08-13 12:02 UTC (permalink / raw)
  To: Feng Tang, Tomoya MORINAGA; +Cc: linux-kernel, Grant Likely, Axel Lin

On Sun, Jul 29, 2012 at 4:55 AM, Axel Lin <axel.lin@gmail.com> wrote:

> gpio_chip.can_sleep is 0, but current code uses mutex in pch_gpio_set
> pch_gpio_get and pch_gpio_direction_input functions.
> Thus those functions are not callable from interrupt context.
> This patch converts mutex into spinlock.
>
> Signed-off-by: Axel Lin <axel.lin@gmail.com>

Same with this, yell or I'll apply.

Yours,
Linus Walleij

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

* Re: [PATCH RFT 1/2] gpio: gpio-ml-ioh: Use spinlock for register access protection
  2012-08-13 12:01 ` [PATCH RFT 1/2] gpio: gpio-ml-ioh: " Linus Walleij
@ 2012-08-14  1:25   ` Feng Tang
  0 siblings, 0 replies; 7+ messages in thread
From: Feng Tang @ 2012-08-14  1:25 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Tomoya MORINAGA, linux-kernel, Grant Likely, Axel Lin

On Mon, 13 Aug 2012 14:01:31 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:

> On Sun, Jul 29, 2012 at 4:54 AM, Axel Lin <axel.lin@gmail.com> wrote:
> 
> > gpio_chip.can_sleep is 0, but current code uses mutex in ioh_gpio_set,
> > ioh_gpio_get and ioh_gpio_direction_input functions.
> > Thus those functions are not callable from interrupt context.
> > This patch converts mutex into spinlock.
> >
> > Signed-off-by: Axel Lin <axel.lin@gmail.com>
> 
> So IOH guys what are you saying about this?

I'm not the IOH guy, but just happened to work on it for some time :) Anyway,
the 2 patches both look good to me.

Thanks,
Feng


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

* Re: [PATCH RFT 1/2] gpio: gpio-ml-ioh: Use spinlock for register access protection
  2012-07-29  2:54 [PATCH RFT 1/2] gpio: gpio-ml-ioh: Use spinlock for register access protection Axel Lin
  2012-07-29  2:55 ` [PATCH RFT 2/2] gpio: gpio-pch: " Axel Lin
  2012-08-13 12:01 ` [PATCH RFT 1/2] gpio: gpio-ml-ioh: " Linus Walleij
@ 2012-08-14 22:18 ` Linus Walleij
  2 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2012-08-14 22:18 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Feng Tang, Tomoya MORINAGA, Grant Likely

On Sun, Jul 29, 2012 at 4:54 AM, Axel Lin <axel.lin@gmail.com> wrote:

> gpio_chip.can_sleep is 0, but current code uses mutex in ioh_gpio_set,
> ioh_gpio_get and ioh_gpio_direction_input functions.
> Thus those functions are not callable from interrupt context.
> This patch converts mutex into spinlock.
>
> Signed-off-by: Axel Lin <axel.lin@gmail.com>

Applied to my devel branch for the next merge window, it doesn't
seem like a regression to me atleast.

Yours,
Linus Walleij

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

* Re: [PATCH RFT 2/2] gpio: gpio-pch: Use spinlock for register access protection
  2012-07-29  2:55 ` [PATCH RFT 2/2] gpio: gpio-pch: " Axel Lin
  2012-08-13 12:02   ` Linus Walleij
@ 2012-08-14 22:20   ` Linus Walleij
  1 sibling, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2012-08-14 22:20 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Feng Tang, Tomoya MORINAGA, Grant Likely

On Sun, Jul 29, 2012 at 4:55 AM, Axel Lin <axel.lin@gmail.com> wrote:

> gpio_chip.can_sleep is 0, but current code uses mutex in pch_gpio_set
> pch_gpio_get and pch_gpio_direction_input functions.
> Thus those functions are not callable from interrupt context.
> This patch converts mutex into spinlock.
>
> Signed-off-by: Axel Lin <axel.lin@gmail.com>

Applied to my devel branch for the next merge window...

Yours,
Linus Walleij

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

end of thread, other threads:[~2012-08-14 22:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-29  2:54 [PATCH RFT 1/2] gpio: gpio-ml-ioh: Use spinlock for register access protection Axel Lin
2012-07-29  2:55 ` [PATCH RFT 2/2] gpio: gpio-pch: " Axel Lin
2012-08-13 12:02   ` Linus Walleij
2012-08-14 22:20   ` Linus Walleij
2012-08-13 12:01 ` [PATCH RFT 1/2] gpio: gpio-ml-ioh: " Linus Walleij
2012-08-14  1:25   ` Feng Tang
2012-08-14 22:18 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).