Skip to content

Commit

Permalink
media: imx: imx8mq-mipi_csi2: fix system resume
Browse files Browse the repository at this point in the history
[ Upstream commit f0c2ba1 ]

during system resume, interconnect bandwidth would currently be requested
even though the device is runtime suspended. This leaves the system in an
unbalanced state.

Fix that by only doing that in runtimem pm and splitting up runtime and
system suspend to be a more readable:
imx8mq_mipi_csi_pm_*() does the generic things called from system- and
runtime functions that each do specific things on top.

Fixes: f33fd8d ("media: imx: add a driver for i.MX8MQ mipi csi rx phy and controller")
Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
merge authored and gregkh committed Apr 8, 2022
1 parent ec51f0a commit efac3af
Showing 1 changed file with 47 additions and 24 deletions.
71 changes: 47 additions & 24 deletions drivers/staging/media/imx/imx8mq-mipi-csi2.c
Expand Up @@ -693,7 +693,7 @@ static int imx8mq_mipi_csi_async_register(struct csi_state *state)
* Suspend/resume
*/

static int imx8mq_mipi_csi_pm_suspend(struct device *dev, bool runtime)
static int imx8mq_mipi_csi_pm_suspend(struct device *dev)
{
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct csi_state *state = mipi_sd_to_csi2_state(sd);
Expand All @@ -705,36 +705,21 @@ static int imx8mq_mipi_csi_pm_suspend(struct device *dev, bool runtime)
imx8mq_mipi_csi_stop_stream(state);
imx8mq_mipi_csi_clk_disable(state);
state->state &= ~ST_POWERED;
if (!runtime)
state->state |= ST_SUSPENDED;
}

mutex_unlock(&state->lock);

ret = icc_set_bw(state->icc_path, 0, 0);
if (ret)
dev_err(dev, "icc_set_bw failed with %d\n", ret);

return ret ? -EAGAIN : 0;
}

static int imx8mq_mipi_csi_pm_resume(struct device *dev, bool runtime)
static int imx8mq_mipi_csi_pm_resume(struct device *dev)
{
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct csi_state *state = mipi_sd_to_csi2_state(sd);
int ret = 0;

ret = icc_set_bw(state->icc_path, 0, state->icc_path_bw);
if (ret) {
dev_err(dev, "icc_set_bw failed with %d\n", ret);
return ret;
}

mutex_lock(&state->lock);

if (!runtime && !(state->state & ST_SUSPENDED))
goto unlock;

if (!(state->state & ST_POWERED)) {
state->state |= ST_POWERED;
ret = imx8mq_mipi_csi_clk_enable(state);
Expand All @@ -755,22 +740,60 @@ static int imx8mq_mipi_csi_pm_resume(struct device *dev, bool runtime)

static int __maybe_unused imx8mq_mipi_csi_suspend(struct device *dev)
{
return imx8mq_mipi_csi_pm_suspend(dev, false);
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct csi_state *state = mipi_sd_to_csi2_state(sd);
int ret;

ret = imx8mq_mipi_csi_pm_suspend(dev);
if (ret)
return ret;

state->state |= ST_SUSPENDED;

return ret;
}

static int __maybe_unused imx8mq_mipi_csi_resume(struct device *dev)
{
return imx8mq_mipi_csi_pm_resume(dev, false);
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct csi_state *state = mipi_sd_to_csi2_state(sd);

if (!(state->state & ST_SUSPENDED))
return 0;

return imx8mq_mipi_csi_pm_resume(dev);
}

static int __maybe_unused imx8mq_mipi_csi_runtime_suspend(struct device *dev)
{
return imx8mq_mipi_csi_pm_suspend(dev, true);
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct csi_state *state = mipi_sd_to_csi2_state(sd);
int ret;

ret = imx8mq_mipi_csi_pm_suspend(dev);
if (ret)
return ret;

ret = icc_set_bw(state->icc_path, 0, 0);
if (ret)
dev_err(dev, "icc_set_bw failed with %d\n", ret);

return ret;
}

static int __maybe_unused imx8mq_mipi_csi_runtime_resume(struct device *dev)
{
return imx8mq_mipi_csi_pm_resume(dev, true);
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct csi_state *state = mipi_sd_to_csi2_state(sd);
int ret;

ret = icc_set_bw(state->icc_path, 0, state->icc_path_bw);
if (ret) {
dev_err(dev, "icc_set_bw failed with %d\n", ret);
return ret;
}

return imx8mq_mipi_csi_pm_resume(dev);
}

static const struct dev_pm_ops imx8mq_mipi_csi_pm_ops = {
Expand Down Expand Up @@ -918,7 +941,7 @@ static int imx8mq_mipi_csi_probe(struct platform_device *pdev)
/* Enable runtime PM. */
pm_runtime_enable(dev);
if (!pm_runtime_enabled(dev)) {
ret = imx8mq_mipi_csi_pm_resume(dev, true);
ret = imx8mq_mipi_csi_runtime_resume(dev);
if (ret < 0)
goto icc;
}
Expand All @@ -931,7 +954,7 @@ static int imx8mq_mipi_csi_probe(struct platform_device *pdev)

cleanup:
pm_runtime_disable(&pdev->dev);
imx8mq_mipi_csi_pm_suspend(&pdev->dev, true);
imx8mq_mipi_csi_runtime_suspend(&pdev->dev);

media_entity_cleanup(&state->sd.entity);
v4l2_async_nf_unregister(&state->notifier);
Expand All @@ -955,7 +978,7 @@ static int imx8mq_mipi_csi_remove(struct platform_device *pdev)
v4l2_async_unregister_subdev(&state->sd);

pm_runtime_disable(&pdev->dev);
imx8mq_mipi_csi_pm_suspend(&pdev->dev, true);
imx8mq_mipi_csi_runtime_suspend(&pdev->dev);
media_entity_cleanup(&state->sd.entity);
mutex_destroy(&state->lock);
pm_runtime_set_suspended(&pdev->dev);
Expand Down

0 comments on commit efac3af

Please sign in to comment.