phy: core: rework phy_set_mode to accept phy mode and submode
authorGrygorii Strashko <grygorii.strashko@ti.com>
Tue, 20 Nov 2018 01:24:20 +0000 (19:24 -0600)
committerKishon Vijay Abraham I <kishon@ti.com>
Wed, 12 Dec 2018 04:31:33 +0000 (10:01 +0530)
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/d63588f6-9ab0-848a-5ad4-8073143bd95d@ti.com
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
16 files changed:
drivers/phy/allwinner/phy-sun4i-usb.c
drivers/phy/amlogic/phy-meson-gxl-usb2.c
drivers/phy/amlogic/phy-meson-gxl-usb3.c
drivers/phy/marvell/phy-mvebu-cp110-comphy.c
drivers/phy/mediatek/phy-mtk-tphy.c
drivers/phy/mediatek/phy-mtk-xsphy.c
drivers/phy/mscc/phy-ocelot-serdes.c
drivers/phy/phy-core.c
drivers/phy/qualcomm/phy-qcom-qmp.c
drivers/phy/qualcomm/phy-qcom-qusb2.c
drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c
drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c
drivers/phy/qualcomm/phy-qcom-usb-hs.c
drivers/phy/ti/phy-da8xx-usb.c
drivers/phy/ti/phy-tusb1210.c
include/linux/phy/phy.h

index ae16854a770a292d6bc4a1520f83afc2a38965f4..5163097b43dff1472af1b905936588750d45b9a8 100644 (file)
@@ -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);
index 9f9b5414b97a03f7af318df0cfa497e1b9b7320a..148ef0bdb9c100aea4245bc9252566068f127c24 100644 (file)
@@ -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);
 
@@ -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);
 
index d37d94ddf9c09bb3c306c8136dc2ccacdd412b7a..c0e9e4c16149e954d134488c692eed711535a124 100644 (file)
@@ -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);
 
@@ -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;
 
index 86a5f7b9448ba70a6944f5264c8bf1e58ea0fac0..79b52c39c5b4779dc7431a89f276e67141c8e543 100644 (file)
@@ -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);
 
index 3eb8e1bd7b78d5a23a335b2d9ca19ff0ae42f1d4..5b6a470ca145738186b976bb0e10c41d4273d40a 100644 (file)
@@ -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);
index 020cd0227397f58d0478632631ef9f9377303ac7..8c51131945c082feb62088184063aa3e8e7c6060 100644 (file)
@@ -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);
index cbb49d9da6f9a0c23daf7d687f733a12546264e7..c61a98908d364700fb43a29e3d8da48dca454b2b 100644 (file)
@@ -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;
index 35fd38c5a4a1baf8ea004b4252de3280c75540dd..df3d4ba516abc211f82c40083543150a44948c5c 100644 (file)
@@ -360,7 +360,7 @@ 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;
 
@@ -368,14 +368,14 @@ int phy_set_mode(struct phy *phy, enum phy_mode 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)
 {
index a833324110264d70a6e78436bf976eeafa23d29e..514db7248a5d0575e7786db4f9e35d9d1a1d0036 100644 (file)
@@ -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;
index 6d4b44b569bc78e7f3548825ddf4522c183bbd7b..9177989f22d129c1d976388dda448d7a79bacd98 100644 (file)
@@ -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);
 
index ba1895b76a5d8e5fe32142609f6a4579b08bbabc..1e0d4f2046a45940985efb7a7e325e32d6ac9a47 100644 (file)
@@ -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);
 
index 49f435c711471f133e6b55f83074fb96d3e28f32..aef40f7a41d494e2ca33df2030eda3ee2cbfa837 100644 (file)
@@ -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);
 
index abbbe75070daa0263765262fd6d4395401cdba55..04934f8dac91ad7c6bf9b6941ba2eb1032325db5 100644 (file)
@@ -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;
index befb886ff1212abe6796f4b67d43816987f5f70b..d5f4fbc32b526b91245aca9363853b407d44e2af 100644 (file)
@@ -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;
index b8ec39ac4dfc1cf0197fb027cea18ea94ce510e6..329fb938099a835c24b6f354af72e1ece6d007d5 100644 (file)
@@ -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;
index 03b319f89a345b37c89c7104d6bc48c1a3d66dc8..b17e7709c5dc5218b6a9158f66eab900d4d9013f 100644 (file)
@@ -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;
@@ -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;
@@ -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;