device-internal.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) 2013 Google, Inc
  3. *
  4. * (C) Copyright 2012
  5. * Pavel Herrmann <morpheus.ibis@gmail.com>
  6. * Marek Vasut <marex@denx.de>
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #ifndef _DM_DEVICE_INTERNAL_H
  11. #define _DM_DEVICE_INTERNAL_H
  12. struct udevice;
  13. /**
  14. * device_bind() - Create a device and bind it to a driver
  15. *
  16. * Called to set up a new device attached to a driver. The device will either
  17. * have platdata, or a device tree node which can be used to create the
  18. * platdata.
  19. *
  20. * Once bound a device exists but is not yet active until device_probe() is
  21. * called.
  22. *
  23. * @parent: Pointer to device's parent, under which this driver will exist
  24. * @drv: Device's driver
  25. * @name: Name of device (e.g. device tree node name)
  26. * @platdata: Pointer to data for this device - the structure is device-
  27. * specific but may include the device's I/O address, etc.. This is NULL for
  28. * devices which use device tree.
  29. * @of_offset: Offset of device tree node for this device. This is -1 for
  30. * devices which don't use device tree.
  31. * @devp: Returns a pointer to the bound device
  32. * @return 0 if OK, -ve on error
  33. */
  34. int device_bind(struct udevice *parent, struct driver *drv,
  35. const char *name, void *platdata, int of_offset,
  36. struct udevice **devp);
  37. /**
  38. * device_bind_by_name: Create a device and bind it to a driver
  39. *
  40. * This is a helper function used to bind devices which do not use device
  41. * tree.
  42. *
  43. * @parent: Pointer to device's parent
  44. * @pre_reloc_only: If true, bind the driver only if its DM_INIT_F flag is set.
  45. * If false bind the driver always.
  46. * @info: Name and platdata for this device
  47. * @devp: Returns a pointer to the bound device
  48. * @return 0 if OK, -ve on error
  49. */
  50. int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
  51. const struct driver_info *info, struct udevice **devp);
  52. /**
  53. * device_probe() - Probe a device, activating it
  54. *
  55. * Activate a device so that it is ready for use. All its parents are probed
  56. * first.
  57. *
  58. * @dev: Pointer to device to probe
  59. * @return 0 if OK, -ve on error
  60. */
  61. int device_probe(struct udevice *dev);
  62. /**
  63. * device_probe() - Probe a child device, activating it
  64. *
  65. * Activate a device so that it is ready for use. All its parents are probed
  66. * first. The child is provided with parent data if parent_priv is not NULL.
  67. *
  68. * @dev: Pointer to device to probe
  69. * @parent_priv: Pointer to parent data. If non-NULL then this is provided to
  70. * the child.
  71. * @return 0 if OK, -ve on error
  72. */
  73. int device_probe_child(struct udevice *dev, void *parent_priv);
  74. /**
  75. * device_remove() - Remove a device, de-activating it
  76. *
  77. * De-activate a device so that it is no longer ready for use. All its
  78. * children are deactivated first.
  79. *
  80. * @dev: Pointer to device to remove
  81. * @return 0 if OK, -ve on error (an error here is normally a very bad thing)
  82. */
  83. #ifdef CONFIG_DM_DEVICE_REMOVE
  84. int device_remove(struct udevice *dev);
  85. #else
  86. static inline int device_remove(struct udevice *dev) { return 0; }
  87. #endif
  88. /**
  89. * device_unbind() - Unbind a device, destroying it
  90. *
  91. * Unbind a device and remove all memory used by it
  92. *
  93. * @dev: Pointer to device to unbind
  94. * @return 0 if OK, -ve on error
  95. */
  96. int device_unbind(struct udevice *dev);
  97. #ifdef CONFIG_DM_DEVICE_REMOVE
  98. void device_free(struct udevice *dev);
  99. #else
  100. static inline void device_free(struct udevice *dev) {}
  101. #endif
  102. /* Cast away any volatile pointer */
  103. #define DM_ROOT_NON_CONST (((gd_t *)gd)->dm_root)
  104. #define DM_UCLASS_ROOT_NON_CONST (((gd_t *)gd)->uclass_root)
  105. #endif