soc.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2020 - Texas Instruments Incorporated - http://www.ti.com/
  4. * Dave Gerlach <d-gerlach@ti.com>
  5. */
  6. #ifndef __SOC_H
  7. #define __SOC_H
  8. #define SOC_MAX_STR_SIZE 128
  9. /**
  10. * struct soc_attr - Contains SoC identify information to be used in
  11. * SoC matching. An array of these structs
  12. * representing different SoCs can be passed to
  13. * soc_device_match and the struct matching the SoC
  14. * in use will be returned.
  15. *
  16. * @family - Name of SoC family that can include multiple related SoC
  17. * variants. Example: am33
  18. * @machine - Name of a specific SoC. Example: am3352
  19. * @revision - Name of a specific SoC revision. Example: SR1.1
  20. * @data - A pointer to user data for the SoC variant
  21. */
  22. struct soc_attr {
  23. const char *family;
  24. const char *machine;
  25. const char *revision;
  26. const void *data;
  27. };
  28. struct soc_ops {
  29. /**
  30. * get_machine() - Get machine name of an SOC
  31. *
  32. * @dev: Device to check (UCLASS_SOC)
  33. * @buf: Buffer to place string
  34. * @size: Size of string space
  35. * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
  36. */
  37. int (*get_machine)(struct udevice *dev, char *buf, int size);
  38. /**
  39. * get_revision() - Get revision name of a SOC
  40. *
  41. * @dev: Device to check (UCLASS_SOC)
  42. * @buf: Buffer to place string
  43. * @size: Size of string space
  44. * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
  45. */
  46. int (*get_revision)(struct udevice *dev, char *buf, int size);
  47. /**
  48. * get_family() - Get family name of an SOC
  49. *
  50. * @dev: Device to check (UCLASS_SOC)
  51. * @buf: Buffer to place string
  52. * @size: Size of string space
  53. * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
  54. */
  55. int (*get_family)(struct udevice *dev, char *buf, int size);
  56. };
  57. #define soc_get_ops(dev) ((struct soc_ops *)(dev)->driver->ops)
  58. #ifdef CONFIG_SOC_DEVICE
  59. /**
  60. * soc_get() - Return the soc device for the soc in use.
  61. * @devp: Pointer to structure to receive the soc device.
  62. *
  63. * Since there can only be at most one SOC instance, the API can supply a
  64. * function that returns the unique device.
  65. *
  66. * Return: 0 if OK, -ve on error.
  67. */
  68. int soc_get(struct udevice **devp);
  69. /**
  70. * soc_get_machine() - Get machine name of an SOC
  71. * @dev: Device to check (UCLASS_SOC)
  72. * @buf: Buffer to place string
  73. * @size: Size of string space
  74. *
  75. * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
  76. */
  77. int soc_get_machine(struct udevice *dev, char *buf, int size);
  78. /**
  79. * soc_get_revision() - Get revision name of an SOC
  80. * @dev: Device to check (UCLASS_SOC)
  81. * @buf: Buffer to place string
  82. * @size: Size of string space
  83. *
  84. * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
  85. */
  86. int soc_get_revision(struct udevice *dev, char *buf, int size);
  87. /**
  88. * soc_get_family() - Get family name of an SOC
  89. * @dev: Device to check (UCLASS_SOC)
  90. * @buf: Buffer to place string
  91. * @size: Size of string space
  92. *
  93. * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
  94. */
  95. int soc_get_family(struct udevice *dev, char *buf, int size);
  96. /**
  97. * soc_device_match() - Return match from an array of soc_attr
  98. * @matches: Array with any combination of family, revision or machine set
  99. *
  100. * Return: Pointer to struct from matches array with set attributes matching
  101. * those provided by the soc device, or NULL if no match found.
  102. */
  103. const struct soc_attr *
  104. soc_device_match(const struct soc_attr *matches);
  105. #else
  106. static inline int soc_get(struct udevice **devp)
  107. {
  108. return -ENOSYS;
  109. }
  110. static inline int soc_get_machine(struct udevice *dev, char *buf, int size)
  111. {
  112. return -ENOSYS;
  113. }
  114. static inline int soc_get_revision(struct udevice *dev, char *buf, int size)
  115. {
  116. return -ENOSYS;
  117. }
  118. static inline int soc_get_family(struct udevice *dev, char *buf, int size)
  119. {
  120. return -ENOSYS;
  121. }
  122. static inline const struct soc_attr *
  123. soc_device_match(const struct soc_attr *matches)
  124. {
  125. return NULL;
  126. }
  127. #endif
  128. #endif /* _SOC_H */