diff options
-rw-r--r-- | AUTHORS | 4 | ||||
-rw-r--r-- | README | 12 | ||||
-rw-r--r-- | mtac_lora.c | 304 |
3 files changed, 269 insertions, 51 deletions
@@ -1,3 +1 @@ -James Maki <jmaki@multitech.com> -John Klug <john.klug@multitech.com> - +Multi-Tech <info@multitech.com> @@ -10,7 +10,13 @@ Documentation for this board is here: http://www.multitech.net/developer/software/mlinux/using-mlinux/mlinux-using-accessory-cards/mtac-eth-usage/ -An init script can look in: -/lib/modules/$(uname -r)/extra/mtac_lora.ko -to find the driver. +To turn on debug add the following lines to +the end of /etc/modprobe.d/mts-io.conf: + +options mts-io dyndbg=+p +options mtac dyndbg=+p +options mtac-lora dyndbg=+p + + + diff --git a/mtac_lora.c b/mtac_lora.c index 8e9d09b..058d486 100644 --- a/mtac_lora.c +++ b/mtac_lora.c @@ -1,4 +1,4 @@ -#define DRIVER_VERSION "v1.1.5" +#define DRIVER_VERSION "v1.1.12" #define DRIVER_AUTHOR "Multi-Tech" #define DRIVER_DESC "MTS LoRa Accessory Card" #define DRIVER_NAME "mtac-lora" @@ -21,10 +21,11 @@ #include <linux/mts_io.h> + static struct gpio_pin gpio_pins_mtac_lora_0_0[] = { // gpio pins for Accessory Card 1 { - .name = "AP1_RESET", + .name = "AP1_NRESET", .pin = { .gpio = M_AP1_NRESET, .flags = GPIOF_OUT_INIT_HIGH, @@ -34,7 +35,7 @@ static struct gpio_pin gpio_pins_mtac_lora_0_0[] = { // gpio pins for Accessory Card 2 { - .name = "AP2_RESET", + .name = "AP2_NRESET", .pin = { .gpio = M_AP2_NRESET, .flags = GPIOF_OUT_INIT_HIGH, @@ -47,54 +48,60 @@ static struct gpio_pin gpio_pins_mtac_lora_0_0[] = { static struct gpio_pin gpio_pins_mtac_lora_1_5[] = { // gpio pins for Accessory Card 1 { - .name = "AP1_RESET", + .name = "AP1_NRESET", .pin = { - .gpio = M_AP1_NRESET, - .flags = GPIOF_OUT_INIT_HIGH, + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, .label = "ap1-reset", - } + }, + .do_gpio_desc = 1 }, { - .name = "AP1_CDONE", + .name = "AP1_GPIO1", .pin = { - .gpio = M_AP1_GPIO1, - .flags = GPIOF_IN, + .gpio = ~0U, + .flags = GPIOD_IN, .label = "ap1-cdone", }, + .do_gpio_desc = 1 }, { - .name = "AP1_CRESET", + .name = "AP1_GPIO2", .pin = { - .gpio = M_AP1_GPIO2, - .flags = GPIOF_OUT_INIT_HIGH, + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, .label = "ap1-creset", - } + }, + .do_gpio_desc = 1 }, // gpio pins for Accessory Card 2 { - .name = "AP2_RESET", + .name = "AP2_NRESET", .pin = { - .gpio = M_AP2_NRESET, - .flags = GPIOF_OUT_INIT_HIGH, + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, .label = "ap2-reset", - } + }, + .do_gpio_desc = 1 }, { - .name = "AP2_CDONE", + .name = "AP2_GPIO1", .pin = { - .gpio = M_AP2_GPIO1, - .flags = GPIOF_IN, + .gpio = ~0U, + .flags = GPIOD_IN, .label = "ap2-cdone", }, + .do_gpio_desc = 1 }, { - .name = "AP2_CRESET", + .name = "AP2_GPIO2", .pin = { - .gpio = M_AP2_GPIO2, - .flags = GPIOF_OUT_INIT_HIGH, + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, .label = "ap2-creset", - } + }, + .do_gpio_desc = 1 }, { }, }; @@ -102,42 +109,178 @@ static struct gpio_pin gpio_pins_mtac_lora_1_5[] = { static struct gpio_pin gpio_pins_mtac_lora_2g4_0_0[] = { // gpio pins for Accessory Card 1 { - .name = "AP1_RESET", + .name = "AP1_NRESET", .pin = { - .gpio = M_AP1_NRESET, - .flags = GPIOF_OUT_INIT_HIGH, + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, .label = "ap1-reset", - } + }, + .do_gpio_desc = 1 }, { - .name = "AP1_BOOT", + .name = "AP1_GPIO1", .pin = { - .gpio = M_AP1_GPIO1, - .flags = GPIOF_OUT_INIT_LOW, + .gpio = ~0U, + .flags = GPIOD_OUT_LOW, .label = "ap1-boot", }, + .do_gpio_desc = 1 }, // gpio pins for Accessory Card 2 { - .name = "AP2_RESET", + .name = "AP2_NRESET", .pin = { - .gpio = M_AP2_NRESET, - .flags = GPIOF_OUT_INIT_HIGH, + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, .label = "ap2-reset", - } + }, + .do_gpio_desc = 1 }, { - .name = "AP2_BOOT", + .name = "AP2_GPIO1", .pin = { - .gpio = M_AP2_GPIO1, - .flags = GPIOF_OUT_INIT_LOW, + .gpio = ~0U, + .flags = GPIOD_OUT_LOW, .label = "ap2-boot", }, + .do_gpio_desc = 1 }, { }, }; +static struct gpio_pin gpio_pins_mtac_lora_003_0_0[] = { + // gpio pins for Accessory Card 1 + { + .name = "AP1_NRESET", + .pin = { + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, + .label = "ap1-reset", + }, + .do_gpio_desc = 1 + }, + + { + .name = "AP1_GPIO4", + .pin = { + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, + .label = "ap1-creset", + }, + .do_gpio_desc = 1 + }, + + { + .name = "AP1_TBD1", + .pin = { + .gpio = ~0U, + .flags = GPIOD_OUT_LOW, + .label = "ap1-lbtreset", + }, + .do_gpio_desc = 1 + }, + + // gpio pins for Accessory Card 2 + { + .name = "AP2_NRESET", + .pin = { + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, + .label = "ap2-reset", + }, + .do_gpio_desc = 1 + }, + + { + .name = "AP2_GPIO4", + .pin = { + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, + .label = "ap2-creset", + }, + .do_gpio_desc = 1 + }, + + { + .name = "AP2_TBD1", + .pin = { + .gpio = ~0U, + .flags = GPIOD_OUT_LOW, + .label = "ap2-lbtreset", + }, + .do_gpio_desc = 1 + }, + + { }, +}; + +static struct gpio_pin gpio_pins_mtac_lora_003_0_1[] = { + // gpio pins for Accessory Card 1 + { + .name = "AP1_NRESET", + .pin = { + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, + .label = "ap1-reset", + }, + .do_gpio_desc = 1 + }, + + { + .name = "AP1_GPIO4", + .pin = { + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, + .label = "ap1-creset", + }, + .do_gpio_desc = 1 + }, + + { + .name = "AP1_TBD1", + .pin = { + .gpio = ~0U, + .flags = GPIOD_OUT_LOW, + .label = "ap1-lbtreset", + }, + .do_gpio_desc = 1 + }, + + // gpio pins for Accessory Card 2 + { + .name = "AP2_NRESET", + .pin = { + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, + .label = "ap2-reset", + }, + .do_gpio_desc = 1 + }, + + { + .name = "AP2_GPIO4", + .pin = { + .gpio = ~0U, + .flags = GPIOD_OUT_HIGH, + .label = "ap2-creset", + }, + .do_gpio_desc = 1 + }, + + { + .name = "AP2_TBD1", + .pin = { + .gpio = ~0U, + .flags = GPIOD_OUT_LOW, + .label = "ap2-lbtreset", + }, + .do_gpio_desc = 1 + }, + + { }, +}; + ssize_t lora_show_eui(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { int retval = -1; @@ -174,6 +317,10 @@ static char* lora_gpio_pin_name_by_attr_name(const char* name, int port) { case port_1: if (! strcmp(name, "reset")) { return "ap1-reset"; + } else if (!strcmp(name,"lbtreset")) { + return "ap1-lbtreset"; + } else if (!strcmp(name,"nreset")) { + return "ap1-nreset"; } else if (!strcmp(name,"cdone")) { return "ap1-cdone"; } else if (!strcmp(name,"creset")) { @@ -188,6 +335,10 @@ static char* lora_gpio_pin_name_by_attr_name(const char* name, int port) { case port_2: if (! strcmp(name, "reset")) { return "ap2-reset"; + } else if (!strcmp(name,"lbtreset")) { + return "ap2-lbtreset"; + } else if (!strcmp(name,"nreset")) { + return "ap2-nreset"; } else if (!strcmp(name,"cdone")) { return "ap2-cdone"; } else if (!strcmp(name,"creset")) { @@ -216,6 +367,8 @@ static char* lora_gpio_pin_name_by_attr_name(const char* name, int port) { #define ATTRS_SIZE_1_5 9 #define ATTRS_SIZE_2G4_0_0 8 #define ATTRS_SIZE_0_0 7 +#define ATTRS_SIZE_003_0_0 9 /*dev*/ +#define ATTRS_SIZE_003_0_1 9 /*dev*/ // Set the hardware version if the ROM string matches one of the valid // hardware versions. @@ -243,7 +396,6 @@ static bool lora_setup(enum ap port) { ap_eeprom = (struct mts_ap_eeprom_layout *)mts_ap_eeprom[port_index]; log_info("loading LORA accessory card in port %d hw: version %s", port, ap_eeprom->hw_version); - sprintf(buf, "ap%d", port); subdir = kobject_create_and_add(buf, &mts_io_platform_device->dev.kobj); if (! subdir) { @@ -259,6 +411,8 @@ static bool lora_setup(enum ap port) { if (mtac_port_info[i - 1]) { if (strstr(mtac_port_info[i - 1]->product_id, PRODUCT_ID_MTAC_LORA)) { count++; + } else if (strstr(mtac_port_info[i - 1]->product_id, PRODUCT_ID_MTAC_LORA_003)) { + count++; } } } @@ -268,6 +422,7 @@ static bool lora_setup(enum ap port) { } else { sprintf(buf, "lora"); } + log_info("sysfs_create_link called"); ret = sysfs_create_link(subdir->parent, subdir, buf); if (ret) { log_error("failed to link [%s] to [%s], %d", buf, subdir->name, ret); @@ -283,6 +438,8 @@ static bool lora_setup(enum ap port) { else if COMPARE_AND_ASSIGN(MTAC_LORA_1_0) else if COMPARE_AND_ASSIGN(MTAC_LORA_1_5) else if COMPARE_AND_ASSIGN(MTAC_LORA_2G4_0_0) + else if COMPARE_AND_ASSIGN(MTAC_LORA_003_0_0) + else if COMPARE_AND_ASSIGN(MTAC_LORA_003_0_1) else { log_error("Unknown hw-version in port %d", port); return false; @@ -294,6 +451,12 @@ static bool lora_setup(enum ap port) { } else if ((lora_hw_version == MTAC_LORA_2G4_0_0) || (lora_hw_version == MTAC_LORA_2G4_0_0)) { ap_lora_attrs_size = ATTRS_SIZE_2G4_0_0; mtac_set_port_pins(port_index,gpio_pins_mtac_lora_2g4_0_0,subdir); + } else if (lora_hw_version == MTAC_LORA_003_0_0) { + ap_lora_attrs_size = ATTRS_SIZE_003_0_0; + mtac_set_port_pins(port_index,gpio_pins_mtac_lora_003_0_0,subdir); + } else if (lora_hw_version == MTAC_LORA_003_0_1) { + ap_lora_attrs_size = ATTRS_SIZE_003_0_1; + mtac_set_port_pins(port_index,gpio_pins_mtac_lora_003_0_1,subdir); } else { ap_lora_attrs_size = ATTRS_SIZE_1_5; mtac_set_port_pins(port_index,gpio_pins_mtac_lora_1_5,subdir); @@ -370,6 +533,46 @@ static bool lora_setup(enum ap port) { } } + if (lora_hw_version == MTAC_LORA_003_0_0 || lora_hw_version == MTAC_LORA_003_0_1) { + log_debug("assigning lbtreset"); + //GPIO1 - boot on MCU controls reset into bootloader mode + sprintf(buf, "lbtreset"); + attr = mtac_create_attribute(buf, MTS_ATTR_MODE_RW); + if (! attr) { + log_error("failed to create attribute [%s] for LORA in port %d", buf, port); + attrs[index] = NULL; + mtac_port_info[port_index]->attr_group.attrs = attrs; + return false; + } + attr->show = mtac_attr_show_ap_gpio_pin; + attr->store = mtac_attr_store_ap_gpio_pin; + attrs[index++] = &attr->attr; + + if(index >= ap_lora_attrs_size) { + panic("Internal error, too many attributes on the LORA card index %d >= %d", + index,ap_lora_attrs_size); + } + + log_debug("assigning creset"); + //NRESET - Resets both the 1303 and 1261 + sprintf(buf, "creset"); + attr = mtac_create_attribute(buf, MTS_ATTR_MODE_RW); + if (! attr) { + log_error("failed to create attribute [%s] for LORA in port %d", buf, port); + attrs[index] = NULL; + mtac_port_info[port_index]->attr_group.attrs = attrs; + return false; + } + attr->show = mtac_attr_show_ap_gpio_pin; + attr->store = mtac_attr_store_ap_gpio_pin; + attrs[index++] = &attr->attr; + + if(index >= ap_lora_attrs_size) { + panic("Internal error, too many attributes on the LORA card index %d >= %d", + index,ap_lora_attrs_size); + } + } + sprintf(buf,"eui"); attr = mtac_create_attribute("eui", MTS_ATTR_MODE_RO); if (! attr) { @@ -402,6 +605,7 @@ static bool lora_setup(enum ap port) { } static bool lora_teardown(enum ap port) { + int port_index = port - 1; struct attribute **attrs = mtac_port_info[port_index]->attr_group.attrs; struct attribute *p; @@ -442,6 +646,13 @@ void set_lora_info(struct ap_info* info) { info->gpio_pin_name_by_attr_name = &lora_gpio_pin_name_by_attr_name; } +void set_lora_info_003(struct ap_info* info) { + snprintf(info->product_id, 32, "%s", PRODUCT_ID_MTAC_LORA_003); + info->setup = &lora_setup; + info->teardown = &lora_teardown; + info->gpio_pin_name_by_attr_name = &lora_gpio_pin_name_by_attr_name; +} + /* * Loop through all the slots, and set up the * mtac-lora driver for all slots. @@ -449,18 +660,20 @@ void set_lora_info(struct ap_info* info) { static int __init mtac_lora_init(void) { int slot_count = 0; - - slot_count = mtac_find(set_lora_info,PRODUCT_ID_MTAC_LORA); - + int slot_count_lora = 0; + int slot_count_003 = 0; + log_debug("mtac_find for LORA called"); + slot_count_lora = mtac_find(set_lora_info,PRODUCT_ID_MTAC_LORA); + log_debug("mtac_find for MTAC-003 called"); + slot_count_003 = mtac_find(set_lora_info_003,PRODUCT_ID_MTAC_LORA_003); + slot_count = slot_count_lora + slot_count_003; if (slot_count < 1) { log_debug("No MTAC LORA found"); if (slot_count < 0) return slot_count; else return -ENXIO; - } - return 0; } @@ -468,6 +681,7 @@ static int __init mtac_lora_init(void) static void __exit mtac_lora_exit(void) { mtac_free(PRODUCT_ID_MTAC_LORA,lora_setup,"lora"); + mtac_free(PRODUCT_ID_MTAC_LORA_003,lora_setup,"lora"); log_info("exiting"); } |