2020-07-14 07:53:27

by Clark Wang

[permalink] [raw]
Subject: [PATCH 0/5] Some bug fix for lpspi

Hi,

This series mainly fixes some recently discovered problems about CS for
LPSPI module.

And two patches to improve the reliability of the driver.

Regards,
Clark

Clark Wang (4):
spi: lpspi: fix the imbalance of runtime pm function call
spi: lpspi: add NULL check when probe device
spi: lpspi: fix kernel warning dump when probe fail after calling
spi_register
spi: lpspi: fix using CS discontinuously on i.MX8DXLEVK

Fabrice Goucem (1):
spi: lpspi: handle EPROBE_DEFER when get cs-gpios number

drivers/spi/spi-fsl-lpspi.c | 52 +++++++++++++++++++++++++++++--------
1 file changed, 41 insertions(+), 11 deletions(-)

--
2.17.1


2020-07-14 07:53:30

by Clark Wang

[permalink] [raw]
Subject: [PATCH 1/5] spi: lpspi: fix the imbalance of runtime pm function call

Call the put function after probe successfully. Otherwise, the lpspi
module will keep active status until the first spi transfer called.

Disable runtime pm when probe fails. There is no need to active runtime
pm after probe failed.

Signed-off-by: Clark Wang <[email protected]>
---
drivers/spi/spi-fsl-lpspi.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index 1552b28b9515..a1555bbc5e5a 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -954,10 +954,15 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
if (ret < 0)
dev_err(&pdev->dev, "dma setup error %d, use pio\n", ret);

+ pm_runtime_mark_last_busy(fsl_lpspi->dev);
+ pm_runtime_put_autosuspend(fsl_lpspi->dev);
+
return 0;

out_pm_get:
- pm_runtime_put_noidle(fsl_lpspi->dev);
+ pm_runtime_dont_use_autosuspend(fsl_lpspi->dev);
+ pm_runtime_put_sync(fsl_lpspi->dev);
+ pm_runtime_disable(fsl_lpspi->dev);
out_controller_put:
spi_controller_put(controller);

--
2.17.1

2020-07-14 07:53:36

by Clark Wang

[permalink] [raw]
Subject: [PATCH 4/5] spi: lpspi: handle EPROBE_DEFER when get cs-gpios number

From: Fabrice Goucem <[email protected]>

If SPI is probed before the GPIO driver, it may miss the cs-gpio
configuration in dtb.
Add defer probe handler to wait GPIO driver probe.

Signed-off-by: Fabrice Goucem <[email protected]>
Signed-off-by: Clark Wang <[email protected]>
---
drivers/spi/spi-fsl-lpspi.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index 6fb77f0f657a..05b6ecd82974 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -887,6 +887,11 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
for (i = 0; i < controller->num_chipselect; i++) {
int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);

+ if (cs_gpio == -EPROBE_DEFER) {
+ ret = -EPROBE_DEFER;
+ goto out_controller_put;
+ }
+
if (!gpio_is_valid(cs_gpio) && lpspi_platform_info)
cs_gpio = lpspi_platform_info->chipselect[i];

--
2.17.1

2020-07-14 07:53:44

by Clark Wang

[permalink] [raw]
Subject: [PATCH 3/5] spi: lpspi: fix kernel warning dump when probe fail after calling spi_register

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.

Meanwhile, in order to keep the multi-CS working, add
"fsl,spi-num-chipselects" check.

Signed-off-by: Clark Wang <[email protected]>
---
drivers/spi/spi-fsl-lpspi.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index ca43d93adf30..6fb77f0f657a 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -837,7 +837,7 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
struct spi_imx_master *lpspi_platform_info =
dev_get_platdata(&pdev->dev);
struct resource *res;
- int i, ret, irq;
+ int i, ret, irq, num_cs;
u32 temp;
bool is_slave;

@@ -859,6 +859,16 @@ static int fsl_lpspi_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, controller);

+ ret = of_property_read_u32(np, "fsl,spi-num-chipselects", &num_cs);
+ if (ret < 0) {
+ if (lpspi_platform_info) {
+ num_cs = lpspi_platform_info->num_chipselect;
+ controller->num_chipselect = num_cs;
+ }
+ } else {
+ controller->num_chipselect = num_cs;
+ }
+
fsl_lpspi = spi_controller_get_devdata(controller);
fsl_lpspi->dev = &pdev->dev;
fsl_lpspi->is_slave = is_slave;
@@ -873,12 +883,6 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
controller->bus_num = pdev->id;
controller->slave_abort = fsl_lpspi_slave_abort;

