summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2014-10-08 11:24:40 -0500
committerMike Fiore <mfiore@multitech.com>2014-10-08 11:24:40 -0500
commitddb473a94114a6de7f0ec0dbd3a90021b2baa87f (patch)
treeffdb8e1f1ba7f9628e3ffc5d9c207f744a8b020f
parent8be9080418b18941129e56b44f7c5218a5a73932 (diff)
downloadmts-io-ddb473a94114a6de7f0ec0dbd3a90021b2baa87f.tar.gz
mts-io-ddb473a94114a6de7f0ec0dbd3a90021b2baa87f.tar.bz2
mts-io-ddb473a94114a6de7f0ec0dbd3a90021b2baa87f.zip
mts-io: improve cleanup on module unload or init error
remove unused attributes remove unused files clean up mtr2d2.c
-rw-r--r--io-module/mtr2d2.c49
-rw-r--r--io-module/mts_io.c138
-rw-r--r--io-module/telit_radio.c219
3 files changed, 30 insertions, 376 deletions
diff --git a/io-module/mtr2d2.c b/io-module/mtr2d2.c
index 428d71c..7e44881 100644
--- a/io-module/mtr2d2.c
+++ b/io-module/mtr2d2.c
@@ -265,9 +265,6 @@ static struct gpio_pin gpio_pins_mtr2d2_0_0[] = {
{ },
};
-static int mtr2d2_platform_attributes_max_size = 64; // including NULL at end
-static int mtr2d2_platform_attributes_size = 21;
-
static struct attribute *mtr2d2_platform_attributes[] = {
&dev_attr_vendor_id.attr,
&dev_attr_product_id.attr,
@@ -291,52 +288,6 @@ static struct attribute *mtr2d2_platform_attributes[] = {
&dev_attr_led_c_gpio.attr,
&dev_attr_led_d_gpio.attr,
&dev_attr_led_e_gpio.attr,
-
- /* extra space for the accessory card attributes */
- NULL, // index 20
- NULL, // index 21
- NULL, // index 22
- NULL, // index 23
- NULL, // index 24
- NULL, // index 25
- NULL, // index 26
- NULL, // index 27
- NULL, // index 28
- NULL, // index 29
- NULL, // index 30
- NULL, // index 31
- NULL, // index 32
- NULL, // index 33
- NULL, // index 34
- NULL, // index 35
- NULL, // index 36
- NULL, // index 37
- NULL, // index 38
- NULL, // index 39
- NULL, // index 40
- NULL, // index 41
- NULL, // index 42
- NULL, // index 43
- NULL, // index 44
- NULL, // index 45
- NULL, // index 46
- NULL, // index 47
- NULL, // index 48
- NULL, // index 49
- NULL, // index 50
- NULL, // index 51
- NULL, // index 52
- NULL, // index 53
- NULL, // index 54
- NULL, // index 55
- NULL, // index 56
- NULL, // index 57
- NULL, // index 58
- NULL, // index 59
- NULL, // index 60
- NULL, // index 61
- NULL, // index 62
- NULL, // index 63
NULL,
};
diff --git a/io-module/mts_io.c b/io-module/mts_io.c
index fa61e1f..0710345 100644
--- a/io-module/mts_io.c
+++ b/io-module/mts_io.c
@@ -98,9 +98,6 @@ static DEFINE_MUTEX(mts_io_mutex);
#include "mtac_gpiob.c"
#include "mtac_mfser.c"
-/* telit radio reset handling */
-#include "telit_radio.c"
-
/* reset button handling */
#define RESET_CHECK_PER_SEC 8
#define RESET_INTERVAL (HZ / RESET_CHECK_PER_SEC)
@@ -250,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",
@@ -321,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);
@@ -342,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,
@@ -515,29 +457,46 @@ static int mts_id_eeprom_load(void)
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;
int port_index;
log_info("init: " DRIVER_VERSION);
ret = mts_id_eeprom_load();
if (ret) {
- goto error1;
+ 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 */
@@ -546,71 +505,34 @@ static int __init mts_io_init(void)
"mtcdp");
if (ret) {
log_error("sysfs_create_link failed: %d", ret);
- goto error3;
+ cleanup();
+ return ret;
}
if (NUM_AP) {
- for (port = 0; port < NUM_AP; port++) {
- port_info[port] = NULL;
+ for (port_index = 0; port_index < NUM_AP; port_index++) {
+ port_info[port_index] = NULL;
}
init_accessory_ports();
}
ret = sysfs_create_group(&mts_io_platform_device->dev.kobj, attr_group);
if (ret) {
- goto error4;
- }
-
- for (pin = gpio_pins; *pin->name; pin++) {
- ret = gpio_request_one(pin->pin.gpio, pin->pin.flags, pin->pin.label);
- if (ret) {
- log_debug("could not request pin %s (%d) but it could have already been requested under a different pin name", pin->name, ret);
- }
+ cleanup();
+ return ret;
}
// start the reset handler
reset_callback(NULL);
return 0;
-
-error4:
- sysfs_remove_group(&mts_io_platform_device->dev.kobj, attr_group);
- 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);
- for (port = 0, port_index = 1; port < NUM_AP; port++, port_index++) {
- if (port_info[port]) {
- port_info[port]->teardown(port_index);
- kfree(port_info[port]);
- }
- }
-
- return ret;
}
static void __exit mts_io_exit(void)
{
- int port;
- int port_index;
-
cancel_delayed_work_sync(&reset_work);
- 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);
-
- for (port = 0, port_index = 1; port < NUM_AP; port++, port_index++) {
- if (port_info[port]) {
- port_info[port]->teardown(port_index);
- kfree(port_info[port]);
- }
- }
+ cleanup();
log_info("exiting");
}
diff --git a/io-module/telit_radio.c b/io-module/telit_radio.c
deleted file mode 100644
index fbac4fa..0000000
--- a/io-module/telit_radio.c
+++ /dev/null
@@ -1,219 +0,0 @@
-
-static int radio_off_telit(void)
-{
- int value, ret;
- struct gpio_pin *pwrmon_pin = gpio_pin_by_name("PWRMON");
- struct gpio_pin *onoff_pin = gpio_pin_by_name("3G_ONOFF");
- struct gpio_pin *rst_pin = gpio_pin_by_name("3G_RST");
-
- if (!onoff_pin || !pwrmon_pin || !rst_pin) {
- return -ENODEV;
- }
-
- value = gpio_get_value(pwrmon_pin->pin.gpio);
- if(value == 0) {
- log_error("radio is already off");
- return -EINVAL;
- }
-
- // drive on/off pin low for at least 3 sec
- log_info("shutting down radio");
- ret = gpio_direction_output_pullup(onoff_pin->pin.gpio, 0, onoff_pin->pin.flags & GPIOF_PULLUP);
- if (ret) {
- return ret;
- }
-
- msleep(3500);
-
- // set on/off pin high
- ret = gpio_direction_output_pullup(onoff_pin->pin.gpio, 1, onoff_pin->pin.flags & GPIOF_PULLUP);
- if (ret) {
- return ret;
- }
-
- // wait for radio to power off
- msleep(5000);
-
- // check that power is low
- value = gpio_get_value(pwrmon_pin->pin.gpio);
- if(value != 0) {
- log_warning("radio is still on. performing radio reset.");
- //Perform Hard Reset
- ret = gpio_direction_output_pullup(rst_pin->pin.gpio, 0, rst_pin->pin.flags & GPIOF_PULLUP);
- if (ret) {
- return ret;
- }
-
- msleep(500);
-
- // set pin high
- ret = gpio_direction_output_pullup(rst_pin->pin.gpio, 1, rst_pin->pin.flags & GPIOF_PULLUP);
- if (ret) {
- return ret;
- }
- } else {
- log_info("radio has been shut down");
- }
-
- return ret;
-}
-
-static int radio_on_telit(void)
-{
- int value, ret;
- struct gpio_pin *pwrmon_pin = gpio_pin_by_name("PWRMON");
- struct gpio_pin *onoff_pin = gpio_pin_by_name("3G_ONOFF");
- struct gpio_pin *rst_pin = gpio_pin_by_name("3G_RST");
-
- if (!onoff_pin || !pwrmon_pin || !rst_pin) {
- return -ENODEV;
- }
-
- value = gpio_get_value(pwrmon_pin->pin.gpio);
- if(value != 0) {
- log_error("radio is already on");
- return -EINVAL;
- }
-
- // drive on/off pin low for at least 5 sec
- log_info("turning on radio");
- ret = gpio_direction_output_pullup(onoff_pin->pin.gpio, 0, onoff_pin->pin.flags & GPIOF_PULLUP);
- if (ret) {
- return ret;
- }
-
- msleep(5500);
-
- // set on/off pin high
- ret = gpio_direction_output_pullup(onoff_pin->pin.gpio, 1, onoff_pin->pin.flags & GPIOF_PULLUP);
- if (ret) {
- return ret;
- }
-
- msleep(200);
-
- // check that power is high
- value = gpio_get_value(pwrmon_pin->pin.gpio);
- if(value == 0) {
- log_warning("radio is still off. performing radio reset");
- //Perform Hard Reset
- ret = gpio_direction_output_pullup(rst_pin->pin.gpio, 0, rst_pin->pin.flags & GPIOF_PULLUP);
- if (ret) {
- return ret;
- }
-
- msleep(500);
-
- // set pin high
- ret = gpio_direction_output_pullup(rst_pin->pin.gpio, 1, rst_pin->pin.flags & GPIOF_PULLUP);
- if (ret) {
- return ret;
- }
- } else {
- log_info("radio has been turned on");
- }
-
- return ret;
-}
-
-static ssize_t mts_attr_store_radio_power_telit(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
-{
- int value;
- int err;
-
- if (sscanf(buf, "%i", &value) != 1) {
- return -EINVAL;
- }
- if (value == 0) {
- mutex_lock(&mts_io_mutex);
- err = radio_off_telit();
- mutex_unlock(&mts_io_mutex);
- } else {
- mutex_lock(&mts_io_mutex);
- err = radio_on_telit();
- mutex_unlock(&mts_io_mutex);
- }
-
- if (err) {
- return err;
- }
-
- return count;
-}
-
-static int radio_reset_telit(void)
-{
- int ret;
- struct gpio_pin *rst_pin = gpio_pin_by_name("3G_RST");
- struct gpio_pin *onoff_pin = gpio_pin_by_name("3G_ONOFF");
-
- if (!rst_pin || !onoff_pin) {
- return -ENODEV;
- }
-
- // drive reset pin low for 500ms
- ret = gpio_direction_output_pullup(rst_pin->pin.gpio, 0, rst_pin->pin.flags & GPIOF_PULLUP);
- if (ret) {
- return ret;
- }
-
- msleep(500);
-
- // set pin high
- ret = gpio_direction_output_pullup(rst_pin->pin.gpio, 1, rst_pin->pin.flags & GPIOF_PULLUP);
- if (ret) {
- return ret;
- }
-
- // wait for 2 sec before toggling on/off pin
- msleep(2000);
-
- // drive on/off pin low for 6 sec
- ret = gpio_direction_output_pullup(onoff_pin->pin.gpio, 0, onoff_pin->pin.flags & GPIOF_PULLUP);
- if (ret) {
- return ret;
- }
-
- msleep(6000);
-
- // set on/off pin high
- ret = gpio_direction_output_pullup(onoff_pin->pin.gpio, 1, onoff_pin->pin.flags & GPIOF_PULLUP);
- if (ret) {
- return ret;
- }
-
- return ret;
-}
-
-static ssize_t mts_attr_store_radio_reset_telit(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
-{
- int value;
- int err;
-
- if (sscanf(buf, "%i", &value) != 1) {
- return -EINVAL;
- }
- if (value != 0) {
- return -EINVAL;
- }
-
- mutex_lock(&mts_io_mutex);
-
- err = radio_reset_telit();
-
- mutex_unlock(&mts_io_mutex);
-
- if (err) {
- return err;
- }
-
- return count;
-}
-
-static DEVICE_ATTR_MTS(dev_attr_radio_power_telit, "radio-power",
- mts_attr_show_gpio_pin, mts_attr_store_radio_power_telit);
-
-static DEVICE_ATTR_MTS(dev_attr_radio_reset_telit, "radio-reset",
- mts_attr_show_gpio_pin, mts_attr_store_radio_reset_telit);