]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-rx51-peripherals.c
Set the smc91x timings for rx51
[linux-2.6-omap-h63xx.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/spi/tsc2005.h>
17 #include <linux/i2c.h>
18 #include <linux/i2c/twl4030.h>
19 #include <linux/clk.h>
20 #include <linux/delay.h>
21 #include <linux/regulator/machine.h>
22
23 #include <mach/mcspi.h>
24 #include <mach/gpio.h>
25 #include <mach/mux.h>
26 #include <mach/board.h>
27 #include <mach/common.h>
28 #include <mach/dma.h>
29 #include <mach/gpmc.h>
30
31 #define SMC91X_CS                       1
32 #define SMC91X_GPIO_IRQ                 54
33 #define SMC91X_GPIO_RESET               164
34 #define SMC91X_GPIO_PWRDWN              86
35
36 #define RX51_TSC2005_RESET_GPIO         104
37 #define RX51_TSC2005_IRQ_GPIO           100
38
39 static struct resource rx51_smc91x_resources[] = {
40         [0] = {
41                 .flags          = IORESOURCE_MEM,
42         },
43         [1] = {
44                 .flags          = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
45         },
46 };
47
48 static struct platform_device rx51_smc91x_device = {
49         .name           = "smc91x",
50         .id             = -1,
51         .num_resources  = ARRAY_SIZE(rx51_smc91x_resources),
52         .resource       = rx51_smc91x_resources,
53 };
54
55 static struct tsc2005_platform_data tsc2005_config = {
56         .reset_gpio             = RX51_TSC2005_RESET_GPIO, /* not used */
57
58         .ts_x_plate_ohm         = 280,
59         .ts_hw_avg              = 0,
60         .ts_touch_pressure      = 1500,
61         .ts_stab_time           = 1000,
62         .ts_pressure_max        = 2048,
63         .ts_pressure_fudge      = 2,
64         .ts_x_max               = 4096,
65         .ts_x_fudge             = 4,
66         .ts_y_max               = 4096,
67         .ts_y_fudge             = 7,
68 };
69
70 static struct omap2_mcspi_device_config tsc2005_mcspi_config = {
71         .turbo_mode     = 0,
72         .single_channel = 1,
73 };
74
75 static struct spi_board_info rx51_peripherals_spi_board_info[] = {
76         [0] = {
77                 .modalias               = "tsc2005",
78                 .bus_num                = 1,
79                 .chip_select            = 0,
80                 .irq                    = OMAP_GPIO_IRQ(RX51_TSC2005_IRQ_GPIO),
81                 .max_speed_hz           = 6000000,
82                 .controller_data        = &tsc2005_mcspi_config,
83                 .platform_data          = &tsc2005_config,
84         },
85 };
86
87 static int rx51_keymap[] = {
88         KEY(0, 0, KEY_Q),
89         KEY(0, 1, KEY_W),
90         KEY(0, 2, KEY_E),
91         KEY(0, 3, KEY_R),
92         KEY(0, 4, KEY_T),
93         KEY(0, 5, KEY_Y),
94         KEY(0, 6, KEY_U),
95         KEY(0, 7, KEY_I),
96         KEY(1, 0, KEY_O),
97         KEY(1, 1, KEY_D),
98         KEY(1, 2, KEY_DOT ),
99         KEY(1, 3, KEY_V),
100         KEY(1, 4, KEY_DOWN ),
101         KEY(2, 0, KEY_P),
102         KEY(2, 1, KEY_F),
103         KEY(2, 2, KEY_UP ),
104         KEY(2, 3, KEY_B),
105         KEY(2, 4, KEY_RIGHT ),
106         KEY(3, 0, KEY_COMMA ),
107         KEY(3, 1, KEY_G),
108         KEY(3, 2, KEY_ENTER ),
109         KEY(3, 3, KEY_N),
110         KEY(4, 0, KEY_BACKSPACE ),
111         KEY(4, 1, KEY_H),
112         KEY(4, 3, KEY_M),
113         KEY(4, 4, KEY_LEFTCTRL),
114         KEY(5, 1, KEY_J),
115         KEY(5, 2, KEY_Z),
116         KEY(5, 3, KEY_SPACE),
117         KEY(5, 4, KEY_LEFTSHIFT),
118         KEY(6, 0, KEY_A),
119         KEY(6, 1, KEY_K),
120         KEY(6, 2, KEY_X),
121         KEY(6, 3, KEY_SPACE),
122         KEY(6, 4, KEY_FN ),
123         KEY(7, 0, KEY_S),
124         KEY(7, 1, KEY_L),
125         KEY(7, 2, KEY_C),
126         KEY(7, 3, KEY_LEFT),
127         KEY(0xff, 0, KEY_F6),
128         KEY(0xff, 1, KEY_F7),
129         KEY(0xff, 2, KEY_F8),
130         KEY(0xff, 4, KEY_F9),
131         KEY(0xff, 5, KEY_F10),
132 };
133
134 static struct twl4030_keypad_data rx51_kp_data = {
135         .rows           = 8,
136         .cols           = 8,
137         .keymap         = rx51_keymap,
138         .keymapsize     = ARRAY_SIZE(rx51_keymap),
139         .rep            = 1,
140 };
141
142 static struct platform_device *rx51_peripherals_devices[] = {
143         &rx51_smc91x_device,
144 };
145
146 /*
147  * Timings are taken from smsc-lan91c96-ms.pdf
148  */
149 static int smc91x_init_gpmc(int cs)
150 {
151         struct gpmc_timings t;
152         const int t2_r = 45;            /* t2 in Figure 12.10 */
153         const int t2_w = 30;            /* t2 in Figure 12.11 */
154         const int t3 = 15;              /* t3 in Figure 12.10 */
155         const int t5_r = 0;             /* t5 in Figure 12.10 */
156         const int t6_r = 45;            /* t6 in Figure 12.10 */
157         const int t6_w = 0;             /* t6 in Figure 12.11 */
158         const int t7_w = 15;            /* t7 in Figure 12.11 */
159         const int t15 = 12;             /* t15 in Figure 12.2 */
160         const int t20 = 185;            /* t20 in Figure 12.2 */
161
162         memset(&t, 0, sizeof(t));
163
164         t.cs_on = t15;
165         t.cs_rd_off = t3 + t2_r + t5_r; /* Figure 12.10 */
166         t.cs_wr_off = t3 + t2_w + t6_w; /* Figure 12.11 */
167         t.adv_on = t3;                  /* Figure 12.10 */
168         t.adv_rd_off = t3 + t2_r;       /* Figure 12.10 */
169         t.adv_wr_off = t3 + t2_w;       /* Figure 12.11 */
170         t.oe_off = t3 + t2_r + t5_r;    /* Figure 12.10 */
171         t.oe_on = t.oe_off - t6_r;      /* Figure 12.10 */
172         t.we_off = t3 + t2_w + t6_w;    /* Figure 12.11 */
173         t.we_on = t.we_off - t7_w;      /* Figure 12.11 */
174         t.rd_cycle = t20;               /* Figure 12.2 */
175         t.wr_cycle = t20;               /* Figure 12.4 */
176         t.access = t3 + t2_r + t5_r;    /* Figure 12.10 */
177         t.wr_access = t3 + t2_w + t6_w; /* Figure 12.11 */
178
179         gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, GPMC_CONFIG1_DEVICESIZE_16);
180
181         return gpmc_cs_set_timings(cs, &t);
182 }
183
184 static void __init rx51_init_smc91x(void)
185 {
186         unsigned long cs_mem_base;
187         int ret;
188
189         omap_cfg_reg(U8_34XX_GPIO54_DOWN);
190         omap_cfg_reg(G25_34XX_GPIO86_OUT);
191         omap_cfg_reg(H19_34XX_GPIO164_OUT);
192
193         if (gpmc_cs_request(SMC91X_CS, SZ_16M, &cs_mem_base) < 0) {
194                 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
195                 return;
196         }
197
198         rx51_smc91x_resources[0].start = cs_mem_base + 0x300;
199         rx51_smc91x_resources[0].end = cs_mem_base + 0x30f;
200
201         smc91x_init_gpmc(SMC91X_CS);
202
203         if (gpio_request(SMC91X_GPIO_IRQ, "SMC91X irq") < 0)
204                 goto free1;
205
206         gpio_direction_input(SMC91X_GPIO_IRQ);
207         rx51_smc91x_resources[1].start = gpio_to_irq(SMC91X_GPIO_IRQ);
208
209         ret = gpio_request(SMC91X_GPIO_PWRDWN, "SMC91X powerdown");
210         if (ret)
211                 goto free2;
212         gpio_direction_output(SMC91X_GPIO_PWRDWN, 0);
213
214         ret = gpio_request(SMC91X_GPIO_RESET, "SMC91X reset");
215         if (ret)
216                 goto free3;
217         gpio_direction_output(SMC91X_GPIO_RESET, 0);
218         gpio_set_value(SMC91X_GPIO_RESET, 1);
219         msleep(100);
220         gpio_set_value(SMC91X_GPIO_RESET, 0);
221
222         return;
223
224 free3:
225         gpio_free(SMC91X_GPIO_PWRDWN);
226 free2:
227         gpio_free(SMC91X_GPIO_IRQ);
228 free1:
229         gpmc_cs_free(SMC91X_CS);
230
231         printk(KERN_ERR "Could not initialize smc91x\n");
232 }
233
234 static void __init rx51_init_tsc2005(void)
235 {
236         int r;
237
238         r = gpio_request(RX51_TSC2005_IRQ_GPIO, "tsc2005 DAV IRQ");
239         if (r >= 0) {
240                 gpio_direction_input(RX51_TSC2005_IRQ_GPIO);
241         } else {
242                 printk(KERN_ERR "unable to get DAV GPIO");
243         }
244 }
245
246 static struct twl4030_madc_platform_data rx51_madc_data = {
247         .irq_line               = 1,
248 };
249
250 static struct regulator_init_data rx51_vaux1 = {
251         .constraints = {
252                 .name                   = "V28",
253                 .min_uV                 = 2800000,
254                 .max_uV                 = 2800000,
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 static struct regulator_init_data rx51_vaux2 = {
263         .constraints = {
264                 .name                   = "VCSI",
265                 .min_uV                 = 1800000,
266                 .max_uV                 = 1800000,
267                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
268                                         | REGULATOR_MODE_STANDBY,
269                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
270                                         | REGULATOR_CHANGE_STATUS,
271         },
272 };
273
274 /* VAUX3 - adds more power to VIO_18 rail */
275 static struct regulator_init_data rx51_vaux3 = {
276         .constraints = {
277                 .name                   = "VCAM_DIG_18",
278                 .min_uV                 = 1800000,
279                 .max_uV                 = 1800000,
280                 .apply_uV               = true,
281                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
282                                         | REGULATOR_MODE_STANDBY,
283                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
284                                         | REGULATOR_CHANGE_STATUS,
285         },
286 };
287
288 static struct regulator_init_data rx51_vaux4 = {
289         .constraints = {
290                 .name                   = "VCAM_ANA_28",
291                 .min_uV                 = 2800000,
292                 .max_uV                 = 2800000,
293                 .apply_uV               = true,
294                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
295                                         | REGULATOR_MODE_STANDBY,
296                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
297                                         | REGULATOR_CHANGE_STATUS,
298         },
299 };
300
301 static struct regulator_init_data rx51_vmmc1 = {
302         .constraints = {
303                 .min_uV                 = 1850000,
304                 .max_uV                 = 3150000,
305                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
306                                         | REGULATOR_MODE_STANDBY,
307                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
308                                         | REGULATOR_CHANGE_MODE
309                                         | REGULATOR_CHANGE_STATUS,
310         },
311 };
312
313 static struct regulator_init_data rx51_vmmc2 = {
314         .constraints = {
315                 .name                   = "VMMC2_30",
316                 .min_uV                 = 1850000,
317                 .max_uV                 = 3150000,
318                 .apply_uV               = true,
319                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
320                                         | REGULATOR_MODE_STANDBY,
321                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
322                                         | REGULATOR_CHANGE_MODE
323                                         | REGULATOR_CHANGE_STATUS,
324         },
325 };
326
327 static struct regulator_init_data rx51_vsim = {
328         .constraints = {
329                 .name                   = "VMMC2_IO_18",
330                 .min_uV                 = 1800000,
331                 .max_uV                 = 1800000,
332                 .apply_uV               = true,
333                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
334                                         | REGULATOR_MODE_STANDBY,
335                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
336                                         | REGULATOR_CHANGE_STATUS,
337         },
338 };
339
340 static struct regulator_init_data rx51_vdac = {
341         .constraints = {
342                 .min_uV                 = 1800000,
343                 .max_uV                 = 1800000,
344                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
345                                         | REGULATOR_MODE_STANDBY,
346                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
347                                         | REGULATOR_CHANGE_MODE
348                                         | REGULATOR_CHANGE_STATUS,
349         },
350 };
351
352 static int rx51_twlgpio_setup(struct device *dev, unsigned gpio, unsigned n)
353 {
354         /* FIXME this gpio setup is just a placeholder for now */
355         gpio_request(gpio + 6, "backlight_pwm");
356         gpio_direction_output(gpio + 6, 0);
357         gpio_request(gpio + 7, "speaker_en");
358         gpio_direction_output(gpio + 7, 1);
359
360         /* FIXME connect power supplies to devices; register MMC */
361
362         return 0;
363 }
364
365 static struct twl4030_gpio_platform_data rx51_gpio_data = {
366         .gpio_base              = OMAP_MAX_GPIO_LINES,
367         .irq_base               = TWL4030_GPIO_IRQ_BASE,
368         .irq_end                = TWL4030_GPIO_IRQ_END,
369         .pulldowns              = BIT(0) | BIT(1) | BIT(2) | BIT(3)
370                                 | BIT(4) | BIT(5)
371                                 | BIT(8) | BIT(9) | BIT(10) | BIT(11)
372                                 | BIT(12) | BIT(13) | BIT(14) | BIT(15)
373                                 | BIT(16) | BIT(17) ,
374         .setup                  = rx51_twlgpio_setup,
375 };
376
377 static struct twl4030_platform_data rx51_twldata = {
378         .irq_base               = TWL4030_IRQ_BASE,
379         .irq_end                = TWL4030_IRQ_END,
380
381         /* platform_data for children goes here */
382         .gpio                   = &rx51_gpio_data,
383         .keypad                 = &rx51_kp_data,
384         .madc                   = &rx51_madc_data,
385
386         .vaux1                  = &rx51_vaux1,
387         .vaux2                  = &rx51_vaux2,
388         .vaux3                  = &rx51_vaux3,
389         .vaux4                  = &rx51_vaux4,
390         .vmmc1                  = &rx51_vmmc1,
391         .vmmc2                  = &rx51_vmmc2,
392         .vsim                   = &rx51_vsim,
393         .vdac                   = &rx51_vdac,
394 };
395
396 static struct i2c_board_info __initdata rx51_peripherals_i2c_board_info_1[] = {
397         {
398                 I2C_BOARD_INFO("twl5030", 0x48),
399                 .flags = I2C_CLIENT_WAKE,
400                 .irq = INT_34XX_SYS_NIRQ,
401                 .platform_data = &rx51_twldata,
402         },
403 };
404
405 static int __init rx51_i2c_init(void)
406 {
407         omap_register_i2c_bus(1, 2600, rx51_peripherals_i2c_board_info_1,
408                         ARRAY_SIZE(rx51_peripherals_i2c_board_info_1));
409         omap_register_i2c_bus(2, 100, NULL, 0);
410         omap_register_i2c_bus(3, 400, NULL, 0);
411         return 0;
412 }
413
414
415 void __init rx51_peripherals_init(void)
416 {
417         platform_add_devices(rx51_peripherals_devices,
418                                 ARRAY_SIZE(rx51_peripherals_devices));
419         spi_register_board_info(rx51_peripherals_spi_board_info,
420                                 ARRAY_SIZE(rx51_peripherals_spi_board_info));
421         rx51_i2c_init();
422         rx51_init_smc91x();
423         rx51_init_tsc2005();
424 }
425