Skip to content

Commit c5d28e2

Browse files
Ulf Hanssonmchehab
authored andcommitted
[media] coda: Improve runtime PM support
For several reasons it's good practice to leave devices in runtime PM active state while those have been probed. In this cases we also want to prevent the device from going inactive, until the firmware has been completely installed, especially when using a PM domain. Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Kamil Debski <k.debski@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
1 parent 7c67281 commit c5d28e2

1 file changed

Lines changed: 21 additions & 34 deletions

File tree

‎drivers/media/platform/coda/coda-common.c‎

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,58 +1688,35 @@ static void coda_fw_callback(const struct firmware *fw, void *context)
16881688

16891689
if (!fw) {
16901690
v4l2_err(&dev->v4l2_dev, "firmware request failed\n");
1691-
return;
1691+
goto put_pm;
16921692
}
16931693

16941694
/* allocate auxiliary per-device code buffer for the BIT processor */
16951695
ret = coda_alloc_aux_buf(dev, &dev->codebuf, fw->size, "codebuf",
16961696
dev->debugfs_root);
16971697
if (ret < 0) {
16981698
dev_err(&pdev->dev, "failed to allocate code buffer\n");
1699-
return;
1699+
goto put_pm;
17001700
}
17011701

17021702
/* Copy the whole firmware image to the code buffer */
17031703
memcpy(dev->codebuf.vaddr, fw->data, fw->size);
17041704
release_firmware(fw);
17051705

1706-
if (pm_runtime_enabled(&pdev->dev) && pdev->dev.pm_domain) {
1707-
/*
1708-
* Enabling power temporarily will cause coda_hw_init to be
1709-
* called via coda_runtime_resume by the pm domain.
1710-
*/
1711-
ret = pm_runtime_get_sync(&dev->plat_dev->dev);
1712-
if (ret < 0) {
1713-
v4l2_err(&dev->v4l2_dev, "failed to power on: %d\n",
1714-
ret);
1715-
return;
1716-
}
1717-
1718-
ret = coda_check_firmware(dev);
1719-
if (ret < 0)
1720-
return;
1721-
1722-
pm_runtime_put_sync(&dev->plat_dev->dev);
1723-
} else {
1724-
/*
1725-
* If runtime pm is disabled or pm_domain is not set,
1726-
* initialize once manually.
1727-
*/
1728-
ret = coda_hw_init(dev);
1729-
if (ret < 0) {
1730-
v4l2_err(&dev->v4l2_dev, "HW initialization failed\n");
1731-
return;
1732-
}
1733-
1734-
ret = coda_check_firmware(dev);
1735-
if (ret < 0)
1736-
return;
1706+
ret = coda_hw_init(dev);
1707+
if (ret < 0) {
1708+
v4l2_err(&dev->v4l2_dev, "HW initialization failed\n");
1709+
goto put_pm;
17371710
}
17381711

1712+
ret = coda_check_firmware(dev);
1713+
if (ret < 0)
1714+
goto put_pm;
1715+
17391716
dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
17401717
if (IS_ERR(dev->alloc_ctx)) {
17411718
v4l2_err(&dev->v4l2_dev, "Failed to alloc vb2 context\n");
1742-
return;
1719+
goto put_pm;
17431720
}
17441721

17451722
dev->m2m_dev = v4l2_m2m_init(&coda_m2m_ops);
@@ -1771,12 +1748,15 @@ static void coda_fw_callback(const struct firmware *fw, void *context)
17711748
v4l2_info(&dev->v4l2_dev, "codec registered as /dev/video[%d-%d]\n",
17721749
dev->vfd[0].num, dev->vfd[1].num);
17731750

1751+
pm_runtime_put_sync(&pdev->dev);
17741752
return;
17751753

17761754
rel_m2m:
17771755
v4l2_m2m_release(dev->m2m_dev);
17781756
rel_ctx:
17791757
vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
1758+
put_pm:
1759+
pm_runtime_put_sync(&pdev->dev);
17801760
}
17811761

17821762
static int coda_firmware_request(struct coda_dev *dev)
@@ -1998,6 +1978,13 @@ static int coda_probe(struct platform_device *pdev)
19981978

19991979
platform_set_drvdata(pdev, dev);
20001980

1981+
/*
1982+
* Start activated so we can directly call coda_hw_init in
1983+
* coda_fw_callback regardless of whether CONFIG_PM_RUNTIME is
1984+
* enabled or whether the device is associated with a PM domain.
1985+
*/
1986+
pm_runtime_get_noresume(&pdev->dev);
1987+
pm_runtime_set_active(&pdev->dev);
20011988
pm_runtime_enable(&pdev->dev);
20021989

20031990
return coda_firmware_request(dev);

0 commit comments

Comments
 (0)