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