xref: /linux/drivers/clk/mmp/clk-pxa1908-mpmu.c (revision 9f3a2ba62c7226a6604b8aaeb92b5ff906fa4e6b)
1*ebac87cdSDuje Mihanović // SPDX-License-Identifier: GPL-2.0-only
2*ebac87cdSDuje Mihanović #include <linux/bits.h>
3*ebac87cdSDuje Mihanović #include <linux/clk-provider.h>
4*ebac87cdSDuje Mihanović #include <linux/module.h>
5*ebac87cdSDuje Mihanović #include <linux/platform_device.h>
6*ebac87cdSDuje Mihanović #include <linux/units.h>
7*ebac87cdSDuje Mihanović 
8*ebac87cdSDuje Mihanović #include <dt-bindings/clock/marvell,pxa1908.h>
9*ebac87cdSDuje Mihanović 
10*ebac87cdSDuje Mihanović #include "clk.h"
11*ebac87cdSDuje Mihanović 
12*ebac87cdSDuje Mihanović #define MPMU_UART_PLL		0x14
13*ebac87cdSDuje Mihanović 
14*ebac87cdSDuje Mihanović #define MPMU_NR_CLKS		39
15*ebac87cdSDuje Mihanović 
16*ebac87cdSDuje Mihanović struct pxa1908_clk_unit {
17*ebac87cdSDuje Mihanović 	struct mmp_clk_unit unit;
18*ebac87cdSDuje Mihanović 	void __iomem *base;
19*ebac87cdSDuje Mihanović };
20*ebac87cdSDuje Mihanović 
21*ebac87cdSDuje Mihanović static struct mmp_param_fixed_rate_clk fixed_rate_clks[] = {
22*ebac87cdSDuje Mihanović 	{PXA1908_CLK_CLK32, "clk32", NULL, 0, 32768},
23*ebac87cdSDuje Mihanović 	{PXA1908_CLK_VCTCXO, "vctcxo", NULL, 0, 26 * HZ_PER_MHZ},
24*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_624, "pll1_624", NULL, 0, 624 * HZ_PER_MHZ},
25*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_416, "pll1_416", NULL, 0, 416 * HZ_PER_MHZ},
26*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_499, "pll1_499", NULL, 0, 499 * HZ_PER_MHZ},
27*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_832, "pll1_832", NULL, 0, 832 * HZ_PER_MHZ},
28*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_1248, "pll1_1248", NULL, 0, 1248 * HZ_PER_MHZ},
29*ebac87cdSDuje Mihanović };
30*ebac87cdSDuje Mihanović 
31*ebac87cdSDuje Mihanović static struct mmp_param_fixed_factor_clk fixed_factor_clks[] = {
32*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_D2, "pll1_d2", "pll1_624", 1, 2, 0},
33*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_D4, "pll1_d4", "pll1_d2", 1, 2, 0},
34*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_D6, "pll1_d6", "pll1_d2", 1, 3, 0},
35*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_D8, "pll1_d8", "pll1_d4", 1, 2, 0},
36*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_D12, "pll1_d12", "pll1_d6", 1, 2, 0},
37*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_D13, "pll1_d13", "pll1_624", 1, 13, 0},
38*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_D16, "pll1_d16", "pll1_d8", 1, 2, 0},
39*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_D24, "pll1_d24", "pll1_d12", 1, 2, 0},
40*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_D48, "pll1_d48", "pll1_d24", 1, 2, 0},
41*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_D96, "pll1_d96", "pll1_d48", 1, 2, 0},
42*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_32, "pll1_32", "pll1_d13", 2, 3, 0},
43*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_208, "pll1_208", "pll1_d2", 2, 3, 0},
44*ebac87cdSDuje Mihanović 	{PXA1908_CLK_PLL1_117, "pll1_117", "pll1_624", 3, 16, 0},
45*ebac87cdSDuje Mihanović };
46*ebac87cdSDuje Mihanović 
47*ebac87cdSDuje Mihanović static struct u32_fract uart_factor_tbl[] = {
48*ebac87cdSDuje Mihanović 	{.numerator = 8125, .denominator = 1536},	/* 14.745MHz */
49*ebac87cdSDuje Mihanović };
50*ebac87cdSDuje Mihanović 
51*ebac87cdSDuje Mihanović static struct mmp_clk_factor_masks uart_factor_masks = {
52*ebac87cdSDuje Mihanović 	.factor = 2,
53*ebac87cdSDuje Mihanović 	.num_mask = GENMASK(12, 0),
54*ebac87cdSDuje Mihanović 	.den_mask = GENMASK(12, 0),
55*ebac87cdSDuje Mihanović 	.num_shift = 16,
56*ebac87cdSDuje Mihanović 	.den_shift = 0,
57*ebac87cdSDuje Mihanović };
58*ebac87cdSDuje Mihanović 
pxa1908_pll_init(struct pxa1908_clk_unit * pxa_unit)59*ebac87cdSDuje Mihanović static void pxa1908_pll_init(struct pxa1908_clk_unit *pxa_unit)
60*ebac87cdSDuje Mihanović {
61*ebac87cdSDuje Mihanović 	struct mmp_clk_unit *unit = &pxa_unit->unit;
62*ebac87cdSDuje Mihanović 
63*ebac87cdSDuje Mihanović 	mmp_register_fixed_rate_clks(unit, fixed_rate_clks,
64*ebac87cdSDuje Mihanović 					ARRAY_SIZE(fixed_rate_clks));
65*ebac87cdSDuje Mihanović 
66*ebac87cdSDuje Mihanović 	mmp_register_fixed_factor_clks(unit, fixed_factor_clks,
67*ebac87cdSDuje Mihanović 					ARRAY_SIZE(fixed_factor_clks));
68*ebac87cdSDuje Mihanović 
69*ebac87cdSDuje Mihanović 	mmp_clk_register_factor("uart_pll", "pll1_d4",
70*ebac87cdSDuje Mihanović 			CLK_SET_RATE_PARENT,
71*ebac87cdSDuje Mihanović 			pxa_unit->base + MPMU_UART_PLL,
72*ebac87cdSDuje Mihanović 			&uart_factor_masks, uart_factor_tbl,
73*ebac87cdSDuje Mihanović 			ARRAY_SIZE(uart_factor_tbl), NULL);
74*ebac87cdSDuje Mihanović }
75*ebac87cdSDuje Mihanović 
pxa1908_mpmu_probe(struct platform_device * pdev)76*ebac87cdSDuje Mihanović static int pxa1908_mpmu_probe(struct platform_device *pdev)
77*ebac87cdSDuje Mihanović {
78*ebac87cdSDuje Mihanović 	struct pxa1908_clk_unit *pxa_unit;
79*ebac87cdSDuje Mihanović 
80*ebac87cdSDuje Mihanović 	pxa_unit = devm_kzalloc(&pdev->dev, sizeof(*pxa_unit), GFP_KERNEL);
81*ebac87cdSDuje Mihanović 	if (IS_ERR(pxa_unit))
82*ebac87cdSDuje Mihanović 		return PTR_ERR(pxa_unit);
83*ebac87cdSDuje Mihanović 
84*ebac87cdSDuje Mihanović 	pxa_unit->base = devm_platform_ioremap_resource(pdev, 0);
85*ebac87cdSDuje Mihanović 	if (IS_ERR(pxa_unit->base))
86*ebac87cdSDuje Mihanović 		return PTR_ERR(pxa_unit->base);
87*ebac87cdSDuje Mihanović 
88*ebac87cdSDuje Mihanović 	mmp_clk_init(pdev->dev.of_node, &pxa_unit->unit, MPMU_NR_CLKS);
89*ebac87cdSDuje Mihanović 
90*ebac87cdSDuje Mihanović 	pxa1908_pll_init(pxa_unit);
91*ebac87cdSDuje Mihanović 
92*ebac87cdSDuje Mihanović 	return 0;
93*ebac87cdSDuje Mihanović }
94*ebac87cdSDuje Mihanović 
95*ebac87cdSDuje Mihanović static const struct of_device_id pxa1908_mpmu_match_table[] = {
96*ebac87cdSDuje Mihanović 	{ .compatible = "marvell,pxa1908-mpmu" },
97*ebac87cdSDuje Mihanović 	{ }
98*ebac87cdSDuje Mihanović };
99*ebac87cdSDuje Mihanović MODULE_DEVICE_TABLE(of, pxa1908_mpmu_match_table);
100*ebac87cdSDuje Mihanović 
101*ebac87cdSDuje Mihanović static struct platform_driver pxa1908_mpmu_driver = {
102*ebac87cdSDuje Mihanović 	.probe = pxa1908_mpmu_probe,
103*ebac87cdSDuje Mihanović 	.driver = {
104*ebac87cdSDuje Mihanović 		.name = "pxa1908-mpmu",
105*ebac87cdSDuje Mihanović 		.of_match_table = pxa1908_mpmu_match_table
106*ebac87cdSDuje Mihanović 	}
107*ebac87cdSDuje Mihanović };
108*ebac87cdSDuje Mihanović module_platform_driver(pxa1908_mpmu_driver);
109*ebac87cdSDuje Mihanović 
110*ebac87cdSDuje Mihanović MODULE_AUTHOR("Duje Mihanović <duje.mihanovic@skole.hr>");
111*ebac87cdSDuje Mihanović MODULE_DESCRIPTION("Marvell PXA1908 MPMU Clock Driver");
112*ebac87cdSDuje Mihanović MODULE_LICENSE("GPL");
113