172e5016fSJean-Jacques Hiblot /* 272e5016fSJean-Jacques Hiblot * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/ 372e5016fSJean-Jacques Hiblot * Written by Jean-Jacques Hiblot <jjhiblot@ti.com> 472e5016fSJean-Jacques Hiblot * 572e5016fSJean-Jacques Hiblot * SPDX-License-Identifier: GPL-2.0+ 672e5016fSJean-Jacques Hiblot */ 772e5016fSJean-Jacques Hiblot 872e5016fSJean-Jacques Hiblot #ifndef __GENERIC_PHY_H 972e5016fSJean-Jacques Hiblot #define __GENERIC_PHY_H 1072e5016fSJean-Jacques Hiblot 11*4ef09685SWyon Bi enum phy_mode { 12*4ef09685SWyon Bi PHY_MODE_INVALID, 13*4ef09685SWyon Bi }; 14*4ef09685SWyon Bi 15*4ef09685SWyon Bi /** 16*4ef09685SWyon Bi * union phy_configure_opts - Opaque generic phy configuration 17*4ef09685SWyon Bi */ 18*4ef09685SWyon Bi union phy_configure_opts { 19*4ef09685SWyon Bi }; 2072e5016fSJean-Jacques Hiblot 2172e5016fSJean-Jacques Hiblot /** 2272e5016fSJean-Jacques Hiblot * struct phy - A handle to (allowing control of) a single phy port. 2372e5016fSJean-Jacques Hiblot * 2472e5016fSJean-Jacques Hiblot * Clients provide storage for phy handles. The content of the structure is 2572e5016fSJean-Jacques Hiblot * managed solely by the PHY API and PHY drivers. A phy struct is 2672e5016fSJean-Jacques Hiblot * initialized by "get"ing the phy struct. The phy struct is passed to all 2772e5016fSJean-Jacques Hiblot * other phy APIs to identify which PHY port to operate upon. 2872e5016fSJean-Jacques Hiblot * 2972e5016fSJean-Jacques Hiblot * @dev: The device which implements the PHY port. 3072e5016fSJean-Jacques Hiblot * @id: The PHY ID within the provider. 3172e5016fSJean-Jacques Hiblot * 3272e5016fSJean-Jacques Hiblot */ 3372e5016fSJean-Jacques Hiblot struct phy { 3472e5016fSJean-Jacques Hiblot struct udevice *dev; 3572e5016fSJean-Jacques Hiblot unsigned long id; 3672e5016fSJean-Jacques Hiblot }; 3772e5016fSJean-Jacques Hiblot 3872e5016fSJean-Jacques Hiblot /* 3972e5016fSJean-Jacques Hiblot * struct udevice_ops - set of function pointers for phy operations 4072e5016fSJean-Jacques Hiblot * @init: operation to be performed for initializing phy (optional) 4172e5016fSJean-Jacques Hiblot * @exit: operation to be performed while exiting (optional) 4272e5016fSJean-Jacques Hiblot * @reset: reset the phy (optional). 4372e5016fSJean-Jacques Hiblot * @power_on: powering on the phy (optional) 4472e5016fSJean-Jacques Hiblot * @power_off: powering off the phy (optional) 4572e5016fSJean-Jacques Hiblot */ 4672e5016fSJean-Jacques Hiblot struct phy_ops { 4772e5016fSJean-Jacques Hiblot /** 4872e5016fSJean-Jacques Hiblot * of_xlate - Translate a client's device-tree (OF) phy specifier. 4972e5016fSJean-Jacques Hiblot * 5072e5016fSJean-Jacques Hiblot * The PHY core calls this function as the first step in implementing 5172e5016fSJean-Jacques Hiblot * a client's generic_phy_get_by_*() call. 5272e5016fSJean-Jacques Hiblot * 5372e5016fSJean-Jacques Hiblot * If this function pointer is set to NULL, the PHY core will use a 5472e5016fSJean-Jacques Hiblot * default implementation, which assumes #phy-cells = <0> or 5572e5016fSJean-Jacques Hiblot * #phy-cells = <1>, and in the later case that the DT cell 5672e5016fSJean-Jacques Hiblot * contains a simple integer PHY port ID. 5772e5016fSJean-Jacques Hiblot * 5872e5016fSJean-Jacques Hiblot * @phy: The phy struct to hold the translation result. 5972e5016fSJean-Jacques Hiblot * @args: The phy specifier values from device tree. 6072e5016fSJean-Jacques Hiblot * @return 0 if OK, or a negative error code. 6172e5016fSJean-Jacques Hiblot */ 6223558bb6SSimon Glass int (*of_xlate)(struct phy *phy, struct ofnode_phandle_args *args); 6372e5016fSJean-Jacques Hiblot 6472e5016fSJean-Jacques Hiblot /** 6572e5016fSJean-Jacques Hiblot * init - initialize the hardware. 6672e5016fSJean-Jacques Hiblot * 6772e5016fSJean-Jacques Hiblot * Hardware intialization should not be done in during probe() but 6872e5016fSJean-Jacques Hiblot * should be implemented in this init() function. It could be starting 6972e5016fSJean-Jacques Hiblot * PLL, taking a controller out of reset, routing, etc. This function 7072e5016fSJean-Jacques Hiblot * is typically called only once per PHY port. 7172e5016fSJean-Jacques Hiblot * If power_on() is not implemented, it must power up the phy. 7272e5016fSJean-Jacques Hiblot * 7372e5016fSJean-Jacques Hiblot * @phy: the PHY port to initialize 7472e5016fSJean-Jacques Hiblot * @return 0 if OK, or a negative error code. 7572e5016fSJean-Jacques Hiblot */ 7672e5016fSJean-Jacques Hiblot int (*init)(struct phy *phy); 7772e5016fSJean-Jacques Hiblot 7872e5016fSJean-Jacques Hiblot /** 7972e5016fSJean-Jacques Hiblot * exit - de-initialize the PHY device 8072e5016fSJean-Jacques Hiblot * 8172e5016fSJean-Jacques Hiblot * Hardware de-intialization should be done here. Every step done in 8272e5016fSJean-Jacques Hiblot * init() should be undone here. 8372e5016fSJean-Jacques Hiblot * This could be used to suspend the phy to reduce power consumption or 8472e5016fSJean-Jacques Hiblot * to put the phy in a known condition before booting the OS (though it 8572e5016fSJean-Jacques Hiblot * is NOT called automatically before booting the OS) 8672e5016fSJean-Jacques Hiblot * If power_off() is not implemented, it must power down the phy. 8772e5016fSJean-Jacques Hiblot * 8872e5016fSJean-Jacques Hiblot * @phy: PHY port to be de-initialized 8972e5016fSJean-Jacques Hiblot * @return 0 if OK, or a negative error code 9072e5016fSJean-Jacques Hiblot */ 9172e5016fSJean-Jacques Hiblot int (*exit)(struct phy *phy); 9272e5016fSJean-Jacques Hiblot 9372e5016fSJean-Jacques Hiblot /** 9472e5016fSJean-Jacques Hiblot * reset - resets a PHY device without shutting down 9572e5016fSJean-Jacques Hiblot * 9672e5016fSJean-Jacques Hiblot * @phy: PHY port to be reset 9772e5016fSJean-Jacques Hiblot * 9872e5016fSJean-Jacques Hiblot * During runtime, the PHY may need to be reset in order to 9972e5016fSJean-Jacques Hiblot * re-establish connection etc without being shut down or exit. 10072e5016fSJean-Jacques Hiblot * 10172e5016fSJean-Jacques Hiblot * @return 0 if OK, or a negative error code 10272e5016fSJean-Jacques Hiblot */ 10372e5016fSJean-Jacques Hiblot int (*reset)(struct phy *phy); 10472e5016fSJean-Jacques Hiblot 10572e5016fSJean-Jacques Hiblot /** 106*4ef09685SWyon Bi * @configure: 107*4ef09685SWyon Bi * 108*4ef09685SWyon Bi * Optional. 109*4ef09685SWyon Bi * 110*4ef09685SWyon Bi * Used to change the PHY parameters. phy_init() must have 111*4ef09685SWyon Bi * been called on the phy. 112*4ef09685SWyon Bi * 113*4ef09685SWyon Bi * Returns: 0 if successful, an negative error code otherwise 114*4ef09685SWyon Bi */ 115*4ef09685SWyon Bi int (*configure)(struct phy *phy, union phy_configure_opts *opts); 116*4ef09685SWyon Bi 117*4ef09685SWyon Bi /** 118*4ef09685SWyon Bi * @validate: 119*4ef09685SWyon Bi * 120*4ef09685SWyon Bi * Optional. 121*4ef09685SWyon Bi * 122*4ef09685SWyon Bi * Used to check that the current set of parameters can be 123*4ef09685SWyon Bi * handled by the phy. Implementations are free to tune the 124*4ef09685SWyon Bi * parameters passed as arguments if needed by some 125*4ef09685SWyon Bi * implementation detail or constraints. It must not change 126*4ef09685SWyon Bi * any actual configuration of the PHY, so calling it as many 127*4ef09685SWyon Bi * times as deemed fit by the consumer must have no side 128*4ef09685SWyon Bi * effect. 129*4ef09685SWyon Bi * 130*4ef09685SWyon Bi * Returns: 0 if the configuration can be applied, an negative 131*4ef09685SWyon Bi * error code otherwise 132*4ef09685SWyon Bi */ 133*4ef09685SWyon Bi int (*validate)(struct phy *phy, enum phy_mode mode, int submode, 134*4ef09685SWyon Bi union phy_configure_opts *opts); 135*4ef09685SWyon Bi 136*4ef09685SWyon Bi /** 13772e5016fSJean-Jacques Hiblot * power_on - power on a PHY device 13872e5016fSJean-Jacques Hiblot * 13972e5016fSJean-Jacques Hiblot * @phy: PHY port to be powered on 14072e5016fSJean-Jacques Hiblot * 14172e5016fSJean-Jacques Hiblot * During runtime, the PHY may need to be powered on or off several 14272e5016fSJean-Jacques Hiblot * times. This function is used to power on the PHY. It relies on the 14372e5016fSJean-Jacques Hiblot * setup done in init(). If init() is not implemented, it must take care 14472e5016fSJean-Jacques Hiblot * of setting up the context (PLLs, ...) 14572e5016fSJean-Jacques Hiblot * 14672e5016fSJean-Jacques Hiblot * @return 0 if OK, or a negative error code 14772e5016fSJean-Jacques Hiblot */ 14872e5016fSJean-Jacques Hiblot int (*power_on)(struct phy *phy); 14972e5016fSJean-Jacques Hiblot 15072e5016fSJean-Jacques Hiblot /** 15172e5016fSJean-Jacques Hiblot * power_off - power off a PHY device 15272e5016fSJean-Jacques Hiblot * 15372e5016fSJean-Jacques Hiblot * @phy: PHY port to be powered off 15472e5016fSJean-Jacques Hiblot * 15572e5016fSJean-Jacques Hiblot * During runtime, the PHY may need to be powered on or off several 15672e5016fSJean-Jacques Hiblot * times. This function is used to power off the PHY. Except if 15772e5016fSJean-Jacques Hiblot * init()/deinit() are not implemented, it must not de-initialize 15872e5016fSJean-Jacques Hiblot * everything. 15972e5016fSJean-Jacques Hiblot * 16072e5016fSJean-Jacques Hiblot * @return 0 if OK, or a negative error code 16172e5016fSJean-Jacques Hiblot */ 16272e5016fSJean-Jacques Hiblot int (*power_off)(struct phy *phy); 16372e5016fSJean-Jacques Hiblot }; 16472e5016fSJean-Jacques Hiblot 165d9fb7becSPatrice Chotard #ifdef CONFIG_PHY 16672e5016fSJean-Jacques Hiblot 16772e5016fSJean-Jacques Hiblot /** 16872e5016fSJean-Jacques Hiblot * generic_phy_init() - initialize the PHY port 16972e5016fSJean-Jacques Hiblot * 17072e5016fSJean-Jacques Hiblot * @phy: the PHY port to initialize 17172e5016fSJean-Jacques Hiblot * @return 0 if OK, or a negative error code 17272e5016fSJean-Jacques Hiblot */ 17372e5016fSJean-Jacques Hiblot int generic_phy_init(struct phy *phy); 17472e5016fSJean-Jacques Hiblot 17572e5016fSJean-Jacques Hiblot /** 17672e5016fSJean-Jacques Hiblot * generic_phy_init() - de-initialize the PHY device 17772e5016fSJean-Jacques Hiblot * 17872e5016fSJean-Jacques Hiblot * @phy: PHY port to be de-initialized 17972e5016fSJean-Jacques Hiblot * @return 0 if OK, or a negative error code 18072e5016fSJean-Jacques Hiblot */ 18172e5016fSJean-Jacques Hiblot int generic_phy_exit(struct phy *phy); 18272e5016fSJean-Jacques Hiblot 18372e5016fSJean-Jacques Hiblot /** 18472e5016fSJean-Jacques Hiblot * generic_phy_reset() - resets a PHY device without shutting down 18572e5016fSJean-Jacques Hiblot * 18672e5016fSJean-Jacques Hiblot * @phy: PHY port to be reset 18772e5016fSJean-Jacques Hiblot *@return 0 if OK, or a negative error code 18872e5016fSJean-Jacques Hiblot */ 18972e5016fSJean-Jacques Hiblot int generic_phy_reset(struct phy *phy); 19072e5016fSJean-Jacques Hiblot 19172e5016fSJean-Jacques Hiblot /** 192*4ef09685SWyon Bi * generic_phy_configure() - change the PHY parameters 193*4ef09685SWyon Bi * 194*4ef09685SWyon Bi * @phy: PHY port to be configure 195*4ef09685SWyon Bi * @return 0 if OK, or a negative error code 196*4ef09685SWyon Bi */ 197*4ef09685SWyon Bi int generic_phy_configure(struct phy *phy, union phy_configure_opts *opts); 198*4ef09685SWyon Bi 199*4ef09685SWyon Bi /** 200*4ef09685SWyon Bi * generic_phy_validate() - validate the PHY parameters 201*4ef09685SWyon Bi * 202*4ef09685SWyon Bi * @phy: PHY port to be validate 203*4ef09685SWyon Bi * @return 0 if OK, or a negative error code 204*4ef09685SWyon Bi */ 205*4ef09685SWyon Bi int generic_phy_validate(struct phy *phy, enum phy_mode mode, int submode, 206*4ef09685SWyon Bi union phy_configure_opts *opts); 207*4ef09685SWyon Bi 208*4ef09685SWyon Bi /** 20972e5016fSJean-Jacques Hiblot * generic_phy_power_on() - power on a PHY device 21072e5016fSJean-Jacques Hiblot * 21172e5016fSJean-Jacques Hiblot * @phy: PHY port to be powered on 21272e5016fSJean-Jacques Hiblot * @return 0 if OK, or a negative error code 21372e5016fSJean-Jacques Hiblot */ 21472e5016fSJean-Jacques Hiblot int generic_phy_power_on(struct phy *phy); 21572e5016fSJean-Jacques Hiblot 21672e5016fSJean-Jacques Hiblot /** 21772e5016fSJean-Jacques Hiblot * generic_phy_power_off() - power off a PHY device 21872e5016fSJean-Jacques Hiblot * 21972e5016fSJean-Jacques Hiblot * @phy: PHY port to be powered off 22072e5016fSJean-Jacques Hiblot * @return 0 if OK, or a negative error code 22172e5016fSJean-Jacques Hiblot */ 22272e5016fSJean-Jacques Hiblot int generic_phy_power_off(struct phy *phy); 22372e5016fSJean-Jacques Hiblot 22472e5016fSJean-Jacques Hiblot 22572e5016fSJean-Jacques Hiblot /** 22672e5016fSJean-Jacques Hiblot * generic_phy_get_by_index() - Get a PHY device by integer index. 22772e5016fSJean-Jacques Hiblot * 22872e5016fSJean-Jacques Hiblot * @user: the client device 22972e5016fSJean-Jacques Hiblot * @index: The index in the list of available PHYs 23072e5016fSJean-Jacques Hiblot * @phy: A pointer to the PHY port 23172e5016fSJean-Jacques Hiblot * 23272e5016fSJean-Jacques Hiblot * This looks up a PHY device for a client device based on its position in the 23372e5016fSJean-Jacques Hiblot * list of the possible PHYs. 23472e5016fSJean-Jacques Hiblot * 23572e5016fSJean-Jacques Hiblot * example: 23672e5016fSJean-Jacques Hiblot * usb1: usb_otg_ss@xxx { 23772e5016fSJean-Jacques Hiblot * compatible = "xxx"; 23872e5016fSJean-Jacques Hiblot * reg = <xxx>; 23972e5016fSJean-Jacques Hiblot * . 24072e5016fSJean-Jacques Hiblot * . 24172e5016fSJean-Jacques Hiblot * phys = <&usb2_phy>, <&usb3_phy>; 24272e5016fSJean-Jacques Hiblot * . 24372e5016fSJean-Jacques Hiblot * . 24472e5016fSJean-Jacques Hiblot * }; 24572e5016fSJean-Jacques Hiblot * the USB2 phy can be accessed by passing index '0' and the USB3 phy can 24672e5016fSJean-Jacques Hiblot * be accessed by passing index '1' 24772e5016fSJean-Jacques Hiblot * 24872e5016fSJean-Jacques Hiblot * @return 0 if OK, or a negative error code 24972e5016fSJean-Jacques Hiblot */ 25072e5016fSJean-Jacques Hiblot int generic_phy_get_by_index(struct udevice *user, int index, 25172e5016fSJean-Jacques Hiblot struct phy *phy); 25272e5016fSJean-Jacques Hiblot 25372e5016fSJean-Jacques Hiblot /** 25472e5016fSJean-Jacques Hiblot * generic_phy_get_by_name() - Get a PHY device by its name. 25572e5016fSJean-Jacques Hiblot * 25672e5016fSJean-Jacques Hiblot * @user: the client device 25772e5016fSJean-Jacques Hiblot * @phy_name: The name of the PHY in the list of possible PHYs 25872e5016fSJean-Jacques Hiblot * @phy: A pointer to the PHY port 25972e5016fSJean-Jacques Hiblot * 26072e5016fSJean-Jacques Hiblot * This looks up a PHY device for a client device in the 26172e5016fSJean-Jacques Hiblot * list of the possible PHYs based on its name. 26272e5016fSJean-Jacques Hiblot * 26372e5016fSJean-Jacques Hiblot * example: 26472e5016fSJean-Jacques Hiblot * usb1: usb_otg_ss@xxx { 26572e5016fSJean-Jacques Hiblot * compatible = "xxx"; 26672e5016fSJean-Jacques Hiblot * reg = <xxx>; 26772e5016fSJean-Jacques Hiblot * . 26872e5016fSJean-Jacques Hiblot * . 26972e5016fSJean-Jacques Hiblot * phys = <&usb2_phy>, <&usb3_phy>; 27072e5016fSJean-Jacques Hiblot * phy-names = "usb2phy", "usb3phy"; 27172e5016fSJean-Jacques Hiblot * . 27272e5016fSJean-Jacques Hiblot * . 27372e5016fSJean-Jacques Hiblot * }; 27472e5016fSJean-Jacques Hiblot * the USB3 phy can be accessed using "usb3phy", and USB2 by using "usb2phy" 27572e5016fSJean-Jacques Hiblot * 27672e5016fSJean-Jacques Hiblot * @return 0 if OK, or a negative error code 27772e5016fSJean-Jacques Hiblot */ 27872e5016fSJean-Jacques Hiblot int generic_phy_get_by_name(struct udevice *user, const char *phy_name, 27972e5016fSJean-Jacques Hiblot struct phy *phy); 28072e5016fSJean-Jacques Hiblot 281d9fb7becSPatrice Chotard #else /* CONFIG_PHY */ 282d9fb7becSPatrice Chotard 283d9fb7becSPatrice Chotard static inline int generic_phy_init(struct phy *phy) 284d9fb7becSPatrice Chotard { 285d9fb7becSPatrice Chotard return 0; 286d9fb7becSPatrice Chotard } 287d9fb7becSPatrice Chotard 288d9fb7becSPatrice Chotard static inline int generic_phy_exit(struct phy *phy) 289d9fb7becSPatrice Chotard { 290d9fb7becSPatrice Chotard return 0; 291d9fb7becSPatrice Chotard } 292d9fb7becSPatrice Chotard 293d9fb7becSPatrice Chotard static inline int generic_phy_reset(struct phy *phy) 294d9fb7becSPatrice Chotard { 295d9fb7becSPatrice Chotard return 0; 296d9fb7becSPatrice Chotard } 297d9fb7becSPatrice Chotard 298*4ef09685SWyon Bi static inline int generic_phy_configure(struct phy *phy, 299*4ef09685SWyon Bi union phy_configure_opts *opts) 300*4ef09685SWyon Bi { 301*4ef09685SWyon Bi return 0; 302*4ef09685SWyon Bi } 303*4ef09685SWyon Bi 304*4ef09685SWyon Bi static inline int generic_phy_validate(struct phy *phy, enum phy_mode mode, 305*4ef09685SWyon Bi int submode, 306*4ef09685SWyon Bi union phy_configure_opts *opts) 307*4ef09685SWyon Bi { 308*4ef09685SWyon Bi return 0; 309*4ef09685SWyon Bi } 310*4ef09685SWyon Bi 311d9fb7becSPatrice Chotard static inline int generic_phy_power_on(struct phy *phy) 312d9fb7becSPatrice Chotard { 313d9fb7becSPatrice Chotard return 0; 314d9fb7becSPatrice Chotard } 315d9fb7becSPatrice Chotard 316d9fb7becSPatrice Chotard static inline int generic_phy_power_off(struct phy *phy) 317d9fb7becSPatrice Chotard { 318d9fb7becSPatrice Chotard return 0; 319d9fb7becSPatrice Chotard } 320d9fb7becSPatrice Chotard 321d9fb7becSPatrice Chotard static inline int generic_phy_get_by_index(struct udevice *user, int index, 322d9fb7becSPatrice Chotard struct phy *phy) 323d9fb7becSPatrice Chotard { 324d9fb7becSPatrice Chotard return 0; 325d9fb7becSPatrice Chotard } 326d9fb7becSPatrice Chotard 327d9fb7becSPatrice Chotard static inline int generic_phy_get_by_name(struct udevice *user, const char *phy_name, 328d9fb7becSPatrice Chotard struct phy *phy) 329d9fb7becSPatrice Chotard { 330d9fb7becSPatrice Chotard return 0; 331d9fb7becSPatrice Chotard } 332d9fb7becSPatrice Chotard 333d9fb7becSPatrice Chotard #endif /* CONFIG_PHY */ 334d9fb7becSPatrice Chotard 335b94888b4SPatrice Chotard /** 336b94888b4SPatrice Chotard * generic_phy_valid() - check if PHY port is valid 337b94888b4SPatrice Chotard * 338b94888b4SPatrice Chotard * @phy: the PHY port to check 339b94888b4SPatrice Chotard * @return TRUE if valid, or FALSE 340b94888b4SPatrice Chotard */ 341b94888b4SPatrice Chotard static inline bool generic_phy_valid(struct phy *phy) 342b94888b4SPatrice Chotard { 3431bac1f39SJean-Jacques Hiblot return phy && phy->dev; 344b94888b4SPatrice Chotard } 345b94888b4SPatrice Chotard 34672e5016fSJean-Jacques Hiblot #endif /*__GENERIC_PHY_H */ 347