From 2e5fcb88eb1d8efe81bbfbb141edb3d1572ac647 Mon Sep 17 00:00:00 2001 From: Mike Fiore Date: Mon, 13 Oct 2014 13:21:23 -0500 Subject: mts-io: add mtac-eth support, card gets ID'd correctly and eeprom attributes are in sysfs --- io-module/mtac.c | 2 +- io-module/mtac_eth.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++ io-module/mts_io.c | 6 +++ io-tool/mts-io-sysfs | 2 +- 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 io-module/mtac_eth.c diff --git a/io-module/mtac.c b/io-module/mtac.c index 9b27e0d..d25771d 100644 --- a/io-module/mtac.c +++ b/io-module/mtac.c @@ -93,7 +93,7 @@ static bool ap_add_product_info_attributes(int port, int type, struct attribute* return false; } kobj_attr->show = ap_show_product_info; - attrs[*index++] = &kobj_attr->attr; + attrs[(*index)++] = &kobj_attr->attr; break; case MTAC_GPIOB_0_0: diff --git a/io-module/mtac_eth.c b/io-module/mtac_eth.c new file mode 100644 index 0000000..09b52ee --- /dev/null +++ b/io-module/mtac_eth.c @@ -0,0 +1,110 @@ +static char* eth_gpio_pin_name_by_attr_name(const char* name, int port) { + log_error("attirbute name [%s] is invalid for ETH in port %d", name, port); + return ""; +} + +// 1 vendor-id +// 1 product-id +// 1 device-id +// 1 hw-version +// NULL +static size_t ap_eth_attrs_size = 5; + +static bool eth_setup(enum ap port) { + int i; + int port_index = port - 1; + int index = 0; + int count = 0; + int ret; + char buf[32]; + struct attribute **attrs; + + log_info("loading ETH accessory card in port %d", port); + + sprintf(buf, "ap%d", port); + ap_subdirs[port_index] = kobject_create_and_add(buf, &mts_io_platform_device->dev.kobj); + if (! ap_subdirs[port_index]) { + log_error("kobject_create_and_add for ETH in port %d failed", port); + return false; + } + + // create the link to the apX directory this card is in + // if we're in the first slot, we get plain "eth" + // if we're in a different slot, we might need to use "eth-2" to differentiate + if (port > 1) { + for (i = 1; i < port; i++) { + if (port_info[i - 1]) { + if (strstr(port_info[i - 1]->product_id, PRODUCT_ID_MTAC_ETH)) { + count++; + } + } + } + } + if (count > 0) { + sprintf(buf, "eth-%d", count + 1); + } else { + sprintf(buf, "eth"); + } + 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); + } + + attrs = kzalloc(sizeof(struct attribute*) * ap_eth_attrs_size, GFP_KERNEL); + if (! attrs) { + log_error("failed to allocate attribute space for port %d", port); + return false; + } + + // add attributes for eeprom contents + if (! ap_add_product_info_attributes(port, MTAC_ETH_0_0, attrs, &index)) { + log_error("failed to add product info attributes for ETH in port %d", port); + return false; + } + + attrs[index] = NULL; + + ap_attr_groups[port_index].attrs = attrs; + if (sysfs_create_group(ap_subdirs[port_index], &ap_attr_groups[port_index])) { + log_error("sysfs_create_group failed for ETH in port %d", port); + return false; + } + + return true; +} + +static bool eth_teardown(enum ap port) { + int i; + int port_index = port - 1; + struct attribute **attrs = ap_attr_groups[port_index].attrs; + + log_info("unloading ETH accessory card in port %d", port); + + // clean up allocated memory for attributes + for (i = 0; i < ap_eth_attrs_size; i++) { + if (attrs[i]) { + if (attrs[i]->name) + kfree(attrs[i]->name); + + kfree(attrs[i]); + } + } + + kfree(attrs); + + // clean up our "apX/" kobject if it exists + if (ap_subdirs[port_index]) { + kobject_put(ap_subdirs[port_index]); + } + + return true; +} + +bool set_eth_info(struct ap_info* info) { + snprintf(info->product_id, 32, "%s", PRODUCT_ID_MTAC_ETH); + info->setup = ð_setup; + info->teardown = ð_teardown; + info->gpio_pin_name_by_attr_name = ð_gpio_pin_name_by_attr_name; + + return true; +} diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 8a2de67..2d60a6d 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -97,6 +97,7 @@ static DEFINE_MUTEX(mts_io_mutex); #include "mtac.c" #include "mtac_gpiob.c" #include "mtac_mfser.c" +#include "mtac_eth.c" /* reset button handling */ #define RESET_CHECK_PER_SEC 8 @@ -400,6 +401,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_ETH)) { + if (! set_eth_info(port_info[port_index])) { + log_error("failed to set up eth port info"); + return false; + } } else { log_error("unknown accessory card [%s] in port %d", ap_eeprom[port_index].product_id, port); return false; diff --git a/io-tool/mts-io-sysfs b/io-tool/mts-io-sysfs index 7ec8da0..0d8ef24 100755 --- a/io-tool/mts-io-sysfs +++ b/io-tool/mts-io-sysfs @@ -102,7 +102,7 @@ usage() { FILENAME=${f##*/mts-io/} case $FILENAME in #mac addresses are read-only - mac-* ) + *mac-* ) ;; #product-id, device-id, vendor-id are all read-only *-id ) -- cgit v1.2.3