Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
[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         .irq_flags = IRQF_TRIGGER_HIGH,
34 };
35
36 static struct resource smc91x_eth_resources[] = {
37         [0] = {
38                 .name   = "SMC91C111" ,
39                 .start  = 0x10000300,
40                 .end    = 0x1000030f,
41                 .flags  = IORESOURCE_MEM,
42         },
43         [1] = {
44                 .start  = 32, /* IRQ0 */
45                 .flags  = IORESOURCE_IRQ,
46         },
47 };
48
49 static struct platform_device smc91x_eth_device = {
50         .name           = "smc91x",
51         .num_resources  = ARRAY_SIZE(smc91x_eth_resources),
52         .resource       = smc91x_eth_resources,
53         .dev    = {
54                 .platform_data  = &smc91x_info,
55         },
56 };
57
58 static struct sh_keysc_info sh_keysc_info = {
59         .mode = SH_KEYSC_MODE_2, /* KEYOUT0->4, KEYIN1->5 */
60         .scan_timing = 3,
61         .delay = 5,
62         .keycodes = {
63                 0, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_ENTER,
64                 0, KEY_F, KEY_C, KEY_D, KEY_H, KEY_1,
65                 0, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6,
66                 0, KEY_7, KEY_8, KEY_9, KEY_S, KEY_0,
67                 0, KEY_P, KEY_STOP, KEY_REWIND, KEY_PLAY, KEY_FASTFORWARD,
68         },
69 };
70
71 static struct resource sh_keysc_resources[] = {
72         [0] = {
73                 .start  = 0x044b0000,
74                 .end    = 0x044b000f,
75                 .flags  = IORESOURCE_MEM,
76         },
77         [1] = {
78                 .start  = 79,
79                 .flags  = IORESOURCE_IRQ,
80         },
81 };
82
83 static struct platform_device sh_keysc_device = {
84         .name           = "sh_keysc",
85         .num_resources  = ARRAY_SIZE(sh_keysc_resources),
86         .resource       = sh_keysc_resources,
87         .dev    = {
88                 .platform_data  = &sh_keysc_info,
89         },
90 };
91
92 static struct mtd_partition migor_nor_flash_partitions[] =
93 {
94         {
95                 .name = "uboot",
96                 .offset = 0,
97                 .size = (1 * 1024 * 1024),
98                 .mask_flags = MTD_WRITEABLE,    /* Read-only */
99         },
100         {
101                 .name = "rootfs",
102                 .offset = MTDPART_OFS_APPEND,
103                 .size = (15 * 1024 * 1024),
104         },
105         {
106                 .name = "other",
107                 .offset = MTDPART_OFS_APPEND,
108                 .size = MTDPART_SIZ_FULL,
109         },
110 };
111
112 static struct physmap_flash_data migor_nor_flash_data = {
113         .width          = 2,
114         .parts          = migor_nor_flash_partitions,
115         .nr_parts       = ARRAY_SIZE(migor_nor_flash_partitions),
116 };
117
118 static struct resource migor_nor_flash_resources[] = {
119         [0] = {
120                 .name           = "NOR Flash",
121                 .start          = 0x00000000,
122                 .end            = 0x03ffffff,
123                 .flags          = IORESOURCE_MEM,
124         }
125 };
126
127 static struct platform_device migor_nor_flash_device = {
128         .name           = "physmap-flash",
129         .resource       = migor_nor_flash_resources,
130         .num_resources  = ARRAY_SIZE(migor_nor_flash_resources),
131         .dev            = {
132                 .platform_data = &migor_nor_flash_data,
133         },
134 };
135
136 static struct mtd_partition migor_nand_flash_partitions[] = {
137         {
138                 .name           = "nanddata1",
139                 .offset         = 0x0,
140                 .size           = 512 * 1024 * 1024,
141         },
142         {
143                 .name           = "nanddata2",
144                 .offset         = MTDPART_OFS_APPEND,
145                 .size           = 512 * 1024 * 1024,
146         },
147 };
148
149 static void migor_nand_flash_cmd_ctl(struct mtd_info *mtd, int cmd,
150                                      unsigned int ctrl)
151 {
152         struct nand_chip *chip = mtd->priv;
153
154         if (cmd == NAND_CMD_NONE)
155                 return;
156
157         if (ctrl & NAND_CLE)
158                 writeb(cmd, chip->IO_ADDR_W + 0x00400000);
159         else if (ctrl & NAND_ALE)
160                 writeb(cmd, chip->IO_ADDR_W + 0x00800000);
161         else
162                 writeb(cmd, chip->IO_ADDR_W);
163 }
164
165 static int migor_nand_flash_ready(struct mtd_info *mtd)
166 {
167         return ctrl_inb(PORT_PADR) & 0x02; /* PTA1 */
168 }
169
170 struct platform_nand_data migor_nand_flash_data = {
171         .chip = {
172                 .nr_chips = 1,
173                 .partitions = migor_nand_flash_partitions,
174                 .nr_partitions = ARRAY_SIZE(migor_nand_flash_partitions),
175                 .chip_delay = 20,
176                 .part_probe_types = (const char *[]) { "cmdlinepart", NULL },
177         },
178         .ctrl = {
179                 .dev_ready = migor_nand_flash_ready,
180                 .cmd_ctrl = migor_nand_flash_cmd_ctl,
181         },
182 };
183
184 static struct resource migor_nand_flash_resources[] = {
185         [0] = {
186                 .name           = "NAND Flash",
187                 .start          = 0x18000000,
188                 .end            = 0x18ffffff,
189                 .flags          = IORESOURCE_MEM,
190         },
191 };
192
193 static struct platform_device migor_nand_flash_device = {
194         .name           = "gen_nand",
195         .resource       = migor_nand_flash_resources,
196         .num_resources  = ARRAY_SIZE(migor_nand_flash_resources),
197         .dev            = {
198                 .platform_data = &migor_nand_flash_data,
199         }
200 };
201
202 static struct platform_device *migor_devices[] __initdata = {
203         &smc91x_eth_device,
204         &sh_keysc_device,
205         &migor_nor_flash_device,
206         &migor_nand_flash_device,
207 };
208
209 static struct i2c_board_info __initdata migor_i2c_devices[] = {
210         {
211                 I2C_BOARD_INFO("rs5c372b", 0x32),
212         },
213         {
214                 I2C_BOARD_INFO("migor_ts", 0x51),
215                 .irq = 38, /* IRQ6 */
216         },
217 };
218
219 static int __init migor_devices_setup(void)
220 {
221         i2c_register_board_info(0, migor_i2c_devices,
222                                 ARRAY_SIZE(migor_i2c_devices));
223  
224         return platform_add_devices(migor_devices, ARRAY_SIZE(migor_devices));
225 }
226 __initcall(migor_devices_setup);
227
228 static void __init migor_setup(char **cmdline_p)
229 {
230         /* SMC91C111 - Enable IRQ0 */
231         ctrl_outw(ctrl_inw(PORT_PJCR) & ~0x0003, PORT_PJCR);
232
233         /* KEYSC */
234         ctrl_outw(ctrl_inw(PORT_PYCR) & ~0x0fff, PORT_PYCR);
235         ctrl_outw(ctrl_inw(PORT_PZCR) & ~0x0ff0, PORT_PZCR);
236         ctrl_outw(ctrl_inw(PORT_PSELA) & ~0x4100, PORT_PSELA);
237         ctrl_outw(ctrl_inw(PORT_HIZCRA) & ~0x4000, PORT_HIZCRA);
238         ctrl_outw(ctrl_inw(PORT_HIZCRC) & ~0xc000, PORT_HIZCRC);
239         ctrl_outl(ctrl_inl(MSTPCR2) & ~0x00004000, MSTPCR2);
240
241         /* NAND Flash */
242         ctrl_outw(ctrl_inw(PORT_PXCR) & 0x0fff, PORT_PXCR);
243         ctrl_outl((ctrl_inl(BSC_CS6ABCR) & ~0x00000600) | 0x00000200,
244                   BSC_CS6ABCR);
245
246         /* I2C */
247         ctrl_outl(ctrl_inl(MSTPCR1) & ~0x00000200, MSTPCR1);
248
249         /* Touch Panel - Enable IRQ6 */
250         ctrl_outw(ctrl_inw(PORT_PZCR) & ~0xc, PORT_PZCR);
251         ctrl_outw((ctrl_inw(PORT_PSELA) | 0x8000), PORT_PSELA);
252         ctrl_outw((ctrl_inw(PORT_HIZCRC) & ~0x4000), PORT_HIZCRC);
253 }
254
255 static struct sh_machine_vector mv_migor __initmv = {
256         .mv_name                = "Migo-R",
257         .mv_setup               = migor_setup,
258 };