diff options
author | John Klug <john.klug@multitech.com> | 2016-09-30 17:22:00 -0500 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2016-09-30 17:22:00 -0500 |
commit | cf9e2ae0c4193f784138e098c929a36a9aaa8854 (patch) | |
tree | a9b66d291b8d852c4e5ed71b709fdabe7d154322 /io-module/mtac_lora.c | |
parent | 670c959a9bdfd4aaae25a6d0c30e31d29b6761de (diff) | |
download | mts-io-cf9e2ae0c4193f784138e098c929a36a9aaa8854.tar.gz mts-io-cf9e2ae0c4193f784138e098c929a36a9aaa8854.tar.bz2 mts-io-cf9e2ae0c4193f784138e098c929a36a9aaa8854.zip |
mts-io driver for Lora-H and additional resets
Diffstat (limited to 'io-module/mtac_lora.c')
-rw-r--r-- | io-module/mtac_lora.c | 82 |
1 files changed, 74 insertions, 8 deletions
diff --git a/io-module/mtac_lora.c b/io-module/mtac_lora.c index 29e37ff..a0907c8 100644 --- a/io-module/mtac_lora.c +++ b/io-module/mtac_lora.c @@ -3,16 +3,24 @@ 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,"cdone")) { + return "ap1-cdone"; + } else if (!strcmp(name,"creset")) { + return "ap1-creset"; } else { - log_error("attirbute name [%s] is invalid for LORA in port %d", name, port); + log_error("attribute name [%s] is invalid for LORA in port %d", name, port); return ""; } case port_2: if (! strcmp(name, "reset")) { return "ap2-reset"; + } else if (!strcmp(name,"cdone")) { + return "ap2-cdone"; + } else if (!strcmp(name,"creset")) { + return "ap2-creset"; } else { - log_error("attirbute name [%s] is invalid for LORA in port %d", name, port); + log_error("attribute name [%s] is invalid for LORA in port %d", name, port); return ""; } } @@ -24,9 +32,10 @@ static char* lora_gpio_pin_name_by_attr_name(const char* name, int port) { // 1 device-id // 1 hw-version // 1 eui -// 1 reset +// 1 cdone +// 1 creset // NULL -static size_t ap_lora_attrs_size = 8; +static size_t ap_lora_attrs_size = 9; // Set the hardware version if the ROM string matches one of the valid // hardware versions. @@ -77,7 +86,8 @@ static bool lora_setup(enum ap port) { ret = sysfs_create_link(ap_subdirs[port_index]->parent, ap_subdirs[port_index], buf); if (ret) { log_error("failed to link [%s] to [%s], %d", buf, ap_subdirs[port_index]->name, ret); - } + } else + log_info("created link [%s] to [%s], success:%d", buf, ap_subdirs[port_index]->name, ret); attrs = kzalloc(sizeof(struct attribute*) * ap_lora_attrs_size, GFP_KERNEL); if (! attrs) { @@ -110,17 +120,73 @@ static bool lora_setup(enum ap port) { attr->store = mts_attr_store_ap_gpio_pin; attrs[index++] = &attr->attr; } + else if (lora_hw_version == MTAC_LORA_1_5) { + // Substitute pins for this port + log_info("Substitute pins"); + int ipin = 0; + while(*(lora_h[port_index][ipin].name)) { + struct gpio_pin *p; + p = gpio_pin_by_num(lora_h[port_index][ipin].pin.gpio); + if(p) { + log_info("LORA H: Replace name %s with name %s",p->name,lora_h[port_index][ipin].name); + log_info("LORA H: Replace pin number %u with number %u",p->pin.gpio,lora_h[port_index][ipin].pin.gpio); + *p = lora_h[port_index][ipin]; + } + ipin++; + } + + //add support for reset + sprintf(buf, "reset"); + attr = create_attribute(buf, MTS_ATTR_MODE_RW); + if (! attr) { + log_error("failed to create attribute [%s] for LORA in port %d", buf, port); + kfree(attrs); + return false; + } + attr->show = mts_attr_show_ap_gpio_pin; + attr->store = mts_attr_store_ap_gpio_pin; + attrs[index++] = &attr->attr; + + //GPIO1 - cdone on FPGA - input to CPU + sprintf(buf, "cdone"); + attr = create_attribute(buf, MTS_ATTR_MODE_RO); + if (! attr) { + log_error("failed to create attribute [%s] for LORA in port %d", buf, port); + kfree(attrs); + return false; + } + attr->show = mts_attr_show_ap_gpio_pin; + attrs[index++] = &attr->attr; + + //GPIO2 reset on FPGA - output from CPU + sprintf(buf, "creset"); + attr = create_attribute(buf, MTS_ATTR_MODE_RW); + if (! attr) { + log_error("failed to create attribute [%s] for LORA in port %d", buf, port); + kfree(attrs); + return false; + } + attr->show = mts_attr_show_ap_gpio_pin; + attr->store = mts_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); + } + } // add attributes for eeprom contents ret = ap_add_product_info_attributes(port, lora_hw_version, attrs, &index); - attrs[index] = NULL; - ap_attr_groups[port_index].attrs = attrs; + + attrs[index] = NULL; // Terminate the array. + ap_attr_groups[port_index].attrs = attrs; // attrs available for teardown. if (!ret) { log_error("failed to add product info attributes for LORA in port %d", port); return false; } - + log_info("ap_subdirs[port_index=%d] = %p ap_subdirs[port_index=%d]=%p", + port_index,ap_subdirs[port_index],port_index,&ap_attr_groups[port_index]); if (sysfs_create_group(ap_subdirs[port_index], &ap_attr_groups[port_index])) { log_error("sysfs_create_group failed for LORA in port %d", port); return false; |