diff mbox series

spi: imx: add 16/32 bits per word support for slave mode

Message ID 20210408103347.244313-1-xiaoning.wang@nxp.com
State New
Headers show
Series spi: imx: add 16/32 bits per word support for slave mode | expand

Commit Message

Clark Wang April 8, 2021, 10:33 a.m. UTC
Enable 16/32 bits per word support for spi-imx slave mode.
It only support 8 bits per word in slave mode before.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
---
 drivers/spi/spi-imx.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Mark Brown April 8, 2021, 1:43 p.m. UTC | #1
On Thu, Apr 08, 2021 at 06:33:47PM +0800, Clark Wang wrote:
> When some drivers use spi to send data, spi_transfer->speed_hz is
> not assigned. If spidev->max_speed_hz is not assigned as well, it
> will cause an error in configuring the clock.

> Add a check for these two values before configuring the clock. An
> error will be returned when they are not assigned.

For the case where the transfer speed is not set __spi_validate() will
take the controller's maximum speed so the controller should just be
able to unconditionally use the transfer's speed.  Your issue is
therefore that the controllers are sometimes not setting a maximum
speed which this doesn't seem to fix AFAICT?  I'd expect the driver to
be able to work one out based on the input clock.

>  struct spi_imx_devtype_data {
>  	void (*intctrl)(struct spi_imx_data *, int);
>  	int (*prepare_message)(struct spi_imx_data *, struct spi_message *);
> -	int (*prepare_transfer)(struct spi_imx_data *, struct spi_device *,
> -				struct spi_transfer *);
> +	int (*prepare_transfer)(struct spi_imx_data *, struct spi_device *);
>  	void (*trigger)(struct spi_imx_data *);
>  	int (*rx_available)(struct spi_imx_data *);
>  	void (*reset)(struct spi_imx_data *);

This seems to be a fairly big and surprising refactoring for the
described change.  It's quite hard to tie the change to the changelog.
Mark Brown April 8, 2021, 2:05 p.m. UTC | #2
On Thu, Apr 08, 2021 at 06:33:47PM +0800, Clark Wang wrote:
> When some drivers use spi to send data, spi_transfer->speed_hz is
> not assigned. If spidev->max_speed_hz is not assigned as well, it
> will cause an error in configuring the clock.

Please don't send new patches in reply to other threads, this makes it
harder to follow what current versions of things are and causes problems
for tools.
Mark Brown April 9, 2021, 4:22 p.m. UTC | #3
On Thu, 8 Apr 2021 18:33:47 +0800, Clark Wang wrote:
> When some drivers use spi to send data, spi_transfer->speed_hz is

> not assigned. If spidev->max_speed_hz is not assigned as well, it

> will cause an error in configuring the clock.

> Add a check for these two values before configuring the clock. An

> error will be returned when they are not assigned.


Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: imx: add a check for speed_hz before calculating the clock
      commit: 4df2f5e1372e9eec8f9e1b4a3025b9be23487d36

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
Tomas Melin May 24, 2021, 8:25 a.m. UTC | #4
Hi,

On 4/8/21 1:33 PM, Clark Wang wrote:
> Enable 16/32 bits per word support for spi-imx slave mode.

> It only support 8 bits per word in slave mode before.

>

> Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>

> Reviewed-by: Haibo Chen <haibo.chen@nxp.com>

> ---

>   drivers/spi/spi-imx.c | 13 +++++++++++--

>   1 file changed, 11 insertions(+), 2 deletions(-)

>

> diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c

> index 4fe767acaca7..24ba7ab1b05d 100644

> --- a/drivers/spi/spi-imx.c

> +++ b/drivers/spi/spi-imx.c

> @@ -386,7 +386,12 @@ static void spi_imx_buf_tx_swap(struct spi_imx_data *spi_imx)

>   

>   static void mx53_ecspi_rx_slave(struct spi_imx_data *spi_imx)

>   {

> -	u32 val = be32_to_cpu(readl(spi_imx->base + MXC_CSPIRXDATA));

> +	u32 val = readl(spi_imx->base + MXC_CSPIRXDATA);

> +

> +	if (spi_imx->bits_per_word <= 8)

> +		val = be32_to_cpu(val);

> +	else if (spi_imx->bits_per_word <= 16)

> +		val = (val << 16) | (val >> 16);


Would it be good to use available

     spi_imx_buf_rx_u32

     spi_imx_buf_rx_u16

     spi_imx_buf_rx_u8

helpers here?

thanks,

Tomas


>   

>   	if (spi_imx->rx_buf) {

>   		int n_bytes = spi_imx->slave_burst % sizeof(val);

> @@ -415,7 +420,11 @@ static void mx53_ecspi_tx_slave(struct spi_imx_data *spi_imx)

>   	if (spi_imx->tx_buf) {

>   		memcpy(((u8 *)&val) + sizeof(val) - n_bytes,

>   		       spi_imx->tx_buf, n_bytes);

> -		val = cpu_to_be32(val);

> +		if (spi_imx->bits_per_word <= 8)

> +			val = cpu_to_be32(val);

> +		else if (spi_imx->bits_per_word <= 16)

> +			val = (val << 16) | (val >> 16);

> +

>   		spi_imx->tx_buf += n_bytes;

>   	}

>
diff mbox series

Patch

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 4fe767acaca7..24ba7ab1b05d 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -386,7 +386,12 @@  static void spi_imx_buf_tx_swap(struct spi_imx_data *spi_imx)
 
 static void mx53_ecspi_rx_slave(struct spi_imx_data *spi_imx)
 {
-	u32 val = be32_to_cpu(readl(spi_imx->base + MXC_CSPIRXDATA));
+	u32 val = readl(spi_imx->base + MXC_CSPIRXDATA);
+
+	if (spi_imx->bits_per_word <= 8)
+		val = be32_to_cpu(val);
+	else if (spi_imx->bits_per_word <= 16)
+		val = (val << 16) | (val >> 16);
 
 	if (spi_imx->rx_buf) {
 		int n_bytes = spi_imx->slave_burst % sizeof(val);
@@ -415,7 +420,11 @@  static void mx53_ecspi_tx_slave(struct spi_imx_data *spi_imx)
 	if (spi_imx->tx_buf) {
 		memcpy(((u8 *)&val) + sizeof(val) - n_bytes,
 		       spi_imx->tx_buf, n_bytes);
-		val = cpu_to_be32(val);
+		if (spi_imx->bits_per_word <= 8)
+			val = cpu_to_be32(val);
+		else if (spi_imx->bits_per_word <= 16)
+			val = (val << 16) | (val >> 16);
+
 		spi_imx->tx_buf += n_bytes;
 	}