summaryrefslogtreecommitdiff
path: root/io-module/mts_io.c
diff options
context:
space:
mode:
authorJesse Gilles <jgilles@multitech.com>2013-02-28 16:26:43 -0600
committerJesse Gilles <jgilles@multitech.com>2013-02-28 16:26:43 -0600
commit4c3ee8ef4c442a4946e726fc0b221874f20da263 (patch)
tree145b2c748f4b8675d85a2e970b875d2bc6b974c2 /io-module/mts_io.c
parent179f87cf87c48e82f7e74b747fd9acbf9c1f8d3a (diff)
downloadcdp-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
Diffstat (limited to 'io-module/mts_io.c')
-rw-r--r--io-module/mts_io.c193
1 files changed, 103 insertions, 90 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");