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