Linux-SPI Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH V2 0/4] Some bug fix for lpspi
@ 2020-07-27  3:14 Clark Wang
  2020-07-27  3:14 ` [PATCH V2 1/4] spi: lpspi: Fix kernel warning dump when probe fail after calling spi_register Clark Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Clark Wang @ 2020-07-27  3:14 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, linux-kernel

Hi,

This patchset mainly fixes some recently discovered problems about CS for
LPSPI module on i.MX8DXLEVK.

Add the dt-bindings description for the new property.

Clark Wang (4):
  spi: lpspi: Fix kernel warning dump when probe fail after calling
    spi_register
  spi: lpspi: remove unused fsl_lpspi->chipselect
  spi: lpspi: fix using CS discontinuously on i.MX8DXLEVK
  dt-bindings: lpspi: New property in document DT bindings for LPSPI

 .../bindings/spi/spi-fsl-lpspi.yaml           |  7 ++++++
 drivers/spi/spi-fsl-lpspi.c                   | 25 +++++++++++--------
 2 files changed, 21 insertions(+), 11 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH V2 1/4] spi: lpspi: Fix kernel warning dump when probe fail after calling spi_register
  2020-07-27  3:14 [PATCH V2 0/4] Some bug fix for lpspi Clark Wang
@ 2020-07-27  3:14 ` Clark Wang
  2020-07-27 11:11   ` Mark Brown
  2020-07-27  3:14 ` [PATCH V2 2/4] spi: lpspi: remove unused fsl_lpspi->chipselect Clark Wang
  2020-07-27  3:14 ` [PATCH V2 3/4] spi: lpspi: fix using CS discontinuously on i.MX8DXLEVK Clark Wang
  2 siblings, 1 reply; 6+ messages in thread
From: Clark Wang @ 2020-07-27  3:14 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, linux-kernel

Calling devm_spi_register_controller() too early will cause problem.
When probe failed occurs after calling devm_spi_register_controller(),
the call of spi_controller_put() will trigger the following warning dump.

[    2.092138] ------------[ cut here ]------------
[    2.096876] kernfs: can not remove 'uevent', no directory
[    2.102440] WARNING: CPU: 0 PID: 181 at fs/kernfs/dir.c:1503 kernfs_remove_by_name_ns+0xa0/0xb0
[    2.111142] Modules linked in:
[    2.114207] CPU: 0 PID: 181 Comm: kworker/0:7 Not tainted 5.4.24-05024-g775c6e8a738c-dirty #1314
[    2.122991] Hardware name: Freescale i.MX8DXL EVK (DT)
[    2.128141] Workqueue: events deferred_probe_work_func
[    2.133281] pstate: 60000005 (nZCv daif -PAN -UAO)
[    2.138076] pc : kernfs_remove_by_name_ns+0xa0/0xb0
[    2.142958] lr : kernfs_remove_by_name_ns+0xa0/0xb0
[    2.147837] sp : ffff8000122bba70
[    2.151145] x29: ffff8000122bba70 x28: ffff8000119d6000
[    2.156462] x27: 0000000000000000 x26: ffff800011edbce8
[    2.161779] x25: 0000000000000000 x24: ffff00003ae4f700
[    2.167096] x23: ffff000010184c10 x22: ffff00003a3d6200
[    2.172412] x21: ffff800011a464a8 x20: ffff000010126a68
[    2.177729] x19: ffff00003ae5c800 x18: 000000000000000e
[    2.183046] x17: 0000000000000001 x16: 0000000000000019
[    2.188362] x15: 0000000000000004 x14: 000000000000004c
[    2.193679] x13: 0000000000000000 x12: 0000000000000001
[    2.198996] x11: 0000000000000000 x10: 00000000000009c0
[    2.204313] x9 : ffff8000122bb7a0 x8 : ffff00003a3d6c20
[    2.209630] x7 : ffff00003a3d6380 x6 : 0000000000000001
[    2.214946] x5 : 0000000000000001 x4 : ffff00003a05eb18
[    2.220263] x3 : 0000000000000005 x2 : ffff8000119f1c48
[    2.225580] x1 : 2bcbda323bf5a800 x0 : 0000000000000000
[    2.230898] Call trace:
[    2.233345]  kernfs_remove_by_name_ns+0xa0/0xb0
[    2.237879]  sysfs_remove_file_ns+0x14/0x20
[    2.242065]  device_del+0x12c/0x348
[    2.245555]  device_unregister+0x14/0x30
[    2.249492]  spi_unregister_controller+0xac/0x120
[    2.254201]  devm_spi_unregister+0x10/0x18
[    2.258304]  release_nodes+0x1a8/0x220
[    2.262055]  devres_release_all+0x34/0x58
[    2.266069]  really_probe+0x1b8/0x318
[    2.269733]  driver_probe_device+0x54/0xe8
[    2.273833]  __device_attach_driver+0x80/0xb8
[    2.278194]  bus_for_each_drv+0x74/0xc0
[    2.282034]  __device_attach+0xdc/0x138
[    2.285876]  device_initial_probe+0x10/0x18
[    2.290063]  bus_probe_device+0x90/0x98
[    2.293901]  deferred_probe_work_func+0x64/0x98
[    2.298442]  process_one_work+0x198/0x320
[    2.302451]  worker_thread+0x1f0/0x420
[    2.306208]  kthread+0xf0/0x120
[    2.309352]  ret_from_fork+0x10/0x18
[    2.312927] ---[ end trace 58abcdfae01bd3c7 ]---

So put this function at the end of the probe sequence.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
---
Changes:
V2:
 - redo the patch base on the new code.
---
 drivers/spi/spi-fsl-lpspi.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index a4a42e85e132..b0a1bb62f10a 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -850,12 +850,6 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
 	if (!fsl_lpspi->is_slave)
 		controller->use_gpio_descriptors = true;
 
-	ret = devm_spi_register_controller(&pdev->dev, controller);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "spi_register_controller error.\n");
-		goto out_controller_put;
-	}
-
 	init_completion(&fsl_lpspi->xfer_done);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -913,6 +907,12 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
 	if (ret < 0)
 		dev_err(&pdev->dev, "dma setup error %d, use pio\n", ret);
 
+	ret = devm_spi_register_controller(&pdev->dev, controller);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "spi_register_controller error.\n");
+		goto out_pm_get;
+	}
+
 	pm_runtime_mark_last_busy(fsl_lpspi->dev);
 	pm_runtime_put_autosuspend(fsl_lpspi->dev);
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH V2 2/4] spi: lpspi: remove unused fsl_lpspi->chipselect
  2020-07-27  3:14 [PATCH V2 0/4] Some bug fix for lpspi Clark Wang
  2020-07-27  3:14 ` [PATCH V2 1/4] spi: lpspi: Fix kernel warning dump when probe fail after calling spi_register Clark Wang
