Skip to content

Commit 8a6abcd

Browse files
author
Linus Walleij
committed
Merge tag 'gpio-v5.4-updates-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux into devel
gpio: updates for v5.4 - use a helper variable for &pdev->dev in gpio-em - tweak the ifdefs in GPIO headers - fix function links in HTML docs - remove an unneeded error message from ixp4xx - use the optional clk_get in gpio-mxc instead of checking the return value - a couple improvements in pca953x - allow to build gpio-lpc32xx on non-lpc32xx targets
2 parents f6a7053 + f2ee731 commit 8a6abcd

10 files changed

Lines changed: 148 additions & 144 deletions

File tree

‎Documentation/driver-api/gpio/driver.rst‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ driver code:
6969

7070
The code implementing a gpio_chip should support multiple instances of the
7171
controller, preferably using the driver model. That code will configure each
72-
gpio_chip and issue ``gpiochip_add[_data]()`` or ``devm_gpiochip_add_data()``.
73-
Removing a GPIO controller should be rare; use ``[devm_]gpiochip_remove()``
74-
when it is unavoidable.
72+
gpio_chip and issue gpiochip_add(), gpiochip_add_data(), or
73+
devm_gpiochip_add_data(). Removing a GPIO controller should be rare; use
74+
gpiochip_remove() when it is unavoidable.
7575

7676
Often a gpio_chip is part of an instance-specific structure with states not
7777
exposed by the GPIO interfaces, such as addressing, power management, and more.
@@ -512,11 +512,11 @@ available but we try to move away from this:
512512

513513
If there is a need to exclude certain GPIO lines from the IRQ domain handled by
514514
these helpers, we can set .irq.need_valid_mask of the gpiochip before
515-
``[devm_]gpiochip_add_data()`` is called. This allocates an .irq.valid_mask with as
516-
many bits set as there are GPIO lines in the chip, each bit representing line
517-
0..n-1. Drivers can exclude GPIO lines by clearing bits from this mask. The mask
518-
must be filled in before gpiochip_irqchip_add() or gpiochip_irqchip_add_nested()
519-
is called.
515+
devm_gpiochip_add_data() or gpiochip_add_data() is called. This allocates an
516+
.irq.valid_mask with as many bits set as there are GPIO lines in the chip, each
517+
bit representing line 0..n-1. Drivers can exclude GPIO lines by clearing bits
518+
from this mask. The mask must be filled in before gpiochip_irqchip_add() or
519+
gpiochip_irqchip_add_nested() is called.
520520

521521
To use the helpers please keep the following in mind:
522522

‎arch/arm/configs/lpc32xx_defconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ CONFIG_SERIAL_HS_LPC32XX_CONSOLE=y
9393
# CONFIG_HW_RANDOM is not set
9494
CONFIG_I2C_CHARDEV=y
9595
CONFIG_I2C_PNX=y
96+
CONFIG_GPIO_LPC32XX=y
9697
CONFIG_SPI=y
9798
CONFIG_SPI_PL022=y
9899
CONFIG_GPIO_SYSFS=y

‎drivers/gpio/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ config GPIO_LPC18XX
311311
Select this option to enable GPIO driver for
312312
NXP LPC18XX/43XX devices.
313313

314+
config GPIO_LPC32XX
315+
tristate "NXP LPC32XX GPIO support"
316+
depends on OF_GPIO && (ARCH_LPC32XX || COMPILE_TEST)
317+
help
318+
Select this option to enable GPIO driver for
319+
NXP LPC32XX devices.
320+
314321
config GPIO_LYNXPOINT
315322
tristate "Intel Lynxpoint GPIO support"
316323
depends on ACPI && X86

‎drivers/gpio/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ obj-$(CONFIG_GPIO_LP3943) += gpio-lp3943.o
7373
obj-$(CONFIG_GPIO_LP873X) += gpio-lp873x.o
7474
obj-$(CONFIG_GPIO_LP87565) += gpio-lp87565.o
7575
obj-$(CONFIG_GPIO_LPC18XX) += gpio-lpc18xx.o
76-
obj-$(CONFIG_ARCH_LPC32XX) += gpio-lpc32xx.o
76+
obj-$(CONFIG_GPIO_LPC32XX) += gpio-lpc32xx.o
7777
obj-$(CONFIG_GPIO_LYNXPOINT) += gpio-lynxpoint.o
7878
obj-$(CONFIG_GPIO_MADERA) += gpio-madera.o
7979
obj-$(CONFIG_GPIO_MAX3191X) += gpio-max3191x.o

