Skip to content

Commit 243f750

Browse files
committed
Merge tag 'gpio-fixes-for-v6.13-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
Pull gpio fixes from Bartosz Golaszewski: - fix several low-level issues in gpio-graniterapids - fix an initialization order issue that manifests itself with __counted_by() checks in gpio-ljca - don't default to y for CONFIG_GPIO_MVEBU with COMPILE_TEST enabled - move the DEFAULT_SYMBOL_NAMESPACE define before the export.h include in gpio-idio-16 * tag 'gpio-fixes-for-v6.13-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: gpio: idio-16: Actually make use of the GPIO_IDIO_16 symbol namespace gpio: graniterapids: Fix GPIO Ack functionality gpio: graniterapids: Check if GPIO line can be used for IRQs gpio: graniterapids: Determine if GPIO pad can be used by driver gpio: graniterapids: Fix invalid RXEVCFG register bitmask gpio: graniterapids: Fix invalid GPI_IS register offset gpio: graniterapids: Fix incorrect BAR assignment gpio: graniterapids: Fix vGPIO driver crash gpio: ljca: Initialize num before accessing item in ljca_gpio_config gpio: GPIO_MVEBU should not default to y when compile-testing
2 parents de20dc2 + 9ac4b58 commit 243f750

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

drivers/gpio/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,9 @@ config GPIO_MT7621
482482
Say yes here to support the Mediatek MT7621 SoC GPIO device.
483483

484484
config GPIO_MVEBU
485-
def_bool y
485+
bool "Marvell Orion and EBU GPIO support" if COMPILE_TEST
486486
depends on PLAT_ORION || ARCH_MVEBU || COMPILE_TEST
487+
default PLAT_ORION || ARCH_MVEBU
487488
select GENERIC_IRQ_CHIP
488489
select REGMAP_MMIO
489490

drivers/gpio/gpio-graniterapids.c

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232
#define GNR_PINS_PER_REG 32
3333
#define GNR_NUM_REGS DIV_ROUND_UP(GNR_NUM_PINS, GNR_PINS_PER_REG)
3434

35-
#define GNR_CFG_BAR 0x00
35+
#define GNR_CFG_PADBAR 0x00
3636
#define GNR_CFG_LOCK_OFFSET 0x04
37-
#define GNR_GPI_STATUS_OFFSET 0x20
37+
#define GNR_GPI_STATUS_OFFSET 0x14
3838
#define GNR_GPI_ENABLE_OFFSET 0x24
3939

