summaryrefslogtreecommitdiff
path: root/io-module/mts_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io-module/mts_io.c')
-rw-r--r--io-module/mts_io.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/io-module/mts_io.c b/io-module/mts_io.c
index 8bdbfca..a67c475 100644
--- a/io-module/mts_io.c
+++ b/io-module/mts_io.c
@@ -2151,6 +2151,83 @@ static struct device_attribute dev_attr_extserial_cd = {
.store = mts_attr_store_gpio_pin_inverted,
};
+static ssize_t mts_attr_show_serial_mode(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ int ret;
+ int smode0;
+ int smode2;
+
+ struct gpio_pin *pin_smode0 = gpio_pin_by_name("SERIAL_MODE0");
+ struct gpio_pin *pin_smode2 = gpio_pin_by_name("SERIAL_MODE2");
+
+ if (!pin_smode0 || !pin_smode2)
+ return -ENODEV;
+
+ mutex_lock(&mts_io_mutex);
+
+ smode0 = at91_get_gpio_value(pin_smode0->pin);
+ smode2 = at91_get_gpio_value(pin_smode2->pin);
+
+ if (smode2 == 0 && smode0 == 1)
+ ret = sprintf(buf, "rs485\n");
+ else if (smode2 == 1 && smode0 == 0)
+ ret = sprintf(buf, "rs232\n");
+ else if (smode2 == 1 && smode0 == 1)
+ ret = sprintf(buf, "rs422\n");
+
+ mutex_unlock(&mts_io_mutex);
+
+ return ret;
+}
+
+static ssize_t mts_attr_store_serial_mode(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ pid_t pid;
+ int smode0;
+ int smode2;
+ struct gpio_pin *pin_smode0 = gpio_pin_by_name("SERIAL_MODE0");
+ struct gpio_pin *pin_smode2 = gpio_pin_by_name("SERIAL_MODE2");
+
+ if (!pin_smode0 || !pin_smode2)
+ return -ENODEV;
+
+ if (!strcasecmp(buf, "rs485")) {
+ smode2 = 0;
+ smode0 = 1;
+ }
+ else if (!strcasecmp(buf, "rs232")) {
+ smode2 = 1;
+ smode0 = 0;
+ }
+ else if (!strcasecmp(buf, "rs422")) {
+ smode2 = 1;
+ smode0 = 1;
+ }
+ else {
+ return -EINVAL;
+ }
+
+ mutex_lock(&mts_io_mutex);
+
+ at91_set_gpio_value(pin_smode2->pin, smode2);
+ at91_set_gpio_value(pin_smode0->pin, smode0);
+
+ mutex_unlock(&mts_io_mutex);
+
+ return count;
+}
+
+static struct device_attribute dev_attr_serial_mode = {
+ .attr = {
+ .name = "serial-mode",
+ .mode = MTS_ATTR_MODE_RW,
+ },
+ .show = mts_attr_show_serial_mode,
+ .store = mts_attr_store_serial_mode,
+};
static struct attribute *mt100eocg_platform_attributes[] = {
&dev_attr_extserial_dtr.attr,
@@ -2206,6 +2283,8 @@ static struct attribute *en4_platform_attributes[] = {
&dev_attr_bt_enabled.attr,
&dev_attr_wlan_enabled.attr,
+ &dev_attr_serial_mode.attr,
+
&dev_attr_led_sig1_gpio.attr,
&dev_attr_led_sig2_gpio.attr,
&dev_attr_led_sig3_gpio.attr,