summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2018-08-06 18:03:48 -0500
committerJohn Klug <john.klug@multitech.com>2018-08-06 18:03:48 -0500
commit342ba736041efa33ccc5c76b67e7214c5cbcd6fd (patch)
tree4e079c024db44d128969d749a6d8ce4284c04616
parent12eb0abd4bb74af5a2f45485e1a6b53b1cd422bc (diff)
parent00608c8b64d34dbfe864dfcec44b8a3fbff2db67 (diff)
downloadmts-io-342ba736041efa33ccc5c76b67e7214c5cbcd6fd.tar.gz
mts-io-342ba736041efa33ccc5c76b67e7214c5cbcd6fd.tar.bz2
mts-io-342ba736041efa33ccc5c76b67e7214c5cbcd6fd.zip
Merge branch 'mtac-pulse' into 'master'
added MTAC Pulse card support for Blue Pillar See merge request !15
-rw-r--r--io-module/mtac.c1
-rw-r--r--io-module/mtac_pulse.c199
-rw-r--r--io-module/mts-io.c6
-rw-r--r--io-module/mts_io.h2
4 files changed, 208 insertions, 0 deletions
diff --git a/io-module/mtac.c b/io-module/mtac.c
index 4cbc31f..f0f1999 100644
--- a/io-module/mtac.c
+++ b/io-module/mtac.c
@@ -108,6 +108,7 @@ static bool ap_add_product_info_attributes(int port, int type, struct attribute*
case MTAC_GPIOB_0_0:
case MTAC_MFSER_0_0:
+ case MTAC_PULSE_1_0:
break;
case MTAC_LORA_0_0:
diff --git a/io-module/mtac_pulse.c b/io-module/mtac_pulse.c
new file mode 100644
index 0000000..dae4fa6
--- /dev/null
+++ b/io-module/mtac_pulse.c
@@ -0,0 +1,199 @@
+/**********************************************************************
+ * COPYRIGHT 2012-2018 CONNECTED DEVELOPMENT, LLC
+ *
+ * ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF
+ * CONNECTED DEVELOPMENT, LLC.
+ *
+ * CONNECTED DEVELOPMENT, LLC - CONFIDENTIAL AND PROPRIETARY
+ * INFORMATION AND/OR TRADE SECRET.
+ *
+ * NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION,
+ * DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL
+ * INFORMATION AND PROPERTY OF CONNECTED DEVELOPMENT, LLC.
+ * USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A
+ * WRITTEN AGREEMENT SIGNED BY CONNECTED DEVELOPMENT, LLC IS PROHIBITED.
+ *
+ ***********************************************************************/
+
+static char* pulse_gpio_pin_name_by_attr_name(const char *name, int port) {
+ switch (port) {
+ case port_1:
+ if (!strcmp(name, "reset")) {
+ return "ap1-reset";
+ } else if (!strcmp(name, "auto-boot")) {
+ return "ap1-gpio1";
+ } else {
+ log_error("attirbute name [%s] is invalid for pulse in port %d",
+ name, port);
+ return "";
+ }
+
+ case port_2:
+ if (!strcmp(name, "reset")) {
+ return "ap2-reset";
+ } else if (!strcmp(name, "auto-boot")) {
+ return "ap2-gpio1";
+ } else {
+ log_error("attirbute name [%s] is invalid for pulse in port %d",
+ name, port);
+ return "";
+ }
+ }
+}
+
+// 1 reset
+// 1 auto-boot
+// 1 vendor-id
+// 1 product-id
+// 1 device-id
+// 1 hw-version
+// NULL
+static size_t ap_pulse_attrs_size = 7;
+
+static bool pulse_setup(enum ap port) {
+ int i;
+ int port_index = port - 1;
+ int index = 0;
+ int count = 0;
+ int ret;
+ char buf[32];
+ struct kobj_attribute *attr;
+ struct attribute **attrs;
+
+ log_info("loading pulse 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 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 "pulse"
+ // if we're in a different slot, we might need to use "pulse-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_PULSE)) {
+ count++;
+ }
+ }
+ }
+ }
+ if (count > 0) {
+ sprintf(buf, "pulse-%d", count + 1);
+ } else {
+ sprintf(buf, "pulse");
+ }
+ 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_pulse_attrs_size,
+ GFP_KERNEL);
+ if (!attrs) {
+ log_error("failed to allocate attribute space for port %d", port);
+ return false;
+ }
+
+ sprintf(buf, "reset");
+ attr = create_attribute(buf, MTS_ATTR_MODE_RW);
+ if (!attr) {
+ log_error("failed to create attribute [%s] for pulse 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;
+
+ sprintf(buf, "auto-boot");
+ attr = create_attribute(buf, MTS_ATTR_MODE_RW);
+ if (!attr) {
+ log_error("failed to create attribute [%s] for pulse 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;
+
+ // add attributes for eeprom contents
+ if (!ap_add_product_info_attributes(port, MTAC_PULSE_1_0, attrs, &index)) {
+ log_error("failed to add product info attributes for pulse 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 pulse in port %d", port);
+ return false;
+ }
+
+ /* override ap_reset output mode to open drain */
+ int res;
+ if (port == 1) {
+ res = gpio_request_one(AT91_PIN_PB12, GPIOF_OUT_INIT_HIGH | GPIOF_OPEN_DRAIN, "ap1-reset");
+ } else {
+ res = gpio_request_one(AT91_PIN_PB13, GPIOF_OUT_INIT_HIGH | GPIOF_OPEN_DRAIN, "ap2-reset");
+ }
+ if (res != 0)
+ {
+ log_error("failed to change ap%d_reset to open drain output", port);
+ }
+
+ return true;
+}
+
+static bool pulse_teardown(enum ap port) {
+ int i;
+ int port_index = port - 1;
+ struct attribute **attrs = ap_attr_groups[port_index].attrs;
+
+ log_info("unloading pulse accessory card in port %d", port);
+
+ if (attrs) {
+ // clean up allocated memory for attributes
+ for (i = 0; i < ap_pulse_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_pulse_info(struct ap_info *info) {
+ snprintf(info->product_id, 32, "%s", PRODUCT_ID_MTAC_PULSE);
+ info->setup = &pulse_setup;
+ info->teardown = &pulse_teardown;
+ info->gpio_pin_name_by_attr_name = &pulse_gpio_pin_name_by_attr_name;
+
+ return true;
+}
+
diff --git a/io-module/mts-io.c b/io-module/mts-io.c
index 31f69f9..180a7b0 100644
--- a/io-module/mts-io.c
+++ b/io-module/mts-io.c
@@ -607,6 +607,7 @@ static struct ap_info* port_info[NUM_AP];
#include "mtac_mfser.c"
#include "mtac_eth.c"
#include "mtac_lora.c"
+#include "mtac_pulse.c"
static bool load_port(int port) {
int port_index = port - 1;
@@ -643,6 +644,11 @@ static bool load_port(int port) {
log_error("failed to set up lora port info");
return false;
}
+ } else if (strstr(ap_eeprom[port_index].product_id, PRODUCT_ID_MTAC_PULSE)) {
+ if (! set_pulse_info(port_info[port_index])) {
+ log_error("failed to set up pulse port info");
+ return false;
+ }
} else {
log_error("unknown accessory card [%s] in port %d", ap_eeprom[port_index].product_id, port);
kfree(port_info[port_index]);
diff --git a/io-module/mts_io.h b/io-module/mts_io.h
index 43523ea..780ee18 100644
--- a/io-module/mts_io.h
+++ b/io-module/mts_io.h
@@ -59,6 +59,7 @@ struct device_attribute mts_dev_name = { \
#define PRODUCT_ID_MTAC_ETH "MTAC-ETH"
#define PRODUCT_ID_MTAC_LORA "MTAC-LORA"
#define PRODUCT_ID_MTHS "MTHS"
+#define PRODUCT_ID_MTAC_PULSE "MTAC-PULSE"
/* Hardware version must be fewer characters than hw_version
in struct mts_ap_eeprom_layout */
@@ -112,6 +113,7 @@ enum {
MTAC_LORA_1_0,
MTAC_LORA_1_1,
MTAC_LORA_1_5,
+ MTAC_PULSE_1_0,
};
struct gpio_pin {