blob: 18d183c4bd3f5599ed25edf976970c01235cb5b9 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +02002/*
3 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
4 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +02005 */
6
7#ifndef __GENERIC_PHY_H
8#define __GENERIC_PHY_H
9
Neil Armstrongc2b9aa92020-03-30 11:27:23 +020010#include <dm/ofnode.h>
11
Marek Vasuta265e5e2018-08-16 14:37:03 +020012struct ofnode_phandle_args;
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +020013
14/**
15 * struct phy - A handle to (allowing control of) a single phy port.
16 *
17 * Clients provide storage for phy handles. The content of the structure is
18 * managed solely by the PHY API and PHY drivers. A phy struct is
19 * initialized by "get"ing the phy struct. The phy struct is passed to all
20 * other phy APIs to identify which PHY port to operate upon.
21 *
22 * @dev: The device which implements the PHY port.
23 * @id: The PHY ID within the provider.
24 *
25 */
26struct phy {
27 struct udevice *dev;
28 unsigned long id;
29};
30
31/*
32 * struct udevice_ops - set of function pointers for phy operations
33 * @init: operation to be performed for initializing phy (optional)
34 * @exit: operation to be performed while exiting (optional)
35 * @reset: reset the phy (optional).
36 * @power_on: powering on the phy (optional)
37 * @power_off: powering off the phy (optional)
38 */
39struct phy_ops {
40 /**
41 * of_xlate - Translate a client's device-tree (OF) phy specifier.
42 *
43 * The PHY core calls this function as the first step in implementing
44 * a client's generic_phy_get_by_*() call.
45 *
46 * If this function pointer is set to NULL, the PHY core will use a
47 * default implementation, which assumes #phy-cells = <0> or
48 * #phy-cells = <1>, and in the later case that the DT cell
49 * contains a simple integer PHY port ID.
50 *
51 * @phy: The phy struct to hold the translation result.
52 * @args: The phy specifier values from device tree.
53 * @return 0 if OK, or a negative error code.
54 */
Simon Glass23558bb2017-05-18 20:09:47 -060055 int (*of_xlate)(struct phy *phy, struct ofnode_phandle_args *args);
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +020056
57 /**
58 * init - initialize the hardware.
59 *
60 * Hardware intialization should not be done in during probe() but
61 * should be implemented in this init() function. It could be starting
62 * PLL, taking a controller out of reset, routing, etc. This function
63 * is typically called only once per PHY port.
64 * If power_on() is not implemented, it must power up the phy.
65 *
66 * @phy: the PHY port to initialize
67 * @return 0 if OK, or a negative error code.
68 */
69 int (*init)(struct phy *phy);
70
71 /**
72 * exit - de-initialize the PHY device
73 *
74 * Hardware de-intialization should be done here. Every step done in
75 * init() should be undone here.
76 * This could be used to suspend the phy to reduce power consumption or
77 * to put the phy in a known condition before booting the OS (though it
78 * is NOT called automatically before booting the OS)
79 * If power_off() is not implemented, it must power down the phy.
80 *
81 * @phy: PHY port to be de-initialized
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010082 * Return: 0 if OK, or a negative error code
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +020083 */
84 int (*exit)(struct phy *phy);
85
86 /**
87 * reset - resets a PHY device without shutting down
88 *
89 * @phy: PHY port to be reset
90 *
91 * During runtime, the PHY may need to be reset in order to
92 * re-establish connection etc without being shut down or exit.
93 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010094 * Return: 0 if OK, or a negative error code
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +020095 */
96 int (*reset)(struct phy *phy);
97
98 /**
99 * power_on - power on a PHY device
100 *
101 * @phy: PHY port to be powered on
102 *
103 * During runtime, the PHY may need to be powered on or off several
104 * times. This function is used to power on the PHY. It relies on the
105 * setup done in init(). If init() is not implemented, it must take care
106 * of setting up the context (PLLs, ...)
107 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100108 * Return: 0 if OK, or a negative error code
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200109 */
110 int (*power_on)(struct phy *phy);
111
112 /**
113 * power_off - power off a PHY device
114 *
115 * @phy: PHY port to be powered off
116 *
117 * During runtime, the PHY may need to be powered on or off several
118 * times. This function is used to power off the PHY. Except if
119 * init()/deinit() are not implemented, it must not de-initialize
120 * everything.
121 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100122 * Return: 0 if OK, or a negative error code
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200123 */
124 int (*power_off)(struct phy *phy);
Neil Armstrongf8da8a82020-12-29 14:58:59 +0100125
126 /**
127 * configure - configure a PHY device
128 *
129 * @phy: PHY port to be configured
130 * @params: PHY Parameters, underlying data is specific to the PHY function
131 *
132 * During runtime, the PHY may need to be configured for it's main function.
133 * This function configures the PHY for it's main function following
134 * power_on/off() after beeing initialized.
135 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100136 * Return: 0 if OK, or a negative error code
Neil Armstrongf8da8a82020-12-29 14:58:59 +0100137 */
138 int (*configure)(struct phy *phy, void *params);
he.hef888b8c2023-02-14 06:01:50 +0000139#ifdef CONFIG_AMLOGIC_USB
140 int (*getinfo)(struct phy *phy);
141#endif
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200142};
143
Chunfeng Yunb13307b2020-05-02 11:35:11 +0200144/**
145 * struct phy_bulk - A handle to (allowing control of) a bulk of phys.
146 *
147 * Consumers provide storage for the phy bulk. The content of the structure is
148 * managed solely by the phy API. A phy bulk struct is initialized
149 * by "get"ing the phy bulk struct.
150 * The phy bulk struct is passed to all other bulk phy APIs to apply
151 * the API to all the phy in the bulk struct.
152 *
153 * @phys: An array of phy handles.
154 * @count: The number of phy handles in the phys array.
155 */
156struct phy_bulk {
157 struct phy *phys;
158 unsigned int count;
159};
160
Michal Simeke81782a2022-03-09 10:05:44 +0100161#if CONFIG_IS_ENABLED(PHY)
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200162
163/**
164 * generic_phy_init() - initialize the PHY port
165 *
166 * @phy: the PHY port to initialize
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100167 * Return: 0 if OK, or a negative error code
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200168 */
169int generic_phy_init(struct phy *phy);
170
171/**
172 * generic_phy_init() - de-initialize the PHY device
173 *
174 * @phy: PHY port to be de-initialized
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100175 * Return: 0 if OK, or a negative error code
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200176 */
177int generic_phy_exit(struct phy *phy);
178
179/**
180 * generic_phy_reset() - resets a PHY device without shutting down
181 *
182 * @phy: PHY port to be reset
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100183 *Return: 0 if OK, or a negative error code
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200184 */
185int generic_phy_reset(struct phy *phy);
186
187/**
188 * generic_phy_power_on() - power on a PHY device
189 *
190 * @phy: PHY port to be powered on
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100191 * Return: 0 if OK, or a negative error code
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200192 */
193int generic_phy_power_on(struct phy *phy);
194
195/**
196 * generic_phy_power_off() - power off a PHY device
197 *
198 * @phy: PHY port to be powered off
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100199 * Return: 0 if OK, or a negative error code
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200200 */
201int generic_phy_power_off(struct phy *phy);
202
Neil Armstrongf8da8a82020-12-29 14:58:59 +0100203/**
204 * generic_phy_configure() - configure a PHY device
205 *
206 * @phy: PHY port to be configured
Wolfgang Denk0cf207e2021-09-27 17:42:39 +0200207 * @params: PHY Parameters, underlying data is specific to the PHY function
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100208 * Return: 0 if OK, or a negative error code
Neil Armstrongf8da8a82020-12-29 14:58:59 +0100209 */
210int generic_phy_configure(struct phy *phy, void *params);
211
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200212
213/**
214 * generic_phy_get_by_index() - Get a PHY device by integer index.
215 *
216 * @user: the client device
217 * @index: The index in the list of available PHYs
218 * @phy: A pointer to the PHY port
219 *
220 * This looks up a PHY device for a client device based on its position in the
221 * list of the possible PHYs.
222 *
223 * example:
224 * usb1: usb_otg_ss@xxx {
225 * compatible = "xxx";
226 * reg = <xxx>;
227 * .
228 * .
229 * phys = <&usb2_phy>, <&usb3_phy>;
230 * .
231 * .
232 * };
233 * the USB2 phy can be accessed by passing index '0' and the USB3 phy can
234 * be accessed by passing index '1'
235 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100236 * Return: 0 if OK, or a negative error code
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200237 */
238int generic_phy_get_by_index(struct udevice *user, int index,
239 struct phy *phy);
240
241/**
Jagan Teki5a2b6772020-05-01 23:44:18 +0530242 * generic_phy_get_by_index_nodev() - Get a PHY device by integer index
243 * without a device
Neil Armstrongc2b9aa92020-03-30 11:27:23 +0200244 *
Jagan Tekicd3e01b2020-05-01 23:44:17 +0530245 * @node: The client ofnode.
Neil Armstrongc2b9aa92020-03-30 11:27:23 +0200246 * @index: The index in the list of available PHYs
247 * @phy: A pointer to the PHY port
248 *
Jagan Teki5a2b6772020-05-01 23:44:18 +0530249 * This is a version of generic_phy_get_by_index() that does not use a device.
250 *
Neil Armstrongc2b9aa92020-03-30 11:27:23 +0200251 * This looks up a PHY device for a client device based on its ofnode and on
252 * its position in the list of the possible PHYs.
253 *
254 * example:
255 * usb1: usb_otg_ss@xxx {
256 * compatible = "xxx";
257 * reg = <xxx>;
258 * .
259 * .
260 * phys = <&usb2_phy>, <&usb3_phy>;
261 * .
262 * .
263 * };
264 * the USB2 phy can be accessed by passing index '0' and the USB3 phy can
265 * be accessed by passing index '1'
266 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100267 * Return: 0 if OK, or a negative error code
Neil Armstrongc2b9aa92020-03-30 11:27:23 +0200268 */
Jagan Teki5a2b6772020-05-01 23:44:18 +0530269int generic_phy_get_by_index_nodev(ofnode node, int index, struct phy *phy);
Neil Armstrongc2b9aa92020-03-30 11:27:23 +0200270
271/**
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200272 * generic_phy_get_by_name() - Get a PHY device by its name.
273 *
274 * @user: the client device
275 * @phy_name: The name of the PHY in the list of possible PHYs
276 * @phy: A pointer to the PHY port
277 *
278 * This looks up a PHY device for a client device in the
279 * list of the possible PHYs based on its name.
280 *
281 * example:
282 * usb1: usb_otg_ss@xxx {
283 * compatible = "xxx";
284 * reg = <xxx>;
285 * .
286 * .
287 * phys = <&usb2_phy>, <&usb3_phy>;
288 * phy-names = "usb2phy", "usb3phy";
289 * .
290 * .
291 * };
292 * the USB3 phy can be accessed using "usb3phy", and USB2 by using "usb2phy"
293 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100294 * Return: 0 if OK, or a negative error code
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200295 */
296int generic_phy_get_by_name(struct udevice *user, const char *phy_name,
297 struct phy *phy);
298
Chunfeng Yunb13307b2020-05-02 11:35:11 +0200299/**
300 * generic_phy_get_bulk - Get all phys of a device.
301 *
302 * This looks up and gets all phys of the consumer device; each device is
303 * assumed to have n phys associated with it somehow, and this function finds
304 * and gets all of them in a separate structure.
305 *
306 * @dev: The consumer device.
307 * @bulk A pointer to a phy bulk struct to initialize.
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100308 * Return: 0 if OK, or a negative error code.
Chunfeng Yunb13307b2020-05-02 11:35:11 +0200309 */
310int generic_phy_get_bulk(struct udevice *dev, struct phy_bulk *bulk);
311
312/**
313 * generic_phy_init_bulk() - Initialize all phys in a phy bulk struct.
314 *
315 * @bulk: A phy bulk struct that was previously successfully requested
316 * by generic_phy_get_bulk().
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100317 * Return: 0 if OK, or negative error code.
Chunfeng Yunb13307b2020-05-02 11:35:11 +0200318 */
319int generic_phy_init_bulk(struct phy_bulk *bulk);
320
321/**
322 * generic_phy_exit_bulk() - de-initialize all phys in a phy bulk struct.
323 *
324 * @bulk: A phy bulk struct that was previously successfully requested
325 * by generic_phy_get_bulk().
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100326 * Return: 0 if OK, or negative error code.
Chunfeng Yunb13307b2020-05-02 11:35:11 +0200327 */
328int generic_phy_exit_bulk(struct phy_bulk *bulk);
329
330/**
331 * generic_phy_power_on_bulk() - Power on all phys in a phy bulk struct.
332 *
333 * @bulk: A phy bulk struct that was previously successfully requested
334 * by generic_phy_get_bulk().
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100335 * Return: 0 if OK, or negative error code.
Chunfeng Yunb13307b2020-05-02 11:35:11 +0200336 */
337int generic_phy_power_on_bulk(struct phy_bulk *bulk);
338
339/**
340 * generic_phy_power_off_bulk() - Power off all phys in a phy bulk struct.
341 *
342 * @bulk: A phy bulk struct that was previously successfully requested
343 * by generic_phy_get_bulk().
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100344 * Return: 0 if OK, or negative error code.
Chunfeng Yunb13307b2020-05-02 11:35:11 +0200345 */
346int generic_phy_power_off_bulk(struct phy_bulk *bulk);
347
Patrice Chotard84e56142022-09-06 08:15:26 +0200348/**
349 * generic_setup_phy() - Get, initialize and power on phy.
350 *
351 * @dev: The consumer device.
352 * @phy: A pointer to the PHY port
353 * @index: The index in the list of available PHYs
354 *
355 * Return: 0 if OK, or negative error code.
356 */
357int generic_setup_phy(struct udevice *dev, struct phy *phy, int index);
358
359/**
360 * generic_shutdown_phy() - Power off and de-initialize phy.
361 *
362 * @phy: A pointer to the PHY port.
363 *
364 * Return: 0 if OK, or negative error code.
365 */
366int generic_shutdown_phy(struct phy *phy);
he.hef888b8c2023-02-14 06:01:50 +0000367#ifdef CONFIG_AMLOGIC_USB
368int generic_phy_getinfo(struct phy *phy);
369#endif
Patrice Chotardd9fb7be2017-07-24 17:07:02 +0200370#else /* CONFIG_PHY */
371
372static inline int generic_phy_init(struct phy *phy)
373{
374 return 0;
375}
376
377static inline int generic_phy_exit(struct phy *phy)
378{
379 return 0;
380}
381
382static inline int generic_phy_reset(struct phy *phy)
383{
384 return 0;
385}
386
387static inline int generic_phy_power_on(struct phy *phy)
388{
389 return 0;
390}
391
392static inline int generic_phy_power_off(struct phy *phy)
393{
394 return 0;
395}
396
397static inline int generic_phy_get_by_index(struct udevice *user, int index,
398 struct phy *phy)
399{
400 return 0;
401}
402
403static inline int generic_phy_get_by_name(struct udevice *user, const char *phy_name,
404 struct phy *phy)
405{
406 return 0;
407}
408
Chunfeng Yunb13307b2020-05-02 11:35:11 +0200409static inline int
410generic_phy_get_bulk(struct udevice *dev, struct phy_bulk *bulk)
411{
412 return 0;
413}
414
415static inline int generic_phy_init_bulk(struct phy_bulk *bulk)
416{
417 return 0;
418}
419
420static inline int generic_phy_exit_bulk(struct phy_bulk *bulk)
421{
422 return 0;
423}
424
425static inline int generic_phy_power_on_bulk(struct phy_bulk *bulk)
426{
427 return 0;
428}
429
430static inline int generic_phy_power_off_bulk(struct phy_bulk *bulk)
431{
432 return 0;
433}
434
Patrice Chotard84e56142022-09-06 08:15:26 +0200435static inline int generic_setup_phy(struct udevice *dev, struct phy *phy, int index)
436{
437 return 0;
438}
439
440static inline int generic_shutdown_phy(struct phy *phy)
441{
442 return 0;
443}
444
Patrice Chotardd9fb7be2017-07-24 17:07:02 +0200445#endif /* CONFIG_PHY */
446
Patrice Chotardb94888b2017-07-18 11:38:43 +0200447/**
448 * generic_phy_valid() - check if PHY port is valid
449 *
450 * @phy: the PHY port to check
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100451 * Return: TRUE if valid, or FALSE
Patrice Chotardb94888b2017-07-18 11:38:43 +0200452 */
453static inline bool generic_phy_valid(struct phy *phy)
454{
Jean-Jacques Hiblot4e184292019-10-01 14:03:26 +0200455 return phy && phy->dev;
Patrice Chotardb94888b2017-07-18 11:38:43 +0200456}
457
Jean-Jacques Hiblot72e50162017-04-24 11:51:27 +0200458#endif /*__GENERIC_PHY_H */