From 4b5fa3b77d46aedd106312f9f14fddb1483fb0ef Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Tue, 1 Nov 2016 15:50:29 -0500 Subject: mtcap: rename mtp to mtcap --- io-module/mtcap.c | 513 +++++++++++++++++++++++++++++++++++++++++++++++++++++ io-module/mtp.c | 513 ----------------------------------------------------- io-module/mts_io.c | 16 +- io-module/mts_io.h | 4 +- 4 files changed, 523 insertions(+), 523 deletions(-) create mode 100644 io-module/mtcap.c delete mode 100644 io-module/mtp.c diff --git a/io-module/mtcap.c b/io-module/mtcap.c new file mode 100644 index 0000000..e651406 --- /dev/null +++ b/io-module/mtcap.c @@ -0,0 +1,513 @@ +static struct gpio_pin gpio_pins_mtcap_0_0[] = { + { + .name = "ETH_RESET", + .pin = { + .gpio = AT91_PIN_PC6, // NETH_RST + .flags = GPIOF_OUT_INIT_HIGH, + .label = "eth-reset", + }, + }, + { + .name = "RADIO_POWER_MONITOR", + .pin = { + .gpio = AT91_PIN_PD21, // PWRMON + .flags = GPIOF_IN, + .label = "radio-power-monitor", + }, + }, + { + .name = "RADIO_RESET", + .pin = { + .gpio = AT91_PIN_PA22, // 3G_RST + .flags = GPIOF_OUT_INIT_HIGH, + .label = "radio-reset", + }, + }, + { + .name = "RADIO_POWER", + .pin = { + .gpio = AT91_PIN_PA21, // 3G_ONOFF + .flags = GPIOF_OUT_INIT_HIGH, + .label = "radio-power", + }, + }, + { + .name = "DEVICE_RESET", + .pin = { + .gpio = AT91_PIN_PC4, // OPT_RST + .flags = GPIOF_IN, + .label = "reset", + }, + .active_low = 1, + }, + { + .name = "LORA_RESET", + .pin = { + .gpio = AT91_PIN_PA8, // LORA_RST + .flags = GPIOF_OUT_INIT_LOW, + .label = "lora-reset", + }, + }, + { // gpio 1 for LORA 1.5 ref design + .name = "LORA_CDONE", + .pin = { + .gpio = AT91_PIN_PA6, + .flags = GPIOF_IN, + .label = "lora-cdone", + }, + }, + { // gpio 2 for LORA 1.5 ref design + .name = "LORA_CRESET", + .pin = { + .gpio = AT91_PIN_PA29, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "lora-creset", + } + }, + + + /* LEDs */ + { + .name = "STATUS_LED", // DEV_LED_GN + .pin = { + .gpio = AT91_PIN_PC25, + .flags = GPIOF_OUT_INIT_LOW, + .label = "led-status", + }, + .active_low = 1, + }, + { + .name = "LED2", // LED2 is for LoRa status + .pin = { + .gpio = AT91_PIN_PC15, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-lora", + }, + .active_low = 1, + }, + { + .name = "LED3", // LED3 is for Cellular status (Modem can directly enable it) + .pin = { + .gpio = AT91_PIN_PC16, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-cd", + }, + .active_low = 1, + }, + { + .name = "LED4", // LED4 is for WiFi status + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-wifi", + }, + .active_low = 1, + }, + { }, +}; + +static int radio_unconditional_shutdown_mtcap(void) +{ + struct gpio_pin *rst_pin = gpio_pin_by_attr_name("radio-reset"); + struct gpio_pin *pwrmon_pin = gpio_pin_by_attr_name("radio-power-monitor"); + int value; + int i; + + if (!rst_pin || !pwrmon_pin) { + return -ENODEV; + } + + // To unconditionally shutdown the LE910, the pad HW_SHUTDOWN* must + // be tied low for at least 200 milliseconds and then released. + reset_gpio_pin(rst_pin, 500, 0); + + msleep(100); + + // Wait for the power off + for (i = 0; i < 5; i++) { + value = gpio_get_value(pwrmon_pin->pin.gpio); + if (value != 0) { + log_warning("radio is still on."); + msleep(500); + continue; + } + log_warning("radio has been shutdown unconditionally"); + break; + } + + return 0; +} + + +/* radio control (power/reset) for mtcap */ +static int radio_off_mtcap(void) +{ + // ref: Telit_LE910_Hardware_User_Guide_r6.pdf (4.3.2 Hardware Shutdown) + struct gpio_pin *pwrmon_pin = gpio_pin_by_attr_name("radio-power-monitor"); + struct gpio_pin *onoff_pin = gpio_pin_by_attr_name("radio-power"); + struct gpio_pin *rst_pin = gpio_pin_by_attr_name("radio-reset"); + int value; + int i; + + if (!onoff_pin || !pwrmon_pin || !rst_pin) { + return -ENODEV; + } + + value = gpio_get_value(pwrmon_pin->pin.gpio); + if(value == 0) { + log_warning("cell radio is already off"); + return 0; + } + + log_info("turning off cell radio"); + + // To turn OFF LE910 the pad ON/OFF# must be tied low for at least 2 seconds and then + // released. Same circuitry and timing for the power on must be used. When the hold + // time of ON/OFF# is above 2 seconds, LE910 goes into the finalization state and + // finally will shut down PWRMON at the end of this state. The period of the + // finalization state can differ according to the situation in which the LE910 is so it + // cannot be fixed definitely. Normally it will be above 15 seconds later from releasing + // ON/OFF# and DTE should monitor the status of PWRMON to see the actual power off. + + reset_gpio_pin(onoff_pin, 2500, 0); + + value = 0; + for (i = 0; i < 15; i++) { + // check that power is low + value = gpio_get_value(pwrmon_pin->pin.gpio); + if (value != 0) { + log_info("cell radio is still on. keep waiting..."); + msleep(2000); + continue; + } + break; + } + + if (value == 0) { + log_info("cell radio has been shut down"); + } + else { + log_warning("cell radio is still on. performing unconditional shutdown..."); + radio_unconditional_shutdown_mtcap(); + } + + return 0; +} + +static int radio_on_mtcap(void) +{ + // ref: Telit_LE910_Hardware_User_Guide_r6.pdf + struct gpio_pin *pwrmon_pin = gpio_pin_by_attr_name("radio-power-monitor"); + struct gpio_pin *onoff_pin = gpio_pin_by_attr_name("radio-power"); + struct gpio_pin *rst_pin = gpio_pin_by_attr_name("radio-reset"); + int value; + + if (!onoff_pin || !pwrmon_pin || !rst_pin) { + return -ENODEV; + } + + value = gpio_get_value(pwrmon_pin->pin.gpio); + if(value != 0) { + log_warning("cell radio is already on"); + return 0; + } + + log_info("turning on cell radio"); + + // drive on/off pin high for at least 1 seconoff_pin + gpio_set_value(onoff_pin->pin.gpio, 1); + msleep(1000); + + // 1) drive on/off pin low for < 2 sec + // 2) drive on/off pin high + reset_gpio_pin(onoff_pin, 1500, 0); + + // check that power is high + value = gpio_get_value(pwrmon_pin->pin.gpio); + if(value == 0) { + log_warning("cell radio is still off."); + } else { + log_info("cell radio has been turned on"); + } + + return 0; +} + +static int radio_reset_mtcap(void) +{ + // ref: Telit_LE910_Hardware_User_Guide_r6.pdf + struct gpio_pin *rst_pin = gpio_pin_by_attr_name("radio-reset"); + struct gpio_pin *onoff_pin = gpio_pin_by_attr_name("radio-power"); + + if (!rst_pin || !onoff_pin) { + return -ENODEV; + } + + // + // Unconditional shutdown + // + + log_info("performing unconditional cell radio shutdown"); + + radio_unconditional_shutdown_mtcap(); + + // + // Turning on radio + // + log_info("turning on cell radio"); + + // drive on/off pin high for at least 1 sec + gpio_set_value(onoff_pin->pin.gpio, 1); + msleep(1000); + + + // drive on/off pin low for < 2 sec + // drive on/off pin high + reset_gpio_pin(onoff_pin, 1500, 0); + + return 0; +} + +static ssize_t mts_attr_store_radio_power_mtcap(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; + } + + mutex_lock(&mts_io_mutex); + if (value == 0) { + err = radio_off_mtcap(); + } else { + err = radio_on_mtcap(); + } + mutex_unlock(&mts_io_mutex); + + if (err) { + return err; + } + + return count; +} + +static ssize_t mts_attr_store_radio_reset_mtcap(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; + } + + /* check reset timings is enabled */ + if (NULL != timings_data) { + /* check reset timer is started */ + if (radio_reset_timer_is_start == 1) { + log_info("cell radio reset timer is running. \n"); + return count; + } + + /* check reset timer available is started */ + if (radio_reset_available_timer_is_start == 1) { + del_timer(&radio_reset_available_timer); + radio_reset_available_timer_is_start = 0; + } + + /* reset timer not started, start it */ + mod_timer(&radio_reset_timer, jiffies + msecs_to_jiffies((timings_data[timings_data_index]) * 1000)); + //log_info("radio reset timer is start = [%d]\n", time_now_secs()); + /* save timings_data_stop_seconds */ + timings_data_stop_seconds = timings_data[timings_data_index] + time_now_secs(); + radio_reset_timer_is_start = 1; + } + + mutex_lock(&mts_io_mutex); + + err = radio_reset_mtcap(); + + mutex_unlock(&mts_io_mutex); + + if (err) { + return err; + } + + return count; +} + +static ssize_t mts_attr_show_radio_power_mtcap(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int value; + struct gpio_pin *pwrmon_pin = gpio_pin_by_attr_name("radio-power-monitor"); + + if ( !pwrmon_pin ) { + return -ENODEV; + } + + value = gpio_get_value(pwrmon_pin->pin.gpio); + return sprintf(buf, "%d\n", value); +} + +static int lora_reset_mtcap(void) +{ + struct gpio_pin *rst_pin = gpio_pin_by_attr_name("lora-reset"); + + if (!rst_pin) { + return -ENODEV; + } + + /* + * drive the reset pin low, set pin high for 100ns, drive pin low + */ + gpio_set_value(rst_pin->pin.gpio, 0); + + gpio_set_value(rst_pin->pin.gpio, 1); + + msleep(1); + + gpio_set_value(rst_pin->pin.gpio, 0); + + msleep(100); + + return 0; +} + +static ssize_t mts_attr_store_lora_reset_mtcap(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; + } + + log_info("performing lora reset"); + + mutex_lock(&mts_io_mutex); + + err = lora_reset_mtcap(); + + mutex_unlock(&mts_io_mutex); + + if (err) { + return err; + } + + return count; +} + +static int eth_reset_mtcap(void) +{ + struct gpio_pin *rst_pin = gpio_pin_by_attr_name("eth-reset"); + + if (!rst_pin) { + return -ENODEV; + } + + /* + * DS00002275A (09-15-16) KSZ8091MNX/RNB DATA SHEET: + * For warm reset, the reset (RST#) pin should be asserted low for a minimum of 500 μs. + */ + gpio_set_value(rst_pin->pin.gpio, 0); + + msleep(2); + + gpio_set_value(rst_pin->pin.gpio, 1); + + msleep(1); + + return 0; +} + +static ssize_t mts_attr_store_eth_reset_mtcap(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; + } + + log_info("performing eth reset"); + + mutex_lock(&mts_io_mutex); + + err = eth_reset_mtcap(); + + mutex_unlock(&mts_io_mutex); + + if (err) { + return err; + } + + return count; +} + +static DEVICE_ATTR_MTS(dev_attr_radio_reset_mtcap, "radio-reset", + mts_attr_show_gpio_pin, mts_attr_store_radio_reset_mtcap); + +static DEVICE_ATTR_MTS(dev_attr_radio_power_mtcap, "radio-power", + mts_attr_show_radio_power_mtcap, mts_attr_store_radio_power_mtcap); + +static DEVICE_ATTR_MTS(dev_attr_lora_reset_mtcap, "lora-reset", + mts_attr_show_gpio_pin, mts_attr_store_lora_reset_mtcap); + +static DEVICE_ATTR_MTS(dev_attr_eth_reset_mtcap, "eth-reset", + mts_attr_show_gpio_pin, mts_attr_store_eth_reset_mtcap); + +static DEVICE_ATTR_MTS(dev_attr_led_lora_gpio_mtcap, "led-lora", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_led_wifi_gpio_mtcap, "led-wifi", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_RO_MTS(dev_attr_lora_eui, "lora-eui", + mts_attr_show_product_info); + +static struct attribute *mtcap_0_0_platform_attributes[] = { + &dev_attr_vendor_id.attr, + &dev_attr_product_id.attr, + &dev_attr_device_id.attr, + &dev_attr_uuid.attr, + &dev_attr_hw_version.attr, + &dev_attr_imei.attr, + &dev_attr_eth_mac.attr, + &dev_attr_reset.attr, + &dev_attr_reset_monitor.attr, + &dev_attr_reset_monitor_intervals.attr, + + &dev_attr_eth_reset_mtcap.attr, + + &dev_attr_lora_reset_mtcap.attr, + + &dev_attr_radio_power_mtcap.attr, + &dev_attr_radio_reset_mtcap.attr, + + &dev_attr_radio_reset_backoffs.attr, + &dev_attr_radio_reset_backoff_index.attr, + &dev_attr_radio_reset_backoff_seconds.attr, + + &dev_attr_led_status.attr, + &dev_attr_led_cd_gpio.attr, + &dev_attr_led_lora_gpio_mtcap.attr, + &dev_attr_led_wifi_gpio_mtcap.attr, + + &dev_attr_lora_eui.attr, + + NULL, +}; + +static struct attribute_group mtcap_0_0_platform_attribute_group = { + .attrs = mtcap_0_0_platform_attributes +}; diff --git a/io-module/mtp.c b/io-module/mtp.c deleted file mode 100644 index 9e411b2..0000000 --- a/io-module/mtp.c +++ /dev/null @@ -1,513 +0,0 @@ -static struct gpio_pin gpio_pins_mtp_0_0[] = { - { - .name = "ETH_RESET", - .pin = { - .gpio = AT91_PIN_PC6, // NETH_RST - .flags = GPIOF_OUT_INIT_HIGH, - .label = "eth-reset", - }, - }, - { - .name = "RADIO_POWER_MONITOR", - .pin = { - .gpio = AT91_PIN_PD21, // PWRMON - .flags = GPIOF_IN, - .label = "radio-power-monitor", - }, - }, - { - .name = "RADIO_RESET", - .pin = { - .gpio = AT91_PIN_PA22, // 3G_RST - .flags = GPIOF_OUT_INIT_HIGH, - .label = "radio-reset", - }, - }, - { - .name = "RADIO_POWER", - .pin = { - .gpio = AT91_PIN_PA21, // 3G_ONOFF - .flags = GPIOF_OUT_INIT_HIGH, - .label = "radio-power", - }, - }, - { - .name = "DEVICE_RESET", - .pin = { - .gpio = AT91_PIN_PC4, // OPT_RST - .flags = GPIOF_IN, - .label = "reset", - }, - .active_low = 1, - }, - { - .name = "LORA_RESET", - .pin = { - .gpio = AT91_PIN_PA8, // LORA_RST - .flags = GPIOF_OUT_INIT_LOW, - .label = "lora-reset", - }, - }, - { // gpio 1 for LORA 1.5 ref design - .name = "LORA_CDONE", - .pin = { - .gpio = AT91_PIN_PA6, - .flags = GPIOF_IN, - .label = "lora-cdone", - }, - }, - { // gpio 2 for LORA 1.5 ref design - .name = "LORA_CRESET", - .pin = { - .gpio = AT91_PIN_PA29, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "lora-creset", - } - }, - - - /* LEDs */ - { - .name = "STATUS_LED", // DEV_LED_GN - .pin = { - .gpio = AT91_PIN_PC25, - .flags = GPIOF_OUT_INIT_LOW, - .label = "led-status", - }, - .active_low = 1, - }, - { - .name = "LED2", // LED2 is for LoRa status - .pin = { - .gpio = AT91_PIN_PC15, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-lora", - }, - .active_low = 1, - }, - { - .name = "LED3", // LED3 is for Cellular status (Modem can directly enable it) - .pin = { - .gpio = AT91_PIN_PC16, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-cd", - }, - .active_low = 1, - }, - { - .name = "LED4", // LED4 is for WiFi status - .pin = { - .gpio = AT91_PIN_PC20, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-wifi", - }, - .active_low = 1, - }, - { }, -}; - -static int radio_unconditional_shutdown_mtp(void) -{ - struct gpio_pin *rst_pin = gpio_pin_by_attr_name("radio-reset"); - struct gpio_pin *pwrmon_pin = gpio_pin_by_attr_name("radio-power-monitor"); - int value; - int i; - - if (!rst_pin || !pwrmon_pin) { - return -ENODEV; - } - - // To unconditionally shutdown the LE910, the pad HW_SHUTDOWN* must - // be tied low for at least 200 milliseconds and then released. - reset_gpio_pin(rst_pin, 500, 0); - - msleep(100); - - // Wait for the power off - for (i = 0; i < 5; i++) { - value = gpio_get_value(pwrmon_pin->pin.gpio); - if (value != 0) { - log_warning("radio is still on."); - msleep(500); - continue; - } - log_warning("radio has been shutdown unconditionally"); - break; - } - - return 0; -} - - -/* radio control (power/reset) for mtp */ -static int radio_off_mtp(void) -{ - // ref: Telit_LE910_Hardware_User_Guide_r6.pdf (4.3.2 Hardware Shutdown) - struct gpio_pin *pwrmon_pin = gpio_pin_by_attr_name("radio-power-monitor"); - struct gpio_pin *onoff_pin = gpio_pin_by_attr_name("radio-power"); - struct gpio_pin *rst_pin = gpio_pin_by_attr_name("radio-reset"); - int value; - int i; - - if (!onoff_pin || !pwrmon_pin || !rst_pin) { - return -ENODEV; - } - - value = gpio_get_value(pwrmon_pin->pin.gpio); - if(value == 0) { - log_warning("cell radio is already off"); - return 0; - } - - log_info("turning off cell radio"); - - // To turn OFF LE910 the pad ON/OFF# must be tied low for at least 2 seconds and then - // released. Same circuitry and timing for the power on must be used. When the hold - // time of ON/OFF# is above 2 seconds, LE910 goes into the finalization state and - // finally will shut down PWRMON at the end of this state. The period of the - // finalization state can differ according to the situation in which the LE910 is so it - // cannot be fixed definitely. Normally it will be above 15 seconds later from releasing - // ON/OFF# and DTE should monitor the status of PWRMON to see the actual power off. - - reset_gpio_pin(onoff_pin, 2500, 0); - - value = 0; - for (i = 0; i < 15; i++) { - // check that power is low - value = gpio_get_value(pwrmon_pin->pin.gpio); - if (value != 0) { - log_info("cell radio is still on. keep waiting..."); - msleep(2000); - continue; - } - break; - } - - if (value == 0) { - log_info("cell radio has been shut down"); - } - else { - log_warning("cell radio is still on. performing unconditional shutdown..."); - radio_unconditional_shutdown_mtp(); - } - - return 0; -} - -static int radio_on_mtp(void) -{ - // ref: Telit_LE910_Hardware_User_Guide_r6.pdf - struct gpio_pin *pwrmon_pin = gpio_pin_by_attr_name("radio-power-monitor"); - struct gpio_pin *onoff_pin = gpio_pin_by_attr_name("radio-power"); - struct gpio_pin *rst_pin = gpio_pin_by_attr_name("radio-reset"); - int value; - - if (!onoff_pin || !pwrmon_pin || !rst_pin) { - return -ENODEV; - } - - value = gpio_get_value(pwrmon_pin->pin.gpio); - if(value != 0) { - log_warning("cell radio is already on"); - return 0; - } - - log_info("turning on cell radio"); - - // drive on/off pin high for at least 1 seconoff_pin - gpio_set_value(onoff_pin->pin.gpio, 1); - msleep(1000); - - // 1) drive on/off pin low for < 2 sec - // 2) drive on/off pin high - reset_gpio_pin(onoff_pin, 1500, 0); - - // check that power is high - value = gpio_get_value(pwrmon_pin->pin.gpio); - if(value == 0) { - log_warning("cell radio is still off."); - } else { - log_info("cell radio has been turned on"); - } - - return 0; -} - -static int radio_reset_mtp(void) -{ - // ref: Telit_LE910_Hardware_User_Guide_r6.pdf - struct gpio_pin *rst_pin = gpio_pin_by_attr_name("radio-reset"); - struct gpio_pin *onoff_pin = gpio_pin_by_attr_name("radio-power"); - - if (!rst_pin || !onoff_pin) { - return -ENODEV; - } - - // - // Unconditional shutdown - // - - log_info("performing unconditional cell radio shutdown"); - - radio_unconditional_shutdown_mtp(); - - // - // Turning on radio - // - log_info("turning on cell radio"); - - // drive on/off pin high for at least 1 sec - gpio_set_value(onoff_pin->pin.gpio, 1); - msleep(1000); - - - // drive on/off pin low for < 2 sec - // drive on/off pin high - reset_gpio_pin(onoff_pin, 1500, 0); - - return 0; -} - -static ssize_t mts_attr_store_radio_power_mtp(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; - } - - mutex_lock(&mts_io_mutex); - if (value == 0) { - err = radio_off_mtp(); - } else { - err = radio_on_mtp(); - } - mutex_unlock(&mts_io_mutex); - - if (err) { - return err; - } - - return count; -} - -static ssize_t mts_attr_store_radio_reset_mtp(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; - } - - /* check reset timings is enabled */ - if (NULL != timings_data) { - /* check reset timer is started */ - if (radio_reset_timer_is_start == 1) { - log_info("cell radio reset timer is running. \n"); - return count; - } - - /* check reset timer available is started */ - if (radio_reset_available_timer_is_start == 1) { - del_timer(&radio_reset_available_timer); - radio_reset_available_timer_is_start = 0; - } - - /* reset timer not started, start it */ - mod_timer(&radio_reset_timer, jiffies + msecs_to_jiffies((timings_data[timings_data_index]) * 1000)); - //log_info("radio reset timer is start = [%d]\n", time_now_secs()); - /* save timings_data_stop_seconds */ - timings_data_stop_seconds = timings_data[timings_data_index] + time_now_secs(); - radio_reset_timer_is_start = 1; - } - - mutex_lock(&mts_io_mutex); - - err = radio_reset_mtp(); - - mutex_unlock(&mts_io_mutex); - - if (err) { - return err; - } - - return count; -} - -static ssize_t mts_attr_show_radio_power_mtp(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int value; - struct gpio_pin *pwrmon_pin = gpio_pin_by_attr_name("radio-power-monitor"); - - if ( !pwrmon_pin ) { - return -ENODEV; - } - - value = gpio_get_value(pwrmon_pin->pin.gpio); - return sprintf(buf, "%d\n", value); -} - -static int lora_reset_mtp(void) -{ - struct gpio_pin *rst_pin = gpio_pin_by_attr_name("lora-reset"); - - if (!rst_pin) { - return -ENODEV; - } - - /* - * drive the reset pin low, set pin high for 100ns, drive pin low - */ - gpio_set_value(rst_pin->pin.gpio, 0); - - gpio_set_value(rst_pin->pin.gpio, 1); - - msleep(1); - - gpio_set_value(rst_pin->pin.gpio, 0); - - msleep(100); - - return 0; -} - -static ssize_t mts_attr_store_lora_reset_mtp(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; - } - - log_info("performing lora reset"); - - mutex_lock(&mts_io_mutex); - - err = lora_reset_mtp(); - - mutex_unlock(&mts_io_mutex); - - if (err) { - return err; - } - - return count; -} - -static int eth_reset_mtp(void) -{ - struct gpio_pin *rst_pin = gpio_pin_by_attr_name("eth-reset"); - - if (!rst_pin) { - return -ENODEV; - } - - /* - * DS00002275A (09-15-16) KSZ8091MNX/RNB DATA SHEET: - * For warm reset, the reset (RST#) pin should be asserted low for a minimum of 500 μs. - */ - gpio_set_value(rst_pin->pin.gpio, 0); - - msleep(2); - - gpio_set_value(rst_pin->pin.gpio, 1); - - msleep(1); - - return 0; -} - -static ssize_t mts_attr_store_eth_reset_mtp(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; - } - - log_info("performing eth reset"); - - mutex_lock(&mts_io_mutex); - - err = eth_reset_mtp(); - - mutex_unlock(&mts_io_mutex); - - if (err) { - return err; - } - - return count; -} - -static DEVICE_ATTR_MTS(dev_attr_radio_reset_mtp, "radio-reset", - mts_attr_show_gpio_pin, mts_attr_store_radio_reset_mtp); - -static DEVICE_ATTR_MTS(dev_attr_radio_power_mtp, "radio-power", - mts_attr_show_radio_power_mtp, mts_attr_store_radio_power_mtp); - -static DEVICE_ATTR_MTS(dev_attr_lora_reset_mtp, "lora-reset", - mts_attr_show_gpio_pin, mts_attr_store_lora_reset_mtp); - -static DEVICE_ATTR_MTS(dev_attr_eth_reset_mtp, "eth-reset", - mts_attr_show_gpio_pin, mts_attr_store_eth_reset_mtp); - -static DEVICE_ATTR_MTS(dev_attr_led_lora_gpio_mtp, "led-lora", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_led_wifi_gpio_mtp, "led-wifi", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_RO_MTS(dev_attr_lora_eui, "lora-eui", - mts_attr_show_product_info); - -static struct attribute *mtp_0_0_platform_attributes[] = { - &dev_attr_vendor_id.attr, - &dev_attr_product_id.attr, - &dev_attr_device_id.attr, - &dev_attr_uuid.attr, - &dev_attr_hw_version.attr, - &dev_attr_imei.attr, - &dev_attr_eth_mac.attr, - &dev_attr_reset.attr, - &dev_attr_reset_monitor.attr, - &dev_attr_reset_monitor_intervals.attr, - - &dev_attr_eth_reset_mtp.attr, - - &dev_attr_lora_reset_mtp.attr, - - &dev_attr_radio_power_mtp.attr, - &dev_attr_radio_reset_mtp.attr, - - &dev_attr_radio_reset_backoffs.attr, - &dev_attr_radio_reset_backoff_index.attr, - &dev_attr_radio_reset_backoff_seconds.attr, - - &dev_attr_led_status.attr, - &dev_attr_led_cd_gpio.attr, - &dev_attr_led_lora_gpio_mtp.attr, - &dev_attr_led_wifi_gpio_mtp.attr, - - &dev_attr_lora_eui.attr, - - NULL, -}; - -static struct attribute_group mtp_0_0_platform_attribute_group = { - .attrs = mtp_0_0_platform_attributes -}; diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 0b22592..547f099 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -47,7 +47,7 @@ #include "mts_io.h" -#define DRIVER_VERSION "v1.4.2" +#define DRIVER_VERSION "v1.5.0" #define DRIVER_AUTHOR "James Maki " #define DRIVER_DESC "MTS-IO Controller" #define DRIVER_NAME "mts-io" @@ -635,7 +635,7 @@ static DEVICE_ATTR_RO_MTS(dev_attr_eth_mac, "mac-eth", /* include per-device pins and attributes */ #include "mtcdt.c" -#include "mtp.c" +#include "mtcap.c" #if NUM_AP > 0 @@ -786,11 +786,11 @@ static int mts_id_eeprom_load() if (mts_id_eeprom[0] == 0xFF) { log_error("uninitialized eeprom"); return -EIO; - } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTP_0_0, strlen(HW_VERSION_MTP_0_0)) == 0) { - attr_group = &mtp_0_0_platform_attribute_group; - gpio_pins = gpio_pins_mtp_0_0; - mts_hw_version = MTP_0_0; - log_info("detected board %s", HW_VERSION_MTP_0_0); + } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTCAP_0_0, strlen(HW_VERSION_MTCAP_0_0)) == 0) { + attr_group = &mtcap_0_0_platform_attribute_group; + gpio_pins = gpio_pins_mtcap_0_0; + mts_hw_version = MTCAP_0_0; + log_info("detected board %s", HW_VERSION_MTCAP_0_0); } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTCDT_0_1, strlen(HW_VERSION_MTCDT_0_1)) == 0) { attr_blength = sizeof mtcdt_0_1_platform_attributes; @@ -877,7 +877,7 @@ static int mts_id_eeprom_load() } log_info("uuid: %s", (char*)buf); - if (mts_hw_version == MTP_0_0) { + if (mts_hw_version == MTCAP_0_0) { log_info("lora-eui: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", id_eeprom.lora_eui[0], id_eeprom.lora_eui[1], diff --git a/io-module/mts_io.h b/io-module/mts_io.h index cc33b80..5918fa9 100644 --- a/io-module/mts_io.h +++ b/io-module/mts_io.h @@ -67,7 +67,7 @@ struct device_attribute _dev_name = { \ #define HW_VERSION_MTR_0_1 "MTR-0.1" #define HW_VERSION_MTCDT_0_0 "MTCDT-0.0" #define HW_VERSION_MTCDT_0_1 "MTCDT-0.1" -#define HW_VERSION_MTP_0_0 "MTP-0.0" +#define HW_VERSION_MTCAP_0_0 "MTCAP-0.0" enum { MTCDP_E1_DK_0_0, @@ -77,7 +77,7 @@ enum { MTR_0_1, MTCDT_0_0, MTCDT_0_1, - MTP_0_0, + MTCAP_0_0, }; enum { -- cgit v1.2.3