spi changes and ti quad spi controller.
Subsystems (2)
cover spi changes and ti quad spi controller.
Add support for calculating message length in spi framework.
Add support for quad spi controller.
Patch 2 of this series had been posted before. Sending along with the series along with ather propsed change.
Sourav Poddar (3):
driver: spi: Modify core to compute the message length
drivers: spi: Add qspi flash controller
driver: spi: Add quad spi read support
Documentation/devicetree/bindings/spi/ti_qspi.txt | 22 + drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/spi-ti-qspi.c | 489 +++++++++++++++++++++ drivers/spi/spi.c | 1 + include/linux/spi/spi.h | 1 + 6 files changed, 522 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/ti_qspi.txt create mode 100644 drivers/spi/spi-ti-qspi.c
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
PATCH 1/3 driver: spi: Modify core to compute the message length
Make spi core calculate the message length while populating the other transfer parameters. This will
be useful in cases where controller driver need to configure its framelength field without iterating through the linklist again in the driver controller.
--- drivers/spi/spi.c | 1 + include/linux/spi/spi.h | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
drivers/spi/spi.c +1 -0
@@ -1375,6 +1375,7 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)* it is not set for this transfer. */ list_for_each_entry (xfer, &message->transfers, transfer_list) { + message->frame_length += xfer->len;if (!xfer->bits_per_word) xfer->bits_per_word = spi->bits_per_word;if (!xfer->speed_hz)
include/linux/spi/spi.h +1 -0
@@ -575,6 +575,7 @@ struct spi_message {/* completion is reported through a callback */ void (*complete)(void *context);void *context; +unsigned frame_length;unsigned actual_length;int status;
Signature · 9 lines
1.7.1 ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev
PATCH v3 2/3 drivers: spi: Add qspi flash controller
In reply to Sourav PoddarThe patch add basic support for the quad spi controller.
QSPI is a kind of spi module that allows single, dual and quad read access to external spi devices. The module has a memory mapped interface which provide direct interface for accessing data form external spi devices.
The patch will configure controller clocks, device control register and for defining low level transfer apis which will be used by the spi framework to transfer data to the slave spi device(flash in this case).
---v2->v3
1. Add threaded irq support
2. made the driver more generic in terms of chip select, bits_per_word etc.
3. Made it more modular by sepoerating tx/rx function.
Documentation/devicetree/bindings/spi/ti_qspi.txt | 22 + drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/spi-ti-qspi.c | 485 +++++++++++++++++++++ 4 files changed, 516 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/ti_qspi.txt create mode 100644 drivers/spi/spi-ti-qspi.c
Documentation/devicetree/bindings/spi/ti_qspi.txt new file +22 -0
@@ -0,0 +1,22 @@ +TI QSPI controller. + +Required properties: +- compatible : should be "ti,dra7xxx-qspi". +- reg: Should contain QSPI registers location and length. +- #address-cells, #size-cells : Must be present if the device has sub-nodes +- ti,hwmods: Name of the hwmod associated to the QSPI + +Recommended properties: +- spi-max-frequency: Definition as per + Documentation/devicetree/bindings/spi/spi-bus.txt + +Example: + +qspi: qspi@4b300000 { + compatible = "ti,dra7xxx-qspi"; + reg = <0x4b300000 0x100>; + #address-cells = <1>; + #size-cells = <0>; + spi-max-frequency = <25000000>; + ti,hwmods = "qspi"; +};
drivers/spi/Kconfig +8 -0
@@ -285,6 +285,14 @@ config SPI_OMAP24XX SPI master controller for OMAP24XX and later Multichannel SPI (McSPI) modules. +config QSPI_DRA7xxx + tristate "DRA7xxx QSPI controller support" + depends on ARCH_OMAP2PLUS || COMPILE_TEST + help + QSPI master controller for DRA7xxx used for flash devices. + This device supports single, dual and quad read support, while + it only supports single write mode. + config SPI_OMAP_100K tristate "OMAP SPI 100K" depends on ARCH_OMAP850 || ARCH_OMAP730
drivers/spi/Makefile +1 -0
@@ -46,6 +46,7 @@ obj-$(CONFIG_SPI_OCTEON) += spi-octeon.o obj-$(CONFIG_SPI_OMAP_UWIRE) += spi-omap-uwire.o obj-$(CONFIG_SPI_OMAP_100K) += spi-omap-100k.o obj-$(CONFIG_SPI_OMAP24XX) += spi-omap2-mcspi.o +obj-$(CONFIG_QSPI_DRA7xxx) += spi-ti-qspi.o obj-$(CONFIG_SPI_ORION) += spi-orion.o obj-$(CONFIG_SPI_PL022) += spi-pl022.o obj-$(CONFIG_SPI_PPC4xx) += spi-ppc4xx.o
drivers/spi/spi-ti-qspi.c new file +485 -0
485 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 3/3 driver: spi: Add quad spi read support
In reply to Sourav PoddarSince, qspi controller uses quad read.
Configuring the command register, if the transfer of data needs quad lines.
This patch has been done on top of the following patch[1], which is still under review/comments.
This patch will also go changes, as the parent patch[1] does.
[1]: http://comments.gmane.org/gmane.linux.kernel.spi.devel/14047
--- drivers/spi/spi-ti-qspi.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/spi/spi-ti-qspi.c +6 -2
@@ -258,8 +258,12 @@ static int qspi_read_msg(struct dra7xxx_qspi *qspi, struct spi_transfer *t) qspi->cmd | QSPI_RD_SNGL, qspi->dc);dra7xxx_writel (qspi,QSPI_WC_INT_EN ,QSPI_INTR_ENABLE_SET_REG );dra7xxx_writel (qspi, qspi->dc,QSPI_SPI_DC_REG ); -dra7xxx_writel (qspi, qspi->cmd |QSPI_RD_SNGL , -QSPI_SPI_CMD_REG ); +if (t->bitwidth ==SPI_BITWIDTH_QUAD ) +dra7xxx_writel (qspi, qspi->cmd |QSPI_RD_QUAD , +QSPI_SPI_CMD_REG ); +else +dra7xxx_writel (qspi, qspi->cmd |QSPI_RD_SNGL , +QSPI_SPI_CMD_REG );wait_for_completion (&qspi->word_complete); *rxbuf++ =dra7xxx_readl_data (qspi,QSPI_SPI_DATA_REG , wlen);dev_dbg (qspi->dev,"rx done, read %02x\n" , *(rxbuf-1 ));
Signature · 9 lines
1.7.1 ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev
Re: [PATCHv3 2/3] drivers: spi: Add qspi flash controller
In reply to Sourav PoddarHi,
Quoted 17 lines · Sourav Poddar
drivers/spi/spi-ti-qspi.c new file +17
-0+static inline unsigned long dra7xxx_readl (struct dra7xxx_qspi *qspi, +unsigned long reg) +{ +return readl (qspi->base + reg); +} + +static inline void dra7xxx_writel (struct dra7xxx_qspi *qspi, +unsigned long val,unsigned long reg) +{ +writel (val, qspi->base + reg); +} + +static inline unsigned long dra7xxx_readl_data (struct dra7xxx_qspi *qspi, +unsigned long reg,int wlen) +{ +switch (wlen) { +case 8 :
drivers/spi/spi-ti-qspi.c line 135
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+return readw (qspi->base + reg); +break ; +case 16 : +return readb (qspi->base + reg); +break ; +case 32 : +return readl (qspi->base + reg); +break ; +default : +return -1 ;
return -EINVAL ? or some other error code ?
Quoted 23 lines
drivers/spi/spi-ti-qspi.c new file +23
-0+ } +} + +static inline void dra7xxx_writel_data (struct dra7xxx_qspi *qspi, +unsigned long val,unsigned long reg,int wlen) +{ +switch (wlen) { +case 8 : +writew (val, qspi->base + reg); +break ; +case 16 : +writeb (val, qspi->base + reg); +break ; +case 32 : +writeb (val, qspi->base + reg); +break ; +default : +dev_dbg (qspi->dev,"word lenght out of range" ); +break ; + } +} + +static int dra7xxx_qspi_setup (struct spi_device *spi)
drivers/spi/spi-ti-qspi.c line 168
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (spi->master); +int clk_div =0 ; +u32 clk_ctrl_reg, clk_rate; + + clk_rate =clk_get_rate (qspi->fclk); + +if (!qspi->spi_max_frequency) { +dev_err (qspi->dev,"spi max frequency not defined\n" ); +return -1 ;
same here
drivers/spi/spi-ti-qspi.c line 169
Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1
-0+ }else
this needs to have curly braces too, per CodingStyle
Quoted 30 lines
drivers/spi/spi-ti-qspi.c new file +30
-0+ clk_div = (clk_rate / qspi->spi_max_frequency) -1 ; + +dev_dbg (qspi->dev,"%s: hz: %d, clock divider %d\n" , __func__, + qspi->spi_max_frequency, clk_div); + +pm_runtime_get_sync (qspi->dev); + + clk_ctrl_reg =dra7xxx_readl (qspi,QSPI_SPI_CLOCK_CNTRL_REG ); + + clk_ctrl_reg &= ~QSPI_CLK_EN ; + +/* disable SCLK */ +dra7xxx_writel (qspi, clk_ctrl_reg,QSPI_SPI_CLOCK_CNTRL_REG ); + +if (clk_div <0 ) { +dev_dbg (qspi->dev,"%s: clock divider < 0, using /1 divider\n" , + __func__); + clk_div =1 ; + } + +if (clk_div >QSPI_CLK_DIV_MAX ) { +dev_dbg (qspi->dev,"%s: clock divider >%d , using /%d divider\n" , + __func__,QSPI_CLK_DIV_MAX ,QSPI_CLK_DIV_MAX +1 ); + clk_div =QSPI_CLK_DIV_MAX ; + } + +/* enable SCLK */ +dra7xxx_writel (qspi,QSPI_CLK_EN | clk_div,QSPI_SPI_CLOCK_CNTRL_REG ); + +pm_runtime_mark_last_busy (qspi->dev);
drivers/spi/spi-ti-qspi.c line 209
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+pm_runtime_put_autosuspend (qspi->dev); + +return 0 ; +} + +static int dra7xxx_qspi_prepare_xfer (struct spi_master *master) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); + +pm_runtime_get_sync (qspi->dev);
not going to check return value ?
drivers/spi/spi-ti-qspi.c line 219
Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9
-0+return 0 ; +} + +static int dra7xxx_qspi_unprepare_xfer (struct spi_master *master) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); + +pm_runtime_mark_last_busy (qspi->dev); +pm_runtime_put_autosuspend (qspi->dev);
what about on these two ?
Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6
-0+return 0 ; +} + +static int qspi_write_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +const u8 *txbuf;
drivers/spi/spi-ti-qspi.c line 236
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+int wlen, count; + + count = t->len; + txbuf = t->tx_buf; + wlen = t->bits_per_word; + +while (count--) { +dev_dbg (qspi->dev,"tx cmd %08x dc %08x data %02x\n" , + qspi->cmd |QSPI_WR_SNGL , qspi->dc, *txbuf); +dra7xxx_writel (qspi,QSPI_WC_INT_EN ,QSPI_INTR_ENABLE_SET_REG );
you should enable the interrupt as the last step. Also, why aren't you using frame interrupt ?
Quoted 13 lines
drivers/spi/spi-ti-qspi.c new file +13
-0+dra7xxx_writel_data (qspi, *txbuf++,QSPI_SPI_DATA_REG , wlen); +dra7xxx_writel (qspi, qspi->dc,QSPI_SPI_DC_REG ); +dra7xxx_writel (qspi, qspi->cmd |QSPI_WR_SNGL , +QSPI_SPI_CMD_REG ); +wait_for_completion (&qspi->word_complete); + } + +return 0 ; +} + +static int qspi_read_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +u8 *rxbuf;
drivers/spi/spi-ti-qspi.c line 259
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+int wlen, count; + + count = t->len; + rxbuf = t->rx_buf; + wlen = t->bits_per_word; + +while (count--) { +dev_dbg (qspi->dev,"rx cmd %08x dc %08x\n" , + qspi->cmd |QSPI_RD_SNGL , qspi->dc); +dra7xxx_writel (qspi,QSPI_WC_INT_EN ,QSPI_INTR_ENABLE_SET_REG );
ditto
Quoted 31 lines
drivers/spi/spi-ti-qspi.c new file +31
-0+dra7xxx_writel (qspi, qspi->dc,QSPI_SPI_DC_REG ); +dra7xxx_writel (qspi, qspi->cmd |QSPI_RD_SNGL , +QSPI_SPI_CMD_REG ); +wait_for_completion (&qspi->word_complete); + *rxbuf++ =dra7xxx_readl_data (qspi,QSPI_SPI_DATA_REG , wlen); +dev_dbg (qspi->dev,"rx done, read %02x\n" , *(rxbuf-1 )); + } + +return 0 ; +} + +static int qspi_transfer_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +if (t->tx_buf) +qspi_write_msg (qspi, t); +if (t->rx_buf) +qspi_read_msg (qspi, t); + +return 0 ; +} + +static int dra7xxx_qspi_start_transfer_one (struct spi_master *master, +struct spi_message *m) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); +struct spi_device *spi = m->spi; +struct spi_transfer *t; +int status =0 ; +int frame_length; + +/* setup device control reg */
drivers/spi/spi-ti-qspi.c line 300
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+ qspi->dc =0 ; + +if (spi->mode &SPI_CPHA ) + qspi->dc |=QSPI_CKPHA (spi->chip_select); +if (spi->mode &SPI_CPOL ) + qspi->dc |=QSPI_CKPOL (spi->chip_select); +if (spi->mode &SPI_CS_HIGH ) + qspi->dc |=QSPI_CSPOL (spi->chip_select); + + frame_length = DIV_ROUND_UP(m->frame_length * spi->bits_per_word,
why this multiplication ? Frame is not counted in bits but in number of words. Which means that m->framelength / spi->bits_per_word should be enough.
Also, this actually brings up a mistake I made, if I read the TRM correclty this time, frame length is nothing but the t->len which renders patch 1 in this series unnecessary, my mistake.
drivers/spi/spi-ti-qspi.c line 308
Quoted 8 lines
drivers/spi/spi-ti-qspi.c new file +8
-0+ spi->bits_per_word); + + frame_length =clamp (frame_length,0 ,QSPI_FRAME_MAX ); + +/* setup command reg */ + qspi->cmd =0 ; + qspi->cmd |=QSPI_EN_CS (spi->chip_select); + qspi->cmd |=QSPI_FLEN (frame_length);
right, right, so far so good...
drivers/spi/spi-ti-qspi.c line 311
Quoted 2 lines
drivers/spi/spi-ti-qspi.c new file +2
-0+list_for_each_entry (t, &m->transfers, transfer_list) { + qspi->cmd |=QSPI_WLEN (t->bits_per_word);
sure about this ? according to TRM a write of 0 means 1 bit, 1, means 2 bits, 2 means 3 bits, etc... So this should be t->bits_per_word - 1.
drivers/spi/spi-ti-qspi.c line 312
Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1
-0+ qspi->cmd |=QSPI_WC_CMD_INT_EN ;
... but why are you still interrupting on every word ????
as I said before, we want to interrupt on every frame. one spi_transfer is one frame, if that frame has a length of 1MiB, I want to be interrupted after 1MiB.
Quoted 19 lines
drivers/spi/spi-ti-qspi.c new file +19
-0+qspi_transfer_msg (qspi, t); + m->actual_length += t->len; + +if (list_is_last (&t->transfer_list, &m->transfers)) + goto out; + } + +out: + m->status = status; +spi_finalize_current_message (master); + +dra7xxx_writel (qspi, qspi->cmd |QSPI_INVAL ,QSPI_SPI_CMD_REG ); + +return status; +} + +static irqreturn_t dra7xxx_qspi_isr (int irq,void *dev_id) +{ +struct dra7xxx_qspi *qspi = dev_id;
drivers/spi/spi-ti-qspi.c line 343
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+u16 mask, stat; + +irqreturn_t ret =IRQ_HANDLED ; + +spin_lock (&qspi->lock); + + stat =dra7xxx_readl (qspi,QSPI_SPI_STATUS_REG ); + mask =dra7xxx_readl (qspi,QSPI_SPI_CMD_REG ); + +if ((stat &QSPI_WC ) && (mask &QSPI_WC_CMD_INT_EN ))
this is wrong, everytime you want to handle another IRQ bit, you will have to update this line.
if (stat & mask)
sounds like it's enough
Signature · 1 line
balbi
Re: [RFC/PATCH 3/3] driver: spi: Add quad spi read support
In reply to Sourav PoddarQuoted 22 lines · Sourav Poddar
Since, qspi controller uses quad read.
Configuring the command register, if the transfer of data needs quad lines.
This patch has been done on top of the following patch[1], which is still under review/comments.
This patch will also go changes, as the parent patch[1] does.[1]: http://comments.gmane.org/gmane.linux.kernel.spi.devel/14047
Signed-off-by Sourav Poddar <[email protected]>--- drivers/spi/spi-ti-qspi.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)drivers/spi/spi-ti-qspi.c +0
-0@@ -258,8 +258,12 @@ static int qspi_read_msg(struct dra7xxx_qspi *qspi, struct spi_transfer *t) qspi->cmd | QSPI_RD_SNGL, qspi->dc);
drivers/spi/spi-ti-qspi.c static int qspi_read_msg(struct dra7xxx_qspi *qspi, struct spi_transfer *t) · line 266
Quoted 10 lines
drivers/spi/spi-ti-qspi.c +6
-2dra7xxx_writel (qspi,QSPI_WC_INT_EN ,QSPI_INTR_ENABLE_SET_REG );dra7xxx_writel (qspi, qspi->dc,QSPI_SPI_DC_REG ); -dra7xxx_writel (qspi, qspi->cmd |QSPI_RD_SNGL , -QSPI_SPI_CMD_REG ); +if (t->bitwidth ==SPI_BITWIDTH_QUAD ) +dra7xxx_writel (qspi, qspi->cmd |QSPI_RD_QUAD , +QSPI_SPI_CMD_REG ); +else +dra7xxx_writel (qspi, qspi->cmd |QSPI_RD_SNGL , +QSPI_SPI_CMD_REG );
we also have read dual, in order to make this code a little better you could:
unsigned cmd = qspi->cmd; switch (t->bitwidth) case SPI_BITWIDTH_QUAD: cmd |= QSPI_RD_QUAD; break; case SPI_BITWIDTH_DUAL: cmd |= QSPI_RD_DUAL; break; case SPI_BITWIDTH_SINGLE: default: cmd |= QSPI_RD_SNGL; } dra7xx_writel(qspi, cmd, QSPI_SPI_CMD_REG);
Signature · 1 line
balbi
Mark Brown
maintainerRe: [RFC/PATCH 1/3] driver: spi: Modify core to compute the message length
In reply to Sourav PoddarQuoted 5 lines · Sourav Poddar
Make spi core calculate the message length while populating the other transfer parameters. This will
be useful in cases where controller driver need to configure its framelength field without iterating through the linklist again in the driver controller.
This seems fine but I'm going to hold off on applying it until it's reqired since it'll bloat the structure a little and it's a bit unusual to need it. We should do an audit in case some drivers do need this though...
Re: [PATCHv3 2/3] drivers: spi: Add qspi flash controller
In reply to Sourav PoddarOn 19:12-20130708, Sourav Poddar wrote:
[..]
generic comment, given our historical mistakes of making drivers specific to a SoC family, it never is.
Now, ti-qspi in file name is a step in the right direction, but, rest of the code(function names etc) is just married to DRA7 family of processor, when it should not be.
Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +0
-0
[...]
Quoted 38 lines
drivers/spi/spi-ti-qspi.c new file +38
-0+static inline unsigned long dra7xxx_readl (struct dra7xxx_qspi *qspi, +unsigned long reg) +{ +return readl (qspi->base + reg); +} + +static inline void dra7xxx_writel (struct dra7xxx_qspi *qspi, +unsigned long val,unsigned long reg) +{ +writel (val, qspi->base + reg); +} + +static inline unsigned long dra7xxx_readl_data (struct dra7xxx_qspi *qspi, +unsigned long reg,int wlen) +{ +switch (wlen) { +case 8 : +return readw (qspi->base + reg); +break ; +case 16 : +return readb (qspi->base + reg); +break ; +case 32 : +return readl (qspi->base + reg); +break ; +default : +return -1 ; + } +} + +static inline void dra7xxx_writel_data (struct dra7xxx_qspi *qspi, +unsigned long val,unsigned long reg,int wlen) +{ +switch (wlen) { +case 8 : +writew (val, qspi->base + reg); +break ; +case 16 :
drivers/spi/spi-ti-qspi.c line 156
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+writeb (val, qspi->base + reg); +break ; +case 32 : +writeb (val, qspi->base + reg); +break ; +default : +dev_dbg (qspi->dev,"word lenght out of range" ); +break ; + } +}
Looks like a case to use regmap?
Dumb q: why cant we use regmap_spi? worst case, you should be able to use mmio if regmap_spi cant be used. The commit message was not clear about this.
Quoted 4 lines
drivers/spi/spi-ti-qspi.c new file +4
-0+ +static int dra7xxx_qspi_setup (struct spi_device *spi) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (spi->master);
drivers/spi/spi-ti-qspi.c line 170
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+int clk_div =0 ; +u32 clk_ctrl_reg, clk_rate; + + clk_rate =clk_get_rate (qspi->fclk); + +if (!qspi->spi_max_frequency) { +dev_err (qspi->dev,"spi max frequency not defined\n" ); +return -1 ; + }else + clk_div = (clk_rate / qspi->spi_max_frequency) -1 ;
did you run checkpatch --strict here?
Also, would you prefer to use DIV_ROUND_UP?
drivers/spi/spi-ti-qspi.c line 175
Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5
-0+ +dev_dbg (qspi->dev,"%s: hz: %d, clock divider %d\n" , __func__, + qspi->spi_max_frequency, clk_div); + +pm_runtime_get_sync (qspi->dev);
error check?
drivers/spi/spi-ti-qspi.c line 187
Quoted 12 lines
drivers/spi/spi-ti-qspi.c new file +12
-0+ + clk_ctrl_reg =dra7xxx_readl (qspi,QSPI_SPI_CLOCK_CNTRL_REG ); + + clk_ctrl_reg &= ~QSPI_CLK_EN ; + +/* disable SCLK */ +dra7xxx_writel (qspi, clk_ctrl_reg,QSPI_SPI_CLOCK_CNTRL_REG ); + +if (clk_div <0 ) { +dev_dbg (qspi->dev,"%s: clock divider < 0, using /1 divider\n" , + __func__); + clk_div =1 ;
should you not fail here?
drivers/spi/spi-ti-qspi.c line 193
Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6
-0+ } + +if (clk_div >QSPI_CLK_DIV_MAX ) { +dev_dbg (qspi->dev,"%s: clock divider >%d , using /%d divider\n" , + __func__,QSPI_CLK_DIV_MAX ,QSPI_CLK_DIV_MAX +1 ); + clk_div =QSPI_CLK_DIV_MAX ;
should you not fail here?
drivers/spi/spi-ti-qspi.c line 200
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7
-0+ } + +/* enable SCLK */ +dra7xxx_writel (qspi,QSPI_CLK_EN | clk_div,QSPI_SPI_CLOCK_CNTRL_REG ); + +pm_runtime_mark_last_busy (qspi->dev); +pm_runtime_put_autosuspend (qspi->dev);
error check?
drivers/spi/spi-ti-qspi.c line 209
Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9
-0+ +return 0 ; +} + +static int dra7xxx_qspi_prepare_xfer (struct spi_master *master) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); + +pm_runtime_get_sync (qspi->dev);
error check?
drivers/spi/spi-ti-qspi.c line 219
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+ +return 0 ; +} + +static int dra7xxx_qspi_unprepare_xfer (struct spi_master *master) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); + +pm_runtime_mark_last_busy (qspi->dev); +pm_runtime_put_autosuspend (qspi->dev);
error check?
Quoted 35 lines
drivers/spi/spi-ti-qspi.c new file +35
-0+ +return 0 ; +} + +static int qspi_write_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +const u8 *txbuf; +int wlen, count; + + count = t->len; + txbuf = t->tx_buf; + wlen = t->bits_per_word; + +while (count--) { +dev_dbg (qspi->dev,"tx cmd %08x dc %08x data %02x\n" , + qspi->cmd |QSPI_WR_SNGL , qspi->dc, *txbuf); +dra7xxx_writel (qspi,QSPI_WC_INT_EN ,QSPI_INTR_ENABLE_SET_REG ); +dra7xxx_writel_data (qspi, *txbuf++,QSPI_SPI_DATA_REG , wlen); +dra7xxx_writel (qspi, qspi->dc,QSPI_SPI_DC_REG ); +dra7xxx_writel (qspi, qspi->cmd |QSPI_WR_SNGL , +QSPI_SPI_CMD_REG ); +wait_for_completion (&qspi->word_complete); + } + +return 0 ; +} + +static int qspi_read_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +u8 *rxbuf; +int wlen, count; + + count = t->len; + rxbuf = t->rx_buf; + wlen = t->bits_per_word;
drivers/spi/spi-ti-qspi.c line 264
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+ +while (count--) { +dev_dbg (qspi->dev,"rx cmd %08x dc %08x\n" , + qspi->cmd |QSPI_RD_SNGL , qspi->dc); +dra7xxx_writel (qspi,QSPI_WC_INT_EN ,QSPI_INTR_ENABLE_SET_REG ); +dra7xxx_writel (qspi, qspi->dc,QSPI_SPI_DC_REG ); +dra7xxx_writel (qspi, qspi->cmd |QSPI_RD_SNGL , +QSPI_SPI_CMD_REG ); +wait_for_completion (&qspi->word_complete); + *rxbuf++ =dra7xxx_readl_data (qspi,QSPI_SPI_DATA_REG , wlen);
*rxbuf =
drivers/spi/spi-ti-qspi.c line 265
Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1
-0+dev_dbg (qspi->dev,"rx done, read %02x\n" , *(rxbuf-1 ));
rxbuf++ after dev_dbg?
drivers/spi/spi-ti-qspi.c line 274
Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9
-0+ } + +return 0 ; +} + +static int qspi_transfer_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +if (t->tx_buf) +qspi_write_msg (qspi, t);
what is the point of the function returning error when we dont use it?
drivers/spi/spi-ti-qspi.c line 276
Quoted 2 lines
drivers/spi/spi-ti-qspi.c new file +2
-0+if (t->rx_buf) +qspi_read_msg (qspi, t);
what is the point of the function returning error when we dont use it?
Quoted 23 lines
drivers/spi/spi-ti-qspi.c new file +23
-0+ +return 0 ; +} + +static int dra7xxx_qspi_start_transfer_one (struct spi_master *master, +struct spi_message *m) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); +struct spi_device *spi = m->spi; +struct spi_transfer *t; +int status =0 ; +int frame_length; + +/* setup device control reg */ + qspi->dc =0 ; + +if (spi->mode &SPI_CPHA ) + qspi->dc |=QSPI_CKPHA (spi->chip_select); +if (spi->mode &SPI_CPOL ) + qspi->dc |=QSPI_CKPOL (spi->chip_select); +if (spi->mode &SPI_CS_HIGH ) + qspi->dc |=QSPI_CSPOL (spi->chip_select); +
drivers/spi/spi-ti-qspi.c line 309
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+ frame_length =DIV_ROUND_UP (m->frame_length * spi->bits_per_word, + spi->bits_per_word); + + frame_length =clamp (frame_length,0 ,QSPI_FRAME_MAX ); + +/* setup command reg */ + qspi->cmd =0 ; + qspi->cmd |=QSPI_EN_CS (spi->chip_select); + qspi->cmd |=QSPI_FLEN (frame_length); +
how does one ensure pm runtime has not disabled clocks in background? e.g. long latency between transfers.
drivers/spi/spi-ti-qspi.c line 314
Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5
-0+list_for_each_entry (t, &m->transfers, transfer_list) { + qspi->cmd |=QSPI_WLEN (t->bits_per_word); + qspi->cmd |=QSPI_WC_CMD_INT_EN ; + +qspi_transfer_msg (qspi, t);
error handling?
Quoted 15 lines
drivers/spi/spi-ti-qspi.c new file +15
-0+ + m->actual_length += t->len; + +if (list_is_last (&t->transfer_list, &m->transfers)) + goto out; + } + +out: + m->status = status; +spi_finalize_current_message (master); + +dra7xxx_writel (qspi, qspi->cmd |QSPI_INVAL ,QSPI_SPI_CMD_REG ); + +return status; +}
drivers/spi/spi-ti-qspi.c line 339
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+ +static irqreturn_t dra7xxx_qspi_isr (int irq,void *dev_id) +{ +struct dra7xxx_qspi *qspi = dev_id; +u16 mask, stat; + +irqreturn_t ret =IRQ_HANDLED ; + +spin_lock (&qspi->lock); +
what if autosuspend has triggered here? before ISR was scheduled?
Quoted 8 lines
drivers/spi/spi-ti-qspi.c new file +8
-0+ stat =dra7xxx_readl (qspi,QSPI_SPI_STATUS_REG ); + mask =dra7xxx_readl (qspi,QSPI_SPI_CMD_REG ); + +if ((stat &QSPI_WC ) && (mask &QSPI_WC_CMD_INT_EN )) + ret =IRQ_WAKE_THREAD ; + +spin_unlock (&qspi->lock); +
drivers/spi/spi-ti-qspi.c line 357
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+return ret; +} + +static irqreturn_t dra7xxx_qspi_threaded_isr (int this_irq,void *dev_id) +{ +struct dra7xxx_qspi *qspi = dev_id; +unsigned long flags; + +spin_lock_irqsave (&qspi->lock, flags); +
what if autosuspend has triggered here? before ISR was scheduled?
Quoted 59 lines
drivers/spi/spi-ti-qspi.c new file +59
-0+dra7xxx_writel (qspi,QSPI_WC_INT_DISABLE ,QSPI_INTR_ENABLE_CLEAR_REG ); +dra7xxx_writel (qspi,QSPI_WC_INT_DISABLE , +QSPI_INTR_STATUS_ENABLED_CLEAR ); + +complete (&qspi->word_complete); + +spin_unlock_irqrestore (&qspi->lock, flags); + +return IRQ_HANDLED ; +} + +static const struct of_device_id dra7xxx_qspi_match[] = { + {.compatible ="ti,dra7xxx-qspi" }, + {}, +}; +MODULE_DEVICE_TABLE (of, dra7xxx_qspi_match); + +static int dra7xxx_qspi_probe (struct platform_device *pdev) +{ +struct dra7xxx_qspi *qspi; +struct spi_master *master; +struct resource *r; +struct device_node *np = pdev->dev.of_node; +u32 max_freq; +int ret =0 , num_cs, irq; + + master =spi_alloc_master (&pdev->dev,sizeof (*qspi)); +if (!master) +return -ENOMEM ; + + master->mode_bits =SPI_CPOL |SPI_CPHA ; + + master->num_chipselect =1 ; + master->bus_num =-1 ; + master->setup = dra7xxx_qspi_setup; + master->prepare_transfer_hardware = dra7xxx_qspi_prepare_xfer; + master->transfer_one_message = dra7xxx_qspi_start_transfer_one; + master->unprepare_transfer_hardware = dra7xxx_qspi_unprepare_xfer; + master->dev.of_node = pdev->dev.of_node; + master->bits_per_word_mask =BIT (32 -1 ) |BIT (16 -1 ) |BIT (8 -1 ); + +if (!of_property_read_u32 (np,"ti,spi-num-cs" , &num_cs)) + master->num_chipselect = num_cs; + +platform_set_drvdata (pdev, master); + + qspi =spi_master_get_devdata (master); + qspi->master = master; + qspi->dev = &pdev->dev; + + r =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (r ==NULL ) { + ret = -ENODEV ; + goto free_master; + } + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) { +dev_err (&pdev->dev,"no irq resource?\n" );
drivers/spi/spi-ti-qspi.c line 426
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+return irq; + } + +spin_lock_init (&qspi->lock); + + qspi->base =devm_ioremap_resource (&pdev->dev, r); +if (IS_ERR (qspi->base)) { + ret = -ENOMEM ; + goto free_master; + }
why not use devm_request_and_ioremap? Lock that region down so that no two drivers can manage the same region?
Quoted 43 lines
drivers/spi/spi-ti-qspi.c new file +43
-0+ + ret =devm_request_threaded_irq (&pdev->dev, irq, dra7xxx_qspi_isr, + dra7xxx_qspi_threaded_isr,IRQF_NO_SUSPEND |IRQF_ONESHOT , +dev_name (&pdev->dev), qspi); +if (ret <0 ) { +dev_err (&pdev->dev,"Failed to register ISR for IRQ %d\n" , + irq); + goto free_master; + } + + qspi->fclk =devm_clk_get (&pdev->dev,"fck" ); +if (IS_ERR (qspi->fclk)) { + ret =PTR_ERR (qspi->fclk); +dev_err (&pdev->dev,"could not get clk: %d\n" , ret); + } + +init_completion (&qspi->word_complete); + +pm_runtime_use_autosuspend (&pdev->dev); +pm_runtime_set_autosuspend_delay (&pdev->dev,SPI_AUTOSUSPEND_TIMEOUT ); +pm_runtime_enable (&pdev->dev); + +if (!of_property_read_u32 (np,"spi-max-frequency" , &max_freq)) + qspi->spi_max_frequency = max_freq; + + ret =spi_register_master (master); +if (ret) + goto free_master; + +return ret; + +free_master: +spi_master_put (master); +return ret; +} + +static int dra7xxx_qspi_remove (struct platform_device *pdev) +{ +struct dra7xxx_qspi *qspi =platform_get_drvdata (pdev); + +spi_unregister_master (qspi->master); + +return 0 ;
drivers/spi/spi-ti-qspi.c line 479
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+} + +static struct platform_driver dra7xxx_qspi_driver = { + .probe = dra7xxx_qspi_probe, + .remove = dra7xxx_qspi_remove, + .driver = { + .name ="ti,dra7xxx-qspi" , + .owner =THIS_MODULE , + .of_match_table = dra7xxx_qspi_match, + }
no need for pm_ops?
drivers/spi/spi-ti-qspi.c line 484
Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5
-0+}; + +module_platform_driver (dra7xxx_qspi_driver); + +MODULE_LICENSE ("GPL" );
GPL V2?
Quoted 1 line
+MODULE_DESCRIPTION("TI QSPI controller driver");
MODULE_AUTHOR?
Quoted 7 lines
Signature · 6 lines
1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Regards, Nishanth Menon
Re: [PATCHv3 2/3] drivers: spi: Add qspi flash controller
Hi,
Quoted 30 lines · Nishanth Menon
Quoted 30 lines
drivers/spi/spi-ti-qspi.c new file +30
-0+static inline unsigned long dra7xxx_readl_data (struct dra7xxx_qspi *qspi, +unsigned long reg,int wlen) +{ +switch (wlen) { +case 8 : +return readw (qspi->base + reg); +break ; +case 16 : +return readb (qspi->base + reg); +break ; +case 32 : +return readl (qspi->base + reg); +break ; +default : +return -1 ; + } +} + +static inline void dra7xxx_writel_data (struct dra7xxx_qspi *qspi, +unsigned long val,unsigned long reg,int wlen) +{ +switch (wlen) { +case 8 : +writew (val, qspi->base + reg); +break ; +case 16 : +writeb (val, qspi->base + reg); +break ; +case 32 : +writeb (val, qspi->base + reg);
Quoted 8 lines
drivers/spi/spi-ti-qspi.c line 156
Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6
-0+break ; +default : +dev_dbg (qspi->dev,"word lenght out of range" ); +break ; + } +}Looks like a case to use regmap?
Dumb q: why cant we useregmap_spi? worst case, you should be able to
read regmap-spi and you'll see why it can't be used in this case.
regmap-spi is for SPI clients who want to read their register map through SPI commands. This is a driver for the SPI master which has its registers memory mapped.
Quoted 23 lines
Quoted 23 lines
drivers/spi/spi-ti-qspi.c new file +23
-0+static int dra7xxx_qspi_start_transfer_one (struct spi_master *master, +struct spi_message *m) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); +struct spi_device *spi = m->spi; +struct spi_transfer *t; +int status =0 ; +int frame_length; + +/* setup device control reg */ + qspi->dc =0 ; + +if (spi->mode &SPI_CPHA ) + qspi->dc |=QSPI_CKPHA (spi->chip_select); +if (spi->mode &SPI_CPOL ) + qspi->dc |=QSPI_CKPOL (spi->chip_select); +if (spi->mode &SPI_CS_HIGH ) + qspi->dc |=QSPI_CSPOL (spi->chip_select); + + frame_length =DIV_ROUND_UP (m->frame_length * spi->bits_per_word, + spi->bits_per_word); + + frame_length =clamp (frame_length,0 ,QSPI_FRAME_MAX );
Quoted 8 lines
drivers/spi/spi-ti-qspi.c line 309
Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6
-0+ +/* setup command reg */ + qspi->cmd =0 ; + qspi->cmd |=QSPI_EN_CS (spi->chip_select); + qspi->cmd |=QSPI_FLEN (frame_length); +how does one ensure pm runtime has not disabled clocks in background? e.g. long latency between transfers.
because pm_runtime_put*() has not been called ?
There's no way clocks will be gated until we kick the pm autosuspend timer, which is only done when the transfer is finished.
Quoted 10 lines
drivers/spi/spi-ti-qspi.c line 339
Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9
-0+static irqreturn_t dra7xxx_qspi_isr (int irq,void *dev_id) +{ +struct dra7xxx_qspi *qspi = dev_id; +u16 mask, stat; + +irqreturn_t ret =IRQ_HANDLED ; + +spin_lock (&qspi->lock); +what if autosuspend has triggered here? before ISR was scheduled?
how ?
the pm timer hasn't been kicked yet
Quoted 11 lines
Quoted 11 lines
drivers/spi/spi-ti-qspi.c new file +11
-0+ stat =dra7xxx_readl (qspi,QSPI_SPI_STATUS_REG ); + mask =dra7xxx_readl (qspi,QSPI_SPI_CMD_REG ); + +if ((stat &QSPI_WC ) && (mask &QSPI_WC_CMD_INT_EN )) + ret =IRQ_WAKE_THREAD ; + +spin_unlock (&qspi->lock); + +return ret; +} +
Quoted 8 lines
drivers/spi/spi-ti-qspi.c line 357
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7
-0+static irqreturn_t dra7xxx_qspi_threaded_isr (int this_irq,void *dev_id) +{ +struct dra7xxx_qspi *qspi = dev_id; +unsigned long flags; + +spin_lock_irqsave (&qspi->lock, flags); +what if autosuspend has triggered here? before ISR was scheduled?
how ?
pm timer hasn't been kicked yet
Quoted 7 lines
drivers/spi/spi-ti-qspi.c line 426
Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5
-0+ qspi->base =devm_ioremap_resource (&pdev->dev, r); +if (IS_ERR (qspi->base)) { + ret = -ENOMEM ; + goto free_master; + }why not use
devm_request_and_ioremap? Lock that region down so that no two drivers can manage the same region?
read devm_ioremap_resource() and look at the git log for all the numerous drivers which were converted to devm_ioremap_resource() to find the reason.
Quoted 9 lines
drivers/spi/spi-ti-qspi.c line 479
Quoted 8 lines
drivers/spi/spi-ti-qspi.c new file +8
-0+static struct platform_driver dra7xxx_qspi_driver = { + .probe = dra7xxx_qspi_probe, + .remove = dra7xxx_qspi_remove, + .driver = { + .name ="ti,dra7xxx-qspi" , + .owner =THIS_MODULE , + .of_match_table = dra7xxx_qspi_match, + }no need for
pm_ops?
+1
Quoted 6 lines
drivers/spi/spi-ti-qspi.c line 484
Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5
-0+}; + +module_platform_driver (dra7xxx_qspi_driver); + +MODULE_LICENSE ("GPL" );GPL V2?
+1
Quoted 2 lines
Quoted 1 line
+MODULE_DESCRIPTION("TI QSPI controller driver");
MODULE_AUTHOR?
+1
Signature · 1 line
balbi
Re: [PATCHv3 2/3] drivers: spi: Add qspi flash controller
In reply to Nishanth MenonQuoted 9 lines · Nishanth Menon
On 19:12-20130708, Sourav Poddar wrote:
[..]
generic comment, given our historical mistakes of making drivers specific to a SoC family, it never is.Now, ti-qspi in file name is a step in the right direction, but, rest of the code(function names etc) is just married to DRA7 family of processor, when it should not be.
Make sense. Will change apis accordingly.
Quoted 50 lines
Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +0
-0[...]
Quoted 44 lines
drivers/spi/spi-ti-qspi.c new file +44
-0+static inline unsigned long dra7xxx_readl (struct dra7xxx_qspi *qspi, +unsigned long reg) +{ +return readl (qspi->base + reg); +} + +static inline void dra7xxx_writel (struct dra7xxx_qspi *qspi, +unsigned long val,unsigned long reg) +{ +writel (val, qspi->base + reg); +} + +static inline unsigned long dra7xxx_readl_data (struct dra7xxx_qspi *qspi, +unsigned long reg,int wlen) +{ +switch (wlen) { +case 8 : +return readw (qspi->base + reg); +break ; +case 16 : +return readb (qspi->base + reg); +break ; +case 32 : +return readl (qspi->base + reg); +break ; +default : +return -1 ; + } +} + +static inline void dra7xxx_writel_data (struct dra7xxx_qspi *qspi, +unsigned long val,unsigned long reg,int wlen) +{ +switch (wlen) { +case 8 : +writew (val, qspi->base + reg); +break ; +case 16 : +writeb (val, qspi->base + reg); +break ; +case 32 : +writeb (val, qspi->base + reg); +break ; +default :
Quoted 9 lines
drivers/spi/spi-ti-qspi.c line 156
Quoted 4 lines
drivers/spi/spi-ti-qspi.c new file +4
-0+dev_dbg (qspi->dev,"word lenght out of range" ); +break ; + } +}Looks like a case to use regmap?
Dumb q: why cant we useregmap_spi? worst case, you should be able to use mmio ifregmap_spicant be used. The commit message was not clear about this.
MMIO can be used as this controller supports memory mapped port, but that will be addition/enhancement on top of this.
This driver is adding qspi controller read/write support in SPI mode.
Quoted 7 lines
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7
-0+ +static int dra7xxx_qspi_setup (struct spi_device *spi) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (spi->master); +int clk_div =0 ; +u32 clk_ctrl_reg, clk_rate; +
Quoted 8 lines
drivers/spi/spi-ti-qspi.c line 170
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7
-0+ clk_rate =clk_get_rate (qspi->fclk); + +if (!qspi->spi_max_frequency) { +dev_err (qspi->dev,"spi max frequency not defined\n" ); +return -1 ; + }else + clk_div = (clk_rate / qspi->spi_max_frequency) -1 ;did you run checkpatch --strict here?
Didn,t do the strict, yes will add braces.
Quoted 2 lines
Also, would you prefer to use
DIV_ROUND_UP?
Ok.
Quoted 6 lines
drivers/spi/spi-ti-qspi.c line 175
Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5
-0+ +dev_dbg (qspi->dev,"%s: hz: %d, clock divider %d\n" , __func__, + qspi->spi_max_frequency, clk_div); + +pm_runtime_get_sync (qspi->dev);error check?
Will add.
Quoted 5 lines
Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5
-0+ + clk_ctrl_reg =dra7xxx_readl (qspi,QSPI_SPI_CLOCK_CNTRL_REG ); + + clk_ctrl_reg&= ~QSPI_CLK_EN ; +
Quoted 8 lines
drivers/spi/spi-ti-qspi.c line 187
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7
-0+/* disable SCLK */ +dra7xxx_writel (qspi, clk_ctrl_reg,QSPI_SPI_CLOCK_CNTRL_REG ); + +if (clk_div<0 ) { +dev_dbg (qspi->dev,"%s: clock divider< 0, using /1 divider\n" , + __func__); + clk_div =1 ;should you not fail here?
May be yes.
Quoted 7 lines
drivers/spi/spi-ti-qspi.c line 193
Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6
-0+ } + +if (clk_div>QSPI_CLK_DIV_MAX ) { +dev_dbg (qspi->dev,"%s: clock divider>%d , using /%d divider\n" , + __func__,QSPI_CLK_DIV_MAX ,QSPI_CLK_DIV_MAX +1 ); + clk_div =QSPI_CLK_DIV_MAX ;should you not fail here?
Yup.
Quoted 8 lines
drivers/spi/spi-ti-qspi.c line 200
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7
-0+ } + +/* enable SCLK */ +dra7xxx_writel (qspi,QSPI_CLK_EN | clk_div,QSPI_SPI_CLOCK_CNTRL_REG ); + +pm_runtime_mark_last_busy (qspi->dev); +pm_runtime_put_autosuspend (qspi->dev);error check?
Will add.
Quoted 10 lines
drivers/spi/spi-ti-qspi.c line 209
Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9
-0+ +return 0 ; +} + +static int dra7xxx_qspi_prepare_xfer (struct spi_master *master) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); + +pm_runtime_get_sync (qspi->dev);error check?
Will add.
Quoted 11 lines
drivers/spi/spi-ti-qspi.c line 219
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+ +return 0 ; +} + +static int dra7xxx_qspi_unprepare_xfer (struct spi_master *master) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); + +pm_runtime_mark_last_busy (qspi->dev); +pm_runtime_put_autosuspend (qspi->dev);error check?
Will add.
Quoted 46 lines
Quoted 35 lines
drivers/spi/spi-ti-qspi.c new file +35
-0+ +return 0 ; +} + +static int qspi_write_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +const u8 *txbuf; +int wlen, count; + + count = t->len; + txbuf = t->tx_buf; + wlen = t->bits_per_word; + +while (count--) { +dev_dbg (qspi->dev,"tx cmd %08x dc %08x data %02x\n" , + qspi->cmd |QSPI_WR_SNGL , qspi->dc, *txbuf); +dra7xxx_writel (qspi,QSPI_WC_INT_EN ,QSPI_INTR_ENABLE_SET_REG ); +dra7xxx_writel_data (qspi, *txbuf++,QSPI_SPI_DATA_REG , wlen); +dra7xxx_writel (qspi, qspi->dc,QSPI_SPI_DC_REG ); +dra7xxx_writel (qspi, qspi->cmd |QSPI_WR_SNGL , +QSPI_SPI_CMD_REG ); +wait_for_completion (&qspi->word_complete); + } + +return 0 ; +} + +static int qspi_read_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +u8 *rxbuf; +int wlen, count; + + count = t->len; + rxbuf = t->rx_buf; + wlen = t->bits_per_word;drivers/spi/spi-ti-qspi.c line 264
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+ +while (count--) { +dev_dbg (qspi->dev,"rx cmd %08x dc %08x\n" , + qspi->cmd |QSPI_RD_SNGL , qspi->dc); +dra7xxx_writel (qspi,QSPI_WC_INT_EN ,QSPI_INTR_ENABLE_SET_REG ); +dra7xxx_writel (qspi, qspi->dc,QSPI_SPI_DC_REG ); +dra7xxx_writel (qspi, qspi->cmd |QSPI_RD_SNGL , +QSPI_SPI_CMD_REG ); +wait_for_completion (&qspi->word_complete); + *rxbuf++ =dra7xxx_readl_data (qspi,QSPI_SPI_DATA_REG , wlen);*rxbuf =
Quoted 2 lines
drivers/spi/spi-ti-qspi.c line 265
Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1
-0+dev_dbg (qspi->dev,"rx done, read %02x\n" , *(rxbuf-1 ));rxbuf++ after
dev_dbg?
I am not sure, anywyas we are decrementing pointer during dev_dbg..
Quoted 10 lines
drivers/spi/spi-ti-qspi.c line 274
Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9
-0+ } + +return 0 ; +} + +static int qspi_transfer_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +if (t->tx_buf) +qspi_write_msg (qspi, t);what is the point of the function returning error when we dont use it?
hmm..yes, will check for errors.
Quoted 3 lines
drivers/spi/spi-ti-qspi.c line 276
Quoted 2 lines
drivers/spi/spi-ti-qspi.c new file +2
-0+if (t->rx_buf) +qspi_read_msg (qspi, t);what is the point of the function returning error when we dont use it?
Same as above.
Quoted 27 lines
Quoted 27 lines
drivers/spi/spi-ti-qspi.c new file +27
-0+ +return 0 ; +} + +static int dra7xxx_qspi_start_transfer_one (struct spi_master *master, +struct spi_message *m) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); +struct spi_device *spi = m->spi; +struct spi_transfer *t; +int status =0 ; +int frame_length; + +/* setup device control reg */ + qspi->dc =0 ; + +if (spi->mode&SPI_CPHA ) + qspi->dc |=QSPI_CKPHA (spi->chip_select); +if (spi->mode&SPI_CPOL ) + qspi->dc |=QSPI_CKPOL (spi->chip_select); +if (spi->mode&SPI_CS_HIGH ) + qspi->dc |=QSPI_CSPOL (spi->chip_select); + + frame_length =DIV_ROUND_UP (m->frame_length * spi->bits_per_word, + spi->bits_per_word); + + frame_length =clamp (frame_length,0 ,QSPI_FRAME_MAX );
Quoted 8 lines
drivers/spi/spi-ti-qspi.c line 309
Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6
-0+ +/* setup command reg */ + qspi->cmd =0 ; + qspi->cmd |=QSPI_EN_CS (spi->chip_select); + qspi->cmd |=QSPI_FLEN (frame_length); +how does one ensure pm runtime has not disabled clocks in background? e.g. long latency between transfers.
As felipe also pointed out, in prepare transfer I will enable clocks which will get get disabled only during unprepare transfer. I dont know if we hit the above scenario.
+ list_for_each_entry(t, &m->transfers, transfer_list) {
Quoted 5 lines
drivers/spi/spi-ti-qspi.c line 314
Quoted 4 lines
drivers/spi/spi-ti-qspi.c new file +4
-0+ qspi->cmd |=QSPI_WLEN (t->bits_per_word); + qspi->cmd |=QSPI_WC_CMD_INT_EN ; + +qspi_transfer_msg (qspi, t);error handling?
Will add.
Quoted 18 lines
Quoted 18 lines
drivers/spi/spi-ti-qspi.c new file +18
-0+ + m->actual_length += t->len; + +if (list_is_last (&t->transfer_list,&m->transfers)) + goto out; + } + +out: + m->status = status; +spi_finalize_current_message (master); + +dra7xxx_writel (qspi, qspi->cmd |QSPI_INVAL ,QSPI_SPI_CMD_REG ); + +return status; +} + +static irqreturn_t dra7xxx_qspi_isr (int irq,void *dev_id) +{
Quoted 8 lines
drivers/spi/spi-ti-qspi.c line 339
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7
-0+struct dra7xxx_qspi *qspi = dev_id; +u16 mask, stat; + +irqreturn_t ret =IRQ_HANDLED ; + +spin_lock (&qspi->lock); +what if autosuspend has triggered here? before ISR was scheduled?
Similar understanding as above, autosuspend should get triggered only during unprepare.
Quoted 136 lines
Quoted 8 lines
drivers/spi/spi-ti-qspi.c new file +8
-0+ stat =dra7xxx_readl (qspi,QSPI_SPI_STATUS_REG ); + mask =dra7xxx_readl (qspi,QSPI_SPI_CMD_REG ); + +if ((stat&QSPI_WC )&& (mask&QSPI_WC_CMD_INT_EN )) + ret =IRQ_WAKE_THREAD ; + +spin_unlock (&qspi->lock); +drivers/spi/spi-ti-qspi.c line 357
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+return ret; +} + +static irqreturn_t dra7xxx_qspi_threaded_isr (int this_irq,void *dev_id) +{ +struct dra7xxx_qspi *qspi = dev_id; +unsigned long flags; + +spin_lock_irqsave (&qspi->lock, flags); +what if autosuspend has triggered here? before ISR was scheduled?
Quoted 59 lines
drivers/spi/spi-ti-qspi.c new file +59
-0+dra7xxx_writel (qspi,QSPI_WC_INT_DISABLE ,QSPI_INTR_ENABLE_CLEAR_REG ); +dra7xxx_writel (qspi,QSPI_WC_INT_DISABLE , +QSPI_INTR_STATUS_ENABLED_CLEAR ); + +complete (&qspi->word_complete); + +spin_unlock_irqrestore (&qspi->lock, flags); + +return IRQ_HANDLED ; +} + +static const struct of_device_id dra7xxx_qspi_match[] = { + {.compatible ="ti,dra7xxx-qspi" }, + {}, +}; +MODULE_DEVICE_TABLE (of, dra7xxx_qspi_match); + +static int dra7xxx_qspi_probe (struct platform_device *pdev) +{ +struct dra7xxx_qspi *qspi; +struct spi_master *master; +struct resource *r; +struct device_node *np = pdev->dev.of_node; +u32 max_freq; +int ret =0 , num_cs, irq; + + master =spi_alloc_master (&pdev->dev,sizeof (*qspi)); +if (!master) +return -ENOMEM ; + + master->mode_bits =SPI_CPOL |SPI_CPHA ; + + master->num_chipselect =1 ; + master->bus_num =-1 ; + master->setup = dra7xxx_qspi_setup; + master->prepare_transfer_hardware = dra7xxx_qspi_prepare_xfer; + master->transfer_one_message = dra7xxx_qspi_start_transfer_one; + master->unprepare_transfer_hardware = dra7xxx_qspi_unprepare_xfer; + master->dev.of_node = pdev->dev.of_node; + master->bits_per_word_mask =BIT (32 -1 ) |BIT (16 -1 ) |BIT (8 -1 ); + +if (!of_property_read_u32 (np,"ti,spi-num-cs" ,&num_cs)) + master->num_chipselect = num_cs; + +platform_set_drvdata (pdev, master); + + qspi =spi_master_get_devdata (master); + qspi->master = master; + qspi->dev =&pdev->dev; + + r =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (r ==NULL ) { + ret = -ENODEV ; + goto free_master; + } + + irq =platform_get_irq (pdev,0 ); +if (irq<0 ) { +dev_err (&pdev->dev,"no irq resource?\n" );drivers/spi/spi-ti-qspi.c line 426
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+return irq; + } + +spin_lock_init (&qspi->lock); + + qspi->base =devm_ioremap_resource (&pdev->dev, r); +if (IS_ERR (qspi->base)) { + ret = -ENOMEM ; + goto free_master; + }why not use
devm_request_and_ioremap? Lock that region down so that no two drivers can manage the same region?Quoted 46 lines
drivers/spi/spi-ti-qspi.c new file +46
-0+ + ret =devm_request_threaded_irq (&pdev->dev, irq, dra7xxx_qspi_isr, + dra7xxx_qspi_threaded_isr,IRQF_NO_SUSPEND |IRQF_ONESHOT , +dev_name (&pdev->dev), qspi); +if (ret<0 ) { +dev_err (&pdev->dev,"Failed to register ISR for IRQ %d\n" , + irq); + goto free_master; + } + + qspi->fclk =devm_clk_get (&pdev->dev,"fck" ); +if (IS_ERR (qspi->fclk)) { + ret =PTR_ERR (qspi->fclk); +dev_err (&pdev->dev,"could not get clk: %d\n" , ret); + } + +init_completion (&qspi->word_complete); + +pm_runtime_use_autosuspend (&pdev->dev); +pm_runtime_set_autosuspend_delay (&pdev->dev,SPI_AUTOSUSPEND_TIMEOUT ); +pm_runtime_enable (&pdev->dev); + +if (!of_property_read_u32 (np,"spi-max-frequency" ,&max_freq)) + qspi->spi_max_frequency = max_freq; + + ret =spi_register_master (master); +if (ret) + goto free_master; + +return ret; + +free_master: +spi_master_put (master); +return ret; +} + +static int dra7xxx_qspi_remove (struct platform_device *pdev) +{ +struct dra7xxx_qspi *qspi =platform_get_drvdata (pdev); + +spi_unregister_master (qspi->master); + +return 0 ; +} + +static struct platform_driver dra7xxx_qspi_driver = {
Quoted 8 lines
drivers/spi/spi-ti-qspi.c line 479
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7
-0+ .probe = dra7xxx_qspi_probe, + .remove = dra7xxx_qspi_remove, + .driver = { + .name = "ti,dra7xxx-qspi", + .owner = THIS_MODULE, + .of_match_table = dra7xxx_qspi_match, + }no need for
pm_ops?
Yes, we need to, I thought of sending that as a seperate patch after this this one gets fixed.
Would you prefer that I add it here?
Quoted 6 lines
drivers/spi/spi-ti-qspi.c line 484
Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5
-0+}; + +module_platform_driver (dra7xxx_qspi_driver); + +MODULE_LICENSE ("GPL" );GPL V2?
Yes, will change.
Quoted 2 lines
Quoted 1 line
+MODULE_DESCRIPTION("TI QSPI controller driver");
MODULE_AUTHOR?
Will add.
Quoted 7 lines
Quoted 7 lines
Signature · 6 lines
1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv3 2/3] drivers: spi: Add qspi flash controller
In reply to Felipe BalbiQuoted 23 lines · Felipe Balbi
Hi,
Quoted 20 lines · Sourav Poddar
drivers/spi/spi-ti-qspi.c new file +20
-0+static inline unsigned long dra7xxx_readl (struct dra7xxx_qspi *qspi, +unsigned long reg) +{ +return readl (qspi->base + reg); +} + +static inline void dra7xxx_writel (struct dra7xxx_qspi *qspi, +unsigned long val,unsigned long reg) +{ +writel (val, qspi->base + reg); +} + +static inline unsigned long dra7xxx_readl_data (struct dra7xxx_qspi *qspi, +unsigned long reg,int wlen) +{ +switch (wlen) { +case 8 : +return readw (qspi->base + reg); +break ; +case 16 :
Quoted 9 lines
drivers/spi/spi-ti-qspi.c line 135
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7
-0+return readb (qspi->base + reg); +break ; +case 32 : +return readl (qspi->base + reg); +break ; +default : +return -1 ;return
-EINVAL? or some other error code ?
Ok.will change.
Quoted 26 lines
Quoted 26 lines
drivers/spi/spi-ti-qspi.c new file +26
-0+ } +} + +static inline void dra7xxx_writel_data (struct dra7xxx_qspi *qspi, +unsigned long val,unsigned long reg,int wlen) +{ +switch (wlen) { +case 8 : +writew (val, qspi->base + reg); +break ; +case 16 : +writeb (val, qspi->base + reg); +break ; +case 32 : +writeb (val, qspi->base + reg); +break ; +default : +dev_dbg (qspi->dev,"word lenght out of range" ); +break ; + } +} + +static int dra7xxx_qspi_setup (struct spi_device *spi) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (spi->master); +int clk_div =0 ;
Quoted 9 lines
drivers/spi/spi-ti-qspi.c line 168
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7
-0+u32 clk_ctrl_reg, clk_rate; + + clk_rate =clk_get_rate (qspi->fclk); + +if (!qspi->spi_max_frequency) { +dev_err (qspi->dev,"spi max frequency not defined\n" ); +return -1 ;same here
Ok.
Quoted 3 lines
drivers/spi/spi-ti-qspi.c line 169
Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1
-0+ }else this needs to have curly braces too, per CodingStyle
hmm..will change.
Quoted 33 lines
Quoted 33 lines
drivers/spi/spi-ti-qspi.c new file +33
-0+ clk_div = (clk_rate / qspi->spi_max_frequency) -1 ; + +dev_dbg (qspi->dev,"%s: hz: %d, clock divider %d\n" , __func__, + qspi->spi_max_frequency, clk_div); + +pm_runtime_get_sync (qspi->dev); + + clk_ctrl_reg =dra7xxx_readl (qspi,QSPI_SPI_CLOCK_CNTRL_REG ); + + clk_ctrl_reg&= ~QSPI_CLK_EN ; + +/* disable SCLK */ +dra7xxx_writel (qspi, clk_ctrl_reg,QSPI_SPI_CLOCK_CNTRL_REG ); + +if (clk_div<0 ) { +dev_dbg (qspi->dev,"%s: clock divider< 0, using /1 divider\n" , + __func__); + clk_div =1 ; + } + +if (clk_div>QSPI_CLK_DIV_MAX ) { +dev_dbg (qspi->dev,"%s: clock divider>%d , using /%d divider\n" , + __func__,QSPI_CLK_DIV_MAX ,QSPI_CLK_DIV_MAX +1 ); + clk_div =QSPI_CLK_DIV_MAX ; + } + +/* enable SCLK */ +dra7xxx_writel (qspi,QSPI_CLK_EN | clk_div,QSPI_SPI_CLOCK_CNTRL_REG ); + +pm_runtime_mark_last_busy (qspi->dev); +pm_runtime_put_autosuspend (qspi->dev); + +return 0 ;
Quoted 9 lines
drivers/spi/spi-ti-qspi.c line 209
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7
-0+} + +static int dra7xxx_qspi_prepare_xfer (struct spi_master *master) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); + +pm_runtime_get_sync (qspi->dev);not going to check return value ?
Will add.
Quoted 11 lines
drivers/spi/spi-ti-qspi.c line 219
Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9
-0+return 0 ; +} + +static int dra7xxx_qspi_unprepare_xfer (struct spi_master *master) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); + +pm_runtime_mark_last_busy (qspi->dev); +pm_runtime_put_autosuspend (qspi->dev);what about on these two ?
Yes, will add error checking.
Quoted 35 lines
Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6
-0+return 0 ; +} + +static int qspi_write_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +const u8 *txbuf;drivers/spi/spi-ti-qspi.c line 236
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+int wlen, count; + + count = t->len; + txbuf = t->tx_buf; + wlen = t->bits_per_word; + +while (count--) { +dev_dbg (qspi->dev,"tx cmd %08x dc %08x data %02x\n" , + qspi->cmd |QSPI_WR_SNGL , qspi->dc, *txbuf); +dra7xxx_writel (qspi,QSPI_WC_INT_EN ,QSPI_INTR_ENABLE_SET_REG );you should enable the interrupt as the last step. Also, why aren't you using frame interrupt ?
Quoted 16 lines
drivers/spi/spi-ti-qspi.c new file +16
-0+dra7xxx_writel_data (qspi, *txbuf++,QSPI_SPI_DATA_REG , wlen); +dra7xxx_writel (qspi, qspi->dc,QSPI_SPI_DC_REG ); +dra7xxx_writel (qspi, qspi->cmd |QSPI_WR_SNGL , +QSPI_SPI_CMD_REG ); +wait_for_completion (&qspi->word_complete); + } + +return 0 ; +} + +static int qspi_read_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +u8 *rxbuf; +int wlen, count; + + count = t->len;
Quoted 9 lines
drivers/spi/spi-ti-qspi.c line 259
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7
-0+ rxbuf = t->rx_buf; + wlen = t->bits_per_word; + +while (count--) { +dev_dbg (qspi->dev,"rx cmd %08x dc %08x\n" , + qspi->cmd |QSPI_RD_SNGL , qspi->dc); +dra7xxx_writel (qspi,QSPI_WC_INT_EN ,QSPI_INTR_ENABLE_SET_REG );ditto
hmm. will move this down.
Quoted 36 lines
Quoted 36 lines
drivers/spi/spi-ti-qspi.c new file +36
-0+dra7xxx_writel (qspi, qspi->dc,QSPI_SPI_DC_REG ); +dra7xxx_writel (qspi, qspi->cmd |QSPI_RD_SNGL , +QSPI_SPI_CMD_REG ); +wait_for_completion (&qspi->word_complete); + *rxbuf++ =dra7xxx_readl_data (qspi,QSPI_SPI_DATA_REG , wlen); +dev_dbg (qspi->dev,"rx done, read %02x\n" , *(rxbuf-1 )); + } + +return 0 ; +} + +static int qspi_transfer_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +if (t->tx_buf) +qspi_write_msg (qspi, t); +if (t->rx_buf) +qspi_read_msg (qspi, t); + +return 0 ; +} + +static int dra7xxx_qspi_start_transfer_one (struct spi_master *master, +struct spi_message *m) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); +struct spi_device *spi = m->spi; +struct spi_transfer *t; +int status =0 ; +int frame_length; + +/* setup device control reg */ + qspi->dc =0 ; + +if (spi->mode&SPI_CPHA ) + qspi->dc |=QSPI_CKPHA (spi->chip_select); +if (spi->mode&SPI_CPOL )
Quoted 8 lines
drivers/spi/spi-ti-qspi.c line 300
Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5
-0+ qspi->dc |=QSPI_CKPOL (spi->chip_select); +if (spi->mode&SPI_CS_HIGH ) + qspi->dc |=QSPI_CSPOL (spi->chip_select); + + frame_length = DIV_ROUND_UP(m->frame_length * spi->bits_per_word,why this multiplication ? Frame is not counted in bits but in number of words. Which means that
m->framelength/spi->bits_per_wordshould be enough.
Yes, got confused here. Will change.
Quoted 4 lines
Also, this actually brings up a mistake I made, if I read the TRM correclty this time, frame length is nothing but the
t->lenwhich renders patch 1 in this series unnecessary, my mistake.
If flen is t->len, then
1.) yes patch 1 is useles.
2.) frame interrupt will make more sense then.
Till now, we were using flen as sum of all transfers, because of
which
I was forced to check for word complete.
I will check on "flen" and will get back on frame interrupt with
experimental results.
Quoted 10 lines
drivers/spi/spi-ti-qspi.c line 308
Quoted 8 lines
drivers/spi/spi-ti-qspi.c new file +8
-0+ spi->bits_per_word); + + frame_length =clamp (frame_length,0 ,QSPI_FRAME_MAX ); + +/* setup command reg */ + qspi->cmd =0 ; + qspi->cmd |=QSPI_EN_CS (spi->chip_select); + qspi->cmd |=QSPI_FLEN (frame_length);right, right, so far so good...
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ list_for_each_entry(t,&m->transfers, transfer_list) { + qspi->cmd |= QSPI_WLEN(t->bits_per_word);sure about this ? according to TRM a write of 0 means 1 bit, 1, means 2 bits, 2 means 3 bits, etc... So this should be
t->bits_per_word- 1.
QSPI_WLEN is taking care of subtrating it by -1.
Quoted 39 lines
drivers/spi/spi-ti-qspi.c line 312
Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1
-0+ qspi->cmd |=QSPI_WC_CMD_INT_EN ;... but why are you still interrupting on every word ????
as I said before, we want to interrupt on every frame. one
spi_transferis one frame, if that frame has a length of 1MiB, I want to be interrupted after 1MiB.Quoted 19 lines
drivers/spi/spi-ti-qspi.c new file +19
-0+qspi_transfer_msg (qspi, t); + m->actual_length += t->len; + +if (list_is_last (&t->transfer_list,&m->transfers)) + goto out; + } + +out: + m->status = status; +spi_finalize_current_message (master); + +dra7xxx_writel (qspi, qspi->cmd |QSPI_INVAL ,QSPI_SPI_CMD_REG ); + +return status; +} + +static irqreturn_t dra7xxx_qspi_isr (int irq,void *dev_id) +{ +struct dra7xxx_qspi *qspi = dev_id;drivers/spi/spi-ti-qspi.c
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+u16 mask, stat; + +irqreturn_t ret =IRQ_HANDLED ; + +spin_lock (&qspi->lock); + + stat =dra7xxx_readl (qspi,QSPI_SPI_STATUS_REG ); + mask =dra7xxx_readl (qspi,QSPI_SPI_CMD_REG ); + +if ((stat&QSPI_WC )&& (mask&QSPI_WC_CMD_INT_EN ))this is wrong, everytime you want to handle another IRQ bit, you will have to update this line.
Quoted 4 lines
if (stat& mask)
sounds like it's enough
Yes, correct will change.
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
Mark Brown
maintainerRe: [PATCHv3 2/3] drivers: spi: Add qspi flash controller
In reply to Felipe BalbiQuoted 8 lines · Felipe Balbi
Quoted 2 lines
Looks like a case to use regmap?
Dumb q: why cant we useregmap_spi? worst case, you should be able toread regmap-spi and you'll see why it can't be used in this case.
regmap-spi is for SPI clients who want to read their register map through SPI commands. This is a driver for the SPI master which has its registers memory mapped.
Indeed, regmap-spi would be a client of this driver. Though there is regmap-mmio which may be helpful, on the other hand it's relatively heavyweight and SPI can be a bit performance sensitive so perhaps it's not awesome here. Russell did mention the idea of some helpers along a similar style though, they may be a good idea but nobody wrote them yet.
Re: [PATCHv3 2/3] drivers: spi: Add qspi flash controller
Quoted 11 lines · Mark Brown
Quoted 8 lines · Felipe Balbi
Quoted 2 lines
Looks like a case to use regmap?
Dumb q: why cant we useregmap_spi? worst case, you should be able toread regmap-spi and you'll see why it can't be used in this case.
regmap-spi is for SPI clients who want to read their register map through SPI commands. This is a driver for the SPI master which has its registers memory mapped.
Quoted 6 lines
Indeed, regmap-spi would be a client of this driver. Though there is regmap-mmio which may be helpful, on the other hand it's relatively heavyweight and SPI can be a bit performance sensitive so perhaps it's not awesome here. Russell did mention the idea of some helpers along a similar style though, they may be a good idea but nobody wrote them yet.
Fair enough. I am starting to see at least a second driver (internally for DRA7 IRQ/DMA crossbar) doing the same handling for different bit sized registers. maybe now is the time for us to create a lighter version of mmio. mmio at least the last I looked uses spinlocks and is fairly fast. But, I agree, when the client of regmap uses locks to protect operations of their own, regmap might be a bit of an overhead. that said, replicating regmap logic in the driver looks a bit weird and might allow the basis for other drivers to do the same as well as some users of mmio would consider themselves performance sensitive :(.
Signature · 9 lines
Regards, Nishanth Menon ------------------------------------------------------------------------------ See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
Re: [PATCHv3 2/3] drivers: spi: Add qspi flash controller
In reply to Felipe BalbiQuoted 34 lines · Felipe Balbi
Quoted 23 lines · Nishanth Menon
Quoted 23 lines
drivers/spi/spi-ti-qspi.c new file +23
-0+static int dra7xxx_qspi_start_transfer_one (struct spi_master *master, +struct spi_message *m) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); +struct spi_device *spi = m->spi; +struct spi_transfer *t; +int status =0 ; +int frame_length; + +/* setup device control reg */ + qspi->dc =0 ; + +if (spi->mode &SPI_CPHA ) + qspi->dc |=QSPI_CKPHA (spi->chip_select); +if (spi->mode &SPI_CPOL ) + qspi->dc |=QSPI_CKPOL (spi->chip_select); +if (spi->mode &SPI_CS_HIGH ) + qspi->dc |=QSPI_CSPOL (spi->chip_select); + + frame_length =DIV_ROUND_UP (m->frame_length * spi->bits_per_word, + spi->bits_per_word); + + frame_length =clamp (frame_length,0 ,QSPI_FRAME_MAX );Quoted 8 lines
drivers/spi/spi-ti-qspi.c line 309
Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6
-0+ +/* setup command reg */ + qspi->cmd =0 ; + qspi->cmd |=QSPI_EN_CS (spi->chip_select); + qspi->cmd |=QSPI_FLEN (frame_length); +how does one ensure pm runtime has not disabled clocks in background? e.g. long latency between transfers.
Quoted 4 lines
because pm_runtime_put*() has not been called ?
There's no way clocks will be gated until we kick the pm autosuspend timer, which is only done when the transfer is finished.
with this input and looking closer, I think I see what you are saying now:dra7xxx_qspi_prepare_xfer -> does a pm_runtime_get_sync dra7xxx_qspi_unprepare_xfer -> does a pm_runtime_mark_last_busy, pm_runtime_put_autosuspend
In between these calls, you have the remaining xfer calls going on.
we are assuming here that autosuspend timeout should be greater than the time to complete the worst case transfer.
Is that a valid assumption? would it not be better to mark_busy at other points? my thought is that considering a threaded isr, if by any chance you have a latency > autosuspend due to premption or some un-forseen event, this could crash badly, no? mark_busy will atleast ensure that runtime timer is reset. yep, we can also argue to converse, with a autosuspend delay set to appropriate value, we should not see this issue. pm_runtime_mark_last_busy() may be executed from interrupt context as well. At least going with "marks the last time of the device's busy state" we dont seem to mark them at all potential points?
ofcourse we can debate about how granular the marking should be, IMHO, though, I like autosuspend, however, I like autosuspend as a way to reduce transfer-to-transfer latency to re-enable the clocks. I however am a bit gittery about autosuspend kicking inside required time boundaries (especially considering the delay is upto user of the system).
Just my 2 cents.
[...]
Quoted 11 lines
Quoted 7 lines
drivers/spi/spi-ti-qspi.c line 426
Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5
-0+ qspi->base =devm_ioremap_resource (&pdev->dev, r); +if (IS_ERR (qspi->base)) { + ret = -ENOMEM ; + goto free_master; + }why not use
devm_request_and_ioremap? Lock that region down so that no two drivers can manage the same region?read
devm_ioremap_resource()and look at the git log for all the numerous drivers which were converted todevm_ioremap_resource()to find the reason.
my bad. fair enough.
Signature · 2 lines
Regards, Nishanth Menon
Mark Brown
maintainerRe: [PATCHv3 2/3] drivers: spi: Add qspi flash controller
Quoted 8 lines · Nishanth Menon
with this input and looking closer, I think I see what you are saying now:
dra7xxx_qspi_prepare_xfer-> does apm_runtime_get_syncdra7xxx_qspi_unprepare_xfer-> does apm_runtime_mark_last_busy,pm_runtime_put_autosuspendIn between these calls, you have the remaining xfer calls going on. we are assuming here that autosuspend timeout should be greater than the time to complete the worst case transfer.
No, autosuspend will do nothing so long as there are references to the device held. The effect of autosuspend is to delay power down after the last reference has been dropped, otherwise things run normally.
Re: [PATCHv3 2/3] drivers: spi: Add qspi flash controller
Quoted 7 lines · Mark Brown
Quoted 4 lines · Nishanth Menon
with this input and looking closer, I think I see what you are saying now:
dra7xxx_qspi_prepare_xfer-> does apm_runtime_get_syncdra7xxx_qspi_unprepare_xfer-> does apm_runtime_mark_last_busy,pm_runtime_put_autosuspend
Quoted 7 lines
Quoted 3 lines
In between these calls, you have the remaining xfer calls going on. we are assuming here that autosuspend timeout should be greater than the time to complete the worst case transfer.
No, autosuspend will do nothing so long as there are references to the device held. The effect of autosuspend is to delay power down after the last reference has been dropped, otherwise things run normally.
Thanks on the clarification. That concludes my confusion on the topic :).
Signature · 9 lines
Regards, Nishanth Menon ------------------------------------------------------------------------------ See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
Re: [PATCHv3 2/3] drivers: spi: Add qspi flash controller
In reply to Felipe BalbiQuoted 112 lines · Felipe Balbi
Hi,
Quoted 17 lines · Sourav Poddar
drivers/spi/spi-ti-qspi.c new file +17
-0+static inline unsigned long dra7xxx_readl (struct dra7xxx_qspi *qspi, +unsigned long reg) +{ +return readl (qspi->base + reg); +} + +static inline void dra7xxx_writel (struct dra7xxx_qspi *qspi, +unsigned long val,unsigned long reg) +{ +writel (val, qspi->base + reg); +} + +static inline unsigned long dra7xxx_readl_data (struct dra7xxx_qspi *qspi, +unsigned long reg,int wlen) +{ +switch (wlen) { +case 8 :drivers/spi/spi-ti-qspi.c line 135
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+return readw (qspi->base + reg); +break ; +case 16 : +return readb (qspi->base + reg); +break ; +case 32 : +return readl (qspi->base + reg); +break ; +default : +return -1 ;return
-EINVAL? or some other error code ?Quoted 23 lines
drivers/spi/spi-ti-qspi.c new file +23
-0+ } +} + +static inline void dra7xxx_writel_data (struct dra7xxx_qspi *qspi, +unsigned long val,unsigned long reg,int wlen) +{ +switch (wlen) { +case 8 : +writew (val, qspi->base + reg); +break ; +case 16 : +writeb (val, qspi->base + reg); +break ; +case 32 : +writeb (val, qspi->base + reg); +break ; +default : +dev_dbg (qspi->dev,"word lenght out of range" ); +break ; + } +} + +static int dra7xxx_qspi_setup (struct spi_device *spi)drivers/spi/spi-ti-qspi.c line 168
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (spi->master); +int clk_div =0 ; +u32 clk_ctrl_reg, clk_rate; + + clk_rate =clk_get_rate (qspi->fclk); + +if (!qspi->spi_max_frequency) { +dev_err (qspi->dev,"spi max frequency not defined\n" ); +return -1 ;same here
drivers/spi/spi-ti-qspi.c line 169
Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1
-0+ }else this needs to have curly braces too, per CodingStyle
Quoted 30 lines
drivers/spi/spi-ti-qspi.c new file +30
-0+ clk_div = (clk_rate / qspi->spi_max_frequency) -1 ; + +dev_dbg (qspi->dev,"%s: hz: %d, clock divider %d\n" , __func__, + qspi->spi_max_frequency, clk_div); + +pm_runtime_get_sync (qspi->dev); + + clk_ctrl_reg =dra7xxx_readl (qspi,QSPI_SPI_CLOCK_CNTRL_REG ); + + clk_ctrl_reg&= ~QSPI_CLK_EN ; + +/* disable SCLK */ +dra7xxx_writel (qspi, clk_ctrl_reg,QSPI_SPI_CLOCK_CNTRL_REG ); + +if (clk_div<0 ) { +dev_dbg (qspi->dev,"%s: clock divider< 0, using /1 divider\n" , + __func__); + clk_div =1 ; + } + +if (clk_div>QSPI_CLK_DIV_MAX ) { +dev_dbg (qspi->dev,"%s: clock divider>%d , using /%d divider\n" , + __func__,QSPI_CLK_DIV_MAX ,QSPI_CLK_DIV_MAX +1 ); + clk_div =QSPI_CLK_DIV_MAX ; + } + +/* enable SCLK */ +dra7xxx_writel (qspi,QSPI_CLK_EN | clk_div,QSPI_SPI_CLOCK_CNTRL_REG ); + +pm_runtime_mark_last_busy (qspi->dev);drivers/spi/spi-ti-qspi.c line 209
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+pm_runtime_put_autosuspend (qspi->dev); + +return 0 ; +} + +static int dra7xxx_qspi_prepare_xfer (struct spi_master *master) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); + +pm_runtime_get_sync (qspi->dev);not going to check return value ?
Quoted 11 lines
drivers/spi/spi-ti-qspi.c line 219
Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9
-0+return 0 ; +} + +static int dra7xxx_qspi_unprepare_xfer (struct spi_master *master) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); + +pm_runtime_mark_last_busy (qspi->dev); +pm_runtime_put_autosuspend (qspi->dev);what about on these two ?
Just realised this, pm_runtime_mark_last_busy does not need a check, it returns nothing.
Quoted 151 lines
Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6
-0+return 0 ; +} + +static int qspi_write_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +const u8 *txbuf;drivers/spi/spi-ti-qspi.c line 236
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+int wlen, count; + + count = t->len; + txbuf = t->tx_buf; + wlen = t->bits_per_word; + +while (count--) { +dev_dbg (qspi->dev,"tx cmd %08x dc %08x data %02x\n" , + qspi->cmd |QSPI_WR_SNGL , qspi->dc, *txbuf); +dra7xxx_writel (qspi,QSPI_WC_INT_EN ,QSPI_INTR_ENABLE_SET_REG );you should enable the interrupt as the last step. Also, why aren't you using frame interrupt ?
Quoted 13 lines
drivers/spi/spi-ti-qspi.c new file +13
-0+dra7xxx_writel_data (qspi, *txbuf++,QSPI_SPI_DATA_REG , wlen); +dra7xxx_writel (qspi, qspi->dc,QSPI_SPI_DC_REG ); +dra7xxx_writel (qspi, qspi->cmd |QSPI_WR_SNGL , +QSPI_SPI_CMD_REG ); +wait_for_completion (&qspi->word_complete); + } + +return 0 ; +} + +static int qspi_read_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +u8 *rxbuf;drivers/spi/spi-ti-qspi.c line 259
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+int wlen, count; + + count = t->len; + rxbuf = t->rx_buf; + wlen = t->bits_per_word; + +while (count--) { +dev_dbg (qspi->dev,"rx cmd %08x dc %08x\n" , + qspi->cmd |QSPI_RD_SNGL , qspi->dc); +dra7xxx_writel (qspi,QSPI_WC_INT_EN ,QSPI_INTR_ENABLE_SET_REG );ditto
Quoted 31 lines
drivers/spi/spi-ti-qspi.c new file +31
-0+dra7xxx_writel (qspi, qspi->dc,QSPI_SPI_DC_REG ); +dra7xxx_writel (qspi, qspi->cmd |QSPI_RD_SNGL , +QSPI_SPI_CMD_REG ); +wait_for_completion (&qspi->word_complete); + *rxbuf++ =dra7xxx_readl_data (qspi,QSPI_SPI_DATA_REG , wlen); +dev_dbg (qspi->dev,"rx done, read %02x\n" , *(rxbuf-1 )); + } + +return 0 ; +} + +static int qspi_transfer_msg (struct dra7xxx_qspi *qspi,struct spi_transfer *t) +{ +if (t->tx_buf) +qspi_write_msg (qspi, t); +if (t->rx_buf) +qspi_read_msg (qspi, t); + +return 0 ; +} + +static int dra7xxx_qspi_start_transfer_one (struct spi_master *master, +struct spi_message *m) +{ +struct dra7xxx_qspi *qspi =spi_master_get_devdata (master); +struct spi_device *spi = m->spi; +struct spi_transfer *t; +int status =0 ; +int frame_length; + +/* setup device control reg */ drivers/spi/spi-ti-qspi.c line 300
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+ qspi->dc =0 ; + +if (spi->mode&SPI_CPHA ) + qspi->dc |=QSPI_CKPHA (spi->chip_select); +if (spi->mode&SPI_CPOL ) + qspi->dc |=QSPI_CKPOL (spi->chip_select); +if (spi->mode&SPI_CS_HIGH ) + qspi->dc |=QSPI_CSPOL (spi->chip_select); + + frame_length = DIV_ROUND_UP(m->frame_length * spi->bits_per_word,why this multiplication ? Frame is not counted in bits but in number of words. Which means that
m->framelength/spi->bits_per_wordshould be enough.Also, this actually brings up a mistake I made, if I read the TRM correclty this time, frame length is nothing but the
t->lenwhich renders patch 1 in this series unnecessary, my mistake.drivers/spi/spi-ti-qspi.c line 308
Quoted 8 lines
drivers/spi/spi-ti-qspi.c new file +8
-0+ spi->bits_per_word); + + frame_length =clamp (frame_length,0 ,QSPI_FRAME_MAX ); + +/* setup command reg */ + qspi->cmd =0 ; + qspi->cmd |=QSPI_EN_CS (spi->chip_select); + qspi->cmd |=QSPI_FLEN (frame_length);right, right, so far so good...
Review
Quoted 2 lines
(quoted diff) +2
-0+ list_for_each_entry(t,&m->transfers, transfer_list) { + qspi->cmd |= QSPI_WLEN(t->bits_per_word);sure about this ? according to TRM a write of 0 means 1 bit, 1, means 2 bits, 2 means 3 bits, etc... So this should be
t->bits_per_word- 1.drivers/spi/spi-ti-qspi.c line 312
Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1
-0+ qspi->cmd |=QSPI_WC_CMD_INT_EN ;... but why are you still interrupting on every word ????
as I said before, we want to interrupt on every frame. one
spi_transferis one frame, if that frame has a length of 1MiB, I want to be interrupted after 1MiB.Quoted 19 lines
drivers/spi/spi-ti-qspi.c new file +19
-0+qspi_transfer_msg (qspi, t); + m->actual_length += t->len; + +if (list_is_last (&t->transfer_list,&m->transfers)) + goto out; + } + +out: + m->status = status; +spi_finalize_current_message (master); + +dra7xxx_writel (qspi, qspi->cmd |QSPI_INVAL ,QSPI_SPI_CMD_REG ); + +return status; +} + +static irqreturn_t dra7xxx_qspi_isr (int irq,void *dev_id) +{ +struct dra7xxx_qspi *qspi = dev_id;drivers/spi/spi-ti-qspi.c
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10
-0+u16 mask, stat; + +irqreturn_t ret =IRQ_HANDLED ; + +spin_lock (&qspi->lock); + + stat =dra7xxx_readl (qspi,QSPI_SPI_STATUS_REG ); + mask =dra7xxx_readl (qspi,QSPI_SPI_CMD_REG ); + +if ((stat&QSPI_WC )&& (mask&QSPI_WC_CMD_INT_EN ))this is wrong, everytime you want to handle another IRQ bit, you will have to update this line.
if (stat& mask)
sounds like it's enough