Skip to content

Commit 324ecc7

Browse files
miquelraynalbroonie
authored andcommitted
spi: cadence-qspi: Kill cqspi_jh7110_clk_init
This controller can be fed by either a main "ref" clock, or three clocks ("ref" again, "ahb", "apb"). In practice, it is likely that all controllers have the same inputs, but a single clock feeds the three interfaces (ref is used for controlling the external interface, ahb/apb the internal ones). Handling these clocks is in no way SoC specific, only the number of expected clocks may change. Plus, we will soon be adding another controller requiring an AHB and an APB clock as well, so it is time to align the whole clock handling. Furthermore, the use of the cqspi_jh7110_clk_init() helper, which specifically grabs and enables the "ahb" and "apb" clocks, is a bit convoluted: - only the JH7110 compatible provides the ->jh7110_clk_init() callback, - in the probe, if the above callback is set in the driver data, the driver does not call the callback (!) but instead calls the helper directly (?), - in the helper, the is_jh7110 boolean is set. This logic does not make sense. Instead: - in the probe, set the is_jh7110 boolean based on the compatible, - collect all available clocks with the "bulk" helper, - enable the extra clocks if they are available, - kill the SoC specific cqspi_jh7110_clk_init() helper. This also allows to group the clock handling instead of depending on the driver data pointer, which further simplifies the error path and the remove callback. Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Miquel Raynal (Schneider Electric) <miquel.raynal@bootlin.com> Link: https://patch.msgid.link/20260205-schneider-6-19-rc1-qspi-v5-2-843632b3c674@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 2b97f5c commit 324ecc7

1 file changed

Lines changed: 29 additions & 83 deletions

File tree

drivers/spi/spi-cadence-quadspi.c

Lines changed: 29 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ static_assert(CQSPI_MAX_CHIPSELECT <= SPI_DEVICE_CS_CNT_MAX);
5757
#define CQSPI_OP_WIDTH(part) ((part).nbytes ? ilog2((part).buswidth) : 0)
5858

