Skip to content

Commit c2a905a

Browse files
committed
Merge tag 'spi-fix-v6.11-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
Pull spi fixes from Mark Brown: "A small collection of fixes here, all driver specific and none of them too serious. For whatever reason runtime PM seems to have been causing a bunch of issues recently" * tag 'spi-fix-v6.11-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: spi: pxa2xx: Move PM runtime handling to the glue drivers spi: pxa2xx: Do not override dev->platform_data on probe spi: spi-fsl-lpspi: limit PRESCALE bit in TCR register spi: spi-cadence-quadspi: Fix OSPI NOR failures during system resume spi: zynqmp-gqspi: Scale timeout by data size
2 parents 3d5f968 + e17465f commit c2a905a

File tree

7 files changed

+106
-33
lines changed

7 files changed

+106
-33
lines changed

drivers/spi/spi-cadence-quadspi.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2000,13 +2000,25 @@ static int cqspi_runtime_resume(struct device *dev)
20002000
static int cqspi_suspend(struct device *dev)
20012001
{
20022002
struct cqspi_st *cqspi = dev_get_drvdata(dev);
2003+
int ret;
20032004

2004-
return spi_controller_suspend(cqspi->host);
2005+
ret = spi_controller_suspend(cqspi->host);
2006+
if (ret)
2007+
return ret;
2008+
2009+
return pm_runtime_force_suspend(dev);
20052010
}
20062011

20072012
static int cqspi_resume(struct device *dev)
20082013
{
20092014
struct cqspi_st *cqspi = dev_get_drvdata(dev);
2015+
int ret;
2016+
2017+
ret = pm_runtime_force_resume(dev);
2018+
if (ret) {
2019+
dev_err(dev, "pm_runtime_force_resume failed on resume\n");
2020+
return ret;
2021+
}
20102022

20112023
return spi_controller_resume(cqspi->host);
20122024
}

drivers/spi/spi-fsl-lpspi.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
#define TCR_RXMSK BIT(19)
8383
#define TCR_TXMSK BIT(18)
8484

