1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
4 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
7 #ifndef __GENERIC_PHY_H
8 #define __GENERIC_PHY_H
10 #include <dm/ofnode.h>
12 struct ofnode_phandle_args
;
22 PHY_MODE_USB_DEVICE_LS
,
23 PHY_MODE_USB_DEVICE_FS
,
24 PHY_MODE_USB_DEVICE_HS
,
25 PHY_MODE_USB_DEVICE_SS
,
38 * struct phy - A handle to (allowing control of) a single phy port.
40 * Clients provide storage for phy handles. The content of the structure is
41 * managed solely by the PHY API and PHY drivers. A phy struct is
42 * initialized by "get"ing the phy struct. The phy struct is passed to all
43 * other phy APIs to identify which PHY port to operate upon.
45 * @dev: The device which implements the PHY port.
46 * @id: The PHY ID within the provider.
55 * struct udevice_ops - set of function pointers for phy operations
56 * @init: operation to be performed for initializing phy (optional)
57 * @exit: operation to be performed while exiting (optional)
58 * @reset: reset the phy (optional).
59 * @power_on: powering on the phy (optional)
60 * @power_off: powering off the phy (optional)
64 * of_xlate - Translate a client's device-tree (OF) phy specifier.
66 * The PHY core calls this function as the first step in implementing
67 * a client's generic_phy_get_by_*() call.
69 * If this function pointer is set to NULL, the PHY core will use a
70 * default implementation, which assumes #phy-cells = <0> or
71 * #phy-cells = <1>, and in the later case that the DT cell
72 * contains a simple integer PHY port ID.
74 * @phy: The phy struct to hold the translation result.
75 * @args: The phy specifier values from device tree.
76 * @return 0 if OK, or a negative error code.
78 int (*of_xlate
)(struct phy
*phy
, struct ofnode_phandle_args
*args
);
81 * init - initialize the hardware.
83 * Hardware intialization should not be done in during probe() but
84 * should be implemented in this init() function. It could be starting
85 * PLL, taking a controller out of reset, routing, etc. This function
86 * is typically called only once per PHY port.
87 * If power_on() is not implemented, it must power up the phy.
89 * @phy: the PHY port to initialize
90 * @return 0 if OK, or a negative error code.
92 int (*init
)(struct phy
*phy
);
95 * exit - de-initialize the PHY device
97 * Hardware de-intialization should be done here. Every step done in
98 * init() should be undone here.
99 * This could be used to suspend the phy to reduce power consumption or
100 * to put the phy in a known condition before booting the OS (though it
101 * is NOT called automatically before booting the OS)
102 * If power_off() is not implemented, it must power down the phy.
104 * @phy: PHY port to be de-initialized
105 * Return: 0 if OK, or a negative error code
107 int (*exit
)(struct phy
*phy
);
110 * reset - resets a PHY device without shutting down
112 * @phy: PHY port to be reset
114 * During runtime, the PHY may need to be reset in order to
115 * re-establish connection etc without being shut down or exit.
117 * Return: 0 if OK, or a negative error code
119 int (*reset
)(struct phy
*phy
);
122 * power_on - power on a PHY device
124 * @phy: PHY port to be powered on
126 * During runtime, the PHY may need to be powered on or off several
127 * times. This function is used to power on the PHY. It relies on the
128 * setup done in init(). If init() is not implemented, it must take care
129 * of setting up the context (PLLs, ...)
131 * Return: 0 if OK, or a negative error code
133 int (*power_on
)(struct phy
*phy
);
136 * power_off - power off a PHY device
138 * @phy: PHY port to be powered off
140 * During runtime, the PHY may need to be powered on or off several
141 * times. This function is used to power off the PHY. Except if
142 * init()/deinit() are not implemented, it must not de-initialize
145 * Return: 0 if OK, or a negative error code
147 int (*power_off
)(struct phy
*phy
);
150 * configure - configure a PHY device
152 * @phy: PHY port to be configured
153 * @params: PHY Parameters, underlying data is specific to the PHY function
155 * During runtime, the PHY may need to be configured for it's main function.
156 * This function configures the PHY for it's main function following
157 * power_on/off() after being initialized.
159 * Return: 0 if OK, or a negative error code
161 int (*configure
)(struct phy
*phy
, void *params
);
164 * set_mode - set PHY device mode
166 * @phy: PHY port to be configured
168 * @submode: PHY submode
170 * Configure PHY mode (e.g. USB, Ethernet, ...) and submode
171 * (e.g. for Ethernet this can be RGMII).
173 * Return: 0 if OK, or a negative error code
175 int (*set_mode
)(struct phy
*phy
, enum phy_mode mode
, int submode
);
178 * set_speed - set PHY device speed
180 * @phy: PHY port to be configured
183 * Configure PHY speed (e.g. for Ethernet, this could be 10 or 100 ...).
185 * Return: 0 if OK, or a negative error code
187 int (*set_speed
)(struct phy
*phy
, int speed
);
191 * struct phy_bulk - A handle to (allowing control of) a bulk of phys.
193 * Consumers provide storage for the phy bulk. The content of the structure is
194 * managed solely by the phy API. A phy bulk struct is initialized
195 * by "get"ing the phy bulk struct.
196 * The phy bulk struct is passed to all other bulk phy APIs to apply
197 * the API to all the phy in the bulk struct.
199 * @phys: An array of phy handles.
200 * @count: The number of phy handles in the phys array.
207 #if CONFIG_IS_ENABLED(PHY)
210 * generic_phy_init() - initialize the PHY port
212 * @phy: the PHY port to initialize
213 * Return: 0 if OK, or a negative error code
215 int generic_phy_init(struct phy
*phy
);
218 * generic_phy_init() - de-initialize the PHY device
220 * @phy: PHY port to be de-initialized
221 * Return: 0 if OK, or a negative error code
223 int generic_phy_exit(struct phy
*phy
);
226 * generic_phy_reset() - resets a PHY device without shutting down
228 * @phy: PHY port to be reset
229 *Return: 0 if OK, or a negative error code
231 int generic_phy_reset(struct phy
*phy
);
234 * generic_phy_power_on() - power on a PHY device
236 * @phy: PHY port to be powered on
237 * Return: 0 if OK, or a negative error code
239 int generic_phy_power_on(struct phy
*phy
);
242 * generic_phy_power_off() - power off a PHY device
244 * @phy: PHY port to be powered off
245 * Return: 0 if OK, or a negative error code
247 int generic_phy_power_off(struct phy
*phy
);
250 * generic_phy_configure() - configure a PHY device
252 * @phy: PHY port to be configured
253 * @params: PHY Parameters, underlying data is specific to the PHY function
254 * Return: 0 if OK, or a negative error code
256 int generic_phy_configure(struct phy
*phy
, void *params
);
259 * generic_phy_set_mode() - set PHY device mode
261 * @phy: PHY port to be configured
263 * @submode: PHY submode
264 * Return: 0 if OK, or a negative error code
266 int generic_phy_set_mode(struct phy
*phy
, enum phy_mode mode
, int submode
);
269 * generic_phy_set_speed() - set PHY device speed
271 * @phy: PHY port to be configured
273 * Return: 0 if OK, or a negative error code
275 int generic_phy_set_speed(struct phy
*phy
, int speed
);
278 * generic_phy_get_by_index() - Get a PHY device by integer index.
280 * @user: the client device
281 * @index: The index in the list of available PHYs
282 * @phy: A pointer to the PHY port
284 * This looks up a PHY device for a client device based on its position in the
285 * list of the possible PHYs.
288 * usb1: usb_otg_ss@xxx {
289 * compatible = "xxx";
293 * phys = <&usb2_phy>, <&usb3_phy>;
297 * the USB2 phy can be accessed by passing index '0' and the USB3 phy can
298 * be accessed by passing index '1'
300 * Return: 0 if OK, or a negative error code
302 int generic_phy_get_by_index(struct udevice
*user
, int index
,
306 * generic_phy_get_by_index_nodev() - Get a PHY device by integer index
309 * @node: The client ofnode.
310 * @index: The index in the list of available PHYs
311 * @phy: A pointer to the PHY port
313 * This is a version of generic_phy_get_by_index() that does not use a device.
315 * This looks up a PHY device for a client device based on its ofnode and on
316 * its position in the list of the possible PHYs.
319 * usb1: usb_otg_ss@xxx {
320 * compatible = "xxx";
324 * phys = <&usb2_phy>, <&usb3_phy>;
328 * the USB2 phy can be accessed by passing index '0' and the USB3 phy can
329 * be accessed by passing index '1'
331 * Return: 0 if OK, or a negative error code
333 int generic_phy_get_by_index_nodev(ofnode node
, int index
, struct phy
*phy
);
336 * generic_phy_get_by_name() - Get a PHY device by its name.
338 * @user: the client device
339 * @phy_name: The name of the PHY in the list of possible PHYs
340 * @phy: A pointer to the PHY port
342 * This looks up a PHY device for a client device in the
343 * list of the possible PHYs based on its name.
346 * usb1: usb_otg_ss@xxx {
347 * compatible = "xxx";
351 * phys = <&usb2_phy>, <&usb3_phy>;
352 * phy-names = "usb2phy", "usb3phy";
356 * the USB3 phy can be accessed using "usb3phy", and USB2 by using "usb2phy"
358 * Return: 0 if OK, or a negative error code
360 int generic_phy_get_by_name(struct udevice
*user
, const char *phy_name
,
364 * generic_phy_get_bulk - Get all phys of a device.
366 * This looks up and gets all phys of the consumer device; each device is
367 * assumed to have n phys associated with it somehow, and this function finds
368 * and gets all of them in a separate structure.
370 * @dev: The consumer device.
371 * @bulk A pointer to a phy bulk struct to initialize.
372 * Return: 0 if OK, or a negative error code.
374 int generic_phy_get_bulk(struct udevice
*dev
, struct phy_bulk
*bulk
);
377 * generic_phy_init_bulk() - Initialize all phys in a phy bulk struct.
379 * @bulk: A phy bulk struct that was previously successfully requested
380 * by generic_phy_get_bulk().
381 * Return: 0 if OK, or negative error code.
383 int generic_phy_init_bulk(struct phy_bulk
*bulk
);
386 * generic_phy_exit_bulk() - de-initialize all phys in a phy bulk struct.
388 * @bulk: A phy bulk struct that was previously successfully requested
389 * by generic_phy_get_bulk().
390 * Return: 0 if OK, or negative error code.
392 int generic_phy_exit_bulk(struct phy_bulk
*bulk
);
395 * generic_phy_power_on_bulk() - Power on all phys in a phy bulk struct.
397 * @bulk: A phy bulk struct that was previously successfully requested
398 * by generic_phy_get_bulk().
399 * Return: 0 if OK, or negative error code.
401 int generic_phy_power_on_bulk(struct phy_bulk
*bulk
);
404 * generic_phy_power_off_bulk() - Power off all phys in a phy bulk struct.
406 * @bulk: A phy bulk struct that was previously successfully requested
407 * by generic_phy_get_bulk().
408 * Return: 0 if OK, or negative error code.
410 int generic_phy_power_off_bulk(struct phy_bulk
*bulk
);
413 * generic_setup_phy() - Get, initialize and power on phy.
415 * @dev: The consumer device.
416 * @phy: A pointer to the PHY port
417 * @index: The index in the list of available PHYs
419 * @submode: PHY submode
421 * Return: 0 if OK, or negative error code.
423 int generic_setup_phy(struct udevice
*dev
, struct phy
*phy
, int index
,
424 enum phy_mode mode
, int submode
);
427 * generic_shutdown_phy() - Power off and de-initialize phy.
429 * @phy: A pointer to the PHY port.
431 * Return: 0 if OK, or negative error code.
433 int generic_shutdown_phy(struct phy
*phy
);
435 #else /* CONFIG_PHY */
437 static inline int generic_phy_init(struct phy
*phy
)
442 static inline int generic_phy_exit(struct phy
*phy
)
447 static inline int generic_phy_reset(struct phy
*phy
)
452 static inline int generic_phy_power_on(struct phy
*phy
)
457 static inline int generic_phy_power_off(struct phy
*phy
)
462 static inline int generic_phy_configure(struct phy
*phy
, void *params
)
467 static inline int generic_phy_set_mode(struct phy
*phy
, enum phy_mode mode
, int submode
)
472 static inline int generic_phy_set_speed(struct phy
*phy
, int speed
)
477 static inline int generic_phy_get_by_index(struct udevice
*user
, int index
,
483 static inline int generic_phy_get_by_name(struct udevice
*user
, const char *phy_name
,
490 generic_phy_get_bulk(struct udevice
*dev
, struct phy_bulk
*bulk
)
495 static inline int generic_phy_init_bulk(struct phy_bulk
*bulk
)
500 static inline int generic_phy_exit_bulk(struct phy_bulk
*bulk
)
505 static inline int generic_phy_power_on_bulk(struct phy_bulk
*bulk
)
510 static inline int generic_phy_power_off_bulk(struct phy_bulk
*bulk
)
515 static inline int generic_setup_phy(struct udevice
*dev
, struct phy
*phy
, int index
,
516 enum phy_mode mode
, int submode
)
521 static inline int generic_shutdown_phy(struct phy
*phy
)
526 #endif /* CONFIG_PHY */
529 * generic_phy_valid() - check if PHY port is valid
531 * @phy: the PHY port to check
532 * Return: TRUE if valid, or FALSE
534 static inline bool generic_phy_valid(struct phy
*phy
)
536 return phy
&& phy
->dev
;
539 #endif /*__GENERIC_PHY_H */