simple-bus.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev), "ranges",
  29. cell, ARRAY_SIZE(cell));
  30. if (!ret) {
  31. struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
  32. plat->base = cell[0];
  33. plat->target = cell[1];
  34. plat->size = cell[2];
  35. }
  36. return dm_scan_fdt_dev(dev);
  37. #endif
  38. }
  39. UCLASS_DRIVER(simple_bus) = {
  40. .id = UCLASS_SIMPLE_BUS,
  41. .name = "simple_bus",
  42. .post_bind = simple_bus_post_bind,
  43. .per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat),
  44. };
  45. static const struct udevice_id generic_simple_bus_ids[] = {
  46. { .compatible = "simple-bus" },
  47. { .compatible = "simple-mfd" },
  48. { }
  49. };
  50. U_BOOT_DRIVER(simple_bus_drv) = {
  51. .name = "generic_simple_bus",
  52. .id = UCLASS_SIMPLE_BUS,
  53. .of_match = generic_simple_bus_ids,
  54. };