Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: add accuracy support for fixed clock

This patch adds support for accuracy retrieval on fixed clocks.
It also adds a new dt property called 'clock-accuracy' to define the clock
accuracy.

This can be usefull for oscillator (RC, crystal, ...) definitions which are
always given an accuracy characteristic.

Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>
Signed-off-by: Mike Turquette <mturquette@linaro.org>

authored by

Boris BREZILLON and committed by
Mike Turquette
0903ea60 5279fc40

+44 -6
+3
Documentation/devicetree/bindings/clock/fixed-clock.txt
··· 10 10 - clock-frequency : frequency of clock in Hz. Should be a single cell. 11 11 12 12 Optional properties: 13 + - clock-accuracy : accuracy of clock in ppb (parts per billion). 14 + Should be a single cell. 13 15 - gpios : From common gpio binding; gpio connection to clock enable pin. 14 16 - clock-output-names : From common clock binding. 15 17 ··· 20 18 compatible = "fixed-clock"; 21 19 #clock-cells = <0>; 22 20 clock-frequency = <1000000000>; 21 + clock-accuracy = <100>; 23 22 };
+37 -6
drivers/clk/clk-fixed-rate.c
··· 34 34 return to_clk_fixed_rate(hw)->fixed_rate; 35 35 } 36 36 37 + static unsigned long clk_fixed_rate_recalc_accuracy(struct clk_hw *hw, 38 + unsigned long parent_accuracy) 39 + { 40 + return to_clk_fixed_rate(hw)->fixed_accuracy; 41 + } 42 + 37 43 const struct clk_ops clk_fixed_rate_ops = { 38 44 .recalc_rate = clk_fixed_rate_recalc_rate, 45 + .recalc_accuracy = clk_fixed_rate_recalc_accuracy, 39 46 }; 40 47 EXPORT_SYMBOL_GPL(clk_fixed_rate_ops); 41 48 42 49 /** 43 - * clk_register_fixed_rate - register fixed-rate clock with the clock framework 50 + * clk_register_fixed_rate_with_accuracy - register fixed-rate clock with the 51 + * clock framework 44 52 * @dev: device that is registering this clock 45 53 * @name: name of this clock 46 54 * @parent_name: name of clock's parent 47 55 * @flags: framework-specific flags 48 56 * @fixed_rate: non-adjustable clock rate 57 + * @fixed_accuracy: non-adjustable clock rate 49 58 */ 50 - struct clk *clk_register_fixed_rate(struct device *dev, const char *name, 51 - const char *parent_name, unsigned long flags, 52 - unsigned long fixed_rate) 59 + struct clk *clk_register_fixed_rate_with_accuracy(struct device *dev, 60 + const char *name, const char *parent_name, unsigned long flags, 61 + unsigned long fixed_rate, unsigned long fixed_accuracy) 53 62 { 54 63 struct clk_fixed_rate *fixed; 55 64 struct clk *clk; ··· 79 70 80 71 /* struct clk_fixed_rate assignments */ 81 72 fixed->fixed_rate = fixed_rate; 73 + fixed->fixed_accuracy = fixed_accuracy; 82 74 fixed->hw.init = &init; 83 75 84 76 /* register the clock */ 85 77 clk = clk_register(dev, &fixed->hw); 86 - 87 78 if (IS_ERR(clk)) 88 79 kfree(fixed); 89 80 90 81 return clk; 82 + } 83 + EXPORT_SYMBOL_GPL(clk_register_fixed_rate_with_accuracy); 84 + 85 + /** 86 + * clk_register_fixed_rate - register fixed-rate clock with the clock framework 87 + * @dev: device that is registering this clock 88 + * @name: name of this clock 89 + * @parent_name: name of clock's parent 90 + * @flags: framework-specific flags 91 + * @fixed_rate: non-adjustable clock rate 92 + */ 93 + struct clk *clk_register_fixed_rate(struct device *dev, const char *name, 94 + const char *parent_name, unsigned long flags, 95 + unsigned long fixed_rate) 96 + { 97 + return clk_register_fixed_rate_with_accuracy(dev, name, parent_name, 98 + flags, fixed_rate, 0); 91 99 } 92 100 EXPORT_SYMBOL_GPL(clk_register_fixed_rate); 93 101 ··· 117 91 struct clk *clk; 118 92 const char *clk_name = node->name; 119 93 u32 rate; 94 + u32 accuracy = 0; 120 95 121 96 if (of_property_read_u32(node, "clock-frequency", &rate)) 122 97 return; 123 98 99 + of_property_read_u32(node, "clock-accuracy", &accuracy); 100 + 124 101 of_property_read_string(node, "clock-output-names", &clk_name); 125 102 126 - clk = clk_register_fixed_rate(NULL, clk_name, NULL, CLK_IS_ROOT, rate); 103 + clk = clk_register_fixed_rate_with_accuracy(NULL, clk_name, NULL, 104 + CLK_IS_ROOT, rate, 105 + accuracy); 127 106 if (!IS_ERR(clk)) 128 107 of_clk_add_provider(node, of_clk_src_simple_get, clk); 129 108 }
+4
include/linux/clk-provider.h
··· 204 204 struct clk_fixed_rate { 205 205 struct clk_hw hw; 206 206 unsigned long fixed_rate; 207 + unsigned long fixed_accuracy; 207 208 u8 flags; 208 209 }; 209 210 ··· 212 211 struct clk *clk_register_fixed_rate(struct device *dev, const char *name, 213 212 const char *parent_name, unsigned long flags, 214 213 unsigned long fixed_rate); 214 + struct clk *clk_register_fixed_rate_with_accuracy(struct device *dev, 215 + const char *name, const char *parent_name, unsigned long flags, 216 + unsigned long fixed_rate, unsigned long fixed_accuracy); 215 217 216 218 void of_fixed_clk_setup(struct device_node *np); 217 219