@ 2020-07-27  3:14 ` Clark Wang
  2020-07-27  3:14 ` [PATCH V2 3/4] spi: lpspi: fix using CS discontinuously on i.MX8DXLEVK Clark Wang
  2 siblings, 0 replies; 6+ messages in thread
From: Clark Wang @ 2020-07-27  3:14 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, linux-kernel

The cs-gpio is initailized by spi_get_gpio_descs() now. Remove the
chipselect.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
---
Changes:
V2:
 - New patch added in the v2 patchset.
---
 drivers/spi/spi-fsl-lpspi.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index b0a1bb62f10a..1e426884ac37 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -119,8 +119,6 @@ struct fsl_lpspi_data {
 	bool usedma;
 	struct completion dma_rx_completion;
 	struct completion dma_tx_completion;
-
-	int chipselect[];
 };
 
 static const struct of_device_id fsl_lpspi_dt_ids[] = {
-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH V2 3/4] spi: lpspi: fix using CS discontinuously on i.MX8DXLEVK
  2020-07-27  3:14 [PATCH V2 0/4] Some bug fix for lpspi Clark Wang
  2020-07-27  3:14 ` [PATCH V2 1/4] spi: lpspi: Fix kernel warning dump when probe fail after calling spi_register Clark Wang
  2020-07-27  3:14 ` [PATCH V2 2/4] spi: lpspi: remove unused fsl_lpspi->chipselect Clark Wang
