LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-28-2012, 04:20 AM   #1
yixiaoyang
LQ Newbie
 
Registered: Mar 2012
Location: China
Posts: 4

Rep: Reputation: Disabled
why couldn't i access spi_read,spi_write in spidev.c??


Iam writing a driver for RF module(spi controller interface) with linux2.6.30 on my Embeded board.I modified spidev.c,add some test code (use spi_read,spi_write).then I have passed test with http://www.kernel.org/doc/Documentation/spi/spidev_test.c ,but I found that the spi_read,spi_write not work in my kernel,but ioctl(fd, SPI_IOC_MESSAGE(1), &tr) is OK in the userspace testing code.why couldn't i access spi_read,spi_write in spidev.c??

Note: probe has been called normally!!!

test code in spidev_probe is following.
Code:
static int spidev_probe(struct spi_device *spi)
{
	struct spidev_data	*spidev;
	int			status;
	unsigned long		minor;
	int i = 0;
	/* Allocate driver data */
	spidev = kzalloc(sizeof(*spidev), GFP_KERNEL);
	if (!spidev)
		return -ENOMEM;

	/* Initialize the driver data */
	spidev->spi = spi;
	spin_lock_init(&spidev->spi_lock);
	mutex_init(&spidev->buf_lock);

	INIT_LIST_HEAD(&spidev->device_entry);

	/* If we can allocate a minor number, hook up this device.
	 * Reusing minors is fine so long as udev or mdev is working.
	 */
	mutex_lock(&device_list_lock);
	minor = find_first_zero_bit(minors, N_SPI_MINORS);
	if (minor < N_SPI_MINORS) {
		struct device *dev;

		spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
		/*dev = device_create(spidev_class, &spi->dev, spidev->devt,
				    spidev, "spidev%d.%d",
				    spi->master->bus_num, spi->chip_select);
		*/
		dev = device_create(spidev_class, &spi->dev, spidev->devt,
				    spidev, this_device_name);
		status = IS_ERR(dev) ? PTR_ERR(dev) : 0;
	} else {
		dev_dbg(&spi->dev, "no minor number available!\n");
		status = -ENODEV;
	}
	if (status == 0) {
		set_bit(minor, minors);
		list_add(&spidev->device_entry, &device_list);
	}
	mutex_unlock(&device_list_lock);

	if (status == 0){
		spi_set_drvdata(spi, spidev);
		
		
		/*test code*/
		printk("test 3 start!\n");
		if(spi_write(spidev->spi,tx_buf,8)< 0){
			printk("spi_write write error!\n");
		}
		if(spi_read (spidev->spi,rx_buf,8)){
			printk("spi_write read error!\n");
		}
		for(i = 0; i < 8; i++){
			printk("{%2x}\n",rx_buf[i]);
		}
		printk("test 4 start!\n");
		for(i = 0; i < 8; i++){
			printk("{%2x}\n",spi_w8r8(spidev->spi,i));
		}
		printk("test end!\n");
		
		#if 0
		RF_CHIP_INITIALIZE(spidev);
		RF_NET_CONFIG(spidev);
		#endif
	}else{
		kfree(spidev);
	}
	
	return status;
}

Note:
bellow is doc about IO interface in http://www.kernel.org/doc/Documentation/spi/spidev

Standard read() and write() operations are obviously only half-duplex, and
the chipselect is deactivated between those operations. Full-duplex access,and composite operation without chipselect de-activation, is available using the SPI_IOC_MESSAGE(N) request.

传统的read write使用的是半双工模式,需要cs片选;而 SPI_IOC_MESSAGE(N) 方式使用全双工,无须片选。

- At this time there is no async I/O support; everything is purely
synchronous.都是同步的?

Last edited by yixiaoyang; 03-28-2012 at 04:22 AM.
 
Old 03-28-2012, 04:28 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,122

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
do you have compile time error or runtime error?
 
Old 03-28-2012, 09:04 PM   #3
yixiaoyang
LQ Newbie
 
Registered: Mar 2012
Location: China
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
do you have compile time error or runtime error?
of course no compile error or runting error.
NOTE:I connect MISO wire with MOSI, and run test file http://www.kernel.org/doc/Documentat.../spidev_test.c in kernel. The result run on the ARM9 board as bellow:

Code:
[root@EmbedSky /test]# insmod lrf020.ko
2012-3-27 16:48
test 3 start!
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
test 4 start!
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
test end!
[root@EmbedSky /test]# ./spi_test3
test 1 start!
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}

test 2 start!
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
{ 0}
test end!
My test code in kernel with spi_read/write not work!

FF FF FF FF FF FF
40 00 00 00 00 95
FF FF FF FF FF FF
FF FF FF FF FF FF
FF FF FF FF FF FF
DE AD BE EF BA AD
F0 0D
It;s OK,so ioctl(fd, SPI_IOC_MESSAGE(1) works!
I wander whether somewhere not be set correctly or I have forgetten something important...
It seems strange

Compiling Message:
make -C /opt/linux/EmbedSky/linux-2.6.30.4 M=/opt/git-hub/linux_driver/lrf020-beta/lrf020-old modules -I /opt/linux/EmbedSky/linux-2.6.30.4/include
make[1]: 进入目录“/opt/linux/EmbedSky/linux-2.6.30.4”
CC [M] /opt/git-hub/linux_driver/lrf020-beta/lrf020-old/rf.o
CC [M] /opt/git-hub/linux_driver/lrf020-beta/lrf020-old/uz2400d.o
CC [M] /opt/git-hub/linux_driver/lrf020-beta/lrf020-old/spidev.o
LD [M] /opt/git-hub/linux_driver/lrf020-beta/lrf020-old/lrf020.o
Building modules, stage 2.
MODPOST 1 modules
CC /opt/git-hub/linux_driver/lrf020-beta/lrf020-old/lrf020.mod.o
LD [M] /opt/git-hub/linux_driver/lrf020-beta/lrf020-old/lrf020.ko
make[1]: 离开目录“/opt/linux/EmbedSky/linux-2.6.30.4”
compiled ok!

Last edited by yixiaoyang; 03-28-2012 at 09:09 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
initialise SPIDEV from userspace beaglebone Nixon Linux - Embedded & Single-board computer 0 02-23-2012 06:25 AM
Problems with SPI driver and spidev asmeti Linux - Software 2 11-11-2011 10:08 PM
Webmail behind the firewall couldn't be access Niceman2005 Linux - Security 2 01-13-2006 07:08 PM
couldn't display smb:/// because access was denied wadly Linux - Networking 2 04-19-2004 07:48 AM
Couldn't get access to most homepages after mandrake update wiggywag Mandriva 1 09-03-2003 07:20 AM


All times are GMT -5. The time now is 10:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration