Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-mmp/irq-mmp2.c |
| 3 | * |
| 4 | * Generic IRQ handling, GPIO IRQ demultiplexing, etc. |
| 5 | * |
| 6 | * Author: Haojian Zhuang <haojian.zhuang@marvell.com> |
| 7 | * Copyright: Marvell International Ltd. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/irq.h> |
| 16 | #include <linux/io.h> |
| 17 | |
Rob Herring | 8661fb9 | 2012-01-03 16:50:40 -0600 | [diff] [blame] | 18 | #include <mach/irqs.h> |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 19 | #include <mach/regs-icu.h> |
Eric Miao | 2728701 | 2010-07-15 22:22:33 +0800 | [diff] [blame] | 20 | #include <mach/mmp2.h> |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 21 | |
| 22 | #include "common.h" |
| 23 | |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 24 | static void icu_mask_irq(struct irq_data *d) |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 25 | { |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 26 | uint32_t r = __raw_readl(ICU_INT_CONF(d->irq)); |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 27 | |
| 28 | r &= ~ICU_INT_ROUTE_PJ4_IRQ; |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 29 | __raw_writel(r, ICU_INT_CONF(d->irq)); |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 30 | } |
| 31 | |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 32 | static void icu_unmask_irq(struct irq_data *d) |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 33 | { |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 34 | uint32_t r = __raw_readl(ICU_INT_CONF(d->irq)); |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 35 | |
| 36 | r |= ICU_INT_ROUTE_PJ4_IRQ; |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 37 | __raw_writel(r, ICU_INT_CONF(d->irq)); |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static struct irq_chip icu_irq_chip = { |
| 41 | .name = "icu_irq", |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 42 | .irq_mask = icu_mask_irq, |
| 43 | .irq_mask_ack = icu_mask_irq, |
| 44 | .irq_unmask = icu_unmask_irq, |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 45 | }; |
| 46 | |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 47 | static void pmic_irq_ack(struct irq_data *d) |
Haojian Zhuang | df0c382 | 2010-02-03 10:01:18 -0500 | [diff] [blame] | 48 | { |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 49 | if (d->irq == IRQ_MMP2_PMIC) |
Haojian Zhuang | df0c382 | 2010-02-03 10:01:18 -0500 | [diff] [blame] | 50 | mmp2_clear_pmic_int(); |
| 51 | } |
| 52 | |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 53 | #define SECOND_IRQ_MASK(_name_, irq_base, prefix) \ |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 54 | static void _name_##_mask_irq(struct irq_data *d) \ |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 55 | { \ |
| 56 | uint32_t r; \ |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 57 | r = __raw_readl(prefix##_MASK) | (1 << (d->irq - irq_base)); \ |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 58 | __raw_writel(r, prefix##_MASK); \ |
| 59 | } |
| 60 | |
| 61 | #define SECOND_IRQ_UNMASK(_name_, irq_base, prefix) \ |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 62 | static void _name_##_unmask_irq(struct irq_data *d) \ |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 63 | { \ |
| 64 | uint32_t r; \ |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 65 | r = __raw_readl(prefix##_MASK) & ~(1 << (d->irq - irq_base)); \ |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 66 | __raw_writel(r, prefix##_MASK); \ |
| 67 | } |
| 68 | |
| 69 | #define SECOND_IRQ_DEMUX(_name_, irq_base, prefix) \ |
| 70 | static void _name_##_irq_demux(unsigned int irq, struct irq_desc *desc) \ |
| 71 | { \ |
| 72 | unsigned long status, mask, n; \ |
| 73 | mask = __raw_readl(prefix##_MASK); \ |
| 74 | while (1) { \ |
| 75 | status = __raw_readl(prefix##_STATUS) & ~mask; \ |
| 76 | if (status == 0) \ |
| 77 | break; \ |
| 78 | n = find_first_bit(&status, BITS_PER_LONG); \ |
| 79 | while (n < BITS_PER_LONG) { \ |
| 80 | generic_handle_irq(irq_base + n); \ |
| 81 | n = find_next_bit(&status, BITS_PER_LONG, n+1); \ |
| 82 | } \ |
| 83 | } \ |
| 84 | } |
| 85 | |
| 86 | #define SECOND_IRQ_CHIP(_name_, irq_base, prefix) \ |
| 87 | SECOND_IRQ_MASK(_name_, irq_base, prefix) \ |
| 88 | SECOND_IRQ_UNMASK(_name_, irq_base, prefix) \ |
| 89 | SECOND_IRQ_DEMUX(_name_, irq_base, prefix) \ |
| 90 | static struct irq_chip _name_##_irq_chip = { \ |
| 91 | .name = #_name_, \ |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 92 | .irq_mask = _name_##_mask_irq, \ |
| 93 | .irq_unmask = _name_##_unmask_irq, \ |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | SECOND_IRQ_CHIP(pmic, IRQ_MMP2_PMIC_BASE, MMP2_ICU_INT4); |
| 97 | SECOND_IRQ_CHIP(rtc, IRQ_MMP2_RTC_BASE, MMP2_ICU_INT5); |
| 98 | SECOND_IRQ_CHIP(twsi, IRQ_MMP2_TWSI_BASE, MMP2_ICU_INT17); |
| 99 | SECOND_IRQ_CHIP(misc, IRQ_MMP2_MISC_BASE, MMP2_ICU_INT35); |
| 100 | SECOND_IRQ_CHIP(ssp, IRQ_MMP2_SSP_BASE, MMP2_ICU_INT51); |
| 101 | |
| 102 | static void init_mux_irq(struct irq_chip *chip, int start, int num) |
| 103 | { |
| 104 | int irq; |
| 105 | |
| 106 | for (irq = start; num > 0; irq++, num--) { |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 107 | struct irq_data *d = irq_get_irq_data(irq); |
| 108 | |
Eric Miao | 2029e56 | 2010-02-02 23:39:35 -0800 | [diff] [blame] | 109 | /* mask and clear the IRQ */ |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 110 | chip->irq_mask(d); |
| 111 | if (chip->irq_ack) |
| 112 | chip->irq_ack(d); |
Eric Miao | 2029e56 | 2010-02-02 23:39:35 -0800 | [diff] [blame] | 113 | |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 114 | irq_set_chip(irq, chip); |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 115 | set_irq_flags(irq, IRQF_VALID); |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 116 | irq_set_handler(irq, handle_level_irq); |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
Haojian Zhuang | 16144bf | 2010-01-25 06:03:54 -0500 | [diff] [blame] | 120 | void __init mmp2_init_icu(void) |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 121 | { |
| 122 | int irq; |
| 123 | |
| 124 | for (irq = 0; irq < IRQ_MMP2_MUX_BASE; irq++) { |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 125 | icu_mask_irq(irq_get_irq_data(irq)); |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 126 | irq_set_chip(irq, &icu_irq_chip); |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 127 | set_irq_flags(irq, IRQF_VALID); |
| 128 | |
| 129 | switch (irq) { |
| 130 | case IRQ_MMP2_PMIC_MUX: |
| 131 | case IRQ_MMP2_RTC_MUX: |
| 132 | case IRQ_MMP2_TWSI_MUX: |
| 133 | case IRQ_MMP2_MISC_MUX: |
| 134 | case IRQ_MMP2_SSP_MUX: |
| 135 | break; |
| 136 | default: |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 137 | irq_set_handler(irq, handle_level_irq); |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 138 | break; |
| 139 | } |
| 140 | } |
| 141 | |
Haojian Zhuang | df0c382 | 2010-02-03 10:01:18 -0500 | [diff] [blame] | 142 | /* NOTE: IRQ_MMP2_PMIC requires the PMIC MFPR register |
| 143 | * to be written to clear the interrupt |
| 144 | */ |
Lennert Buytenhek | a157f26 | 2010-11-29 10:36:07 +0100 | [diff] [blame] | 145 | pmic_irq_chip.irq_ack = pmic_irq_ack; |
Haojian Zhuang | df0c382 | 2010-02-03 10:01:18 -0500 | [diff] [blame] | 146 | |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 147 | init_mux_irq(&pmic_irq_chip, IRQ_MMP2_PMIC_BASE, 2); |
| 148 | init_mux_irq(&rtc_irq_chip, IRQ_MMP2_RTC_BASE, 2); |
| 149 | init_mux_irq(&twsi_irq_chip, IRQ_MMP2_TWSI_BASE, 5); |
| 150 | init_mux_irq(&misc_irq_chip, IRQ_MMP2_MISC_BASE, 15); |
| 151 | init_mux_irq(&ssp_irq_chip, IRQ_MMP2_SSP_BASE, 2); |
| 152 | |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 153 | irq_set_chained_handler(IRQ_MMP2_PMIC_MUX, pmic_irq_demux); |
| 154 | irq_set_chained_handler(IRQ_MMP2_RTC_MUX, rtc_irq_demux); |
| 155 | irq_set_chained_handler(IRQ_MMP2_TWSI_MUX, twsi_irq_demux); |
| 156 | irq_set_chained_handler(IRQ_MMP2_MISC_MUX, misc_irq_demux); |
| 157 | irq_set_chained_handler(IRQ_MMP2_SSP_MUX, ssp_irq_demux); |
Haojian Zhuang | 2f7e8fa | 2009-12-04 09:41:28 -0500 | [diff] [blame] | 158 | } |