diff options
Diffstat (limited to 'io-module/mts_io.c')
-rw-r--r-- | io-module/mts_io.c | 942 |
1 files changed, 454 insertions, 488 deletions
diff --git a/io-module/mts_io.c b/io-module/mts_io.c index c62b534..225131a 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -41,7 +41,7 @@ #include "mts_io.h" -#define DRIVER_VERSION "v0.5.1" +#define DRIVER_VERSION "v0.6.0" #define DRIVER_AUTHOR "James Maki <jmaki@multitech.com>" #define DRIVER_DESC "MTCDP IO Controller" #define DRIVER_NAME "mts-io" @@ -97,6 +97,7 @@ enum { struct gpio_pin { char name[32]; + char attr_name[32]; unsigned pin; int direction; int output_value; @@ -104,12 +105,16 @@ struct gpio_pin { }; static uint8_t mts_product_id; +static uint8_t has_spi_sout; +static uint8_t has_spi_din; +static uint8_t has_spi_dout; static struct gpio_pin *gpio_pins; static struct gpio_pin gpio_pins_mtcdp_0_0[] = { { .name = "ENIO", + .attr_name = "", .pin = AT91_PIN_PC15, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -117,6 +122,7 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = { }, { .name = "ETH0_ENABLED", + .attr_name = "eth0-enabled", .pin = AT91_PIN_PB31, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -124,6 +130,7 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = { }, { .name = "RADIO_RESET", + .attr_name = "radio-reset", .pin = AT91_PIN_PB30, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -131,6 +138,7 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = { }, { .name = "DEVICE_RESET", + .attr_name = "reset", .pin = AT91_PIN_PA22, .direction = GPIO_DIR_INPUT, .output_value = 0, @@ -138,6 +146,7 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = { }, { .name = "LS_LED", + .attr_name = "led-ls", .pin = AT91_PIN_PC9, #if LED_LS_CONTROLLABLE .direction = GPIO_DIR_OUTPUT, @@ -150,6 +159,7 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = { #if LED_STATUS_CONTROLLABLE { .name = "STATUS_LED", + .attr_name = "led-status", .pin = AT91_PIN_PA30, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -158,6 +168,7 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = { #endif { .name = "RSERSRC", + .attr_name = "rsersrc", .pin = AT91_PIN_PC7, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -165,6 +176,7 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = { }, { .name = "DTR1", + .attr_name = "extserial-dtr", .pin = AT91_PIN_PC10, .direction = GPIO_DIR_INPUT, .output_value = 0, @@ -176,6 +188,7 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = { static struct gpio_pin gpio_pins_mtcdp_1_0[] = { { .name = "ENIO", + .attr_name = "", .pin = AT91_PIN_PC15, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -183,6 +196,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { }, { .name = "ETH0_ENABLED", + .attr_name = "eth0-enabled", .pin = AT91_PIN_PB31, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -190,6 +204,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { }, { .name = "RADIO_RESET", + .attr_name = "radio-reset", .pin = AT91_PIN_PB30, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -197,6 +212,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { }, { .name = "DEVICE_RESET", + .attr_name = "reset", .pin = AT91_PIN_PA22, .direction = GPIO_DIR_INPUT, .output_value = 0, @@ -204,6 +220,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { }, { .name = "LS_LED", + .attr_name = "led-ls", .pin = AT91_PIN_PC9, #if LED_LS_CONTROLLABLE .direction = GPIO_DIR_OUTPUT, @@ -217,6 +234,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { #if LED_STATUS_CONTROLLABLE { .name = "STATUS_LED", + .attr_name = "led-status", .pin = AT91_PIN_PA30, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -225,6 +243,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { #endif { .name = "RSERSRC", + .attr_name = "rsersrc", .pin = AT91_PIN_PC7, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -232,6 +251,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { }, { .name = "TXD1", + .attr_name = "", .pin = AT91_PIN_PB17, .direction = GPIO_DIR_INPUT, .output_value = 0, @@ -239,6 +259,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { }, { .name = "DTR1", + .attr_name = "extserial-dtr", .pin = AT91_PIN_PB18, .direction = GPIO_DIR_INPUT, .output_value = 0, @@ -246,6 +267,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { }, { .name = "USBH2_PS_OC", + .attr_name = "usbh2-ps-oc", .pin = AT91_PIN_PB19, .direction = GPIO_DIR_INPUT, .output_value = 0, @@ -254,6 +276,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { #if USBH2_PS_CONTROLLABLE { .name = "USBH2_PS_ENABLED", + .attr_name = "usbh2-ps-enabled", .pin = AT91_PIN_PB20, .direction = GPIO_DIR_OUTPUT, .output_value = 0, @@ -262,6 +285,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { #endif { .name = "NDC_RESET", + .attr_name = "ndc-reset", .pin = AT91_PIN_PB21, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -273,6 +297,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { { .name = "ENIO", + .attr_name = "", .pin = AT91_PIN_PC15, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -280,6 +305,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { }, { .name = "ETH0_ENABLED", + .attr_name = "eth0-enabled", .pin = AT91_PIN_PB31, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -287,6 +313,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { }, { .name = "RADIO_RESET", + .attr_name = "radio-reset", .pin = AT91_PIN_PB30, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -294,6 +321,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { }, { .name = "DEVICE_RESET", + .attr_name = "reset", .pin = AT91_PIN_PA22, .direction = GPIO_DIR_INPUT, .output_value = 0, @@ -301,6 +329,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { }, { .name = "LED3", + .attr_name = "led-ls", .pin = AT91_PIN_PC9, #if LED_LS_CONTROLLABLE .direction = GPIO_DIR_OUTPUT, @@ -312,6 +341,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { }, { .name = "LED2", + .attr_name = "led2", .pin = AT91_PIN_PA30, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -319,6 +349,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { }, { .name = "RSERSRC", + .attr_name = "rsersrc", .pin = AT91_PIN_PC7, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -326,6 +357,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { }, { .name = "TXD1", + .attr_name = "", .pin = AT91_PIN_PB17, .direction = GPIO_DIR_INPUT, .output_value = 0, @@ -333,6 +365,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { }, { .name = "DTR1", + .attr_name = "extserial-dtr", .pin = AT91_PIN_PB18, .direction = GPIO_DIR_INPUT, .output_value = 0, @@ -340,6 +373,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { }, { .name = "DCD1", + .attr_name = "extserial-dcd", .pin = AT91_PIN_PB3, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -347,6 +381,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { }, { .name = "GPIO11", + .attr_name = "gpio11", .pin = AT91_PIN_PB19, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -354,6 +389,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { }, { .name = "GPIO12", + .attr_name = "gpio12", .pin = AT91_PIN_PB20, .direction = GPIO_DIR_OUTPUT, .output_value = 1, @@ -362,6 +398,168 @@ 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", + .pin = AT91_PIN_PC6, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "RADIO_RESET", + .attr_name = "radio-reset", + .pin = AT91_PIN_PC5, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "DEVICE_RESET", + .attr_name = "reset", + .pin = AT91_PIN_PC4, + .direction = GPIO_DIR_INPUT, + .output_value = 0, + .use_pullup = 0, + }, + { + .name = "LS_LED", + .attr_name = "led-ls", + .pin = AT91_PIN_PA29, +#if LED_LS_CONTROLLABLE + .direction = GPIO_DIR_OUTPUT, +#else + .direction = GPIO_DIR_INPUT, +#endif + .output_value = 1, + .use_pullup = 0, + }, +#if LED_STATUS_CONTROLLABLE + { + .name = "STATUS_LED", + .attr_name = "led-status", + .pin = AT91_PIN_PA24, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, +#endif + { + .name = "LED7", + .attr_name = "led-cd", + .pin = AT91_PIN_PA25, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "LED10", + .attr_name = "led-sig1", + .pin = AT91_PIN_PA26, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "LED11", + .attr_name = "led-sig2", + .pin = AT91_PIN_PA27, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "LED12", + .attr_name = "led-sig3", + .pin = AT91_PIN_PA28, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "RSERSRC", + .attr_name = "rsersrc", + .pin = AT91_PIN_PC14, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "DTR1", + .attr_name = "extserial-dtr", + .pin = AT91_PIN_PC12, + .direction = GPIO_DIR_INPUT, + .output_value = 0, + .use_pullup = 0, + }, + { + .name = "DSR1", + .attr_name = "extserial-dsr", + .pin = AT91_PIN_PC11, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "DCD1", + .attr_name = "extserial-dcd", + .pin = AT91_PIN_PC10, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "RI1", + .attr_name = "extserial-ri", + .pin = AT91_PIN_PC13, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "NDC_RESET", + .attr_name = "ndc-reset", + .pin = AT91_PIN_PC3, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "BT_EN", + .attr_name = "bt-enabled", + .pin = AT91_PIN_PC0, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "WLAN_EN", + .attr_name = "wlan-enabled", + .pin = AT91_PIN_PC1, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { + .name = "SERIAL_MODE0", + .attr_name = "", + .pin = AT91_PIN_PC23, + .direction = GPIO_DIR_OUTPUT, + .output_value = 0, + .use_pullup = 0, + }, + { + .name = "SERIAL_MODE2", + .attr_name = "", + .pin = AT91_PIN_PC24, + .direction = GPIO_DIR_OUTPUT, + .output_value = 1, + .use_pullup = 0, + }, + { }, +}; + struct gpio_pin *gpio_pin_by_name(const char *name) { struct gpio_pin *pin; @@ -377,6 +575,20 @@ struct gpio_pin *gpio_pin_by_name(const char *name) { return NULL; } +struct gpio_pin *gpio_pin_by_attr_name(const char *name) { + struct gpio_pin *pin; + + for (pin = gpio_pins; *pin->attr_name; pin++) { + if (!strcmp(pin->attr_name, name)) { + return pin; + } + } + + log_error("pin with attr name %s not found", name); + + return NULL; +} + extern uint8_t mts_id_eeprom[512]; static struct mts_id_eeprom_layout id_eeprom; @@ -385,6 +597,9 @@ static int mts_id_eeprom_load(void) memcpy(&id_eeprom, mts_id_eeprom, sizeof(mts_id_eeprom)); mts_product_id = MTCDP_E1_DK_1_0; + has_spi_sout = 1; + has_spi_din = 1; + has_spi_dout = 1; if (mts_id_eeprom[0] == 0xFF) { log_error("uninitialized eeprom"); @@ -402,9 +617,21 @@ static int mts_id_eeprom_load(void) } else if (strncmp(id_eeprom.product_id, PRODUCT_ID_MT100EOCG, strlen(PRODUCT_ID_MT100EOCG)) == 0) { gpio_pins = gpio_pins_mt100eocg_0_0; mts_product_id = MT100EOCG_0_0; + has_spi_sout = 0; + has_spi_din = 1; + has_spi_dout = 1; + } else if (strncmp(id_eeprom.product_id, PRODUCT_ID_EN4, strlen(PRODUCT_ID_EN4)) == 0) { + gpio_pins = gpio_pins_en4_0_0; + mts_product_id = EN4_0_0; + has_spi_sout = 0; + has_spi_din = 0; + has_spi_dout = 0; } else { gpio_pins = gpio_pins_mtcdp_1_0; mts_product_id = MTCDP_E1_DK_1_0; + has_spi_sout = 1; + has_spi_din = 1; + has_spi_dout = 1; } log_info("sizeof: %lu", (unsigned long) sizeof(struct mts_id_eeprom_layout)); @@ -647,26 +874,36 @@ static int ADT7302_to_celsius(int value) #define MTS_ATTR_MODE_RW S_IWUSR | S_IRUGO #define MTS_ATTR_MODE_RO S_IRUGO -#define MTS_ATTR_NAME(name) mts_attr_##name -#define MTS_ATTR_SHOW(name) mts_attr_show_##name -#define MTS_ATTR_STORE(name) mts_attr_store_##name - -#define MTS_ATTR(name, attr_name, attr_mode, show, store) \ -static struct device_attribute MTS_ATTR_NAME(name) = \ - .attr = { \ - .name = attr_name, \ - .mode = attr_mode, \ - }, \ - .show = show, \ - .store = store, \ +static ssize_t mts_attr_show_gpio_pin(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int value; + struct gpio_pin *pin = gpio_pin_by_attr_name(attr->attr.name); + + if (!pin) { + return -ENODEV; + } + + mutex_lock(&mts_io_mutex); + + value = at91_get_gpio_value(pin->pin); + + mutex_unlock(&mts_io_mutex); + + if (value < 0) { + return value; + } + + return sprintf(buf, "%d\n", value); } -static ssize_t mts_attr_show_radio_reset(struct device *dev, +static ssize_t mts_attr_show_gpio_pin_inverted(struct device *dev, struct device_attribute *attr, char *buf) { int value; - struct gpio_pin *pin = gpio_pin_by_name("RADIO_RESET"); + struct gpio_pin *pin = gpio_pin_by_attr_name(attr->attr.name); if (!pin) { return -ENODEV; @@ -682,25 +919,27 @@ static ssize_t mts_attr_show_radio_reset(struct device *dev, return value; } - return sprintf(buf, "%d\n", value); + return sprintf(buf, "%d\n", !value); } -static ssize_t mts_attr_store_radio_reset(struct device *dev, +static ssize_t mts_attr_store_gpio_pin(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 (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; + if (!pin) { + return -ENODEV; } - if (value != 0) { + + if (sscanf(buf, "%i", &value) != 1) { return -EINVAL; } mutex_lock(&mts_io_mutex); - err = radio_reset(); + err = at91_set_gpio_value(pin->pin, value); mutex_unlock(&mts_io_mutex); @@ -711,40 +950,35 @@ static ssize_t mts_attr_store_radio_reset(struct device *dev, return count; } -static struct device_attribute dev_attr_radio_reset = { - .attr = { - .name = "radio-reset", - .mode = MTS_ATTR_MODE_RW, - }, - .show = mts_attr_show_radio_reset, - .store = mts_attr_store_radio_reset, -}; - -static ssize_t mts_attr_show_ndc_reset(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t mts_attr_store_gpio_pin_inverted(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) { int value; - struct gpio_pin *pin = gpio_pin_by_name("NDC_RESET"); + 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); - value = at91_get_gpio_value(pin->pin); + err = at91_set_gpio_value(pin->pin, !value); mutex_unlock(&mts_io_mutex); - if (value < 0) { - return value; + if (err) { + return err; } - return sprintf(buf, "%d\n", value); + return count; } -static ssize_t mts_attr_store_ndc_reset(struct device *dev, +static ssize_t mts_attr_store_radio_reset(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int value; @@ -759,7 +993,7 @@ static ssize_t mts_attr_store_ndc_reset(struct device *dev, mutex_lock(&mts_io_mutex); - err = ndc_reset(); + err = radio_reset(); mutex_unlock(&mts_io_mutex); @@ -770,57 +1004,31 @@ static ssize_t mts_attr_store_ndc_reset(struct device *dev, return count; } -static struct device_attribute dev_attr_ndc_reset = { +static struct device_attribute dev_attr_radio_reset = { .attr = { - .name = "ndc-reset", + .name = "radio-reset", .mode = MTS_ATTR_MODE_RW, }, - .show = mts_attr_show_ndc_reset, - .store = mts_attr_store_ndc_reset, + .show = mts_attr_show_gpio_pin, + .store = mts_attr_store_radio_reset, }; -static ssize_t mts_attr_show_eth0_enabled(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int value; - struct gpio_pin *pin = gpio_pin_by_name("ETH0_ENABLED"); - - if (!pin) { - return -ENODEV; - } - - mutex_lock(&mts_io_mutex); - - value = at91_get_gpio_value(pin->pin); - - mutex_unlock(&mts_io_mutex); - - if (value < 0) { - return value; - } - - return sprintf(buf, "%d\n", value); -} - -static ssize_t mts_attr_store_eth0_enabled(struct device *dev, +static ssize_t mts_attr_store_ndc_reset(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int value; int err; - struct gpio_pin *pin = gpio_pin_by_name("ETH0_ENABLED"); - - if (!pin) { - return -ENODEV; - } if (sscanf(buf, "%i", &value) != 1) { return -EINVAL; } + if (value != 0) { + return -EINVAL; + } mutex_lock(&mts_io_mutex); - err = at91_set_gpio_value(pin->pin, value); + err = ndc_reset(); mutex_unlock(&mts_io_mutex); @@ -831,15 +1039,41 @@ static ssize_t mts_attr_store_eth0_enabled(struct device *dev, return count; } +static struct device_attribute dev_attr_ndc_reset = { + .attr = { + .name = "ndc-reset", + .mode = MTS_ATTR_MODE_RW, + }, + .show = mts_attr_show_gpio_pin, + .store = mts_attr_store_ndc_reset, +}; + static struct device_attribute dev_attr_eth0_enabled = { .attr = { .name = "eth0-enabled", .mode = MTS_ATTR_MODE_RW, }, - .show = mts_attr_show_eth0_enabled, - .store = mts_attr_store_eth0_enabled, + .show = mts_attr_show_gpio_pin, + .store = mts_attr_store_gpio_pin, +}; + +static struct device_attribute dev_attr_bt_enabled = { + .attr = { + .name = "bt-enabled", + .mode = MTS_ATTR_MODE_RW, + }, + .show = mts_attr_show_gpio_pin, + .store = mts_attr_store_gpio_pin, }; +static struct device_attribute dev_attr_wlan_enabled = { + .attr = { + .name = "wlan-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) @@ -1336,37 +1570,30 @@ static struct device_attribute dev_attr_din7 = { .show = mts_attr_show_din, }; - -static ssize_t mts_attr_show_extserial_dtr(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int value; - struct gpio_pin *pin = gpio_pin_by_name("DTR1"); - - if (!pin) { - return -ENODEV; - } - - mutex_lock(&mts_io_mutex); - - value = !at91_get_gpio_value(pin->pin); - - mutex_unlock(&mts_io_mutex); - - if (value < 0) { - return value; - } - - return sprintf(buf, "%d\n", value); -} - static struct device_attribute dev_attr_extserial_dtr = { .attr = { .name = "extserial-dtr", .mode = MTS_ATTR_MODE_RO, }, - .show = mts_attr_show_extserial_dtr, + .show = mts_attr_show_gpio_pin_inverted, +}; + +static struct device_attribute dev_attr_extserial_dsr_gpio = { + .attr = { + .name = "extserial-dsr", + .mode = MTS_ATTR_MODE_RW, + }, + .show = mts_attr_show_gpio_pin_inverted, + .store = mts_attr_store_gpio_pin_inverted, +}; + +static struct device_attribute dev_attr_extserial_ri_gpio = { + .attr = { + .name = "extserial-ri", + .mode = MTS_ATTR_MODE_RW, + }, + .show = mts_attr_show_gpio_pin_inverted, + .store = mts_attr_store_gpio_pin_inverted, }; #if LED_STATUS_CONTROLLABLE @@ -1516,40 +1743,52 @@ static struct device_attribute dev_attr_led_ls = { .mode = MTS_ATTR_MODE_RO, #endif }, - .show = mts_attr_show_led_ls, - .store = mts_attr_store_led_ls, + .show = mts_attr_show_gpio_pin_inverted, + .store = mts_attr_store_gpio_pin_inverted, }; -static ssize_t mts_attr_show_reset(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int value; - struct gpio_pin *pin = gpio_pin_by_name("DEVICE_RESET"); - - if (!pin) { - return -ENODEV; - } - - mutex_lock(&mts_io_mutex); - - value = !at91_get_gpio_value(pin->pin); +static struct device_attribute dev_attr_led_sig1_gpio = { + .attr = { + .name = "led-sig1", + .mode = MTS_ATTR_MODE_RW, + }, + .show = mts_attr_show_gpio_pin_inverted, + .store = mts_attr_store_gpio_pin_inverted, +}; - mutex_unlock(&mts_io_mutex); +static struct device_attribute dev_attr_led_sig2_gpio = { + .attr = { + .name = "led-sig2", + .mode = MTS_ATTR_MODE_RW, + }, + .show = mts_attr_show_gpio_pin_inverted, + .store = mts_attr_store_gpio_pin_inverted, +}; - if (value < 0) { - return value; - } +static struct device_attribute dev_attr_led_sig3_gpio = { + .attr = { + .name = "led-sig3", + .mode = MTS_ATTR_MODE_RW, + }, + .show = mts_attr_show_gpio_pin_inverted, + .store = mts_attr_store_gpio_pin_inverted, +}; - return sprintf(buf, "%d\n", value); -} +static struct device_attribute dev_attr_led_cd_gpio = { + .attr = { + .name = "led-cd", + .mode = MTS_ATTR_MODE_RW, + }, + .show = mts_attr_show_gpio_pin_inverted, + .store = mts_attr_store_gpio_pin_inverted, +}; static struct device_attribute dev_attr_reset = { .attr = { .name = "reset", .mode = MTS_ATTR_MODE_RO, }, - .show = mts_attr_show_reset, + .show = mts_attr_show_gpio_pin_inverted, }; static ssize_t mts_attr_show_reset_monitor(struct device *dev, @@ -1715,355 +1954,25 @@ static struct device_attribute dev_attr_adc3 = { .show = mts_attr_show_adc, }; -static ssize_t mts_attr_show_usbh2_ps_oc(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int value; - struct gpio_pin *pin = gpio_pin_by_name("USBH2_PS_OC"); - - if (!pin) { - return -ENODEV; - } - - mutex_lock(&mts_io_mutex); - - value = at91_get_gpio_value(pin->pin); - - mutex_unlock(&mts_io_mutex); - - if (value < 0) { - return value; - } - - return sprintf(buf, "%d\n", !value); -} - static struct device_attribute dev_attr_usbh2_ps_oc = { .attr = { .name = "usbh2-ps-oc", .mode = MTS_ATTR_MODE_RO, }, - .show = mts_attr_show_usbh2_ps_oc, + .show = mts_attr_show_gpio_pin_inverted, }; #if USBH2_PS_CONTROLLABLE -static ssize_t mts_attr_show_usbh2_ps_enabled(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int value; - struct gpio_pin *pin = gpio_pin_by_name("USBH2_PS_ENABLED"); - - if (!pin) { - return -ENODEV; - } - - mutex_lock(&mts_io_mutex); - - value = at91_get_gpio_value(pin->pin); - - mutex_unlock(&mts_io_mutex); - - if (value < 0) { - return value; - } - - return sprintf(buf, "%d\n", !value); -} - -static ssize_t mts_attr_store_usbh2_ps_enabled(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int value; - int err; - struct gpio_pin *pin = gpio_pin_by_name("USBH2_PS_ENABLED"); - - if (!pin) { - return -ENODEV; - } - - if (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; - } - - mutex_lock(&mts_io_mutex); - - err = at91_set_gpio_value(pin->pin, !value); - - mutex_unlock(&mts_io_mutex); - - if (err) { - return err; - } - - return count; -} - static struct device_attribute dev_attr_usbh2_ps_enabled = { .attr = { .name = "usbh2-ps-enabled", .mode = MTS_ATTR_MODE_RW, }, - .show = mts_attr_show_usbh2_ps_enabled, - .store = mts_attr_store_usbh2_ps_enabled, + .show = mts_attr_show_gpio_pin_inverted, + .store = mts_attr_store_gpio_pin_inverted, }; #endif - -static ssize_t mts_attr_show_led2(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int value; - struct gpio_pin *pin = gpio_pin_by_name("LED2"); - - if (!pin) { - return -ENODEV; - } - - mutex_lock(&mts_io_mutex); - - value = at91_get_gpio_value(pin->pin); - - mutex_unlock(&mts_io_mutex); - - if (value < 0) { - return value; - } - - return sprintf(buf, "%d\n", !value); -} - -static ssize_t mts_attr_store_led2(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int value; - int err; - struct gpio_pin *pin = gpio_pin_by_name("LED2"); - - if (!pin) { - return -ENODEV; - } - - if (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; - } - - mutex_lock(&mts_io_mutex); - - err = at91_set_gpio_value(pin->pin, !value); - - mutex_unlock(&mts_io_mutex); - - if (err) { - return err; - } - - return count; -} - -static ssize_t mts_attr_show_gpio11(struct device *dev, - struct device_attribute *attr, char *buf) -{ - int value; - struct gpio_pin *pin = gpio_pin_by_name("GPIO11"); - - if (!pin) { - return -ENODEV; - } - - mutex_lock(&mts_io_mutex); - - value = at91_get_gpio_value(pin->pin); - - mutex_unlock(&mts_io_mutex); - - if (value < 0) { - return value; - } - - return sprintf(buf, "%d\n", value); -} - -static ssize_t mts_attr_store_gpio11(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int value; - int err; - struct gpio_pin *pin = gpio_pin_by_name("GPIO11"); - - if (!pin) { - return -ENODEV; - } - - if (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; - } - - mutex_lock(&mts_io_mutex); - - err = at91_set_gpio_value(pin->pin, value); - - mutex_unlock(&mts_io_mutex); - - return count; -} - -static ssize_t mts_attr_show_gpio12(struct device *dev, - struct device_attribute *attr, char *buf) -{ - int value; - struct gpio_pin *pin = gpio_pin_by_name("GPIO12"); - - if (!pin) { - return -ENODEV; - } - - mutex_lock(&mts_io_mutex); - - value = at91_get_gpio_value(pin->pin); - - mutex_unlock(&mts_io_mutex); - - if (value < 0) { - return value; - } - - return sprintf(buf, "%d\n", value); -} - -static ssize_t mts_attr_store_gpio12(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int value; - int err; - struct gpio_pin *pin = gpio_pin_by_name("GPIO12"); - - if (!pin) { - return -ENODEV; - } - - if (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; - } - - mutex_lock(&mts_io_mutex); - - err = at91_set_gpio_value(pin->pin, value); - - mutex_unlock(&mts_io_mutex); - - if (err) { - return err; - } - - return count; -} - -static ssize_t mts_attr_show_rsersrc(struct device *dev, - struct device_attribute *attr, char *buf) -{ - int value; - struct gpio_pin *pin = gpio_pin_by_name("RSERSRC"); - - if (!pin) { - return -ENODEV; - } - - mutex_lock(&mts_io_mutex); - - value = at91_get_gpio_value(pin->pin); - - mutex_unlock(&mts_io_mutex); - - if (value < 0) { - return value; - } - - return sprintf(buf, "%d\n", !value); -} - -static ssize_t mts_attr_store_rsersrc(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int value; - int err; - struct gpio_pin *pin = gpio_pin_by_name("RSERSRC"); - - if (!pin) { - return -ENODEV; - } - - if (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; - } - - mutex_lock(&mts_io_mutex); - - err = at91_set_gpio_value(pin->pin, !value); - - mutex_unlock(&mts_io_mutex); - - if (err) { - return err; - } - - return count; -} - -static ssize_t mts_attr_show_cd(struct device *dev, - struct device_attribute *attr, char *buf) -{ - int value; - struct gpio_pin *pin = gpio_pin_by_name("DCD1"); - - if (!pin) { - return -ENODEV; - } - - mutex_lock(&mts_io_mutex); - - value = at91_get_gpio_value(pin->pin); - - mutex_unlock(&mts_io_mutex); - - if (value < 0) { - return value; - } - - return sprintf(buf, "%d\n", !value); -} - -static ssize_t mts_attr_store_cd(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int value; - int err; - struct gpio_pin *pin = gpio_pin_by_name("DCD1"); - - if (!pin) { - return -ENODEV; - } - - if (sscanf(buf, "%i", &value) != 1) { - return -EINVAL; - } - - mutex_lock(&mts_io_mutex); - - err = at91_set_gpio_value(pin->pin, !value); - - mutex_unlock(&mts_io_mutex); - - if (err) { - return err; - } - - return count; -} - - static struct device_attribute dev_attr_gpo1 = { .attr = { .name = "gpo1", @@ -2162,8 +2071,8 @@ static struct device_attribute dev_attr_led2 = { .name = "led2", .mode = MTS_ATTR_MODE_RW, }, - .show = mts_attr_show_led2, - .store = mts_attr_store_led2, + .show = mts_attr_show_gpio_pin_inverted, + .store = mts_attr_store_gpio_pin_inverted, }; static struct device_attribute dev_attr_led3 = { @@ -2211,8 +2120,8 @@ static struct device_attribute dev_attr_gpio11 = { .name = "gpio11", .mode = MTS_ATTR_MODE_RW, }, - .show = mts_attr_show_gpio11, - .store = mts_attr_store_gpio11, + .show = mts_attr_show_gpio_pin, + .store = mts_attr_store_gpio_pin, }; static struct device_attribute dev_attr_gpio12 = { @@ -2220,8 +2129,8 @@ static struct device_attribute dev_attr_gpio12 = { .name = "gpio12", .mode = MTS_ATTR_MODE_RW, }, - .show = mts_attr_show_gpio12, - .store = mts_attr_store_gpio12, + .show = mts_attr_show_gpio_pin, + .store = mts_attr_store_gpio_pin, }; static struct device_attribute dev_attr_rsersrc = { @@ -2229,8 +2138,8 @@ static struct device_attribute dev_attr_rsersrc = { .name = "rsersrc", .mode = MTS_ATTR_MODE_RW, }, - .show = mts_attr_show_rsersrc, - .store = mts_attr_store_rsersrc, + .show = mts_attr_show_gpio_pin_inverted, + .store = mts_attr_store_gpio_pin_inverted, }; static struct device_attribute dev_attr_extserial_cd = { @@ -2238,8 +2147,8 @@ static struct device_attribute dev_attr_extserial_cd = { .name = "extserial-dcd", .mode = MTS_ATTR_MODE_RW, }, - .show = mts_attr_show_cd, - .store = mts_attr_store_cd, + .show = mts_attr_show_gpio_pin_inverted, + .store = mts_attr_store_gpio_pin_inverted, }; @@ -2284,6 +2193,30 @@ static struct attribute_group mt100eocg_platform_attribute_group = { .attrs = mt100eocg_platform_attributes }; +static struct attribute *en4_platform_attributes[] = { + &dev_attr_extserial_dtr.attr, + &dev_attr_extserial_dsr_gpio.attr, + &dev_attr_extserial_ri_gpio.attr, + &dev_attr_extserial_cd.attr, + &dev_attr_rsersrc.attr, + &dev_attr_radio_reset.attr, + &dev_attr_eth0_enabled.attr, + &dev_attr_bt_enabled.attr, + &dev_attr_wlan_enabled.attr, + + &dev_attr_led_sig1_gpio.attr, + &dev_attr_led_sig2_gpio.attr, + &dev_attr_led_sig3_gpio.attr, + &dev_attr_led_cd_gpio.attr, + + &dev_attr_board_temperature.attr, + + NULL, +}; + +static struct attribute_group en4_platform_attribute_group = { + .attrs = en4_platform_attributes +}; static struct attribute *platform_attributes[] = { &dev_attr_reset.attr, @@ -2548,6 +2481,13 @@ static int __init mts_io_init(void) goto error3; } } + else if ( mts_product_id == EN4_0_0 ) { + ret = sysfs_create_group(&mts_io_platform_device->dev.kobj, + &en4_platform_attribute_group); + if (ret) { + goto error3; + } + } else { ret = sysfs_create_group(&mts_io_platform_device->dev.kobj, &platform_attribute_group); @@ -2556,30 +2496,37 @@ static int __init mts_io_init(void) } } - // No sout driver for MT100EOCG - if ( mts_product_id != MT100EOCG_0_0 ) { + if ( has_spi_sout ) { ret = spi_register_driver(&mts_spi_sout_driver); if (ret) { goto error4; } } + ret = spi_register_driver(&mts_spi_board_temp_driver); if (ret) { goto error7; } - ret = spi_register_driver(&mts_spi_dout_driver); - if (ret) { - goto error5; + if ( has_spi_dout ) { + ret = spi_register_driver(&mts_spi_dout_driver); + if (ret) { + goto error5; + } } - - ret = spi_register_driver(&mts_spi_din_driver); - if (ret) { - goto error6; + if ( has_spi_din ) { + ret = spi_register_driver(&mts_spi_din_driver); + if (ret) { + goto error6; + } } +#ifdef CONFIG_ARCH_AT91SAM9X5 + adc_base = ioremap(AT91SAM9X5_BASE_ADC, SZ_16K); +#else adc_base = ioremap(AT91SAM9260_BASE_ADC, SZ_16K); +#endif if (!adc_base) { goto error8; } @@ -2621,9 +2568,11 @@ static int __init mts_io_init(void) } } - pin = gpio_pin_by_name("ENIO"); - if (pin) { - at91_set_gpio_value(pin->pin, 0); + if ( has_spi_sout || has_spi_dout || has_spi_din ) { + pin = gpio_pin_by_name("ENIO"); + if (pin) { + at91_set_gpio_value(pin->pin, 0); + } } // No blink_callback for MT100EOCG @@ -2638,11 +2587,15 @@ error9: error8: spi_unregister_driver(&mts_spi_board_temp_driver); error7: - spi_unregister_driver(&mts_spi_din_driver); + if ( has_spi_din ) { + spi_unregister_driver(&mts_spi_din_driver); + } error6: - spi_unregister_driver(&mts_spi_dout_driver); + if ( has_spi_dout ) { + spi_unregister_driver(&mts_spi_dout_driver); + } error5: - if ( mts_product_id != MT100EOCG_0_0 ) { + if ( has_spi_sout ) { spi_unregister_driver(&mts_spi_sout_driver); } error4: @@ -2650,6 +2603,10 @@ error4: sysfs_remove_group(&mts_io_platform_device->dev.kobj, &mt100eocg_platform_attribute_group); } + else if ( mts_product_id == EN4_0_0 ) { + sysfs_remove_group(&mts_io_platform_device->dev.kobj, + &en4_platform_attribute_group); + } else { sysfs_remove_group(&mts_io_platform_device->dev.kobj, &platform_attribute_group); @@ -2674,17 +2631,26 @@ static void __exit mts_io_exit(void) clk_disable(adc_clk); clk_put(adc_clk); - spi_unregister_driver(&mts_spi_din_driver); - spi_unregister_driver(&mts_spi_dout_driver); spi_unregister_driver(&mts_spi_board_temp_driver); + if (has_spi_din) + spi_unregister_driver(&mts_spi_din_driver); + + if (has_spi_dout) + spi_unregister_driver(&mts_spi_dout_driver); + + if (has_spi_sout) + spi_unregister_driver(&mts_spi_sout_driver); + if ( mts_product_id == MT100EOCG_0_0 ) { sysfs_remove_group(&mts_io_platform_device->dev.kobj, &mt100eocg_platform_attribute_group); } + else if ( mts_product_id == EN4_0_0 ) { + sysfs_remove_group(&mts_io_platform_device->dev.kobj, + &en4_platform_attribute_group); + } else { - spi_unregister_driver(&mts_spi_sout_driver); - sysfs_remove_group(&mts_io_platform_device->dev.kobj, &platform_attribute_group); } |