Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | |
| 3 | /* |
| 4 | * linux/arch/m68knommu/platform/527x/config.c |
| 5 | * |
| 6 | * Sub-architcture dependant initialization code for the Freescale |
| 7 | * 5270/5271 CPUs. |
| 8 | * |
| 9 | * Copyright (C) 1999-2004, Greg Ungerer (gerg@snapgear.com) |
| 10 | * Copyright (C) 2001-2004, SnapGear Inc. (www.snapgear.com) |
| 11 | */ |
| 12 | |
| 13 | /***************************************************************************/ |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/param.h> |
| 17 | #include <linux/init.h> |
Greg Ungerer | e206da0 | 2008-02-01 17:34:40 +1000 | [diff] [blame] | 18 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/machdep.h> |
| 20 | #include <asm/coldfire.h> |
| 21 | #include <asm/mcfsim.h> |
Greg Ungerer | e206da0 | 2008-02-01 17:34:40 +1000 | [diff] [blame] | 22 | #include <asm/mcfuart.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | /***************************************************************************/ |
| 25 | |
Greg Ungerer | e206da0 | 2008-02-01 17:34:40 +1000 | [diff] [blame] | 26 | static struct mcf_platform_uart m527x_uart_platform[] = { |
| 27 | { |
| 28 | .mapbase = MCF_MBAR + MCFUART_BASE1, |
| 29 | .irq = MCFINT_VECBASE + MCFINT_UART0, |
| 30 | }, |
| 31 | { |
| 32 | .mapbase = MCF_MBAR + MCFUART_BASE2, |
| 33 | .irq = MCFINT_VECBASE + MCFINT_UART1, |
| 34 | }, |
| 35 | { |
| 36 | .mapbase = MCF_MBAR + MCFUART_BASE3, |
| 37 | .irq = MCFINT_VECBASE + MCFINT_UART2, |
| 38 | }, |
| 39 | { }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Greg Ungerer | e206da0 | 2008-02-01 17:34:40 +1000 | [diff] [blame] | 42 | static struct platform_device m527x_uart = { |
| 43 | .name = "mcfuart", |
| 44 | .id = 0, |
| 45 | .dev.platform_data = m527x_uart_platform, |
| 46 | }; |
| 47 | |
Greg Ungerer | ffba3f4 | 2009-02-26 22:40:38 -0800 | [diff] [blame] | 48 | static struct resource m527x_fec0_resources[] = { |
| 49 | { |
| 50 | .start = MCF_MBAR + 0x1000, |
| 51 | .end = MCF_MBAR + 0x1000 + 0x7ff, |
| 52 | .flags = IORESOURCE_MEM, |
| 53 | }, |
| 54 | { |
| 55 | .start = 64 + 23, |
| 56 | .end = 64 + 23, |
| 57 | .flags = IORESOURCE_IRQ, |
| 58 | }, |
| 59 | { |
| 60 | .start = 64 + 27, |
| 61 | .end = 64 + 27, |
| 62 | .flags = IORESOURCE_IRQ, |
| 63 | }, |
| 64 | { |
| 65 | .start = 64 + 29, |
| 66 | .end = 64 + 29, |
| 67 | .flags = IORESOURCE_IRQ, |
| 68 | }, |
| 69 | }; |
| 70 | |
| 71 | static struct resource m527x_fec1_resources[] = { |
| 72 | { |
| 73 | .start = MCF_MBAR + 0x1800, |
| 74 | .end = MCF_MBAR + 0x1800 + 0x7ff, |
| 75 | .flags = IORESOURCE_MEM, |
| 76 | }, |
| 77 | { |
| 78 | .start = 128 + 23, |
| 79 | .end = 128 + 23, |
| 80 | .flags = IORESOURCE_IRQ, |
| 81 | }, |
| 82 | { |
| 83 | .start = 128 + 27, |
| 84 | .end = 128 + 27, |
| 85 | .flags = IORESOURCE_IRQ, |
| 86 | }, |
| 87 | { |
| 88 | .start = 128 + 29, |
| 89 | .end = 128 + 29, |
| 90 | .flags = IORESOURCE_IRQ, |
| 91 | }, |
| 92 | }; |
| 93 | |
| 94 | static struct platform_device m527x_fec[] = { |
| 95 | { |
| 96 | .name = "fec", |
| 97 | .id = 0, |
| 98 | .num_resources = ARRAY_SIZE(m527x_fec0_resources), |
| 99 | .resource = m527x_fec0_resources, |
| 100 | }, |
| 101 | { |
| 102 | .name = "fec", |
| 103 | .id = 1, |
| 104 | .num_resources = ARRAY_SIZE(m527x_fec1_resources), |
| 105 | .resource = m527x_fec1_resources, |
| 106 | }, |
| 107 | }; |
| 108 | |
Greg Ungerer | e206da0 | 2008-02-01 17:34:40 +1000 | [diff] [blame] | 109 | static struct platform_device *m527x_devices[] __initdata = { |
| 110 | &m527x_uart, |
Greg Ungerer | ffba3f4 | 2009-02-26 22:40:38 -0800 | [diff] [blame] | 111 | &m527x_fec[0], |
| 112 | #ifdef CONFIG_FEC2 |
| 113 | &m527x_fec[1], |
| 114 | #endif |
Greg Ungerer | e206da0 | 2008-02-01 17:34:40 +1000 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | /***************************************************************************/ |
| 118 | |
| 119 | #define INTC0 (MCF_MBAR + MCFICM_INTC0) |
| 120 | |
| 121 | static void __init m527x_uart_init_line(int line, int irq) |
| 122 | { |
| 123 | u16 sepmask; |
| 124 | u32 imr; |
| 125 | |
| 126 | if ((line < 0) || (line > 2)) |
| 127 | return; |
| 128 | |
| 129 | /* level 6, line based priority */ |
| 130 | writeb(0x30+line, INTC0 + MCFINTC_ICR0 + MCFINT_UART0 + line); |
| 131 | |
| 132 | imr = readl(INTC0 + MCFINTC_IMRL); |
| 133 | imr &= ~((1 << (irq - MCFINT_VECBASE)) | 1); |
| 134 | writel(imr, INTC0 + MCFINTC_IMRL); |
| 135 | |
| 136 | /* |
| 137 | * External Pin Mask Setting & Enable External Pin for Interface |
| 138 | */ |
| 139 | sepmask = readw(MCF_IPSBAR + MCF_GPIO_PAR_UART); |
| 140 | if (line == 0) |
| 141 | sepmask |= UART0_ENABLE_MASK; |
| 142 | else if (line == 1) |
| 143 | sepmask |= UART1_ENABLE_MASK; |
| 144 | else if (line == 2) |
| 145 | sepmask |= UART2_ENABLE_MASK; |
| 146 | writew(sepmask, MCF_IPSBAR + MCF_GPIO_PAR_UART); |
| 147 | } |
| 148 | |
| 149 | static void __init m527x_uarts_init(void) |
| 150 | { |
| 151 | const int nrlines = ARRAY_SIZE(m527x_uart_platform); |
| 152 | int line; |
| 153 | |
| 154 | for (line = 0; (line < nrlines); line++) |
| 155 | m527x_uart_init_line(line, m527x_uart_platform[line].irq); |
| 156 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | /***************************************************************************/ |
| 159 | |
Greg Ungerer | ffba3f4 | 2009-02-26 22:40:38 -0800 | [diff] [blame] | 160 | static void __init m527x_fec_irq_init(int nr) |
| 161 | { |
| 162 | unsigned long base; |
| 163 | u32 imr; |
| 164 | |
| 165 | base = MCF_IPSBAR + (nr ? MCFICM_INTC1 : MCFICM_INTC0); |
| 166 | |
| 167 | writeb(0x28, base + MCFINTC_ICR0 + 23); |
| 168 | writeb(0x27, base + MCFINTC_ICR0 + 27); |
| 169 | writeb(0x26, base + MCFINTC_ICR0 + 29); |
| 170 | |
| 171 | imr = readl(base + MCFINTC_IMRH); |
| 172 | imr &= ~0xf; |
| 173 | writel(imr, base + MCFINTC_IMRH); |
| 174 | imr = readl(base + MCFINTC_IMRL); |
| 175 | imr &= ~0xff800001; |
| 176 | writel(imr, base + MCFINTC_IMRL); |
| 177 | } |
| 178 | |
| 179 | static void __init m527x_fec_init(void) |
| 180 | { |
| 181 | u16 par; |
| 182 | u8 v; |
| 183 | |
| 184 | m527x_fec_irq_init(0); |
| 185 | |
| 186 | /* Set multi-function pins to ethernet mode for fec0 */ |
Richard Retanubun | 592578a | 2009-04-08 11:51:27 +1000 | [diff] [blame] | 187 | #if defined(CONFIG_M5271) |
| 188 | v = readb(MCF_IPSBAR + 0x100047); |
| 189 | writeb(v | 0xf0, MCF_IPSBAR + 0x100047); |
| 190 | #else |
Greg Ungerer | ffba3f4 | 2009-02-26 22:40:38 -0800 | [diff] [blame] | 191 | par = readw(MCF_IPSBAR + 0x100082); |
| 192 | writew(par | 0xf00, MCF_IPSBAR + 0x100082); |
| 193 | v = readb(MCF_IPSBAR + 0x100078); |
| 194 | writeb(v | 0xc0, MCF_IPSBAR + 0x100078); |
Richard Retanubun | 592578a | 2009-04-08 11:51:27 +1000 | [diff] [blame] | 195 | #endif |
Greg Ungerer | ffba3f4 | 2009-02-26 22:40:38 -0800 | [diff] [blame] | 196 | |
| 197 | #ifdef CONFIG_FEC2 |
| 198 | m527x_fec_irq_init(1); |
| 199 | |
| 200 | /* Set multi-function pins to ethernet mode for fec1 */ |
| 201 | par = readw(MCF_IPSBAR + 0x100082); |
| 202 | writew(par | 0xa0, MCF_IPSBAR + 0x100082); |
| 203 | v = readb(MCF_IPSBAR + 0x100079); |
| 204 | writeb(v | 0xc0, MCF_IPSBAR + 0x100079); |
| 205 | #endif |
| 206 | } |
| 207 | |
| 208 | /***************************************************************************/ |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | void mcf_disableall(void) |
| 211 | { |
| 212 | *((volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRH)) = 0xffffffff; |
| 213 | *((volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRL)) = 0xffffffff; |
| 214 | } |
| 215 | |
| 216 | /***************************************************************************/ |
| 217 | |
| 218 | void mcf_autovector(unsigned int vec) |
| 219 | { |
| 220 | /* Everything is auto-vectored on the 5272 */ |
| 221 | } |
| 222 | |
| 223 | /***************************************************************************/ |
| 224 | |
Greg Ungerer | 4c0b008 | 2009-04-30 23:06:45 +1000 | [diff] [blame^] | 225 | static void m527x_cpu_reset(void) |
| 226 | { |
| 227 | local_irq_disable(); |
| 228 | __raw_writeb(MCF_RCR_SWRESET, MCF_IPSBAR + MCF_RCR); |
| 229 | } |
| 230 | |
| 231 | /***************************************************************************/ |
| 232 | |
Greg Ungerer | e206da0 | 2008-02-01 17:34:40 +1000 | [diff] [blame] | 233 | void __init config_BSP(char *commandp, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { |
| 235 | mcf_disableall(); |
Greg Ungerer | 4c0b008 | 2009-04-30 23:06:45 +1000 | [diff] [blame^] | 236 | mach_reset = m527x_cpu_reset; |
Greg Ungerer | ffba3f4 | 2009-02-26 22:40:38 -0800 | [diff] [blame] | 237 | m527x_uarts_init(); |
| 238 | m527x_fec_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /***************************************************************************/ |
Greg Ungerer | e206da0 | 2008-02-01 17:34:40 +1000 | [diff] [blame] | 242 | |
| 243 | static int __init init_BSP(void) |
| 244 | { |
Greg Ungerer | e206da0 | 2008-02-01 17:34:40 +1000 | [diff] [blame] | 245 | platform_add_devices(m527x_devices, ARRAY_SIZE(m527x_devices)); |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | arch_initcall(init_BSP); |
| 250 | |
| 251 | /***************************************************************************/ |