summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2014-09-25 15:52:29 -0500
committerMike Fiore <mfiore@multitech.com>2014-09-25 15:52:29 -0500
commit8f1a0efb9e68a955544bce4bbc9dec6e4cb57f61 (patch)
tree086040622992cff66e83ee7ff98eea8ef5c71ea2
parentc83b0cf41999478d31c86fb50740d1fdf0fbb003 (diff)
downloadmts-io-8f1a0efb9e68a955544bce4bbc9dec6e4cb57f61.tar.gz
mts-io-8f1a0efb9e68a955544bce4bbc9dec6e4cb57f61.tar.bz2
mts-io-8f1a0efb9e68a955544bce4bbc9dec6e4cb57f61.zip
mts-io: add accessory card eeprom contents as read-only sysfs attribtues
-rw-r--r--io-module/mtac.c91
-rw-r--r--io-module/mtac_gpiob.c14
-rw-r--r--io-module/mtac_mfser.c12
-rw-r--r--io-module/mts_io.h1
4 files changed, 115 insertions, 3 deletions
diff --git a/io-module/mtac.c b/io-module/mtac.c
index b9a2520..99e2ce7 100644
--- a/io-module/mtac.c
+++ b/io-module/mtac.c
@@ -20,3 +20,94 @@ static struct kobj_attribute* create_attribute(const char* _name, umode_t _mode)
return _attr;
}
+
+static ssize_t ap_show_product_info(struct kobject *kobj, struct kobj_attribute *attr, char *buf) {
+ ssize_t value;
+ int port;
+
+ if (sscanf(attr->attr.name, "vendor-id:%d", &port) > 0) {
+ value = snprintf(buf, 32, "%s\n", ap_eeprom[port - 1].vendor_id);
+ } else if (sscanf(attr->attr.name, "product-id:%d", &port) > 0) {
+ value = snprintf(buf, 32, "%s\n", ap_eeprom[port - 1].product_id);
+ } else if (sscanf(attr->attr.name, "device-id:%d", &port) > 0) {
+ value = snprintf(buf, 32, "%s\n", ap_eeprom[port - 1].device_id);
+ } else if (sscanf(attr->attr.name, "hw-version:%d", &port) > 0) {
+ value = snprintf(buf, 32, "%s\n", ap_eeprom[port - 1].hw_version);
+ } else if (sscanf(attr->attr.name, "mac-eth:%d", &port) > 0) {
+ value = sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X\n",
+ ap_eeprom[port - 1].mac_addr[0],
+ ap_eeprom[port - 1].mac_addr[1],
+ ap_eeprom[port - 1].mac_addr[2],
+ ap_eeprom[port - 1].mac_addr[3],
+ ap_eeprom[port - 1].mac_addr[4],
+ ap_eeprom[port - 1].mac_addr[5]);
+ } else {
+ log_error("attribute '%s' not found", attr->attr.name);
+ value = -1;
+ }
+
+ return value;
+}
+
+static bool ap_add_product_info_attributes(int port, int type) {
+ struct kobj_attribute *attr;
+ char buf[32];
+
+ switch (type) {
+ case MTAC_ETH_0_0:
+ sprintf(buf, "mac-eth:%d", port);
+ attr = create_attribute(buf, MTS_ATTR_MODE_RO);
+ if (! attr) {
+ log_error("failed to create attribute[%s]", buf);
+ return false;
+ }
+ attr->show = ap_show_product_info;
+ device_attrs[device_attrs_size++] = &attr->attr;
+ break;
+
+ case MTAC_GPIOB_0_0:
+ case MTAC_MFSER_0_0:
+ break;
+ default:
+ log_error("invalid accessory card type");
+ return false;
+ }
+
+ sprintf(buf, "vendor-id:%d", port);
+ attr = create_attribute(buf, MTS_ATTR_MODE_RO);
+ if (! attr) {
+ log_error("failed to create attribute[%s]", buf);
+ return false;
+ }
+ attr->show = ap_show_product_info;
+ device_attrs[device_attrs_size++] = &attr->attr;
+
+ sprintf(buf, "product-id:%d", port);
+ attr = create_attribute(buf, MTS_ATTR_MODE_RO);
+ if (! attr) {
+ log_error("failed to create attribute[%s]", buf);
+ return false;
+ }
+ attr->show = ap_show_product_info;
+ device_attrs[device_attrs_size++] = &attr->attr;
+
+ sprintf(buf, "device-id:%d", port);
+ attr = create_attribute(buf, MTS_ATTR_MODE_RO);
+ if (! attr) {
+ log_error("failed to create attribute[%s]", buf);
+ return false;
+ }
+ attr->show = ap_show_product_info;
+ device_attrs[device_attrs_size++] = &attr->attr;
+
+ sprintf(buf, "hw-version:%d", port);
+ attr = create_attribute(buf, MTS_ATTR_MODE_RO);
+ if (! attr) {
+ log_error("failed to create attribute[%s]", buf);
+ return false;
+ }
+ attr->show = ap_show_product_info;
+ device_attrs[device_attrs_size++] = &attr->attr;
+
+ return true;
+}
diff --git a/io-module/mtac_gpiob.c b/io-module/mtac_gpiob.c
index f2cd9b2..ebbe0c6 100644
--- a/io-module/mtac_gpiob.c
+++ b/io-module/mtac_gpiob.c
@@ -380,7 +380,11 @@ static bool gpiob_spi_driver_setup(struct spi_driver *driver, const char *driver
// 2 LEDs
// 1 digital out enable
// 1 reset
-static int ap_gpiob_attrs_size = 15;
+// 1 vendor-id
+// 1 product-id
+// 1 device-id
+// 1 hw-version
+static int ap_gpiob_attrs_size = 19;
static bool gpiob_setup(enum ap port) {
int i;
@@ -449,7 +453,13 @@ static bool gpiob_setup(enum ap port) {
device_attrs[device_attrs_size++] = &attr->attr;
}
- // misc attributes
+ // add attributes for eeprom contents
+ if (! ap_add_product_info_attributes(port, MTAC_GPIOB_0_0)) {
+ log_error("failed to add product info attributes");
+ return false;
+ }
+
+ // add misc attributes
sprintf(buf, "ap-dout-enable:%d", port);
attr = create_attribute(buf, MTS_ATTR_MODE_RW);
if (! attr) {
diff --git a/io-module/mtac_mfser.c b/io-module/mtac_mfser.c
index 207180f..ed97cc6 100644
--- a/io-module/mtac_mfser.c
+++ b/io-module/mtac_mfser.c
@@ -187,7 +187,11 @@ static ssize_t mts_attr_store_mfser_mode(struct kobject *kobj,
// 1 serial mode
// 1 rs4xx term resistor
// 1 rts override
-static int ap_mfser_attrs_size = 3;
+// 1 vendor-id
+// 1 product-id
+// 1 device-id
+// 1 hw-version
+static int ap_mfser_attrs_size = 7;
static bool mfser_setup(enum ap port) {
int port_index = port - 1;
@@ -235,6 +239,12 @@ static bool mfser_setup(enum ap port) {
attr->store = mts_attr_store_ap_mfser_pin;
device_attrs[device_attrs_size++] = &attr->attr;
+ // add attributes for eeprom contents
+ if (! ap_add_product_info_attributes(port, MTAC_MFSER_0_0)) {
+ log_error("failed to add product info attributes");
+ return false;
+ }
+
return true;
}
diff --git a/io-module/mts_io.h b/io-module/mts_io.h
index 2aedd3e..44fb03c 100644
--- a/io-module/mts_io.h
+++ b/io-module/mts_io.h
@@ -81,6 +81,7 @@ enum {
MTAC_NONE,
MTAC_GPIOB_0_0,
MTAC_MFSER_0_0,
+ MTAC_ETH_0_0,
};
// GPIO pin types:input, output, open drain (1 = high Z, 0 = output low)