@@ -1399,8 +1399,18 @@ static int gpiochip_irq_map(struct irq_domain *d, unsigned int irq,
13991399 return 0 ;
14001400}
14011401
1402+ static void gpiochip_irq_unmap (struct irq_domain * d , unsigned int irq )
1403+ {
1404+ #ifdef CONFIG_ARM
1405+ set_irq_flags (irq , 0 );
1406+ #endif
1407+ irq_set_chip_and_handler (irq , NULL , NULL );
1408+ irq_set_chip_data (irq , NULL );
1409+ }
1410+
14021411static const struct irq_domain_ops gpiochip_domain_ops = {
14031412 .map = gpiochip_irq_map ,
1413+ .unmap = gpiochip_irq_unmap ,
14041414 /* Virtually all GPIO irqchips are twocell:ed */
14051415 .xlate = irq_domain_xlate_twocell ,
14061416};
@@ -1438,8 +1448,14 @@ static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset)
14381448 */
14391449static void gpiochip_irqchip_remove (struct gpio_chip * gpiochip )
14401450{
1441- if (gpiochip -> irqdomain )
1451+ unsigned int offset ;
1452+
1453+ /* Remove all IRQ mappings and delete the domain */
1454+ if (gpiochip -> irqdomain ) {
1455+ for (offset = 0 ; offset < gpiochip -> ngpio ; offset ++ )
1456+ irq_dispose_mapping (gpiochip -> irq_base + offset );
14421457 irq_domain_remove (gpiochip -> irqdomain );
1458+ }
14431459
14441460 if (gpiochip -> irqchip ) {
14451461 gpiochip -> irqchip -> irq_request_resources = NULL ;
@@ -1467,7 +1483,8 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
14671483 * translation. The gpiochip will need to be initialized and registered
14681484 * before calling this function.
14691485 *
1470- * This function will handle two cell:ed simple IRQs. Everything else
1486+ * This function will handle two cell:ed simple IRQs and assumes all
1487+ * the pins on the gpiochip can generate a unique IRQ. Everything else
14711488 * need to be open coded.
14721489 */
14731490int gpiochip_irqchip_add (struct gpio_chip * gpiochip ,
@@ -1478,6 +1495,7 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
14781495{
14791496 struct device_node * of_node ;
14801497 unsigned int offset ;
1498+ unsigned irq_base = 0 ;
14811499
14821500 if (!gpiochip || !irqchip )
14831501 return - EINVAL ;
@@ -1514,8 +1532,15 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
15141532 * any gpiochip calls. If the first_irq was zero, this is
15151533 * necessary to allocate descriptors for all IRQs.
15161534 */
1517- for (offset = 0 ; offset < gpiochip -> ngpio ; offset ++ )
1518- irq_create_mapping (gpiochip -> irqdomain , offset );
1535+ for (offset = 0 ; offset < gpiochip -> ngpio ; offset ++ ) {
1536+ irq_base = irq_create_mapping (gpiochip -> irqdomain , offset );
1537+ if (offset == 0 )
1538+ /*
1539+ * Store the base into the gpiochip to be used when
1540+ * unmapping the irqs.
1541+ */
1542+ gpiochip -> irq_base = irq_base ;
1543+ }
15191544
15201545 return 0 ;
15211546}
0 commit comments