blob: 63bd7fe92a16c4712e589da8cddf8ef916eccaed [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2015-2016 MediaTek Inc.
4 * Author: Yong Wu <yong.wu@mediatek.com>
5 */
6#include <linux/clk.h>
7#include <linux/component.h>
8#include <linux/device.h>
9#include <linux/err.h>
10#include <linux/io.h>
11#include <linux/module.h>
12#include <linux/of.h>
13#include <linux/of_platform.h>
14#include <linux/platform_device.h>
15#include <linux/pm_runtime.h>
16#include <soc/mediatek/smi.h>
17#include <dt-bindings/memory/mt2701-larb-port.h>
18
19/* mt8173 */
20#define SMI_LARB_MMU_EN 0xf00
21
22/* mt2701 */
23#define REG_SMI_SECUR_CON_BASE 0x5c0
24
25/* every register control 8 port, register offset 0x4 */
26#define REG_SMI_SECUR_CON_OFFSET(id) (((id) >> 3) << 2)
27#define REG_SMI_SECUR_CON_ADDR(id) \
28 (REG_SMI_SECUR_CON_BASE + REG_SMI_SECUR_CON_OFFSET(id))
29
30/*
31 * every port have 4 bit to control, bit[port + 3] control virtual or physical,
32 * bit[port + 2 : port + 1] control the domain, bit[port] control the security
33 * or non-security.
34 */
35#define SMI_SECUR_CON_VAL_MSK(id) (~(0xf << (((id) & 0x7) << 2)))
36#define SMI_SECUR_CON_VAL_VIRT(id) BIT((((id) & 0x7) << 2) + 3)
37/* mt2701 domain should be set to 3 */
38#define SMI_SECUR_CON_VAL_DOMAIN(id) (0x3 << ((((id) & 0x7) << 2) + 1))
39
40/* mt2712 */
41#define SMI_LARB_NONSEC_CON(id) (0x380 + ((id) * 4))
42#define F_MMU_EN BIT(0)
43
44#define SMI_LARB_CMD_THRT_CON 0x24
45#define SMI_LARB_SW_FLAG 0x40
46#define SMI_LARB_WRR_PORT 0x100
47#define SMI_LARB_WRR_PORTx(id) (SMI_LARB_WRR_PORT + ((id) << 2))
48#define SMI_LARB_OSTDL_PORT 0x200
49#define SMI_LARB_OSTDL_PORTx(id) (SMI_LARB_OSTDL_PORT + ((id) << 2))
50
51/* SMI COMMON */
52#define SMI_BUS_SEL 0x220
53#define SMI_BUS_LARB_SHIFT(larbid) ((larbid) << 1)
54/* All are MMU0 defaultly. Only specialize mmu1 here. */
55#define F_MMU1_LARB(larbid) (0x1 << SMI_BUS_LARB_SHIFT(larbid))
56
57#define SMI_L1LEN 0x100
58#define SMI_L1ARB0 0x104
59#define SMI_L1ARB(id) (SMI_L1ARB0 + ((id) << 2))
60#define SMI_M4U_TH 0x234
61#define SMI_FIFO_TH1 0x238
62#define SMI_FIFO_TH2 0x23c
63#define SMI_DCM 0x300
64#define SMI_DUMMY 0x444
65
66#define SMI_LARB_PORT_NR_MAX 32
67#define SMI_COMMON_LARB_NR_MAX 8
68
69#define SMI_LARB_MISC_NR 2
70#define SMI_COMMON_MISC_NR 6
71
72struct mtk_smi_reg_pair {
73 u16 offset;
74 u32 value;
75};
76
77enum mtk_smi_gen {
78 MTK_SMI_GEN1,
79 MTK_SMI_GEN2
80};
81
82struct mtk_smi_common_plat {
83 enum mtk_smi_gen gen;
84 bool has_gals;
85 u32 bus_sel; /* Balance some larbs to enter mmu0 or mmu1 */
86 bool has_bwl;
87 u16 *bwl;
88 struct mtk_smi_reg_pair *misc;
89};
90
91struct mtk_smi_larb_gen {
92 int port_in_larb[MTK_LARB_NR_MAX + 1];
93 void (*config_port)(struct device *);
94 unsigned int larb_direct_to_common_mask;
95 bool has_gals;
96 bool has_bwl;
97 u8 *bwl;
98 struct mtk_smi_reg_pair *misc;
99};
100
101struct mtk_smi {
102 struct device *dev;
103 struct clk *clk_apb, *clk_smi;
104 struct clk *clk_gals0, *clk_gals1;
105 struct clk *clk_async; /*only needed by mt2701*/
106 void __iomem *smi_ao_base; /* only for gen1 */
107 void __iomem *base; /* only for gen2 */
108 const struct mtk_smi_common_plat *plat;
109};
110
111struct mtk_smi_larb { /* larb: local arbiter */
112 struct mtk_smi smi;
113 void __iomem *base;
114 struct device *smi_common_dev;
115 const struct mtk_smi_larb_gen *larb_gen;
116 int larbid;
117 u32 *mmu;
118};
119
120void mtk_smi_common_bw_set(struct device *dev, const u32 port, const u32 val)
121{
122 struct mtk_smi_larb *larb = dev_get_drvdata(dev);
123 struct mtk_smi *common = dev_get_drvdata(larb->smi_common_dev);
124
125 writel(val, common->base + SMI_L1ARB(port));
126}
127EXPORT_SYMBOL_GPL(mtk_smi_common_bw_set);
128
129void mtk_smi_larb_bw_set(struct device *dev, const u32 port, const u32 val)
130{
131 struct mtk_smi_larb *larb = dev_get_drvdata(dev);
132
133 if (val)
134 writel(val, larb->base + SMI_LARB_OSTDL_PORTx(port));
135}
136EXPORT_SYMBOL_GPL(mtk_smi_larb_bw_set);
137
138static int mtk_smi_clk_enable(const struct mtk_smi *smi)
139{
140 /*int ret;
141
142 pr_info("[SMI LOG] Start SMI CLK_EN\n");
143 ret = clk_prepare_enable(smi->clk_apb);
144 if (ret){
145 pr_err("Failed to get smi->clk_apb\n");
146 }
147 pr_info("[SMI LOG] Start SMI CLK_EN-smi->clk_smi\n");
148 ret = clk_prepare_enable(smi->clk_smi);
149 if (ret){
150 pr_err("Failed to get smi->clk_smi\n");
151 }
152 pr_info("[SMI LOG] Start SMI CLK_EN-smi->clk_gals0\n");
153 ret = clk_prepare_enable(smi->clk_gals0);
154 if (ret){
155 pr_err("Failed to get smi->clk_gals0\n");
156 }
157 pr_info("[SMI LOG] Start SMI CLK_EN-smi->clk_gals1\n");
158 ret = clk_prepare_enable(smi->clk_gals1);
159 if (ret){
160 pr_err("Failed to get smi->smi->clk_gals1\n");
161 }*/
162
163 return 0;
164 /*ret = clk_prepare_enable(smi->clk_apb);
165 if (ret)
166 return ret;
167 ret = clk_prepare_enable(smi->clk_smi);
168 if (ret)
169 goto err_disable_apb;
170
171 ret = clk_prepare_enable(smi->clk_gals0);
172 if (ret)
173 goto err_disable_smi;
174 ret = clk_prepare_enable(smi->clk_gals1);
175 if (ret)
176 goto err_disable_gals0;
177
178 return 0;
179
180err_disable_gals0:
181 clk_disable_unprepare(smi->clk_gals0);
182err_disable_smi:
183 clk_disable_unprepare(smi->clk_smi);
184err_disable_apb:
185 clk_disable_unprepare(smi->clk_apb);
186 return ret;*/
187}
188
189static void mtk_smi_clk_disable(const struct mtk_smi *smi)
190{
191 clk_disable_unprepare(smi->clk_gals1);
192 clk_disable_unprepare(smi->clk_gals0);
193 clk_disable_unprepare(smi->clk_smi);
194 clk_disable_unprepare(smi->clk_apb);
195}
196
197static int
198mtk_smi_larb_bind(struct device *dev, struct device *master, void *data)
199{
200 struct mtk_smi_larb *larb = dev_get_drvdata(dev);
201 struct mtk_smi_iommu *smi_iommu = data;
202 unsigned int i;
203
204 for (i = 0; i < MTK_LARB_NR_MAX; i++) {
205 if (dev == smi_iommu->larb_imu[i].dev) {
206 larb->larbid = i;
207 larb->mmu = &smi_iommu->larb_imu[i].mmu;
208 return 0;
209 }
210 }
211 return -ENODEV;
212}
213
214static void mtk_smi_larb_config_port_gen2_general(struct device *dev)
215{
216 struct mtk_smi_larb *larb = dev_get_drvdata(dev);
217 u32 reg;
218 int i;
219
220 if (BIT(larb->larbid) & larb->larb_gen->larb_direct_to_common_mask)
221 return;
222
223 for_each_set_bit(i, (unsigned long *)larb->mmu, 32) {
224 reg = readl_relaxed(larb->base + SMI_LARB_NONSEC_CON(i));
225 reg |= F_MMU_EN;
226 writel(reg, larb->base + SMI_LARB_NONSEC_CON(i));
227 }
228
229 if (!larb->larb_gen->has_bwl)
230 return;
231
232 for (i = 0; i < larb->larb_gen->port_in_larb[larb->larbid]; i++)
233 mtk_smi_larb_bw_set(larb->smi.dev, i, larb->larb_gen->bwl[
234 larb->larbid * SMI_LARB_PORT_NR_MAX + i]);
235
236 for (i = 0; i < SMI_LARB_MISC_NR; i++)
237 writel_relaxed(larb->larb_gen->misc[
238 larb->larbid * SMI_LARB_MISC_NR + i].value,
239 larb->base + larb->larb_gen->misc[
240 larb->larbid * SMI_LARB_MISC_NR + i].offset);
241 wmb(); /* make sure settings are written */
242}
243
244static void mtk_smi_larb_config_port_mt8173(struct device *dev)
245{
246 struct mtk_smi_larb *larb = dev_get_drvdata(dev);
247
248 writel(*larb->mmu, larb->base + SMI_LARB_MMU_EN);
249}
250
251static void mtk_smi_larb_config_port_gen1(struct device *dev)
252{
253 struct mtk_smi_larb *larb = dev_get_drvdata(dev);
254 const struct mtk_smi_larb_gen *larb_gen = larb->larb_gen;
255 struct mtk_smi *common = dev_get_drvdata(larb->smi_common_dev);
256 int i, m4u_port_id, larb_port_num;
257 u32 sec_con_val, reg_val;
258
259 m4u_port_id = larb_gen->port_in_larb[larb->larbid];
260 larb_port_num = larb_gen->port_in_larb[larb->larbid + 1]
261 - larb_gen->port_in_larb[larb->larbid];
262
263 for (i = 0; i < larb_port_num; i++, m4u_port_id++) {
264 if (*larb->mmu & BIT(i)) {
265 /* bit[port + 3] controls the virtual or physical */
266 sec_con_val = SMI_SECUR_CON_VAL_VIRT(m4u_port_id);
267 } else {
268 /* do not need to enable m4u for this port */
269 continue;
270 }
271 reg_val = readl(common->smi_ao_base
272 + REG_SMI_SECUR_CON_ADDR(m4u_port_id));
273 reg_val &= SMI_SECUR_CON_VAL_MSK(m4u_port_id);
274 reg_val |= sec_con_val;
275 reg_val |= SMI_SECUR_CON_VAL_DOMAIN(m4u_port_id);
276 writel(reg_val,
277 common->smi_ao_base
278 + REG_SMI_SECUR_CON_ADDR(m4u_port_id));
279 }
280}
281
282static void
283mtk_smi_larb_unbind(struct device *dev, struct device *master, void *data)
284{
285 /* Do nothing as the iommu is always enabled. */
286}
287
288static const struct component_ops mtk_smi_larb_component_ops = {
289 .bind = mtk_smi_larb_bind,
290 .unbind = mtk_smi_larb_unbind,
291};
292
293static u8
294mtk_smi_larb_mt6779_bwl[MTK_LARB_NR_MAX][SMI_LARB_PORT_NR_MAX] = {
295 {0x28, 0x28, 0x01, 0x28, 0x01, 0x01, 0x0a, 0x0a, 0x28,},
296 {0x28, 0x01, 0x28, 0x28, 0x0a, 0x01, 0x01, 0x0d, 0x0d, 0x07,
297 0x01, 0x07, 0x01, 0x28,},
298 {0x18, 0x01, 0x08, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02,
299 0x01, 0x01},
300 {0x01, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01, 0x04, 0x02, 0x01,
301 0x04, 0x01, 0x01, 0x01, 0x01, 0x04, 0x0b, 0x13, 0x14,},
302 {},
303 {0x13, 0x0f, 0x0d, 0x07, 0x07, 0x04, 0x03, 0x01, 0x03, 0x01,
304 0x05, 0x0c, 0x01, 0x01, 0x08, 0x06, 0x02, 0x01, 0x08, 0x08,
305 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,},
306 {0x01, 0x01, 0x01,},
307 {0x01, 0x01, 0x01, 0x01,},
308 {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,},
309 {0x1f, 0x1a, 0x02, 0x04, 0x1f, 0x02, 0x14, 0x01, 0x1f, 0x04,
310 0x04, 0x01, 0x01, 0x01, 0x02, 0x02, 0x04, 0x02, 0x01, 0x02,
311 0x04, 0x02, 0x02, 0x01,},
312 {0x1f, 0x1a, 0x02, 0x04, 0x1f, 0x02, 0x14, 0x01, 0x1f, 0x1a,
313 0x02, 0x04, 0x1f, 0x02, 0x14, 0x01, 0x01, 0x02, 0x02, 0x04,
314 0x02, 0x0a, 0x02, 0x02, 0x04, 0x02, 0x0a, 0x02, 0x04, 0x02, 0x04,},
315 {0x01, 0x01, 0x01, 0x01, 0x01,},
316};
317
318static struct mtk_smi_reg_pair
319mtk_smi_larb_mt6779_misc[MTK_LARB_NR_MAX][SMI_LARB_MISC_NR] = {
320 {{SMI_LARB_CMD_THRT_CON, 0x370256}, {SMI_LARB_SW_FLAG, 0x1},},
321 {{SMI_LARB_CMD_THRT_CON, 0x300256}, {SMI_LARB_SW_FLAG, 0x1},},
322 {{SMI_LARB_CMD_THRT_CON, 0x370256}, {SMI_LARB_SW_FLAG, 0x1},},
323 {},
324 {{SMI_LARB_CMD_THRT_CON, 0x300256}, {SMI_LARB_SW_FLAG, 0x1},},
325 {{SMI_LARB_CMD_THRT_CON, 0x300256}, {SMI_LARB_SW_FLAG, 0x1},},
326 {{SMI_LARB_CMD_THRT_CON, 0x300256}, {SMI_LARB_SW_FLAG, 0x1},},
327 {{SMI_LARB_CMD_THRT_CON, 0x300256}, {SMI_LARB_SW_FLAG, 0x1},},
328 {{SMI_LARB_CMD_THRT_CON, 0x370256}, {SMI_LARB_SW_FLAG, 0x1},},
329 {{SMI_LARB_CMD_THRT_CON, 0x370256}, {SMI_LARB_SW_FLAG, 0x1},},
330 {{SMI_LARB_CMD_THRT_CON, 0x370256}, {SMI_LARB_SW_FLAG, 0x1},},
331};
332
333static const struct mtk_smi_larb_gen mtk_smi_larb_mt8173 = {
334 /* mt8173 do not need the port in larb */
335 .config_port = mtk_smi_larb_config_port_mt8173,
336};
337
338static const struct mtk_smi_larb_gen mtk_smi_larb_mt2701 = {
339 .port_in_larb = {
340 LARB0_PORT_OFFSET, LARB1_PORT_OFFSET,
341 LARB2_PORT_OFFSET, LARB3_PORT_OFFSET
342 },
343 .config_port = mtk_smi_larb_config_port_gen1,
344};
345
346static const struct mtk_smi_larb_gen mtk_smi_larb_mt2712 = {
347 .config_port = mtk_smi_larb_config_port_gen2_general,
348 .larb_direct_to_common_mask = BIT(8) | BIT(9), /* bdpsys */
349};
350
351static const struct mtk_smi_larb_gen mtk_smi_larb_mt6779 = {
352 .port_in_larb = {9, 14, 12, 19, 0, 26, 3, 4, 10, 24, 31, 5,},
353 .config_port = mtk_smi_larb_config_port_gen2_general,
354 .larb_direct_to_common_mask = BIT(4) | BIT(6) | BIT(11) |
355 BIT(12) | BIT(13),
356 /* DUMMY | IPU0 | IPU1 | CCU | MDLA */
357 .has_bwl = true,
358 .bwl = (u8 *)mtk_smi_larb_mt6779_bwl,
359 .misc = (struct mtk_smi_reg_pair *)mtk_smi_larb_mt6779_misc,
360};
361
362static const struct mtk_smi_larb_gen mtk_smi_larb_mt8183 = {
363 .has_gals = true,
364 .config_port = mtk_smi_larb_config_port_gen2_general,
365 .larb_direct_to_common_mask = BIT(2) | BIT(3) | BIT(7),
366 /* IPU0 | IPU1 | CCU */
367};
368
369static const struct mtk_smi_larb_gen mtk_smi_larb_mt6880 = {
370};
371
372static const struct of_device_id mtk_smi_larb_of_ids[] = {
373 {
374 .compatible = "mediatek,mt8173-smi-larb",
375 .data = &mtk_smi_larb_mt8173
376 },
377 {
378 .compatible = "mediatek,mt2701-smi-larb",
379 .data = &mtk_smi_larb_mt2701
380 },
381 {
382 .compatible = "mediatek,mt2712-smi-larb",
383 .data = &mtk_smi_larb_mt2712
384 },
385 {
386 .compatible = "mediatek,mt6779-smi-larb",
387 .data = &mtk_smi_larb_mt6779
388 },
389 {
390 .compatible = "mediatek,mt8183-smi-larb",
391 .data = &mtk_smi_larb_mt8183
392 },
393 {
394 .compatible = "mediatek,mt6880-smi-larb",
395 .data = &mtk_smi_larb_mt6880
396 },
397 {}
398};
399
400static int mtk_smi_larb_probe(struct platform_device *pdev)
401{
402 struct mtk_smi_larb *larb;
403 struct resource *res;
404 struct device *dev = &pdev->dev;
405 struct device_node *smi_node;
406 struct platform_device *smi_pdev;
407 struct device_link *link;
408
409 larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL);
410 if (!larb)
411 return -ENOMEM;
412
413 larb->larb_gen = of_device_get_match_data(dev);
414 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
415 larb->base = devm_ioremap_resource(dev, res);
416
417 if (IS_ERR(larb->base))
418 pr_err("Failed to get larb->base\n");
419
420 larb->smi.clk_apb = devm_clk_get(dev, "apb");
421 if (IS_ERR(larb->smi.clk_apb))
422 pr_err("Failed to get larb->smi.clk_apb\n");
423
424 larb->smi.clk_smi = devm_clk_get(dev, "smi");
425 if (IS_ERR(larb->smi.clk_smi))
426 pr_err("Failed to get larb->smi.clk_smi\n");
427
428 if (larb->larb_gen->has_gals) {
429 /* The larbs may still haven't gals even if the SoC support.*/
430 larb->smi.clk_gals0 = devm_clk_get(dev, "gals");
431 if (PTR_ERR(larb->smi.clk_gals0) == -ENOENT)
432 larb->smi.clk_gals0 = NULL;
433 else if (IS_ERR(larb->smi.clk_gals0))
434 pr_err("Failed to get larb->smi.clk_gals0\n");
435 }
436 larb->smi.dev = dev;
437
438 smi_node = of_parse_phandle(dev->of_node, "mediatek,smi", 0);
439 if (!smi_node)
440 return -EINVAL;
441
442 smi_pdev = of_find_device_by_node(smi_node);
443 of_node_put(smi_node);
444 if (smi_pdev) {
445 if (!platform_get_drvdata(smi_pdev))
446 return -EPROBE_DEFER;
447 larb->smi_common_dev = &smi_pdev->dev;
448 link = device_link_add(dev, larb->smi_common_dev,
449 DL_FLAG_PM_RUNTIME);
450 if (!link) {
451 dev_err(dev, "Unable to link smi-common dev\n");
452 return -ENODEV;
453 }
454 } else {
455 dev_err(dev, "Failed to get the smi_common device\n");
456 return -EINVAL;
457 }
458
459 pm_runtime_enable(dev);
460 platform_set_drvdata(pdev, larb);
461 pr_info("[SMI LOG] smi larb probe done\n");
462 return component_add(dev, &mtk_smi_larb_component_ops);
463}
464
465static int mtk_smi_larb_remove(struct platform_device *pdev)
466{
467 pm_runtime_disable(&pdev->dev);
468 component_del(&pdev->dev, &mtk_smi_larb_component_ops);
469 return 0;
470}
471
472static int __maybe_unused mtk_smi_larb_resume(struct device *dev)
473{
474 struct mtk_smi_larb *larb = dev_get_drvdata(dev);
475 const struct mtk_smi_larb_gen *larb_gen = larb->larb_gen;
476 int ret;
477
478 ret = mtk_smi_clk_enable(&larb->smi);
479 if (ret < 0) {
480 dev_err(dev, "Failed to enable clock(%d).\n", ret);
481 //return ret;
482 }
483
484 /* Configure the basic setting for this larb */
485 larb_gen->config_port(dev);
486
487 return 0;
488}
489
490static int __maybe_unused mtk_smi_larb_suspend(struct device *dev)
491{
492 struct mtk_smi_larb *larb = dev_get_drvdata(dev);
493
494 mtk_smi_clk_disable(&larb->smi);
495 return 0;
496}
497
498static const struct dev_pm_ops smi_larb_pm_ops = {
499 SET_RUNTIME_PM_OPS(mtk_smi_larb_suspend, mtk_smi_larb_resume, NULL)
500 SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
501 pm_runtime_force_resume)
502};
503
504static struct platform_driver mtk_smi_larb_driver = {
505 .probe = mtk_smi_larb_probe,
506 .remove = mtk_smi_larb_remove,
507 .driver = {
508 .name = "mtk-smi-larb",
509 .of_match_table = mtk_smi_larb_of_ids,
510 .pm = &smi_larb_pm_ops,
511 }
512};
513
514static u16 mtk_smi_common_mt6779_bwl[SMI_COMMON_LARB_NR_MAX] = {
515 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000,
516};
517
518static struct mtk_smi_reg_pair
519mtk_smi_common_mt6779_misc[SMI_COMMON_MISC_NR] = {
520 {SMI_L1LEN, 0xb},
521 {SMI_M4U_TH, 0xe100e10},
522 {SMI_FIFO_TH1, 0x506090a},
523 {SMI_FIFO_TH2, 0x506090a},
524 {SMI_DCM, 0x4f1},
525 {SMI_DUMMY, 0x1},
526};
527
528static const struct mtk_smi_common_plat mtk_smi_common_gen1 = {
529 .gen = MTK_SMI_GEN1,
530};
531
532static const struct mtk_smi_common_plat mtk_smi_common_gen2 = {
533 .gen = MTK_SMI_GEN2,
534};
535
536static const struct mtk_smi_common_plat mtk_smi_common_mt6779 = {
537 .gen = MTK_SMI_GEN2,
538 .has_gals = true,
539 .bus_sel = F_MMU1_LARB(1) | F_MMU1_LARB(2) | F_MMU1_LARB(4) |
540 F_MMU1_LARB(5) | F_MMU1_LARB(6) | F_MMU1_LARB(7),
541 .has_bwl = true,
542 .bwl = mtk_smi_common_mt6779_bwl,
543 .misc = mtk_smi_common_mt6779_misc,
544};
545
546static const struct mtk_smi_common_plat mtk_smi_common_mt8183 = {
547 .gen = MTK_SMI_GEN2,
548 .has_gals = true,
549 .bus_sel = F_MMU1_LARB(1) | F_MMU1_LARB(2) | F_MMU1_LARB(5) |
550 F_MMU1_LARB(7),
551};
552
553static const struct mtk_smi_common_plat mtk_smi_common_mt6880 = {
554};
555
556static const struct of_device_id mtk_smi_common_of_ids[] = {
557 {
558 .compatible = "mediatek,mt8173-smi-common",
559 .data = &mtk_smi_common_gen2,
560 },
561 {
562 .compatible = "mediatek,mt2701-smi-common",
563 .data = &mtk_smi_common_gen1,
564 },
565 {
566 .compatible = "mediatek,mt2712-smi-common",
567 .data = &mtk_smi_common_gen2,
568 },
569 {
570 .compatible = "mediatek,mt6779-smi-common",
571 .data = &mtk_smi_common_mt6779,
572 },
573 {
574 .compatible = "mediatek,mt8183-smi-common",
575 .data = &mtk_smi_common_mt8183,
576 },
577 {
578 .compatible = "mediatek,mt6880-smi-common",
579 .data = &mtk_smi_common_mt6880,
580 },
581 {}
582};
583
584static int mtk_smi_common_probe(struct platform_device *pdev)
585{
586 struct device *dev = &pdev->dev;
587 struct mtk_smi *common;
588 struct resource *res;
589 //int ret;
590
591 common = devm_kzalloc(dev, sizeof(*common), GFP_KERNEL);
592 if (!common)
593 return -ENOMEM;
594
595 common->dev = dev;
596 common->plat = of_device_get_match_data(dev);
597
598 common->clk_apb = devm_clk_get(dev, "apb");
599 if (IS_ERR(common->clk_apb))
600 pr_err("Failed to get common->clk_apb\n");
601
602 common->clk_smi = devm_clk_get(dev, "smi");
603 if (IS_ERR(common->clk_smi))
604 pr_err("Failed to get common->clk_smi\n");
605
606 if (common->plat->has_gals) {
607 common->clk_gals0 = devm_clk_get(dev, "gals0");
608 if (IS_ERR(common->clk_gals0))
609 pr_err("Failed to get common->clk_gals0\n");
610
611 common->clk_gals1 = devm_clk_get(dev, "gals1");
612 if (IS_ERR(common->clk_gals1))
613 pr_err("Failed to get common->clk_gals1\n");
614 }
615
616 /*
617 * for mtk smi gen 1, we need to get the ao(always on) base to config
618 * m4u port, and we need to enable the aync clock for transform the smi
619 * clock into emi clock domain, but for mtk smi gen2, there's no smi ao
620 * base.
621 */
622 if (common->plat->gen == MTK_SMI_GEN1) {
623 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
624 common->smi_ao_base = devm_ioremap_resource(dev, res);
625 if (IS_ERR(common->smi_ao_base))
626 pr_err("Failed to get common->smi_ao_base\n");
627
628 common->clk_async = devm_clk_get(dev, "async");
629 if (IS_ERR(common->clk_async))
630 pr_err("Failed to get common->clk_async\n");
631
632 //ret = clk_prepare_enable(common->clk_async);
633 //if (ret){
634 // pr_err("Failed to get common->clk_async\n");
635 //}
636 /*ret = clk_prepare_enable(common->clk_async);
637 if (ret)
638 return ret;*/
639 } else {
640 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
641 common->base = devm_ioremap_resource(dev, res);
642 if (IS_ERR(common->base))
643 pr_err("Failed to get common->base\n");
644 }
645 pm_runtime_enable(dev);
646 platform_set_drvdata(pdev, common);
647 return 0;
648}
649
650static int mtk_smi_common_remove(struct platform_device *pdev)
651{
652 pm_runtime_disable(&pdev->dev);
653 return 0;
654}
655
656static int __maybe_unused mtk_smi_common_resume(struct device *dev)
657{
658 /*struct mtk_smi *common = dev_get_drvdata(dev);
659 u32 bus_sel = common->plat->bus_sel;
660 int i, ret;
661
662 ret = mtk_smi_clk_enable(common);
663 if (ret) {
664 dev_err(common->dev, "Failed to enable clock(%d).\n", ret);
665 return ret;
666 }
667
668 if (common->plat->gen == MTK_SMI_GEN2 && bus_sel)
669 writel(bus_sel, common->base + SMI_BUS_SEL);
670
671 if (common->plat->gen != MTK_SMI_GEN2 || !common->plat->has_bwl)
672 return 0;
673
674 for (i = 0; i < SMI_COMMON_LARB_NR_MAX; i++)
675 writel_relaxed(common->plat->bwl[i],
676 common->base + SMI_L1ARB(i));
677
678 for (i = 0; i < SMI_COMMON_MISC_NR; i++)
679 writel_relaxed(common->plat->misc[i].value,
680 common->base + common->plat->misc[i].offset);
681 wmb();*/ /* make sure settings are written */
682 pr_info("[SMI LOG] mtk_smi_common_resume Done\n");
683 return 0;
684}
685
686static int __maybe_unused mtk_smi_common_suspend(struct device *dev)
687{
688 /*struct mtk_smi *common = dev_get_drvdata(dev);
689
690 mtk_smi_clk_disable(common);*/
691 return 0;
692}
693
694static const struct dev_pm_ops smi_common_pm_ops = {
695 SET_RUNTIME_PM_OPS(mtk_smi_common_suspend, mtk_smi_common_resume, NULL)
696 SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
697 pm_runtime_force_resume)
698};
699
700static struct platform_driver mtk_smi_common_driver = {
701 .probe = mtk_smi_common_probe,
702 .remove = mtk_smi_common_remove,
703 .driver = {
704 .name = "mtk-smi-common",
705 .of_match_table = mtk_smi_common_of_ids,
706 .pm = &smi_common_pm_ops,
707 }
708};
709
710static int __init mtk_smi_init(void)
711{
712 int ret;
713 pr_info("[SMI LOG] Start to register-COMMON SMI driver\n");
714 ret = platform_driver_register(&mtk_smi_common_driver);
715 if (ret != 0) {
716 pr_err("Failed to register SMI driver\n");
717 return ret;
718 }
719 pr_info("[SMI LOG] Start to register SMI-LARB driver\n");
720 ret = platform_driver_register(&mtk_smi_larb_driver);
721 if (ret != 0) {
722 pr_err("Failed to register SMI-LARB driver\n");
723 goto err_unreg_smi;
724 }
725 pr_info("[SMI LOG] smi init done\n");
726 return ret;
727
728err_unreg_smi:
729 platform_driver_unregister(&mtk_smi_common_driver);
730 return ret;
731}
732
733module_init(mtk_smi_init);
734MODULE_LICENSE("GPL v2");