85+
struct fsl_lpspi_devtype_data {
86+
u8 prescale_max;
87+
};
88+
8589
struct lpspi_config {
8690
u8 bpw;
8791
u8 chip_select;
@@ -119,10 +123,25 @@ struct fsl_lpspi_data {
119123
bool usedma;
120124
struct completion dma_rx_completion;
121125
struct completion dma_tx_completion;
126+
127+
const struct fsl_lpspi_devtype_data *devtype_data;
128+
};
129+
130+
/*
131+
* ERR051608 fixed or not:
132+
* https://www.nxp.com/docs/en/errata/i.MX93_1P87f.pdf
133+
*/
134+
static struct fsl_lpspi_devtype_data imx93_lpspi_devtype_data = {
135+
.prescale_max = 1,
136+
};
137+
138+
static struct fsl_lpspi_devtype_data imx7ulp_lpspi_devtype_data = {
139+
.prescale_max = 8,
122140
};
123141

124142
static const struct of_device_id fsl_lpspi_dt_ids[] = {
125-
{ .compatible = "fsl,imx7ulp-spi", },
143+
{ .compatible = "fsl,imx7ulp-spi", .data = &imx7ulp_lpspi_devtype_data,},
144+
{ .compatible = "fsl,imx93-spi", .data = &imx93_lpspi_devtype_data,},
126145
{ /* sentinel */ }
127146
};
128147
MODULE_DEVICE_TABLE(of, fsl_lpspi_dt_ids);
@@ -297,9 +316,11 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
297316
{
298317
struct lpspi_config config = fsl_lpspi->config;
299318
unsigned int perclk_rate, scldiv, div;
319+
u8 prescale_max;
300320
u8 prescale;
301321

302322
perclk_rate = clk_get_rate(fsl_lpspi->clk_per);
323+
prescale_max = fsl_lpspi->devtype_data->prescale_max;
303324

304325
if (!config.speed_hz) {
305326
dev_err(fsl_lpspi->dev,
@@ -315,7 +336,7 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
315336

316337
div = DIV_ROUND_UP(perclk_rate, config.speed_hz);
317338

318-
for (prescale = 0; prescale < 8; prescale++) {
339+
for (prescale = 0; prescale < prescale_max; prescale++) {
319340
scldiv = div / (1 << prescale) - 2;
320341
if (scldiv < 256) {
321342
fsl_lpspi->config.prescale = prescale;
@@ -822,6 +843,7 @@ static int fsl_lpspi_init_rpm(struct fsl_lpspi_data *fsl_lpspi)
822843

823844
static int fsl_lpspi_probe(struct platform_device *pdev)
824845
{
846+
const struct fsl_lpspi_devtype_data *devtype_data;
825847
struct fsl_lpspi_data *fsl_lpspi;
826848
struct spi_controller *controller;
827849
struct resource *res;
@@ -830,6 +852,10 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
830852
u32 temp;
831853
bool is_target;
832854

855+
devtype_data = of_device_get_match_data(&pdev->dev);
856+
if (!devtype_data)
857+
return -ENODEV;
858+
833859
is_target = of_property_read_bool((&pdev->dev)->of_node, "spi-slave");
834860
if (is_target)
835861
controller = devm_spi_alloc_target(&pdev->dev,
@@ -848,6 +874,7 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
848874
fsl_lpspi->is_target = is_target;
849875
fsl_lpspi->is_only_cs1 = of_property_read_bool((&pdev->dev)->of_node,
850876
"fsl,spi-only-use-cs1-sel");
877+
fsl_lpspi->devtype_data = devtype_data;
851878

852879
init_completion(&fsl_lpspi->xfer_done);
853880

drivers/spi/spi-pxa2xx-pci.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/module.h>
1212
#include <linux/pci.h>
1313
#include <linux/pm.h>
14+
#include <linux/pm_runtime.h>
1415
#include <linux/sprintf.h>
1516
#include <linux/string.h>
1617
#include <linux/types.h>
@@ -297,11 +298,23 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
297298
return ret;
298299
ssp->irq = pci_irq_vector(dev, 0);
299300

300-
return pxa2xx_spi_probe(&dev->dev, ssp);
301+
ret = pxa2xx_spi_probe(&dev->dev, ssp, pdata);
302+
if (ret)
303+
return ret;
304+
305+
pm_runtime_set_autosuspend_delay(&dev->dev, 50);
306+
pm_runtime_use_autosuspend(&dev->dev);
307+
pm_runtime_put_autosuspend(&dev->dev);
308+
pm_runtime_allow(&dev->dev);
309+
310+
return 0;
301311
}
302312

303313
static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
304314
{
315+
pm_runtime_forbid(&dev->dev);
316+
pm_runtime_get_noresume(&dev->dev);
317+
305318
pxa2xx_spi_remove(&dev->dev);
306319
}
307320

drivers/spi/spi-pxa2xx-platform.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/init.h>
88
#include <linux/mod_devicetable.h>
99
#include <linux/platform_device.h>
10+
#include <linux/pm_runtime.h>
1011
#include <linux/property.h>
1112
#include <linux/types.h>
1213

@@ -63,7 +64,7 @@ static struct ssp_device *pxa2xx_spi_ssp_request(struct platform_device *pdev)
6364

6465
ssp = pxa_ssp_request(pdev->id, pdev->name);
6566
if (!ssp)
66-
return ssp;
67+
return NULL;
6768

6869
status = devm_add_action_or_reset(&pdev->dev, pxa2xx_spi_ssp_release, ssp);
6970
if (status)
@@ -142,14 +143,13 @@ static int pxa2xx_spi_platform_probe(struct platform_device *pdev)
142143
struct pxa2xx_spi_controller *platform_info;
143144
struct device *dev = &pdev->dev;
144145
struct ssp_device *ssp;
146+
int ret;
145147

146148
platform_info = dev_get_platdata(dev);
147149
if (!platform_info) {
148150
platform_info = pxa2xx_spi_init_pdata(pdev);
149151
if (IS_ERR(platform_info))
150152
return dev_err_probe(dev, PTR_ERR(platform_info), "missing platform data\n");
151-
152-
dev->platform_data = platform_info;
153153
}
154154

155155
ssp = pxa2xx_spi_ssp_request(pdev);
@@ -158,12 +158,28 @@ static int pxa2xx_spi_platform_probe(struct platform_device *pdev)
158158
if (!ssp)
159159
ssp = &platform_info->ssp;
160160

161-
return pxa2xx_spi_probe(dev, ssp);
161+
pm_runtime_set_autosuspend_delay(dev, 50);
162+
pm_runtime_use_autosuspend(dev);
163+
pm_runtime_set_active(dev);
164+
pm_runtime_enable(dev);
165+
166+
ret = pxa2xx_spi_probe(dev, ssp, platform_info);
167+
if (ret)
168+
pm_runtime_disable(dev);
169+
170+
return ret;
162171
}
163172

164173
static void pxa2xx_spi_platform_remove(struct platform_device *pdev)
165174
{
166-
pxa2xx_spi_remove(&pdev->dev);
175+
struct device *dev = &pdev->dev;
176+
177+
pm_runtime_get_sync(dev);
178+
179+
pxa2xx_spi_remove(dev);
180+
181+
pm_runtime_put_noidle(dev);
182+
pm_runtime_disable(dev);
167183
}
168184

169185
static const struct acpi_device_id pxa2xx_spi_acpi_match[] = {

drivers/spi/spi-pxa2xx.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,16 +1277,15 @@ static size_t pxa2xx_spi_max_dma_transfer_size(struct spi_device *spi)
12771277
return MAX_DMA_LEN;
12781278
}
12791279

1280-
int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp)
1280+
int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp,
1281+
struct pxa2xx_spi_controller *platform_info)
12811282
{
1282-
struct pxa2xx_spi_controller *platform_info;
12831283
struct spi_controller *controller;
12841284
struct driver_data *drv_data;
12851285
const struct lpss_config *config;
12861286
int status;
12871287
u32 tmp;
12881288

1289-
platform_info = dev_get_platdata(dev);
12901289
if (platform_info->is_target)
12911290
controller = devm_spi_alloc_target(dev, sizeof(*drv_data));
12921291
else
@@ -1450,24 +1449,16 @@ int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp)
14501449
}
14511450
}
14521451

1453-
pm_runtime_set_autosuspend_delay(dev, 50);
1454-
pm_runtime_use_autosuspend(dev);
1455-
pm_runtime_set_active(dev);
1456-
pm_runtime_enable(dev);
1457-
14581452
/* Register with the SPI framework */
14591453
dev_set_drvdata(dev, drv_data);
14601454
status = spi_register_controller(controller);
14611455
if (status) {
14621456
dev_err_probe(dev, status, "problem registering SPI controller\n");
1463-
goto out_error_pm_runtime_enabled;
1457+
goto out_error_clock_enabled;
14641458
}
14651459

14661460
return status;
14671461

1468-
out_error_pm_runtime_enabled:
1469-
pm_runtime_disable(dev);
1470-
14711462
out_error_clock_enabled:
14721463
clk_disable_unprepare(ssp->clk);
14731464

@@ -1484,8 +1475,6 @@ void pxa2xx_spi_remove(struct device *dev)
14841475
struct driver_data *drv_data = dev_get_drvdata(dev);
14851476
struct ssp_device *ssp = drv_data->ssp;
14861477

1487-
pm_runtime_get_sync(dev);
1488-
14891478
spi_unregister_controller(drv_data->controller);
14901479

14911480
/* Disable the SSP at the peripheral and SOC level */
@@ -1496,9 +1485,6 @@ void pxa2xx_spi_remove(struct device *dev)
14961485
if (drv_data->controller_info->enable_dma)
14971486
pxa2xx_spi_dma_release(drv_data);
14981487

1499-
pm_runtime_put_noidle(dev);
1500-
pm_runtime_disable(dev);
1501-
15021488
/* Release IRQ */
15031489
free_irq(ssp->irq, drv_data);
15041490
}

drivers/spi/spi-pxa2xx.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ extern void pxa2xx_spi_dma_stop(struct driver_data *drv_data);
132132
extern int pxa2xx_spi_dma_setup(struct driver_data *drv_data);
133133
extern void pxa2xx_spi_dma_release(struct driver_data *drv_data);
134134

135-
int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp);
135+
int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp,
136+
struct pxa2xx_spi_controller *platform_info);
136137
void pxa2xx_spi_remove(struct device *dev);
137138

