diff mbox series

[v4,15/17] media: qcom: camss: Move vfe_disable into a common routine where applicable

Message ID 20230907164410.36651-16-bryan.odonoghue@linaro.org
State Superseded
Headers show
Series media: qcom: camss: Add parameter passing to remove several outstanding bugs | expand

Commit Message

Bryan O'Donoghue Sept. 7, 2023, 4:44 p.m. UTC
We can move vfe_disable() into a common routine in the core VFE file
provided we make wm_stop() a VFE specific callback.

The callback is required to capture the case where VFE 17x currently isn't
VC enabled where as VFE 480 is.

Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 .../media/platform/qcom/camss/camss-vfe-170.c | 40 +-----------------
 .../media/platform/qcom/camss/camss-vfe-480.c | 40 +-----------------
 drivers/media/platform/qcom/camss/camss-vfe.c | 42 +++++++++++++++++++
 drivers/media/platform/qcom/camss/camss-vfe.h |  9 ++++
 4 files changed, 53 insertions(+), 78 deletions(-)

Comments

Konrad Dybcio Sept. 8, 2023, 10:02 a.m. UTC | #1
On 7.09.2023 18:44, Bryan O'Donoghue wrote:
> We can move vfe_disable() into a common routine in the core VFE file
> provided we make wm_stop() a VFE specific callback.
> 
> The callback is required to capture the case where VFE 17x currently isn't
> VC enabled where as VFE 480 is.
> 
> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
Acked-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad
Konrad Dybcio Sept. 8, 2023, 10:04 a.m. UTC | #2
On 8.09.2023 12:02, Konrad Dybcio wrote:
> On 7.09.2023 18:44, Bryan O'Donoghue wrote:
>> We can move vfe_disable() into a common routine in the core VFE file
>> provided we make wm_stop() a VFE specific callback.
>>
>> The callback is required to capture the case where VFE 17x currently isn't
>> VC enabled where as VFE 480 is.
>>
>> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
>> ---
> Acked-by: Konrad Dybcio <konrad.dybcio@linaro.org>
> 
> Konrad
Actually there's 

ret = vfe_reset(vfe);

return ret;


which could just be

return vfe_reset(vfe);


Konrad
Bryan O'Donoghue Sept. 8, 2023, 10:21 a.m. UTC | #3
On 08/09/2023 11:04, Konrad Dybcio wrote:
> On 8.09.2023 12:02, Konrad Dybcio wrote:
>> On 7.09.2023 18:44, Bryan O'Donoghue wrote:
>>> We can move vfe_disable() into a common routine in the core VFE file
>>> provided we make wm_stop() a VFE specific callback.
>>>
>>> The callback is required to capture the case where VFE 17x currently isn't
>>> VC enabled where as VFE 480 is.
>>>
>>> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
>>> ---
>> Acked-by: Konrad Dybcio <konrad.dybcio@linaro.org>
>>
>> Konrad
> Actually there's
> 
> ret = vfe_reset(vfe);
> 
> return ret;
> 
> 
> which could just be
> 
> return vfe_reset(vfe);
> 
> 
> Konrad

On purpose.

I prefer the ret = ; return ret; pattern since it makes it easier / less 
work to

ret = fn();
if (ret)
     goto error;

error:
     return ret;

---
bod
Konrad Dybcio Sept. 8, 2023, 10:24 a.m. UTC | #4
On 8.09.2023 12:21, Bryan O'Donoghue wrote:
> On 08/09/2023 11:04, Konrad Dybcio wrote:
>> On 8.09.2023 12:02, Konrad Dybcio wrote:
>>> On 7.09.2023 18:44, Bryan O'Donoghue wrote:
>>>> We can move vfe_disable() into a common routine in the core VFE file
>>>> provided we make wm_stop() a VFE specific callback.
>>>>
>>>> The callback is required to capture the case where VFE 17x currently isn't
>>>> VC enabled where as VFE 480 is.
>>>>
>>>> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>>> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
>>>> ---
>>> Acked-by: Konrad Dybcio <konrad.dybcio@linaro.org>
>>>
>>> Konrad
>> Actually there's
>>
>> ret = vfe_reset(vfe);
>>
>> return ret;
>>
>>
>> which could just be
>>
>> return vfe_reset(vfe);
>>
>>
>> Konrad
> 
> On purpose.
> 
> I prefer the ret = ; return ret; pattern since it makes it easier / less work to
> 
> ret = fn();
> if (ret)
>     goto error;
> 
> error:
>     return ret;
There's no error label in vfe_disable_output

