summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2022-03-01 18:22:54 -0600
committerJohn Klug <john.klug@multitech.com>2022-03-01 18:25:15 -0600
commitfcc334385cccb84bd9c5f758f129bd959a8b5f69 (patch)
treed0d2ed792a7fff36f26a73f70b11b083c5f34404
parente6c76e4b3fa7df78186c3381ea4aadf7b9decd0c (diff)
downloadmtac-xdot-master.tar.gz
mtac-xdot-master.tar.bz2
mtac-xdot-master.zip
Move mtac-xdot to gpiod driverHEAD2.0.0master
-rw-r--r--AUTHORS3
-rw-r--r--README6
-rw-r--r--mtac_xdot.c99
3 files changed, 49 insertions, 59 deletions
diff --git a/AUTHORS b/AUTHORS
index f8e3fb5..d338ebe 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,2 +1 @@
-James Maki <jmaki@multitech.com>
-John Klug <john.klug@multitech.com>
+Multi-Tech <info@multitech.com>
diff --git a/README b/README
index 2ece0ee..9466d61 100644
--- a/README
+++ b/README
@@ -8,9 +8,5 @@ of this.
Documentation for this board is here:
-http://www.multitech.net/developer/software/mlinux/using-mlinux/mlinux-using-accessory-cards/mtac-xdot-usage/
+https://www.multitech.net/developer/products/multiconnect-conduit-platform/accessory-cards/mtac-xdot/
-An init script can look in:
-/lib/modules/$(uname -r)/extra/mtac_xdot.ko
-
-to find the driver.
diff --git a/mtac_xdot.c b/mtac_xdot.c
index 2035182..af0645b 100644
--- a/mtac_xdot.c
+++ b/mtac_xdot.c
@@ -1,11 +1,9 @@
-#define DRIVER_VERSION "v1.1.1"
+#define DRIVER_VERSION "v2.0.0"
#define DRIVER_AUTHOR "Multi-Tech"
#define DRIVER_DESC "MTS XDOT (LoRa) Accessory Card"
#define DRIVER_NAME "mtac-xdot"
-#define DEBUG 0
#include <linux/types.h>
-#include <linux/gpio.h>
#include <linux/platform_device.h>
#include <linux/kmod.h>
#include <linux/bitops.h>
@@ -13,33 +11,30 @@
#include <linux/slab.h>
#include <linux/mtac.h>
#include <linux/mts_io.h>
-#ifdef TI43X
-#include <linux/ti43x_gpio.h>
-#endif
-#ifdef SAM9G25
-#include <linux/sam9g25_gpio.h>
-#endif
+#include <linux/gpio/consumer.h>
static struct gpio_pin gpio_pins_mtcdt_mtac_xdot[] = {
// gpio pins for Accessory Card 1
{
- .name = "AP1_RESET",
+ .name = "AP1_NRESET",
.pin = {
- .gpio = M_AP1_NRESET,
- .flags = GPIOF_OUT_INIT_HIGH, // Only when not flashing
+ .gpio = ~0U,
+ .flags = GPIOD_OUT_HIGH, // Only when not flashing
.label = "ap1-reset",
- }
+ },
+ .do_gpio_desc = 1,
},
-
+
// gpio pins for Accessory Card 2
{
- .name = "AP2_RESET",
+ .name = "AP2_NRESET",
.pin = {
- .gpio = M_AP2_NRESET,
- .flags = GPIOF_OUT_INIT_HIGH, // Only when not flashing
+ .gpio = ~0U,
+ .flags = GPIOD_OUT_HIGH,
.label = "ap2-reset",
- }
+ },
+ .do_gpio_desc = 1,
},
{ },
};
@@ -54,11 +49,11 @@ static ssize_t xdot_show_reset(struct kobject *kobj,
int port;
struct gpio_pin *pin;
- log_debug("xdot_show_reset: enter");
+ dev_dbg(&mts_io_platform_device->dev,"xdot_show_reset: enter\n");
port = mtac_port_from_kobject(kobj);
- log_debug("xdot_show_reset: %d",reset_state[port - 1]);
+ dev_dbg(&mts_io_platform_device->dev,"xdot_show_reset: %d\n",reset_state[port - 1]);
if (port < 1) {
- log_error("mtac_port_from_kobject returned %d", port);
+ dev_err(&mts_io_platform_device->dev,"mtac_port_from_kobject returned %d\n", port);
return -EINVAL;
}
@@ -67,11 +62,11 @@ static ssize_t xdot_show_reset(struct kobject *kobj,
return -ENODEV;
}
- log_debug("mtac_attr_show_ap_gpio_pin: State of mtac mutex is %s",
+ dev_dbg(&mts_io_platform_device->dev,"mtac_attr_show_ap_gpio_pin: State of mtac mutex is %s\n",
mutex_is_locked(&mtac_mutex) ? "locked" : "unlocked");
mutex_lock(&mtac_mutex);
- value = gpio_get_value(pin->pin.gpio);
+ value = gpiod_get_value(pin->desc);
if (value < 0) {
mutex_unlock(&mtac_mutex);
return -ENODEV;
@@ -92,10 +87,10 @@ static ssize_t xdot_store_reset(struct kobject *kobj,
int port, port_index;
struct gpio_pin *pin;
- log_debug("xdot_store_reset: store %s",buf);
+ dev_dbg(&mts_io_platform_device->dev,"xdot_store_reset: store %s\n",buf);
port = mtac_port_from_kobject(kobj);
if (port < 1) {
- log_error("mtac_port_from_kobject returned %d", port);
+ dev_err(&mts_io_platform_device->dev,"mtac_port_from_kobject returned %d\n", port);
return -EINVAL;
}
port_index = port - 1;
@@ -111,10 +106,10 @@ static ssize_t xdot_store_reset(struct kobject *kobj,
if(value < -1 || value > 1)
return EINVAL;
- log_debug("xdot_store_reset: old %d new %d",reset_state[port_index],value);
+ dev_dbg(&mts_io_platform_device->dev,"xdot_store_reset: old %d new %d\n",reset_state[port_index],value);
- log_debug("mtac_attr_store_ap_gpio_pin: State of mtac mutex is %s",
+ dev_dbg(&mts_io_platform_device->dev,"mtac_attr_store_ap_gpio_pin: State of mtac mutex is %s\n",
mutex_is_locked(&mtac_mutex) ? "locked" : "unlocked");
mutex_lock(&mtac_mutex);
@@ -127,13 +122,13 @@ static ssize_t xdot_store_reset(struct kobject *kobj,
if (value == -1) {
// Wrong GPIO flags, so change to input
- gpio_free(pin->pin.gpio);
- ret = gpio_request_one(pin->pin.gpio, GPIOF_IN, pin->pin.label);
- if(ret) {
- log_error("Could not request pin %s (%d)", pin->name, ret);
+ gpiod_put(pin->desc);
+ pin->desc = devm_gpiod_get_optional(&mts_io_platform_device->dev, pin->name, GPIOD_IN);
+ if (IS_ERR(pin->desc)) {
+ dev_err(&mts_io_platform_device->dev,"Could not request pin %s (%d)\n", pin->name, ret);
reset_state[port_index] = -2; // Invalid state
mutex_unlock(&mtac_mutex);
- return EINVAL;
+ return PTR_ERR(pin->desc);
}
reset_state[port_index] = -1;
mutex_unlock(&mtac_mutex);
@@ -142,19 +137,19 @@ static ssize_t xdot_store_reset(struct kobject *kobj,
if (reset_state[port_index] == -1) {
// Wrong GPIO flags, so change to output pin type
- gpio_free(pin->pin.gpio);
- ret = gpio_request_one(pin->pin.gpio, pin->pin.flags, pin->pin.label);
- if(ret) {
- log_error("Could not request pin %s (%d)", pin->name, ret);
+ gpiod_put(pin->desc);
+ pin->desc = devm_gpiod_get_optional(&mts_io_platform_device->dev, pin->name, GPIOD_IN);
+ if (IS_ERR(pin->desc)) {
+ dev_err(&mts_io_platform_device->dev,"Could not request pin %s (%d)\n", pin->name, ret);
reset_state[port_index] = -2; // Invalid state
mutex_unlock(&mtac_mutex);
- return EINVAL;
+ return PTR_ERR(pin->desc);
}
}
if (value >= 0) {
// Change the value
- gpio_set_value(pin->pin.gpio, value);
+ gpiod_set_value(pin->desc, value);
reset_state[port_index] = value;
}
@@ -174,7 +169,7 @@ ssize_t xdot_show_eui(struct kobject *kobj, struct kobj_attribute *attr, char *b
port = mtac_port_from_kobject(kobj);
if (port < 1) {
- log_error("mtac_port_from_kobject returned %d", port);
+ dev_err(&mts_io_platform_device->dev,"mtac_port_from_kobject returned %d\n", port);
return -1;
}
port_index = port - 1;
@@ -200,7 +195,7 @@ static char* xdot_gpio_pin_name_by_attr_name(const char* name, int port) {
if (! strcmp(name, "reset")) {
return "ap1-reset";
} else {
- log_error("attribute name [%s] is invalid for XDOT in port %d", name, port);
+ dev_err(&mts_io_platform_device->dev,"attribute name [%s] is invalid for XDOT in port %d\n", name, port);
return "";
}
@@ -208,7 +203,7 @@ static char* xdot_gpio_pin_name_by_attr_name(const char* name, int port) {
if (! strcmp(name, "reset")) {
return "ap2-reset";
} else {
- log_error("attribute name [%s] is invalid for XDOT in port %d", name, port);
+ dev_err(&mts_io_platform_device->dev,"attribute name [%s] is invalid for XDOT in port %d\n", name, port);
return "";
}
}
@@ -235,12 +230,12 @@ static bool xdot_setup(enum ap port) {
struct attribute **attrs;
struct kobject *subdir;
- log_info("loading XDOT accessory card in port %d", port);
+ dev_info(&mts_io_platform_device->dev,"loading XDOT accessory card in port %d\n", 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 for XDOT in port %d failed", port);
+ dev_err(&mts_io_platform_device->dev,"kobject_create_and_add for XDOT in port %d failed\n", port);
return false;
}
@@ -265,19 +260,19 @@ static bool xdot_setup(enum ap port) {
}
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);
+ dev_err(&mts_io_platform_device->dev,"Failed to link [%s] to [%s], %d\n", buf, mtac_port_info[port_index]->subdirs->name, ret);
}
attrs = kzalloc(sizeof(struct attribute*) * ap_xdot_attrs_size, GFP_KERNEL);
if (! attrs) {
- log_error("Failed to allocate attribute space for port %d", port);
+ dev_err(&mts_io_platform_device->dev,"Failed to allocate attribute space for port %d\n", port);
return false;
}
sprintf(buf,"eui");
attr = mtac_create_attribute("eui", MTS_ATTR_MODE_RO);
if (! attr) {
- log_error("Failed to create attribute [%s] for XDOT in port %d", buf, port);
+ dev_err(&mts_io_platform_device->dev,"Failed to create attribute [%s] for XDOT in port %d\n", buf, port);
attrs[index] = NULL;
mtac_port_info[port_index]->attr_group.attrs = attrs;
return false;
@@ -288,7 +283,7 @@ static bool xdot_setup(enum ap port) {
sprintf(buf, "reset");
attr = mtac_create_attribute(buf, MTS_ATTR_MODE_RW);
if (! attr) {
- log_error("Failed to create attribute [%s] for ETH in port %d", buf, port);
+ dev_err(&mts_io_platform_device->dev,"Failed to create attribute [%s] for ETH in port %d\n", buf, port);
kfree(attrs);
return false;
}
@@ -299,7 +294,7 @@ static bool xdot_setup(enum ap port) {
// add attributes for eeprom contents
if (! mtac_add_product_info_attributes(port, attrs, &index)) {
- log_error("Failed to add product info attributes for XDOT in port %d", port);
+ dev_err(&mts_io_platform_device->dev,"Failed to add product info attributes for XDOT in port %d\n", port);
return false;
}
@@ -307,7 +302,7 @@ static bool xdot_setup(enum ap port) {
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 XDOT in port %d", port);
+ dev_err(&mts_io_platform_device->dev,"sysfs_create_group failed for XDOT in port %d\n", port);
return false;
}
@@ -319,7 +314,7 @@ static bool xdot_teardown(enum ap port) {
int port_index = port - 1;
struct attribute **attrs = mtac_port_info[port_index]->attr_group.attrs;
- log_info("unloading XDOT accessory card in port %d", port);
+ dev_info(&mts_io_platform_device->dev,"unloading XDOT accessory card in port %d\n", port);
// clean up allocated memory for attributes
for (i = 0; i < ap_xdot_attrs_size; i++) {
@@ -360,7 +355,7 @@ static int __init mtac_xdot_init(void)
slot_count = mtac_find(set_xdot_info,PRODUCT_ID_MTAC_XDOT);
if (slot_count < 1) {
- log_debug("No MTAC XDOT found");
+ dev_dbg(&mts_io_platform_device->dev,"No MTAC XDOT found\n");
if (slot_count < 0)
return slot_count;
else
@@ -374,7 +369,7 @@ static int __init mtac_xdot_init(void)
static void __exit mtac_xdot_exit(void)
{
mtac_free(PRODUCT_ID_MTAC_XDOT,xdot_setup,"xdot");
- log_info("exiting");
+ dev_info(&mts_io_platform_device->dev,"exiting\n");
}
module_init(mtac_xdot_init);