summaryrefslogtreecommitdiff
path: root/io-module
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2014-10-08 10:38:26 -0500
committerMike Fiore <mfiore@multitech.com>2014-10-08 10:38:26 -0500
commit72412963e66f4a2448fd87f455b33f3a5115f4bd (patch)
treeb4d91a4a929356571fda47baafc600c11f842348 /io-module
parentb4e12fd5092d6de675da8c6a3629a23dcb5a34f2 (diff)
downloadmts-io-72412963e66f4a2448fd87f455b33f3a5115f4bd.tar.gz
mts-io-72412963e66f4a2448fd87f455b33f3a5115f4bd.tar.bz2
mts-io-72412963e66f4a2448fd87f455b33f3a5115f4bd.zip
mts-io: remove all unused spi and adc code from mtcdp
remote board-temperature attribute
Diffstat (limited to 'io-module')
-rw-r--r--io-module/adc.c87
-rw-r--r--io-module/mtac_gpiob.c37
-rw-r--r--io-module/mtr2d2.c3
-rw-r--r--io-module/mts_io.c133
-rw-r--r--io-module/spi.c608
5 files changed, 42 insertions, 826 deletions
diff --git a/io-module/adc.c b/io-module/adc.c
deleted file mode 100644
index bcb3598..0000000
--- a/io-module/adc.c
+++ /dev/null
@@ -1,87 +0,0 @@
-
-#define ADC_SHTIME_DEFAULT 0x05
-#define ADC_STARTUP_DEFAULT 0x04
-#define ADC_PRESCALE_DEFAULT 0x3F
-#define ADC_MODE_DEFAULT \
- ((ADC_SHTIME_DEFAULT & 0x0F) << 24) | \
- ((ADC_STARTUP_DEFAULT & 0x1F) << 16) | \
- ((ADC_PRESCALE_DEFAULT & 0x3F) << 8)
-
-#define ADC_CR_OFFSET 0x00
-#define ADC_MR_OFFSET 0x04
-#define ADC_CHER_OFFSET 0x10
-#define ADC_CHDR_OFFSET 0x14
-#define ADC_CHSR_OFFSET 0x18
-#define ADC_SR_OFFSET 0x1C
-#define ADC_LDCR_OFFSET 0x20
-#define ADC_IER_OFFSET 0x14
-#define ADC_IDR_OFFSET 0x28
-#define ADC_IMR_OFFSET 0x2C
-#define ADC_CDR0_OFFSET 0x30
-#define ADC_CDR1_OFFSET 0x34
-#define ADC_CDR2_OFFSET 0x38
-#define ADC_CDR3_OFFSET 0x3C
-
-void __iomem *adc_base;
-struct clk *adc_clk;
-
-#define ADC_CONVERT_RESET(base) writel(0x01, (base) + ADC_CR_OFFSET)
-#define ADC_CONVERT_START(base) writel(0x02, (base) + ADC_CR_OFFSET)
-
-static ssize_t mts_attr_show_adc(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- int offset;
- u32 value;
- u32 chan_mask;
-
- if (!DEVICE_CAPA(id_eeprom.capa, CAPA_ADC)) {
- log_debug("ADC not available");
- return -ENODEV;
- }
-
- if (!strcmp(attr->attr.name, "adc0")) {
- offset = ADC_CDR0_OFFSET;
- chan_mask = 0x01;
- } else if (!strcmp(attr->attr.name, "adc1")) {
- offset = ADC_CDR1_OFFSET;
- chan_mask = 0x02;
- } else if (!strcmp(attr->attr.name, "adc2")) {
- offset = ADC_CDR2_OFFSET;
- chan_mask = 0x04;
- } else if (!strcmp(attr->attr.name, "adc3")) {
- offset = ADC_CDR3_OFFSET;
- chan_mask = 0x08;
- } else {
- log_notice("adc attr does not exist");
- return -ENOENT;
- }
-
- mutex_lock(&mts_io_mutex);
-
- // disable all channels and enable the one we want
- writel(0x0F, adc_base + ADC_CHDR_OFFSET);
- writel(chan_mask, adc_base + ADC_CHER_OFFSET);
-
- ADC_CONVERT_START(adc_base);
-
- // wait for conversion to complete (EOC bit set)
- value = 0;
- while (value != chan_mask) {
- value = readl(adc_base + ADC_SR_OFFSET) & chan_mask;
- log_debug("ADC_SR EOC [%X]", value);
- }
-
- // read result
- value = readl(adc_base + offset);
-
- mutex_unlock(&mts_io_mutex);
-
- return sprintf(buf, "%lu\n", (unsigned long) value);
-}
-
-static DEVICE_ATTR_RO_MTS(dev_attr_adc0, "adc0", mts_attr_show_adc);
-static DEVICE_ATTR_RO_MTS(dev_attr_adc1, "adc1", mts_attr_show_adc);
-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);
diff --git a/io-module/mtac_gpiob.c b/io-module/mtac_gpiob.c
index 3f9631d..0485494 100644
--- a/io-module/mtac_gpiob.c
+++ b/io-module/mtac_gpiob.c
@@ -30,6 +30,43 @@ static bool gpiob_get_dev_info_from_modalias(const char* modalias, int* port, ch
return true;
}
+/* Generic SPI functions */
+static inline int spi_writen(struct spi_device *spi, const u8 *buf, size_t len)
+{
+ int tmp;
+ u8 *tx;
+
+ tx = kmalloc(len, GFP_KERNEL);
+ if (!tx) {
+ return -ENOMEM;
+ }
+
+ memcpy(tx, buf, len);
+ tmp = spi_write(spi, tx, len);
+
+ kfree(tx);
+
+ return tmp;
+}
+
+static inline int spi_readn(struct spi_device *spi, u8 *buf, size_t len)
+{
+ int tmp;
+ u8 *rx;
+
+ rx = kmalloc(len, GFP_KERNEL);
+ if (!rx) {
+ return -ENOMEM;
+ }
+
+ tmp = spi_read(spi, rx, len);
+ memcpy(buf, rx, len);
+
+ kfree(rx);
+
+ return tmp;
+}
+
static int mts_spi_ap_probe(struct spi_device *spi)
{
int tmp;
diff --git a/io-module/mtr2d2.c b/io-module/mtr2d2.c
index 24a99f3..428d71c 100644
--- a/io-module/mtr2d2.c
+++ b/io-module/mtr2d2.c
@@ -292,9 +292,8 @@ static struct attribute *mtr2d2_platform_attributes[] = {
&dev_attr_led_d_gpio.attr,
&dev_attr_led_e_gpio.attr,
- &dev_attr_board_temperature.attr,
-
/* extra space for the accessory card attributes */
+ NULL, // index 20
NULL, // index 21
NULL, // index 22
NULL, // index 23
diff --git a/io-module/mts_io.c b/io-module/mts_io.c
index 38d1086..fa61e1f 100644
--- a/io-module/mts_io.c
+++ b/io-module/mts_io.c
@@ -54,8 +54,6 @@
#define LED_LS_CONTROLLABLE 0
-#define AT91SAM9X5_BASE_ADC 0xf804c000
-
/* on-board EEPROM */
extern uint8_t mts_id_eeprom[512];
static struct mts_id_eeprom_layout id_eeprom;
@@ -86,12 +84,6 @@ static struct attribute_group ap_attr_groups[NUM_AP];
static struct ap_info* port_info[NUM_AP];
-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 uint8_t has_spi_temp;
-
static struct platform_device *mts_io_platform_device;
static struct attribute_group *attr_group;
static struct gpio_pin *gpio_pins;
@@ -101,12 +93,6 @@ static DEFINE_MUTEX(mts_io_mutex);
/* generic GPIO support */
#include "gpio.c"
-/* AT91 built-in ADC */
-#include "adc.c"
-
-/* SPI-based stuff */
-#include "spi.c"
-
/* accessory card support */
#include "mtac.c"
#include "mtac_gpiob.c"
@@ -479,23 +465,12 @@ 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;
- has_spi_temp = 1;
-
if (mts_id_eeprom[0] == 0xFF) {
log_error("uninitialized eeprom");
return -EIO;
} else {
attr_group = &mtr2d2_platform_attribute_group;
gpio_pins = gpio_pins_mtr2d2_0_0;
- mts_product_id = MTR2D2_0_0;
- has_spi_sout = 0;
- has_spi_din = 0;
- has_spi_dout = 0;
- has_spi_temp = 0;
log_info("detected board %s", HW_VERSION_MTR2D2_0_0);
}
@@ -586,56 +561,6 @@ static int __init mts_io_init(void)
goto error4;
}
- if ( has_spi_sout ) {
- ret = spi_register_driver(&mts_spi_sout_driver);
- if (ret) {
- goto error5;
- }
- }
-
- if ( has_spi_dout ) {
- ret = spi_register_driver(&mts_spi_dout_driver);
- if (ret) {
- goto error6;
- }
- }
- if ( has_spi_din ) {
- ret = spi_register_driver(&mts_spi_din_driver);
- if (ret) {
- goto error7;
- }
- }
-
- if ( has_spi_temp ) {
- ret = spi_register_driver(&mts_spi_board_temp_driver);
- if (ret) {
- goto error8;
- }
- }
-
- /* ADC Setup */
-#ifdef CONFIG_SOC_AT91SAM9X5
- adc_base = ioremap(AT91SAM9X5_BASE_ADC, SZ_16K);
-#else
- adc_base = ioremap(AT91SAM9260_BASE_ADC, SZ_16K);
-#endif
- if (!adc_base) {
- goto error9;
- }
-
- adc_clk = clk_get(NULL, "adc_clk");
- if (!adc_clk) {
- goto error10;
- }
- clk_enable(adc_clk);
-
- ADC_CONVERT_RESET(adc_base);
- writel(ADC_MODE_DEFAULT, adc_base + ADC_MR_OFFSET);
- writel(0x000F0F0F, adc_base + ADC_IDR_OFFSET);
- if (!DEVICE_CAPA(id_eeprom.capa, CAPA_ADC)) {
- writel(0x0F, adc_base + ADC_CHDR_OFFSET);
- }
-
for (pin = gpio_pins; *pin->name; pin++) {
ret = gpio_request_one(pin->pin.gpio, pin->pin.flags, pin->pin.label);
if (ret) {
@@ -643,41 +568,13 @@ static int __init mts_io_init(void)
}
}
- if ( has_spi_sout || has_spi_dout || has_spi_din ) {
- pin = gpio_pin_by_name("ENIO");
- if (pin) {
- gpio_set_value(pin->pin.gpio, 0);
- }
- }
-
- // No reset_callback for MT100EOCG
- if ( mts_product_id != MT100EOCG_0_0 ) {
- reset_callback(NULL);
- }
+ // start the reset handler
+ reset_callback(NULL);
return 0;
-error10:
- iounmap(adc_base);
-error9:
- if ( has_spi_temp ) {
- spi_unregister_driver(&mts_spi_board_temp_driver);
- }
-error8:
- if ( has_spi_din ) {
- spi_unregister_driver(&mts_spi_din_driver);
- }
-error7:
- if ( has_spi_dout ) {
- spi_unregister_driver(&mts_spi_dout_driver);
- }
-error6:
- if ( has_spi_sout ) {
- spi_unregister_driver(&mts_spi_sout_driver);
- }
-error5:
- sysfs_remove_group(&mts_io_platform_device->dev.kobj, attr_group);
error4:
+ sysfs_remove_group(&mts_io_platform_device->dev.kobj, attr_group);
sysfs_remove_link(&mts_io_platform_device->dev.parent->kobj, "mtcdp");
error3:
platform_device_del(mts_io_platform_device);
@@ -700,25 +597,7 @@ static void __exit mts_io_exit(void)
int port;
int port_index;
- if ( mts_product_id != MT100EOCG_0_0 ) {
- cancel_delayed_work_sync(&reset_work);
- }
-
- iounmap(adc_base);
- clk_disable(adc_clk);
- clk_put(adc_clk);
-
- if (has_spi_temp)
- 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);
+ cancel_delayed_work_sync(&reset_work);
sysfs_remove_group(&mts_io_platform_device->dev.kobj, attr_group);
@@ -744,10 +623,6 @@ MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_VERSION(DRIVER_VERSION);
MODULE_LICENSE("GPL");
-MODULE_ALIAS("mts-io-sout");
-MODULE_ALIAS("mts-io-board-temp");
-MODULE_ALIAS("mts-io-dout");
-MODULE_ALIAS("mts-io-din");
MODULE_ALIAS("mts-io-ap1-dout");
MODULE_ALIAS("mts-io-ap1-din");
MODULE_ALIAS("mts-io-ap1-adc");
diff --git a/io-module/spi.c b/io-module/spi.c
deleted file mode 100644
index 210371c..0000000
--- a/io-module/spi.c
+++ /dev/null
@@ -1,608 +0,0 @@
-/* SPI devices, functions, and attributes */
-
-static int ADT7302_to_celsius(int value)
-{
- if (value & 0x2000) {
- value = value - 16384;
- }
-
- value = value / 32 + 1 * ((value % 32) >= 16);
-
- return value;
-}
-
-/* SPI Devices */
-static struct spi_device *spi_sout_dev;
-static u8 spi_sout_value;
-static DEFINE_MUTEX(spi_sout_mutex);
-static unsigned int sout_max_speed_hz = 1 * 1000 * 1000;
-module_param(sout_max_speed_hz, uint, S_IRUGO);
-MODULE_PARM_DESC(
- sout_max_speed_hz,
- "Maximum clock rate to be used with this device (default: 1 MHz)"
-);
-
-static struct spi_device *spi_dout_dev;
-static u8 spi_dout_value;
-static DEFINE_MUTEX(spi_dout_mutex);
-static unsigned int dout_max_speed_hz = 1 * 1000 * 1000;
-module_param(dout_max_speed_hz, uint, S_IRUGO);
-MODULE_PARM_DESC(
- dout_max_speed_hz,
- "Maximum clock rate to be used with this device (default: 1 MHz)"
-);
-
-static struct spi_device *spi_din_dev;
-static unsigned int din_max_speed_hz = 1 * 1000 * 1000;
-module_param(din_max_speed_hz, uint, S_IRUGO);
-MODULE_PARM_DESC(
- din_max_speed_hz,
- "Maximum clock rate to be used with this device (default: 1 MHz)"
-);
-
-static struct spi_device *spi_board_temp_dev;
-static unsigned int board_temp_max_speed_hz = 1 * 1000 * 1000;
-module_param(board_temp_max_speed_hz, uint, S_IRUGO);
-MODULE_PARM_DESC(
- board_temp_max_speed_hz,
- "Maximum clock rate to be used with this device (default: 1 MHz)"
-);
-
-/* Generic SPI functions */
-static inline int spi_writen(struct spi_device *spi, const u8 *buf, size_t len)
-{
- int tmp;
- u8 *tx;
-
- tx = kmalloc(len, GFP_KERNEL);
- if (!tx) {
- return -ENOMEM;
- }
-
- memcpy(tx, buf, len);
- tmp = spi_write(spi, tx, len);
-
- kfree(tx);
-
- return tmp;
-}
-
-static inline int spi_readn(struct spi_device *spi, u8 *buf, size_t len)
-{
- int tmp;
- u8 *rx;
-
- rx = kmalloc(len, GFP_KERNEL);
- if (!rx) {
- return -ENOMEM;
- }
-
- tmp = spi_read(spi, rx, len);
- memcpy(buf, rx, len);
-
- kfree(rx);
-
- return tmp;
-}
-
-/* ----------------------------------------------------------------------------
- *
- * SPI-based attribute show/store functions
- *
- * ----------------------------------------------------------------------------
-*/
-
-#define SOUT_LED_CD_BIT BIT(0)
-#define SOUT_EXTSERIAL_RI_BIT BIT(1)
-#define SOUT_EXTSERIAL_DSR_BIT BIT(2)
-#define SOUT_LED_DTR BIT(3)
-#define SOUT_LED_SIG1_BIT BIT(4)
-#define SOUT_LED_SIG2_BIT BIT(5)
-#define SOUT_LED_SIG3_BIT BIT(6)
-#define SOUT_EXTSERIAL_DCD_BIT BIT(7)
-
-static ssize_t mts_attr_store_sout(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
-{
- int value;
- u8 bit;
-
- if (!spi_sout_dev) {
- log_notice("sout device not present");
- return -ENODEV;
- }
-
- if (!strcmp(attr->attr.name, "extserial-ri")) {
- bit = SOUT_EXTSERIAL_RI_BIT;
- } else if (!strcmp(attr->attr.name, "extserial-dsr")) {
- bit = SOUT_EXTSERIAL_DSR_BIT;
- } else if (!strcmp(attr->attr.name, "extserial-dcd")) {
- bit = SOUT_EXTSERIAL_DCD_BIT;
- } else if (!strcmp(attr->attr.name, "led-cd") ||
- !strcmp(attr->attr.name, "led-sdk-b")) {
- bit = SOUT_LED_CD_BIT;
- } else if (!strcmp(attr->attr.name, "led-dtr") ||
- !strcmp(attr->attr.name, "led-sdk-f")) {
- bit = SOUT_LED_DTR;
- } else if (!strcmp(attr->attr.name, "led-sig1") ||
- !strcmp(attr->attr.name, "led-sdk-c")) {
- bit = SOUT_LED_SIG1_BIT;
- } else if (!strcmp(attr->attr.name, "led-sig2") ||
- !strcmp(attr->attr.name, "led-sdk-d")) {
- bit = SOUT_LED_SIG2_BIT;
- } else if (!strcmp(attr->attr.name, "led-sig3") ||
- !strcmp(attr->attr.name, "led-sdk-e")) {
- bit = SOUT_LED_SIG3_BIT;
- } else {
- log_notice("sout attr does not exist");
- return -ENOENT;
- }
-
- if (sscanf(buf, "%i", &value) != 1) {
- log_notice("sout attr invalid argument");
- return -EINVAL;
- }
-
- mutex_lock(&spi_sout_mutex);
-
- if (value) {
- spi_sout_value &= ~bit;
- } else {
- spi_sout_value |= bit;
- }
- spi_writen(spi_sout_dev, &spi_sout_value, 1);
-
- mutex_unlock(&spi_sout_mutex);
-
- return count;
-}
-
-static ssize_t mts_attr_show_sout(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- int value;
- u8 bit;
-
- if (!spi_sout_dev) {
- log_error("sout device not present");
- return -ENODEV;
- }
-
- if (!strcmp(attr->attr.name, "extserial-ri")) {
- bit = SOUT_EXTSERIAL_RI_BIT;
- } else if (!strcmp(attr->attr.name, "extserial-dsr")) {
- bit = SOUT_EXTSERIAL_DSR_BIT;
- } else if (!strcmp(attr->attr.name, "extserial-dcd")) {
- bit = SOUT_EXTSERIAL_DCD_BIT;
- } else if (!strcmp(attr->attr.name, "led-cd") ||
- !strcmp(attr->attr.name, "led-sdk-b")) {
- bit = SOUT_LED_CD_BIT;
- } else if (!strcmp(attr->attr.name, "led-dtr") ||
- !strcmp(attr->attr.name, "led-sdk-f")) {
- bit = SOUT_LED_DTR;
- } else if (!strcmp(attr->attr.name, "led-sig1") ||
- !strcmp(attr->attr.name, "led-sdk-c")) {
- bit = SOUT_LED_SIG1_BIT;
- } else if (!strcmp(attr->attr.name, "led-sig2") ||
- !strcmp(attr->attr.name, "led-sdk-d")) {
- bit = SOUT_LED_SIG2_BIT;
- } else if (!strcmp(attr->attr.name, "led-sig3") ||
- !strcmp(attr->attr.name, "led-sdk-e")) {
- bit = SOUT_LED_SIG3_BIT;
- } else {
- log_notice("sout attr does not exist");
- return -ENOENT;
- }
-
- mutex_lock(&spi_sout_mutex);
-
- value = spi_sout_value & bit ? 0 : 1;
-
- mutex_unlock(&spi_sout_mutex);
-
- return sprintf(buf, "%d\n", value);
-}
-
-static ssize_t mts_attr_store_dout(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
-{
- int value;
- u8 bit;
-
- if (!spi_dout_dev) {
- log_notice("dout device not present");
- return -ENODEV;
- }
-
- if ((!strcmp(attr->attr.name, "dout0")) || (!strcmp(attr->attr.name, "gpo1"))) {
- bit = BIT(0);
- } else if ((!strcmp(attr->attr.name, "dout1")) || (!strcmp(attr->attr.name, "gpo2"))) {
- bit = BIT(1);
- } else if ((!strcmp(attr->attr.name, "dout2")) || (!strcmp(attr->attr.name, "gpo3"))) {
- bit = BIT(2);
- } else if ((!strcmp(attr->attr.name, "dout3")) || (!strcmp(attr->attr.name, "gpo4"))) {
- bit = BIT(3);
- } else if ((!strcmp(attr->attr.name, "dout4")) || (!strcmp(attr->attr.name, "led1"))) {
- bit = BIT(4);
- } else if ((!strcmp(attr->attr.name, "dout5")) || (!strcmp(attr->attr.name, "led4"))) {
- bit = BIT(5);
- } else if ((!strcmp(attr->attr.name, "dout6")) || (!strcmp(attr->attr.name, "led5"))) {
- bit = BIT(6);
- } else if ((!strcmp(attr->attr.name, "dout7")) || (!strcmp(attr->attr.name, "led6"))) {
- bit = BIT(7);
- } else {
- log_notice("dout attr does not exist");
- return -ENOENT;
- }
-
- if (sscanf(buf, "%i", &value) != 1) {
- log_notice("dout attr invalid argument");
- return -EINVAL;
- }
-
- mutex_lock(&spi_dout_mutex);
-
- if (value) {
- spi_dout_value &= ~bit;
- } else {
- spi_dout_value |= bit;
- }
-
- spi_writen(spi_dout_dev, &spi_dout_value, 1);
-
- mutex_unlock(&spi_dout_mutex);
-
- return count;
-}
-
-static ssize_t mts_attr_show_dout(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- int value;
- u8 bit;
-
- if (!spi_dout_dev) {
- log_error("dout device not present");
- return -ENODEV;
- }
-
- if ((!strcmp(attr->attr.name, "dout0")) || (!strcmp(attr->attr.name, "gpo1"))) {
- bit = BIT(0);
- } else if ((!strcmp(attr->attr.name, "dout1")) || (!strcmp(attr->attr.name, "gpo2"))) {
- bit = BIT(1);
- } else if ((!strcmp(attr->attr.name, "dout2")) || (!strcmp(attr->attr.name, "gpo3"))) {
- bit = BIT(2);
- } else if ((!strcmp(attr->attr.name, "dout3")) || (!strcmp(attr->attr.name, "gpo4"))) {
- bit = BIT(3);
- } else if ((!strcmp(attr->attr.name, "dout4")) || (!strcmp(attr->attr.name, "led1"))) {
- bit = BIT(4);
- } else if ((!strcmp(attr->attr.name, "dout5")) || (!strcmp(attr->attr.name, "led4"))) {
- bit = BIT(5);
- } else if ((!strcmp(attr->attr.name, "dout6")) || (!strcmp(attr->attr.name, "led5"))) {
- bit = BIT(6);
- } else if ((!strcmp(attr->attr.name, "dout7")) || (!strcmp(attr->attr.name, "led6"))) {
- bit = BIT(7);
- } else {
- log_notice("dout attr does not exist");
- return -ENOENT;
- }
-
- mutex_lock(&spi_dout_mutex);
-
- value = spi_dout_value & bit ? 0 : 1;
-
- mutex_unlock(&spi_dout_mutex);
-
- return sprintf(buf, "%d\n", value);
-}
-
-static ssize_t mts_attr_show_din(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- int tmp;
- u8 bit;
- u8 byte;
-
- if (!spi_din_dev) {
- log_error("din device not present");
- return -ENODEV;
- }
-
- if ((!strcmp(attr->attr.name, "din0")) || (!strcmp(attr->attr.name, "gpi5"))) {
- bit = BIT(0);
- } else if ((!strcmp(attr->attr.name, "din1")) || (!strcmp(attr->attr.name, "gpi6"))) {
- bit = BIT(1);
- } else if ((!strcmp(attr->attr.name, "din2")) || (!strcmp(attr->attr.name, "gpi7"))) {
- bit = BIT(2);
- } else if ((!strcmp(attr->attr.name, "din3")) || (!strcmp(attr->attr.name, "gpi8"))) {
- bit = BIT(3);
- } else if ((!strcmp(attr->attr.name, "din4")) || (!strcmp(attr->attr.name, "gpi9"))) {
- bit = BIT(4);
- } else if ((!strcmp(attr->attr.name, "din5")) || (!strcmp(attr->attr.name, "gpi10"))) {
- bit = BIT(5);
- } else if (!strcmp(attr->attr.name, "din6")) {
- bit = BIT(6);
- } else if (!strcmp(attr->attr.name, "din7")) {
- bit = BIT(7);
- } else {
- log_notice("din attr does not exist");
- return -ENOENT;
- }
-
- tmp = spi_readn(spi_din_dev, &byte, 1);
- if (tmp) {
- log_error("spi_read failed %d", tmp);
- return tmp;
- }
-
- tmp = byte & bit ? 1 : 0;
-
- return sprintf(buf, "%d\n", tmp);
-}
-
-static ssize_t mts_attr_show_board_temperature(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- int tmp;
- u16 temp_raw;
-
- if (!spi_board_temp_dev) {
- log_notice("spi_board_temp device not present");
- return -ENODEV;
- }
-
- tmp = spi_readn(spi_board_temp_dev, (u8 *) buf, 2);
- if (tmp) {
- log_error("spi_readn failed %d", tmp);
- return tmp;
- }
- temp_raw = ((u8 *) buf)[0] << 8 | ((u8 *) buf)[1];
-
- log_debug("temp: 0x%04X", temp_raw);
-
- return sprintf(buf, "%d\n", ADT7302_to_celsius(temp_raw));
-}
-
-/* ----------------------------------------------------------------------------
- *
- * SPI-based attributes
- *
- * ----------------------------------------------------------------------------
-*/
-
-static DEVICE_ATTR_RO_MTS(dev_attr_board_temperature, "board-temperature",
- mts_attr_show_board_temperature);
-
-static DEVICE_ATTR_MTS(dev_attr_extserial_dcd, "extserial-dcd",
- mts_attr_show_sout, mts_attr_store_sout);
-static DEVICE_ATTR_MTS(dev_attr_extserial_ri, "extserial-ri",
- mts_attr_show_sout, mts_attr_store_sout);
-static DEVICE_ATTR_MTS(dev_attr_extserial_dsr, "extserial-dsr",
- mts_attr_show_sout, mts_attr_store_sout);
-
-static DEVICE_ATTR_MTS(dev_attr_led_cd, "led-cd",
- mts_attr_show_sout, mts_attr_store_sout);
-static DEVICE_ATTR_MTS(dev_attr_led_sdk_b, "led-sdk-b",
- mts_attr_show_sout, mts_attr_store_sout);
-static DEVICE_ATTR_MTS(dev_attr_led_sig1, "led-sig1",
- mts_attr_show_sout, mts_attr_store_sout);
-static DEVICE_ATTR_MTS(dev_attr_led_sdk_c, "led-sdk-c",
- mts_attr_show_sout, mts_attr_store_sout);
-static DEVICE_ATTR_MTS(dev_attr_led_sig2, "led-sig2",
- mts_attr_show_sout, mts_attr_store_sout);
-static DEVICE_ATTR_MTS(dev_attr_led_sdk_d, "led-sdk-d",
- mts_attr_show_sout, mts_attr_store_sout);
-static DEVICE_ATTR_MTS(dev_attr_led_sig3, "led-sig3",
- mts_attr_show_sout, mts_attr_store_sout);
-static DEVICE_ATTR_MTS(dev_attr_led_sdk_e, "led-sdk-e",
- mts_attr_show_sout, mts_attr_store_sout);
-static DEVICE_ATTR_MTS(dev_attr_led_dtr, "led-dtr",
- mts_attr_show_sout, mts_attr_store_sout);
-static DEVICE_ATTR_MTS(dev_attr_led_sdk_f, "led-sdk-f",
- mts_attr_show_sout, mts_attr_store_sout);
-
-static DEVICE_ATTR_MTS(dev_attr_dout0, "dout0",
- mts_attr_show_dout, mts_attr_store_dout);
-static DEVICE_ATTR_MTS(dev_attr_dout1, "dout1",
- mts_attr_show_dout, mts_attr_store_dout);
-static DEVICE_ATTR_MTS(dev_attr_dout2, "dout2",
- mts_attr_show_dout, mts_attr_store_dout);
-static DEVICE_ATTR_MTS(dev_attr_dout3, "dout3",
- mts_attr_show_dout, mts_attr_store_dout);
-static DEVICE_ATTR_MTS(dev_attr_dout4, "dout4",
- mts_attr_show_dout, mts_attr_store_dout);
-static DEVICE_ATTR_MTS(dev_attr_dout5, "dout5",
- mts_attr_show_dout, mts_attr_store_dout);
-static DEVICE_ATTR_MTS(dev_attr_dout6, "dout6",
- mts_attr_show_dout, mts_attr_store_dout);
-static DEVICE_ATTR_MTS(dev_attr_dout7, "dout7",
- mts_attr_show_dout, mts_attr_store_dout);
-
-static DEVICE_ATTR_RO_MTS(dev_attr_din0, "din0", mts_attr_show_din);
-static DEVICE_ATTR_RO_MTS(dev_attr_din1, "din1", mts_attr_show_din);
-static DEVICE_ATTR_RO_MTS(dev_attr_din2, "din2", mts_attr_show_din);
-static DEVICE_ATTR_RO_MTS(dev_attr_din3, "din3", mts_attr_show_din);
-static DEVICE_ATTR_RO_MTS(dev_attr_din4, "din4", mts_attr_show_din);
-static DEVICE_ATTR_RO_MTS(dev_attr_din5, "din5", mts_attr_show_din);
-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_gpi5, "gpi5", mts_attr_show_din);
-static DEVICE_ATTR_RO_MTS(dev_attr_gpi6, "gpi6", mts_attr_show_din);
-static DEVICE_ATTR_RO_MTS(dev_attr_gpi7, "gpi7", mts_attr_show_din);
-static DEVICE_ATTR_RO_MTS(dev_attr_gpi8, "gpi8", mts_attr_show_din);
-static DEVICE_ATTR_RO_MTS(dev_attr_gpi9, "gpi9", mts_attr_show_din);
-static DEVICE_ATTR_RO_MTS(dev_attr_gpi10, "gpi10", mts_attr_show_din);
-
-/* SPI driver setup */
-static int mts_spi_sout_probe(struct spi_device *spi)
-{
- int tmp;
-
- spi->max_speed_hz = sout_max_speed_hz;
- spi->mode = 0;
-
- log_debug("sout_max_speed_hz: %d", sout_max_speed_hz);
-
- tmp = spi_setup(spi);
- if (tmp < 0) {
- log_error("spi_setup sout failed");
- return tmp;
- }
-
- spi_sout_value = 0xFF;
- spi_writen(spi, &spi_sout_value, 1);
-
- spi_sout_dev = spi;
-
- return 0;
-}
-
-static int mts_spi_sout_remove(struct spi_device *spi)
-{
- spi_sout_dev = NULL;
-
- return 0;
-}
-
-static struct spi_driver mts_spi_sout_driver = {
- .driver = {
- .name = "mts-io-sout",
- .bus = &spi_bus_type,
- .owner = THIS_MODULE,
- },
-
- .probe = mts_spi_sout_probe,
- .remove = mts_spi_sout_remove,
-};
-
-static int mts_spi_dout_probe(struct spi_device *spi)
-{
- int tmp;
-
- if (!DEVICE_CAPA(id_eeprom.capa, CAPA_DOUT)) {
- log_debug("digital outputs not available");
- return -ENODEV;
- }
-
- spi->max_speed_hz = dout_max_speed_hz;
- spi->mode = 0;
-
- log_debug("dout_max_speed_hz: %d", dout_max_speed_hz);
-
- tmp = spi_setup(spi);
- if (tmp < 0) {
- log_error("spi_setup dout failed");
- return tmp;
- }
-
- spi_dout_value = 0x00;
- spi_writen(spi, &spi_dout_value, 1);
-
- spi_dout_dev = spi;
-
- return 0;
-}
-
-static int mts_spi_dout_remove(struct spi_device *spi)
-{
- spi_dout_dev = NULL;
-
- return 0;
-}
-
-static struct spi_driver mts_spi_dout_driver = {
- .driver = {
- .name = "mts-io-dout",
- .bus = &spi_bus_type,
- .owner = THIS_MODULE,
- },
-
- .probe = mts_spi_dout_probe,
- .remove = mts_spi_dout_remove,
-};
-
-static int mts_spi_din_probe(struct spi_device *spi)
-{
- int tmp;
-
- if (!DEVICE_CAPA(id_eeprom.capa, CAPA_DIN)) {
- log_debug("digital inputs not available");
- return -ENODEV;
- }
-
- spi->max_speed_hz = din_max_speed_hz;
- spi->mode = SPI_CPOL;
-
- log_debug("din_max_speed_hz: %d", din_max_speed_hz);
-
- tmp = spi_setup(spi);
- if (tmp < 0) {
- log_error("spi_setup din failed");
- return tmp;
- }
-
- spi_din_dev = spi;
-
- return 0;
-}
-
-static int mts_spi_din_remove(struct spi_device *spi)
-{
- spi_din_dev = NULL;
-
- return 0;
-}
-
-static struct spi_driver mts_spi_din_driver = {
- .driver = {
- .name = "mts-io-din",
- .bus = &spi_bus_type,
- .owner = THIS_MODULE,
- },
-
- .probe = mts_spi_din_probe,
- .remove = mts_spi_din_remove,
-};
-
-static int mts_spi_board_temp_probe(struct spi_device *spi)
-{
- int tmp;
-
- spi->max_speed_hz = board_temp_max_speed_hz;
- spi->mode = SPI_CPOL | SPI_CPHA;
-
- log_debug("board_temp_max_speed_hz: %d", board_temp_max_speed_hz);
-
- tmp = spi_setup(spi);
- if (tmp < 0) {
- log_error("spi_setup board-temp failed");
- return tmp;
- }
-
- spi_board_temp_dev = spi;
-
- return 0;
-}
-
-static int mts_spi_board_temp_remove(struct spi_device *spi)
-{
- spi_board_temp_dev = NULL;
-
- return 0;
-}
-
-static struct spi_driver mts_spi_board_temp_driver = {
- .driver = {
- .name = "mts-io-board-temp",
- .bus = &spi_bus_type,
- .owner = THIS_MODULE,
- },
-
- .probe = mts_spi_board_temp_probe,
- .remove = mts_spi_board_temp_remove,
-};