Skip to content

Commit 56643d9

Browse files
mripardbebarino
authored andcommitted
clk: bcm: rpi: Remove the quirks for the CPU clock
The CPU clock has had so far a bunch of quirks to expose the clock tree properly, but since we reverted to exposing them through the MMIO driver, we can remove that code from the firmware driver. Acked-by: Nicolas Saenz Julienne <[email protected]> Tested-by: Nicolas Saenz Julienne <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> Link: https://lore.kernel.org/r/acdf820c2f78a25dd7480a0c018b8b387acd013e.1592210452.git-series.maxime@cerno.tech Signed-off-by: Stephen Boyd <[email protected]>
1 parent 0d46faf commit 56643d9

File tree

1 file changed

+0
-164
lines changed

1 file changed

+0
-164
lines changed

drivers/clk/bcm/clk-raspberrypi.c

Lines changed: 0 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ static char *rpi_firmware_clk_names[] = {
5656
#define RPI_FIRMWARE_STATE_ENABLE_BIT BIT(0)
5757
#define RPI_FIRMWARE_STATE_WAIT_BIT BIT(1)
5858

59-
/*
60-
* Even though the firmware interface alters 'pllb' the frequencies are
61-
* provided as per 'pllb_arm'. We need to scale before passing them trough.
62-
*/
63-
#define RPI_FIRMWARE_PLLB_ARM_DIV_RATE 2
64-
65-
#define A2W_PLL_FRAC_BITS 20
66-
6759
struct raspberrypi_clk {
6860
struct device *dev;
6961
struct rpi_firmware *firmware;
@@ -152,13 +144,6 @@ static unsigned long raspberrypi_fw_get_rate(struct clk_hw *hw,
152144
return val;
153145
}
154146

155-
static unsigned long raspberrypi_fw_pll_get_rate(struct clk_hw *hw,
156-
unsigned long parent_rate)
157-
{
158-
return raspberrypi_fw_get_rate(hw, parent_rate) *
159-
RPI_FIRMWARE_PLLB_ARM_DIV_RATE;
160-
}
161-
162147
static int raspberrypi_fw_set_rate(struct clk_hw *hw, unsigned long rate,
163148
unsigned long parent_rate)
164149
{
@@ -177,142 +162,6 @@ static int raspberrypi_fw_set_rate(struct clk_hw *hw, unsigned long rate,
177162
return ret;
178163
}
179164

180-
static int raspberrypi_fw_pll_set_rate(struct clk_hw *hw, unsigned long rate,
181-
unsigned long parent_rate)
182-
{
183-
u32 new_rate = rate / RPI_FIRMWARE_PLLB_ARM_DIV_RATE;
184-
185-
return raspberrypi_fw_set_rate(hw, new_rate, parent_rate);
186-
}
187-
188-
/*
189-
* Sadly there is no firmware rate rounding interface. We borrowed it from
190-
* clk-bcm2835.
191-
*/
192-
static int raspberrypi_pll_determine_rate(struct clk_hw *hw,
193-
struct clk_rate_request *req)
194-
{
195-
u64 div, final_rate;
196-
u32 ndiv, fdiv;
197-
198-
/* We can't use req->rate directly as it would overflow */
199-
final_rate = clamp(req->rate, req->min_rate, req->max_rate);
200-
201-
div = (u64)final_rate << A2W_PLL_FRAC_BITS;
202-
do_div(div, req->best_parent_rate);
203-
204-
ndiv = div >> A2W_PLL_FRAC_BITS;
205-
fdiv = div & ((1 << A2W_PLL_FRAC_BITS) - 1);
206-
207-
final_rate = ((u64)req->best_parent_rate *
208-
((ndiv << A2W_PLL_FRAC_BITS) + fdiv));
209-
210-
req->rate = final_rate >> A2W_PLL_FRAC_BITS;
211-
212-
return 0;
213-
}
214-
215-
static const struct clk_ops raspberrypi_firmware_pll_clk_ops = {
216-
.is_prepared = raspberrypi_fw_is_prepared,
217-
.recalc_rate = raspberrypi_fw_pll_get_rate,
218-
.set_rate = raspberrypi_fw_pll_set_rate,
219-
.determine_rate = raspberrypi_pll_determine_rate,
220-
};
221-
222-
static struct clk_hw *raspberrypi_register_pllb(struct raspberrypi_clk *rpi)
223-
{
224-
struct raspberrypi_clk_data *data;
225-
struct clk_init_data init = {};
226-
u32 min_rate = 0, max_rate = 0;
227-
int ret;
228-
229-
data = devm_kzalloc(rpi->dev, sizeof(*data), GFP_KERNEL);
230-
if (!data)
231-
return ERR_PTR(-ENOMEM);
232-
data->rpi = rpi;
233-
data->id = RPI_FIRMWARE_ARM_CLK_ID;
234-
235-
/* All of the PLLs derive from the external oscillator. */
236-
init.parent_names = (const char *[]){ "osc" };
237-
init.num_parents = 1;
238-
init.name = "pllb";
239-
init.ops = &raspberrypi_firmware_pll_clk_ops;
240-
init.flags = CLK_GET_RATE_NOCACHE | CLK_IGNORE_UNUSED;
241-
242-
/* Get min & max rates set by the firmware */
243-
ret = raspberrypi_clock_property(rpi->firmware, data,
244-
RPI_FIRMWARE_GET_MIN_CLOCK_RATE,
245-
&min_rate);
246-
if (ret) {
247-
dev_err(rpi->dev, "Failed to get %s min freq: %d\n",
248-
init.name, ret);
249-
return ERR_PTR(ret);
250-
}
251-
252-
ret = raspberrypi_clock_property(rpi->firmware, data,
253-
RPI_FIRMWARE_GET_MAX_CLOCK_RATE,
254-
&max_rate);
255-
if (ret) {
256-
dev_err(rpi->dev, "Failed to get %s max freq: %d\n",
257-
init.name, ret);
258-
return ERR_PTR(ret);
259-
}
260-
261-
if (!min_rate || !max_rate) {
262-
dev_err(rpi->dev, "Unexpected frequency range: min %u, max %u\n",
263-
min_rate, max_rate);
264-
return ERR_PTR(-EINVAL);
265-
}
266-
267-
dev_info(rpi->dev, "CPU frequency range: min %u, max %u\n",
268-
min_rate, max_rate);
269-
270-
data->hw.init = &init;
271-
272-
ret = devm_clk_hw_register(rpi->dev, &data->hw);
273-
if (ret)
274-
return ERR_PTR(ret);
275-
276-
clk_hw_set_rate_range(&data->hw,
277-
min_rate * RPI_FIRMWARE_PLLB_ARM_DIV_RATE,
278-
max_rate * RPI_FIRMWARE_PLLB_ARM_DIV_RATE);
279-
280-
return &data->hw;
281-
}
282-
283-
static struct clk_fixed_factor raspberrypi_clk_pllb_arm = {
284-
.mult = 1,
285-
.div = 2,
286-
.hw.init = &(struct clk_init_data) {
287-
.name = "pllb_arm",
288-
.parent_names = (const char *[]){ "pllb" },
289-
.num_parents = 1,
290-
.ops = &clk_fixed_factor_ops,
291-
.flags = CLK_SET_RATE_PARENT | CLK_GET_RATE_NOCACHE,
292-
},
293-
};
294-
295-
static struct clk_hw *raspberrypi_register_pllb_arm(struct raspberrypi_clk *rpi)
296-
{
297-
int ret;
298-
299-
ret = devm_clk_hw_register(rpi->dev, &raspberrypi_clk_pllb_arm.hw);
300-
if (ret) {
301-
dev_err(rpi->dev, "Failed to initialize pllb_arm\n");
302-
return ERR_PTR(ret);
303-
}
304-
305-
ret = devm_clk_hw_register_clkdev(rpi->dev,
306-
&raspberrypi_clk_pllb_arm.hw,
307-
NULL, "cpu0");
308-
if (ret) {
309-
dev_err(rpi->dev, "Failed to initialize clkdev\n");
310-
return ERR_PTR(ret);
311-
}
312-
313-
return &raspberrypi_clk_pllb_arm.hw;
314-
}
315-
316165
static int raspberrypi_fw_dumb_determine_rate(struct clk_hw *hw,
317166
struct clk_rate_request *req)
318167
{
@@ -341,19 +190,6 @@ static struct clk_hw *raspberrypi_clk_register(struct raspberrypi_clk *rpi,
341190
u32 min_rate, max_rate;
342191
int ret;
343192

344-
if (id == RPI_FIRMWARE_ARM_CLK_ID) {
345-
struct clk_hw *hw;
346-
347-
hw = raspberrypi_register_pllb(rpi);
348-
if (IS_ERR(hw)) {
349-
dev_err(rpi->dev, "Failed to initialize pllb, %ld\n",
350-
PTR_ERR(hw));
351-
return hw;
352-
}
353-
354-
return raspberrypi_register_pllb_arm(rpi);
355-
}
356-
357193
data = devm_kzalloc(rpi->dev, sizeof(*data), GFP_KERNEL);
358194
if (!data)
359195
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)