aboutsummaryrefslogtreecommitdiff
path: root/docs/devel
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-01-28 11:41:22 +0000
committerPeter Maydell <peter.maydell@linaro.org>2021-01-29 15:54:42 +0000
commit132b10251cd7b6271aa081ddfda329cd3c45bc00 (patch)
tree5dade257f8216a06f0892f6c51614a628078b92e /docs/devel
parentad140dadd591cdfd47959a7b4538e8133053b3c7 (diff)
downloadqemu-132b10251cd7b6271aa081ddfda329cd3c45bc00.zip
qemu-132b10251cd7b6271aa081ddfda329cd3c45bc00.tar.gz
qemu-132b10251cd7b6271aa081ddfda329cd3c45bc00.tar.bz2
clock: Add new clock_has_source() function
Add a function for checking whether a clock has a source. This is useful for devices which have input clocks that must be wired up by the board as it allows them to fail in realize rather than ploughing on with a zero-period clock. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Luc Michel <luc@lmichel.fr> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-id: 20210128114145.20536-3-peter.maydell@linaro.org Message-id: 20210121190622.22000-3-peter.maydell@linaro.org
Diffstat (limited to 'docs/devel')
-rw-r--r--docs/devel/clocks.rst16
1 files changed, 16 insertions, 0 deletions
diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst
index 2548d84..c54bbb8 100644
--- a/docs/devel/clocks.rst
+++ b/docs/devel/clocks.rst
@@ -235,6 +235,22 @@ object during device instance init. For example:
/* set initial value to 10ns / 100MHz */
clock_set_ns(clk, 10);
+To enforce that the clock is wired up by the board code, you can
+call ``clock_has_source()`` in your device's realize method:
+
+.. code-block:: c
+
+ if (!clock_has_source(s->clk)) {
+ error_setg(errp, "MyDevice: clk input must be connected");
+ return;
+ }
+
+Note that this only checks that the clock has been wired up; it is
+still possible that the output clock connected to it is disabled
+or has not yet been configured, in which case the period will be
+zero. You should use the clock callback to find out when the clock
+period changes.
+
Fetching clock frequency/period
-------------------------------