ARM: OMAP2/3: Add generic smc91x support when connected to GPMC
[linux-2.6.git] / arch / arm / mach-omap2 / board-rx51-peripherals.c
1 /*
2  * linux/arch/arm/mach-omap2/board-rx51-flash.c
3  *
4  * Copyright (C) 2008-2009 Nokia
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/input.h>
15 #include <linux/spi/spi.h>
16 #include <linux/i2c.h>
17 #include <linux/i2c/twl4030.h>
18 #include <linux/clk.h>
19 #include <linux/delay.h>
20 #include <linux/regulator/machine.h>
21 #include <linux/gpio.h>
22
23 #include <mach/mcspi.h>
24 #include <mach/mux.h>
25 #include <mach/board.h>
26 #include <mach/common.h>
27 #include <mach/dma.h>
28 #include <mach/gpmc.h>
29 #include <mach/keypad.h>
30 #include <mach/onenand.h>
31 #include <mach/gpmc-smc91x.h>
32
33 #include "mmc-twl4030.h"
34
35 static int rx51_keymap[] = {
36         KEY(0, 0, KEY_Q),
37         KEY(0, 1, KEY_W),
38         KEY(0, 2, KEY_E),
39         KEY(0, 3, KEY_R),
40         KEY(0, 4, KEY_T),
41         KEY(0, 5, KEY_Y),
42         KEY(0, 6, KEY_U),
43         KEY(0, 7, KEY_I),
44         KEY(1, 0, KEY_O),
45         KEY(1, 1, KEY_D),
46         KEY(1, 2, KEY_DOT),
47         KEY(1, 3, KEY_V),
48         KEY(1, 4, KEY_DOWN),
49         KEY(2, 0, KEY_P),
50         KEY(2, 1, KEY_F),
51         KEY(2, 2, KEY_UP),
52         KEY(2, 3, KEY_B),
53         KEY(2, 4, KEY_RIGHT),
54         KEY(3, 0, KEY_COMMA),
55         KEY(3, 1, KEY_G),
56         KEY(3, 2, KEY_ENTER),
57         KEY(3, 3, KEY_N),
58         KEY(4, 0, KEY_BACKSPACE),
59         KEY(4, 1, KEY_H),
60         KEY(4, 3, KEY_M),
61         KEY(4, 4, KEY_LEFTCTRL),
62         KEY(5, 1, KEY_J),
63         KEY(5, 2, KEY_Z),
64         KEY(5, 3, KEY_SPACE),
65         KEY(5, 4, KEY_LEFTSHIFT),
66         KEY(6, 0, KEY_A),
67         KEY(6, 1, KEY_K),
68         KEY(6, 2, KEY_X),
69         KEY(6, 3, KEY_SPACE),
70         KEY(6, 4, KEY_FN),
71         KEY(7, 0, KEY_S),
72         KEY(7, 1, KEY_L),
73         KEY(7, 2, KEY_C),
74         KEY(7, 3, KEY_LEFT),
75         KEY(0xff, 0, KEY_F6),
76         KEY(0xff, 1, KEY_F7),
77         KEY(0xff, 2, KEY_F8),
78         KEY(0xff, 4, KEY_F9),
79         KEY(0xff, 5, KEY_F10),
80 };
81
82 static struct twl4030_keypad_data rx51_kp_data = {
83         .rows           = 8,
84         .cols           = 8,
85         .keymap         = rx51_keymap,
86         .keymapsize     = ARRAY_SIZE(rx51_keymap),
87         .rep            = 1,
88 };
89
90 static struct twl4030_madc_platform_data rx51_madc_data = {
91         .irq_line               = 1,
92 };
93
94 static struct twl4030_hsmmc_info mmc[] = {
95         {
96                 .name           = "external",
97                 .mmc            = 1,
98                 .wires          = 4,
99                 .cover_only     = true,
100                 .gpio_cd        = 160,
101                 .gpio_wp        = -EINVAL,
102         },
103         {
104                 .name           = "internal",
105                 .mmc            = 2,
106                 .wires          = 8,
107                 .gpio_cd        = -EINVAL,
108                 .gpio_wp        = -EINVAL,
109         },
110         {}      /* Terminator */
111 };
112
113 static struct regulator_consumer_supply rx51_vmmc1_supply = {
114         .supply                 = "vmmc",
115 };
116
117 static struct regulator_consumer_supply rx51_vmmc2_supply = {
118         .supply                 = "vmmc",
119 };
120
121 static struct regulator_consumer_supply rx51_vsim_supply = {
122         .supply                 = "vmmc_aux",
123 };
124
125 static struct regulator_init_data rx51_vaux1 = {
126         .constraints = {
127                 .name                   = "V28",
128                 .min_uV                 = 2800000,
129                 .max_uV                 = 2800000,
130                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
131                                         | REGULATOR_MODE_STANDBY,
132                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
133                                         | REGULATOR_CHANGE_STATUS,
134         },
135 };
136
137 static struct regulator_init_data rx51_vaux2 = {
138         .constraints = {
139                 .name                   = "VCSI",
140                 .min_uV                 = 1800000,
141                 .max_uV                 = 1800000,
142                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
143                                         | REGULATOR_MODE_STANDBY,
144                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
145                                         | REGULATOR_CHANGE_STATUS,
146         },
147 };
148
149 /* VAUX3 - adds more power to VIO_18 rail */
150 static struct regulator_init_data rx51_vaux3 = {
151         .constraints = {
152                 .name                   = "VCAM_DIG_18",
153                 .min_uV                 = 1800000,
154                 .max_uV                 = 1800000,
155                 .apply_uV               = true,
156                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
157                                         | REGULATOR_MODE_STANDBY,
158                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
159                                         | REGULATOR_CHANGE_STATUS,
160         },
161 };
162
163 static struct regulator_init_data rx51_vaux4 = {
164         .constraints = {
165                 .name                   = "VCAM_ANA_28",
166                 .min_uV                 = 2800000,
167                 .max_uV                 = 2800000,
168                 .apply_uV               = true,
169                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
170                                         | REGULATOR_MODE_STANDBY,
171                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
172                                         | REGULATOR_CHANGE_STATUS,
173         },
174 };
175
176 static struct regulator_init_data rx51_vmmc1 = {
177         .constraints = {
178                 .min_uV                 = 1850000,
179                 .max_uV                 = 3150000,
180                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
181                                         | REGULATOR_MODE_STANDBY,
182                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
183                                         | REGULATOR_CHANGE_MODE
184                                         | REGULATOR_CHANGE_STATUS,
185         },
186         .num_consumer_supplies  = 1,
187         .consumer_supplies      = &rx51_vmmc1_supply,
188 };
189
190 static struct regulator_init_data rx51_vmmc2 = {
191         .constraints = {
192                 .name                   = "VMMC2_30",
193                 .min_uV                 = 1850000,
194                 .max_uV                 = 3150000,
195                 .apply_uV               = true,
196                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
197                                         | REGULATOR_MODE_STANDBY,
198                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
199                                         | REGULATOR_CHANGE_MODE
200                                         | REGULATOR_CHANGE_STATUS,
201         },
202         .num_consumer_supplies  = 1,
203         .consumer_supplies      = &rx51_vmmc2_supply,
204 };
205
206 static struct regulator_init_data rx51_vsim = {
207         .constraints = {
208                 .name                   = "VMMC2_IO_18",
209                 .min_uV                 = 1800000,
210                 .max_uV                 = 1800000,
211                 .apply_uV               = true,
212                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
213                                         | REGULATOR_MODE_STANDBY,
214                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
215                                         | REGULATOR_CHANGE_STATUS,
216         },
217         .num_consumer_supplies  = 1,
218         .consumer_supplies      = &rx51_vsim_supply,
219 };
220
221 static struct regulator_init_data rx51_vdac = {
222         .constraints = {
223                 .min_uV                 = 1800000,
224                 .max_uV                 = 1800000,
225                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
226                                         | REGULATOR_MODE_STANDBY,
227                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
228                                         | REGULATOR_CHANGE_MODE
229                                         | REGULATOR_CHANGE_STATUS,
230         },
231 };
232
233 static int rx51_twlgpio_setup(struct device *dev, unsigned gpio, unsigned n)
234 {
235         /* FIXME this gpio setup is just a placeholder for now */
236         gpio_request(gpio + 6, "backlight_pwm");
237         gpio_direction_output(gpio + 6, 0);
238         gpio_request(gpio + 7, "speaker_en");
239         gpio_direction_output(gpio + 7, 1);
240
241         /* set up MMC adapters, linking their regulators to them */
242         twl4030_mmc_init(mmc);
243         rx51_vmmc1_supply.dev = mmc[0].dev;
244         rx51_vmmc2_supply.dev = mmc[1].dev;
245         rx51_vsim_supply.dev = mmc[1].dev;
246
247         return 0;
248 }
249
250 static struct twl4030_gpio_platform_data rx51_gpio_data = {
251         .gpio_base              = OMAP_MAX_GPIO_LINES,
252         .irq_base               = TWL4030_GPIO_IRQ_BASE,
253         .irq_end                = TWL4030_GPIO_IRQ_END,
254         .pulldowns              = BIT(0) | BIT(1) | BIT(2) | BIT(3)
255                                 | BIT(4) | BIT(5)
256                                 | BIT(8) | BIT(9) | BIT(10) | BIT(11)
257                                 | BIT(12) | BIT(13) | BIT(14) | BIT(15)
258                                 | BIT(16) | BIT(17) ,
259         .setup                  = rx51_twlgpio_setup,
260 };
261
262 static struct twl4030_platform_data rx51_twldata = {
263         .irq_base               = TWL4030_IRQ_BASE,
264         .irq_end                = TWL4030_IRQ_END,
265
266         /* platform_data for children goes here */
267         .gpio                   = &rx51_gpio_data,
268         .keypad                 = &rx51_kp_data,
269         .madc                   = &rx51_madc_data,
270
271         .vaux1                  = &rx51_vaux1,
272         .vaux2                  = &rx51_vaux2,
273         .vaux3                  = &rx51_vaux3,
274         .vaux4                  = &rx51_vaux4,
275         .vmmc1                  = &rx51_vmmc1,
276         .vmmc2                  = &rx51_vmmc2,
277         .vsim                   = &rx51_vsim,
278         .vdac                   = &rx51_vdac,
279 };
280
281 static struct i2c_board_info __initdata rx51_peripherals_i2c_board_info_1[] = {
282         {
283                 I2C_BOARD_INFO("twl5030", 0x48),
284                 .flags = I2C_CLIENT_WAKE,
285                 .irq = INT_34XX_SYS_NIRQ,
286                 .platform_data = &rx51_twldata,
287         },
288 };
289
290 static int __init rx51_i2c_init(void)
291 {
292         omap_register_i2c_bus(1, 2600, rx51_peripherals_i2c_board_info_1,
293                         ARRAY_SIZE(rx51_peripherals_i2c_board_info_1));
294         omap_register_i2c_bus(2, 100, NULL, 0);
295         omap_register_i2c_bus(3, 400, NULL, 0);
296         return 0;
297 }
298
299 #if defined(CONFIG_MTD_ONENAND_OMAP2) || \
300         defined(CONFIG_MTD_ONENAND_OMAP2_MODULE)
301
302 static struct mtd_partition onenand_partitions[] = {
303         {
304                 .name           = "bootloader",
305                 .offset         = 0,
306                 .size           = 0x20000,
307                 .mask_flags     = MTD_WRITEABLE,        /* Force read-only */
308         },
309         {
310                 .name           = "config",
311                 .offset         = MTDPART_OFS_APPEND,
312                 .size           = 0x60000,
313         },
314         {
315                 .name           = "log",
316                 .offset         = MTDPART_OFS_APPEND,
317                 .size           = 0x40000,
318         },
319         {
320                 .name           = "kernel",
321                 .offset         = MTDPART_OFS_APPEND,
322                 .size           = 0x200000,
323         },
324         {
325                 .name           = "initfs",
326                 .offset         = MTDPART_OFS_APPEND,
327                 .size           = 0x200000,
328         },
329         {
330                 .name           = "rootfs",
331                 .offset         = MTDPART_OFS_APPEND,
332                 .size           = MTDPART_SIZ_FULL,
333         },
334 };
335
336 static struct omap_onenand_platform_data board_onenand_data = {
337         .cs             = 0,
338         .gpio_irq       = 65,
339         .parts          = onenand_partitions,
340         .nr_parts       = ARRAY_SIZE(onenand_partitions),
341 };
342
343 static void __init board_onenand_init(void)
344 {
345         gpmc_onenand_init(&board_onenand_data);
346 }
347
348 #else
349
350 static inline void board_onenand_init(void)
351 {
352 }
353
354 #endif
355
356 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
357
358 static struct omap_smc91x_platform_data board_smc91x_data = {
359         .cs             = 1,
360         .gpio_irq       = 54,
361         .gpio_pwrdwn    = 86,
362         .gpio_reset     = 164,
363         .flags          = GPMC_TIMINGS_SMC91C96 | IORESOURCE_IRQ_HIGHLEVEL,
364 };
365
366 static void __init board_smc91x_init(void)
367 {
368         omap_cfg_reg(U8_34XX_GPIO54_DOWN);
369         omap_cfg_reg(G25_34XX_GPIO86_OUT);
370         omap_cfg_reg(H19_34XX_GPIO164_OUT);
371
372         gpmc_smc91x_init(&board_smc91x_data);
373 }
374
375 #else
376
377 static inline void board_smc91x_init(void)
378 {
379 }
380
381 #endif
382
383 void __init rx51_peripherals_init(void)
384 {
385         rx51_i2c_init();
386         board_onenand_init();
387         board_smc91x_init();
388 }
389