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

soc: fsl: qe: introduce qe_get_device_node helper

The 'try of_find_compatible_node(NULL, NULL, "fsl,qe"), fall back to
of_find_node_by_type(NULL, "qe")' pattern is repeated five
times. Factor it into a common helper.

Reviewed-by: Christophe Leroy <christophe.leroy@c-s.fr>
Reviewed-by: Qiang Zhao <qiang.zhao@nxp.com>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Li Yang <leoyang.li@nxp.com>

authored by

Rasmus Villemoes and committed by
Li Yang
d7fc5963 875f2aab

+29 -42
+29 -42
drivers/soc/fsl/qe/qe.c
··· 56 56 57 57 static phys_addr_t qebase = -1; 58 58 59 + static struct device_node *qe_get_device_node(void) 60 + { 61 + struct device_node *qe; 62 + 63 + /* 64 + * Newer device trees have an "fsl,qe" compatible property for the QE 65 + * node, but we still need to support older device trees. 66 + */ 67 + qe = of_find_compatible_node(NULL, NULL, "fsl,qe"); 68 + if (qe) 69 + return qe; 70 + return of_find_node_by_type(NULL, "qe"); 71 + } 72 + 59 73 static phys_addr_t get_qe_base(void) 60 74 { 61 75 struct device_node *qe; ··· 79 65 if (qebase != -1) 80 66 return qebase; 81 67 82 - qe = of_find_compatible_node(NULL, NULL, "fsl,qe"); 83 - if (!qe) { 84 - qe = of_find_node_by_type(NULL, "qe"); 85 - if (!qe) 86 - return qebase; 87 - } 68 + qe = qe_get_device_node(); 69 + if (!qe) 70 + return qebase; 88 71 89 72 ret = of_address_to_resource(qe, 0, &res); 90 73 if (!ret) ··· 175 164 if (brg_clk) 176 165 return brg_clk; 177 166 178 - qe = of_find_compatible_node(NULL, NULL, "fsl,qe"); 179 - if (!qe) { 180 - qe = of_find_node_by_type(NULL, "qe"); 181 - if (!qe) 182 - return brg_clk; 183 - } 167 + qe = qe_get_device_node(); 168 + if (!qe) 169 + return brg_clk; 184 170 185 171 prop = of_get_property(qe, "brg-frequency", &size); 186 172 if (prop && size == sizeof(*prop)) ··· 566 558 567 559 initialized = 1; 568 560 569 - /* 570 - * Newer device trees have an "fsl,qe" compatible property for the QE 571 - * node, but we still need to support older device trees. 572 - */ 573 - qe = of_find_compatible_node(NULL, NULL, "fsl,qe"); 574 - if (!qe) { 575 - qe = of_find_node_by_type(NULL, "qe"); 576 - if (!qe) 577 - return NULL; 578 - } 561 + qe = qe_get_device_node(); 562 + if (!qe) 563 + return NULL; 579 564 580 565 /* Find the 'firmware' child node */ 581 566 fw = of_get_child_by_name(qe, "firmware"); ··· 614 613 unsigned int num_of_risc = 0; 615 614 const u32 *prop; 616 615 617 - qe = of_find_compatible_node(NULL, NULL, "fsl,qe"); 618 - if (!qe) { 619 - /* Older devices trees did not have an "fsl,qe" 620 - * compatible property, so we need to look for 621 - * the QE node by name. 622 - */ 623 - qe = of_find_node_by_type(NULL, "qe"); 624 - if (!qe) 625 - return num_of_risc; 626 - } 616 + qe = qe_get_device_node(); 617 + if (!qe) 618 + return num_of_risc; 627 619 628 620 prop = of_get_property(qe, "fsl,qe-num-riscs", &size); 629 621 if (prop && size == sizeof(*prop)) ··· 636 642 const u32 *prop; 637 643 638 644 num_of_snums = 28; /* The default number of snum for threads is 28 */ 639 - qe = of_find_compatible_node(NULL, NULL, "fsl,qe"); 640 - if (!qe) { 641 - /* Older devices trees did not have an "fsl,qe" 642 - * compatible property, so we need to look for 643 - * the QE node by name. 644 - */ 645 - qe = of_find_node_by_type(NULL, "qe"); 646 - if (!qe) 647 - return num_of_snums; 648 - } 645 + qe = qe_get_device_node(); 646 + if (!qe) 647 + return num_of_snums; 649 648 650 649 prop = of_get_property(qe, "fsl,qe-num-snums", &size); 651 650 if (prop && size == sizeof(*prop)) {