diff options
author | James Maki <jmaki@multitech.com> | 2010-05-03 17:57:14 -0500 |
---|---|---|
committer | James Maki <jmaki@multitech.com> | 2010-05-03 17:57:14 -0500 |
commit | 1e10e510b23bc04d949b7180db0d513317d0a520 (patch) | |
tree | b8a8456dde64bd5ad5a012d8600ba2d4a16f46b2 | |
parent | 29fb8a9b088bf7d4dfc33bfd6c295c7f4d1897c9 (diff) | |
download | cdp-io-controller-1e10e510b23bc04d949b7180db0d513317d0a520.tar.gz cdp-io-controller-1e10e510b23bc04d949b7180db0d513317d0a520.tar.bz2 cdp-io-controller-1e10e510b23bc04d949b7180db0d513317d0a520.zip |
register devices with spi controller
-rw-r--r-- | io-module/mts_io.c | 558 | ||||
-rw-r--r-- | io-tool/mts-io-sysfs-inc.sh | 2 | ||||
-rwxr-xr-x | io-tool/sysfs-tests | 16 |
3 files changed, 304 insertions, 272 deletions
diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 6f7f559..e93020f 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -39,6 +39,7 @@ #include <linux/platform_device.h> #include <linux/device.h> #include <linux/bitops.h> +#include <linux/spi/spi.h> #include "mts_io.h" @@ -49,18 +50,27 @@ #define PLATFORM_NAME "mtcdp" +#define DEBUG 1 #if DEBUG -# define dbg(fmt, args...) printk(KERN_DEBUG __FILE__ ": " fmt "\n" , ##args) +# define dbg(fmt, args...) printk(KERN_DEBUG DRIVER_NAME ": " fmt "\n" , ##args) #else # define dbg(fmt, args...) do {} while (0) #endif -#define error(fmt, args...) printk(KERN_ERR __FILE__ ": " fmt "\n" , ##args) -#define info(fmt, args...) printk(KERN_INFO fmt "\n" , ##args) +#define error(fmt, args...) printk(KERN_ERR DRIVER_NAME ": " fmt "\n" , ##args) +#define info(fmt, args...) printk(KERN_INFO DRIVER_NAME ": " fmt "\n" , ##args) + +enum { + LED_OFF, + LED_ON, + LED_FLASHING, +}; #define BOARD_REVA 0 #define BOARD_REVB 1 #define BOARD_REVC 2 +static u8 board_rev = BOARD_REVA; + #define LED_CD_BIT BIT(0) #define EXTSERIAL_RI_BIT BIT(1) #define EXTSERIAL_DSR_BIT BIT(2) @@ -70,20 +80,14 @@ #define LED_SIG3_BIT BIT(6) #define EXTSERIAL_DCD_BIT BIT(7) -#define GPIO_CS0 AT91_PIN_PB3 -#define GPIO_CS1 AT91_PIN_PC5 -#define GPIO_CS2 AT91_PIN_PC4 -#define GPIO_CS3 AT91_PIN_PC3 +#define GPIO_VER0 AT91_PIN_PA23 +#define GPIO_VER1 AT91_PIN_PA24 +#define GPIO_STATUS_LED AT91_PIN_PA30 +#define GPIO_LS_LED AT91_PIN_PC9 #define GPIO_ENIO AT91_PIN_PC15 #define GPIO_ETH0_ENABLED AT91_PIN_PB31 #define GPIO_RADIO_RESET AT91_PIN_PB30 #define GPIO_OPTRST AT91_PIN_PA22 -#define GPIO_LS_LED AT91_PIN_PC9 -#define GPIO_SERCLK AT91_PIN_PB2 -#define GPIO_SERDOUT AT91_PIN_PB1 -#define GPIO_SERDIN AT91_PIN_PB0 -#define GPIO_VER0 AT91_PIN_PA23 -#define GPIO_VER1 AT91_PIN_PA24 #define GPIO_RSERSRC AT91_PIN_PC7 #define GPIO_DBSERON AT91_PIN_PC6 #define GPIO_DTR1 AT91_PIN_PC10 @@ -95,34 +99,46 @@ #define GPIO_EXTIN4 AT91_PIN_PB9 #define GPIO_EXTIN5 AT91_PIN_PB8 #define GPIO_GPS_NINT2 AT91_PIN_PC2 -#define GPIO_STATUS_LED AT91_PIN_PA30 -#define LED_STATUS_CONTROLLABLE 1 +#define LED_STATUS_CONTROLLABLE 0 #define LED_LS_CONTROLLABLE 0 -enum { - LED_OFF, - LED_ON, - LED_FLASHING, -}; - -static u8 board_rev = BOARD_REVA; -static u8 cs0_bits = 0xFF; -static DEFINE_MUTEX(mts_io_mutex); #if LED_STATUS_CONTROLLABLE static int led_mode_status = LED_OFF; #endif -static pid_t reset_pid = -1; -static pid_t reset_count = 0; -static int reset_short_signal = SIGUSR1; -static int reset_long_signal = SIGUSR2; +static struct spi_device *spi_sregout; +static u8 spi_sregout_byte; +static DEFINE_MUTEX(spi_sregout_mutex); +static struct spi_device *spi_temp; + +static int spi_sregout_write(struct spi_device *spi, const u8 value) +{ + return spi_write(spi, &value, 1); +} + +static int spi_temp_read(struct spi_device *spi, u16 *value) +{ + int tmp; + u8 buf[2] = {0, 0}; + + tmp = spi_read(spi, buf, 2); + *value = buf[0] << 8 | buf[1]; + + return tmp; +} #define BLINK_PER_SEC 8 #define BLINK_INTERVAL (HZ / BLINK_PER_SEC) #define RESET_HOLD_COUNT (BLINK_PER_SEC * 3) +static pid_t reset_pid = -1; +static pid_t reset_count = 0; +static int reset_short_signal = SIGUSR1; +static int reset_long_signal = SIGUSR2; +static DEFINE_MUTEX(mts_io_mutex); + static void blink_callback(struct work_struct *ignored); static DECLARE_DELAYED_WORK(blink_work, blink_callback); @@ -165,93 +181,6 @@ static void blink_callback(struct work_struct *ignored) schedule_delayed_work(&blink_work, BLINK_INTERVAL); } -static void serial_writeb(u8 data, int cs) -{ - int i; - - if (board_rev == BOARD_REVA) { - if (cs == GPIO_CS0) { - cs = 2; - } else if (cs == GPIO_CS1) { - cs = 3; - } else if (cs == GPIO_CS2) { - cs = 4; - } else if (cs == GPIO_CS3) { - cs = 5; - } else { - return; - } - at91_set_gpio_value(GPIO_CS0, cs & 1); - at91_set_gpio_value(GPIO_CS1, cs & 2); - at91_set_gpio_value(GPIO_CS2, cs & 4); - } else { - at91_set_gpio_value(cs, 0); - } - - for (i = 7; i >= 0; i--) { - at91_set_gpio_value(GPIO_SERDOUT, data & (1 << i)); - at91_set_gpio_value(GPIO_SERCLK, 1); - at91_set_gpio_value(GPIO_SERCLK, 0); - } - - if (board_rev == BOARD_REVA) { - at91_set_gpio_value(GPIO_CS0, 1); - at91_set_gpio_value(GPIO_CS1, 1); - at91_set_gpio_value(GPIO_CS2, 1); - } else { - at91_set_gpio_value(cs, 1); - } -} - -static u16 serial_readw(int cs) -{ - int i; - u16 data; - - at91_set_gpio_value(GPIO_SERCLK, 1); - - /* set low so we don't power down temp sensor */ - at91_set_gpio_value(GPIO_SERDOUT, 0); - - if (board_rev == BOARD_REVA) { - if (cs == GPIO_CS0) { - cs = 2; - } else if (cs == GPIO_CS1) { - cs = 3; - } else if (cs == GPIO_CS2) { - cs = 4; - } else if (cs == GPIO_CS3) { - cs = 5; - } else { - cs = 2; - } - at91_set_gpio_value(GPIO_CS0, cs & 1); - at91_set_gpio_value(GPIO_CS1, cs & 2); - at91_set_gpio_value(GPIO_CS2, cs & 4); - } else { - at91_set_gpio_value(cs, 0); - } - - data = 0; - for (i = 15; i >= 0; i--) { - at91_set_gpio_value(GPIO_SERCLK, 0); - at91_set_gpio_value(GPIO_SERCLK, 1); - data |= (((u16) at91_get_gpio_value(GPIO_SERDIN)) << i); - } - - if (board_rev == BOARD_REVA) { - at91_set_gpio_value(GPIO_CS0, 1); - at91_set_gpio_value(GPIO_CS1, 1); - at91_set_gpio_value(GPIO_CS2, 1); - } else { - at91_set_gpio_value(cs, 1); - } - - at91_set_gpio_value(GPIO_SERCLK, 0); - - return data; -} - static int radio_reset(void) { int ret; @@ -268,23 +197,15 @@ static int radio_reset(void) return ret; } -static int board_temperature(void) +static int ADT7302_to_celsius(int value) { - int temp; - - temp = serial_readw(GPIO_CS2); - - /* - * If sign bit set, convert raw value to negative integer. - * @see: ADT7302 datasheet - */ - if (temp & 0x2000) { - temp = temp - 16384; + if (value & 0x2000) { + value = value - 16384; } - temp = temp / 32 + 1 * ((temp % 32) >= 16); + value = value / 32 + 1 * ((value % 32) >= 16); - return temp; + return value; } static ssize_t show_radio_reset(struct device *dev, @@ -398,11 +319,16 @@ static ssize_t show_extserial_dcd(struct device *dev, { int value; - mutex_lock(&mts_io_mutex); + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } - value = !(cs0_bits & EXTSERIAL_DCD_BIT); + mutex_lock(&spi_sregout_mutex); - mutex_unlock(&mts_io_mutex); + value = spi_sregout_byte & EXTSERIAL_DCD_BIT ? 0 : 1; + + mutex_unlock(&spi_sregout_mutex); return sprintf(buf, "%d\n", value); } @@ -412,20 +338,25 @@ static ssize_t store_extserial_dcd(struct device *dev, struct device_attribute * { int value; + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } + if (sscanf(buf, "%i", &value) != 1) { return -EINVAL; } - mutex_lock(&mts_io_mutex); + mutex_lock(&spi_sregout_mutex); if (value) { - cs0_bits &= ~EXTSERIAL_DCD_BIT; + spi_sregout_byte &= ~EXTSERIAL_DCD_BIT; } else { - cs0_bits |= EXTSERIAL_DCD_BIT; + spi_sregout_byte |= EXTSERIAL_DCD_BIT; } - serial_writeb(cs0_bits, GPIO_CS0); + spi_sregout_write(spi_sregout, spi_sregout_byte); - mutex_unlock(&mts_io_mutex); + mutex_unlock(&spi_sregout_mutex); return count; } @@ -445,11 +376,16 @@ static ssize_t show_extserial_ri(struct device *dev, { int value; - mutex_lock(&mts_io_mutex); + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } - value = !(cs0_bits & EXTSERIAL_RI_BIT); + mutex_lock(&spi_sregout_mutex); - mutex_unlock(&mts_io_mutex); + value = spi_sregout_byte & EXTSERIAL_RI_BIT ? 0 : 1; + + mutex_unlock(&spi_sregout_mutex); return sprintf(buf, "%d\n", value); } @@ -459,20 +395,25 @@ static ssize_t store_extserial_ri(struct device *dev, struct device_attribute *a { int value; + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } + if (sscanf(buf, "%i", &value) != 1) { return -EINVAL; } - mutex_lock(&mts_io_mutex); + mutex_lock(&spi_sregout_mutex); if (value) { - cs0_bits &= ~EXTSERIAL_RI_BIT; + spi_sregout_byte &= ~EXTSERIAL_RI_BIT; } else { - cs0_bits |= EXTSERIAL_RI_BIT; + spi_sregout_byte |= EXTSERIAL_RI_BIT; } - serial_writeb(cs0_bits, GPIO_CS0); + spi_sregout_write(spi_sregout, spi_sregout_byte); - mutex_unlock(&mts_io_mutex); + mutex_unlock(&spi_sregout_mutex); return count; } @@ -492,11 +433,16 @@ static ssize_t show_extserial_dsr(struct device *dev, { int value; - mutex_lock(&mts_io_mutex); + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } - value = !(cs0_bits & EXTSERIAL_DSR_BIT); + mutex_lock(&spi_sregout_mutex); - mutex_unlock(&mts_io_mutex); + value = spi_sregout_byte & EXTSERIAL_DSR_BIT ? 0 : 1; + + mutex_unlock(&spi_sregout_mutex); return sprintf(buf, "%d\n", value); } @@ -506,20 +452,25 @@ static ssize_t store_extserial_dsr(struct device *dev, struct device_attribute * { int value; + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } + if (sscanf(buf, "%i", &value) != 1) { return -EINVAL; } - mutex_lock(&mts_io_mutex); + mutex_lock(&spi_sregout_mutex); if (value) { - cs0_bits &= ~EXTSERIAL_DSR_BIT; + spi_sregout_byte &= ~EXTSERIAL_DSR_BIT; } else { - cs0_bits |= EXTSERIAL_DSR_BIT; + spi_sregout_byte |= EXTSERIAL_DSR_BIT; } - serial_writeb(cs0_bits, GPIO_CS0); + spi_sregout_write(spi_sregout, spi_sregout_byte); - mutex_unlock(&mts_io_mutex); + mutex_unlock(&spi_sregout_mutex); return count; } @@ -539,11 +490,16 @@ static ssize_t show_led_sig1(struct device *dev, { int value; - mutex_lock(&mts_io_mutex); + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } - value = !(cs0_bits & LED_SIG1_BIT); + mutex_lock(&spi_sregout_mutex); - mutex_unlock(&mts_io_mutex); + value = spi_sregout_byte & LED_SIG1_BIT ? 0 : 1; + + mutex_unlock(&spi_sregout_mutex); return sprintf(buf, "%d\n", value); } @@ -553,20 +509,25 @@ static ssize_t store_led_sig1(struct device *dev, struct device_attribute *attr, { int value; + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } + if (sscanf(buf, "%i", &value) != 1) { return -EINVAL; } - mutex_lock(&mts_io_mutex); + mutex_lock(&spi_sregout_mutex); if (value) { - cs0_bits &= ~LED_SIG1_BIT; + spi_sregout_byte &= ~LED_SIG1_BIT; } else { - cs0_bits |= LED_SIG1_BIT; + spi_sregout_byte |= LED_SIG1_BIT; } - serial_writeb(cs0_bits, GPIO_CS0); + spi_sregout_write(spi_sregout, spi_sregout_byte); - mutex_unlock(&mts_io_mutex); + mutex_unlock(&spi_sregout_mutex); return count; } @@ -595,11 +556,16 @@ static ssize_t show_led_sig2(struct device *dev, { int value; - mutex_lock(&mts_io_mutex); + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } - value = !(cs0_bits & LED_SIG2_BIT); + mutex_lock(&spi_sregout_mutex); - mutex_unlock(&mts_io_mutex); + value = spi_sregout_byte & LED_SIG2_BIT ? 0 : 1; + + mutex_unlock(&spi_sregout_mutex); return sprintf(buf, "%d\n", value); } @@ -609,20 +575,25 @@ static ssize_t store_led_sig2(struct device *dev, struct device_attribute *attr, { int value; + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } + if (sscanf(buf, "%i", &value) != 1) { return -EINVAL; } - mutex_lock(&mts_io_mutex); + mutex_lock(&spi_sregout_mutex); if (value) { - cs0_bits &= ~LED_SIG2_BIT; + spi_sregout_byte &= ~LED_SIG2_BIT; } else { - cs0_bits |= LED_SIG2_BIT; + spi_sregout_byte |= LED_SIG2_BIT; } - serial_writeb(cs0_bits, GPIO_CS0); + spi_sregout_write(spi_sregout, spi_sregout_byte); - mutex_unlock(&mts_io_mutex); + mutex_unlock(&spi_sregout_mutex); return count; } @@ -651,11 +622,16 @@ static ssize_t show_led_sig3(struct device *dev, { int value; - mutex_lock(&mts_io_mutex); + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } - value = !(cs0_bits & LED_SIG3_BIT); + mutex_lock(&spi_sregout_mutex); - mutex_unlock(&mts_io_mutex); + value = spi_sregout_byte & LED_SIG3_BIT ? 0 : 1; + + mutex_unlock(&spi_sregout_mutex); return sprintf(buf, "%d\n", value); } @@ -665,20 +641,25 @@ static ssize_t store_led_sig3(struct device *dev, struct device_attribute *attr, { int value; + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } + if (sscanf(buf, "%i", &value) != 1) { return -EINVAL; } - mutex_lock(&mts_io_mutex); + mutex_lock(&spi_sregout_mutex); if (value) { - cs0_bits &= ~LED_SIG3_BIT; + spi_sregout_byte &= ~LED_SIG3_BIT; } else { - cs0_bits |= LED_SIG3_BIT; + spi_sregout_byte |= LED_SIG3_BIT; } - serial_writeb(cs0_bits, GPIO_CS0); + spi_sregout_write(spi_sregout, spi_sregout_byte); - mutex_unlock(&mts_io_mutex); + mutex_unlock(&spi_sregout_mutex); return count; } @@ -707,11 +688,16 @@ static ssize_t show_led_cd(struct device *dev, { int value; - mutex_lock(&mts_io_mutex); + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } - value = !(cs0_bits & LED_CD_BIT); + mutex_lock(&spi_sregout_mutex); - mutex_unlock(&mts_io_mutex); + value = spi_sregout_byte & LED_CD_BIT ? 0 : 1; + + mutex_unlock(&spi_sregout_mutex); return sprintf(buf, "%d\n", value); } @@ -721,20 +707,25 @@ static ssize_t store_led_cd(struct device *dev, struct device_attribute *attr, { int value; + if (!spi_sregout) { + error("device not present"); + return -ENODEV; + } + if (sscanf(buf, "%i", &value) != 1) { return -EINVAL; } - mutex_lock(&mts_io_mutex); + mutex_lock(&spi_sregout_mutex); if (value) { - cs0_bits &= ~LED_CD_BIT; + spi_sregout_byte &= ~LED_CD_BIT; } else { - cs0_bits |= LED_CD_BIT; + spi_sregout_byte |= LED_CD_BIT; } - serial_writeb(cs0_bits, GPIO_CS0); + spi_sregout_write(spi_sregout, spi_sregout_byte); - mutex_unlock(&mts_io_mutex); + mutex_unlock(&spi_sregout_mutex); return count; } @@ -954,15 +945,18 @@ static ssize_t show_board_temperature(struct device *dev, struct device_attribute *attr, char *buf) { - int ret; - - mutex_lock(&mts_io_mutex); + int tmp; + u16 temp_raw; - ret = sprintf(buf, "%d\n", board_temperature()); + tmp = spi_temp_read(spi_temp, &temp_raw); + if (tmp) { + error("spi_read temp failed %d", tmp); + return tmp; + } - mutex_unlock(&mts_io_mutex); + dbg("temp: 0x%04X", temp_raw); - return ret; + return sprintf(buf, "%d\n", ADT7302_to_celsius(temp_raw)); } static struct device_attribute dev_attr_board_temperature = { @@ -1040,38 +1034,6 @@ static struct gpio_pin_init init_pins[] = { .board_rev_added = BOARD_REVA, }, { - .name = "GPIO_CS0", - .pin = GPIO_CS0, - .direction = DIR_OUTPUT, - .output_value = 1, - .use_pullup = 1, - .board_rev_added = BOARD_REVA, - }, - { - .name = "GPIO_CS1", - .pin = GPIO_CS1, - .direction = DIR_OUTPUT, - .output_value = 1, - .use_pullup = 1, - .board_rev_added = BOARD_REVA, - }, - { - .name = "GPIO_CS2", - .pin = GPIO_CS2, - .direction = DIR_OUTPUT, - .output_value = 1, - .use_pullup = 1, - .board_rev_added = BOARD_REVA, - }, - { - .name = "GPIO_CS3", - .pin = GPIO_CS3, - .direction = DIR_OUTPUT, - .output_value = 1, - .use_pullup = 1, - .board_rev_added = BOARD_REVC, - }, - { .name = "GPIO_ENIO", .pin = GPIO_ENIO, .direction = DIR_OUTPUT, @@ -1113,30 +1075,6 @@ static struct gpio_pin_init init_pins[] = { .board_rev_added = BOARD_REVA, }, #endif - { - .name = "GPIO_SERCLK", - .pin = GPIO_SERCLK, - .direction = DIR_OUTPUT, - .output_value = 0, - .use_pullup = 0, - .board_rev_added = BOARD_REVA, - }, - { - .name = "GPIO_SERDOUT", - .pin = GPIO_SERDOUT, - .direction = DIR_OUTPUT, - .output_value = 0, - .use_pullup = 1, - .board_rev_added = BOARD_REVA, - }, - { - .name = "GPIO_SERDIN", - .pin = GPIO_SERDIN, - .direction = DIR_INPUT, - .output_value = 0, - .use_pullup = 1, - .board_rev_added = BOARD_REVA, - }, #if LED_STATUS_CONTROLLABLE { .name = "GPIO_STATUS_LED", @@ -1239,28 +1177,98 @@ static struct gpio_pin_init init_pins[] = { #endif }; +static int __devinit mts_spi_sregout_probe(struct spi_device *spi) +{ + int tmp; + + spi->max_speed_hz = 1 * 1000 * 1000; + spi->mode = 0; + + tmp = spi_setup(spi); + if (tmp < 0) { + return tmp; + } + + spi_sregout_byte = 0xFF; + spi_sregout_write(spi, spi_sregout_byte); + + spi_sregout = spi; + + return 0; +} + +static int mts_spi_sregout_remove(struct spi_device *spi) +{ + return 0; +} + +static struct spi_driver mts_spi_sregout_driver = { + .driver = { + .name = "mts-io-sregout", + .bus = &spi_bus_type, + .owner = THIS_MODULE, + }, + + .probe = mts_spi_sregout_probe, + .remove = __devexit_p(mts_spi_sregout_remove), +}; + +static int __devinit mts_spi_board_temp_probe(struct spi_device *spi) +{ + int tmp; + + spi->max_speed_hz = 1 * 1000 * 1000; + spi->mode = SPI_CPOL | SPI_CPHA; + + tmp = spi_setup(spi); + if (tmp < 0) { + error("spi_setup board-tmp"); + return tmp; + } + + spi_temp = spi; + + return 0; +} + +static int mts_spi_board_temp_remove(struct spi_device *spi) +{ + 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 = __devexit_p(mts_spi_board_temp_remove), +}; + static int __init mts_io_init(void) { int i; int ret; - info(DRIVER_NAME ": init"); + info("init"); mts_io_platform_device = platform_device_alloc(PLATFORM_NAME, -1); if (!mts_io_platform_device) { ret = -ENOMEM; - goto error_platform_device_alloc; + goto error1; } ret = platform_device_add(mts_io_platform_device); if (ret) { - goto error_platform_device_add; + goto error2; } ret = sysfs_create_group(&mts_io_platform_device->dev.kobj, &platform_attribute_group); if (ret) { - goto error_sysfs_create_group; + goto error3; } for (i = 0; i < ARRAY_SIZE(init_pins); i++) { @@ -1268,37 +1276,52 @@ static int __init mts_io_init(void) if (board_rev >= init_pins[i].board_rev_added) { if (init_pins[i].direction == DIR_OUTPUT) { - at91_set_gpio_output(init_pins[i].pin, init_pins[i].output_value); + at91_set_gpio_output(init_pins[i].pin, + init_pins[i].output_value); } else { - at91_set_gpio_input(init_pins[i].pin, init_pins[i].use_pullup); + at91_set_gpio_input(init_pins[i].pin, + init_pins[i].use_pullup); } } if (i == 1) { - board_rev = (at91_get_gpio_value(GPIO_VER1) << 1) | at91_get_gpio_value(GPIO_VER0); + board_rev = (at91_get_gpio_value(GPIO_VER1) << 1) | + at91_get_gpio_value(GPIO_VER0); board_rev ^= 0x03; - info(DRIVER_NAME ": board rev: %d", board_rev); - } - } + info("board rev: %d", board_rev); - serial_writeb(cs0_bits, GPIO_CS0); - serial_writeb(0xFF, GPIO_CS1); + if (board_rev == BOARD_REVA) { + error("rev A boards are not supported"); + ret = -EIO; + goto error3; + } + } + } - /* - * enable serial device data output bus - */ at91_set_gpio_value(GPIO_ENIO, 0); + ret = spi_register_driver(&mts_spi_sregout_driver); + if (ret) { + goto error3; + } + + ret = spi_register_driver(&mts_spi_board_temp_driver); + if (ret) { + goto error4; + } + blink_callback(NULL); return 0; -error_sysfs_create_group: +error4: + spi_unregister_driver(&mts_spi_sregout_driver); +error3: platform_device_del(mts_io_platform_device); -error_platform_device_add: +error2: platform_device_put(mts_io_platform_device); -error_platform_device_alloc: - error(DRIVER_NAME " init failed: %d", ret); +error1: + error("init failed: %d", ret); return ret; } @@ -1309,6 +1332,9 @@ static void __exit mts_io_exit(void) cancel_delayed_work_sync(&blink_work); + spi_unregister_driver(&mts_spi_board_temp_driver); + spi_unregister_driver(&mts_spi_sregout_driver); + if (board_rev >= init_pins[i].board_rev_added) { for (i = 0; i < ARRAY_SIZE(init_pins); i++) { at91_set_gpio_input(init_pins[i].pin, init_pins[i].use_pullup); @@ -1319,7 +1345,7 @@ static void __exit mts_io_exit(void) &platform_attribute_group); platform_device_unregister(mts_io_platform_device); - info(DRIVER_NAME ": exiting"); + info("exiting"); } module_init(mts_io_init); diff --git a/io-tool/mts-io-sysfs-inc.sh b/io-tool/mts-io-sysfs-inc.sh index 7c24353..c4a48db 100644 --- a/io-tool/mts-io-sysfs-inc.sh +++ b/io-tool/mts-io-sysfs-inc.sh @@ -26,7 +26,7 @@ VERBOSE=false PLATFORM_NAME=mtcdp SYSFS_PLATFORM_DIR=/sys/devices/platform/${PLATFORM_NAME} -MTS_IO_CONTROLS_STATUS_LED=true +MTS_IO_CONTROLS_STATUS_LED=false MTS_IO_CONTROLS_LS_LED=false LEDS_GPIO_DIR=/sys/devices/platform/leds-gpio/leds diff --git a/io-tool/sysfs-tests b/io-tool/sysfs-tests index cb65c57..7b07955 100755 --- a/io-tool/sysfs-tests +++ b/io-tool/sysfs-tests @@ -83,11 +83,13 @@ show_assert_in_set() { for value in "$@"; do if [ "${value}" = "${actual_value}" ]; then - log_info "${name} is '${value}'" + log_info "${name} is '${actual_value}'" return fi done + log_info "${name} is '${actual_value}'" + exit 1 } @@ -100,6 +102,14 @@ modprobe mts-io sleep 2 +show_assert_in_set board-temperature {30..40} +store board-temperature 1000 +show_assert_in_set board-temperature {30..40} + +#for ((i = 0; i < 1000; i++)); do +# show_assert_in_set board-temperature {30..40} +#done + show_assert radio-reset 1 log_info "resetting radio..." store radio-reset 0 @@ -171,10 +181,6 @@ show_assert reset 0 store reset 1 show_assert reset 0 -show_assert_in_set board-temperature {30..40} -store board-temperature 1000 -show_assert_in_set board-temperature {30..40} - show_assert reset-monitor "-1 10 12" exit 0 |