diff options
author | Jesse Gilles <jgilles@multitech.com> | 2012-05-08 12:52:32 -0500 |
---|---|---|
committer | Jesse Gilles <jgilles@multitech.com> | 2012-05-08 12:52:32 -0500 |
commit | 24b8febcc1ed2da68a497c5e5c479e19fce2d19a (patch) | |
tree | 4ab5e03b9f43cdabbe4216799fe5fa274143e47a /io-module | |
parent | 1c8988725087b8df35a759d45db2bcb74c40585c (diff) | |
download | cdp-io-controller-24b8febcc1ed2da68a497c5e5c479e19fce2d19a.tar.gz cdp-io-controller-24b8febcc1ed2da68a497c5e5c479e19fce2d19a.tar.bz2 cdp-io-controller-24b8febcc1ed2da68a497c5e5c479e19fce2d19a.zip |
added serial-mode for en4
Diffstat (limited to 'io-module')
-rw-r--r-- | io-module/mts_io.c | 79 |
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, |