Skip to content

Commit 31bc94d

Browse files
lweiss-fairphonevinodkoul
authored andcommitted
phy: qualcomm: phy-qcom-eusb2-repeater: Don't zero-out registers
Zeroing out registers does not happen in the downstream kernel, and will "tune" the repeater in surely unexpected ways since most registers don't have a reset value of 0x0. Stop doing that and instead just set the registers that are in the init sequence (though long term I don't think there's actually PMIC-specific init sequences, there's board specific tuning, but that's a story for another day). Fixes: 99a517a ("phy: qualcomm: phy-qcom-eusb2-repeater: Zero out untouched tuning regs") Reviewed-by: Konrad Dybcio <[email protected]> Reviewed-by: Neil Armstrong <[email protected]> Signed-off-by: Luca Weiss <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Reviewed-by: Abel Vesa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent db9f3e3 commit 31bc94d

File tree

1 file changed

+32
-55
lines changed

1 file changed

+32
-55
lines changed

drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,13 @@
3737
#define EUSB2_TUNE_EUSB_EQU 0x5A
3838
#define EUSB2_TUNE_EUSB_HS_COMP_CUR 0x5B
3939

40-
enum eusb2_reg_layout {
41-
TUNE_EUSB_HS_COMP_CUR,
42-
TUNE_EUSB_EQU,
43-
TUNE_EUSB_SLEW,
44-
TUNE_USB2_HS_COMP_CUR,
45-
TUNE_USB2_PREEM,
46-
TUNE_USB2_EQU,
47-
TUNE_USB2_SLEW,
48-
TUNE_SQUELCH_U,
49-
TUNE_HSDISC,
50-
TUNE_RES_FSDIF,
51-
TUNE_IUSB2,
52-
TUNE_USB2_CROSSOVER,
53-
NUM_TUNE_FIELDS,
54-
55-
FORCE_VAL_5 = NUM_TUNE_FIELDS,
56-
FORCE_EN_5,
57-
58-
EN_CTL1,
59-
60-
RPTR_STATUS,
61-
LAYOUT_SIZE,
40+
struct eusb2_repeater_init_tbl_reg {
41+
unsigned int reg;
42+
unsigned int value;
6243
};
6344

6445
struct eusb2_repeater_cfg {
65-
const u32 *init_tbl;
46+
const struct eusb2_repeater_init_tbl_reg *init_tbl;
6647
int init_tbl_num;
6748
const char * const *vreg_list;
6849
int num_vregs;
@@ -82,16 +63,16 @@ static const char * const pm8550b_vreg_l[] = {
8263
"vdd18", "vdd3",
8364
};
8465

85-
static const u32 pm8550b_init_tbl[NUM_TUNE_FIELDS] = {
86-
[TUNE_IUSB2] = 0x8,
87-
[TUNE_SQUELCH_U] = 0x3,
88-
[TUNE_USB2_PREEM] = 0x5,
66+
static const struct eusb2_repeater_init_tbl_reg pm8550b_init_tbl[] = {
67+
{ EUSB2_TUNE_IUSB2, 0x8 },
68+
{ EUSB2_TUNE_SQUELCH_U, 0x3 },
69+
{ EUSB2_TUNE_USB2_PREEM, 0x5 },
8970
};
9071

91-
static const u32 smb2360_init_tbl[NUM_TUNE_FIELDS] = {
92-
[TUNE_IUSB2] = 0x5,
93-
[TUNE_SQUELCH_U] = 0x3,
94-
[TUNE_USB2_PREEM] = 0x2,
72+
static const struct eusb2_repeater_init_tbl_reg smb2360_init_tbl[] = {
73+
{ EUSB2_TUNE_IUSB2, 0x5 },
74+
{ EUSB2_TUNE_SQUELCH_U, 0x3 },
75+
{ EUSB2_TUNE_USB2_PREEM, 0x2 },
9576
};
9677

9778
static const struct eusb2_repeater_cfg pm8550b_eusb2_cfg = {
@@ -129,39 +110,35 @@ static int eusb2_repeater_init(struct phy *phy)
129110
struct eusb2_repeater *rptr = phy_get_drvdata(phy);
130111
struct device_node *np = rptr->dev->of_node;
131112
struct regmap *regmap = rptr->regmap;
132-
const u32 *init_tbl = rptr->cfg->init_tbl;
133-
u8 tune_usb2_preem = init_tbl[TUNE_USB2_PREEM];
134-
u8 tune_hsdisc = init_tbl[TUNE_HSDISC];
135-
u8 tune_iusb2 = init_tbl[TUNE_IUSB2];
136113
u32 base = rptr->base;
137-
u32 val;
114+
u32 poll_val;
138115
int ret;
139-
140-
of_property_read_u8(np, "qcom,tune-usb2-amplitude", &tune_iusb2);
141-
of_property_read_u8(np, "qcom,tune-usb2-disc-thres", &tune_hsdisc);
142-
of_property_read_u8(np, "qcom,tune-usb2-preem", &tune_usb2_preem);
116+
u8 val;
143117

144118
ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
145119
if (ret)
146120
return ret;
147121

148122
regmap_write(regmap, base + EUSB2_EN_CTL1, EUSB2_RPTR_EN);
149123

150-
regmap_write(regmap, base + EUSB2_TUNE_EUSB_HS_COMP_CUR, init_tbl[TUNE_EUSB_HS_COMP_CUR]);
151-
regmap_write(regmap, base + EUSB2_TUNE_EUSB_EQU, init_tbl[TUNE_EUSB_EQU]);
152-
regmap_write(regmap, base + EUSB2_TUNE_EUSB_SLEW, init_tbl[TUNE_EUSB_SLEW]);
153-
regmap_write(regmap, base + EUSB2_TUNE_USB2_HS_COMP_CUR, init_tbl[TUNE_USB2_HS_COMP_CUR]);
154-
regmap_write(regmap, base + EUSB2_TUNE_USB2_EQU, init_tbl[TUNE_USB2_EQU]);
155-
regmap_write(regmap, base + EUSB2_TUNE_USB2_SLEW, init_tbl[TUNE_USB2_SLEW]);
156-
regmap_write(regmap, base + EUSB2_TUNE_SQUELCH_U, init_tbl[TUNE_SQUELCH_U]);
157-
regmap_write(regmap, base + EUSB2_TUNE_RES_FSDIF, init_tbl[TUNE_RES_FSDIF]);
158-
regmap_write(regmap, base + EUSB2_TUNE_USB2_CROSSOVER, init_tbl[TUNE_USB2_CROSSOVER]);
159-
160-
regmap_write(regmap, base + EUSB2_TUNE_USB2_PREEM, tune_usb2_preem);
161-
regmap_write(regmap, base + EUSB2_TUNE_HSDISC, tune_hsdisc);
162-
regmap_write(regmap, base + EUSB2_TUNE_IUSB2, tune_iusb2);
163-
164-
ret = regmap_read_poll_timeout(regmap, base + EUSB2_RPTR_STATUS, val, val & RPTR_OK, 10, 5);
124+
/* Write registers from init table */
125+
for (int i = 0; i < rptr->cfg->init_tbl_num; i++)
126+
regmap_write(regmap, base + rptr->cfg->init_tbl[i].reg,
127+
rptr->cfg->init_tbl[i].value);
128+
129+
/* Override registers from devicetree values */
130+
if (!of_property_read_u8(np, "qcom,tune-usb2-amplitude", &val))
131+
regmap_write(regmap, base + EUSB2_TUNE_USB2_PREEM, val);
132+
133+
if (!of_property_read_u8(np, "qcom,tune-usb2-disc-thres", &val))
134+
regmap_write(regmap, base + EUSB2_TUNE_HSDISC, val);
135+
136+
if (!of_property_read_u8(np, "qcom,tune-usb2-preem", &val))
137+
regmap_write(regmap, base + EUSB2_TUNE_IUSB2, val);
138+
139+
/* Wait for status OK */
140+
ret = regmap_read_poll_timeout(regmap, base + EUSB2_RPTR_STATUS, poll_val,
141+
poll_val & RPTR_OK, 10, 5);
165142
if (ret)
166143
dev_err(rptr->dev, "initialization timed-out\n");
167144

0 commit comments

Comments
 (0)