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