Skip to content

Commit 0bf0dfd

Browse files
committed
Merge tag 'gpio-v5.9-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO fixes from Linus Walleij: "Some late GPIO fixes for the v5.9 series: - Fix compiler warnings on the OMAP when PM is disabled - Clear the interrupt when setting edge sensitivity on the Spreadtrum driver. - Fix up spurious interrupts on the TC35894. - Support threaded interrupts on the Siox controller. - Fix resource leaks on the mockup driver. - Fix line event handling in syscall compatible mode for the character device. - Fix an unitialized variable in the PCA953A driver. - Fix access to all GPIO IRQs on the Aspeed AST2600. - Fix line direction on the AMD FCH driver. - Use the bitmap API instead of compiler intrinsics for bit manipulation in the PCA953x driver" * tag 'gpio-v5.9-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: gpio: pca953x: Correctly initialize registers 6 and 7 for PCA957x gpio: pca953x: Use bitmap API over implicit GCC extension gpio: amd-fch: correct logic of GPIO_LINE_DIRECTION gpio: aspeed: fix ast2600 bank properties gpio/aspeed-sgpio: don't enable all interrupts by default gpio/aspeed-sgpio: enable access to all 80 input & output sgpios gpio: pca953x: Fix uninitialized pending variable gpiolib: Fix line event handling in syscall compatible mode gpio: mockup: fix resource leak in error path gpio: siox: explicitly support only threaded irqs gpio: tc35894: fix up tc35894 interrupt configuration gpio: sprd: Clear interrupt when setting the type as edge gpio: omap: Fix warnings if PM is disabled
2 parents 2270b89 + 8c1f1c3 commit 0bf0dfd

11 files changed

Lines changed: 138 additions & 60 deletions

File tree

Documentation/devicetree/bindings/gpio/sgpio-aspeed.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ Required properties:
2020
- gpio-controller : Marks the device node as a GPIO controller
2121
- interrupts : Interrupt specifier, see interrupt-controller/interrupts.txt
2222
- interrupt-controller : Mark the GPIO controller as an interrupt-controller
23-
- ngpios : number of GPIO lines, see gpio.txt
24-
(should be multiple of 8, up to 80 pins)
23+
- ngpios : number of *hardware* GPIO lines, see gpio.txt. This will expose
24+
2 software GPIOs per hardware GPIO: one for hardware input, one for hardware
25+
output. Up to 80 pins, must be a multiple of 8.
2526
- clocks : A phandle to the APB clock for SGPM clock division
2627
- bus-frequency : SGPM CLK frequency
2728

drivers/gpio/gpio-amd-fch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static int amd_fch_gpio_get_direction(struct gpio_chip *gc, unsigned int gpio)
9292
ret = (readl_relaxed(ptr) & AMD_FCH_GPIO_FLAG_DIRECTION);
9393
spin_unlock_irqrestore(&priv->lock, flags);
9494

95-
return ret ? GPIO_LINE_DIRECTION_IN : GPIO_LINE_DIRECTION_OUT;
95+
return ret ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
9696
}
9797

