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>
54 [RPI_FIRMWARE_PIXEL_BVB_CLK_ID] = "pixel-bvb",
66 struct platform_device *cpufreq; member
70 struct clk_hw hw; member
160 * https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
173 .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
191 container_of(hw, struct raspberrypi_clk_data, hw); in raspberrypi_fw_is_prepared()
192 struct raspberrypi_clk *rpi = data->rpi; in raspberrypi_fw_is_prepared()
196 ret = raspberrypi_clock_property(rpi->firmware, data, in raspberrypi_fw_is_prepared()
205 static unsigned long raspberrypi_fw_get_rate(struct clk_hw *hw, in raspberrypi_fw_get_rate() argument
209 container_of(hw, struct raspberrypi_clk_data, hw); in raspberrypi_fw_get_rate()
210 struct raspberrypi_clk *rpi = data->rpi; in raspberrypi_fw_get_rate()
214 ret = raspberrypi_clock_property(rpi->firmware, data, in raspberrypi_fw_get_rate()
222 static int raspberrypi_fw_set_rate(struct clk_hw *hw, unsigned long rate, in raspberrypi_fw_set_rate() argument
226 container_of(hw, struct raspberrypi_clk_data, hw); in raspberrypi_fw_set_rate()
227 struct raspberrypi_clk *rpi = data->rpi; in raspberrypi_fw_set_rate()
231 ret = raspberrypi_clock_property(rpi->firmware, data, in raspberrypi_fw_set_rate()
234 dev_err_ratelimited(rpi->dev, "Failed to change %s frequency: %d\n", in raspberrypi_fw_set_rate()
235 clk_hw_get_name(hw), ret); in raspberrypi_fw_set_rate()
240 static int raspberrypi_fw_dumb_determine_rate(struct clk_hw *hw, in raspberrypi_fw_dumb_determine_rate() argument
244 container_of(hw, struct raspberrypi_clk_data, hw); in raspberrypi_fw_dumb_determine_rate()
245 struct raspberrypi_clk_variant *variant = data->variant; in raspberrypi_fw_dumb_determine_rate()
253 req->rate = clamp(req->rate, req->min_rate, req->max_rate); in raspberrypi_fw_dumb_determine_rate()
260 if (variant->minimize && req->min_rate > 0) in raspberrypi_fw_dumb_determine_rate()
261 req->rate = req->min_rate; in raspberrypi_fw_dumb_determine_rate()
283 data = devm_kzalloc(rpi->dev, sizeof(*data), GFP_KERNEL); in raspberrypi_clk_register()
285 return ERR_PTR(-ENOMEM); in raspberrypi_clk_register()
286 data->rpi = rpi; in raspberrypi_clk_register()
287 data->id = id; in raspberrypi_clk_register()
288 data->variant = variant; in raspberrypi_clk_register()
290 init.name = devm_kasprintf(rpi->dev, GFP_KERNEL, in raspberrypi_clk_register()
291 "fw-clk-%s", in raspberrypi_clk_register()
296 data->hw.init = &init; in raspberrypi_clk_register()
298 ret = raspberrypi_clock_property(rpi->firmware, data, in raspberrypi_clk_register()
302 dev_err(rpi->dev, "Failed to get clock %d min freq: %d\n", in raspberrypi_clk_register()
307 ret = raspberrypi_clock_property(rpi->firmware, data, in raspberrypi_clk_register()
311 dev_err(rpi->dev, "Failed to get clock %d max freq: %d\n", in raspberrypi_clk_register()
316 ret = devm_clk_hw_register(rpi->dev, &data->hw); in raspberrypi_clk_register()
320 clk_hw_set_rate_range(&data->hw, min_rate, max_rate); in raspberrypi_clk_register()
322 if (variant->clkdev) { in raspberrypi_clk_register()
323 ret = devm_clk_hw_register_clkdev(rpi->dev, &data->hw, in raspberrypi_clk_register()
324 NULL, variant->clkdev); in raspberrypi_clk_register()
326 dev_err(rpi->dev, "Failed to initialize clkdev\n"); in raspberrypi_clk_register()
331 if (variant->min_rate) { in raspberrypi_clk_register()
334 clk_hw_set_rate_range(&data->hw, variant->min_rate, max_rate); in raspberrypi_clk_register()
336 rate = raspberrypi_fw_get_rate(&data->hw, 0); in raspberrypi_clk_register()
337 if (rate < variant->min_rate) { in raspberrypi_clk_register()
338 ret = raspberrypi_fw_set_rate(&data->hw, variant->min_rate, 0); in raspberrypi_clk_register()
344 return &data->hw; in raspberrypi_clk_register()
363 clks = devm_kcalloc(rpi->dev, in raspberrypi_discover_clocks()
367 return -ENOMEM; in raspberrypi_discover_clocks()
369 ret = rpi_firmware_property(rpi->firmware, RPI_FIRMWARE_GET_CLOCKS, in raspberrypi_discover_clocks()
375 while (clks->id) { in raspberrypi_discover_clocks()
378 if (clks->id > RPI_FIRMWARE_NUM_CLK_ID) { in raspberrypi_discover_clocks()
379 dev_err(rpi->dev, "Unknown clock id: %u (max: %u)\n", in raspberrypi_discover_clocks()
380 clks->id, RPI_FIRMWARE_NUM_CLK_ID); in raspberrypi_discover_clocks()
381 return -EINVAL; in raspberrypi_discover_clocks()
384 variant = &raspberrypi_clk_variants[clks->id]; in raspberrypi_discover_clocks()
385 if (variant->export) { in raspberrypi_discover_clocks()
386 struct clk_hw *hw; in raspberrypi_discover_clocks() local
388 hw = raspberrypi_clk_register(rpi, clks->parent, in raspberrypi_discover_clocks()
389 clks->id, variant); in raspberrypi_discover_clocks()
390 if (IS_ERR(hw)) in raspberrypi_discover_clocks()
391 return PTR_ERR(hw); in raspberrypi_discover_clocks()
393 data->hws[clks->id] = hw; in raspberrypi_discover_clocks()
394 data->num = clks->id + 1; in raspberrypi_discover_clocks()
407 struct device *dev = &pdev->dev; in raspberrypi_clk_probe()
413 * We can be probed either through the an old-fashioned in raspberrypi_clk_probe()
417 if (dev->of_node) in raspberrypi_clk_probe()
418 firmware_node = of_get_parent(dev->of_node); in raspberrypi_clk_probe()
421 "raspberrypi,bcm2835-firmware"); in raspberrypi_clk_probe()
424 return -ENOENT; in raspberrypi_clk_probe()
427 firmware = devm_rpi_firmware_get(&pdev->dev, firmware_node); in raspberrypi_clk_probe()
430 return -EPROBE_DEFER; in raspberrypi_clk_probe()
434 return -ENOMEM; in raspberrypi_clk_probe()
436 rpi->dev = dev; in raspberrypi_clk_probe()
437 rpi->firmware = firmware; in raspberrypi_clk_probe()
444 return -ENOMEM; in raspberrypi_clk_probe()
455 rpi->cpufreq = platform_device_register_data(dev, "raspberrypi-cpufreq", in raspberrypi_clk_probe()
456 -1, NULL, 0); in raspberrypi_clk_probe()
465 platform_device_unregister(rpi->cpufreq); in raspberrypi_clk_remove()
471 { .compatible = "raspberrypi,firmware-clocks" },
478 .name = "raspberrypi-clk",
489 MODULE_ALIAS("platform:raspberrypi-clk");