Skip to content

Commit bc38073

Browse files
committed
Merge tag 'gpio-v4.20-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO fixes from Linus Walleij: "Hopefully last round of GPIO fixes. The ACPI patch is pretty important for some laptop users, the rest is driver-specific for embedded (mostly ARM) systems. I took out one ACPI patch that wasn't critical enough because I couldn't justify sending it at this point, and that is why the commit date is today, but the patches have been in linux-next. Sorry for not sending some of them earlier :( Notice that we have a co-maintainer for GPIO now, Bartosz Golaszewski, and he might jump in and make some pull requests at times when I am off. Summary: - ACPI IRQ request deferral - OMAP: revert deferred wakeup quirk - MAX7301: fix DMA safe memory handling - MVEBU: selective probe failure on missing clk" * tag 'gpio-v4.20-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: gpio: mvebu: only fail on missing clk if pwm is actually to be used gpio: max7301: fix driver for use with CONFIG_VMAP_STACK gpio: gpio-omap: Revert deferred wakeup quirk handling for regressions gpiolib-acpi: Only defer request_irq for GpioInt ACPI event handlers
2 parents 7836195 + c8da642 commit bc38073

File tree

4 files changed

+95
-131
lines changed

4 files changed

+95
-131
lines changed

drivers/gpio/gpio-max7301.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static int max7301_spi_write(struct device *dev, unsigned int reg,
2525
struct spi_device *spi = to_spi_device(dev);
2626
u16 word = ((reg & 0x7F) << 8) | (val & 0xFF);
2727

28-
return spi_write(spi, (const u8 *)&word, sizeof(word));
28+
return spi_write_then_read(spi, &word, sizeof(word), NULL, 0);
2929
}
3030

3131
/* A read from the MAX7301 means two transfers; here, one message each */
@@ -37,14 +37,8 @@ static int max7301_spi_read(struct device *dev, unsigned int reg)
3737
struct spi_device *spi = to_spi_device(dev);
3838

3939
word = 0x8000 | (reg << 8);
40-
ret = spi_write(spi, (const u8 *)&word, sizeof(word));
41-
if (ret)
42-
return ret;
43-
/*
44-
* This relies on the fact, that a transfer with NULL tx_buf shifts out
45-
* zero bytes (=NOOP for MAX7301)
46-
*/
47-
ret = spi_read(spi, (u8 *)&word, sizeof(word));
40+
ret = spi_write_then_read(spi, &word, sizeof(word), &word,
41+
sizeof(word));
4842
if (ret)
4943
return ret;
5044
return word & 0xff;

drivers/gpio/gpio-mvebu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,6 @@ static int mvebu_pwm_probe(struct platform_device *pdev,
773773
"marvell,armada-370-gpio"))
774774
return 0;
775775

776-
if (IS_ERR(mvchip->clk))
777-
return PTR_ERR(mvchip->clk);
778-
779776
/*
780777
* There are only two sets of PWM configuration registers for
781778
* all the GPIO lines on those SoCs which this driver reserves
@@ -786,6 +783,9 @@ static int mvebu_pwm_probe(struct platform_device *pdev,
786783
if (!res)
787784
return 0;
788785

786+
if (IS_ERR(mvchip->clk))
787+
return PTR_ERR(mvchip->clk);
788+
789789
/*
790790
* Use set A for lines of GPIO chip with id 0, B for GPIO chip
791791
* with id 1. Don't allow further GPIO chips to be used for PWM.

drivers/gpio/gpio-omap.c

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#define OMAP4_GPIO_DEBOUNCINGTIME_MASK 0xFF
3333

3434
#define OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER BIT(2)
35-
#define OMAP_GPIO_QUIRK_DEFERRED_WKUP_EN BIT(1)
3635

3736
struct gpio_regs {
3837
u32 irqenable1;
@@ -379,18 +378,9 @@ static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio,
379378
readl_relaxed(bank->base + bank->regs->fallingdetect);
380379

381380
if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
382-
/* Defer wkup_en register update until we idle? */
383-
if (bank->quirks & OMAP_GPIO_QUIRK_DEFERRED_WKUP_EN) {
384-
if (trigger)
385-
bank->context.wake_en |= gpio_bit;
386-
else
387-
bank->context.wake_en &= ~gpio_bit;
388-
} else {
389-
omap_gpio_rmw(base, bank->regs->wkup_en, gpio_bit,
390-
trigger != 0);
391-
bank->context.wake_en =
392-
readl_relaxed(bank->base + bank->regs->wkup_en);
393-
}
381+
omap_gpio_rmw(base, bank->regs->wkup_en, gpio_bit, trigger != 0);
382+
bank->context.wake_en =
383+
readl_relaxed(bank->base + bank->regs->wkup_en);
394384
}
395385

