summaryrefslogtreecommitdiff
path: root/mtac_pulse.c
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2018-10-15 14:38:39 -0500
committerJohn Klug <john.klug@multitech.com>2018-10-15 14:38:39 -0500
commit77a9b455375b15279928c57ae08a845e18a87bb4 (patch)
treec7abb155b62b9e365435497ba7c9f4b7ab630078 /mtac_pulse.c
downloadmtac-pulse-77a9b455375b15279928c57ae08a845e18a87bb4.tar.gz
mtac-pulse-77a9b455375b15279928c57ae08a845e18a87bb4.tar.bz2
mtac-pulse-77a9b455375b15279928c57ae08a845e18a87bb4.zip
mtac pulse derived from mts-io 2.2.21.0.0
Diffstat (limited to 'mtac_pulse.c')
-rw-r--r--mtac_pulse.c302
1 files changed, 302 insertions, 0 deletions
diff --git a/mtac_pulse.c b/mtac_pulse.c
new file mode 100644
index 0000000..547cd02
--- /dev/null
+++ b/mtac_pulse.c
@@ -0,0 +1,302 @@
+#define DRIVER_VERSION "v1.0.0"
+#define DRIVER_AUTHOR "John Klug <john.klug@multitech.com>"
+#define DRIVER_DESC "MTAC Pulse Accessory Card"
+#define DRIVER_NAME "mtac-pulse"
+
+#include <linux/types.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/kmod.h>
+#include <linux/bitops.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/mtac.h>
+#include <linux/mts_io.h>
+
+/**********************************************************************
+ * 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 struct gpio_pin gpio_pins_mtcdt_mtac_pulse[] = {
+ // gpio pins for Accessory Card 1
+ {
+ .name = "AP1_RESET",
+ .pin = {
+ .gpio = AT91_PIN_PB12,
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "ap1-reset",
+ }
+ },
+ {
+ .name = "AP1_GPIO1",
+ .pin = {
+ .gpio = AT91_PIN_PC6,
+ .flags = GPIOF_OUT_INIT_LOW,
+ .label = "ap1-gpio1",
+ },
+ .active_low = 1,
+ },
+ // gpio pins for Accessory Card 2
+ {
+ .name = "AP2_RESET",
+ .pin = {
+ .gpio = AT91_PIN_PB13,
+ .flags = GPIOF_OUT_INIT_HIGH,
+ .label = "ap2-reset",
+ }
+ },
+ {
+ .name = "AP2_GPIO1",
+ .pin = {
+ .gpio = AT91_PIN_PC20,
+ .flags = GPIOF_OUT_INIT_LOW,
+ .label = "ap2-gpio1",
+ },
+ .active_low = 1,
+ }
+};
+
+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 "";
+ }
+ }
+ /* NOTREACHED */
+ 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;
+ int res;
+ struct kobject *subdir;
+
+ log_info("loading pulse accessory card in port %d", port);
+
+ sprintf(buf, "ap%d", port);
+ subdir = kobject_create_and_add(buf,
+ &mts_io_platform_device->dev.kobj);
+ if (!subdir) {
+ log_error("kobject_create_and_add in port %d failed", port);
+ return false;
+ }
+
+ mtac_set_port_pins(port_index,gpio_pins_mtcdt_mtac_pulse,subdir);
+
+ // 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 (mtac_port_info[i - 1]) {
+ if (strstr(mtac_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(mtac_port_info[port_index]->subdirs->parent,
+ mtac_port_info[port_index]->subdirs, buf);
+ if (ret) {
+ log_error("failed to link [%s] to [%s], %d", buf,
+ mtac_port_info[port_index]->subdirs->name, ret);
+ } else {
+ log_info("created link [%s] to [%s], success:%d", buf,
+ mtac_port_info[port_index]->subdirs->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 = mtac_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 = mtac_attr_show_ap_gpio_pin;
+ attr->store = mtac_attr_store_ap_gpio_pin;
+ attrs[index++] = &attr->attr;
+
+ sprintf(buf, "auto-boot");
+ attr = mtac_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 = mtac_attr_show_ap_gpio_pin;
+ attr->store = mtac_attr_store_ap_gpio_pin;
+ attrs[index++] = &attr->attr;
+
+ // add attributes for eeprom contents
+ if (! mtac_add_product_info_attributes(port, attrs, &index)) {
+ log_error("failed to add product info attributes for pulse in port %d",
+ port);
+ return false;
+ }
+
+ attrs[index] = NULL;
+
+ mtac_port_info[port_index]->attr_group.attrs = attrs;
+ if (sysfs_create_group(mtac_port_info[port_index]->subdirs,
+ &mtac_port_info[port_index]->attr_group)) {
+ log_error("sysfs_create_group failed for pulse in port %d", port);
+ return false;
+ }
+
+ /* override ap_reset output mode to open drain */
+ 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 = mtac_port_info[port_index]->attr_group.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 (mtac_port_info[port_index]->subdirs) {
+ kobject_put(mtac_port_info[port_index]->subdirs);
+ }
+ mtac_clear_port_pins(port_index);
+ return true;
+}
+
+void 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;
+}
+
+/*
+ * Loop through all the slots, and set up the
+ * mtac-xdot driver for all slots.
+ */
+static int __init mtac_pulse_init(void)
+{
+ int slot_count = 0;
+
+ slot_count = mtac_find(set_pulse_info,PRODUCT_ID_MTAC_PULSE);
+
+ if (slot_count < 1) {
+ log_debug("No MTAC PULSE found");
+ if (slot_count < 0)
+ return slot_count;
+ else
+ return -ENXIO;
+
+ }
+
+ return 0;
+}
+/* We can only tear down our own device */
+static void __exit mtac_pulse_exit(void)
+{
+ int port_index;
+ struct mts_ap_eeprom_layout *app;
+
+ for (port_index = 0; port_index < NUM_AP; port_index++) {
+ app = (struct mts_ap_eeprom_layout *)mts_ap_eeprom[port_index];
+ if (app && strstr(app->product_id, PRODUCT_ID_MTAC_XDOT)) {
+ if (mtac_port_info[port_index]->setup == &pulse_setup) {
+ mtac_port_info[port_index]->teardown(port_index+1);
+ kfree(mtac_port_info[port_index]);
+ }
+ }
+ }
+ log_info("exiting");
+}
+
+module_init(mtac_pulse_init);
+module_exit(mtac_pulse_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_VERSION(DRIVER_VERSION);
+MODULE_LICENSE("GPL");