2 * Clock driver for the ARM Integrator/IM-PD1 board
3 * Copyright (C) 2012-2013 Linus Walleij
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 #include <linux/clk-provider.h>
10 #include <linux/clkdev.h>
11 #include <linux/err.h>
13 #include <linux/platform_data/clk-integrator.h>
17 #define IMPD1_OSC1 0x00
18 #define IMPD1_OSC2 0x04
19 #define IMPD1_LOCK 0x08
35 struct clk_lookup
*clks
[15];
38 /* One entry for each connected IM-PD1 LM */
39 static struct impd1_clk impd1_clks
[4];
42 * There are two VCO's on the IM-PD1
45 static const struct icst_params impd1_vco1_params
= {
46 .ref
= 24000000, /* 24 MHz */
47 .vco_max
= ICST525_VCO_MAX_3V
,
48 .vco_min
= ICST525_VCO_MIN
,
53 .s2div
= icst525_s2div
,
54 .idx2s
= icst525_idx2s
,
57 static const struct clk_icst_desc impd1_icst1_desc
= {
58 .params
= &impd1_vco1_params
,
59 .vco_offset
= IMPD1_OSC1
,
60 .lock_offset
= IMPD1_LOCK
,
63 static const struct icst_params impd1_vco2_params
= {
64 .ref
= 24000000, /* 24 MHz */
65 .vco_max
= ICST525_VCO_MAX_3V
,
66 .vco_min
= ICST525_VCO_MIN
,
71 .s2div
= icst525_s2div
,
72 .idx2s
= icst525_idx2s
,
75 static const struct clk_icst_desc impd1_icst2_desc
= {
76 .params
= &impd1_vco2_params
,
77 .vco_offset
= IMPD1_OSC2
,
78 .lock_offset
= IMPD1_LOCK
,
82 * integrator_impd1_clk_init() - set up the integrator clock tree
83 * @base: base address of the logic module (LM)
84 * @id: the ID of this LM
86 void integrator_impd1_clk_init(void __iomem
*base
, unsigned int id
)
88 struct impd1_clk
*imc
;
94 pr_crit("no more than 4 LMs can be attached\n");
97 imc
= &impd1_clks
[id
];
99 /* Register the fixed rate PCLK */
100 imc
->pclkname
= kasprintf(GFP_KERNEL
, "lm%x-pclk", id
);
101 pclk
= clk_register_fixed_rate(NULL
, imc
->pclkname
, NULL
, 0, 0);
104 imc
->vco1name
= kasprintf(GFP_KERNEL
, "lm%x-vco1", id
);
105 clk
= icst_clk_register(NULL
, &impd1_icst1_desc
, imc
->vco1name
, NULL
,
108 imc
->clks
[0] = clkdev_alloc(pclk
, "apb_pclk", "lm%x:01000", id
);
109 imc
->clks
[1] = clkdev_alloc(clk
, NULL
, "lm%x:01000", id
);
111 /* VCO2 is also called "CLK2" */
112 imc
->vco2name
= kasprintf(GFP_KERNEL
, "lm%x-vco2", id
);
113 clk
= icst_clk_register(NULL
, &impd1_icst2_desc
, imc
->vco2name
, NULL
,
117 /* MMCI uses CLK2 right off */
118 imc
->clks
[2] = clkdev_alloc(pclk
, "apb_pclk", "lm%x:00700", id
);
119 imc
->clks
[3] = clkdev_alloc(clk
, NULL
, "lm%x:00700", id
);
121 /* UART reference clock divides CLK2 by a fixed factor 4 */
122 imc
->uartname
= kasprintf(GFP_KERNEL
, "lm%x-uartclk", id
);
123 clk
= clk_register_fixed_factor(NULL
, imc
->uartname
, imc
->vco2name
,
124 CLK_IGNORE_UNUSED
, 1, 4);
126 imc
->clks
[4] = clkdev_alloc(pclk
, "apb_pclk", "lm%x:00100", id
);
127 imc
->clks
[5] = clkdev_alloc(clk
, NULL
, "lm%x:00100", id
);
128 imc
->clks
[6] = clkdev_alloc(pclk
, "apb_pclk", "lm%x:00200", id
);
129 imc
->clks
[7] = clkdev_alloc(clk
, NULL
, "lm%x:00200", id
);
131 /* SPI PL022 clock divides CLK2 by a fixed factor 64 */
132 imc
->spiname
= kasprintf(GFP_KERNEL
, "lm%x-spiclk", id
);
133 clk
= clk_register_fixed_factor(NULL
, imc
->spiname
, imc
->vco2name
,
134 CLK_IGNORE_UNUSED
, 1, 64);
135 imc
->clks
[8] = clkdev_alloc(pclk
, "apb_pclk", "lm%x:00300", id
);
136 imc
->clks
[9] = clkdev_alloc(clk
, NULL
, "lm%x:00300", id
);
138 /* The GPIO blocks and AACI have only PCLK */
139 imc
->clks
[10] = clkdev_alloc(pclk
, "apb_pclk", "lm%x:00400", id
);
140 imc
->clks
[11] = clkdev_alloc(pclk
, "apb_pclk", "lm%x:00500", id
);
141 imc
->clks
[12] = clkdev_alloc(pclk
, "apb_pclk", "lm%x:00800", id
);
143 /* Smart Card clock divides CLK2 by a fixed factor 4 */
144 imc
->scname
= kasprintf(GFP_KERNEL
, "lm%x-scclk", id
);
145 clk
= clk_register_fixed_factor(NULL
, imc
->scname
, imc
->vco2name
,
146 CLK_IGNORE_UNUSED
, 1, 4);
148 imc
->clks
[13] = clkdev_alloc(pclk
, "apb_pclk", "lm%x:00600", id
);
149 imc
->clks
[14] = clkdev_alloc(clk
, NULL
, "lm%x:00600", id
);
151 for (i
= 0; i
< ARRAY_SIZE(imc
->clks
); i
++)
152 clkdev_add(imc
->clks
[i
]);
154 EXPORT_SYMBOL_GPL(integrator_impd1_clk_init
);
156 void integrator_impd1_clk_exit(unsigned int id
)
159 struct impd1_clk
*imc
;
163 imc
= &impd1_clks
[id
];
165 for (i
= 0; i
< ARRAY_SIZE(imc
->clks
); i
++)
166 clkdev_drop(imc
->clks
[i
]);
167 clk_unregister(imc
->spiclk
);
168 clk_unregister(imc
->uartclk
);
169 clk_unregister(imc
->vco2clk
);
170 clk_unregister(imc
->vco1clk
);
171 clk_unregister(imc
->pclk
);
174 kfree(imc
->uartname
);
175 kfree(imc
->vco2name
);
176 kfree(imc
->vco1name
);
177 kfree(imc
->pclkname
);
179 EXPORT_SYMBOL_GPL(integrator_impd1_clk_exit
);