Skip to content

Commit

Permalink
phy: core: rework phy_set_mode to accept phy mode and submode
Browse files Browse the repository at this point in the history
Currently the attempt to add support for Ethernet interface mode PHY
(MII/GMII/RGMII) will lead to the necessity of extending enum phy_mode and
duplicate there values from phy_interface_t enum (or introduce more PHY
callbacks) [1]. Both approaches are ineffective and would lead to fast
bloating of enum phy_mode or struct phy_ops in the process of adding more
PHYs for different subsystems which will make them unmaintainable.

As discussed in [1] the solution could be to introduce dual level PHYs mode
configuration - PHY mode and PHY submode. The PHY mode will define generic
PHY type (subsystem - PCIE/ETHERNET/USB_) while the PHY submode - subsystem
specific interface mode. The last is usually already defined in
corresponding subsystem headers (phy_interface_t for Ethernet, enum
usb_device_speed for USB).

This patch is cumulative change which refactors PHY framework code to
support dual level PHYs mode configuration - PHY mode and PHY submode. It
extends .set_mode() callback to support additional parameter "int submode"
and converts all corresponding PHY drivers to support new .set_mode()
callback declaration.
The new extended PHY API
 int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode)
is introduced to support dual level PHYs mode configuration and existing
phy_set_mode() API is converted to macros, so PHY framework consumers do
not need to be changed (~21 matches).

[1] http://lkml.kernel.org/r/[email protected]
Signed-off-by: Grygorii Strashko <[email protected]>
Signed-off-by: Kishon Vijay Abraham I <[email protected]>
  • Loading branch information
grygoriyS authored and kishon committed Dec 12, 2018
1 parent 640ac14 commit 79a5a18
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 22 deletions.
3 changes: 2 additions & 1 deletion drivers/phy/allwinner/phy-sun4i-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ static int sun4i_usb_phy_power_off(struct phy *_phy)
return 0;
}

static int sun4i_usb_phy_set_mode(struct phy *_phy, enum phy_mode mode)
static int sun4i_usb_phy_set_mode(struct phy *_phy,
enum phy_mode mode, int submode)
{
struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
Expand Down
5 changes: 3 additions & 2 deletions drivers/phy/amlogic/phy-meson-gxl-usb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ static int phy_meson_gxl_usb2_reset(struct phy *phy)
return 0;
}

static int phy_meson_gxl_usb2_set_mode(struct phy *phy, enum phy_mode mode)
static int phy_meson_gxl_usb2_set_mode(struct phy *phy,
enum phy_mode mode, int submode)
{
struct phy_meson_gxl_usb2_priv *priv = phy_get_drvdata(phy);

Expand Down Expand Up @@ -209,7 +210,7 @@ static int phy_meson_gxl_usb2_power_on(struct phy *phy)
/* power on the PHY by taking it out of reset mode */
regmap_update_bits(priv->regmap, U2P_R0, U2P_R0_POWER_ON_RESET, 0);

ret = phy_meson_gxl_usb2_set_mode(phy, priv->mode);
ret = phy_meson_gxl_usb2_set_mode(phy, priv->mode, 0);
if (ret) {
phy_meson_gxl_usb2_power_off(phy);

Expand Down
5 changes: 3 additions & 2 deletions drivers/phy/amlogic/phy-meson-gxl-usb3.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ static int phy_meson_gxl_usb3_power_off(struct phy *phy)
return 0;
}

static int phy_meson_gxl_usb3_set_mode(struct phy *phy, enum phy_mode mode)
static int phy_meson_gxl_usb3_set_mode(struct phy *phy,
enum phy_mode mode, int submode)
{
struct phy_meson_gxl_usb3_priv *priv = phy_get_drvdata(phy);

Expand Down Expand Up @@ -164,7 +165,7 @@ static int phy_meson_gxl_usb3_init(struct phy *phy)
if (ret)
goto err_disable_clk_phy;

ret = phy_meson_gxl_usb3_set_mode(phy, priv->mode);
ret = phy_meson_gxl_usb3_set_mode(phy, priv->mode, 0);
if (ret)
goto err_disable_clk_peripheral;

Expand Down
3 changes: 2 additions & 1 deletion drivers/phy/marvell/phy-mvebu-cp110-comphy.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ static int mvebu_comphy_power_on(struct phy *phy)
return ret;
}

static int mvebu_comphy_set_mode(struct phy *phy, enum phy_mode mode)
static int mvebu_comphy_set_mode(struct phy *phy,
enum phy_mode mode, int submode)
{
struct mvebu_comphy_lane *lane = phy_get_drvdata(phy);

Expand Down
2 changes: 1 addition & 1 deletion drivers/phy/mediatek/phy-mtk-tphy.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ static int mtk_phy_exit(struct phy *phy)
return 0;
}

static int mtk_phy_set_mode(struct phy *phy, enum phy_mode mode)
static int mtk_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode)
{
struct mtk_phy_instance *instance = phy_get_drvdata(phy);
struct mtk_tphy *tphy = dev_get_drvdata(phy->dev.parent);
Expand Down
2 changes: 1 addition & 1 deletion drivers/phy/mediatek/phy-mtk-xsphy.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ static int mtk_phy_exit(struct phy *phy)
return 0;
}

