Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: sprd: Clear interrupt when setting the type as edge

The raw interrupt status of GPIO maybe set before the interrupt is enabled,
which would trigger the interrupt event once enabled it from user side.
This is the case for edge interrupts only. Adding a clear operation when
setting interrupt type can avoid that.

There're a few considerations for the solution:
1) This issue is for edge interrupt only; The interrupts requested by users
are IRQ_TYPE_LEVEL_HIGH as default, so clearing interrupt when request
is useless.
2) The interrupt type can be set to edge when request and following up
with clearing it though, but the problem is still there once users set
the interrupt type to level trggier.
3) We can add a clear operation after each time of setting interrupt
enable bit, but it is redundant for level trigger interrupt.

Therefore, the solution is this patch seems the best for now.

Fixes: 9a3821c2bb47 ("gpio: Add GPIO driver for Spreadtrum SC9860 platform")
Signed-off-by: Taiping Lai <taiping.lai@unisoc.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
Reviewed-by: Baolin Wang <baolin.wang7@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

authored by

Taiping Lai and committed by
Bartosz Golaszewski
5fcface6 d3f99f91

+3
+3
drivers/gpio/gpio-sprd.c
··· 149 149 sprd_gpio_update(chip, offset, SPRD_GPIO_IS, 0); 150 150 sprd_gpio_update(chip, offset, SPRD_GPIO_IBE, 0); 151 151 sprd_gpio_update(chip, offset, SPRD_GPIO_IEV, 1); 152 + sprd_gpio_update(chip, offset, SPRD_GPIO_IC, 1); 152 153 irq_set_handler_locked(data, handle_edge_irq); 153 154 break; 154 155 case IRQ_TYPE_EDGE_FALLING: 155 156 sprd_gpio_update(chip, offset, SPRD_GPIO_IS, 0); 156 157 sprd_gpio_update(chip, offset, SPRD_GPIO_IBE, 0); 157 158 sprd_gpio_update(chip, offset, SPRD_GPIO_IEV, 0); 159 + sprd_gpio_update(chip, offset, SPRD_GPIO_IC, 1); 158 160 irq_set_handler_locked(data, handle_edge_irq); 159 161 break; 160 162 case IRQ_TYPE_EDGE_BOTH: 161 163 sprd_gpio_update(chip, offset, SPRD_GPIO_IS, 0); 162 164 sprd_gpio_update(chip, offset, SPRD_GPIO_IBE, 1); 165 + sprd_gpio_update(chip, offset, SPRD_GPIO_IC, 1); 163 166 irq_set_handler_locked(data, handle_edge_irq); 164 167 break; 165 168 case IRQ_TYPE_LEVEL_HIGH: