From: lw Date: Wed, 20 Jun 2012 07:20:39 +0000 (+0800) Subject: add spi bus test code X-Git-Tag: firefly_0821_release~9079 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=38415d21fa7f06e1ee6223fb8278fbf68d42674f;p=firefly-linux-kernel-4.4.55.git add spi bus test code --- diff --git a/arch/arm/mach-rk30/board-rk30-sdk.c b/arch/arm/mach-rk30/board-rk30-sdk.c index fd47452bc232..1a486057d2c6 100755 --- a/arch/arm/mach-rk30/board-rk30-sdk.c +++ b/arch/arm/mach-rk30/board-rk30-sdk.c @@ -715,7 +715,7 @@ static struct sensor_platform_data lis3dh_info = { .irq_enable = 1, .poll_delay_ms = 30, .init_platform_hw = lis3dh_init_platform_hw, - .orientation = {0, 1, 0, 0, 0, 1, -1, 0, 0}, + .orientation = {-1, 0, 0, 0, 0, 1, 0, -1, 0}, }; #endif #if defined (CONFIG_COMPASS_AK8975) diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index db08a9b79c29..51fc9c9f56ab 100755 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -440,7 +440,11 @@ config SPIM1_RK29 bool "RK SPI1 master controller" depends on SPIM_RK29 help - enable SPI1 master controller for RK29 + enable SPI1 master controller for RK29 + +config RK_SPIM_TEST + bool "RK SPIM test" + depends on (SPIM0_RK29 && SPIM1_RK29) config LCD_USE_SPIM_CONTROL bool "Switch gpio to spim with spin lock" diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index 58a98b01e0c8..7f1a2aee8620 100755 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -13,14 +13,15 @@ obj-$(CONFIG_SPI_ALTERA) += spi_altera.o obj-$(CONFIG_SPI_ATMEL) += atmel_spi.o obj-$(CONFIG_SPI_ATH79) += ath79_spi.o obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx.o -obj-$(CONFIG_SPI_BFIN_SPORT) += spi_bfin_sport.o +obj-$(CONFIG_SPI_BFIN_SPORT) += spi_bfin_sport.o obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o obj-$(CONFIG_SPI_AU1550) += au1550_spi.o obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o -obj-$(CONFIG_SPIM_RK29) += rk29_spim.o -obj-$(CONFIG_SPI_COLDFIRE_QSPI) += coldfire_qspi.o +obj-$(CONFIG_SPIM_RK29) += rk29_spim.o +obj-$(CONFIG_RK_SPIM_TEST) += spi_test.o +obj-$(CONFIG_SPI_COLDFIRE_QSPI) += coldfire_qspi.o obj-$(CONFIG_SPI_DAVINCI) += davinci_spi.o -obj-$(CONFIG_SPI_DESIGNWARE) += dw_spi.o +obj-$(CONFIG_SPI_DESIGNWARE) += dw_spi.o obj-$(CONFIG_SPI_DW_PCI) += dw_spi_midpci.o dw_spi_midpci-objs := dw_spi_pci.o dw_spi_mid.o obj-$(CONFIG_SPI_DW_MMIO) += dw_spi_mmio.o diff --git a/drivers/spi/spi_test.c b/drivers/spi/spi_test.c new file mode 100755 index 000000000000..9c7bc8fbb93e --- /dev/null +++ b/drivers/spi/spi_test.c @@ -0,0 +1,175 @@ +/*drivers/serial/spi_test.c -spi test driver + * + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "rk29_spim.h" +#include +#include + +struct spi_test_data { + struct device *dev; + struct spi_device *spi; + char *rx_buf; + int rx_len; + char *tx_buf; + int tx_len; +}; +static struct spi_test_data *g_spi_test_data; + + +static struct rk29xx_spi_chip spi_test_chip = { + //.poll_mode = 1, + .enable_dma = 1, +}; + +static struct spi_board_info board_spi_test_devices[] = { + { + .modalias = "spi_test", + .bus_num = 0, //0 or 1 + .max_speed_hz = 12*1000*1000, + .chip_select = 0, + .controller_data = &spi_test_chip, + }, + +}; + +static ssize_t spi_test_write(struct file *file, + const char __user *buf, size_t count, loff_t *offset) +{ + char nr_buf[8]; + int nr = 0, ret; + int i = 0; + struct spi_device *spi = g_spi_test_data->spi; + char txbuf[256],rxbuf[256]; + + if(count > 3) + return -EFAULT; + ret = copy_from_user(nr_buf, buf, count); + if(ret < 0) + return -EFAULT; + + sscanf(nr_buf, "%d", &nr); + if(nr >= 2 || nr < 0) + { + printk("%s:data is error\n",__func__); + return -EFAULT; + } + + for(i=0; i<256; i++) + txbuf[i] = i; + + switch(nr) + { + case 0: + spi->chip_select = 0; + break; + case 1: + spi->chip_select = 1; + break; + + default: + break; + + } + + for(i=0; i<10; i++) + { + ret = spi_write(spi, txbuf, 256); + ret = spi_read(spi, rxbuf, 256); + ret = spi_write_then_read(spi,txbuf,256,rxbuf,256); + printk("%s:test %d times\n\n",__func__,i+1); + } + + if(!ret) + printk("%s:ok\n",__func__); + else + printk("%s:error\n",__func__); + + return count; +} + + +static const struct file_operations spi_test_fops = { + .write = spi_test_write, +}; + +static struct miscdevice spi_test_misc = { + .minor = MISC_DYNAMIC_MINOR, + .name = "spi_misc_test", + .fops = &spi_test_fops, +}; + +static int __devinit spi_test_probe(struct spi_device *spi) +{ + struct spi_test_data *spi_test_data; + int ret; + + spi_test_data = (struct spi_test_data *)kzalloc(sizeof(struct spi_test_data), GFP_KERNEL); + if(!spi_test_data){ + dev_err(&spi->dev, "ERR: no memory for spi_test_data\n"); + return -ENOMEM; + } + + spi->bits_per_word = 8; + spi->mode = SPI_MODE_0; + + spi_test_data->spi = spi; + spi_test_data->dev = &spi->dev; + ret = spi_setup(spi); + if (ret < 0){ + dev_err(spi_test_data->dev, "ERR: fail to setup spi\n"); + return -1; + } + + g_spi_test_data = spi_test_data; + + printk("%s:bus_num=%d,ok\n",__func__,spi->bus_num); + + return ret; + +} + + +static struct spi_driver spi_test_driver = { + .driver = { + .name = "spi_test", + .bus = &spi_bus_type, + .owner = THIS_MODULE, + }, + + .probe = spi_test_probe, +}; + +static int __init spi_test_init(void) +{ + spi_register_board_info(board_spi_test_devices, ARRAY_SIZE(board_spi_test_devices)); + misc_register(&spi_test_misc); + return spi_register_driver(&spi_test_driver); +} + +static void __exit spi_test_exit(void) +{ + misc_deregister(&spi_test_misc); + return spi_unregister_driver(&spi_test_driver); +} +module_init(spi_test_init); +module_exit(spi_test_exit); +