blob: ca18ae94185a4aaaec600cbab9d5a76933f753a5 [file] [log] [blame]
Lauri Leukkunenffe7f952009-03-23 18:38:17 -07001/*
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>
Juha Yrjolaaa62e902009-05-28 13:23:52 -070030#include <mach/onenand.h>
Lauri Leukkunenffe7f952009-03-23 18:38:17 -070031
32#include "mmc-twl4030.h"
33
34
35#define SMC91X_CS 1
36#define SMC91X_GPIO_IRQ 54
37#define SMC91X_GPIO_RESET 164
38#define SMC91X_GPIO_PWRDWN 86
39
40static struct resource rx51_smc91x_resources[] = {
41 [0] = {
42 .flags = IORESOURCE_MEM,
43 },
44 [1] = {
45 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
46 },
47};
48
49static struct platform_device rx51_smc91x_device = {
50 .name = "smc91x",
51 .id = -1,
52 .num_resources = ARRAY_SIZE(rx51_smc91x_resources),
53 .resource = rx51_smc91x_resources,
54};
55
56static int rx51_keymap[] = {
57 KEY(0, 0, KEY_Q),
58 KEY(0, 1, KEY_W),
59 KEY(0, 2, KEY_E),
60 KEY(0, 3, KEY_R),
61 KEY(0, 4, KEY_T),
62 KEY(0, 5, KEY_Y),
63 KEY(0, 6, KEY_U),
64 KEY(0, 7, KEY_I),
65 KEY(1, 0, KEY_O),
66 KEY(1, 1, KEY_D),
67 KEY(1, 2, KEY_DOT),
68 KEY(1, 3, KEY_V),
69 KEY(1, 4, KEY_DOWN),
70 KEY(2, 0, KEY_P),
71 KEY(2, 1, KEY_F),
72 KEY(2, 2, KEY_UP),
73 KEY(2, 3, KEY_B),
74 KEY(2, 4, KEY_RIGHT),
75 KEY(3, 0, KEY_COMMA),
76 KEY(3, 1, KEY_G),
77 KEY(3, 2, KEY_ENTER),
78 KEY(3, 3, KEY_N),
79 KEY(4, 0, KEY_BACKSPACE),
80 KEY(4, 1, KEY_H),
81 KEY(4, 3, KEY_M),
82 KEY(4, 4, KEY_LEFTCTRL),
83 KEY(5, 1, KEY_J),
84 KEY(5, 2, KEY_Z),
85 KEY(5, 3, KEY_SPACE),
86 KEY(5, 4, KEY_LEFTSHIFT),
87 KEY(6, 0, KEY_A),
88 KEY(6, 1, KEY_K),
89 KEY(6, 2, KEY_X),
90 KEY(6, 3, KEY_SPACE),
91 KEY(6, 4, KEY_FN),
92 KEY(7, 0, KEY_S),
93 KEY(7, 1, KEY_L),
94 KEY(7, 2, KEY_C),
95 KEY(7, 3, KEY_LEFT),
96 KEY(0xff, 0, KEY_F6),
97 KEY(0xff, 1, KEY_F7),
98 KEY(0xff, 2, KEY_F8),
99 KEY(0xff, 4, KEY_F9),
100 KEY(0xff, 5, KEY_F10),
101};
102
103static struct twl4030_keypad_data rx51_kp_data = {
104 .rows = 8,
105 .cols = 8,
106 .keymap = rx51_keymap,
107 .keymapsize = ARRAY_SIZE(rx51_keymap),
108 .rep = 1,
109};
110
111static struct platform_device *rx51_peripherals_devices[] = {
112 &rx51_smc91x_device,
113};
114
115/*
116 * Timings are taken from smsc-lan91c96-ms.pdf
117 */
118static int smc91x_init_gpmc(int cs)
119{
120 struct gpmc_timings t;
121 const int t2_r = 45; /* t2 in Figure 12.10 */
122 const int t2_w = 30; /* t2 in Figure 12.11 */
123 const int t3 = 15; /* t3 in Figure 12.10 */
124 const int t5_r = 0; /* t5 in Figure 12.10 */
125 const int t6_r = 45; /* t6 in Figure 12.10 */
126 const int t6_w = 0; /* t6 in Figure 12.11 */
127 const int t7_w = 15; /* t7 in Figure 12.11 */
128 const int t15 = 12; /* t15 in Figure 12.2 */
129 const int t20 = 185; /* t20 in Figure 12.2 */
130
131 memset(&t, 0, sizeof(t));
132
133 t.cs_on = t15;
134 t.cs_rd_off = t3 + t2_r + t5_r; /* Figure 12.10 */
135 t.cs_wr_off = t3 + t2_w + t6_w; /* Figure 12.11 */
136 t.adv_on = t3; /* Figure 12.10 */
137 t.adv_rd_off = t3 + t2_r; /* Figure 12.10 */
138 t.adv_wr_off = t3 + t2_w; /* Figure 12.11 */
139 t.oe_off = t3 + t2_r + t5_r; /* Figure 12.10 */
140 t.oe_on = t.oe_off - t6_r; /* Figure 12.10 */
141 t.we_off = t3 + t2_w + t6_w; /* Figure 12.11 */
142 t.we_on = t.we_off - t7_w; /* Figure 12.11 */
143 t.rd_cycle = t20; /* Figure 12.2 */
144 t.wr_cycle = t20; /* Figure 12.4 */
145 t.access = t3 + t2_r + t5_r; /* Figure 12.10 */
146 t.wr_access = t3 + t2_w + t6_w; /* Figure 12.11 */
147
148 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, GPMC_CONFIG1_DEVICESIZE_16);
149
150 return gpmc_cs_set_timings(cs, &t);
151}
152
153static void __init rx51_init_smc91x(void)
154{
155 unsigned long cs_mem_base;
156 int ret;
157
158 omap_cfg_reg(U8_34XX_GPIO54_DOWN);
159 omap_cfg_reg(G25_34XX_GPIO86_OUT);
160 omap_cfg_reg(H19_34XX_GPIO164_OUT);
161
162 if (gpmc_cs_request(SMC91X_CS, SZ_16M, &cs_mem_base) < 0) {
163 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
164 return;
165 }
166
167 rx51_smc91x_resources[0].start = cs_mem_base + 0x300;
168 rx51_smc91x_resources[0].end = cs_mem_base + 0x30f;
169
170 smc91x_init_gpmc(SMC91X_CS);
171
172 if (gpio_request(SMC91X_GPIO_IRQ, "SMC91X irq") < 0)
173 goto free1;
174
175 gpio_direction_input(SMC91X_GPIO_IRQ);
176 rx51_smc91x_resources[1].start = gpio_to_irq(SMC91X_GPIO_IRQ);
177
178 ret = gpio_request(SMC91X_GPIO_PWRDWN, "SMC91X powerdown");
179 if (ret)
180 goto free2;
181 gpio_direction_output(SMC91X_GPIO_PWRDWN, 0);
182
183 ret = gpio_request(SMC91X_GPIO_RESET, "SMC91X reset");
184 if (ret)
185 goto free3;
186 gpio_direction_output(SMC91X_GPIO_RESET, 0);
187 gpio_set_value(SMC91X_GPIO_RESET, 1);
188 msleep(100);
189 gpio_set_value(SMC91X_GPIO_RESET, 0);
190
191 return;
192
193free3:
194 gpio_free(SMC91X_GPIO_PWRDWN);
195free2:
196 gpio_free(SMC91X_GPIO_IRQ);
197free1:
198 gpmc_cs_free(SMC91X_CS);
199
200 printk(KERN_ERR "Could not initialize smc91x\n");
201}
202
203static struct twl4030_madc_platform_data rx51_madc_data = {
204 .irq_line = 1,
205};
206
207static struct twl4030_hsmmc_info mmc[] = {
208 {
209 .name = "external",
210 .mmc = 1,
211 .wires = 4,
212 .cover_only = true,
213 .gpio_cd = 160,
214 .gpio_wp = -EINVAL,
215 },
216 {
217 .name = "internal",
218 .mmc = 2,
219 .wires = 8,
220 .gpio_cd = -EINVAL,
221 .gpio_wp = -EINVAL,
222 },
223 {} /* Terminator */
224};
225
226static struct regulator_consumer_supply rx51_vmmc1_supply = {
227 .supply = "vmmc",
228};
229
230static struct regulator_consumer_supply rx51_vmmc2_supply = {
231 .supply = "vmmc",
232};
233
234static struct regulator_consumer_supply rx51_vsim_supply = {
235 .supply = "vmmc_aux",
236};
237
238static struct regulator_init_data rx51_vaux1 = {
239 .constraints = {
240 .name = "V28",
241 .min_uV = 2800000,
242 .max_uV = 2800000,
243 .valid_modes_mask = REGULATOR_MODE_NORMAL
244 | REGULATOR_MODE_STANDBY,
245 .valid_ops_mask = REGULATOR_CHANGE_MODE
246 | REGULATOR_CHANGE_STATUS,
247 },
248};
249
250static struct regulator_init_data rx51_vaux2 = {
251 .constraints = {
252 .name = "VCSI",
253 .min_uV = 1800000,
254 .max_uV = 1800000,
255 .valid_modes_mask = REGULATOR_MODE_NORMAL
256 | REGULATOR_MODE_STANDBY,
257 .valid_ops_mask = REGULATOR_CHANGE_MODE
258 | REGULATOR_CHANGE_STATUS,
259 },
260};
261
262/* VAUX3 - adds more power to VIO_18 rail */
263static struct regulator_init_data rx51_vaux3 = {
264 .constraints = {
265 .name = "VCAM_DIG_18",
266 .min_uV = 1800000,
267 .max_uV = 1800000,
268 .apply_uV = true,
269 .valid_modes_mask = REGULATOR_MODE_NORMAL
270 | REGULATOR_MODE_STANDBY,
271 .valid_ops_mask = REGULATOR_CHANGE_MODE
272 | REGULATOR_CHANGE_STATUS,
273 },
274};
275
276static struct regulator_init_data rx51_vaux4 = {
277 .constraints = {
278 .name = "VCAM_ANA_28",
279 .min_uV = 2800000,
280 .max_uV = 2800000,
281 .apply_uV = true,
282 .valid_modes_mask = REGULATOR_MODE_NORMAL
283 | REGULATOR_MODE_STANDBY,
284 .valid_ops_mask = REGULATOR_CHANGE_MODE
285 | REGULATOR_CHANGE_STATUS,
286 },
287};
288
289static struct regulator_init_data rx51_vmmc1 = {
290 .constraints = {
291 .min_uV = 1850000,
292 .max_uV = 3150000,
293 .valid_modes_mask = REGULATOR_MODE_NORMAL
294 | REGULATOR_MODE_STANDBY,
295 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
296 | REGULATOR_CHANGE_MODE
297 | REGULATOR_CHANGE_STATUS,
298 },
299 .num_consumer_supplies = 1,
300 .consumer_supplies = &rx51_vmmc1_supply,
301};
302
303static struct regulator_init_data rx51_vmmc2 = {
304 .constraints = {
305 .name = "VMMC2_30",
306 .min_uV = 1850000,
307 .max_uV = 3150000,
308 .apply_uV = true,
309 .valid_modes_mask = REGULATOR_MODE_NORMAL
310 | REGULATOR_MODE_STANDBY,
311 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
312 | REGULATOR_CHANGE_MODE
313 | REGULATOR_CHANGE_STATUS,
314 },
315 .num_consumer_supplies = 1,
316 .consumer_supplies = &rx51_vmmc2_supply,
317};
318
319static struct regulator_init_data rx51_vsim = {
320 .constraints = {
321 .name = "VMMC2_IO_18",
322 .min_uV = 1800000,
323 .max_uV = 1800000,
324 .apply_uV = true,
325 .valid_modes_mask = REGULATOR_MODE_NORMAL
326 | REGULATOR_MODE_STANDBY,
327 .valid_ops_mask = REGULATOR_CHANGE_MODE
328 | REGULATOR_CHANGE_STATUS,
329 },
330 .num_consumer_supplies = 1,
331 .consumer_supplies = &rx51_vsim_supply,
332};
333
334static struct regulator_init_data rx51_vdac = {
335 .constraints = {
336 .min_uV = 1800000,
337 .max_uV = 1800000,
338 .valid_modes_mask = REGULATOR_MODE_NORMAL
339 | REGULATOR_MODE_STANDBY,
340 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
341 | REGULATOR_CHANGE_MODE
342 | REGULATOR_CHANGE_STATUS,
343 },
344};
345
346static int rx51_twlgpio_setup(struct device *dev, unsigned gpio, unsigned n)
347{
348 /* FIXME this gpio setup is just a placeholder for now */
349 gpio_request(gpio + 6, "backlight_pwm");
350 gpio_direction_output(gpio + 6, 0);
351 gpio_request(gpio + 7, "speaker_en");
352 gpio_direction_output(gpio + 7, 1);
353
354 /* set up MMC adapters, linking their regulators to them */
355 twl4030_mmc_init(mmc);
356 rx51_vmmc1_supply.dev = mmc[0].dev;
357 rx51_vmmc2_supply.dev = mmc[1].dev;
358 rx51_vsim_supply.dev = mmc[1].dev;
359
360 return 0;
361}
362
363static struct twl4030_gpio_platform_data rx51_gpio_data = {
364 .gpio_base = OMAP_MAX_GPIO_LINES,
365 .irq_base = TWL4030_GPIO_IRQ_BASE,
366 .irq_end = TWL4030_GPIO_IRQ_END,
367 .pulldowns = BIT(0) | BIT(1) | BIT(2) | BIT(3)
368 | BIT(4) | BIT(5)
369 | BIT(8) | BIT(9) | BIT(10) | BIT(11)
370 | BIT(12) | BIT(13) | BIT(14) | BIT(15)
371 | BIT(16) | BIT(17) ,
372 .setup = rx51_twlgpio_setup,
373};
374
375static struct twl4030_platform_data rx51_twldata = {
376 .irq_base = TWL4030_IRQ_BASE,
377 .irq_end = TWL4030_IRQ_END,
378
379 /* platform_data for children goes here */
380 .gpio = &rx51_gpio_data,
381 .keypad = &rx51_kp_data,
382 .madc = &rx51_madc_data,
383
384 .vaux1 = &rx51_vaux1,
385 .vaux2 = &rx51_vaux2,
386 .vaux3 = &rx51_vaux3,
387 .vaux4 = &rx51_vaux4,
388 .vmmc1 = &rx51_vmmc1,
389 .vmmc2 = &rx51_vmmc2,
390 .vsim = &rx51_vsim,
391 .vdac = &rx51_vdac,
392};
393
394static struct i2c_board_info __initdata rx51_peripherals_i2c_board_info_1[] = {
395 {
396 I2C_BOARD_INFO("twl5030", 0x48),
397 .flags = I2C_CLIENT_WAKE,
398 .irq = INT_34XX_SYS_NIRQ,
399 .platform_data = &rx51_twldata,
400 },
401};
402
403static int __init rx51_i2c_init(void)
404{
405 omap_register_i2c_bus(1, 2600, rx51_peripherals_i2c_board_info_1,
406 ARRAY_SIZE(rx51_peripherals_i2c_board_info_1));
407 omap_register_i2c_bus(2, 100, NULL, 0);
408 omap_register_i2c_bus(3, 400, NULL, 0);
409 return 0;
410}
411
Juha Yrjolaaa62e902009-05-28 13:23:52 -0700412#if defined(CONFIG_MTD_ONENAND_OMAP2) || \
413 defined(CONFIG_MTD_ONENAND_OMAP2_MODULE)
414
415static struct mtd_partition onenand_partitions[] = {
416 {
417 .name = "bootloader",
418 .offset = 0,
419 .size = 0x20000,
420 .mask_flags = MTD_WRITEABLE, /* Force read-only */
421 },
422 {
423 .name = "config",
424 .offset = MTDPART_OFS_APPEND,
425 .size = 0x60000,
426 },
427 {
428 .name = "log",
429 .offset = MTDPART_OFS_APPEND,
430 .size = 0x40000,
431 },
432 {
433 .name = "kernel",
434 .offset = MTDPART_OFS_APPEND,
435 .size = 0x200000,
436 },
437 {
438 .name = "initfs",
439 .offset = MTDPART_OFS_APPEND,
440 .size = 0x200000,
441 },
442 {
443 .name = "rootfs",
444 .offset = MTDPART_OFS_APPEND,
445 .size = MTDPART_SIZ_FULL,
446 },
447};
448
449static struct omap_onenand_platform_data board_onenand_data = {
450 .cs = 0,
451 .gpio_irq = 65,
452 .parts = onenand_partitions,
453 .nr_parts = ARRAY_SIZE(onenand_partitions),
454};
455
456static void __init board_onenand_init(void)
457{
458 gpmc_onenand_init(&board_onenand_data);
459}
460
461#else
462
463static inline void board_onenand_init(void)
464{
465}
466
467#endif
Lauri Leukkunenffe7f952009-03-23 18:38:17 -0700468
469void __init rx51_peripherals_init(void)
470{
471 platform_add_devices(rx51_peripherals_devices,
472 ARRAY_SIZE(rx51_peripherals_devices));
473 rx51_i2c_init();
474 rx51_init_smc91x();
Juha Yrjolaaa62e902009-05-28 13:23:52 -0700475 board_onenand_init();
Lauri Leukkunenffe7f952009-03-23 18:38:17 -0700476}
477