9898
static void amd_fch_gpio_set(struct gpio_chip *gc,

drivers/gpio/gpio-aspeed-sgpio.c

Lines changed: 87 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@
1717
#include <linux/spinlock.h>
1818
#include <linux/string.h>
1919

20-
#define MAX_NR_SGPIO 80
20+
/*
21+
* MAX_NR_HW_GPIO represents the number of actual hardware-supported GPIOs (ie,
22+
* slots within the clocked serial GPIO data). Since each HW GPIO is both an
23+
* input and an output, we provide MAX_NR_HW_GPIO * 2 lines on our gpiochip
24+
* device.
25+
*
26+
* We use SGPIO_OUTPUT_OFFSET to define the split between the inputs and
27+
* outputs; the inputs start at line 0, the outputs start at OUTPUT_OFFSET.
28+
*/
29+
#define MAX_NR_HW_SGPIO 80
30+
#define SGPIO_OUTPUT_OFFSET MAX_NR_HW_SGPIO
2131

2232
#define ASPEED_SGPIO_CTRL 0x54
2333

@@ -30,8 +40,8 @@ struct aspeed_sgpio {
3040
struct clk *pclk;
3141
spinlock_t lock;
3242
void __iomem *base;
33-
uint32_t dir_in[3];
3443
int irq;
44+
int n_sgpio;
3545
};
3646

3747
struct aspeed_sgpio_bank {
@@ -111,54 +121,101 @@ static void __iomem *bank_reg(struct aspeed_sgpio *gpio,
111121
}
112122
}
113123

114-
#define GPIO_BANK(x) ((x) >> 5)
115-
#define GPIO_OFFSET(x) ((x) & 0x1f)
124+
#define GPIO_BANK(x) ((x % SGPIO_OUTPUT_OFFSET) >> 5)
125+
#define GPIO_OFFSET(x) ((x % SGPIO_OUTPUT_OFFSET) & 0x1f)
116126
#define GPIO_BIT(x) BIT(GPIO_OFFSET(x))
117127

118128
static const struct aspeed_sgpio_bank *to_bank(unsigned int offset)
119129
{
120-
unsigned int bank = GPIO_BANK(offset);
130+
unsigned int bank;
131+
132+
bank = GPIO_BANK(offset);
121133

122134
WARN_ON(bank >= ARRAY_SIZE(aspeed_sgpio_banks));
123135
return &aspeed_sgpio_banks[bank];
124136
}
125137

138+
static int aspeed_sgpio_init_valid_mask(struct gpio_chip *gc,
139+
unsigned long *valid_mask, unsigned int ngpios)
140+
{
141+
struct aspeed_sgpio *sgpio = gpiochip_get_data(gc);
142+
int n = sgpio->n_sgpio;
143+
int c = SGPIO_OUTPUT_OFFSET - n;
144+
145+
WARN_ON(ngpios < MAX_NR_HW_SGPIO * 2);
146+
147+
/* input GPIOs in the lower range */
148+
bitmap_set(valid_mask, 0, n);
149+
bitmap_clear(valid_mask, n, c);
150+
151+
/* output GPIOS above SGPIO_OUTPUT_OFFSET */
152+
bitmap_set(valid_mask, SGPIO_OUTPUT_OFFSET, n);
153+
bitmap_clear(valid_mask, SGPIO_OUTPUT_OFFSET + n, c);
154+
155+
return 0;
156+
}
157+
158+
static void aspeed_sgpio_irq_init_valid_mask(struct gpio_chip *gc,
159+
unsigned long *valid_mask, unsigned int ngpios)
160+
{
161+
struct aspeed_sgpio *sgpio = gpiochip_get_data(gc);
162+
int n = sgpio->n_sgpio;
163+
164+
WARN_ON(ngpios < MAX_NR_HW_SGPIO * 2);
165+
166+
/* input GPIOs in the lower range */
167+
bitmap_set(valid_mask, 0, n);
168+
bitmap_clear(valid_mask, n, ngpios - n);
169+
}
170+
171+
static bool aspeed_sgpio_is_input(unsigned int offset)
172+
{
173+
return offset < SGPIO_OUTPUT_OFFSET;
174+
}
175+
126176
static int aspeed_sgpio_get(struct gpio_chip *gc, unsigned int offset)
127177
{
128178
struct aspeed_sgpio *gpio = gpiochip_get_data(gc);
129179
const struct aspeed_sgpio_bank *bank = to_bank(offset);
130180
unsigned long flags;
131181
enum aspeed_sgpio_reg reg;
132-
bool is_input;
133182
int rc = 0;
134183

135184
spin_lock_irqsave(&gpio->lock, flags);
136185

137-
is_input = gpio->dir_in[GPIO_BANK(offset)] & GPIO_BIT(offset);
138-
reg = is_input ? reg_val : reg_rdata;
186+
reg = aspeed_sgpio_is_input(offset) ? reg_val : reg_rdata;
139187
rc = !!(ioread32(bank_reg(gpio, bank, reg)) & GPIO_BIT(offset));
140188

141189
spin_unlock_irqrestore(&gpio->lock, flags);
142190

143191
return rc;
144192
}
145193

146-
static void sgpio_set_value(struct gpio_chip *gc, unsigned int offset, int val)
194+
static int sgpio_set_value(struct gpio_chip *gc, unsigned int offset, int val)
147195
{
148196
struct aspeed_sgpio *gpio = gpiochip_get_data(gc);
149197
const struct aspeed_sgpio_bank *bank = to_bank(offset);
150-
void __iomem *addr;
198+
void __iomem *addr_r, *addr_w;
151199
u32 reg = 0;
152200

153-
addr = bank_reg(gpio, bank, reg_val);
154-
reg = ioread32(addr);
201+
if (aspeed_sgpio_is_input(offset))
202+
return -EINVAL;
203+
204+
/* Since this is an output, read the cached value from rdata, then
205+
* update val. */
206+
addr_r = bank_reg(gpio, bank, reg_rdata);
207+
addr_w = bank_reg(gpio, bank, reg_val);
208+
209+
reg = ioread32(addr_r);
155210

156211
if (val)
157212
reg |= GPIO_BIT(offset);
158213
else
159214
reg &= ~GPIO_BIT(offset);
160215

161-
iowrite32(reg, addr);
216+
iowrite32(reg, addr_w);
217+
218+
return 0;
162219
}
163220

164221
static void aspeed_sgpio_set(struct gpio_chip *gc, unsigned int offset, int val)
@@ -175,43 +232,28 @@ static void aspeed_sgpio_set(struct gpio_chip *gc, unsigned int offset, int val)
175232

176233
static int aspeed_sgpio_dir_in(struct gpio_chip *gc, unsigned int offset)
177234
{
178-
struct aspeed_sgpio *gpio = gpiochip_get_data(gc);
179-
unsigned long flags;
180-
181-
spin_lock_irqsave(&gpio->lock, flags);
182-
gpio->dir_in[GPIO_BANK(offset)] |= GPIO_BIT(offset);
183-
spin_unlock_irqrestore(&gpio->lock, flags);
184-
185-
return 0;
235+
return aspeed_sgpio_is_input(offset) ? 0 : -EINVAL;
186236
}
187237

188238
static int aspeed_sgpio_dir_out(struct gpio_chip *gc, unsigned int offset, int val)
189239
{
190240
struct aspeed_sgpio *gpio = gpiochip_get_data(gc);
191241
unsigned long flags;
242+
int rc;
192243

193-
spin_lock_irqsave(&gpio->lock, flags);
194-
195-
gpio->dir_in[GPIO_BANK(offset)] &= ~GPIO_BIT(offset);
196-
sgpio_set_value(gc, offset, val);
244+
/* No special action is required for setting the direction; we'll
245+
* error-out in sgpio_set_value if this isn't an output GPIO */
197246

247+
spin_lock_irqsave(&gpio->lock, flags);
248+
rc = sgpio_set_value(gc, offset, val);
198249
spin_unlock_irqrestore(&gpio->lock, flags);
199250

200-
return 0;
251+
return rc;
201252
}
202253

203254
static int aspeed_sgpio_get_direction(struct gpio_chip *gc, unsigned int offset)
204255
{
205-
int dir_status;
206-
struct aspeed_sgpio *gpio = gpiochip_get_data(gc);
207-
unsigned long flags;
208-
209-
spin_lock_irqsave(&gpio->lock, flags);
210-
dir_status = gpio->dir_in[GPIO_BANK(offset)] & GPIO_BIT(offset);
211-
spin_unlock_irqrestore(&gpio->lock, flags);
212-
213-
return dir_status;
214-
256+
return !!aspeed_sgpio_is_input(offset);
215257
}
216258

217259
static void irqd_to_aspeed_sgpio_data(struct irq_data *d,
@@ -402,24 +444,23 @@ static int aspeed_sgpio_setup_irqs(struct aspeed_sgpio *gpio,
402444

403445
irq = &gpio->chip.irq;
404446
irq->chip = &aspeed_sgpio_irqchip;
447+
irq->init_valid_mask = aspeed_sgpio_irq_init_valid_mask;
405448
irq->handler = handle_bad_irq;
406449
irq->default_type = IRQ_TYPE_NONE;
407450
irq->parent_handler = aspeed_sgpio_irq_handler;
408451
irq->parent_handler_data = gpio;
409452
irq->parents = &gpio->irq;
410453
irq->num_parents = 1;
411454

412-
/* set IRQ settings and Enable Interrupt */
455+
/* Apply default IRQ settings */
413456
for (i = 0; i < ARRAY_SIZE(aspeed_sgpio_banks); i++) {
414457
bank = &aspeed_sgpio_banks[i];
415458
/* set falling or level-low irq */
416459
iowrite32(0x00000000, bank_reg(gpio, bank, reg_irq_type0));
417460
/* trigger type is edge */
418461
iowrite32(0x00000000, bank_reg(gpio, bank, reg_irq_type1));
419-
/* dual edge trigger mode. */
420-
iowrite32(0xffffffff, bank_reg(gpio, bank, reg_irq_type2));
421-
/* enable irq */
422-
iowrite32(0xffffffff, bank_reg(gpio, bank, reg_irq_enable));
462+
/* single edge trigger */
463+
iowrite32(0x00000000, bank_reg(gpio, bank, reg_irq_type2));
423464
}
424465

425466
return 0;
@@ -452,11 +493,12 @@ static int __init aspeed_sgpio_probe(struct platform_device *pdev)
452493
if (rc < 0) {
453494
dev_err(&pdev->dev, "Could not read ngpios property\n");
454495
return -EINVAL;
455-
} else if (nr_gpios > MAX_NR_SGPIO) {
496+
} else if (nr_gpios > MAX_NR_HW_SGPIO) {
456497
dev_err(&pdev->dev, "Number of GPIOs exceeds the maximum of %d: %d\n",
457-
MAX_NR_SGPIO, nr_gpios);
498+
MAX_NR_HW_SGPIO, nr_gpios);
458499
return -EINVAL;
459500
}
501+
gpio->n_sgpio = nr_gpios;
460502

461503
rc = of_property_read_u32(pdev->dev.of_node, "bus-frequency", &sgpio_freq);
462504
if (rc < 0) {
@@ -497,7 +539,8 @@ static int __init aspeed_sgpio_probe(struct platform_device *pdev)
497539
spin_lock_init(&gpio->lock);
498540

499541
gpio->chip.parent = &pdev->dev;
500-
gpio->chip.ngpio = nr_gpios;
542+
gpio->chip.ngpio = MAX_NR_HW_SGPIO * 2;
543+
gpio->chip.init_valid_mask = aspeed_sgpio_init_valid_mask;
501544
gpio->chip.direction_input = aspeed_sgpio_dir_in;
502545
gpio->chip.direction_output = aspeed_sgpio_dir_out;
503546
gpio->chip.get_direction = aspeed_sgpio_get_direction;
@@ -509,9 +552,6 @@ static int __init aspeed_sgpio_probe(struct platform_device *pdev)
509552
gpio->chip.label = dev_name(&pdev->dev);
510553
gpio->chip.base = -1;
511554

512-
/* set all SGPIO pins as input (1). */
513-
memset(gpio->dir_in, 0xff, sizeof(gpio->dir_in));
514-
515555
aspeed_sgpio_setup_irqs(gpio, pdev);
516556

517557
rc = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio);

drivers/gpio/gpio-aspeed.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,8 +1114,8 @@ static const struct aspeed_gpio_config ast2500_config =
11141114

11151115
static const struct aspeed_bank_props ast2600_bank_props[] = {
11161116
/* input output */
1117-
{5, 0xffffffff, 0x0000ffff}, /* U/V/W/X */
1118-
{6, 0xffff0000, 0x0fff0000}, /* Y/Z */
1117+
{5, 0xffffffff, 0xffffff00}, /* U/V/W/X */
1118+
{6, 0x0000ffff, 0x0000ffff}, /* Y/Z */
11191119
{ },
11201120
};
11211121

drivers/gpio/gpio-mockup.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ static int __init gpio_mockup_init(void)
552552
err = platform_driver_register(&gpio_mockup_driver);
553553
if (err) {
554554
gpio_mockup_err("error registering platform driver\n");
555+
debugfs_remove_recursive(gpio_mockup_dbg_dir);
555556
return err;
556557
}
557558

@@ -582,6 +583,7 @@ static int __init gpio_mockup_init(void)
582583
gpio_mockup_err("error registering device");
583584
platform_driver_unregister(&gpio_mockup_driver);
584585
gpio_mockup_unregister_pdevs();
586+
debugfs_remove_recursive(gpio_mockup_dbg_dir);
585587
return PTR_ERR(pdev);
586588
}
587589

drivers/gpio/gpio-omap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ static int __maybe_unused omap_gpio_runtime_resume(struct device *dev)
15161516
return 0;
15171517
}
15181518

