[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [microblaze-uclinux] spi and spidev usage



Hi everyone,

I apologize for not updating this thread for quite some time.  I've
been finishing my paper at my university regarding implementing the
SPIDEV driver for the Spartan 3E.  I will be happy to share the link
once it has been published.

In the meantime, as Dr. Williams suggested, I have posted the kernel
patch below.  I gone through all my work and tested it to ensure it
works correctly.  I have successfully tested the DAC and ADC on the
Spartan 3E using a user application I have written.  I will be happy
to post any of this code if requested (it will be contained in the
paper I am finishing).

This patch was just updated for v.0.40-rc3 build of Petalinux using
the latest build of the Xilinx SPI drivers off their git repsitory.
There was quite a bit of difference in the patch previously posted on
this thread and the one below.  Xilinx appears to have added some new
structures in their SPI code in the repository, which required me to
update the patch.

In addition to the patch, keep in mind that three files are required
from the Xilinx git repository to use SPIDEV:

1) linux-2.6-xlnx/drivers/spi/xilinx_spi.c
2) linux-2.6-xlnx/drivers/spi/spidev.c
3) linux-2.6-xlnx/include/linux/spi/spidev.h

I'd be happy to answer any questions and just wanted to thank everyone
again for all your help.  Thanks!

Matt

SPIDEV Kernel Patch

----------------------------------------------------------------

diff -rupN petalinux-svn.orig/software/linux-2.6.x-petalogix/arch/microblaze/platform/common/Makefile
petalinux-svn/software/linux-2.6.x-petalogix/arch/microblaze/platform/common/Makefile
--- petalinux-svn.orig/software/linux-2.6.x-petalogix/arch/microblaze/platform/common/Makefile	2009-01-30
12:24:12.000000000 +0100
+++ petalinux-svn/software/linux-2.6.x-petalogix/arch/microblaze/platform/common/Makefile	2009-03-02
10:38:46.000000000 +0100
@@ -14,7 +14,7 @@ EXTRA_CFLAGS	+= -I$(TOPDIR)/drivers/xili

 platobj-$(CONFIG_MTD_PHYSMAP) += physmap-flash.o
 platobj-$(CONFIG_XILINX_GPIO) += xgpio.o
-platobj-$(CONFIG_XILINX_SPI)  += xspi.o
+platobj-$(CONFIG_SPI_XILINX)  += xspi.o
 platobj-$(CONFIG_SERIAL_UARTLITE)  += xuartlite.o
 platobj-$(CONFIG_SERIAL_8250)  += x16550.o
 platobj-$(CONFIG_XILINX_SYSACE)  += xsysace.o
