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