simple-bus.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. DECLARE_GLOBAL_DATA_PTR;
  9. struct simple_bus_plat {
  10. u32 base;
  11. u32 size;
  12. u32 target;
  13. };
  14. fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr)
  15. {
  16. struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
  17. if (addr >= plat->base && addr < plat->base + plat->size)
  18. addr = (addr - plat->base) + plat->target;
  19. return addr;
  20. }
  21. static int simple_bus_post_bind(struct udevice *dev)
  22. {
  23. #if CONFIG_IS_ENABLED(OF_PLATDATA)
  24. return 0;
  25. #else
  26. u32 cell[3];
  27. int ret;
  28. ret = dev_read_u32_array(dev, "ranges", cell, ARRAY_SIZE(cell));
  29. if (!ret) {
  30. struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
  31. plat->base = cell[0];
  32. plat->target = cell[1];
  33. plat->size = cell[2];
  34. }
  35. return dm_scan_fdt_dev(dev);
  36. #endif
  37. }
  38. UCLASS_DRIVER(simple_bus) = {
  39. .id = UCLASS_SIMPLE_BUS,
  40. .name = "simple_bus",
  41. .post_bind = simple_bus_post_bind,
  42. .per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat),
  43. };
  44. static const struct udevice_id generic_simple_bus_ids[] = {
  45. { .compatible = "simple-bus" },
  46. { .compatible = "simple-mfd" },
  47. { }
  48. };
  49. U_BOOT_DRIVER(simple_bus_drv) = {
  50. .name = "generic_simple_bus",
  51. .id = UCLASS_SIMPLE_BUS,
  52. .of_match = generic_simple_bus_ids,
  53. };