mpc5xxx_clocks.c 854 B

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