summaryrefslogtreecommitdiff
path: root/io-module/mts_io.c
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2014-01-31 14:59:20 -0600
committerMike Fiore <mfiore@multitech.com>2014-01-31 14:59:20 -0600
commit935ba9982e7afb39489f5a52e4a671ebbfed6fe7 (patch)
treeaf4f9806b9792a79ec54f88ed030a660204c47c0 /io-module/mts_io.c
parent8e600fd2726f303694fdb87f2eb08ddc78f5c3ee (diff)
downloadmts-io-935ba9982e7afb39489f5a52e4a671ebbfed6fe7.tar.gz
mts-io-935ba9982e7afb39489f5a52e4a671ebbfed6fe7.tar.bz2
mts-io-935ba9982e7afb39489f5a52e4a671ebbfed6fe7.zip
set up handling of different daughter card types
add GPIO daughter card attributes to sysfs if card is installed
Diffstat (limited to 'io-module/mts_io.c')
-rw-r--r--io-module/mts_io.c119
1 files changed, 117 insertions, 2 deletions
diff --git a/io-module/mts_io.c b/io-module/mts_io.c
index a8e85e3..a7a5d75 100644
--- a/io-module/mts_io.c
+++ b/io-module/mts_io.c
@@ -95,6 +95,7 @@ bool daughter_card_capable = false;
bool has_daughter_card = false;
static uint8_t mts_product_id;
+static uint8_t mts_dc_product_id;
static uint8_t has_spi_sout;
static uint8_t has_spi_din;
static uint8_t has_spi_dout;
@@ -2497,6 +2498,43 @@ static DEVICE_ATTR_RO_MTS(dev_attr_wifi_mac, "mac-wifi",
static DEVICE_ATTR_RO_MTS(dev_attr_eth_mac, "mac-eth",
mts_attr_show_product_info);
+static ssize_t mts_attr_show_dc_din(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ /* TODO: actually write this function */
+ return sprintf(buf, "%d\n", 0);
+}
+
+static ssize_t mts_attr_store_dc_dout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+{
+ /* TODO: actually write this function */
+ return 0;
+}
+
+static ssize_t mts_attr_show_dc_dout(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ /* TODO: actually write this function */
+ return sprintf(buf, "%d\n", 0);
+}
+
+static ssize_t mts_attr_show_dc_adc(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ /* TODO: actually write this function */
+ return sprintf(buf, "%lu\n", (unsigned long) 0);
+}
+
+/* daughter card gpio */
+static DEVICE_ATTR_RO_MTS(dev_attr_dc_din0, "dc-din0", mts_attr_show_dc_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_dc_din1, "dc-din1", mts_attr_show_dc_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_dc_din2, "dc-din2", mts_attr_show_dc_din);
+static DEVICE_ATTR_RO_MTS(dev_attr_dc_din3, "dc-din3", mts_attr_show_dc_din);
+static DEVICE_ATTR_MTS(dev_attr_dc_dout0, "dc-dout0", mts_attr_show_dc_dout, mts_attr_store_dc_dout);
+static DEVICE_ATTR_MTS(dev_attr_dc_dout1, "dc-dout1", mts_attr_show_dc_dout, mts_attr_store_dc_dout);
+static DEVICE_ATTR_MTS(dev_attr_dc_dout2, "dc-dout2", mts_attr_show_dc_dout, mts_attr_store_dc_dout);
+static DEVICE_ATTR_MTS(dev_attr_dc_dout3, "dc-dout3", mts_attr_show_dc_dout, mts_attr_store_dc_dout);
+static DEVICE_ATTR_RO_MTS(dev_attr_dc_adc0, "dc-adc0", mts_attr_show_dc_adc);
+static DEVICE_ATTR_RO_MTS(dev_attr_dc_adc1, "dc-adc1", mts_attr_show_dc_adc);
+static DEVICE_ATTR_RO_MTS(dev_attr_dc_adc2, "dc-adc2", mts_attr_show_dc_adc);
+
static struct attribute *mt100eocg_platform_attributes[] = {
&dev_attr_vendor_id.attr,
&dev_attr_product_id.attr,
@@ -2544,7 +2582,7 @@ static struct attribute_group mt100eocg_platform_attribute_group = {
.attrs = mt100eocg_platform_attributes
};
-static struct attribute *mtr2_platform_attributes[] = {
+struct attribute *mtr2_platform_attributes[] = {
&dev_attr_vendor_id.attr,
&dev_attr_product_id.attr,
&dev_attr_device_id.attr,
@@ -2584,6 +2622,38 @@ static struct attribute *mtr2_platform_attributes[] = {
&dev_attr_board_temperature.attr,
+ /* extra space for the daughter card attributes */
+ NULL, // index 34
+ NULL, // index 35
+ NULL, // index 36
+ NULL, // index 37
+ NULL, // index 38
+ NULL, // index 39
+ NULL, // index 40
+ NULL, // index 41
+ NULL, // index 42
+ NULL, // index 43
+ NULL, // index 44
+ NULL, // index 45
+ NULL, // index 46
+ NULL,
+};
+
+static struct attribute *mtr2_daughter_card_attributes[] = {
+ &dev_attr_dc_din0.attr,
+ &dev_attr_dc_din1.attr,
+ &dev_attr_dc_din2.attr,
+ &dev_attr_dc_din3.attr,
+
+ &dev_attr_dc_dout0.attr,
+ &dev_attr_dc_dout1.attr,
+ &dev_attr_dc_dout2.attr,
+ &dev_attr_dc_dout3.attr,
+
+ &dev_attr_dc_adc0.attr,
+ &dev_attr_dc_adc1.attr,
+ &dev_attr_dc_adc2.attr,
+
NULL,
};
@@ -2591,6 +2661,32 @@ static struct attribute_group mtr2_platform_attribute_group = {
.attrs = mtr2_platform_attributes
};
+bool mtr2_add_daughter_card_attributes()
+{
+ size_t platform_attrs_size = sizeof(mtr2_platform_attributes) / sizeof(struct attribute *);
+ size_t daughter_card_attrs_size = sizeof(mtr2_daughter_card_attributes) / sizeof(struct attribute *);
+ size_t platform_attrs_index;
+ size_t daughter_card_attrs_index;
+ size_t copy_length = daughter_card_attrs_size - 1; /* don't need to copy the NULL at the end */
+
+ for (platform_attrs_index = 0; platform_attrs_index < platform_attrs_size; platform_attrs_index++) {
+ if (! mtr2_platform_attributes[platform_attrs_index]) {
+ break;
+ }
+ }
+
+ if (platform_attrs_size < platform_attrs_index + daughter_card_attrs_size) {
+ log_error("not enough room for MTR2 daughter card attributes!");
+ return false;
+ }
+
+ for (daughter_card_attrs_index = 0; daughter_card_attrs_index < copy_length; daughter_card_attrs_index++, platform_attrs_index++) {
+ mtr2_platform_attributes[platform_attrs_index] = mtr2_daughter_card_attributes[daughter_card_attrs_index];
+ }
+
+ return true;
+}
+
static struct attribute *mtcdp_platform_attributes[] = {
&dev_attr_vendor_id.attr,
&dev_attr_product_id.attr,
@@ -3052,6 +3148,7 @@ static int __init mts_io_init(void)
}
if (daughter_card_capable) {
+ mts_dc_product_id = MTDC_NONE;
ret = mts_dc_eeprom_load();
if (ret) {
/* error reading the EEPROM from the daughter card */
@@ -3062,7 +3159,25 @@ static int __init mts_io_init(void)
/* boolean flag wasn't set, no card */
log_info("no daughter card is inserted");
} else {
- /* TODO: handle daughter card specific configuration here */
+ /* no error and we have a daughter card */
+ if (strstr(dc_eeprom.product_id, PRODUCT_ID_MTDC_GPIOB)) {
+ mts_dc_product_id = MTDC_GPIOB_0_0;
+ }
+
+ switch(mts_dc_product_id) {
+ case MTDC_GPIOB_0_0:
+ log_info("adding GPIO daughter card attributes");
+ if (! mtr2_add_daughter_card_attributes()) {
+ log_error("failed to add GPIO daughter card attributes");
+ goto error1;
+ } else {
+ log_info("successfully added GPIO daughter card attributes");
+ }
+ break;
+
+ default:
+ log_info("daughter card '%s' currently unsupported", dc_eeprom.product_id);
+ }
}
}