diff options
Diffstat (limited to 'io-module/mtac_mfser.c')
-rw-r--r-- | io-module/mtac_mfser.c | 106 |
1 files changed, 68 insertions, 38 deletions
diff --git a/io-module/mtac_mfser.c b/io-module/mtac_mfser.c index 14eddd1..5871bfe 100644 --- a/io-module/mtac_mfser.c +++ b/io-module/mtac_mfser.c @@ -2,13 +2,13 @@ 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:0")) { + if (!strcmp(name, "rs4xx-term-res:1")) { pin_attr_name = "ap1-gpio3"; - } else if (!strcmp(name, "rts-override:0")) { + } else if (!strcmp(name, "rts-override:1")) { pin_attr_name = "ap1-gpio4"; - } else if (!strcmp(name, "rs4xx-term-res:1")) { + } else if (!strcmp(name, "rs4xx-term-res:2")) { pin_attr_name = "ap2-gpio3"; - } else if (!strcmp(name, "rts-override:1")) { + } else if (!strcmp(name, "rts-override:2")) { pin_attr_name = "ap2-gpio4"; } else { log_error("accessory card attribute %s not available", name); @@ -27,8 +27,8 @@ struct gpio_pin *ap_mfser_pin_by_attr_name(const char *name) { } -static ssize_t mts_attr_show_ap_mfser_pin(struct device *dev, - struct device_attribute *attr, +static ssize_t mts_attr_show_ap_mfser_pin(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) { int value; @@ -55,8 +55,8 @@ static ssize_t mts_attr_show_ap_mfser_pin(struct device *dev, return sprintf(buf, "%d\n", value); } -static ssize_t mts_attr_store_ap_mfser_pin(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) +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); @@ -82,8 +82,8 @@ static ssize_t mts_attr_store_ap_mfser_pin(struct device *dev, return count; } -static ssize_t mts_attr_show_mfser_mode(struct device *dev, - struct device_attribute *attr, +static ssize_t mts_attr_show_mfser_mode(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) { int ret; @@ -93,11 +93,11 @@ static ssize_t mts_attr_show_mfser_mode(struct device *dev, struct gpio_pin *pin_modesel0; struct gpio_pin *pin_modesel1; - if (strstr(attr->attr.name, ":0")) { + if (strstr(attr->attr.name, ":1")) { pin_modesel0 = gpio_pin_by_name("AP1_GPIO1"); pin_modesel1 = gpio_pin_by_name("AP1_GPIO2"); } - else if (strstr(attr->attr.name, ":1")) { + else if (strstr(attr->attr.name, ":2")) { pin_modesel0 = gpio_pin_by_name("AP2_GPIO1"); pin_modesel1 = gpio_pin_by_name("AP2_GPIO2"); } @@ -130,19 +130,19 @@ static ssize_t mts_attr_show_mfser_mode(struct device *dev, return ret; } -static ssize_t mts_attr_store_mfser_mode(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) +static ssize_t mts_attr_store_mfser_mode(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) { int modesel0; int modesel1; struct gpio_pin *pin_modesel0; struct gpio_pin *pin_modesel1; - if (strstr(attr->attr.name, ":0")) { + if (strstr(attr->attr.name, ":1")) { pin_modesel0 = gpio_pin_by_name("AP1_GPIO1"); pin_modesel1 = gpio_pin_by_name("AP1_GPIO2"); } - else if (strstr(attr->attr.name, ":1")) { + else if (strstr(attr->attr.name, ":2")) { pin_modesel0 = gpio_pin_by_name("AP2_GPIO1"); pin_modesel1 = gpio_pin_by_name("AP2_GPIO2"); } @@ -184,32 +184,62 @@ static ssize_t mts_attr_store_mfser_mode(struct device *dev, return count; } -/* accessory port 1 serial attributes */ -static DEVICE_ATTR_MTS(dev_attr_ap1_serial_mode, "serial-mode:0", mts_attr_show_mfser_mode, mts_attr_store_mfser_mode); -static DEVICE_ATTR_MTS(dev_attr_ap1_rs4xx_term_res, "rs4xx-term-res:0", mts_attr_show_ap_mfser_pin, mts_attr_store_ap_mfser_pin); -static DEVICE_ATTR_MTS(dev_attr_ap1_rts_override, "rts-override:0", mts_attr_show_ap_mfser_pin, mts_attr_store_ap_mfser_pin); +// 1 serial mode +// 1 rs4xx term resistor +// 1 rts override +static int ap_mfser_attrs_size = 3; -static int ap1_mfser_attributes_size = 3; // not including NULL at end +static bool mfser_setup(enum ap port) { + struct kobj_attribute *attr; + char buf[32]; -static struct attribute *ap1_mfser_attributes[] = { - &dev_attr_ap1_serial_mode.attr, - &dev_attr_ap1_rs4xx_term_res.attr, // gpio3 - &dev_attr_ap1_rts_override.attr, // gpio4 - NULL, -}; + log_info("loading MFSER accessory card in port %d", port); -/* accessory port 2 serial attributes */ -static DEVICE_ATTR_MTS(dev_attr_ap2_serial_mode, "serial-mode:1", mts_attr_show_mfser_mode, mts_attr_store_mfser_mode); -static DEVICE_ATTR_MTS(dev_attr_ap2_rs4xx_term_res, "rs4xx-term-res:1", mts_attr_show_ap_mfser_pin, mts_attr_store_ap_mfser_pin); -static DEVICE_ATTR_MTS(dev_attr_ap2_rts_override, "rts-override:1", mts_attr_show_ap_mfser_pin, mts_attr_store_ap_mfser_pin); + if (device_attrs_size + ap_mfser_attrs_size >= device_attrs_max_size) { + log_error("can't load MFSER accessory card in port %d - not enough room for attributes", port); + return false; + } -static int ap2_mfser_attributes_size = 3; // not including NULL at end + sprintf(buf, "serial-mode:%d", port); + attr = create_attribute(buf, MTS_ATTR_MODE_RW); + if (! attr) { + log_error("failed to create attribute[%s]", buf); + return false; + } + attr->show = mts_attr_show_mfser_mode; + attr->store = mts_attr_store_mfser_mode; + device_attrs[device_attrs_size++] = &attr->attr; -static struct attribute *ap2_mfser_attributes[] = { - &dev_attr_ap2_serial_mode.attr, - &dev_attr_ap2_rs4xx_term_res.attr, // gpio3 - &dev_attr_ap2_rts_override.attr, // gpio4 - NULL, -}; + sprintf(buf, "rs4xx-term-res:%d", port); + attr = create_attribute(buf, MTS_ATTR_MODE_RW); + if (! attr) { + 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; + device_attrs[device_attrs_size++] = &attr->attr; + sprintf(buf, "rts-override:%d", port); + attr = create_attribute(buf, MTS_ATTR_MODE_RW); + if (! attr) { + 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; + device_attrs[device_attrs_size++] = &attr->attr; + + return true; +} +static bool mfser_teardown(enum ap port) { + log_info("unloading MFSER accessory card in port %d", port); + return true; +} + +static struct ap_info mfser_info = { + .product_id = MTAC_MFSER_0_0, + .setup = &mfser_setup, + .teardown = &mfser_teardown +}; |