Skip to content

Commit 7996c5f

Browse files
mwalleLinus Walleij
authored andcommitted
pinctrl: microchip-sgpio: lock RMW access
Protect any RMW access to the registers by a spinlock. Fixes: 7e5ea97 ("pinctrl: pinctrl-microchip-sgpio: Add pinctrl driver for Microsemi Serial GPIO") Signed-off-by: Michael Walle <michael@walle.cc> Link: https://lore.kernel.org/r/20220226204507.2511633-2-michael@walle.cc Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent d1f2c82 commit 7996c5f

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

drivers/pinctrl/pinctrl-microchip-sgpio.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/property.h>
2020
#include <linux/regmap.h>
2121
#include <linux/reset.h>
22+
#include <linux/spinlock.h>
2223

2324
#include "core.h"
2425
#include "pinconf.h"
@@ -116,6 +117,7 @@ struct sgpio_priv {
116117
u32 clock;
117118
struct regmap *regs;
118119
const struct sgpio_properties *properties;
120+
spinlock_t lock;
119121
};
120122

121123
struct sgpio_port_addr {
@@ -228,6 +230,7 @@ static void sgpio_output_set(struct sgpio_priv *priv,
228230
int value)
229231
{
230232
unsigned int bit = SGPIO_SRC_BITS * addr->bit;
233+
unsigned long flags;
231234
u32 clr, set;
232235

233236
switch (priv->properties->arch) {
@@ -246,7 +249,10 @@ static void sgpio_output_set(struct sgpio_priv *priv,
246249
default:
247250
return;
248251
}
252+
253+
spin_lock_irqsave(&priv->lock, flags);
249254
sgpio_clrsetbits(priv, REG_PORT_CONFIG, addr->port, clr, set);
255+
spin_unlock_irqrestore(&priv->lock, flags);
250256
}
251257

252258
static int sgpio_output_get(struct sgpio_priv *priv,
@@ -574,10 +580,13 @@ static void microchip_sgpio_irq_settype(struct irq_data *data,
574580
struct sgpio_bank *bank = gpiochip_get_data(chip);
575581
unsigned int gpio = irqd_to_hwirq(data);
576582
struct sgpio_port_addr addr;
583+
unsigned long flags;
577584
u32 ena;
578585

579586
sgpio_pin_to_addr(bank->priv, gpio, &addr);
580587

588+
spin_lock_irqsave(&bank->priv->lock, flags);
589+
581590
/* Disable interrupt while changing type */
582591
ena = sgpio_readl(bank->priv, REG_INT_ENABLE, addr.bit);
583592
sgpio_writel(bank->priv, ena & ~BIT(addr.port), REG_INT_ENABLE, addr.bit);
@@ -594,6 +603,8 @@ static void microchip_sgpio_irq_settype(struct irq_data *data,
594603

595604
/* Possibly re-enable interrupts */
596605
sgpio_writel(bank->priv, ena, REG_INT_ENABLE, addr.bit);
606+
607+
spin_unlock_irqrestore(&bank->priv->lock, flags);
597608
}
598609

599610
static void microchip_sgpio_irq_setreg(struct irq_data *data,
@@ -604,13 +615,16 @@ static void microchip_sgpio_irq_setreg(struct irq_data *data,
604615
struct sgpio_bank *bank = gpiochip_get_data(chip);
605616
unsigned int gpio = irqd_to_hwirq(data);
606617
struct sgpio_port_addr addr;
618+
unsigned long flags;
607619

608620
sgpio_pin_to_addr(bank->priv, gpio, &addr);
609621

622+
spin_lock_irqsave(&bank->priv->lock, flags);
610623
if (clear)
611624
sgpio_clrsetbits(bank->priv, reg, addr.bit, BIT(addr.port), 0);
612625
else
613626
sgpio_clrsetbits(bank->priv, reg, addr.bit, 0, BIT(addr.port));
627+
spin_unlock_irqrestore(&bank->priv->lock, flags);
614628
}
615629

616630
static void microchip_sgpio_irq_mask(struct irq_data *data)
@@ -832,6 +846,7 @@ static int microchip_sgpio_probe(struct platform_device *pdev)
832846
return -ENOMEM;
833847

834848
priv->dev = dev;
849+
spin_lock_init(&priv->lock);
835850

836851
reset = devm_reset_control_get_optional_shared(&pdev->dev, "switch");
837852
if (IS_ERR(reset))

0 commit comments

Comments
 (0)