summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMykyta Dorokhin <mykyta.dorokhin@globallogic.com>2016-09-13 22:35:55 +0300
committerMykyta Dorokhin <mykyta.dorokhin@globallogic.com>2016-09-13 22:35:55 +0300
commitf544b19438dc3a0c14b957d8ba5fcc1113ecf542 (patch)
treeb646dff5614f9f2009904cec34d49c466ddb227b
parentf85e518970c3fec481ce59aabf91f097466ef40c (diff)
downloadmts-io-f544b19438dc3a0c14b957d8ba5fcc1113ecf542.tar.gz
mts-io-f544b19438dc3a0c14b957d8ba5fcc1113ecf542.tar.bz2
mts-io-f544b19438dc3a0c14b957d8ba5fcc1113ecf542.zip
feat: add MTP-0.0 hardware support1.3.0
-rw-r--r--io-module/mtp.c418
-rw-r--r--io-module/mts_io.c8
-rw-r--r--io-module/mts_io.h2
3 files changed, 427 insertions, 1 deletions
diff --git a/io-module/mtp.c b/io-module/mtp.c
new file mode 100644
index 0000000..3d536a4
--- /dev/null
+++ b/io-module/mtp.c
@@ -0,0 +1,418 @@
+#define MTP_RADIO_RESET
+
+static struct gpio_pin gpio_pins_mtp_0_0[] = {
+ {
+ .name = "ETH_EN",
+ .pin = {
+ .gpio = AT91_PIN_PC6, // NETH_RST
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "eth-enabled",
+ },
+ .active_low = 0,
+ },
+ {
+ .name = "RADIO_POWER_MONITOR",
+ .pin = {
+ .gpio = AT91_PIN_PA23, // 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 = "USER_PUSHBUTTON",
+ .pin = {
+ .gpio = AT91_PIN_PA5, // User Pushbutton
+ .flags = GPIOF_IN,
+ .label = "button",
+ },
+ .active_low = 1,
+ },
+ {
+ .name = "LORA_RESET",
+ .pin = {
+ .gpio = AT91_PIN_PA8, // LORA_RST
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "lora-reset",
+ },
+ },
+
+ /* LEDs */
+ {
+ .name = "LED2", // LED2 is for LoRa status
+ .pin = {
+ .gpio = AT91_PIN_PC15,
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "led-lora",
+ },
+ .active_low = 1,
+ },
+ {
+ .name = "LED2",
+ .pin = {
+ .gpio = AT91_PIN_PC15,
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "led-a",
+ },
+ .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 = "LED3",
+ .pin = {
+ .gpio = AT91_PIN_PC16,
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "led-b",
+ },
+ .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,
+ },
+ {
+ .name = "LED4",
+ .pin = {
+ .gpio = AT91_PIN_PC20,
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "led-c",
+ },
+ .active_low = 1,
+ },
+ {
+ .name = "LED5", // DEV_LED_GN
+ .pin = {
+ .gpio = AT91_PIN_PC25,
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "led-dev",
+ },
+ .active_low = 1,
+ },
+ {
+ .name = "LED5",
+ .pin = {
+ .gpio = AT91_PIN_PC25,
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "led-d",
+ },
+ .active_low = 1,
+ },
+ { },
+};
+
+
+#ifdef MTP_RADIO_RESET
+
+/* radio control (power/reset) for mtp */
+static int radio_off_mtp(void)
+{
+ int value;
+ 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");
+
+ 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");
+ gpio_set_value(onoff_pin->pin.gpio, 0);
+
+ msleep(3500);
+
+ // set on/off pin high
+ gpio_set_value(onoff_pin->pin.gpio, 1);
+
+ msleep(200);
+
+ // 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
+ gpio_set_value(rst_pin->pin.gpio, 0);
+
+ msleep(500);
+
+ // set pin high
+ gpio_set_value(rst_pin->pin.gpio, 1);
+ } else {
+ log_info("radio has been shut down");
+ }
+
+ return 0;
+}
+
+static int radio_on_mtp(void)
+{
+ int value;
+ 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");
+
+ 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");
+ gpio_set_value(onoff_pin->pin.gpio, 0);
+
+ msleep(5500);
+
+ // set on/off pin high
+ gpio_set_value(onoff_pin->pin.gpio, 1);
+
+ 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
+ gpio_set_value(rst_pin->pin.gpio, 0);
+
+ msleep(500);
+
+ // set pin high
+ gpio_set_value(rst_pin->pin.gpio, 1);
+ } else {
+ log_info("radio has been turned on");
+ }
+
+ return 0;
+}
+
+static int radio_reset_mtp(void)
+{
+ struct gpio_pin *onoff_pin = gpio_pin_by_attr_name("radio-power");
+ struct gpio_pin *rst_pin = gpio_pin_by_attr_name("radio-reset");
+
+ if (!rst_pin || !onoff_pin) {
+ return -ENODEV;
+ }
+
+ // drive reset pin low for 500ms
+ gpio_set_value(rst_pin->pin.gpio, 0);
+
+ msleep(500);
+
+ // set pin high
+ gpio_set_value(rst_pin->pin.gpio, 1);
+
+ // wait for 2 sec before toggling on/off pin
+ msleep(2000);
+
+ // drive on/off pin low for 6 sec
+ gpio_set_value(onoff_pin->pin.gpio, 0);
+
+ msleep(6000);
+
+ // set on/off pin high
+ gpio_set_value(onoff_pin->pin.gpio, 1);
+
+ 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;
+ }
+ if (value == 0) {
+ mutex_lock(&mts_io_mutex);
+ err = radio_off_mtp();
+ mutex_unlock(&mts_io_mutex);
+ } else {
+ mutex_lock(&mts_io_mutex);
+ 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("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;
+ }
+
+ log_info("radio is reset\n");
+
+ 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 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);
+#endif // MTP_RADIO_RESET
+
+static DEVICE_ATTR_MTS(dev_attr_lora_reset_mtp, "lora-reset",
+ mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
+
+static DEVICE_ATTR_MTS(dev_attr_eth_enabled_mtp, "eth-enabled",
+ mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
+
+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_dev_gpio_mtp, "led-dev",
+ mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
+
+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_enabled_mtp.attr,
+
+#ifdef MTP_RADIO_RESET
+ &dev_attr_radio_power_mtp.attr,
+ &dev_attr_radio_reset_mtp.attr,
+#else
+ &dev_attr_radio_power.attr,
+ &dev_attr_radio_reset.attr,
+#endif
+
+ &dev_attr_radio_reset_backoffs.attr,
+ &dev_attr_radio_reset_backoff_index.attr,
+ &dev_attr_radio_reset_backoff_seconds.attr,
+
+ &dev_attr_led_cd_gpio.attr,
+ &dev_attr_led_lora_gpio_mtp.attr,
+ &dev_attr_led_dev_gpio_mtp.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_lora_reset_mtp.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 deb2d92..bf0a6bd 100644
--- a/io-module/mts_io.c
+++ b/io-module/mts_io.c
@@ -623,6 +623,7 @@ static DEVICE_ATTR_RO_MTS(dev_attr_eth_mac, "mac-eth",
/* include per-device pins and attributes */
#include "mtcdt.c"
+#include "mtp.c"
#if NUM_AP > 0
@@ -766,7 +767,12 @@ static int mts_id_eeprom_load(void)
if (mts_id_eeprom[0] == 0xFF) {
log_error("uninitialized eeprom");
return -EIO;
- } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTCDT_0_1, strlen(HW_VERSION_MTCDT_0_1)) == 0) {
+ } 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;
+ log_info("detected board %s", HW_VERSION_MTP_0_0);
+ }
+ else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTCDT_0_1, strlen(HW_VERSION_MTCDT_0_1)) == 0) {
attr_group = &mtcdt_0_1_platform_attribute_group;
gpio_pins = gpio_pins_mtcdt_0_1;
log_info("detected board %s", HW_VERSION_MTCDT_0_1);
diff --git a/io-module/mts_io.h b/io-module/mts_io.h
index 2939894..791235f 100644
--- a/io-module/mts_io.h
+++ b/io-module/mts_io.h
@@ -63,6 +63,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"
enum {
MTCDP_E1_DK_0_0,
@@ -72,6 +73,7 @@ enum {
MTR_0_1,
MTCDT_0_0,
MTCDT_0_1,
+ MTP_0_0,
};
enum {