@@ -104,18 +104,20 @@ static int dwmac1000_validate_ucast_entries(int ucast_entries)
104
104
* this function is to read the driver parameters from device-tree and
105
105
* set some private fields that will be used by the main at runtime.
106
106
*/
107
- static int stmmac_probe_config_dt (struct platform_device * pdev ,
108
- struct plat_stmmacenet_data * plat ,
109
- const char * * mac )
107
+ struct plat_stmmacenet_data *
108
+ stmmac_probe_config_dt (struct platform_device * pdev , const char * * mac )
110
109
{
111
110
struct device_node * np = pdev -> dev .of_node ;
111
+ struct plat_stmmacenet_data * plat ;
112
+ const struct stmmac_of_data * data ;
112
113
struct stmmac_dma_cfg * dma_cfg ;
113
- const struct of_device_id * device ;
114
- struct device * dev = & pdev -> dev ;
115
114
116
- device = of_match_device (dev -> driver -> of_match_table , dev );
117
- if (device -> data ) {
118
- const struct stmmac_of_data * data = device -> data ;
115
+ plat = devm_kzalloc (& pdev -> dev , sizeof (* plat ), GFP_KERNEL );
116
+ if (!plat )
117
+ return ERR_PTR (- ENOMEM );
118
+
119
+ data = of_device_get_match_data (& pdev -> dev );
120
+ if (data ) {
119
121
plat -> has_gmac = data -> has_gmac ;
120
122
plat -> enh_desc = data -> enh_desc ;
121
123
plat -> tx_coe = data -> tx_coe ;
@@ -151,7 +153,7 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
151
153
/* If phy-handle is not specified, check if we have a fixed-phy */
152
154
if (!plat -> phy_node && of_phy_is_fixed_link (np )) {
153
155
if ((of_phy_register_fixed_link (np ) < 0 ))
154
- return - ENODEV ;
156
+ return ERR_PTR ( - ENODEV ) ;
155
157
156
158
plat -> phy_node = of_node_get (np );
157
159
}
@@ -182,6 +184,12 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
182
184
*/
183
185
plat -> maxmtu = JUMBO_LEN ;
184
186
187
+ /* Set default value for multicast hash bins */
188
+ plat -> multicast_filter_bins = HASH_TABLE_SIZE ;
189
+
190
+ /* Set default value for unicast filter entries */
191
+ plat -> unicast_filter_entries = 1 ;
192
+
185
193
/*
186
194
* Currently only the properties needed on SPEAr600
187
195
* are provided. All other properties should be added
@@ -222,7 +230,7 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
222
230
GFP_KERNEL );
223
231
if (!dma_cfg ) {
224
232
of_node_put (np );
225
- return - ENOMEM ;
233
+ return ERR_PTR ( - ENOMEM ) ;
226
234
}
227
235
plat -> dma_cfg = dma_cfg ;
228
236
of_property_read_u32 (np , "snps,pbl" , & dma_cfg -> pbl );
@@ -240,44 +248,34 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
240
248
pr_warn ("force_sf_dma_mode is ignored if force_thresh_dma_mode is set." );
241
249
}
242
250
243
- return 0 ;
251
+ return plat ;
244
252
}
245
253
#else
246
- static int stmmac_probe_config_dt (struct platform_device * pdev ,
247
- struct plat_stmmacenet_data * plat ,
248
- const char * * mac )
254
+ struct plat_stmmacenet_data *
255
+ stmmac_probe_config_dt (struct platform_device * pdev , const char * * mac )
249
256
{
250
- return - ENOSYS ;
257
+ return ERR_PTR ( - ENOSYS ) ;
251
258
}
252
259
#endif /* CONFIG_OF */
260
+ EXPORT_SYMBOL_GPL (stmmac_probe_config_dt );
253
261
254
- /**
255
- * stmmac_pltfr_probe - platform driver probe.
256
- * @pdev: platform device pointer
257
- * Description: platform_device probe function. It is to allocate
258
- * the necessary platform resources, invoke custom helper (if required) and
259
- * invoke the main probe function.
260
- */
261
- int stmmac_pltfr_probe (struct platform_device * pdev )
262
+ int stmmac_get_platform_resources (struct platform_device * pdev ,
263
+ struct stmmac_resources * stmmac_res )
262
264
{
263
- struct stmmac_resources stmmac_res ;
264
- int ret = 0 ;
265
265
struct resource * res ;
266
- struct device * dev = & pdev -> dev ;
267
- struct plat_stmmacenet_data * plat_dat = NULL ;
268
266
269
- memset (& stmmac_res , 0 , sizeof (stmmac_res ));
267
+ memset (stmmac_res , 0 , sizeof (* stmmac_res ));
270
268
271
269
/* Get IRQ information early to have an ability to ask for deferred
272
270
* probe if needed before we went too far with resource allocation.
273
271
*/
274
- stmmac_res . irq = platform_get_irq_byname (pdev , "macirq" );
275
- if (stmmac_res . irq < 0 ) {
276
- if (stmmac_res . irq != - EPROBE_DEFER ) {
277
- dev_err (dev ,
272
+ stmmac_res -> irq = platform_get_irq_byname (pdev , "macirq" );
273
+ if (stmmac_res -> irq < 0 ) {
274
+ if (stmmac_res -> irq != - EPROBE_DEFER ) {
275
+ dev_err (& pdev -> dev ,
278
276
"MAC IRQ configuration information not found\n" );
279
277
}
280
- return stmmac_res . irq ;
278
+ return stmmac_res -> irq ;
281
279
}
282
280
283
281
/* On some platforms e.g. SPEAr the wake up irq differs from the mac irq
@@ -287,45 +285,61 @@ int stmmac_pltfr_probe(struct platform_device *pdev)
287
285
* In case the wake up interrupt is not passed from the platform
288
286
* so the driver will continue to use the mac irq (ndev->irq)
289
287
*/
290
- stmmac_res . wol_irq = platform_get_irq_byname (pdev , "eth_wake_irq" );
291
- if (stmmac_res . wol_irq < 0 ) {
292
- if (stmmac_res . wol_irq == - EPROBE_DEFER )
288
+ stmmac_res -> wol_irq = platform_get_irq_byname (pdev , "eth_wake_irq" );
289
+ if (stmmac_res -> wol_irq < 0 ) {
290
+ if (stmmac_res -> wol_irq == - EPROBE_DEFER )
293
291
return - EPROBE_DEFER ;
294
- stmmac_res . wol_irq = stmmac_res . irq ;
292
+ stmmac_res -> wol_irq = stmmac_res -> irq ;
295
293
}
296
294
297
- stmmac_res . lpi_irq = platform_get_irq_byname (pdev , "eth_lpi" );
298
- if (stmmac_res . lpi_irq == - EPROBE_DEFER )
295
+ stmmac_res -> lpi_irq = platform_get_irq_byname (pdev , "eth_lpi" );
296
+ if (stmmac_res -> lpi_irq == - EPROBE_DEFER )
299
297
return - EPROBE_DEFER ;
300
298
301
299
res = platform_get_resource (pdev , IORESOURCE_MEM , 0 );
302
- stmmac_res .addr = devm_ioremap_resource (dev , res );
303
- if (IS_ERR (stmmac_res .addr ))
304
- return PTR_ERR (stmmac_res .addr );
305
-
306
- plat_dat = dev_get_platdata (& pdev -> dev );
307
-
308
- if (!plat_dat )
309
- plat_dat = devm_kzalloc (& pdev -> dev ,
310
- sizeof (struct plat_stmmacenet_data ),
311
- GFP_KERNEL );
312
- if (!plat_dat ) {
313
- pr_err ("%s: ERROR: no memory" , __func__ );
314
- return - ENOMEM ;
315
- }
300
+ stmmac_res -> addr = devm_ioremap_resource (& pdev -> dev , res );
301
+ if (IS_ERR (stmmac_res -> addr ))
302
+ return PTR_ERR (stmmac_res -> addr );
316
303
317
- /* Set default value for multicast hash bins */
318
- plat_dat -> multicast_filter_bins = HASH_TABLE_SIZE ;
304
+ return 0 ;
305
+ }
306
+ EXPORT_SYMBOL_GPL (stmmac_get_platform_resources );
319
307
320
- /* Set default value for unicast filter entries */
321
- plat_dat -> unicast_filter_entries = 1 ;
308
+ /**
309
+ * stmmac_pltfr_probe - platform driver probe.
310
+ * @pdev: platform device pointer
311
+ * Description: platform_device probe function. It is to allocate
312
+ * the necessary platform resources, invoke custom helper (if required) and
313
+ * invoke the main probe function.
314
+ */
315
+ int stmmac_pltfr_probe (struct platform_device * pdev )
316
+ {
317
+ struct plat_stmmacenet_data * plat_dat ;
318
+ struct stmmac_resources stmmac_res ;
319
+ int ret ;
320
+
321
+ ret = stmmac_get_platform_resources (pdev , & stmmac_res );
322
+ if (ret )
323
+ return ret ;
322
324
323
325
if (pdev -> dev .of_node ) {
324
- ret = stmmac_probe_config_dt (pdev , plat_dat , & stmmac_res .mac );
325
- if (ret ) {
326
- pr_err ("%s: main dt probe failed" , __func__ );
327
- return ret ;
326
+ plat_dat = stmmac_probe_config_dt (pdev , & stmmac_res .mac );
327
+ if (IS_ERR (plat_dat )) {
328
+ dev_err (& pdev -> dev , "dt configuration failed\n" );
329
+ return PTR_ERR (plat_dat );
330
+ }
331
+ } else {
332
+ plat_dat = dev_get_platdata (& pdev -> dev );
333
+ if (!plat_dat ) {
334
+ dev_err (& pdev -> dev , "no platform data provided\n" );
335
+ return - EINVAL ;
328
336
}
337
+
338
+ /* Set default value for multicast hash bins */
339
+ plat_dat -> multicast_filter_bins = HASH_TABLE_SIZE ;
340
+
341
+ /* Set default value for unicast filter entries */
342
+ plat_dat -> unicast_filter_entries = 1 ;
329
343
}
330
344
331
345
/* Custom setup (if needed) */
0 commit comments