summaryrefslogtreecommitdiff
path: root/io-module/mtac_mfser.c
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2014-10-01 08:41:26 -0500
committerMike Fiore <mfiore@multitech.com>2014-10-01 08:41:26 -0500
commit0f27f5666932274a30ca018c7dacfd7a9e5fc8bb (patch)
treed9873f1528405dc1676fe025634c8c895a084f5a /io-module/mtac_mfser.c
parent4c4f2f12985dc811898ebbf6d14de43874e3ca9d (diff)
downloadmts-io-0f27f5666932274a30ca018c7dacfd7a9e5fc8bb.tar.gz
mts-io-0f27f5666932274a30ca018c7dacfd7a9e5fc8bb.tar.bz2
mts-io-0f27f5666932274a30ca018c7dacfd7a9e5fc8bb.zip
mts-io: standardize lookup of pin name by attribute name
1 set of functions for ap gpio pin store and show each type of card defines a callback that specifies the mapping of attribute names to pin names
Diffstat (limited to 'io-module/mtac_mfser.c')
-rw-r--r--io-module/mtac_mfser.c100
1 files changed, 16 insertions, 84 deletions
diff --git a/io-module/mtac_mfser.c b/io-module/mtac_mfser.c
index ed97cc6..7c5862c 100644
--- a/io-module/mtac_mfser.c
+++ b/io-module/mtac_mfser.c
@@ -1,85 +1,16 @@
-struct gpio_pin *ap_mfser_pin_by_attr_name(const char *name) {
- struct gpio_pin *pin;
- char *pin_attr_name;
-
- if (!strcmp(name, "rs4xx-term-res:1")) {
- pin_attr_name = "ap1-gpio3";
- } else if (!strcmp(name, "rts-override:1")) {
- pin_attr_name = "ap1-gpio4";
- } else if (!strcmp(name, "rs4xx-term-res:2")) {
- pin_attr_name = "ap2-gpio3";
- } else if (!strcmp(name, "rts-override:2")) {
- pin_attr_name = "ap2-gpio4";
+static char* mfser_gpio_pin_name_by_attr_name(const char* name) {
+ if (! strcmp(name, "rs4xx-term-res:1")) {
+ return "ap1-gpio3";
+ } else if (! strcmp(name, "rts-override:1")) {
+ return "ap1-gpio4";
+ } else if (! strcmp(name, "rs4xx-term-res:2")) {
+ return "ap2-gpio3";
+ } else if (! strcmp(name, "rts-override:2")) {
+ return "ap2-gpio4";
} else {
- log_error("accessory card attribute %s not available", name);
- return NULL;
+ log_error("attirbute name [%s] is invalid for MFSER", name);
+ return "";
}
-
- for (pin = gpio_pins; *pin->name; pin++) {
- if (!strcmp(pin->pin.label, pin_attr_name)) {
- return pin;
- }
- }
-
- log_error("pin with attr name %s not found", name);
-
- return NULL;
-}
-
-
-static ssize_t mts_attr_show_ap_mfser_pin(struct kobject *kobj,
- struct kobj_attribute *attr,
- char *buf)
-{
- int value;
- struct gpio_pin *pin = ap_mfser_pin_by_attr_name(attr->attr.name);
-
- if (!pin) {
- return -ENODEV;
- }
-
- mutex_lock(&mts_io_mutex);
-
- value = gpio_get_value(pin->pin.gpio);
-
- mutex_unlock(&mts_io_mutex);
-
- if (value < 0) {
- return value;
- }
-
- if (pin->active_low) {
- value = !value;
- }
-
- return sprintf(buf, "%d\n", value);
-}
-
-static ssize_t mts_attr_store_ap_mfser_pin(struct kobject *kobj,
- struct kobj_attribute *attr, const char *buf, size_t count)
-{
- int value;
- struct gpio_pin *pin = ap_mfser_pin_by_attr_name(attr->attr.name);
-
- if (!pin) {
- return -ENODEV;
- }
-
- if (sscanf(buf, "%i", &value) != 1) {
- return -EINVAL;
- }
-
- if (pin->active_low) {
- value = !value;
- }
-
- mutex_lock(&mts_io_mutex);
-
- gpio_set_value(pin->pin.gpio, value);
-
- mutex_unlock(&mts_io_mutex);
-
- return count;
}
static ssize_t mts_attr_show_mfser_mode(struct kobject *kobj,
@@ -225,8 +156,8 @@ static bool mfser_setup(enum ap port) {
log_error("failed to create attribute[%s]", buf);
return false;
}
- attr->show = mts_attr_show_ap_mfser_pin;
- attr->store = mts_attr_store_ap_mfser_pin;
+ attr->show = mts_attr_show_ap_gpio_pin;
+ attr->store = mts_attr_store_ap_gpio_pin;
device_attrs[device_attrs_size++] = &attr->attr;
sprintf(buf, "rts-override:%d", port);
@@ -235,8 +166,8 @@ static bool mfser_setup(enum ap port) {
log_error("failed to create attribute[%s]", buf);
return false;
}
- attr->show = mts_attr_show_ap_mfser_pin;
- attr->store = mts_attr_store_ap_mfser_pin;
+ attr->show = mts_attr_show_ap_gpio_pin;
+ attr->store = mts_attr_store_ap_gpio_pin;
device_attrs[device_attrs_size++] = &attr->attr;
// add attributes for eeprom contents
@@ -276,6 +207,7 @@ bool set_mfser_info(struct ap_info* info) {
info->teardown = &mfser_teardown;
info->attrs_start = 0;
info->attrs_end = 0;
+ info->gpio_pin_name_by_attr_name = &mfser_gpio_pin_name_by_attr_name;
return true;
}