Lines Matching +full:bcm2835 +full:- +full:firmware

1 // SPDX-License-Identifier: GPL-2.0+
3 * Raspberry Pi driver for firmware controlled clocks
5 * Even though clk-bcm2835 provides an interface to the hardware registers for
6 * the system clocks we've had to factor out 'pllb' as the firmware 'owns' it.
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",
47 struct rpi_firmware *firmware; member
99 * HDMI connector, the firmware will skip the HSM
150 * Structure of the message passed to Raspberry Pi's firmware in order to
156 * use the firmware interface as the firmware ultimately takes care of
160 * For more information on the firmware interface check:
161 * https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
169 static int raspberrypi_clock_property(struct rpi_firmware *firmware, in raspberrypi_clock_property() argument
174 .id = cpu_to_le32(data->id), in raspberrypi_clock_property()
179 ret = rpi_firmware_property(firmware, tag, &msg, sizeof(msg)); in raspberrypi_clock_property()
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()
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()
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()
241 struct raspberrypi_clk_variant *variant = data->variant; in raspberrypi_fw_dumb_determine_rate()
244 * The firmware will do the rounding but that isn't part of in raspberrypi_fw_dumb_determine_rate()
245 * the interface with the firmware, so we just do our best 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()
355 * The firmware doesn't guarantee that the last element of in raspberrypi_discover_clocks()
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()
384 hw = raspberrypi_clk_register(rpi, clks->parent, in raspberrypi_discover_clocks()
385 clks->id, variant); 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()
404 struct rpi_firmware *firmware; in raspberrypi_clk_probe() local
409 * We can be probed either through the an old-fashioned in raspberrypi_clk_probe()
411 * child of the firmware node. Handle both cases. 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()
419 dev_err(dev, "Missing firmware node\n"); 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()
425 if (!firmware) 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",
481 MODULE_DESCRIPTION("Raspberry Pi firmware clock driver");
483 MODULE_ALIAS("platform:raspberrypi-clk");