‎drivers/gpio/gpio-em.c‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,12 @@ static int em_gio_probe(struct platform_device *pdev)
272272
struct resource *io[2], *irq[2];
273273
struct gpio_chip *gpio_chip;
274274
struct irq_chip *irq_chip;
275-
const char *name = dev_name(&pdev->dev);
275+
struct device *dev = &pdev->dev;
276+
const char *name = dev_name(dev);
276277
unsigned int ngpios;
277278
int ret;
278279

279-
p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
280+
p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
280281
if (!p)
281282
return -ENOMEM;
282283

@@ -290,27 +291,27 @@ static int em_gio_probe(struct platform_device *pdev)
290291
irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
291292

292293
if (!io[0] || !io[1] || !irq[0] || !irq[1]) {
293-
dev_err(&pdev->dev, "missing IRQ or IOMEM\n");
294+
dev_err(dev, "missing IRQ or IOMEM\n");
294295
return -EINVAL;
295296
}
296297

297-
p->base0 = devm_ioremap_nocache(&pdev->dev, io[0]->start,
298+
p->base0 = devm_ioremap_nocache(dev, io[0]->start,
298299
resource_size(io[0]));
299300
if (!p->base0)
300301
return -ENOMEM;
301302

302-
p->base1 = devm_ioremap_nocache(&pdev->dev, io[1]->start,
303+
p->base1 = devm_ioremap_nocache(dev, io[1]->start,
303304
resource_size(io[1]));
304305
if (!p->base1)
305306
return -ENOMEM;
306307

307-
if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) {
308-
dev_err(&pdev->dev, "Missing ngpios OF property\n");
308+
if (of_property_read_u32(dev->of_node, "ngpios", &ngpios)) {
309+
dev_err(dev, "Missing ngpios OF property\n");
309310
return -EINVAL;
310311
}
311312

312313
gpio_chip = &p->gpio_chip;
313-
gpio_chip->of_node = pdev->dev.of_node;
314+
gpio_chip->of_node = dev->of_node;
314315
gpio_chip->direction_input = em_gio_direction_input;
315316
gpio_chip->get = em_gio_get;
316317
gpio_chip->direction_output = em_gio_direction_output;
@@ -319,7 +320,7 @@ static int em_gio_probe(struct platform_device *pdev)
319320
gpio_chip->request = em_gio_request;
320321
gpio_chip->free = em_gio_free;
321322
gpio_chip->label = name;
322-
gpio_chip->parent = &pdev->dev;
323+
gpio_chip->parent = dev;
323324
gpio_chip->owner = THIS_MODULE;
324325
gpio_chip->base = -1;
325326
gpio_chip->ngpio = ngpios;
@@ -333,33 +334,33 @@ static int em_gio_probe(struct platform_device *pdev)
333334
irq_chip->irq_release_resources = em_gio_irq_relres;
334335
irq_chip->flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND;
335336

336-
p->irq_domain = irq_domain_add_simple(pdev->dev.of_node, ngpios, 0,
337+
p->irq_domain = irq_domain_add_simple(dev->of_node, ngpios, 0,
337338
&em_gio_irq_domain_ops, p);
338339
if (!p->irq_domain) {
339-
dev_err(&pdev->dev, "cannot initialize irq domain\n");
340+
dev_err(dev, "cannot initialize irq domain\n");
340341
return -ENXIO;
341342
}
342343

343-
ret = devm_add_action_or_reset(&pdev->dev, em_gio_irq_domain_remove,
344+
ret = devm_add_action_or_reset(dev, em_gio_irq_domain_remove,
344345
p->irq_domain);
345346
if (ret)
346347
return ret;
347348

348-
if (devm_request_irq(&pdev->dev, irq[0]->start,
349+
if (devm_request_irq(dev, irq[0]->start,
349350
em_gio_irq_handler, 0, name, p)) {
350-
dev_err(&pdev->dev, "failed to request low IRQ\n");
351+
dev_err(dev, "failed to request low IRQ\n");
351352
return -ENOENT;
352353
}
353354

354-
if (devm_request_irq(&pdev->dev, irq[1]->start,
355+
if (devm_request_irq(dev, irq[1]->start,
355356
em_gio_irq_handler, 0, name, p)) {
356-
dev_err(&pdev->dev, "failed to request high IRQ\n");
357+
dev_err(dev, "failed to request high IRQ\n");
357358
return -ENOENT;
358359
}
359360

360-
ret = devm_gpiochip_add_data(&pdev->dev, gpio_chip, p);
361+
ret = devm_gpiochip_add_data(dev, gpio_chip, p);
361362
if (ret) {
362-
dev_err(&pdev->dev, "failed to add GPIO controller\n");
363+
dev_err(dev, "failed to add GPIO controller\n");
363364
return ret;
364365
}
365366

‎drivers/gpio/gpio-ixp4xx.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,8 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev)
204204

205205
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
206206
g->base = devm_ioremap_resource(dev, res);
207-
if (IS_ERR(g->base)) {
208-
dev_err(dev, "ioremap error\n");
207+
if (IS_ERR(g->base))
209208
return PTR_ERR(g->base);
210-
}
211209

212210
/*
213211
* When we convert to device tree we will simply look up the

‎drivers/gpio/gpio-lpc32xx.c‎

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,33 @@
1616
#include <linux/platform_device.h>
1717
#include <linux/module.h>
1818

19-
#include <mach/hardware.h>
20-
#include <mach/platform.h>
21-
22-
#define LPC32XX_GPIO_P3_INP_STATE _GPREG(0x000)
23-
#define LPC32XX_GPIO_P3_OUTP_SET _GPREG(0x004)
24-
#define LPC32XX_GPIO_P3_OUTP_CLR _GPREG(0x008)
25-
#define LPC32XX_GPIO_P3_OUTP_STATE _GPREG(0x00C)
26-
#define LPC32XX_GPIO_P2_DIR_SET _GPREG(0x010)
27-
#define LPC32XX_GPIO_P2_DIR_CLR _GPREG(0x014)
28-
#define LPC32XX_GPIO_P2_DIR_STATE _GPREG(0x018)
29-
#define LPC32XX_GPIO_P2_INP_STATE _GPREG(0x01C)
30-
#define LPC32XX_GPIO_P2_OUTP_SET _GPREG(0x020)
31-
#define LPC32XX_GPIO_P2_OUTP_CLR _GPREG(0x024)
32-
#define LPC32XX_GPIO_P2_MUX_SET _GPREG(0x028)
33-
#define LPC32XX_GPIO_P2_MUX_CLR _GPREG(0x02C)
34-
#define LPC32XX_GPIO_P2_MUX_STATE _GPREG(0x030)
35-
#define LPC32XX_GPIO_P0_INP_STATE _GPREG(0x040)
36-
#define LPC32XX_GPIO_P0_OUTP_SET _GPREG(0x044)
37-
#define LPC32XX_GPIO_P0_OUTP_CLR _GPREG(0x048)
38-
#define LPC32XX_GPIO_P0_OUTP_STATE _GPREG(0x04C)
39-
#define LPC32XX_GPIO_P0_DIR_SET _GPREG(0x050)
40-
#define LPC32XX_GPIO_P0_DIR_CLR _GPREG(0x054)
41-
#define LPC32XX_GPIO_P0_DIR_STATE _GPREG(0x058)
42-
#define LPC32XX_GPIO_P1_INP_STATE _GPREG(0x060)
43-
#define LPC32XX_GPIO_P1_OUTP_SET _GPREG(0x064)
44-
#define LPC32XX_GPIO_P1_OUTP_CLR _GPREG(0x068)
45-
#define LPC32XX_GPIO_P1_OUTP_STATE _GPREG(0x06C)
46-
#define LPC32XX_GPIO_P1_DIR_SET _GPREG(0x070)
47-
#define LPC32XX_GPIO_P1_DIR_CLR _GPREG(0x074)
48-
#define LPC32XX_GPIO_P1_DIR_STATE _GPREG(0x078)
19+
#define LPC32XX_GPIO_P3_INP_STATE (0x000)
20+
#define LPC32XX_GPIO_P3_OUTP_SET (0x004)
21+
#define LPC32XX_GPIO_P3_OUTP_CLR (0x008)
22+
#define LPC32XX_GPIO_P3_OUTP_STATE (0x00C)
23+
#define LPC32XX_GPIO_P2_DIR_SET (0x010)
24+
#define LPC32XX_GPIO_P2_DIR_CLR (0x014)
25+
#define LPC32XX_GPIO_P2_DIR_STATE (0x018)
26+
#define LPC32XX_GPIO_P2_INP_STATE (0x01C)
27+
#define LPC32XX_GPIO_P2_OUTP_SET (0x020)
28+
#define LPC32XX_GPIO_P2_OUTP_CLR (0x024)
29+
#define LPC32XX_GPIO_P2_MUX_SET (0x028)
30+
#define LPC32XX_GPIO_P2_MUX_CLR (0x02C)
31+
#define LPC32XX_GPIO_P2_MUX_STATE (0x030)
32+
#define LPC32XX_GPIO_P0_INP_STATE (0x040)
33+
#define LPC32XX_GPIO_P0_OUTP_SET (0x044)
34+
#define LPC32XX_GPIO_P0_OUTP_CLR (0x048)
35+
#define LPC32XX_GPIO_P0_OUTP_STATE (0x04C)
36+
#define LPC32XX_GPIO_P0_DIR_SET (0x050)
37+
#define LPC32XX_GPIO_P0_DIR_CLR (0x054)
38+
#define LPC32XX_GPIO_P0_DIR_STATE (0x058)
39+
#define LPC32XX_GPIO_P1_INP_STATE (0x060)
40+
#define LPC32XX_GPIO_P1_OUTP_SET (0x064)
41+
#define LPC32XX_GPIO_P1_OUTP_CLR (0x068)
42+
#define LPC32XX_GPIO_P1_OUTP_STATE (0x06C)
43+
#define LPC32XX_GPIO_P1_DIR_SET (0x070)
44+
#define LPC32XX_GPIO_P1_DIR_CLR (0x074)
45+
#define LPC32XX_GPIO_P1_DIR_STATE (0x078)
4946

5047
#define GPIO012_PIN_TO_BIT(x) (1 << (x))
5148
#define GPIO3_PIN_TO_BIT(x) (1 << ((x) + 25))
@@ -72,12 +69,12 @@
7269
#define LPC32XX_GPO_P3_GRP (LPC32XX_GPI_P3_GRP + LPC32XX_GPI_P3_MAX)
7370

7471
struct gpio_regs {
75-
void __iomem *inp_state;
76-
void __iomem *outp_state;
77-
void __iomem *outp_set;
78-
void __iomem *outp_clr;
79-
void __iomem *dir_set;
80-
void __iomem *dir_clr;
72+
unsigned long inp_state;
73+
unsigned long outp_state;
74+
unsigned long outp_set;
75+
unsigned long outp_clr;
76+
unsigned long dir_set;
77+
unsigned long dir_clr;
8178
};
8279

8380
/*
@@ -165,16 +162,27 @@ static struct gpio_regs gpio_grp_regs_p3 = {
165162
struct lpc32xx_gpio_chip {
166163
struct gpio_chip chip;
167164
struct gpio_regs *gpio_grp;
165+
void __iomem *reg_base;
168166
};
169167

168+
static inline u32 gpreg_read(struct lpc32xx_gpio_chip *group, unsigned long offset)
169+
{
170+
return __raw_readl(group->reg_base + offset);
171+
}
172+
173+
static inline void gpreg_write(struct lpc32xx_gpio_chip *group, u32 val, unsigned long offset)
174+
{
175+
__raw_writel(val, group->reg_base + offset);
176+
}
177+
170178
static void __set_gpio_dir_p012(struct lpc32xx_gpio_chip *group,
171179
unsigned pin, int input)
172180
{
173181
if (input)
174-
__raw_writel(GPIO012_PIN_TO_BIT(pin),
182+
gpreg_write(group, GPIO012_PIN_TO_BIT(pin),
175183
group->gpio_grp->dir_clr);
176184
else
177-
__raw_writel(GPIO012_PIN_TO_BIT(pin),
185+
gpreg_write(group, GPIO012_PIN_TO_BIT(pin),
178186
group->gpio_grp->dir_set);
179187
}
180188

@@ -184,19 +192,19 @@ static void __set_gpio_dir_p3(struct lpc32xx_gpio_chip *group,
184192
u32 u = GPIO3_PIN_TO_BIT(pin);
185193

186194
if (input)
187-
__raw_writel(u, group->gpio_grp->dir_clr);
195+
gpreg_write(group, u, group->gpio_grp->dir_clr);
188196
else
189-
__raw_writel(u, group->gpio_grp->dir_set);
197+
gpreg_write(group, u, group->gpio_grp->dir_set);
190198
}
191199

192200
static void __set_gpio_level_p012(struct lpc32xx_gpio_chip *group,
193201
unsigned pin, int high)
194202
{
195203
if (high)
196-
__raw_writel(GPIO012_PIN_TO_BIT(pin),
204+
gpreg_write(group, GPIO012_PIN_TO_BIT(pin),
197205
group->gpio_grp->outp_set);
198206
else
199-
__raw_writel(GPIO012_PIN_TO_BIT(pin),
207+
gpreg_write(group, GPIO012_PIN_TO_BIT(pin),
200208
group->gpio_grp->outp_clr);
201209
}
202210

@@ -206,31 +214,31 @@ static void __set_gpio_level_p3(struct lpc32xx_gpio_chip *group,
206214
u32 u = GPIO3_PIN_TO_BIT(pin);
207215

208216
if (high)
209-
__raw_writel(u, group->gpio_grp->outp_set);
217+
gpreg_write(group, u, group->gpio_grp->outp_set);
210218
else
211-
__raw_writel(u, group->gpio_grp->outp_clr);
219+
gpreg_write(group, u, group->gpio_grp->outp_clr);
212220
}
213221

214222
static void __set_gpo_level_p3(struct lpc32xx_gpio_chip *group,
215223
unsigned pin, int high)
216224
{
217225
if (high)
218-
__raw_writel(GPO3_PIN_TO_BIT(pin), group->gpio_grp->outp_set);
226+
gpreg_write(group, GPO3_PIN_TO_BIT(pin), group->gpio_grp->outp_set);
219227
else
220-
__raw_writel(GPO3_PIN_TO_BIT(pin), group->gpio_grp->outp_clr);
228+
gpreg_write(group, GPO3_PIN_TO_BIT(pin), group->gpio_grp->outp_clr);
221229
}
222230

223231
static int __get_gpio_state_p012(struct lpc32xx_gpio_chip *group,
224232
unsigned pin)
225233
{
226-
return GPIO012_PIN_IN_SEL(__raw_readl(group->gpio_grp->inp_state),
234+
return GPIO012_PIN_IN_SEL(gpreg_read(group, group->gpio_grp->inp_state),
227235
pin);
228236
}
229237

230238
static int __get_gpio_state_p3(struct lpc32xx_gpio_chip *group,
231239
unsigned pin)
232240
{
233-
int state = __raw_readl(group->gpio_grp->inp_state);
241+
int state = gpreg_read(group, group->gpio_grp->inp_state);
234242

235243
/*
236244
* P3 GPIO pin input mapping is not contiguous, GPIOP3-0..4 is mapped
@@ -242,13 +250,13 @@ static int __get_gpio_state_p3(struct lpc32xx_gpio_chip *group,
242250
static int __get_gpi_state_p3(struct lpc32xx_gpio_chip *group,
243251
unsigned pin)
244252
{
245-
return GPI3_PIN_IN_SEL(__raw_readl(group->gpio_grp->inp_state), pin);
253+
return GPI3_PIN_IN_SEL(gpreg_read(group, group->gpio_grp->inp_state), pin);
246254
}
247255

248256
static int __get_gpo_state_p3(struct lpc32xx_gpio_chip *group,
249257
unsigned pin)
250258
{
251-
return GPO3_PIN_IN_SEL(__raw_readl(group->gpio_grp->outp_state), pin);
259+
return GPO3_PIN_IN_SEL(gpreg_read(group, group->gpio_grp->outp_state), pin);
252260
}
253261

254262
/*
@@ -497,12 +505,18 @@ static int lpc32xx_of_xlate(struct gpio_chip *gc,
497505
static int lpc32xx_gpio_probe(struct platform_device *pdev)
498506
{
499507
int i;
508+
void __iomem *reg_base;
509+
510+
reg_base = devm_platform_ioremap_resource(pdev, 0);
511+
if (IS_ERR(reg_base))
512+
return PTR_ERR(reg_base);
500513

501514
for (i = 0; i < ARRAY_SIZE(lpc32xx_gpiochip); i++) {
502515
if (pdev->dev.of_node) {
503516
lpc32xx_gpiochip[i].chip.of_xlate = lpc32xx_of_xlate;
504517
lpc32xx_gpiochip[i].chip.of_gpio_n_cells = 3;
505518
lpc32xx_gpiochip[i].chip.of_node = pdev->dev.of_node;
519+
lpc32xx_gpiochip[i].reg_base = reg_base;
506520
}
507521
devm_gpiochip_add_data(&pdev->dev, &lpc32xx_gpiochip[i].chip,
508522
&lpc32xx_gpiochip[i]);
@@ -527,3 +541,7 @@ static struct platform_driver lpc32xx_gpio_driver = {
527541
};
528542

529543
module_platform_driver(lpc32xx_gpio_driver);
544+
545+
MODULE_AUTHOR("Kevin Wells <kevin.wells@nxp.com>");
546+
MODULE_LICENSE("GPL");
547+
MODULE_DESCRIPTION("GPIO driver for LPC32xx SoC");

0 commit comments

Comments
 (0)