summaryrefslogtreecommitdiff
path: root/io-module/mts_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io-module/mts_io.c')
-rw-r--r--io-module/mts_io.c584
1 files changed, 147 insertions, 437 deletions
diff --git a/io-module/mts_io.c b/io-module/mts_io.c
index 229a8f7..6ce8981 100644
--- a/io-module/mts_io.c
+++ b/io-module/mts_io.c
@@ -5,6 +5,7 @@
*
* Authors: James Maki <jmaki@multitech.com>
* Jesse Gilles <jgilles@multitech.com>
+ * Mike Fiore <mfiore@multitech.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -53,34 +54,35 @@
#define LED_LS_CONTROLLABLE 0
-#define AT91SAM9X5_BASE_ADC 0xf804c000
-
/* on-board EEPROM */
extern uint8_t mts_id_eeprom[512];
static struct mts_id_eeprom_layout id_eeprom;
-/* accessory card EEPROMs */
-#ifdef MTOCGD2
-extern uint8_t mts_ap1_eeprom[512];
-extern uint8_t mts_ap2_eeprom[512];
+// NUM_AP should be defined from the board code
+// it should be set to the value of CONFIG_MTS_NUM_ACCESSORY_PORTS
+// arch/arm/mach-at91/board-dt-sam9.c
+// if it is 0 or undefined, there is no accessory card support on this HW
+#ifdef CONFIG_MTS_NUM_ACCESSORY_PORTS
+
+#ifndef NUM_AP
+#define NUM_AP CONFIG_MTS_NUM_ACCESSORY_PORTS
+#endif
+
#else
-uint8_t mts_ap1_eeprom[512] = {};
-uint8_t mts_ap2_eeprom[512] = {};
+#define NUM_AP 0
#endif
-static struct mts_ap_eeprom_layout ap1_eeprom;
-static struct mts_ap_eeprom_layout ap2_eeprom;
-bool accessory_card_capable = false;
-bool has_accessory_card_port_1 = false;
-bool has_accessory_card_port_2 = false;
+#if NUM_AP > 0
+/* accessory card EEPROMs */
+extern uint8_t mts_ap_eeprom[NUM_AP][512];
+static struct mts_ap_eeprom_layout ap_eeprom[NUM_AP];
+/* kobject pointers for the apX subdirectories that correspond to the accessory ports */
+static struct kobject *ap_subdirs[NUM_AP];
+/* attribute groups for the accessory ports*/
+static struct attribute_group ap_attr_groups[NUM_AP];
+#endif
-static uint8_t mts_product_id;
-static uint8_t mts_ap1_product_id;
-static uint8_t mts_ap2_product_id;
-static uint8_t has_spi_sout;
-static uint8_t has_spi_din;
-static uint8_t has_spi_dout;
-static uint8_t has_spi_temp;
+static struct ap_info* port_info[NUM_AP];
static struct platform_device *mts_io_platform_device;
static struct attribute_group *attr_group;
@@ -91,17 +93,10 @@ static DEFINE_MUTEX(mts_io_mutex);
/* generic GPIO support */
#include "gpio.c"
-/* AT91 built-in ADC */
-#include "adc.c"
-
-/* SPI-based stuff */
-#include "spi.c"
-
/* accessory card support */
-#include "mtdc_gpiob.c"
-
-/* telit radio reset handling */
-#include "telit_radio.c"
+#include "mtac.c"
+#include "mtac_gpiob.c"
+#include "mtac_mfser.c"
/* reset button handling */
#define RESET_CHECK_PER_SEC 8
@@ -252,62 +247,12 @@ static ssize_t mts_attr_store_radio_reset(struct device *dev,
return count;
}
-static ssize_t mts_attr_store_ndc_reset(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
-{
- int value;
- int err;
- struct gpio_pin *pin;
-
- if (sscanf(buf, "%i", &value) != 1) {
- return -EINVAL;
- }
- if (value != 0) {
- return -EINVAL;
- }
-
- pin = gpio_pin_by_name("NDC_RESET");
-
- if (!pin) {
- return -ENODEV;
- }
-
- mutex_lock(&mts_io_mutex);
-
- // 1ms low reset
- err = reset_gpio_pin(pin, 1, 0);
-
- mutex_unlock(&mts_io_mutex);
-
- if (err) {
- return err;
- }
-
- return count;
-}
-
static DEVICE_ATTR_MTS(dev_attr_radio_reset, "radio-reset",
mts_attr_show_gpio_pin, mts_attr_store_radio_reset);
-static DEVICE_ATTR_MTS(dev_attr_ndc_reset, "ndc-reset",
- mts_attr_show_gpio_pin, mts_attr_store_ndc_reset);
/* shared gpio attributes */
static DEVICE_ATTR_MTS(dev_attr_radio_power, "radio-power",
mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
-static DEVICE_ATTR_MTS(dev_attr_eth0_enabled, "eth0-enabled",
- mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
-static DEVICE_ATTR_MTS(dev_attr_bt_enabled, "bt-enabled",
- mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
-static DEVICE_ATTR_MTS(dev_attr_wlan_enabled, "wlan-enabled",
- mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
-static DEVICE_ATTR_RO_MTS(dev_attr_extserial_dtr, "extserial-dtr",
- mts_attr_show_gpio_pin);
-static DEVICE_ATTR_MTS(dev_attr_extserial_dsr_gpio, "extserial-dsr",
- mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
-static DEVICE_ATTR_MTS(dev_attr_extserial_ri_gpio, "extserial-ri",
- mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
-static DEVICE_ATTR_MTS(dev_attr_extserial_dcd_gpio, "extserial-dcd",
- mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
/* shared gpio-based LEDs */
static DEVICE_ATTR_MTS(dev_attr_led_status, "led-status",
@@ -323,8 +268,6 @@ static DEVICE_ATTR_RO_MTS(dev_attr_led_ls, "led-ls",
mts_attr_show_gpio_pin);
#endif
-static DEVICE_ATTR_MTS(dev_attr_led_wifi_gpio, "led-wifi",
- mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
static DEVICE_ATTR_MTS(dev_attr_led_b_gpio, "led-b",
mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
@@ -344,9 +287,6 @@ static DEVICE_ATTR_MTS(dev_attr_led_d_gpio, "led-d",
mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
static DEVICE_ATTR_MTS(dev_attr_led_e_gpio, "led-e",
mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
-static DEVICE_ATTR_MTS(dev_attr_led_f_gpio, "led-f",
- mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
-
/* eeprom info */
static ssize_t mts_attr_show_product_info(struct device *dev,
@@ -365,14 +305,6 @@ static ssize_t mts_attr_show_product_info(struct device *dev,
value = sprintf(buf, "%.32s\n", id_eeprom.hw_version);
} else if (strcmp(attr->attr.name, "imei") == 0) {
value = sprintf(buf, "%.32s\n", id_eeprom.imei);
- } else if (strcmp(attr->attr.name, "mac-wifi") == 0) {
- value = sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X\n",
- id_eeprom.mac_wifi[0],
- id_eeprom.mac_wifi[1],
- id_eeprom.mac_wifi[2],
- id_eeprom.mac_wifi[3],
- id_eeprom.mac_wifi[4],
- id_eeprom.mac_wifi[5]);
} else if (strcmp(attr->attr.name, "mac-eth") == 0) {
value = sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X\n",
id_eeprom.mac_addr[0],
@@ -399,166 +331,89 @@ static DEVICE_ATTR_RO_MTS(dev_attr_hw_version, "hw-version",
mts_attr_show_product_info);
static DEVICE_ATTR_RO_MTS(dev_attr_imei, "imei",
mts_attr_show_product_info);
-static DEVICE_ATTR_RO_MTS(dev_attr_wifi_mac, "mac-wifi",
- mts_attr_show_product_info);
static DEVICE_ATTR_RO_MTS(dev_attr_eth_mac, "mac-eth",
mts_attr_show_product_info);
/* include per-device pins and attributes */
-#include "mtr2.c"
-#include "mtr.c"
#include "mtr2d2.c"
-/* currently not supported
-#include "mtcdp.c"
-#include "mt100eocg.c"
-*/
+static bool load_port(int port) {
+ int port_index = port - 1;
+ memcpy(&ap_eeprom[port_index], mts_ap_eeprom[port_index], sizeof(mts_ap_eeprom[port_index]));
-/* reorg this function to load and log both accessory card EEPROMs
- * should be able to handle either or both slots being empty
- */
-static int mts_ap_eeprom_load(void)
-{
- memcpy(&ap1_eeprom, mts_ap1_eeprom, sizeof(mts_ap1_eeprom));
+ if (mts_ap_eeprom[port_index][0] == 0xFF) {
+ log_error("uninitialized eeprom on accessory card %d", port);
+ } else if (mts_ap_eeprom[port_index][0] == 0x00) {
+ log_info("no accessory card inserted in port %d", port);
+ } else {
+ port_info[port_index] = kzalloc(sizeof(struct ap_info), GFP_KERNEL);
+ if (! port_info[port_index]) {
+ log_error("alloc of port info failed");
+ return false;
+ }
- if (mts_ap1_eeprom[0] == 0xFF) {
- log_error("uninitialized eeprom on accessory card");
- return -EIO;
- } else if (mts_ap1_eeprom[0] == 0x00) {
- log_info("no accessory card inserted");
- return 0;
+ if (strstr(ap_eeprom[port_index].product_id, PRODUCT_ID_MTAC_GPIOB)) {
+ if (! set_gpiob_info(port_info[port_index])) {
+ log_error("failed to set up gpiob port info");
+ return false;
+ }
+ } else if (strstr(ap_eeprom[port_index].product_id, PRODUCT_ID_MTAC_MFSER)) {
+ if (! set_mfser_info(port_info[port_index])) {
+ log_error("failed to set up mfser port info");
+ return false;
+ }
+ } else {
+ log_error("unknown accessory card [%s] in port %d", ap_eeprom[port_index].product_id, port);
+ return false;
+ }
+
+ log_info("accessory card %d vendor-id: %.32s", port, ap_eeprom[port_index].vendor_id);
+ log_info("accessory card %d product-id: %.32s", port, ap_eeprom[port_index].product_id);
+ log_info("accessory card %d device-id: %.32s", port, ap_eeprom[port_index].device_id);
+ log_info("accessory card %d hw-version: %.32s", port, ap_eeprom[port_index].hw_version);
+ if (strncmp(ap_eeprom[port_index].product_id, PRODUCT_ID_MTAC_ETH, strlen(PRODUCT_ID_MTAC_ETH)) == 0) {
+ log_info("accessory card %d mac-addr: %02X:%02X:%02X:%02X:%02X:%02X",
+ port,
+ ap_eeprom[port_index].mac_addr[0],
+ ap_eeprom[port_index].mac_addr[1],
+ ap_eeprom[port_index].mac_addr[2],
+ ap_eeprom[port_index].mac_addr[3],
+ ap_eeprom[port_index].mac_addr[4],
+ ap_eeprom[port_index].mac_addr[5]);
+ }
+
+ if (! port_info[port_index]->setup(port)) {
+ log_error("accessory port %d setup failed", port);
+ port_info[port_index]->teardown(port);
+ kfree(port_info[port]);
+ return false;
+ }
}
- has_accessory_card_port_1 = true;
-
- log_info("accessory card vendor-id: %.32s", ap1_eeprom.vendor_id);
- log_info("accessory card product-id: %.32s", ap1_eeprom.product_id);
- log_info("accessory card device-id: %.32s", ap1_eeprom.device_id);
- log_info("accessory card hw-version: %.32s", ap1_eeprom.hw_version);
- /* TODO: only show the mac address if this is the ethernet card */
- log_info("accessory card mac-addr: %02X:%02X:%02X:%02X:%02X:%02X",
- ap1_eeprom.mac_addr[0],
- ap1_eeprom.mac_addr[1],
- ap1_eeprom.mac_addr[2],
- ap1_eeprom.mac_addr[3],
- ap1_eeprom.mac_addr[4],
- ap1_eeprom.mac_addr[5]);
+ return true;
+}
- return 0;
+static void init_accessory_ports(void)
+{
+ int i;
+ for (i = 1; i <= NUM_AP; i++) {
+ if (! load_port(i)) {
+ log_error("failed to load accessory card in port %d", i);
+ }
+ }
}
static int mts_id_eeprom_load(void)
{
memcpy(&id_eeprom, mts_id_eeprom, sizeof(mts_id_eeprom));
- mts_product_id = MTCDP_E1_DK_1_0;
- has_spi_sout = 1;
- has_spi_din = 1;
- has_spi_dout = 1;
- has_spi_temp = 1;
-
if (mts_id_eeprom[0] == 0xFF) {
log_error("uninitialized eeprom");
return -EIO;
- /*
- } else if (mts_id_eeprom[0] == 0x00) {
- strncpy(id_eeprom.vendor_id, VENDOR_ID_MULTITECH, sizeof(id_eeprom.vendor_id) - 1);
- strncpy(id_eeprom.product_id, PRODUCT_ID_MTCDP_E1_DK, sizeof(id_eeprom.product_id) - 1);
- strncpy(id_eeprom.device_id, "", sizeof(id_eeprom.device_id) - 1);
- strncpy(id_eeprom.hw_version, HW_VERSION_MTCDP_0_0, sizeof(id_eeprom.hw_version) - 1);
-
- DEVICE_CAPA_SET(id_eeprom.capa, CAPA_GPS);
-
- attr_group = &mtcdp_platform_attribute_group;
- gpio_pins = gpio_pins_mtcdp_0_0;
- mts_product_id = MTCDP_E1_DK_0_0;
- log_info("detected board %s", HW_VERSION_MTCDP_0_0);
- } else if (strncmp(id_eeprom.product_id, PRODUCT_ID_MT100EOCG, strlen(PRODUCT_ID_MT100EOCG)) == 0) {
- attr_group = &mt100eocg_platform_attribute_group;
- gpio_pins = gpio_pins_mt100eocg_0_0;
- mts_product_id = MT100EOCG_0_0;
- has_spi_sout = 0;
- has_spi_din = 1;
- has_spi_dout = 1;
- has_spi_temp = 1;
- log_info("detected board %s", HW_VERSION_MT100EOCG_0_0);
- */
- } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTR2_0_0, strlen(HW_VERSION_MTR2_0_0)) == 0) {
- attr_group = &mtr2_platform_attribute_group;
- gpio_pins = gpio_pins_mtr2_0_0;
- mts_product_id = MTR2_0_0;
- accessory_card_capable = true;
- has_spi_sout = 0;
- has_spi_din = 0;
- has_spi_dout = 0;
- has_spi_temp = 1;
- log_info("detected board %s", HW_VERSION_MTR2_0_0);
- } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTR_0_0, strlen(HW_VERSION_MTR_0_0)) == 0) {
- attr_group = &mtr_platform_attribute_group;
- gpio_pins = gpio_pins_mtr_0_0;
- mts_product_id = MTR_0_0;
- has_spi_sout = 0;
- has_spi_din = 0;
- has_spi_dout = 0;
- has_spi_temp = 0;
- log_info("detected board %s", HW_VERSION_MTR_0_0);
- } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTR_0_1, strlen(HW_VERSION_MTR_0_1)) == 0) {
- attr_group = &mtr_platform_attribute_group;
- gpio_pins = gpio_pins_mtr_0_1;
- mts_product_id = MTR_0_1;
- has_spi_sout = 0;
- has_spi_din = 0;
- has_spi_dout = 0;
- has_spi_temp = 0;
- log_info("detected board %s", HW_VERSION_MTR_0_1);
- } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTOCGD2_0_0, strlen(HW_VERSION_MTOCGD2_0_0)) == 0) {
- attr_group = &mtr2_platform_attribute_group;
- gpio_pins = gpio_pins_mtr2_0_0;
- mts_product_id = MTOCGD2_0_0;
- accessory_card_capable = true;
- has_spi_sout = 0;
- has_spi_din = 0;
- has_spi_dout = 0;
- has_spi_temp = 1;
- log_info("detected board %s", HW_VERSION_MTOCGD2_0_0);
- } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTOCGD_0_0, strlen(HW_VERSION_MTOCGD_0_0)) == 0) {
- attr_group = &mtr_platform_attribute_group;
- gpio_pins = gpio_pins_mtr_0_0;
- mts_product_id = MTOCGD_0_0;
- has_spi_sout = 0;
- has_spi_din = 0;
- has_spi_dout = 0;
- has_spi_temp = 0;
- log_info("detected board %s", HW_VERSION_MTOCGD_0_0);
- } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTOCGD_0_1, strlen(HW_VERSION_MTOCGD_0_1)) == 0) {
- attr_group = &mtr_platform_attribute_group;
- gpio_pins = gpio_pins_mtr_0_1;
- mts_product_id = MTOCGD_0_1;
- has_spi_sout = 0;
- has_spi_din = 0;
- has_spi_dout = 0;
- has_spi_temp = 0;
- log_info("detected board %s", HW_VERSION_MTOCGD_0_1);
- } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTR2D2_0_0, strlen(HW_VERSION_MTR2D2_0_0)) == 0) {
+ } else {
attr_group = &mtr2d2_platform_attribute_group;
gpio_pins = gpio_pins_mtr2d2_0_0;
- mts_product_id = MTR2D2_0_0;
- has_spi_sout = 0;
- has_spi_din = 0;
- has_spi_dout = 0;
- has_spi_temp = 0;
log_info("detected board %s", HW_VERSION_MTR2D2_0_0);
- /*
- } else {
- attr_group = &mtcdp_platform_attribute_group;
- gpio_pins = gpio_pins_mtcdp_1_0;
- mts_product_id = MTCDP_E1_DK_1_0;
- has_spi_sout = 1;
- has_spi_din = 1;
- has_spi_dout = 1;
- has_spi_temp = 1;
- log_info("detected board %s", HW_VERSION_MTCDP_1_0);
- */
}
log_info("sizeof: %lu", (unsigned long) sizeof(struct mts_id_eeprom_layout));
@@ -580,97 +435,69 @@ static int mts_id_eeprom_load(void)
log_info("capa-adc: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_ADC) ? "yes" : "no");
log_info("capa-wifi: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_WIFI) ? "yes" : "no");
log_info("capa-bluetooth: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_BLUETOOTH) ? "yes" : "no");
- log_info("mac-bluetooth: %02X:%02X:%02X:%02X:%02X:%02X",
- id_eeprom.mac_bluetooth[0],
- id_eeprom.mac_bluetooth[1],
- id_eeprom.mac_bluetooth[2],
- id_eeprom.mac_bluetooth[3],
- id_eeprom.mac_bluetooth[4],
- id_eeprom.mac_bluetooth[5]);
- log_info("mac-wifi: %02X:%02X:%02X:%02X:%02X:%02X",
- id_eeprom.mac_wifi[0],
- id_eeprom.mac_wifi[1],
- id_eeprom.mac_wifi[2],
- id_eeprom.mac_wifi[3],
- id_eeprom.mac_wifi[4],
- id_eeprom.mac_wifi[5]);
+ if (DEVICE_CAPA(id_eeprom.capa, CAPA_BLUETOOTH)) {
+ log_info("mac-bluetooth: %02X:%02X:%02X:%02X:%02X:%02X",
+ id_eeprom.mac_bluetooth[0],
+ id_eeprom.mac_bluetooth[1],
+ id_eeprom.mac_bluetooth[2],
+ id_eeprom.mac_bluetooth[3],
+ id_eeprom.mac_bluetooth[4],
+ id_eeprom.mac_bluetooth[5]);
+ }
+ if (DEVICE_CAPA(id_eeprom.capa, CAPA_WIFI)) {
+ log_info("mac-wifi: %02X:%02X:%02X:%02X:%02X:%02X",
+ id_eeprom.mac_wifi[0],
+ id_eeprom.mac_wifi[1],
+ id_eeprom.mac_wifi[2],
+ id_eeprom.mac_wifi[3],
+ id_eeprom.mac_wifi[4],
+ id_eeprom.mac_wifi[5]);
+ }
return 0;
}
+static void cleanup(void)
+{
+ int port;
+ int port_index;
+
+ log_info("cleaning up....");
+ sysfs_remove_link(&mts_io_platform_device->dev.parent->kobj, "mtcdp");
+ platform_device_unregister(mts_io_platform_device);
+ for (port_index = 0, port = 1; port_index < NUM_AP; port_index++, port++) {
+ if (port_info[port_index]) {
+ port_info[port_index]->teardown(port);
+ kfree(port_info[port_index]);
+ }
+ }
+ log_info("done cleaning up....");
+}
+
static int __init mts_io_init(void)
{
struct gpio_pin *pin;
int ret;
+ int port_index;
log_info("init: " DRIVER_VERSION);
ret = mts_id_eeprom_load();
if (ret) {
- goto error1;
- }
-
- if (accessory_card_capable) {
- mts_ap1_product_id = MTDC_NONE;
- ret = mts_ap_eeprom_load();
- if (ret) {
- /* error reading the EEPROM from the accessory card */
- log_error("error reading accessory card eeprom: %d", ret);
- log_error("unable to initialize accessory card");
- } else if (has_accessory_card_port_1) {
- /* no error and we have a accessory card */
- if (strstr(ap1_eeprom.product_id, PRODUCT_ID_MTDC_GPIOB)) {
- mts_ap1_product_id = MTDC_GPIOB_0_0;
- }
-
- switch(mts_ap1_product_id) {
- case MTDC_GPIOB_0_0:
- log_debug("adding GPIO accessory card attributes");
- if (! mtr2_add_accessory_card_attributes()) {
- log_error("failed to add GPIO accessory card attributes");
- goto error1;
- } else {
- log_info("successfully added GPIO accessory card attributes");
- }
-
- log_debug("registering accessory card dout driver");
- ret = spi_register_driver(&mts_spi_dc_dout_driver);
- if (ret) {
- log_error("failed to register dc dout driver");
- spi_unregister_driver(&mts_spi_dc_dout_driver);
- goto error1;
- }
- log_debug("registering accessory card din driver");
- ret = spi_register_driver(&mts_spi_dc_din_driver);
- if (ret) {
- log_error("failed to register dc din driver");
- spi_unregister_driver(&mts_spi_dc_din_driver);
- goto error1;
- }
- log_debug("registering accessory card adc driver");
- ret = spi_register_driver(&mts_spi_dc_adc_driver);
- if (ret) {
- log_error("failed to register dc adc driver");
- spi_unregister_driver(&mts_spi_dc_adc_driver);
- goto error1;
- }
- break;
-
- default:
- log_info("accessory card '%s' currently unsupported", ap1_eeprom.product_id);
- }
- }
+ cleanup();
+ return ret;
}
mts_io_platform_device = platform_device_alloc(PLATFORM_NAME, -1);
if (!mts_io_platform_device) {
- ret = -ENOMEM;
- goto error1;
+ cleanup();
+ return -ENOMEM;
}
ret = platform_device_add(mts_io_platform_device);
if (ret) {
- goto error2;
+ cleanup();
+ return ret;
}
/* preserve backwards compatibility with old mtcdp platform name */
@@ -679,62 +506,21 @@ static int __init mts_io_init(void)
"mtcdp");
if (ret) {
log_error("sysfs_create_link failed: %d", ret);
- goto error3;
- }
-
- ret = sysfs_create_group(&mts_io_platform_device->dev.kobj, attr_group);
- if (ret) {
- goto error4;
- }
-
- if ( has_spi_sout ) {
- ret = spi_register_driver(&mts_spi_sout_driver);
- if (ret) {
- goto error5;
- }
- }
-
- if ( has_spi_dout ) {
- ret = spi_register_driver(&mts_spi_dout_driver);
- if (ret) {
- goto error6;
- }
- }
- if ( has_spi_din ) {
- ret = spi_register_driver(&mts_spi_din_driver);
- if (ret) {
- goto error7;
- }
+ cleanup();
+ return ret;
}
- if ( has_spi_temp ) {
- ret = spi_register_driver(&mts_spi_board_temp_driver);
- if (ret) {
- goto error8;
+ if (NUM_AP) {
+ for (port_index = 0; port_index < NUM_AP; port_index++) {
+ port_info[port_index] = NULL;
}
+ init_accessory_ports();
}
- /* ADC Setup */
-#ifdef CONFIG_SOC_AT91SAM9X5
- adc_base = ioremap(AT91SAM9X5_BASE_ADC, SZ_16K);
-#else
- adc_base = ioremap(AT91SAM9260_BASE_ADC, SZ_16K);
-#endif
- if (!adc_base) {
- goto error9;
- }
-
- adc_clk = clk_get(NULL, "adc_clk");
- if (!adc_clk) {
- goto error10;
- }
- clk_enable(adc_clk);
-
- ADC_CONVERT_RESET(adc_base);
- writel(ADC_MODE_DEFAULT, adc_base + ADC_MR_OFFSET);
- writel(0x000F0F0F, adc_base + ADC_IDR_OFFSET);
- if (!DEVICE_CAPA(id_eeprom.capa, CAPA_ADC)) {
- writel(0x0F, adc_base + ADC_CHDR_OFFSET);
+ ret = sysfs_create_group(&mts_io_platform_device->dev.kobj, attr_group);
+ if (ret) {
+ cleanup();
+ return ret;
}
for (pin = gpio_pins; *pin->name; pin++) {
@@ -744,92 +530,17 @@ static int __init mts_io_init(void)
}
}
- if ( has_spi_sout || has_spi_dout || has_spi_din ) {
- pin = gpio_pin_by_name("ENIO");
- if (pin) {
- gpio_set_value(pin->pin.gpio, 0);
- }
- }
-
- // No reset_callback for MT100EOCG
- if ( mts_product_id != MT100EOCG_0_0 ) {
- reset_callback(NULL);
- }
+ // start the reset handler
+ reset_callback(NULL);
return 0;
-
-error10:
- iounmap(adc_base);
-error9:
- if ( has_spi_temp ) {
- spi_unregister_driver(&mts_spi_board_temp_driver);
- }
-error8:
- if ( has_spi_din ) {
- spi_unregister_driver(&mts_spi_din_driver);
- }
-error7:
- if ( has_spi_dout ) {
- spi_unregister_driver(&mts_spi_dout_driver);
- }
-error6:
- if ( has_spi_sout ) {
- spi_unregister_driver(&mts_spi_sout_driver);
- }
-error5:
- sysfs_remove_group(&mts_io_platform_device->dev.kobj, attr_group);
-error4:
- sysfs_remove_link(&mts_io_platform_device->dev.parent->kobj, "mtcdp");
-error3:
- platform_device_del(mts_io_platform_device);
-error2:
- platform_device_put(mts_io_platform_device);
-error1:
- log_error("init failed: %d", ret);
-
- return ret;
}
static void __exit mts_io_exit(void)
{
- if ( mts_product_id != MT100EOCG_0_0 ) {
- cancel_delayed_work_sync(&reset_work);
- }
-
- iounmap(adc_base);
- clk_disable(adc_clk);
- clk_put(adc_clk);
-
- if (has_spi_temp)
- spi_unregister_driver(&mts_spi_board_temp_driver);
-
- if (has_spi_din)
- spi_unregister_driver(&mts_spi_din_driver);
-
- if (has_spi_dout)
- spi_unregister_driver(&mts_spi_dout_driver);
+ cancel_delayed_work_sync(&reset_work);
- if (has_spi_sout)
- spi_unregister_driver(&mts_spi_sout_driver);
-
- if (has_accessory_card_port_1) {
- switch (mts_ap1_product_id) {
- case MTDC_GPIOB_0_0:
- spi_unregister_driver(&mts_spi_dc_dout_driver);
- spi_unregister_driver(&mts_spi_dc_din_driver);
- spi_unregister_driver(&mts_spi_dc_adc_driver);
- break;
-
- default:
- break;
- }
- }
-
- sysfs_remove_group(&mts_io_platform_device->dev.kobj, attr_group);
-
- sysfs_remove_link(&mts_io_platform_device->dev.parent->kobj, "mtcdp");
-
- platform_device_unregister(mts_io_platform_device);
+ cleanup();
log_info("exiting");
}
@@ -842,10 +553,9 @@ MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_VERSION(DRIVER_VERSION);
MODULE_LICENSE("GPL");
-MODULE_ALIAS("mts-io-sout");
-MODULE_ALIAS("mts-io-board-temp");
-MODULE_ALIAS("mts-io-dout");
-MODULE_ALIAS("mts-io-din");
-MODULE_ALIAS("mts-io-dc-dout");
-MODULE_ALIAS("mts-io-dc-din");
-MODULE_ALIAS("mts-io-dc-adc");
+MODULE_ALIAS("mts-io-ap1-dout");
+MODULE_ALIAS("mts-io-ap1-din");
+MODULE_ALIAS("mts-io-ap1-adc");
+MODULE_ALIAS("mts-io-ap2-dout");
+MODULE_ALIAS("mts-io-ap2-din");
+MODULE_ALIAS("mts-io-ap2-adc");