Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Renesas Technology Sales RTS7751R2D Support. |
| 3 | * |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 4 | * Copyright (C) 2002 - 2006 Atom Create Engineering Co., Ltd. |
| 5 | * Copyright (C) 2004 - 2007 Paul Mundt |
Paul Mundt | ade2b3f | 2006-09-27 16:48:46 +0900 | [diff] [blame] | 6 | * |
| 7 | * This file is subject to the terms and conditions of the GNU General Public |
| 8 | * License. See the file "COPYING" in the main directory of this archive |
| 9 | * for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/init.h> |
Paul Mundt | ade2b3f | 2006-09-27 16:48:46 +0900 | [diff] [blame] | 12 | #include <linux/platform_device.h> |
Jeff Garzik | 0a87e3e | 2008-02-01 18:02:30 -0500 | [diff] [blame^] | 13 | #include <linux/ata_platform.h> |
Paul Mundt | ade2b3f | 2006-09-27 16:48:46 +0900 | [diff] [blame] | 14 | #include <linux/serial_8250.h> |
Paul Mundt | c87a711 | 2007-03-01 18:47:08 +0900 | [diff] [blame] | 15 | #include <linux/sm501.h> |
Magnus Damm | 29ec677 | 2008-01-15 12:47:53 +0900 | [diff] [blame] | 16 | #include <linux/sm501-regs.h> |
Paul Mundt | a56d276 | 2006-09-27 11:43:24 +0900 | [diff] [blame] | 17 | #include <linux/pm.h> |
Magnus Damm | cbd10df | 2008-01-15 12:44:44 +0900 | [diff] [blame] | 18 | #include <linux/fb.h> |
Magnus Damm | 6582d7b | 2008-01-23 16:21:18 +0900 | [diff] [blame] | 19 | #include <linux/spi/spi.h> |
| 20 | #include <linux/spi/spi_bitbang.h> |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 21 | #include <asm/machvec.h> |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 22 | #include <asm/rts7751r2d.h> |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 23 | #include <asm/io.h> |
Magnus Damm | 6582d7b | 2008-01-23 16:21:18 +0900 | [diff] [blame] | 24 | #include <asm/spi.h> |
Paul Mundt | ade2b3f | 2006-09-27 16:48:46 +0900 | [diff] [blame] | 25 | |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 26 | static struct resource cf_ide_resources[] = { |
| 27 | [0] = { |
| 28 | .start = PA_AREA5_IO + 0x1000, |
Aoi Shinkai | 43f4b8c | 2007-09-21 15:18:33 +0900 | [diff] [blame] | 29 | .end = PA_AREA5_IO + 0x1000 + 0x10 - 0x2, |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 30 | .flags = IORESOURCE_MEM, |
| 31 | }, |
| 32 | [1] = { |
| 33 | .start = PA_AREA5_IO + 0x80c, |
Aoi Shinkai | 43f4b8c | 2007-09-21 15:18:33 +0900 | [diff] [blame] | 34 | .end = PA_AREA5_IO + 0x80c, |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 35 | .flags = IORESOURCE_MEM, |
| 36 | }, |
Magnus Damm | abac3f7 | 2007-11-23 14:39:13 +0900 | [diff] [blame] | 37 | #ifndef CONFIG_RTS7751R2D_1 /* For R2D-1 polling is preferred */ |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 38 | [2] = { |
Magnus Damm | 2eeec85 | 2007-08-12 15:29:16 +0900 | [diff] [blame] | 39 | .start = IRQ_CF_IDE, |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 40 | .flags = IORESOURCE_IRQ, |
| 41 | }, |
Magnus Damm | abac3f7 | 2007-11-23 14:39:13 +0900 | [diff] [blame] | 42 | #endif |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | static struct pata_platform_info pata_info = { |
| 46 | .ioport_shift = 1, |
| 47 | }; |
| 48 | |
| 49 | static struct platform_device cf_ide_device = { |
| 50 | .name = "pata_platform", |
| 51 | .id = -1, |
| 52 | .num_resources = ARRAY_SIZE(cf_ide_resources), |
| 53 | .resource = cf_ide_resources, |
| 54 | .dev = { |
| 55 | .platform_data = &pata_info, |
| 56 | }, |
| 57 | }; |
| 58 | |
Magnus Damm | 6582d7b | 2008-01-23 16:21:18 +0900 | [diff] [blame] | 59 | static struct spi_board_info spi_bus[] = { |
| 60 | { |
| 61 | .modalias = "rtc-r9701", |
| 62 | .max_speed_hz = 1000000, |
| 63 | .mode = SPI_MODE_3, |
| 64 | }, |
| 65 | }; |
| 66 | |
| 67 | static void r2d_chip_select(struct sh_spi_info *spi, int cs, int state) |
| 68 | { |
| 69 | BUG_ON(cs != 0); /* Single Epson RTC-9701JE attached on CS0 */ |
| 70 | ctrl_outw(state == BITBANG_CS_ACTIVE, PA_RTCCE); |
| 71 | } |
| 72 | |
| 73 | static struct sh_spi_info spi_info = { |
| 74 | .num_chipselect = 1, |
| 75 | .chip_select = r2d_chip_select, |
| 76 | }; |
| 77 | |
| 78 | static struct resource spi_sh_sci_resources[] = { |
| 79 | { |
| 80 | .start = 0xffe00000, |
| 81 | .end = 0xffe0001f, |
| 82 | .flags = IORESOURCE_MEM, |
| 83 | }, |
| 84 | }; |
| 85 | |
| 86 | static struct platform_device spi_sh_sci_device = { |
| 87 | .name = "spi_sh_sci", |
| 88 | .id = -1, |
| 89 | .num_resources = ARRAY_SIZE(spi_sh_sci_resources), |
| 90 | .resource = spi_sh_sci_resources, |
| 91 | .dev = { |
| 92 | .platform_data = &spi_info, |
| 93 | }, |
| 94 | }; |
| 95 | |
Magnus Damm | f8b40d8 | 2007-08-12 15:30:40 +0900 | [diff] [blame] | 96 | static struct resource heartbeat_resources[] = { |
| 97 | [0] = { |
| 98 | .start = PA_OUTPORT, |
Paul Mundt | a1fd306 | 2007-08-23 15:11:44 +0900 | [diff] [blame] | 99 | .end = PA_OUTPORT, |
Magnus Damm | f8b40d8 | 2007-08-12 15:30:40 +0900 | [diff] [blame] | 100 | .flags = IORESOURCE_MEM, |
| 101 | }, |
| 102 | }; |
| 103 | |
| 104 | static struct platform_device heartbeat_device = { |
| 105 | .name = "heartbeat", |
| 106 | .id = -1, |
| 107 | .num_resources = ARRAY_SIZE(heartbeat_resources), |
| 108 | .resource = heartbeat_resources, |
| 109 | }; |
| 110 | |
| 111 | #ifdef CONFIG_MFD_SM501 |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 112 | static struct plat_serial8250_port uart_platform_data[] = { |
| 113 | { |
Magnus Damm | 29ec677 | 2008-01-15 12:47:53 +0900 | [diff] [blame] | 114 | .membase = (void __iomem *)0xb3e30000, |
| 115 | .mapbase = 0xb3e30000, |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 116 | .iotype = UPIO_MEM, |
Magnus Damm | 29ec677 | 2008-01-15 12:47:53 +0900 | [diff] [blame] | 117 | .irq = IRQ_VOYAGER, |
| 118 | .flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ, |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 119 | .regshift = 2, |
| 120 | .uartclk = (9600 * 16), |
Magnus Damm | 3a35382 | 2007-07-20 16:34:22 +0900 | [diff] [blame] | 121 | }, |
| 122 | { 0 }, |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 123 | }; |
| 124 | |
Paul Mundt | ade2b3f | 2006-09-27 16:48:46 +0900 | [diff] [blame] | 125 | static struct platform_device uart_device = { |
| 126 | .name = "serial8250", |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 127 | .id = PLAT8250_DEV_PLATFORM, |
Paul Mundt | ade2b3f | 2006-09-27 16:48:46 +0900 | [diff] [blame] | 128 | .dev = { |
| 129 | .platform_data = uart_platform_data, |
| 130 | }, |
| 131 | }; |
| 132 | |
Paul Mundt | c87a711 | 2007-03-01 18:47:08 +0900 | [diff] [blame] | 133 | static struct resource sm501_resources[] = { |
| 134 | [0] = { |
| 135 | .start = 0x10000000, |
| 136 | .end = 0x13e00000 - 1, |
| 137 | .flags = IORESOURCE_MEM, |
| 138 | }, |
| 139 | [1] = { |
| 140 | .start = 0x13e00000, |
| 141 | .end = 0x13ffffff, |
| 142 | .flags = IORESOURCE_MEM, |
| 143 | }, |
| 144 | [2] = { |
Magnus Damm | 29ec677 | 2008-01-15 12:47:53 +0900 | [diff] [blame] | 145 | .start = IRQ_VOYAGER, |
Paul Mundt | c87a711 | 2007-03-01 18:47:08 +0900 | [diff] [blame] | 146 | .flags = IORESOURCE_IRQ, |
| 147 | }, |
| 148 | }; |
| 149 | |
Magnus Damm | cbd10df | 2008-01-15 12:44:44 +0900 | [diff] [blame] | 150 | static struct fb_videomode sm501_default_mode = { |
| 151 | .pixclock = 35714, |
| 152 | .xres = 640, |
| 153 | .yres = 480, |
| 154 | .left_margin = 105, |
| 155 | .right_margin = 50, |
| 156 | .upper_margin = 35, |
| 157 | .lower_margin = 0, |
| 158 | .hsync_len = 96, |
| 159 | .vsync_len = 2, |
| 160 | .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 161 | }; |
| 162 | |
| 163 | static struct sm501_platdata_fbsub sm501_pdata_fbsub_pnl = { |
| 164 | .def_bpp = 16, |
| 165 | .def_mode = &sm501_default_mode, |
| 166 | .flags = SM501FB_FLAG_USE_INIT_MODE | |
| 167 | SM501FB_FLAG_USE_HWCURSOR | |
| 168 | SM501FB_FLAG_USE_HWACCEL | |
| 169 | SM501FB_FLAG_DISABLE_AT_EXIT, |
| 170 | }; |
| 171 | |
| 172 | static struct sm501_platdata_fbsub sm501_pdata_fbsub_crt = { |
| 173 | .flags = (SM501FB_FLAG_USE_INIT_MODE | |
| 174 | SM501FB_FLAG_USE_HWCURSOR | |
| 175 | SM501FB_FLAG_USE_HWACCEL | |
| 176 | SM501FB_FLAG_DISABLE_AT_EXIT), |
| 177 | |
| 178 | }; |
| 179 | |
| 180 | static struct sm501_platdata_fb sm501_fb_pdata = { |
| 181 | .fb_route = SM501_FB_OWN, |
| 182 | .fb_crt = &sm501_pdata_fbsub_crt, |
| 183 | .fb_pnl = &sm501_pdata_fbsub_pnl, |
| 184 | .flags = SM501_FBPD_SWAP_FB_ENDIAN, |
| 185 | }; |
| 186 | |
Magnus Damm | 29ec677 | 2008-01-15 12:47:53 +0900 | [diff] [blame] | 187 | static struct sm501_initdata sm501_initdata = { |
| 188 | .gpio_high = { |
| 189 | .set = 0x00001fe0, |
| 190 | .mask = 0x0, |
| 191 | }, |
Magnus Damm | d1eea50 | 2008-01-15 12:48:15 +0900 | [diff] [blame] | 192 | .devices = SM501_USE_USB_HOST, |
Magnus Damm | 29ec677 | 2008-01-15 12:47:53 +0900 | [diff] [blame] | 193 | }; |
| 194 | |
Magnus Damm | cbd10df | 2008-01-15 12:44:44 +0900 | [diff] [blame] | 195 | static struct sm501_platdata sm501_platform_data = { |
Magnus Damm | 29ec677 | 2008-01-15 12:47:53 +0900 | [diff] [blame] | 196 | .init = &sm501_initdata, |
Magnus Damm | cbd10df | 2008-01-15 12:44:44 +0900 | [diff] [blame] | 197 | .fb = &sm501_fb_pdata, |
| 198 | }; |
| 199 | |
Paul Mundt | c87a711 | 2007-03-01 18:47:08 +0900 | [diff] [blame] | 200 | static struct platform_device sm501_device = { |
| 201 | .name = "sm501", |
| 202 | .id = -1, |
Magnus Damm | cbd10df | 2008-01-15 12:44:44 +0900 | [diff] [blame] | 203 | .dev = { |
| 204 | .platform_data = &sm501_platform_data, |
| 205 | }, |
Paul Mundt | c87a711 | 2007-03-01 18:47:08 +0900 | [diff] [blame] | 206 | .num_resources = ARRAY_SIZE(sm501_resources), |
| 207 | .resource = sm501_resources, |
| 208 | }; |
| 209 | |
Magnus Damm | f8b40d8 | 2007-08-12 15:30:40 +0900 | [diff] [blame] | 210 | #endif /* CONFIG_MFD_SM501 */ |
| 211 | |
Paul Mundt | ade2b3f | 2006-09-27 16:48:46 +0900 | [diff] [blame] | 212 | static struct platform_device *rts7751r2d_devices[] __initdata = { |
Magnus Damm | f8b40d8 | 2007-08-12 15:30:40 +0900 | [diff] [blame] | 213 | #ifdef CONFIG_MFD_SM501 |
Paul Mundt | ade2b3f | 2006-09-27 16:48:46 +0900 | [diff] [blame] | 214 | &uart_device, |
Paul Mundt | c87a711 | 2007-03-01 18:47:08 +0900 | [diff] [blame] | 215 | &sm501_device, |
Magnus Damm | f8b40d8 | 2007-08-12 15:30:40 +0900 | [diff] [blame] | 216 | #endif |
Aoi Shinkai | 43f4b8c | 2007-09-21 15:18:33 +0900 | [diff] [blame] | 217 | &cf_ide_device, |
Magnus Damm | f8b40d8 | 2007-08-12 15:30:40 +0900 | [diff] [blame] | 218 | &heartbeat_device, |
Magnus Damm | 6582d7b | 2008-01-23 16:21:18 +0900 | [diff] [blame] | 219 | &spi_sh_sci_device, |
Paul Mundt | ade2b3f | 2006-09-27 16:48:46 +0900 | [diff] [blame] | 220 | }; |
| 221 | |
| 222 | static int __init rts7751r2d_devices_setup(void) |
| 223 | { |
Magnus Damm | 6582d7b | 2008-01-23 16:21:18 +0900 | [diff] [blame] | 224 | spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus)); |
Paul Mundt | ade2b3f | 2006-09-27 16:48:46 +0900 | [diff] [blame] | 225 | return platform_add_devices(rts7751r2d_devices, |
| 226 | ARRAY_SIZE(rts7751r2d_devices)); |
| 227 | } |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 228 | __initcall(rts7751r2d_devices_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Paul Mundt | a56d276 | 2006-09-27 11:43:24 +0900 | [diff] [blame] | 230 | static void rts7751r2d_power_off(void) |
| 231 | { |
| 232 | ctrl_outw(0x0001, PA_POWOFF); |
| 233 | } |
| 234 | |
Aoi Shinkai | 43f4b8c | 2007-09-21 15:18:33 +0900 | [diff] [blame] | 235 | static inline unsigned char is_ide_ioaddr(unsigned long addr) |
| 236 | { |
| 237 | return ((cf_ide_resources[0].start <= addr && |
| 238 | addr <= cf_ide_resources[0].end) || |
| 239 | (cf_ide_resources[1].start <= addr && |
| 240 | addr <= cf_ide_resources[1].end)); |
| 241 | } |
| 242 | |
Paul Mundt | 02353f5 | 2007-09-21 15:21:55 +0900 | [diff] [blame] | 243 | void rts7751r2d_writeb(u8 b, void __iomem *addr) |
Aoi Shinkai | 43f4b8c | 2007-09-21 15:18:33 +0900 | [diff] [blame] | 244 | { |
| 245 | unsigned long tmp = (unsigned long __force)addr; |
| 246 | |
| 247 | if (is_ide_ioaddr(tmp)) |
| 248 | ctrl_outw((u16)b, tmp); |
| 249 | else |
| 250 | ctrl_outb(b, tmp); |
| 251 | } |
| 252 | |
Paul Mundt | 02353f5 | 2007-09-21 15:21:55 +0900 | [diff] [blame] | 253 | u8 rts7751r2d_readb(void __iomem *addr) |
Aoi Shinkai | 43f4b8c | 2007-09-21 15:18:33 +0900 | [diff] [blame] | 254 | { |
| 255 | unsigned long tmp = (unsigned long __force)addr; |
| 256 | |
| 257 | if (is_ide_ioaddr(tmp)) |
| 258 | return ctrl_inw(tmp) & 0xff; |
| 259 | else |
| 260 | return ctrl_inb(tmp); |
| 261 | } |
| 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | /* |
| 264 | * Initialize the board |
| 265 | */ |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 266 | static void __init rts7751r2d_setup(char **cmdline_p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
Magnus Damm | 29ec677 | 2008-01-15 12:47:53 +0900 | [diff] [blame] | 268 | void __iomem *sm501_reg; |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 269 | u16 ver = ctrl_inw(PA_VERREG); |
| 270 | |
| 271 | printk(KERN_INFO "Renesas Technology Sales RTS7751R2D support.\n"); |
| 272 | |
| 273 | printk(KERN_INFO "FPGA version:%d (revision:%d)\n", |
| 274 | (ver >> 4) & 0xf, ver & 0xf); |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | ctrl_outw(0x0000, PA_OUTPORT); |
Paul Mundt | a56d276 | 2006-09-27 11:43:24 +0900 | [diff] [blame] | 277 | pm_power_off = rts7751r2d_power_off; |
Paul Mundt | ade2b3f | 2006-09-27 16:48:46 +0900 | [diff] [blame] | 278 | |
Magnus Damm | 29ec677 | 2008-01-15 12:47:53 +0900 | [diff] [blame] | 279 | /* sm501 dram configuration: |
| 280 | * ColSizeX = 11 - External Memory Column Size: 256 words. |
| 281 | * APX = 1 - External Memory Active to Pre-Charge Delay: 7 clocks. |
| 282 | * RstX = 1 - External Memory Reset: Normal. |
| 283 | * Rfsh = 1 - Local Memory Refresh to Command Delay: 12 clocks. |
| 284 | * BwC = 1 - Local Memory Block Write Cycle Time: 2 clocks. |
| 285 | * BwP = 1 - Local Memory Block Write to Pre-Charge Delay: 1 clock. |
| 286 | * AP = 1 - Internal Memory Active to Pre-Charge Delay: 7 clocks. |
| 287 | * Rst = 1 - Internal Memory Reset: Normal. |
| 288 | * RA = 1 - Internal Memory Remain in Active State: Do not remain. |
| 289 | */ |
| 290 | |
| 291 | sm501_reg = (void __iomem *)0xb3e00000 + SM501_DRAM_CONTROL; |
| 292 | writel(readl(sm501_reg) | 0x00f107c0, sm501_reg); |
| 293 | |
| 294 | /* |
| 295 | * Power Mode Gate - Enable UART0 |
| 296 | */ |
| 297 | |
| 298 | sm501_reg = (void __iomem *)0xb3e00000 + SM501_POWER_MODE_0_GATE; |
| 299 | writel(readl(sm501_reg) | (1 << SM501_GATE_UART0), sm501_reg); |
| 300 | |
| 301 | sm501_reg = (void __iomem *)0xb3e00000 + SM501_POWER_MODE_1_GATE; |
| 302 | writel(readl(sm501_reg) | (1 << SM501_GATE_UART0), sm501_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 304 | |
| 305 | /* |
| 306 | * The Machine Vector |
| 307 | */ |
Paul Mundt | 82f81f4 | 2007-05-15 15:19:34 +0900 | [diff] [blame] | 308 | static struct sh_machine_vector mv_rts7751r2d __initmv = { |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 309 | .mv_name = "RTS7751R2D", |
| 310 | .mv_setup = rts7751r2d_setup, |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 311 | .mv_init_irq = init_rts7751r2d_IRQ, |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 312 | .mv_irq_demux = rts7751r2d_irq_demux, |
Aoi Shinkai | 43f4b8c | 2007-09-21 15:18:33 +0900 | [diff] [blame] | 313 | .mv_writeb = rts7751r2d_writeb, |
| 314 | .mv_readb = rts7751r2d_readb, |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 315 | }; |