396386
/* This part needs to be executed always for OMAP{34xx, 44xx} */
@@ -942,44 +932,6 @@ omap2_gpio_disable_level_quirk(struct gpio_bank *bank)
942932
bank->base + bank->regs->risingdetect);
943933
}
944934

945-
/*
946-
* On omap4 and later SoC variants a level interrupt with wkup_en
947-
* enabled blocks the GPIO functional clock from idling until the GPIO
948-
* instance has been reset. To avoid that, we must set wkup_en only for
949-
* idle for level interrupts, and clear level registers for the duration
950-
* of idle. The level interrupts will be still there on wakeup by their
951-
* nature.
952-
*/
953-
static void __maybe_unused
954-
omap4_gpio_enable_level_quirk(struct gpio_bank *bank)
955-
{
956-
/* Update wake register for idle, edge bits might be already set */
957-
writel_relaxed(bank->context.wake_en,
958-
bank->base + bank->regs->wkup_en);
959-
960-
/* Clear level registers for idle */
961-
writel_relaxed(0, bank->base + bank->regs->leveldetect0);
962-
writel_relaxed(0, bank->base + bank->regs->leveldetect1);
963-
}
964-
965-
static void __maybe_unused
966-
omap4_gpio_disable_level_quirk(struct gpio_bank *bank)
967-
{
968-
/* Restore level registers after idle */
969-
writel_relaxed(bank->context.leveldetect0,
970-
bank->base + bank->regs->leveldetect0);
971-
writel_relaxed(bank->context.leveldetect1,
972-
bank->base + bank->regs->leveldetect1);
973-
974-
/* Clear saved wkup_en for level, it will be set for next idle again */
975-
bank->context.wake_en &= ~(bank->context.leveldetect0 |
976-
bank->context.leveldetect1);
977-
978-
/* Update wake with only edge configuration */
979-
writel_relaxed(bank->context.wake_en,
980-
bank->base + bank->regs->wkup_en);
981-
}
982-
983935
/*---------------------------------------------------------------------*/
984936

985937
static int omap_mpuio_suspend_noirq(struct device *dev)
@@ -1412,12 +1364,7 @@ static int omap_gpio_probe(struct platform_device *pdev)
14121364
omap_set_gpio_dataout_mask_multiple;
14131365
}
14141366

