xilinx_spi: Added platform driver and support for DS570
Subsystems (2)
PATCH 1/1 xilinx_spi: Added platform driver and support for DS570
Here is a patch where the xilinx_spi is splitted into three parts, an OF and a platform driver and generic part.
The generic part now also works on X86 and support for the Xilinx SPI IP DS570
---
drivers/spi/Kconfig +21 -2
@@ -211,8 +211,8 @@ SPI driver for Toshiba TXx9 MIPS SoCs config SPI_XILINX - tristate "Xilinx SPI controller" - depends on XILINX_VIRTEX && EXPERIMENTAL + tristate "Xilinx SPI controller common module" + depends on EXPERIMENTAL select SPI_BITBANG help This exposes the SPI controller IP from the Xilinx EDK.
@@ -220,6 +220,25 @@ See the "OPB Serial Peripheral Interface (SPI) (v1.00e)" Product Specification document (DS464) for hardware details. +config SPI_XILINX_OF + tristate "Xilinx SPI controller OF device" + depends on SPI_XILINX && XILINX_VIRTEX + help + This exposes the SPI controller IP from the Xilinx EDK. + + See the "OPB Serial Peripheral Interface (SPI) (v1.00e)" + Product Specification document (DS464) for hardware details. + +config SPI_XILINX_PLTFM + tristate "Xilinx SPI controller platform device" + depends on SPI_XILINX + help + This exposes the SPI controller IP from the Xilinx EDK. + + See the "OPB Serial Peripheral Interface (SPI) (v1.00e)" + Product Specification document (DS464) for hardware details. + + # # Add new SPI master controllers in alphabetical order above this line #
drivers/spi/xilinx_spi_of.c +123 -0
123 lines not on this page · raw message
drivers/spi/xilinx_spi.c +204 -188
589 lines not on this page · raw message
drivers/spi/xilinx_spi_pltfm.c +104 -0
104 lines not on this page · raw message
drivers/spi/xilinx_spi.h +27 -0
@@ -0,0 +1,27 @@ +/* +* xilinx_spi.c +* +* Xilinx SPI controller driver (master mode only) +* +* Author: MontaVista Software, Inc. +* [email protected] +* +* 2002-2007 (c) MontaVista Software, Inc. 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. +*/ + +#ifndef _XILINX_SPI_H_ +#define _XILINX_SPI_H_ 1 + +#include <linux/spi/spi.h> +#include <linux/spi/spi_bitbang.h> +#include <linux/spi/xilinx_spi.h> + +#define XILINX_SPI_NAME "xilinx_spi" + +struct spi_master *xilinx_spi_init (struct device *dev,struct resource *mem, +u32 irq,u8 model,s16 bus_num,u16 num_chipselect,u8 bits_per_word); + +void xilinx_spi_deinit (struct spi_master *master); +#endif
drivers/spi/Makefile +2 -0
@@ -29,6 +29,8 @@ obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx.o obj-$(CONFIG_SPI_TXX9) += spi_txx9.o obj-$(CONFIG_SPI_XILINX) += xilinx_spi.o +obj-$(CONFIG_SPI_XILINX_OF) += xilinx_spi_of.o +obj-$(CONFIG_SPI_XILINX_PLTFM) += xilinx_spi_pltfm.o obj-$(CONFIG_SPI_SH_SCI) += spi_sh_sci.o # ... add above this line ...
include/linux/spi/mc33880.h +10 -0
@@ -0,0 +1,10 @@ +#ifndef LINUX_SPI_MC33880_H +#define LINUX_SPI_MC33880_H + +struct mc33880_platform_data { +/* number assigned to the first GPIO */ +unsigned base; +}; + +#endif +
include/linux/spi/xilinx_spi.h +19 -0
@@ -0,0 +1,19 @@ +#ifndef __LINUX_SPI_XILINX_SPI_H +#define __LINUX_SPI_XILINX_SPI_H + +#define XILINX_SPI_MODEL_DS464 0 +#define XILINX_SPI_MODEL_DS570 1 + +/* SPI Controller IP */ +struct xspi_platform_data { +s16 bus_num; +u16 num_chipselect; +u8 model; +u8 bits_per_word; +/* devices to add to the bus when the host is up */ +struct spi_board_info *devices; +u8 num_devices; +}; + +#endif /* __LINUX_SPI_XILINX_SPI_H */ +
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
spi-devel-general mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/spi-devel-general
Hmmm. It seems like this patch got dropped on the floor without any comments. Here's my review....
Quoted 5 lines · Richard Ršöjfors
Here is a patch where the
xilinx_spiis splitted into three parts, an OF and a platform driver and generic part.The generic part now also works on X86 and support for the Xilinx SPI IP DS570
Signed-off-by Richard Röjfors <[email protected]>
In general I'm not opposed to the change, but I've got concerns about the form and some of the details.
First, it is an invasive patch, primarily due to the addition of accesor macros. I'd like to see the creation of the accessors split into a separate patch from the platform/of_platform bus binding changes so that review is easier. More comments below.
Quoted 8 lines
---
Index: linux-2.6.30-rc7/drivers/spi/Kconfig
===================================================================drivers/spi/Kconfig (revision 869) renamed from drivers/spi/Kconfig (revision 861) +0
-0@@ -211,8 +211,8 @@SPI driver for Toshiba TXx9 MIPS SoCs
Quoted 5 lines
config
SPI_XILINX
- tristate "Xilinx SPI controller"
- depends onXILINX_VIRTEX&& EXPERIMENTAL
+ tristate "Xilinx SPI controller common module"
+ depends on EXPERIMENTAL
Drop the change to the description (see below)
Quoted 14 lines
select
SPI_BITBANG
help
This exposes the SPI controller IP from the Xilinx EDK.drivers/spi/Kconfig (revision 869) renamed from drivers/spi/Kconfig (revision 861) +0
-0@@ -220,6 +220,25 @@See the "OPB Serial Peripheral Interface (SPI) (v1.00e)" Product Specification document (DS464) for hardware details.
drivers/spi/Kconfig (revision 869) renamed from drivers/spi/Kconfig (revision 861) +7
-0+config SPI_XILINX_OF + tristate "Xilinx SPI controller OF device" + depends on SPI_XILINX && XILINX_VIRTEX + help + This exposes the SPI controller IP from the Xilinx EDK. + + See the "OPB Serial Peripheral Interface (SPI) (v1.00e)"
drivers/spi/Kconfig (revision 869)
Quoted 10 lines
drivers/spi/Kconfig (revision 869) renamed from drivers/spi/Kconfig (revision 861) +10
-0+ Product Specification document (DS464) for hardware details. + +config SPI_XILINX_PLTFM + tristate "Xilinx SPI controller platform device" + depends on SPI_XILINX + help + This exposes the SPI controller IP from the Xilinx EDK. + + See the "OPB Serial Peripheral Interface (SPI) (v1.00e)" + Product Specification document (DS464) for hardware details.
Personally, I'd rather these 2 options not be user-visable and instead auto-enable the OF binding when the of_bus is enabled, and auto-enable the platform bus binding when platform bus is enabled.
Quoted 30 lines
Index:
linux-2.6.30-rc7/drivers/spi/xilinx_spi.c
===================================================================drivers/spi/xilinx_spi.c (revision 869) renamed from drivers/spi/xilinx_spi.c (revision 861) +10
-6@@ -14,22 +14,79 @@ #include <linux/module.h> #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> -#define XILINX_SPI_NAME "xilinx_spi" +#include "xilinx_spi.h" +struct xilinx_spi { + /* bitbang has to be first */ + struct spi_bitbang bitbang; + struct completion done; + struct resource mem; /* phys mem */ + void __iomem *regs; /* virt. address of the control registers */ + u32 irq; + u8 *rx_ptr; /* pointer in the Tx buffer */ + const u8 *tx_ptr; /* pointer in the Rx buffer */
drivers/spi/xilinx_spi.c (revision 869) line 42
Quoted 10 lines
drivers/spi/xilinx_spi.c (revision 869) renamed from drivers/spi/xilinx_spi.c (revision 861) +10
-0+ int remaining_bytes; /* the number of bytes left to transfer */ + /* offset to the XSPI regs, these might vary... */ + u8 cr_offset; + u8 sr_offset; + u8 txd_offset; + u8 rxd_offset; + u8 ssr_offset; + u8 bits_per_word; + u8 model; +};
Why did the structure definition get moved?
drivers/spi/xilinx_spi.c (revision 869) line 51
Quoted 9 lines
drivers/spi/xilinx_spi.c (revision 869) renamed from drivers/spi/xilinx_spi.c (revision 861) +9
-0+#ifndef CONFIG_PPC +#define in_8(addr) ioread8(addr) +#define in_be16(addr) ioread16(addr) +#define in_be32(addr) ioread32(addr) + +#define out_8(addr, b) iowrite8(b, addr) +#define out_be16(addr, w) iowrite16(w, addr) +#define out_be32(addr, l) iowrite32(l, addr) +#endif
Oh, ugly. If in_*/out_* are no longer appropriate, then don't define them to the little endian variants. Remove the calls to in_/out_* and use the ioread/iowrite calls instead. In fact, even for powerpc the driver could probably be modified to use io{read,write}{8,16be,32be).
Quoted 20 lines
drivers/spi/xilinx_spi.c (revision 869) renamed from drivers/spi/xilinx_spi.c (revision 861) +20
-0+ +#define XSPI_WRITE8(xspi, offs, val) \ + do { \ + if (xspi->model == XILINX_SPI_MODEL_DS464) \ + out_8(xspi->regs + offs, (val) & 0xff); \ + else \ + XSPI_WRITE32(xspi, offs, val); \ + } while (0) + +#define XSPI_WRITE16(xspi, offs, val) \ + do { \ + if (xspi->model == XILINX_SPI_MODEL_DS464) \ + out_be16(xspi->regs + offs, (val) & 0xffff); \ + else \ + XSPI_WRITE32(xspi, offs, val); \ + } while (0) + +#define XSPI_WRITE32(xspi, offs, val) \ + out_be32(xspi->regs + offs, val) +
drivers/spi/xilinx_spi.c (revision 869) line 81
Quoted 10 lines
drivers/spi/xilinx_spi.c (revision 869) renamed from drivers/spi/xilinx_spi.c (revision 861) +10
-0+#define XSPI_READ8(xspi, offs) \ + (xspi->model == XILINX_SPI_MODEL_DS464) ? \ + in_8(xspi->regs + offs) : XSPI_READ32(xspi, offs) + +#define XSPI_READ16(xspi, offs) \ + (xspi->model == XILINX_SPI_MODEL_DS464) ? \ + in_be16(xspi->regs + offs) : XSPI_READ32(xspi, offs) + +#define XSPI_READ32(xspi, offs) \ + in_be32(xspi->regs + offs)
inlines please. Don't use #define macros. In fact, I'd consider setting up an IO access ops table which would allow the correct accessors to be set up at probe time and would eliminate all the xspi->model checks from above.
Quoted 27 lines
drivers/spi/xilinx_spi.c (revision 869) renamed from drivers/spi/xilinx_spi.c (revision 861) +7
-2+ + /* Register definitions as per "OPB Serial Peripheral Interface (SPI) (v1.00e) * Product Specification", DS464 */ -#define XSPI_CR_OFFSET 0x62 /* 16-bit Control Register */ +#define XSPI_CR_OFFSET_DS464 0x62 /* 16-bit Control Register */ +#define XSPI_CR_OFFSET_DS570 0x60 #define XSPI_CR_ENABLE 0x02 #define XSPI_CR_MASTER_MODE 0x04@@ -40,8 +97,10 @@ #define XSPI_CR_RXFIFO_RESET 0x40 #define XSPI_CR_MANUAL_SSELECT 0x80 #define XSPI_CR_TRANS_INHIBIT 0x100 +#define XSPI_CR_LSB_FIRST 0x200 -#define XSPI_SR_OFFSET 0x67 /* 8-bit Status Register */ +#define XSPI_SR_OFFSET_DS464 0x67 /* 8-bit Status Register */ +#define XSPI_SR_OFFSET_DS570 0x64 #define XSPI_SR_RX_EMPTY_MASK 0x01 /* Receive FIFO is empty */ #define XSPI_SR_RX_FULL_MASK 0x02 /* Receive FIFO is full */@@ -49,10 +108,13 @@ #define XSPI_SR_TX_FULL_MASK 0x08 /* Transmit FIFO is full */ #define XSPI_SR_MODE_FAULT_MASK 0x10 /* Mode fault error */
drivers/spi/xilinx_spi.c (revision 869) line 117
Quoted 10 lines
drivers/spi/xilinx_spi.c (revision 869) renamed from drivers/spi/xilinx_spi.c (revision 861) +6
-3-#define XSPI_TXD_OFFSET 0x6b /* 8-bit Data Transmit Register */ -#define XSPI_RXD_OFFSET 0x6f /* 8-bit Data Receive Register */ +#define XSPI_TXD_OFFSET_DS464 0x6b /* 8-bit Data Transmit Register */ +#define XSPI_TXD_OFFSET_DS570 0x68 +#define XSPI_RXD_OFFSET_DS464 0x6f /* 8-bit Data Receive Register */ +#define XSPI_RXD_OFFSET_DS570 0x6C -#define XSPI_SSR_OFFSET 0x70 /* 32-bit Slave Select Register */ +#define XSPI_SSR_OFFSET_DS464 0x70 /* 32-bit Slave Select Register */ +#define XSPI_SSR_OFFSET_DS570 0x70
It looks like you need to access the registers on 32 bit boundaries, and the current ppc code happens to do a few 16 and 8 bit acccesses. I haven't looked at the data sheet, but I wouldn't be surprised if the 8 and 16 bit registers can also be cleanly access with 32 bit transfers. In which case if you changed all access to be 32 bit aligned, then your patch could be a good deal simpler, and you wouldn't need to mess about with all the DS464/DS570 stuff.
g.
Signature · 12 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ spi-devel-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/spi-devel-general