Convert the spmi-pmic-arb IRQ code to use the version 2 IRQ interface in order to support hierarchical IRQ chips. This is necessary so that spmi-gpio can be setup as a hierarchical IRQ chip with pmic-arb as the parent. IRQ chips in device tree should be usable from the start without the consumer having to make an additional call to gpio[d]_to_irq() to get the proper IRQ on the parent. The old qpnpint_irq_domain_map function would hardcode the handler as handle_level_irq, however qpnpint_irq_set_type would later override the handler. Properly set the handler when the IRQ is mapped. This new code doesn't return an error for IRQ_TYPE_NONE and preserves the existing behavior of using handle_level_irq since there are some broken device tree bindings that need to be corrected first. Driver was tested on a LG Nexus 5 (hammerhead) phone.
Unified · Split
| @@ -666,7 +666,8 @@ static int qpnpint_get_irqchip_state(struct irq_data *d, · 665 unmodified lines | |||
| 666 | return 0; | 666 | return 0; |
| 667 | } | 667 | } |
| 668 | 668 | ||
| 669 | static int qpnpint_irq_request_resources(struct irq_data *d) | 669 | static int qpnpint_irq_domain_activate(struct irq_domain *domain, |
| 670 | struct irq_data *d, bool reserve) | ||
| 670 | { | 671 | { |
| 671 | struct spmi_pmic_arb *pmic_arb = irq_data_get_irq_chip_data(d); | 672 | struct spmi_pmic_arb *pmic_arb = irq_data_get_irq_chip_data(d); |
| 672 | u16 periph = hwirq_to_per(d->hwirq); | 673 | u16 periph = hwirq_to_per(d->hwirq); |
| @@ -692,27 +693,25 @@ static struct irq_chip pmic_arb_irqchip = { · 19 unmodified lines | |||
| 692 | .irq_set_type = qpnpint_irq_set_type, | 693 | .irq_set_type = qpnpint_irq_set_type, |
| 693 | .irq_set_wake = qpnpint_irq_set_wake, | 694 | .irq_set_wake = qpnpint_irq_set_wake, |
| 694 | .irq_get_irqchip_state = qpnpint_get_irqchip_state, | 695 | .irq_get_irqchip_state = qpnpint_get_irqchip_state, |
| 695 | .irq_request_resources = qpnpint_irq_request_resources, | ||
| 696 | .flags = IRQCHIP_MASK_ON_SUSPEND, | 696 | .flags = IRQCHIP_MASK_ON_SUSPEND, |
| 697 | }; | 697 | }; |
| 698 | 698 | ||
| 699 | static int qpnpint_irq_domain_dt_translate(struct irq_domain *d, | 699 | static int qpnpint_irq_domain_translate(struct irq_domain *d, |
| 700 | struct device_node *controller, | 700 | struct irq_fwspec *fwspec, |
| 701 | const u32 *intspec, | 701 | unsigned long *out_hwirq, |
| 702 | unsigned int intsize, | 702 | unsigned int *out_type) |
| 703 | unsigned long *out_hwirq, | ||
| 704 | unsigned int *out_type) | ||
| 705 | { | 703 | { |
| 706 | struct spmi_pmic_arb *pmic_arb = d->host_data; | 704 | struct spmi_pmic_arb *pmic_arb = d->host_data; |
| 705 | u32 *intspec = fwspec->param; | ||
| 707 | u16 apid, ppid; | 706 | u16 apid, ppid; |
| 708 | int rc; | 707 | int rc; |
| 709 | 708 | ||
| 710 | dev_dbg(&pmic_arb->spmic->dev, "intspec[0] 0x%1x intspec[1] 0x%02x intspec[2] 0x%02x\n", | 709 | dev_dbg(&pmic_arb->spmic->dev, "intspec[0] 0x%1x intspec[1] 0x%02x intspec[2] 0x%02x\n", |
| 711 | intspec[0], intspec[1], intspec[2]); | 710 | intspec[0], intspec[1], intspec[2]); |
| 712 | 711 | ||
| 713 | if (irq_domain_get_of_node(d) != controller) | 712 | if (irq_domain_get_of_node(d) != pmic_arb->spmic->dev.of_node) |
| 714 | return -EINVAL; | 713 | return -EINVAL; |
| 715 | if (intsize != 4) | 714 | if (fwspec->param_count != 4) |
| 716 | return -EINVAL; | 715 | return -EINVAL; |
| 717 | if (intspec[0] > 0xF || intspec[1] > 0xFF || intspec[2] > 0x7) | 716 | if (intspec[0] > 0xF || intspec[1] > 0xFF || intspec[2] > 0x7) |
| 718 | return -EINVAL; | 717 | return -EINVAL; |
| @@ -740,17 +739,43 @@ static int qpnpint_irq_domain_dt_translate(struct irq_domain *d, · 21 unmodified lines | |||
| 740 | return 0; | 739 | return 0; |
| 741 | } | 740 | } |
| 742 | 741 | ||
| 743 | static int qpnpint_irq_domain_map(struct irq_domain *d, | 742 | |
| 744 | unsigned int virq, | 743 | static void qpnpint_irq_domain_map(struct spmi_pmic_arb *pmic_arb, |
| 745 | irq_hw_number_t hwirq) | 744 | struct irq_domain *domain, unsigned int virq, |
| 745 | irq_hw_number_t hwirq, unsigned int type) | ||
| 746 | { | 746 | { |
| 747 | struct spmi_pmic_arb *pmic_arb = d->host_data; | 747 | irq_flow_handler_t handler; |
| 748 | |||
| 749 | dev_dbg(&pmic_arb->spmic->dev, "virq = %u, hwirq = %lu, type = %u\n", | ||
| 750 | virq, hwirq, type); | ||
| 751 | |||
| 752 | if (type & IRQ_TYPE_EDGE_BOTH) | ||
| 753 | handler = handle_edge_irq; | ||
| 754 | else | ||
| 755 | handler = handle_level_irq; | ||
| 756 | |||
| 757 | irq_domain_set_info(domain, virq, hwirq, &pmic_arb_irqchip, pmic_arb, | ||
| 758 | handler, NULL, NULL); | ||
| 759 | } | ||
| 760 | |||
| 761 | static int qpnpint_irq_domain_alloc(struct irq_domain *domain, | ||
| 762 | unsigned int virq, unsigned int nr_irqs, | ||
| 763 | void *data) | ||
| 764 | { | ||
| 765 | struct spmi_pmic_arb *pmic_arb = domain->host_data; | ||
| 766 | struct irq_fwspec *fwspec = data; | ||
| 767 | irq_hw_number_t hwirq; | ||
| 768 | unsigned int type; | ||
| 769 | int ret, i; | ||
| 770 | |||
| 771 | ret = qpnpint_irq_domain_translate(domain, fwspec, &hwirq, &type); | ||
| 772 | if (ret) | ||
| 773 | return ret; | ||
| 748 | 774 | ||
| 749 | dev_dbg(&pmic_arb->spmic->dev, "virq = %u, hwirq = %lu\n", virq, hwirq); | 775 | for (i = 0; i < nr_irqs; i++) |
| 776 | qpnpint_irq_domain_map(pmic_arb, domain, virq + i, hwirq + i, | ||
| 777 | type); | ||
| 750 | 778 | ||
| 751 | irq_set_chip_and_handler(virq, &pmic_arb_irqchip, handle_level_irq); | ||
| 752 | irq_set_chip_data(virq, d->host_data); | ||
| 753 | irq_set_noprobe(virq); | ||
| 754 | return 0; | 779 | return 0; |
| 755 | } | 780 | } |
| 756 | 781 | ||
| @@ -1126,8 +1151,10 @@ static const struct pmic_arb_ver_ops pmic_arb_v5 = { · 369 unmodified lines | |||
| 1126 | }; | 1151 | }; |
| 1127 | 1152 | ||
| 1128 | static const struct irq_domain_ops pmic_arb_irq_domain_ops = { | 1153 | static const struct irq_domain_ops pmic_arb_irq_domain_ops = { |
| 1129 | .map = qpnpint_irq_domain_map, | 1154 | .activate = qpnpint_irq_domain_activate, |
| 1130 | .xlate = qpnpint_irq_domain_dt_translate, | 1155 | .alloc = qpnpint_irq_domain_alloc, |
| 1156 | .free = irq_domain_free_irqs_common, | ||
| 1157 | .translate = qpnpint_irq_domain_translate, | ||
| 1131 | }; | 1158 | }; |
| 1132 | 1159 | ||
| 1133 | static int spmi_pmic_arb_probe(struct platform_device *pdev) | 1160 | static int spmi_pmic_arb_probe(struct platform_device *pdev) |