58f90db46dafa43aa60eaff6ec6ad6db770d0ab4
[openwrt/openwrt.git] / target / linux / at91 / patches-5.10 / 155-media-atmel-properly-get-pm_runtime.patch
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
5
6 There are several issues in the way the atmel driver handles
7 pm_runtime_get_sync():
8
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.
14
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.
18
19 With that, add additional checks when this is called, in order
20 to ensure that errors will be properly addressed.
21
22 Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
23 ---
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(-)
27
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)
32 {
33 struct isc_clk *isc_clk = to_isc_clk(hw);
34 + int ret;
35
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);
40 + if (ret < 0)
41 + return ret;
42 + }
43
44 return isc_wait_clk_stable(hw);
45 }
46 @@ -353,9 +357,13 @@ static int isc_clk_is_enabled(struct clk
47 {
48 struct isc_clk *isc_clk = to_isc_clk(hw);
49 u32 status;
50 + int ret;
51
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);
56 + if (ret < 0)
57 + return 0;
58 + }
59
60 regmap_read(isc_clk->regmap, ISC_CLKSR, &status);
61
62 @@ -807,7 +815,12 @@ static int isc_start_streaming(struct vb
63 goto err_start_stream;
64 }
65
66 - pm_runtime_get_sync(isc->dev);
67 + ret = pm_runtime_resume_and_get(isc->dev);
68 + if (ret < 0) {
69 + v4l2_err(&isc->v4l2_dev, "RPM resume failed in subdev %d\n",
70 + ret);
71 + goto err_pm_get;
72 + }
73
74 ret = isc_configure(isc);
75 if (unlikely(ret))
76 @@ -838,7 +851,7 @@ static int isc_start_streaming(struct vb
77
78 err_configure:
79 pm_runtime_put_sync(isc->dev);
80 -
81 +err_pm_get:
82 v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0);
83
84 err_start_stream:
85 @@ -1809,6 +1822,7 @@ static void isc_awb_work(struct work_str
86 u32 baysel;
87 unsigned long flags;
88 u32 min, max;
89 + int ret;
90
91 /* streaming is not active anymore */
92 if (isc->stop)
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;
96
97 - pm_runtime_get_sync(isc->dev);
98 + ret = pm_runtime_resume_and_get(isc->dev);
99 + if (ret < 0)
100 + return;
101
102 /*
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;
108 int ret;
109
110 - pm_runtime_get_sync(isi->dev);
111 + ret = pm_runtime_resume_and_get(isi->dev);
112 + if (ret < 0)
113 + return ret;
114
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
118 return 0;
119 }
120
121 -static void isi_camera_set_bus_param(struct atmel_isi *isi)
122 +static int isi_camera_set_bus_param(struct atmel_isi *isi)
123 {
124 u32 cfg1 = 0;
125 + int ret;
126
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;
131
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);
135 + if (ret < 0)
136 + return ret;
137
138 isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
139 isi_writel(isi, ISI_CFG1, cfg1);
140
141 pm_runtime_put(isi->dev);
142 +
143 + return 0;
144 }
145
146 /* -----------------------------------------------------------------------*/
147 @@ -1086,7 +1093,11 @@ static int isi_graph_notify_complete(str
148 dev_err(isi->dev, "No supported mediabus format found\n");
149 return ret;
150 }
151 - isi_camera_set_bus_param(isi);
152 + ret = isi_camera_set_bus_param(isi);
153 + if (ret) {
154 + dev_err(isi->dev, "Can't wake up device\n");
155 + return ret;
156 + }
157
158 ret = isi_set_default_fmt(isi);
159 if (ret) {