40-
#define GNR_CFG_DW_RX_MASK GENMASK(25, 22)
40+
#define GNR_CFG_DW_HOSTSW_MODE BIT(27)
41+
#define GNR_CFG_DW_RX_MASK GENMASK(23, 22)
42+
#define GNR_CFG_DW_INTSEL_MASK GENMASK(21, 14)
4143
#define GNR_CFG_DW_RX_DISABLE FIELD_PREP(GNR_CFG_DW_RX_MASK, 2)
4244
#define GNR_CFG_DW_RX_EDGE FIELD_PREP(GNR_CFG_DW_RX_MASK, 1)
4345
#define GNR_CFG_DW_RX_LEVEL FIELD_PREP(GNR_CFG_DW_RX_MASK, 0)
@@ -50,13 +52,15 @@
5052
* struct gnr_gpio - Intel Granite Rapids-D vGPIO driver state
5153
* @gc: GPIO controller interface
5254
* @reg_base: base address of the GPIO registers
55+
* @pad_base: base address of the vGPIO pad configuration registers
5356
* @ro_bitmap: bitmap of read-only pins
5457
* @lock: guard the registers
5558
* @pad_backup: backup of the register state for suspend
5659
*/
5760
struct gnr_gpio {
5861
struct gpio_chip gc;
5962
void __iomem *reg_base;
63+
void __iomem *pad_base;
6064
DECLARE_BITMAP(ro_bitmap, GNR_NUM_PINS);
6165
raw_spinlock_t lock;
6266
u32 pad_backup[];
@@ -65,7 +69,7 @@ struct gnr_gpio {
6569
static void __iomem *gnr_gpio_get_padcfg_addr(const struct gnr_gpio *priv,
6670
unsigned int gpio)
6771
{
68-
return priv->reg_base + gpio * sizeof(u32);
72+
return priv->pad_base + gpio * sizeof(u32);
6973
}
7074

7175
static int gnr_gpio_configure_line(struct gpio_chip *gc, unsigned int gpio,
@@ -88,6 +92,20 @@ static int gnr_gpio_configure_line(struct gpio_chip *gc, unsigned int gpio,
8892
return 0;
8993
}
9094

95+
static int gnr_gpio_request(struct gpio_chip *gc, unsigned int gpio)
96+
{
97+
struct gnr_gpio *priv = gpiochip_get_data(gc);
98+
u32 dw;
99+
100+
dw = readl(gnr_gpio_get_padcfg_addr(priv, gpio));
101+
if (!(dw & GNR_CFG_DW_HOSTSW_MODE)) {
102+
dev_warn(gc->parent, "GPIO %u is not owned by host", gpio);
103+
return -EBUSY;
104+
}
105+
106+
return 0;
107+
}
108+
91109
static int gnr_gpio_get(struct gpio_chip *gc, unsigned int gpio)
92110
{
93111
const struct gnr_gpio *priv = gpiochip_get_data(gc);
@@ -139,6 +157,7 @@ static int gnr_gpio_direction_output(struct gpio_chip *gc, unsigned int gpio, in
139157

140158
static const struct gpio_chip gnr_gpio_chip = {
141159
.owner = THIS_MODULE,
160+
.request = gnr_gpio_request,
142161
.get = gnr_gpio_get,
143162
.set = gnr_gpio_set,
144163
.get_direction = gnr_gpio_get_direction,
@@ -166,7 +185,7 @@ static void gnr_gpio_irq_ack(struct irq_data *d)
166185
guard(raw_spinlock_irqsave)(&priv->lock);
167186

168187
reg = readl(addr);
169-
reg &= ~BIT(bit_idx);
188+
reg |= BIT(bit_idx);
170189
writel(reg, addr);
171190
}
172191

@@ -209,10 +228,18 @@ static void gnr_gpio_irq_unmask(struct irq_data *d)
209228
static int gnr_gpio_irq_set_type(struct irq_data *d, unsigned int type)
210229
{
211230
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
212-
irq_hw_number_t pin = irqd_to_hwirq(d);
213-
u32 mask = GNR_CFG_DW_RX_MASK;
231+
struct gnr_gpio *priv = gpiochip_get_data(gc);
232+
irq_hw_number_t hwirq = irqd_to_hwirq(d);
233+
u32 reg;
214234
u32 set;
215235

236+
/* Allow interrupts only if Interrupt Select field is non-zero */
237+
reg = readl(gnr_gpio_get_padcfg_addr(priv, hwirq));
238+
if (!(reg & GNR_CFG_DW_INTSEL_MASK)) {
239+
dev_dbg(gc->parent, "GPIO %lu cannot be used as IRQ", hwirq);
240+
return -EPERM;
241+
}
242+
216243
/* Falling edge and level low triggers not supported by the GPIO controller */
217244
switch (type) {
218245
case IRQ_TYPE_NONE:
@@ -230,10 +257,11 @@ static int gnr_gpio_irq_set_type(struct irq_data *d, unsigned int type)
230257
return -EINVAL;
231258
}
232259

233-
return gnr_gpio_configure_line(gc, pin, mask, set);
260+
return gnr_gpio_configure_line(gc, hwirq, GNR_CFG_DW_RX_MASK, set);
234261
}
235262

236263
static const struct irq_chip gnr_gpio_irq_chip = {
264+
.name = "gpio-graniterapids",
237265
.irq_ack = gnr_gpio_irq_ack,
238266
.irq_mask = gnr_gpio_irq_mask,
239267
.irq_unmask = gnr_gpio_irq_unmask,
@@ -291,6 +319,7 @@ static int gnr_gpio_probe(struct platform_device *pdev)
291319
struct gnr_gpio *priv;
292320
void __iomem *regs;
293321
int irq, ret;
322+
u32 offset;
294323

295324
priv = devm_kzalloc(dev, struct_size(priv, pad_backup, num_backup_pins), GFP_KERNEL);
296325
if (!priv)
@@ -302,6 +331,10 @@ static int gnr_gpio_probe(struct platform_device *pdev)
302331
if (IS_ERR(regs))
303332
return PTR_ERR(regs);
304333

334+
priv->reg_base = regs;
335+
offset = readl(priv->reg_base + GNR_CFG_PADBAR);
336+
priv->pad_base = priv->reg_base + offset;
337+
305338
irq = platform_get_irq(pdev, 0);
306339
if (irq < 0)
307340
return irq;
@@ -311,8 +344,6 @@ static int gnr_gpio_probe(struct platform_device *pdev)
311344
if (ret)
312345
return dev_err_probe(dev, ret, "failed to request interrupt\n");
313346

314-
priv->reg_base = regs + readl(regs + GNR_CFG_BAR);
315-
316347
gnr_gpio_init_pin_ro_bits(dev, priv->reg_base + GNR_CFG_LOCK_OFFSET,
317348
priv->ro_bitmap);
318349

@@ -324,7 +355,6 @@ static int gnr_gpio_probe(struct platform_device *pdev)
324355

325356
girq = &priv->gc.irq;
326357
gpio_irq_chip_set_chip(girq, &gnr_gpio_irq_chip);
327-
girq->chip->name = dev_name(dev);
328358
girq->parent_handler = NULL;
329359
girq->num_parents = 0;
330360
girq->parents = NULL;

drivers/gpio/gpio-idio-16.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* GPIO library for the ACCES IDIO-16 family
44
* Copyright (C) 2022 William Breathitt Gray
55
*/
6+
7+
#define DEFAULT_SYMBOL_NAMESPACE "GPIO_IDIO_16"
8+
69
#include <linux/bits.h>
710
#include <linux/device.h>
811
#include <linux/err.h>
@@ -14,8 +17,6 @@
1417

1518
#include "gpio-idio-16.h"
1619

17-
#define DEFAULT_SYMBOL_NAMESPACE "GPIO_IDIO_16"
18-
1920
#define IDIO_16_DAT_BASE 0x0
2021
#define IDIO_16_OUT_BASE IDIO_16_DAT_BASE
2122
#define IDIO_16_IN_BASE (IDIO_16_DAT_BASE + 1)

drivers/gpio/gpio-ljca.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ static int ljca_gpio_config(struct ljca_gpio_dev *ljca_gpio, u8 gpio_id,
8282
int ret;
8383

8484
mutex_lock(&ljca_gpio->trans_lock);
85+
packet->num = 1;
8586
packet->item[0].index = gpio_id;
8687
packet->item[0].value = config | ljca_gpio->connect_mode[gpio_id];
87-
packet->num = 1;
8888

8989
ret = ljca_transfer(ljca_gpio->ljca, LJCA_GPIO_CONFIG, (u8 *)packet,
9090
struct_size(packet, item, packet->num), NULL, 0);

0 commit comments

Comments
 (0)