Konrad
Bryan O'Donoghue Sept. 8, 2023, 10:36 a.m. UTC | #5
On 08/09/2023 11:24, Konrad Dybcio wrote:
> On 8.09.2023 12:21, Bryan O'Donoghue wrote:
>> On 08/09/2023 11:04, Konrad Dybcio wrote:
>>> On 8.09.2023 12:02, Konrad Dybcio wrote:
>>>> On 7.09.2023 18:44, Bryan O'Donoghue wrote:
>>>>> We can move vfe_disable() into a common routine in the core VFE file
>>>>> provided we make wm_stop() a VFE specific callback.
>>>>>
>>>>> The callback is required to capture the case where VFE 17x currently isn't
>>>>> VC enabled where as VFE 480 is.
>>>>>
>>>>> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>>>> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
>>>>> ---
>>>> Acked-by: Konrad Dybcio <konrad.dybcio@linaro.org>
>>>>
>>>> Konrad
>>> Actually there's
>>>
>>> ret = vfe_reset(vfe);
>>>
>>> return ret;
>>>
>>>
>>> which could just be
>>>
>>> return vfe_reset(vfe);
>>>
>>>
>>> Konrad
>>
>> On purpose.
>>
>> I prefer the ret = ; return ret; pattern since it makes it easier / less work to
>>
>> ret = fn();
>> if (ret)
>>      goto error;
>>
>> error:
>>      return ret;
> There's no error label in vfe_disable_output
> 
> Konrad

No there is not. Its a pattern I use to make adding jump labels easier 
later on.

Just like you use the pattern of appending "," to aggregate initialisation.

---
bod
Hans Verkuil Sept. 11, 2023, 9:10 a.m. UTC | #6
On 08/09/2023 12:36, Bryan O'Donoghue wrote:
> On 08/09/2023 11:24, Konrad Dybcio wrote:
>> On 8.09.2023 12:21, Bryan O'Donoghue wrote:
>>> On 08/09/2023 11:04, Konrad Dybcio wrote:
>>>> On 8.09.2023 12:02, Konrad Dybcio wrote:
>>>>> On 7.09.2023 18:44, Bryan O'Donoghue wrote:
>>>>>> We can move vfe_disable() into a common routine in the core VFE file
>>>>>> provided we make wm_stop() a VFE specific callback.
>>>>>>
>>>>>> The callback is required to capture the case where VFE 17x currently isn't
>>>>>> VC enabled where as VFE 480 is.
>>>>>>
>>>>>> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>>>>> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
>>>>>> ---
>>>>> Acked-by: Konrad Dybcio <konrad.dybcio@linaro.org>
>>>>>
>>>>> Konrad
>>>> Actually there's
>>>>
>>>> ret = vfe_reset(vfe);
>>>>
>>>> return ret;
>>>>
>>>>
>>>> which could just be
>>>>
>>>> return vfe_reset(vfe);
>>>>
>>>>
>>>> Konrad
>>>
>>> On purpose.
>>>
>>> I prefer the ret = ; return ret; pattern since it makes it easier / less work to
>>>
>>> ret = fn();
>>> if (ret)
>>>      goto error;
>>>
>>> error:
>>>      return ret;
>> There's no error label in vfe_disable_output
>>
>> Konrad
> 
> No there is not. Its a pattern I use to make adding jump labels easier later on.

This adds a bunch of extra lines just in case something might happen in the
future. That is generally a bad idea, so please change this. As you can see
it just causes reviewers to trip over this with exactly the question you got
here.

> 
> Just like you use the pattern of appending "," to aggregate initialisation.

Adding a comma at the end doesn't add extra lines. To be honest, I don't
have a strong opinion on this either way. Personally I would probably use a
comma if it is likely that the list would be extended in the future, and
leave it out if I am pretty certain that won't happen. In any case, I don't
mind either way.

Regards,

	Hans

> 
> ---
> bod
diff mbox series

Patch

diff --git a/drivers/media/platform/qcom/camss/camss-vfe-170.c b/drivers/media/platform/qcom/camss/camss-vfe-170.c
index a5aa799501861..0b211fed12760 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-170.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-170.c
@@ -494,22 +494,6 @@  static int vfe_enable_output(struct vfe_line *line)
 	return 0;
 }
 