static int mtk_phy_set_mode(struct phy *phy, enum phy_mode mode)
static int mtk_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode)
{
struct xsphy_instance *inst = phy_get_drvdata(phy);
struct mtk_xsphy *xsphy = dev_get_drvdata(phy->dev.parent);
Expand Down
2 changes: 1 addition & 1 deletion drivers/phy/mscc/phy-ocelot-serdes.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static const struct serdes_mux ocelot_serdes_muxes[] = {
HSIO_HW_CFG_PCIE_ENA),
};

static int serdes_set_mode(struct phy *phy, enum phy_mode mode)
static int serdes_set_mode(struct phy *phy, enum phy_mode mode, int submode)
{
struct serdes_macro *macro = phy_get_drvdata(phy);
unsigned int i;
Expand Down
6 changes: 3 additions & 3 deletions drivers/phy/phy-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,22 +360,22 @@ int phy_power_off(struct phy *phy)
}
EXPORT_SYMBOL_GPL(phy_power_off);

int phy_set_mode(struct phy *phy, enum phy_mode mode)
int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode)
{
int ret;

if (!phy || !phy->ops->set_mode)
return 0;

mutex_lock(&phy->mutex);
ret = phy->ops->set_mode(phy, mode);
ret = phy->ops->set_mode(phy, mode, submode);
if (!ret)
phy->attrs.mode = mode;
mutex_unlock(&phy->mutex);

return ret;
}
EXPORT_SYMBOL_GPL(phy_set_mode);
EXPORT_SYMBOL_GPL(phy_set_mode_ext);

int phy_reset(struct phy *phy)
{
Expand Down
3 changes: 2 additions & 1 deletion drivers/phy/qualcomm/phy-qcom-qmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,8 @@ static int qcom_qmp_phy_poweron(struct phy *phy)
return ret;
}

static int qcom_qmp_phy_set_mode(struct phy *phy, enum phy_mode mode)
static int qcom_qmp_phy_set_mode(struct phy *phy,
enum phy_mode mode, int submode)
{
struct qmp_phy *qphy = phy_get_drvdata(phy);
struct qcom_qmp *qmp = qphy->qmp;
Expand Down
3 changes: 2 additions & 1 deletion drivers/phy/qualcomm/phy-qcom-qusb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
HSTX_TRIM_MASK);
}

static int qusb2_phy_set_mode(struct phy *phy, enum phy_mode mode)
static int qusb2_phy_set_mode(struct phy *phy,
enum phy_mode mode, int submode)
{
struct qusb2_phy *qphy = phy_get_drvdata(phy);

Expand Down
3 changes: 2 additions & 1 deletion drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ static int ufs_qcom_phy_qmp_14nm_exit(struct phy *generic_phy)
}

