Loading...
1// SPDX-License-Identifier: GPL-2.0
2
3#include <linux/kernel.h>
4#include <linux/export.h>
5#include <linux/property.h>
6
7#include <asm/mpc5xxx.h>
8
9/**
10 * mpc5xxx_fwnode_get_bus_frequency - Find the bus frequency for a firmware node
11 * @fwnode: firmware node
12 *
13 * Returns bus frequency (IPS on MPC512x, IPB on MPC52xx),
14 * or 0 if the bus frequency cannot be found.
15 */
16unsigned long mpc5xxx_fwnode_get_bus_frequency(struct fwnode_handle *fwnode)
17{
18 struct fwnode_handle *parent;
19 u32 bus_freq;
20 int ret;
21
22 ret = fwnode_property_read_u32(fwnode, "bus-frequency", &bus_freq);
23 if (!ret)
24 return bus_freq;
25
26 fwnode_for_each_parent_node(fwnode, parent) {
27 ret = fwnode_property_read_u32(parent, "bus-frequency", &bus_freq);
28 if (!ret) {
29 fwnode_handle_put(parent);
30 return bus_freq;
31 }
32 }
33
34 return 0;
35}
36EXPORT_SYMBOL(mpc5xxx_fwnode_get_bus_frequency);
1/**
2 * mpc5xxx_get_bus_frequency - Find the bus frequency for a device
3 * @node: device node
4 *
5 * Returns bus frequency (IPS on MPC512x, IPB on MPC52xx),
6 * or 0 if the bus frequency cannot be found.
7 */
8
9#include <linux/kernel.h>
10#include <linux/of_platform.h>
11#include <linux/export.h>
12
13unsigned int
14mpc5xxx_get_bus_frequency(struct device_node *node)
15{
16 struct device_node *np;
17 const unsigned int *p_bus_freq = NULL;
18
19 of_node_get(node);
20 while (node) {
21 p_bus_freq = of_get_property(node, "bus-frequency", NULL);
22 if (p_bus_freq)
23 break;
24
25 np = of_get_parent(node);
26 of_node_put(node);
27 node = np;
28 }
29 if (node)
30 of_node_put(node);
31
32 return p_bus_freq ? *p_bus_freq : 0;
33}
34EXPORT_SYMBOL(mpc5xxx_get_bus_frequency);