diff options
Diffstat (limited to 'io-module/mtac_gpiob.c')
-rw-r--r-- | io-module/mtac_gpiob.c | 109 |
1 files changed, 20 insertions, 89 deletions
diff --git a/io-module/mtac_gpiob.c b/io-module/mtac_gpiob.c index ebbe0c6..ce1d7de 100644 --- a/io-module/mtac_gpiob.c +++ b/io-module/mtac_gpiob.c @@ -105,97 +105,27 @@ static int mts_spi_ap_remove(struct spi_device *spi) return 0; } -// Is there a way to make this dynamic as well? -struct gpio_pin *ap_gpio_pin_by_attr_name(const char *name) { - struct gpio_pin *pin; - char *pin_attr_name; - - if (!strcmp(name, "ap-led1:1")) { - pin_attr_name = "ap1-gpio3"; - } else if (!strcmp(name, "ap-led2:1")) { - pin_attr_name = "ap1-gpio4"; - } else if (!strcmp(name, "ap-dout-enable:1")) { - pin_attr_name = "ap1-gpio1"; - } else if (!strcmp(name, "ap-reset:1")) { - pin_attr_name = "ap1-reset"; - } else if (!strcmp(name, "ap-led1:2")) { - pin_attr_name = "ap2-gpio3"; - } else if (!strcmp(name, "ap-led2:2")) { - pin_attr_name = "ap2-gpio4"; - } else if (!strcmp(name, "ap-dout-enable:2")) { - pin_attr_name = "ap2-gpio1"; - } else if (!strcmp(name, "ap-reset:2")) { - pin_attr_name = "ap2-reset"; +static char* gpiob_gpio_pin_name_by_attr_name(const char* name) { + if (! strcmp(name, "ap-led1:1")) { + return "ap1-gpio3"; + } else if (! strcmp(name, "ap-led2:1")) { + return "ap1-gpio4"; + } else if (! strcmp(name, "ap-dout-enable:1")) { + return "ap1-gpio1"; + } else if (! strcmp(name, "ap-reset:1")) { + return "ap1-reset"; + } else if (! strcmp(name, "ap-led1:2")) { + return "ap2-gpio3"; + } else if (! strcmp(name, "ap-led2:2")) { + return "ap2-gpio4"; + } else if (! strcmp(name, "ap-dout-enable:2")) { + return "ap2-gpio1"; + } else if (! strcmp(name, "ap-reset:2")) { + return "ap2-reset"; } else { - log_error("accessory card attribute %s not available", name); - return NULL; + log_error("attirbute name [%s] is invalid for GPIOB", 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_gpio_pin(struct kobject *kobj, - struct kobj_attribute *attr, - char *buf) -{ - int value; - struct gpio_pin *pin = ap_gpio_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_gpio_pin(struct kobject *kobj, - struct kobj_attribute *attr, const char *buf, size_t count) -{ - int value; - struct gpio_pin *pin = ap_gpio_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_ap_din(struct kobject *kobj, struct kobj_attribute *attr, char *buf) @@ -561,6 +491,7 @@ bool set_gpiob_info(struct ap_info* info) { info->teardown = &gpiob_teardown; info->attrs_start = 0; info->attrs_end = 0; + info->gpio_pin_name_by_attr_name = &gpiob_gpio_pin_name_by_attr_name; return true; } |