From 5a93570f21fb963f2dc1bdd4dedc01f2d9a86200 Mon Sep 17 00:00:00 2001 From: Mykyta Dorokhin Date: Mon, 3 Apr 2017 15:08:56 +0300 Subject: Add mtr support --- io-module/mtr.c | 1298 ++++++++++++++++++++++++++++++++++++++++++++++++++++ io-module/mts_io.c | 38 +- io-module/mts_io.h | 11 +- 3 files changed, 1335 insertions(+), 12 deletions(-) create mode 100644 io-module/mtr.c diff --git a/io-module/mtr.c b/io-module/mtr.c new file mode 100644 index 0000000..712dc62 --- /dev/null +++ b/io-module/mtr.c @@ -0,0 +1,1298 @@ +static struct gpio_pin gpio_pins_mtr_0_0[] = { + { + .name = "ETH_EN", + .pin = { + .gpio = AT91_PIN_PC6, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "eth-enabled", + }, + .active_low = 0, + }, + { + .name = "RADIO_POWER_MONITOR", + .pin = { + .gpio = AT91_PIN_PA23, + .flags = GPIOF_IN, + .label = "radio-power-monitor", + }, + .active_low = 0, + }, + { + .name = "RADIO_RESET", + .pin = { + .gpio = AT91_PIN_PA22, + .flags = GPIOF_OUT_INIT_HIGH | GPIOF_OPEN_DRAIN, + .label = "radio-reset", + }, + .active_low = 0, + }, + { + .name = "RADIO_POWER", + .pin = { + .gpio = AT91_PIN_PA21, + .flags = GPIOF_OUT_INIT_HIGH | GPIOF_OPEN_DRAIN, + .label = "radio-power", + }, + .active_low = 0, + }, + { + .name = "DEVICE_RESET", + .pin = { + .gpio = AT91_PIN_PC4, + .flags = GPIOF_IN, + .label = "reset", + }, + .active_low = 1, + }, + { + .name = "LS_LED", + .pin = { + .gpio = AT91_PIN_PC16, +#if LED_LS_CONTROLLABLE + .flags = GPIOF_OUT_INIT_HIGH, +#else + .flags = GPIOF_IN, +#endif + .label = "led-ls", + }, + .active_low = 1, + }, + { + .name = "STATUS_LED", + .pin = { + .gpio = AT91_PIN_PC21, + .flags = GPIOF_OUT_INIT_LOW, + .label = "led-status", + }, + .active_low = 1, + }, + { + .name = "LED3", + .pin = { + .gpio = AT91_PIN_PC15, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-wifi", + }, + .active_low = 1, + }, + { + .name = "LED3", + .pin = { + .gpio = AT91_PIN_PC15, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-b", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-cd", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-c", + }, + .active_low = 1, + }, + { + .name = "LED6", + .pin = { + .gpio = AT91_PIN_PC19, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig1", + }, + .active_low = 1, + }, + { + .name = "LED6", + .pin = { + .gpio = AT91_PIN_PC19, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-d", + }, + .active_low = 1, + }, + { + .name = "LED7", + .pin = { + .gpio = AT91_PIN_PC18, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig2", + }, + .active_low = 1, + }, + { + .name = "LED7", + .pin = { + .gpio = AT91_PIN_PC18, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-e", + }, + .active_low = 1, + }, + { + .name = "LED8", + .pin = { + .gpio = AT91_PIN_PC17, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig3", + }, + .active_low = 1, + }, + { + .name = "LED8", + .pin = { + .gpio = AT91_PIN_PC17, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-f", + }, + .active_low = 1, + }, + { + .name = "RI_B", + .pin = { + .gpio = AT91_PIN_PC25, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "extserial-ri", + }, + .active_low = 1, + }, + { + .name = "DTR_B", + .pin = { + .gpio = AT91_PIN_PC26, + .flags = GPIOF_IN, + .label = "extserial-dtr", + }, + .active_low = 1, + }, + { + .name = "DSR_B", + .pin = { + .gpio = AT91_PIN_PC27, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "extserial-dsr", + }, + .active_low = 1, + }, + { + .name = "DCD_B", + .pin = { + .gpio = AT91_PIN_PC28, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "extserial-dcd", + }, + .active_low = 1, + }, + { + .name = "BT_EN", + .pin = { + .gpio = AT91_PIN_PA28, + .flags = GPIOF_OUT_INIT_LOW, + .label = "bt-enabled", + }, + .active_low = 0, + }, + { + .name = "WLAN_EN", + .pin = { + .gpio = AT91_PIN_PA27, + .flags = GPIOF_OUT_INIT_LOW, + .label = "wlan-enabled", + }, + .active_low = 0, + }, + { }, +}; + +static struct gpio_pin gpio_pins_mtr_0_1[] = { + { + .name = "ETH_EN", + .pin = { + .gpio = AT91_PIN_PC6, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "eth-enabled", + }, + .active_low = 0, + }, + { + .name = "RADIO_POWER_MONITOR", + .pin = { + .gpio = AT91_PIN_PA23, + .flags = GPIOF_IN, + .label = "radio-power-monitor", + }, + .active_low = 0, + }, + { + .name = "RADIO_RESET", + .pin = { + .gpio = AT91_PIN_PA22, + .flags = GPIOF_OUT_INIT_HIGH | GPIOF_PULLUP, + .label = "radio-reset", + }, + .active_low = 0, + }, + { + .name = "RADIO_POWER", + .pin = { + .gpio = AT91_PIN_PA21, + .flags = GPIOF_OUT_INIT_HIGH | GPIOF_PULLUP, + .label = "radio-power", + }, + .active_low = 0, + }, + { + .name = "DEVICE_RESET", + .pin = { + .gpio = AT91_PIN_PC4, + .flags = GPIOF_IN, + .label = "reset", + }, + .active_low = 1, + }, + { + .name = "LS_LED", + .pin = { + .gpio = AT91_PIN_PC16, +#if LED_LS_CONTROLLABLE + .flags = GPIOF_OUT_INIT_HIGH, +#else + .flags = GPIOF_IN, +#endif + .label = "led-ls", + }, + .active_low = 1, + }, + { + .name = "STATUS_LED", + .pin = { + .gpio = AT91_PIN_PC21, + .flags = GPIOF_OUT_INIT_LOW, + .label = "led-status", + }, + .active_low = 1, + }, + { + .name = "LED3", + .pin = { + .gpio = AT91_PIN_PC15, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-wifi", + }, + .active_low = 1, + }, + { + .name = "LED3", + .pin = { + .gpio = AT91_PIN_PC15, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-b", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-cd", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-c", + }, + .active_low = 1, + }, + { + .name = "LED6", + .pin = { + .gpio = AT91_PIN_PC19, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig1", + }, + .active_low = 1, + }, + { + .name = "LED6", + .pin = { + .gpio = AT91_PIN_PC19, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-d", + }, + .active_low = 1, + }, + { + .name = "LED7", + .pin = { + .gpio = AT91_PIN_PC18, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig2", + }, + .active_low = 1, + }, + { + .name = "LED7", + .pin = { + .gpio = AT91_PIN_PC18, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-e", + }, + .active_low = 1, + }, + { + .name = "LED8", + .pin = { + .gpio = AT91_PIN_PC17, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig3", + }, + .active_low = 1, + }, + { + .name = "LED8", + .pin = { + .gpio = AT91_PIN_PC17, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-f", + }, + .active_low = 1, + }, + { + .name = "RI_B", + .pin = { + .gpio = AT91_PIN_PC25, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "extserial-ri", + }, + .active_low = 1, + }, + { + .name = "DTR_B", + .pin = { + .gpio = AT91_PIN_PC26, + .flags = GPIOF_IN, + .label = "extserial-dtr", + }, + .active_low = 1, + }, + { + .name = "DSR_B", + .pin = { + .gpio = AT91_PIN_PC27, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "extserial-dsr", + }, + .active_low = 1, + }, + { + .name = "DCD_B", + .pin = { + .gpio = AT91_PIN_PC28, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "extserial-dcd", + }, + .active_low = 1, + }, + { + .name = "BT_EN", + .pin = { + .gpio = AT91_PIN_PA28, + .flags = GPIOF_OUT_INIT_LOW, + .label = "bt-enabled", + }, + .active_low = 0, + }, + { + .name = "WLAN_EN", + .pin = { + .gpio = AT91_PIN_PA27, + .flags = GPIOF_OUT_INIT_LOW, + .label = "wlan-enabled", + }, + .active_low = 0, + }, + { }, +}; + +static struct gpio_pin gpio_pins_mtrv1_0_0[] = { + { + .name = "ETH_EN", + .pin = { + .gpio = AT91_PIN_PC6, + .flags = GPIOF_OUT_INIT_HIGH | GPIOF_OPEN_DRAIN, /* without GPIOF_OPEN_DRAIN causes issues with the Micrel KSZ8091RNBCA (RMII) PHY */ + .label = "eth-enabled", + }, + .active_low = 0, + }, + { + .name = "RADIO_POWER_MONITOR", + .pin = { + .gpio = AT91_PIN_PA23, + .flags = GPIOF_IN, + .label = "radio-power-monitor", + }, + .active_low = 0, + }, + { + .name = "RADIO_RESET", + .pin = { + .gpio = AT91_PIN_PA22, + .flags = GPIOF_OUT_INIT_HIGH | GPIOF_PULLUP, + .label = "radio-reset", + }, + .active_low = 0, + }, + { + .name = "RADIO_POWER", + .pin = { + .gpio = AT91_PIN_PA21, + .flags = GPIOF_OUT_INIT_HIGH | GPIOF_PULLUP, + .label = "radio-power", + }, + .active_low = 0, + }, + { + .name = "DEVICE_RESET", + .pin = { + .gpio = AT91_PIN_PC4, + .flags = GPIOF_IN, + .label = "reset", + }, + .active_low = 1, + }, + { + .name = "LS_LED", + .pin = { + .gpio = AT91_PIN_PC4, +#if LED_LS_CONTROLLABLE + .flags = GPIOF_OUT_INIT_HIGH, +#else + .flags = GPIOF_IN, +#endif + .label = "led-ls", + }, + .active_low = 1, + }, + { + .name = "STATUS_LED", + .pin = { + .gpio = AT91_PIN_PC21, + .flags = GPIOF_OUT_INIT_LOW, + .label = "led-status", + }, + .active_low = 1, + }, + { + .name = "LED3", + .pin = { + .gpio = AT91_PIN_PC15, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-wifi", + }, + .active_low = 1, + }, + { + .name = "LED3", + .pin = { + .gpio = AT91_PIN_PC15, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-b", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-cd", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-c", + }, + .active_low = 1, + }, + { + .name = "LED6", + .pin = { + .gpio = AT91_PIN_PC19, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig1", + }, + .active_low = 1, + }, + { + .name = "LED6", + .pin = { + .gpio = AT91_PIN_PC19, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-d", + }, + .active_low = 1, + }, + { + .name = "LED7", + .pin = { + .gpio = AT91_PIN_PC18, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig2", + }, + .active_low = 1, + }, + { + .name = "LED7", + .pin = { + .gpio = AT91_PIN_PC18, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-e", + }, + .active_low = 1, + }, + { + .name = "LED8", + .pin = { + .gpio = AT91_PIN_PC17, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig3", + }, + .active_low = 1, + }, + { + .name = "LED8", + .pin = { + .gpio = AT91_PIN_PC17, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-f", + }, + .active_low = 1, + }, + { + .name = "RI_B", + .pin = { + .gpio = AT91_PIN_PC25, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "extserial-ri", + }, + .active_low = 1, + }, + { + .name = "DTR_B", + .pin = { + .gpio = AT91_PIN_PC26, + .flags = GPIOF_IN, + .label = "extserial-dtr", + }, + .active_low = 1, + }, + { + .name = "DSR_B", + .pin = { + .gpio = AT91_PIN_PC27, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "extserial-dsr", + }, + .active_low = 1, + }, + { + .name = "DCD_B", + .pin = { + .gpio = AT91_PIN_PC28, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "extserial-dcd", + }, + .active_low = 1, + }, + { + .name = "BT_EN", + .pin = { + .gpio = AT91_PIN_PA28, + .flags = GPIOF_OUT_INIT_LOW, + .label = "bt-enabled", + }, + .active_low = 0, + }, + { + .name = "WLAN_EN", + .pin = { + .gpio = AT91_PIN_PA27, + .flags = GPIOF_OUT_INIT_LOW, + .label = "wlan-enabled", + }, + .active_low = 0, + }, + { }, +}; + + +static struct gpio_pin gpio_pins_mtrv1_0_1[] = { + { + .name = "ETH_EN", + .pin = { + .gpio = AT91_PIN_PC6, + .flags = GPIOF_OUT_INIT_HIGH | GPIOF_OPEN_DRAIN, /* without GPIOF_OPEN_DRAIN causes issues with the Micrel KSZ8091RNBCA (RMII) PHY */ + .label = "eth-enabled", + }, + .active_low = 0, + }, + { + .name = "RADIO_POWER_MONITOR", + .pin = { + .gpio = AT91_PIN_PA23, + .flags = GPIOF_IN, + .label = "radio-power-monitor", + }, + .active_low = 0, + }, + { + .name = "RADIO_RESET", + .pin = { + .gpio = AT91_PIN_PA22, + .flags = GPIOF_OUT_INIT_HIGH | GPIOF_PULLUP, + .label = "radio-reset", + }, + .active_low = 0, + }, + { + .name = "RADIO_POWER", + .pin = { + .gpio = AT91_PIN_PA21, + .flags = GPIOF_OUT_INIT_HIGH | GPIOF_PULLUP, + .label = "radio-power", + }, + .active_low = 0, + }, + { + .name = "DEVICE_RESET", + .pin = { + .gpio = AT91_PIN_PC4, + .flags = GPIOF_IN, + .label = "reset", + }, + .active_low = 1, + }, + { + .name = "LS_LED", + .pin = { + .gpio = AT91_PIN_PC4, +#if LED_LS_CONTROLLABLE + .flags = GPIOF_OUT_INIT_HIGH, +#else + .flags = GPIOF_IN, +#endif + .label = "led-ls", + }, + .active_low = 1, + }, + { + .name = "STATUS_LED", + .pin = { + .gpio = AT91_PIN_PC21, + .flags = GPIOF_OUT_INIT_LOW, + .label = "led-status", + }, + .active_low = 1, + }, + { + .name = "LED3", + .pin = { + .gpio = AT91_PIN_PC15, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-wifi", + }, + .active_low = 1, + }, + { + .name = "LED3", + .pin = { + .gpio = AT91_PIN_PC15, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-b", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-cd", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-c", + }, + .active_low = 1, + }, + { + .name = "LED6", + .pin = { + .gpio = AT91_PIN_PC19, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig1", + }, + .active_low = 1, + }, + { + .name = "LED6", + .pin = { + .gpio = AT91_PIN_PC19, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-d", + }, + .active_low = 1, + }, + { + .name = "LED7", + .pin = { + .gpio = AT91_PIN_PC18, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig2", + }, + .active_low = 1, + }, + { + .name = "LED7", + .pin = { + .gpio = AT91_PIN_PC18, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-e", + }, + .active_low = 1, + }, + { + .name = "LED8", + .pin = { + .gpio = AT91_PIN_PC17, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig3", + }, + .active_low = 1, + }, + { + .name = "LED8", + .pin = { + .gpio = AT91_PIN_PC17, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-f", + }, + .active_low = 1, + }, + { + .name = "RI_B", + .pin = { + .gpio = AT91_PIN_PC25, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "extserial-ri", + }, + .active_low = 1, + }, + { + .name = "DTR_B", + .pin = { + .gpio = AT91_PIN_PC26, + .flags = GPIOF_IN, + .label = "extserial-dtr", + }, + .active_low = 1, + }, + { + .name = "DSR_B", + .pin = { + .gpio = AT91_PIN_PC27, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "extserial-dsr", + }, + .active_low = 1, + }, + { + .name = "DCD_B", + .pin = { + .gpio = AT91_PIN_PC28, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "extserial-dcd", + }, + .active_low = 1, + }, + + // The difference between MTRv1_0_0 and MTRv1_0_1 starts here + { + .name = "WIFI_BT_ULPWKUP", + .pin = { + .gpio = AT91_PIN_PA0, + .flags = GPIOF_IN, + .label = "wifi-bt-ulpwkup", + } + }, + { + .name = "WIFI_BT_LPWKUP", + .pin = { + .gpio = AT91_PIN_PA6, + .flags = GPIOF_IN, + .label = "wifi-bt-lpwkup", + } + }, + { + .name = "WIFI_BT_INT", + .pin = { + .gpio = AT91_PIN_PB11, + .flags = GPIOF_IN, + .label = "wifi-bt-int", + } + }, + { + .name = "WIFI_BT_RESET", + .pin = { + .gpio = AT91_PIN_PD14, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "wifi-bt-reset", + } + }, + { + .name = "WIFI_BT_LPMODE", + .pin = { + .gpio = AT91_PIN_PD20, + .flags = GPIOF_IN, + .label = "wifi-bt-lpmode", + } + }, + { + .name = "GNSS_RESET", + .pin = { + .gpio = AT91_PIN_PD15, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "gnss-reset", + } + }, + { + .name = "SECURE_RESET", + .pin = { + .gpio = AT91_PIN_PD16, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "secure-reset", + } + }, + { + .name = "USBHUB_RESET", + .pin = { + .gpio = AT91_PIN_PD18, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "usbhub-reset", + } + }, + { + .name = "GNSS_INT", + .pin = { + .gpio = AT91_PIN_PD19, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "gnss-int", + } + }, + + + { }, +}; + + +/* radio control (power/reset) for mtr */ +static int radio_off_mtr(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_mtr(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_mtr(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_mtr(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_mtr(); + mutex_unlock(&mts_io_mutex); + } else { + mutex_lock(&mts_io_mutex); + err = radio_on_mtr(); + mutex_unlock(&mts_io_mutex); + } + + if (err) { + return err; + } + + return count; +} + +static ssize_t mts_attr_store_radio_reset_mtr(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_mtr(); + + mutex_unlock(&mts_io_mutex); + + if (err) { + return err; + } + + return count; +} + +static ssize_t mts_attr_show_radio_power(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_power_mtr, "radio-power", + mts_attr_show_radio_power, mts_attr_store_radio_power_mtr); + +static DEVICE_ATTR_MTS(dev_attr_radio_reset_mtr, "radio-reset", + mts_attr_show_gpio_pin, mts_attr_store_radio_reset_mtr); + +static DEVICE_ATTR_MTS(dev_attr_eth_enabled_mtr, "eth-enabled", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_bt_enabled_mtr, "bt-enabled", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_wlan_enabled_mtr, "wlan-enabled", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_led_wifi_gpio_mtr, "led-wifi", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_led_f_gpio_mtr, "led-f", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_extserial_ri_gpio_mtr, "extserial-ri", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_RO_MTS(dev_attr_extserial_dtr_mtr, "extserial-dtr", + mts_attr_show_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_extserial_dsr_gpio_mtr, "extserial-dsr", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_extserial_dcd_gpio_mtr, "extserial-dcd", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_RO_MTS(dev_attr_wifi_mac_mtr, "mac-wifi", + mts_attr_show_product_info); + +static DEVICE_ATTR_MTS(dev_attr_wifi_bt_lpwkup_mtr, "wifi-bt-lpwkup", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_wifi_bt_ulpwkup_mtr, "wifi-bt-ulpwkup", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_wifi_bt_reset_mtr, "wifi-bt-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_RO_MTS(dev_attr_wifi_bt_lpmode_mtr, "wifi-bt-lpmode", + mts_attr_show_gpio_pin); + +static DEVICE_ATTR_RO_MTS(dev_attr_wifi_bt_int_mtr, "wifi-bt-int", + mts_attr_show_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_gnss_reset_mtr, "gnss-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_usbhub_reset_mtr, "usbhub-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_RO_MTS(dev_attr_gnss_int_mtr, "gnss-int", + mts_attr_show_gpio_pin); + + +static struct attribute *mtr_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_wifi_mac_mtr.attr, + &dev_attr_reset.attr, + &dev_attr_reset_monitor.attr, + &dev_attr_reset_monitor_intervals.attr, + &dev_attr_radio_power_mtr.attr, + &dev_attr_radio_reset_mtr.attr, + + &dev_attr_radio_reset_backoffs.attr, + &dev_attr_radio_reset_backoff_index.attr, + &dev_attr_radio_reset_backoff_seconds.attr, + + &dev_attr_extserial_ri_gpio_mtr.attr, + &dev_attr_extserial_dtr_mtr.attr, + &dev_attr_extserial_dsr_gpio_mtr.attr, + &dev_attr_extserial_dcd_gpio_mtr.attr, + + &dev_attr_eth_enabled_mtr.attr, + &dev_attr_bt_enabled_mtr.attr, + &dev_attr_wlan_enabled_mtr.attr, + + &dev_attr_led_status.attr, + &dev_attr_led_cd_gpio.attr, + &dev_attr_led_sig1_gpio.attr, + &dev_attr_led_sig2_gpio.attr, + &dev_attr_led_sig3_gpio.attr, + &dev_attr_led_wifi_gpio_mtr.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_mtr.attr, + + NULL, +}; + +static struct attribute_group mtr_platform_attribute_group = { + .attrs = mtr_platform_attributes +}; + + +static struct attribute *mtrv1_0_1_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_wifi_mac_mtr.attr, + + &dev_attr_reset.attr, + &dev_attr_reset_monitor.attr, + &dev_attr_reset_monitor_intervals.attr, + &dev_attr_radio_power_mtr.attr, + &dev_attr_radio_reset_mtr.attr, + + &dev_attr_radio_reset_backoffs.attr, + &dev_attr_radio_reset_backoff_index.attr, + &dev_attr_radio_reset_backoff_seconds.attr, + + &dev_attr_extserial_ri_gpio_mtr.attr, + &dev_attr_extserial_dtr_mtr.attr, + &dev_attr_extserial_dsr_gpio_mtr.attr, + &dev_attr_extserial_dcd_gpio_mtr.attr, + + &dev_attr_eth_enabled_mtr.attr, + &dev_attr_wifi_bt_lpwkup_mtr.attr, + &dev_attr_wifi_bt_ulpwkup_mtr.attr, + &dev_attr_wifi_bt_reset_mtr.attr, + &dev_attr_wifi_bt_lpmode_mtr.attr, + &dev_attr_wifi_bt_int_mtr.attr, + &dev_attr_gnss_reset_mtr.attr, + &dev_attr_usbhub_reset_mtr.attr, + &dev_attr_gnss_int_mtr.attr, + + &dev_attr_led_status.attr, + &dev_attr_led_cd_gpio.attr, + &dev_attr_led_sig1_gpio.attr, + &dev_attr_led_sig2_gpio.attr, + &dev_attr_led_sig3_gpio.attr, + &dev_attr_led_wifi_gpio_mtr.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_mtr.attr, + + NULL, +}; + +static struct attribute_group mtrv1_0_1_platform_attribute_group = { + .attrs = mtrv1_0_1_platform_attributes +}; diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 371243c..1217250 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.5.10" +#define DRIVER_VERSION "v1.5.11" #define DRIVER_AUTHOR "James Maki " #define DRIVER_DESC "MTS-IO Controller" #define DRIVER_NAME "mts-io" @@ -124,7 +124,7 @@ static void reset_callback(struct work_struct *ignored) mutex_lock(&mts_io_mutex); - pin = gpio_pin_by_name("DEVICE_RESET"); + pin = gpio_pin_by_attr_name("reset"); if (pin) { reset_pressed = !gpio_get_value(pin->pin.gpio); } @@ -288,7 +288,7 @@ static ssize_t mts_attr_store_radio_reset(struct device *dev, log_info("radio is reset\n"); - pin = gpio_pin_by_name("RADIO_RESET"); + pin = gpio_pin_by_attr_name("radio-reset"); if (!pin) { return -ENODEV; @@ -592,6 +592,14 @@ 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], @@ -640,6 +648,7 @@ static DEVICE_ATTR_RO_MTS(dev_attr_eth_mac, "mac-eth", /* include per-device pins and attributes */ #include "mtcdt.c" #include "mtcap.c" +#include "mtr.c" /* include capabilities sub-directory support */ #include "mts_capab.c" @@ -821,8 +830,27 @@ static int mts_id_eeprom_load() } 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) { + } 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_hw_version = MTR_0_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_hw_version = MTR_0_1; + log_info("detected board %s", HW_VERSION_MTR_0_1); + } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTRV1_0_0, strlen(HW_VERSION_MTRV1_0_0)) == 0) { + attr_group = &mtr_platform_attribute_group; + gpio_pins = gpio_pins_mtrv1_0_0; + mts_hw_version = MTRV1_0_0; + log_info("detected board %s", HW_VERSION_MTRV1_0_0); + } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTRV1_0_1, strlen(HW_VERSION_MTRV1_0_1)) == 0) { + attr_group = &mtrv1_0_1_platform_attribute_group; + gpio_pins = gpio_pins_mtrv1_0_1; + mts_hw_version = MTRV1_0_1; + log_info("detected board %s", HW_VERSION_MTRV1_0_1); + } 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; if(DEVICE_CAPA(id_eeprom.capa, CAPA_WIFI)) { attr_blength += sizeof mtcdt_0_1_wifi_bt_attributes; diff --git a/io-module/mts_io.h b/io-module/mts_io.h index 5918fa9..05111c7 100644 --- a/io-module/mts_io.h +++ b/io-module/mts_io.h @@ -65,6 +65,8 @@ struct device_attribute _dev_name = { \ #define HW_VERSION_MT100EOCG_0_0 "MT100EOCG-0.0" #define HW_VERSION_MTR_0_0 "MTR-0.0" #define HW_VERSION_MTR_0_1 "MTR-0.1" +#define HW_VERSION_MTRV1_0_0 "MTRV1-0.0" +#define HW_VERSION_MTRV1_0_1 "MTRV1-0.1" #define HW_VERSION_MTCDT_0_0 "MTCDT-0.0" #define HW_VERSION_MTCDT_0_1 "MTCDT-0.1" #define HW_VERSION_MTCAP_0_0 "MTCAP-0.0" @@ -75,6 +77,8 @@ enum { MT100EOCG_0_0, MTR_0_0, MTR_0_1, + MTRV1_0_0, + MTRV1_0_1, MTCDT_0_0, MTCDT_0_1, MTCAP_0_0, @@ -91,13 +95,6 @@ enum { MTAC_LORA_1_5, }; -// GPIO pin types:input, output, open drain (1 = high Z, 0 = output low) -enum { - GPIO_DIR_INPUT, - GPIO_DIR_OUTPUT, - GPIO_DIR_OD, -}; - struct gpio_pin { char name[32]; struct gpio pin; -- cgit v1.2.3