diff options
Diffstat (limited to 'io-module/mtcap.c')
-rw-r--r-- | io-module/mtcap.c | 163 |
1 files changed, 48 insertions, 115 deletions
diff --git a/io-module/mtcap.c b/io-module/mtcap.c index e651406..d86c5a6 100644 --- a/io-module/mtcap.c +++ b/io-module/mtcap.c @@ -45,24 +45,27 @@ static struct gpio_pin gpio_pins_mtcap_0_0[] = { .pin = { .gpio = AT91_PIN_PA8, // LORA_RST .flags = GPIOF_OUT_INIT_LOW, - .label = "lora-reset", + .label = "lora/reset", }, + .capability = CAPA_LORA, }, { // gpio 1 for LORA 1.5 ref design .name = "LORA_CDONE", .pin = { .gpio = AT91_PIN_PA6, .flags = GPIOF_IN, - .label = "lora-cdone", + .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", - } + .label = "lora/creset", + }, + .capability = CAPA_LORA, }, @@ -357,123 +360,20 @@ static ssize_t mts_attr_show_radio_power_mtcap(struct device *dev, return sprintf(buf, "%d\n", value); } -static int lora_reset_mtcap(void) -{ - struct gpio_pin *rst_pin = gpio_pin_by_attr_name("lora-reset"); - - if (!rst_pin) { - return -ENODEV; - } - - /* - * drive the reset pin low, set pin high for 100ns, drive pin low - */ - gpio_set_value(rst_pin->pin.gpio, 0); - - gpio_set_value(rst_pin->pin.gpio, 1); - - msleep(1); - - gpio_set_value(rst_pin->pin.gpio, 0); - - msleep(100); - - return 0; -} - -static ssize_t mts_attr_store_lora_reset_mtcap(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int value; - int err; - - if (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; - } - - log_info("performing lora reset"); - - mutex_lock(&mts_io_mutex); - - err = lora_reset_mtcap(); - - mutex_unlock(&mts_io_mutex); - - if (err) { - return err; - } - - return count; -} - -static int eth_reset_mtcap(void) -{ - struct gpio_pin *rst_pin = gpio_pin_by_attr_name("eth-reset"); - - if (!rst_pin) { - return -ENODEV; - } - - /* - * DS00002275A (09-15-16) KSZ8091MNX/RNB DATA SHEET: - * For warm reset, the reset (RST#) pin should be asserted low for a minimum of 500 μs. - */ - gpio_set_value(rst_pin->pin.gpio, 0); - - msleep(2); - - gpio_set_value(rst_pin->pin.gpio, 1); - - msleep(1); - - return 0; -} - -static ssize_t mts_attr_store_eth_reset_mtcap(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int value; - int err; - - if (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; - } - - log_info("performing eth reset"); - - mutex_lock(&mts_io_mutex); - - err = eth_reset_mtcap(); - - mutex_unlock(&mts_io_mutex); - - if (err) { - return err; - } - - return count; -} - static DEVICE_ATTR_MTS(dev_attr_radio_reset_mtcap, "radio-reset", - mts_attr_show_gpio_pin, mts_attr_store_radio_reset_mtcap); + mts_attr_show_gpio_pin, mts_attr_store_radio_reset_mtcap); static DEVICE_ATTR_MTS(dev_attr_radio_power_mtcap, "radio-power", mts_attr_show_radio_power_mtcap, mts_attr_store_radio_power_mtcap); -static DEVICE_ATTR_MTS(dev_attr_lora_reset_mtcap, "lora-reset", - mts_attr_show_gpio_pin, mts_attr_store_lora_reset_mtcap); - static DEVICE_ATTR_MTS(dev_attr_eth_reset_mtcap, "eth-reset", - mts_attr_show_gpio_pin, mts_attr_store_eth_reset_mtcap); + 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); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); static DEVICE_ATTR_MTS(dev_attr_led_wifi_gpio_mtcap, "led-wifi", - mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); - -static DEVICE_ATTR_RO_MTS(dev_attr_lora_eui, "lora-eui", - mts_attr_show_product_info); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); static struct attribute *mtcap_0_0_platform_attributes[] = { &dev_attr_vendor_id.attr, @@ -489,8 +389,6 @@ static struct attribute *mtcap_0_0_platform_attributes[] = { &dev_attr_eth_reset_mtcap.attr, - &dev_attr_lora_reset_mtcap.attr, - &dev_attr_radio_power_mtcap.attr, &dev_attr_radio_reset_mtcap.attr, @@ -503,11 +401,46 @@ static struct attribute *mtcap_0_0_platform_attributes[] = { &dev_attr_led_lora_gpio_mtcap.attr, &dev_attr_led_wifi_gpio_mtcap.attr, - &dev_attr_lora_eui.attr, - NULL, }; static struct attribute_group mtcap_0_0_platform_attribute_group = { .attrs = mtcap_0_0_platform_attributes }; + + +// +// 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 +}; |