board.c 878 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <linux/init.h>
  2. #include <linux/device.h>
  3. #include <linux/kernel.h>
  4. #include <linux/of.h>
  5. #include <linux/of_address.h>
  6. #include "board.h"
  7. static bool find_by_address(u64 base_address)
  8. {
  9. struct device_node *dn = of_find_all_nodes(NULL);
  10. struct resource res;
  11. while (dn) {
  12. if (of_can_translate_address(dn)
  13. && !of_address_to_resource(dn, 0, &res)) {
  14. if (res.start == base_address) {
  15. of_node_put(dn);
  16. return true;
  17. }
  18. }
  19. dn = of_find_all_nodes(dn);
  20. }
  21. return false;
  22. }
  23. bool __init board_staging_dt_node_available(const struct resource *resource,
  24. unsigned int num_resources)
  25. {
  26. unsigned int i;
  27. for (i = 0; i < num_resources; i++) {
  28. const struct resource *r = resource + i;
  29. if (resource_type(r) == IORESOURCE_MEM)
  30. if (find_by_address(r->start))
  31. return true; /* DT node available */
  32. }
  33. return false; /* Nothing found */
  34. }