blob: 794c8e3759f2c5058872196ce3eff8edec5c71d0 [file] [log] [blame]
developer399f8052021-07-13 18:08:17 +08001From 0c1e4af01506c913cc54e63f66bb5470f50790c7 Mon Sep 17 00:00:00 2001
2From: Leilk Liu <leilk.liu@mediatek.com>
3Date: Tue, 13 Jul 2021 21:45:59 +0800
4Subject: [PATCH] [WCNCR00148458] [Add spi runtime PM support]
5
6[Description]
7Add ahb clk and enable runtime pm
8
9[Release-log]
10N/A
11
12Change-Id: I0529f6e829f5fc4c5880508971c97b9434820340
13Signed-off-by: Leilk Liu <leilk.liu@mediatek.com>
14CR-Id: WCNCR00148458
15---
16 drivers/spi/spi-mt65xx.c | 77 ++++++++++++++++++++++++++++++++++------
17 1 file changed, 67 insertions(+), 10 deletions(-)
18
19diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
20index 7e54984..ff2d825 100644
21--- a/drivers/spi/spi-mt65xx.c
22+++ b/drivers/spi/spi-mt65xx.c
23@@ -119,6 +119,8 @@ struct mtk_spi_compatible {
24 /* the IPM IP design improve some feature, and support dual/quad mode */
25 bool ipm_design;
26 bool support_quad;
27+ /* some IC ahb & apb clk is different and also need to be enabled */
28+ bool need_ahb_clk;
29 };
30
31 struct mtk_spi {
32@@ -126,7 +128,7 @@ struct mtk_spi {
33 u32 state;
34 int pad_num;
35 u32 *pad_sel;
36- struct clk *parent_clk, *sel_clk, *spi_clk;
37+ struct clk *parent_clk, *sel_clk, *spi_clk, *spi_hclk;
38 struct spi_transfer *cur_transfer;
39 u32 xfer_len;
40 u32 num_xfered;
41@@ -147,12 +149,21 @@ static const struct mtk_spi_compatible mt2712_compat = {
42 .must_tx = true,
43 };
44
45-static const struct mtk_spi_compatible ipm_compat = {
46+static const struct mtk_spi_compatible ipm_compat_single = {
47+ .must_tx = true,
48+ .enhance_timing = true,
49+ .dma_ext = true,
50+ .ipm_design = true,
51+ .need_ahb_clk = true,
52+};
53+
54+static const struct mtk_spi_compatible ipm_compat_quad = {
55 .must_tx = true,
56 .enhance_timing = true,
57 .dma_ext = true,
58 .ipm_design = true,
59 .support_quad = true,
60+ .need_ahb_clk = true,
61 };
62
63 static const struct mtk_spi_compatible mt6765_compat = {
64@@ -188,8 +199,11 @@ static const struct mtk_chip_config mtk_default_chip_info = {
65 };
66
67 static const struct of_device_id mtk_spi_of_match[] = {
68- { .compatible = "mediatek,ipm-spi",
69- .data = (void *)&ipm_compat,
70+ { .compatible = "mediatek,ipm-spi-single",
71+ .data = (void *)&ipm_compat_single,
72+ },
73+ { .compatible = "mediatek,ipm-spi-quad",
74+ .data = (void *)&ipm_compat_quad,
75 },
76 { .compatible = "mediatek,mt2701-spi",
77 .data = (void *)&mtk_common_compat,
78@@ -992,7 +1006,7 @@ static int mtk_spi_probe(struct platform_device *pdev)
79 return -ENOMEM;
80 }
81
82-// master->auto_runtime_pm = true;
83+ master->auto_runtime_pm = true;
84 master->dev.of_node = pdev->dev.of_node;
85 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
86
87@@ -1106,22 +1120,40 @@ static int mtk_spi_probe(struct platform_device *pdev)
88 goto err_put_master;
89 }
90
91+ if (mdata->dev_comp->need_ahb_clk) {
92+ mdata->spi_hclk = devm_clk_get(&pdev->dev, "spi-hclk");
93+ if (IS_ERR(mdata->spi_hclk)) {
94+ ret = PTR_ERR(mdata->spi_hclk);
95+ dev_err(&pdev->dev, "failed to get spi-hclk: %d\n", ret);
96+ goto err_put_master;
97+ }
98+
99+ ret = clk_prepare_enable(mdata->spi_hclk);
100+ if (ret < 0) {
101+ dev_err(&pdev->dev, "failed to enable spi_hclk (%d)\n", ret);
102+ goto err_put_master;
103+ }
104+ }
105+
106 ret = clk_prepare_enable(mdata->spi_clk);
107 if (ret < 0) {
108 dev_err(&pdev->dev, "failed to enable spi_clk (%d)\n", ret);
109 goto err_put_master;
110 }
111
112- /*ret = clk_set_parent(mdata->sel_clk, mdata->parent_clk);
113+ ret = clk_set_parent(mdata->sel_clk, mdata->parent_clk);
114 if (ret < 0) {
115 dev_err(&pdev->dev, "failed to clk_set_parent (%d)\n", ret);
116 clk_disable_unprepare(mdata->spi_clk);
117 goto err_put_master;
118 }
119
120- clk_disable_unprepare(mdata->sel_clk);*/
121+ clk_disable_unprepare(mdata->spi_clk);
122+
123+ if (mdata->dev_comp->need_ahb_clk)
124+ clk_disable_unprepare(mdata->spi_hclk);
125
126- //pm_runtime_enable(&pdev->dev);
127+ pm_runtime_enable(&pdev->dev);
128
129 ret = devm_spi_register_master(&pdev->dev, master);
130 if (ret) {
131@@ -1201,8 +1233,11 @@ static int mtk_spi_suspend(struct device *dev)
132 if (ret)
133 return ret;
134
135- if (!pm_runtime_suspended(dev))
136+ if (!pm_runtime_suspended(dev)) {
137 clk_disable_unprepare(mdata->spi_clk);
138+ if (mdata->dev_comp->need_ahb_clk)
139+ clk_disable_unprepare(mdata->spi_hclk);
140+ }
141
142 return ret;
143 }
144@@ -1214,6 +1249,14 @@ static int mtk_spi_resume(struct device *dev)
145 struct mtk_spi *mdata = spi_master_get_devdata(master);
146
147 if (!pm_runtime_suspended(dev)) {
148+ if (mdata->dev_comp->need_ahb_clk) {
149+ ret = clk_prepare_enable(mdata->spi_hclk);
150+ if (ret < 0) {
151+ dev_err(dev, "failed to enable spi_hclk (%d)\n", ret);
152+ return ret;
153+ }
154+ }
155+
156 ret = clk_prepare_enable(mdata->spi_clk);
157 if (ret < 0) {
158 dev_err(dev, "failed to enable spi_clk (%d)\n", ret);
159@@ -1222,8 +1265,11 @@ static int mtk_spi_resume(struct device *dev)
160 }
161
162 ret = spi_master_resume(master);
163- if (ret < 0)
164+ if (ret < 0) {
165 clk_disable_unprepare(mdata->spi_clk);
166+ if (mdata->dev_comp->need_ahb_clk)
167+ clk_disable_unprepare(mdata->spi_hclk);
168+ }
169
170 return ret;
171 }
172@@ -1237,6 +1283,9 @@ static int mtk_spi_runtime_suspend(struct device *dev)
173
174 clk_disable_unprepare(mdata->spi_clk);
175
176+ if (mdata->dev_comp->need_ahb_clk)
177+ clk_disable_unprepare(mdata->spi_hclk);
178+
179 return 0;
180 }
181
182@@ -1246,6 +1295,14 @@ static int mtk_spi_runtime_resume(struct device *dev)
183 struct mtk_spi *mdata = spi_master_get_devdata(master);
184 int ret;
185
186+ if (mdata->dev_comp->need_ahb_clk) {
187+ ret = clk_prepare_enable(mdata->spi_hclk);
188+ if (ret < 0) {
189+ dev_err(dev, "failed to enable spi_hclk (%d)\n", ret);
190+ return ret;
191+ }
192+ }
193+
194 ret = clk_prepare_enable(mdata->spi_clk);
195 if (ret < 0) {
196 dev_err(dev, "failed to enable spi_clk (%d)\n", ret);
197--
1982.18.0
199