-static void vfe_disable_output(struct vfe_line *line)
-{
-	struct vfe_device *vfe = to_vfe(line);
-	struct vfe_output *output = &line->output;
-	unsigned long flags;
-	unsigned int i;
-
-	spin_lock_irqsave(&vfe->output_lock, flags);
-	for (i = 0; i < output->wm_num; i++)
-		vfe_wm_stop(vfe, output->wm_idx[i]);
-	output->gen2.active_num = 0;
-	spin_unlock_irqrestore(&vfe->output_lock, flags);
-
-	vfe_reset(vfe);
-}
-
 /*
  * vfe_enable - Enable streaming on VFE line
  * @line: VFE line
@@ -555,29 +539,6 @@  static int vfe_enable(struct vfe_line *line)
 	return ret;
 }
 
-/*
- * vfe_disable - Disable streaming on VFE line
- * @line: VFE line
- *
- * Return 0 on success or a negative error code otherwise
- */
-static int vfe_disable(struct vfe_line *line)
-{
-	struct vfe_device *vfe = to_vfe(line);
-
-	vfe_disable_output(line);
-
-	vfe_put_output(line);
-
-	mutex_lock(&vfe->stream_lock);
-
-	vfe->stream_count--;
-
-	mutex_unlock(&vfe->stream_lock);
-
-	return 0;
-}
-
 /*
  * vfe_isr_sof - Process start of frame interrupt
  * @vfe: VFE Device
@@ -770,4 +731,5 @@  const struct vfe_hw_ops vfe_ops_170 = {
 	.vfe_enable = vfe_enable,
 	.vfe_halt = vfe_halt,
 	.violation_read = vfe_violation_read,
+	.vfe_wm_stop = vfe_wm_stop,
 };
diff --git a/drivers/media/platform/qcom/camss/camss-vfe-480.c b/drivers/media/platform/qcom/camss/camss-vfe-480.c
index 43a2964121f22..f2368b77fc6d6 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-480.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-480.c
@@ -327,22 +327,6 @@  static int vfe_enable_output(struct vfe_line *line)
 	return 0;
 }
 
-static void vfe_disable_output(struct vfe_line *line)
-{
-	struct vfe_device *vfe = to_vfe(line);
-	struct vfe_output *output = &line->output;
-	unsigned long flags;
-	unsigned int i;
-
-	spin_lock_irqsave(&vfe->output_lock, flags);
-	for (i = 0; i < output->wm_num; i++)
-		vfe_wm_stop(vfe, output->wm_idx[i]);
-	output->gen2.active_num = 0;
-	spin_unlock_irqrestore(&vfe->output_lock, flags);
-
-	vfe_reset(vfe);
-}
-
 /*
  * vfe_enable - Enable streaming on VFE line
  * @line: VFE line
@@ -390,29 +374,6 @@  static int vfe_enable(struct vfe_line *line)
 	return ret;
 }
 
-/*
- * vfe_disable - Disable streaming on VFE line
- * @line: VFE line
- *
- * Return 0 on success or a negative error code otherwise
- */
-static int vfe_disable(struct vfe_line *line)
-{
-	struct vfe_device *vfe = to_vfe(line);
-
-	vfe_disable_output(line);
-
-	vfe_put_output(line);
-
-	mutex_lock(&vfe->stream_lock);
-
-	vfe->stream_count--;
-
-	mutex_unlock(&vfe->stream_lock);
-
-	return 0;
-}
-
 /*
  * vfe_isr_reg_update - Process reg update interrupt
  * @vfe: VFE Device
@@ -581,4 +542,5 @@  const struct vfe_hw_ops vfe_ops_480 = {
 	.vfe_disable = vfe_disable,
 	.vfe_enable = vfe_enable,
 	.vfe_halt = vfe_halt,
+	.vfe_wm_stop = vfe_wm_stop,
 };
diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c
index f3cf387e4907e..26817f9ca4f1a 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe.c
@@ -410,6 +410,48 @@  int vfe_put_output(struct vfe_line *line)
 	return 0;
 }
 
+static int vfe_disable_output(struct vfe_line *line)
+{
+	struct vfe_device *vfe = to_vfe(line);
+	struct vfe_output *output = &line->output;
+	unsigned long flags;
+	unsigned int i;
+	int ret;
+
+	spin_lock_irqsave(&vfe->output_lock, flags);
+	for (i = 0; i < output->wm_num; i++)
+		vfe->ops->vfe_wm_stop(vfe, output->wm_idx[i]);
+	output->gen2.active_num = 0;
+	spin_unlock_irqrestore(&vfe->output_lock, flags);
+
+	ret = vfe_reset(vfe);
+
+	return ret;
+}
+
+/*
+ * vfe_disable - Disable streaming on VFE line
+ * @line: VFE line
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+int vfe_disable(struct vfe_line *line)
+{
+	struct vfe_device *vfe = to_vfe(line);
+
+	vfe_disable_output(line);
+
+	vfe_put_output(line);
+
+	mutex_lock(&vfe->stream_lock);
+
+	vfe->stream_count--;
+
+	mutex_unlock(&vfe->stream_lock);
+
+	return 0;
+}
+
 /**
  * vfe_isr_comp_done() - Process composite image done interrupt
  * @vfe: VFE Device
diff --git a/drivers/media/platform/qcom/camss/camss-vfe.h b/drivers/media/platform/qcom/camss/camss-vfe.h
index 4783afa73a365..09baded0dcdd6 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe.h
+++ b/drivers/media/platform/qcom/camss/camss-vfe.h
@@ -114,6 +114,7 @@  struct vfe_hw_ops {
 	int (*vfe_enable)(struct vfe_line *line);
 	int (*vfe_halt)(struct vfe_device *vfe);
 	void (*violation_read)(struct vfe_device *vfe);
+	void (*vfe_wm_stop)(struct vfe_device *vfe, u8 wm);
 };
 
 struct vfe_isr_ops {
@@ -192,6 +193,14 @@  int vfe_reserve_wm(struct vfe_device *vfe, enum vfe_line_id line_id);
  */
 int vfe_reset(struct vfe_device *vfe);
 
+/*
+ * vfe_disable - Disable streaming on VFE line
+ * @line: VFE line
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+int vfe_disable(struct vfe_line *line);
+
 extern const struct vfe_hw_ops vfe_ops_4_1;
 extern const struct vfe_hw_ops vfe_ops_4_7;
 extern const struct vfe_hw_ops vfe_ops_4_8;