blob: f21ee49ef3a5c842c540c8e4a0780b113d666c2a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Renesas Technology Sales RTS7751R2D Support.
3 *
Paul Mundt9c575482007-02-15 18:20:52 +09004 * Copyright (C) 2002 - 2006 Atom Create Engineering Co., Ltd.
5 * Copyright (C) 2004 - 2007 Paul Mundt
Paul Mundtade2b3f2006-09-27 16:48:46 +09006 *
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 Torvalds1da177e2005-04-16 15:20:36 -070010 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/init.h>
Paul Mundtade2b3f2006-09-27 16:48:46 +090012#include <linux/platform_device.h>
Jeff Garzik0a87e3e2008-02-01 18:02:30 -050013#include <linux/ata_platform.h>
Paul Mundtade2b3f2006-09-27 16:48:46 +090014#include <linux/serial_8250.h>
Paul Mundtc87a7112007-03-01 18:47:08 +090015#include <linux/sm501.h>
Magnus Damm29ec6772008-01-15 12:47:53 +090016#include <linux/sm501-regs.h>
Paul Mundta56d2762006-09-27 11:43:24 +090017#include <linux/pm.h>
Magnus Dammcbd10df2008-01-15 12:44:44 +090018#include <linux/fb.h>
Magnus Damm6582d7b2008-01-23 16:21:18 +090019#include <linux/spi/spi.h>
20#include <linux/spi/spi_bitbang.h>
Paul Mundt2c7834a2006-09-27 18:17:31 +090021#include <asm/machvec.h>
Paul Mundt9c575482007-02-15 18:20:52 +090022#include <asm/rts7751r2d.h>
Paul Mundt9c575482007-02-15 18:20:52 +090023#include <asm/io.h>
Magnus Damm2d952b42008-02-07 20:21:10 +090024#include <asm/io_trapped.h>
Magnus Damm6582d7b2008-01-23 16:21:18 +090025#include <asm/spi.h>
Paul Mundtade2b3f2006-09-27 16:48:46 +090026
Paul Mundt9c575482007-02-15 18:20:52 +090027static struct resource cf_ide_resources[] = {
28 [0] = {
29 .start = PA_AREA5_IO + 0x1000,
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +090030 .end = PA_AREA5_IO + 0x1000 + 0x10 - 0x2,
Paul Mundt9c575482007-02-15 18:20:52 +090031 .flags = IORESOURCE_MEM,
32 },
33 [1] = {
34 .start = PA_AREA5_IO + 0x80c,
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +090035 .end = PA_AREA5_IO + 0x80c,
Paul Mundt9c575482007-02-15 18:20:52 +090036 .flags = IORESOURCE_MEM,
37 },
Magnus Dammabac3f72007-11-23 14:39:13 +090038#ifndef CONFIG_RTS7751R2D_1 /* For R2D-1 polling is preferred */
Paul Mundt9c575482007-02-15 18:20:52 +090039 [2] = {
Magnus Damm2eeec852007-08-12 15:29:16 +090040 .start = IRQ_CF_IDE,
Paul Mundt9c575482007-02-15 18:20:52 +090041 .flags = IORESOURCE_IRQ,
42 },
Magnus Dammabac3f72007-11-23 14:39:13 +090043#endif
Paul Mundt9c575482007-02-15 18:20:52 +090044};
45
46static struct pata_platform_info pata_info = {
47 .ioport_shift = 1,
48};
49
50static struct platform_device cf_ide_device = {
51 .name = "pata_platform",
52 .id = -1,
53 .num_resources = ARRAY_SIZE(cf_ide_resources),
54 .resource = cf_ide_resources,
55 .dev = {
56 .platform_data = &pata_info,
57 },
58};
59
Magnus Damm6582d7b2008-01-23 16:21:18 +090060static struct spi_board_info spi_bus[] = {
61 {
62 .modalias = "rtc-r9701",
63 .max_speed_hz = 1000000,
64 .mode = SPI_MODE_3,
65 },
66};
67
68static void r2d_chip_select(struct sh_spi_info *spi, int cs, int state)
69{
70 BUG_ON(cs != 0); /* Single Epson RTC-9701JE attached on CS0 */
71 ctrl_outw(state == BITBANG_CS_ACTIVE, PA_RTCCE);
72}
73
74static struct sh_spi_info spi_info = {
75 .num_chipselect = 1,
76 .chip_select = r2d_chip_select,
77};
78
79static struct resource spi_sh_sci_resources[] = {
80 {
81 .start = 0xffe00000,
82 .end = 0xffe0001f,
83 .flags = IORESOURCE_MEM,
84 },
85};
86
87static struct platform_device spi_sh_sci_device = {
88 .name = "spi_sh_sci",
89 .id = -1,
90 .num_resources = ARRAY_SIZE(spi_sh_sci_resources),
91 .resource = spi_sh_sci_resources,
92 .dev = {
93 .platform_data = &spi_info,
94 },
95};
96
Magnus Dammf8b40d82007-08-12 15:30:40 +090097static struct resource heartbeat_resources[] = {
98 [0] = {
99 .start = PA_OUTPORT,
Paul Mundta1fd3062007-08-23 15:11:44 +0900100 .end = PA_OUTPORT,
Magnus Dammf8b40d82007-08-12 15:30:40 +0900101 .flags = IORESOURCE_MEM,
102 },
103};
104
105static struct platform_device heartbeat_device = {
106 .name = "heartbeat",
107 .id = -1,
108 .num_resources = ARRAY_SIZE(heartbeat_resources),
109 .resource = heartbeat_resources,
110};
111
112#ifdef CONFIG_MFD_SM501
Paul Mundt9c575482007-02-15 18:20:52 +0900113static struct plat_serial8250_port uart_platform_data[] = {
114 {
Magnus Damm29ec6772008-01-15 12:47:53 +0900115 .membase = (void __iomem *)0xb3e30000,
116 .mapbase = 0xb3e30000,
Paul Mundt9c575482007-02-15 18:20:52 +0900117 .iotype = UPIO_MEM,
Magnus Damm29ec6772008-01-15 12:47:53 +0900118 .irq = IRQ_VOYAGER,
119 .flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ,
Paul Mundt9c575482007-02-15 18:20:52 +0900120 .regshift = 2,
121 .uartclk = (9600 * 16),
Magnus Damm3a353822007-07-20 16:34:22 +0900122 },
123 { 0 },
Paul Mundt9c575482007-02-15 18:20:52 +0900124};
125
Paul Mundtade2b3f2006-09-27 16:48:46 +0900126static struct platform_device uart_device = {
127 .name = "serial8250",
Paul Mundt9c575482007-02-15 18:20:52 +0900128 .id = PLAT8250_DEV_PLATFORM,
Paul Mundtade2b3f2006-09-27 16:48:46 +0900129 .dev = {
130 .platform_data = uart_platform_data,
131 },
132};
133
Paul Mundtc87a7112007-03-01 18:47:08 +0900134static struct resource sm501_resources[] = {
135 [0] = {
136 .start = 0x10000000,
137 .end = 0x13e00000 - 1,
138 .flags = IORESOURCE_MEM,
139 },
140 [1] = {
141 .start = 0x13e00000,
142 .end = 0x13ffffff,
143 .flags = IORESOURCE_MEM,
144 },
145 [2] = {
Magnus Damm29ec6772008-01-15 12:47:53 +0900146 .start = IRQ_VOYAGER,
Paul Mundtc87a7112007-03-01 18:47:08 +0900147 .flags = IORESOURCE_IRQ,
148 },
149};
150
Magnus Dammcbd10df2008-01-15 12:44:44 +0900151static struct fb_videomode sm501_default_mode = {
152 .pixclock = 35714,
153 .xres = 640,
154 .yres = 480,
155 .left_margin = 105,
156 .right_margin = 50,
157 .upper_margin = 35,
158 .lower_margin = 0,
159 .hsync_len = 96,
160 .vsync_len = 2,
161 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
162};
163
164static struct sm501_platdata_fbsub sm501_pdata_fbsub_pnl = {
165 .def_bpp = 16,
166 .def_mode = &sm501_default_mode,
167 .flags = SM501FB_FLAG_USE_INIT_MODE |
168 SM501FB_FLAG_USE_HWCURSOR |
169 SM501FB_FLAG_USE_HWACCEL |
170 SM501FB_FLAG_DISABLE_AT_EXIT,
171};
172
173static struct sm501_platdata_fbsub sm501_pdata_fbsub_crt = {
174 .flags = (SM501FB_FLAG_USE_INIT_MODE |
175 SM501FB_FLAG_USE_HWCURSOR |
176 SM501FB_FLAG_USE_HWACCEL |
177 SM501FB_FLAG_DISABLE_AT_EXIT),
178
179};
180
181static struct sm501_platdata_fb sm501_fb_pdata = {
182 .fb_route = SM501_FB_OWN,
183 .fb_crt = &sm501_pdata_fbsub_crt,
184 .fb_pnl = &sm501_pdata_fbsub_pnl,
185 .flags = SM501_FBPD_SWAP_FB_ENDIAN,
186};
187
Magnus Damm29ec6772008-01-15 12:47:53 +0900188static struct sm501_initdata sm501_initdata = {
189 .gpio_high = {
190 .set = 0x00001fe0,
191 .mask = 0x0,
192 },
Magnus Dammd1eea502008-01-15 12:48:15 +0900193 .devices = SM501_USE_USB_HOST,
Magnus Damm29ec6772008-01-15 12:47:53 +0900194};
195
Magnus Dammcbd10df2008-01-15 12:44:44 +0900196static struct sm501_platdata sm501_platform_data = {
Magnus Damm29ec6772008-01-15 12:47:53 +0900197 .init = &sm501_initdata,
Magnus Dammcbd10df2008-01-15 12:44:44 +0900198 .fb = &sm501_fb_pdata,
199};
200
Paul Mundtc87a7112007-03-01 18:47:08 +0900201static struct platform_device sm501_device = {
202 .name = "sm501",
203 .id = -1,
Magnus Dammcbd10df2008-01-15 12:44:44 +0900204 .dev = {
205 .platform_data = &sm501_platform_data,
206 },
Paul Mundtc87a7112007-03-01 18:47:08 +0900207 .num_resources = ARRAY_SIZE(sm501_resources),
208 .resource = sm501_resources,
209};
210
Magnus Dammf8b40d82007-08-12 15:30:40 +0900211#endif /* CONFIG_MFD_SM501 */
212
Paul Mundtade2b3f2006-09-27 16:48:46 +0900213static struct platform_device *rts7751r2d_devices[] __initdata = {
Magnus Dammf8b40d82007-08-12 15:30:40 +0900214#ifdef CONFIG_MFD_SM501
Paul Mundtade2b3f2006-09-27 16:48:46 +0900215 &uart_device,
Paul Mundtc87a7112007-03-01 18:47:08 +0900216 &sm501_device,
Magnus Dammf8b40d82007-08-12 15:30:40 +0900217#endif
218 &heartbeat_device,
Magnus Damm6582d7b2008-01-23 16:21:18 +0900219 &spi_sh_sci_device,
Paul Mundtade2b3f2006-09-27 16:48:46 +0900220};
221
Magnus Damm2d952b42008-02-07 20:21:10 +0900222/*
223 * The CF is connected with a 16-bit bus where 8-bit operations are
224 * unsupported. The linux ata driver is however using 8-bit operations, so
225 * insert a trapped io filter to convert 8-bit operations into 16-bit.
226 */
227static struct trapped_io cf_trapped_io = {
228 .resource = cf_ide_resources,
229 .num_resources = 2,
230 .minimum_bus_width = 16,
231};
232
Paul Mundtade2b3f2006-09-27 16:48:46 +0900233static int __init rts7751r2d_devices_setup(void)
234{
Magnus Damm2d952b42008-02-07 20:21:10 +0900235 if (register_trapped_io(&cf_trapped_io) == 0)
236 platform_device_register(&cf_ide_device);
Magnus Damm6582d7b2008-01-23 16:21:18 +0900237 spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus));
Paul Mundtade2b3f2006-09-27 16:48:46 +0900238 return platform_add_devices(rts7751r2d_devices,
239 ARRAY_SIZE(rts7751r2d_devices));
240}
Paul Mundt9c575482007-02-15 18:20:52 +0900241__initcall(rts7751r2d_devices_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Paul Mundta56d2762006-09-27 11:43:24 +0900243static void rts7751r2d_power_off(void)
244{
245 ctrl_outw(0x0001, PA_POWOFF);
246}
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248/*
249 * Initialize the board
250 */
Paul Mundt2c7834a2006-09-27 18:17:31 +0900251static void __init rts7751r2d_setup(char **cmdline_p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Magnus Damm29ec6772008-01-15 12:47:53 +0900253 void __iomem *sm501_reg;
Paul Mundt9c575482007-02-15 18:20:52 +0900254 u16 ver = ctrl_inw(PA_VERREG);
255
256 printk(KERN_INFO "Renesas Technology Sales RTS7751R2D support.\n");
257
258 printk(KERN_INFO "FPGA version:%d (revision:%d)\n",
259 (ver >> 4) & 0xf, ver & 0xf);
Paul Mundt2c7834a2006-09-27 18:17:31 +0900260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 ctrl_outw(0x0000, PA_OUTPORT);
Paul Mundta56d2762006-09-27 11:43:24 +0900262 pm_power_off = rts7751r2d_power_off;
Paul Mundtade2b3f2006-09-27 16:48:46 +0900263
Magnus Damm29ec6772008-01-15 12:47:53 +0900264 /* sm501 dram configuration:
265 * ColSizeX = 11 - External Memory Column Size: 256 words.
266 * APX = 1 - External Memory Active to Pre-Charge Delay: 7 clocks.
267 * RstX = 1 - External Memory Reset: Normal.
268 * Rfsh = 1 - Local Memory Refresh to Command Delay: 12 clocks.
269 * BwC = 1 - Local Memory Block Write Cycle Time: 2 clocks.
270 * BwP = 1 - Local Memory Block Write to Pre-Charge Delay: 1 clock.
271 * AP = 1 - Internal Memory Active to Pre-Charge Delay: 7 clocks.
272 * Rst = 1 - Internal Memory Reset: Normal.
273 * RA = 1 - Internal Memory Remain in Active State: Do not remain.
274 */
275
276 sm501_reg = (void __iomem *)0xb3e00000 + SM501_DRAM_CONTROL;
277 writel(readl(sm501_reg) | 0x00f107c0, sm501_reg);
278
279 /*
280 * Power Mode Gate - Enable UART0
281 */
282
283 sm501_reg = (void __iomem *)0xb3e00000 + SM501_POWER_MODE_0_GATE;
284 writel(readl(sm501_reg) | (1 << SM501_GATE_UART0), sm501_reg);
285
286 sm501_reg = (void __iomem *)0xb3e00000 + SM501_POWER_MODE_1_GATE;
287 writel(readl(sm501_reg) | (1 << SM501_GATE_UART0), sm501_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
Paul Mundt2c7834a2006-09-27 18:17:31 +0900289
290/*
291 * The Machine Vector
292 */
Paul Mundt82f81f42007-05-15 15:19:34 +0900293static struct sh_machine_vector mv_rts7751r2d __initmv = {
Paul Mundt2c7834a2006-09-27 18:17:31 +0900294 .mv_name = "RTS7751R2D",
295 .mv_setup = rts7751r2d_setup,
Paul Mundt2c7834a2006-09-27 18:17:31 +0900296 .mv_init_irq = init_rts7751r2d_IRQ,
Paul Mundt2c7834a2006-09-27 18:17:31 +0900297 .mv_irq_demux = rts7751r2d_irq_demux,
Paul Mundt2c7834a2006-09-27 18:17:31 +0900298};