diff -rupN petalinux-svn.orig/software/linux-2.6.x-petalogix/arch/microblaze/platform/common/xspi.c
petalinux-svn/software/linux-2.6.x-petalogix/arch/microblaze/platform/common/xspi.c
--- petalinux-svn.orig/software/linux-2.6.x-petalogix/arch/microblaze/platform/common/xspi.c	2007-04-01
22:54:51.000000000 -0700
+++ petalinux-svn/software/linux-2.6.x-petalogix/arch/microblaze/platform/common/xspi.c	2009-05-18
23:44:51.000000000 -0700
@@ -1,83 +1,80 @@
-/*
- * arch/microblaze/platform/common/xspi.c
- *
- * platform device initialisation for Xilinx SPI devices
- *
- * Copyright 2007 PetaLogix
- *
- * based on original kernel/platform.c which was
- * Copyright 2007 LynuxWorks
- *
- * This file is licensed under the terms of the GNU General Public License
- * version 2.  This program is licensed "as is" without any warranty of any
- * kind, whether express or implied.
- */
-
-#include <linux/autoconf.h>
-#include <linux/init.h>
-#include <linux/resource.h>
-#include <linux/xilinx_devices.h>
-#include <linux/serial_8250.h>
-
-#define XSPI_PLATFORM_DATA_INITIALISER(n) 		\
-{							\
-	.device_flags = (CONFIG_XILINX_SPI_##n##_FIFO_EXIST ? XSPI_HAS_FIFOS : 0) | \
-		(CONFIG_XILINX_SPI_##n##_SPI_SLAVE_ONLY ? XSPI_SLAVE_ONLY : 0), \
-	.num_slave_bits = CONFIG_XILINX_SPI_##n##_NUM_SS_BITS	\
-}
-
-#define XSPI_PLATFORM_DEVICE_INITIALISER(n)		\
-{							\
-	.name = "xilinx_spi",				\
-	.id = (n),					\
-	.dev.platform_data = &xspi_pdata[n],		\
-	.num_resources = 2,				\
-	.resource = (struct resource[]) {		\
-		{					\
-			.start	= CONFIG_XILINX_SPI_##n##_BASEADDR,	\
-			.end	= CONFIG_XILINX_SPI_##n##_HIGHADDR,	\
-			.flags	= IORESOURCE_MEM			\
-		},							\
-		{							\
-			.start	= CONFIG_XILINX_SPI_##n##_IRQ,		\
-			.end	= CONFIG_XILINX_SPI_##n##_IRQ,		\
-			.flags	= IORESOURCE_IRQ			\
-		}					\
-	}						\
-}
-
-static struct xspi_platform_data xspi_pdata[] = {
-#ifdef CONFIG_XILINX_SPI_0_INSTANCE
-XSPI_PLATFORM_DATA_INITIALISER(0),
-#endif
-#ifdef CONFIG_XILINX_SPI_1_INSTANCE
-XSPI_PLATFORM_DATA_INITIALISER(1),
-#endif
-#ifdef CONFIG_XILINX_SPI_2_INSTANCE
-XSPI_PLATFORM_DATA_INITIALISER(2),
-#endif
-};
-
-static struct platform_device xilinx_spi_device[] = {
-#ifdef CONFIG_XILINX_SPI_0_INSTANCE
-XSPI_PLATFORM_DEVICE_INITIALISER(0),
-#endif
-#ifdef CONFIG_XILINX_SPI_1_INSTANCE
-XSPI_PLATFORM_DEVICE_INITIALISER(1),
-#endif
-#ifdef CONFIG_XILINX_SPI_2_INSTANCE
-XSPI_PLATFORM_DEVICE_INITIALISER(2),
-#endif
-};
-
-static int __init xspi_platform_init(void)
-{
-	int i;
-		
-	for(i=0;i<ARRAY_SIZE(xilinx_spi_device); i++)
-		platform_device_register(&xilinx_spi_device[i]);
-
-	return 0;
-}
-
-device_initcall(xspi_platform_init);
+/*

+* arch/microblaze/platform/common/xspi.c

+*

+* platform device initialisation for Xilinx SPI devices

+*

+* Based on arch/microblaze/platform/common/xspi.c and

+* xilspi.c from someone posting to the uclinux mailing list.

+*

+* Modified for the Xilinx xilinx_spi driver!

+*/

+

+#include <linux/autoconf.h>

+#include <linux/init.h>

+#include <linux/resource.h>

+#include <linux/xilinx_devices.h>

+#include <linux/serial_8250.h>

+

+

+#define XSPI_PLATFORM_DATA_INITIALISER(n) 		\

+{							\

+	.bus_num = n, \

+	.num_chipselect = CONFIG_XILINX_SPI_##n##_NUM_SS_BITS,	\

+	.speed_hz = CONFIG_XILINX_CPU_CLOCK_FREQ /
CONFIG_XILINX_SPI_##n##_OPB_SCK_RATIO \

+}

+

+#define XSPI_PLATFORM_DEVICE_INITIALISER(n)                \

+{                                                        \

+        .name = "xilinx_spi",                                \

+        .id = (n),                                        \

+        .dev.platform_data = &xspi_pdata[n],                \

+        .num_resources = 2,                                \

+        .resource = (struct resource[]) {                \

+                {                                        \

+                        .start        =
CONFIG_XILINX_SPI_##n##_BASEADDR,        \

+                        .end        =
CONFIG_XILINX_SPI_##n##_HIGHADDR,        \

+                        .flags        = IORESOURCE_MEM                        \

+                },                                                        \

+                {                                                        \

+                        .start        = CONFIG_XILINX_SPI_##n##_IRQ,
              \

+                        .end        = CONFIG_XILINX_SPI_##n##_IRQ,
            \

+                        .flags        = IORESOURCE_IRQ                        \

+                }                                        \

+        }                                                \

+}

+

+static struct xspi_platform_data xspi_pdata[] = {

+#ifdef CONFIG_XILINX_SPI_0_INSTANCE

+XSPI_PLATFORM_DATA_INITIALISER(0),

+#endif

+#ifdef CONFIG_XILINX_SPI_1_INSTANCE

+XSPI_PLATFORM_DATA_INITIALISER(1),

+#endif

+#ifdef CONFIG_XILINX_SPI_2_INSTANCE

+XSPI_PLATFORM_DATA_INITIALISER(2),

+#endif

+};

+

+static struct platform_device xilinx_spi_device[] = {

+#ifdef CONFIG_XILINX_SPI_0_INSTANCE

+XSPI_PLATFORM_DEVICE_INITIALISER(0),

+#endif

+#ifdef CONFIG_XILINX_SPI_1_INSTANCE

+XSPI_PLATFORM_DEVICE_INITIALISER(1),

+#endif

+#ifdef CONFIG_XILINX_SPI_2_INSTANCE

+XSPI_PLATFORM_DEVICE_INITIALISER(2),

+#endif

+};

+

+static int __init xspi_platform_init(void)

+{

+        int i;

+

+        for(i=0;i<ARRAY_SIZE(xilinx_spi_device); i++)

+                platform_device_register(&xilinx_spi_device[i]);

+

+	return 0;

+}

+

+device_initcall(xspi_platform_init);


diff -rupN petalinux-svn.orig/software/linux-2.6.x-petalogix/arch/microblaze/platform/Xilinx-Spartan3E500-RevD/setup.c
petalinux-svn/software/linux-2.6.x-petalogix/arch/microblaze/platform/Xilinx-Spartan3E500-RevD/setup.c
--- petalinux-svn.orig/software/linux-2.6.x-petalogix/arch/microblaze/platform/Xilinx-Spartan3E500-RevD/setup.c	2009-01-14
10:16:06.000000000 +0100
+++ petalinux-svn/software/linux-2.6.x-petalogix/arch/microblaze/platform/Xilinx-Spartan3E500-RevD/setup.c	2009-03-02
11:22:45.000000000 +0100
@@ -7,4 +7,76 @@
  */

 /* Nothing to do, but we need this C file to keep kbuild happy */
+/* This is not true. We are now registering SPI slaves here. */

+#include <linux/device.h>
+#include <linux/spi/spi.h>
+
+static struct spi_board_info spi_board_info[] __initdata = {
+	/* (order of busses here has no influence on numbering) */
+	/* first bus on EVM (only 4 devices) */
+	{
+		/* SPI flash on the Spartan EVM --> spi-0 */
+		.modalias	= "spidev",
+		.max_speed_hz	= 1000000,
+		.bus_num	= 0,
+		.chip_select	= 0,
+	},
+	{
+		/* dummy --> spi-1 */
+		.modalias	= "spidev",
+		.max_speed_hz	= 1000000,
+		.bus_num	= 0,
+		.chip_select	= 1,
+	},
+	{
+		/* dummy --> spi-2 */
+		.modalias	= "spidev",
+		.max_speed_hz	= 1000000,
+		.bus_num	= 0,
+		.chip_select	= 2,
+	},
+	{
+		/* dummy --> spi-3 */
+		.modalias	= "spidev",
+		.max_speed_hz	= 1000000,
+		.bus_num	= 0,
+		.chip_select	= 3,
+	},
+	/* second bus on expansion board (only 4 devices) */
+	{
+		/* dummy --> spi-4 */
+		.modalias	= "spidev",
+		.max_speed_hz	= 1000000,
+		.bus_num	= 1,
+		.chip_select	= 0,
+	},
+	{
+		/* dummy --> spi-5 */
+		.modalias	= "spidev",
+		.max_speed_hz	= 1000000,
+		.bus_num	= 1,
+		.chip_select	= 1,
+	},
+	{
+		/* dummy --> spi-6 */
+		.modalias	= "spidev",
+		.max_speed_hz	= 1000000,
+		.bus_num	= 1,
+		.chip_select	= 2,
+	},
+	{
+		/* dummy --> spi-7 */
+		.modalias	= "spidev",
+		.max_speed_hz	= 1000000,
+		.bus_num	= 1,
+		.chip_select	= 3,
+	},
+};
+
+static int board_init_spi(void)
+{
+	spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
+	return 0;
+}
+arch_initcall(board_init_spi);
diff -rupN petalinux-svn.orig/software/linux-2.6.x-petalogix/drivers/spi/Kconfig
petalinux-svn/software/linux-2.6.x-petalogix/drivers/spi/Kconfig
--- petalinux-svn.orig/software/linux-2.6.x-petalogix/drivers/spi/Kconfig	2007-03-30
07:49:34.000000000 +0200
+++ petalinux-svn/software/linux-2.6.x-petalogix/drivers/spi/Kconfig	2009-03-02
10:37:45.000000000 +0100
@@ -103,6 +103,14 @@ config SPI_S3C24XX_GPIO
 	  GPIO lines to provide the SPI bus. This can be used where
 	  the inbuilt hardware cannot provide the transfer mode, or
 	  where the board is using non hardware connected pins.
+
+config SPI_XILINX
+	tristate "Xilinx SPI controller"
+	depends on SPI_MASTER
+	select SPI_BITBANG
+ 	help
+	This exposes the SPI controller IP from the Xilinx EDK.
+	Experimental.
 #
 # Add new SPI master controllers in alphabetical order above this line
 #
@@ -143,6 +151,13 @@ config SPI_S3C24XX
 comment "SPI Protocol Masters"
 	depends on SPI_MASTER

+config SPI_SPIDEV
+	tristate "User mode SPI device driver support"
+	help
+	  This supports user mode SPI protocol drivers.
+
+	  Note that this application programming interface is EXPERIMENTAL
+	  and hence SUBJECT TO CHANGE WITHOUT NOTICE while it stabilizes.

 #
 # Add new SPI protocol masters in alphabetical order above this line
diff -rupN petalinux-svn.orig/software/linux-2.6.x-petalogix/drivers/spi/Makefile
petalinux-svn/software/linux-2.6.x-petalogix/drivers/spi/Makefile
--- petalinux-svn.orig/software/linux-2.6.x-petalogix/drivers/spi/Makefile	2007-03-30
07:49:34.000000000 +0200
+++ petalinux-svn/software/linux-2.6.x-petalogix/drivers/spi/Makefile	2009-03-02
10:38:05.000000000 +0100
@@ -19,9 +19,11 @@ obj-$(CONFIG_SPI_S3C24XX_GPIO)		+= spi_s
 obj-$(CONFIG_SPI_S3C24XX)		+= spi_s3c24xx.o
 obj-$(CONFIG_MCFQSPI)			+= mcf_qspi.o
 obj-$(CONFIG_DS1305)			+= DS1305RTC.o
+obj-$(CONFIG_SPI_XILINX)                += xilinx_spi.o
 # 	... add above this line ...

 # SPI protocol drivers (device/link on bus)
+obj-$(CONFIG_SPI_SPIDEV)                += spidev.o
 # 	... add above this line ...

 # SPI slave controller drivers (upstream link)
diff -rupN petalinux-svn.orig/software/linux-2.6.x-petalogix/drivers/spi/spidev.c
petalinux-svn/software/linux-2.6.x-petalogix/drivers/spi/spidev.c
--- petalinux-svn.orig/software/linux-2.6.x-petalogix/drivers/spi/spidev.c	2009-03-02
11:09:02.000000000 +0100
+++ petalinux-svn/software/linux-2.6.x-petalogix/drivers/spi/spidev.c	2009-03-02
11:20:39.000000000 +0100
@@ -37,6 +37,7 @@

 #include <asm/uaccess.h>

+typedef unsigned int* uintptr_t;

 /*
  * This supports acccess to SPI devices using normal userspace I/O calls.
@@ -52,9 +53,11 @@
  * particular SPI bus or device.
  */
 #define SPIDEV_MAJOR			153	/* assigned */
-#define N_SPI_MINORS			32	/* ... up to 256 */
+//#define N_SPI_MINORS			32	/* ... up to 256 */
+#define N_SPI_MINORS			8	/* ... up to 256 */

-static unsigned long	minors[N_SPI_MINORS / BITS_PER_LONG];
+//static unsigned long	minors[N_SPI_MINORS / BITS_PER_LONG];
+static unsigned long	minors[1];


 /* Bit masks for spi_device.mode management.  Note that incorrect
@@ -561,7 +564,7 @@ static int spidev_probe(struct spi_devic
 	struct spidev_data	*spidev;
 	int			status;
 	unsigned long		minor;
-
+	
 	/* Allocate driver data */
 	spidev = kzalloc(sizeof(*spidev), GFP_KERNEL);
 	if (!spidev)
@@ -584,9 +587,10 @@ static int spidev_probe(struct spi_devic

 		spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
 		dev = device_create(spidev_class, &spi->dev, spidev->devt,
-				    spidev, "spidev%d.%d",
+				    /*spidev,*/ "spidev%d.%d",
 				    spi->master->bus_num, spi->chip_select);
 		status = IS_ERR(dev) ? PTR_ERR(dev) : 0;
+		dev_dbg(&spi->dev, "spidev%d.%d created\n", spi->master->bus_num,
spi->chip_select);
 	} else {
 		dev_dbg(&spi->dev, "no minor number available!\n");
 		status = -ENODEV;
@@ -668,6 +672,7 @@ static int __init spidev_init(void)
 		class_destroy(spidev_class);
 		unregister_chrdev(SPIDEV_MAJOR, spidev_spi.driver.name);
 	}
+
 	return status;
 }
 module_init(spidev_init);
diff -rupN petalinux-svn.orig/software/linux-2.6.x-petalogix/drivers/spi/xilinx_spi.c
petalinux-svn/software/linux-2.6.x-petalogix/drivers/spi/xilinx_spi.c
--- petalinux-svn.orig/software/linux-2.6.x-petalogix/drivers/spi/xilinx_spi.c	2009-05-22
14:13:52.000000000 -0700
+++ petalinux-svn/software/linux-2.6.x-petalogix/drivers/spi/xilinx_spi.c	2009-03-04
22:18:58.000000000 -0800
@@ -15,15 +15,12 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
-
-#include <linux/of_platform.h>
-#include <linux/of_device.h>
-#include <linux/of_spi.h>
-
 #include <linux/spi/spi.h>
 #include <linux/spi/spi_bitbang.h>
 #include <linux/io.h>

+#include <linux/xilinx_devices.h>
+
 #define XILINX_SPI_NAME "xilinx_spi"

 /* Register definitions as per "OPB Serial Peripheral Interface (SPI) (v1.00e)
@@ -147,11 +144,20 @@
 		struct spi_transfer *t)
 {
 	u8 bits_per_word;
+	u32 hz;
+	struct xilinx_spi *xspi = spi_master_get_devdata(spi->master);

 	bits_per_word = (t) ? t->bits_per_word : spi->bits_per_word;
+	hz = (t) ? t->speed_hz : spi->max_speed_hz;
 	if (bits_per_word != 8) {
-		dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
-			__func__, bits_per_word);
+		dev_err(&spi->dev, "%s, unsupported bits_per_word=%d, bus supports 8\n",
+  			__func__, bits_per_word);
+		return -EINVAL;
+	}
+
+	if (hz && xspi->speed_hz > hz) {
+		dev_err(&spi->dev, "%s, unsupported clock rate %uHz, bus uses %uHz\n",
+			__func__, hz, xspi->speed_hz);
 		return -EINVAL;
 	}

@@ -299,38 +304,32 @@
 	return IRQ_HANDLED;
 }

-static int __init xilinx_spi_of_probe(struct of_device *ofdev,
-					const struct of_device_id *match)
+static int __init xilinx_spi_probe(struct platform_device *dev)
 {
+	int ret = 0;
 	struct spi_master *master;
 	struct xilinx_spi *xspi;
-	struct resource r_irq_struct;
-	struct resource r_mem_struct;
-
-	struct resource *r_irq = &r_irq_struct;
-	struct resource *r_mem = &r_mem_struct;
-	int rc = 0;
-	const u32 *prop;
-	int len;
+	struct xspi_platform_data *pdata;
+	struct resource *r;

 	/* Get resources(memory, IRQ) associated with the device */
-	master = spi_alloc_master(&ofdev->dev, sizeof(struct xilinx_spi));
+	master = spi_alloc_master(&dev->dev, sizeof(struct xilinx_spi));

 	if (master == NULL) {
 		return -ENOMEM;
 	}

-	dev_set_drvdata(&ofdev->dev, master);
+	platform_set_drvdata(dev, master);
+	pdata = dev->dev.platform_data;

-	rc = of_address_to_resource(ofdev->node, 0, r_mem);
-	if (rc) {
-		dev_warn(&ofdev->dev, "invalid address\n");
+	if (pdata == NULL) {
+		ret = -ENODEV;
 		goto put_master;
 	}

-	rc = of_irq_to_resource(ofdev->node, 0, r_irq);
-	if (rc == NO_IRQ) {
-		dev_warn(&ofdev->dev, "no IRQ found\n");
+	r = platform_get_resource(dev, IORESOURCE_MEM, 0);
+	if (r == NULL) {
+		ret = -ENODEV;
 		goto put_master;
 	}

@@ -342,84 +341,69 @@
 	xspi->bitbang.master->setup = xilinx_spi_setup;
 	init_completion(&xspi->done);

-	xspi->irq = r_irq->start;
-
-	if (!request_mem_region(r_mem->start,
-			r_mem->end - r_mem->start + 1, XILINX_SPI_NAME)) {
-		rc = -ENXIO;
-		dev_warn(&ofdev->dev, "memory request failure\n");
+	if (!request_mem_region(r->start,
+			r->end - r->start + 1, XILINX_SPI_NAME)) {
+		ret = -ENXIO;
 		goto put_master;
 	}

-	xspi->regs = ioremap(r_mem->start, r_mem->end - r_mem->start + 1);
+	xspi->regs = ioremap(r->start, r->end - r->start + 1);
 	if (xspi->regs == NULL) {
-		rc = -ENOMEM;
-		dev_warn(&ofdev->dev, "ioremap failure\n");
-		goto release_mem;
-	}
-	xspi->irq = r_irq->start;
-
-	/* dynamic bus assignment */
-	master->bus_num = -1;
-
-	/* number of slave select bits is required */
-	prop = of_get_property(ofdev->node, "xlnx,num-ss-bits", &len);
-	if (!prop || len < sizeof(*prop)) {
-		dev_warn(&ofdev->dev, "no 'xlnx,num-ss-bits' property\n");
+		ret = -ENOMEM;
+		goto put_master;
+	}
+
+	ret = platform_get_irq(dev, 0);
+	if (ret < 0) {
+		ret = -ENXIO;
 		goto unmap_io;
 	}
-	master->num_chipselect = *prop;
+	xspi->irq = ret;
+
+	master->bus_num = pdata->bus_num;
+	master->num_chipselect = pdata->num_chipselect;
+	xspi->speed_hz = pdata->speed_hz;

 	/* SPI controller initializations */
 	xspi_init_hw(xspi->regs);

 	/* Register for SPI Interrupt */
-	rc = request_irq(xspi->irq, xilinx_spi_irq, 0, XILINX_SPI_NAME, xspi);
-	if (rc != 0) {
-		dev_warn(&ofdev->dev, "irq request failure: %d\n", xspi->irq);
+	ret = request_irq(xspi->irq, xilinx_spi_irq, 0, XILINX_SPI_NAME, xspi);
+	if (ret != 0)
 		goto unmap_io;
-	}

-	rc = spi_bitbang_start(&xspi->bitbang);
-	if (rc != 0) {
-		dev_err(&ofdev->dev, "spi_bitbang_start FAILED\n");
+	ret = spi_bitbang_start(&xspi->bitbang);
+	if (ret != 0) {
+		dev_err(&dev->dev, "spi_bitbang_start FAILED\n");
 		goto free_irq;
 	}

-	dev_info(&ofdev->dev, "at 0x%08X mapped to 0x%08X, irq=%d\n",
-			(unsigned int)r_mem->start, (u32)xspi->regs, xspi->irq);
-
-	/* Add any subnodes on the SPI bus */
-	of_register_spi_devices(master, ofdev->node);
+	dev_info(&dev->dev, "at 0x%08X mapped to 0x%08X, irq=%d\n",
+			r->start, (u32)xspi->regs, xspi->irq);

-	return rc;
+	return ret;

 free_irq:
 	free_irq(xspi->irq, xspi);
 unmap_io:
 	iounmap(xspi->regs);
-release_mem:
-	release_mem_region(r_mem->start, resource_size(r_mem));
 put_master:
 	spi_master_put(master);
-	return rc;
+	return ret;
 }

-static int __devexit xilinx_spi_remove(struct of_device *ofdev)
+static int __devexit xilinx_spi_remove(struct platform_device *dev)
 {
 	struct xilinx_spi *xspi;
 	struct spi_master *master;
-	struct resource r_mem;

-	master = platform_get_drvdata(ofdev);
+	master = platform_get_drvdata(dev);
 	xspi = spi_master_get_devdata(master);

 	spi_bitbang_stop(&xspi->bitbang);
 	free_irq(xspi->irq, xspi);
 	iounmap(xspi->regs);
-	if (!of_address_to_resource(ofdev->node, 0, &r_mem))
-		release_mem_region(r_mem.start, resource_size(&r_mem));
-	dev_set_drvdata(&ofdev->dev, 0);
+	platform_set_drvdata(dev, 0);
 	spi_master_put(xspi->bitbang.master);

 	return 0;
@@ -428,42 +412,27 @@
 /* work with hotplug and coldplug */
 MODULE_ALIAS("platform:" XILINX_SPI_NAME);

-static int __exit xilinx_spi_of_remove(struct of_device *op)
-{
-	return xilinx_spi_remove(op);
-}
-
-static struct of_device_id xilinx_spi_of_match[] = {
-	{ .compatible = "xlnx,xps-spi-2.00.a", },
-	{ .compatible = "xlnx,xps-spi-2.00.b", },
-	{}
-};
-
-MODULE_DEVICE_TABLE(of, xilinx_spi_of_match);
-
-static struct of_platform_driver xilinx_spi_of_driver = {
-	.owner = THIS_MODULE,
-	.name = "xilinx-xps-spi",
-	.match_table = xilinx_spi_of_match,
-	.probe = xilinx_spi_of_probe,
-	.remove = __exit_p(xilinx_spi_of_remove),
+static struct platform_driver xilinx_spi_driver = {
+	.probe	= xilinx_spi_probe,
+	.remove	= __devexit_p(xilinx_spi_remove),
 	.driver = {
-		.name = "xilinx-xps-spi",
+		.name = XILINX_SPI_NAME,
 		.owner = THIS_MODULE,
 	},
 };

 static int __init xilinx_spi_init(void)
 {
-	return of_register_platform_driver(&xilinx_spi_of_driver);
+	return platform_driver_register(&xilinx_spi_driver);
 }
 module_init(xilinx_spi_init);

 static void __exit xilinx_spi_exit(void)
 {
-	of_unregister_platform_driver(&xilinx_spi_of_driver);
+	platform_driver_unregister(&xilinx_spi_driver);
 }
 module_exit(xilinx_spi_exit);
+
 MODULE_AUTHOR("MontaVista Software, Inc. <source@xxxxxxxxxx>");
 MODULE_DESCRIPTION("Xilinx SPI driver");
 MODULE_LICENSE("GPL");
diff -rupN petalinux-svn.orig/software/linux-2.6.x-petalogix/include/linux/spi/spi.h
petalinux-svn/software/linux-2.6.x-petalogix/include/linux/spi/spi.h
--- petalinux-svn.orig/software/linux-2.6.x-petalogix/include/linux/spi/spi.h	2007-03-30
04:57:33.000000000 +0200
+++ petalinux-svn/software/linux-2.6.x-petalogix/include/linux/spi/spi.h	2009-03-02
10:43:22.000000000 +0100
@@ -680,4 +680,15 @@ spi_unregister_device(struct spi_device
 		device_unregister(&spi->dev);
 }

+/* device driver data */
+static inline void spi_set_drvdata(struct spi_device *spi, void *data)
+{
+       dev_set_drvdata(&spi->dev, data);
+}
+
+static inline void *spi_get_drvdata(struct spi_device *spi)
+{
+       return dev_get_drvdata(&spi->dev);
+}
+
 #endif /* __LINUX_SPI_H */
diff -rupN petalinux-svn.orig/software/linux-2.6.x-petalogix/include/linux/xilinx_devices.h
petalinux-svn/software/linux-2.6.x-petalogix/include/linux/xilinx_devices.h
--- petalinux-svn.orig/software/linux-2.6.x-petalogix/include/linux/xilinx_devices.h	2009-05-22
14:13:12.000000000 -0700
+++ petalinux-svn/software/linux-2.6.x-petalogix/include/linux/xilinx_devices.h	2009-05-18
23:44:56.000000000 -0700
@@ -18,11 +18,7 @@

 #include <linux/types.h>
 #include <linux/version.h>
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
-#include <linux/device.h>
-#else
 #include <linux/platform_device.h>
-#endif

 /*- 10/100 Mb Ethernet Controller IP (XEMAC) -*/

@@ -51,14 +47,23 @@
 #define XEMAC_DMA_SIMPLE	2	/* simple 2 channel DMA */
 #define XEMAC_DMA_SGDMA		3	/* scatter gather DMA */

+/*- 10/100 Mb Ethernet Controller IP (XEMACLITE) -*/
+struct xemaclite_platform_data {
+	u32 tx_ping_pong;
+	u32 rx_ping_pong;
+	u8 mac_addr[6];
+};
+
 /*- 10/100/1000 Mb Ethernet Controller IP (XTEMAC) -*/

 struct xtemac_platform_data {
+#ifdef XPAR_TEMAC_0_INCLUDE_RX_CSUM
 	u8 tx_dre;
 	u8 rx_dre;
 	u8 tx_csum;
 	u8 rx_csum;
 	u8 phy_type;
+#endif
 	u8 dma_mode;
 	u32 rx_pkt_fifo_depth;
 	u32 tx_pkt_fifo_depth;
@@ -74,6 +79,7 @@
 #define XTEMAC_DMA_SIMPLE	2	/* simple 2 channel DMA */
 #define XTEMAC_DMA_SGDMA	3	/* scatter gather DMA */

+/* LLTEMAC platform data */
 struct xlltemac_platform_data {
 	u8 tx_csum;
 	u8 rx_csum;
@@ -86,23 +92,22 @@
 	u32 ll_dev_fifo_irq;

 	u8 mac_addr[6];
-};
+ };
+

 /* LocalLink TYPE Enumerations */
 #define XPAR_LL_FIFO    1
 #define XPAR_LL_DMA     2

 /*- SPI -*/
-
+
+/* SPI Controller IP */
 struct xspi_platform_data {
-	u32 device_flags;
-	u8 num_slave_bits;
+	s16 bus_num;
+	u16 num_chipselect;
+	u32 speed_hz;
 };

-/* Flags related to XSPI device features */
-#define XSPI_HAS_FIFOS		0x00000001
-#define XSPI_SLAVE_ONLY		0x00000002
-
 /*- GPIO -*/

 /* Flags related to XGPIO device features */

diff -rupN petalinux-svn.orig/software/petalinux-dist/vendors/PetaLogix/common/common.mak
petalinux-svn/software/petalinux-dist/vendors/PetaLogix/common/common.mak
--- petalinux-svn.orig/software/petalinux-dist/vendors/PetaLogix/common/common.mak	2009-01-15
18:08:10.000000000 +0100
+++ petalinux-svn/software/petalinux-dist/vendors/PetaLogix/common/common.mak	2009-03-02
11:08:21.000000000 +0100
@@ -180,6 +180,7 @@ DEVICES +=	\
 endif

 I2C_MAJOR = 89
+SPIDEV_MAJOR = 153

 ifndef CONFIG_SYSTEM_ROOT_PASSWD
 CONFIG_SYSTEM_ROOT_PASSWD := "root"
@@ -231,6 +232,15 @@ ifdef CONFIG_I2C
 	done
 endif #IIC

+# make SPI nodes if necessary
+# SPIDEV_MAJOR taken from spidev.c (see definition above),
+# max number of devices matches spidev.c
+ifdef CONFIG_SPI_SPIDEV
+	for i in 0 1 2 3 4 5 6 7; do \
+		touch $(ROMFSDIR)/dev/@spi-$$i,c,$(SPIDEV_MAJOR),$$i; \
+	done
+endif #SPI_SPIDEV
+
 else
 	$(ROMFSINST) $(COMMON)/etc/rc/checkroot /etc/init.d/checkroot
 	$(ROMFSINST) -s /etc/init.d/checkroot /etc/rc.d/S01checkroot
diff -rupN petalinux-svn.orig/software/petalinux-dist/vendors/Xilinx/Spartan3E500-RevD/config.linux-2.6.x
petalinux-svn/software/petalinux-dist/vendors/Xilinx/Spartan3E500-RevD/config.linux-2.6.x
--- petalinux-svn.orig/software/petalinux-dist/vendors/Xilinx/Spartan3E500-RevD/config.linux-2.6.x	2009-02-02
11:55:59.000000000 +0100
+++ petalinux-svn/software/petalinux-dist/vendors/Xilinx/Spartan3E500-RevD/config.linux-2.6.x	2009-02-05
19:31:09.000000000 +0100
@@ -1541,8 +1541,20 @@ CONFIG_XILINX_IIC=y
 #
 # SPI support
 #
-# CONFIG_SPI is not set
-# CONFIG_SPI_MASTER is not set
+CONFIG_SPI=y
+CONFIG_SPI_MASTER=y
+
+#
+# SPI Master Controller Drivers
+#
+CONFIG_SPI_BITBANG=y
+CONFIG_SPI_XILINX=y
+# CONFIG_MCFQSPI is not set
+
+#
+# SPI Protocol Masters
+#
+CONFIG_SPI_SPIDEV=y

 #
 # Dallas's 1-wire bus

----------------------------------------------------------------
___________________________
microblaze-uclinux mailing list
microblaze-uclinux@xxxxxxxxxxxxxx
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive : http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/