- ret = devm_spi_register_controller(&pdev->dev, controller);
- if (ret < 0) {
- dev_err(&pdev->dev, "spi_register_controller error.\n");
- goto out_controller_put;
- }
-
if (!fsl_lpspi->is_slave) {
for (i = 0; i < controller->num_chipselect; i++) {
int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
@@ -959,6 +963,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

2020-07-14 07:55:36

by Clark Wang

[permalink] [raw]
Subject: [PATCH 2/5] spi: lpspi: add NULL check when probe device

Add a NULL check for device node and lpspi_platform_info when lpspi
device probe.

Signed-off-by: Clark Wang <[email protected]>
---
drivers/spi/spi-fsl-lpspi.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index a1555bbc5e5a..ca43d93adf30 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -841,6 +841,11 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
u32 temp;
bool is_slave;

+ if (!np && !lpspi_platform_info) {
+ dev_err(&pdev->dev, "can't get the platform data\n");
+ return -EINVAL;
+ }
+
is_slave = of_property_read_bool((&pdev->dev)->of_node, "spi-slave");
if (is_slave)
controller = spi_alloc_slave(&pdev->dev,
--
2.17.1

2020-07-14 07:56:08

by Clark Wang

[permalink] [raw]
Subject: [PATCH 5/5] spi: lpspi: fix using CS discontinuously on i.MX8DXLEVK

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 <[email protected]>
---
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 05b6ecd82974..3f722f8f143f 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -101,6 +101,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;
@@ -276,10 +277,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.
@@ -440,7 +440,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;
@@ -872,6 +875,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

2020-07-14 08:49:36

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 2/5] spi: lpspi: add NULL check when probe device


> +++ b/drivers/spi/spi-fsl-lpspi.c
> @@ -841,6 +841,11 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
> u32 temp;
> bool is_slave;
>
> + if (!np && !lpspi_platform_info) {
> + dev_err(&pdev->dev, "can't get the platform data\n");
> + return -EINVAL;
> + }


How do you think about to combine these null pointer checks by the logical
operator “or” instead of “and”?

Regards,
Markus

2020-07-14 11:40:16

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 3/5] spi: lpspi: fix kernel warning dump when probe fail after calling spi_register

On Tue, Jul 14, 2020 at 03:52:49PM +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


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.


Attachments:
(No filename) (1.01 kB)
signature.asc (499.00 B)
Download all attachments

2020-07-21 22:48:18

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 3/5] spi: lpspi: fix kernel warning dump when probe fail after calling spi_register

On Tue, Jul 14, 2020 at 03:52:49PM +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.

This doesn't apply against current code, please check and resend.

> [ 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


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.


Attachments:
(No filename) (1.07 kB)
signature.asc (499.00 B)
Download all attachments

2020-07-21 23:46:33

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 2/5] spi: lpspi: add NULL check when probe device

On Tue, Jul 14, 2020 at 03:52:48PM +0800, Clark Wang wrote:
> Add a NULL check for device node and lpspi_platform_info when lpspi
> device probe.

This has build problems, I guess there's been a context change that's
caused issues along with causing the later patches to not apply:

/mnt/kernel/drivers/spi/spi-fsl-lpspi.c: In function 'fsl_lpspi_probe':
/mnt/kernel/drivers/spi/spi-fsl-lpspi.c:824:7: error: 'np' undeclared (first use in this function); did you mean 'up'?
if (!np && !lpspi_platform_info) {
^~
up
/mnt/kernel/drivers/spi/spi-fsl-lpspi.c:824:7: note: each undeclared identifier is reported only once for each function it appears in
/mnt/kernel/drivers/spi/spi-fsl-lpspi.c:824:14: error: 'lpspi_platform_info' undeclared (first use in this function); did you mean 'spi_board_info'?
if (!np && !lpspi_platform_info) {
^~~~~~~~~~~~~~~~~~~
spi_board_info


Attachments:
(No filename) (931.00 B)
signature.asc (499.00 B)
Download all attachments

2020-07-22 13:47:12

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 0/5] Some bug fix for lpspi

On Tue, 14 Jul 2020 15:52:46 +0800, Clark Wang wrote:
> This series mainly fixes some recently discovered problems about CS for
> LPSPI module.
>
> And two patches to improve the reliability of the driver.
>
> Regards,
> Clark
>
> [...]

Applied to

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

Thanks!

[1/5] spi: lpspi: fix the imbalance of runtime pm function call
commit: 2abbae5a0e4e1d81016f56a403b2daadfee314c3
[2/5] spi: lpspi: add NULL check when probe device
(no commit info)
[3/5] spi: lpspi: fix kernel warning dump when probe fail after calling spi_register
(no commit info)
[4/5] spi: lpspi: handle EPROBE_DEFER when get cs-gpios number
(no commit info)
[5/5] spi: lpspi: fix using CS discontinuously on i.MX8DXLEVK
(no commit info)

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