From f8421437524cbba156e63c2fa04d1b641d963d48 Mon Sep 17 00:00:00 2001 From: Mike Fiore Date: Wed, 1 May 2013 12:16:51 -0500 Subject: add mtocgd product id and hw version, support to detect board type in init code --- io-module/mts_io.c | 9 +++++++++ io-module/mts_io.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/io-module/mts_io.c b/io-module/mts_io.c index b20a5f8..1cae937 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -2390,6 +2390,15 @@ static int mts_id_eeprom_load(void) has_spi_dout = 0; has_spi_temp = 1; log_info("detected board %s", HW_VERSION_MTOCGD3_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 { attr_group = &mtcdp_platform_attribute_group; gpio_pins = gpio_pins_mtcdp_1_0; diff --git a/io-module/mts_io.h b/io-module/mts_io.h index 4d6a1bd..43106cb 100644 --- a/io-module/mts_io.h +++ b/io-module/mts_io.h @@ -31,6 +31,7 @@ struct device_attribute _dev_name = { \ #define PRODUCT_ID_MTR2 "MTR2" #define PRODUCT_ID_MTR "MTR" #define PRODUCT_ID_MTOCGD3 "MTOCGD3" +#define PRODUCT_ID_MTOCGD "MTOCGD" #define HW_VERSION_MTCBA2_2_0 "MTCBA2-2.0" #define HW_VERSION_MTCDP_0_0 "MTCDP-0.0" @@ -39,6 +40,7 @@ struct device_attribute _dev_name = { \ #define HW_VERSION_MTR2_0_0 "MTR2-0.0" #define HW_VERSION_MTR_0_0 "MTR-0.0" #define HW_VERSION_MTOCGD3_0_0 "MTOCGD3-0.0" +#define HW_VERSION_MTOCGD_0_0 "MTOCGD-0.0" enum { MTCDP_E1_DK_0_0, @@ -47,6 +49,7 @@ enum { MTR2_0_0, MTR_0_0, MTOCGD3_0_0, + MTOCGD_0_0, }; #define DEVICE_CAPA_INDEX(c) (((c) & 0xFF) >> 3) -- cgit v1.2.3 From d5beeadc07864a4bdc970ed76bd4693529039fcd Mon Sep 17 00:00:00 2001 From: Mike Fiore Date: Wed, 1 May 2013 14:29:13 -0500 Subject: add leds b-f for mtr/mtocgd hw --- io-module/mts_io.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 1cae937..60ab232 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -691,6 +691,15 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .use_pullup = 0, .active_low = 1, }, + { + .name = "LED3", + .attr_name = "led-b", + .pin = AT91_PIN_PC15, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + .active_low = 1, + }, { .name = "LED4", .attr_name = "led-cd", @@ -700,6 +709,15 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .use_pullup = 0, .active_low = 1, }, + { + .name = "LED4", + .attr_name = "led-c", + .pin = AT91_PIN_PC20, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + .active_low = 1, + }, { .name = "LED6", .attr_name = "led-sig1", @@ -709,6 +727,15 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .use_pullup = 0, .active_low = 1, }, + { + .name = "LED6", + .attr_name = "led-d", + .pin = AT91_PIN_PC19, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + .active_low = 1, + }, { .name = "LED7", .attr_name = "led-sig2", @@ -718,6 +745,15 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .use_pullup = 0, .active_low = 1, }, + { + .name = "LED7", + .attr_name = "led-e", + .pin = AT91_PIN_PC18, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + .active_low = 1, + }, { .name = "LED8", .attr_name = "led-sig3", @@ -727,6 +763,15 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .use_pullup = 0, .active_low = 1, }, + { + .name = "LED8", + .attr_name = "led-f", + .pin = AT91_PIN_PC17, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + .active_low = 1, + }, { .name = "RI_B", .attr_name = "extserial-ri", @@ -2152,6 +2197,13 @@ static struct attribute *mtr_platform_attributes[] = { &dev_attr_led_cd_gpio.attr, &dev_attr_led_wifi_gpio.attr, + &dev_attr_led_a_gpio.attr, + &dev_attr_led_b_gpio.attr, + &dev_attr_led_c_gpio.attr, + &dev_attr_led_d_gpio.attr, + &dev_attr_led_e_gpio.attr, + &dev_attr_led_f_gpio.attr, + NULL, }; -- cgit v1.2.3 From 5b405021260a35757d594bddc313b75d2c15a994 Mon Sep 17 00:00:00 2001 From: Sean Godinez Date: Thu, 18 Jul 2013 11:14:06 -0500 Subject: added radio-power attribute to turn off/on and status power to the radio for mtr/mtr2 --- io-module/mts_io.c | 197 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) diff --git a/io-module/mts_io.c b/io-module/mts_io.c index ba9996f..211dbc4 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -635,6 +635,15 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .output_value = 1, .use_pullup = 0, }, + { + .name = "PWRMON", + .attr_name = "radio-power", + .pin = AT91_PIN_PA23, + .direction = GPIO_DIR_INPUT, + .output_value = 0, + .use_pullup = 0, + .active_low = 0, + }, { .name = "3G_RST", .attr_name = "radio-reset", @@ -836,6 +845,15 @@ static struct gpio_pin gpio_pins_mtr_0_1[] = { .output_value = 1, .use_pullup = 0, }, + { + .name = "PWRMON", + .attr_name = "radio-power", + .pin = AT91_PIN_PA23, + .direction = GPIO_DIR_INPUT, + .output_value = 0, + .use_pullup = 0, + .active_low = 0, + }, { .name = "3G_RST", .attr_name = "radio-reset", @@ -1217,6 +1235,177 @@ static void blink_callback(struct work_struct *ignored) schedule_delayed_work(&blink_work, BLINK_INTERVAL); } +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 = at91_get_gpio_value(pwrmon_pin->pin); + 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 = at91_set_gpio_output_with_pullup(onoff_pin->pin, 0, onoff_pin->use_pullup); + if (ret) { + return ret; + } + + msleep(3500); + + // set on/off pin high + ret = at91_set_gpio_output_with_pullup(onoff_pin->pin, 1, onoff_pin->use_pullup); + if (ret) { + return ret; + } + + msleep(200); + + // check that power is low + value = at91_get_gpio_value(pwrmon_pin->pin); + if(value != 0) { + log_warning("radio is still on. performing radio reset."); + //Perform Hard Reset + ret = at91_set_gpio_output_with_pullup(rst_pin->pin, 0, rst_pin->use_pullup); + if (ret) { + return ret; + } + + msleep(500); + + // set pin high + ret = at91_set_gpio_output_with_pullup(rst_pin->pin, 1, rst_pin->use_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 = at91_get_gpio_value(pwrmon_pin->pin); + 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 = at91_set_gpio_output_with_pullup(onoff_pin->pin, 0, onoff_pin->use_pullup); + if (ret) { + return ret; + } + + msleep(5500); + + // set on/off pin high + ret = at91_set_gpio_output_with_pullup(onoff_pin->pin, 1, onoff_pin->use_pullup); + if (ret) { + return ret; + } + + msleep(200); + + // check that power is high + value = at91_get_gpio_value(pwrmon_pin->pin); + if(value == 0) { + log_warning("radio is still off. performing radio reset"); + //Perform Hard Reset + ret = at91_set_gpio_output_with_pullup(rst_pin->pin, 0, rst_pin->use_pullup); + if (ret) { + return ret; + } + + msleep(500); + + // set pin high + ret = at91_set_gpio_output_with_pullup(rst_pin->pin, 1, rst_pin->use_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 ssize_t mts_attr_store_radio_power(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int value; + int ret; + + struct gpio_pin *pin = gpio_pin_by_name("RADIO_RESET"); + + if (!pin) { + return -ENODEV; + } + + if (sscanf(buf, "%i", &value) != 1) { + return -EINVAL; + } + + if (value == 0) { + mutex_lock(&mts_io_mutex); + ret = at91_set_gpio_value(pin->pin, 0); + mutex_unlock(&mts_io_mutex); + } else { + mutex_lock(&mts_io_mutex); + ret = at91_set_gpio_value(pin->pin, 1); + mutex_unlock(&mts_io_mutex); + } + + return ret; +} + static int radio_reset_telit(void) { int ret; @@ -1426,6 +1615,9 @@ static ssize_t mts_attr_store_radio_reset_telit(struct device *dev, return count; } +static DEVICE_ATTR_MTS(dev_attr_radio_power, "radio-power", + mts_attr_show_gpio_pin, mts_attr_store_radio_power); + static DEVICE_ATTR_MTS(dev_attr_radio_reset, "radio-reset", mts_attr_show_gpio_pin, mts_attr_store_radio_reset); @@ -2186,6 +2378,9 @@ static DEVICE_ATTR_MTS(dev_attr_serial_mode, "serial-mode", static DEVICE_ATTR_MTS(dev_attr_eth_switch_enabled, "eth-switch-enabled", mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +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); @@ -2267,6 +2462,7 @@ static struct attribute *mtr2_platform_attributes[] = { &dev_attr_wifi_mac.attr, &dev_attr_reset.attr, &dev_attr_reset_monitor.attr, + &dev_attr_radio_power.attr, &dev_attr_radio_reset.attr, &dev_attr_extserial_dtr.attr, &dev_attr_extserial_dsr_gpio.attr, @@ -2381,6 +2577,7 @@ static struct attribute *mtr_platform_attributes[] = { &dev_attr_wifi_mac.attr, &dev_attr_reset.attr, &dev_attr_reset_monitor.attr, + &dev_attr_radio_power_telit.attr, &dev_attr_radio_reset_telit.attr, &dev_attr_extserial_ri_gpio.attr, &dev_attr_extserial_dtr.attr, -- cgit v1.2.3 From a7eb04eef347e5481a42a3afd0bcd038e1b4acda Mon Sep 17 00:00:00 2001 From: Mike Fiore Date: Mon, 12 Aug 2013 11:56:12 -0500 Subject: add option to set serial-mode to hw loopback --- io-module/mts_io.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 211dbc4..4d2bc64 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -596,7 +596,7 @@ static struct gpio_pin gpio_pins_mtr2_0_0[] = { .attr_name = "serial_mode", .pin = AT91_PIN_PC23, .direction = GPIO_DIR_OUTPUT, - .output_value = 1, + .output_value = 0, .use_pullup = 0, }, { @@ -2281,6 +2281,8 @@ static ssize_t mts_attr_show_serial_mode(struct device *dev, ret = sprintf(buf, "rs485\n"); else if (smode2 == 1 && smode1 == 0 && smode0 == 0) ret = sprintf(buf, "rs422\n"); + else if (smode2 == 0 && smode1 == 0 && smode0 == 0) + ret = sprintf(buf, "loopback\n"); else ret = sprintf(buf, "error\n"); @@ -2317,6 +2319,11 @@ static ssize_t mts_attr_store_serial_mode(struct device *dev, smode1 = 0; smode0 = 0; } + else if (!strcasecmp(buf, "loopback")) { + smode2 = 0; + smode1 = 0; + smode0 = 0; + } else { return -EINVAL; } -- cgit v1.2.3 From e0e72edb4da3ac44f8db1d144729ea87e50b24f1 Mon Sep 17 00:00:00 2001 From: Sean Godinez Date: Fri, 22 Nov 2013 10:23:06 -0600 Subject: added optional extra long reset hold signal --- io-module/mts_io.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 211dbc4..bdbc43d 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -1179,11 +1179,13 @@ struct clk *adc_clk; #define BLINK_PER_SEC 8 #define BLINK_INTERVAL (HZ / BLINK_PER_SEC) #define RESET_HOLD_COUNT (BLINK_PER_SEC * 3) +#define RESET_LONG_HOLD_COUNT (BLINK_PER_SEC * 30) static pid_t reset_pid = -1; static pid_t reset_count = 0; static int reset_short_signal = SIGUSR1; static int reset_long_signal = SIGUSR2; +static int reset_extra_long_signal = SIGHUP; static DEFINE_MUTEX(mts_io_mutex); static void blink_callback(struct work_struct *ignored); @@ -1213,11 +1215,14 @@ static void blink_callback(struct work_struct *ignored) } else if (reset_count > 0 && reset_count < RESET_HOLD_COUNT) { kill_pid(vpid, reset_short_signal, 1); reset_count = 0; + } else if (reset_count >= RESET_HOLD_COUNT && reset_count < RESET_LONG_HOLD_COUNT) { + reset_count = 0; + kill_pid(vpid, reset_long_signal, 1); } - if (reset_count >= RESET_HOLD_COUNT) { + if (reset_count >= RESET_LONG_HOLD_COUNT) { reset_count = 0; - kill_pid(vpid, reset_long_signal, 1); + kill_pid(vpid, reset_extra_long_signal, 1); } } else { reset_count = 0; @@ -2083,7 +2088,7 @@ static ssize_t mts_attr_show_reset_monitor(struct device *dev, mutex_lock(&mts_io_mutex); - ret = sprintf(buf, "%d %d %d\n", reset_pid, reset_short_signal, reset_long_signal); + ret = sprintf(buf, "%d %d %d %d\n", reset_pid, reset_short_signal, reset_long_signal, reset_extra_long_signal); mutex_unlock(&mts_io_mutex); @@ -2096,18 +2101,31 @@ static ssize_t mts_attr_store_reset_monitor(struct device *dev, pid_t pid; int short_signal; int long_signal; + int extra_long_signal; + int result = sscanf(buf, "%i %i %i %i", &pid, &short_signal, &long_signal, &extra_long_signal); - if (sscanf(buf, "%i %i %i", &pid, &short_signal, &long_signal) != 3) { + if (result < 3 || result > 4) { return -EINVAL; } - mutex_lock(&mts_io_mutex); + if(result == 3) { + mutex_lock(&mts_io_mutex); - reset_pid = pid; - reset_short_signal = short_signal; - reset_long_signal = long_signal; + reset_pid = pid; + reset_short_signal = short_signal; + reset_long_signal = long_signal; - mutex_unlock(&mts_io_mutex); + mutex_unlock(&mts_io_mutex); + } else { + mutex_lock(&mts_io_mutex); + + reset_pid = pid; + reset_short_signal = short_signal; + reset_long_signal = long_signal; + reset_extra_long_signal = long_signal; + + mutex_unlock(&mts_io_mutex); + } return count; } -- cgit v1.2.3 From f70588d90e5166739b3d527f51b02c28f906c7df Mon Sep 17 00:00:00 2001 From: Sean Godinez Date: Fri, 22 Nov 2013 17:34:53 -0600 Subject: reset logic fix --- io-module/mts_io.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 9f27af2..728e39b 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -1212,12 +1212,15 @@ static void blink_callback(struct work_struct *ignored) if (vpid) { if (reset_pressed) { reset_count++; - } else if (reset_count > 0 && reset_count < RESET_HOLD_COUNT) { - kill_pid(vpid, reset_short_signal, 1); - reset_count = 0; - } else if (reset_count >= RESET_HOLD_COUNT && reset_count < RESET_LONG_HOLD_COUNT) { - reset_count = 0; - kill_pid(vpid, reset_long_signal, 1); + } else { + //Reset button has not been pressed + if (reset_count > 0 && reset_count < RESET_HOLD_COUNT) { + kill_pid(vpid, reset_short_signal, 1); + reset_count = 0; + } else if (reset_count >= RESET_HOLD_COUNT && reset_count < RESET_LONG_HOLD_COUNT) { + reset_count = 0; + kill_pid(vpid, reset_long_signal, 1); + } } if (reset_count >= RESET_LONG_HOLD_COUNT) { -- cgit v1.2.3 From d3a44aaa5f2ef5a23f181c88fa3f13e9662edb81 Mon Sep 17 00:00:00 2001 From: Sean Godinez Date: Mon, 25 Nov 2013 13:12:02 -0600 Subject: fixed copy/paste error --- io-module/mts_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 728e39b..d6df5f9 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -2125,7 +2125,7 @@ static ssize_t mts_attr_store_reset_monitor(struct device *dev, reset_pid = pid; reset_short_signal = short_signal; reset_long_signal = long_signal; - reset_extra_long_signal = long_signal; + reset_extra_long_signal = extra_long_signal; mutex_unlock(&mts_io_mutex); } -- cgit v1.2.3 From 5be8276633ef25569de793e5d2d3c5c0943a7718 Mon Sep 17 00:00:00 2001 From: Sean Godinez Date: Mon, 25 Nov 2013 13:19:07 -0600 Subject: --help update for reset-monitor extra long signal --- io-tool/mts-io-sysfs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io-tool/mts-io-sysfs b/io-tool/mts-io-sysfs index 22d0be6..71253f6 100755 --- a/io-tool/mts-io-sysfs +++ b/io-tool/mts-io-sysfs @@ -144,7 +144,7 @@ usage() { radio-reset ) printf " $FILENAME { 0 }\n" >&${out} ;; reset-monitor ) - printf " $FILENAME { pid short-signal long-signal }\n" >&${out} ;; + printf " $FILENAME { pid short-signal long-signal [extra-long-signal] }\n" >&${out} ;; serial-mode ) printf " $FILENAME { rs232 | rs422 | rs485 }\n" >&${out} ;; * ) -- cgit v1.2.3