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