| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2019 MediaTek Inc. |
| 4 | */ |
| 5 | |
| 6 | #include <linux/clk-provider.h> |
| 7 | #include <linux/platform_device.h> |
| 8 | |
| 9 | #include "clk-mtk.h" |
| 10 | #include "clk-gate.h" |
| 11 | |
| 12 | #include <dt-bindings/clock/mt8168-clk.h> |
| 13 | |
| 14 | static const struct mtk_gate_regs mfg0_cg_regs = { |
| 15 | .set_ofs = 0x4, |
| 16 | .clr_ofs = 0x8, |
| 17 | .sta_ofs = 0x0, |
| 18 | }; |
| 19 | |
| 20 | static const struct mtk_gate_regs mfg1_cg_regs = { |
| 21 | .set_ofs = 0x280, |
| 22 | .clr_ofs = 0x280, |
| 23 | .sta_ofs = 0x280, |
| 24 | }; |
| 25 | |
| 26 | #define GATE_MFG0(_id, _name, _parent, _shift) { \ |
| 27 | .id = _id, \ |
| 28 | .name = _name, \ |
| 29 | .parent_name = _parent, \ |
| 30 | .regs = &mfg0_cg_regs, \ |
| 31 | .shift = _shift, \ |
| 32 | .ops = &mtk_clk_gate_ops_setclr, \ |
| 33 | } |
| 34 | |
| 35 | #define GATE_MFG1(_id, _name, _parent, _shift) { \ |
| 36 | .id = _id, \ |
| 37 | .name = _name, \ |
| 38 | .parent_name = _parent, \ |
| 39 | .regs = &mfg1_cg_regs, \ |
| 40 | .shift = _shift, \ |
| 41 | .ops = &mtk_clk_gate_ops_no_setclr, \ |
| 42 | } |
| 43 | |
| 44 | static const struct mtk_gate mfg_clks[] = { |
| 45 | /* MFG0 */ |
| 46 | GATE_MFG0(CLK_MFG_BG3D, "mfg_bg3d", "mfg_sel", 0), |
| 47 | /* MFG1 */ |
| 48 | GATE_MFG1(CLK_MFG_MBIST_DIAG, "mfg_mbist_diag", "mbist_diag_sel", 24), |
| 49 | }; |
| 50 | |
| 51 | static int clk_mt8168_mfg_probe(struct platform_device *pdev) |
| 52 | { |
| 53 | struct clk_onecell_data *clk_data; |
| 54 | int r; |
| 55 | struct device_node *node = pdev->dev.of_node; |
| 56 | |
| 57 | clk_data = mtk_alloc_clk_data(CLK_MFG_NR_CLK); |
| 58 | |
| 59 | mtk_clk_register_gates(node, mfg_clks, ARRAY_SIZE(mfg_clks), clk_data); |
| 60 | |
| 61 | r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); |
| 62 | |
| 63 | if (r) |
| 64 | pr_err("%s(): could not register clock provider: %d\n", |
| 65 | __func__, r); |
| 66 | |
| 67 | return r; |
| 68 | } |
| 69 | |
| 70 | static const struct of_device_id of_match_clk_mt8168_mfg[] = { |
| 71 | { .compatible = "mediatek,mt8168-mfgcfg", }, |
| 72 | {} |
| 73 | }; |
| 74 | |
| 75 | static struct platform_driver clk_mt8168_mfg_drv = { |
| 76 | .probe = clk_mt8168_mfg_probe, |
| 77 | .driver = { |
| 78 | .name = "clk-mt8168-mfg", |
| 79 | .of_match_table = of_match_clk_mt8168_mfg, |
| 80 | }, |
| 81 | }; |
| 82 | |
| 83 | builtin_platform_driver(clk_mt8168_mfg_drv); |