@ 2020-07-27  3:14 ` Clark Wang
  2 siblings, 0 replies; 6+ messages in thread
From: Clark Wang @ 2020-07-27  3:14 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, linux-kernel

SPI common code does not support using CS discontinuously for now.
However, i.MX8DXL-EVK only uses CS1 without CS0. Therefore, add a flag
is_only_cs1 to set the correct TCR[PCS].

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
---
Changes:
V2:
 - No changes.
---
 drivers/spi/spi-fsl-lpspi.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index 1e426884ac37..85a5c952389a 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -98,6 +98,7 @@ struct fsl_lpspi_data {
 	struct clk *clk_ipg;
 	struct clk *clk_per;
 	bool is_slave;
+	bool is_only_cs1;
 	bool is_first_byte;
 
 	void *rx_buf;
@@ -257,10 +258,9 @@ static void fsl_lpspi_set_cmd(struct fsl_lpspi_data *fsl_lpspi)
 
 	temp |= fsl_lpspi->config.bpw - 1;
 	temp |= (fsl_lpspi->config.mode & 0x3) << 30;
+	temp |= (fsl_lpspi->config.chip_select & 0x3) << 24;
 	if (!fsl_lpspi->is_slave) {
 		temp |= fsl_lpspi->config.prescale << 27;
-		temp |= (fsl_lpspi->config.chip_select & 0x3) << 24;
-
 		/*
 		 * Set TCR_CONT will keep SS asserted after current transfer.
 		 * For the first transfer, clear TCR_CONTC to assert SS.
@@ -421,7 +421,10 @@ static int fsl_lpspi_setup_transfer(struct spi_controller *controller,
 	fsl_lpspi->config.mode = spi->mode;
 	fsl_lpspi->config.bpw = t->bits_per_word;
 	fsl_lpspi->config.speed_hz = t->speed_hz;
-	fsl_lpspi->config.chip_select = spi->chip_select;
+	if (fsl_lpspi->is_only_cs1)
+		fsl_lpspi->config.chip_select = 1;
+	else
+		fsl_lpspi->config.chip_select = spi->chip_select;
 
 	if (!fsl_lpspi->config.speed_hz)
 		fsl_lpspi->config.speed_hz = spi->max_speed_hz;
@@ -835,6 +838,8 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
 	fsl_lpspi = spi_controller_get_devdata(controller);
 	fsl_lpspi->dev = &pdev->dev;
 	fsl_lpspi->is_slave = is_slave;
+	fsl_lpspi->is_only_cs1 = of_property_read_bool((&pdev->dev)->of_node,
+						"fsl,spi-only-use-cs1-sel");
 
 	controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32);
 	controller->transfer_one = fsl_lpspi_transfer_one;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V2 1/4] spi: lpspi: Fix kernel warning dump when probe fail after calling spi_register
  2020-07-27  3:14 ` [PATCH V2 1/4] spi: lpspi: Fix kernel warning dump when probe fail after calling spi_register Clark Wang
@ 2020-07-27 11:11   ` Mark Brown
  2020-07-31  2:01     ` [EXT] " Clark Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2020-07-27 11:11 UTC (permalink / raw)
  To: Clark Wang; +Cc: linux-spi, linux-kernel


