1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/clk-provider.h>
3 #include <linux/module.h>
4 #include <linux/platform_device.h>
5 #include <linux/spinlock.h>
7 #include <dt-bindings/clock/marvell,pxa1908.h>
11 #define APMU_CLK_GATE_CTRL 0x40
12 #define APMU_CCIC1 0x24
14 #define APMU_DSI1 0x44
15 #define APMU_DISP1 0x4c
16 #define APMU_CCIC0 0x50
17 #define APMU_SDH0 0x54
18 #define APMU_SDH1 0x58
23 #define APMU_SDH2 0xe0
24 #define APMU_GC2D 0xf4
25 #define APMU_TRACE 0x108
26 #define APMU_DVC_DFC_DEBUG 0x140
28 #define APMU_NR_CLKS 17
30 struct pxa1908_clk_unit
{
31 struct mmp_clk_unit unit
;
35 static DEFINE_SPINLOCK(pll1_lock
);
36 static struct mmp_param_general_gate_clk pll1_gate_clks
[] = {
37 {PXA1908_CLK_PLL1_D2_GATE
, "pll1_d2_gate", "pll1_d2", 0, APMU_CLK_GATE_CTRL
, 29, 0, &pll1_lock
},
38 {PXA1908_CLK_PLL1_416_GATE
, "pll1_416_gate", "pll1_416", 0, APMU_CLK_GATE_CTRL
, 27, 0, &pll1_lock
},
39 {PXA1908_CLK_PLL1_624_GATE
, "pll1_624_gate", "pll1_624", 0, APMU_CLK_GATE_CTRL
, 26, 0, &pll1_lock
},
40 {PXA1908_CLK_PLL1_832_GATE
, "pll1_832_gate", "pll1_832", 0, APMU_CLK_GATE_CTRL
, 30, 0, &pll1_lock
},
41 {PXA1908_CLK_PLL1_1248_GATE
, "pll1_1248_gate", "pll1_1248", 0, APMU_CLK_GATE_CTRL
, 28, 0, &pll1_lock
},
44 static DEFINE_SPINLOCK(sdh0_lock
);
45 static DEFINE_SPINLOCK(sdh1_lock
);
46 static DEFINE_SPINLOCK(sdh2_lock
);
48 static const char * const sdh_parent_names
[] = {"pll1_416", "pll1_624"};
50 static struct mmp_clk_mix_config sdh_mix_config
= {
51 .reg_info
= DEFINE_MIX_REG_INFO(3, 8, 2, 6, 11),
54 static struct mmp_param_gate_clk apmu_gate_clks
[] = {
55 {PXA1908_CLK_USB
, "usb_clk", NULL
, 0, APMU_USB
, 0x9, 0x9, 0x1, 0, NULL
},
56 {PXA1908_CLK_SDH0
, "sdh0_clk", "sdh0_mix_clk", CLK_SET_RATE_PARENT
| CLK_SET_RATE_UNGATE
, APMU_SDH0
, 0x12, 0x12, 0x0, 0, &sdh0_lock
},
57 {PXA1908_CLK_SDH1
, "sdh1_clk", "sdh1_mix_clk", CLK_SET_RATE_PARENT
| CLK_SET_RATE_UNGATE
, APMU_SDH1
, 0x12, 0x12, 0x0, 0, &sdh1_lock
},
58 {PXA1908_CLK_SDH2
, "sdh2_clk", "sdh2_mix_clk", CLK_SET_RATE_PARENT
| CLK_SET_RATE_UNGATE
, APMU_SDH2
, 0x12, 0x12, 0x0, 0, &sdh2_lock
}
61 static void pxa1908_axi_periph_clk_init(struct pxa1908_clk_unit
*pxa_unit
)
63 struct mmp_clk_unit
*unit
= &pxa_unit
->unit
;
65 mmp_register_general_gate_clks(unit
, pll1_gate_clks
,
66 pxa_unit
->base
, ARRAY_SIZE(pll1_gate_clks
));
68 sdh_mix_config
.reg_info
.reg_clk_ctrl
= pxa_unit
->base
+ APMU_SDH0
;
69 mmp_clk_register_mix(NULL
, "sdh0_mix_clk", sdh_parent_names
,
70 ARRAY_SIZE(sdh_parent_names
), CLK_SET_RATE_PARENT
,
71 &sdh_mix_config
, &sdh0_lock
);
72 sdh_mix_config
.reg_info
.reg_clk_ctrl
= pxa_unit
->base
+ APMU_SDH1
;
73 mmp_clk_register_mix(NULL
, "sdh1_mix_clk", sdh_parent_names
,
74 ARRAY_SIZE(sdh_parent_names
), CLK_SET_RATE_PARENT
,
75 &sdh_mix_config
, &sdh1_lock
);
76 sdh_mix_config
.reg_info
.reg_clk_ctrl
= pxa_unit
->base
+ APMU_SDH2
;
77 mmp_clk_register_mix(NULL
, "sdh2_mix_clk", sdh_parent_names
,
78 ARRAY_SIZE(sdh_parent_names
), CLK_SET_RATE_PARENT
,
79 &sdh_mix_config
, &sdh2_lock
);
81 mmp_register_gate_clks(unit
, apmu_gate_clks
, pxa_unit
->base
,
82 ARRAY_SIZE(apmu_gate_clks
));
85 static int pxa1908_apmu_probe(struct platform_device
*pdev
)
87 struct pxa1908_clk_unit
*pxa_unit
;
89 pxa_unit
= devm_kzalloc(&pdev
->dev
, sizeof(*pxa_unit
), GFP_KERNEL
);
91 return PTR_ERR(pxa_unit
);
93 pxa_unit
->base
= devm_platform_ioremap_resource(pdev
, 0);
94 if (IS_ERR(pxa_unit
->base
))
95 return PTR_ERR(pxa_unit
->base
);
97 mmp_clk_init(pdev
->dev
.of_node
, &pxa_unit
->unit
, APMU_NR_CLKS
);
99 pxa1908_axi_periph_clk_init(pxa_unit
);
104 static const struct of_device_id pxa1908_apmu_match_table
[] = {
105 { .compatible
= "marvell,pxa1908-apmu" },
108 MODULE_DEVICE_TABLE(of
, pxa1908_apmu_match_table
);
110 static struct platform_driver pxa1908_apmu_driver
= {
111 .probe
= pxa1908_apmu_probe
,
113 .name
= "pxa1908-apmu",
114 .of_match_table
= pxa1908_apmu_match_table
117 module_platform_driver(pxa1908_apmu_driver
);
119 MODULE_AUTHOR("Duje Mihanović <duje.mihanovic@skole.hr>");
120 MODULE_DESCRIPTION("Marvell PXA1908 APMU Clock Driver");
121 MODULE_LICENSE("GPL");