diff mbox series

[v1,1/7] staging: media: starfive: Replaced current_fmt with get from sd_state

Message ID 20240306093334.9321-2-changhuang.liang@starfivetech.com
State New
Headers show
Series Add ISP RAW for StarFive | expand

Commit Message

Changhuang Liang March 6, 2024, 9:33 a.m. UTC
current_fmt only can store one pad format, when setting other pad it
will be overwrote. Replaced it with get from sd_state directly.

Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
 .../media/starfive/camss/stf-isp-hw-ops.c     | 10 ++++---
 .../staging/media/starfive/camss/stf-isp.c    | 26 +++++++++++++++----
 .../staging/media/starfive/camss/stf-isp.h    |  3 ++-
 3 files changed, 30 insertions(+), 9 deletions(-)

Comments

Dan Carpenter March 6, 2024, 2:23 p.m. UTC | #1
On Wed, Mar 06, 2024 at 01:33:28AM -0800, Changhuang Liang wrote:
> current_fmt only can store one pad format, when setting other pad it
> will be overwrote. Replaced it with get from sd_state directly.
>

These commit descriptions are kind of hard to understand so I have
proposed new commit messages.

Subject: staging: media: starfive: Get rid of current_fmt

We want to support mutiple formats so saving one "current_fmt" doesn't
work.  This was only used to set the ISP_REG_STRIDE so use the sd_state
directly for that and delete the ->current_fmt pointer.  No functional
change.

regards,
dan carpenter
Changhuang Liang March 7, 2024, 1:58 a.m. UTC | #2
Hi, Dan

Thanks for your comments.

> -----邮件原件-----
> 发件人: Dan Carpenter <dan.carpenter@linaro.org>
> 发送时间: 2024年3月6日 22:23
> 收件人: Changhuang Liang <changhuang.liang@starfivetech.com>
> 抄送: Mauro Carvalho Chehab <mchehab@kernel.org>; Greg Kroah-Hartman
> <gregkh@linuxfoundation.org>; Hans Verkuil <hverkuil-cisco@xs4all.nl>;
> Laurent Pinchart <laurent.pinchart@ideasonboard.com>; Jack Zhu
> <jack.zhu@starfivetech.com>; linux-media@vger.kernel.org;
> linux-kernel@vger.kernel.org; linux-staging@lists.linux.dev
> 主题: Re: [PATCH v1 1/7] staging: media: starfive: Replaced current_fmt with
> get from sd_state
> 
> On Wed, Mar 06, 2024 at 01:33:28AM -0800, Changhuang Liang wrote:
> > current_fmt only can store one pad format, when setting other pad it
> > will be overwrote. Replaced it with get from sd_state directly.
> >
> 
> These commit descriptions are kind of hard to understand so I have proposed
> new commit messages.
> 
> Subject: staging: media: starfive: Get rid of current_fmt
> 
> We want to support mutiple formats so saving one "current_fmt" doesn't
> work.  This was only used to set the ISP_REG_STRIDE so use the sd_state
> directly for that and delete the ->current_fmt pointer.  No functional change.
> 

I will re-change the patch description and add more details to all the patches.

Thanks
diff mbox series

Patch

diff --git a/drivers/staging/media/starfive/camss/stf-isp-hw-ops.c b/drivers/staging/media/starfive/camss/stf-isp-hw-ops.c
index c34631ff9422..b933d425cbd0 100644
--- a/drivers/staging/media/starfive/camss/stf-isp-hw-ops.c
+++ b/drivers/staging/media/starfive/camss/stf-isp-hw-ops.c
@@ -345,7 +345,6 @@  void stf_isp_init_cfg(struct stf_isp_dev *isp_dev)
 static void stf_isp_config_crop(struct stfcamss *stfcamss,
 				struct v4l2_rect *crop)
 {
-	u32 bpp = stfcamss->isp_dev.current_fmt->bpp;
 	u32 val;
 
 	val = VSTART_CAP(crop->top) | HSTART_CAP(crop->left);
@@ -357,9 +356,14 @@  static void stf_isp_config_crop(struct stfcamss *stfcamss,
 
 	val = H_ACT_CAP(crop->height) | W_ACT_CAP(crop->width);
 	stf_isp_reg_write(stfcamss, ISP_REG_PIPELINE_XY_SIZE, val);
+}
+
+void stf_isp_config_yuv_out_stride(struct stf_isp_dev *isp_dev,
+				   u32 width, u8 bpp)
+{
+	u32 val = ALIGN(width * bpp / 8, STFCAMSS_FRAME_WIDTH_ALIGN_8);
 
-	val = ALIGN(crop->width * bpp / 8, STFCAMSS_FRAME_WIDTH_ALIGN_8);
-	stf_isp_reg_write(stfcamss, ISP_REG_STRIDE, val);
+	stf_isp_reg_write(isp_dev->stfcamss, ISP_REG_STRIDE, val);
 }
 
 static void stf_isp_config_raw_fmt(struct stfcamss *stfcamss, u32 mcode)
diff --git a/drivers/staging/media/starfive/camss/stf-isp.c b/drivers/staging/media/starfive/camss/stf-isp.c
index d50616ef351e..a5573abe0d7b 100644
--- a/drivers/staging/media/starfive/camss/stf-isp.c
+++ b/drivers/staging/media/starfive/camss/stf-isp.c
@@ -46,6 +46,19 @@  stf_g_fmt_by_mcode(const struct stf_isp_format_table *fmt_table, u32 mcode)
 	return NULL;
 }
 
