Skip to content

Commit cff8064

Browse files
Akash Asthanaandersson
authored andcommitted
spi: spi-qcom-qspi: Add interconnect support
Get the interconnect paths for QSPI device and vote according to the current bus speed of the driver. Acked-by: Mark Brown <[email protected]> Signed-off-by: Akash Asthana <[email protected]> Reviewed-by: Matthias Kaehlcke <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bjorn Andersson <[email protected]>
1 parent 0e3b8a8 commit cff8064

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

drivers/spi/spi-qcom-qspi.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright (c) 2017-2018, The Linux foundation. All rights reserved.
33

44
#include <linux/clk.h>
5+
#include <linux/interconnect.h>
56
#include <linux/interrupt.h>
67
#include <linux/io.h>
78
#include <linux/module.h>
@@ -139,7 +140,8 @@ struct qcom_qspi {
139140
struct device *dev;
140141
struct clk_bulk_data *clks;
141142
struct qspi_xfer xfer;
142-
/* Lock to protect xfer and IRQ accessed registers */
143+
struct icc_path *icc_path_cpu_to_qspi;
144+
/* Lock to protect data accessed by IRQs */
143145
spinlock_t lock;
144146
};
145147

@@ -229,6 +231,7 @@ static int qcom_qspi_transfer_one(struct spi_master *master,
229231
int ret;
230232
unsigned long speed_hz;
231233
unsigned long flags;
234+
unsigned int avg_bw_cpu;
232235

233236
speed_hz = slv->max_speed_hz;
234237
if (xfer->speed_hz)
@@ -241,6 +244,18 @@ static int qcom_qspi_transfer_one(struct spi_master *master,
241244
return ret;
242245
}
243246

247+
/*
248+
* Set BW quota for CPU as driver supports FIFO mode only.
249+
* We don't have explicit peak requirement so keep it equal to avg_bw.
250+
*/
251+
avg_bw_cpu = Bps_to_icc(speed_hz);
252+
ret = icc_set_bw(ctrl->icc_path_cpu_to_qspi, avg_bw_cpu, avg_bw_cpu);
253+
if (ret) {
254+
dev_err(ctrl->dev, "%s: ICC BW voting failed for cpu: %d\n",
255+
__func__, ret);
256+
return ret;
257+
}
258+
244259
spin_lock_irqsave(&ctrl->lock, flags);
245260

246261
/* We are half duplex, so either rx or tx will be set */
@@ -458,6 +473,29 @@ static int qcom_qspi_probe(struct platform_device *pdev)
458473
if (ret)
459474
goto exit_probe_master_put;
460475

476+
ctrl->icc_path_cpu_to_qspi = devm_of_icc_get(dev, "qspi-config");
477+
if (IS_ERR(ctrl->icc_path_cpu_to_qspi)) {
478+
ret = PTR_ERR(ctrl->icc_path_cpu_to_qspi);
479+
if (ret != -EPROBE_DEFER)
480+
dev_err(dev, "Failed to get cpu path: %d\n", ret);
481+
goto exit_probe_master_put;
482+
}
483+
/* Set BW vote for register access */
484+
ret = icc_set_bw(ctrl->icc_path_cpu_to_qspi, Bps_to_icc(1000),
485+
Bps_to_icc(1000));
486+
if (ret) {
487+
dev_err(ctrl->dev, "%s: ICC BW voting failed for cpu: %d\n",
488+
__func__, ret);
489+
goto exit_probe_master_put;
490+
}
491+
492+
ret = icc_disable(ctrl->icc_path_cpu_to_qspi);
493+
if (ret) {
494+
dev_err(ctrl->dev, "%s: ICC disable failed for cpu: %d\n",
495+
__func__, ret);
496+
goto exit_probe_master_put;
497+
}
498+
461499
ret = platform_get_irq(pdev, 0);
462500
if (ret < 0)
463501
goto exit_probe_master_put;
@@ -511,16 +549,32 @@ static int __maybe_unused qcom_qspi_runtime_suspend(struct device *dev)
511549
{
512550
struct spi_master *master = dev_get_drvdata(dev);
513551
struct qcom_qspi *ctrl = spi_master_get_devdata(master);
552+
int ret;
514553

515554
clk_bulk_disable_unprepare(QSPI_NUM_CLKS, ctrl->clks);
516555

556+
ret = icc_disable(ctrl->icc_path_cpu_to_qspi);
557+
if (ret) {
558+
dev_err_ratelimited(ctrl->dev, "%s: ICC disable failed for cpu: %d\n",
559+
__func__, ret);
560+
return ret;
561+
}
562+
517563
return 0;
518564
}
519565

520566
static int __maybe_unused qcom_qspi_runtime_resume(struct device *dev)
521567
{
522568
struct spi_master *master = dev_get_drvdata(dev);
523569
struct qcom_qspi *ctrl = spi_master_get_devdata(master);
570+
int ret;
571+
572+
ret = icc_enable(ctrl->icc_path_cpu_to_qspi);
573+
if (ret) {
574+
dev_err_ratelimited(ctrl->dev, "%s: ICC enable failed for cpu: %d\n",
575+
__func__, ret);
576+
return ret;
577+
}
524578

525579
return clk_bulk_prepare_enable(QSPI_NUM_CLKS, ctrl->clks);
526580
}

0 commit comments

Comments
 (0)