powerpc: Add MPC5200 Interrupt Controller support.
This patch add MPC52xx Interrupt controller for ARCH=powerpc.
It includes the main code in arch/powerpc/sysdev/ ad well as an header file in include/asm-powerpc.
---
arch/powerpc/sysdev/mpc52xx_pic.c +527 -0
@@ -0,0 +1,527 @@ +/* +* +* Programmable Interrupt Controller functions for the Freescale MPC52xx. +* +* Copyright (C) 2006 bplan GmbH +* +* Based on (well, mostly copied from) the code from the 2.4 kernel by +* Dale Farnsworth <[email protected]> and Kent Borg. +* +* Copyright (C) 2004 Sylvain Munaut <[email protected]> +* Copyright (C) 2003 Montavista Software, Inc +* +* This file is licensed under the terms of the GNU General Public License +* version 2. This program is licensed "as is" without any warranty of any +* kind, whether express or implied. +* +*/ + +#undef DEBUG + +#include <linux/stddef.h> +#include <linux/init.h> +#include <linux/sched.h> +#include <linux/signal.h> +#include <linux/stddef.h> +#include <linux/delay.h> +#include <linux/irq.h> +#include <linux/hardirq.h> + +#include <asm/io.h> +#include <asm/processor.h> +#include <asm/system.h> +#include <asm/irq.h> +#include <asm/prom.h> +#include <asm/mpc52xx.h> + +/* +* +*/ + +static struct mpc52xx_intr __iomem *intr; +static struct mpc52xx_sdma __iomem *sdma; +static struct irq_host *mpc52xx_irqhost =NULL ; + +static unsigned char mpc52xx_map_senses[4 ] = { +IRQ_TYPE_LEVEL_HIGH , +IRQ_TYPE_EDGE_RISING , +IRQ_TYPE_EDGE_FALLING , +IRQ_TYPE_LEVEL_LOW , +}; + +/* +* +*/ + +static inline void io_be_setbit (u32 __iomem *addr,int bitno) +{ +out_be32 (addr,in_be32 (addr) | (1 << bitno) ); +} + +static inline void io_be_clrbit (u32 __iomem *addr,int bitno) +{ +out_be32 (addr,in_be32 (addr) & ~(1 << bitno)); +} + +/* +* IRQ[0-3] interrupt irq_chip +*/ + +static void mpc52xx_extirq_mask (unsigned int virq) +{ +int irq; +int l2irq; + + irq = irq_map[virq].hwirq; + l2irq = (irq & MPC52xx_IRQ_L2_MASK) >> MPC52xx_IRQ_L2_OFFSET; + +pr_debug ("%s: irq=%x. l2=%d\n" , __func__, irq, l2irq); + +io_be_clrbit (&intr->ctrl,11 - l2irq); +} + +static void mpc52xx_extirq_unmask (unsigned int virq) +{ +int irq; +int l2irq; + + irq = irq_map[virq].hwirq; + l2irq = (irq & MPC52xx_IRQ_L2_MASK) >> MPC52xx_IRQ_L2_OFFSET; + +pr_debug ("%s: irq=%x. l2=%d\n" , __func__, irq, l2irq); + +io_be_setbit (&intr->ctrl,11 - l2irq); +} + +static void mpc52xx_extirq_ack (unsigned int virq) +{ +int irq; +int l2irq; + + irq = irq_map[virq].hwirq; + l2irq = (irq & MPC52xx_IRQ_L2_MASK) >> MPC52xx_IRQ_L2_OFFSET; + +pr_debug ("%s: irq=%x. l2=%d\n" , __func__, irq, l2irq); + +io_be_setbit (&intr->ctrl,27 -l2irq); +} + +static struct irq_chip mpc52xx_extirq_irqchip = { + .typename =" MPC52xx IRQ[0-3] " , + .mask = mpc52xx_extirq_mask, + .unmask = mpc52xx_extirq_unmask, + .ack = mpc52xx_extirq_ack, +}; + +/* +* Main interrupt irq_chip +*/ + +static void mpc52xx_main_mask (unsigned int virq) +{ +int irq; +int l2irq; + + irq = irq_map[virq].hwirq; + l2irq = (irq & MPC52xx_IRQ_L2_MASK) >> MPC52xx_IRQ_L2_OFFSET; + +pr_debug ("%s: irq=%x. l2=%d\n" , __func__, irq, l2irq); + +io_be_setbit (&intr->main_mask,15 - l2irq); +} + +static void mpc52xx_main_unmask (unsigned int virq) +{ +int irq; +int l2irq; + + irq = irq_map[virq].hwirq; + l2irq = (irq & MPC52xx_IRQ_L2_MASK) >> MPC52xx_IRQ_L2_OFFSET; + +pr_debug ("%s: irq=%x. l2=%d\n" , __func__, irq, l2irq); + +io_be_clrbit (&intr->main_mask,15 - l2irq); +} + +static struct irq_chip mpc52xx_main_irqchip = { + .typename ="MPC52xx Main" , + .mask = mpc52xx_main_mask, + .mask_ack = mpc52xx_main_mask, + .unmask = mpc52xx_main_unmask, +}; + +/* +* Peripherals interrupt irq_chip +*/ + +static void mpc52xx_periph_mask (unsigned int virq) +{ +int irq; +int l2irq; + + irq = irq_map[virq].hwirq; + l2irq = (irq & MPC52xx_IRQ_L2_MASK) >> MPC52xx_IRQ_L2_OFFSET; + +pr_debug ("%s: irq=%x. l2=%d\n" , __func__, irq, l2irq); + +io_be_setbit (&intr->per_mask,31 - l2irq); +} + +static void mpc52xx_periph_unmask (unsigned int virq) +{ +int irq; +int l2irq; + + irq = irq_map[virq].hwirq; + l2irq = (irq & MPC52xx_IRQ_L2_MASK) >> MPC52xx_IRQ_L2_OFFSET; + +pr_debug ("%s: irq=%x. l2=%d\n" , __func__, irq, l2irq); + +io_be_clrbit (&intr->per_mask,31 - l2irq); +} + +static struct irq_chip mpc52xx_periph_irqchip = { + .typename ="MPC52xx Peripherals" , + .mask = mpc52xx_periph_mask, + .mask_ack = mpc52xx_periph_mask, + .unmask = mpc52xx_periph_unmask, +}; + +/* +* SDMA interrupt irq_chip +*/ + +static void mpc52xx_sdma_mask (unsigned int virq) +{ +int irq; +int l2irq; + + irq = irq_map[virq].hwirq; + l2irq = (irq & MPC52xx_IRQ_L2_MASK) >> MPC52xx_IRQ_L2_OFFSET; + +pr_debug ("%s: irq=%x. l2=%d\n" , __func__, irq, l2irq); + +io_be_setbit (&sdma->IntMask, l2irq); +} + +static void mpc52xx_sdma_unmask (unsigned int virq) +{ +int irq; +int l2irq; + + irq = irq_map[virq].hwirq; + l2irq = (irq & MPC52xx_IRQ_L2_MASK) >> MPC52xx_IRQ_L2_OFFSET; + +pr_debug ("%s: irq=%x. l2=%d\n" , __func__, irq, l2irq); + +io_be_clrbit (&sdma->IntMask, l2irq); +} + +static void mpc52xx_sdma_ack (unsigned int virq) +{ +int irq; +int l2irq; + + irq = irq_map[virq].hwirq; + l2irq = (irq & MPC52xx_IRQ_L2_MASK) >> MPC52xx_IRQ_L2_OFFSET; + +pr_debug ("%s: irq=%x. l2=%d\n" , __func__, irq, l2irq); + +out_be32 (&sdma->IntPend,1 << l2irq); +} + +static struct irq_chip mpc52xx_sdma_irqchip = { + .typename ="MPC52xx SDMA" , + .mask = mpc52xx_sdma_mask, + .unmask = mpc52xx_sdma_unmask, + .ack = mpc52xx_sdma_ack, +}; + +/* +* irq_host +*/ + +static int mpc52xx_irqhost_match (struct irq_host *h,struct device_node *node) +{ +pr_debug ("%s: node=%p\n" , __func__, node); +return mpc52xx_irqhost->host_data == node; +} + +static int mpc52xx_irqhost_xlate (struct irq_host *h,struct device_node *ct, +u32 * intspec,unsigned int intsize, +irq_hw_number_t * out_hwirq, +unsigned int *out_flags) +{ +int intrvect_l1; +int intrvect_l2; +int intrvect_type; +int intrvect_linux; + +if (intsize !=3 ) +return -1 ; + + intrvect_l1 = (int )intspec[0 ]; + intrvect_l2 = (int )intspec[1 ]; + intrvect_type = (int )intspec[2 ]; + + intrvect_linux = + (intrvect_l1 << MPC52xx_IRQ_L1_OFFSET) & MPC52xx_IRQ_L1_MASK; + intrvect_linux |= + (intrvect_l2 << MPC52xx_IRQ_L2_OFFSET) & MPC52xx_IRQ_L2_MASK; + +pr_debug ("return %x, l1=%d, l2=%d\n" , intrvect_linux, intrvect_l1, + intrvect_l2); + + *out_hwirq = intrvect_linux; + *out_flags = mpc52xx_map_senses[intrvect_type]; + +return 0 ; +} + +/* +* this function retrieves the correct IRQ type out +* of the MPC regs +* Only externals IRQs needs this +*/ +static int mpc52xx_irqx_gettype (int irq) +{ +int type; +u32 ctrl_reg; + + ctrl_reg =in_be32 (&intr->ctrl); + type = (ctrl_reg >> (22 - irq *2 )) &0x3 ; + +return mpc52xx_map_senses[type]; +} + +static int mpc52xx_irqhost_map (struct irq_host *h,unsigned int virq, +irq_hw_number_t irq) +{ +int l1irq; +int l2irq; +struct irq_chip *good_irqchip; +void *good_handle; +int type; + + l1irq = (irq & MPC52xx_IRQ_L1_MASK) >> MPC52xx_IRQ_L1_OFFSET; + l2irq = (irq & MPC52xx_IRQ_L2_MASK) >> MPC52xx_IRQ_L2_OFFSET; + +/* +* Most of ours IRQs will be level low +* Only external IRQs on some platform may be others +*/ + type =IRQ_TYPE_LEVEL_LOW ; + +switch (l1irq) { +case MPC52xx_IRQ_L1_CRIT: +pr_debug ("%s: Critical. l2=%x\n" , __func__, l2irq); + +BUG_ON (l2irq !=0 ); + + type =mpc52xx_irqx_gettype (l2irq); + good_irqchip = &mpc52xx_extirq_irqchip; +break ; + +case MPC52xx_IRQ_L1_MAIN: +pr_debug ("%s: Main IRQ[1-3] l2=%x\n" , __func__, l2irq); + +if ((l2irq >=1 ) && (l2irq <=3 )) { + type =mpc52xx_irqx_gettype (l2irq); + good_irqchip = &mpc52xx_extirq_irqchip; + }else { + good_irqchip = &mpc52xx_main_irqchip; + } +break ; + +case MPC52xx_IRQ_L1_PERP: +pr_debug ("%s: Peripherals. l2=%x\n" , __func__, l2irq); + good_irqchip = &mpc52xx_periph_irqchip; +break ; + +case MPC52xx_IRQ_L1_SDMA: +pr_debug ("%s: SDMA. l2=%x\n" , __func__, l2irq); + good_irqchip = &mpc52xx_sdma_irqchip; +break ; + +default : +pr_debug ("%s: Error, unknown L1 IRQ (0x%x)\n" , __func__, l1irq); +printk (KERN_ERR "Unknow IRQ!\n" ); +return -EINVAL ; + } + +switch (type) { +case IRQ_TYPE_EDGE_FALLING : +case IRQ_TYPE_EDGE_RISING : + good_handle = handle_edge_irq; +break ; +default : + good_handle = handle_level_irq; + } + +set_irq_chip_and_handler (virq, good_irqchip, good_handle); + +pr_debug ("%s: virq=%x, hw=%x. type=%x\n" , __func__, virq, + (int )irq, type); + +return 0 ; +} + +static struct irq_host_ops mpc52xx_irqhost_ops = { + .match = mpc52xx_irqhost_match, + .xlate = mpc52xx_irqhost_xlate, + .map = mpc52xx_irqhost_map, +}; + +/* +* init (public) +*/ + +void __init mpc52xx_init_irq (void ) +{ +struct device_node *picnode =NULL ; +int picnode_regsize; +u32 picnode_regoffset; + +struct device_node *sdmanode =NULL ; +int sdmanode_regsize; +u32 sdmanode_regoffset; + +u64 size64; +int flags; + +u32 intr_ctrl; + + picnode =of_find_compatible_node (NULL ,"interrupt-controller" ,"mpc5200-pic" ); +if (picnode ==NULL ) { +printk (KERN_ERR "MPC52xx PIC: Unable to find the interrupt controller in the OpenFirmware device tree\n" ); + goto end; + } + + sdmanode =of_find_compatible_node (NULL ,"dma-controller" ,"mpc5200-bestcomm" ); +if (sdmanode ==NULL ) { +printk (KERN_ERR "MPC52xx PIC: Unable to find the Bestcomm DMA controller device in the OpenFirmware device tree\n" ); + goto end; + } + +/* Retrieve PIC ressources */ + picnode_regoffset = (u32 )of_get_address (picnode,0 , &size64, &flags); +if (picnode_regoffset ==0 ) { +printk (KERN_ERR "MPC52xx PIC: Unable to get the interrupt controller address\n" ); + goto end; + } + + picnode_regoffset =of_translate_address (picnode, (u32 *) picnode_regoffset); + picnode_regsize = (int ) size64; + +/* Retrieve SDMA ressources */ + sdmanode_regoffset = (u32 )of_get_address (sdmanode,0 , &size64, &flags); +if (sdmanode_regoffset ==0 ) { +printk (KERN_ERR "MPC52xx PIC: Unable to get the Bestcomm DMA controller address\n" ); + goto end; + } + + sdmanode_regoffset =of_translate_address (sdmanode, (u32 *) sdmanode_regoffset); + sdmanode_regsize = (int ) size64; + +/* Remap the necessary zones */ + intr =ioremap (picnode_regoffset, picnode_regsize); +if (intr ==NULL ) { +printk (KERN_ERR "MPC52xx PIC: Unable to ioremap interrupt controller registers!" ); + goto end; + } + + sdma =ioremap (sdmanode_regoffset, sdmanode_regsize); +if (sdma ==NULL ) { +iounmap (intr); +printk (KERN_ERR "MPC52xx PIC: Unable to ioremap Bestcomm DMA controller registers!" ); + goto end; + } + +printk (KERN_INFO "MPC52xx PIC: MPC52xx PIC Remapped at 0x%8.8x\n" , picnode_regoffset); +printk (KERN_INFO "MPC52xx PIC: MPC52xx SDMA Remapped at 0x%8.8x\n" , sdmanode_regoffset); + +/* Disable all interrupt sources. */ +out_be32 (&sdma->IntPend,0xffffffff );/* 1 means clear pending */ +out_be32 (&sdma->IntMask,0xffffffff );/* 1 means disabled */ +out_be32 (&intr->per_mask,0x7ffffc00 );/* 1 means disabled */ +out_be32 (&intr->main_mask,0x00010fff );/* 1 means disabled */ + intr_ctrl =in_be32 (&intr->ctrl); + intr_ctrl &=0x00ff0000 ;/* Keeps IRQ[0-3] config */ + intr_ctrl |=0x0f000000 |/* clear IRQ 0-3 */ +0x00001000 |/* MEE master external enable */ +0x00000000 |/* 0 means disable IRQ 0-3 */ +0x00000001 ;/* CEb route critical normally */ +out_be32 (&intr->ctrl, intr_ctrl); + +/* Zero a bunch of the priority settings. */ +out_be32 (&intr->per_pri1,0 ); +out_be32 (&intr->per_pri2,0 ); +out_be32 (&intr->per_pri3,0 ); +out_be32 (&intr->main_pri1,0 ); +out_be32 (&intr->main_pri2,0 ); + +/* +* As last step, add an irq host to translate the real +* hw irq information provided by the ofw to linux virq +*/ + + mpc52xx_irqhost = +irq_alloc_host (IRQ_HOST_MAP_LINEAR , MPC52xx_IRQ_HIGHTESTHWIRQ, + &mpc52xx_irqhost_ops,-1 ); + +if (mpc52xx_irqhost) { + mpc52xx_irqhost->host_data = picnode; +printk (KERN_INFO "MPC52xx PIC is up and running!\n" ); + }else { +printk (KERN_ERR "MPC52xx PIC: Unable to allocate the IRQ host\n" ); + } + +end: +of_node_put (picnode); +of_node_put (sdmanode); +} + +/* +* get_irq (public) +*/ +unsigned int mpc52xx_get_irq (void ) +{ +u32 status; +int irq =NO_IRQ_IGNORE ; + + status =in_be32 (&intr->enc_status); +if (status &0x00000400 ) {/* critical */ + irq = (status >>8 ) &0x3 ; +if (irq ==2 )/* high priority peripheral */ + goto peripheral; + irq |= + (MPC52xx_IRQ_L1_CRIT << MPC52xx_IRQ_L1_OFFSET) & + MPC52xx_IRQ_L1_MASK; + }else if (status &0x00200000 ) {/* main */ + irq = (status >>16 ) &0x1f ; +if (irq ==4 )/* low priority peripheral */ + goto peripheral; + irq |= + (MPC52xx_IRQ_L1_MAIN << MPC52xx_IRQ_L1_OFFSET) & + MPC52xx_IRQ_L1_MASK; + }else if (status &0x20000000 ) {/* peripheral */ + peripheral: + irq = (status >>24 ) &0x1f ; +if (irq ==0 ) {/* bestcomm */ + status =in_be32 (&sdma->IntPend); + irq =ffs (status) -1 ; + irq |= + (MPC52xx_IRQ_L1_SDMA << MPC52xx_IRQ_L1_OFFSET) & + MPC52xx_IRQ_L1_MASK; + }else + irq |= + (MPC52xx_IRQ_L1_PERP << MPC52xx_IRQ_L1_OFFSET) & + MPC52xx_IRQ_L1_MASK; + + } + +pr_debug ("%s: irq=%x. virq=%d\n" , __func__, irq, +irq_linear_revmap (mpc52xx_irqhost, irq)); + +return irq_linear_revmap (mpc52xx_irqhost, irq); +}
arch/powerpc/sysdev/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_FSL_SOC) += fsl_soc.o obj-$(CONFIG_PPC_TODC) += todc.o obj-$(CONFIG_TSI108_BRIDGE) += tsi108_pci.o tsi108_dev.o obj-$(CONFIG_QUICC_ENGINE) += qe_lib/ +obj-$(CONFIG_PPC_MPC52xx) += mpc52xx_pic.o ifeq ($(CONFIG_PPC_MERGE),y) obj-$(CONFIG_PPC_I8259) += i8259.o
include/asm-powerpc/mpc52xx.h +283 -0
283 lines not on this page · raw message
arch/powerpc/sysdev/mpc52xx_pic.c line 313
Quoted 8 lines
arch/powerpc/sysdev/mpc52xx_pic.c +6
-0+ +/* +* Most of ours IRQs will be level low +* Only external IRQs on some platform may be others +*/ + type =IRQ_TYPE_LEVEL_LOW ;
I've been wondering : Why LEVEL_LOW ?
Aren't they LEVEL_HIGH ?
(not that it changes much here ...)
arch/powerpc/sysdev/mpc52xx_pic.c line 481
Quoted 5 lines
arch/powerpc/sysdev/mpc52xx_pic.c +4
-0+ +end: +of_node_put (picnode); +of_node_put (sdmanode);
Is of_node_put specified as resilient to NULL argument ? (in the error path, that could happen)
Also, I think "PANIC" would be appropriate in the error path. If we can't init
the PIC properly we may as well give up ... It's not like we're going to do much
without it ...
Quoted 23 lines
include/asm-powerpc/mpc52xx.h +22
-0+/* HW IRQ mapping */ +#define MPC52xx_IRQ_L1_CRIT (0) +#define MPC52xx_IRQ_L1_MAIN (1) +#define MPC52xx_IRQ_L1_PERP (2) +#define MPC52xx_IRQ_L1_SDMA (3) + +#define MPC52xx_IRQ_L1_OFFSET (6) +#define MPC52xx_IRQ_L1_MASK (0xc0) + +#define MPC52xx_IRQ_L2_OFFSET (0) +#define MPC52xx_IRQ_L2_MASK (0x3f) + +#define MPC52xx_IRQ_HIGHTESTHWIRQ (0xd0) + +/* Interrupt controller Register set */ +struct mpc52xx_intr { +u32 per_mask;/* INTR + 0x00 */ +u32 per_pri1;/* INTR + 0x04 */ +u32 per_pri2;/* INTR + 0x08 */ +u32 per_pri3;/* INTR + 0x0c */ +u32 ctrl;/* INTR + 0x10 */ +u32 main_mask;/* INTR + 0x14 */
include/asm-powerpc/mpc52xx.h line 52
Quoted 10 lines
include/asm-powerpc/mpc52xx.h +10
-0+u32 main_pri1;/* INTR + 0x18 */ +u32 main_pri2;/* INTR + 0x1c */ +u32 reserved1;/* INTR + 0x20 */ +u32 enc_status;/* INTR + 0x24 */ +u32 crit_status;/* INTR + 0x28 */ +u32 main_status;/* INTR + 0x2c */ +u32 per_status;/* INTR + 0x30 */ +u32 reserved2;/* INTR + 0x34 */ +u32 per_error;/* INTR + 0x38 */ +};
When I said on IRC you could remerge them, I meant a little more smartly than just 'join' them. i.e., put the mpc52xx_intr with all the other register set at the very least ...
Sylvain
Quoted 11 lines · Sylvain Munaut
arch/powerpc/sysdev/mpc52xx_pic.c line 313
Quoted 7 lines
arch/powerpc/sysdev/mpc52xx_pic.c +6
-0+ +/* +* Most of ours IRQs will be level low +* Only external IRQs on some platform may be others +*/ + type =IRQ_TYPE_LEVEL_LOW ;I've been wondering : Why
LEVEL_LOW?
Aren't theyLEVEL_HIGH?
(not that it changes much here ...)
It makes only sense for the ext interrupts and not for the internal peripherals.
I made everything level low because it's quiet common (for example: PCI). Moreover, On our hardware (Efika) the IRQ[0-3] are dedicated to the PCI.
Anyway, as the current code looks inside the chipset register to retrieve the real settings, the 'type' vaiiable will be overwrite if require.
In my opinion, others platforms (without proper hw init by the firmware) may overwrite the external interrupt control reg in their platforms specific part.
Quoted 7 lines
arch/powerpc/sysdev/mpc52xx_pic.c line 481
Quoted 5 lines
arch/powerpc/sysdev/mpc52xx_pic.c +4
-0+ +end: +of_node_put (picnode); +of_node_put (sdmanode);Is
of_node_putspecified as resilient to NULL argument ? (in the error path, that could happen)
of_node_put() is said to be NULL pointer safe.
Quoted 7 lines
Also, I think "PANIC" would be appropriate in the error path. If we can't init
the PIC properly we may as well give up ... It's not like we're going to do much
without it ...
Well, panic or not your board won't do much ;-) Moreover, the serial console should work a bit without interrupt.
On another hand, init_IRQ may return a value to indicate it succeed or not. but, this is beyound the scope of this patch.
Regards,
begin:vcard
fn:Nicolas DET ( bplan GmbH )
n:DET;Nicolas
org:bplan GmbH
adr:;;;;;;Germany
email;internet:[email protected]
title:Software Entwicklung
tel;work:+49 6171 9187 - 31
x-mozilla-html:FALSE
url:http://www.bplan-gmbh.de
version:2.1
end:vcard