+static int stf_isp_g_index_by_mcode(const struct stf_isp_format_table *fmt_table,
+				    u32 mcode)
+{
+	int i;
+
+	for (i = 0; i < fmt_table->nfmts; i++) {
+		if (fmt_table->fmts[i].code == mcode)
+			return i;
+	}
+
+	return -EINVAL;
+}
+
 int stf_isp_init(struct stfcamss *stfcamss)
 {
 	struct stf_isp_dev *isp_dev = &stfcamss->isp_dev;
@@ -53,7 +66,6 @@  int stf_isp_init(struct stfcamss *stfcamss)
 	isp_dev->stfcamss = stfcamss;
 	isp_dev->formats = isp_formats_st7110;
 	isp_dev->nformats = ARRAY_SIZE(isp_formats_st7110);
-	isp_dev->current_fmt = &isp_formats_source[0];
 
 	return 0;
 }
@@ -61,18 +73,25 @@  int stf_isp_init(struct stfcamss *stfcamss)
 static int isp_set_stream(struct v4l2_subdev *sd, int enable)
 {
 	struct stf_isp_dev *isp_dev = v4l2_get_subdevdata(sd);
+	const struct stf_isp_format_table *fmt_t_src;
+	struct v4l2_mbus_framefmt *fmt, *fmt_src;
 	struct v4l2_subdev_state *sd_state;
-	struct v4l2_mbus_framefmt *fmt;
 	struct v4l2_rect *crop;
+	int src;
 
 	sd_state = v4l2_subdev_lock_and_get_active_state(sd);
+	fmt_t_src = &isp_dev->formats[STF_ISP_PAD_SRC];
 	fmt = v4l2_subdev_state_get_format(sd_state, STF_ISP_PAD_SINK);
+	fmt_src = v4l2_subdev_state_get_format(sd_state, STF_ISP_PAD_SRC);
 	crop = v4l2_subdev_state_get_crop(sd_state, STF_ISP_PAD_SRC);
+	src = stf_isp_g_index_by_mcode(fmt_t_src, fmt_src->code);
 
 	if (enable) {
 		stf_isp_reset(isp_dev);
 		stf_isp_init_cfg(isp_dev);
 		stf_isp_settings(isp_dev, crop, fmt->code);
+		stf_isp_config_yuv_out_stride(isp_dev, crop->width,
+					      fmt_t_src->fmts[src].bpp);
 		stf_isp_stream_set(isp_dev);
 	}
 
@@ -157,9 +176,6 @@  static int isp_set_format(struct v4l2_subdev *sd,
 	isp_try_format(isp_dev, state, fmt->pad, &fmt->format);
 	*format = fmt->format;
 
-	isp_dev->current_fmt = stf_g_fmt_by_mcode(&isp_dev->formats[fmt->pad],
-						  fmt->format.code);
-
 	/* Propagate to in crop */
 	if (fmt->pad == STF_ISP_PAD_SINK) {
 		struct v4l2_subdev_selection sel = { 0 };
diff --git a/drivers/staging/media/starfive/camss/stf-isp.h b/drivers/staging/media/starfive/camss/stf-isp.h
index 955cbb048363..07d6c2758253 100644
--- a/drivers/staging/media/starfive/camss/stf-isp.h
+++ b/drivers/staging/media/starfive/camss/stf-isp.h
@@ -413,7 +413,6 @@  struct stf_isp_dev {
 	const struct stf_isp_format_table *formats;
 	unsigned int nformats;
 	struct v4l2_subdev *source_subdev;
-	const struct stf_isp_format *current_fmt;
 };
 
 int stf_isp_reset(struct stf_isp_dev *isp_dev);
@@ -421,6 +420,8 @@  void stf_isp_init_cfg(struct stf_isp_dev *isp_dev);
 void stf_isp_settings(struct stf_isp_dev *isp_dev,
 		      struct v4l2_rect *crop, u32 mcode);
 void stf_isp_stream_set(struct stf_isp_dev *isp_dev);
+void stf_isp_config_yuv_out_stride(struct stf_isp_dev *isp_dev,
+				   u32 width, u8 bpp);
 int stf_isp_init(struct stfcamss *stfcamss);
 int stf_isp_register(struct stf_isp_dev *isp_dev, struct v4l2_device *v4l2_dev);
 int stf_isp_unregister(struct stf_isp_dev *isp_dev);