Skip to content

Commit 1f44de0

Browse files
Wang KefengRussell King (Oracle)
authored andcommitted
ARM: 9193/1: amba: Add amba_read_periphid() helper
Add new amba_read_periphid() helper to simplify error handling. Signed-off-by: Kefeng Wang <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]>
1 parent 3cfb301 commit 1f44de0

File tree

1 file changed

+62
-71
lines changed

1 file changed

+62
-71
lines changed

drivers/amba/bus.c

Lines changed: 62 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -395,107 +395,98 @@ static void amba_device_release(struct device *dev)
395395
kfree(d);
396396
}
397397

398-
static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
398+
static int amba_read_periphid(struct amba_device *dev)
399399
{
400-
u32 size;
400+
struct reset_control *rstc;
401+
u32 size, pid, cid;
401402
void __iomem *tmp;
402403
int i, ret;
403404

404-
ret = request_resource(parent, &dev->res);
405+
ret = dev_pm_domain_attach(&dev->dev, true);
405406
if (ret)
406407
goto err_out;
407408

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;
411412

412413
/*
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.
415415
*/
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+
416426
size = resource_size(&dev->res);
417427
tmp = ioremap(dev->res.start, size);
418428
if (!tmp) {
419429
ret = -ENOMEM;
420-
goto err_release;
430+
goto err_clk;
421431
}
422432

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);
468441

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;
470445

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+
}
475449

476-
if (!dev->periphid)
477-
ret = -ENODEV;
450+
if (cid == AMBA_CID || cid == CORESIGHT_CID) {
451+
dev->periphid = pid;
452+
dev->cid = cid;
478453
}
479454

455+
if (!dev->periphid)
456+
ret = -ENODEV;
457+
480458
iounmap(tmp);
459+
460+
err_clk:
461+
amba_put_disable_pclk(dev);
462+
err_pm:
481463
dev_pm_domain_detach(&dev->dev, true);
464+
err_out:
465+
return ret;
466+
}
482467

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);
483473
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;
485479

486-
skip_probe:
480+
ret = amba_read_periphid(dev);
481+
if (ret)
482+
goto err_release;
483+
skip_probe:
487484
ret = device_add(&dev->dev);
488-
err_release:
485+
err_release:
489486
if (ret)
490487
release_resource(&dev->res);
491-
err_out:
488+
err_out:
492489
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;
499490
}
500491

501492
/*

0 commit comments

Comments
 (0)