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. 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. u32 cell[3];
  24. int ret;
  25. ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev), "ranges",
  26. 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. }
  35. UCLASS_DRIVER(simple_bus) = {
  36. .id = UCLASS_SIMPLE_BUS,
  37. .name = "simple_bus",
  38. .post_bind = simple_bus_post_bind,
  39. .per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat),
  40. };
  41. static const struct udevice_id generic_simple_bus_ids[] = {
  42. { .compatible = "simple-bus" },
  43. { .compatible = "simple-mfd" },
  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. };