• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2018 MediaTek Inc.
4  * Author: Sean Wang <sean.wang@mediatek.com>
5  *
6  */
7 
8 #include <linux/clk-provider.h>
9 #include <linux/of.h>
10 #include <linux/of_address.h>
11 #include <linux/of_device.h>
12 #include <linux/platform_device.h>
13 
14 #include "clk-mtk.h"
15 #include "clk-gate.h"
16 
17 #include <dt-bindings/clock/mt2701-clk.h>
18 
19 #define GATE_G3D(_id, _name, _parent, _shift)				\
20 	GATE_MTK(_id, _name, _parent, &g3d_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
21 
22 static const struct mtk_gate_regs g3d_cg_regs = {
23 	.sta_ofs = 0x0,
24 	.set_ofs = 0x4,
25 	.clr_ofs = 0x8,
26 };
27 
28 static const struct mtk_gate g3d_clks[] = {
29 	GATE_G3D(CLK_G3DSYS_CORE, "g3d_core", "mfg_sel", 0),
30 };
31 
32 static u16 rst_ofs[] = { 0xc, };
33 
34 static const struct mtk_clk_rst_desc clk_rst_desc = {
35 	.version = MTK_RST_SIMPLE,
36 	.rst_bank_ofs = rst_ofs,
37 	.rst_bank_nr = ARRAY_SIZE(rst_ofs),
38 };
39 
clk_mt2701_g3dsys_init(struct platform_device * pdev)40 static int clk_mt2701_g3dsys_init(struct platform_device *pdev)
41 {
42 	struct clk_hw_onecell_data *clk_data;
43 	struct device_node *node = pdev->dev.of_node;
44 	int r;
45 
46 	clk_data = mtk_alloc_clk_data(CLK_G3DSYS_NR);
47 
48 	mtk_clk_register_gates(node, g3d_clks, ARRAY_SIZE(g3d_clks),
49 			       clk_data);
50 
51 	r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
52 	if (r)
53 		dev_err(&pdev->dev,
54 			"could not register clock provider: %s: %d\n",
55 			pdev->name, r);
56 
57 	mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
58 
59 	return r;
60 }
61 
62 static const struct of_device_id of_match_clk_mt2701_g3d[] = {
63 	{
64 		.compatible = "mediatek,mt2701-g3dsys",
65 		.data = clk_mt2701_g3dsys_init,
66 	}, {
67 		/* sentinel */
68 	}
69 };
70 
clk_mt2701_g3d_probe(struct platform_device * pdev)71 static int clk_mt2701_g3d_probe(struct platform_device *pdev)
72 {
73 	int (*clk_init)(struct platform_device *);
74 	int r;
75 
76 	clk_init = of_device_get_match_data(&pdev->dev);
77 	if (!clk_init)
78 		return -EINVAL;
79 
80 	r = clk_init(pdev);
81 	if (r)
82 		dev_err(&pdev->dev,
83 			"could not register clock provider: %s: %d\n",
84 			pdev->name, r);
85 
86 	return r;
87 }
88 
89 static struct platform_driver clk_mt2701_g3d_drv = {
90 	.probe = clk_mt2701_g3d_probe,
91 	.driver = {
92 		.name = "clk-mt2701-g3d",
93 		.of_match_table = of_match_clk_mt2701_g3d,
94 	},
95 };
96 
97 builtin_platform_driver(clk_mt2701_g3d_drv);
98