Commit 40d3e0f4942ec12c4521fe1b2a2b774164cd2c80

Authored by Russell King
1 parent 6cfa6279ed

clk: provide prepare/unprepare functions

As discussed previously, there's the need on some platforms to run some
parts of clk_enable() in contexts which can schedule.  The solution
which was agreed upon was to provide clk_prepare() and clk_unprepare()
to contain this parts, while clk_enable() and clk_disable() perform
the atomic part.

This patch provides a common definition for clk_prepare() and
clk_unprepare() in linux/clk.h, and provides an upgrade path for
existing implementation and drivers: drivers can start using
clk_prepare() and clk_unprepare() once this patch is merged without
having to wait for platform support.  Platforms can then start to
provide these additional functions.

Eventually, HAVE_CLK_PREPARE will be removed from the kernel, and
everyone will have to provide these new APIs.

Acked-by: Saravana Kannan <skannan@codeaurora.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

Showing 1 changed file with 43 additions and 0 deletions Side-by-side Diff

... ... @@ -11,6 +11,8 @@
11 11 #ifndef __LINUX_CLK_H
12 12 #define __LINUX_CLK_H
13 13  
  14 +#include <linux/kernel.h>
  15 +
14 16 struct device;
15 17  
16 18 /*
17 19  
... ... @@ -41,11 +43,31 @@
41 43 struct clk *clk_get(struct device *dev, const char *id);
42 44  
43 45 /**
  46 + * clk_prepare - prepare a clock source
  47 + * @clk: clock source
  48 + *
  49 + * This prepares the clock source for use.
  50 + *
  51 + * Must not be called from within atomic context.
  52 + */
  53 +#ifdef CONFIG_HAVE_CLK_PREPARE
  54 +int clk_prepare(struct clk *clk);
  55 +#else
  56 +static inline int clk_prepare(struct clk *clk)
  57 +{
  58 + might_sleep();
  59 + return 0;
  60 +}
  61 +#endif
  62 +
  63 +/**
44 64 * clk_enable - inform the system when the clock source should be running.
45 65 * @clk: clock source
46 66 *
47 67 * If the clock can not be enabled/disabled, this should return success.
48 68 *
  69 + * May be called from atomic contexts.
  70 + *
49 71 * Returns success (0) or negative errno.
50 72 */
51 73 int clk_enable(struct clk *clk);
52 74  
... ... @@ -57,12 +79,33 @@
57 79 * Inform the system that a clock source is no longer required by
58 80 * a driver and may be shut down.
59 81 *
  82 + * May be called from atomic contexts.
  83 + *
60 84 * Implementation detail: if the clock source is shared between
61 85 * multiple drivers, clk_enable() calls must be balanced by the
62 86 * same number of clk_disable() calls for the clock source to be
63 87 * disabled.
64 88 */
65 89 void clk_disable(struct clk *clk);
  90 +
  91 +
  92 +/**
  93 + * clk_unprepare - undo preparation of a clock source
  94 + * @clk: clock source
  95 + *
  96 + * This undoes a previously prepared clock. The caller must balance
  97 + * the number of prepare and unprepare calls.
  98 + *
  99 + * Must not be called from within atomic context.
  100 + */
  101 +#ifdef CONFIG_HAVE_CLK_PREPARE
  102 +void clk_unprepare(struct clk *clk);
  103 +#else
  104 +static inline void clk_unprepare(struct clk *clk)
  105 +{
  106 + might_sleep();
  107 +}
  108 +#endif
66 109  
67 110 /**
68 111 * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.