138139
extern const struct dev_pm_ops pxa2xx_spi_pm_ops;

drivers/spi/spi-zynqmp-gqspi.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,18 @@ static int __maybe_unused zynqmp_runtime_resume(struct device *dev)
10331033
return 0;
10341034
}
10351035

1036+
static unsigned long zynqmp_qspi_timeout(struct zynqmp_qspi *xqspi, u8 bits,
1037+
unsigned long bytes)
1038+
{
1039+
unsigned long timeout;
1040+
1041+
/* Assume we are at most 2x slower than the nominal bus speed */
1042+
timeout = mult_frac(bytes, 2 * 8 * MSEC_PER_SEC,
1043+
bits * xqspi->speed_hz);
1044+
/* And add 100 ms for scheduling delays */
1045+
return msecs_to_jiffies(timeout + 100);
1046+
}
1047+
10361048
/**
10371049
* zynqmp_qspi_exec_op() - Initiates the QSPI transfer
10381050
* @mem: The SPI memory
@@ -1049,6 +1061,7 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
10491061
{
10501062
struct zynqmp_qspi *xqspi = spi_controller_get_devdata
10511063
(mem->spi->controller);
1064+
unsigned long timeout;
10521065
int err = 0, i;
10531066
u32 genfifoentry = 0;
10541067
u16 opcode = op->cmd.opcode;
@@ -1077,8 +1090,10 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
10771090
zynqmp_gqspi_write(xqspi, GQSPI_IER_OFST,
10781091
GQSPI_IER_GENFIFOEMPTY_MASK |
10791092
GQSPI_IER_TXNOT_FULL_MASK);
1080-
if (!wait_for_completion_timeout
1081-
(&xqspi->data_completion, msecs_to_jiffies(1000))) {
1093+
timeout = zynqmp_qspi_timeout(xqspi, op->cmd.buswidth,
1094+
op->cmd.nbytes);
1095+
if (!wait_for_completion_timeout(&xqspi->data_completion,
1096+
timeout)) {
10821097
err = -ETIMEDOUT;
10831098
goto return_err;
10841099
}
@@ -1104,8 +1119,10 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
11041119
GQSPI_IER_TXEMPTY_MASK |
11051120
GQSPI_IER_GENFIFOEMPTY_MASK |
11061121
GQSPI_IER_TXNOT_FULL_MASK);
1107-
if (!wait_for_completion_timeout
1108-
(&xqspi->data_completion, msecs_to_jiffies(1000))) {
1122+
timeout = zynqmp_qspi_timeout(xqspi, op->addr.buswidth,
1123+
op->addr.nbytes);
1124+
if (!wait_for_completion_timeout(&xqspi->data_completion,
1125+
timeout)) {
11091126
err = -ETIMEDOUT;
11101127
goto return_err;
11111128
}
@@ -1173,8 +1190,9 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
11731190
GQSPI_IER_RXEMPTY_MASK);
11741191
}
11751192
}
1176-
if (!wait_for_completion_timeout
1177-
(&xqspi->data_completion, msecs_to_jiffies(1000)))
1193+
timeout = zynqmp_qspi_timeout(xqspi, op->data.buswidth,
1194+
op->data.nbytes);
1195+
if (!wait_for_completion_timeout(&xqspi->data_completion, timeout))
11781196
err = -ETIMEDOUT;
11791197
}
11801198

0 commit comments

Comments
 (0)