@@ -126,8 +126,8 @@ struct sti_dwmac {
126
126
struct clk * clk ; /* PHY clock */
127
127
u32 ctrl_reg ; /* GMAC glue-logic control register */
128
128
int clk_sel_reg ; /* GMAC ext clk selection register */
129
- struct device * dev ;
130
129
struct regmap * regmap ;
130
+ bool gmac_en ;
131
131
u32 speed ;
132
132
void (* fix_retime_src )(void * priv , unsigned int speed );
133
133
};
@@ -191,7 +191,7 @@ static void stih4xx_fix_retime_src(void *priv, u32 spd)
191
191
}
192
192
}
193
193
194
- if (src == TX_RETIME_SRC_CLKGEN && dwmac -> clk && freq )
194
+ if (src == TX_RETIME_SRC_CLKGEN && freq )
195
195
clk_set_rate (dwmac -> clk , freq );
196
196
197
197
regmap_update_bits (dwmac -> regmap , reg , STIH4XX_RETIME_SRC_MASK ,
@@ -222,45 +222,32 @@ static void stid127_fix_retime_src(void *priv, u32 spd)
222
222
freq = DWMAC_2_5MHZ ;
223
223
}
224
224
225
- if (dwmac -> clk && freq )
225
+ if (freq )
226
226
clk_set_rate (dwmac -> clk , freq );
227
227
228
228
regmap_update_bits (dwmac -> regmap , reg , STID127_RETIME_SRC_MASK , val );
229
229
}
230
230
231
- static int sti_dwmac_init (struct platform_device * pdev , void * priv )
231
+ static int sti_dwmac_set_mode (struct sti_dwmac * dwmac )
232
232
{
233
- struct sti_dwmac * dwmac = priv ;
234
233
struct regmap * regmap = dwmac -> regmap ;
235
234
int iface = dwmac -> interface ;
236
- struct device * dev = dwmac -> dev ;
237
- struct device_node * np = dev -> of_node ;
238
235
u32 reg = dwmac -> ctrl_reg ;
239
236
u32 val ;
240
237
241
- if (dwmac -> clk )
242
- clk_prepare_enable (dwmac -> clk );
243
-
244
- if (of_property_read_bool (np , "st,gmac_en" ))
238
+ if (dwmac -> gmac_en )
245
239
regmap_update_bits (regmap , reg , EN_MASK , EN );
246
240
247
241
regmap_update_bits (regmap , reg , MII_PHY_SEL_MASK , phy_intf_sels [iface ]);
248
242
249
243
val = (iface == PHY_INTERFACE_MODE_REVMII ) ? 0 : ENMII ;
250
244
regmap_update_bits (regmap , reg , ENMII_MASK , val );
251
245
252
- dwmac -> fix_retime_src (priv , dwmac -> speed );
246
+ dwmac -> fix_retime_src (dwmac , dwmac -> speed );
253
247
254
248
return 0 ;
255
249
}
256
250
257
- static void sti_dwmac_exit (struct platform_device * pdev , void * priv )
258
- {
259
- struct sti_dwmac * dwmac = priv ;
260
-
261
- if (dwmac -> clk )
262
- clk_disable_unprepare (dwmac -> clk );
263
- }
264
251
static int sti_dwmac_parse_data (struct sti_dwmac * dwmac ,
265
252
struct platform_device * pdev )
266
253
{
@@ -270,9 +257,6 @@ static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
270
257
struct regmap * regmap ;
271
258
int err ;
272
259
273
- if (!np )
274
- return - EINVAL ;
275
-
276
260
/* clk selection from extra syscfg register */
277
261
dwmac -> clk_sel_reg = - ENXIO ;
278
262
res = platform_get_resource_byname (pdev , IORESOURCE_MEM , "sti-clkconf" );
@@ -289,9 +273,9 @@ static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
289
273
return err ;
290
274
}
291
275
292
- dwmac -> dev = dev ;
293
276
dwmac -> interface = of_get_phy_mode (np );
294
277
dwmac -> regmap = regmap ;
278
+ dwmac -> gmac_en = of_property_read_bool (np , "st,gmac_en" );
295
279
dwmac -> ext_phyclk = of_property_read_bool (np , "st,ext-phyclk" );
296
280
dwmac -> tx_retime_src = TX_RETIME_SRC_NA ;
297
281
dwmac -> speed = SPEED_100 ;
@@ -357,17 +341,62 @@ static int sti_dwmac_probe(struct platform_device *pdev)
357
341
dwmac -> fix_retime_src = data -> fix_retime_src ;
358
342
359
343
plat_dat -> bsp_priv = dwmac ;
360
- plat_dat -> init = sti_dwmac_init ;
361
- plat_dat -> exit = sti_dwmac_exit ;
362
344
plat_dat -> fix_mac_speed = data -> fix_retime_src ;
363
345
364
- ret = sti_dwmac_init ( pdev , plat_dat -> bsp_priv );
346
+ ret = clk_prepare_enable ( dwmac -> clk );
365
347
if (ret )
366
348
return ret ;
367
349
368
- return stmmac_dvr_probe (& pdev -> dev , plat_dat , & stmmac_res );
350
+ ret = sti_dwmac_set_mode (dwmac );
351
+ if (ret )
352
+ goto disable_clk ;
353
+
354
+ ret = stmmac_dvr_probe (& pdev -> dev , plat_dat , & stmmac_res );
355
+ if (ret )
356
+ goto disable_clk ;
357
+
358
+ return 0 ;
359
+
360
+ disable_clk :
361
+ clk_disable_unprepare (dwmac -> clk );
362
+ return ret ;
369
363
}
370
364
365
+ static int sti_dwmac_remove (struct platform_device * pdev )
366
+ {
367
+ struct sti_dwmac * dwmac = get_stmmac_bsp_priv (& pdev -> dev );
368
+ int ret = stmmac_dvr_remove (& pdev -> dev );
369
+
370
+ clk_disable_unprepare (dwmac -> clk );
371
+
372
+ return ret ;
373
+ }
374
+
375
+ #ifdef CONFIG_PM_SLEEP
376
+ static int sti_dwmac_suspend (struct device * dev )
377
+ {
378
+ struct sti_dwmac * dwmac = get_stmmac_bsp_priv (dev );
379
+ int ret = stmmac_suspend (dev );
380
+
381
+ clk_disable_unprepare (dwmac -> clk );
382
+
383
+ return ret ;
384
+ }
385
+
386
+ static int sti_dwmac_resume (struct device * dev )
387
+ {
388
+ struct sti_dwmac * dwmac = get_stmmac_bsp_priv (dev );
389
+
390
+ clk_prepare_enable (dwmac -> clk );
391
+ sti_dwmac_set_mode (dwmac );
392
+
393
+ return stmmac_resume (dev );
394
+ }
395
+ #endif /* CONFIG_PM_SLEEP */
396
+
397
+ static SIMPLE_DEV_PM_OPS (sti_dwmac_pm_ops , sti_dwmac_suspend ,
398
+ sti_dwmac_resume ) ;
399
+
371
400
static const struct sti_dwmac_of_data stih4xx_dwmac_data = {
372
401
.fix_retime_src = stih4xx_fix_retime_src ,
373
402
};
@@ -387,10 +416,10 @@ MODULE_DEVICE_TABLE(of, sti_dwmac_match);
387
416
388
417
static struct platform_driver sti_dwmac_driver = {
389
418
.probe = sti_dwmac_probe ,
390
- .remove = stmmac_pltfr_remove ,
419
+ .remove = sti_dwmac_remove ,
391
420
.driver = {
392
421
.name = "sti-dwmac" ,
393
- .pm = & stmmac_pltfr_pm_ops ,
422
+ .pm = & sti_dwmac_pm_ops ,
394
423
.of_match_table = sti_dwmac_match ,
395
424
},
396
425
};
0 commit comments