spi: aspeed: generic spi master
Subsystems (3)
cover spi: aspeed: generic spi master
Some time ago we mentioned we are interested in a generic spi master for use with some sensors that were not flash chips; that was some time ago so I do not expect anyone to remember. Anyway, I implemented an initial version.
I stole the *read_from_ahb/*write_to_ahb methods for the spi nor driver; so we should consider, at the very least putting those in a common library, but I think we could probably share even more code between the implementations: the m25p80 mtd spi driver provides an mtd interface given a spi master; so we might want to consider rolling the spi-nor and spi-master into the same driver.
I am especially looking for feedback on how I did the multiple io port ranges; currently, I require two address ranges to be given, in addition to the address ranges for the control registers, one for each chip select. Obviously, this does not completely work for the fmc spi master, as it has three chip selects and three coresponding io port regions. I was thinking that I should not require all the io port regions to be specified and then just limit the available number of chip selects, but that is kind of messy for someone who wants to use the third chip select, when there is nothing on the second chip select.
Not yet implmented:
- DMA support: we are not interested in it at this time and it probably does not belong in an initial version anyway, but I could implement it in a future version if someone really wants it.
- AST24XX support: we are not using the chip and do not have any copies to test on, so I have not implmented anything for it; again, I do not mind adding support for this, but I will probably need someone's help.
- clock interface: currently, we do not have an interface for the AHB clock, so there is no clock interface for the spi master to use; the current spi-nor appears to be in the same place. I do not think we have much control over this clock; even so, should we implement a fixed frequency clock as we have done for the lower speed peripherals?
I have tested this on the AST2500 evaluation board.
Brendan Higgins (2):
spi: aspeed: added generic spi master for Aspeed
spi: aspeed: added device tree documentation
.../devicetree/bindings/spi/spi-aspeed.txt | 33 ++ drivers/spi/Kconfig | 12 + drivers/spi/Makefile | 1 + drivers/spi/spi-aspeed.c | 582 +++++++++++++++++++++ 4 files changed, 628 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-aspeed.txt create mode 100644 drivers/spi/spi-aspeed.c
Signature · 1 line
2.8.0.rc3.226.g39d4020
RFC 1/2 spi: aspeed: added generic spi master for Aspeed
Added initial generic spi master support to the Aspeed 25XX SoCs.
--- drivers/spi/Kconfig | 12 + drivers/spi/Makefile | 1 + drivers/spi/spi-aspeed.c | 582 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 595 insertions(+) create mode 100644 drivers/spi/spi-aspeed.c
drivers/spi/Kconfig +12 -0
@@ -59,6 +59,18 @@ config SPI_ALTERA help This is the driver for the Altera SPI Controller. +config SPI_ASPEED + tristate "Aspeed AST24XX/AST25XX SPI controller driver" + depends on ARCH_ASPEED + help + This enables support for the SPI controller on the Aspeed AST25XX SoCs + as a generic SPI master. + + The Aspeed AST25XX SoCs have three SPI controllers intended as SPI + flash controllers; nevertheless, they are flexible enough to support + the Linux SPI master framework and are physically capable of + supporting some other SPI devices. + config SPI_ATH79 tristate "Atheros AR71XX/AR724X/AR913X SPI controller driver" depends on ATH79 && GPIOLIB
drivers/spi/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-$(CONFIG_SPI_LOOPBACK_TEST) += spi-loopback-test.o # SPI master controller drivers (bus) obj-$(CONFIG_SPI_ALTERA) += spi-altera.o +obj-$(CONFIG_SPI_ASPEED) += spi-aspeed.o obj-$(CONFIG_SPI_ATMEL) += spi-atmel.o obj-$(CONFIG_SPI_ATH79) += spi-ath79.o obj-$(CONFIG_SPI_AU1550) += spi-au1550.o
drivers/spi/spi-aspeed.c new file +582 -0
582 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
Joel Stanley
maintainerRe: [RFC linux 1/2] spi: aspeed: added generic spi master for Aspeed
Hi Brendan,
Quoted 1 line · Brendan Higgins
Added initial generic spi master support to the Aspeed 25XX SoCs.
Can you expand on what you mean by "initial"?
I've got a few comments below. Once you've fixed them I suggest that you send this directly upstream from here, ccing Cedric and myself.
Quoted 14 lines
Signed-off-by Brendan Higgins <[email protected]>--- drivers/spi/Kconfig | 12 + drivers/spi/Makefile | 1 + drivers/spi/spi-aspeed.c | 582 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 595 insertions(+) create mode 100644 drivers/spi/spi-aspeed.cdrivers/spi/Kconfig +0
-0
drivers/spi/Kconfig config SPI_ALTERA · line 62
Quoted 4 lines
drivers/spi/Kconfig +1
-0@@ -59,6 +59,18 @@ config SPI_ALTERA help This is the driver for the Altera SPI Controller. +config SPI_ASPEED
This is currently taken by the SPI NOR driver. We may need to come up with a different name.
drivers/spi/Kconfig config SPI_ALTERA · line 64
Quoted 2 lines
drivers/spi/Kconfig +2
-0+ tristate "Aspeed AST24XX/AST25XX SPI controller driver" + depends on ARCH_ASPEED
or COMPILE_TEST.
drivers/spi/Kconfig config SPI_ALTERA · line 72
Quoted 8 lines
drivers/spi/Kconfig +8
-0+ help + This enables support for the SPI controller on the Aspeed AST25XX SoCs + as a generic SPI master. + + The Aspeed AST25XX SoCs have three SPI controllers intended as SPI + flash controllers; nevertheless, they are flexible enough to support + the Linux SPI master framework and are physically capable of + supporting some other SPI devices.
This is worth putting in the commit message too.
drivers/spi/spi-aspeed.c
Quoted 22 lines
drivers/spi/Kconfig +1
-0+ config SPI_ATH79 tristate "Atheros AR71XX/AR724X/AR913X SPI controller driver" depends on ATH79 && GPIOLIBdrivers/spi/Makefile +1
-0@@ -12,6 +12,7 @@ obj-$(CONFIG_SPI_LOOPBACK_TEST) += spi-loopback-test.o # SPI master controller drivers (bus) obj-$(CONFIG_SPI_ALTERA) += spi-altera.o +obj-$(CONFIG_SPI_ASPEED) += spi-aspeed.o obj-$(CONFIG_SPI_ATMEL) += spi-atmel.o obj-$(CONFIG_SPI_ATH79) += spi-ath79.o obj-$(CONFIG_SPI_AU1550) += spi-au1550.odrivers/spi/spi-aspeed.c new file +0
-0@@ -0,0 +1,582 @@
You must include a copyright header in each file.
drivers/spi/spi-aspeed.c line 65
Quoted 4 lines
drivers/spi/spi-aspeed.c new file +4
-0+* TODO: This is taken from drivers/mtd/spi-nor/aspeed-smc.c we should discuss +* sharing code between the two implementations. It appears that there is a +* spi_device implementation of a spi_nor device, so it probably makes sense to +* just move the entire non-dma implementation here.
I've added Cedric so you can discuss this.
The defines above could be shared as well.
Quoted 8 lines
drivers/spi/spi-aspeed.c new file +7
-0+* +* In user mode all data bytes read or written to the chip decode address +* range are transferred to or from the SPI bus. The range is treated as a +* fifo of arbitratry 1, 2, or 4 byte width but each write has to be aligned +* to its size. The address within the multiple 8kB range is ignored when +* sending bytes to the SPI bus. +if (divider > 16) {
drivers/spi/spi-aspeed.c
Quoted 10 lines
drivers/spi/spi-aspeed.c new file +10
-0+WARN_ONCE (true, +"device requested clock speed, %u, less than minimum clock speed, %u.\n" , + requested_speed, base_speed /16 ); + divider =16 ; + } + +if (divider %2 ==0 ) +return (16 - divider) /2 ; +else +return 8 + (15 - divider) /2 ;
I think these could be collapsed into the one line.
Quoted 13 lines
drivers/spi/spi-aspeed.c new file +13
-0+static int aspeed_spi_probe (struct platform_device *pdev) +{ +struct aspeed_spi_master *aspeed_spi_master; +struct spi_master *spi_master; +struct aspeed_spi_bus *bus; +struct resource *res; +int irq, ret =0 ; + + spi_master =spi_alloc_master (&pdev->dev, +sizeof (struct aspeed_spi_master )); +if (!spi_master) +return -ENOMEM ; + aspeed_spi_master =spi_master_get_devdata (spi_master);
drivers/spi/spi-aspeed.c line 439
Quoted 10 lines
drivers/spi/spi-aspeed.c new file +10
-0+platform_set_drvdata (pdev, spi_master); + + aspeed_spi_master->dev = &pdev->dev; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"could not get register memory.\n" ); + ret = -ENOMEM ; + goto err_out; + }
The common pattern is to let the ioremap call error check for you. Check out the documentation for devm_ioremap_resource in lib/devres.c.
drivers/spi/spi-aspeed.c line 442
Quoted 3 lines
drivers/spi/spi-aspeed.c new file +3
-0+ aspeed_spi_master->base =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (aspeed_spi_master->base)) { +dev_err (&pdev->dev,"could not ioremap register memory.\n" );
Drop the dev_err.
drivers/spi/spi-aspeed.c line 515
Quoted 12 lines
drivers/spi/spi-aspeed.c new file +11
-0+ ret =PTR_ERR (aspeed_spi_master->base); + goto err_out; + } + + spi_master->num_chipselect =ASPEED_SPI_BUS_NUM ; +/* TODO: Should also be able to support 2 bit transfers. */ + spi_master->mode_bits =SPI_MODE_0 |SPI_MODE_3 |SPI_LSB_FIRST ; + spi_master->bits_per_word_mask =SPI_BPW_MASK (8 ); +/* TODO: This is just the clock speed of the AHB; should we make a fixed +* frequency clock for the AHB and use that here? +*/
Yeah we should.
I have a driver for creating struct clks for all of our clocks that I need to finish. For now we can create fixed-clocks in the device tree and wire them up to the drivers.
Quoted 9 lines
drivers/spi/spi-aspeed.c new file +9
-0+ spi_master->max_speed_hz =100000000 ; + spi_master->min_speed_hz = spi_master->max_speed_hz /16 ; + spi_master->flags =SPI_MASTER_HALF_DUPLEX ; + + spi_master->max_transfer_size = aspeed_spi_max_transfer_size; + spi_master->set_cs = aspeed_spi_set_cs; + spi_master->transfer_one = aspeed_spi_transfer_one; + spi_master->dev.of_node = pdev->dev.of_node; +
RFC 2/2 spi: aspeed: added device tree documentation
In reply to Brendan HigginsAdded device tree binding documentation for Aspeed AST25XX SoC SPI driver.
--- .../devicetree/bindings/spi/spi-aspeed.txt | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-aspeed.txt
Documentation/devicetree/bindings/spi/spi-aspeed.txt new file +33 -0
@@ -0,0 +1,33 @@ +Device tree configuration for the generic Aspeed AST25XX SoC SPI controllers. + +Required Properties: + - #address-cells : should be 1 + - #size-cells : should be 0 + - compatible : should be "aspeed,ast2500-spi" + - reg : address ranges for the control registers + and IO ports. There is one IO port window + for each chip select. + - interrupts : interrupt number + +Example: + + spi1: spi@1e630000 { + compatible = "aspeed,ast2500-spi"; + reg = <0x1e630000 0xc1 0x30000000 0x02000000 0x36000000 0x02000000>; + interrupts = <59>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + flash@0 { + reg = <0>; /* chip select number */ + compatible = "jedec,spi-nor"; + spi-max-frequency = <100000000>; + status = "disabled"; + }; + flash@1 { + reg = <1>; /* chip select number */ + compatible = "jedec,spi-nor"; + spi-max-frequency = <100000000>; + status = "disabled"; + }; + };
Signature · 1 line
2.8.0.rc3.226.g39d4020