soc.h 3.9 KB

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