1415-
if (bank->quirks & OMAP_GPIO_QUIRK_DEFERRED_WKUP_EN) {
1416-
bank->funcs.idle_enable_level_quirk =
1417-
omap4_gpio_enable_level_quirk;
1418-
bank->funcs.idle_disable_level_quirk =
1419-
omap4_gpio_disable_level_quirk;
1420-
} else if (bank->quirks & OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER) {
1367+
if (bank->quirks & OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER) {
14211368
bank->funcs.idle_enable_level_quirk =
14221369
omap2_gpio_enable_level_quirk;
14231370
bank->funcs.idle_disable_level_quirk =
@@ -1806,8 +1753,7 @@ static const struct omap_gpio_platform_data omap4_pdata = {
18061753
.regs = &omap4_gpio_regs,
18071754
.bank_width = 32,
18081755
.dbck_flag = true,
1809-
.quirks = OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER |
1810-
OMAP_GPIO_QUIRK_DEFERRED_WKUP_EN,
1756+
.quirks = OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER,
18111757
};
18121758

18131759
static const struct of_device_id omap_gpio_match[] = {

drivers/gpio/gpiolib-acpi.c

Lines changed: 84 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,28 @@
1919

2020
#include "gpiolib.h"
2121

22+
/**
23+
* struct acpi_gpio_event - ACPI GPIO event handler data
24+
*
25+
* @node: list-entry of the events list of the struct acpi_gpio_chip
26+
* @handle: handle of ACPI method to execute when the IRQ triggers
27+
* @handler: irq_handler to pass to request_irq when requesting the IRQ
28+
* @pin: GPIO pin number on the gpio_chip
29+
* @irq: Linux IRQ number for the event, for request_ / free_irq
30+
* @irqflags: flags to pass to request_irq when requesting the IRQ
31+
* @irq_is_wake: If the ACPI flags indicate the IRQ is a wakeup source
32+
* @is_requested: True if request_irq has been done
33+
* @desc: gpio_desc for the GPIO pin for this event
34+
*/
2235
struct acpi_gpio_event {
2336
struct list_head node;
2437
acpi_handle handle;
38+
irq_handler_t handler;
2539
unsigned int pin;
2640
unsigned int irq;
41+
unsigned long irqflags;
42+
bool irq_is_wake;
43+
bool irq_requested;
2744
struct gpio_desc *desc;
2845
};
2946

@@ -49,10 +66,10 @@ struct acpi_gpio_chip {
4966

5067
/*
5168
* For gpiochips which call acpi_gpiochip_request_interrupts() before late_init
52-
* (so builtin drivers) we register the ACPI GpioInt event handlers from a
69+
* (so builtin drivers) we register the ACPI GpioInt IRQ handlers from a
5370
* late_initcall_sync handler, so that other builtin drivers can register their
5471
* OpRegions before the event handlers can run. This list contains gpiochips
55-
* for which the acpi_gpiochip_request_interrupts() has been deferred.
72+
* for which the acpi_gpiochip_request_irqs() call has been deferred.
5673
*/
5774
static DEFINE_MUTEX(acpi_gpio_deferred_req_irqs_lock);
5875
static LIST_HEAD(acpi_gpio_deferred_req_irqs_list);
@@ -133,8 +150,42 @@ bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
133150
}
134151
EXPORT_SYMBOL_GPL(acpi_gpio_get_irq_resource);
135152

136-
static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
137-
void *context)
153+
static void acpi_gpiochip_request_irq(struct acpi_gpio_chip *acpi_gpio,
154+
struct acpi_gpio_event *event)
155+
{
156+
int ret, value;
157+
158+
ret = request_threaded_irq(event->irq, NULL, event->handler,
159+
event->irqflags, "ACPI:Event", event);
160+
if (ret) {
161+
dev_err(acpi_gpio->chip->parent,
162+
"Failed to setup interrupt handler for %d\n",
163+
event->irq);
164+
return;
165+
}
166+
167+
if (event->irq_is_wake)
168+
enable_irq_wake(event->irq);
169+
170+
event->irq_requested = true;
171+
172+
/* Make sure we trigger the initial state of edge-triggered IRQs */
173+
value = gpiod_get_raw_value_cansleep(event->desc);
174+
if (((event->irqflags & IRQF_TRIGGER_RISING) && value == 1) ||
175+
((event->irqflags & IRQF_TRIGGER_FALLING) && value == 0))
176+
event->handler(event->irq, event);
177+
}
178+
179+
static void acpi_gpiochip_request_irqs(struct acpi_gpio_chip *acpi_gpio)
180+
{
181+
struct acpi_gpio_event *event;
182+
183+
list_for_each_entry(event, &acpi_gpio->events, node)
184+
acpi_gpiochip_request_irq(acpi_gpio, event);
185+
}
186+
187+
static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares,
188+
void *context)
138189
{
139190
struct acpi_gpio_chip *acpi_gpio = context;
140191
struct gpio_chip *chip = acpi_gpio->chip;
@@ -143,8 +194,7 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
143194
struct acpi_gpio_event *event;
144195
irq_handler_t handler = NULL;
145196
struct gpio_desc *desc;
146-
unsigned long irqflags;
147-
int ret, pin, irq, value;
197+
int ret, pin, irq;
148198

149199
if (!acpi_gpio_get_irq_resource(ares, &agpio))
150200
return AE_OK;
@@ -175,8 +225,6 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
175225

176226
gpiod_direction_input(desc);
177227

178-
value = gpiod_get_value_cansleep(desc);
179-
180228
ret = gpiochip_lock_as_irq(chip, pin);
181229
if (ret) {
182230
dev_err(chip->parent, "Failed to lock GPIO as interrupt\n");
@@ -189,64 +237,42 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
189237
goto fail_unlock_irq;
190238
}
191239

192-
irqflags = IRQF_ONESHOT;
240+
event = kzalloc(sizeof(*event), GFP_KERNEL);
241+
if (!event)
242+
goto fail_unlock_irq;
243+
244+
event->irqflags = IRQF_ONESHOT;
193245
if (agpio->triggering == ACPI_LEVEL_SENSITIVE) {
194246
if (agpio->polarity == ACPI_ACTIVE_HIGH)
195-
irqflags |= IRQF_TRIGGER_HIGH;
247+
event->irqflags |= IRQF_TRIGGER_HIGH;
196248
else
197-
irqflags |= IRQF_TRIGGER_LOW;
249+
event->irqflags |= IRQF_TRIGGER_LOW;
198250
} else {
199251
switch (agpio->polarity) {
200252
case ACPI_ACTIVE_HIGH:
201-
irqflags |= IRQF_TRIGGER_RISING;
253+
event->irqflags |= IRQF_TRIGGER_RISING;
202254
break;
203255
case ACPI_ACTIVE_LOW:
204-
irqflags |= IRQF_TRIGGER_FALLING;
256+
event->irqflags |= IRQF_TRIGGER_FALLING;
205257
break;
206258
default:
207-
irqflags |= IRQF_TRIGGER_RISING |
208-
IRQF_TRIGGER_FALLING;
259+
event->irqflags |= IRQF_TRIGGER_RISING |
260+
IRQF_TRIGGER_FALLING;
209261
break;
210262
}
211263
}
212264

213-
event = kzalloc(sizeof(*event), GFP_KERNEL);
214-
if (!event)
215-
goto fail_unlock_irq;
216-
217265
event->handle = evt_handle;
266+
event->handler = handler;
218267
event->irq = irq;
268+
event->irq_is_wake = agpio->wake_capable == ACPI_WAKE_CAPABLE;
219269
event->pin = pin;
220270
event->desc = desc;
221271

222-
ret = request_threaded_irq(event->irq, NULL, handler, irqflags,
223-
"ACPI:Event", event);
224-
if (ret) {
225-
dev_err(chip->parent,
226-
"Failed to setup interrupt handler for %d\n",
227-
event->irq);
228-
goto fail_free_event;
229-
}
230-
231-
if (agpio->wake_capable == ACPI_WAKE_CAPABLE)
232-
enable_irq_wake(irq);
233-
234272
list_add_tail(&event->node, &acpi_gpio->events);
235273

236-
/*
237-
* Make sure we trigger the initial state of the IRQ when using RISING
238-
* or FALLING. Note we run the handlers on late_init, the AML code
239-
* may refer to OperationRegions from other (builtin) drivers which
240-
* may be probed after us.
241-
*/
242-
if (((irqflags & IRQF_TRIGGER_RISING) && value == 1) ||
243-
((irqflags & IRQF_TRIGGER_FALLING) && value == 0))
244-
handler(event->irq, event);
245-
246274
return AE_OK;
247275

248-
fail_free_event:
249-
kfree(event);
250276
fail_unlock_irq:
251277
gpiochip_unlock_as_irq(chip, pin);
252278
fail_free_desc:
@@ -283,6 +309,9 @@ void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
283309
if (ACPI_FAILURE(status))
284310
return;
285311

312+
acpi_walk_resources(handle, "_AEI",
313+
acpi_gpiochip_alloc_event, acpi_gpio);
314+
286315
mutex_lock(&acpi_gpio_deferred_req_irqs_lock);
287316
defer = !acpi_gpio_deferred_req_irqs_done;
288317
if (defer)
@@ -293,8 +322,7 @@ void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
293322
if (defer)
294323
return;
295324

296-
acpi_walk_resources(handle, "_AEI",
297-
acpi_gpiochip_request_interrupt, acpi_gpio);
325+
acpi_gpiochip_request_irqs(acpi_gpio);
298326
}
299327
EXPORT_SYMBOL_GPL(acpi_gpiochip_request_interrupts);
300328

@@ -331,10 +359,13 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
331359
list_for_each_entry_safe_reverse(event, ep, &acpi_gpio->events, node) {
332360
struct gpio_desc *desc;
333361

334-
if (irqd_is_wakeup_set(irq_get_irq_data(event->irq)))
335-
disable_irq_wake(event->irq);
362+
if (event->irq_requested) {
363+
if (event->irq_is_wake)
364+
disable_irq_wake(event->irq);
365+
366+
free_irq(event->irq, event);
367+
}
336368

337-
free_irq(event->irq, event);
338369
desc = event->desc;
339370
if (WARN_ON(IS_ERR(desc)))
340371
continue;
@@ -1200,28 +1231,21 @@ bool acpi_can_fallback_to_crs(struct acpi_device *adev, const char *con_id)
12001231
return con_id == NULL;
12011232
}
12021233

1203-
/* Run deferred acpi_gpiochip_request_interrupts() */
1204-
static int acpi_gpio_handle_deferred_request_interrupts(void)
1234+
/* Run deferred acpi_gpiochip_request_irqs() */
1235+
static int acpi_gpio_handle_deferred_request_irqs(void)
12051236
{
12061237
struct acpi_gpio_chip *acpi_gpio, *tmp;
12071238

12081239
mutex_lock(&acpi_gpio_deferred_req_irqs_lock);
12091240
list_for_each_entry_safe(acpi_gpio, tmp,
12101241
&acpi_gpio_deferred_req_irqs_list,
1211-
deferred_req_irqs_list_entry) {
1212-
acpi_handle handle;
1213-
1214-
handle = ACPI_HANDLE(acpi_gpio->chip->parent);
1215-
acpi_walk_resources(handle, "_AEI",
1216-
acpi_gpiochip_request_interrupt, acpi_gpio);
1217-
1218-
list_del_init(&acpi_gpio->deferred_req_irqs_list_entry);
1219-
}
1242+
deferred_req_irqs_list_entry)
1243+
acpi_gpiochip_request_irqs(acpi_gpio);
12201244

12211245
acpi_gpio_deferred_req_irqs_done = true;
12221246
mutex_unlock(&acpi_gpio_deferred_req_irqs_lock);
12231247

12241248
return 0;
12251249
}
12261250
/* We must use _sync so that this runs after the first deferred_probe run */
1227-
late_initcall_sync(acpi_gpio_handle_deferred_request_interrupts);
1251+
late_initcall_sync(acpi_gpio_handle_deferred_request_irqs);

0 commit comments

Comments
 (0)