Skip to content

Commit 815891e

Browse files
quic-bjorandevinodkoul
authored andcommitted
phy: qcom-qmp-combo: Introduce orientation variable
In multiple places throughout the driver code has been written in prepration for handling of orientation switching. Introduce a typec_orientation in qmp_combo and fill out the various "placeholders" with the associated logic. By initializing the orientation to "normal" this change has no functional impact, but reduces the size of the upcoming introduction of dynamic orientation switching. Reviewed-by: Neil Armstrong <[email protected]> Tested-by: Abel Vesa <[email protected]> Tested-by: Steev Klimaszewski <[email protected]> Tested-by: Neil Armstrong <[email protected]> # on HDK8450 Tested-by: Johan Hovold <[email protected]> # X13s Reviewed-by: Johan Hovold <[email protected]> Signed-off-by: Bjorn Andersson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 77cbca3 commit 815891e

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

drivers/phy/qualcomm/phy-qcom-qmp-combo.c

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/regulator/consumer.h>
2020
#include <linux/reset.h>
2121
#include <linux/slab.h>
22+
#include <linux/usb/typec.h>
2223

2324
#include <dt-bindings/phy/phy-qcom-qmp.h>
2425

@@ -63,6 +64,10 @@
6364
/* QPHY_V3_PCS_MISC_CLAMP_ENABLE register bits */
6465
#define CLAMP_EN BIT(0) /* enables i/o clamp_n */
6566

67+
/* QPHY_V3_DP_COM_TYPEC_CTRL register bits */
68+
#define SW_PORTSELECT_VAL BIT(0)
69+
#define SW_PORTSELECT_MUX BIT(1)
70+
6671
#define PHY_INIT_COMPLETE_TIMEOUT 10000
6772

