From aa3be1b385cc26566745207d7862fa9067dcdf3c Mon Sep 17 00:00:00 2001 From: John Klug Date: Tue, 25 Feb 2020 13:06:26 -0600 Subject: Support mtcpm CPU board --- configure.ac | 2 +- io-module/adc.c | 126 --- io-module/machine/mtcap.c | 536 ++++++++++++ io-module/machine/mtcdt.c | 481 +++++++++++ io-module/machine/mtcpm.c | 297 +++++++ io-module/machine/mths.c | 883 ++++++++++++++++++++ io-module/machine/mtr.c | 2001 +++++++++++++++++++++++++++++++++++++++++++++ io-module/mt100eocg.c | 252 ------ io-module/mtcap.c | 536 ------------ io-module/mtcdt.c | 477 ----------- io-module/mths.c | 879 -------------------- io-module/mtr.c | 1994 -------------------------------------------- io-module/mts-io.c | 142 ++-- io-module/mts_capab.c | 35 +- io-module/mts_io.h | 1 + io-module/mts_io_module.h | 11 +- io-module/spi.c | 597 -------------- 17 files changed, 4307 insertions(+), 4943 deletions(-) delete mode 100644 io-module/adc.c create mode 100644 io-module/machine/mtcap.c create mode 100644 io-module/machine/mtcdt.c create mode 100644 io-module/machine/mtcpm.c create mode 100644 io-module/machine/mths.c create mode 100644 io-module/machine/mtr.c delete mode 100644 io-module/mt100eocg.c delete mode 100644 io-module/mtcap.c delete mode 100644 io-module/mtcdt.c delete mode 100644 io-module/mths.c delete mode 100644 io-module/mtr.c delete mode 100644 io-module/spi.c diff --git a/configure.ac b/configure.ac index 97499a3..e584de0 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([mts-io], [4.1.4]) +AC_INIT([mts-io], [4.3.0]) AC_CONFIG_SRCDIR([util/mts_util_lora2_reset.c]) AM_INIT_AUTOMAKE AM_CONFIG_HEADER([config.h]) diff --git a/io-module/adc.c b/io-module/adc.c deleted file mode 100644 index 3d5f3d0..0000000 --- a/io-module/adc.c +++ /dev/null @@ -1,126 +0,0 @@ -#define AT91SAM9X5_BASE_ADC 0xf804c000 -#define AT91SAM9260_BASE_ADC 0xfffe0000 - -#define ADC_SHTIME_DEFAULT 0x05 -#define ADC_STARTUP_DEFAULT 0x04 -#define ADC_PRESCALE_DEFAULT 0x3F -#define ADC_MODE_DEFAULT \ - ((ADC_SHTIME_DEFAULT & 0x0F) << 24) | \ - ((ADC_STARTUP_DEFAULT & 0x1F) << 16) | \ - ((ADC_PRESCALE_DEFAULT & 0x3F) << 8) - -#define ADC_CR_OFFSET 0x00 -#define ADC_MR_OFFSET 0x04 -#define ADC_CHER_OFFSET 0x10 -#define ADC_CHDR_OFFSET 0x14 -#define ADC_CHSR_OFFSET 0x18 -#define ADC_SR_OFFSET 0x1C -#define ADC_LDCR_OFFSET 0x20 -#define ADC_IER_OFFSET 0x14 -#define ADC_IDR_OFFSET 0x28 -#define ADC_IMR_OFFSET 0x2C -#define ADC_CDR0_OFFSET 0x30 -#define ADC_CDR1_OFFSET 0x34 -#define ADC_CDR2_OFFSET 0x38 -#define ADC_CDR3_OFFSET 0x3C - -void __iomem *adc_base; -struct clk *adc_clk; - -#define ADC_CONVERT_RESET(base) writel(0x01, (base) + ADC_CR_OFFSET) -#define ADC_CONVERT_START(base) writel(0x02, (base) + ADC_CR_OFFSET) - -static ssize_t mts_attr_show_adc(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int offset; - u32 value; - u32 chan_mask; - - if (!DEVICE_CAPA(id_eeprom.capa, CAPA_ADC)) { - log_debug("ADC not available"); - return -ENODEV; - } - - if (!strcmp(attr->attr.name, "adc0")) { - offset = ADC_CDR0_OFFSET; - chan_mask = 0x01; - } else if (!strcmp(attr->attr.name, "adc1")) { - offset = ADC_CDR1_OFFSET; - chan_mask = 0x02; - } else if (!strcmp(attr->attr.name, "adc2")) { - offset = ADC_CDR2_OFFSET; - chan_mask = 0x04; - } else if (!strcmp(attr->attr.name, "adc3")) { - offset = ADC_CDR3_OFFSET; - chan_mask = 0x08; - } else { - log_notice("adc attr does not exist"); - return -ENOENT; - } - - mutex_lock(&mts_io_mutex); - - // disable all channels and enable the one we want - writel(0x0F, adc_base + ADC_CHDR_OFFSET); - writel(chan_mask, adc_base + ADC_CHER_OFFSET); - - ADC_CONVERT_START(adc_base); - - // wait for conversion to complete (EOC bit set) - value = 0; - while (value != chan_mask) { - value = readl(adc_base + ADC_SR_OFFSET) & chan_mask; - log_debug("ADC_SR EOC [%X]", value); - } - - // read result - value = readl(adc_base + offset); - - mutex_unlock(&mts_io_mutex); - - return sprintf(buf, "%lu\n", (unsigned long) value); -} - -static DEVICE_ATTR_RO_MTS(dev_attr_adc0, "adc0", mts_attr_show_adc); -static DEVICE_ATTR_RO_MTS(dev_attr_adc1, "adc1", mts_attr_show_adc); -static DEVICE_ATTR_RO_MTS(dev_attr_adc2, "adc2", mts_attr_show_adc); -static DEVICE_ATTR_RO_MTS(dev_attr_adc3, "adc3", mts_attr_show_adc); - -static int mts_io_board_adc_probe(struct platform_device *pdev) -{ - int err; - adc_clk = clk_get(&pdev->dev, "adc_clk"); - if (adc_clk) { - err = clk_prepare_enable(adc_clk); - if (err) { - log_error("clock failed to prepare+enable: %d\n", err); - return err; - } - #ifdef CONFIG_SOC_AT91SAM9X5 - adc_base = ioremap(AT91SAM9X5_BASE_ADC, SZ_16K); - #else - adc_base = ioremap(AT91SAM9260_BASE_ADC, SZ_16K); - #endif - if (!adc_base) { - log_error("ioremap failed.\n"); - return -ENOMEM; - } - ADC_CONVERT_RESET(adc_base); - writel(ADC_MODE_DEFAULT, adc_base + ADC_MR_OFFSET); - writel(0x000F0F0F, adc_base + ADC_IDR_OFFSET); - writel(0x0F, adc_base + ADC_CHDR_OFFSET); - } - return 0; -} - -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 new file mode 100644 index 0000000..bd08d5a --- /dev/null +++ b/io-module/machine/mtcap.c @@ -0,0 +1,536 @@ +#include "at91gpio.h" +/* Used for both MTCAP 0.0 and 0.1 */ +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", + }, + .capability = CAPA_LORA, + .active_low = 1, + }, + { // gpio 1 for LORA 1.5 ref design + .name = "LORA_CDONE", + .pin = { + .gpio = AT91_PIN_PA6, + .flags = GPIOF_IN, + .label = "lora/cdone", + }, + .capability = CAPA_LORA, + }, + { // gpio 2 for LORA 1.5 ref design + .name = "LORA_CRESET", + .pin = { + .gpio = AT91_PIN_PA29, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "lora/creset", + }, + .capability = CAPA_LORA, + }, + + + /* 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, + }, + { + .name = "WLAN_EN", + .pin = { + .gpio = AT91_PIN_PA4, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "wlan-en", + }, + }, + { + .name = "WLAN_RST", + .pin = { + .gpio = AT91_PIN_PA3, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "wlan-rst", + }, + }, + { }, +}; + +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(int radio_model) +{ + // 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"); + unsigned int hold_time; + 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. + hold_time = 2500; + if (radio_model == RADIO_LNA3 || radio_model == RADIO_LEU3) { + + // To turn OFF the LE910 V2 the pad ON_OFF* must be tied low for at least 3 seconds and then released. + // ref: Telit_LE910_V2_Hardware_User_Guide_r7.pdf + hold_time = 3500; + } + + reset_gpio_pin(onoff_pin, hold_time, 0); + msleep(200); // Give time for pin to change state before inspection. + + 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(int radio_model) +{ + // 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"); + unsigned int hold_time; + 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"); + + // for LEU1 (ref: Telit_LE910_Hardware_User_Guide_r6.pdf) + hold_time = 1500; + if (radio_model == RADIO_LNA3 || radio_model == RADIO_LEU3) { + + // To turn on the LE910 V2 the pad ON_OFF* must be tied low for at least 5 seconds and then released. + // ref: Telit_LE910_V2_Hardware_User_Guide_r7.pdf + // ref:Telit_LE910_V2_Hardware_User_Guide_r9.pdf + // pg 32: When USB is connected or after firmware updating, + // delay must be equal at least to 10 seconds. + hold_time = 10500; + } + + // drive on/off pin high for at least 1 seconoff_pin + gpio_set_value(onoff_pin->pin.gpio, 1); + msleep(1000); + + // ON_OFF must be tied low and then released + reset_gpio_pin(onoff_pin, hold_time, 0); + msleep(200); // Make sure modem has had time to move the status pin + // 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(int radio_model) +{ + // 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"); + unsigned int hold_time; + + 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 for reset"); + + // for LEU1 (ref: Telit_LE910_Hardware_User_Guide_r6.pdf) + hold_time = 1500; + if (radio_model == RADIO_LNA3 || radio_model == RADIO_LEU3) { + // To turn on the LE910 V2 the pad ON_OFF* must be tied low for at least 5 seconds and then released. + // ref: Telit_LE910_V2_Hardware_User_Guide_r7.pdf + // ref:Telit_LE910_V2_Hardware_User_Guide_r9.pdf + // pg 32: When USB is connected or after firmware updating, + // delay must be equal at least to 10 seconds. + // + // Note that a hold time of 5.5 seconds on MTCAP + // with Verizon Firmware 20.00.12 will cause a + // radio-reset to power the LE910-NA1 off until + // a reload of the mts-io driver, or a reboot. + hold_time = 10500; + } + + // 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 + log_info("turning off cell radio for reset"); + reset_gpio_pin(onoff_pin, hold_time, 0); + log_info("Reset is complete. Wait for power monitor pin"); + msleep(200); // Make sure modem has had time to move the status pin + 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; + int radio_model = get_radio_model_from_product_id(); + + if (sscanf(buf, "%i", &value) != 1) { + return -EINVAL; + } + + mutex_lock(&mts_io_mutex); + if (value == 0) { + err = radio_off_mtcap(radio_model); + } else { + err = radio_on_mtcap(radio_model); + } + 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; /* 0 = normal reset; -1 = forced reset */ + int err; + int radio_model = get_radio_model_from_product_id(); + + if (sscanf(buf, "%i", &value) != 1) { + return -EINVAL; + } + + if (value != 0 && value != -1) { + return -EINVAL; + } + + /* check reset timings is enabled */ + if (value != -1 && 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(radio_model); + + 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 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_eth_reset_mtcap, "eth-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +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_MTS(dev_attr_wlan_en_gpio_mtcap, "wlan-en", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_wlan_rst_gpio_mtcap, "wlan-rst", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +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_has_radio.attr, + &dev_attr_reset.attr, + &dev_attr_reset_monitor.attr, + &dev_attr_reset_monitor_intervals.attr, + + &dev_attr_eth_reset_mtcap.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_wlan_en_gpio_mtcap.attr, + &dev_attr_wlan_rst_gpio_mtcap.attr, + + /* Set to NULL if no radio -- should be 1st radio attribute */ + &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, + + NULL, +}; + +static int +is_radio_power_attr_mtcap(struct attribute *attr) +{ + return (attr == &dev_attr_radio_power_mtcap.attr); +} + +static struct attribute_group mtcap_0_0_platform_attribute_group = { + .attrs = mtcap_0_0_platform_attributes +}; + + +// +// on-board LORA attributes are to be stored in the lora/ sub-directory +// +// +static DEVICE_ATTR_MTS(dev_attr_lora_reset_mtcap, "reset", + mts_attr_show_lora_gpio_pin, mts_attr_store_lora_gpio_pin); + +static DEVICE_ATTR_RO_MTS(dev_attr_lora_cdone_mtcap, "cdone", + mts_attr_show_lora_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_lora_creset_mtcap, "creset", + mts_attr_show_lora_gpio_pin, mts_attr_store_lora_gpio_pin); + +static DEVICE_ATTR_RO_MTS(dev_attr_lora_eui_mtcap, "eui", + mts_attr_show_lora_product_info); + +static DEVICE_ATTR_RO_MTS(dev_attr_lora_product_id_mtcap, "product-id", + mts_attr_show_lora_product_info); + +static DEVICE_ATTR_RO_MTS(dev_attr_lora_hw_version_mtcap, "hw-version", + mts_attr_show_lora_product_info); + +static struct attribute *mtcap_0_0_lora_attributes[] = { + &dev_attr_lora_eui_mtcap.attr, + &dev_attr_lora_product_id_mtcap.attr, + &dev_attr_lora_hw_version_mtcap.attr, + &dev_attr_lora_reset_mtcap.attr, + &dev_attr_lora_cdone_mtcap.attr, + &dev_attr_lora_creset_mtcap.attr, + NULL, +}; + +static struct attribute_group mtcap_0_0_lora_attribute_group = { + .attrs = mtcap_0_0_lora_attributes +}; + +// Reset for LoRa firmware is done using the I2C bus +// on the MTCDTIPHP LoRa board. +static struct attribute *mtcdtiphp_0_0_lora_attributes[] = { + &dev_attr_lora_eui_mtcap.attr, + &dev_attr_lora_product_id_mtcap.attr, + &dev_attr_lora_hw_version_mtcap.attr, + NULL, +}; + +static struct attribute_group mtcdtiphp_0_0_lora_attribute_group = { + .attrs = mtcdtiphp_0_0_lora_attributes +}; diff --git a/io-module/machine/mtcdt.c b/io-module/machine/mtcdt.c new file mode 100644 index 0000000..575dd1e --- /dev/null +++ b/io-module/machine/mtcdt.c @@ -0,0 +1,481 @@ +#include "at91gpio.h" +/* + * Within a struct gpio_pin, there is only one + * occurrence of each pin, so there is only one + * pin label set for each gpio pin. + */ +static struct gpio_pin gpio_pins_mtcdt_0_0[] = { + { + .name = "RADIO_RESET", + .pin = { + .gpio = AT91_PIN_PC3, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "radio-reset", + }, + }, + { + .name = "RADIO_RESET", + .pin = { + .gpio = AT91_PIN_PC3, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "radio-power", + }, + }, + { + .name = "DEVICE_RESET", + .pin = { + .gpio = AT91_PIN_PC2, + .flags = GPIOF_IN, + .label = "reset", + }, + .active_low = 1, + }, + { + .name = "ETH_RESET", + .pin = { + .gpio = AT91_PIN_PC4, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "eth-reset", + } + }, + { + .name = "LS_LED", /* LED7 */ + .pin = { + .gpio = AT91_PIN_PA14, +#if LED_LS_CONTROLLABLE + .flags = GPIOF_OUT_INIT_HIGH, +#else + .flags = GPIOF_IN, +#endif + .label = "led-ls", + }, + .active_low = 1, + }, + { + .name = "STATUS_LED", /* LED2 */ + .pin = { + .gpio = AT91_PIN_PA24, + .flags = GPIOF_OUT_INIT_LOW, + .label = "led-status", + }, + .active_low = 1, + }, + { + .name = "LED5", + .pin = { + .gpio = AT91_PIN_PA25, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-cd", + }, + .active_low = 1, + }, + { + .name = "LED5", + .pin = { + .gpio = AT91_PIN_PA25, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-a", + }, + .active_low = 1, + }, + { + .name = "LED1", + .pin = { + .gpio = AT91_PIN_PA26, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig1", + }, + .active_low = 1, + }, + { + .name = "LED1", + .pin = { + .gpio = AT91_PIN_PA26, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-b", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PA27, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig2", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PA27, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-c", + }, + .active_low = 1, + }, + { + .name = "LED3", + .pin = { + .gpio = AT91_PIN_PA28, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig3", + }, + .active_low = 1, + }, + { + .name = "LED3", + .pin = { + .gpio = AT91_PIN_PA28, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-d", + }, + .active_low = 1, + }, +}; + +static struct gpio_pin gpio_pins_mtcdt_0_1[] = { + { + .name = "RADIO_RESET", + .pin = { + .gpio = AT91_PIN_PC3, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "radio-reset", + }, + }, + { + .name = "RADIO_RESET", + .pin = { + .gpio = AT91_PIN_PC3, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "radio-power", + }, + }, + { + .name = "DEVICE_RESET", + .pin = { + .gpio = AT91_PIN_PC2, + .flags = GPIOF_IN, + .label = "reset", + }, + .active_low = 1, + }, + { + .name = "LS_LED", /* LED7 */ + .pin = { + .gpio = AT91_PIN_PA14, +#if LED_LS_CONTROLLABLE + .flags = GPIOF_OUT_INIT_HIGH, +#else + .flags = GPIOF_IN, +#endif + .label = "led-ls", + }, + .active_low = 1, + }, + { + .name = "STATUS_LED", /* LED2 */ + .pin = { + .gpio = AT91_PIN_PA24, + .flags = GPIOF_OUT_INIT_LOW, + .label = "led-status", + }, + .active_low = 1, + }, + { + .name = "LED5", + .pin = { + .gpio = AT91_PIN_PA25, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-cd", + }, + .active_low = 1, + }, + { + .name = "LED5", + .pin = { + .gpio = AT91_PIN_PA25, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-a", + }, + .active_low = 1, + }, + { + .name = "LED1", + .pin = { + .gpio = AT91_PIN_PA26, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig1", + }, + .active_low = 1, + }, + { + .name = "LED1", + .pin = { + .gpio = AT91_PIN_PA26, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-b", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PA27, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig2", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PA27, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-c", + }, + .active_low = 1, + }, + { + .name = "LED3", + .pin = { + .gpio = AT91_PIN_PA28, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig3", + }, + .active_low = 1, + }, + { + .name = "LED3", + .pin = { + .gpio = AT91_PIN_PA28, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-d", + }, + .active_low = 1, + }, + { + .name = "ETH_RESET", + .pin = { + .gpio = AT91_PIN_PC4, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "eth-reset", + } + }, + { + .name = "WIFI_BT_ULPWKUP", + .pin = { + .gpio = AT91_PIN_PA0, + .flags = GPIOF_IN, + .label = "wifi-bt-ulpwkup", + }, + .capability = CAPA_WIFI, + }, + { + .name = "WIFI_BT_LPWKUP", + .pin = { + .gpio = AT91_PIN_PA6, + .flags = GPIOF_IN, + .label = "wifi-bt-lpwkup", + }, + .capability = CAPA_WIFI, + }, + { + .name = "WIFI_BT_INT", + .pin = { + .gpio = AT91_PIN_PB11, + .flags = GPIOF_IN, + .label = "wifi-bt-int", + }, + .capability = CAPA_WIFI, + }, + { + .name = "WIFI_BT_RESET", + .pin = { + .gpio = AT91_PIN_PD14, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "wifi-bt-reset", + }, + .capability = CAPA_WIFI, + }, + { + .name = "GNSS_RESET", + .pin = { + .gpio = AT91_PIN_PD15, + .flags = GPIOF_OUT_INIT_LOW, /* Keep GPS quiet during boot for EXAR */ + .label = "gnss-reset", + }, + .capability = CAPA_GPS, + }, + { + .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 = "mtq-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", + }, + .capability = CAPA_GPS, + }, + { + .name = "WIFI_BT_LPMODE", + .pin = { + .gpio = AT91_PIN_PD20, + .flags = GPIOF_IN, + .label = "wifi-bt-lpmode", + }, + .capability = CAPA_WIFI, + }, + { }, +}; + +static DEVICE_ATTR_MTS(dev_attr_wifi_bt_lpwkup, "wifi-bt-lpwkup", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_wifi_bt_ulpwkup, "wifi-bt-ulpwkup", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_wifi_bt_reset, "wifi-bt-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_RO_MTS(dev_attr_wifi_bt_lpmode, "wifi-bt-lpmode", + mts_attr_show_gpio_pin); +static DEVICE_ATTR_RO_MTS(dev_attr_wifi_bt_int, "wifi-bt-int", + mts_attr_show_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_gnss_reset, "gnss-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_usbhub_reset, "usbhub-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_eth_reset, "eth-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_gnss_int, "gnss-int", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_RO_MTS(dev_attr_wifi_mac, "mac-wifi", + mts_attr_show_product_info); +static DEVICE_ATTR_RO_MTS(dev_attr_bluetooth_mac, "mac-bluetooth", + mts_attr_show_product_info); + +static struct attribute *mtcdt_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_reset.attr, + &dev_attr_reset_monitor.attr, + &dev_attr_reset_monitor_intervals.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_a_gpio.attr, + &dev_attr_led_b_gpio.attr, + &dev_attr_led_c_gpio.attr, + &dev_attr_led_d_gpio.attr, + &dev_attr_eth_reset.attr, + + &dev_attr_radio_power.attr, + &dev_attr_radio_reset.attr, + + &dev_attr_radio_reset_backoffs.attr, + &dev_attr_radio_reset_backoff_index.attr, + &dev_attr_radio_reset_backoff_seconds.attr, + NULL, +}; + +static struct attribute *mtcdt_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_has_radio.attr, + &dev_attr_reset.attr, + &dev_attr_reset_monitor.attr, + &dev_attr_reset_monitor_intervals.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_a_gpio.attr, + &dev_attr_led_b_gpio.attr, + &dev_attr_led_c_gpio.attr, + &dev_attr_led_d_gpio.attr, + + &dev_attr_usbhub_reset.attr, + &dev_attr_eth_reset.attr, + + // radio feature is last to be able to + // easily remove radio. + // is_radio_power_attr_mtcdt() searches + // for this for truncation. + &dev_attr_radio_power.attr, /* Must be first radio attribute */ + &dev_attr_radio_reset.attr, + + &dev_attr_radio_reset_backoffs.attr, + &dev_attr_radio_reset_backoff_index.attr, + &dev_attr_radio_reset_backoff_seconds.attr, + + NULL, +}; + +static struct attribute *mtcdt_0_1_wifi_bt_attributes[] = { + &dev_attr_wifi_bt_lpwkup.attr, + &dev_attr_wifi_bt_ulpwkup.attr, + &dev_attr_wifi_bt_reset.attr, + &dev_attr_wifi_bt_lpmode.attr, + &dev_attr_wifi_bt_int.attr, + &dev_attr_bluetooth_mac.attr, + &dev_attr_wifi_mac.attr, +}; + +static struct attribute *mtcdt_0_1_gnss_attributes[] = { + &dev_attr_gnss_reset.attr, + &dev_attr_gnss_int.attr, +}; + + +static struct attribute_group mtcdt_platform_attribute_group = { + .attrs = mtcdt_platform_attributes +}; +static struct attribute_group mtcdt_0_1_platform_attribute_group = { + .attrs = mtcdt_0_1_platform_attributes +}; + + +static int +is_radio_power_attr_mtcdt(struct attribute *attr) +{ + return (attr == &dev_attr_radio_power.attr); +} diff --git a/io-module/machine/mtcpm.c b/io-module/machine/mtcpm.c new file mode 100644 index 0000000..8167218 --- /dev/null +++ b/io-module/machine/mtcpm.c @@ -0,0 +1,297 @@ +#include "mts_io.h" + +#define OMAP_GPIO(BANK, GPIO) ((BANK*32)+GPIO) +/* + * Within a struct gpio_pin, there is only one + * occurrence of each pin, so there is only one + * pin label set for each gpio pin. + */ +static struct gpio_pin gpio_pins_mtcpm[] = { + { + .name = "RADIO_RESET", + .pin = { + .gpio = OMAP_GPIO(5,9), /* 5_9 */ + .flags = GPIOF_OUT_INIT_HIGH, + .label = "radio-reset", + }, + }, +#if 0 + /* This goes through the PMIC for now */ + { + .name = "RADIO_POWER", + .pin = { + .gpio = 0, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "radio-power", + }, + }, +#endif + { + .name = "DEVICE_RESET", + .pin = { + .gpio = OMAP_GPIO(1,29), + .flags = GPIOF_IN, + .label = "reset", + }, + .active_low = 1, + }, + { + .name = "WIFI_BT_INT", + .pin = { + .gpio = OMAP_GPIO(4,12), /* 4_12 */ + .flags = GPIOF_IN, + .label = "wifi-bt-int", + }, + .capability = CAPA_BLUETOOTH, + }, + { + .name = "WIFI_RESET", + .pin = { + .gpio = OMAP_GPIO(4,11), /* 4_11 */ + .flags = GPIOF_OUT_INIT_HIGH, + .label = "wlan-enabled", + }, + .capability = CAPA_WIFI, + .active_low = 0, + }, + { + .name = "BT_RESET", + .pin = { + .gpio = OMAP_GPIO(4,10), /* 4_10 */ + .flags = GPIOF_OUT_INIT_HIGH, + .label = "bt-enabled", + }, + .capability = CAPA_BLUETOOTH, + .active_low = 0, + }, + { + .name = "USBHUB_RESET", + .pin = { + .gpio = OMAP_GPIO(3, 15), + .flags = GPIOF_OUT_INIT_HIGH, + .label = "usbhub-reset", + }, + .active_low = 0, + }, + { + .name = "ETH_RESET", + .pin = { + .gpio = OMAP_GPIO(4,7), /* 4_7 */ + .flags = GPIOF_OUT_INIT_HIGH, + .label = "eth-reset", + }, + .active_low = 0, + }, + { + .name = "GNSS_INT", + .pin = { + .gpio = OMAP_GPIO(5,12), /* 5_12 */ + .flags = GPIOF_OUT_INIT_HIGH, + .label = "gnss-int", + }, + .capability = CAPA_GPS, + }, + { + .name = "GNSS_RESET", + .pin = { + .gpio = OMAP_GPIO(5,10), /* 5_10 */ + .flags = GPIOF_OUT_INIT_HIGH, + .label = "gnss-reset", + }, + .capability = CAPA_GPS, + .active_low = 0, + }, +#if 0 + /* Link status comes directly from the MTQ out to the baseboard */ + { + .name = "LS_LED", + .pin = { + .gpio = 0, + .flags = GPIOF_IN, + .label = "led-ls", + }, + .active_low = 1, + }, +#endif + { + .name = "STATUS_LED", + .pin = { + .gpio = OMAP_GPIO(0, 20), + .flags = GPIOF_OUT_INIT_LOW, + .label = "led-status", + }, + }, + { + .name = "CD", + .pin = { + .gpio = OMAP_GPIO(0, 21), + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-cd", + }, + }, + { + .name = "LED1", + .pin = { + .gpio = OMAP_GPIO(4, 26), + .flags = GPIOF_OUT_INIT_LOW, + .label = "led-sig1", + }, + }, + { + .name = "LED2", + .pin = { + .gpio = OMAP_GPIO(4, 27), + .flags = GPIOF_OUT_INIT_LOW, + .label = "led-sig2", + }, + }, + { + .name = "LED3", + .pin = { + .gpio = OMAP_GPIO(4, 28), + .flags = GPIOF_OUT_INIT_LOW, + .label = "led-sig3", + }, + }, + { }, +}; + +static DEVICE_ATTR_MTS(dev_attr_wifi_reset_mtcpm, "wlan-enabled", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_bt_reset_mtcpm, "bt-enabled", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_RO_MTS(dev_attr_wifi_bt_int_mtcpm, "wifi-bt-int", + mts_attr_show_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_gnss_reset_mtcpm, "gnss-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_usbhub_reset_mtcpm, "usbhub-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_eth_reset_mtcpm, "eth-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_gnss_int_mtcpm, "gnss-int", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_lora_reset_mtcpm, "reset", + mts_attr_show_lora_gpio_pin, mts_attr_store_lora_gpio_pin); +static DEVICE_ATTR_RO_MTS(dev_attr_lora_cdone_mtcpm, "cdone", + mts_attr_show_lora_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_lora_creset_mtcpm, "creset", + mts_attr_show_lora_gpio_pin, mts_attr_store_lora_gpio_pin); +static DEVICE_ATTR_RO_MTS(dev_attr_lora_eui_mtcpm, "eui", + mts_attr_show_lora_product_info); +static DEVICE_ATTR_RO_MTS(dev_attr_lora_product_id_mtcpm, "product-id", + mts_attr_show_lora_product_info); +static DEVICE_ATTR_RO_MTS(dev_attr_lora_hw_version_mtcpm, "hw-version", + mts_attr_show_lora_product_info); +static DEVICE_ATTR_RO_MTS(dev_attr_wifi_mac_mtcpm, "mac-wifi", + mts_attr_show_product_info); +static DEVICE_ATTR_RO_MTS(dev_attr_bluetooth_mac_mtcpm, "mac-bluetooth", + mts_attr_show_product_info); + +static struct attribute *mtcpm_platform_attributes[] = { + &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_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_usbhub_reset.attr, + &dev_attr_eth_reset.attr, + + // radio feature is last to be able to + // easily remove radio. + // is_radio_power_attr_mtcdt() searches + // for this for truncation. + &dev_attr_radio_power.attr, /* Must be first radio attribute */ + &dev_attr_radio_reset.attr, + + &dev_attr_radio_reset_backoffs.attr, + &dev_attr_radio_reset_backoff_index.attr, + &dev_attr_radio_reset_backoff_seconds.attr, + + &dev_attr_wifi_reset_mtcpm.attr, + &dev_attr_bt_reset_mtcpm.attr, + &dev_attr_wifi_bt_int_mtcpm.attr, + + &dev_attr_gnss_reset_mtcpm.attr, + &dev_attr_gnss_int_mtcpm.attr, + &dev_attr_wifi_mac_mtcpm.attr, + &dev_attr_bluetooth_mac_mtcpm.attr, + NULL, +}; + + + +static struct attribute_group mtcpm_platform_attribute_group = { + .attrs = mtcpm_platform_attributes +}; + +static int +is_radio_power_attr_mtcpm(struct attribute *attr) +{ + return (attr == &dev_attr_radio_power.attr); +} + +static struct attribute *mtcpm_lora_attributes[] = { + &dev_attr_lora_eui_mtcpm.attr, + &dev_attr_lora_product_id_mtcpm.attr, + &dev_attr_lora_hw_version_mtcpm.attr, + &dev_attr_lora_reset_mtcpm.attr, + &dev_attr_lora_cdone_mtcpm.attr, + &dev_attr_lora_creset_mtcpm.attr, + NULL, +}; + +static struct attribute_group mtcpm_lora_attribute_group = { + .attrs = mtcpm_lora_attributes +}; + +static struct attribute *mtcpm_cpu_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, + NULL, +}; + + +static struct attribute_group mtcpm_cpu_attribute_group = { + .attrs = mtcpm_cpu_attributes +}; + +static struct kobject *mts_cpu_kobject = NULL; + +static int mts_cpu_dir_create(uint8_t hw_version) +{ + if (hw_version != MTCPM_0_0) + return 0; + + mts_cpu_kobject = kobject_create_and_add("cpu", &mts_io_platform_device->dev.kobj); + if (!mts_cpu_kobject) { + log_error("kobject_create_and_add for cpu directory failed"); + return -ENOMEM; + } + + if (sysfs_create_group(mts_cpu_kobject, &mtcpm_cpu_attribute_group)) { + log_error("sysfs_create_group failed to create cpu group"); + return -ENOMEM; + } + + return 0; +} + +static void mts_cpu_dir_delete(void) +{ + if (mts_cpu_kobject) { + kobject_put(mts_cpu_kobject); + mts_cpu_kobject = NULL; + } +} + diff --git a/io-module/machine/mths.c b/io-module/machine/mths.c new file mode 100644 index 0000000..c19598d --- /dev/null +++ b/io-module/machine/mths.c @@ -0,0 +1,883 @@ +/* + * mths.c + * + * Created on: Apr 26, 2018 + * Author: leonid + */ +#include "at91gpio.h" +#include "buttons.h" + +static struct gpio_pin gpio_pins_mths_0_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 = "WPS_BUTTON", + .pin = { + .gpio = AT91_PIN_PA13, + .flags = GPIOF_IN, + .label = "wps_button", + }, + .active_low = 1, + }, + { + .name = "BT_BUTTON", + .pin = { + //TODO return back .gpio = AT91_PIN_PC4, + .gpio = AT91_PIN_PA12, + .flags = GPIOF_IN, + .label = "bt_button", + }, + .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 = "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-bt", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-c", + }, + .active_low = 1, + }, + { + .name = "LED5", + .pin = { + .gpio = AT91_PIN_PC21, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-status", + }, + .active_low = 1, + }, + { + .name = "LED5", + .pin = { + .gpio = AT91_PIN_PC21, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-cd", + }, + .active_low = 1, + }, + { + .name = "LED6", + .pin = { + .gpio = AT91_PIN_PC19, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig3", + }, + .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-sig1", + }, + .active_low = 1, + }, + { + .name = "LED8", + .pin = { + .gpio = AT91_PIN_PC17, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-f", + }, + .active_low = 1, + }, + + // The difference between MTRv1_0_0 and MTRv1_0_1 starts here + { + .name = "WIFI_BT_ULPWKUP", + .pin = { + .gpio = AT91_PIN_PB9, + .flags = GPIOF_IN, + .label = "wifi-bt-ulpwkup", + } + }, + { + .name = "WIFI_BT_LPWKUP", + .pin = { + .gpio = AT91_PIN_PB11, + .flags = GPIOF_IN, + .label = "wifi-bt-lpwkup", + } + }, + { + .name = "WIFI_BT_INT", + .pin = { + .gpio = AT91_PIN_PB13, + .flags = GPIOF_IN, + .label = "wifi-bt-int", + } + }, + { + .name = "WIFI_BT_RESET", + .pin = { + .gpio = AT91_PIN_PB10, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "wifi-bt-reset", + } + }, + { + .name = "WIFI_BT_LPMODE", + .pin = { + .gpio = AT91_PIN_PB12, + .flags = GPIOF_IN, + .label = "wifi-bt-lpmode", + } + }, + { + .name = "GNSS_RESET", + .pin = { + .gpio = AT91_PIN_PC6, + .flags = GPIOF_OUT_INIT_LOW, + .label = "gnss-reset", + } + }, + { + .name = "USBHUB_RESET", + .pin = { + .gpio = AT91_PIN_PB6, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "usbhub-reset", + } + }, + { + .name = "GNSS_INT", + .pin = { + .gpio = AT91_PIN_PC7, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "gnss-int", + } + }, + + + { }, +}; + +/* MTHS-0.1 has no WIFI LED */ +static struct gpio_pin gpio_pins_mths_0_1[] = { + { + .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 = "WPS_BUTTON", + .pin = { + .gpio = AT91_PIN_PA13, + .flags = GPIOF_IN, + .label = "wps_button", + }, + .active_low = 1, + }, + { + .name = "BT_BUTTON", + .pin = { + //TODO return back .gpio = AT91_PIN_PC4, + .gpio = AT91_PIN_PA12, + .flags = GPIOF_IN, + .label = "bt_button", + }, + .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 = "LED4", + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-bt", + }, + .active_low = 1, + }, + { + .name = "LED4", + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-c", + }, + .active_low = 1, + }, + { + .name = "LED5", + .pin = { + .gpio = AT91_PIN_PC21, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-status", + }, + .active_low = 1, + }, + { + .name = "LED5", + .pin = { + .gpio = AT91_PIN_PC21, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-cd", + }, + .active_low = 1, + }, + { + .name = "LED6", + .pin = { + .gpio = AT91_PIN_PC19, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-sig3", + }, + .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-sig1", + }, + .active_low = 1, + }, + { + .name = "LED8", + .pin = { + .gpio = AT91_PIN_PC17, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "led-f", + }, + .active_low = 1, + }, + + // The difference between MTRv1_0_0 and MTRv1_0_1 starts here + { + .name = "WIFI_BT_ULPWKUP", + .pin = { + .gpio = AT91_PIN_PB9, + .flags = GPIOF_IN, + .label = "wifi-bt-ulpwkup", + } + }, + { + .name = "WIFI_BT_LPWKUP", + .pin = { + .gpio = AT91_PIN_PB11, + .flags = GPIOF_IN, + .label = "wifi-bt-lpwkup", + } + }, + { + .name = "WIFI_BT_INT", + .pin = { + .gpio = AT91_PIN_PB13, + .flags = GPIOF_IN, + .label = "wifi-bt-int", + } + }, + { + .name = "WIFI_BT_RESET", + .pin = { + .gpio = AT91_PIN_PB10, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "wifi-bt-reset", + } + }, + { + .name = "WIFI_BT_LPMODE", + .pin = { + .gpio = AT91_PIN_PB12, + .flags = GPIOF_IN, + .label = "wifi-bt-lpmode", + } + }, + { + .name = "GNSS_RESET", + .pin = { + .gpio = AT91_PIN_PC6, + .flags = GPIOF_OUT_INIT_LOW, + .label = "gnss-reset", + } + }, + { + .name = "USBHUB_RESET", + .pin = { + .gpio = AT91_PIN_PB6, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "usbhub-reset", + } + }, + { + .name = "GNSS_INT", + .pin = { + .gpio = AT91_PIN_PC7, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "gnss-int", + } + }, + + + { }, +}; + +button_info_t mths_wps_button = { + .name = "User Push Button WPS", + .label_pin = "wps_button", + .label_monitor = "wps_button-monitor", + .label_monitor_intervals = "wps_button-monitor-intervals", + + /* Signals */ + .short_signal = SIGUSR1, + .long_signal = SIGUSR2, + .short_signal = SIGHUP, + + /* Intervals */ + .short_interval = BUTTON_HOLD_COUNT, + .long_interval = BUTTON_LONG_HOLD_COUNT, +}; + +button_info_t mths_bt_button = { + .name = "User Push Button BT", + .label_pin = "bt_button", + .label_monitor = "bt_button-monitor", + .label_monitor_intervals = "bt_button-monitor-intervals", + + /* Signals */ + .short_signal = SIGUSR1, + .long_signal = SIGUSR2, + .short_signal = SIGHUP, + + /* Intervals */ + .short_interval = BUTTON_HOLD_COUNT, + .long_interval = BUTTON_LONG_HOLD_COUNT, +}; + +/* MTHS 0.0 and 0.1 have same buttons. */ +static button_info_pt mths_buttons_0_0[] = { + &reset_button, + &mths_wps_button, + &mths_bt_button, + NULL, +}; + +static DEVICE_ATTR_MTS(dev_attr_wps_button_monitor_intervals_mths, + mths_wps_button.label_monitor_intervals, + mts_attr_show_button_monitor_intervals, + mts_attr_store_button_monitor_intervals); + +static DEVICE_ATTR_MTS(dev_attr_wps_button_monitor_mths, + mths_wps_button.label_monitor, + mts_attr_show_button_monitor, + mts_attr_store_button_monitor); + +static DEVICE_ATTR_RO_MTS(dev_attr_wps_button_pin_mths, + mths_wps_button.label_pin, + mts_attr_show_gpio_pin); + + +static DEVICE_ATTR_MTS(dev_attr_bt_button_monitor_intervals_mths, + mths_bt_button.label_monitor_intervals, + mts_attr_show_button_monitor_intervals, + mts_attr_store_button_monitor_intervals); + +static DEVICE_ATTR_MTS(dev_attr_bt_button_monitor_mths, + mths_bt_button.label_monitor, + mts_attr_show_button_monitor, + mts_attr_store_button_monitor); + +static DEVICE_ATTR_RO_MTS(dev_attr_bt_button_pin_mths, + mths_bt_button.label_pin, + mts_attr_show_gpio_pin); + + +/* radio control (power/reset) for mtr */ +static int radio_off_mths(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_mths(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); + + // ref:Telit_LE910_V2_Hardware_User_Guide_r9.pdf + // pg 32: When USB is connected or after firmware updating, + // delay must be equal at least to 10 seconds. + msleep(10500); + + // set on/off pin high + gpio_set_value(onoff_pin->pin.gpio, 1); + log_info("radio_on_mths: radio should be coming up"); + + msleep(200); + + // check that power is high + value = gpio_get_value(pwrmon_pin->pin.gpio); + if(value == 0) { + log_warning("radio_on_mths: 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_mths(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 10.5 sec + gpio_set_value(onoff_pin->pin.gpio, 0); + + log_info("Wait 10.5 seconds for on/off pin"); + msleep(10500); + + log_info("Done with wait 10.5 seconds for on/off pin"); + // set on/off pin high + gpio_set_value(onoff_pin->pin.gpio, 1); + msleep(200); // Delay for status pin to switch + return 0; +} + +static ssize_t mts_attr_store_radio_power_mths(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_mths(); + mutex_unlock(&mts_io_mutex); + } else { + mutex_lock(&mts_io_mutex); + err = radio_on_mths(); + mutex_unlock(&mts_io_mutex); + } + + if (err) { + return err; + } + + return count; +} + +static ssize_t mts_attr_store_radio_reset_mths(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int value; /* 0 = normal reset; -1 = forced reset */ + int err; + + if (sscanf(buf, "%i", &value) != 1) { + return -EINVAL; + } + if (value != 0 && value != -1) { + return -EINVAL; + } + + /* check reset timings is enabled */ + if (value != -1 && 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_mths(); + + mutex_unlock(&mts_io_mutex); + + if (err) { + return err; + } + + return count; +} + +static ssize_t mts_attr_show_radio_power_mths(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_mths, "radio-power", + mts_attr_show_radio_power_mths, mts_attr_store_radio_power_mths); + +static DEVICE_ATTR_MTS(dev_attr_radio_reset_mths, "radio-reset", + mts_attr_show_gpio_pin, mts_attr_store_radio_reset_mths); + + +static DEVICE_ATTR_MTS(dev_attr_led_wifi_gpio_mths, "led-wifi", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_led_bt_gpio_mths, "led-bt", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_led_f_gpio_mths, "led-f", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_RO_MTS(dev_attr_wifi_mac_mths, "mac-wifi", + mts_attr_show_product_info); + +static DEVICE_ATTR_RO_MTS(dev_attr_bluetooth_mac_mths, "mac-bluetooth", + mts_attr_show_product_info); + +static DEVICE_ATTR_MTS(dev_attr_wifi_bt_lpwkup_mths, "wifi-bt-lpwkup", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_wifi_bt_ulpwkup_mths, "wifi-bt-ulpwkup", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_wifi_bt_reset_mths, "wifi-bt-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_RO_MTS(dev_attr_wifi_bt_lpmode_mths, "wifi-bt-lpmode", + mts_attr_show_gpio_pin); + +static DEVICE_ATTR_RO_MTS(dev_attr_wifi_bt_int_mths, "wifi-bt-int", + mts_attr_show_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_gnss_reset_mths, "gnss-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_MTS(dev_attr_usbhub_reset_mths, "usbhub-reset", + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); + +static DEVICE_ATTR_RO_MTS(dev_attr_gnss_int_mths, "gnss-int", + mts_attr_show_gpio_pin); + + + +static struct attribute *mths_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_wifi_mac_mths.attr, + &dev_attr_bluetooth_mac_mths.attr, + &dev_attr_has_radio.attr, + + &dev_attr_reset.attr, + &dev_attr_reset_monitor.attr, + &dev_attr_reset_monitor_intervals.attr, + &dev_attr_wps_button_pin_mths.attr, + &dev_attr_wps_button_monitor_mths.attr, + &dev_attr_wps_button_monitor_intervals_mths.attr, + &dev_attr_bt_button_pin_mths.attr, + &dev_attr_bt_button_monitor_mths.attr, + &dev_attr_bt_button_monitor_intervals_mths.attr, + + &dev_attr_radio_power_mths.attr, + &dev_attr_radio_reset_mths.attr, + + &dev_attr_radio_reset_backoffs.attr, + &dev_attr_radio_reset_backoff_index.attr, + &dev_attr_radio_reset_backoff_seconds.attr, + + &dev_attr_wifi_bt_lpwkup_mths.attr, + &dev_attr_wifi_bt_ulpwkup_mths.attr, + &dev_attr_wifi_bt_reset_mths.attr, + &dev_attr_wifi_bt_lpmode_mths.attr, + &dev_attr_wifi_bt_int_mths.attr, + &dev_attr_gnss_reset_mths.attr, + &dev_attr_usbhub_reset_mths.attr, + &dev_attr_gnss_int_mths.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_mths.attr, + &dev_attr_led_bt_gpio_mths.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_mths.attr, + + NULL, +}; + +static struct attribute_group mths_0_0_platform_attribute_group = { + .attrs = mths_0_0_platform_attributes +}; diff --git a/io-module/machine/mtr.c b/io-module/machine/mtr.c new file mode 100644 index 0000000..8664984 --- /dev/null +++ b/io-module/machine/mtr.c @@ -0,0 +1,2001 @@ +#include "at91gpio.h" +static struct gpio_pin gpio_pins_mtr_0_0[] = { + { + .name = "ETH_RESET", + .pin = { + .gpio = AT91_PIN_PC6, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "eth-reset", + }, + .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_RESET", + .pin = { + .gpio = AT91_PIN_PC6, + .flags = GPIOF_OUT_INIT_HIGH, + .label = "eth-reset", + }, + .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, + .label = "radio-reset", + }, + .active_low = 0, + }, + { + .name = "RADIO_POWER", + .pin = { + .gpio = AT91_PIN_PA21, + .flags = GPIOF_OUT_INIT_HIGH, + .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_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 = "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, + .label = "radio-reset", + }, + .active_low = 0, + }, + { + .name = "RADIO_POWER", + .pin = { + .gpio = AT91_PIN_PA21, + .flags = GPIOF_OUT_INIT_HIGH, + .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_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 = "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, + .label = "radio-reset", + }, + .active_low = 0, + }, + { + .name = "RADIO_POWER", + .pin = { + .gpio = AT91_PIN_PA21, + .flags = GPIOF_OUT_INIT_HIGH, + .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_LOW, + .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", + } + }, + + + { }, +}; + +static struct gpio_pin gpio_pins_mtrv1_0_2[] = { + { + .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 = "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, + .label = "radio-reset", + }, + .active_low = 0, + }, + { + .name = "RADIO_POWER", + .pin = { + .gpio = AT91_PIN_PA21, + .flags = GPIOF_OUT_INIT_HIGH, + .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_LOW, + .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", + } + }, + // 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", + } + }, + + { }, +}; + +static struct gpio_pin gpio_pins_mtrv1_0_3[] = { + { + .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, + }, + { + .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_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 = "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", + } + }, + // 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 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 int radio_reset_mtr_mtq(void) +{ + struct gpio_pin *rst_pin = gpio_pin_by_attr_name("radio-reset"); + + if (!rst_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); + + 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; /* 0 = normal reset; -1 = forced reset */ + int err; + + if (sscanf(buf, "%i", &value) != 1) { + return -EINVAL; + } + if (value != 0 && value != -1) { + return -EINVAL; + } + + /* check reset timings is enabled */ + if (value != -1 && 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); + + if (mts_hw_version == MTRV1_0_3) + { + err = radio_reset_mtr_mtq(); + } + else + { + 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_reset_mtr, "eth-reset", + 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_RO_MTS(dev_attr_bluetooth_mac_mtr, "mac-bluetooth", + 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 DEVICE_ATTR_RO_MTS(dev_attr_radio_wm_lk_m, "radio-wm-lk-m", + 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_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_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_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, + + /* Radio stuff moved to end for possible removal */ + &dev_attr_radio_power_mtr.attr, /* radio_power must be first */ + &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, + + 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_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_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_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_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 +}; + +static struct attribute *mtrv1_0_2_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_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_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_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, + + &dev_attr_radio_wm_lk_m.attr, // CAT M feature + + NULL, +}; + +static struct attribute_group mtrv1_0_2_platform_attribute_group = { + .attrs = mtrv1_0_2_platform_attributes +}; + + +static struct attribute *mtrv1_0_3_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_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, + + &dev_attr_radio_wm_lk_m.attr, // CAT M feature? Is this still there on the MTQ with Quectel? + + NULL, +}; + +static struct attribute_group mtrv1_0_3_platform_attribute_group = { + .attrs = mtrv1_0_3_platform_attributes +}; diff --git a/io-module/mt100eocg.c b/io-module/mt100eocg.c deleted file mode 100644 index 749b85a..0000000 --- a/io-module/mt100eocg.c +++ /dev/null @@ -1,252 +0,0 @@ -#include "at91gpio.h" -/* Used for both MT100EOCG 0.0 */ -static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { - { - .name = "ADC0", - .pin = { - .label = "adc0", - .gpio = AT91_PIN_PC0, - .flags = GPIOF_IN, - }, - }, - { - .name = "ADC1", - .pin = { - .label = "adc1", - .gpio = AT91_PIN_PC1, - .flags = GPIOF_IN, - }, - }, - { - .name = "ADC2", - .pin = { - .label = "adc2", - .gpio = AT91_PIN_PC2, - .flags = GPIOF_IN, - }, - }, - { - .name = "ADC3", - .pin = { - .label = "adc3", - .gpio = AT91_PIN_PC3, - .flags = GPIOF_IN, - }, - }, - { - .name = "DTR1", - .pin = { - .label = "extserial-dtr", - .gpio = AT91_PIN_PB18, - .flags = GPIOF_IN, - }, - .active_low = 1, - }, - { - .name = "DCD1", - .pin = { - .label = "extserial-dcd", - .gpio = AT91_PIN_PB3, - .flags = GPIOF_OUT_INIT_HIGH, - }, - .active_low = 1, - }, - { - .name = "ETH0_ENABLED", - .pin = { - .label = "eth0-enabled", - .gpio = AT91_PIN_PB31, - .flags = GPIOF_OUT_INIT_HIGH, - }, - }, - { - .name = "ENIO", - .pin = { - .label = "enio", - .gpio = AT91_PIN_PC15, - .flags = GPIOF_OUT_INIT_LOW, - }, - }, - { - .name = "DEVICE_RESET", - .pin = { - .label = "reset", - .gpio = AT91_PIN_PA22, - .flags = GPIOF_IN, - }, - .active_low = 1, - }, - { - .name = "RSERSRC", - .pin = { - .label = "rsersrc", - .gpio = AT91_PIN_PC7, - .flags = GPIOF_OUT_INIT_HIGH, - }, - .active_low = 1, - }, - { - .name = "RADIO_RESET", - .pin = { - .label = "radio-reset", - .gpio = AT91_PIN_PB30, - .flags = GPIOF_OUT_INIT_HIGH, - }, - }, - { - .name = "GPIO11", - .pin = { - .label = "gpio11", - .gpio = AT91_PIN_PB19, - .flags = GPIOF_OPEN_DRAIN | GPIOF_INIT_HIGH, - }, - }, - { - .name = "GPIO12", - .pin = { - .label = "gpio12", - .gpio = AT91_PIN_PB20, - .flags = GPIOF_OPEN_DRAIN | GPIOF_INIT_HIGH, - }, - }, - { - .name = "LED2", - .pin = { - .label = "led2", - .gpio = AT91_PIN_PA30, - .flags = GPIOF_OUT_INIT_HIGH, - }, - .active_low = 1, - }, - { - .name = "LED3", - .pin = { - .label = "led3", - .gpio = AT91_PIN_PC9, -#if LED_LS_CONTROLLABLE - .flags = GPIOF_OUT_INIT_HIGH, -#else - .flags = GPIOF_IN, -#endif - }, - .active_low = 1, - }, - /* - { - .name = "TXD1", - .pin = { - .gpio = AT91_PIN_PB17, - .flags = GPIOF_IN, - }, - },*/ - { }, -}; - -/* mt100eocg specific attributes */ -static DEVICE_ATTR_RO_MTS(dev_attr_extserial_dtr, "extserial-dtr", - mts_attr_show_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_extserial_dcd_gpio, "extserial-dcd", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_eth0_enabled, "eth0-enabled", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_enio, "enio", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_gpo1, "gpo1", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_gpo2, "gpo2", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_gpo3, "gpo3", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_gpo4, "gpo4", - mts_attr_show_dout, mts_attr_store_dout); - - -static DEVICE_ATTR_MTS(dev_attr_led1, "led1", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_led2, "led2", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -#if LED_LS_CONTROLLABLE -static DEVICE_ATTR_MTS(dev_attr_led3, "led3", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); -#else -static DEVICE_ATTR_RO_MTS(dev_attr_led3, "led3", mts_attr_show_gpio_pin); -#endif - -static DEVICE_ATTR_MTS(dev_attr_led4, "led4", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_led5, "led5", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_led6, "led6", - mts_attr_show_dout, mts_attr_store_dout); - -static DEVICE_ATTR_MTS(dev_attr_gpio11, "gpio11", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); -static DEVICE_ATTR_MTS(dev_attr_gpio12, "gpio12", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_rsersrc, "rsersrc", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static struct attribute *mt100eocg_platform_attributes[] = { - &dev_attr_vendor_id.attr, - &dev_attr_product_id.attr, - &dev_attr_device_id.attr, - &dev_attr_hw_version.attr, - &dev_attr_imei.attr, - &dev_attr_eth_mac.attr, - &dev_attr_has_radio.attr, - &dev_attr_reset.attr, - &dev_attr_reset_monitor.attr, - &dev_attr_reset_monitor_intervals.attr, - &dev_attr_extserial_dtr.attr, - &dev_attr_extserial_dcd_gpio.attr, - &dev_attr_rsersrc.attr, // AT91_PIN_PC7 - &dev_attr_radio_reset.attr, // AT91_PIN_PB30 - &dev_attr_eth0_enabled.attr, - &dev_attr_gpio11.attr, // AT91_PIN_PB19 - &dev_attr_gpio12.attr, // AT91_PIN_PB20 - &dev_attr_enio.attr, -// SPI - &dev_attr_gpo1.attr, - &dev_attr_gpo2.attr, - &dev_attr_gpo3.attr, - &dev_attr_gpo4.attr, -// -// SPI - &dev_attr_led1.attr, -// - &dev_attr_led2.attr, // AT91_PIN_PA30 - &dev_attr_led3.attr, // AT91_PIN_PC9 -// SPI - &dev_attr_led4.attr, - &dev_attr_led5.attr, - &dev_attr_led6.attr, -// -// SPI - &dev_attr_gpi5.attr, - &dev_attr_gpi6.attr, - &dev_attr_gpi7.attr, - &dev_attr_gpi8.attr, - &dev_attr_gpi9.attr, - &dev_attr_gpi10.attr, -// -// SPI - &dev_attr_board_temperature.attr, -// -// adc - &dev_attr_adc0.attr, - &dev_attr_adc1.attr, - &dev_attr_adc2.attr, - &dev_attr_adc3.attr, - - NULL, -}; - -static struct attribute_group mt100eocg_platform_attribute_group = { - .attrs = mt100eocg_platform_attributes -}; diff --git a/io-module/mtcap.c b/io-module/mtcap.c deleted file mode 100644 index bd08d5a..0000000 --- a/io-module/mtcap.c +++ /dev/null @@ -1,536 +0,0 @@ -#include "at91gpio.h" -/* Used for both MTCAP 0.0 and 0.1 */ -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", - }, - .capability = CAPA_LORA, - .active_low = 1, - }, - { // gpio 1 for LORA 1.5 ref design - .name = "LORA_CDONE", - .pin = { - .gpio = AT91_PIN_PA6, - .flags = GPIOF_IN, - .label = "lora/cdone", - }, - .capability = CAPA_LORA, - }, - { // gpio 2 for LORA 1.5 ref design - .name = "LORA_CRESET", - .pin = { - .gpio = AT91_PIN_PA29, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "lora/creset", - }, - .capability = CAPA_LORA, - }, - - - /* 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, - }, - { - .name = "WLAN_EN", - .pin = { - .gpio = AT91_PIN_PA4, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "wlan-en", - }, - }, - { - .name = "WLAN_RST", - .pin = { - .gpio = AT91_PIN_PA3, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "wlan-rst", - }, - }, - { }, -}; - -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(int radio_model) -{ - // 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"); - unsigned int hold_time; - 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. - hold_time = 2500; - if (radio_model == RADIO_LNA3 || radio_model == RADIO_LEU3) { - - // To turn OFF the LE910 V2 the pad ON_OFF* must be tied low for at least 3 seconds and then released. - // ref: Telit_LE910_V2_Hardware_User_Guide_r7.pdf - hold_time = 3500; - } - - reset_gpio_pin(onoff_pin, hold_time, 0); - msleep(200); // Give time for pin to change state before inspection. - - 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(int radio_model) -{ - // 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"); - unsigned int hold_time; - 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"); - - // for LEU1 (ref: Telit_LE910_Hardware_User_Guide_r6.pdf) - hold_time = 1500; - if (radio_model == RADIO_LNA3 || radio_model == RADIO_LEU3) { - - // To turn on the LE910 V2 the pad ON_OFF* must be tied low for at least 5 seconds and then released. - // ref: Telit_LE910_V2_Hardware_User_Guide_r7.pdf - // ref:Telit_LE910_V2_Hardware_User_Guide_r9.pdf - // pg 32: When USB is connected or after firmware updating, - // delay must be equal at least to 10 seconds. - hold_time = 10500; - } - - // drive on/off pin high for at least 1 seconoff_pin - gpio_set_value(onoff_pin->pin.gpio, 1); - msleep(1000); - - // ON_OFF must be tied low and then released - reset_gpio_pin(onoff_pin, hold_time, 0); - msleep(200); // Make sure modem has had time to move the status pin - // 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(int radio_model) -{ - // 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"); - unsigned int hold_time; - - 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 for reset"); - - // for LEU1 (ref: Telit_LE910_Hardware_User_Guide_r6.pdf) - hold_time = 1500; - if (radio_model == RADIO_LNA3 || radio_model == RADIO_LEU3) { - // To turn on the LE910 V2 the pad ON_OFF* must be tied low for at least 5 seconds and then released. - // ref: Telit_LE910_V2_Hardware_User_Guide_r7.pdf - // ref:Telit_LE910_V2_Hardware_User_Guide_r9.pdf - // pg 32: When USB is connected or after firmware updating, - // delay must be equal at least to 10 seconds. - // - // Note that a hold time of 5.5 seconds on MTCAP - // with Verizon Firmware 20.00.12 will cause a - // radio-reset to power the LE910-NA1 off until - // a reload of the mts-io driver, or a reboot. - hold_time = 10500; - } - - // 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 - log_info("turning off cell radio for reset"); - reset_gpio_pin(onoff_pin, hold_time, 0); - log_info("Reset is complete. Wait for power monitor pin"); - msleep(200); // Make sure modem has had time to move the status pin - 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; - int radio_model = get_radio_model_from_product_id(); - - if (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; - } - - mutex_lock(&mts_io_mutex); - if (value == 0) { - err = radio_off_mtcap(radio_model); - } else { - err = radio_on_mtcap(radio_model); - } - 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; /* 0 = normal reset; -1 = forced reset */ - int err; - int radio_model = get_radio_model_from_product_id(); - - if (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; - } - - if (value != 0 && value != -1) { - return -EINVAL; - } - - /* check reset timings is enabled */ - if (value != -1 && 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(radio_model); - - 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 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_eth_reset_mtcap, "eth-reset", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -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_MTS(dev_attr_wlan_en_gpio_mtcap, "wlan-en", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_wlan_rst_gpio_mtcap, "wlan-rst", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -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_has_radio.attr, - &dev_attr_reset.attr, - &dev_attr_reset_monitor.attr, - &dev_attr_reset_monitor_intervals.attr, - - &dev_attr_eth_reset_mtcap.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_wlan_en_gpio_mtcap.attr, - &dev_attr_wlan_rst_gpio_mtcap.attr, - - /* Set to NULL if no radio -- should be 1st radio attribute */ - &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, - - NULL, -}; - -static int -is_radio_power_attr_mtcap(struct attribute *attr) -{ - return (attr == &dev_attr_radio_power_mtcap.attr); -} - -static struct attribute_group mtcap_0_0_platform_attribute_group = { - .attrs = mtcap_0_0_platform_attributes -}; - - -// -// on-board LORA attributes are to be stored in the lora/ sub-directory -// -// -static DEVICE_ATTR_MTS(dev_attr_lora_reset_mtcap, "reset", - mts_attr_show_lora_gpio_pin, mts_attr_store_lora_gpio_pin); - -static DEVICE_ATTR_RO_MTS(dev_attr_lora_cdone_mtcap, "cdone", - mts_attr_show_lora_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_lora_creset_mtcap, "creset", - mts_attr_show_lora_gpio_pin, mts_attr_store_lora_gpio_pin); - -static DEVICE_ATTR_RO_MTS(dev_attr_lora_eui_mtcap, "eui", - mts_attr_show_lora_product_info); - -static DEVICE_ATTR_RO_MTS(dev_attr_lora_product_id_mtcap, "product-id", - mts_attr_show_lora_product_info); - -static DEVICE_ATTR_RO_MTS(dev_attr_lora_hw_version_mtcap, "hw-version", - mts_attr_show_lora_product_info); - -static struct attribute *mtcap_0_0_lora_attributes[] = { - &dev_attr_lora_eui_mtcap.attr, - &dev_attr_lora_product_id_mtcap.attr, - &dev_attr_lora_hw_version_mtcap.attr, - &dev_attr_lora_reset_mtcap.attr, - &dev_attr_lora_cdone_mtcap.attr, - &dev_attr_lora_creset_mtcap.attr, - NULL, -}; - -static struct attribute_group mtcap_0_0_lora_attribute_group = { - .attrs = mtcap_0_0_lora_attributes -}; - -// Reset for LoRa firmware is done using the I2C bus -// on the MTCDTIPHP LoRa board. -static struct attribute *mtcdtiphp_0_0_lora_attributes[] = { - &dev_attr_lora_eui_mtcap.attr, - &dev_attr_lora_product_id_mtcap.attr, - &dev_attr_lora_hw_version_mtcap.attr, - NULL, -}; - -static struct attribute_group mtcdtiphp_0_0_lora_attribute_group = { - .attrs = mtcdtiphp_0_0_lora_attributes -}; diff --git a/io-module/mtcdt.c b/io-module/mtcdt.c deleted file mode 100644 index 69f87f7..0000000 --- a/io-module/mtcdt.c +++ /dev/null @@ -1,477 +0,0 @@ -#include "at91gpio.h" -/* - * Within a struct gpio_pin, there is only one - * occurrence of each pin, so there is only one - * pin label set for each gpio pin. - */ -static struct gpio_pin gpio_pins_mtcdt_0_0[] = { - { - .name = "RADIO_RESET", - .pin = { - .gpio = AT91_PIN_PC3, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "radio-reset", - }, - }, - { - .name = "RADIO_RESET", - .pin = { - .gpio = AT91_PIN_PC3, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "radio-power", - }, - }, - { - .name = "DEVICE_RESET", - .pin = { - .gpio = AT91_PIN_PC2, - .flags = GPIOF_IN, - .label = "reset", - }, - .active_low = 1, - }, - { - .name = "ETH_RESET", - .pin = { - .gpio = AT91_PIN_PC4, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "eth-reset", - } - }, - { - .name = "LS_LED", /* LED7 */ - .pin = { - .gpio = AT91_PIN_PA14, -#if LED_LS_CONTROLLABLE - .flags = GPIOF_OUT_INIT_HIGH, -#else - .flags = GPIOF_IN, -#endif - .label = "led-ls", - }, - .active_low = 1, - }, - { - .name = "STATUS_LED", /* LED2 */ - .pin = { - .gpio = AT91_PIN_PA24, - .flags = GPIOF_OUT_INIT_LOW, - .label = "led-status", - }, - .active_low = 1, - }, - { - .name = "LED5", - .pin = { - .gpio = AT91_PIN_PA25, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-cd", - }, - .active_low = 1, - }, - { - .name = "LED5", - .pin = { - .gpio = AT91_PIN_PA25, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-a", - }, - .active_low = 1, - }, - { - .name = "LED1", - .pin = { - .gpio = AT91_PIN_PA26, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-sig1", - }, - .active_low = 1, - }, - { - .name = "LED1", - .pin = { - .gpio = AT91_PIN_PA26, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-b", - }, - .active_low = 1, - }, - { - .name = "LED4", - .pin = { - .gpio = AT91_PIN_PA27, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-sig2", - }, - .active_low = 1, - }, - { - .name = "LED4", - .pin = { - .gpio = AT91_PIN_PA27, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-c", - }, - .active_low = 1, - }, - { - .name = "LED3", - .pin = { - .gpio = AT91_PIN_PA28, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-sig3", - }, - .active_low = 1, - }, - { - .name = "LED3", - .pin = { - .gpio = AT91_PIN_PA28, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-d", - }, - .active_low = 1, - }, -}; - -static struct gpio_pin gpio_pins_mtcdt_0_1[] = { - { - .name = "RADIO_RESET", - .pin = { - .gpio = AT91_PIN_PC3, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "radio-reset", - }, - }, - { - .name = "RADIO_RESET", - .pin = { - .gpio = AT91_PIN_PC3, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "radio-power", - }, - }, - { - .name = "DEVICE_RESET", - .pin = { - .gpio = AT91_PIN_PC2, - .flags = GPIOF_IN, - .label = "reset", - }, - .active_low = 1, - }, - { - .name = "LS_LED", /* LED7 */ - .pin = { - .gpio = AT91_PIN_PA14, -#if LED_LS_CONTROLLABLE - .flags = GPIOF_OUT_INIT_HIGH, -#else - .flags = GPIOF_IN, -#endif - .label = "led-ls", - }, - .active_low = 1, - }, - { - .name = "STATUS_LED", /* LED2 */ - .pin = { - .gpio = AT91_PIN_PA24, - .flags = GPIOF_OUT_INIT_LOW, - .label = "led-status", - }, - .active_low = 1, - }, - { - .name = "LED5", - .pin = { - .gpio = AT91_PIN_PA25, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-cd", - }, - .active_low = 1, - }, - { - .name = "LED5", - .pin = { - .gpio = AT91_PIN_PA25, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-a", - }, - .active_low = 1, - }, - { - .name = "LED1", - .pin = { - .gpio = AT91_PIN_PA26, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-sig1", - }, - .active_low = 1, - }, - { - .name = "LED1", - .pin = { - .gpio = AT91_PIN_PA26, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-b", - }, - .active_low = 1, - }, - { - .name = "LED4", - .pin = { - .gpio = AT91_PIN_PA27, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-sig2", - }, - .active_low = 1, - }, - { - .name = "LED4", - .pin = { - .gpio = AT91_PIN_PA27, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-c", - }, - .active_low = 1, - }, - { - .name = "LED3", - .pin = { - .gpio = AT91_PIN_PA28, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-sig3", - }, - .active_low = 1, - }, - { - .name = "LED3", - .pin = { - .gpio = AT91_PIN_PA28, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-d", - }, - .active_low = 1, - }, - { - .name = "ETH_RESET", - .pin = { - .gpio = AT91_PIN_PC4, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "eth-reset", - } - }, - { - .name = "WIFI_BT_ULPWKUP", - .pin = { - .gpio = AT91_PIN_PA0, - .flags = GPIOF_IN, - .label = "wifi-bt-ulpwkup", - }, - .capability = CAPA_WIFI, - }, - { - .name = "WIFI_BT_LPWKUP", - .pin = { - .gpio = AT91_PIN_PA6, - .flags = GPIOF_IN, - .label = "wifi-bt-lpwkup", - }, - .capability = CAPA_WIFI, - }, - { - .name = "WIFI_BT_INT", - .pin = { - .gpio = AT91_PIN_PB11, - .flags = GPIOF_IN, - .label = "wifi-bt-int", - }, - .capability = CAPA_WIFI, - }, - { - .name = "WIFI_BT_RESET", - .pin = { - .gpio = AT91_PIN_PD14, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "wifi-bt-reset", - }, - .capability = CAPA_WIFI, - }, - { - .name = "GNSS_RESET", - .pin = { - .gpio = AT91_PIN_PD15, - .flags = GPIOF_OUT_INIT_LOW, /* Keep GPS quiet during boot */ - .label = "gnss-reset", - }, - .capability = CAPA_GPS, - }, - { - .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 = "mtq-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", - }, - .capability = CAPA_GPS, - }, - { - .name = "WIFI_BT_LPMODE", - .pin = { - .gpio = AT91_PIN_PD20, - .flags = GPIOF_IN, - .label = "wifi-bt-lpmode", - }, - .capability = CAPA_WIFI, - }, - { }, -}; - -static DEVICE_ATTR_MTS(dev_attr_wifi_bt_lpwkup, "wifi-bt-lpwkup", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); -static DEVICE_ATTR_MTS(dev_attr_wifi_bt_ulpwkup, "wifi-bt-ulpwkup", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); -static DEVICE_ATTR_MTS(dev_attr_wifi_bt_reset, "wifi-bt-reset", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); -static DEVICE_ATTR_RO_MTS(dev_attr_wifi_bt_lpmode, "wifi-bt-lpmode", - mts_attr_show_gpio_pin); -static DEVICE_ATTR_RO_MTS(dev_attr_wifi_bt_int, "wifi-bt-int", - mts_attr_show_gpio_pin); -static DEVICE_ATTR_MTS(dev_attr_gnss_reset, "gnss-reset", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); -static DEVICE_ATTR_MTS(dev_attr_usbhub_reset, "usbhub-reset", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); -static DEVICE_ATTR_MTS(dev_attr_eth_reset, "eth-reset", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); -static DEVICE_ATTR_MTS(dev_attr_gnss_int, "gnss-int", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - - - -static struct attribute *mtcdt_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_reset.attr, - &dev_attr_reset_monitor.attr, - &dev_attr_reset_monitor_intervals.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_a_gpio.attr, - &dev_attr_led_b_gpio.attr, - &dev_attr_led_c_gpio.attr, - &dev_attr_led_d_gpio.attr, - &dev_attr_eth_reset.attr, - - &dev_attr_radio_power.attr, - &dev_attr_radio_reset.attr, - - &dev_attr_radio_reset_backoffs.attr, - &dev_attr_radio_reset_backoff_index.attr, - &dev_attr_radio_reset_backoff_seconds.attr, - NULL, -}; - -static struct attribute *mtcdt_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_has_radio.attr, - &dev_attr_reset.attr, - &dev_attr_reset_monitor.attr, - &dev_attr_reset_monitor_intervals.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_a_gpio.attr, - &dev_attr_led_b_gpio.attr, - &dev_attr_led_c_gpio.attr, - &dev_attr_led_d_gpio.attr, - - &dev_attr_usbhub_reset.attr, - &dev_attr_eth_reset.attr, - - // radio feature is last to be able to - // easily remove radio. - // is_radio_power_attr_mtcdt() searches - // for this for truncation. - &dev_attr_radio_power.attr, /* Must be first radio attribute */ - &dev_attr_radio_reset.attr, - - &dev_attr_radio_reset_backoffs.attr, - &dev_attr_radio_reset_backoff_index.attr, - &dev_attr_radio_reset_backoff_seconds.attr, - - NULL, -}; - -static struct attribute *mtcdt_0_1_wifi_bt_attributes[] = { - &dev_attr_wifi_bt_lpwkup.attr, - &dev_attr_wifi_bt_ulpwkup.attr, - &dev_attr_wifi_bt_reset.attr, - &dev_attr_wifi_bt_lpmode.attr, - &dev_attr_wifi_bt_int.attr, -}; - -static struct attribute *mtcdt_0_1_gnss_attributes[] = { - &dev_attr_gnss_reset.attr, - &dev_attr_gnss_int.attr, -}; - - -static struct attribute_group mtcdt_platform_attribute_group = { - .attrs = mtcdt_platform_attributes -}; -static struct attribute_group mtcdt_0_1_platform_attribute_group = { - .attrs = mtcdt_0_1_platform_attributes -}; - - -static int -is_radio_power_attr_mtcdt(struct attribute *attr) -{ - return (attr == &dev_attr_radio_power.attr); -} diff --git a/io-module/mths.c b/io-module/mths.c deleted file mode 100644 index a51380c..0000000 --- a/io-module/mths.c +++ /dev/null @@ -1,879 +0,0 @@ -/* - * mths.c - * - * Created on: Apr 26, 2018 - * Author: leonid - */ -#include "at91gpio.h" -#include "buttons.h" - -static struct gpio_pin gpio_pins_mths_0_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 = "WPS_BUTTON", - .pin = { - .gpio = AT91_PIN_PA13, - .flags = GPIOF_IN, - .label = "wps_button", - }, - .active_low = 1, - }, - { - .name = "BT_BUTTON", - .pin = { - //TODO return back .gpio = AT91_PIN_PC4, - .gpio = AT91_PIN_PA12, - .flags = GPIOF_IN, - .label = "bt_button", - }, - .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 = "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-bt", - }, - .active_low = 1, - }, - { - .name = "LED4", - .pin = { - .gpio = AT91_PIN_PC20, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-c", - }, - .active_low = 1, - }, - { - .name = "LED5", - .pin = { - .gpio = AT91_PIN_PC21, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-status", - }, - .active_low = 1, - }, - { - .name = "LED5", - .pin = { - .gpio = AT91_PIN_PC21, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-cd", - }, - .active_low = 1, - }, - { - .name = "LED6", - .pin = { - .gpio = AT91_PIN_PC19, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-sig3", - }, - .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-sig1", - }, - .active_low = 1, - }, - { - .name = "LED8", - .pin = { - .gpio = AT91_PIN_PC17, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-f", - }, - .active_low = 1, - }, - - // The difference between MTRv1_0_0 and MTRv1_0_1 starts here - { - .name = "WIFI_BT_ULPWKUP", - .pin = { - .gpio = AT91_PIN_PB9, - .flags = GPIOF_IN, - .label = "wifi-bt-ulpwkup", - } - }, - { - .name = "WIFI_BT_LPWKUP", - .pin = { - .gpio = AT91_PIN_PB11, - .flags = GPIOF_IN, - .label = "wifi-bt-lpwkup", - } - }, - { - .name = "WIFI_BT_INT", - .pin = { - .gpio = AT91_PIN_PB13, - .flags = GPIOF_IN, - .label = "wifi-bt-int", - } - }, - { - .name = "WIFI_BT_RESET", - .pin = { - .gpio = AT91_PIN_PB10, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "wifi-bt-reset", - } - }, - { - .name = "WIFI_BT_LPMODE", - .pin = { - .gpio = AT91_PIN_PB12, - .flags = GPIOF_IN, - .label = "wifi-bt-lpmode", - } - }, - { - .name = "GNSS_RESET", - .pin = { - .gpio = AT91_PIN_PC6, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "gnss-reset", - } - }, - { - .name = "USBHUB_RESET", - .pin = { - .gpio = AT91_PIN_PB6, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "usbhub-reset", - } - }, - { - .name = "GNSS_INT", - .pin = { - .gpio = AT91_PIN_PC7, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "gnss-int", - } - }, - - - { }, -}; - -/* MTHS-0.1 has no WIFI LED */ -static struct gpio_pin gpio_pins_mths_0_1[] = { - { - .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 = "WPS_BUTTON", - .pin = { - .gpio = AT91_PIN_PA13, - .flags = GPIOF_IN, - .label = "wps_button", - }, - .active_low = 1, - }, - { - .name = "BT_BUTTON", - .pin = { - //TODO return back .gpio = AT91_PIN_PC4, - .gpio = AT91_PIN_PA12, - .flags = GPIOF_IN, - .label = "bt_button", - }, - .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 = "LED4", - .pin = { - .gpio = AT91_PIN_PC20, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-bt", - }, - .active_low = 1, - }, - { - .name = "LED4", - .pin = { - .gpio = AT91_PIN_PC20, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-c", - }, - .active_low = 1, - }, - { - .name = "LED5", - .pin = { - .gpio = AT91_PIN_PC21, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-status", - }, - .active_low = 1, - }, - { - .name = "LED5", - .pin = { - .gpio = AT91_PIN_PC21, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-cd", - }, - .active_low = 1, - }, - { - .name = "LED6", - .pin = { - .gpio = AT91_PIN_PC19, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-sig3", - }, - .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-sig1", - }, - .active_low = 1, - }, - { - .name = "LED8", - .pin = { - .gpio = AT91_PIN_PC17, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "led-f", - }, - .active_low = 1, - }, - - // The difference between MTRv1_0_0 and MTRv1_0_1 starts here - { - .name = "WIFI_BT_ULPWKUP", - .pin = { - .gpio = AT91_PIN_PB9, - .flags = GPIOF_IN, - .label = "wifi-bt-ulpwkup", - } - }, - { - .name = "WIFI_BT_LPWKUP", - .pin = { - .gpio = AT91_PIN_PB11, - .flags = GPIOF_IN, - .label = "wifi-bt-lpwkup", - } - }, - { - .name = "WIFI_BT_INT", - .pin = { - .gpio = AT91_PIN_PB13, - .flags = GPIOF_IN, - .label = "wifi-bt-int", - } - }, - { - .name = "WIFI_BT_RESET", - .pin = { - .gpio = AT91_PIN_PB10, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "wifi-bt-reset", - } - }, - { - .name = "WIFI_BT_LPMODE", - .pin = { - .gpio = AT91_PIN_PB12, - .flags = GPIOF_IN, - .label = "wifi-bt-lpmode", - } - }, - { - .name = "GNSS_RESET", - .pin = { - .gpio = AT91_PIN_PC6, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "gnss-reset", - } - }, - { - .name = "USBHUB_RESET", - .pin = { - .gpio = AT91_PIN_PB6, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "usbhub-reset", - } - }, - { - .name = "GNSS_INT", - .pin = { - .gpio = AT91_PIN_PC7, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "gnss-int", - } - }, - - - { }, -}; - -button_info_t mths_wps_button = { - .name = "User Push Button WPS", - .label_pin = "wps_button", - .label_monitor = "wps_button-monitor", - .label_monitor_intervals = "wps_button-monitor-intervals", - - /* Signals */ - .short_signal = SIGUSR1, - .long_signal = SIGUSR2, - .short_signal = SIGHUP, - - /* Intervals */ - .short_interval = BUTTON_HOLD_COUNT, - .long_interval = BUTTON_LONG_HOLD_COUNT, -}; - -button_info_t mths_bt_button = { - .name = "User Push Button BT", - .label_pin = "bt_button", - .label_monitor = "bt_button-monitor", - .label_monitor_intervals = "bt_button-monitor-intervals", - - /* Signals */ - .short_signal = SIGUSR1, - .long_signal = SIGUSR2, - .short_signal = SIGHUP, - - /* Intervals */ - .short_interval = BUTTON_HOLD_COUNT, - .long_interval = BUTTON_LONG_HOLD_COUNT, -}; - -/* MTHS 0.0 and 0.1 have same buttons. */ -static button_info_pt mths_buttons_0_0[] = { - &reset_button, - &mths_wps_button, - &mths_bt_button, - NULL, -}; - -static DEVICE_ATTR_MTS(dev_attr_wps_button_monitor_intervals_mths, - mths_wps_button.label_monitor_intervals, - mts_attr_show_button_monitor_intervals, - mts_attr_store_button_monitor_intervals); - -static DEVICE_ATTR_MTS(dev_attr_wps_button_monitor_mths, - mths_wps_button.label_monitor, - mts_attr_show_button_monitor, - mts_attr_store_button_monitor); - -static DEVICE_ATTR_RO_MTS(dev_attr_wps_button_pin_mths, - mths_wps_button.label_pin, - mts_attr_show_gpio_pin); - - -static DEVICE_ATTR_MTS(dev_attr_bt_button_monitor_intervals_mths, - mths_bt_button.label_monitor_intervals, - mts_attr_show_button_monitor_intervals, - mts_attr_store_button_monitor_intervals); - -static DEVICE_ATTR_MTS(dev_attr_bt_button_monitor_mths, - mths_bt_button.label_monitor, - mts_attr_show_button_monitor, - mts_attr_store_button_monitor); - -static DEVICE_ATTR_RO_MTS(dev_attr_bt_button_pin_mths, - mths_bt_button.label_pin, - mts_attr_show_gpio_pin); - - -/* radio control (power/reset) for mtr */ -static int radio_off_mths(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_mths(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); - - // ref:Telit_LE910_V2_Hardware_User_Guide_r9.pdf - // pg 32: When USB is connected or after firmware updating, - // delay must be equal at least to 10 seconds. - msleep(10500); - - // set on/off pin high - gpio_set_value(onoff_pin->pin.gpio, 1); - log_info("radio_on_mths: radio should be coming up"); - - msleep(200); - - // check that power is high - value = gpio_get_value(pwrmon_pin->pin.gpio); - if(value == 0) { - log_warning("radio_on_mths: 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_mths(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 10.5 sec - gpio_set_value(onoff_pin->pin.gpio, 0); - - log_info("Wait 10.5 seconds for on/off pin"); - msleep(10500); - - log_info("Done with wait 10.5 seconds for on/off pin"); - // set on/off pin high - gpio_set_value(onoff_pin->pin.gpio, 1); - msleep(200); // Delay for status pin to switch - return 0; -} - -static ssize_t mts_attr_store_radio_power_mths(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_mths(); - mutex_unlock(&mts_io_mutex); - } else { - mutex_lock(&mts_io_mutex); - err = radio_on_mths(); - mutex_unlock(&mts_io_mutex); - } - - if (err) { - return err; - } - - return count; -} - -static ssize_t mts_attr_store_radio_reset_mths(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int value; /* 0 = normal reset; -1 = forced reset */ - int err; - - if (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; - } - if (value != 0 && value != -1) { - return -EINVAL; - } - - /* check reset timings is enabled */ - if (value != -1 && 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_mths(); - - mutex_unlock(&mts_io_mutex); - - if (err) { - return err; - } - - return count; -} - -static ssize_t mts_attr_show_radio_power_mths(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_mths, "radio-power", - mts_attr_show_radio_power_mths, mts_attr_store_radio_power_mths); - -static DEVICE_ATTR_MTS(dev_attr_radio_reset_mths, "radio-reset", - mts_attr_show_gpio_pin, mts_attr_store_radio_reset_mths); - - -static DEVICE_ATTR_MTS(dev_attr_led_wifi_gpio_mths, "led-wifi", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_led_bt_gpio_mths, "led-bt", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_led_f_gpio_mths, "led-f", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_RO_MTS(dev_attr_wifi_mac_mths, "mac-wifi", - mts_attr_show_product_info); - -static DEVICE_ATTR_MTS(dev_attr_wifi_bt_lpwkup_mths, "wifi-bt-lpwkup", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_wifi_bt_ulpwkup_mths, "wifi-bt-ulpwkup", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_wifi_bt_reset_mths, "wifi-bt-reset", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_RO_MTS(dev_attr_wifi_bt_lpmode_mths, "wifi-bt-lpmode", - mts_attr_show_gpio_pin); - -static DEVICE_ATTR_RO_MTS(dev_attr_wifi_bt_int_mths, "wifi-bt-int", - mts_attr_show_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_gnss_reset_mths, "gnss-reset", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_MTS(dev_attr_usbhub_reset_mths, "usbhub-reset", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_RO_MTS(dev_attr_gnss_int_mths, "gnss-int", - mts_attr_show_gpio_pin); - - - -static struct attribute *mths_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_wifi_mac_mths.attr, - &dev_attr_has_radio.attr, - - &dev_attr_reset.attr, - &dev_attr_reset_monitor.attr, - &dev_attr_reset_monitor_intervals.attr, - &dev_attr_wps_button_pin_mths.attr, - &dev_attr_wps_button_monitor_mths.attr, - &dev_attr_wps_button_monitor_intervals_mths.attr, - &dev_attr_bt_button_pin_mths.attr, - &dev_attr_bt_button_monitor_mths.attr, - &dev_attr_bt_button_monitor_intervals_mths.attr, - - &dev_attr_radio_power_mths.attr, - &dev_attr_radio_reset_mths.attr, - - &dev_attr_radio_reset_backoffs.attr, - &dev_attr_radio_reset_backoff_index.attr, - &dev_attr_radio_reset_backoff_seconds.attr, - - &dev_attr_wifi_bt_lpwkup_mths.attr, - &dev_attr_wifi_bt_ulpwkup_mths.attr, - &dev_attr_wifi_bt_reset_mths.attr, - &dev_attr_wifi_bt_lpmode_mths.attr, - &dev_attr_wifi_bt_int_mths.attr, - &dev_attr_gnss_reset_mths.attr, - &dev_attr_usbhub_reset_mths.attr, - &dev_attr_gnss_int_mths.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_mths.attr, - &dev_attr_led_bt_gpio_mths.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_mths.attr, - - NULL, -}; - -static struct attribute_group mths_0_0_platform_attribute_group = { - .attrs = mths_0_0_platform_attributes -}; diff --git a/io-module/mtr.c b/io-module/mtr.c deleted file mode 100644 index e47beae..0000000 --- a/io-module/mtr.c +++ /dev/null @@ -1,1994 +0,0 @@ -#include "at91gpio.h" -static struct gpio_pin gpio_pins_mtr_0_0[] = { - { - .name = "ETH_RESET", - .pin = { - .gpio = AT91_PIN_PC6, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "eth-reset", - }, - .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_RESET", - .pin = { - .gpio = AT91_PIN_PC6, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "eth-reset", - }, - .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, - .label = "radio-reset", - }, - .active_low = 0, - }, - { - .name = "RADIO_POWER", - .pin = { - .gpio = AT91_PIN_PA21, - .flags = GPIOF_OUT_INIT_HIGH, - .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_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 = "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, - .label = "radio-reset", - }, - .active_low = 0, - }, - { - .name = "RADIO_POWER", - .pin = { - .gpio = AT91_PIN_PA21, - .flags = GPIOF_OUT_INIT_HIGH, - .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_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 = "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, - .label = "radio-reset", - }, - .active_low = 0, - }, - { - .name = "RADIO_POWER", - .pin = { - .gpio = AT91_PIN_PA21, - .flags = GPIOF_OUT_INIT_HIGH, - .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", - } - }, - - - { }, -}; - -static struct gpio_pin gpio_pins_mtrv1_0_2[] = { - { - .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 = "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, - .label = "radio-reset", - }, - .active_low = 0, - }, - { - .name = "RADIO_POWER", - .pin = { - .gpio = AT91_PIN_PA21, - .flags = GPIOF_OUT_INIT_HIGH, - .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", - } - }, - // 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", - } - }, - - { }, -}; - -static struct gpio_pin gpio_pins_mtrv1_0_3[] = { - { - .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, - }, - { - .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 = "MTQ_RESET", - .pin = { - .gpio = AT91_PIN_PD17, - .flags = GPIOF_OUT_INIT_HIGH, - .label = "radio-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", - } - }, - // 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 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 int radio_reset_mtr_mtq(void) -{ - struct gpio_pin *rst_pin = gpio_pin_by_attr_name("radio-reset"); - - if (!rst_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); - - 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; /* 0 = normal reset; -1 = forced reset */ - int err; - - if (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; - } - if (value != 0 && value != -1) { - return -EINVAL; - } - - /* check reset timings is enabled */ - if (value != -1 && 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); - - if (mts_hw_version == MTRV1_0_3) - { - err = radio_reset_mtr_mtq(); - } - else - { - 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_reset_mtr, "eth-reset", - 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 DEVICE_ATTR_RO_MTS(dev_attr_radio_wm_lk_m, "radio-wm-lk-m", - 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_has_radio.attr, - &dev_attr_wifi_mac_mtr.attr, - &dev_attr_reset.attr, - &dev_attr_reset_monitor.attr, - &dev_attr_reset_monitor_intervals.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_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, - - /* Radio stuff moved to end for possible removal */ - &dev_attr_radio_power_mtr.attr, /* radio_power must be first */ - &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, - - 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_has_radio.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_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_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 -}; - -static struct attribute *mtrv1_0_2_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_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_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_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, - - &dev_attr_radio_wm_lk_m.attr, // CAT M feature - - NULL, -}; - -static struct attribute_group mtrv1_0_2_platform_attribute_group = { - .attrs = mtrv1_0_2_platform_attributes -}; - - -static struct attribute *mtrv1_0_3_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_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_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, - - &dev_attr_radio_wm_lk_m.attr, // CAT M feature? Is this still there on the MTQ with Quectel? - - NULL, -}; - -static struct attribute_group mtrv1_0_3_platform_attribute_group = { - .attrs = mtrv1_0_3_platform_attributes -}; diff --git a/io-module/mts-io.c b/io-module/mts-io.c index d6bd4f2..f224777 100644 --- a/io-module/mts-io.c +++ b/io-module/mts-io.c @@ -20,7 +20,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#include + #include #include #include @@ -71,11 +71,6 @@ static const struct of_device_id mts_io_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, mts_io_dt_ids); -/* on-board EEPROM */ -static struct mts_id_eeprom_layout id_eeprom; - -#include "adc.c" - /* * We must call platform_set_drvdata, or else the * devres_head for the driver has junk in it, and @@ -88,11 +83,7 @@ static struct mts_id_eeprom_layout id_eeprom; */ static int mts_io_probe(struct platform_device *pdev) { - int ret = 0; - if (!DEVICE_CAPA(id_eeprom.capa, CAPA_ADC)) { - ret = mts_io_board_adc_probe(pdev); - } - return ret; + return 0; } static int mts_io_remove(struct platform_device *pdev) @@ -113,6 +104,8 @@ static struct platform_driver mts_io_driver = { }; +/* on-board EEPROM */ +static struct mts_id_eeprom_layout id_eeprom; static uint8_t mts_hw_version; struct platform_device *mts_io_platform_device; EXPORT_SYMBOL(mts_io_platform_device); @@ -135,8 +128,6 @@ static time_t time_now_secs(void); /* generic GPIO support */ #include "gpio.c" -#include "spi.c" - /* generic Button support */ //#include "buttons.c" @@ -165,8 +156,8 @@ bool sent_extra_long = false; * by a numeric, we have no modem. * All other cases, we have a modem. */ -static int -has_radio(const char *product_id, size_t len) +int +mts_has_radio(const char *product_id, size_t len) { char *p; if (!product_id || ! *product_id) @@ -203,6 +194,7 @@ has_radio(const char *product_id, size_t len) log_debug("Undefined product-id - has modem"); return 1; /* Product id invalid or empty, so instantiate a radio anyway */ } +EXPORT_SYMBOL(mts_has_radio); /* active-low socket modem reset */ static ssize_t mts_attr_store_radio_reset(struct device *dev, @@ -528,7 +520,7 @@ static ssize_t mts_attr_show_product_info(struct device *dev, value = sprintf(buf, "%.32s\n", id_eeprom.product_id); } else if (strcmp(attr->attr.name, "has-radio") == 0) { value = sprintf(buf, "%1d\n", - has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id)); + mts_has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id)); } else if (strcmp(attr->attr.name, "device-id") == 0) { value = sprintf(buf, "%.32s\n", id_eeprom.device_id); } else if (strcmp(attr->attr.name, "uuid") == 0) { @@ -558,7 +550,15 @@ static ssize_t mts_attr_show_product_info(struct device *dev, id_eeprom.mac_wifi[3], id_eeprom.mac_wifi[4], id_eeprom.mac_wifi[5]); - } else if (strcmp(attr->attr.name, "mac-eth") == 0) { + } else if (strcmp(attr->attr.name, "mac-bluetooth") == 0) { + value = sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X\n", + id_eeprom.mac_bluetooth[0], + id_eeprom.mac_bluetooth[1], + id_eeprom.mac_bluetooth[2], + id_eeprom.mac_bluetooth[3], + id_eeprom.mac_bluetooth[4], + id_eeprom.mac_bluetooth[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], id_eeprom.mac_addr[1], @@ -617,11 +617,12 @@ static int get_radio_model_from_product_id(void) { #include "mts_lora.c" /* include per-device pins and attributes */ -#include "mtcdt.c" -#include "mtcap.c" -#include "mtr.c" -#include "mths.c" -#include "mt100eocg.c" +#include "machine/mtcdt.c" +#include "machine/mtcap.c" +#include "machine/mtr.c" +#include "machine/mths.c" +#include "machine/mtcpm.c" + /* include capabilities sub-directory support */ #include "mts_capab.c" @@ -649,15 +650,20 @@ mts_id_eeprom_load(void) log_info("Platform EEPROM contents loaded"); } else { log_error("Invalid platform EEPROM length (%d)", fw->size); + return -EINVAL; } release_firmware(fw); } else { log_error("Unable to load EEPROM contents (%d)", ret); + return -ENODEV; } - noradio = ! has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id); - log_debug("mts_id_eeprom: noradio=%d",noradio); + // If we are an MTCPM, the base board sets the radio existance. + if (strncmp(id_eeprom.hw_version,HW_VERSION_MTCPM_DASH,sizeof HW_VERSION_MTCPM_DASH) != 0) { + noradio = ! mts_has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id); + log_debug("mts_id_eeprom: noradio=%d",noradio); + } if (((tmp=HW_VERSION_MTCAP_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || ((tmp=HW_VERSION_MTCAP_0_1),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || @@ -784,7 +790,7 @@ mts_id_eeprom_load(void) attr_group = &mtcdt_0_1_platform_attribute_group; gpio_pins = gpio_pins_mtcdt_0_1; - set_buttons(default_buttons); + set_buttons(default_buttons); log_info("detected board %s", tmp); } else if ((tmp=HW_VERSION_MTCDTIPHP_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) { current_blength = attr_blength = sizeof mtcdt_0_1_platform_attributes; @@ -831,15 +837,9 @@ mts_id_eeprom_load(void) if (DEVICE_CAPA(id_eeprom.capa, CAPA_LORA)) { attr_group_lora = &mtcdtiphp_0_0_lora_attribute_group; } - set_buttons(default_buttons); + set_buttons(default_buttons); log_info("detected board %s", tmp); - } else if (strncmp(id_eeprom.product_id, PRODUCT_ID_MT100EOCG, strlen(PRODUCT_ID_MT100EOCG)) == 0) { - attr_group = &mt100eocg_platform_attribute_group; - gpio_pins = gpio_pins_mt100eocg_0_0; - mts_hw_version = MT100EOCG_0_0; - set_buttons(default_buttons); - log_info("detected board %s", HW_VERSION_MT100EOCG_0_0); - } else { + } else if ((tmp=HW_VERSION_MTCDT_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) { if(noradio) { struct attribute **ap = mtcdt_platform_attribute_group.attrs; while(1) { @@ -859,9 +859,35 @@ mts_id_eeprom_load(void) attr_group = &mtcdt_platform_attribute_group; gpio_pins = gpio_pins_mtcdt_0_0; mts_hw_version = MTCDT_0_0; + set_buttons(default_buttons); + log_info("detected board %s", tmp); + + } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTCPM_0_0, strlen(HW_VERSION_MTCPM_0_0)) == 0) { + attr_group = &mtcpm_platform_attribute_group; + gpio_pins = gpio_pins_mtcpm; set_buttons(default_buttons); - log_info("detected board %s", HW_VERSION_MTCDT_0_0); - } + mts_hw_version = MTCPM_0_0; + log_info("detected board %s", HW_VERSION_MTCPM_0_0); + } else { + int i; + + for(i=0;iname, ret); } } + + // Create CPU directory if approprate (only MTCDT3 for now) + ret = mts_cpu_dir_create(mts_hw_version); + // start general buttons processing init_buttons(); @@ -1038,14 +1052,6 @@ 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; /* delete radio_reset_timer */ del_timer(&radio_reset_timer); diff --git a/io-module/mts_capab.c b/io-module/mts_capab.c index 17c505a..38e8442 100644 --- a/io-module/mts_capab.c +++ b/io-module/mts_capab.c @@ -68,21 +68,34 @@ static struct attribute_group mts_capa_attr_group = { }; static struct kobject *mts_capa_kobject = NULL; +EXPORT_SYMBOL(mts_capa_kobject); -static int mts_capab_dir_create(void) +static int mts_capab_dir_create(uint8_t hw_version) { - mts_capa_kobject = kobject_create_and_add("capability", &mts_io_platform_device->dev.kobj); - if (!mts_capa_kobject) { - log_error("kobject_create_and_add for capability directory failed"); - return -ENOMEM; - } + int i,j; + + if (hw_version == MTCPM_0_0) { + for (i=0; mts_capa_attributes[i]; i++) { + /* Remove capa_lora for MTCPM mts-io driver */ + if (mts_capa_attributes[i] == &capa_attr_lora.attr) { + for(j=i; mts_capa_attributes[j]; j++) + mts_capa_attributes[j] = mts_capa_attributes[j+1]; + break; + } + } + } + mts_capa_kobject = kobject_create_and_add("capability", &mts_io_platform_device->dev.kobj); + if (!mts_capa_kobject) { + log_error("kobject_create_and_add for capability directory failed"); + return -ENOMEM; + } - if (sysfs_create_group(mts_capa_kobject, &mts_capa_attr_group)) { - log_error("sysfs_create_group failed to create capability group"); - return -ENOMEM; - } + if (sysfs_create_group(mts_capa_kobject, &mts_capa_attr_group)) { + log_error("sysfs_create_group failed to create capability group"); + return -ENOMEM; + } - return 0; + return 0; } static void mts_capab_dir_delete(void) diff --git a/io-module/mts_io.h b/io-module/mts_io.h index 5e83879..12647fb 100644 --- a/io-module/mts_io.h +++ b/io-module/mts_io.h @@ -49,6 +49,7 @@ struct gpio_pin { uint8_t capability; }; +extern int mts_has_radio(const char *product_id, size_t len); #endif /* __MTS_IO_H */ diff --git a/io-module/mts_io_module.h b/io-module/mts_io_module.h index 0e1b1d5..4fcd3a7 100644 --- a/io-module/mts_io_module.h +++ b/io-module/mts_io_module.h @@ -5,13 +5,13 @@ * MTAC cards. */ -#define DRIVER_VERSION "v4.1.4a" +#define DRIVER_VERSION "v4.3.0a" #define DRIVER_AUTHOR "Multitech Systems" #define DRIVER_DESC "MTS-IO Controller" #define DRIVER_NAME "mts-io" #define DEBUG 0 - +/* Atmel AT91 Platforms */ #define PRODUCT_ID_MTCDP_E1_DK "MTCDP-E1-DK" #define PRODUCT_ID_MT100EOCG "MT100EOCG" #define PRODUCT_ID_MTR "MTR" @@ -41,6 +41,12 @@ #define HW_VERSION_MTHS_0_0 "MTHS-0.0" #define HW_VERSION_MTHS_0_1 "MTHS-0.1" +/* TI OMAP Platforms */ +#define PRODUCT_ID_MTCPM "MTCPM" + +#define HW_VERSION_MTCPM_DASH "MTCPM-" +#define HW_VERSION_MTCPM_0_0 "MTCPM-0.0" + enum { MTCDP_E1_DK_0_0, MTCDP_E1_DK_1_0, @@ -58,6 +64,7 @@ enum { MTCAP_0_1, MTHS_0_0, MTHS_0_1, + MTCPM_0_0, }; enum { diff --git a/io-module/spi.c b/io-module/spi.c deleted file mode 100644 index 1244cfc..0000000 --- a/io-module/spi.c +++ /dev/null @@ -1,597 +0,0 @@ -/* SPI devices, functions, and attributes */ - -static int ADT7302_to_celsius(int value) -{ - if (value & 0x2000) { - value = value - 16384; - } - - value = value / 32 + 1 * ((value % 32) >= 16); - - return value; -} - -/* SPI Devices */ -static struct spi_device *spi_sout_dev; -static u8 spi_sout_value; -static DEFINE_MUTEX(spi_sout_mutex); -static unsigned int sout_max_speed_hz = 1 * 1000 * 1000; -module_param(sout_max_speed_hz, uint, S_IRUGO); -MODULE_PARM_DESC( - sout_max_speed_hz, - "Maximum clock rate to be used with this device (default: 1 MHz)" -); - -static struct spi_device *spi_dout_dev; -static u8 spi_dout_value; -static DEFINE_MUTEX(spi_dout_mutex); -static unsigned int dout_max_speed_hz = 1 * 1000 * 1000; -module_param(dout_max_speed_hz, uint, S_IRUGO); -MODULE_PARM_DESC( - dout_max_speed_hz, - "Maximum clock rate to be used with this device (default: 1 MHz)" -); - -static struct spi_device *spi_din_dev; -static unsigned int din_max_speed_hz = 1 * 1000 * 1000; -module_param(din_max_speed_hz, uint, S_IRUGO); -MODULE_PARM_DESC( - din_max_speed_hz, - "Maximum clock rate to be used with this device (default: 1 MHz)" -); - -static struct spi_device *spi_board_temp_dev; -static unsigned int board_temp_max_speed_hz = 1 * 1000 * 1000; -module_param(board_temp_max_speed_hz, uint, S_IRUGO); -MODULE_PARM_DESC( - board_temp_max_speed_hz, - "Maximum clock rate to be used with this device (default: 1 MHz)" -); - -/* Generic SPI functions */ -static inline int spi_writen(struct spi_device *spi, const u8 *buf, size_t len) -{ - int tmp; - u8 *tx; - - tx = kmalloc(len, GFP_KERNEL); - if (!tx) { - return -ENOMEM; - } - - memcpy(tx, buf, len); - tmp = spi_write(spi, tx, len); - - kfree(tx); - - return tmp; -} - -static inline int spi_readn(struct spi_device *spi, u8 *buf, size_t len) -{ - int tmp; - u8 *rx; - - rx = kmalloc(len, GFP_KERNEL); - if (!rx) { - return -ENOMEM; - } - - tmp = spi_read(spi, rx, len); - memcpy(buf, rx, len); - - kfree(rx); - - return tmp; -} - -/* ---------------------------------------------------------------------------- - * - * SPI-based attribute show/store functions - * - * ---------------------------------------------------------------------------- -*/ - -#define SOUT_LED_CD_BIT BIT(0) -#define SOUT_EXTSERIAL_RI_BIT BIT(1) -#define SOUT_EXTSERIAL_DSR_BIT BIT(2) -#define SOUT_LED_DTR BIT(3) -#define SOUT_LED_SIG1_BIT BIT(4) -#define SOUT_LED_SIG2_BIT BIT(5) -#define SOUT_LED_SIG3_BIT BIT(6) -#define SOUT_EXTSERIAL_DCD_BIT BIT(7) - -static ssize_t mts_attr_store_sout(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int value; - u8 bit; - - if (!spi_sout_dev) { - log_notice("sout device not present"); - return -ENODEV; - } - - if (!strcmp(attr->attr.name, "extserial-ri")) { - bit = SOUT_EXTSERIAL_RI_BIT; - } else if (!strcmp(attr->attr.name, "extserial-dsr")) { - bit = SOUT_EXTSERIAL_DSR_BIT; - } else if (!strcmp(attr->attr.name, "extserial-dcd")) { - bit = SOUT_EXTSERIAL_DCD_BIT; - } else if (!strcmp(attr->attr.name, "led-cd") || - !strcmp(attr->attr.name, "led-sdk-b")) { - bit = SOUT_LED_CD_BIT; - } else if (!strcmp(attr->attr.name, "led-dtr") || - !strcmp(attr->attr.name, "led-sdk-f")) { - bit = SOUT_LED_DTR; - } else if (!strcmp(attr->attr.name, "led-sig1") || - !strcmp(attr->attr.name, "led-sdk-c")) { - bit = SOUT_LED_SIG1_BIT; - } else if (!strcmp(attr->attr.name, "led-sig2") || - !strcmp(attr->attr.name, "led-sdk-d")) { - bit = SOUT_LED_SIG2_BIT; - } else if (!strcmp(attr->attr.name, "led-sig3") || - !strcmp(attr->attr.name, "led-sdk-e")) { - bit = SOUT_LED_SIG3_BIT; - } else { - log_notice("sout attr does not exist"); - return -ENOENT; - } - - if (sscanf(buf, "%i", &value) != 1) { - log_notice("sout attr invalid argument"); - return -EINVAL; - } - - mutex_lock(&spi_sout_mutex); - - if (value) { - spi_sout_value &= ~bit; - } else { - spi_sout_value |= bit; - } - spi_writen(spi_sout_dev, &spi_sout_value, 1); - - mutex_unlock(&spi_sout_mutex); - - return count; -} - -static ssize_t mts_attr_show_sout(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int value; - u8 bit; - - if (!spi_sout_dev) { - log_error("sout device not present"); - return -ENODEV; - } - - if (!strcmp(attr->attr.name, "extserial-ri")) { - bit = SOUT_EXTSERIAL_RI_BIT; - } else if (!strcmp(attr->attr.name, "extserial-dsr")) { - bit = SOUT_EXTSERIAL_DSR_BIT; - } else if (!strcmp(attr->attr.name, "extserial-dcd")) { - bit = SOUT_EXTSERIAL_DCD_BIT; - } else if (!strcmp(attr->attr.name, "led-cd") || - !strcmp(attr->attr.name, "led-sdk-b")) { - bit = SOUT_LED_CD_BIT; - } else if (!strcmp(attr->attr.name, "led-dtr") || - !strcmp(attr->attr.name, "led-sdk-f")) { - bit = SOUT_LED_DTR; - } else if (!strcmp(attr->attr.name, "led-sig1") || - !strcmp(attr->attr.name, "led-sdk-c")) { - bit = SOUT_LED_SIG1_BIT; - } else if (!strcmp(attr->attr.name, "led-sig2") || - !strcmp(attr->attr.name, "led-sdk-d")) { - bit = SOUT_LED_SIG2_BIT; - } else if (!strcmp(attr->attr.name, "led-sig3") || - !strcmp(attr->attr.name, "led-sdk-e")) { - bit = SOUT_LED_SIG3_BIT; - } else { - log_notice("sout attr does not exist"); - return -ENOENT; - } - - mutex_lock(&spi_sout_mutex); - - value = spi_sout_value & bit ? 0 : 1; - - mutex_unlock(&spi_sout_mutex); - - return sprintf(buf, "%d\n", value); -} - -static ssize_t mts_attr_store_dout(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int value; - u8 bit; - - if (!spi_dout_dev) { - log_notice("dout device not present"); - return -ENODEV; - } - - if ((!strcmp(attr->attr.name, "dout0")) || (!strcmp(attr->attr.name, "gpo1"))) { - bit = BIT(0); - } else if ((!strcmp(attr->attr.name, "dout1")) || (!strcmp(attr->attr.name, "gpo2"))) { - bit = BIT(1); - } else if ((!strcmp(attr->attr.name, "dout2")) || (!strcmp(attr->attr.name, "gpo3"))) { - bit = BIT(2); - } else if ((!strcmp(attr->attr.name, "dout3")) || (!strcmp(attr->attr.name, "gpo4"))) { - bit = BIT(3); - } else if ((!strcmp(attr->attr.name, "dout4")) || (!strcmp(attr->attr.name, "led1"))) { - bit = BIT(4); - } else if ((!strcmp(attr->attr.name, "dout5")) || (!strcmp(attr->attr.name, "led4"))) { - bit = BIT(5); - } else if ((!strcmp(attr->attr.name, "dout6")) || (!strcmp(attr->attr.name, "led5"))) { - bit = BIT(6); - } else if ((!strcmp(attr->attr.name, "dout7")) || (!strcmp(attr->attr.name, "led6"))) { - bit = BIT(7); - } else { - log_notice("dout attr does not exist"); - return -ENOENT; - } - - if (sscanf(buf, "%i", &value) != 1) { - log_notice("dout attr invalid argument"); - return -EINVAL; - } - - mutex_lock(&spi_dout_mutex); - - if (value) { - spi_dout_value &= ~bit; - } else { - spi_dout_value |= bit; - } - - spi_writen(spi_dout_dev, &spi_dout_value, 1); - - mutex_unlock(&spi_dout_mutex); - - return count; -} - -static ssize_t mts_attr_show_dout(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int value; - u8 bit; - - if (!spi_dout_dev) { - log_error("dout device not present"); - return -ENODEV; - } - - if ((!strcmp(attr->attr.name, "dout0")) || (!strcmp(attr->attr.name, "gpo1"))) { - bit = BIT(0); - } else if ((!strcmp(attr->attr.name, "dout1")) || (!strcmp(attr->attr.name, "gpo2"))) { - bit = BIT(1); - } else if ((!strcmp(attr->attr.name, "dout2")) || (!strcmp(attr->attr.name, "gpo3"))) { - bit = BIT(2); - } else if ((!strcmp(attr->attr.name, "dout3")) || (!strcmp(attr->attr.name, "gpo4"))) { - bit = BIT(3); - } else if ((!strcmp(attr->attr.name, "dout4")) || (!strcmp(attr->attr.name, "led1"))) { - bit = BIT(4); - } else if ((!strcmp(attr->attr.name, "dout5")) || (!strcmp(attr->attr.name, "led4"))) { - bit = BIT(5); - } else if ((!strcmp(attr->attr.name, "dout6")) || (!strcmp(attr->attr.name, "led5"))) { - bit = BIT(6); - } else if ((!strcmp(attr->attr.name, "dout7")) || (!strcmp(attr->attr.name, "led6"))) { - bit = BIT(7); - } else { - log_notice("dout attr does not exist"); - return -ENOENT; - } - - mutex_lock(&spi_dout_mutex); - - value = spi_dout_value & bit ? 0 : 1; - - mutex_unlock(&spi_dout_mutex); - - return sprintf(buf, "%d\n", value); -} - -static ssize_t mts_attr_show_din(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int tmp; - u8 bit; - u8 byte; - - if (!spi_din_dev) { - log_error("din device not present"); - return -ENODEV; - } - - if ((!strcmp(attr->attr.name, "din0")) || (!strcmp(attr->attr.name, "gpi5"))) { - bit = BIT(0); - } else if ((!strcmp(attr->attr.name, "din1")) || (!strcmp(attr->attr.name, "gpi6"))) { - bit = BIT(1); - } else if ((!strcmp(attr->attr.name, "din2")) || (!strcmp(attr->attr.name, "gpi7"))) { - bit = BIT(2); - } else if ((!strcmp(attr->attr.name, "din3")) || (!strcmp(attr->attr.name, "gpi8"))) { - bit = BIT(3); - } else if ((!strcmp(attr->attr.name, "din4")) || (!strcmp(attr->attr.name, "gpi9"))) { - bit = BIT(4); - } else if ((!strcmp(attr->attr.name, "din5")) || (!strcmp(attr->attr.name, "gpi10"))) { - bit = BIT(5); - } else if (!strcmp(attr->attr.name, "din6")) { - bit = BIT(6); - } else if (!strcmp(attr->attr.name, "din7")) { - bit = BIT(7); - } else { - log_notice("din attr does not exist"); - return -ENOENT; - } - - tmp = spi_readn(spi_din_dev, &byte, 1); - if (tmp) { - log_error("spi_read failed %d", tmp); - return tmp; - } - - tmp = byte & bit ? 1 : 0; - - return sprintf(buf, "%d\n", tmp); -} - -static ssize_t mts_attr_show_board_temperature(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int tmp; - u16 temp_raw; - - if (!spi_board_temp_dev) { - log_notice("spi_board_temp device not present"); - return -ENODEV; - } - - tmp = spi_readn(spi_board_temp_dev, (u8 *) buf, 2); - if (tmp) { - log_error("spi_readn failed %d", tmp); - return tmp; - } - temp_raw = ((u8 *) buf)[0] << 8 | ((u8 *) buf)[1]; - - log_debug("temp: 0x%04X", temp_raw); - - return sprintf(buf, "%d\n", ADT7302_to_celsius(temp_raw)); -} - -/* ---------------------------------------------------------------------------- - * - * SPI-based attributes - * - * ---------------------------------------------------------------------------- -*/ - -static DEVICE_ATTR_RO_MTS(dev_attr_board_temperature, "board-temperature", - mts_attr_show_board_temperature); - -static DEVICE_ATTR_MTS(dev_attr_extserial_dcd, "extserial-dcd", - mts_attr_show_sout, mts_attr_store_sout); -static DEVICE_ATTR_MTS(dev_attr_extserial_ri, "extserial-ri", - mts_attr_show_sout, mts_attr_store_sout); -static DEVICE_ATTR_MTS(dev_attr_extserial_dsr, "extserial-dsr", - mts_attr_show_sout, mts_attr_store_sout); - -static DEVICE_ATTR_MTS(dev_attr_led_cd, "led-cd", - mts_attr_show_sout, mts_attr_store_sout); -static DEVICE_ATTR_MTS(dev_attr_led_sdk_b, "led-sdk-b", - mts_attr_show_sout, mts_attr_store_sout); -static DEVICE_ATTR_MTS(dev_attr_led_sig1, "led-sig1", - mts_attr_show_sout, mts_attr_store_sout); -static DEVICE_ATTR_MTS(dev_attr_led_sdk_c, "led-sdk-c", - mts_attr_show_sout, mts_attr_store_sout); -static DEVICE_ATTR_MTS(dev_attr_led_sig2, "led-sig2", - mts_attr_show_sout, mts_attr_store_sout); -static DEVICE_ATTR_MTS(dev_attr_led_sdk_d, "led-sdk-d", - mts_attr_show_sout, mts_attr_store_sout); -static DEVICE_ATTR_MTS(dev_attr_led_sig3, "led-sig3", - mts_attr_show_sout, mts_attr_store_sout); -static DEVICE_ATTR_MTS(dev_attr_led_sdk_e, "led-sdk-e", - mts_attr_show_sout, mts_attr_store_sout); -static DEVICE_ATTR_MTS(dev_attr_led_dtr, "led-dtr", - mts_attr_show_sout, mts_attr_store_sout); -static DEVICE_ATTR_MTS(dev_attr_led_sdk_f, "led-sdk-f", - mts_attr_show_sout, mts_attr_store_sout); - -static DEVICE_ATTR_MTS(dev_attr_dout0, "dout0", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_dout1, "dout1", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_dout2, "dout2", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_dout3, "dout3", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_dout4, "dout4", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_dout5, "dout5", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_dout6, "dout6", - mts_attr_show_dout, mts_attr_store_dout); -static DEVICE_ATTR_MTS(dev_attr_dout7, "dout7", - mts_attr_show_dout, mts_attr_store_dout); - -static DEVICE_ATTR_RO_MTS(dev_attr_din0, "din0", mts_attr_show_din); -static DEVICE_ATTR_RO_MTS(dev_attr_din1, "din1", mts_attr_show_din); -static DEVICE_ATTR_RO_MTS(dev_attr_din2, "din2", mts_attr_show_din); -static DEVICE_ATTR_RO_MTS(dev_attr_din3, "din3", mts_attr_show_din); -static DEVICE_ATTR_RO_MTS(dev_attr_din4, "din4", mts_attr_show_din); -static DEVICE_ATTR_RO_MTS(dev_attr_din5, "din5", mts_attr_show_din); -static DEVICE_ATTR_RO_MTS(dev_attr_din6, "din6", mts_attr_show_din); -static DEVICE_ATTR_RO_MTS(dev_attr_din7, "din7", mts_attr_show_din); - -static DEVICE_ATTR_RO_MTS(dev_attr_gpi5, "gpi5", mts_attr_show_din); -static DEVICE_ATTR_RO_MTS(dev_attr_gpi6, "gpi6", mts_attr_show_din); -static DEVICE_ATTR_RO_MTS(dev_attr_gpi7, "gpi7", mts_attr_show_din); -static DEVICE_ATTR_RO_MTS(dev_attr_gpi8, "gpi8", mts_attr_show_din); -static DEVICE_ATTR_RO_MTS(dev_attr_gpi9, "gpi9", mts_attr_show_din); -static DEVICE_ATTR_RO_MTS(dev_attr_gpi10, "gpi10", mts_attr_show_din); - -/* SPI driver setup */ -static int mts_spi_sout_probe(struct spi_device *spi) -{ - int tmp; - - spi->max_speed_hz = sout_max_speed_hz; - spi->mode = 0; - - log_debug("sout_max_speed_hz: %d", sout_max_speed_hz); - - tmp = spi_setup(spi); - if (tmp < 0) { - log_error("spi_setup sout failed"); - return tmp; - } - - spi_sout_value = 0xFF; - spi_writen(spi, &spi_sout_value, 1); - - spi_sout_dev = spi; - - return 0; -} - -static int mts_spi_sout_remove(struct spi_device *spi) -{ - spi_sout_dev = NULL; - - return 0; -} - -static struct spi_driver mts_spi_sout_driver = { - .driver = { - .name = "mts-io-sout", - .bus = &spi_bus_type, - .owner = THIS_MODULE, - }, - - .probe = mts_spi_sout_probe, - .remove = mts_spi_sout_remove, -}; - -static int mts_spi_dout_probe(struct spi_device *spi) -{ - int tmp; - - spi->max_speed_hz = dout_max_speed_hz; - spi->mode = 0; - - log_debug("dout_max_speed_hz: %d", dout_max_speed_hz); - - tmp = spi_setup(spi); - if (tmp < 0) { - log_error("spi_setup dout failed"); - return tmp; - } - - spi_dout_value = 0x00; - spi_writen(spi, &spi_dout_value, 1); - - spi_dout_dev = spi; - - return 0; -} - -static int mts_spi_dout_remove(struct spi_device *spi) -{ - spi_dout_dev = NULL; - - return 0; -} - -static struct spi_driver mts_spi_dout_driver = { - .driver = { - .name = "mts-io-dout", - .bus = &spi_bus_type, - .owner = THIS_MODULE, - }, - - .probe = mts_spi_dout_probe, - .remove = mts_spi_dout_remove, -}; - -static int mts_spi_din_probe(struct spi_device *spi) -{ - int tmp; - spi->max_speed_hz = din_max_speed_hz; - spi->mode = SPI_CPOL; - - log_debug("din_max_speed_hz: %d", din_max_speed_hz); - - tmp = spi_setup(spi); - if (tmp < 0) { - log_error("spi_setup din failed"); - return tmp; - } - - spi_din_dev = spi; - - return 0; -} - -static int mts_spi_din_remove(struct spi_device *spi) -{ - spi_din_dev = NULL; - - return 0; -} - -static struct spi_driver mts_spi_din_driver = { - .driver = { - .name = "mts-io-din", - .bus = &spi_bus_type, - .owner = THIS_MODULE, - }, - - .probe = mts_spi_din_probe, - .remove = mts_spi_din_remove, -}; - -static int mts_spi_board_temp_probe(struct spi_device *spi) -{ - int tmp; - - spi->max_speed_hz = board_temp_max_speed_hz; - spi->mode = SPI_CPOL | SPI_CPHA; - - log_debug("board_temp_max_speed_hz: %d", board_temp_max_speed_hz); - - tmp = spi_setup(spi); - if (tmp < 0) { - log_error("spi_setup board-temp failed"); - return tmp; - } - - spi_board_temp_dev = spi; - - return 0; -} - -static int mts_spi_board_temp_remove(struct spi_device *spi) -{ - spi_board_temp_dev = NULL; - - return 0; -} - -static struct spi_driver mts_spi_board_temp_driver = { - .driver = { - .name = "mts-io-board-temp", - .bus = &spi_bus_type, - .owner = THIS_MODULE, - }, - - .probe = mts_spi_board_temp_probe, - .remove = mts_spi_board_temp_remove, -}; -- cgit v1.2.3