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