From 3e7f8d202e9728daafc985f36ff0fff24e1a4840 Mon Sep 17 00:00:00 2001 From: John Klug Date: Tue, 19 Jun 2018 16:04:47 -0500 Subject: XDOT feature --- io-module/mtac_eth.c | 4 +- io-module/mtac_gpiob.c | 16 +++++ io-module/mtac_mfser.c | 38 ++++++++++-- io-module/mtcdt.c | 156 ++++++++++++++++++++++++++++++++++++++++++++----- io-module/mts-io.c | 20 +++++-- io-module/mts_io.h | 3 +- 6 files changed, 209 insertions(+), 28 deletions(-) diff --git a/io-module/mtac_eth.c b/io-module/mtac_eth.c index 7a35ea5..99e8c1d 100644 --- a/io-module/mtac_eth.c +++ b/io-module/mtac_eth.c @@ -4,7 +4,7 @@ static char* eth_gpio_pin_name_by_attr_name(const char* name, int port) { if (! strcmp(name, "reset")) { return "ap1-reset"; } else { - log_error("attribute name [%s] is invalid for LORA in port %d", name, port); + log_error("attribute name [%s] is invalid for ETH in port %d", name, port); return ""; } @@ -12,7 +12,7 @@ static char* eth_gpio_pin_name_by_attr_name(const char* name, int port) { if (! strcmp(name, "reset")) { return "ap2-reset"; } else { - log_error("attribute name [%s] is invalid for LORA in port %d", name, port); + log_error("attribute name [%s] is invalid for ETH in port %d", name, port); return ""; } } diff --git a/io-module/mtac_gpiob.c b/io-module/mtac_gpiob.c index 3dbd828..17d0ac3 100644 --- a/io-module/mtac_gpiob.c +++ b/io-module/mtac_gpiob.c @@ -384,6 +384,7 @@ static bool gpiob_setup(enum ap port) { char buf[32]; struct kobj_attribute* attr; struct attribute **attrs; + int ipin = 0; log_info("loading GPIOB accessory card in port %d", port); @@ -422,6 +423,21 @@ static bool gpiob_setup(enum ap port) { return false; } + // Change GPIO 1-4 to match older levels of this driver + // Substitute pins for this port + log_info("Substitute pins"); + while(*(gpiob[port_index][ipin].name)) { + struct gpio_pin *p; + p = gpio_pin_by_num(gpiob[port_index][ipin].pin.gpio); + if(p) { + log_info("GPIOB: Replace name %s with name %s",p->name,gpiob[port_index][ipin].name); + log_info("GPIOB: Replace pin number %u with number %u",p->pin.gpio,gpiob[port_index][ipin].pin.gpio); + *p = gpiob[port_index][ipin]; + } + ipin++; + } + + // add digital inputs for (i = 0; i < 4; i++) { sprintf(buf, "din%d", i); diff --git a/io-module/mtac_mfser.c b/io-module/mtac_mfser.c index 26fd339..d8b0029 100644 --- a/io-module/mtac_mfser.c +++ b/io-module/mtac_mfser.c @@ -5,7 +5,9 @@ static char* mfser_gpio_pin_name_by_attr_name(const char* name, int port) { return "ap1-gpio3"; } else if (! strcmp(name, "rts-override")) { return "ap1-gpio4"; - } else { + } else if (! strcmp(name, "reset")) { + return "ap1-reset"; + } else { log_error("attirbute name [%s] is invalid for MFSER in port %d", name, port); return ""; } @@ -15,8 +17,10 @@ static char* mfser_gpio_pin_name_by_attr_name(const char* name, int port) { return "ap2-gpio3"; } else if (! strcmp(name, "rts-override")) { return "ap2-gpio4"; + } else if (! strcmp(name, "reset")) { + return "ap2-reset"; } else { - log_error("attirbute name [%s] is invalid for MFSER in port %d", name, port); + log_error("attribute name [%s] is invalid for MFSER in port %d", name, port); return ""; } } @@ -145,6 +149,7 @@ static ssize_t mts_attr_store_mfser_mode(struct kobject *kobj, return count; } +// 1 reset # Unused in MFSER, but similar MTAC-XDOT needs reset // 1 serial mode // 1 rs4xx term resistor // 1 rts override @@ -153,7 +158,7 @@ static ssize_t mts_attr_store_mfser_mode(struct kobject *kobj, // 1 device-id // 1 hw-version // NULL -static size_t ap_mfser_attrs_size = 8; +static size_t ap_mfser_attrs_size = 9; static bool mfser_setup(enum ap port) { int i; @@ -164,7 +169,8 @@ static bool mfser_setup(enum ap port) { char buf[32]; struct kobj_attribute* attr; struct attribute **attrs; - + int ipin = 0; + log_info("loading MFSER accessory card in port %d", port); sprintf(buf, "ap%d", port); @@ -201,6 +207,30 @@ static bool mfser_setup(enum ap port) { log_error("failed to allocate attribute space for port %d", port); return false; } + + // Change GPIO ports 3 and 4 to match older versions of this driver. + // Substitute pins for this port + log_info("Substitute pins"); + while(*(mfser[port_index][ipin].name)) { + struct gpio_pin *p; + p = gpio_pin_by_num(mfser[port_index][ipin].pin.gpio); + if(p) { + log_info("MFSER: Replace name %s with name %s",p->name,mfser[port_index][ipin].name); + log_info("MFSER: Replace pin number %u with number %u",p->pin.gpio,mfser[port_index][ipin].pin.gpio); + *p = mfser[port_index][ipin]; + } + ipin++; + } + + sprintf(buf, "reset"); + attr = create_attribute(buf, MTS_ATTR_MODE_RW); + if (! attr) { + log_error("failed to create attribute [%s] for MFSER in port %d", buf, port); + return false; + } + attr->show = mts_attr_show_ap_gpio_pin; + attr->store = mts_attr_store_ap_gpio_pin; + attrs[index++] = &attr->attr; sprintf(buf, "serial-mode"); attr = create_attribute(buf, MTS_ATTR_MODE_RW); diff --git a/io-module/mtcdt.c b/io-module/mtcdt.c index 0fca7aa..e8aed3b 100644 --- a/io-module/mtcdt.c +++ b/io-module/mtcdt.c @@ -145,7 +145,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_0[] = { .name = "AP1_GPIO1", .pin = { .gpio = AT91_PIN_PC6, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap1-gpio1", }, .active_low = 1, @@ -154,7 +154,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_0[] = { .name = "AP1_GPIO2", .pin = { .gpio = AT91_PIN_PC7, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap1-gpio2", } }, @@ -162,7 +162,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_0[] = { .name = "AP1_GPIO3", .pin = { .gpio = AT91_PIN_PC8, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap1-gpio3", } }, @@ -170,7 +170,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_0[] = { .name = "AP1_GPIO4", .pin = { .gpio = AT91_PIN_PC9, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap1-gpio4", } }, @@ -212,7 +212,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_0[] = { .name = "AP2_GPIO1", .pin = { .gpio = AT91_PIN_PC20, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap2-gpio1", }, .active_low = 1, @@ -221,7 +221,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_0[] = { .name = "AP2_GPIO2", .pin = { .gpio = AT91_PIN_PC21, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap2-gpio2", } }, @@ -229,7 +229,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_0[] = { .name = "AP2_GPIO3", .pin = { .gpio = AT91_PIN_PC22, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap2-gpio3", } }, @@ -237,7 +237,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_0[] = { .name = "AP2_GPIO4", .pin = { .gpio = AT91_PIN_PC23, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap2-gpio4", } }, @@ -403,7 +403,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_1[] = { .name = "AP1_GPIO1", .pin = { .gpio = AT91_PIN_PC6, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap1-gpio1", }, .active_low = 1, @@ -412,7 +412,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_1[] = { .name = "AP1_GPIO2", .pin = { .gpio = AT91_PIN_PC7, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap1-gpio2", } }, @@ -420,7 +420,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_1[] = { .name = "AP1_GPIO3", .pin = { .gpio = AT91_PIN_PC8, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap1-gpio3", } }, @@ -428,7 +428,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_1[] = { .name = "AP1_GPIO4", .pin = { .gpio = AT91_PIN_PC9, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap1-gpio4", } }, @@ -471,7 +471,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_1[] = { .name = "AP2_GPIO1", .pin = { .gpio = AT91_PIN_PC20, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap2-gpio1", }, .active_low = 1, @@ -480,7 +480,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_1[] = { .name = "AP2_GPIO2", .pin = { .gpio = AT91_PIN_PC21, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap2-gpio2", } }, @@ -488,7 +488,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_1[] = { .name = "AP2_GPIO3", .pin = { .gpio = AT91_PIN_PC22, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap2-gpio3", } }, @@ -496,7 +496,7 @@ static struct gpio_pin gpio_pins_mtcdt_0_1[] = { .name = "AP2_GPIO4", .pin = { .gpio = AT91_PIN_PC23, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_IN, .label = "ap2-gpio4", } }, @@ -650,6 +650,130 @@ static struct gpio_pin lora_h[3 /* Port */][3 /* Pin */] = { { }, }; +// GPIO Board +static struct gpio_pin gpiob[3 /* Port */][5 /* Pin */] = { + { // port 1 of 2 + { + .name = "AP1_GPIO1", + .pin = { + .gpio = AT91_PIN_PC6, + .flags = GPIOF_OUT_INIT_LOW, + .label = "ap1-gpio1", + }, + .active_low = 1, + }, + { + .name = "AP1_GPIO2", + .pin = { + .gpio = AT91_PIN_PC7, + .flags = GPIOF_OUT_INIT_LOW, + .label = "ap1-gpio2", + } + }, + { + .name = "AP1_GPIO3", + .pin = { + .gpio = AT91_PIN_PC8, + .flags = GPIOF_OUT_INIT_LOW, + .label = "ap1-gpio3", + } + }, + { + .name = "AP1_GPIO4", + .pin = { + .gpio = AT91_PIN_PC9, + .flags = GPIOF_OUT_INIT_LOW, + .label = "ap1-gpio4", + } + }, + { }, + }, // End of port 1 +// GPIOB AP2 + { // Port 2 of 2 + { + .name = "AP2_GPIO1", + .pin = { + .gpio = AT91_PIN_PC20, + .flags = GPIOF_OUT_INIT_LOW, + .label = "ap2-gpio1", + }, + .active_low = 1, + }, + { + .name = "AP2_GPIO2", + .pin = { + .gpio = AT91_PIN_PC21, + .flags = GPIOF_OUT_INIT_LOW, + .label = "ap2-gpio2", + } + }, + { + .name = "AP2_GPIO3", + .pin = { + .gpio = AT91_PIN_PC22, + .flags = GPIOF_OUT_INIT_LOW, + .label = "ap2-gpio3", + } + }, + { + .name = "AP2_GPIO4", + .pin = { + .gpio = AT91_PIN_PC23, + .flags = GPIOF_OUT_INIT_LOW, + .label = "ap2-gpio4", + } + }, + { }, + }, // End of port 2 + { }, +}; + + +// MFSER AP1 +static struct gpio_pin mfser[3 /* Port */][3 /* Pin */] = { + { // port 1 of 2 + { + .name = "AP1_GPIO3", + .pin = { + .gpio = AT91_PIN_PC8, + .flags = GPIOF_OUT_INIT_LOW, + .label = "ap1-gpio3", + } + }, + { + .name = "AP1_GPIO4", + .pin = { + .gpio = AT91_PIN_PC9, + .flags = GPIOF_OUT_INIT_LOW, + .label = "ap1-gpio4", + } + }, + { }, + }, // End of port 1 +// MFSER + { // Port 2 of 2 + { + .name = "AP2_GPIO3", + .pin = { + .gpio = AT91_PIN_PC22, + .flags = GPIOF_OUT_INIT_LOW, + .label = "ap2-gpio3", + } + }, + { + .name = "AP2_GPIO4", + .pin = { + .gpio = AT91_PIN_PC23, + .flags = GPIOF_OUT_INIT_LOW, + .label = "ap2-gpio4", + } + }, + { }, + }, // End of port 2 + { }, +}; + + 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", diff --git a/io-module/mts-io.c b/io-module/mts-io.c index 31f69f9..c8e0f4b 100644 --- a/io-module/mts-io.c +++ b/io-module/mts-io.c @@ -613,7 +613,11 @@ static bool load_port(int port) { memcpy(&ap_eeprom[port_index], mts_ap_eeprom[port_index], sizeof(mts_ap_eeprom[port_index])); if (mts_ap_eeprom[port_index][0] == 0xFF) { - log_error("uninitialized eeprom on accessory card %d", port); + log_error("uninitialized eeprom on accessory card %d -- assuming MFSER", port); + if (! set_mfser_info(port_info[port_index])) { + log_error("failed to set up mfser port info"); + return false; + } } else if (mts_ap_eeprom[port_index][0] == 0x00) { log_info("no accessory card inserted in port %d", port); } else { @@ -633,6 +637,11 @@ static bool load_port(int port) { log_error("failed to set up mfser port info"); return false; } + } else if (strstr(ap_eeprom[port_index].product_id, PRODUCT_ID_MTAC_XDOT)) { + if (! set_mfser_info(port_info[port_index])) { + log_error("failed to set up xdot port info"); + return false; + } } else if (strstr(ap_eeprom[port_index].product_id, PRODUCT_ID_MTAC_ETH)) { if (! set_eth_info(port_info[port_index])) { log_error("failed to set up eth port info"); @@ -644,10 +653,11 @@ static bool load_port(int port) { return false; } } else { - log_error("unknown accessory card [%s] in port %d", ap_eeprom[port_index].product_id, port); - kfree(port_info[port_index]); - port_info[port_index] = NULL; - return false; + log_error("unknown accessory card [%s] in port %d -- assuming MFSER", ap_eeprom[port_index].product_id, port); + if (! set_mfser_info(port_info[port_index])) { + log_error("failed to set up mfser port info"); + return false; + } } log_info("accessory card %d vendor-id: %.32s", port, ap_eeprom[port_index].vendor_id); diff --git a/io-module/mts_io.h b/io-module/mts_io.h index 7c2f45b..84a2349 100644 --- a/io-module/mts_io.h +++ b/io-module/mts_io.h @@ -5,7 +5,7 @@ #include -#define DRIVER_VERSION "v2.0.7" +#define DRIVER_VERSION "v2.1.0" #define DRIVER_AUTHOR "James Maki " #define DRIVER_DESC "MTS-IO Controller" #define DRIVER_NAME "mts-io" @@ -56,6 +56,7 @@ struct device_attribute mts_dev_name = { \ #define PRODUCT_ID_MTAC_GPIOB "MTAC-GPIOB" #define PRODUCT_ID_MTAC_MFSER "MTAC-MFSER" +#define PRODUCT_ID_MTAC_XDOT "MTAC-XDOT" #define PRODUCT_ID_MTAC_ETH "MTAC-ETH" #define PRODUCT_ID_MTAC_LORA "MTAC-LORA" #define PRODUCT_ID_MTHS "MTHS" -- cgit v1.2.3