blob: 92dbb4296133914bba20a0f7d9e52631c30e5d10 [file] [log] [blame]
developer5d148cb2023-06-02 13:08:11 +08001From c8ea5f2bbc2ece3efcb7b8c704a7bee4c5f7adef Mon Sep 17 00:00:00 2001
2From: Sam Shih <sam.shih@mediatek.com>
3Date: Fri, 2 Jun 2023 13:06:20 +0800
4Subject: [PATCH] [spi-and-storage][999-2369-Add-spi-runtime-PM-support.patch]
developer399f8052021-07-13 18:08:17 +08005
developer399f8052021-07-13 18:08:17 +08006---
7 drivers/spi/spi-mt65xx.c | 77 ++++++++++++++++++++++++++++++++++------
8 1 file changed, 67 insertions(+), 10 deletions(-)
9
10diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
developer5d148cb2023-06-02 13:08:11 +080011index b03257132..7c3ee3381 100644
developer399f8052021-07-13 18:08:17 +080012--- a/drivers/spi/spi-mt65xx.c
13+++ b/drivers/spi/spi-mt65xx.c
14@@ -119,6 +119,8 @@ struct mtk_spi_compatible {
15 /* the IPM IP design improve some feature, and support dual/quad mode */
16 bool ipm_design;
17 bool support_quad;
18+ /* some IC ahb & apb clk is different and also need to be enabled */
19+ bool need_ahb_clk;
20 };
21
22 struct mtk_spi {
23@@ -126,7 +128,7 @@ struct mtk_spi {
24 u32 state;
25 int pad_num;
26 u32 *pad_sel;
27- struct clk *parent_clk, *sel_clk, *spi_clk;
28+ struct clk *parent_clk, *sel_clk, *spi_clk, *spi_hclk;
29 struct spi_transfer *cur_transfer;
30 u32 xfer_len;
31 u32 num_xfered;
32@@ -147,12 +149,21 @@ static const struct mtk_spi_compatible mt2712_compat = {
33 .must_tx = true,
34 };
35
36-static const struct mtk_spi_compatible ipm_compat = {
37+static const struct mtk_spi_compatible ipm_compat_single = {
38+ .must_tx = true,
39+ .enhance_timing = true,
40+ .dma_ext = true,
41+ .ipm_design = true,
42+ .need_ahb_clk = true,
43+};
44+
45+static const struct mtk_spi_compatible ipm_compat_quad = {
46 .must_tx = true,
47 .enhance_timing = true,
48 .dma_ext = true,
49 .ipm_design = true,
50 .support_quad = true,
51+ .need_ahb_clk = true,
52 };
53
54 static const struct mtk_spi_compatible mt6765_compat = {
55@@ -188,8 +199,11 @@ static const struct mtk_chip_config mtk_default_chip_info = {
56 };
57
58 static const struct of_device_id mtk_spi_of_match[] = {
59- { .compatible = "mediatek,ipm-spi",
60- .data = (void *)&ipm_compat,
61+ { .compatible = "mediatek,ipm-spi-single",
62+ .data = (void *)&ipm_compat_single,
63+ },
64+ { .compatible = "mediatek,ipm-spi-quad",
65+ .data = (void *)&ipm_compat_quad,
66 },
67 { .compatible = "mediatek,mt2701-spi",
68 .data = (void *)&mtk_common_compat,
developer5d148cb2023-06-02 13:08:11 +080069@@ -993,7 +1007,7 @@ static int mtk_spi_probe(struct platform_device *pdev)
developer399f8052021-07-13 18:08:17 +080070 return -ENOMEM;
71 }
72
73-// master->auto_runtime_pm = true;
74+ master->auto_runtime_pm = true;
75 master->dev.of_node = pdev->dev.of_node;
76 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
77
developer5d148cb2023-06-02 13:08:11 +080078@@ -1107,22 +1121,40 @@ static int mtk_spi_probe(struct platform_device *pdev)
developer399f8052021-07-13 18:08:17 +080079 goto err_put_master;
80 }
81
82+ if (mdata->dev_comp->need_ahb_clk) {
83+ mdata->spi_hclk = devm_clk_get(&pdev->dev, "spi-hclk");
84+ if (IS_ERR(mdata->spi_hclk)) {
85+ ret = PTR_ERR(mdata->spi_hclk);
86+ dev_err(&pdev->dev, "failed to get spi-hclk: %d\n", ret);
87+ goto err_put_master;
88+ }
89+
90+ ret = clk_prepare_enable(mdata->spi_hclk);
91+ if (ret < 0) {
92+ dev_err(&pdev->dev, "failed to enable spi_hclk (%d)\n", ret);
93+ goto err_put_master;
94+ }
95+ }
96+
97 ret = clk_prepare_enable(mdata->spi_clk);
98 if (ret < 0) {
99 dev_err(&pdev->dev, "failed to enable spi_clk (%d)\n", ret);
100 goto err_put_master;
101 }
102
103- /*ret = clk_set_parent(mdata->sel_clk, mdata->parent_clk);
104+ ret = clk_set_parent(mdata->sel_clk, mdata->parent_clk);
105 if (ret < 0) {
106 dev_err(&pdev->dev, "failed to clk_set_parent (%d)\n", ret);
107 clk_disable_unprepare(mdata->spi_clk);
108 goto err_put_master;
109 }
110
111- clk_disable_unprepare(mdata->sel_clk);*/
112+ clk_disable_unprepare(mdata->spi_clk);
113+
114+ if (mdata->dev_comp->need_ahb_clk)
115+ clk_disable_unprepare(mdata->spi_hclk);
116
117- //pm_runtime_enable(&pdev->dev);
118+ pm_runtime_enable(&pdev->dev);
119
120 ret = devm_spi_register_master(&pdev->dev, master);
121 if (ret) {
developer5d148cb2023-06-02 13:08:11 +0800122@@ -1202,8 +1234,11 @@ static int mtk_spi_suspend(struct device *dev)
developer399f8052021-07-13 18:08:17 +0800123 if (ret)
124 return ret;
125
126- if (!pm_runtime_suspended(dev))
127+ if (!pm_runtime_suspended(dev)) {
128 clk_disable_unprepare(mdata->spi_clk);
129+ if (mdata->dev_comp->need_ahb_clk)
130+ clk_disable_unprepare(mdata->spi_hclk);
131+ }
132
133 return ret;
134 }
developer5d148cb2023-06-02 13:08:11 +0800135@@ -1215,6 +1250,14 @@ static int mtk_spi_resume(struct device *dev)
developer399f8052021-07-13 18:08:17 +0800136 struct mtk_spi *mdata = spi_master_get_devdata(master);
137
138 if (!pm_runtime_suspended(dev)) {
139+ if (mdata->dev_comp->need_ahb_clk) {
140+ ret = clk_prepare_enable(mdata->spi_hclk);
141+ if (ret < 0) {
142+ dev_err(dev, "failed to enable spi_hclk (%d)\n", ret);
143+ return ret;
144+ }
145+ }
146+
147 ret = clk_prepare_enable(mdata->spi_clk);
148 if (ret < 0) {
149 dev_err(dev, "failed to enable spi_clk (%d)\n", ret);
developer5d148cb2023-06-02 13:08:11 +0800150@@ -1223,8 +1266,11 @@ static int mtk_spi_resume(struct device *dev)
developer399f8052021-07-13 18:08:17 +0800151 }
152
153 ret = spi_master_resume(master);
154- if (ret < 0)
155+ if (ret < 0) {
156 clk_disable_unprepare(mdata->spi_clk);
157+ if (mdata->dev_comp->need_ahb_clk)
158+ clk_disable_unprepare(mdata->spi_hclk);
159+ }
160
161 return ret;
162 }
developer5d148cb2023-06-02 13:08:11 +0800163@@ -1238,6 +1284,9 @@ static int mtk_spi_runtime_suspend(struct device *dev)
developer399f8052021-07-13 18:08:17 +0800164
165 clk_disable_unprepare(mdata->spi_clk);
166
167+ if (mdata->dev_comp->need_ahb_clk)
168+ clk_disable_unprepare(mdata->spi_hclk);
169+
170 return 0;
171 }
172
developer5d148cb2023-06-02 13:08:11 +0800173@@ -1247,6 +1296,14 @@ static int mtk_spi_runtime_resume(struct device *dev)
developer399f8052021-07-13 18:08:17 +0800174 struct mtk_spi *mdata = spi_master_get_devdata(master);
175 int ret;
176
177+ if (mdata->dev_comp->need_ahb_clk) {
178+ ret = clk_prepare_enable(mdata->spi_hclk);
179+ if (ret < 0) {
180+ dev_err(dev, "failed to enable spi_hclk (%d)\n", ret);
181+ return ret;
182+ }
183+ }
184+
185 ret = clk_prepare_enable(mdata->spi_clk);
186 if (ret < 0) {
187 dev_err(dev, "failed to enable spi_clk (%d)\n", ret);
188--
developer5d148cb2023-06-02 13:08:11 +08001892.34.1
developer399f8052021-07-13 18:08:17 +0800190