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

metag: init common clk and use "core" clk

If the common clock framework is enabled, call of_clk_init(NULL) in
time_init() to register device tree clocks with the clock framework.

After this time_init() calls a new function init_metag_clocks(), which
looks for a clock named "core" in the node compatible with "img,meta"
(usually the root node). If found the get_core_freq machine callback is
overridden to obtain the core clock frequency using that clock.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Mike Turquette <mturquette@linaro.org>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: devicetree-discuss@lists.ozlabs.org

+106 -3
+30
Documentation/devicetree/bindings/metag/meta.txt
··· 1 + * Meta Processor Binding 2 + 3 + This binding specifies what properties must be available in the device tree 4 + representation of a Meta Processor Core, which is the root node in the tree. 5 + 6 + Required properties: 7 + 8 + - compatible: Specifies the compatibility list for the Meta processor. 9 + The type shall be <string> and the value shall include "img,meta". 10 + 11 + Optional properties: 12 + 13 + - clocks: Clock consumer specifiers as described in 14 + Documentation/devicetree/bindings/clock/clock-bindings.txt 15 + 16 + - clock-names: Clock consumer names as described in 17 + Documentation/devicetree/bindings/clock/clock-bindings.txt. 18 + 19 + Clocks are identified by name. Valid clocks are: 20 + 21 + - "core": The Meta core clock from which the Meta timers are derived. 22 + 23 + * Examples 24 + 25 + / { 26 + compatible = "toumaz,tz1090", "img,meta"; 27 + 28 + clocks = <&meta_core_clk>; 29 + clock-names = "core"; 30 + };
+8
arch/metag/include/asm/clock.h
··· 19 19 * core frequency will be determined like this: 20 20 * Meta 1: based on loops_per_jiffy. 21 21 * Meta 2: (EXPAND_TIMER_DIV + 1) MHz. 22 + * If a "core" clock is provided by the device tree, it 23 + * will override this function. 22 24 */ 23 25 struct meta_clock_desc { 24 26 unsigned long (*get_core_freq)(void); 25 27 }; 26 28 27 29 extern struct meta_clock_desc _meta_clock; 30 + 31 + /* 32 + * Perform platform clock initialisation, reading clocks from device tree etc. 33 + * Only accessible during boot. 34 + */ 35 + void init_metag_clocks(void); 28 36 29 37 /* 30 38 * Set up the default clock, ensuring all callbacks are valid - only accessible
+56 -1
arch/metag/kernel/clock.c
··· 8 8 * published by the Free Software Foundation. 9 9 */ 10 10 11 + #include <linux/clk.h> 11 12 #include <linux/delay.h> 12 13 #include <linux/io.h> 14 + #include <linux/of.h> 13 15 14 16 #include <asm/param.h> 15 17 #include <asm/clock.h> ··· 36 34 #endif 37 35 } 38 36 37 + static struct clk *clk_core; 38 + 39 + /* Clk based get_core_freq callback. */ 40 + static unsigned long get_core_freq_clk(void) 41 + { 42 + return clk_get_rate(clk_core); 43 + } 44 + 39 45 /** 40 - * setup_meta_clocks() - Set up the Meta clock. 46 + * init_metag_core_clock() - Set up core clock from devicetree. 47 + * 48 + * Checks to see if a "core" clock is provided in the device tree, and overrides 49 + * the get_core_freq callback to use it. 50 + */ 51 + static void __init init_metag_core_clock(void) 52 + { 53 + /* 54 + * See if a core clock is provided by the devicetree (and 55 + * registered by the init callback above). 56 + */ 57 + struct device_node *node; 58 + node = of_find_compatible_node(NULL, NULL, "img,meta"); 59 + if (!node) { 60 + pr_warn("%s: no compatible img,meta DT node found\n", 61 + __func__); 62 + return; 63 + } 64 + 65 + clk_core = of_clk_get_by_name(node, "core"); 66 + if (IS_ERR(clk_core)) { 67 + pr_warn("%s: no core clock found in DT\n", 68 + __func__); 69 + return; 70 + } 71 + 72 + /* 73 + * Override the core frequency callback to use 74 + * this clk. 75 + */ 76 + _meta_clock.get_core_freq = get_core_freq_clk; 77 + } 78 + 79 + /** 80 + * init_metag_clocks() - Set up clocks from devicetree. 81 + * 82 + * Set up important clocks from device tree. In particular any needed for clock 83 + * sources. 84 + */ 85 + void __init init_metag_clocks(void) 86 + { 87 + init_metag_core_clock(); 88 + } 89 + 90 + /** 91 + * setup_meta_clocks() - Early set up of the Meta clock. 41 92 * @desc: Clock descriptor usually provided by machine description 42 93 * 43 94 * Ensures all callbacks are valid.
+12 -2
arch/metag/kernel/time.c
··· 5 5 * 6 6 */ 7 7 8 - #include <linux/init.h> 9 - 10 8 #include <clocksource/metag_generic.h> 9 + #include <linux/clk-provider.h> 10 + #include <linux/init.h> 11 + #include <asm/clock.h> 11 12 12 13 void __init time_init(void) 13 14 { 15 + #ifdef CONFIG_COMMON_CLK 16 + /* Init clocks from device tree */ 17 + of_clk_init(NULL); 18 + #endif 19 + 20 + /* Init meta clocks, particularly the core clock */ 21 + init_metag_clocks(); 22 + 23 + /* Set up the timer clock sources */ 14 24 metag_generic_timer_init(); 15 25 }