Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 1 | /* |
| 2 | * arch/sh/boards/renesas/r7780rp/setup.c |
| 3 | * |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 4 | * Renesas Solutions Highlander Support. |
| 5 | * |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 6 | * Copyright (C) 2002 Atom Create Engineering Co., Ltd. |
Paul Mundt | 71074d3 | 2007-02-14 14:49:04 +0900 | [diff] [blame] | 7 | * Copyright (C) 2005 - 2007 Paul Mundt |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 8 | * |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 9 | * This contains support for the R7780RP-1, R7780MP, and R7785RP |
| 10 | * Highlander modules. |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 11 | * |
| 12 | * This file is subject to the terms and conditions of the GNU General Public |
| 13 | * License. See the file "COPYING" in the main directory of this archive |
| 14 | * for more details. |
| 15 | */ |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/platform_device.h> |
Paul Mundt | 71074d3 | 2007-02-14 14:49:04 +0900 | [diff] [blame] | 18 | #include <linux/pata_platform.h> |
Paul Mundt | b5751e2 | 2007-11-02 14:17:19 +0900 | [diff] [blame^] | 19 | #include <linux/types.h> |
Magnus Damm | c6f93a3 | 2007-10-15 10:36:45 +0900 | [diff] [blame] | 20 | #include <net/ax88796.h> |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 21 | #include <asm/machvec.h> |
Paul Mundt | 082c44d | 2006-10-19 16:16:18 +0900 | [diff] [blame] | 22 | #include <asm/r7780rp.h> |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 23 | #include <asm/clock.h> |
Paul Mundt | 8786c95 | 2007-08-20 13:03:41 +0900 | [diff] [blame] | 24 | #include <asm/heartbeat.h> |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 25 | #include <asm/io.h> |
| 26 | |
Yoshihiro Shimoda | e6c972f | 2007-07-17 13:38:54 +0900 | [diff] [blame] | 27 | static struct resource r8a66597_usb_host_resources[] = { |
| 28 | [0] = { |
| 29 | .name = "r8a66597_hcd", |
| 30 | .start = 0xA4200000, |
| 31 | .end = 0xA42000FF, |
| 32 | .flags = IORESOURCE_MEM, |
| 33 | }, |
| 34 | [1] = { |
| 35 | .name = "r8a66597_hcd", |
Magnus Damm | 897cfcd8 | 2007-09-10 12:06:03 +0900 | [diff] [blame] | 36 | .start = IRQ_EXT1, /* irq number */ |
| 37 | .end = IRQ_EXT1, |
Yoshihiro Shimoda | e6c972f | 2007-07-17 13:38:54 +0900 | [diff] [blame] | 38 | .flags = IORESOURCE_IRQ, |
| 39 | }, |
| 40 | }; |
| 41 | |
| 42 | static struct platform_device r8a66597_usb_host_device = { |
| 43 | .name = "r8a66597_hcd", |
| 44 | .id = -1, |
| 45 | .dev = { |
| 46 | .dma_mask = NULL, /* don't use dma */ |
| 47 | .coherent_dma_mask = 0xffffffff, |
| 48 | }, |
| 49 | .num_resources = ARRAY_SIZE(r8a66597_usb_host_resources), |
| 50 | .resource = r8a66597_usb_host_resources, |
| 51 | }; |
| 52 | |
| 53 | static struct resource m66592_usb_peripheral_resources[] = { |
| 54 | [0] = { |
| 55 | .name = "m66592_udc", |
| 56 | .start = 0xb0000000, |
| 57 | .end = 0xb00000FF, |
| 58 | .flags = IORESOURCE_MEM, |
| 59 | }, |
| 60 | [1] = { |
| 61 | .name = "m66592_udc", |
Magnus Damm | 897cfcd8 | 2007-09-10 12:06:03 +0900 | [diff] [blame] | 62 | .start = IRQ_EXT4, /* irq number */ |
| 63 | .end = IRQ_EXT4, |
Yoshihiro Shimoda | e6c972f | 2007-07-17 13:38:54 +0900 | [diff] [blame] | 64 | .flags = IORESOURCE_IRQ, |
| 65 | }, |
| 66 | }; |
| 67 | |
| 68 | static struct platform_device m66592_usb_peripheral_device = { |
| 69 | .name = "m66592_udc", |
| 70 | .id = -1, |
| 71 | .dev = { |
| 72 | .dma_mask = NULL, /* don't use dma */ |
| 73 | .coherent_dma_mask = 0xffffffff, |
| 74 | }, |
| 75 | .num_resources = ARRAY_SIZE(m66592_usb_peripheral_resources), |
| 76 | .resource = m66592_usb_peripheral_resources, |
| 77 | }; |
| 78 | |
Paul Mundt | 0c020e3 | 2006-12-06 10:43:44 +0900 | [diff] [blame] | 79 | static struct resource cf_ide_resources[] = { |
| 80 | [0] = { |
Paul Mundt | 71074d3 | 2007-02-14 14:49:04 +0900 | [diff] [blame] | 81 | .start = PA_AREA5_IO + 0x1000, |
| 82 | .end = PA_AREA5_IO + 0x1000 + 0x08 - 1, |
| 83 | .flags = IORESOURCE_MEM, |
Paul Mundt | 0c020e3 | 2006-12-06 10:43:44 +0900 | [diff] [blame] | 84 | }, |
| 85 | [1] = { |
Paul Mundt | 71074d3 | 2007-02-14 14:49:04 +0900 | [diff] [blame] | 86 | .start = PA_AREA5_IO + 0x80c, |
| 87 | .end = PA_AREA5_IO + 0x80c + 0x16 - 1, |
| 88 | .flags = IORESOURCE_MEM, |
Paul Mundt | 0c020e3 | 2006-12-06 10:43:44 +0900 | [diff] [blame] | 89 | }, |
| 90 | [2] = { |
Magnus Damm | 897cfcd8 | 2007-09-10 12:06:03 +0900 | [diff] [blame] | 91 | .start = IRQ_CF, |
Paul Mundt | 0c020e3 | 2006-12-06 10:43:44 +0900 | [diff] [blame] | 92 | .flags = IORESOURCE_IRQ, |
| 93 | }, |
| 94 | }; |
| 95 | |
Paul Mundt | 71074d3 | 2007-02-14 14:49:04 +0900 | [diff] [blame] | 96 | static struct pata_platform_info pata_info = { |
| 97 | .ioport_shift = 1, |
| 98 | }; |
| 99 | |
Paul Mundt | 0c020e3 | 2006-12-06 10:43:44 +0900 | [diff] [blame] | 100 | static struct platform_device cf_ide_device = { |
| 101 | .name = "pata_platform", |
| 102 | .id = -1, |
| 103 | .num_resources = ARRAY_SIZE(cf_ide_resources), |
| 104 | .resource = cf_ide_resources, |
Paul Mundt | 71074d3 | 2007-02-14 14:49:04 +0900 | [diff] [blame] | 105 | .dev = { |
| 106 | .platform_data = &pata_info, |
| 107 | }, |
Paul Mundt | 0c020e3 | 2006-12-06 10:43:44 +0900 | [diff] [blame] | 108 | }; |
| 109 | |
Paul Mundt | 3b4d953 | 2007-02-13 15:42:28 +0900 | [diff] [blame] | 110 | static struct resource heartbeat_resources[] = { |
| 111 | [0] = { |
| 112 | .start = PA_OBLED, |
Paul Mundt | a1fd306 | 2007-08-23 15:11:44 +0900 | [diff] [blame] | 113 | .end = PA_OBLED, |
Paul Mundt | 3b4d953 | 2007-02-13 15:42:28 +0900 | [diff] [blame] | 114 | .flags = IORESOURCE_MEM, |
| 115 | }, |
| 116 | }; |
| 117 | |
Paul Mundt | 8786c95 | 2007-08-20 13:03:41 +0900 | [diff] [blame] | 118 | #ifndef CONFIG_SH_R7785RP |
| 119 | static unsigned char heartbeat_bit_pos[] = { 2, 1, 0, 3, 6, 5, 4, 7 }; |
| 120 | |
| 121 | static struct heartbeat_data heartbeat_data = { |
| 122 | .bit_pos = heartbeat_bit_pos, |
| 123 | .nr_bits = ARRAY_SIZE(heartbeat_bit_pos), |
| 124 | }; |
| 125 | #endif |
| 126 | |
Paul Mundt | 3b4d953 | 2007-02-13 15:42:28 +0900 | [diff] [blame] | 127 | static struct platform_device heartbeat_device = { |
| 128 | .name = "heartbeat", |
| 129 | .id = -1, |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 130 | |
| 131 | /* R7785RP has a slightly more sensible FPGA.. */ |
| 132 | #ifndef CONFIG_SH_R7785RP |
Paul Mundt | 3b4d953 | 2007-02-13 15:42:28 +0900 | [diff] [blame] | 133 | .dev = { |
Paul Mundt | a1fd306 | 2007-08-23 15:11:44 +0900 | [diff] [blame] | 134 | .platform_data = &heartbeat_data, |
Paul Mundt | 3b4d953 | 2007-02-13 15:42:28 +0900 | [diff] [blame] | 135 | }, |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 136 | #endif |
Paul Mundt | 3b4d953 | 2007-02-13 15:42:28 +0900 | [diff] [blame] | 137 | .num_resources = ARRAY_SIZE(heartbeat_resources), |
| 138 | .resource = heartbeat_resources, |
| 139 | }; |
| 140 | |
Magnus Damm | c6f93a3 | 2007-10-15 10:36:45 +0900 | [diff] [blame] | 141 | static struct ax_plat_data ax88796_platdata = { |
| 142 | .flags = AXFLG_HAS_93CX6, |
| 143 | .wordlength = 2, |
| 144 | .dcr_val = 0x1, |
| 145 | .rcr_val = 0x40, |
| 146 | }; |
| 147 | |
| 148 | static struct resource ax88796_resources[] = { |
| 149 | { |
| 150 | #ifdef CONFIG_SH_R7780RP |
| 151 | .start = 0xa5800400, |
| 152 | .end = 0xa5800400 + (0x20 * 0x2) - 1, |
| 153 | #else |
| 154 | .start = 0xa4100400, |
| 155 | .end = 0xa4100400 + (0x20 * 0x2) - 1, |
| 156 | #endif |
| 157 | .flags = IORESOURCE_MEM, |
| 158 | }, |
| 159 | { |
| 160 | .start = IRQ_AX88796, |
| 161 | .end = IRQ_AX88796, |
| 162 | .flags = IORESOURCE_IRQ, |
| 163 | }, |
| 164 | }; |
| 165 | |
| 166 | static struct platform_device ax88796_device = { |
| 167 | .name = "ax88796", |
| 168 | .id = 0, |
| 169 | |
| 170 | .dev = { |
| 171 | .platform_data = &ax88796_platdata, |
| 172 | }, |
| 173 | |
| 174 | .num_resources = ARRAY_SIZE(ax88796_resources), |
| 175 | .resource = ax88796_resources, |
| 176 | }; |
| 177 | |
| 178 | |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 179 | static struct platform_device *r7780rp_devices[] __initdata = { |
Yoshihiro Shimoda | e6c972f | 2007-07-17 13:38:54 +0900 | [diff] [blame] | 180 | &r8a66597_usb_host_device, |
| 181 | &m66592_usb_peripheral_device, |
Paul Mundt | 0c020e3 | 2006-12-06 10:43:44 +0900 | [diff] [blame] | 182 | &cf_ide_device, |
Paul Mundt | 3b4d953 | 2007-02-13 15:42:28 +0900 | [diff] [blame] | 183 | &heartbeat_device, |
Magnus Damm | c6f93a3 | 2007-10-15 10:36:45 +0900 | [diff] [blame] | 184 | &ax88796_device, |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | static int __init r7780rp_devices_setup(void) |
| 188 | { |
| 189 | return platform_add_devices(r7780rp_devices, |
| 190 | ARRAY_SIZE(r7780rp_devices)); |
| 191 | } |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 192 | device_initcall(r7780rp_devices_setup); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 193 | |
| 194 | /* |
| 195 | * Platform specific clocks |
| 196 | */ |
| 197 | static void ivdr_clk_enable(struct clk *clk) |
| 198 | { |
Ryusuke Sakato | 39374aa | 2007-05-07 10:48:56 +0900 | [diff] [blame] | 199 | ctrl_outw(ctrl_inw(PA_IVDRCTL) | (1 << IVDR_CK_ON), PA_IVDRCTL); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static void ivdr_clk_disable(struct clk *clk) |
| 203 | { |
Ryusuke Sakato | 39374aa | 2007-05-07 10:48:56 +0900 | [diff] [blame] | 204 | ctrl_outw(ctrl_inw(PA_IVDRCTL) & ~(1 << IVDR_CK_ON), PA_IVDRCTL); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static struct clk_ops ivdr_clk_ops = { |
| 208 | .enable = ivdr_clk_enable, |
| 209 | .disable = ivdr_clk_disable, |
| 210 | }; |
| 211 | |
| 212 | static struct clk ivdr_clk = { |
| 213 | .name = "ivdr_clk", |
| 214 | .ops = &ivdr_clk_ops, |
| 215 | }; |
| 216 | |
| 217 | static struct clk *r7780rp_clocks[] = { |
| 218 | &ivdr_clk, |
| 219 | }; |
| 220 | |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 221 | static void r7780rp_power_off(void) |
| 222 | { |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 223 | if (mach_is_r7780mp() || mach_is_r7785rp()) |
| 224 | ctrl_outw(0x0001, PA_POFF); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 225 | } |
| 226 | |
Paul Mundt | b5751e2 | 2007-11-02 14:17:19 +0900 | [diff] [blame^] | 227 | static inline unsigned char is_ide_ioaddr(unsigned long addr) |
| 228 | { |
| 229 | return ((cf_ide_resources[0].start <= addr && |
| 230 | addr <= cf_ide_resources[0].end) || |
| 231 | (cf_ide_resources[1].start <= addr && |
| 232 | addr <= cf_ide_resources[1].end)); |
| 233 | } |
| 234 | |
| 235 | void highlander_writeb(u8 b, void __iomem *addr) |
| 236 | { |
| 237 | unsigned long tmp = (unsigned long __force)addr; |
| 238 | |
| 239 | if (is_ide_ioaddr(tmp)) |
| 240 | ctrl_outw((u16)b, tmp); |
| 241 | else |
| 242 | ctrl_outb(b, tmp); |
| 243 | } |
| 244 | |
| 245 | u8 highlander_readb(void __iomem *addr) |
| 246 | { |
| 247 | unsigned long tmp = (unsigned long __force)addr; |
| 248 | |
| 249 | if (is_ide_ioaddr(tmp)) |
| 250 | return ctrl_inw(tmp) & 0xff; |
| 251 | else |
| 252 | return ctrl_inb(tmp); |
| 253 | } |
| 254 | |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 255 | /* |
| 256 | * Initialize the board |
| 257 | */ |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 258 | static void __init highlander_setup(char **cmdline_p) |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 259 | { |
| 260 | u16 ver = ctrl_inw(PA_VERREG); |
| 261 | int i; |
| 262 | |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 263 | printk(KERN_INFO "Renesas Solutions Highlander %s support.\n", |
| 264 | mach_is_r7780rp() ? "R7780RP-1" : |
| 265 | mach_is_r7780mp() ? "R7780MP" : |
| 266 | "R7785RP"); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 267 | |
| 268 | printk(KERN_INFO "Board version: %d (revision %d), " |
| 269 | "FPGA version: %d (revision %d)\n", |
| 270 | (ver >> 12) & 0xf, (ver >> 8) & 0xf, |
| 271 | (ver >> 4) & 0xf, ver & 0xf); |
| 272 | |
| 273 | /* |
| 274 | * Enable the important clocks right away.. |
| 275 | */ |
| 276 | for (i = 0; i < ARRAY_SIZE(r7780rp_clocks); i++) { |
| 277 | struct clk *clk = r7780rp_clocks[i]; |
| 278 | |
| 279 | clk_register(clk); |
| 280 | clk_enable(clk); |
| 281 | } |
| 282 | |
| 283 | ctrl_outw(0x0000, PA_OBLED); /* Clear LED. */ |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 284 | |
| 285 | if (mach_is_r7780rp()) |
| 286 | ctrl_outw(0x0001, PA_SDPOW); /* SD Power ON */ |
| 287 | |
Paul Mundt | 2c081e7 | 2006-12-25 18:28:33 +0900 | [diff] [blame] | 288 | ctrl_outw(ctrl_inw(PA_IVDRCTL) | 0x01, PA_IVDRCTL); /* Si13112 */ |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 289 | |
| 290 | pm_power_off = r7780rp_power_off; |
| 291 | } |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 292 | |
Magnus Damm | 897cfcd8 | 2007-09-10 12:06:03 +0900 | [diff] [blame] | 293 | static unsigned char irl2irq[HL_NR_IRL]; |
| 294 | |
| 295 | int highlander_irq_demux(int irq) |
| 296 | { |
| 297 | if (irq >= HL_NR_IRL || !irl2irq[irq]) |
| 298 | return irq; |
| 299 | |
| 300 | return irl2irq[irq]; |
| 301 | } |
| 302 | |
| 303 | void __init highlander_init_irq(void) |
| 304 | { |
| 305 | unsigned char *ucp = NULL; |
| 306 | |
| 307 | do { |
| 308 | #ifdef CONFIG_SH_R7780MP |
| 309 | ucp = highlander_init_irq_r7780mp(); |
| 310 | if (ucp) |
| 311 | break; |
| 312 | #endif |
| 313 | #ifdef CONFIG_SH_R7785RP |
| 314 | ucp = highlander_init_irq_r7785rp(); |
| 315 | if (ucp) |
| 316 | break; |
| 317 | #endif |
| 318 | #ifdef CONFIG_SH_R7780RP |
| 319 | highlander_init_irq_r7780rp(); |
| 320 | ucp = irl2irq; |
| 321 | break; |
| 322 | #endif |
| 323 | } while (0); |
| 324 | |
| 325 | if (ucp) { |
| 326 | plat_irq_setup_pins(IRQ_MODE_IRL3210); |
| 327 | memcpy(irl2irq, ucp, HL_NR_IRL); |
| 328 | } |
| 329 | } |
| 330 | |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 331 | /* |
| 332 | * The Machine Vector |
| 333 | */ |
Paul Mundt | 82f81f4 | 2007-05-15 15:19:34 +0900 | [diff] [blame] | 334 | static struct sh_machine_vector mv_highlander __initmv = { |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 335 | .mv_name = "Highlander", |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 336 | .mv_setup = highlander_setup, |
| 337 | .mv_init_irq = highlander_init_irq, |
Magnus Damm | 897cfcd8 | 2007-09-10 12:06:03 +0900 | [diff] [blame] | 338 | .mv_irq_demux = highlander_irq_demux, |
Paul Mundt | b5751e2 | 2007-11-02 14:17:19 +0900 | [diff] [blame^] | 339 | .mv_readb = highlander_readb, |
| 340 | .mv_writeb = highlander_writeb, |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 341 | }; |