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

gpio: sch: Hook into ACPI GPE handler to catch GPIO edge events

Neither the ACPI description on Intel Minnowboard (v1) platform provides
the required information to establish a generic handling nor the hardware
capable of doing it. According to the data sheet the hardware can generate
SCI events. Therefore, we need to hook from the driver into GPE handler of
the ACPI subsystem in order to catch and report GPIO-related events.

Validated on the Inlel Minnowboard (v1) platform and Intel Galileo Gen 2.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Andy Shevchenko and committed by
Bartosz Golaszewski
fdc1f5df 7a816384

+83 -1
+1 -1
drivers/gpio/Kconfig
··· 860 860 861 861 config GPIO_SCH 862 862 tristate "Intel SCH/TunnelCreek/Centerton/Quark X1000 GPIO" 863 - depends on (X86 || COMPILE_TEST) && PCI 863 + depends on (X86 || COMPILE_TEST) && ACPI 864 864 select GPIOLIB_IRQCHIP 865 865 select MFD_CORE 866 866 select LPC_SCH
+82
drivers/gpio/gpio-sch.c
··· 7 7 */ 8 8 9 9 #include <linux/acpi.h> 10 + #include <linux/bitops.h> 10 11 #include <linux/errno.h> 11 12 #include <linux/gpio/driver.h> 12 13 #include <linux/io.h> ··· 30 29 #define CORE_BANK_OFFSET 0x00 31 30 #define RESUME_BANK_OFFSET 0x20 32 31 32 + /* 33 + * iLB datasheet describes GPE0BLK registers, in particular GPE0E.GPIO bit. 34 + * Document Number: 328195-001 35 + */ 36 + #define GPE0E_GPIO 14 37 + 33 38 struct sch_gpio { 34 39 struct gpio_chip chip; 35 40 struct irq_chip irqchip; 36 41 spinlock_t lock; 37 42 unsigned short iobase; 38 43 unsigned short resume_base; 44 + 45 + /* GPE handling */ 46 + u32 gpe; 47 + acpi_gpe_handler gpe_handler; 39 48 }; 40 49 41 50 static unsigned int sch_gpio_offset(struct sch_gpio *sch, unsigned int gpio, ··· 240 229 sch_irq_mask_unmask(d, 1); 241 230 } 242 231 232 + static u32 sch_gpio_gpe_handler(acpi_handle gpe_device, u32 gpe, void *context) 233 + { 234 + struct sch_gpio *sch = context; 235 + struct gpio_chip *gc = &sch->chip; 236 + unsigned long core_status, resume_status; 237 + unsigned long pending; 238 + unsigned long flags; 239 + int offset; 240 + u32 ret; 241 + 242 + spin_lock_irqsave(&sch->lock, flags); 243 + 244 + core_status = inl(sch->iobase + CORE_BANK_OFFSET + GTS); 245 + resume_status = inl(sch->iobase + RESUME_BANK_OFFSET + GTS); 246 + 247 + spin_unlock_irqrestore(&sch->lock, flags); 248 + 249 + pending = (resume_status << sch->resume_base) | core_status; 250 + for_each_set_bit(offset, &pending, sch->chip.ngpio) 251 + generic_handle_irq(irq_find_mapping(gc->irq.domain, offset)); 252 + 253 + /* Set returning value depending on whether we handled an interrupt */ 254 + ret = pending ? ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; 255 + 256 + /* Acknowledge GPE to ACPICA */ 257 + ret |= ACPI_REENABLE_GPE; 258 + 259 + return ret; 260 + } 261 + 262 + static void sch_gpio_remove_gpe_handler(void *data) 263 + { 264 + struct sch_gpio *sch = data; 265 + 266 + acpi_disable_gpe(NULL, sch->gpe); 267 + acpi_remove_gpe_handler(NULL, sch->gpe, sch->gpe_handler); 268 + } 269 + 270 + static int sch_gpio_install_gpe_handler(struct sch_gpio *sch) 271 + { 272 + struct device *dev = sch->chip.parent; 273 + acpi_status status; 274 + 275 + status = acpi_install_gpe_handler(NULL, sch->gpe, ACPI_GPE_LEVEL_TRIGGERED, 276 + sch->gpe_handler, sch); 277 + if (ACPI_FAILURE(status)) { 278 + dev_err(dev, "Failed to install GPE handler for %u: %s\n", 279 + sch->gpe, acpi_format_exception(status)); 280 + return -ENODEV; 281 + } 282 + 283 + status = acpi_enable_gpe(NULL, sch->gpe); 284 + if (ACPI_FAILURE(status)) { 285 + dev_err(dev, "Failed to enable GPE handler for %u: %s\n", 286 + sch->gpe, acpi_format_exception(status)); 287 + acpi_remove_gpe_handler(NULL, sch->gpe, sch->gpe_handler); 288 + return -ENODEV; 289 + } 290 + 291 + return devm_add_action_or_reset(dev, sch_gpio_remove_gpe_handler, sch); 292 + } 293 + 243 294 static int sch_gpio_probe(struct platform_device *pdev) 244 295 { 245 296 struct gpio_irq_chip *girq; 246 297 struct sch_gpio *sch; 247 298 struct resource *res; 299 + int ret; 248 300 249 301 sch = devm_kzalloc(&pdev->dev, sizeof(*sch), GFP_KERNEL); 250 302 if (!sch) ··· 380 306 girq->parent_handler = NULL; 381 307 girq->default_type = IRQ_TYPE_NONE; 382 308 girq->handler = handle_bad_irq; 309 + 310 + /* GPE setup is optional */ 311 + sch->gpe = GPE0E_GPIO; 312 + sch->gpe_handler = sch_gpio_gpe_handler; 313 + 314 + ret = sch_gpio_install_gpe_handler(sch); 315 + if (ret) 316 + dev_warn(&pdev->dev, "Can't setup GPE, no IRQ support\n"); 383 317 384 318 return devm_gpiochip_add_data(&pdev->dev, &sch->chip, sch); 385 319 }