Add Mediatek SPI slave driver
Subsystems (3)
v3 cover Add Mediatek SPI slave driver
Quoted 1 line
From
82bced99683343899dea4634452940b15d6374ebMon Sep 17 00:00:00 2001
From: Leilk Liu <[email protected]>
Date: Mon, 17 Sep 2018 10:07:45 +0800
Subject: [PATCH v3 0/3] Add Mediatek SPI slave driver
v3:
1. Fix Rob Herring review comment about bindings.
2. remove unused variables in driver.
v2:
1. Fix Sean Wang review comment.
2. remove unused register and offset define.
3. update bindings file with assigned-clocks and assigned-clocks-parents.
v1:
This series are based on 4.19-rc1 and provide three patches to add mediatek spi slave driver.
Leilk Liu (3):
spis: mediatek: add bindings for Mediatek MT2712 soc platform
spis: mediatek: add spi slave for Mediatek MT2712
arm64: dts: Add spi slave dts
.../devicetree/bindings/spi/spi-slave-mt27xx.txt | 32 ++ arch/arm64/boot/dts/mediatek/mt2712e.dtsi | 11 + drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/spi-slave-mt27xx.c | 553 +++++++++++++++++++++ 5 files changed, 605 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-slave-mt27xx.txt create mode 100644 drivers/spi/spi-slave-mt27xx.c
Signature · 1 line
1.9.1
PATCH v3 1/3 spis: mediatek: add bindings for Mediatek MT2712 soc platform
This patch adds a DT binding documentation for the MT2712 soc.
--- .../devicetree/bindings/spi/spi-slave-mt27xx.txt | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-slave-mt27xx.txt
Documentation/devicetree/bindings/spi/spi-slave-mt27xx.txt new file +32 -0
@@ -0,0 +1,32 @@ +Binding for MTK SPI Slave controller + +Required properties: +- compatible: should be one of the following. + - mediatek,mt2712-spi-slave: for mt2712 platforms +- reg: Address and length of the register set for the device. +- interrupts: Should contain spi interrupt. +- clocks: phandles to input clocks. + It's clock gate, and should be <&infracfg CLK_INFRA_AO_SPI1>. +- clock-names: should be "spi" for the clock gate. + +Optional properties: +- assigned-clocks: it's mux clock, should be <&topckgen CLK_TOP_SPISLV_SEL>. +- assigned-clock-parents: parent of mux clock. + It's PLL, and should be on of the following. + - <&topckgen CLK_TOP_UNIVPLL1_D2>: specify parent clock 312MHZ. + It's the default one. + - <&topckgen CLK_TOP_UNIVPLL1_D4>: specify parent clock 156MHZ. + - <&topckgen CLK_TOP_UNIVPLL2_D4>: specify parent clock 104MHZ. + - <&topckgen CLK_TOP_UNIVPLL1_D8>: specify parent clock 78MHZ. + +Example: +- SoC Specific Portion: +spis1: spi at 10013000 { + compatible = "mediatek,mt2712-spi-slave"; + reg = <0 0x10013000 0 0x100>; + interrupts = <GIC_SPI 283 IRQ_TYPE_LEVEL_LOW>; + clocks = <&infracfg CLK_INFRA_AO_SPI1>; + clock-names = "spi"; + assigned-clocks = <&topckgen CLK_TOP_SPISLV_SEL>; + assigned-clock-parents = <&topckgen CLK_TOP_UNIVPLL1_D2>; +};
Signature · 1 line
1.7.9.5
Rob Herring
maintainerPATCH v3 1/3 spis: mediatek: add bindings for Mediatek MT2712 soc platform
Quoted 19 lines · Leilk Liu
This patch adds a DT binding documentation for the MT2712 soc.
Signed-off-by Leilk Liu <[email protected]>--- .../devicetree/bindings/spi/spi-slave-mt27xx.txt | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-slave-mt27xx.txtDocumentation/devicetree/bindings/spi/spi-slave-mt27xx.txt new file +5
-0@@ -0,0 +1,32 @@ +Binding for MTK SPI Slave controller + +Required properties: +- compatible: should be one of the following. + - mediatek,mt2712-spi-slave: for mt2712 platforms
Documentation/devicetree/bindings/spi/spi-slave-mt27xx.txt line 15
Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-slave-mt27xx.txt new file +10
-0+- reg: Address and length of the register set for the device. +- interrupts: Should contain spi interrupt. +- clocks: phandles to input clocks. + It's clock gate, and should be <&infracfg CLK_INFRA_AO_SPI1>. +- clock-names: should be "spi" for the clock gate. + +Optional properties: +- assigned-clocks: it's mux clock, should be <&topckgen CLK_TOP_SPISLV_SEL>. +- assigned-clock-parents: parent of mux clock. + It's PLL, and should be on of the following.
s/on/one/
With that fixed,
Re: [PATCH v3 1/3] spis: mediatek: add bindings for Mediatek MT2712 soc platform
Quoted 33 lines · Rob Herring
Quoted 19 lines · Leilk Liu
This patch adds a DT binding documentation for the MT2712 soc.
Signed-off-by Leilk Liu <[email protected]>--- .../devicetree/bindings/spi/spi-slave-mt27xx.txt | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-slave-mt27xx.txtDocumentation/devicetree/bindings/spi/spi-slave-mt27xx.txt new file +5
-0@@ -0,0 +1,32 @@ +Binding for MTK SPI Slave controller + +Required properties: +- compatible: should be one of the following. + - mediatek,mt2712-spi-slave: for mt2712 platformsDocumentation/devicetree/bindings/spi/spi-slave-mt27xx.txt line 15
Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-slave-mt27xx.txt new file +10
-0+- reg: Address and length of the register set for the device. +- interrupts: Should contain spi interrupt. +- clocks: phandles to input clocks. + It's clock gate, and should be <&infracfg CLK_INFRA_AO_SPI1>. +- clock-names: should be "spi" for the clock gate. + +Optional properties: +- assigned-clocks: it's mux clock, should be <&topckgen CLK_TOP_SPISLV_SEL>. +- assigned-clock-parents: parent of mux clock. + It's PLL, and should be on of the following.s/on/one/
Quoted 3 lines
With that fixed,
Reviewed-by Rob Herring <[email protected]>
Yes, it's a mistake, I'll fix it, thanks
PATCH v3 2/3 spis: mediatek: add spi slave for Mediatek MT2712
In reply to Leilk LiuThis patchs add basic spi slave for MT2712.
--- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/spi-slave-mt27xx.c | 553 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 562 insertions(+) create mode 100644 drivers/spi/spi-slave-mt27xx.c
drivers/spi/Kconfig +8 -0
@@ -802,6 +802,14 @@ config SPI_SLAVE slave protocol handlers. if SPI_SLAVE +config SPI_SLAVE_MT27XX + tristate "MediaTek SPI slave device" + depends on ARCH_MEDIATEK || COMPILE_TEST + help + This selects the MediaTek(R) SPI slave device driver. + If you want to use MediaTek(R) SPI slave interface, + say Y or M here.If you are not sure, say N. + SPI slave drivers for Mediatek MT27XX series ARM SoCs. config SPI_SLAVE_TIME tristate "SPI slave handler reporting boot up time"
drivers/spi/Makefile +1 -0
@@ -109,5 +109,6 @@ obj-$(CONFIG_SPI_XTENSA_XTFPGA) += spi-xtensa-xtfpga.o obj-$(CONFIG_SPI_ZYNQMP_GQSPI) += spi-zynqmp-gqspi.o # SPI slave protocol handlers +obj-$(CONFIG_SPI_SLAVE_MT27XX) += spi-slave-mt27xx.o obj-$(CONFIG_SPI_SLAVE_TIME) += spi-slave-time.o obj-$(CONFIG_SPI_SLAVE_SYSTEM_CONTROL) += spi-slave-system-control.o
drivers/spi/spi-slave-mt27xx.c new file +553 -0
553 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Mark Brown
maintainerRe: [PATCH v3 2/3] spis: mediatek: add spi slave for Mediatek MT2712
On Mon, Sep 17, 2018 at 10:19:21AM +0800, Leilk Liu wrote:
This looks overall pretty good, a few smallish comments below:
Please use subject lines matching the style for the subsystem. This makes it easier for people to identify relevant patches.
drivers/spi/Kconfig config SPI_SLAVE · line 814
Quoted 11 lines
if
SPI_SLAVEdrivers/spi/Kconfig +8
-0+config SPI_SLAVE_MT27XX + tristate "MediaTek SPI slave device" + depends on ARCH_MEDIATEK || COMPILE_TEST + help + This selects the MediaTek(R) SPI slave device driver. + If you want to use MediaTek(R) SPI slave interface, + say Y or M here.If you are not sure, say N. + SPI slave drivers for Mediatek MT27XX series ARM SoCs. config SPI_SLAVE_TIME
This is a driver not a slave implementation, it should be with the other drivers in the Kconfig. The slave implementations are for the functionality that uses the drivers, not the drivers themselves.
drivers/spi/spi-slave-mt27xx.c line 146
Quoted 9 lines
drivers/spi/spi-slave-mt27xx.c new file +9
-0+/* set the tx/rx endian */ +#ifdef __LITTLE_ENDIAN + reg_val &= ~SPIS_TX_ENDIAN ; + reg_val &= ~SPIS_RX_ENDIAN ; +#else + reg_val |=SPIS_TX_ENDIAN ; + reg_val |=SPIS_RX_ENDIAN ; +#endif +writel (reg_val, mdata->base +SPIS_CFG_REG );
This seems weird - it looks like it's changing the endianess of the protocol based on the endianness the processor is running in. What's going on here? I'd expect the driver to be just treating everything as a byte stream and letting the protocol driver handle the endianness issues, otherwise we might end up with double converions.
Review
Quoted 2 lines
(quoted diff) +2
-0+ xfer->tx_dma = dma_map_single(dev, (void *)xfer->tx_buf, + xfer->len, DMA_TO_DEVICE);
Why is there a cast to void here? That's usually a sign that there's a type safety issue, the whole point with void is that it's compatible with any other pointer.
drivers/spi/spi-slave-mt27xx.c line 322
Quoted 12 lines
drivers/spi/spi-slave-mt27xx.c new file +12
-0+static irqreturn_t mtk_spi_slave_interrupt (int irq,void *dev_id) +{ +struct spi_controller *ctlr = dev_id; +struct mtk_spi_slave *mdata =spi_controller_get_devdata (ctlr); +struct spi_transfer *trans = mdata->cur_transfer; +u32 int_status, reg_val, cnt, remainder; + + int_status =readl (mdata->base +SPIS_IRQ_ST_REG ); +writel (int_status, mdata->base +SPIS_IRQ_CLR_REG ); + +if (!trans) +return IRQ_HANDLED ;
Are you sure that this is the right thing to do if we get a spurious interrupt - the normal thing would be to return IRQ_NONE, possibly logging a warning as well?
drivers/spi/spi-slave-mt27xx.c line 358
Quoted 2 lines
drivers/spi/spi-slave-mt27xx.c new file +2
-0+if (int_status &CMD_INVALID_ST ) +dev_err (&ctlr->dev,"cmd invalid\n" );
If there's an interrupt that doesn't have any of the interrupt status
flags set I'd expect to see a warning and probably IRQ_NONE being
returned. That way if the interrupt line is shared we work correctly
and if something goes wrong and the interrupt gets stuck on then the
core interrupt code's error handling can kick in.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180918/354dd5c7/attachment.sig>
Re: [PATCH v3 2/3] spis: mediatek: add spi slave for Mediatek MT2712
Hi Mark,
Thanks for your comments.
Quoted 7 lines · Mark Brown
On Mon, Sep 17, 2018 at 10:19:21AM +0800, Leilk Liu wrote:
This looks overall pretty good, a few smallish comments below:
Please use subject lines matching the style for the subsystem. This makes it easier for people to identify relevant patches.
OK, I'll fix it, thanks.
Quoted 10 lines
Quoted 10 lines
if
SPI_SLAVEdrivers/spi/Kconfig +8
-0+config SPI_SLAVE_MT27XX + tristate "MediaTek SPI slave device" + depends on ARCH_MEDIATEK || COMPILE_TEST + help + This selects the MediaTek(R) SPI slave device driver. + If you want to use MediaTek(R) SPI slave interface, + say Y or M here.If you are not sure, say N. + SPI slave drivers for Mediatek MT27XX series ARM SoCs.
Quoted 6 lines
Quoted 1 line
config
SPI_SLAVE_TIMEThis is a driver not a slave implementation, it should be with the other drivers in the
Kconfig. The slave implementations are for the functionality that uses the drivers, not the drivers themselves.
OK, I'll fix it, thanks.
Quoted 7 lines
Quoted 7 lines
drivers/spi/spi-slave-mt27xx.c new file +7
-0+/* set the tx/rx endian */ +#ifdef __LITTLE_ENDIAN + reg_val &= ~SPIS_TX_ENDIAN ; + reg_val &= ~SPIS_RX_ENDIAN ; +#else + reg_val |=SPIS_TX_ENDIAN ; + reg_val |=SPIS_RX_ENDIAN ;
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#endif + writel(reg_val, mdata->base + SPIS_CFG_REG);This seems weird - it looks like it's changing the endianess of the protocol based on the endianness the processor is running in. What's going on here? I'd expect the driver to be just treating everything as a byte stream and letting the protocol driver handle the endianness issues, otherwise we might end up with double converions.
OK, I'll set the endian of SPI the same with the processor. Thanks.
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ xfer->tx_dma = dma_map_single(dev, (void *)xfer->tx_buf, + xfer->len, DMA_TO_DEVICE);Why is there a cast to void here? That's usually a sign that there's a type safety issue, the whole point with void is that it's compatible with any other pointer.
tx_buf is a const void*, here it need a void * for the dma mapping. And I'll remove void * from dma_map_single((void *)rx_buf). Thanks.
Quoted 8 lines
Quoted 8 lines
drivers/spi/spi-slave-mt27xx.c new file +8
-0+static irqreturn_t mtk_spi_slave_interrupt (int irq,void *dev_id) +{ +struct spi_controller *ctlr = dev_id; +struct mtk_spi_slave *mdata =spi_controller_get_devdata (ctlr); +struct spi_transfer *trans = mdata->cur_transfer; +u32 int_status, reg_val, cnt, remainder; + + int_status =readl (mdata->base +SPIS_IRQ_ST_REG );
Quoted 9 lines
drivers/spi/spi-slave-mt27xx.c line 322
Quoted 4 lines
drivers/spi/spi-slave-mt27xx.c new file +4
-0+writel (int_status, mdata->base +SPIS_IRQ_CLR_REG ); + +if (!trans) +return IRQ_HANDLED ;Are you sure that this is the right thing to do if we get a spurious interrupt - the normal thing would be to return
IRQ_NONE, possibly logging a warning as well?
OK, it should reture IRQ_NONE here, thanks.
Quoted 8 lines
drivers/spi/spi-slave-mt27xx.c line 358
Quoted 2 lines
drivers/spi/spi-slave-mt27xx.c new file +2
-0+if (int_status &CMD_INVALID_ST ) +dev_err (&ctlr->dev,"cmd invalid\n" );If there's an interrupt that doesn't have any of the interrupt status flags set I'd expect to see a warning and probably
IRQ_NONEbeing returned. That way if the interrupt line is shared we work correctly and if something goes wrong and the interrupt gets stuck on then the core interrupt code's error handling can kick in.
OK, I'll fix it, thanks.
PATCH v3 3/3 arm64: dts: Add spi slave dts
In reply to Leilk LiuThis patch adds MT2712 spi slave into device tree.
--- arch/arm64/boot/dts/mediatek/mt2712e.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/mediatek/mt2712e.dtsi +11 -0
@@ -301,6 +301,17 @@ status = "disabled"; }; + spis1: spi at 10013000 { + compatible = "mediatek,mt2712-spi-slave"; + reg = <0 0x10013000 0 0x100>; + interrupts = <GIC_SPI 283 IRQ_TYPE_LEVEL_LOW>; + clocks = <&infracfg CLK_INFRA_AO_SPI1>; + clock-names = "spi"; + assigned-clocks = <&topckgen CLK_TOP_SPISLV_SEL>; + assigned-clock-parents = <&topckgen CLK_TOP_UNIVPLL1_D2>; + status = "disabled"; + }; + apmixedsys: syscon at 10209000 { compatible = "mediatek,mt2712-apmixedsys", "syscon"; reg = <0 0x10209000 0 0x1000>;
Signature · 1 line
1.7.9.5