static
int ufs_qcom_phy_qmp_14nm_set_mode(struct phy *generic_phy, enum phy_mode mode)
int ufs_qcom_phy_qmp_14nm_set_mode(struct phy *generic_phy,
enum phy_mode mode, int submode)
{
struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy);

Expand Down
3 changes: 2 additions & 1 deletion drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ static int ufs_qcom_phy_qmp_20nm_exit(struct phy *generic_phy)
}

static
int ufs_qcom_phy_qmp_20nm_set_mode(struct phy *generic_phy, enum phy_mode mode)
int ufs_qcom_phy_qmp_20nm_set_mode(struct phy *generic_phy,
enum phy_mode mode, int submode)
{
struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy);

Expand Down
3 changes: 2 additions & 1 deletion drivers/phy/qualcomm/phy-qcom-usb-hs.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ struct qcom_usb_hs_phy {
struct notifier_block vbus_notify;
};

static int qcom_usb_hs_phy_set_mode(struct phy *phy, enum phy_mode mode)
static int qcom_usb_hs_phy_set_mode(struct phy *phy,
enum phy_mode mode, int submode)
{
struct qcom_usb_hs_phy *uphy = phy_get_drvdata(phy);
u8 addr;
Expand Down
3 changes: 2 additions & 1 deletion drivers/phy/ti/phy-da8xx-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ static int da8xx_usb20_phy_power_off(struct phy *phy)
return 0;
}

static int da8xx_usb20_phy_set_mode(struct phy *phy, enum phy_mode mode)
static int da8xx_usb20_phy_set_mode(struct phy *phy,
enum phy_mode mode, int submode)
{
struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
u32 val;
Expand Down
2 changes: 1 addition & 1 deletion drivers/phy/ti/phy-tusb1210.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static int tusb1210_power_off(struct phy *phy)
return 0;
}

static int tusb1210_set_mode(struct phy *phy, enum phy_mode mode)
static int tusb1210_set_mode(struct phy *phy, enum phy_mode mode, int submode)
{
struct tusb1210 *tusb = phy_get_drvdata(phy);
int ret;
Expand Down
13 changes: 10 additions & 3 deletions include/linux/phy/phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct phy_ops {
int (*exit)(struct phy *phy);
int (*power_on)(struct phy *phy);
int (*power_off)(struct phy *phy);
int (*set_mode)(struct phy *phy, enum phy_mode mode);
int (*set_mode)(struct phy *phy, enum phy_mode mode, int submode);
int (*reset)(struct phy *phy);
int (*calibrate)(struct phy *phy);
struct module *owner;
Expand Down Expand Up @@ -164,7 +164,10 @@ int phy_init(struct phy *phy);
int phy_exit(struct phy *phy);
int phy_power_on(struct phy *phy);
int phy_power_off(struct phy *phy);
int phy_set_mode(struct phy *phy, enum phy_mode mode);
int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode);
#define phy_set_mode(phy, mode) \
phy_set_mode_ext(phy, mode, 0)

static inline enum phy_mode phy_get_mode(struct phy *phy)
{
return phy->attrs.mode;
Expand Down Expand Up @@ -278,13 +281,17 @@ static inline int phy_power_off(struct phy *phy)
return -ENOSYS;
}

static inline int phy_set_mode(struct phy *phy, enum phy_mode mode)
static inline int phy_set_mode_ext(struct phy *phy, enum phy_mode mode,
int submode)
{
if (!phy)
return 0;
return -ENOSYS;
}

#define phy_set_mode(phy, mode) \
phy_set_mode_ext(phy, mode, 0)

static inline enum phy_mode phy_get_mode(struct phy *phy)
{
return PHY_MODE_INVALID;
Expand Down

0 comments on commit 79a5a18

Please sign in to comment.