Skip to content

Commit 65e9363

Browse files
ConchuODBartosz Golaszewski
authored andcommitted
gpio: mpfs: add CoreGPIO support
coreGPIO, which the "hard" core in PolarFire SoC is based on, has different offsets for inp/outp. Add some match_data handling to account for the differences. Signed-off-by: Conor Dooley <[email protected]> Link: https://lore.kernel.org/r/20241113-jovial-atlantic-cd07f05eb2e5@spud Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 8bcbd03 commit 65e9363

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

drivers/gpio/gpio-mpfs.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/init.h>
1313
#include <linux/mod_devicetable.h>
1414
#include <linux/platform_device.h>
15+
#include <linux/property.h>
1516
#include <linux/regmap.h>
1617
#include <linux/spinlock.h>
1718

@@ -30,11 +31,20 @@
3031
#define MPFS_GPIO_TYPE_INT_LEVEL_HIGH 0x00
3132
#define MPFS_GPIO_TYPE_INT_MASK GENMASK(7, 5)
3233
#define MPFS_IRQ_REG 0x80
34+
3335
#define MPFS_INP_REG 0x84
36+
#define COREGPIO_INP_REG 0x90
3437
#define MPFS_OUTP_REG 0x88
38+
#define COREGPIO_OUTP_REG 0xA0
39+
40+
struct mpfs_gpio_reg_offsets {
41+
u8 inp;
42+
u8 outp;
43+
};
3544

3645
struct mpfs_gpio_chip {
3746
struct regmap *regs;
47+
const struct mpfs_gpio_reg_offsets *offsets;
3848
struct gpio_chip gc;
3949
};
4050

@@ -60,7 +70,7 @@ static int mpfs_gpio_direction_output(struct gpio_chip *gc, unsigned int gpio_in
6070

6171
regmap_update_bits(mpfs_gpio->regs, MPFS_GPIO_CTRL(gpio_index),
6272
MPFS_GPIO_DIR_MASK, MPFS_GPIO_EN_IN);
63-
regmap_update_bits(mpfs_gpio->regs, MPFS_OUTP_REG, BIT(gpio_index),
73+
regmap_update_bits(mpfs_gpio->regs, mpfs_gpio->offsets->outp, BIT(gpio_index),
6474
value << gpio_index);
6575

6676
return 0;
@@ -84,9 +94,9 @@ static int mpfs_gpio_get(struct gpio_chip *gc, unsigned int gpio_index)
8494
struct mpfs_gpio_chip *mpfs_gpio = gpiochip_get_data(gc);
8595

8696
if (mpfs_gpio_get_direction(gc, gpio_index) == GPIO_LINE_DIRECTION_OUT)
87-
return regmap_test_bits(mpfs_gpio->regs, MPFS_OUTP_REG, BIT(gpio_index));
97+
return regmap_test_bits(mpfs_gpio->regs, mpfs_gpio->offsets->outp, BIT(gpio_index));
8898
else
89-
return regmap_test_bits(mpfs_gpio->regs, MPFS_INP_REG, BIT(gpio_index));
99+
return regmap_test_bits(mpfs_gpio->regs, mpfs_gpio->offsets->inp, BIT(gpio_index));
90100
}
91101

92102
static void mpfs_gpio_set(struct gpio_chip *gc, unsigned int gpio_index, int value)
@@ -95,7 +105,7 @@ static void mpfs_gpio_set(struct gpio_chip *gc, unsigned int gpio_index, int val
95105

96106
mpfs_gpio_get(gc, gpio_index);
97107

98-
regmap_update_bits(mpfs_gpio->regs, MPFS_OUTP_REG, BIT(gpio_index),
108+
regmap_update_bits(mpfs_gpio->regs, mpfs_gpio->offsets->outp, BIT(gpio_index),
99109
value << gpio_index);
100110

101111
mpfs_gpio_get(gc, gpio_index);
@@ -113,6 +123,8 @@ static int mpfs_gpio_probe(struct platform_device *pdev)
113123
if (!mpfs_gpio)
114124
return -ENOMEM;
115125

126+
mpfs_gpio->offsets = device_get_match_data(&pdev->dev);
127+
116128
base = devm_platform_ioremap_resource(pdev, 0);
117129
if (IS_ERR(base))
118130
return dev_err_probe(dev, PTR_ERR(base), "failed to ioremap memory resource\n");
@@ -145,8 +157,24 @@ static int mpfs_gpio_probe(struct platform_device *pdev)
145157
return devm_gpiochip_add_data(dev, &mpfs_gpio->gc, mpfs_gpio);
146158
}
147159

160+
static const struct mpfs_gpio_reg_offsets mpfs_reg_offsets = {
161+
.inp = MPFS_INP_REG,
162+
.outp = MPFS_OUTP_REG,
163+
};
164+
165+
static const struct mpfs_gpio_reg_offsets coregpio_reg_offsets = {
166+
.inp = COREGPIO_INP_REG,
167+
.outp = COREGPIO_OUTP_REG,
168+
};
169+
148170
static const struct of_device_id mpfs_gpio_of_ids[] = {
149-
{ .compatible = "microchip,mpfs-gpio", },
171+
{
172+
.compatible = "microchip,mpfs-gpio",
173+
.data = &mpfs_reg_offsets,
174+
}, {
175+
.compatible = "microchip,coregpio-rtl-v3",
176+
.data = &coregpio_reg_offsets,
177+
},
150178
{ /* end of list */ }
151179
};
152180

0 commit comments

Comments
 (0)