5959
enum {
60-
CLK_QSPI_APB = 0,
60+
CLK_QSPI_REF = 0,
61+
CLK_QSPI_APB,
6162
CLK_QSPI_AHB,
6263
CLK_QSPI_NUM,
6364
};
@@ -78,8 +79,7 @@ struct cqspi_flash_pdata {
7879
struct cqspi_st {
7980
struct platform_device *pdev;
8081
struct spi_controller *host;
81-
struct clk *clk;
82-
struct clk *clks[CLK_QSPI_NUM];
82+
struct clk_bulk_data clks[CLK_QSPI_NUM];
8383
unsigned int sclk;
8484

8585
void __iomem *iobase;
@@ -123,8 +123,6 @@ struct cqspi_driver_platdata {
123123
int (*indirect_read_dma)(struct cqspi_flash_pdata *f_pdata,
124124
u_char *rxbuf, loff_t from_addr, size_t n_rx);
125125
u32 (*get_dma_status)(struct cqspi_st *cqspi);
126-
int (*jh7110_clk_init)(struct platform_device *pdev,
127-
struct cqspi_st *cqspi);
128126
};
129127

130128
/* Operation timeout value */
@@ -1771,51 +1769,6 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
17711769
return 0;
17721770
}
17731771

1774-
static int cqspi_jh7110_clk_init(struct platform_device *pdev, struct cqspi_st *cqspi)
1775-
{
1776-
static struct clk_bulk_data qspiclk[] = {
1777-
{ .id = "apb" },
1778-
{ .id = "ahb" },
1779-
};
1780-
1781-
int ret = 0;
1782-
1783-
ret = devm_clk_bulk_get(&pdev->dev, ARRAY_SIZE(qspiclk), qspiclk);
1784-
if (ret) {
1785-
dev_err(&pdev->dev, "%s: failed to get qspi clocks\n", __func__);
1786-
return ret;
1787-
}
1788-
1789-
cqspi->clks[CLK_QSPI_APB] = qspiclk[0].clk;
1790-
cqspi->clks[CLK_QSPI_AHB] = qspiclk[1].clk;
1791-
1792-
ret = clk_prepare_enable(cqspi->clks[CLK_QSPI_APB]);
1793-
if (ret) {
1794-
dev_err(&pdev->dev, "%s: failed to enable CLK_QSPI_APB\n", __func__);
1795-
return ret;
1796-
}
1797-
1798-
ret = clk_prepare_enable(cqspi->clks[CLK_QSPI_AHB]);
1799-
if (ret) {
1800-
dev_err(&pdev->dev, "%s: failed to enable CLK_QSPI_AHB\n", __func__);
1801-
goto disable_apb_clk;
1802-
}
1803-
1804-
cqspi->is_jh7110 = true;
1805-
1806-
return 0;
1807-
1808-
disable_apb_clk:
1809-
clk_disable_unprepare(cqspi->clks[CLK_QSPI_APB]);
1810-
1811-
return ret;
1812-
}
1813-
1814-
static void cqspi_jh7110_disable_clk(struct platform_device *pdev, struct cqspi_st *cqspi)
1815-
{
1816-
clk_disable_unprepare(cqspi->clks[CLK_QSPI_AHB]);
1817-
clk_disable_unprepare(cqspi->clks[CLK_QSPI_APB]);
1818-
}
18191772
static int cqspi_probe(struct platform_device *pdev)
18201773
{
18211774
const struct cqspi_driver_platdata *ddata;
@@ -1824,8 +1777,7 @@ static int cqspi_probe(struct platform_device *pdev)
18241777
struct spi_controller *host;
18251778
struct resource *res_ahb;
18261779
struct cqspi_st *cqspi;
1827-
int ret;
1828-
int irq;
1780+
int ret, irq;
18291781

18301782
host = devm_spi_alloc_host(&pdev->dev, sizeof(*cqspi));
18311783
if (!host)
@@ -1836,10 +1788,11 @@ static int cqspi_probe(struct platform_device *pdev)
18361788
host->mem_caps = &cqspi_mem_caps;
18371789

18381790
cqspi = spi_controller_get_devdata(host);
1791+
if (of_device_is_compatible(pdev->dev.of_node, "starfive,jh7110-qspi"))
1792+
cqspi->is_jh7110 = true;
18391793

18401794
cqspi->pdev = pdev;
18411795
cqspi->host = host;
1842-
cqspi->is_jh7110 = false;
18431796
cqspi->ddata = ddata = of_device_get_match_data(dev);
18441797
platform_set_drvdata(pdev, cqspi);
18451798

@@ -1856,12 +1809,14 @@ static int cqspi_probe(struct platform_device *pdev)
18561809
return ret;
18571810
}
18581811

1859-
/* Obtain QSPI clock. */
1860-
cqspi->clk = devm_clk_get(dev, NULL);
1861-
if (IS_ERR(cqspi->clk)) {
1862-
dev_err(dev, "Cannot claim QSPI clock.\n");
1863-
ret = PTR_ERR(cqspi->clk);
1864-
return ret;
1812+
/* Obtain QSPI clocks. */
1813+
ret = devm_clk_bulk_get_optional(dev, CLK_QSPI_NUM, cqspi->clks);
1814+
if (ret)
1815+
return dev_err_probe(dev, ret, "Failed to get clocks\n");
1816+
1817+
if (!cqspi->clks[CLK_QSPI_REF].clk) {
1818+
dev_err(dev, "Cannot claim mandatory QSPI ref clock.\n");
1819+
return -ENODEV;
18651820
}
18661821

18671822
/* Obtain and remap controller address. */
@@ -1893,10 +1848,9 @@ static int cqspi_probe(struct platform_device *pdev)
18931848
if (ret)
18941849
return ret;
18951850

1896-
1897-
ret = clk_prepare_enable(cqspi->clk);
1851+
ret = clk_bulk_prepare_enable(CLK_QSPI_NUM, cqspi->clks);
18981852
if (ret) {
1899-
dev_err(dev, "Cannot enable QSPI clock.\n");
1853+
dev_err(dev, "Cannot enable QSPI clocks.\n");
19001854
goto disable_rpm;
19011855
}
19021856

@@ -1905,22 +1859,22 @@ static int cqspi_probe(struct platform_device *pdev)
19051859
if (IS_ERR(rstc)) {
19061860
ret = PTR_ERR(rstc);
19071861
dev_err(dev, "Cannot get QSPI reset.\n");
1908-
goto disable_clk;
1862+
goto disable_clks;
19091863
}
19101864

19111865
rstc_ocp = devm_reset_control_get_optional_exclusive(dev, "qspi-ocp");
19121866
if (IS_ERR(rstc_ocp)) {
19131867
ret = PTR_ERR(rstc_ocp);
19141868
dev_err(dev, "Cannot get QSPI OCP reset.\n");
1915-
goto disable_clk;
1869+
goto disable_clks;
19161870
}
19171871

1918-
if (of_device_is_compatible(pdev->dev.of_node, "starfive,jh7110-qspi")) {
1872+
if (cqspi->is_jh7110) {
19191873
rstc_ref = devm_reset_control_get_optional_exclusive(dev, "rstc_ref");
19201874
if (IS_ERR(rstc_ref)) {
19211875
ret = PTR_ERR(rstc_ref);
19221876
dev_err(dev, "Cannot get QSPI REF reset.\n");
1923-
goto disable_clk;
1877+
goto disable_clks;
19241878
}
19251879
reset_control_assert(rstc_ref);
19261880
reset_control_deassert(rstc_ref);
@@ -1932,7 +1886,7 @@ static int cqspi_probe(struct platform_device *pdev)
19321886
reset_control_assert(rstc_ocp);
19331887
reset_control_deassert(rstc_ocp);
19341888

1935-
cqspi->master_ref_clk_hz = clk_get_rate(cqspi->clk);
1889+
cqspi->master_ref_clk_hz = clk_get_rate(cqspi->clks[CLK_QSPI_REF].clk);
19361890
host->max_speed_hz = cqspi->master_ref_clk_hz;
19371891

19381892
/* write completion is supported by default */
@@ -1958,12 +1912,6 @@ static int cqspi_probe(struct platform_device *pdev)
19581912
cqspi->slow_sram = true;
19591913
if (ddata->quirks & CQSPI_NEEDS_APB_AHB_HAZARD_WAR)
19601914
cqspi->apb_ahb_hazard = true;
1961-
1962-
if (ddata->jh7110_clk_init) {
1963-
ret = cqspi_jh7110_clk_init(pdev, cqspi);
1964-
if (ret)
1965-
goto disable_clk;
1966-
}
19671915
if (ddata->quirks & CQSPI_DISABLE_STIG_MODE)
19681916
cqspi->disable_stig_mode = true;
19691917

@@ -2029,11 +1977,8 @@ static int cqspi_probe(struct platform_device *pdev)
20291977
disable_controller:
20301978
cqspi_controller_enable(cqspi, 0);
20311979
disable_clks:
2032-
if (cqspi->is_jh7110)
2033-
cqspi_jh7110_disable_clk(pdev, cqspi);
2034-
disable_clk:
20351980
if (pm_runtime_get_sync(&pdev->dev) >= 0)
2036-
clk_disable_unprepare(cqspi->clk);
1981+
clk_bulk_disable_unprepare(CLK_QSPI_NUM, cqspi->clks);
20371982
disable_rpm:
20381983
if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM)))
20391984
pm_runtime_disable(dev);
@@ -2062,14 +2007,12 @@ static void cqspi_remove(struct platform_device *pdev)
20622007

20632008
cqspi_controller_enable(cqspi, 0);
20642009

2065-
if (cqspi->is_jh7110)
2066-
cqspi_jh7110_disable_clk(pdev, cqspi);
20672010

20682011
if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM)))
20692012
ret = pm_runtime_get_sync(&pdev->dev);
20702013