1519-
static int omap_gpio_suspend(struct device *dev)
1519+
static int __maybe_unused omap_gpio_suspend(struct device *dev)
15201520
{
15211521
struct gpio_bank *bank = dev_get_drvdata(dev);
15221522

@@ -1528,7 +1528,7 @@ static int omap_gpio_suspend(struct device *dev)
15281528
return omap_gpio_runtime_suspend(dev);
15291529
}
15301530

1531-
static int omap_gpio_resume(struct device *dev)
1531+
static int __maybe_unused omap_gpio_resume(struct device *dev)
15321532
{
15331533
struct gpio_bank *bank = dev_get_drvdata(dev);
15341534

drivers/gpio/gpio-pca953x.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,8 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
818818
int level;
819819
bool ret;
820820

821+
bitmap_zero(pending, MAX_LINE);
822+
821823
mutex_lock(&chip->i2c_lock);
822824
ret = pca953x_irq_pending(chip, pending);
823825
mutex_unlock(&chip->i2c_lock);
@@ -940,14 +942,17 @@ static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert)
940942
static int device_pca957x_init(struct pca953x_chip *chip, u32 invert)
941943
{
942944
DECLARE_BITMAP(val, MAX_LINE);
945+
unsigned int i;
943946
int ret;
944947

945948
ret = device_pca95xx_init(chip, invert);
946949
if (ret)
947950
goto out;
948951

949952
/* To enable register 6, 7 to control pull up and pull down */
950-
memset(val, 0x02, NBANK(chip));
953+
for (i = 0; i < NBANK(chip); i++)
954+
bitmap_set_value8(val, 0x02, i * BANK_SZ);
955+
951956
ret = pca953x_write_regs(chip, PCA957X_BKEN, val);
952957
if (ret)
953958
goto out;

drivers/gpio/gpio-siox.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ static int gpio_siox_probe(struct siox_device *sdevice)
245245
girq->chip = &ddata->ichip;
246246
girq->default_type = IRQ_TYPE_NONE;
247247
girq->handler = handle_level_irq;
248+
girq->threaded = true;
248249

249250
ret = devm_gpiochip_add_data(dev, &ddata->gchip, NULL);
250251
if (ret)

drivers/gpio/gpio-sprd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,20 @@ static int sprd_gpio_irq_set_type(struct irq_data *data,
149149
sprd_gpio_update(chip, offset, SPRD_GPIO_IS, 0);
150150
sprd_gpio_update(chip, offset, SPRD_GPIO_IBE, 0);
151151
sprd_gpio_update(chip, offset, SPRD_GPIO_IEV, 1);
152+
sprd_gpio_update(chip, offset, SPRD_GPIO_IC, 1);
152153
irq_set_handler_locked(data, handle_edge_irq);
153154
break;
154155
case IRQ_TYPE_EDGE_FALLING:
155156
sprd_gpio_update(chip, offset, SPRD_GPIO_IS, 0);
156157
sprd_gpio_update(chip, offset, SPRD_GPIO_IBE, 0);
157158
sprd_gpio_update(chip, offset, SPRD_GPIO_IEV, 0);
159+
sprd_gpio_update(chip, offset, SPRD_GPIO_IC, 1);
158160
irq_set_handler_locked(data, handle_edge_irq);
159161
break;
160162
case IRQ_TYPE_EDGE_BOTH:
161163
sprd_gpio_update(chip, offset, SPRD_GPIO_IS, 0);
162164
sprd_gpio_update(chip, offset, SPRD_GPIO_IBE, 1);
165+
sprd_gpio_update(chip, offset, SPRD_GPIO_IC, 1);
163166
irq_set_handler_locked(data, handle_edge_irq);
164167
break;
165168
case IRQ_TYPE_LEVEL_HIGH:

drivers/gpio/gpio-tc3589x.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d)
212212
continue;
213213

214214
tc3589x_gpio->oldregs[i][j] = new;
215-
tc3589x_reg_write(tc3589x, regmap[i] + j * 8, new);
215+
tc3589x_reg_write(tc3589x, regmap[i] + j, new);
216216
}
217217
}
218218

0 commit comments

Comments
 (0)