1*43c04ed7SYassine Oudjana // SPDX-License-Identifier: GPL-2.0 2*43c04ed7SYassine Oudjana /* 3*43c04ed7SYassine Oudjana * Copyright (c) 2022 Yassine Oudjana <y.oudjana@protonmail.com> 4*43c04ed7SYassine Oudjana */ 5*43c04ed7SYassine Oudjana 6*43c04ed7SYassine Oudjana #include <linux/clk-provider.h> 7*43c04ed7SYassine Oudjana #include <linux/platform_device.h> 8*43c04ed7SYassine Oudjana 9*43c04ed7SYassine Oudjana #include "clk-gate.h" 10*43c04ed7SYassine Oudjana #include "clk-mtk.h" 11*43c04ed7SYassine Oudjana 12*43c04ed7SYassine Oudjana #include <dt-bindings/clock/mediatek,mt6735-infracfg.h> 13*43c04ed7SYassine Oudjana #include <dt-bindings/reset/mediatek,mt6735-infracfg.h> 14*43c04ed7SYassine Oudjana 15*43c04ed7SYassine Oudjana #define INFRA_RST0 0x30 16*43c04ed7SYassine Oudjana #define INFRA_GLOBALCON_PDN0 0x40 17*43c04ed7SYassine Oudjana #define INFRA_PDN1 0x44 18*43c04ed7SYassine Oudjana #define INFRA_PDN_STA 0x48 19*43c04ed7SYassine Oudjana 20*43c04ed7SYassine Oudjana #define RST_NR_PER_BANK 32 21*43c04ed7SYassine Oudjana 22*43c04ed7SYassine Oudjana static struct mtk_gate_regs infra_cg_regs = { 23*43c04ed7SYassine Oudjana .set_ofs = INFRA_GLOBALCON_PDN0, 24*43c04ed7SYassine Oudjana .clr_ofs = INFRA_PDN1, 25*43c04ed7SYassine Oudjana .sta_ofs = INFRA_PDN_STA, 26*43c04ed7SYassine Oudjana }; 27*43c04ed7SYassine Oudjana 28*43c04ed7SYassine Oudjana static const struct mtk_gate infracfg_gates[] = { 29*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_DBG, "dbg", "axi_sel", &infra_cg_regs, 0, &mtk_clk_gate_ops_setclr), 30*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_GCE, "gce", "axi_sel", &infra_cg_regs, 1, &mtk_clk_gate_ops_setclr), 31*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_TRBG, "trbg", "axi_sel", &infra_cg_regs, 2, &mtk_clk_gate_ops_setclr), 32*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_CPUM, "cpum", "axi_sel", &infra_cg_regs, 3, &mtk_clk_gate_ops_setclr), 33*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_DEVAPC, "devapc", "axi_sel", &infra_cg_regs, 4, &mtk_clk_gate_ops_setclr), 34*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_AUDIO, "audio", "aud_intbus_sel", &infra_cg_regs, 5, &mtk_clk_gate_ops_setclr), 35*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_GCPU, "gcpu", "axi_sel", &infra_cg_regs, 6, &mtk_clk_gate_ops_setclr), 36*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_L2C_SRAM, "l2csram", "axi_sel", &infra_cg_regs, 7, &mtk_clk_gate_ops_setclr), 37*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_M4U, "m4u", "axi_sel", &infra_cg_regs, 8, &mtk_clk_gate_ops_setclr), 38*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_CLDMA, "cldma", "axi_sel", &infra_cg_regs, 12, &mtk_clk_gate_ops_setclr), 39*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_CONNMCU_BUS, "connmcu_bus", "axi_sel", &infra_cg_regs, 15, &mtk_clk_gate_ops_setclr), 40*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_KP, "kp", "axi_sel", &infra_cg_regs, 16, &mtk_clk_gate_ops_setclr), 41*43c04ed7SYassine Oudjana GATE_MTK_FLAGS(CLK_INFRA_APXGPT, "apxgpt", "axi_sel", &infra_cg_regs, 18, &mtk_clk_gate_ops_setclr, CLK_IS_CRITICAL), 42*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_SEJ, "sej", "axi_sel", &infra_cg_regs, 19, &mtk_clk_gate_ops_setclr), 43*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_CCIF0_AP, "ccif0ap", "axi_sel", &infra_cg_regs, 20, &mtk_clk_gate_ops_setclr), 44*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_CCIF1_AP, "ccif1ap", "axi_sel", &infra_cg_regs, 21, &mtk_clk_gate_ops_setclr), 45*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_PMIC_SPI, "pmicspi", "pmicspi_sel", &infra_cg_regs, 22, &mtk_clk_gate_ops_setclr), 46*43c04ed7SYassine Oudjana GATE_MTK(CLK_INFRA_PMIC_WRAP, "pmicwrap", "axi_sel", &infra_cg_regs, 23, &mtk_clk_gate_ops_setclr) 47*43c04ed7SYassine Oudjana }; 48*43c04ed7SYassine Oudjana 49*43c04ed7SYassine Oudjana static u16 infracfg_rst_bank_ofs[] = { INFRA_RST0 }; 50*43c04ed7SYassine Oudjana 51*43c04ed7SYassine Oudjana static u16 infracfg_rst_idx_map[] = { 52*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_EMI_REG] = 0 * RST_NR_PER_BANK + 0, 53*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_DRAMC0_AO] = 0 * RST_NR_PER_BANK + 1, 54*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_AP_CIRQ_EINT] = 0 * RST_NR_PER_BANK + 3, 55*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_APXGPT] = 0 * RST_NR_PER_BANK + 4, 56*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_SCPSYS] = 0 * RST_NR_PER_BANK + 5, 57*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_KP] = 0 * RST_NR_PER_BANK + 6, 58*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_PMIC_WRAP] = 0 * RST_NR_PER_BANK + 7, 59*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_CLDMA_AO_TOP] = 0 * RST_NR_PER_BANK + 8, 60*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_USBSIF_TOP] = 0 * RST_NR_PER_BANK + 9, 61*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_EMI] = 0 * RST_NR_PER_BANK + 16, 62*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_CCIF] = 0 * RST_NR_PER_BANK + 17, 63*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_DRAMC0] = 0 * RST_NR_PER_BANK + 18, 64*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_EMI_AO_REG] = 0 * RST_NR_PER_BANK + 19, 65*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_CCIF_AO] = 0 * RST_NR_PER_BANK + 20, 66*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_TRNG] = 0 * RST_NR_PER_BANK + 21, 67*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_SYS_CIRQ] = 0 * RST_NR_PER_BANK + 22, 68*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_GCE] = 0 * RST_NR_PER_BANK + 23, 69*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_M4U] = 0 * RST_NR_PER_BANK + 24, 70*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_CCIF1] = 0 * RST_NR_PER_BANK + 25, 71*43c04ed7SYassine Oudjana [MT6735_INFRA_RST0_CLDMA_TOP_PD] = 0 * RST_NR_PER_BANK + 26 72*43c04ed7SYassine Oudjana }; 73*43c04ed7SYassine Oudjana 74*43c04ed7SYassine Oudjana static const struct mtk_clk_rst_desc infracfg_resets = { 75*43c04ed7SYassine Oudjana .version = MTK_RST_SIMPLE, 76*43c04ed7SYassine Oudjana .rst_bank_ofs = infracfg_rst_bank_ofs, 77*43c04ed7SYassine Oudjana .rst_bank_nr = ARRAY_SIZE(infracfg_rst_bank_ofs), 78*43c04ed7SYassine Oudjana .rst_idx_map = infracfg_rst_idx_map, 79*43c04ed7SYassine Oudjana .rst_idx_map_nr = ARRAY_SIZE(infracfg_rst_idx_map) 80*43c04ed7SYassine Oudjana }; 81*43c04ed7SYassine Oudjana 82*43c04ed7SYassine Oudjana static const struct mtk_clk_desc infracfg_clks = { 83*43c04ed7SYassine Oudjana .clks = infracfg_gates, 84*43c04ed7SYassine Oudjana .num_clks = ARRAY_SIZE(infracfg_gates), 85*43c04ed7SYassine Oudjana 86*43c04ed7SYassine Oudjana .rst_desc = &infracfg_resets 87*43c04ed7SYassine Oudjana }; 88*43c04ed7SYassine Oudjana 89*43c04ed7SYassine Oudjana static const struct of_device_id of_match_mt6735_infracfg[] = { 90*43c04ed7SYassine Oudjana { .compatible = "mediatek,mt6735-infracfg", .data = &infracfg_clks }, 91*43c04ed7SYassine Oudjana { /* sentinel */ } 92*43c04ed7SYassine Oudjana }; 93*43c04ed7SYassine Oudjana MODULE_DEVICE_TABLE(of, of_match_mt6735_infracfg); 94*43c04ed7SYassine Oudjana 95*43c04ed7SYassine Oudjana static struct platform_driver clk_mt6735_infracfg = { 96*43c04ed7SYassine Oudjana .probe = mtk_clk_simple_probe, 97*43c04ed7SYassine Oudjana .remove = mtk_clk_simple_remove, 98*43c04ed7SYassine Oudjana .driver = { 99*43c04ed7SYassine Oudjana .name = "clk-mt6735-infracfg", 100*43c04ed7SYassine Oudjana .of_match_table = of_match_mt6735_infracfg, 101*43c04ed7SYassine Oudjana }, 102*43c04ed7SYassine Oudjana }; 103*43c04ed7SYassine Oudjana module_platform_driver(clk_mt6735_infracfg); 104*43c04ed7SYassine Oudjana 105*43c04ed7SYassine Oudjana MODULE_AUTHOR("Yassine Oudjana <y.oudjana@protonmail.com>"); 106*43c04ed7SYassine Oudjana MODULE_DESCRIPTION("MediaTek MT6735 infracfg clock and reset driver"); 107*43c04ed7SYassine Oudjana MODULE_LICENSE("GPL"); 108