xref: /linux/drivers/clk/mmp/clk-pxa1908-apmu.c (revision 9f3a2ba62c7226a6604b8aaeb92b5ff906fa4e6b)
1*03437e85SDuje Mihanović // SPDX-License-Identifier: GPL-2.0-only
2*03437e85SDuje Mihanović #include <linux/clk-provider.h>
3*03437e85SDuje Mihanović #include <linux/module.h>
4*03437e85SDuje Mihanović #include <linux/platform_device.h>
5*03437e85SDuje Mihanović #include <linux/spinlock.h>
6*03437e85SDuje Mihanović 
7*03437e85SDuje Mihanović #include <dt-bindings/clock/marvell,pxa1908.h>
8*03437e85SDuje Mihanović 
9*03437e85SDuje Mihanović #include "clk.h"
10*03437e85SDuje Mihanović 
11*03437e85SDuje Mihanović #define APMU_CLK_GATE_CTRL	0x40
12*03437e85SDuje Mihanović #define APMU_CCIC1		0x24
13*03437e85SDuje Mihanović #define APMU_ISP		0x38
14*03437e85SDuje Mihanović #define APMU_DSI1		0x44
15*03437e85SDuje Mihanović #define APMU_DISP1		0x4c
16*03437e85SDuje Mihanović #define APMU_CCIC0		0x50
17*03437e85SDuje Mihanović #define APMU_SDH0		0x54
18*03437e85SDuje Mihanović #define APMU_SDH1		0x58
19*03437e85SDuje Mihanović #define APMU_USB		0x5c
20*03437e85SDuje Mihanović #define APMU_NF			0x60
21*03437e85SDuje Mihanović #define APMU_VPU		0xa4
22*03437e85SDuje Mihanović #define APMU_GC			0xcc
23*03437e85SDuje Mihanović #define APMU_SDH2		0xe0
24*03437e85SDuje Mihanović #define APMU_GC2D		0xf4
25*03437e85SDuje Mihanović #define APMU_TRACE		0x108
26*03437e85SDuje Mihanović #define APMU_DVC_DFC_DEBUG	0x140
27*03437e85SDuje Mihanović 
28*03437e85SDuje Mihanović #define APMU_NR_CLKS		17
29*03437e85SDuje Mihanović 
30*03437e85SDuje Mihanović struct pxa1908_clk_unit {
31*03437e85SDuje Mihanović 	struct mmp_clk_unit unit;
32*03437e85SDuje Mihanović 	void __iomem *base;
33*03437e85SDuje Mihanović };
34*03437e85SDuje Mihanović 
35*03437e85SDuje Mihanović static DEFINE_SPINLOCK(pll1_lock);
36*03437e85SDuje Mihanović static struct mmp_param_general_gate_clk pll1_gate_clks[] = {
37*03437e85SDuje Mihanović 	{PXA1908_CLK_PLL1_D2_GATE, "pll1_d2_gate", "pll1_d2", 0, APMU_CLK_GATE_CTRL, 29, 0, &pll1_lock},
38*03437e85SDuje Mihanović 	{PXA1908_CLK_PLL1_416_GATE, "pll1_416_gate", "pll1_416", 0, APMU_CLK_GATE_CTRL, 27, 0, &pll1_lock},
39*03437e85SDuje Mihanović 	{PXA1908_CLK_PLL1_624_GATE, "pll1_624_gate", "pll1_624", 0, APMU_CLK_GATE_CTRL, 26, 0, &pll1_lock},
40*03437e85SDuje Mihanović 	{PXA1908_CLK_PLL1_832_GATE, "pll1_832_gate", "pll1_832", 0, APMU_CLK_GATE_CTRL, 30, 0, &pll1_lock},
41*03437e85SDuje Mihanović 	{PXA1908_CLK_PLL1_1248_GATE, "pll1_1248_gate", "pll1_1248", 0, APMU_CLK_GATE_CTRL, 28, 0, &pll1_lock},
42*03437e85SDuje Mihanović };
43*03437e85SDuje Mihanović 
44*03437e85SDuje Mihanović static DEFINE_SPINLOCK(sdh0_lock);
45*03437e85SDuje Mihanović static DEFINE_SPINLOCK(sdh1_lock);
46*03437e85SDuje Mihanović static DEFINE_SPINLOCK(sdh2_lock);
47*03437e85SDuje Mihanović 
48*03437e85SDuje Mihanović static const char * const sdh_parent_names[] = {"pll1_416", "pll1_624"};
49*03437e85SDuje Mihanović 
50*03437e85SDuje Mihanović static struct mmp_clk_mix_config sdh_mix_config = {
51*03437e85SDuje Mihanović 	.reg_info = DEFINE_MIX_REG_INFO(3, 8, 2, 6, 11),
52*03437e85SDuje Mihanović };
53*03437e85SDuje Mihanović 
54*03437e85SDuje Mihanović static struct mmp_param_gate_clk apmu_gate_clks[] = {
55*03437e85SDuje Mihanović 	{PXA1908_CLK_USB, "usb_clk", NULL, 0, APMU_USB, 0x9, 0x9, 0x1, 0, NULL},
56*03437e85SDuje Mihanović 	{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*03437e85SDuje Mihanović 	{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*03437e85SDuje Mihanović 	{PXA1908_CLK_SDH2, "sdh2_clk", "sdh2_mix_clk", CLK_SET_RATE_PARENT | CLK_SET_RATE_UNGATE, APMU_SDH2, 0x12, 0x12, 0x0, 0, &sdh2_lock}
59*03437e85SDuje Mihanović };
60*03437e85SDuje Mihanović 
pxa1908_axi_periph_clk_init(struct pxa1908_clk_unit * pxa_unit)61*03437e85SDuje Mihanović static void pxa1908_axi_periph_clk_init(struct pxa1908_clk_unit *pxa_unit)
62*03437e85SDuje Mihanović {
63*03437e85SDuje Mihanović 	struct mmp_clk_unit *unit = &pxa_unit->unit;
64*03437e85SDuje Mihanović 
65*03437e85SDuje Mihanović 	mmp_register_general_gate_clks(unit, pll1_gate_clks,
66*03437e85SDuje Mihanović 			pxa_unit->base, ARRAY_SIZE(pll1_gate_clks));
67*03437e85SDuje Mihanović 
68*03437e85SDuje Mihanović 	sdh_mix_config.reg_info.reg_clk_ctrl = pxa_unit->base + APMU_SDH0;
69*03437e85SDuje Mihanović 	mmp_clk_register_mix(NULL, "sdh0_mix_clk", sdh_parent_names,
70*03437e85SDuje Mihanović 			ARRAY_SIZE(sdh_parent_names), CLK_SET_RATE_PARENT,
71*03437e85SDuje Mihanović 			&sdh_mix_config, &sdh0_lock);
72*03437e85SDuje Mihanović 	sdh_mix_config.reg_info.reg_clk_ctrl = pxa_unit->base + APMU_SDH1;
73*03437e85SDuje Mihanović 	mmp_clk_register_mix(NULL, "sdh1_mix_clk", sdh_parent_names,
74*03437e85SDuje Mihanović 			ARRAY_SIZE(sdh_parent_names), CLK_SET_RATE_PARENT,
75*03437e85SDuje Mihanović 			&sdh_mix_config, &sdh1_lock);
76*03437e85SDuje Mihanović 	sdh_mix_config.reg_info.reg_clk_ctrl = pxa_unit->base + APMU_SDH2;
77*03437e85SDuje Mihanović 	mmp_clk_register_mix(NULL, "sdh2_mix_clk", sdh_parent_names,
78*03437e85SDuje Mihanović 			ARRAY_SIZE(sdh_parent_names), CLK_SET_RATE_PARENT,
79*03437e85SDuje Mihanović 			&sdh_mix_config, &sdh2_lock);
80*03437e85SDuje Mihanović 
81*03437e85SDuje Mihanović 	mmp_register_gate_clks(unit, apmu_gate_clks, pxa_unit->base,
82*03437e85SDuje Mihanović 			ARRAY_SIZE(apmu_gate_clks));
83*03437e85SDuje Mihanović }
84*03437e85SDuje Mihanović 
pxa1908_apmu_probe(struct platform_device * pdev)85*03437e85SDuje Mihanović static int pxa1908_apmu_probe(struct platform_device *pdev)
86*03437e85SDuje Mihanović {
87*03437e85SDuje Mihanović 	struct pxa1908_clk_unit *pxa_unit;
88*03437e85SDuje Mihanović 
89*03437e85SDuje Mihanović 	pxa_unit = devm_kzalloc(&pdev->dev, sizeof(*pxa_unit), GFP_KERNEL);
90*03437e85SDuje Mihanović 	if (IS_ERR(pxa_unit))
91*03437e85SDuje Mihanović 		return PTR_ERR(pxa_unit);
92*03437e85SDuje Mihanović 
93*03437e85SDuje Mihanović 	pxa_unit->base = devm_platform_ioremap_resource(pdev, 0);
94*03437e85SDuje Mihanović 	if (IS_ERR(pxa_unit->base))
95*03437e85SDuje Mihanović 		return PTR_ERR(pxa_unit->base);
96*03437e85SDuje Mihanović 
97*03437e85SDuje Mihanović 	mmp_clk_init(pdev->dev.of_node, &pxa_unit->unit, APMU_NR_CLKS);
98*03437e85SDuje Mihanović 
99*03437e85SDuje Mihanović 	pxa1908_axi_periph_clk_init(pxa_unit);
100*03437e85SDuje Mihanović 
101*03437e85SDuje Mihanović 	return 0;
102*03437e85SDuje Mihanović }
103*03437e85SDuje Mihanović 
104*03437e85SDuje Mihanović static const struct of_device_id pxa1908_apmu_match_table[] = {
105*03437e85SDuje Mihanović 	{ .compatible = "marvell,pxa1908-apmu" },
106*03437e85SDuje Mihanović 	{ }
107*03437e85SDuje Mihanović };
108*03437e85SDuje Mihanović MODULE_DEVICE_TABLE(of, pxa1908_apmu_match_table);
109*03437e85SDuje Mihanović 
110*03437e85SDuje Mihanović static struct platform_driver pxa1908_apmu_driver = {
111*03437e85SDuje Mihanović 	.probe = pxa1908_apmu_probe,
112*03437e85SDuje Mihanović 	.driver = {
113*03437e85SDuje Mihanović 		.name = "pxa1908-apmu",
114*03437e85SDuje Mihanović 		.of_match_table = pxa1908_apmu_match_table
115*03437e85SDuje Mihanović 	}
116*03437e85SDuje Mihanović };
117*03437e85SDuje Mihanović module_platform_driver(pxa1908_apmu_driver);
118*03437e85SDuje Mihanović 
119*03437e85SDuje Mihanović MODULE_AUTHOR("Duje Mihanović <duje.mihanovic@skole.hr>");
120*03437e85SDuje Mihanović MODULE_DESCRIPTION("Marvell PXA1908 APMU Clock Driver");
121*03437e85SDuje Mihanović MODULE_LICENSE("GPL");
122