device-internal.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * @info: Name and platdata for this device
  45. * @devp: Returns a pointer to the bound device
  46. * @return 0 if OK, -ve on error
  47. */
  48. int device_bind_by_name(struct udevice *parent, const struct driver_info *info,
  49. struct udevice **devp);
  50. /**
  51. * device_probe() - Probe a device, activating it
  52. *
  53. * Activate a device so that it is ready for use. All its parents are probed
  54. * first.
  55. *
  56. * @dev: Pointer to device to probe
  57. * @return 0 if OK, -ve on error
  58. */
  59. int device_probe(struct udevice *dev);
  60. /**
  61. * device_remove() - Remove a device, de-activating it
  62. *
  63. * De-activate a device so that it is no longer ready for use. All its
  64. * children are deactivated first.
  65. *
  66. * @dev: Pointer to device to remove
  67. * @return 0 if OK, -ve on error (an error here is normally a very bad thing)
  68. */
  69. int device_remove(struct udevice *dev);
  70. /**
  71. * device_unbind() - Unbind a device, destroying it
  72. *
  73. * Unbind a device and remove all memory used by it
  74. *
  75. * @dev: Pointer to device to unbind
  76. * @return 0 if OK, -ve on error
  77. */
  78. int device_unbind(struct udevice *dev);
  79. /* Cast away any volatile pointer */
  80. #define DM_ROOT_NON_CONST (((gd_t *)gd)->dm_root)
  81. #define DM_UCLASS_ROOT_NON_CONST (((gd_t *)gd)->uclass_root)
  82. #endif