blob: 8528616feaa0d069299f521dca81478faa69fbd6 [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>
Paul Mundt9c575482007-02-15 18:20:52 +090013#include <linux/pata_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>
Paul Mundt2c7834a2006-09-27 18:17:31 +090019#include <asm/machvec.h>
Paul Mundt9c575482007-02-15 18:20:52 +090020#include <asm/rts7751r2d.h>
Paul Mundt9c575482007-02-15 18:20:52 +090021#include <asm/io.h>
Paul Mundtade2b3f2006-09-27 16:48:46 +090022
Paul Mundt9c575482007-02-15 18:20:52 +090023static struct resource cf_ide_resources[] = {
24 [0] = {
25 .start = PA_AREA5_IO + 0x1000,
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +090026 .end = PA_AREA5_IO + 0x1000 + 0x10 - 0x2,
Paul Mundt9c575482007-02-15 18:20:52 +090027 .flags = IORESOURCE_MEM,
28 },
29 [1] = {
30 .start = PA_AREA5_IO + 0x80c,
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +090031 .end = PA_AREA5_IO + 0x80c,
Paul Mundt9c575482007-02-15 18:20:52 +090032 .flags = IORESOURCE_MEM,
33 },
Magnus Dammabac3f72007-11-23 14:39:13 +090034#ifndef CONFIG_RTS7751R2D_1 /* For R2D-1 polling is preferred */
Paul Mundt9c575482007-02-15 18:20:52 +090035 [2] = {
Magnus Damm2eeec852007-08-12 15:29:16 +090036 .start = IRQ_CF_IDE,
Paul Mundt9c575482007-02-15 18:20:52 +090037 .flags = IORESOURCE_IRQ,
38 },
Magnus Dammabac3f72007-11-23 14:39:13 +090039#endif
Paul Mundt9c575482007-02-15 18:20:52 +090040};
41
42static struct pata_platform_info pata_info = {
43 .ioport_shift = 1,
44};
45
46static struct platform_device cf_ide_device = {
47 .name = "pata_platform",
48 .id = -1,
49 .num_resources = ARRAY_SIZE(cf_ide_resources),
50 .resource = cf_ide_resources,
51 .dev = {
52 .platform_data = &pata_info,
53 },
54};
55
Magnus Dammf8b40d82007-08-12 15:30:40 +090056static struct resource heartbeat_resources[] = {
57 [0] = {
58 .start = PA_OUTPORT,
Paul Mundta1fd3062007-08-23 15:11:44 +090059 .end = PA_OUTPORT,
Magnus Dammf8b40d82007-08-12 15:30:40 +090060 .flags = IORESOURCE_MEM,
61 },
62};
63
64static struct platform_device heartbeat_device = {
65 .name = "heartbeat",
66 .id = -1,
67 .num_resources = ARRAY_SIZE(heartbeat_resources),
68 .resource = heartbeat_resources,
69};
70
71#ifdef CONFIG_MFD_SM501
Paul Mundt9c575482007-02-15 18:20:52 +090072static struct plat_serial8250_port uart_platform_data[] = {
73 {
Magnus Damm29ec6772008-01-15 12:47:53 +090074 .membase = (void __iomem *)0xb3e30000,
75 .mapbase = 0xb3e30000,
Paul Mundt9c575482007-02-15 18:20:52 +090076 .iotype = UPIO_MEM,
Magnus Damm29ec6772008-01-15 12:47:53 +090077 .irq = IRQ_VOYAGER,
78 .flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ,
Paul Mundt9c575482007-02-15 18:20:52 +090079 .regshift = 2,
80 .uartclk = (9600 * 16),
Magnus Damm3a353822007-07-20 16:34:22 +090081 },
82 { 0 },
Paul Mundt9c575482007-02-15 18:20:52 +090083};
84
Paul Mundtade2b3f2006-09-27 16:48:46 +090085static struct platform_device uart_device = {
86 .name = "serial8250",
Paul Mundt9c575482007-02-15 18:20:52 +090087 .id = PLAT8250_DEV_PLATFORM,
Paul Mundtade2b3f2006-09-27 16:48:46 +090088 .dev = {
89 .platform_data = uart_platform_data,
90 },
91};
92
Paul Mundtc87a7112007-03-01 18:47:08 +090093static struct resource sm501_resources[] = {
94 [0] = {
95 .start = 0x10000000,
96 .end = 0x13e00000 - 1,
97 .flags = IORESOURCE_MEM,
98 },
99 [1] = {
100 .start = 0x13e00000,
101 .end = 0x13ffffff,
102 .flags = IORESOURCE_MEM,
103 },
104 [2] = {
Magnus Damm29ec6772008-01-15 12:47:53 +0900105 .start = IRQ_VOYAGER,
Paul Mundtc87a7112007-03-01 18:47:08 +0900106 .flags = IORESOURCE_IRQ,
107 },
108};
109
Magnus Dammcbd10df2008-01-15 12:44:44 +0900110static struct fb_videomode sm501_default_mode = {
111 .pixclock = 35714,
112 .xres = 640,
113 .yres = 480,
114 .left_margin = 105,
115 .right_margin = 50,
116 .upper_margin = 35,
117 .lower_margin = 0,
118 .hsync_len = 96,
119 .vsync_len = 2,
120 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
121};
122
123static struct sm501_platdata_fbsub sm501_pdata_fbsub_pnl = {
124 .def_bpp = 16,
125 .def_mode = &sm501_default_mode,
126 .flags = SM501FB_FLAG_USE_INIT_MODE |
127 SM501FB_FLAG_USE_HWCURSOR |
128 SM501FB_FLAG_USE_HWACCEL |
129 SM501FB_FLAG_DISABLE_AT_EXIT,
130};
131
132static struct sm501_platdata_fbsub sm501_pdata_fbsub_crt = {
133 .flags = (SM501FB_FLAG_USE_INIT_MODE |
134 SM501FB_FLAG_USE_HWCURSOR |
135 SM501FB_FLAG_USE_HWACCEL |
136 SM501FB_FLAG_DISABLE_AT_EXIT),
137
138};
139
140static struct sm501_platdata_fb sm501_fb_pdata = {
141 .fb_route = SM501_FB_OWN,
142 .fb_crt = &sm501_pdata_fbsub_crt,
143 .fb_pnl = &sm501_pdata_fbsub_pnl,
144 .flags = SM501_FBPD_SWAP_FB_ENDIAN,
145};
146
Magnus Damm29ec6772008-01-15 12:47:53 +0900147static struct sm501_initdata sm501_initdata = {
148 .gpio_high = {
149 .set = 0x00001fe0,
150 .mask = 0x0,
151 },
Magnus Dammd1eea502008-01-15 12:48:15 +0900152 .devices = SM501_USE_USB_HOST,
Magnus Damm29ec6772008-01-15 12:47:53 +0900153};
154
Magnus Dammcbd10df2008-01-15 12:44:44 +0900155static struct sm501_platdata sm501_platform_data = {
Magnus Damm29ec6772008-01-15 12:47:53 +0900156 .init = &sm501_initdata,
Magnus Dammcbd10df2008-01-15 12:44:44 +0900157 .fb = &sm501_fb_pdata,
158};
159
Paul Mundtc87a7112007-03-01 18:47:08 +0900160static struct platform_device sm501_device = {
161 .name = "sm501",
162 .id = -1,
Magnus Dammcbd10df2008-01-15 12:44:44 +0900163 .dev = {
164 .platform_data = &sm501_platform_data,
165 },
Paul Mundtc87a7112007-03-01 18:47:08 +0900166 .num_resources = ARRAY_SIZE(sm501_resources),
167 .resource = sm501_resources,
168};
169
Magnus Dammf8b40d82007-08-12 15:30:40 +0900170#endif /* CONFIG_MFD_SM501 */
171
Paul Mundtade2b3f2006-09-27 16:48:46 +0900172static struct platform_device *rts7751r2d_devices[] __initdata = {
Magnus Dammf8b40d82007-08-12 15:30:40 +0900173#ifdef CONFIG_MFD_SM501
Paul Mundtade2b3f2006-09-27 16:48:46 +0900174 &uart_device,
Paul Mundtc87a7112007-03-01 18:47:08 +0900175 &sm501_device,
Magnus Dammf8b40d82007-08-12 15:30:40 +0900176#endif
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +0900177 &cf_ide_device,
Magnus Dammf8b40d82007-08-12 15:30:40 +0900178 &heartbeat_device,
Paul Mundtade2b3f2006-09-27 16:48:46 +0900179};
180
181static int __init rts7751r2d_devices_setup(void)
182{
183 return platform_add_devices(rts7751r2d_devices,
184 ARRAY_SIZE(rts7751r2d_devices));
185}
Paul Mundt9c575482007-02-15 18:20:52 +0900186__initcall(rts7751r2d_devices_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Paul Mundta56d2762006-09-27 11:43:24 +0900188static void rts7751r2d_power_off(void)
189{
190 ctrl_outw(0x0001, PA_POWOFF);
191}
192
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +0900193static inline unsigned char is_ide_ioaddr(unsigned long addr)
194{
195 return ((cf_ide_resources[0].start <= addr &&
196 addr <= cf_ide_resources[0].end) ||
197 (cf_ide_resources[1].start <= addr &&
198 addr <= cf_ide_resources[1].end));
199}
200
Paul Mundt02353f52007-09-21 15:21:55 +0900201void rts7751r2d_writeb(u8 b, void __iomem *addr)
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +0900202{
203 unsigned long tmp = (unsigned long __force)addr;
204
205 if (is_ide_ioaddr(tmp))
206 ctrl_outw((u16)b, tmp);
207 else
208 ctrl_outb(b, tmp);
209}
210
Paul Mundt02353f52007-09-21 15:21:55 +0900211u8 rts7751r2d_readb(void __iomem *addr)
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +0900212{
213 unsigned long tmp = (unsigned long __force)addr;
214
215 if (is_ide_ioaddr(tmp))
216 return ctrl_inw(tmp) & 0xff;
217 else
218 return ctrl_inb(tmp);
219}
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/*
222 * Initialize the board
223 */
Paul Mundt2c7834a2006-09-27 18:17:31 +0900224static void __init rts7751r2d_setup(char **cmdline_p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
Magnus Damm29ec6772008-01-15 12:47:53 +0900226 void __iomem *sm501_reg;
Paul Mundt9c575482007-02-15 18:20:52 +0900227 u16 ver = ctrl_inw(PA_VERREG);
228
229 printk(KERN_INFO "Renesas Technology Sales RTS7751R2D support.\n");
230
231 printk(KERN_INFO "FPGA version:%d (revision:%d)\n",
232 (ver >> 4) & 0xf, ver & 0xf);
Paul Mundt2c7834a2006-09-27 18:17:31 +0900233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 ctrl_outw(0x0000, PA_OUTPORT);
Paul Mundta56d2762006-09-27 11:43:24 +0900235 pm_power_off = rts7751r2d_power_off;
Paul Mundtade2b3f2006-09-27 16:48:46 +0900236
Magnus Damm29ec6772008-01-15 12:47:53 +0900237 /* sm501 dram configuration:
238 * ColSizeX = 11 - External Memory Column Size: 256 words.
239 * APX = 1 - External Memory Active to Pre-Charge Delay: 7 clocks.
240 * RstX = 1 - External Memory Reset: Normal.
241 * Rfsh = 1 - Local Memory Refresh to Command Delay: 12 clocks.
242 * BwC = 1 - Local Memory Block Write Cycle Time: 2 clocks.
243 * BwP = 1 - Local Memory Block Write to Pre-Charge Delay: 1 clock.
244 * AP = 1 - Internal Memory Active to Pre-Charge Delay: 7 clocks.
245 * Rst = 1 - Internal Memory Reset: Normal.
246 * RA = 1 - Internal Memory Remain in Active State: Do not remain.
247 */
248
249 sm501_reg = (void __iomem *)0xb3e00000 + SM501_DRAM_CONTROL;
250 writel(readl(sm501_reg) | 0x00f107c0, sm501_reg);
251
252 /*
253 * Power Mode Gate - Enable UART0
254 */
255
256 sm501_reg = (void __iomem *)0xb3e00000 + SM501_POWER_MODE_0_GATE;
257 writel(readl(sm501_reg) | (1 << SM501_GATE_UART0), sm501_reg);
258
259 sm501_reg = (void __iomem *)0xb3e00000 + SM501_POWER_MODE_1_GATE;
260 writel(readl(sm501_reg) | (1 << SM501_GATE_UART0), sm501_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261}
Paul Mundt2c7834a2006-09-27 18:17:31 +0900262
263/*
264 * The Machine Vector
265 */
Paul Mundt82f81f42007-05-15 15:19:34 +0900266static struct sh_machine_vector mv_rts7751r2d __initmv = {
Paul Mundt2c7834a2006-09-27 18:17:31 +0900267 .mv_name = "RTS7751R2D",
268 .mv_setup = rts7751r2d_setup,
Paul Mundt2c7834a2006-09-27 18:17:31 +0900269 .mv_init_irq = init_rts7751r2d_IRQ,
Paul Mundt2c7834a2006-09-27 18:17:31 +0900270 .mv_irq_demux = rts7751r2d_irq_demux,
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +0900271 .mv_writeb = rts7751r2d_writeb,
272 .mv_readb = rts7751r2d_readb,
Paul Mundt2c7834a2006-09-27 18:17:31 +0900273};