[-- Attachment #1: Type: text/plain, Size: 1153 bytes --]

On Mon, Jul 27, 2020 at 11:14:46AM +0800, Clark Wang wrote:
> Calling devm_spi_register_controller() too early will cause problem.
> When probe failed occurs after calling devm_spi_register_controller(),
> the call of spi_controller_put() will trigger the following warning dump.
> 
> [    2.092138] ------------[ cut here ]------------
> [    2.096876] kernfs: can not remove 'uevent', no directory
> [    2.102440] WARNING: CPU: 0 PID: 181 at fs/kernfs/dir.c:1503 kernfs_remove_by_name_ns+0xa0/0xb0
> [    2.111142] Modules linked in:
> [    2.114207] CPU: 0 PID: 181 Comm: kworker/0:7 Not tainted 5.4.24-05024-g775c6e8a738c-dirty #1314
> [    2.122991] Hardware name: Freescale i.MX8DXL EVK (DT)
> [    2.128141] Workqueue: events deferred_probe_work_func

Please think hard before including complete backtraces in upstream
reports, they are very large and contain almost no useful information
relative to their size so often obscure the relevant content in your
message. If part of the backtrace is usefully illustrative (it often is
for search engines if nothing else) then it's usually better to pull out
the relevant sections.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [EXT] Re: [PATCH V2 1/4] spi: lpspi: Fix kernel warning dump when probe fail after calling spi_register
  2020-07-27 11:11   ` Mark Brown
@ 2020-07-31  2:01     ` Clark Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Clark Wang @ 2020-07-31  2:01 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel


> -----Original Message-----
> From: Mark Brown <broonie@kernel.org>
> Sent: Monday, July 27, 2020 19:11
> To: Clark Wang <xiaoning.wang@nxp.com>
> Cc: linux-spi@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: [EXT] Re: [PATCH V2 1/4] spi: lpspi: Fix kernel warning dump when
> probe fail after calling spi_register
> 
> On Mon, Jul 27, 2020 at 11:14:46AM +0800, Clark Wang wrote:
> > Calling devm_spi_register_controller() too early will cause problem.
> > When probe failed occurs after calling devm_spi_register_controller(),
> > the call of spi_controller_put() will trigger the following warning dump.
> >
> > [    2.092138] ------------[ cut here ]------------
> > [    2.096876] kernfs: can not remove 'uevent', no directory
> > [    2.102440] WARNING: CPU: 0 PID: 181 at fs/kernfs/dir.c:1503
> kernfs_remove_by_name_ns+0xa0/0xb0
> > [    2.111142] Modules linked in:
> > [    2.114207] CPU: 0 PID: 181 Comm: kworker/0:7 Not tainted 5.4.24-05024-
> g775c6e8a738c-dirty #1314
> > [    2.122991] Hardware name: Freescale i.MX8DXL EVK (DT)
> > [    2.128141] Workqueue: events deferred_probe_work_func
> 
> Please think hard before including complete backtraces in upstream reports,
> they are very large and contain almost no useful information relative to their
> size so often obscure the relevant content in your message. If part of the
> backtrace is usefully illustrative (it often is for search engines if nothing else)
> then it's usually better to pull out the relevant sections.

Hi Mark,

Thank you very much for reminding. 
I will remove the redundant part when I meet similar situations in the future. 😊

Best Regards,
Clark Wang

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27  3:14 [PATCH V2 0/4] Some bug fix for lpspi Clark Wang
2020-07-27  3:14 ` [PATCH V2 1/4] spi: lpspi: Fix kernel warning dump when probe fail after calling spi_register Clark Wang
2020-07-27 11:11   ` Mark Brown
2020-07-31  2:01     ` [EXT] " Clark Wang
2020-07-27  3:14 ` [PATCH V2 2/4] spi: lpspi: remove unused fsl_lpspi->chipselect Clark Wang
2020-07-27  3:14 ` [PATCH V2 3/4] spi: lpspi: fix using CS discontinuously on i.MX8DXLEVK Clark Wang

Linux-SPI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-spi/0 linux-spi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-spi linux-spi/ https://lore.kernel.org/linux-spi \
		linux-spi@vger.kernel.org
	public-inbox-index linux-spi

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-spi


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git