From 15b996529938fc943dc491e40aa5aeae32a57793 Mon Sep 17 00:00:00 2001 From: Jesse Gilles Date: Wed, 9 May 2012 09:24:42 -0500 Subject: add eth-switch-enabled for en4, only drive output when low * Only drive the output pin when set low (reset active), else leave pin floating since it has an external pull up. If instead the output pin is driven high, the ethernet switch locks up after a soft reboot. --- io-module/mts_io.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/io-module/mts_io.c b/io-module/mts_io.c index a67c475..6316894 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -400,10 +400,10 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { static struct gpio_pin gpio_pins_en4_0_0[] = { { - .name = "ETH0_ENABLED", - .attr_name = "eth0-enabled", + .name = "NETH_RST", + .attr_name = "eth-switch-enabled", .pin = AT91_PIN_PC6, - .direction = GPIO_DIR_OUTPUT, + .direction = GPIO_DIR_INPUT, .output_value = 1, .use_pullup = 0, }, @@ -2229,6 +2229,49 @@ static struct device_attribute dev_attr_serial_mode = { .store = mts_attr_store_serial_mode, }; +static ssize_t mts_attr_store_eth_switch_en(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int value; + int err; + struct gpio_pin *pin = gpio_pin_by_attr_name(attr->attr.name); + + if (!pin) { + return -ENODEV; + } + + if (sscanf(buf, "%i", &value) != 1) { + return -EINVAL; + } + + mutex_lock(&mts_io_mutex); + + // set to input if high (floating), else set as output and drive low + if (value) { + err = at91_set_gpio_input(pin->pin, pin->use_pullup); + } + else { + err = at91_set_gpio_output_with_pullup(pin->pin, value, pin->use_pullup); + } + + mutex_unlock(&mts_io_mutex); + + if (err) { + return err; + } + + return count; +} + +static struct device_attribute dev_attr_eth_switch_enabled = { + .attr = { + .name = "eth-switch-enabled", + .mode = MTS_ATTR_MODE_RW, + }, + .show = mts_attr_show_gpio_pin, + .store = mts_attr_store_eth_switch_en, +}; + static struct attribute *mt100eocg_platform_attributes[] = { &dev_attr_extserial_dtr.attr, &dev_attr_extserial_cd.attr, @@ -2279,7 +2322,7 @@ static struct attribute *en4_platform_attributes[] = { &dev_attr_extserial_ri_gpio.attr, &dev_attr_extserial_cd.attr, &dev_attr_rsersrc.attr, - &dev_attr_eth0_enabled.attr, + &dev_attr_eth_switch_enabled.attr, &dev_attr_bt_enabled.attr, &dev_attr_wlan_enabled.attr, -- cgit v1.2.3