summaryrefslogtreecommitdiff
path: root/include/board.h
blob: 678b652b0aa3fc547c01689f6f69cf6478a4504b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * (C) Copyright 2017
 * Mario Six,  Guntermann & Drunck GmbH, mario.six@gdsys.cc
 */

/*
 * This uclass encapsulates hardware methods to gather information about a
 * board or a specific device such as hard-wired GPIOs on GPIO expanders,
 * read-only data in flash ICs, or similar.
 *
 * The interface offers functions to read the usual standard data types (bool,
 * int, string) from the device, each of which is identified by a static
 * numeric ID (which will usually be defined as a enum in a header file).
 *
 * If for example the board had a read-only serial number flash IC, we could
 * call
 *
 * ret = board_detect(dev);
 * if (ret) {
 *	debug("board device not found.");
 *	return ret;
 * }
 *
 * ret = board_get_int(dev, ID_SERIAL_NUMBER, &serial);
 * if (ret) {
 *	debug("Error when reading serial number from device.");
 *	return ret;
 * }
 *
 * to read the serial number.
 */

#if CONFIG_IS_ENABLED(BOARD)
struct board_ops {
	/**
	 * detect() - Run the hardware info detection procedure for this
	 *	      device.
	 * @dev:      The device containing the information
	 *
	 * This operation might take a long time (e.g. read from EEPROM,
	 * check the presence of a device on a bus etc.), hence this is not
	 * done in the probe() method, but later during operation in this
	 * dedicated method.
	 *
	 * Return: 0 if OK, -ve on error.
	 */
	int (*detect)(struct udevice *dev);

	/**
	 * get_bool() - Read a specific bool data value that describes the
	 *		hardware setup.
	 * @dev:	The board instance to gather the data.
	 * @id:		A unique identifier for the bool value to be read.
	 * @val:	Pointer to a buffer that receives the value read.
	 *
	 * Return: 0 if OK, -ve on error.
	 */
	int (*get_bool)(struct udevice *dev, int id, bool *val);

	/**
	 * get_int() - Read a specific int data value that describes the
	 *	       hardware setup.
	 * @dev:       The board instance to gather the data.
	 * @id:        A unique identifier for the int value to be read.
	 * @val:       Pointer to a buffer that receives the value read.
	 *
	 * Return: 0 if OK, -ve on error.
	 */
	int (*get_int)(struct udevice *dev, int id, int *val);

	/**
	 * get_str() - Read a specific string data value that describes the
	 *	       hardware setup.
	 * @dev:	The board instance to gather the data.
	 * @id:		A unique identifier for the string value to be read.
	 * @size:	The size of the buffer to receive the string data.
	 * @val:	Pointer to a buffer that receives the value read.
	 *
	 * Return: 0 if OK, -ve on error.
	 */
	int (*get_str)(struct udevice *dev, int id, size_t size, char *val);

	/**
	 * get_fit_loadable - Get the name of an image to load from FIT
	 * This function can be used to provide the image names based on runtime
	 * detection. A classic use-case would when DTBOs are used to describe
	 * additionnal daughter cards.
	 *
	 * @dev:	The board instance to gather the data.
	 * @index:	Index of the image. Starts at 0 and gets incremented
	 *		after each call to this function.
	 * @type:	The type of image. For example, "fdt" for DTBs
	 * @strp:	A pointer to string. Untouched if the function fails
	 *
	 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
	 * error.
	 */
	int (*get_fit_loadable)(struct udevice *dev, int index,
				const char *type, const char **strp);
};

#define board_get_ops(dev)	((struct board_ops *)(dev)->driver->ops)

/**
 * board_detect() - Run the hardware info detection procedure for this device.
 *
 * @dev:	The device containing the information
 *
 * Return: 0 if OK, -ve on error.
 */
int board_detect(struct udevice *dev);

/**
 * board_get_bool() - Read a specific bool data value that describes the
 *		      hardware setup.
 * @dev:	The board instance to gather the data.
 * @id:		A unique identifier for the bool value to be read.
 * @val:	Pointer to a buffer that receives the value read.
 *
 * Return: 0 if OK, -ve on error.
 */
int board_get_bool(struct udevice *dev, int id, bool *val);

/**
 * board_get_int() - Read a specific int data value that describes the
 *		     hardware setup.
 * @dev:	The board instance to gather the data.
 * @id:		A unique identifier for the int value to be read.
 * @val:	Pointer to a buffer that receives the value read.
 *
 * Return: 0 if OK, -ve on error.
 */
int board_get_int(struct udevice *dev, int id, int *val);

/**
 * board_get_str() - Read a specific string data value that describes the
 *		     hardware setup.
 * @dev:	The board instance to gather the data.
 * @id:		A unique identifier for the string value to be read.
 * @size:	The size of the buffer to receive the string data.
 * @val:	Pointer to a buffer that receives the value read.
 *
 * Return: 0 if OK, -ve on error.
 */
int board_get_str(struct udevice *dev, int id, size_t size, char *val);

/**
 * board_get() - Return the board device for the board in question.
 * @devp: Pointer to structure to receive the board device.
 *
 * Since there can only be at most one board instance, the API can supply a
 * function that returns the unique device. This is especially useful for use
 * in board files.
 *
 * Return: 0 if OK, -ve on error.
 */
int board_get(struct udevice **devp);

/**
 * board_get_fit_loadable - Get the name of an image to load from FIT
 * This function can be used to provide the image names based on runtime
 * detection. A classic use-case would when DTBOs are used to describe
 * additionnal daughter cards.
 *
 * @dev:	The board instance to gather the data.
 * @index:	Index of the image. Starts at 0 and gets incremented
 *		after each call to this function.
 * @type:	The type of image. For example, "fdt" for DTBs
 * @strp:	A pointer to string. Untouched if the function fails
 *
 *
 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
 * error.
 */
int board_get_fit_loadable(struct udevice *dev, int index,
			   const char *type, const char **strp);

#else

static inline int board_detect(struct udevice *dev)
{
	return -ENOSYS;
}

static inline int board_get_bool(struct udevice *dev, int id, bool *val)
{
	return -ENOSYS;
}

static inline int board_get_int(struct udevice *dev, int id, int *val)
{
	return -ENOSYS;
}

static inline int board_get_str(struct udevice *dev, int id, size_t size,
				char *val)
{
	return -ENOSYS;
}

static inline int board_get(struct udevice **devp)
{
	return -ENOSYS;
}

static inline int board_get_fit_loadable(struct udevice *dev, int index,
					 const char *type, const char **strp)
{
	return -ENOSYS;
}

#endif