MIPS: csrc-r4k: get counter rate from devicetree
Subsystems (2)
cover MIPS: csrc-r4k: get counter rate from devicetree
At the moment csrc-r4k rate is fixed to 100 MHz.
This is acceptable only for qemu-malta.
This patch introduces a devicetree-based solution
for detecting csrc-r4k counter rate.
The most notable users of this patch are AR9331-based boards.
Antony Pavlov (2):
of: base: import of_get_cpu_node() from linux-v4.7-rc2
MIPS: csrc-r4k: get cp0 counter rate from devicetree
arch/mips/lib/csrc-r4k.c | 24 ++++++++++++-- drivers/of/base.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ include/of.h | 10 ++++++ 3 files changed, 118 insertions(+), 2 deletions(-)
Signature · 7 lines
2.8.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/2 of: base: import of_get_cpu_node() from linux-v4.7-rc2
--- drivers/of/base.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/of.h | 10 +++++++ 2 files changed, 96 insertions(+)
drivers/of/base.c +86 -0
@@ -380,6 +380,92 @@ const void *of_get_property(const struct device_node *np, const char *name, }EXPORT_SYMBOL (of_get_property); +/* +* arch_match_cpu_phys_id - Match the given logical CPU and physical id +* +* @cpu: logical cpu index of a core/thread +* @phys_id: physical identifier of a core/thread +* +* Returns true if the physical identifier and the logical cpu index +* correspond to the same core/thread, false otherwise. +*/ +static bool arch_match_cpu_phys_id (int cpu,u64 phys_id) +{ +return (u32 )phys_id == cpu; +} + +/** +* Checks if the given "prop_name" property holds the physical id of the +* core/thread corresponding to the logical cpu 'cpu'. If 'thread' is not +* NULL, local thread number within the core is returned in it. +*/ +static bool __of_find_n_match_cpu_property (struct device_node *cpun, +const char *prop_name,int cpu,unsigned int *thread) +{ +const __be32 *cell; +int ac, prop_len, tid; +u64 hwid; + + ac =of_n_addr_cells (cpun); + cell =of_get_property (cpun, prop_name, &prop_len); +if (!cell || !ac) +return false; + prop_len /=sizeof (*cell) * ac; +for (tid =0 ; tid < prop_len; tid++) { + hwid =of_read_number (cell, ac); +if (arch_match_cpu_phys_id (cpu, hwid)) { +if (thread) + *thread = tid; +return true; + } + cell += ac; + } +return false; +} + +/* +* arch_find_n_match_cpu_physical_id - See if the given device node is +* for the cpu corresponding to logical cpu 'cpu'. Return true if so, +* else false. If 'thread' is non-NULL, the local thread number within the +* core is returned in it. +*/ +static bool arch_find_n_match_cpu_physical_id (struct device_node *cpun, +int cpu,unsigned int *thread) +{ +return __of_find_n_match_cpu_property (cpun,"reg" , cpu, thread); +} + +/** +* of_get_cpu_node - Get device node associated with the given logical CPU +* +* @cpu: CPU number(logical index) for which device node is required +* @thread: if not NULL, local thread number within the physical core is +* returned +* +* The main purpose of this function is to retrieve the device node for the +* given logical CPU index. It should be used to initialize the of_node in +* cpu device. Once of_node in cpu device is populated, all the further +* references can use that instead. +* +* CPU logical to physical index mapping is architecture specific and is built +* before booting secondary cores. This function uses arch_match_cpu_phys_id +* which can be overridden by architecture specific implementation. +* +* Returns a node pointer for the logical cpu with refcount incremented, use +* of_node_put() on it when done. Returns NULL if not found. +*/ +struct device_node *of_get_cpu_node (int cpu,unsigned int *thread) +{ +struct device_node *cpun; + +for_each_node_by_type (cpun,"cpu" ) { +if (arch_find_n_match_cpu_physical_id (cpun, cpu, thread)) +return cpun; + } +return NULL ; +} +EXPORT_SYMBOL (of_get_cpu_node); +/** Checks if the given "compat" string matches one of the strings in * the device's "compatible" property */
include/of.h +10 -0
@@ -111,6 +111,7 @@ extern struct property *of_find_property(const struct device_node *np, const char *name, int *lenp);extern const void *of_get_property (const struct device_node *np,const char *name,int *lenp); +extern struct device_node *of_get_cpu_node (int cpu,unsigned int *thread);extern int of_set_property (struct device_node *node,const char *p,const void *val,int len,int create);
@@ -347,6 +348,12 @@ static inline const void *of_get_property(const struct device_node *np,return NULL ; } +static inline struct device_node *of_get_cpu_node (int cpu, +unsigned int *thread) +{ +return NULL ; +} +static inline int of_set_property (struct device_node *node,const char *p,const void *val,int len,int create) {
@@ -639,6 +646,9 @@ static inline struct device_node *of_find_node_by_path_or_alias(#define for_each_node_by_name (dn, name) \ for (dn = of_find_node_by_name(NULL, name); dn; \ dn = of_find_node_by_name(dn, name)) +#define for_each_node_by_type (dn, type) \ + for (dn = of_find_node_by_type(NULL, type); dn; \ + dn = of_find_node_by_type(dn, type))#define for_each_node_by_name_from (dn, root, name) \ for (dn = of_find_node_by_name(root, name); dn; \ dn = of_find_node_by_name(dn, name))
Signature · 7 lines
2.8.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/2 MIPS: csrc-r4k: get cp0 counter rate from devicetree
In reply to Antony Pavlov--- arch/mips/lib/csrc-r4k.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
arch/mips/lib/csrc-r4k.c +22 -2
@@ -21,6 +21,8 @@*/ #include <init.h> +#include <of.h> +#include <linux/clk.h> #include <clock.h> #include <io.h> #include <asm/mipsregs.h>
@@ -37,8 +39,26 @@ static struct clocksource cs = {static int clocksource_init (void ) { - cs.mult =clocksource_hz2mult (100000000 , cs.shift); +unsigned int mips_hpt_frequency; +struct device_node *np; +struct clk *clk; + +/* default rate: 100 MHz */ + mips_hpt_frequency =100000000 ; + +if (IS_ENABLED (CONFIG_OFTREE )) { + np =of_get_cpu_node (0 ,NULL ); +if (np) { + clk =of_clk_get (np,0 ); +if (!IS_ERR (clk)) { + mips_hpt_frequency =clk_get_rate (clk) /2 ; + } + } + } + +clocks_calc_mult_shift (&cs.mult, &cs.shift, + mips_hpt_frequency,NSEC_PER_SEC ,10 );return init_clock (&cs); } -core_initcall (clocksource_init); +postcore_initcall (clocksource_init);
Signature · 7 lines
2.8.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 6 lines · Antony Pavlov
At the moment csrc-r4k rate is fixed to 100 MHz.
This is acceptable only for qemu-malta.This patch introduces a devicetree-based solution
for detecting csrc-r4k counter rate.
Quoted 6 lines
The most notable users of this patch are AR9331-based boards.
Antony Pavlov (2):
of: base: importof_get_cpu_node()from linux-v4.7-rc2
MIPS: csrc-r4k: get cp0 counter rate from devicetree
Applied, thanks
Sascha
Quoted 10 lines
arch/mips/lib/csrc-r4k.c | 24 ++++++++++++-- drivers/of/base.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ include/of.h | 10 ++++++ 3 files changed, 118 insertions(+), 2 deletions(-)Signature · 1 line
2.8.1
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox