@@ -110,23 +110,27 @@ struct phy_override_seq {
110
110
/**
111
111
* struct qcom_snps_hsphy - snps hs phy attributes
112
112
*
113
+ * @dev: device structure
114
+ *
113
115
* @phy: generic phy
114
116
* @base: iomapped memory space for snps hs phy
115
117
*
116
- * @cfg_ahb_clk: AHB2PHY interface clock
117
- * @ref_clk: phy reference clock
118
+ * @num_clks: number of clocks
119
+ * @clks: array of clocks
118
120
* @phy_reset: phy reset control
119
121
* @vregs: regulator supplies bulk data
120
122
* @phy_initialized: if PHY has been initialized correctly
121
123
* @mode: contains the current mode the PHY is in
122
124
* @update_seq_cfg: tuning parameters for phy init
123
125
*/
124
126
struct qcom_snps_hsphy {
127
+ struct device * dev ;
128
+
125
129
struct phy * phy ;
126
130
void __iomem * base ;
127
131
128
- struct clk * cfg_ahb_clk ;
129
- struct clk * ref_clk ;
132
+ int num_clks ;
133
+ struct clk_bulk_data * clks ;
130
134
struct reset_control * phy_reset ;
131
135
struct regulator_bulk_data vregs [SNPS_HS_NUM_VREGS ];
132
136
@@ -135,6 +139,34 @@ struct qcom_snps_hsphy {
135
139
struct phy_override_seq update_seq_cfg [NUM_HSPHY_TUNING_PARAMS ];
136
140
};
137
141
142
+ static int qcom_snps_hsphy_clk_init (struct qcom_snps_hsphy * hsphy )
143
+ {
144
+ struct device * dev = hsphy -> dev ;
145
+
146
+ hsphy -> num_clks = 2 ;
147
+ hsphy -> clks = devm_kcalloc (dev , hsphy -> num_clks , sizeof (* hsphy -> clks ), GFP_KERNEL );
148
+ if (!hsphy -> clks )
149
+ return - ENOMEM ;
150
+
151
+ /*
152
+ * TODO: Currently no device tree instantiation of the PHY is using the clock.
153
+ * This needs to be fixed in order for this code to be able to use devm_clk_bulk_get().
154
+ */
155
+ hsphy -> clks [0 ].id = "cfg_ahb" ;
156
+ hsphy -> clks [0 ].clk = devm_clk_get_optional (dev , "cfg_ahb" );
157
+ if (IS_ERR (hsphy -> clks [0 ].clk ))
158
+ return dev_err_probe (dev , PTR_ERR (hsphy -> clks [0 ].clk ),
159
+ "failed to get cfg_ahb clk\n" );
160
+
161
+ hsphy -> clks [1 ].id = "ref" ;
162
+ hsphy -> clks [1 ].clk = devm_clk_get (dev , "ref" );
163
+ if (IS_ERR (hsphy -> clks [1 ].clk ))
164
+ return dev_err_probe (dev , PTR_ERR (hsphy -> clks [1 ].clk ),
165
+ "failed to get ref clk\n" );
166
+
167
+ return 0 ;
168
+ }
169
+
138
170
static inline void qcom_snps_hsphy_write_mask (void __iomem * base , u32 offset ,
139
171
u32 mask , u32 val )
140
172
{
@@ -165,22 +197,13 @@ static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
165
197
0 , USB2_AUTO_RESUME );
166
198
}
167
199
168
- clk_disable_unprepare (hsphy -> cfg_ahb_clk );
169
200
return 0 ;
170
201
}
171
202
172
203
static int qcom_snps_hsphy_resume (struct qcom_snps_hsphy * hsphy )
173
204
{
174
- int ret ;
175
-
176
205
dev_dbg (& hsphy -> phy -> dev , "Resume QCOM SNPS PHY, mode\n" );
177
206
178
- ret = clk_prepare_enable (hsphy -> cfg_ahb_clk );
179
- if (ret ) {
180
- dev_err (& hsphy -> phy -> dev , "failed to enable cfg ahb clock\n" );
181
- return ret ;
182
- }
183
-
184
207
return 0 ;
185
208
}
186
209
@@ -191,8 +214,7 @@ static int __maybe_unused qcom_snps_hsphy_runtime_suspend(struct device *dev)
191
214
if (!hsphy -> phy_initialized )
192
215
return 0 ;
193
216
194
- qcom_snps_hsphy_suspend (hsphy );
195
- return 0 ;
217
+ return qcom_snps_hsphy_suspend (hsphy );
196
218
}
197
219
198
220
static int __maybe_unused qcom_snps_hsphy_runtime_resume (struct device * dev )
@@ -202,8 +224,7 @@ static int __maybe_unused qcom_snps_hsphy_runtime_resume(struct device *dev)
202
224
if (!hsphy -> phy_initialized )
203
225
return 0 ;
204
226
205
- qcom_snps_hsphy_resume (hsphy );
206
- return 0 ;
227
+ return qcom_snps_hsphy_resume (hsphy );
207
228
}
208
229
209
230
static int qcom_snps_hsphy_set_mode (struct phy * phy , enum phy_mode mode ,
@@ -374,24 +395,24 @@ static int qcom_snps_hsphy_init(struct phy *phy)
374
395
if (ret )
375
396
return ret ;
376
397
377
- ret = clk_prepare_enable (hsphy -> cfg_ahb_clk );
398
+ ret = clk_bulk_prepare_enable (hsphy -> num_clks , hsphy -> clks );
378
399
if (ret ) {
379
- dev_err (& phy -> dev , "failed to enable cfg ahb clock , %d\n" , ret );
400
+ dev_err (& phy -> dev , "failed to enable clocks , %d\n" , ret );
380
401
goto poweroff_phy ;
381
402
}
382
403
383
404
ret = reset_control_assert (hsphy -> phy_reset );
384
405
if (ret ) {
385
406
dev_err (& phy -> dev , "failed to assert phy_reset, %d\n" , ret );
386
- goto disable_ahb_clk ;
407
+ goto disable_clks ;
387
408
}
388
409
389
410
usleep_range (100 , 150 );
390
411
391
412
ret = reset_control_deassert (hsphy -> phy_reset );
392
413
if (ret ) {
393
414
dev_err (& phy -> dev , "failed to de-assert phy_reset, %d\n" , ret );
394
- goto disable_ahb_clk ;
415
+ goto disable_clks ;
395
416
}
396
417
397
418
qcom_snps_hsphy_write_mask (hsphy -> base , USB2_PHY_USB_PHY_CFG0 ,
@@ -448,8 +469,8 @@ static int qcom_snps_hsphy_init(struct phy *phy)
448
469
449
470
return 0 ;
450
471
451
- disable_ahb_clk :
452
- clk_disable_unprepare (hsphy -> cfg_ahb_clk );
472
+ disable_clks :
473
+ clk_bulk_disable_unprepare (hsphy -> num_clks , hsphy -> clks );
453
474
poweroff_phy :
454
475
regulator_bulk_disable (ARRAY_SIZE (hsphy -> vregs ), hsphy -> vregs );
455
476
@@ -461,7 +482,7 @@ static int qcom_snps_hsphy_exit(struct phy *phy)
461
482
struct qcom_snps_hsphy * hsphy = phy_get_drvdata (phy );
462
483
463
484
reset_control_assert (hsphy -> phy_reset );
464
- clk_disable_unprepare (hsphy -> cfg_ahb_clk );
485
+ clk_bulk_disable_unprepare (hsphy -> num_clks , hsphy -> clks );
465
486
regulator_bulk_disable (ARRAY_SIZE (hsphy -> vregs ), hsphy -> vregs );
466
487
hsphy -> phy_initialized = false;
467
488
@@ -554,14 +575,15 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)
554
575
if (!hsphy )
555
576
return - ENOMEM ;
556
577
578
+ hsphy -> dev = dev ;
579
+
557
580
hsphy -> base = devm_platform_ioremap_resource (pdev , 0 );
558
581
if (IS_ERR (hsphy -> base ))
559
582
return PTR_ERR (hsphy -> base );
560
583
561
- hsphy -> ref_clk = devm_clk_get (dev , "ref" );
562
- if (IS_ERR (hsphy -> ref_clk ))
563
- return dev_err_probe (dev , PTR_ERR (hsphy -> ref_clk ),
564
- "failed to get ref clk\n" );
584
+ ret = qcom_snps_hsphy_clk_init (hsphy );
585
+ if (ret )
586
+ return dev_err_probe (dev , ret , "failed to initialize clocks\n" );
565
587
566
588
hsphy -> phy_reset = devm_reset_control_get_exclusive (& pdev -> dev , NULL );
567
589
if (IS_ERR (hsphy -> phy_reset )) {
0 commit comments