simple-bus.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2014 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <dm/root.h>
  9. DECLARE_GLOBAL_DATA_PTR;
  10. struct simple_bus_plat {
  11. u32 base;
  12. u32 size;
  13. u32 target;
  14. };
  15. fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr)
  16. {
  17. struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
  18. if (addr >= plat->base && addr < plat->base + plat->size)
  19. addr = (addr - plat->base) + plat->target;
  20. return addr;
  21. }
  22. static int simple_bus_post_bind(struct udevice *dev)
  23. {
  24. u32 cell[3];
  25. int ret;
  26. ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset, "ranges",
  27. cell, ARRAY_SIZE(cell));
  28. if (!ret) {
  29. struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
  30. plat->base = cell[0];
  31. plat->target = cell[1];
  32. plat->size = cell[2];
  33. }
  34. return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
  35. }
  36. UCLASS_DRIVER(simple_bus) = {
  37. .id = UCLASS_SIMPLE_BUS,
  38. .name = "simple_bus",
  39. .post_bind = simple_bus_post_bind,
  40. .per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat),
  41. };
  42. static const struct udevice_id generic_simple_bus_ids[] = {
  43. { .compatible = "simple-bus" },
  44. { }
  45. };
  46. U_BOOT_DRIVER(simple_bus_drv) = {
  47. .name = "generic_simple_bus",
  48. .id = UCLASS_SIMPLE_BUS,
  49. .of_match = generic_simple_bus_ids,
  50. };