summaryrefslogtreecommitdiff
path: root/io-module
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2021-09-03 04:59:39 -0500
committerJohn Klug <john.klug@multitech.com>2021-09-03 05:02:41 -0500
commit1d2d4cb343e6d8b290e801a7dc776f9fb0aa8999 (patch)
treee584dc2b9e399a37817fe2c4dccaa2e645702c1b /io-module
parentbc918398a517f618ac102cde2ade494924a85a0c (diff)
downloadmts-io-1d2d4cb343e6d8b290e801a7dc776f9fb0aa8999.tar.gz
mts-io-1d2d4cb343e6d8b290e801a7dc776f9fb0aa8999.tar.bz2
mts-io-1d2d4cb343e6d8b290e801a7dc776f9fb0aa8999.zip
radio reset monitor feature and MTRV1-0.4 hardware4.7.0
Diffstat (limited to 'io-module')
-rw-r--r--io-module/Makefile2
-rw-r--r--io-module/adc.c1
-rw-r--r--io-module/machine/mtcap.c2
-rw-r--r--io-module/machine/mtcap3.c19
-rw-r--r--io-module/machine/mths.c2
-rw-r--r--io-module/machine/mtr.c369
-rw-r--r--io-module/mts-io.c72
-rw-r--r--io-module/mts_io_module.h4
-rw-r--r--io-module/radio_udev_discovery.c308
-rw-r--r--io-module/radio_udev_discovery.h24
10 files changed, 752 insertions, 51 deletions
diff --git a/io-module/Makefile b/io-module/Makefile
index 0c05414..e45e789 100644
--- a/io-module/Makefile
+++ b/io-module/Makefile
@@ -1,6 +1,6 @@
obj-m := mts_io.o
-mts_io-objs := buttons.o mts-io.o mts_supercap.o
+mts_io-objs := buttons.o mts-io.o mts_supercap.o radio_udev_discovery.o
clean:
rm -f *.ko *.o
diff --git a/io-module/adc.c b/io-module/adc.c
index 3d5f3d0..541dc95 100644
--- a/io-module/adc.c
+++ b/io-module/adc.c
@@ -118,7 +118,6 @@ static int mts_io_board_adc_probe(struct platform_device *pdev)
static int mts_io_board_adc_remove(struct platform_device *pdev)
{
if (adc_clk) {
- int ret;
clk_disable_unprepare(adc_clk);
}
return 0;
diff --git a/io-module/machine/mtcap.c b/io-module/machine/mtcap.c
index 0d4af0f..e013f14 100644
--- a/io-module/machine/mtcap.c
+++ b/io-module/machine/mtcap.c
@@ -349,7 +349,7 @@ static int radio_reset_mtcap(int radio_model)
if (!rst_pin || !onoff_pin) {
return -ENODEV;
}
-
+ reset_radio_udev_discovery();
//
// Unconditional shutdown
//
diff --git a/io-module/machine/mtcap3.c b/io-module/machine/mtcap3.c
index 2304a28..8d2f3c4 100644
--- a/io-module/machine/mtcap3.c
+++ b/io-module/machine/mtcap3.c
@@ -373,7 +373,8 @@ static ssize_t mts_attr_store_radio_reset_mtcap3(struct device *dev,
if (value != 0 && value != -1) {
return -EINVAL;
}
-
+
+ reset_radio_udev_discovery();
mutex_lock(&mts_io_mutex);
radio_off_mtcap3();
@@ -453,6 +454,11 @@ static DEVICE_ATTR_MTS(dev_attr_led_lora_gpio_mtcap3, "led-lora",
static DEVICE_ATTR_MTS(dev_attr_led_extra_gpio_mtcap3, "led-extra",
mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
+// here to maintain compatiblility
+static DEVICE_ATTR_MTS(dev_attr_radio_enable_mtcap3, "radio-enable",
+ mts_attr_show_radio_enable_mtcap3, mts_attr_store_radio_enable_mtcap3);
+
+
static struct attribute *mtcap3_0_0_platform_attributes[] = {
&dev_attr_vendor_id.attr,
&dev_attr_product_id.attr,
@@ -481,6 +487,8 @@ static struct attribute *mtcap3_0_0_platform_attributes[] = {
&dev_attr_radio_reset_backoff_index.attr,
&dev_attr_radio_reset_backoff_seconds.attr,
+ &dev_attr_radio_enable_mtcap3.attr,
+
NULL,
};
@@ -529,12 +537,3 @@ static struct attribute *mtcap3_0_0_lora_attributes[] = {
static struct attribute_group mtcap3_0_0_lora_attribute_group = {
.attrs = mtcap3_0_0_lora_attributes
};
-
-// here to maintain compatiblility
-static DEVICE_ATTR_MTS(dev_attr_radio_enable_mtcap3, "radio-enable",
- mts_attr_show_radio_enable_mtcap3, mts_attr_store_radio_enable_mtcap3);
-
-static struct attribute *mtcap3_0_0_enable_radio_attribute[] = {
- &dev_attr_radio_enable_mtcap3.attr,
-};
-
diff --git a/io-module/machine/mths.c b/io-module/machine/mths.c
index 1922d88..b74e69f 100644
--- a/io-module/machine/mths.c
+++ b/io-module/machine/mths.c
@@ -658,7 +658,7 @@ static int radio_reset_mths(void)
if (!rst_pin || !onoff_pin) {
return -ENODEV;
}
-
+ reset_radio_udev_discovery();
// drive reset pin low for 500ms
gpio_set_value(rst_pin->pin.gpio, 0);
diff --git a/io-module/machine/mtr.c b/io-module/machine/mtr.c
index 9f00be8..3838fd2 100644
--- a/io-module/machine/mtr.c
+++ b/io-module/machine/mtr.c
@@ -1460,6 +1460,270 @@ static struct gpio_pin gpio_pins_mtrv1_0_3[] = {
{ },
};
+static struct gpio_pin gpio_pins_mtrv1_0_4[] = {
+ {
+ .name = "ETH_RESET",
+ .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-reset",
+ },
+ .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,
+ },
+ { // Moved in MTRV1-0.4
+ .name = "RI_B",
+ .pin = {
+ .gpio = AT91_PIN_PC14,
+ .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_LOW,
+ .label = "gnss-reset",
+ }
+ },
+ {
+ .name = "SECURE_RESET",
+ .pin = {
+ .gpio = AT91_PIN_PD16,
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "secure-reset",
+ }
+ },
+ {
+ .name = "MTQ_RESET",
+ .pin = {
+ .gpio = AT91_PIN_PD17,
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "radio-reset",
+ }
+ },
+ {
+ .name = "GNSS_INT",
+ .pin = {
+ .gpio = AT91_PIN_PD19,
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "gnss-int",
+ }
+ },
+ // Difference with mtrv1_0_1 starts here
+ {
+ .name = "RADIO_WM_LK_M", // WM LINK Monitor for CAT M
+ .pin = {
+ .gpio = AT91_PIN_PA14,
+ .flags = GPIOF_IN,
+ .label = "radio-wm-lk-m",
+ }
+ },
+ // RADIO_STATUS must be at the end, because it might be removed
+ // if we ever support a Telit module which has no radio status.
+ {
+ .name = "RADIO_STATUS",
+ .pin = {
+ .gpio = AT91_PIN_PA28,
+ .flags = GPIOF_IN,
+ .label = "radio-status",
+ }
+ },
+
+ { },
+};
+
/* radio control (power/reset) for mtr */
static int radio_off_mtr(void)
{
@@ -1561,7 +1825,7 @@ static int radio_reset_mtr(void)
if (!rst_pin || !onoff_pin) {
return -ENODEV;
}
-
+ reset_radio_udev_discovery();
// drive reset pin low for 500ms
gpio_set_value(rst_pin->pin.gpio, 0);
@@ -1590,7 +1854,7 @@ static int radio_reset_mtr_mtq(void)
if (!rst_pin) {
return -ENODEV;
}
-
+ reset_radio_udev_discovery();
// drive reset pin low for 500ms
gpio_set_value(rst_pin->pin.gpio, 0);
@@ -1670,7 +1934,7 @@ static ssize_t mts_attr_store_radio_reset_mtr(struct device *dev,
mutex_lock(&mts_io_mutex);
- if (mts_hw_version == MTRV1_0_3)
+ if (mts_hw_version == MTRV1_0_3 || mts_hw_version == MTRV1_0_4)
{
err = radio_reset_mtr_mtq();
}
@@ -1766,6 +2030,9 @@ static DEVICE_ATTR_MTS(dev_attr_usbhub_reset_mtr, "usbhub-reset",
static DEVICE_ATTR_RO_MTS(dev_attr_gnss_int_mtr, "gnss-int",
mts_attr_show_gpio_pin);
+static DEVICE_ATTR_RO_MTS(dev_attr_radio_status_mtr, "radio-status",
+ mts_attr_show_gpio_pin);
+
static DEVICE_ATTR_RO_MTS(dev_attr_radio_wm_lk_m, "radio-wm-lk-m",
mts_attr_show_gpio_pin);
@@ -1816,6 +2083,9 @@ static struct attribute *mtr_platform_attributes[] = {
&dev_attr_radio_reset_backoff_index.attr,
&dev_attr_radio_reset_backoff_seconds.attr,
+ // UDEV notification of radio discovery
+ &dev_attr_radio_udev_discovery.attr,
+ &dev_attr_radio_reset_monitor.attr,
NULL,
};
@@ -1873,7 +2143,8 @@ static struct attribute *mtrv1_0_1_platform_attributes[] = {
&dev_attr_led_d_gpio.attr,
&dev_attr_led_e_gpio.attr,
&dev_attr_led_f_gpio_mtr.attr,
-
+ &dev_attr_radio_udev_discovery.attr,
+ &dev_attr_radio_reset_monitor.attr,
NULL,
};
@@ -1931,8 +2202,9 @@ static struct attribute *mtrv1_0_2_platform_attributes[] = {
&dev_attr_led_e_gpio.attr,
&dev_attr_led_f_gpio_mtr.attr,
- &dev_attr_radio_wm_lk_m.attr, // CAT M feature
-
+ &dev_attr_radio_wm_lk_m.attr, // CAT M feature
+ &dev_attr_radio_udev_discovery.attr,
+ &dev_attr_radio_reset_monitor.attr,
NULL,
};
@@ -1990,11 +2262,92 @@ static struct attribute *mtrv1_0_3_platform_attributes[] = {
&dev_attr_led_e_gpio.attr,
&dev_attr_led_f_gpio_mtr.attr,
- &dev_attr_radio_wm_lk_m.attr, // CAT M feature? Is this still there on the MTQ with Quectel?
-
+ &dev_attr_radio_wm_lk_m.attr, // CAT M feature? Is this still there on the MTQ with Quectel?
+ &dev_attr_radio_udev_discovery.attr,
+ &dev_attr_radio_reset_monitor.attr,
NULL,
};
static struct attribute_group mtrv1_0_3_platform_attribute_group = {
.attrs = mtrv1_0_3_platform_attributes
};
+
+static struct attribute *mtrv1_0_4_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_has_radio.attr,
+ &dev_attr_wifi_mac_mtr.attr,
+ &dev_attr_bluetooth_mac_mtr.attr,
+
+ &dev_attr_reset.attr,
+ &dev_attr_reset_monitor.attr,
+ &dev_attr_reset_monitor_intervals.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_reset_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_gnss_int_mtr.attr,
+ &dev_attr_radio_status_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,
+
+ &dev_attr_radio_wm_lk_m.attr, // CAT M feature? Is this still there on the MTQ with Quectel?
+ &dev_attr_radio_udev_discovery.attr,
+ &dev_attr_radio_reset_monitor.attr,
+ NULL,
+};
+
+static struct attribute_group mtrv1_0_4_platform_attribute_group = {
+ .attrs = mtrv1_0_4_platform_attributes
+};
+
+// L4G1 is active low, but other modules are active-high.
+int
+mtr_setup_radio_status(const char *product_id)
+{
+ struct gpio_pin *pin;
+ int l4g1;
+
+ l4g1 = (strstr(product_id,"L4G1") != NULL);
+ if (l4g1) {
+ pin = gpio_pin_by_attr_name("radio-status");
+ if (pin == NULL) {
+ printk(KERN_ERR "mts-io mtr_setup_radio_status() cannot find radio-status gpio");
+ return -ENODEV;
+ }
+ pin->active_low = 1;
+ return 0;
+ }
+ return 0;
+}
+
diff --git a/io-module/mts-io.c b/io-module/mts-io.c
index e4290a6..ed0cb49 100644
--- a/io-module/mts-io.c
+++ b/io-module/mts-io.c
@@ -49,6 +49,7 @@
#include "mts_io.h"
#include "buttons.h"
#include "mts_supercap.h"
+#include "radio_udev_discovery.h"
#define PLATFORM_NAME "mts-io"
@@ -257,6 +258,7 @@ static ssize_t mts_attr_store_radio_reset(struct device *dev,
radio_reset_timer_is_start = 1;
}
+ reset_radio_udev_discovery();
log_info("radio is reset\n");
pin = gpio_pin_by_attr_name("radio-reset");
@@ -509,6 +511,13 @@ static DEVICE_ATTR_MTS(dev_attr_radio_reset_backoff_index, "radio-reset-backoff-
static DEVICE_ATTR_RO_MTS(dev_attr_radio_reset_backoff_seconds, "radio-reset-backoff-seconds",
mts_attr_show_radio_reset_backoff_seconds);
+static DEVICE_ATTR_MTS(dev_attr_radio_udev_discovery, "radio-udev-discovery",
+ mts_attr_show_radio_udev_discovery, mts_attr_store_radio_udev_discovery);
+
+static DEVICE_ATTR_MTS(dev_attr_radio_reset_monitor, "radio-reset-monitor",
+ mts_attr_show_radio_reset_monitor, mts_attr_store_radio_reset_monitor);
+
+
/* shared gpio-based LEDs */
static DEVICE_ATTR_MTS(dev_attr_led_status, "led-status",
mts_attr_show_gpio_pin, mts_attr_store_gpio_pin);
@@ -878,6 +887,13 @@ mts_id_eeprom_load(void)
set_buttons(default_buttons);
mts_hw_version = MTRV1_0_3;
log_info("detected board %s", HW_VERSION_MTRV1_0_3);
+ } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTRV1_0_4, strlen(HW_VERSION_MTRV1_0_4)) == 0) {
+ attr_group = &mtrv1_0_4_platform_attribute_group;
+ gpio_pins = gpio_pins_mtrv1_0_4;
+ set_buttons(default_buttons);
+ mts_hw_version = MTRV1_0_4;
+ mtr_setup_radio_status(id_eeprom.product_id);
+ log_info("detected board %s", HW_VERSION_MTRV1_0_4);
} else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTHS_0_0, strlen(HW_VERSION_MTHS_0_0)) == 0) {
attr_group = &mths_0_0_platform_attribute_group;
gpio_pins = gpio_pins_mths_0_0;
@@ -1307,41 +1323,41 @@ static int __init mts_io_init(void)
static void __exit mts_io_exit(void)
{
- if (DEVICE_CAPA(id_eeprom.capa, CAPA_DOUT)) {
- spi_unregister_driver(&mts_spi_dout_driver);
- }
- if (DEVICE_CAPA(id_eeprom.capa, CAPA_DIN)) {
- spi_unregister_driver(&mts_spi_din_driver);
- }
- spi_unregister_driver(&mts_spi_board_temp_driver);
+ struct gpio_pin *pin;
+ if (DEVICE_CAPA(id_eeprom.capa, CAPA_DOUT)) {
+ spi_unregister_driver(&mts_spi_dout_driver);
+ }
+ if (DEVICE_CAPA(id_eeprom.capa, CAPA_DIN)) {
+ spi_unregister_driver(&mts_spi_din_driver);
+ }
+ spi_unregister_driver(&mts_spi_board_temp_driver);
- struct gpio_pin *pin;
- /* delete radio_reset_timer */
- del_timer(&radio_reset_timer);
- /* delete radio_reset_available_timer */
- del_timer(&radio_reset_available_timer);
+ /* delete radio_reset_timer */
+ del_timer(&radio_reset_timer);
+ /* delete radio_reset_available_timer */
+ del_timer(&radio_reset_available_timer);
- for (pin = gpio_pins; *pin->name; pin++)
- if (pin->capability == 0 || DEVICE_CAPA(id_eeprom.capa,pin->capability))
- gpio_free(pin->pin.gpio);
+ for (pin = gpio_pins; *pin->name; pin++)
+ if (pin->capability == 0 || DEVICE_CAPA(id_eeprom.capa,pin->capability))
+ gpio_free(pin->pin.gpio);
- cleanup_buttons();
+ cleanup_buttons();
- //cleanup supercap monitor worker if SUPERCAP CAPA is true
- if(DEVICE_CAPA(id_eeprom.capa, CAPA_SUPERCAP)) {
- cleanup_supercap_worker();
- }
+ //cleanup supercap monitor worker if SUPERCAP CAPA is true
+ if(DEVICE_CAPA(id_eeprom.capa, CAPA_SUPERCAP)) {
+ cleanup_supercap_worker();
+ }
- cleanup();
+ cleanup();
- if (mts_leds) {
- mts_leds_unregister();
- }
+ if (mts_leds) {
+ mts_leds_unregister();
+ }
- if (DEVICE_CAPA(id_eeprom.capa, CAPA_LORA) && attr_group_lora) {
- mts_teardown_lora_port();
- }
- log_info("exiting");
+ if (DEVICE_CAPA(id_eeprom.capa, CAPA_LORA) && attr_group_lora) {
+ mts_teardown_lora_port();
+ }
+ log_info("exiting");
}
module_init(mts_io_init);
diff --git a/io-module/mts_io_module.h b/io-module/mts_io_module.h
index 5655f29..3219753 100644
--- a/io-module/mts_io_module.h
+++ b/io-module/mts_io_module.h
@@ -5,7 +5,7 @@
* MTAC cards.
*/
-#define DRIVER_VERSION "v4.6.0"
+#define DRIVER_VERSION "v4.7.0"
#define DRIVER_AUTHOR "Multitech Systems"
#define DRIVER_DESC "MTS-IO Controller"
#define DRIVER_NAME "mts-io"
@@ -32,6 +32,7 @@
#define HW_VERSION_MTRV1_0_1 "MTRV1-0.1"
#define HW_VERSION_MTRV1_0_2 "MTRV1-0.2" // Cat M
#define HW_VERSION_MTRV1_0_3 "MTRV1-0.3" // MTR-MTQ
+#define HW_VERSION_MTRV1_0_4 "MTRV1-0.4" // MTR No USB hub
#define HW_VERSION_MTRE "MTRE-0.0"
#define HW_VERSION_MTCDT_0_0 "MTCDT-0.0" // No GPS or WiFi Capability
#define HW_VERSION_MTCDT_0_1 "MTCDT-0.1" // Conduit refresh with GPS and WiFi possible
@@ -65,6 +66,7 @@ enum {
MTRV1_0_1,
MTRV1_0_2,
MTRV1_0_3,
+ MTRV1_0_4,
MTRE_0_0,
MTCDT_0_0,
MTCDT_0_1,
diff --git a/io-module/radio_udev_discovery.c b/io-module/radio_udev_discovery.c
new file mode 100644
index 0000000..eb6c1aa
--- /dev/null
+++ b/io-module/radio_udev_discovery.c
@@ -0,0 +1,308 @@
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/platform_device.h>
+#include "mts_io_module.h"
+#include "radio_udev_discovery.h"
+
+/*
+ * radio-reset in the mts-io driver sets radio_udev_discovery to 0.
+ * Then it returns early if radio_udev_discovery is set to 1. The
+ * UDEV daemon is used to set radio_udev_discovery. Notifications
+ * are sent if radio_udev_discovery goes from 0 to 1.
+ */
+
+int radio_udev_discovery = 1;
+
+
+struct sig_pid_radio_reset_monitor_s {
+ pid_t pid;
+ int signal;
+ struct pid *vpid;
+};
+
+#define PID_MAX_COUNT 20
+static struct sig_pid_radio_reset_monitor_s sig_pid_radio_reset_monitor[PID_MAX_COUNT];
+
+
+/* Clear an entry in the table that no longer exists.
+ * unlocks the mts_io_lock, toggles the rcu_read_lock,
+ * then puts back the mts_io_lock.
+ */
+static int
+verify_vpid(struct sig_pid_radio_reset_monitor_s *p)
+{
+ pid_t pid0 = p->pid;
+ struct pid *vpid1;
+ struct pid *vpid0 = p->vpid;
+ unsigned int vcount;
+
+ // Check to see if vpid and pid still match
+ if (p->pid == 0)
+ return 0;
+ if (vpid0 == NULL) {
+ p->pid = 0;
+ return 0;
+ }
+
+ mutex_unlock(&mts_io_mutex);
+ rcu_read_lock();
+ vpid1 = find_vpid((pid_t)pid0);
+ if(vpid1 != NULL)
+ vcount = atomic_read(&vpid1->count);
+ else
+ vcount = 0;
+ rcu_read_unlock();
+ mutex_lock(&mts_io_mutex);
+ if ((vpid1 != vpid0) || (vpid1 == NULL))
+ p->pid = 0;
+ pr_debug("%s: verify_vpid: vpid0 0x%x vpid1 0x%x vcount %d for pid %d\n",
+ __FUNCTION__,
+ (unsigned int)vpid0, (unsigned int)vpid1, vcount, (int)pid0);
+ return p->pid;
+}
+
+// Need to find existing entries and allow updates. Signal 0 removes a value.
+ssize_t mts_attr_store_radio_reset_monitor(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+{
+ long pid0;
+ int sig;
+ int i;
+ int found;
+ struct pid *vpid1, *vpid0;
+ int retval;
+
+ retval = sscanf(buf, "%ld %d", &pid0, &sig);
+ if (retval != 2)
+ return -EINVAL;
+
+ if (pid0 < 0)
+ return -EINVAL;
+
+ rcu_read_lock();
+ vpid0 = find_vpid((pid_t)pid0);
+ rcu_read_unlock();
+ pr_debug("%s: Try to store %ld %d 0x%x\n",
+ __FUNCTION__,
+ pid0,sig,(unsigned int)vpid0);
+ if (vpid0) {
+ /* Note that since we no longer hold the rcu lock, vpid
+ * could become invalid, unless it is ours.
+ */
+ mutex_lock(&mts_io_mutex);
+ /* First see if we are already in the table -- search whole table */
+ found = -1;
+ for (i=0; i < PID_MAX_COUNT; i++) {
+ if ((sig_pid_radio_reset_monitor[i].pid == (pid_t)pid0) &&
+ (sig_pid_radio_reset_monitor[i].vpid == vpid0)) {
+ if (sig == 0) {
+ sig_pid_radio_reset_monitor[i].pid = 0;
+ sig_pid_radio_reset_monitor[i].vpid = NULL;
+ } else {
+ sig_pid_radio_reset_monitor[i].signal = sig;
+ mutex_unlock(&mts_io_mutex);
+ rcu_read_lock();
+ vpid0 = find_vpid((pid_t)pid0);
+ rcu_read_unlock();
+ pr_debug("%s: slot %d: pid %d, vpid 0x%x/vpid 0x%x\n",
+ __FUNCTION__,
+ i,pid0,vpid0,sig_pid_radio_reset_monitor[i].vpid);
+ mutex_lock(&mts_io_mutex);
+ if (vpid0 != sig_pid_radio_reset_monitor[i].vpid) {
+ sig_pid_radio_reset_monitor[i].pid = 0; /* Maybe exited? */
+ sig_pid_radio_reset_monitor[i].vpid = NULL;
+ pr_debug("%s: mts-io: vpid mismatch pid %d, vpid 0x%x/0x%x, sig %d, cleared %d\n",
+ __FUNCTION__,
+ (int)sig_pid_radio_reset_monitor[i].pid,
+ (unsigned int)sig_pid_radio_reset_monitor[i].vpid,(unsigned int)vpid0,
+ (unsigned int)sig_pid_radio_reset_monitor[i].signal,i);
+ } else {
+ found = i;
+ pr_debug("%s: mts-io: found pid %d, vpid 0x%x, sig %d\n",
+ __FUNCTION__,
+ (int)sig_pid_radio_reset_monitor[i].pid,
+ (unsigned int)sig_pid_radio_reset_monitor[i].vpid,
+ (unsigned int)sig_pid_radio_reset_monitor[i].signal);
+ sig = 0; // Clear any more that we find.
+ }
+
+ }
+ } // Location matches our pid
+ } // Loop through table
+
+ pr_debug("%s: found=%d, sig=%d\n",__FUNCTION__,sig);
+ if (found > -1) {
+ mutex_unlock(&mts_io_mutex);
+ return count;
+ }
+
+ if (sig == 0) {
+ // Nothing to clear out.
+ mutex_unlock(&mts_io_mutex);
+ return count;
+ }
+
+ /* Need to find an unused slot and save our signal and PID.
+ * Still holding mutex_lock(&mts_io_mutex)
+ * Find first open slot
+ */
+ found = -1;
+ for (i=0; i < PID_MAX_COUNT; i++) {
+ if (sig_pid_radio_reset_monitor[i].pid == 0) {
+ sig_pid_radio_reset_monitor[i].pid = (pid_t)pid0;
+ sig_pid_radio_reset_monitor[i].signal = sig;
+ sig_pid_radio_reset_monitor[i].vpid = vpid0;
+ pr_debug("%s: mts-io: open slot: pid %d, vpid 0x%x, sig %d, slot %d\n",
+ __FUNCTION__,
+ (int)pid0,
+ (unsigned int)vpid0,
+ (unsigned int)sig, i);
+ found = i;
+ break;
+ } else {
+ // See if this slot may be used.
+ pid_t pid1 = sig_pid_radio_reset_monitor[i].pid;
+ if (pid1 > 0) {
+ mutex_unlock(&mts_io_mutex);
+ rcu_read_lock();
+ vpid1 = find_vpid((pid_t)pid1);
+ rcu_read_unlock();
+ mutex_lock(&mts_io_mutex);
+ // See if pid and vpid still exists
+ if (!vpid1 || (vpid1 != sig_pid_radio_reset_monitor[i].vpid)) {
+ // Make sure no one else has claimed this slot
+ if (pid1 == sig_pid_radio_reset_monitor[i].pid) {
+ sig_pid_radio_reset_monitor[i].pid = 0;
+ sig_pid_radio_reset_monitor[i].vpid = NULL;
+ i--; // Should be able to use this slot.
+ continue;
+ } // Has not been re-claimed.
+ } // Slot has no user or exited user
+ } // Verify that slot in use is still in use
+ } // Found an empty slot
+ } // Loop through all the slots.
+ mutex_unlock(&mts_io_mutex);
+ } // pid is in pid table
+ return count;
+}
+
+// Examples say buf is PAGE_SIZE long
+ssize_t mts_attr_show_radio_reset_monitor(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ int count;
+ int max = PAGE_SIZE;
+ int ret;
+ int i;
+ pid_t pid1;
+
+ mutex_lock(&mts_io_mutex);
+
+ count = 0;
+ for (i=0; i < PID_MAX_COUNT; i++) {
+ pid1 = verify_vpid(sig_pid_radio_reset_monitor + i);
+ if (pid1 == 0) {
+ sig_pid_radio_reset_monitor[i].pid = 0;
+ sig_pid_radio_reset_monitor[i].vpid = NULL;
+ continue;
+ }
+ pr_debug("%s: found a pid in slot %d\n",__FUNCTION__,i);
+ ret = snprintf(buf+count, max, "%lu %d\n",
+ (unsigned long)pid1,
+ sig_pid_radio_reset_monitor[i].signal);
+ if (ret > 0) {
+ max -= ret;
+ count += ret;
+ }
+ if (max == 0)
+ break;
+ if(ret == 0)
+ break;
+ } // Loop through all the slots until we are full.
+
+ mutex_unlock(&mts_io_mutex);
+
+ return count;
+}
+
+
+/*
+ * After a radio reset, prime the flag, so if it is set to one
+ * after this, then we wake the processes waiting on the flag.
+ * Caller holds the mts_io_mutex lock.
+ */
+void
+reset_radio_udev_discovery(void)
+{
+ radio_udev_discovery = 0;
+}
+
+int
+udev_discovered_radio(void)
+{
+ return radio_udev_discovery;
+}
+
+ssize_t mts_attr_show_radio_udev_discovery(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ return sprintf(buf, "%d\n", radio_udev_discovery);
+}
+
+
+ssize_t mts_attr_store_radio_udev_discovery(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ int value = -1;
+ pid_t pid1;
+ struct pid *vpid0, *vpid1;
+ int sig, i;
+ int retval;
+
+ retval = sscanf(buf, "%i", &value);
+ if (retval != 1)
+ return -EINVAL;
+
+ if (radio_udev_discovery == -1) {
+ // Not ready
+ return -EPROTO;
+ }
+
+ // Only driver can set this to zero.
+ if (value == 0)
+ return -EINVAL;
+
+ mutex_lock(&mts_io_mutex);
+ if((value == 1) && (radio_udev_discovery == 0)) {
+ radio_udev_discovery = 1;
+ pr_debug("%s: mts-io: UDEV discovered cellular modem after radio-reset so signal registered processes",
+ __FUNCTION__);
+ // kill all processes that are queued
+ for (i=0; i < PID_MAX_COUNT; i++) {
+ pid1 = verify_vpid(sig_pid_radio_reset_monitor + i);
+ if (pid1 == 0) continue;
+ sig = sig_pid_radio_reset_monitor[i].signal;
+ vpid0 = sig_pid_radio_reset_monitor[i].vpid;
+ mutex_unlock(&mts_io_mutex);
+ rcu_read_lock();
+ vpid1 = find_vpid(pid1);
+ if (vpid1 == vpid0) {
+ printk(KERN_ALERT
+ "mts-io: %s: Sending signal %d to pid %d due to UDEV radio discovery\n",
+ __FUNCTION__,
+ sig,pid1);
+ kill_pid(vpid1,sig,1);
+ } // vpid is valid, same as registered
+ else {
+ printk(KERN_ALERT
+ "mts-io: %s: mismatched vpid %x/%x\n", __FUNCTION__, (unsigned int)vpid1, (unsigned int) vpid0);
+ }
+
+ rcu_read_unlock();
+ mutex_lock(&mts_io_mutex);
+ } // Find empty slot
+ } // udev wants us to wake everybody up after reset
+ mutex_unlock(&mts_io_mutex);
+ return count;
+}
diff --git a/io-module/radio_udev_discovery.h b/io-module/radio_udev_discovery.h
new file mode 100644
index 0000000..d735dc1
--- /dev/null
+++ b/io-module/radio_udev_discovery.h
@@ -0,0 +1,24 @@
+#ifndef IO_MODULE_RADIO_UDEV_DISCOVERY_H_
+#define IO_MODULE_RADIO_UDEV_DISCOVERY_H_
+
+
+void reset_radio_udev_discovery(void);
+
+int udev_discovered_radio(void);
+
+ssize_t mts_attr_show_radio_udev_discovery(struct device *dev,
+ struct device_attribute *attr,
+ char *buf);
+
+ssize_t mts_attr_store_radio_udev_discovery(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count);
+
+ssize_t mts_attr_show_radio_reset_monitor(struct device *dev,
+ struct device_attribute *attr, char *buf);
+
+ssize_t mts_attr_store_radio_reset_monitor(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count);
+
+#endif /* IO_MODULE_RADIO_UDEV_DISCOVERY_H_ */
+