diff options
Diffstat (limited to 'io-module')
-rw-r--r-- | io-module/mts_io.c | 80 |
1 files changed, 18 insertions, 62 deletions
diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 1f3040e..68e856f 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -88,11 +88,11 @@ static int led_mode_status = LED_OFF; #define SOUT_LED_SIG3_BIT BIT(6) #define SOUT_EXTSERIAL_DCD_BIT BIT(7) -// GPIO pin types:input, output, open collector (1 = input (high Z), 0 = output low) +// GPIO pin types:input, output, open drain (1 = high Z, 0 = output low) enum { GPIO_DIR_INPUT, GPIO_DIR_OUTPUT, - GPIO_DIR_OC, + GPIO_DIR_OD, }; struct gpio_pin { @@ -384,7 +384,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { .name = "GPIO11", .attr_name = "gpio11", .pin = AT91_PIN_PB19, - .direction = GPIO_DIR_OUTPUT, + .direction = GPIO_DIR_OD, .output_value = 1, .use_pullup = 1, }, @@ -392,7 +392,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { .name = "GPIO12", .attr_name = "gpio12", .pin = AT91_PIN_PB20, - .direction = GPIO_DIR_OUTPUT, + .direction = GPIO_DIR_OD, .output_value = 1, .use_pullup = 1, }, @@ -404,7 +404,7 @@ static struct gpio_pin gpio_pins_mtr2_0_0[] = { .name = "NETH_RST", .attr_name = "eth-switch-enabled", .pin = AT91_PIN_PC6, - .direction = GPIO_DIR_OC, + .direction = GPIO_DIR_OD, .output_value = 1, .use_pullup = 0, }, @@ -588,7 +588,7 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .name = "3G_RST", .attr_name = "radio-reset", .pin = AT91_PIN_PA22, - .direction = GPIO_DIR_OC, + .direction = GPIO_DIR_OD, .output_value = 1, .use_pullup = 0, }, @@ -596,7 +596,7 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .name = "3G_ONOFF", .attr_name = "radio-enabled", .pin = AT91_PIN_PA21, - .direction = GPIO_DIR_OC, + .direction = GPIO_DIR_OD, .output_value = 1, .use_pullup = 0, }, @@ -1024,8 +1024,8 @@ static int radio_reset_telit(void) msleep(500); - // set pin as input (high Z) - ret = at91_set_gpio_input(rst_pin->pin, rst_pin->use_pullup); + // set pin high (high Z) + ret = at91_set_gpio_output_with_pullup(rst_pin->pin, 1, rst_pin->use_pullup); if (ret) { return ret; } @@ -1041,8 +1041,8 @@ static int radio_reset_telit(void) msleep(6000); - // set on/off pin as input (high Z) - ret = at91_set_gpio_input(onoff_pin->pin, onoff_pin->use_pullup); + // set on/off pin high (high Z) + ret = at91_set_gpio_output_with_pullup(onoff_pin->pin, 1, onoff_pin->use_pullup); if (ret) { return ret; } @@ -2516,47 +2516,13 @@ static struct device_attribute dev_attr_serial_mode = { .store = mts_attr_store_serial_mode, }; -static ssize_t mts_attr_store_gpio_open_collector(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_gpio_open_collector, + .store = mts_attr_store_gpio_pin, }; static struct device_attribute dev_attr_radio_reset_telit = { @@ -3003,28 +2969,18 @@ static int __init mts_io_init(void) for (pin = gpio_pins; *pin->name; pin++) { gpio_request(pin->pin, pin->name); - if (pin->direction == GPIO_DIR_OUTPUT || - (pin->direction == GPIO_DIR_OC && pin->output_value == 0) ) { + if (pin->direction == GPIO_DIR_OD) { + log_info("Setting pin %s to multi-drive\n", pin->name); + at91_set_multi_drive(pin->pin, true); + } + + if (pin->direction == GPIO_DIR_OUTPUT || pin->direction == GPIO_DIR_OD) { at91_set_gpio_output_with_pullup(pin->pin, pin->output_value, pin->use_pullup); } else { at91_set_gpio_input(pin->pin, pin->use_pullup); } } - if ( mts_product_id == MT100EOCG_0_0 ) { - //Set open drain for GPIO11 and GPIO12 using multi drive - pin = gpio_pin_by_name("GPIO11"); - if (pin) { - log_info("Set open drain for GPIO11"); - at91_set_multi_drive(pin->pin, true); - } - pin = gpio_pin_by_name("GPIO12"); - if (pin) { - log_info("Set open drain for GPIO12"); - at91_set_multi_drive(pin->pin, true); - } - } - if ( has_spi_sout || has_spi_dout || has_spi_din ) { pin = gpio_pin_by_name("ENIO"); if (pin) { |