Message ID | 20220312152505.145453-2-jacopo@jmondi.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | None | expand |
Hi Jacopo, Thank you for the patch. On Sat, Mar 12, 2022 at 04:25:05PM +0100, Jacopo Mondi wrote: > The mipi_csis_device.powered flag only serves for the purpose of > not accessing registers in mipi_csis_log_status() when the interface > is not powered up. > > Instead of manually tracking the power state, rely on > pm_runtime_get_if_in_use() and remove the flag. > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> > --- > drivers/media/platform/imx/imx-mipi-csis.c | 18 ++++++++++-------- > 1 file changed, 10 insertions(+), 8 deletions(-) > > diff --git a/drivers/media/platform/imx/imx-mipi-csis.c b/drivers/media/platform/imx/imx-mipi-csis.c > index fa00b36fc394..505dd373b40c 100644 > --- a/drivers/media/platform/imx/imx-mipi-csis.c > +++ b/drivers/media/platform/imx/imx-mipi-csis.c > @@ -327,10 +327,9 @@ struct mipi_csis_device { > u32 hs_settle; > u32 clk_settle; > > - struct mutex lock; /* Protect csis_fmt, format_mbus and powered */ > + struct mutex lock; /* Protect csis_fmt and format_mbus */ > const struct csis_pix_format *csis_fmt; > struct v4l2_mbus_framefmt format_mbus[CSIS_PADS_NUM]; > - bool powered; > > spinlock_t slock; /* Protect events */ > struct mipi_csis_event events[MIPI_CSIS_NUM_EVENTS]; > @@ -1176,8 +1175,15 @@ static int mipi_csis_log_status(struct v4l2_subdev *sd) > > mutex_lock(&csis->lock); > mipi_csis_log_counters(csis, true); > - if (csis->debug.enable && csis->powered) > - mipi_csis_dump_regs(csis); > + if (!csis->debug.enable || > + !pm_runtime_get_if_in_use(csis->dev)) > + goto unlock; > + > + mipi_csis_dump_regs(csis); > + > + pm_runtime_put(csis->dev); > + > +unlock: I like this change, but I think we can go one step further and drop the lock here, as there's no powered field to access anymore: struct mipi_csis_device *csis = sd_to_mipi_csis_device(sd); mipi_csis_log_counters(csis, true); if (csis->debug.enable && pm_runtime_get_if_in_use(csi->dev)) { mipi_csis_dump_regs(csis); pm_runtime_put(csis->dev); } return 0; A third patch could then drop the lock from mipi_csis_runtime_suspend() and mipi_csis_runtime_resume(). What do you think ? > mutex_unlock(&csis->lock); > > return 0; > @@ -1344,8 +1350,6 @@ static int __maybe_unused mipi_csis_runtime_suspend(struct device *dev) > > mipi_csis_clk_disable(csis); > > - csis->powered = false; > - > unlock: > mutex_unlock(&csis->lock); > > @@ -1366,8 +1370,6 @@ static int __maybe_unused mipi_csis_runtime_resume(struct device *dev) > > mipi_csis_clk_enable(csis); > > - csis->powered = true; > - > unlock: > mutex_unlock(&csis->lock); >
diff --git a/drivers/media/platform/imx/imx-mipi-csis.c b/drivers/media/platform/imx/imx-mipi-csis.c index fa00b36fc394..505dd373b40c 100644 --- a/drivers/media/platform/imx/imx-mipi-csis.c +++ b/drivers/media/platform/imx/imx-mipi-csis.c @@ -327,10 +327,9 @@ struct mipi_csis_device { u32 hs_settle; u32 clk_settle; - struct mutex lock; /* Protect csis_fmt, format_mbus and powered */ + struct mutex lock; /* Protect csis_fmt and format_mbus */ const struct csis_pix_format *csis_fmt; struct v4l2_mbus_framefmt format_mbus[CSIS_PADS_NUM]; - bool powered; spinlock_t slock; /* Protect events */ struct mipi_csis_event events[MIPI_CSIS_NUM_EVENTS]; @@ -1176,8 +1175,15 @@ static int mipi_csis_log_status(struct v4l2_subdev *sd) mutex_lock(&csis->lock); mipi_csis_log_counters(csis, true); - if (csis->debug.enable && csis->powered) - mipi_csis_dump_regs(csis); + if (!csis->debug.enable || + !pm_runtime_get_if_in_use(csis->dev)) + goto unlock; + + mipi_csis_dump_regs(csis); + + pm_runtime_put(csis->dev); + +unlock: mutex_unlock(&csis->lock); return 0; @@ -1344,8 +1350,6 @@ static int __maybe_unused mipi_csis_runtime_suspend(struct device *dev) mipi_csis_clk_disable(csis); - csis->powered = false; - unlock: mutex_unlock(&csis->lock); @@ -1366,8 +1370,6 @@ static int __maybe_unused mipi_csis_runtime_resume(struct device *dev) mipi_csis_clk_enable(csis); - csis->powered = true; - unlock: mutex_unlock(&csis->lock);
The mipi_csis_device.powered flag only serves for the purpose of not accessing registers in mipi_csis_log_status() when the interface is not powered up. Instead of manually tracking the power state, rely on pm_runtime_get_if_in_use() and remove the flag. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> --- drivers/media/platform/imx/imx-mipi-csis.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) -- 2.35.1