37
37
#define EUSB2_TUNE_EUSB_EQU 0x5A
38
38
#define EUSB2_TUNE_EUSB_HS_COMP_CUR 0x5B
39
39
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 ;
62
43
};
63
44
64
45
struct eusb2_repeater_cfg {
65
- const u32 * init_tbl ;
46
+ const struct eusb2_repeater_init_tbl_reg * init_tbl ;
66
47
int init_tbl_num ;
67
48
const char * const * vreg_list ;
68
49
int num_vregs ;
@@ -82,16 +63,16 @@ static const char * const pm8550b_vreg_l[] = {
82
63
"vdd18" , "vdd3" ,
83
64
};
84
65
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 } ,
89
70
};
90
71
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 } ,
95
76
};
96
77
97
78
static const struct eusb2_repeater_cfg pm8550b_eusb2_cfg = {
@@ -129,39 +110,35 @@ static int eusb2_repeater_init(struct phy *phy)
129
110
struct eusb2_repeater * rptr = phy_get_drvdata (phy );
130
111
struct device_node * np = rptr -> dev -> of_node ;
131
112
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 ];
136
113
u32 base = rptr -> base ;
137
- u32 val ;
114
+ u32 poll_val ;
138
115
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 ;
143
117
144
118
ret = regulator_bulk_enable (rptr -> cfg -> num_vregs , rptr -> vregs );
145
119
if (ret )
146
120
return ret ;
147
121
148
122
regmap_write (regmap , base + EUSB2_EN_CTL1 , EUSB2_RPTR_EN );
149
123
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 );
165
142
if (ret )
166
143
dev_err (rptr -> dev , "initialization timed-out\n" );
167
144
0 commit comments