6873
struct qmp_phy_init_tbl {
@@ -1323,6 +1328,8 @@ struct qmp_combo {
13231328
struct clk_fixed_rate pipe_clk_fixed;
13241329
struct clk_hw dp_link_hw;
13251330
struct clk_hw dp_pixel_hw;
1331+
1332+
enum typec_orientation orientation;
13261333
};
13271334

13281335
static void qmp_v3_dp_aux_init(struct qmp_combo *qmp);
@@ -1954,30 +1961,24 @@ static void qmp_v3_configure_dp_tx(struct qmp_combo *qmp)
19541961

19551962
static bool qmp_combo_configure_dp_mode(struct qmp_combo *qmp)
19561963
{
1964+
bool reverse = (qmp->orientation == TYPEC_ORIENTATION_REVERSE);
1965+
const struct phy_configure_opts_dp *dp_opts = &qmp->dp_opts;
19571966
u32 val;
1958-
bool reverse = false;
19591967

19601968
val = DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
19611969
DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN;
19621970

1963-
/*
1964-
* TODO: Assume orientation is CC1 for now and two lanes, need to
1965-
* use type-c connector to understand orientation and lanes.
1966-
*
1967-
* Otherwise val changes to be like below if this code understood
1968-
* the orientation of the type-c cable.
1969-
*
1970-
* if (lane_cnt == 4 || orientation == ORIENTATION_CC2)
1971-
* val |= DP_PHY_PD_CTL_LANE_0_1_PWRDN;
1972-
* if (lane_cnt == 4 || orientation == ORIENTATION_CC1)
1973-
* val |= DP_PHY_PD_CTL_LANE_2_3_PWRDN;
1974-
* if (orientation == ORIENTATION_CC2)
1975-
* writel(0x4c, qmp->dp_dp_phy + QSERDES_V3_DP_PHY_MODE);
1976-
*/
1977-
val |= DP_PHY_PD_CTL_LANE_2_3_PWRDN;
1971+
if (dp_opts->lanes == 4 || reverse)
1972+
val |= DP_PHY_PD_CTL_LANE_0_1_PWRDN;
1973+
if (dp_opts->lanes == 4 || !reverse)
1974+
val |= DP_PHY_PD_CTL_LANE_2_3_PWRDN;
1975+
19781976
writel(val, qmp->dp_dp_phy + QSERDES_DP_PHY_PD_CTL);
19791977

1980-
writel(0x5c, qmp->dp_dp_phy + QSERDES_DP_PHY_MODE);
1978+
if (reverse)
1979+
writel(0x4c, qmp->pcs + QSERDES_DP_PHY_MODE);
1980+
else
1981+
writel(0x5c, qmp->pcs + QSERDES_DP_PHY_MODE);
19811982

19821983
return reverse;
19831984
}
@@ -2233,9 +2234,9 @@ static int qmp_v456_configure_dp_phy(struct qmp_combo *qmp,
22332234

22342235
static int qmp_v4_configure_dp_phy(struct qmp_combo *qmp)
22352236
{
2237+
bool reverse = (qmp->orientation == TYPEC_ORIENTATION_REVERSE);
22362238
const struct phy_configure_opts_dp *dp_opts = &qmp->dp_opts;
22372239
u32 bias0_en, drvr0_en, bias1_en, drvr1_en;
2238-
bool reverse = false;
22392240
u32 status;
22402241
int ret;
22412242

@@ -2297,9 +2298,9 @@ static int qmp_v4_configure_dp_phy(struct qmp_combo *qmp)
22972298

22982299
static int qmp_v5_configure_dp_phy(struct qmp_combo *qmp)
22992300
{
2301+
bool reverse = (qmp->orientation == TYPEC_ORIENTATION_REVERSE);
23002302
const struct phy_configure_opts_dp *dp_opts = &qmp->dp_opts;
23012303
u32 bias0_en, drvr0_en, bias1_en, drvr1_en;
2302-
bool reverse = false;
23032304
u32 status;
23042305
int ret;
23052306

@@ -2356,9 +2357,9 @@ static int qmp_v5_configure_dp_phy(struct qmp_combo *qmp)
23562357

23572358
static int qmp_v6_configure_dp_phy(struct qmp_combo *qmp)
23582359
{
2360+
bool reverse = (qmp->orientation == TYPEC_ORIENTATION_REVERSE);
23592361
const struct phy_configure_opts_dp *dp_opts = &qmp->dp_opts;
23602362
u32 bias0_en, drvr0_en, bias1_en, drvr1_en;
2361-
bool reverse = false;
23622363
u32 status;
23632364
int ret;
23642365

@@ -2471,6 +2472,7 @@ static int qmp_combo_com_init(struct qmp_combo *qmp)
24712472
const struct qmp_phy_cfg *cfg = qmp->cfg;
24722473
void __iomem *com = qmp->com;
24732474
int ret;
2475+
u32 val;
24742476

24752477
if (qmp->init_count++)
24762478
return 0;
@@ -2504,10 +2506,12 @@ static int qmp_combo_com_init(struct qmp_combo *qmp)
25042506
SW_DPPHY_RESET_MUX | SW_DPPHY_RESET |
25052507
SW_USB3PHY_RESET_MUX | SW_USB3PHY_RESET);
25062508

2507-
/* Default type-c orientation, i.e CC1 */
2508-
qphy_setbits(com, QPHY_V3_DP_COM_TYPEC_CTRL, 0x02);
2509-
2510-
qphy_setbits(com, QPHY_V3_DP_COM_PHY_MODE_CTRL, USB3_MODE | DP_MODE);
2509+
/* Use software based port select and switch on typec orientation */
2510+
val = SW_PORTSELECT_MUX;
2511+
if (qmp->orientation == TYPEC_ORIENTATION_REVERSE)
2512+
val |= SW_PORTSELECT_VAL;
2513+
writel(val, com + QPHY_V3_DP_COM_TYPEC_CTRL);
2514+
writel(USB3_MODE | DP_MODE, com + QPHY_V3_DP_COM_PHY_MODE_CTRL);
25112515

25122516
/* bring both QMP USB and QMP DP PHYs PCS block out of reset */
25132517
qphy_clrbits(com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
@@ -3379,6 +3383,8 @@ static int qmp_combo_probe(struct platform_device *pdev)
33793383

33803384
qmp->dev = dev;
33813385

3386+
qmp->orientation = TYPEC_ORIENTATION_NORMAL;
3387+
33823388
qmp->cfg = of_device_get_match_data(dev);
33833389
if (!qmp->cfg)
33843390
return -EINVAL;

0 commit comments

Comments
 (0)