From 99483c244edc6501a8d217379906bbb486c0f9fd Mon Sep 17 00:00:00 2001 From: Jesse Gilles Date: Fri, 27 Jul 2012 16:24:06 -0500 Subject: add open collector pin type, MTR radio reset/init support, fix minor bug --- io-module/mts_io.c | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/io-module/mts_io.c b/io-module/mts_io.c index e96360f..0220817 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -88,9 +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) enum { GPIO_DIR_INPUT, GPIO_DIR_OUTPUT, + GPIO_DIR_OC, }; struct gpio_pin { @@ -402,7 +404,7 @@ static struct gpio_pin gpio_pins_en4_0_0[] = { .name = "NETH_RST", .attr_name = "eth-switch-enabled", .pin = AT91_PIN_PC6, - .direction = GPIO_DIR_INPUT, + .direction = GPIO_DIR_OC, .output_value = 1, .use_pullup = 0, }, @@ -586,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_OUTPUT, + .direction = GPIO_DIR_OC, .output_value = 1, .use_pullup = 0, }, @@ -594,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_OUTPUT, + .direction = GPIO_DIR_OC, .output_value = 1, .use_pullup = 0, }, @@ -727,7 +729,7 @@ struct gpio_pin *gpio_pin_by_name(const char *name) { struct gpio_pin *gpio_pin_by_attr_name(const char *name) { struct gpio_pin *pin; - for (pin = gpio_pins; pin->attr_name; pin++) { + for (pin = gpio_pins; *pin->attr_name; pin++) { if (!strcmp(pin->attr_name, name)) { return pin; } @@ -1233,15 +1235,6 @@ static struct device_attribute dev_attr_wlan_enabled = { .store = mts_attr_store_gpio_pin, }; -static struct device_attribute dev_attr_radio_enabled = { - .attr = { - .name = "radio-enabled", - .mode = MTS_ATTR_MODE_RW, - }, - .show = mts_attr_show_gpio_pin, - .store = mts_attr_store_gpio_pin, -}; - static ssize_t mts_attr_store_sout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -2422,7 +2415,7 @@ 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, +static ssize_t mts_attr_store_gpio_open_collector(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int value; @@ -2462,7 +2455,25 @@ static struct device_attribute dev_attr_eth_switch_enabled = { .mode = MTS_ATTR_MODE_RW, }, .show = mts_attr_show_gpio_pin, - .store = mts_attr_store_eth_switch_en, + .store = mts_attr_store_gpio_open_collector, +}; + +static struct device_attribute dev_attr_radio_reset_oc = { + .attr = { + .name = "radio-reset", + .mode = MTS_ATTR_MODE_RW, + }, + .show = mts_attr_show_gpio_pin, + .store = mts_attr_store_gpio_open_collector, +}; + +static struct device_attribute dev_attr_radio_enabled_oc = { + .attr = { + .name = "radio-enabled", + .mode = MTS_ATTR_MODE_RW, + }, + .show = mts_attr_show_gpio_pin, + .store = mts_attr_store_gpio_open_collector, }; static struct attribute *mt100eocg_platform_attributes[] = { @@ -2604,8 +2615,8 @@ static struct attribute_group platform_attribute_group = { static struct attribute *mtr_platform_attributes[] = { &dev_attr_reset.attr, &dev_attr_reset_monitor.attr, - &dev_attr_radio_reset.attr, - &dev_attr_radio_enabled.attr, + &dev_attr_radio_reset_oc.attr, + &dev_attr_radio_enabled_oc.attr, &dev_attr_extserial_dtr.attr, &dev_attr_extserial_dsr_gpio.attr, &dev_attr_extserial_cd.attr, @@ -2901,7 +2912,8 @@ 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) { + if (pin->direction == GPIO_DIR_OUTPUT || + (pin->direction == GPIO_DIR_OC && pin->output_value == 0) ) { at91_set_gpio_output_with_pullup(pin->pin, pin->output_value, pin->use_pullup); } else { at91_set_gpio_input(pin->pin, pin->use_pullup); -- cgit v1.2.3