1 From c7660cc977621c4a14d870d523918df067f0db39 Mon Sep 17 00:00:00 2001
2 From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
3 Date: Fri, 23 Apr 2021 16:47:42 +0200
4 Subject: [PATCH 155/247] media: atmel: properly get pm_runtime
6 There are several issues in the way the atmel driver handles
9 - it doesn't check return codes;
10 - it doesn't properly decrement the usage_count on all places;
11 - it starts streaming even if pm_runtime_get_sync() fails.
12 - while it tries to get pm_runtime at the clock enable logic,
13 it doesn't check if the operation was suceeded.
15 Replace all occurrences of it to use the new kAPI:
16 pm_runtime_resume_and_get(), which ensures that, if the
17 return code is not negative, the usage_count was incremented.
19 With that, add additional checks when this is called, in order
20 to ensure that errors will be properly addressed.
22 Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
24 drivers/media/platform/atmel/atmel-isc-base.c | 30 ++++++++++++++-----
25 drivers/media/platform/atmel/atmel-isi.c | 19 +++++++++---
26 2 files changed, 38 insertions(+), 11 deletions(-)
28 --- a/drivers/media/platform/atmel/atmel-isc-base.c
29 +++ b/drivers/media/platform/atmel/atmel-isc-base.c
30 @@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct cl
31 static int isc_clk_prepare(struct clk_hw *hw)
33 struct isc_clk *isc_clk = to_isc_clk(hw);
36 - if (isc_clk->id == ISC_ISPCK)
37 - pm_runtime_get_sync(isc_clk->dev);
38 + if (isc_clk->id == ISC_ISPCK) {
39 + ret = pm_runtime_resume_and_get(isc_clk->dev);
44 return isc_wait_clk_stable(hw);
46 @@ -353,9 +357,13 @@ static int isc_clk_is_enabled(struct clk
48 struct isc_clk *isc_clk = to_isc_clk(hw);
52 - if (isc_clk->id == ISC_ISPCK)
53 - pm_runtime_get_sync(isc_clk->dev);
54 + if (isc_clk->id == ISC_ISPCK) {
55 + ret = pm_runtime_resume_and_get(isc_clk->dev);
60 regmap_read(isc_clk->regmap, ISC_CLKSR, &status);
62 @@ -807,7 +815,12 @@ static int isc_start_streaming(struct vb
63 goto err_start_stream;
66 - pm_runtime_get_sync(isc->dev);
67 + ret = pm_runtime_resume_and_get(isc->dev);
69 + v4l2_err(&isc->v4l2_dev, "RPM resume failed in subdev %d\n",
74 ret = isc_configure(isc);
76 @@ -838,7 +851,7 @@ static int isc_start_streaming(struct vb
79 pm_runtime_put_sync(isc->dev);
82 v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0);
85 @@ -1809,6 +1822,7 @@ static void isc_awb_work(struct work_str
91 /* streaming is not active anymore */
93 @@ -1831,7 +1845,9 @@ static void isc_awb_work(struct work_str
94 ctrls->hist_id = hist_id;
95 baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
97 - pm_runtime_get_sync(isc->dev);
98 + ret = pm_runtime_resume_and_get(isc->dev);
103 * only update if we have all the required histograms and controls
104 --- a/drivers/media/platform/atmel/atmel-isi.c
105 +++ b/drivers/media/platform/atmel/atmel-isi.c
106 @@ -423,7 +423,9 @@ static int start_streaming(struct vb2_qu
107 struct frame_buffer *buf, *node;
110 - pm_runtime_get_sync(isi->dev);
111 + ret = pm_runtime_resume_and_get(isi->dev);
115 /* Enable stream on the sub device */
116 ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 1);
117 @@ -783,9 +785,10 @@ static int isi_enum_frameintervals(struc
121 -static void isi_camera_set_bus_param(struct atmel_isi *isi)
122 +static int isi_camera_set_bus_param(struct atmel_isi *isi)
127 /* set bus param for ISI */
128 if (isi->pdata.hsync_act_low)
129 @@ -802,12 +805,16 @@ static void isi_camera_set_bus_param(str
130 cfg1 |= ISI_CFG1_THMASK_BEATS_16;
132 /* Enable PM and peripheral clock before operate isi registers */
133 - pm_runtime_get_sync(isi->dev);
134 + ret = pm_runtime_resume_and_get(isi->dev);
138 isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
139 isi_writel(isi, ISI_CFG1, cfg1);
141 pm_runtime_put(isi->dev);
146 /* -----------------------------------------------------------------------*/
147 @@ -1086,7 +1093,11 @@ static int isi_graph_notify_complete(str
148 dev_err(isi->dev, "No supported mediabus format found\n");
151 - isi_camera_set_bus_param(isi);
152 + ret = isi_camera_set_bus_param(isi);
154 + dev_err(isi->dev, "Can't wake up device\n");
158 ret = isi_set_default_fmt(isi);