@@ -395,107 +395,98 @@ static void amba_device_release(struct device *dev)
395
395
kfree (d );
396
396
}
397
397
398
- static int amba_device_try_add (struct amba_device * dev , struct resource * parent )
398
+ static int amba_read_periphid (struct amba_device * dev )
399
399
{
400
- u32 size ;
400
+ struct reset_control * rstc ;
401
+ u32 size , pid , cid ;
401
402
void __iomem * tmp ;
402
403
int i , ret ;
403
404
404
- ret = request_resource ( parent , & dev -> res );
405
+ ret = dev_pm_domain_attach ( & dev -> dev , true );
405
406
if (ret )
406
407
goto err_out ;
407
408
408
- /* Hard-coded primecell ID instead of plug-n-play */
409
- if (dev -> periphid != 0 )
410
- goto skip_probe ;
409
+ ret = amba_get_enable_pclk ( dev );
410
+ if (ret )
411
+ goto err_pm ;
411
412
412
413
/*
413
- * Dynamically calculate the size of the resource
414
- * and use this for iomap
414
+ * Find reset control(s) of the amba bus and de-assert them.
415
415
*/
416
+ rstc = of_reset_control_array_get_optional_shared (dev -> dev .of_node );
417
+ if (IS_ERR (rstc )) {
418
+ ret = PTR_ERR (rstc );
419
+ if (ret != - EPROBE_DEFER )
420
+ dev_err (& dev -> dev , "can't get reset: %d\n" , ret );
421
+ goto err_clk ;
422
+ }
423
+ reset_control_deassert (rstc );
424
+ reset_control_put (rstc );
425
+
416
426
size = resource_size (& dev -> res );
417
427
tmp = ioremap (dev -> res .start , size );
418
428
if (!tmp ) {
419
429
ret = - ENOMEM ;
420
- goto err_release ;
430
+ goto err_clk ;
421
431
}
422
432
423
- ret = dev_pm_domain_attach (& dev -> dev , true);
424
- if (ret ) {
425
- iounmap (tmp );
426
- goto err_release ;
427
- }
428
-
429
- ret = amba_get_enable_pclk (dev );
430
- if (ret == 0 ) {
431
- u32 pid , cid ;
432
- struct reset_control * rstc ;
433
-
434
- /*
435
- * Find reset control(s) of the amba bus and de-assert them.
436
- */
437
- rstc = of_reset_control_array_get_optional_shared (dev -> dev .of_node );
438
- if (IS_ERR (rstc )) {
439
- ret = PTR_ERR (rstc );
440
- if (ret != - EPROBE_DEFER )
441
- dev_err (& dev -> dev , "can't get reset: %d\n" ,
442
- ret );
443
- goto err_reset ;
444
- }
445
- reset_control_deassert (rstc );
446
- reset_control_put (rstc );
447
-
448
- /*
449
- * Read pid and cid based on size of resource
450
- * they are located at end of region
451
- */
452
- for (pid = 0 , i = 0 ; i < 4 ; i ++ )
453
- pid |= (readl (tmp + size - 0x20 + 4 * i ) & 255 ) <<
454
- (i * 8 );
455
- for (cid = 0 , i = 0 ; i < 4 ; i ++ )
456
- cid |= (readl (tmp + size - 0x10 + 4 * i ) & 255 ) <<
457
- (i * 8 );
458
-
459
- if (cid == CORESIGHT_CID ) {
460
- /* set the base to the start of the last 4k block */
461
- void __iomem * csbase = tmp + size - 4096 ;
462
-
463
- dev -> uci .devarch =
464
- readl (csbase + UCI_REG_DEVARCH_OFFSET );
465
- dev -> uci .devtype =
466
- readl (csbase + UCI_REG_DEVTYPE_OFFSET ) & 0xff ;
467
- }
433
+ /*
434
+ * Read pid and cid based on size of resource
435
+ * they are located at end of region
436
+ */
437
+ for (pid = 0 , i = 0 ; i < 4 ; i ++ )
438
+ pid |= (readl (tmp + size - 0x20 + 4 * i ) & 255 ) << (i * 8 );
439
+ for (cid = 0 , i = 0 ; i < 4 ; i ++ )
440
+ cid |= (readl (tmp + size - 0x10 + 4 * i ) & 255 ) << (i * 8 );
468
441
469
- amba_put_disable_pclk (dev );
442
+ if (cid == CORESIGHT_CID ) {
443
+ /* set the base to the start of the last 4k block */
444
+ void __iomem * csbase = tmp + size - 4096 ;
470
445
471
- if (cid == AMBA_CID || cid == CORESIGHT_CID ) {
472
- dev -> periphid = pid ;
473
- dev -> cid = cid ;
474
- }
446
+ dev -> uci .devarch = readl (csbase + UCI_REG_DEVARCH_OFFSET );
447
+ dev -> uci .devtype = readl (csbase + UCI_REG_DEVTYPE_OFFSET ) & 0xff ;
448
+ }
475
449
476
- if (!dev -> periphid )
477
- ret = - ENODEV ;
450
+ if (cid == AMBA_CID || cid == CORESIGHT_CID ) {
451
+ dev -> periphid = pid ;
452
+ dev -> cid = cid ;
478
453
}
479
454
455
+ if (!dev -> periphid )
456
+ ret = - ENODEV ;
457
+
480
458
iounmap (tmp );
459
+
460
+ err_clk :
461
+ amba_put_disable_pclk (dev );
462
+ err_pm :
481
463
dev_pm_domain_detach (& dev -> dev , true);
464
+ err_out :
465
+ return ret ;
466
+ }
482
467
468
+ static int amba_device_try_add (struct amba_device * dev , struct resource * parent )
469
+ {
470
+ int ret ;
471
+
472
+ ret = request_resource (parent , & dev -> res );
483
473
if (ret )
484
- goto err_release ;
474
+ goto err_out ;
475
+
476
+ /* Hard-coded primecell ID instead of plug-n-play */
477
+ if (dev -> periphid != 0 )
478
+ goto skip_probe ;
485
479
486
- skip_probe :
480
+ ret = amba_read_periphid (dev );
481
+ if (ret )
482
+ goto err_release ;
483
+ skip_probe :
487
484
ret = device_add (& dev -> dev );
488
- err_release :
485
+ err_release :
489
486
if (ret )
490
487
release_resource (& dev -> res );
491
- err_out :
488
+ err_out :
492
489
return ret ;
493
-
494
- err_reset :
495
- amba_put_disable_pclk (dev );
496
- iounmap (tmp );
497
- dev_pm_domain_detach (& dev -> dev , true);
498
- goto err_release ;
499
490
}
500
491
501
492
/*
0 commit comments