diff options
author | Mike Turquette <mturquette@linaro.org> | 2014-02-19 00:21:25 -0500 |
---|---|---|
committer | Maxime Ripard <maxime.ripard@free-electrons.com> | 2014-09-27 02:57:38 -0400 |
commit | e59c5371fb9d8268d1c043172e88cecab9dc934f (patch) | |
tree | 54acf05ccfffdc1dc17dd3c0adb92f54332e0bb0 | |
parent | cfe4c93b58924b3764cd7269d3d953049405e938 (diff) |
clk: introduce clk_set_phase function & callback
A common operation for a clock signal generator is to shift the phase of
that signal. This patch introduces a new function to the clk.h API to
dynamically adjust the phase of a clock signal. Additionally this patch
introduces support for the new function in the common clock framework
via the .set_phase call back in struct clk_ops.
Signed-off-by: Mike Turquette <mturquette@linaro.org>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Reviewed-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r-- | drivers/clk/clk.c | 85 | ||||
-rw-r--r-- | include/linux/clk-private.h | 1 | ||||
-rw-r--r-- | include/linux/clk-provider.h | 5 | ||||
-rw-r--r-- | include/linux/clk.h | 29 |
4 files changed, 116 insertions, 4 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index b76fa69b44cb..d87661af0c72 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c | |||
@@ -117,11 +117,11 @@ static void clk_summary_show_one(struct seq_file *s, struct clk *c, int level) | |||
117 | if (!c) | 117 | if (!c) |
118 | return; | 118 | return; |
119 | 119 | ||
120 | seq_printf(s, "%*s%-*s %11d %12d %11lu %10lu\n", | 120 | seq_printf(s, "%*s%-*s %11d %12d %11lu %10lu %-3d\n", |
121 | level * 3 + 1, "", | 121 | level * 3 + 1, "", |
122 | 30 - level * 3, c->name, | 122 | 30 - level * 3, c->name, |
123 | c->enable_count, c->prepare_count, clk_get_rate(c), | 123 | c->enable_count, c->prepare_count, clk_get_rate(c), |
124 | clk_get_accuracy(c)); | 124 | clk_get_accuracy(c), clk_get_phase(c)); |
125 | } | 125 | } |
126 | 126 | ||
127 | static void clk_summary_show_subtree(struct seq_file *s, struct clk *c, | 127 | static void clk_summary_show_subtree(struct seq_file *s, struct clk *c, |
@@ -143,8 +143,8 @@ static int clk_summary_show(struct seq_file *s, void *data) | |||
143 | struct clk *c; | 143 | struct clk *c; |
144 | struct hlist_head **lists = (struct hlist_head **)s->private; | 144 | struct hlist_head **lists = (struct hlist_head **)s->private; |
145 | 145 | ||
146 | seq_puts(s, " clock enable_cnt prepare_cnt rate accuracy\n"); | 146 | seq_puts(s, " clock enable_cnt prepare_cnt rate accuracy phase\n"); |
147 | seq_puts(s, "--------------------------------------------------------------------------------\n"); | 147 | seq_puts(s, "----------------------------------------------------------------------------------------\n"); |
148 | 148 | ||
149 | clk_prepare_lock(); | 149 | clk_prepare_lock(); |
150 | 150 | ||
@@ -180,6 +180,7 @@ static void clk_dump_one(struct seq_file *s, struct clk *c, int level) | |||
180 | seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); | 180 | seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); |
181 | seq_printf(s, "\"rate\": %lu", clk_get_rate(c)); | 181 | seq_printf(s, "\"rate\": %lu", clk_get_rate(c)); |
182 | seq_printf(s, "\"accuracy\": %lu", clk_get_accuracy(c)); | 182 | seq_printf(s, "\"accuracy\": %lu", clk_get_accuracy(c)); |
183 | seq_printf(s, "\"phase\": %d", clk_get_phase(c)); | ||
183 | } | 184 | } |
184 | 185 | ||
185 | static void clk_dump_subtree(struct seq_file *s, struct clk *c, int level) | 186 | static void clk_dump_subtree(struct seq_file *s, struct clk *c, int level) |
@@ -264,6 +265,11 @@ static int clk_debug_create_one(struct clk *clk, struct dentry *pdentry) | |||
264 | if (!d) | 265 | if (!d) |
265 | goto err_out; | 266 | goto err_out; |
266 | 267 | ||
268 | d = debugfs_create_u32("clk_phase", S_IRUGO, clk->dentry, | ||
269 | (u32 *)&clk->phase); | ||
270 | if (!d) | ||
271 | goto err_out; | ||
272 | |||
267 | d = debugfs_create_x32("clk_flags", S_IRUGO, clk->dentry, | 273 | d = debugfs_create_x32("clk_flags", S_IRUGO, clk->dentry, |
268 | (u32 *)&clk->flags); | 274 | (u32 *)&clk->flags); |
269 | if (!d) | 275 | if (!d) |
@@ -1739,6 +1745,77 @@ out: | |||
1739 | EXPORT_SYMBOL_GPL(clk_set_parent); | 1745 | EXPORT_SYMBOL_GPL(clk_set_parent); |
1740 | 1746 | ||
1741 | /** | 1747 | /** |
1748 | * clk_set_phase - adjust the phase shift of a clock signal | ||
1749 | * @clk: clock signal source | ||
1750 | * @degrees: number of degrees the signal is shifted | ||
1751 | * | ||
1752 | * Shifts the phase of a clock signal by the specified | ||
1753 | * degrees. Returns 0 on success, -EERROR otherwise. | ||
1754 | * | ||
1755 | * This function makes no distinction about the input or reference | ||
1756 | * signal that we adjust the clock signal phase against. For example | ||
1757 | * phase locked-loop clock signal generators we may shift phase with | ||
1758 | * respect to feedback clock signal input, but for other cases the | ||
1759 | * clock phase may be shifted with respect to some other, unspecified | ||
1760 | * signal. | ||
1761 | * | ||
1762 | * Additionally the concept of phase shift does not propagate through | ||
1763 | * the clock tree hierarchy, which sets it apart from clock rates and | ||
1764 | * clock accuracy. A parent clock phase attribute does not have an | ||
1765 | * impact on the phase attribute of a child clock. | ||
1766 | */ | ||
1767 | int clk_set_phase(struct clk *clk, int degrees) | ||
1768 | { | ||
1769 | int ret = 0; | ||
1770 | |||
1771 | if (!clk) | ||
1772 | goto out; | ||
1773 | |||
1774 | /* sanity check degrees */ | ||
1775 | degrees %= 360; | ||
1776 | if (degrees < 0) | ||
1777 | degrees += 360; | ||
1778 | |||
1779 | clk_prepare_lock(); | ||
1780 | |||
1781 | if (!clk->ops->set_phase) | ||
1782 | goto out_unlock; | ||
1783 | |||
1784 | ret = clk->ops->set_phase(clk->hw, degrees); | ||
1785 | |||
1786 | if (!ret) | ||
1787 | clk->phase = degrees; | ||
1788 | |||
1789 | out_unlock: | ||
1790 | clk_prepare_unlock(); | ||
1791 | |||
1792 | out: | ||
1793 | return ret; | ||
1794 | } | ||
1795 | |||
1796 | /** | ||
1797 | * clk_get_phase - return the phase shift of a clock signal | ||
1798 | * @clk: clock signal source | ||
1799 | * | ||
1800 | * Returns the phase shift of a clock node in degrees, otherwise returns | ||
1801 | * -EERROR. | ||
1802 | */ | ||
1803 | int clk_get_phase(struct clk *clk) | ||
1804 | { | ||
1805 | int ret = 0; | ||
1806 | |||
1807 | if (!clk) | ||
1808 | goto out; | ||
1809 | |||
1810 | clk_prepare_lock(); | ||
1811 | ret = clk->phase; | ||
1812 | clk_prepare_unlock(); | ||
1813 | |||
1814 | out: | ||
1815 | return ret; | ||
1816 | } | ||
1817 | |||
1818 | /** | ||
1742 | * __clk_init - initialize the data structures in a struct clk | 1819 | * __clk_init - initialize the data structures in a struct clk |
1743 | * @dev: device initializing this clk, placeholder for now | 1820 | * @dev: device initializing this clk, placeholder for now |
1744 | * @clk: clk being initialized | 1821 | * @clk: clk being initialized |
diff --git a/include/linux/clk-private.h b/include/linux/clk-private.h index efbf70b9fd84..845be30be50f 100644 --- a/include/linux/clk-private.h +++ b/include/linux/clk-private.h | |||
@@ -46,6 +46,7 @@ struct clk { | |||
46 | unsigned int enable_count; | 46 | unsigned int enable_count; |
47 | unsigned int prepare_count; | 47 | unsigned int prepare_count; |
48 | unsigned long accuracy; | 48 | unsigned long accuracy; |
49 | int phase; | ||
49 | struct hlist_head children; | 50 | struct hlist_head children; |
50 | struct hlist_node child_node; | 51 | struct hlist_node child_node; |
51 | unsigned int notifier_count; | 52 | unsigned int notifier_count; |
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 411dd7eb2653..201a6195a3eb 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h | |||
@@ -129,6 +129,10 @@ struct dentry; | |||
129 | * set then clock accuracy will be initialized to parent accuracy | 129 | * set then clock accuracy will be initialized to parent accuracy |
130 | * or 0 (perfect clock) if clock has no parent. | 130 | * or 0 (perfect clock) if clock has no parent. |
131 | * | 131 | * |
132 | * @set_phase: Shift the phase this clock signal in degrees specified | ||
133 | * by the second argument. Valid values for degrees are | ||
134 | * 0-359. Return 0 on success, otherwise -EERROR. | ||
135 | * | ||
132 | * @init: Perform platform-specific initialization magic. | 136 | * @init: Perform platform-specific initialization magic. |
133 | * This is not not used by any of the basic clock types. | 137 | * This is not not used by any of the basic clock types. |
134 | * Please consider other ways of solving initialization problems | 138 | * Please consider other ways of solving initialization problems |
@@ -177,6 +181,7 @@ struct clk_ops { | |||
177 | unsigned long parent_rate, u8 index); | 181 | unsigned long parent_rate, u8 index); |
178 | unsigned long (*recalc_accuracy)(struct clk_hw *hw, | 182 | unsigned long (*recalc_accuracy)(struct clk_hw *hw, |
179 | unsigned long parent_accuracy); | 183 | unsigned long parent_accuracy); |
184 | int (*set_phase)(struct clk_hw *hw, int degrees); | ||
180 | void (*init)(struct clk_hw *hw); | 185 | void (*init)(struct clk_hw *hw); |
181 | int (*debug_init)(struct clk_hw *hw, struct dentry *dentry); | 186 | int (*debug_init)(struct clk_hw *hw, struct dentry *dentry); |
182 | }; | 187 | }; |
diff --git a/include/linux/clk.h b/include/linux/clk.h index fb5e097d8f72..38bdedd3e389 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h | |||
@@ -106,6 +106,25 @@ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb); | |||
106 | */ | 106 | */ |
107 | long clk_get_accuracy(struct clk *clk); | 107 | long clk_get_accuracy(struct clk *clk); |
108 | 108 | ||
109 | /** | ||
110 | * clk_set_phase - adjust the phase shift of a clock signal | ||
111 | * @clk: clock signal source | ||
112 | * @degrees: number of degrees the signal is shifted | ||
113 | * | ||
114 | * Shifts the phase of a clock signal by the specified degrees. Returns 0 on | ||
115 | * success, -EERROR otherwise. | ||
116 | */ | ||
117 | int clk_set_phase(struct clk *clk, int degrees); | ||
118 | |||
119 | /** | ||
120 | * clk_get_phase - return the phase shift of a clock signal | ||
121 | * @clk: clock signal source | ||
122 | * | ||
123 | * Returns the phase shift of a clock node in degrees, otherwise returns | ||
124 | * -EERROR. | ||
125 | */ | ||
126 | int clk_get_phase(struct clk *clk); | ||
127 | |||
109 | #else | 128 | #else |
110 | 129 | ||
111 | static inline long clk_get_accuracy(struct clk *clk) | 130 | static inline long clk_get_accuracy(struct clk *clk) |
@@ -113,6 +132,16 @@ static inline long clk_get_accuracy(struct clk *clk) | |||
113 | return -ENOTSUPP; | 132 | return -ENOTSUPP; |
114 | } | 133 | } |
115 | 134 | ||
135 | static inline long clk_set_phase(struct clk *clk, int phase) | ||
136 | { | ||
137 | return -ENOTSUPP; | ||
138 | } | ||
139 | |||
140 | static inline long clk_get_phase(struct clk *clk) | ||
141 | { | ||
142 | return -ENOTSUPP; | ||
143 | } | ||
144 | |||
116 | #endif | 145 | #endif |
117 | 146 | ||
118 | /** | 147 | /** |