Merge branch 'pxa' into devel
[linux-2.6] / arch / sh / boards / renesas / migor / setup.c
1 /*
2  * Renesas System Solutions Asia Pte. Ltd - Migo-R
3  *
4  * Copyright (C) 2008 Magnus Damm
5  *
6  * This file is subject to the terms and conditions of the GNU General Public
7  * License.  See the file "COPYING" in the main directory of this archive
8  * for more details.
9  */
10 #include <linux/init.h>
11 #include <linux/platform_device.h>
12 #include <linux/interrupt.h>
13 #include <linux/input.h>
14 #include <linux/mtd/physmap.h>
15 #include <linux/mtd/nand.h>
16 #include <linux/i2c.h>
17 #include <linux/smc91x.h>
18 #include <asm/machvec.h>
19 #include <asm/io.h>
20 #include <asm/sh_keysc.h>
21 #include <asm/migor.h>
22
23 /* Address     IRQ  Size  Bus  Description
24  * 0x00000000       64MB  16   NOR Flash (SP29PL256N)
25  * 0x0c000000       64MB  64   SDRAM (2xK4M563233G)
26  * 0x10000000  IRQ0       16   Ethernet (SMC91C111)
27  * 0x14000000  IRQ4       16   USB 2.0 Host Controller (M66596)
28  * 0x18000000       8GB    8   NAND Flash (K9K8G08U0A)
29  */
30
31 static struct smc91x_platdata smc91x_info = {
32         .flags = SMC91X_USE_16BIT,
33 };
34
35 static struct resource smc91x_eth_resources[] = {
36         [0] = {
37                 .name   = "SMC91C111" ,
38                 .start  = 0x10000300,
39                 .end    = 0x1000030f,
40                 .flags  = IORESOURCE_MEM,
41         },
42         [1] = {
43                 .start  = 32, /* IRQ0 */
44                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
45         },
46 };
47
48 static struct platform_device smc91x_eth_device = {
49         .name           = "smc91x",
50         .num_resources  = ARRAY_SIZE(smc91x_eth_resources),
51         .resource       = smc91x_eth_resources,
52         .dev    = {
53                 .platform_data  = &smc91x_info,
54         },
55 };
56
57 static struct sh_keysc_info sh_keysc_info = {
58         .mode = SH_KEYSC_MODE_2, /* KEYOUT0->4, KEYIN1->5 */
59         .scan_timing = 3,
60         .delay = 5,
61         .keycodes = {
62                 0, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_ENTER,
63                 0, KEY_F, KEY_C, KEY_D, KEY_H, KEY_1,
64                 0, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6,
65                 0, KEY_7, KEY_8, KEY_9, KEY_S, KEY_0,
66                 0, KEY_P, KEY_STOP, KEY_REWIND, KEY_PLAY, KEY_FASTFORWARD,
67         },
68 };
69
70 static struct resource sh_keysc_resources[] = {
71         [0] = {
72                 .start  = 0x044b0000,
73                 .end    = 0x044b000f,
74                 .flags  = IORESOURCE_MEM,
75         },
76         [1] = {
77                 .start  = 79,
78                 .flags  = IORESOURCE_IRQ,
79         },
80 };
81
82 static struct platform_device sh_keysc_device = {
83         .name           = "sh_keysc",
84         .num_resources  = ARRAY_SIZE(sh_keysc_resources),
85         .resource       = sh_keysc_resources,
86         .dev    = {
87                 .platform_data  = &sh_keysc_info,
88         },
89 };
90
91 static struct mtd_partition migor_nor_flash_partitions[] =
92 {
93         {
94                 .name = "uboot",
95                 .offset = 0,
96                 .size = (1 * 1024 * 1024),
97                 .mask_flags = MTD_WRITEABLE,    /* Read-only */
98         },
99         {
100                 .name = "rootfs",
101                 .offset = MTDPART_OFS_APPEND,
102                 .size = (15 * 1024 * 1024),
103         },
104         {
105                 .name = "other",
106                 .offset = MTDPART_OFS_APPEND,
107                 .size = MTDPART_SIZ_FULL,
108         },
109 };
110
111 static struct physmap_flash_data migor_nor_flash_data = {
112         .width          = 2,
113         .parts          = migor_nor_flash_partitions,
114         .nr_parts       = ARRAY_SIZE(migor_nor_flash_partitions),
115 };
116
117 static struct resource migor_nor_flash_resources[] = {
118         [0] = {
119                 .name           = "NOR Flash",
120                 .start          = 0x00000000,
121                 .end            = 0x03ffffff,
122                 .flags          = IORESOURCE_MEM,
123         }
124 };
125
126 static struct platform_device migor_nor_flash_device = {
127         .name           = "physmap-flash",
128         .resource       = migor_nor_flash_resources,
129         .num_resources  = ARRAY_SIZE(migor_nor_flash_resources),
130         .dev            = {
131                 .platform_data = &migor_nor_flash_data,
132         },
133 };
134
135 static struct mtd_partition migor_nand_flash_partitions[] = {
136         {
137                 .name           = "nanddata1",
138                 .offset         = 0x0,
139                 .size           = 512 * 1024 * 1024,
140         },
141         {
142                 .name           = "nanddata2",
143                 .offset         = MTDPART_OFS_APPEND,
144                 .size           = 512 * 1024 * 1024,
145         },
146 };
147
148 static void migor_nand_flash_cmd_ctl(struct mtd_info *mtd, int cmd,
149                                      unsigned int ctrl)
150 {
151         struct nand_chip *chip = mtd->priv;
152
153         if (cmd == NAND_CMD_NONE)
154                 return;
155
156         if (ctrl & NAND_CLE)
157                 writeb(cmd, chip->IO_ADDR_W + 0x00400000);
158         else if (ctrl & NAND_ALE)
159                 writeb(cmd, chip->IO_ADDR_W + 0x00800000);
160         else
161                 writeb(cmd, chip->IO_ADDR_W);
162 }
163
164 static int migor_nand_flash_ready(struct mtd_info *mtd)
165 {
166         return ctrl_inb(PORT_PADR) & 0x02; /* PTA1 */
167 }
168
169 struct platform_nand_data migor_nand_flash_data = {
170         .chip = {
171                 .nr_chips = 1,
172                 .partitions = migor_nand_flash_partitions,
173                 .nr_partitions = ARRAY_SIZE(migor_nand_flash_partitions),
174                 .chip_delay = 20,
175                 .part_probe_types = (const char *[]) { "cmdlinepart", NULL },
176         },
177         .ctrl = {
178                 .dev_ready = migor_nand_flash_ready,
179                 .cmd_ctrl = migor_nand_flash_cmd_ctl,
180         },
181 };
182
183 static struct resource migor_nand_flash_resources[] = {
184         [0] = {
185                 .name           = "NAND Flash",
186                 .start          = 0x18000000,
187                 .end            = 0x18ffffff,
188                 .flags          = IORESOURCE_MEM,
189         },
190 };
191
192 static struct platform_device migor_nand_flash_device = {
193         .name           = "gen_nand",
194         .resource       = migor_nand_flash_resources,
195         .num_resources  = ARRAY_SIZE(migor_nand_flash_resources),
196         .dev            = {
197                 .platform_data = &migor_nand_flash_data,
198         }
199 };
200
201 static struct platform_device *migor_devices[] __initdata = {
202         &smc91x_eth_device,
203         &sh_keysc_device,
204         &migor_nor_flash_device,
205         &migor_nand_flash_device,
206 };
207
208 static struct i2c_board_info __initdata migor_i2c_devices[] = {
209         {
210                 I2C_BOARD_INFO("rs5c372b", 0x32),
211         },
212         {
213                 I2C_BOARD_INFO("migor_ts", 0x51),
214                 .irq = 38, /* IRQ6 */
215         },
216 };
217
218 static int __init migor_devices_setup(void)
219 {
220         i2c_register_board_info(0, migor_i2c_devices,
221                                 ARRAY_SIZE(migor_i2c_devices));
222  
223         return platform_add_devices(migor_devices, ARRAY_SIZE(migor_devices));
224 }
225 __initcall(migor_devices_setup);
226
227 static void __init migor_setup(char **cmdline_p)
228 {
229         /* SMC91C111 - Enable IRQ0 */
230         ctrl_outw(ctrl_inw(PORT_PJCR) & ~0x0003, PORT_PJCR);
231
232         /* KEYSC */
233         ctrl_outw(ctrl_inw(PORT_PYCR) & ~0x0fff, PORT_PYCR);
234         ctrl_outw(ctrl_inw(PORT_PZCR) & ~0x0ff0, PORT_PZCR);
235         ctrl_outw(ctrl_inw(PORT_PSELA) & ~0x4100, PORT_PSELA);
236         ctrl_outw(ctrl_inw(PORT_HIZCRA) & ~0x4000, PORT_HIZCRA);
237         ctrl_outw(ctrl_inw(PORT_HIZCRC) & ~0xc000, PORT_HIZCRC);
238         ctrl_outl(ctrl_inl(MSTPCR2) & ~0x00004000, MSTPCR2);
239
240         /* NAND Flash */
241         ctrl_outw(ctrl_inw(PORT_PXCR) & 0x0fff, PORT_PXCR);
242         ctrl_outl((ctrl_inl(BSC_CS6ABCR) & ~0x00000600) | 0x00000200,
243                   BSC_CS6ABCR);
244
245         /* I2C */
246         ctrl_outl(ctrl_inl(MSTPCR1) & ~0x00000200, MSTPCR1);
247
248         /* Touch Panel - Enable IRQ6 */
249         ctrl_outw(ctrl_inw(PORT_PZCR) & ~0xc, PORT_PZCR);
250         ctrl_outw((ctrl_inw(PORT_PSELA) | 0x8000), PORT_PSELA);
251         ctrl_outw((ctrl_inw(PORT_HIZCRC) & ~0x4000), PORT_HIZCRC);
252 }
253
254 static struct sh_machine_vector mv_migor __initmv = {
255         .mv_name                = "Migo-R",
256         .mv_setup               = migor_setup,
257 };