SPI: xilinx_spi: Added platform driver and support for DS570
Subsystems (2)
PATCH RESEND 1/1 SPI: xilinx_spi: Added platform driver and support for DS570
This patch splits xilinx_spi into three parts, an OF and a platform driver and generic part.
The generic part now also works on X86 and also supports 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 +216 -200
615 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/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/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 */ +
This appears to be a ppc thing, so let's cc that list. Let's also cc the driver's author and other contributors. Please cc these people on future versions of the patch also.
Quoted 9 lines · On Mon, 15 Jun 2009 17:17:54 +0200 Richard R__jfors…
This patch splits
xilinx_spiinto three parts, an OF and a platform driver and generic part.The generic part now also works on X86 and also supports the Xilinx SPI IP DS570
...
drivers/spi/xilinx_spi.c line 52
Quoted 9 lines
drivers/spi/xilinx_spi.c +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
Why do we need these?
Quoted 19 lines
drivers/spi/xilinx_spi.c +19
-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 line 82
Quoted 10 lines
drivers/spi/xilinx_spi.c +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)
I'm seeing no reason why these had to be implemented as macros. They're ugly, add considerable code bloat and, because they evaluate their args multiple times they will fail if passed as expression with side-effects.
I suggest that they be reimplemented as lower-case, uninlined C functions.
Quoted 5 lines · Richard Röjfors
This patch splits
xilinx_spiinto three parts, an OF and a platform driver and generic part.The generic part now also works on X86 and also supports the Xilinx SPI IP DS570
Your Kconfig still mentions only DS464.
Is there any reason the platform driver shouldn't also build on x86? Surely *any* system should be able to talk to an FPGA which exports this register interface?
Quoted 2 lines
Signed-off-by Richard Röjfors <[email protected]>
I'll second Andrew's comments. Also, for my review, it'd be better to split OF bits out from the rest ... but maybe that's not practical given the previous xilinx_spi code. At least future patches will have a more-sane structure to build on.
drivers/spi/Kconfig line 227
Quoted 5 lines
drivers/spi/Kconfig +5
-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.
If it's IP, then why is it dependent on VIRTEX? Surely the same IP should work on Spartan etc. I'd think just depending on something like OF should suffice.
drivers/spi/Kconfig line 234
Quoted 7 lines
drivers/spi/Kconfig +7
-0+ + 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
This should go first in the Kconfig, so that you don't goof up the dependency display ... the OF bits depend on it.
drivers/spi/xilinx_spi_of.c line 82
Quoted 8 lines
drivers/spi/xilinx_spi_of.c +3
-0@@ -0,0 +1,123 @@ + +/* work with hotplug and coldplug */ +MODULE_ALIAS ("platform:" XILINX_SPI_NAME );
This is clearly inappropriate for a file with an OpenFirmware driver. For that matter, it's not needed with platform devices any more either; so take it out of your platform driver code too.
include/linux/spi/xilinx_spi.h line 9
Quoted 12 lines
include/linux/spi/xilinx_spi.h +9
-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;
Not needed on the platform_bus; pdev->id suffices. This is specific to the OF glue, yes?
include/linux/spi/xilinx_spi.h line 12
Quoted 3 lines
include/linux/spi/xilinx_spi.h +3
-0+u16 num_chipselect; +u8 model; +u8 bits_per_word;
Synthesis data that's not explicitly visible in
the IP registers, I guess.
include/linux/spi/xilinx_spi.h line 15
Quoted 3 lines
include/linux/spi/xilinx_spi.h +3
-0+/* devices to add to the bus when the host is up */ +struct spi_board_info *devices; +u8 num_devices;
This is duplicating functionality in the SPI core code. That's not really the way to fly. That may also be specific to the OF glue.
include/linux/spi/xilinx_spi.h line 19
Quoted 6 lines
include/linux/spi/xilinx_spi.h +4
-0+}; + +#endif /* __LINUX_SPI_XILINX_SPI_H */ +
------------------------------------------------------------------------------
Quoted 8 lines · David Brownell
Quoted 5 lines · Richard Röjfors
This patch splits
xilinx_spiinto three parts, an OF and a platform driver and generic part.The generic part now also works on X86 and also supports the Xilinx SPI IP DS570
Your
Kconfigstill mentions only DS464.
Correct, will update.
Quoted 3 lines
Is there any reason the platform driver shouldn't also build on x86? Surely *any* system should be able to talk to an FPGA which exports this register interface?
The platform _builds_ on X86, previously the driver only built on PPC.
That's one of my updates.
Quoted 6 lines
Quoted 1 line
Signed-off-by Richard Röjfors <[email protected]>I'll second Andrew's comments. Also, for my review, it'd be better to split OF bits out from the rest ... but maybe that's not practical given the previous
xilinx_spicode. At least future patches will have a more-sane structure to build on.
Ah I will generate three patches in the future. (generic, platform, of).
Quoted 9 lines
drivers/spi/Kconfig line 227
Quoted 5 lines
drivers/spi/Kconfig +5
-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.If it's IP, then why is it dependent on VIRTEX? Surely the same IP should work on Spartan etc. I'd think just depending on something like OF should suffice.
Actually I left the OF part with the same dependencies as the whole driver had before.
We run the IP on a spartan, so you are completely right :)
Will update to OF-something.
Quoted 10 lines
drivers/spi/Kconfig line 234
Quoted 7 lines
drivers/spi/Kconfig +7
-0+ + 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_XILINXThis should go first in the
Kconfig, so that you don't goof up the dependency display ... the OF bits depend on it.
The OF parts only depend on SPI_XILINX, not SPI_XILINX_PLTFM. But I can change the order anyway(?)
Quoted 5 lines
Quoted 4 lines
drivers/spi/xilinx_spi_of.c +0
-0@@ -0,0 +1,123 @@
Quoted 7 lines
drivers/spi/xilinx_spi_of.c line 82
Quoted 3 lines
drivers/spi/xilinx_spi_of.c +3
-0+ +/* work with hotplug and coldplug */ +MODULE_ALIAS ("platform:" XILINX_SPI_NAME );This is clearly inappropriate for a file with an OpenFirmware driver. For that matter, it's not needed with platform devices any more either; so take it out of your platform driver code too.
Oops, my mistake, will remove it.
Quoted 7 lines
Quoted 7 lines
include/linux/spi/xilinx_spi.h +4
-0@@ -0,0 +1,19 @@ +#ifndef __LINUX_SPI_XILINX_SPI_H +#define __LINUX_SPI_XILINX_SPI_H + +#define XILINX_SPI_MODEL_DS464 0
Quoted 8 lines
include/linux/spi/xilinx_spi.h line 9
Quoted 5 lines
include/linux/spi/xilinx_spi.h +5
-0+#define XILINX_SPI_MODEL_DS570 1 + +/* SPI Controller IP */ +struct xspi_platform_data { +s16 bus_num;Not needed on the
platform_bus;pdev->idsuffices. This is specific to the OF glue, yes?
Good point, it can be removed, and pdev->id used instead.
Quoted 6 lines
include/linux/spi/xilinx_spi.h line 12
Quoted 3 lines
include/linux/spi/xilinx_spi.h +3
-0+u16 num_chipselect; +u8 model; +u8 bits_per_word;Synthesis data that's not explicitly visible in
the IP registers, I guess.
Exactly, its built into the IP and can not be read.
Quoted 6 lines
include/linux/spi/xilinx_spi.h line 15
Quoted 3 lines
include/linux/spi/xilinx_spi.h +3
-0+/* devices to add to the bus when the host is up */ +struct spi_board_info *devices; +u8 num_devices;This is duplicating functionality in the SPI core code. That's not really the way to fly.
I have discussed the same problem in the I2C list.
We have a PCIe device which is a MFD (multifunction device).
Several MFD devices could be connected to a standard PC -> we don't know the bus numbers in advance, and there could be several PCIe devices connected. Which mean the we can not use spi_register_board_info.
We can not call spi_add_device from the MFD because when it's probed the drivers for the SPI bus might not be available.
So the solution in the I2C case was to add this into the driver and if this tend to be a generic problem some generic solution might be implemented.
So I would like to have the same thing in here.
--Richard
Quoted 11 lines · Richard Röjfors
Quoted 8 lines · David Brownell
Quoted 5 lines · Richard Röjfors
This patch splits
xilinx_spiinto three parts, an OF and a platform driver and generic part.The generic part now also works on X86 and also supports the Xilinx SPI IP DS570
Your
Kconfigstill mentions only DS464.Correct, will update.
Just checking -- you didn't send an update yet, right?
Quoted 10 lines
Quoted 9 lines
drivers/spi/Kconfig line 234
Quoted 6 lines
drivers/spi/Kconfig +6
-0+ 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_XILINXThis should go first in the
Kconfig, so that you don't goof up the dependency display ... the OF bits depend on it.
Quoted 2 lines
The OF parts only depend on
SPI_XILINX, notSPI_XILINX_PLTFM. But I can change the order anyway(?)
Maybe I misread something. Make sure the Kconfig doesn't goof.
Quoted 7 lines
Quoted 6 lines
include/linux/spi/xilinx_spi.h line 15
Quoted 3 lines
include/linux/spi/xilinx_spi.h +3
-0+/* devices to add to the bus when the host is up */ +struct spi_board_info *devices; +u8 num_devices;This is duplicating functionality in the SPI core code. That's not really the way to fly.
Quoted 8 lines
I have discussed the same problem in the I2C list.
We have a PCIe device which is a MFD (multifunction device).
Several MFD devices could be connected to a standard PC -> we don't know the bus numbers in advance, and there could be several PCIe devices connected. Which mean the we can not use
spi_register_board_info.
You could, actually, given metadata about those devices. That's one of the things ACPI does -- in a way that many of us find ugly! -- and the "device tree" some PPCs use.
Quoted 2 lines
We can not call
spi_add_devicefrom the MFD because when it's probed the drivers for the SPI bus might not be available.
And you can't call spi_register_board_info() there since the init section is gone.
Quoted 5 lines
So the solution in the I2C case was to add this into the driver and if this tend to be a generic problem some generic solution might be implemented.
So I would like to have the same thing in here.
What I've done in such cases is make sure the bus adapter driver (in this case, for the spi_master) can issue some callback to code which makes spi_add_device(), or similar, calls.
But if your initialization doesn't have that sort of clean structure, it's probably kind of awkward to add it just now... :(
- Dave
Quoted 6 lines · David Brownell
Quoted 5 lines · Richard Röjfors
Quoted 4 lines · David Brownell
Quoted 3 lines · Richard Röjfors
This patch splits
xilinx_spiinto three parts, an OF and a platform driver and generic part.
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
The generic part now also works on X86 and also supports the Xilinx SPI IP DS570
Your
Kconfigstill mentions only DS464.Correct, will update.
Just checking -- you didn't send an update yet, right?
Nope not yet. I will send it within the next weeks, I'm actually on vacation.
--Richard