xtensa xtfpga SPI controller driver
Subsystems (3)
Max Filippov
maintainercover xtensa xtfpga SPI controller driver
Hello,
this series adds driver for SPI controller used on xtfpga xtensa platform, device tree binding documentation and an entry to MAINTAINERS.
Max Filippov (3):
spi: add xtfpga SPI controller driver
spi/xtensa-xtfpga: add DT binding documentation
MAINTAINERS: add xtfpga platform section
.../devicetree/bindings/spi/spi-xtensa-xtfpga.txt | 9 ++ MAINTAINERS | 6 + drivers/spi/Kconfig | 13 ++ drivers/spi/Makefile | 1 + drivers/spi/spi-xtensa-xtfpga.c | 165 +++++++++++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-xtensa-xtfpga.txt create mode 100644 drivers/spi/spi-xtensa-xtfpga.c
Signature · 1 line
1.8.1.4
Max Filippov
maintainerPATCH 1/3 spi: add xtfpga SPI controller driver
This simple SPI master controller is built into xtfpga bitstreams. It always transfers 16 bit words in SPI mode 0, automatically asserting CS on transfer start and deasserting on end.
--- drivers/spi/Kconfig | 13 ++++ drivers/spi/Makefile | 1 + drivers/spi/spi-xtensa-xtfpga.c | 165 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 drivers/spi/spi-xtensa-xtfpga.c
drivers/spi/Kconfig +13 -0
@@ -520,6 +520,19 @@ config SPI_XILINX Or for the DS570, see "XPS Serial Peripheral Interface (SPI) (v2.00b)" +config SPI_XTENSA_XTFPGA + tristate "Xtensa SPI controller for xtfpga" + depends on XTENSA && XTENSA_PLATFORM_XTFPGA + select SPI_BITBANG + help + SPI driver for xtfpga SPI master controller. + + This simple SPI master controller is built into xtfpga bitstreams + and is used to control daughterboard audio codec. It always transfers + 16 bit words in SPI mode 0, automatically asserting CS on transfer + start and deasserting on end. + + config SPI_NUC900 tristate "Nuvoton NUC900 series SPI" depends on ARCH_W90X900
drivers/spi/Makefile +1 -0
@@ -79,3 +79,4 @@ obj-$(CONFIG_SPI_TOPCLIFF_PCH) += spi-topcliff-pch.o obj-$(CONFIG_SPI_TXX9) += spi-txx9.o obj-$(CONFIG_SPI_XCOMM) += spi-xcomm.o obj-$(CONFIG_SPI_XILINX) += spi-xilinx.o +obj-$(CONFIG_SPI_XTENSA_XTFPGA) += spi-xtensa-xtfpga.o
drivers/spi/spi-xtensa-xtfpga.c new file +165 -0
165 lines not on this page · raw message
Signature · 6 lines
1.8.1.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Brown
maintainerRe: [PATCH 1/3] spi: add xtfpga SPI controller driver
drivers/spi/spi-xtensa-xtfpga.c line 52
Quoted 11 lines · Max Filippov
drivers/spi/spi-xtensa-xtfpga.c new file +11
-0+static inline int xtfpga_spi_wait_busy (struct xtfpga_spi *xspi) +{ +unsigned long timeout = jiffies +msecs_to_jiffies (100 ); +while (xtfpga_spi_read32 (xspi,XTFPGA_SPI_BUSY )) { +if (!time_before (jiffies, timeout)) +return -EBUSY ; +else +cpu_relax (); + } +return 0 ; +}
So we'll busy wait for up to 100ms - that seems like an awfully long time. Perhaps fall back to msleep() if the delay is non-trivial (or just reduce the timeout)? If there are large enough FIFOs dead reckoning a sleep for the expected transfer time might be helpful but it seems like there's no meaningful FIFO.
Quoted 3 lines
+/* Unused: this device controls its only CS automatically,
+ * deactivating it after every 16 bit transfer completion.
+ */
This is too limited to use with most SPI clients, they'll want to be able to transmit more than one word (and the fact that only 16 bit words are supported is also an issue, though that's easy enough to handle for a bitbanging driver - I'd really strongly suggest supporting 8 bits per word as well). Clients are pretty much going to need to use GPIO based chip select, you should make sure that's supported and covered in the binding.
drivers/spi/spi-xtensa-xtfpga.c line 76
Quoted 3 lines
drivers/spi/spi-xtensa-xtfpga.c new file +3
-0+static void xtfpga_spi_chipselect (struct spi_device *spi,int is_on) +{ +}
Omit this since it's empty.
Max Filippov
maintainerRe: [PATCH 1/3] spi: add xtfpga SPI controller driver
Quoted 17 lines · Mark Brown
drivers/spi/spi-xtensa-xtfpga.c line 52
Quoted 11 lines · Max Filippov
drivers/spi/spi-xtensa-xtfpga.c new file +11
-0+static inline int xtfpga_spi_wait_busy (struct xtfpga_spi *xspi) +{ +unsigned long timeout = jiffies +msecs_to_jiffies (100 ); +while (xtfpga_spi_read32 (xspi,XTFPGA_SPI_BUSY )) { +if (!time_before (jiffies, timeout)) +return -EBUSY ; +else +cpu_relax (); + } +return 0 ; +}So we'll busy wait for up to 100ms - that seems like an awfully long time. Perhaps fall back to
msleep()if the delay is non-trivial (or just reduce the timeout)?
The timeout is here for the unlikely case everything went wrong. Normally transfers get completed in about 10 useconds on 50 MHz hardware, it doesn't seem worth msleeping here. I put the timeout here just because otherwise infinite loop polling the device register looks scary.
Quoted 3 lines
If there are large enough FIFOs dead
reckoning a sleep for the expected transfer time might be helpful but it seems like there's no meaningful FIFO.
Right, there's no FIFO in that device.
Quoted 11 lines
Quoted 3 lines
+/* Unused: this device controls its only CS automatically,
+ * deactivating it after every 16 bit transfer completion.
+ */This is too limited to use with most SPI clients, they'll want to be able to transmit more than one word (and the fact that only 16 bit words are supported is also an issue, though that's easy enough to handle for a bitbanging driver - I'd really strongly suggest supporting 8 bits per word as well). Clients are pretty much going to need to use GPIO based chip select, you should make sure that's supported and covered in the binding.
There's no hardware for that. This device is really dumb, it is specifically suited to control TLV320AIC23 which expects exactly 16 bit words, SPI mode 0.
Quoted 5 lines
drivers/spi/spi-xtensa-xtfpga.c line 76
Quoted 3 lines
drivers/spi/spi-xtensa-xtfpga.c new file +3
-0+static void xtfpga_spi_chipselect (struct spi_device *spi,int is_on) +{ +}Omit this since it's empty.
The bitbang side doesn't like when this callback is NULL and returns -EINVAL from spi_bitbang_start.
Signature · 2 lines
Thanks. -- Max
Mark Brown
maintainerRe: [PATCH 1/3] spi: add xtfpga SPI controller driver
Quoted 11 lines · Max Filippov
Quoted 9 lines · Mark Brown
Quoted 7 lines · Max Filippov
drivers/spi/spi-xtensa-xtfpga.c new file +7
-0+unsigned long timeout = jiffies +msecs_to_jiffies (100 ); +while (xtfpga_spi_read32 (xspi,XTFPGA_SPI_BUSY )) { +if (!time_before (jiffies, timeout)) +return -EBUSY ; +else +cpu_relax (); + }
Quoted 8 lines
Quoted 3 lines
So we'll busy wait for up to 100ms - that seems like an awfully long time. Perhaps fall back to
msleep()if the delay is non-trivial (or just reduce the timeout)?The timeout is here for the unlikely case everything went wrong. Normally transfers get completed in about 10 useconds on 50 MHz hardware, it doesn't seem worth msleeping here. I put the timeout here just because otherwise infinite loop polling the device register looks scary.
I appreciate that but even with 5MHz that's three orders of magnitude longer busy waiting in the error case than the operation is expected to take. If you must wait for that long busy wait for a bit then start sleeping.
Quoted 13 lines
Quoted 5 lines
Quoted 4 lines
+/* Unused: this device controls its only CS automatically,
+ * deactivating it after every 16 bit transfer completion.
+ */Quoted 7 lines
This is too limited to use with most SPI clients, they'll want to be able to transmit more than one word (and the fact that only 16 bit words are supported is also an issue, though that's easy enough to handle for a bitbanging driver - I'd really strongly suggest supporting 8 bits per word as well). Clients are pretty much going to need to use GPIO based chip select, you should make sure that's supported and covered in the binding.
Quoted 3 lines
There's no hardware for that. This device is really dumb, it is specifically suited to control TLV320AIC23 which expects exactly 16 bit words, SPI mode 0.
This driver is not actually compatible with the tlv320aic23 driver since it needs 8 bit words, you need to at least support that. You don't need hardware in the controller to support a GPIO chip select, the whole point is that the controller chip select isn't wired up and a GPIO is used instead.
Quoted 8 lines
Quoted 5 lines
drivers/spi/spi-xtensa-xtfpga.c line 76
Quoted 3 lines
drivers/spi/spi-xtensa-xtfpga.c new file +3
-0+static void xtfpga_spi_chipselect (struct spi_device *spi,int is_on) +{ +}Omit this since it's empty.
The bitbang side doesn't like when this callback is NULL and returns
-EINVALfromspi_bitbang_start.
So fix that, but really it's trying to tell you that the hardware is far too limited to work with many things.
Max Filippov
maintainerRe: [PATCH 1/3] spi: add xtfpga SPI controller driver
Quoted 21 lines · Mark Brown
Quoted 11 lines · Max Filippov
Quoted 9 lines · Mark Brown
Quoted 7 lines · Max Filippov
drivers/spi/spi-xtensa-xtfpga.c new file +7
-0+unsigned long timeout = jiffies +msecs_to_jiffies (100 ); +while (xtfpga_spi_read32 (xspi,XTFPGA_SPI_BUSY )) { +if (!time_before (jiffies, timeout)) +return -EBUSY ; +else +cpu_relax (); + }Quoted 8 lines
Quoted 3 lines
So we'll busy wait for up to 100ms - that seems like an awfully long time. Perhaps fall back to
msleep()if the delay is non-trivial (or just reduce the timeout)?The timeout is here for the unlikely case everything went wrong. Normally transfers get completed in about 10 useconds on 50 MHz hardware, it doesn't seem worth msleeping here. I put the timeout here just because otherwise infinite loop polling the device register looks scary.
Quoted 4 lines
I appreciate that but even with 5MHz that's three orders of magnitude longer busy waiting in the error case than the operation is expected to take. If you must wait for that long busy wait for a bit then start sleeping.
Ok, I'll fix that.
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
+/* Unused: this device controls its only CS automatically,
+ * deactivating it after every 16 bit transfer completion.
+ */This is too limited to use with most SPI clients, they'll want to be able to transmit more than one word (and the fact that only 16 bit words are supported is also an issue, though that's easy enough to handle for a bitbanging driver - I'd really strongly suggest supporting 8 bits per word as well). Clients are pretty much going to need to use GPIO based chip select, you should make sure that's supported and covered in the binding.
Quoted 6 lines
Quoted 3 lines
There's no hardware for that. This device is really dumb, it is specifically suited to control TLV320AIC23 which expects exactly 16 bit words, SPI mode 0.
This driver is not actually compatible with the tlv320aic23 driver since it needs 8 bit words, you need to at least support that. You don't need
That's strange, because the codec datasheet says the following (section 3.1.1):
A control word consists of 16 bits, starting with the MSB. The data bits are latched on the rising edge of SCLK. A rising edge on CS after the 16th rising clock edge latches the data word into the AIC (see Figure 3-1).
And tlv320aic23 has the following regmap:
const struct regmap_config tlv320aic23_regmap = {
.reg_bits = 7,
.val_bits = 9,and its SPI interface accordingly does the following in .probe:
spi->bits_per_word = 16
spi->mode = SPI_MODE_0;
ret = spi_setup(spi);Quoted 3 lines
hardware in the controller to support a GPIO chip select, the whole point is that the controller chip select isn't wired up and a GPIO is used instead.
Actually it's not GPIO. The controller asserts CS line once we set the start bit while the busy bit is cleared and deasserts it after 16 SCK pulses.
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
drivers/spi/spi-xtensa-xtfpga.c line 76
Quoted 3 lines
drivers/spi/spi-xtensa-xtfpga.c new file +3
-0+static void xtfpga_spi_chipselect (struct spi_device *spi,int is_on) +{ +}Omit this since it's empty.
The bitbang side doesn't like when this callback is NULL and returns
-EINVALfromspi_bitbang_start.So fix that, but really it's trying to tell you that the hardware is far too limited to work with many things.
Ok. It's not designed to work with many things. Should I just move this driver to the rest of the platform code under arch/xtensa/platform/xtfpga?
Signature · 6 lines
Thanks. -- Max -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Brown
maintainerRe: [PATCH 1/3] spi: add xtfpga SPI controller driver
Quoted 12 lines · Max Filippov
Quoted 2 lines · Mark Brown
This driver is not actually compatible with the tlv320aic23 driver since it needs 8 bit words, you need to at least support that. You don't need
That's strange, because the codec datasheet says the following (section 3.1.1):
A control word consists of 16 bits, starting with the MSB. The data bits are latched on the rising edge of SCLK. A rising edge on CS after the 16th rising clock edge latches the data word into the AIC (see Figure 3-1).
Quoted 5 lines
And tlv320aic23 has the following regmap:
const struct regmap_config tlv320aic23_regmap = { .reg_bits = 7, .val_bits = 9,
Yes, and regmap will format that itself for transmission in 8 bit words so you don't want the SPI controller to also do byte swapping.
Quoted 5 lines
and its SPI interface accordingly does the following in .probe:
spi->bits_per_word = 16 spi->mode = SPI_MODE_0; ret = spi_setup(spi);
That's buggy, drivers should never configure anything more than 8 bits per word with regmap.
Quoted 7 lines
Quoted 3 lines
hardware in the controller to support a GPIO chip select, the whole point is that the controller chip select isn't wired up and a GPIO is used instead.
Actually it's not GPIO. The controller asserts CS line once we set the start bit while the busy bit is cleared and deasserts it after 16 SCK pulses.
You're missing the point. The controller chip select line can do what it likes, it's not connected to the target device if a GPIO is being used.
Quoted 5 lines
Quoted 2 lines
So fix that, but really it's trying to tell you that the hardware is far too limited to work with many things.
Ok. It's not designed to work with many things. Should I just move this driver to the rest of the platform code under
arch/xtensa/platform/xtfpga?
No, not if you intend to use generic drivers with it.
Max Filippov
maintainerRe: [PATCH 1/3] spi: add xtfpga SPI controller driver
Quoted 22 lines · Mark Brown
Quoted 12 lines · Max Filippov
Quoted 2 lines · Mark Brown
This driver is not actually compatible with the tlv320aic23 driver since it needs 8 bit words, you need to at least support that. You don't need
That's strange, because the codec datasheet says the following (section 3.1.1):
A control word consists of 16 bits, starting with the MSB. The data bits are latched on the rising edge of SCLK. A rising edge on CS after the 16th rising clock edge latches the data word into the AIC (see Figure 3-1).
Quoted 5 lines
And tlv320aic23 has the following regmap:
const struct regmap_config tlv320aic23_regmap = { .reg_bits = 7, .val_bits = 9,Yes, and regmap will format that itself for transmission in 8 bit words so you don't want the SPI controller to also do byte swapping.
Quoted 8 lines
Quoted 5 lines
and its SPI interface accordingly does the following in .probe:
spi->bits_per_word = 16 spi->mode = SPI_MODE_0; ret = spi_setup(spi);That's buggy, drivers should never configure anything more than 8 bits per word with regmap.
Ok, so the driver should allow for 8 bit transfers and regmap will arrange transfers as 8-bit pairs, making CS to be asserted for 16 bits, right?
Hmmm... I see the only way to support that with that hardware: advertise 8 bit support, buffer bytes up to 16 bits, send 16 bit words on CS deassertion request, log violations verbosely. Other ideas?
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
hardware in the controller to support a GPIO chip select, the whole point is that the controller chip select isn't wired up and a GPIO is used instead.
Actually it's not GPIO. The controller asserts CS line once we set the start bit while the busy bit is cleared and deasserts it after 16 SCK pulses.
You're missing the point. The controller chip select line can do what it likes, it's not connected to the target device if a GPIO is being used.
In my case SPI controller is wired directly to the codec with three
wires: SDIN, SCLK and CS. There are no registers that can control either of these wires independently of others.
Signature · 6 lines
Thanks. -- Max -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Brown
maintainerRe: [PATCH 1/3] spi: add xtfpga SPI controller driver
Quoted 11 lines · Max Filippov
Quoted 2 lines · Mark Brown
That's buggy, drivers should never configure anything more than 8 bits per word with regmap.
Ok, so the driver should allow for 8 bit transfers and regmap will arrange transfers as 8-bit pairs, making CS to be asserted for 16 bits, right?
Hmmm... I see the only way to support that with that hardware: advertise 8 bit support, buffer bytes up to 16 bits, send 16 bit words on CS deassertion request, log violations verbosely. Other ideas?
That's about it. Like I keep saying for any sort of generic use you really want to support 8 bits per word.
Quoted 7 lines
Quoted 3 lines
You're missing the point. The controller chip select line can do what it likes, it's not connected to the target device if a GPIO is being used.
In my case SPI controller is wired directly to the codec with three
wires: SDIN, SCLK and CS. There are no registers that can control either of these wires independently of others.
Right, but other users are likely to exist and the framework has support for this so it's not much work to support.
Mark Brown
maintainerRe: [PATCH 1/3] spi: add xtfpga SPI controller driver
In reply to Max FilippovQuoted 11 lines · Max Filippov
And tlv320aic23 has the following regmap:
const struct regmap_config tlv320aic23_regmap = { .reg_bits = 7, .val_bits = 9,and its SPI interface accordingly does the following in .probe:
spi->bits_per_word = 16 spi->mode = SPI_MODE_0; ret = spi_setup(spi);
So I just looked again - the SPI code isn't in mainline, there must be some out of tree patches here that can't have been tested since the driver was converted to regmap (or the byte swapping you're doing in the controller is buggy for 16 bits per word).
Max Filippov
maintainerRe: [PATCH 1/3] spi: add xtfpga SPI controller driver
Quoted 10 lines · Mark Brown
Quoted 7 lines · Max Filippov
And tlv320aic23 has the following regmap:
const struct regmap_config tlv320aic23_regmap = { .reg_bits = 7, .val_bits = 9,and its SPI interface accordingly does the following in .probe:
Quoted 8 lines
Quoted 3 lines
spi->bits_per_word = 16 spi->mode = SPI_MODE_0; ret = spi_setup(spi);So I just looked again - the SPI code isn't in mainline, there must be some out of tree patches here that can't have been tested since the driver was converted to regmap (or the byte swapping you're doing in the controller is buggy for 16 bits per word).
I'm successfully running this driver with the patches in your ASoC tree branch topic/tlv320aic23.
Signature · 2 lines
Thanks. -- Max
Mark Brown
maintainerRe: [PATCH 1/3] spi: add xtfpga SPI controller driver
Quoted 9 lines · Max Filippov
Quoted 4 lines · Mark Brown
So I just looked again - the SPI code isn't in mainline, there must be some out of tree patches here that can't have been tested since the driver was converted to regmap (or the byte swapping you're doing in the controller is buggy for 16 bits per word).
I'm successfully running this driver with the patches in your ASoC tree branch topic/tlv320aic23.
Ah, I missed that during review - the driver shouldn't be forcing 16 bits per word, any swapping that's needed should be being done in the regmap API. Though based on the discussion of the SPI driver it seems like this may be compensating for an unwanted byte swap there.
Max Filippov
maintainerPATCH 2/3 spi/xtensa-xtfpga: add DT binding documentation
In reply to Max Filippov--- Documentation/devicetree/bindings/spi/spi-xtensa-xtfpga.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-xtensa-xtfpga.txt
Documentation/devicetree/bindings/spi/spi-xtensa-xtfpga.txt new file +9 -0
@@ -0,0 +1,9 @@ +Cadence Xtensa XTFPGA platform SPI controller. + +This simple SPI master controller is built into xtfpga bitstreams and is used +to control daughterboard audio codec. + +Required properties: +- compatible: should be "cdns,xtfpga-spi". +- reg: physical base address of the controller and length of memory mapped + region.
Signature · 1 line
1.8.1.4
Max Filippov
maintainerPATCH 3/3 MAINTAINERS: add xtfpga platform section
In reply to Max FilippovThis section will list xtfpga platform-specific drivers.
--- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -9768,6 +9768,12 @@ L: [email protected] S: Maintained F: drivers/tty/serial/uartlite.c +XTENSA XTFPGA PLATFORM SUPPORT +M: Max Filippov <[email protected]> +L: linux-xtensa-PjhNF2WwrV/[email protected] +S: Maintained +F: drivers/spi/spi-xtensa-xtfpga.c + YAM DRIVER FOR AX.25 M: Jean-Paul Roubelat <[email protected]> L: [email protected]
Signature · 6 lines
1.8.1.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html