Commit 7cb6580c authored by Axel Lin's avatar Axel Lin Committed by Linus Walleij

gpio: gpio-pch: Use spinlock for register access protection

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: default avatarAxel Lin <axel.lin@gmail.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 02a6794d
...@@ -92,9 +92,7 @@ struct pch_gpio_reg_data { ...@@ -92,9 +92,7 @@ struct pch_gpio_reg_data {
* @lock: Used for register access protection * @lock: Used for register access protection
* @irq_base: Save base of IRQ number for interrupt * @irq_base: Save base of IRQ number for interrupt
* @ioh: IOH ID * @ioh: IOH ID
* @spinlock: Used for register access protection in * @spinlock: Used for register access protection
* interrupt context pch_irq_mask,
* pch_irq_unmask and pch_irq_type;
*/ */
struct pch_gpio { struct pch_gpio {
void __iomem *base; void __iomem *base;
...@@ -102,7 +100,6 @@ struct pch_gpio { ...@@ -102,7 +100,6 @@ struct pch_gpio {
struct device *dev; struct device *dev;
struct gpio_chip gpio; struct gpio_chip gpio;
struct pch_gpio_reg_data pch_gpio_reg; struct pch_gpio_reg_data pch_gpio_reg;
struct mutex lock;
int irq_base; int irq_base;
enum pch_type_t ioh; enum pch_type_t ioh;
spinlock_t spinlock; spinlock_t spinlock;
...@@ -112,8 +109,9 @@ static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) ...@@ -112,8 +109,9 @@ static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
{ {
u32 reg_val; u32 reg_val;
struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); 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); reg_val = ioread32(&chip->reg->po);
if (val) if (val)
reg_val |= (1 << nr); reg_val |= (1 << nr);
...@@ -121,7 +119,7 @@ static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) ...@@ -121,7 +119,7 @@ static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
reg_val &= ~(1 << nr); reg_val &= ~(1 << nr);
iowrite32(reg_val, &chip->reg->po); 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) 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, ...@@ -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); struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio);
u32 pm; u32 pm;
u32 reg_val; 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 = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1);
pm |= (1 << nr); pm |= (1 << nr);
iowrite32(pm, &chip->reg->pm); iowrite32(pm, &chip->reg->pm);
...@@ -149,8 +148,7 @@ static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, ...@@ -149,8 +148,7 @@ static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr,
else else
reg_val &= ~(1 << nr); reg_val &= ~(1 << nr);
iowrite32(reg_val, &chip->reg->po); iowrite32(reg_val, &chip->reg->po);
spin_unlock_irqrestore(&chip->spinlock, flags);
mutex_unlock(&chip->lock);
return 0; return 0;
} }
...@@ -159,12 +157,13 @@ static int pch_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) ...@@ -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); struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio);
u32 pm; 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 = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1);
pm &= ~(1 << nr); pm &= ~(1 << nr);
iowrite32(pm, &chip->reg->pm); iowrite32(pm, &chip->reg->pm);
mutex_unlock(&chip->lock); spin_unlock_irqrestore(&chip->spinlock, flags);
return 0; return 0;
} }
...@@ -387,7 +386,6 @@ static int __devinit pch_gpio_probe(struct pci_dev *pdev, ...@@ -387,7 +386,6 @@ static int __devinit pch_gpio_probe(struct pci_dev *pdev,
chip->reg = chip->base; chip->reg = chip->base;
pci_set_drvdata(pdev, chip); pci_set_drvdata(pdev, chip);
mutex_init(&chip->lock);
spin_lock_init(&chip->spinlock); spin_lock_init(&chip->spinlock);
pch_gpio_setup(chip); pch_gpio_setup(chip);
ret = gpiochip_add(&chip->gpio); ret = gpiochip_add(&chip->gpio);
......
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