20712014
if (ret >= 0)
2072-
clk_disable(cqspi->clk);
2015+
clk_bulk_disable_unprepare(CLK_QSPI_NUM, cqspi->clks);
20732016

20742017
if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM))) {
20752018
pm_runtime_put_sync(&pdev->dev);
@@ -2082,15 +2025,19 @@ static int cqspi_runtime_suspend(struct device *dev)
20822025
struct cqspi_st *cqspi = dev_get_drvdata(dev);
20832026

20842027
cqspi_controller_enable(cqspi, 0);
2085-
clk_disable_unprepare(cqspi->clk);
2028+
clk_bulk_disable_unprepare(CLK_QSPI_NUM, cqspi->clks);
20862029
return 0;
20872030
}
20882031

20892032
static int cqspi_runtime_resume(struct device *dev)
20902033
{
20912034
struct cqspi_st *cqspi = dev_get_drvdata(dev);
2035+
int ret;
2036+
2037+
ret = clk_bulk_prepare_enable(CLK_QSPI_NUM, cqspi->clks);
2038+
if (ret)
2039+
return ret;
20922040

2093-
clk_prepare_enable(cqspi->clk);
20942041
cqspi_wait_idle(cqspi);
20952042
cqspi_controller_enable(cqspi, 0);
20962043
cqspi_controller_init(cqspi);
@@ -2173,7 +2120,6 @@ static const struct cqspi_driver_platdata versal2_ospi = {
21732120

21742121
static const struct cqspi_driver_platdata jh7110_qspi = {
21752122
.quirks = CQSPI_DISABLE_DAC_MODE,
2176-
.jh7110_clk_init = cqspi_jh7110_clk_init,
21772123
};
21782124

21792125
static const struct cqspi_driver_platdata pensando_cdns_qspi = {

0 commit comments

Comments
 (0)