diff options
author | Jesse Gilles <jgilles@multitech.com> | 2013-02-28 16:26:43 -0600 |
---|---|---|
committer | Jesse Gilles <jgilles@multitech.com> | 2013-02-28 16:26:43 -0600 |
commit | 4c3ee8ef4c442a4946e726fc0b221874f20da263 (patch) | |
tree | 145b2c748f4b8675d85a2e970b875d2bc6b974c2 | |
parent | 179f87cf87c48e82f7e74b747fd9acbf9c1f8d3a (diff) | |
download | cdp-io-controller-4c3ee8ef4c442a4946e726fc0b221874f20da263.tar.gz cdp-io-controller-4c3ee8ef4c442a4946e726fc0b221874f20da263.tar.bz2 cdp-io-controller-4c3ee8ef4c442a4946e726fc0b221874f20da263.zip |
more code clean up, rename platform to "mts-io", add mtocgd3 hardware
* add active_low to gpio struct, remove inverted gpio funcs
* rename platform to "mts-io", add symlink to "mtcdp" for compatbility
* add MTOCGD3 hardware
-rw-r--r-- | io-module/mts_io.c | 193 | ||||
-rw-r--r-- | io-module/mts_io.h | 4 | ||||
-rw-r--r-- | io-tool/mts-io-sysfs-inc.sh | 2 |
3 files changed, 108 insertions, 91 deletions
diff --git a/io-module/mts_io.c b/io-module/mts_io.c index ced39b9..6aacf74 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -1,5 +1,5 @@ /* - * MTCDP IO Controller + * MTS-IO Controller * * Copyright (C) 2013 by Multi-Tech Systems * @@ -44,10 +44,10 @@ #define DRIVER_VERSION "v0.6.0" #define DRIVER_AUTHOR "James Maki <jmaki@multitech.com>" -#define DRIVER_DESC "MTCDP IO Controller" +#define DRIVER_DESC "MTS-IO Controller" #define DRIVER_NAME "mts-io" -#define PLATFORM_NAME "mtcdp" +#define PLATFORM_NAME "mts-io" #define DEBUG 0 @@ -128,6 +128,7 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = { .direction = GPIO_DIR_INPUT, .output_value = 0, .use_pullup = 0, + .active_low = 1, }, { .name = "LS_LED", @@ -140,6 +141,7 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = { #endif .output_value = 1, .use_pullup = 0, + .active_low = 1, }, #if LED_STATUS_CONTROLLABLE_MTCDP { @@ -158,6 +160,7 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "DTR1", @@ -166,6 +169,7 @@ static struct gpio_pin gpio_pins_mtcdp_0_0[] = { .direction = GPIO_DIR_INPUT, .output_value = 0, .use_pullup = 0, + .active_low = 1, }, { }, }; @@ -202,6 +206,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { .direction = GPIO_DIR_INPUT, .output_value = 0, .use_pullup = 0, + .active_low = 1, }, { .name = "LS_LED", @@ -214,6 +219,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { #endif .output_value = 1, .use_pullup = 0, + .active_low = 1, }, #if LED_STATUS_CONTROLLABLE_MTCDP { @@ -232,6 +238,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "TXD1", @@ -248,6 +255,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { .direction = GPIO_DIR_INPUT, .output_value = 0, .use_pullup = 0, + .active_low = 1, }, { .name = "USBH2_PS_OC", @@ -256,6 +264,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { .direction = GPIO_DIR_INPUT, .output_value = 0, .use_pullup = 0, + .active_low = 1, }, #if USBH2_PS_CONTROLLABLE { @@ -265,6 +274,7 @@ static struct gpio_pin gpio_pins_mtcdp_1_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 0, .use_pullup = 0, + .active_low = 1, }, #endif { @@ -322,6 +332,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { #endif .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "LED2", @@ -330,6 +341,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "RSERSRC", @@ -338,6 +350,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "TXD1", @@ -354,6 +367,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { .direction = GPIO_DIR_INPUT, .output_value = 0, .use_pullup = 0, + .active_low = 1, }, { .name = "DCD1", @@ -362,6 +376,7 @@ static struct gpio_pin gpio_pins_mt100eocg_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "GPIO11", @@ -418,6 +433,7 @@ static struct gpio_pin gpio_pins_mtr2_0_0[] = { #endif .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "STATUS_LED", @@ -434,6 +450,7 @@ static struct gpio_pin gpio_pins_mtr2_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "LED10", @@ -442,6 +459,7 @@ static struct gpio_pin gpio_pins_mtr2_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "LED11", @@ -450,6 +468,7 @@ static struct gpio_pin gpio_pins_mtr2_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "LED12", @@ -458,6 +477,7 @@ static struct gpio_pin gpio_pins_mtr2_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "LED13", @@ -466,6 +486,7 @@ static struct gpio_pin gpio_pins_mtr2_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "UART3_DTR", @@ -474,6 +495,7 @@ static struct gpio_pin gpio_pins_mtr2_0_0[] = { .direction = GPIO_DIR_INPUT, .output_value = 0, .use_pullup = 0, + .active_low = 1, }, { .name = "UART3_DSR", @@ -482,6 +504,7 @@ static struct gpio_pin gpio_pins_mtr2_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "UART3_DCD", @@ -490,6 +513,7 @@ static struct gpio_pin gpio_pins_mtr2_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "UART3_RI", @@ -498,6 +522,7 @@ static struct gpio_pin gpio_pins_mtr2_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "NDC_RESET", @@ -602,6 +627,7 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { #endif .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "STATUS_LED", @@ -618,6 +644,7 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "LED4", @@ -626,6 +653,7 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "LED6", @@ -634,6 +662,7 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "LED7", @@ -642,6 +671,7 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "LED8", @@ -650,6 +680,7 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "RI_B", @@ -658,6 +689,7 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "DTR_B", @@ -666,6 +698,7 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .direction = GPIO_DIR_INPUT, .output_value = 0, .use_pullup = 0, + .active_low = 1, }, { .name = "DSR_B", @@ -674,6 +707,7 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "DCD_B", @@ -682,6 +716,7 @@ static struct gpio_pin gpio_pins_mtr_0_0[] = { .direction = GPIO_DIR_OUTPUT, .output_value = 1, .use_pullup = 0, + .active_low = 1, }, { .name = "BT_EN", @@ -1010,31 +1045,11 @@ static ssize_t mts_attr_show_gpio_pin(struct device *dev, return value; } - return sprintf(buf, "%d\n", value); -} - -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_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; + if (pin->active_low) { + value = !value; } - return sprintf(buf, "%d\n", !value); + return sprintf(buf, "%d\n", value); } static ssize_t mts_attr_store_gpio_pin(struct device *dev, @@ -1052,37 +1067,13 @@ static ssize_t mts_attr_store_gpio_pin(struct device *dev, 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_store_gpio_pin_inverted(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; + if (pin->active_low) { + value = !value; } mutex_lock(&mts_io_mutex); - err = at91_set_gpio_value(pin->pin, !value); + err = at91_set_gpio_value(pin->pin, value); mutex_unlock(&mts_io_mutex); @@ -1495,13 +1486,13 @@ static DEVICE_ATTR_RO_MTS(dev_attr_din6, "din6", mts_attr_show_din); static DEVICE_ATTR_RO_MTS(dev_attr_din7, "din7", mts_attr_show_din); static DEVICE_ATTR_RO_MTS(dev_attr_extserial_dtr, "extserial-dtr", - mts_attr_show_gpio_pin_inverted); + mts_attr_show_gpio_pin); static DEVICE_ATTR_MTS(dev_attr_extserial_dsr_gpio, "extserial-dsr", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); static DEVICE_ATTR_MTS(dev_attr_extserial_ri_gpio, "extserial-ri", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); static ssize_t mts_attr_show_led_status(struct device *dev, struct device_attribute *attr, @@ -1565,26 +1556,26 @@ static DEVICE_ATTR_MTS(dev_attr_led_sdk_a, "led-sdk-a", #if LED_LS_CONTROLLABLE static DEVICE_ATTR_MTS(dev_attr_led_ls, "led-ls", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); #else static DEVICE_ATTR_RO_MTS(dev_attr_led_ls, "led-ls", - mts_attr_show_gpio_pin_inverted); + mts_attr_show_gpio_pin); #endif static DEVICE_ATTR_MTS(dev_attr_led_sig1_gpio, "led-sig1", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); static DEVICE_ATTR_MTS(dev_attr_led_sig2_gpio, "led-sig2", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); static DEVICE_ATTR_MTS(dev_attr_led_sig3_gpio, "led-sig3", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); static DEVICE_ATTR_MTS(dev_attr_led_cd_gpio, "led-cd", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); static DEVICE_ATTR_MTS(dev_attr_led_wifi_gpio, "led-wifi", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); -static DEVICE_ATTR_RO_MTS(dev_attr_reset, "reset", mts_attr_show_gpio_pin_inverted); +static DEVICE_ATTR_RO_MTS(dev_attr_reset, "reset", mts_attr_show_gpio_pin); static DEVICE_ATTR_MTS(dev_attr_rs4xx_term_res, "rs4xx-term-res", mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); @@ -1715,11 +1706,11 @@ static DEVICE_ATTR_RO_MTS(dev_attr_adc2, "adc2", mts_attr_show_adc); static DEVICE_ATTR_RO_MTS(dev_attr_adc3, "adc3", mts_attr_show_adc); static DEVICE_ATTR_RO_MTS(dev_attr_usbh2_ps_oc, "usbh2-ps-oc", - mts_attr_show_gpio_pin_inverted); + mts_attr_show_gpio_pin); #if USBH2_PS_CONTROLLABLE static DEVICE_ATTR_MTS(dev_attr_usbh2_ps_enabled, "usbh2-ps-enabled", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); #endif static DEVICE_ATTR_MTS(dev_attr_gpo1, "gpo1", @@ -1741,13 +1732,13 @@ static DEVICE_ATTR_RO_MTS(dev_attr_gpi10, "gpi10", mts_attr_show_din); static DEVICE_ATTR_MTS(dev_attr_led1, "led1", mts_attr_show_dout, mts_attr_store_dout); static DEVICE_ATTR_MTS(dev_attr_led2, "led2", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); #if LED_LS_CONTROLLABLE static DEVICE_ATTR_MTS(dev_attr_led3, "led3", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); #else -static DEVICE_ATTR_RO_MTS(dev_attr_led3, "led3", mts_attr_show_gpio_pin_inverted); +static DEVICE_ATTR_RO_MTS(dev_attr_led3, "led3", mts_attr_show_gpio_pin); #endif static DEVICE_ATTR_MTS(dev_attr_led4, "led4", @@ -1763,9 +1754,9 @@ static DEVICE_ATTR_MTS(dev_attr_gpio12, "gpio12", mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); static DEVICE_ATTR_MTS(dev_attr_rsersrc, "rsersrc", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); static DEVICE_ATTR_MTS(dev_attr_extserial_dcd_gpio, "extserial-dcd", - mts_attr_show_gpio_pin_inverted, mts_attr_store_gpio_pin_inverted); + mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); static ssize_t mts_attr_show_serial_mode(struct device *dev, struct device_attribute *attr, @@ -2238,6 +2229,15 @@ static int mts_id_eeprom_load(void) has_spi_dout = 0; has_spi_temp = 0; log_info("detected board %s", HW_VERSION_MTR_0_0); + } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTOCGD3_0_0, strlen(HW_VERSION_MTOCGD3_0_0)) == 0) { + attr_group = &mtr2_platform_attribute_group; + gpio_pins = gpio_pins_mtr2_0_0; + mts_product_id = MTOCGD3_0_0; + has_spi_sout = 0; + has_spi_din = 0; + has_spi_dout = 0; + has_spi_temp = 1; + log_info("detected board %s", HW_VERSION_MTOCGD3_0_0); } else { attr_group = &mtcdp_platform_attribute_group; gpio_pins = gpio_pins_mtcdp_1_0; @@ -2309,35 +2309,44 @@ static int __init mts_io_init(void) goto error2; } - ret = sysfs_create_group(&mts_io_platform_device->dev.kobj, attr_group); + /* preserve backwards compatibility with old mtcdp platform name */ + ret = sysfs_create_link(&mts_io_platform_device->dev.parent->kobj, + &mts_io_platform_device->dev.kobj, + "mtcdp"); if (ret) { + log_error("sysfs_create_link failed: %d", ret); goto error3; } - if ( has_spi_sout ) { - ret = spi_register_driver(&mts_spi_sout_driver); - if (ret) { - goto error4; - } + ret = sysfs_create_group(&mts_io_platform_device->dev.kobj, attr_group); + if (ret) { + goto error4; } - if ( has_spi_temp ) { - ret = spi_register_driver(&mts_spi_board_temp_driver); + if ( has_spi_sout ) { + ret = spi_register_driver(&mts_spi_sout_driver); if (ret) { - goto error7; + goto error5; } } if ( has_spi_dout ) { ret = spi_register_driver(&mts_spi_dout_driver); if (ret) { - goto error5; + goto error6; } } if ( has_spi_din ) { ret = spi_register_driver(&mts_spi_din_driver); if (ret) { - goto error6; + goto error7; + } + } + + if ( has_spi_temp ) { + ret = spi_register_driver(&mts_spi_board_temp_driver); + if (ret) { + goto error8; } } @@ -2347,12 +2356,12 @@ static int __init mts_io_init(void) adc_base = ioremap(AT91SAM9260_BASE_ADC, SZ_16K); #endif if (!adc_base) { - goto error8; + goto error9; } adc_clk = clk_get(NULL, "adc_clk"); if (!adc_clk) { - goto error9; + goto error10; } clk_enable(adc_clk); @@ -2392,26 +2401,28 @@ static int __init mts_io_init(void) return 0; -error9: +error10: iounmap(adc_base); -error8: +error9: if ( has_spi_temp ) { spi_unregister_driver(&mts_spi_board_temp_driver); } -error7: +error8: if ( has_spi_din ) { spi_unregister_driver(&mts_spi_din_driver); } -error6: +error7: if ( has_spi_dout ) { spi_unregister_driver(&mts_spi_dout_driver); } -error5: +error6: if ( has_spi_sout ) { spi_unregister_driver(&mts_spi_sout_driver); } -error4: +error5: sysfs_remove_group(&mts_io_platform_device->dev.kobj, attr_group); +error4: + sysfs_remove_link(&mts_io_platform_device->dev.parent->kobj, "mtcdp"); error3: platform_device_del(mts_io_platform_device); error2: @@ -2446,6 +2457,8 @@ static void __exit mts_io_exit(void) sysfs_remove_group(&mts_io_platform_device->dev.kobj, attr_group); + sysfs_remove_link(&mts_io_platform_device->dev.parent->kobj, "mtcdp"); + platform_device_unregister(mts_io_platform_device); log_info("exiting"); diff --git a/io-module/mts_io.h b/io-module/mts_io.h index 5f2235c..4d6a1bd 100644 --- a/io-module/mts_io.h +++ b/io-module/mts_io.h @@ -30,6 +30,7 @@ struct device_attribute _dev_name = { \ #define PRODUCT_ID_MT100EOCG "MT100EOCG" #define PRODUCT_ID_MTR2 "MTR2" #define PRODUCT_ID_MTR "MTR" +#define PRODUCT_ID_MTOCGD3 "MTOCGD3" #define HW_VERSION_MTCBA2_2_0 "MTCBA2-2.0" #define HW_VERSION_MTCDP_0_0 "MTCDP-0.0" @@ -37,6 +38,7 @@ struct device_attribute _dev_name = { \ #define HW_VERSION_MT100EOCG_0_0 "MT100EOCG-0.0" #define HW_VERSION_MTR2_0_0 "MTR2-0.0" #define HW_VERSION_MTR_0_0 "MTR-0.0" +#define HW_VERSION_MTOCGD3_0_0 "MTOCGD3-0.0" enum { MTCDP_E1_DK_0_0, @@ -44,6 +46,7 @@ enum { MT100EOCG_0_0, MTR2_0_0, MTR_0_0, + MTOCGD3_0_0, }; #define DEVICE_CAPA_INDEX(c) (((c) & 0xFF) >> 3) @@ -98,6 +101,7 @@ struct gpio_pin { int direction; int output_value; int use_pullup; + int active_low; }; enum { diff --git a/io-tool/mts-io-sysfs-inc.sh b/io-tool/mts-io-sysfs-inc.sh index c4a48db..af94a7a 100644 --- a/io-tool/mts-io-sysfs-inc.sh +++ b/io-tool/mts-io-sysfs-inc.sh @@ -23,7 +23,7 @@ VERBOSE=false -PLATFORM_NAME=mtcdp +PLATFORM_NAME=mts-io SYSFS_PLATFORM_DIR=/sys/devices/platform/${PLATFORM_NAME} MTS_IO_CONTROLS_STATUS_LED=false |