platdata.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2013 Google, Inc
  4. *
  5. * (C) Copyright 2012
  6. * Pavel Herrmann <morpheus.ibis@gmail.com>
  7. * Marek Vasut <marex@denx.de>
  8. */
  9. #ifndef _DM_PLATDATA_H
  10. #define _DM_PLATDATA_H
  11. #include <linker_lists.h>
  12. /**
  13. * struct driver_info - Information required to instantiate a device
  14. *
  15. * NOTE: Avoid using this except in extreme circumstances, where device tree
  16. * is not feasible (e.g. serial driver in SPL where <8KB of SRAM is
  17. * available). U-Boot's driver model uses device tree for configuration.
  18. *
  19. * @name: Driver name
  20. * @platdata: Driver-specific platform data
  21. * @platdata_size: Size of platform data structure
  22. * @parent_idx: Index of the parent driver_info structure
  23. */
  24. struct driver_info {
  25. const char *name;
  26. const void *platdata;
  27. #if CONFIG_IS_ENABLED(OF_PLATDATA)
  28. unsigned short platdata_size;
  29. short parent_idx;
  30. #endif
  31. };
  32. #if CONFIG_IS_ENABLED(OF_PLATDATA)
  33. #define driver_info_parent_id(driver_info) driver_info->parent_idx
  34. #else
  35. #define driver_info_parent_id(driver_info) (-1)
  36. #endif
  37. /**
  38. * driver_rt - runtime information set up by U-Boot
  39. *
  40. * There is one of these for every driver_info in the linker list, indexed by
  41. * the driver_info idx value.
  42. *
  43. * @dev: Device created from this idx
  44. */
  45. struct driver_rt {
  46. struct udevice *dev;
  47. };
  48. /**
  49. * NOTE: Avoid using these except in extreme circumstances, where device tree
  50. * is not feasible (e.g. serial driver in SPL where <8KB of SRAM is
  51. * available). U-Boot's driver model uses device tree for configuration.
  52. *
  53. * When of-platdata is in use, U_BOOT_DEVICE() cannot be used outside of the
  54. * dt-platdata.c file created by dtoc
  55. */
  56. #if CONFIG_IS_ENABLED(OF_PLATDATA) && !defined(DT_PLATDATA_C)
  57. #define U_BOOT_DEVICE(__name) _Static_assert(false, \
  58. "Cannot use U_BOOT_DEVICE with of-platdata. Please use devicetree instead")
  59. #else
  60. #define U_BOOT_DEVICE(__name) \
  61. ll_entry_declare(struct driver_info, __name, driver_info)
  62. #endif
  63. /* Declare a list of devices. The argument is a driver_info[] array */
  64. #define U_BOOT_DEVICES(__name) \
  65. ll_entry_declare_list(struct driver_info, __name, driver_info)
  66. /**
  67. * Get a pointer to a given device info given its name
  68. *
  69. * With the declaration U_BOOT_DEVICE(name), DM_GET_DEVICE(name) will return a
  70. * pointer to the struct driver_info created by that declaration.
  71. *
  72. * if OF_PLATDATA is enabled, from this it is possible to use the @dev member of
  73. * struct driver_info to find the device pointer itself.
  74. *
  75. * TODO(sjg@chromium.org): U_BOOT_DEVICE() tells U-Boot to create a device, so
  76. * the naming seems sensible, but DM_GET_DEVICE() is a bit of misnomer, since it
  77. * finds the driver_info record, not the device.
  78. *
  79. * @__name: Driver name (C identifier, not a string. E.g. gpio7_at_ff7e0000)
  80. * @return struct driver_info * to the driver that created the device
  81. */
  82. #define DM_GET_DEVICE(__name) \
  83. ll_entry_get(struct driver_info, __name, driver_info)
  84. /**
  85. * dm_populate_phandle_data() - Populates phandle data in platda
  86. *
  87. * This populates phandle data with an U_BOOT_DEVICE entry get by
  88. * DM_GET_DEVICE. The implementation of this function will be done
  89. * by dtoc when parsing dtb.
  90. */
  91. void dm_populate_phandle_data(void);
  92. #endif