simple-bus.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2014 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. struct simple_bus_plat {
  8. u32 base;
  9. u32 size;
  10. u32 target;
  11. };
  12. fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr)
  13. {
  14. struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
  15. if (addr >= plat->base && addr < plat->base + plat->size)
  16. addr = (addr - plat->base) + plat->target;
  17. return addr;
  18. }
  19. static int simple_bus_post_bind(struct udevice *dev)
  20. {
  21. #if CONFIG_IS_ENABLED(OF_PLATDATA)
  22. return 0;
  23. #else
  24. u32 cell[3];
  25. int ret;
  26. ret = dev_read_u32_array(dev, "ranges", cell, ARRAY_SIZE(cell));
  27. if (!ret) {
  28. struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
  29. plat->base = cell[0];
  30. plat->target = cell[1];
  31. plat->size = cell[2];
  32. }
  33. return dm_scan_fdt_dev(dev);
  34. #endif
  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. { .compatible = "simple-mfd" },
  45. { }
  46. };
  47. U_BOOT_DRIVER(simple_bus_drv) = {
  48. .name = "generic_simple_bus",
  49. .id = UCLASS_SIMPLE_BUS,
  50. .of_match = generic_simple_bus_ids,
  51. };