ARM: at91: Convert the boards to the init_time callback
[sfrench/cifs-2.6.git] / arch / arm / mach-at91 / board-gsia18s.c
1 /*
2  *  Copyright (C) 2010 Christian Glindkamp <christian.glindkamp@taskit.de>
3  *                     taskit GmbH
4  *                2010 Igor Plyatov <plyatov@gmail.com>
5  *                     GeoSIG Ltd
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <linux/platform_device.h>
23 #include <linux/gpio.h>
24 #include <linux/w1-gpio.h>
25 #include <linux/i2c.h>
26 #include <linux/i2c/pcf857x.h>
27 #include <linux/gpio_keys.h>
28 #include <linux/input.h>
29
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32
33 #include <mach/at91sam9_smc.h>
34 #include <mach/hardware.h>
35
36 #include "at91_aic.h"
37 #include "board.h"
38 #include "sam9_smc.h"
39 #include "generic.h"
40 #include "gsia18s.h"
41 #include "stamp9g20.h"
42 #include "gpio.h"
43
44 static void __init gsia18s_init_early(void)
45 {
46         stamp9g20_init_early();
47 }
48
49 /*
50  * Two USB Host ports
51  */
52 static struct at91_usbh_data __initdata usbh_data = {
53         .ports          = 2,
54         .vbus_pin       = {-EINVAL, -EINVAL},
55         .overcurrent_pin= {-EINVAL, -EINVAL},
56 };
57
58 /*
59  * USB Device port
60  */
61 static struct at91_udc_data __initdata udc_data = {
62         .vbus_pin       = AT91_PIN_PA22,
63         .pullup_pin     = -EINVAL,              /* pull-up driven by UDC */
64 };
65
66 /*
67  * MACB Ethernet device
68  */
69 static struct macb_platform_data __initdata macb_data = {
70         .phy_irq_pin    = AT91_PIN_PA28,
71         .is_rmii        = 1,
72 };
73
74 /*
75  * LEDs and GPOs
76  */
77 static struct gpio_led gpio_leds[] = {
78         {
79                 .name                   = "gpo:spi1reset",
80                 .gpio                   = AT91_PIN_PC1,
81                 .active_low             = 0,
82                 .default_trigger        = "none",
83                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
84         },
85         {
86                 .name                   = "gpo:trig_net_out",
87                 .gpio                   = AT91_PIN_PB20,
88                 .active_low             = 0,
89                 .default_trigger        = "none",
90                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
91         },
92         {
93                 .name                   = "gpo:trig_net_dir",
94                 .gpio                   = AT91_PIN_PB19,
95                 .active_low             = 0,
96                 .default_trigger        = "none",
97                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
98         },
99         {
100                 .name                   = "gpo:charge_dis",
101                 .gpio                   = AT91_PIN_PC2,
102                 .active_low             = 0,
103                 .default_trigger        = "none",
104                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
105         },
106         {
107                 .name                   = "led:event",
108                 .gpio                   = AT91_PIN_PB17,
109                 .active_low             = 1,
110                 .default_trigger        = "none",
111                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
112         },
113         {
114                 .name                   = "led:lan",
115                 .gpio                   = AT91_PIN_PB18,
116                 .active_low             = 1,
117                 .default_trigger        = "none",
118                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
119         },
120         {
121                 .name                   = "led:error",
122                 .gpio                   = AT91_PIN_PB16,
123                 .active_low             = 1,
124                 .default_trigger        = "none",
125                 .default_state          = LEDS_GPIO_DEFSTATE_ON,
126         }
127 };
128
129 static struct gpio_led_platform_data gpio_led_info = {
130         .leds           = gpio_leds,
131         .num_leds       = ARRAY_SIZE(gpio_leds),
132 };
133
134 static struct platform_device leds = {
135         .name   = "leds-gpio",
136         .id     = 0,
137         .dev    = {
138                 .platform_data  = &gpio_led_info,
139         }
140 };
141
142 static void __init gsia18s_leds_init(void)
143 {
144         platform_device_register(&leds);
145 }
146
147 /* PCF8574 0x20 GPIO - U1 on the GS_IA18-CB_V3 board */
148 static struct gpio_led pcf_gpio_leds1[] = {
149         { /* bit 0 */
150                 .name                   = "gpo:hdc_power",
151                 .gpio                   = PCF_GPIO_HDC_POWER,
152                 .active_low             = 0,
153                 .default_trigger        = "none",
154                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
155         },
156         { /* bit 1 */
157                 .name                   = "gpo:wifi_setup",
158                 .gpio                   = PCF_GPIO_WIFI_SETUP,
159                 .active_low             = 1,
160                 .default_trigger        = "none",
161                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
162         },
163         { /* bit 2 */
164                 .name                   = "gpo:wifi_enable",
165                 .gpio                   = PCF_GPIO_WIFI_ENABLE,
166                 .active_low             = 1,
167                 .default_trigger        = "none",
168                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
169         },
170         { /* bit 3      */
171                 .name                   = "gpo:wifi_reset",
172                 .gpio                   = PCF_GPIO_WIFI_RESET,
173                 .active_low             = 1,
174                 .default_trigger        = "none",
175                 .default_state          = LEDS_GPIO_DEFSTATE_ON,
176         },
177         /* bit 4 used as GPI    */
178         { /* bit 5 */
179                 .name                   = "gpo:gps_setup",
180                 .gpio                   = PCF_GPIO_GPS_SETUP,
181                 .active_low             = 1,
182                 .default_trigger        = "none",
183                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
184         },
185         { /* bit 6 */
186                 .name                   = "gpo:gps_standby",
187                 .gpio                   = PCF_GPIO_GPS_STANDBY,
188                 .active_low             = 0,
189                 .default_trigger        = "none",
190                 .default_state          = LEDS_GPIO_DEFSTATE_ON,
191         },
192         { /* bit 7 */
193                 .name                   = "gpo:gps_power",
194                 .gpio                   = PCF_GPIO_GPS_POWER,
195                 .active_low             = 0,
196                 .default_trigger        = "none",
197                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
198         }
199 };
200
201 static struct gpio_led_platform_data pcf_gpio_led_info1 = {
202         .leds           = pcf_gpio_leds1,
203         .num_leds       = ARRAY_SIZE(pcf_gpio_leds1),
204 };
205
206 static struct platform_device pcf_leds1 = {
207         .name   = "leds-gpio", /* GS_IA18-CB_board */
208         .id     = 1,
209         .dev    = {
210                 .platform_data  = &pcf_gpio_led_info1,
211         }
212 };
213
214 /* PCF8574 0x22 GPIO - U1 on the GS_2G_OPT1-A_V0 board (Alarm) */
215 static struct gpio_led pcf_gpio_leds2[] = {
216         { /* bit 0 */
217                 .name                   = "gpo:alarm_1",
218                 .gpio                   = PCF_GPIO_ALARM1,
219                 .active_low             = 1,
220                 .default_trigger        = "none",
221                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
222         },
223         { /* bit 1 */
224                 .name                   = "gpo:alarm_2",
225                 .gpio                   = PCF_GPIO_ALARM2,
226                 .active_low             = 1,
227                 .default_trigger        = "none",
228                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
229         },
230         { /* bit 2 */
231                 .name                   = "gpo:alarm_3",
232                 .gpio                   = PCF_GPIO_ALARM3,
233                 .active_low             = 1,
234                 .default_trigger        = "none",
235                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
236         },
237         { /* bit 3 */
238                 .name                   = "gpo:alarm_4",
239                 .gpio                   = PCF_GPIO_ALARM4,
240                 .active_low             = 1,
241                 .default_trigger        = "none",
242                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
243         },
244         /* bits 4, 5, 6 not used */
245         { /* bit 7 */
246                 .name                   = "gpo:alarm_v_relay_on",
247                 .gpio                   = PCF_GPIO_ALARM_V_RELAY_ON,
248                 .active_low             = 0,
249                 .default_trigger        = "none",
250                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
251         },
252 };
253
254 static struct gpio_led_platform_data pcf_gpio_led_info2 = {
255         .leds           = pcf_gpio_leds2,
256         .num_leds       = ARRAY_SIZE(pcf_gpio_leds2),
257 };
258
259 static struct platform_device pcf_leds2 = {
260         .name   = "leds-gpio",
261         .id     = 2,
262         .dev    = {
263                 .platform_data  = &pcf_gpio_led_info2,
264         }
265 };
266
267 /* PCF8574 0x24 GPIO U1 on the GS_2G-OPT23-A_V0 board (Modem) */
268 static struct gpio_led pcf_gpio_leds3[] = {
269         { /* bit 0 */
270                 .name                   = "gpo:modem_power",
271                 .gpio                   = PCF_GPIO_MODEM_POWER,
272                 .active_low             = 1,
273                 .default_trigger        = "none",
274                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
275         },
276                 /* bits 1 and 2 not used */
277         { /* bit 3 */
278                 .name                   = "gpo:modem_reset",
279                 .gpio                   = PCF_GPIO_MODEM_RESET,
280                 .active_low             = 1,
281                 .default_trigger        = "none",
282                 .default_state          = LEDS_GPIO_DEFSTATE_ON,
283         },
284                 /* bits 4, 5 and 6 not used */
285         { /* bit 7 */
286                 .name                   = "gpo:trx_reset",
287                 .gpio                   = PCF_GPIO_TRX_RESET,
288                 .active_low             = 1,
289                 .default_trigger        = "none",
290                 .default_state          = LEDS_GPIO_DEFSTATE_ON,
291         }
292 };
293
294 static struct gpio_led_platform_data pcf_gpio_led_info3 = {
295         .leds           = pcf_gpio_leds3,
296         .num_leds       = ARRAY_SIZE(pcf_gpio_leds3),
297 };
298
299 static struct platform_device pcf_leds3 = {
300         .name   = "leds-gpio",
301         .id     = 3,
302         .dev    = {
303                 .platform_data  = &pcf_gpio_led_info3,
304         }
305 };
306
307 static void __init gsia18s_pcf_leds_init(void)
308 {
309         platform_device_register(&pcf_leds1);
310         platform_device_register(&pcf_leds2);
311         platform_device_register(&pcf_leds3);
312 }
313
314 /*
315  * SPI busses.
316  */
317 static struct spi_board_info gsia18s_spi_devices[] = {
318         { /* User accessible spi0, cs0 used for communication with MSP RTC */
319                 .modalias       = "spidev",
320                 .bus_num        = 0,
321                 .chip_select    = 0,
322                 .max_speed_hz   = 580000,
323                 .mode           = SPI_MODE_1,
324         },
325         { /* User accessible spi1, cs0 used for communication with int. DSP */
326                 .modalias       = "spidev",
327                 .bus_num        = 1,
328                 .chip_select    = 0,
329                 .max_speed_hz   = 5600000,
330                 .mode           = SPI_MODE_0,
331         },
332         { /* User accessible spi1, cs1 used for communication with ext. DSP */
333                 .modalias       = "spidev",
334                 .bus_num        = 1,
335                 .chip_select    = 1,
336                 .max_speed_hz   = 5600000,
337                 .mode           = SPI_MODE_0,
338         },
339         { /* User accessible spi1, cs2 used for communication with ext. DSP */
340                 .modalias       = "spidev",
341                 .bus_num        = 1,
342                 .chip_select    = 2,
343                 .max_speed_hz   = 5600000,
344                 .mode           = SPI_MODE_0,
345         },
346         { /* User accessible spi1, cs3 used for communication with ext. DSP */
347                 .modalias       = "spidev",
348                 .bus_num        = 1,
349                 .chip_select    = 3,
350                 .max_speed_hz   = 5600000,
351                 .mode           = SPI_MODE_0,
352         }
353 };
354
355 /*
356  * GPI Buttons
357  */
358 static struct gpio_keys_button buttons[] = {
359         {
360                 .gpio           = GPIO_TRIG_NET_IN,
361                 .code           = BTN_1,
362                 .desc           = "TRIG_NET_IN",
363                 .type           = EV_KEY,
364                 .active_low     = 0,
365                 .wakeup         = 1,
366         },
367         { /* SW80 on the GS_IA18_S-MN board*/
368                 .gpio           = GPIO_CARD_UNMOUNT_0,
369                 .code           = BTN_2,
370                 .desc           = "Card umount 0",
371                 .type           = EV_KEY,
372                 .active_low     = 1,
373                 .wakeup         = 1,
374         },
375         { /* SW79 on the GS_IA18_S-MN board*/
376                 .gpio           = GPIO_CARD_UNMOUNT_1,
377                 .code           = BTN_3,
378                 .desc           = "Card umount 1",
379                 .type           = EV_KEY,
380                 .active_low     = 1,
381                 .wakeup         = 1,
382         },
383         { /* SW280 on the GS_IA18-CB board*/
384                 .gpio           = GPIO_KEY_POWER,
385                 .code           = KEY_POWER,
386                 .desc           = "Power Off Button",
387                 .type           = EV_KEY,
388                 .active_low     = 0,
389                 .wakeup         = 1,
390         }
391 };
392
393 static struct gpio_keys_platform_data button_data = {
394         .buttons        = buttons,
395         .nbuttons       = ARRAY_SIZE(buttons),
396 };
397
398 static struct platform_device button_device = {
399         .name           = "gpio-keys",
400         .id             = -1,
401         .num_resources  = 0,
402         .dev            = {
403                 .platform_data  = &button_data,
404         }
405 };
406
407 static void __init gsia18s_add_device_buttons(void)
408 {
409         at91_set_gpio_input(GPIO_TRIG_NET_IN, 1);
410         at91_set_deglitch(GPIO_TRIG_NET_IN, 1);
411         at91_set_gpio_input(GPIO_CARD_UNMOUNT_0, 1);
412         at91_set_deglitch(GPIO_CARD_UNMOUNT_0, 1);
413         at91_set_gpio_input(GPIO_CARD_UNMOUNT_1, 1);
414         at91_set_deglitch(GPIO_CARD_UNMOUNT_1, 1);
415         at91_set_gpio_input(GPIO_KEY_POWER, 0);
416         at91_set_deglitch(GPIO_KEY_POWER, 1);
417
418         platform_device_register(&button_device);
419 }
420
421 /*
422  * I2C
423  */
424 static int pcf8574x_0x20_setup(struct i2c_client *client, int gpio,
425                                 unsigned int ngpio, void *context)
426 {
427         int status;
428
429         status = gpio_request(gpio + PCF_GPIO_ETH_DETECT, "eth_det");
430         if (status < 0) {
431                 pr_err("error: can't request GPIO%d\n",
432                         gpio + PCF_GPIO_ETH_DETECT);
433                 return status;
434         }
435         status = gpio_direction_input(gpio + PCF_GPIO_ETH_DETECT);
436         if (status < 0) {
437                 pr_err("error: can't setup GPIO%d as input\n",
438                         gpio + PCF_GPIO_ETH_DETECT);
439                 return status;
440         }
441         status = gpio_export(gpio + PCF_GPIO_ETH_DETECT, false);
442         if (status < 0) {
443                 pr_err("error: can't export GPIO%d\n",
444                         gpio + PCF_GPIO_ETH_DETECT);
445                 return status;
446         }
447         status = gpio_sysfs_set_active_low(gpio + PCF_GPIO_ETH_DETECT, 1);
448         if (status < 0) {
449                 pr_err("error: gpio_sysfs_set active_low(GPIO%d, 1)\n",
450                         gpio + PCF_GPIO_ETH_DETECT);
451                 return status;
452         }
453
454         return 0;
455 }
456
457 static int pcf8574x_0x20_teardown(struct i2c_client *client, int gpio,
458                                         unsigned ngpio, void *context)
459 {
460         gpio_free(gpio + PCF_GPIO_ETH_DETECT);
461         return 0;
462 }
463
464 static struct pcf857x_platform_data pcf20_pdata = {
465         .gpio_base      = GS_IA18_S_PCF_GPIO_BASE0,
466         .n_latch        = (1 << 4),
467         .setup          = pcf8574x_0x20_setup,
468         .teardown       = pcf8574x_0x20_teardown,
469 };
470
471 static struct pcf857x_platform_data pcf22_pdata = {
472         .gpio_base      = GS_IA18_S_PCF_GPIO_BASE1,
473 };
474
475 static struct pcf857x_platform_data pcf24_pdata = {
476         .gpio_base      = GS_IA18_S_PCF_GPIO_BASE2,
477 };
478
479 static struct i2c_board_info __initdata gsia18s_i2c_devices[] = {
480         { /* U1 on the GS_IA18-CB_V3 board */
481                 I2C_BOARD_INFO("pcf8574", 0x20),
482                 .platform_data = &pcf20_pdata,
483         },
484         { /* U1 on the GS_2G_OPT1-A_V0 board (Alarm) */
485                 I2C_BOARD_INFO("pcf8574", 0x22),
486                 .platform_data = &pcf22_pdata,
487         },
488         { /* U1 on the GS_2G-OPT23-A_V0 board (Modem) */
489                 I2C_BOARD_INFO("pcf8574", 0x24),
490                 .platform_data = &pcf24_pdata,
491         },
492         { /* U161 on the GS_IA18_S-MN board */
493                 I2C_BOARD_INFO("24c1024", 0x50),
494         },
495         { /* U162 on the GS_IA18_S-MN board */
496                 I2C_BOARD_INFO("24c01", 0x53),
497         },
498 };
499
500 /*
501  * Compact Flash
502  */
503 static struct at91_cf_data __initdata gsia18s_cf1_data = {
504         .irq_pin        = AT91_PIN_PA27,
505         .det_pin        = AT91_PIN_PB30,
506         .vcc_pin        = -EINVAL,
507         .rst_pin        = AT91_PIN_PB31,
508         .chipselect     = 5,
509         .flags          = AT91_CF_TRUE_IDE,
510 };
511
512 /* Power Off by RTC */
513 static void gsia18s_power_off(void)
514 {
515         pr_notice("Power supply will be switched off automatically now or after 60 seconds without ArmDAS.\n");
516         at91_set_gpio_output(AT91_PIN_PA25, 1);
517         /* Spin to death... */
518         while (1)
519                 ;
520 }
521
522 static int __init gsia18s_power_off_init(void)
523 {
524         pm_power_off = gsia18s_power_off;
525         return 0;
526 }
527
528 /* ---------------------------------------------------------------------------*/
529
530 static void __init gsia18s_board_init(void)
531 {
532         /*
533          * USART0 on ttyS1 (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI).
534          * Used for Internal Analog Modem.
535          */
536         at91_register_uart(AT91SAM9260_ID_US0, 1,
537                                 ATMEL_UART_CTS | ATMEL_UART_RTS |
538                                 ATMEL_UART_DTR | ATMEL_UART_DSR |
539                                 ATMEL_UART_DCD | ATMEL_UART_RI);
540         /*
541          * USART1 on ttyS2 (Rx, Tx, CTS, RTS).
542          * Used for GPS or WiFi or Data stream.
543          */
544         at91_register_uart(AT91SAM9260_ID_US1, 2,
545                                 ATMEL_UART_CTS | ATMEL_UART_RTS);
546         /*
547          * USART2 on ttyS3 (Rx, Tx, CTS, RTS).
548          * Used for External Modem.
549          */
550         at91_register_uart(AT91SAM9260_ID_US2, 3,
551                                 ATMEL_UART_CTS | ATMEL_UART_RTS);
552         /*
553          * USART3 on ttyS4 (Rx, Tx, RTS).
554          * Used for RS-485.
555          */
556         at91_register_uart(AT91SAM9260_ID_US3, 4, ATMEL_UART_RTS);
557
558         /*
559          * USART4 on ttyS5 (Rx, Tx).
560          * Used for TRX433 Radio Module.
561          */
562         at91_register_uart(AT91SAM9260_ID_US4, 5, 0);
563         stamp9g20_board_init();
564         at91_add_device_usbh(&usbh_data);
565         at91_add_device_udc(&udc_data);
566         at91_add_device_eth(&macb_data);
567         gsia18s_leds_init();
568         gsia18s_pcf_leds_init();
569         gsia18s_add_device_buttons();
570         at91_add_device_i2c(gsia18s_i2c_devices,
571                                 ARRAY_SIZE(gsia18s_i2c_devices));
572         at91_add_device_cf(&gsia18s_cf1_data);
573         at91_add_device_spi(gsia18s_spi_devices,
574                                 ARRAY_SIZE(gsia18s_spi_devices));
575         gsia18s_power_off_init();
576 }
577
578 MACHINE_START(GSIA18S, "GS_IA18_S")
579         .init_time      = at91_init_time,
580         .map_io         = at91_map_io,
581         .handle_irq     = at91_aic_handle_irq,
582         .init_early     = gsia18s_init_early,
583         .init_irq       = at91_init_irq_default,
584         .init_machine   = gsia18s_board_init,
585 MACHINE_END