Yoshinori Sato | 8a76448 | 2015-05-10 02:30:47 +0900 | [diff] [blame] | 1 | /* |
| 2 | * H8/300H interrupt controller driver |
| 3 | * |
| 4 | * Copyright 2015 Yoshinori Sato <ysato@users.sourceforge.jp> |
| 5 | */ |
| 6 | |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/irq.h> |
| 9 | #include <linux/irqchip.h> |
| 10 | #include <linux/of_address.h> |
| 11 | #include <linux/of_irq.h> |
| 12 | #include <asm/io.h> |
| 13 | |
Yoshinori Sato | 8a76448 | 2015-05-10 02:30:47 +0900 | [diff] [blame] | 14 | static const char ipr_bit[] = { |
| 15 | 7, 6, 5, 5, |
| 16 | 4, 4, 4, 4, 3, 3, 3, 3, |
| 17 | 2, 2, 2, 2, 1, 1, 1, 1, |
| 18 | 0, 0, 0, 0, 15, 15, 15, 15, |
| 19 | 14, 14, 14, 14, 13, 13, 13, 13, |
| 20 | -1, -1, -1, -1, 11, 11, 11, 11, |
| 21 | 10, 10, 10, 10, 9, 9, 9, 9, |
| 22 | }; |
| 23 | |
| 24 | static void *intc_baseaddr; |
| 25 | |
| 26 | #define IPR ((unsigned long)intc_baseaddr + 6) |
| 27 | |
| 28 | static void h8300h_disable_irq(struct irq_data *data) |
| 29 | { |
| 30 | int bit; |
| 31 | int irq = data->irq - 12; |
| 32 | |
| 33 | bit = ipr_bit[irq]; |
| 34 | if (bit >= 0) { |
| 35 | if (bit < 8) |
| 36 | ctrl_bclr(bit & 7, IPR); |
| 37 | else |
| 38 | ctrl_bclr(bit & 7, (IPR+1)); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | static void h8300h_enable_irq(struct irq_data *data) |
| 43 | { |
| 44 | int bit; |
| 45 | int irq = data->irq - 12; |
| 46 | |
| 47 | bit = ipr_bit[irq]; |
| 48 | if (bit >= 0) { |
| 49 | if (bit < 8) |
| 50 | ctrl_bset(bit & 7, IPR); |
| 51 | else |
| 52 | ctrl_bset(bit & 7, (IPR+1)); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | struct irq_chip h8300h_irq_chip = { |
| 57 | .name = "H8/300H-INTC", |
| 58 | .irq_enable = h8300h_enable_irq, |
| 59 | .irq_disable = h8300h_disable_irq, |
| 60 | }; |
| 61 | |
| 62 | static int irq_map(struct irq_domain *h, unsigned int virq, |
| 63 | irq_hw_number_t hw_irq_num) |
| 64 | { |
| 65 | irq_set_chip_and_handler(virq, &h8300h_irq_chip, handle_simple_irq); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static struct irq_domain_ops irq_ops = { |
| 71 | .map = irq_map, |
| 72 | .xlate = irq_domain_xlate_onecell, |
| 73 | }; |
| 74 | |
| 75 | static int __init h8300h_intc_of_init(struct device_node *intc, |
| 76 | struct device_node *parent) |
| 77 | { |
| 78 | struct irq_domain *domain; |
| 79 | |
| 80 | intc_baseaddr = of_iomap(intc, 0); |
| 81 | BUG_ON(!intc_baseaddr); |
| 82 | |
| 83 | /* All interrupt priority low */ |
| 84 | ctrl_outb(0x00, IPR + 0); |
| 85 | ctrl_outb(0x00, IPR + 1); |
| 86 | |
| 87 | domain = irq_domain_add_linear(intc, NR_IRQS, &irq_ops, NULL); |
| 88 | BUG_ON(!domain); |
| 89 | irq_set_default_host(domain); |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | IRQCHIP_DECLARE(h8300h_intc, "renesas,h8300h-intc", h8300h_intc_of_init); |