phy: Add configuration interface

The phy framework is only allowing to configure the power state of thePHY
using the init and power_on hooks, and their power_off and exit
counterparts.

While it works for most, simple, PHYs supported so far, some more advanced
PHYs need some configuration depending on runtime parameters. These PHYs
have been supported by a number of means already, often by using ad-hoc
drivers in their consumer drivers.

That doesn't work too well however, when a consumer device needs to deal
with multiple PHYs, or when multiple consumers need to deal with the same
PHY (a DSI driver and a CSI driver for example).

So we'll add a new interface, through two funtions, phy_validate and
phy_configure. The first one will allow to check that a current
configuration, for a given mode, is applicable. It will also allow the PHY
driver to tune the settings given as parameters as it sees fit.

phy_configure will actually apply that configuration in the phy itself.

Signed-off-by: Wyon Bi <bivvy.bi@rock-chips.com>
Change-Id: Icd170eaef9a1dbe21e0c7664b797a27877c703b5
This commit is contained in:
Wyon Bi 2020-12-10 02:12:15 +00:00 committed by Jianhong Chen
parent 37a5e4d859
commit 4ef09685de
2 changed files with 93 additions and 0 deletions

View File

@ -151,6 +151,29 @@ int generic_phy_power_off(struct phy *phy)
return ops->power_off ? ops->power_off(phy) : 0;
}
int generic_phy_configure(struct phy *phy, union phy_configure_opts *opts)
{
struct phy_ops const *ops;
if (!generic_phy_valid(phy))
return 0;
ops = phy_dev_ops(phy->dev);
return ops->configure ? ops->configure(phy, opts) : 0;
}
int generic_phy_validate(struct phy *phy, enum phy_mode mode, int submode,
union phy_configure_opts *opts)
{
struct phy_ops const *ops;
if (!generic_phy_valid(phy))
return 0;
ops = phy_dev_ops(phy->dev);
return ops->validate ? ops->validate(phy, mode, submode, opts) : 0;
}
UCLASS_DRIVER(phy) = {
.id = UCLASS_PHY,
.name = "phy",

View File

@ -8,6 +8,15 @@
#ifndef __GENERIC_PHY_H
#define __GENERIC_PHY_H
enum phy_mode {
PHY_MODE_INVALID,
};
/**
* union phy_configure_opts - Opaque generic phy configuration
*/
union phy_configure_opts {
};
/**
* struct phy - A handle to (allowing control of) a single phy port.
@ -93,6 +102,37 @@ struct phy_ops {
*/
int (*reset)(struct phy *phy);
/**
* @configure:
*
* Optional.
*
* Used to change the PHY parameters. phy_init() must have
* been called on the phy.
*
* Returns: 0 if successful, an negative error code otherwise
*/
int (*configure)(struct phy *phy, union phy_configure_opts *opts);
/**
* @validate:
*
* Optional.
*
* Used to check that the current set of parameters can be
* handled by the phy. Implementations are free to tune the
* parameters passed as arguments if needed by some
* implementation detail or constraints. It must not change
* any actual configuration of the PHY, so calling it as many
* times as deemed fit by the consumer must have no side
* effect.
*
* Returns: 0 if the configuration can be applied, an negative
* error code otherwise
*/
int (*validate)(struct phy *phy, enum phy_mode mode, int submode,
union phy_configure_opts *opts);
/**
* power_on - power on a PHY device
*
@ -148,6 +188,23 @@ int generic_phy_exit(struct phy *phy);
*/
int generic_phy_reset(struct phy *phy);
/**
* generic_phy_configure() - change the PHY parameters
*
* @phy: PHY port to be configure
* @return 0 if OK, or a negative error code
*/
int generic_phy_configure(struct phy *phy, union phy_configure_opts *opts);
/**
* generic_phy_validate() - validate the PHY parameters
*
* @phy: PHY port to be validate
* @return 0 if OK, or a negative error code
*/
int generic_phy_validate(struct phy *phy, enum phy_mode mode, int submode,
union phy_configure_opts *opts);
/**
* generic_phy_power_on() - power on a PHY device
*
@ -238,6 +295,19 @@ static inline int generic_phy_reset(struct phy *phy)
return 0;
}
static inline int generic_phy_configure(struct phy *phy,
union phy_configure_opts *opts)
{
return 0;
}
static inline int generic_phy_validate(struct phy *phy, enum phy_mode mode,
int submode,
union phy_configure_opts *opts)
{
return 0;
}
static inline int generic_phy_power_on(struct phy *phy)
{
return 0;