Lines Matching +full:cpufreq +full:- +full:hw
1 // SPDX-License-Identifier: GPL-2.0+
5 * Even though clk-bcm2835 provides an interface to the hardware registers for
8 * over-temperature and under-voltage protections provided by the firmware.
14 #include <linux/clk-provider.h>
19 #include <soc/bcm2835/raspberrypi-firmware.h>
35 [RPI_FIRMWARE_PIXEL_BVB_CLK_ID] = "pixel-bvb",
48 struct platform_device *cpufreq; member
52 struct clk_hw hw; member
61 const struct raspberrypi_clk_data *clk_hw_to_data(const struct clk_hw *hw) in clk_hw_to_data() argument
63 return container_of(hw, struct raspberrypi_clk_data, hw); in clk_hw_to_data()
161 * https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
174 .id = cpu_to_le32(data->id), in raspberrypi_clock_property()
188 static int raspberrypi_fw_is_prepared(struct clk_hw *hw) in raspberrypi_fw_is_prepared() argument
190 const struct raspberrypi_clk_data *data = clk_hw_to_data(hw); in raspberrypi_fw_is_prepared()
191 struct raspberrypi_clk *rpi = data->rpi; in raspberrypi_fw_is_prepared()
195 ret = raspberrypi_clock_property(rpi->firmware, data, in raspberrypi_fw_is_prepared()
204 static unsigned long raspberrypi_fw_get_rate(struct clk_hw *hw, in raspberrypi_fw_get_rate() argument
207 const struct raspberrypi_clk_data *data = clk_hw_to_data(hw); in raspberrypi_fw_get_rate()
208 struct raspberrypi_clk *rpi = data->rpi; in raspberrypi_fw_get_rate()
212 ret = raspberrypi_clock_property(rpi->firmware, data, in raspberrypi_fw_get_rate()
220 static int raspberrypi_fw_set_rate(struct clk_hw *hw, unsigned long rate, in raspberrypi_fw_set_rate() argument
223 const struct raspberrypi_clk_data *data = clk_hw_to_data(hw); in raspberrypi_fw_set_rate()
224 struct raspberrypi_clk *rpi = data->rpi; in raspberrypi_fw_set_rate()
228 ret = raspberrypi_clock_property(rpi->firmware, data, in raspberrypi_fw_set_rate()
231 dev_err_ratelimited(rpi->dev, "Failed to change %s frequency: %d\n", in raspberrypi_fw_set_rate()
232 clk_hw_get_name(hw), ret); in raspberrypi_fw_set_rate()
237 static int raspberrypi_fw_dumb_determine_rate(struct clk_hw *hw, in raspberrypi_fw_dumb_determine_rate() argument
240 const struct raspberrypi_clk_data *data = clk_hw_to_data(hw); in raspberrypi_fw_dumb_determine_rate()
241 struct raspberrypi_clk_variant *variant = data->variant; in raspberrypi_fw_dumb_determine_rate()
249 req->rate = clamp(req->rate, req->min_rate, req->max_rate); in raspberrypi_fw_dumb_determine_rate()
256 if (variant->minimize && req->min_rate > 0) in raspberrypi_fw_dumb_determine_rate()
257 req->rate = req->min_rate; in raspberrypi_fw_dumb_determine_rate()
279 data = devm_kzalloc(rpi->dev, sizeof(*data), GFP_KERNEL); in raspberrypi_clk_register()
281 return ERR_PTR(-ENOMEM); in raspberrypi_clk_register()
282 data->rpi = rpi; in raspberrypi_clk_register()
283 data->id = id; in raspberrypi_clk_register()
284 data->variant = variant; in raspberrypi_clk_register()
286 init.name = devm_kasprintf(rpi->dev, GFP_KERNEL, in raspberrypi_clk_register()
287 "fw-clk-%s", in raspberrypi_clk_register()
292 data->hw.init = &init; in raspberrypi_clk_register()
294 ret = raspberrypi_clock_property(rpi->firmware, data, in raspberrypi_clk_register()
298 dev_err(rpi->dev, "Failed to get clock %d min freq: %d\n", in raspberrypi_clk_register()
303 ret = raspberrypi_clock_property(rpi->firmware, data, in raspberrypi_clk_register()
307 dev_err(rpi->dev, "Failed to get clock %d max freq: %d\n", in raspberrypi_clk_register()
312 ret = devm_clk_hw_register(rpi->dev, &data->hw); in raspberrypi_clk_register()
316 clk_hw_set_rate_range(&data->hw, min_rate, max_rate); in raspberrypi_clk_register()
318 if (variant->clkdev) { in raspberrypi_clk_register()
319 ret = devm_clk_hw_register_clkdev(rpi->dev, &data->hw, in raspberrypi_clk_register()
320 NULL, variant->clkdev); in raspberrypi_clk_register()
322 dev_err(rpi->dev, "Failed to initialize clkdev\n"); in raspberrypi_clk_register()
327 if (variant->min_rate) { in raspberrypi_clk_register()
330 clk_hw_set_rate_range(&data->hw, variant->min_rate, max_rate); in raspberrypi_clk_register()
332 rate = raspberrypi_fw_get_rate(&data->hw, 0); in raspberrypi_clk_register()
333 if (rate < variant->min_rate) { in raspberrypi_clk_register()
334 ret = raspberrypi_fw_set_rate(&data->hw, variant->min_rate, 0); in raspberrypi_clk_register()
340 return &data->hw; in raspberrypi_clk_register()
359 clks = devm_kcalloc(rpi->dev, in raspberrypi_discover_clocks()
363 return -ENOMEM; in raspberrypi_discover_clocks()
365 ret = rpi_firmware_property(rpi->firmware, RPI_FIRMWARE_GET_CLOCKS, in raspberrypi_discover_clocks()
371 while (clks->id) { in raspberrypi_discover_clocks()
374 if (clks->id >= RPI_FIRMWARE_NUM_CLK_ID) { in raspberrypi_discover_clocks()
375 dev_err(rpi->dev, "Unknown clock id: %u (max: %u)\n", in raspberrypi_discover_clocks()
376 clks->id, RPI_FIRMWARE_NUM_CLK_ID - 1); in raspberrypi_discover_clocks()
377 return -EINVAL; in raspberrypi_discover_clocks()
380 variant = &raspberrypi_clk_variants[clks->id]; in raspberrypi_discover_clocks()
381 if (variant->export) { in raspberrypi_discover_clocks()
382 struct clk_hw *hw; in raspberrypi_discover_clocks() local
384 hw = raspberrypi_clk_register(rpi, clks->parent, in raspberrypi_discover_clocks()
385 clks->id, variant); in raspberrypi_discover_clocks()
386 if (IS_ERR(hw)) in raspberrypi_discover_clocks()
387 return PTR_ERR(hw); in raspberrypi_discover_clocks()
389 data->num = clks->id + 1; in raspberrypi_discover_clocks()
390 data->hws[clks->id] = hw; in raspberrypi_discover_clocks()
403 struct device *dev = &pdev->dev; in raspberrypi_clk_probe()
409 * We can be probed either through the an old-fashioned in raspberrypi_clk_probe()
413 if (dev->of_node) in raspberrypi_clk_probe()
414 firmware_node = of_get_parent(dev->of_node); in raspberrypi_clk_probe()
417 "raspberrypi,bcm2835-firmware"); in raspberrypi_clk_probe()
420 return -ENOENT; in raspberrypi_clk_probe()
423 firmware = devm_rpi_firmware_get(&pdev->dev, firmware_node); in raspberrypi_clk_probe()
426 return -EPROBE_DEFER; in raspberrypi_clk_probe()
430 return -ENOMEM; in raspberrypi_clk_probe()
432 rpi->dev = dev; in raspberrypi_clk_probe()
433 rpi->firmware = firmware; in raspberrypi_clk_probe()
440 return -ENOMEM; in raspberrypi_clk_probe()
451 rpi->cpufreq = platform_device_register_data(dev, "raspberrypi-cpufreq", in raspberrypi_clk_probe()
452 -1, NULL, 0); in raspberrypi_clk_probe()
461 platform_device_unregister(rpi->cpufreq); in raspberrypi_clk_remove()
465 { .compatible = "raspberrypi,firmware-clocks" },
472 .name = "raspberrypi-clk",
483 MODULE_ALIAS("platform:raspberrypi-clk");