2023-12-15 08:25:10

by Tommaso Merciai

[permalink] [raw]
Subject: [PATCH 0/3] media: i2c: alvium: store frame interval in subdev state

Hi All,
The goal of this series as suggested by LPinchart is to remove the following
data from alvium_dev struct:

- struct v4l2_fract frame_interval;
- u64 dft_fr;
- u64 min_fr;
- u64 max_fr;
- u64 fr;

And use instead the the newly added storage for frame interval in the subdev state.
This series is made on top of the following series:

- media: v4l2-subdev: Improve frame interval handling
- base-commit: 76cb0b74268f1347e4b7fdefc343b064410e0e10

Tommaso Merciai (3):
media: i2c: alvium: removal of dft_fr, min_fr and max_fr
media: i2c: alvium: inline set_frame_interval into s_frame_interval
media: i2c: alvium: store frame interval in subdev state

drivers/media/i2c/alvium-csi2.c | 91 ++++++++++-----------------------
drivers/media/i2c/alvium-csi2.h | 5 --
2 files changed, 28 insertions(+), 68 deletions(-)

--
2.34.1



2023-12-15 08:25:41

by Tommaso Merciai

[permalink] [raw]
Subject: [PATCH 2/3] media: i2c: alvium: inline set_frame_interval into s_frame_interval

Inline alvium_s_frame_interval function into alvium_s_frame_interval.
This to clean the driver code.

Signed-off-by: Tommaso Merciai <[email protected]>
---
drivers/media/i2c/alvium-csi2.c | 56 ++++++++++++---------------------
1 file changed, 20 insertions(+), 36 deletions(-)

diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
index c4b7851045a1..fde456357be1 100644
--- a/drivers/media/i2c/alvium-csi2.c
+++ b/drivers/media/i2c/alvium-csi2.c
@@ -1662,16 +1662,25 @@ static int alvium_g_frame_interval(struct v4l2_subdev *sd,
return 0;
}

-static int alvium_set_frame_interval(struct alvium_dev *alvium,
- struct v4l2_subdev *sd,
- struct v4l2_subdev_state *sd_state,
- struct v4l2_subdev_frame_interval *fi,
- u64 *req_fr)
+static int alvium_s_frame_interval(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *sd_state,
+ struct v4l2_subdev_frame_interval *fi)
{
+ struct alvium_dev *alvium = sd_to_alvium(sd);
struct device *dev = &alvium->i2c_client->dev;
- u64 dft_fr, min_fr, max_fr;
+ u64 req_fr, dft_fr, min_fr, max_fr;
int ret;

+ /*
+ * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
+ * subdev active state API.
+ */
+ if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
+ return -EINVAL;
+
+ if (alvium->streaming)
+ return -EBUSY;
+
if (fi->interval.denominator == 0)
return -EINVAL;

@@ -1686,42 +1695,17 @@ static int alvium_set_frame_interval(struct alvium_dev *alvium,
dev_dbg(dev, "fi->interval.denominator = %d\n",
fi->interval.denominator);

- *req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
+ req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
fi->interval.numerator);

- if (*req_fr >= max_fr && *req_fr <= min_fr)
- *req_fr = dft_fr;
+ if (req_fr >= max_fr && req_fr <= min_fr)
+ req_fr = dft_fr;

- alvium->fr = *req_fr;
+ alvium->fr = req_fr;
alvium->frame_interval.numerator = fi->interval.numerator;
alvium->frame_interval.denominator = fi->interval.denominator;

- return 0;
-}
-
-static int alvium_s_frame_interval(struct v4l2_subdev *sd,
- struct v4l2_subdev_state *sd_state,
- struct v4l2_subdev_frame_interval *fi)
-{
- struct alvium_dev *alvium = sd_to_alvium(sd);
- u64 req_fr;
- int ret;
-
- /*
- * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
- * subdev active state API.
- */
- if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
- return -EINVAL;
-
- if (alvium->streaming)
- return -EBUSY;
-
- ret = alvium_set_frame_interval(alvium, sd, sd_state, fi, &req_fr);
- if (!ret)
- ret = alvium_set_frame_rate(alvium, req_fr);
-
- return ret;
+ return alvium_set_frame_rate(alvium, req_fr);
}

static int alvium_enum_mbus_code(struct v4l2_subdev *sd,
--
2.34.1


2023-12-15 08:26:01

by Tommaso Merciai

[permalink] [raw]
Subject: [PATCH 3/3] media: i2c: alvium: store frame interval in subdev state

Use the newly added storage for frame interval in the subdev state to
simplify the driver.

Signed-off-by: Tommaso Merciai <[email protected]>
---
drivers/media/i2c/alvium-csi2.c | 40 ++++++++++-----------------------
drivers/media/i2c/alvium-csi2.h | 2 --
2 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
index fde456357be1..81f683b3c849 100644
--- a/drivers/media/i2c/alvium-csi2.c
+++ b/drivers/media/i2c/alvium-csi2.c
@@ -1643,25 +1643,6 @@ static int alvium_hw_init(struct alvium_dev *alvium)
}

/* --------------- Subdev Operations --------------- */
-
-static int alvium_g_frame_interval(struct v4l2_subdev *sd,
- struct v4l2_subdev_state *sd_state,
- struct v4l2_subdev_frame_interval *fi)
-{
- struct alvium_dev *alvium = sd_to_alvium(sd);
-
- /*
- * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
- * subdev active state API.
- */
- if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
- return -EINVAL;
-
- fi->interval = alvium->frame_interval;
-
- return 0;
-}
-
static int alvium_s_frame_interval(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_frame_interval *fi)
@@ -1669,6 +1650,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
struct alvium_dev *alvium = sd_to_alvium(sd);
struct device *dev = &alvium->i2c_client->dev;
u64 req_fr, dft_fr, min_fr, max_fr;
+ struct v4l2_fract *interval;
int ret;

/*
@@ -1701,9 +1683,10 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
if (req_fr >= max_fr && req_fr <= min_fr)
req_fr = dft_fr;

- alvium->fr = req_fr;
- alvium->frame_interval.numerator = fi->interval.numerator;
- alvium->frame_interval.denominator = fi->interval.denominator;
+ interval = v4l2_subdev_state_get_interval(sd_state, 0);
+
+ interval->numerator = fi->interval.numerator;
+ interval->denominator = fi->interval.denominator;

return alvium_set_frame_rate(alvium, req_fr);
}
@@ -1853,6 +1836,7 @@ static int alvium_init_state(struct v4l2_subdev *sd,
{
struct alvium_dev *alvium = sd_to_alvium(sd);
struct alvium_mode *mode = &alvium->mode;
+ struct v4l2_fract *interval;
struct v4l2_subdev_format sd_fmt = {
.which = V4L2_SUBDEV_FORMAT_TRY,
.format = alvium_csi2_default_fmt,
@@ -1870,6 +1854,11 @@ static int alvium_init_state(struct v4l2_subdev *sd,
*v4l2_subdev_state_get_crop(state, 0) = sd_crop.rect;
*v4l2_subdev_state_get_format(state, 0) = sd_fmt.format;

+ /* Setup initial frame interval*/
+ interval = v4l2_subdev_state_get_interval(state, 0);
+ interval->numerator = 1;
+ interval->denominator = ALVIUM_DEFAULT_FR_HZ;
+
return 0;
}

@@ -2239,7 +2228,7 @@ static const struct v4l2_subdev_pad_ops alvium_pad_ops = {
.set_fmt = alvium_set_fmt,
.get_selection = alvium_get_selection,
.set_selection = alvium_set_selection,
- .get_frame_interval = alvium_g_frame_interval,
+ .get_frame_interval = v4l2_subdev_get_frame_interval,
.set_frame_interval = alvium_s_frame_interval,
};

@@ -2260,11 +2249,6 @@ static int alvium_subdev_init(struct alvium_dev *alvium)
struct v4l2_subdev *sd = &alvium->sd;
int ret;

- /* Setup initial frame interval*/
- alvium->frame_interval.numerator = 1;
- alvium->frame_interval.denominator = ALVIUM_DEFAULT_FR_HZ;
- alvium->fr = ALVIUM_DEFAULT_FR_HZ;
-
/* Setup the initial mode */
alvium->mode.fmt = alvium_csi2_default_fmt;
alvium->mode.width = alvium_csi2_default_fmt.width;
diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
index a6529b28e7dd..f5e26257b042 100644
--- a/drivers/media/i2c/alvium-csi2.h
+++ b/drivers/media/i2c/alvium-csi2.h
@@ -442,8 +442,6 @@ struct alvium_dev {
s32 inc_sharp;

struct alvium_mode mode;
- struct v4l2_fract frame_interval;
- u64 fr;

u8 h_sup_csi_lanes;
u64 link_freq;
--
2.34.1


2023-12-15 08:32:38

by Tommaso Merciai

[permalink] [raw]
Subject: [PATCH 1/3] media: i2c: alvium: removal of dft_fr, min_fr and max_fr

Remove driver private data dft_fr, min_fr and max_fr.
Those are used only in alvium_set_frame_interval function.
Use local ones instead.

Signed-off-by: Tommaso Merciai <[email protected]>
---
drivers/media/i2c/alvium-csi2.c | 45 +++++++++++++++------------------
drivers/media/i2c/alvium-csi2.h | 3 ---
2 files changed, 21 insertions(+), 27 deletions(-)

diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
index 34ff7fad3877..c4b7851045a1 100644
--- a/drivers/media/i2c/alvium-csi2.c
+++ b/drivers/media/i2c/alvium-csi2.c
@@ -1170,40 +1170,36 @@ static int alvium_set_bayer_pattern(struct alvium_dev *alvium,
return 0;
}

-static int alvium_get_frame_interval(struct alvium_dev *alvium)
+static int alvium_get_frame_interval(struct alvium_dev *alvium,
+ u64 *dft_fr, u64 *min_fr, u64 *max_fr)
{
- u64 dft_fr, min_fr, max_fr;
int ret = 0;

alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW,
- &dft_fr, &ret);
+ dft_fr, &ret);
alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MIN_R,
- &min_fr, &ret);
+ min_fr, &ret);
alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MAX_R,
- &max_fr, &ret);
+ max_fr, &ret);
if (ret)
return ret;

- alvium->dft_fr = dft_fr;
- alvium->min_fr = min_fr;
- alvium->max_fr = max_fr;
-
return 0;
}

-static int alvium_set_frame_rate(struct alvium_dev *alvium)
+static int alvium_set_frame_rate(struct alvium_dev *alvium, u64 fr)
{
struct device *dev = &alvium->i2c_client->dev;
int ret;

ret = alvium_write_hshake(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW,
- alvium->fr);
+ fr);
if (ret) {
dev_err(dev, "Fail to set frame rate lanes reg\n");
return ret;
}

- dev_dbg(dev, "set frame rate: %llu us\n", alvium->fr);
+ dev_dbg(dev, "set frame rate: %llu us\n", fr);

return 0;
}
@@ -1667,36 +1663,36 @@ static int alvium_g_frame_interval(struct v4l2_subdev *sd,
}

static int alvium_set_frame_interval(struct alvium_dev *alvium,
- struct v4l2_subdev_frame_interval *fi)
+ struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *sd_state,
+ struct v4l2_subdev_frame_interval *fi,
+ u64 *req_fr)
{
struct device *dev = &alvium->i2c_client->dev;
- u64 req_fr, min_fr, max_fr;
+ u64 dft_fr, min_fr, max_fr;
int ret;

if (fi->interval.denominator == 0)
return -EINVAL;

- ret = alvium_get_frame_interval(alvium);
+ ret = alvium_get_frame_interval(alvium, &dft_fr, &min_fr, &max_fr);
if (ret) {
dev_err(dev, "Fail to get frame interval\n");
return ret;
}

- min_fr = alvium->min_fr;
- max_fr = alvium->max_fr;
-
dev_dbg(dev, "fi->interval.numerator = %d\n",
fi->interval.numerator);
dev_dbg(dev, "fi->interval.denominator = %d\n",
fi->interval.denominator);

- req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
+ *req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
fi->interval.numerator);

- if (req_fr >= max_fr && req_fr <= min_fr)
- req_fr = alvium->dft_fr;
+ if (*req_fr >= max_fr && *req_fr <= min_fr)
+ *req_fr = dft_fr;

- alvium->fr = req_fr;
+ alvium->fr = *req_fr;
alvium->frame_interval.numerator = fi->interval.numerator;
alvium->frame_interval.denominator = fi->interval.denominator;

@@ -1708,6 +1704,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
struct v4l2_subdev_frame_interval *fi)
{
struct alvium_dev *alvium = sd_to_alvium(sd);
+ u64 req_fr;
int ret;

/*
@@ -1720,9 +1717,9 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
if (alvium->streaming)
return -EBUSY;

- ret = alvium_set_frame_interval(alvium, fi);
+ ret = alvium_set_frame_interval(alvium, sd, sd_state, fi, &req_fr);
if (!ret)
- ret = alvium_set_frame_rate(alvium);
+ ret = alvium_set_frame_rate(alvium, req_fr);

return ret;
}
diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
index 8b554bffdc39..a6529b28e7dd 100644
--- a/drivers/media/i2c/alvium-csi2.h
+++ b/drivers/media/i2c/alvium-csi2.h
@@ -443,9 +443,6 @@ struct alvium_dev {

struct alvium_mode mode;
struct v4l2_fract frame_interval;
- u64 dft_fr;
- u64 min_fr;
- u64 max_fr;
u64 fr;

u8 h_sup_csi_lanes;
--
2.34.1


2023-12-18 02:51:12

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH 1/3] media: i2c: alvium: removal of dft_fr, min_fr and max_fr

Hi Tommaso,

Thank you for the patch.

On Fri, Dec 15, 2023 at 09:24:50AM +0100, Tommaso Merciai wrote:
> Remove driver private data dft_fr, min_fr and max_fr.
> Those are used only in alvium_set_frame_interval function.
> Use local ones instead.

The fields are used to pass data from alvium_get_frame_interval() to its
caller, not just in alvium_get_frame_interval(). You can write

The dft_fr, min_fr and max_fr fields of the alvium_dev structure are
only used to pass results from alvium_get_frame_interval() to its
caller. Replace them with function parameters.

> Signed-off-by: Tommaso Merciai <[email protected]>
> ---
> drivers/media/i2c/alvium-csi2.c | 45 +++++++++++++++------------------
> drivers/media/i2c/alvium-csi2.h | 3 ---
> 2 files changed, 21 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> index 34ff7fad3877..c4b7851045a1 100644
> --- a/drivers/media/i2c/alvium-csi2.c
> +++ b/drivers/media/i2c/alvium-csi2.c
> @@ -1170,40 +1170,36 @@ static int alvium_set_bayer_pattern(struct alvium_dev *alvium,
> return 0;
> }
>
> -static int alvium_get_frame_interval(struct alvium_dev *alvium)
> +static int alvium_get_frame_interval(struct alvium_dev *alvium,
> + u64 *dft_fr, u64 *min_fr, u64 *max_fr)
> {
> - u64 dft_fr, min_fr, max_fr;
> int ret = 0;
>
> alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW,
> - &dft_fr, &ret);
> + dft_fr, &ret);
> alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MIN_R,
> - &min_fr, &ret);
> + min_fr, &ret);
> alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MAX_R,
> - &max_fr, &ret);
> + max_fr, &ret);
> if (ret)
> return ret;

You can just

return ret;

>
> - alvium->dft_fr = dft_fr;
> - alvium->min_fr = min_fr;
> - alvium->max_fr = max_fr;
> -
> return 0;
> }
>
> -static int alvium_set_frame_rate(struct alvium_dev *alvium)
> +static int alvium_set_frame_rate(struct alvium_dev *alvium, u64 fr)
> {
> struct device *dev = &alvium->i2c_client->dev;
> int ret;
>
> ret = alvium_write_hshake(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW,
> - alvium->fr);
> + fr);

This is unrelated to the commit message. Please split handling of the fr
field to a separate patch. One change, one patch.

> if (ret) {
> dev_err(dev, "Fail to set frame rate lanes reg\n");
> return ret;
> }
>
> - dev_dbg(dev, "set frame rate: %llu us\n", alvium->fr);
> + dev_dbg(dev, "set frame rate: %llu us\n", fr);
>
> return 0;
> }
> @@ -1667,36 +1663,36 @@ static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> }
>
> static int alvium_set_frame_interval(struct alvium_dev *alvium,
> - struct v4l2_subdev_frame_interval *fi)
> + struct v4l2_subdev *sd,
> + struct v4l2_subdev_state *sd_state,
> + struct v4l2_subdev_frame_interval *fi,
> + u64 *req_fr)
> {
> struct device *dev = &alvium->i2c_client->dev;
> - u64 req_fr, min_fr, max_fr;
> + u64 dft_fr, min_fr, max_fr;
> int ret;
>
> if (fi->interval.denominator == 0)
> return -EINVAL;
>
> - ret = alvium_get_frame_interval(alvium);
> + ret = alvium_get_frame_interval(alvium, &dft_fr, &min_fr, &max_fr);
> if (ret) {
> dev_err(dev, "Fail to get frame interval\n");
> return ret;
> }
>
> - min_fr = alvium->min_fr;
> - max_fr = alvium->max_fr;
> -
> dev_dbg(dev, "fi->interval.numerator = %d\n",
> fi->interval.numerator);
> dev_dbg(dev, "fi->interval.denominator = %d\n",
> fi->interval.denominator);
>
> - req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
> + *req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
> fi->interval.numerator);
>
> - if (req_fr >= max_fr && req_fr <= min_fr)
> - req_fr = alvium->dft_fr;
> + if (*req_fr >= max_fr && *req_fr <= min_fr)
> + *req_fr = dft_fr;
>
> - alvium->fr = req_fr;
> + alvium->fr = *req_fr;
> alvium->frame_interval.numerator = fi->interval.numerator;
> alvium->frame_interval.denominator = fi->interval.denominator;
>
> @@ -1708,6 +1704,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> struct v4l2_subdev_frame_interval *fi)
> {
> struct alvium_dev *alvium = sd_to_alvium(sd);
> + u64 req_fr;
> int ret;
>
> /*
> @@ -1720,9 +1717,9 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> if (alvium->streaming)
> return -EBUSY;
>
> - ret = alvium_set_frame_interval(alvium, fi);
> + ret = alvium_set_frame_interval(alvium, sd, sd_state, fi, &req_fr);
> if (!ret)
> - ret = alvium_set_frame_rate(alvium);
> + ret = alvium_set_frame_rate(alvium, req_fr);
>
> return ret;
> }
> diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
> index 8b554bffdc39..a6529b28e7dd 100644
> --- a/drivers/media/i2c/alvium-csi2.h
> +++ b/drivers/media/i2c/alvium-csi2.h
> @@ -443,9 +443,6 @@ struct alvium_dev {
>
> struct alvium_mode mode;
> struct v4l2_fract frame_interval;
> - u64 dft_fr;
> - u64 min_fr;
> - u64 max_fr;
> u64 fr;
>
> u8 h_sup_csi_lanes;

--
Regards,

Laurent Pinchart

2023-12-18 02:55:03

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH 1/3] media: i2c: alvium: removal of dft_fr, min_fr and max_fr

On Mon, Dec 18, 2023 at 04:50:46AM +0200, Laurent Pinchart wrote:
> Hi Tommaso,
>
> Thank you for the patch.
>
> On Fri, Dec 15, 2023 at 09:24:50AM +0100, Tommaso Merciai wrote:
> > Remove driver private data dft_fr, min_fr and max_fr.
> > Those are used only in alvium_set_frame_interval function.
> > Use local ones instead.
>
> The fields are used to pass data from alvium_get_frame_interval() to its
> caller, not just in alvium_get_frame_interval(). You can write
>
> The dft_fr, min_fr and max_fr fields of the alvium_dev structure are
> only used to pass results from alvium_get_frame_interval() to its
> caller. Replace them with function parameters.
>
> > Signed-off-by: Tommaso Merciai <[email protected]>
> > ---
> > drivers/media/i2c/alvium-csi2.c | 45 +++++++++++++++------------------
> > drivers/media/i2c/alvium-csi2.h | 3 ---
> > 2 files changed, 21 insertions(+), 27 deletions(-)
> >
> > diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> > index 34ff7fad3877..c4b7851045a1 100644
> > --- a/drivers/media/i2c/alvium-csi2.c
> > +++ b/drivers/media/i2c/alvium-csi2.c
> > @@ -1170,40 +1170,36 @@ static int alvium_set_bayer_pattern(struct alvium_dev *alvium,
> > return 0;
> > }
> >
> > -static int alvium_get_frame_interval(struct alvium_dev *alvium)
> > +static int alvium_get_frame_interval(struct alvium_dev *alvium,
> > + u64 *dft_fr, u64 *min_fr, u64 *max_fr)
> > {
> > - u64 dft_fr, min_fr, max_fr;
> > int ret = 0;
> >
> > alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW,
> > - &dft_fr, &ret);
> > + dft_fr, &ret);
> > alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MIN_R,
> > - &min_fr, &ret);
> > + min_fr, &ret);
> > alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MAX_R,
> > - &max_fr, &ret);
> > + max_fr, &ret);
> > if (ret)
> > return ret;
>
> You can just
>
> return ret;
>
> >
> > - alvium->dft_fr = dft_fr;
> > - alvium->min_fr = min_fr;
> > - alvium->max_fr = max_fr;
> > -
> > return 0;
> > }
> >
> > -static int alvium_set_frame_rate(struct alvium_dev *alvium)
> > +static int alvium_set_frame_rate(struct alvium_dev *alvium, u64 fr)
> > {
> > struct device *dev = &alvium->i2c_client->dev;
> > int ret;
> >
> > ret = alvium_write_hshake(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW,
> > - alvium->fr);
> > + fr);
>
> This is unrelated to the commit message. Please split handling of the fr
> field to a separate patch. One change, one patch.
>
> > if (ret) {
> > dev_err(dev, "Fail to set frame rate lanes reg\n");
> > return ret;
> > }
> >
> > - dev_dbg(dev, "set frame rate: %llu us\n", alvium->fr);
> > + dev_dbg(dev, "set frame rate: %llu us\n", fr);
> >
> > return 0;
> > }
> > @@ -1667,36 +1663,36 @@ static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> > }
> >
> > static int alvium_set_frame_interval(struct alvium_dev *alvium,
> > - struct v4l2_subdev_frame_interval *fi)
> > + struct v4l2_subdev *sd,
> > + struct v4l2_subdev_state *sd_state,

This is also unrelated to this patch.

> > + struct v4l2_subdev_frame_interval *fi,
> > + u64 *req_fr)
> > {
> > struct device *dev = &alvium->i2c_client->dev;
> > - u64 req_fr, min_fr, max_fr;
> > + u64 dft_fr, min_fr, max_fr;
> > int ret;
> >
> > if (fi->interval.denominator == 0)
> > return -EINVAL;
> >
> > - ret = alvium_get_frame_interval(alvium);
> > + ret = alvium_get_frame_interval(alvium, &dft_fr, &min_fr, &max_fr);
> > if (ret) {
> > dev_err(dev, "Fail to get frame interval\n");
> > return ret;
> > }
> >
> > - min_fr = alvium->min_fr;
> > - max_fr = alvium->max_fr;
> > -
> > dev_dbg(dev, "fi->interval.numerator = %d\n",
> > fi->interval.numerator);
> > dev_dbg(dev, "fi->interval.denominator = %d\n",
> > fi->interval.denominator);
> >
> > - req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
> > + *req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
> > fi->interval.numerator);
> >
> > - if (req_fr >= max_fr && req_fr <= min_fr)
> > - req_fr = alvium->dft_fr;
> > + if (*req_fr >= max_fr && *req_fr <= min_fr)
> > + *req_fr = dft_fr;
> >
> > - alvium->fr = req_fr;
> > + alvium->fr = *req_fr;
> > alvium->frame_interval.numerator = fi->interval.numerator;
> > alvium->frame_interval.denominator = fi->interval.denominator;
> >
> > @@ -1708,6 +1704,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > struct v4l2_subdev_frame_interval *fi)
> > {
> > struct alvium_dev *alvium = sd_to_alvium(sd);
> > + u64 req_fr;
> > int ret;
> >
> > /*
> > @@ -1720,9 +1717,9 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > if (alvium->streaming)
> > return -EBUSY;
> >
> > - ret = alvium_set_frame_interval(alvium, fi);
> > + ret = alvium_set_frame_interval(alvium, sd, sd_state, fi, &req_fr);
> > if (!ret)
> > - ret = alvium_set_frame_rate(alvium);
> > + ret = alvium_set_frame_rate(alvium, req_fr);
> >
> > return ret;
> > }
> > diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
> > index 8b554bffdc39..a6529b28e7dd 100644
> > --- a/drivers/media/i2c/alvium-csi2.h
> > +++ b/drivers/media/i2c/alvium-csi2.h
> > @@ -443,9 +443,6 @@ struct alvium_dev {
> >
> > struct alvium_mode mode;
> > struct v4l2_fract frame_interval;
> > - u64 dft_fr;
> > - u64 min_fr;
> > - u64 max_fr;
> > u64 fr;
> >
> > u8 h_sup_csi_lanes;

--
Regards,

Laurent Pinchart

2023-12-18 02:55:22

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH 2/3] media: i2c: alvium: inline set_frame_interval into s_frame_interval

Hi Tommaso,

Thank you for the patch.

On Fri, Dec 15, 2023 at 09:24:51AM +0100, Tommaso Merciai wrote:
> Inline alvium_s_frame_interval function into alvium_s_frame_interval.

I think you mean "alvium_set_frame_interval() function into
alvium_s_frame_interval.()"

> This to clean the driver code.

You can describe the reason more precisely:

The alvium_set_frame_interval() is called once only, by
alvium_s_frame_interval(). The latter is a thin wrapper around the
former. Inline the function in its caller to make the code more
readable.

The rest looks good to me.

> Signed-off-by: Tommaso Merciai <[email protected]>
> ---
> drivers/media/i2c/alvium-csi2.c | 56 ++++++++++++---------------------
> 1 file changed, 20 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> index c4b7851045a1..fde456357be1 100644
> --- a/drivers/media/i2c/alvium-csi2.c
> +++ b/drivers/media/i2c/alvium-csi2.c
> @@ -1662,16 +1662,25 @@ static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> return 0;
> }
>
> -static int alvium_set_frame_interval(struct alvium_dev *alvium,
> - struct v4l2_subdev *sd,
> - struct v4l2_subdev_state *sd_state,
> - struct v4l2_subdev_frame_interval *fi,
> - u64 *req_fr)
> +static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> + struct v4l2_subdev_state *sd_state,
> + struct v4l2_subdev_frame_interval *fi)
> {
> + struct alvium_dev *alvium = sd_to_alvium(sd);
> struct device *dev = &alvium->i2c_client->dev;
> - u64 dft_fr, min_fr, max_fr;
> + u64 req_fr, dft_fr, min_fr, max_fr;
> int ret;
>
> + /*
> + * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
> + * subdev active state API.
> + */
> + if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> + return -EINVAL;
> +
> + if (alvium->streaming)
> + return -EBUSY;
> +
> if (fi->interval.denominator == 0)
> return -EINVAL;
>
> @@ -1686,42 +1695,17 @@ static int alvium_set_frame_interval(struct alvium_dev *alvium,
> dev_dbg(dev, "fi->interval.denominator = %d\n",
> fi->interval.denominator);
>
> - *req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
> + req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
> fi->interval.numerator);
>
> - if (*req_fr >= max_fr && *req_fr <= min_fr)
> - *req_fr = dft_fr;
> + if (req_fr >= max_fr && req_fr <= min_fr)
> + req_fr = dft_fr;
>
> - alvium->fr = *req_fr;
> + alvium->fr = req_fr;
> alvium->frame_interval.numerator = fi->interval.numerator;
> alvium->frame_interval.denominator = fi->interval.denominator;
>
> - return 0;
> -}
> -
> -static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> - struct v4l2_subdev_state *sd_state,
> - struct v4l2_subdev_frame_interval *fi)
> -{
> - struct alvium_dev *alvium = sd_to_alvium(sd);
> - u64 req_fr;
> - int ret;
> -
> - /*
> - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
> - * subdev active state API.
> - */
> - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> - return -EINVAL;
> -
> - if (alvium->streaming)
> - return -EBUSY;
> -
> - ret = alvium_set_frame_interval(alvium, sd, sd_state, fi, &req_fr);
> - if (!ret)
> - ret = alvium_set_frame_rate(alvium, req_fr);
> -
> - return ret;
> + return alvium_set_frame_rate(alvium, req_fr);
> }
>
> static int alvium_enum_mbus_code(struct v4l2_subdev *sd,

--
Regards,

Laurent Pinchart

2023-12-18 02:59:15

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH 3/3] media: i2c: alvium: store frame interval in subdev state

Hi Tommaso,

Thank you for the patch.

On Fri, Dec 15, 2023 at 09:24:52AM +0100, Tommaso Merciai wrote:
> Use the newly added storage for frame interval in the subdev state to
> simplify the driver.
>
> Signed-off-by: Tommaso Merciai <[email protected]>
> ---
> drivers/media/i2c/alvium-csi2.c | 40 ++++++++++-----------------------
> drivers/media/i2c/alvium-csi2.h | 2 --
> 2 files changed, 12 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> index fde456357be1..81f683b3c849 100644
> --- a/drivers/media/i2c/alvium-csi2.c
> +++ b/drivers/media/i2c/alvium-csi2.c
> @@ -1643,25 +1643,6 @@ static int alvium_hw_init(struct alvium_dev *alvium)
> }
>
> /* --------------- Subdev Operations --------------- */
> -
> -static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> - struct v4l2_subdev_state *sd_state,
> - struct v4l2_subdev_frame_interval *fi)
> -{
> - struct alvium_dev *alvium = sd_to_alvium(sd);
> -
> - /*
> - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
> - * subdev active state API.
> - */
> - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> - return -EINVAL;
> -
> - fi->interval = alvium->frame_interval;
> -
> - return 0;
> -}
> -
> static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> struct v4l2_subdev_state *sd_state,
> struct v4l2_subdev_frame_interval *fi)
> @@ -1669,6 +1650,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> struct alvium_dev *alvium = sd_to_alvium(sd);
> struct device *dev = &alvium->i2c_client->dev;
> u64 req_fr, dft_fr, min_fr, max_fr;
> + struct v4l2_fract *interval;
> int ret;
>
> /*

You should drop the FIXME comment here and the ACTIVE check...

> @@ -1701,9 +1683,10 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> if (req_fr >= max_fr && req_fr <= min_fr)
> req_fr = dft_fr;
>
> - alvium->fr = req_fr;
> - alvium->frame_interval.numerator = fi->interval.numerator;
> - alvium->frame_interval.denominator = fi->interval.denominator;
> + interval = v4l2_subdev_state_get_interval(sd_state, 0);
> +
> + interval->numerator = fi->interval.numerator;
> + interval->denominator = fi->interval.denominator;
>


... and here only call alvium_set_frame_rate() for the ACTIVE frame
interval.

> return alvium_set_frame_rate(alvium, req_fr);
> }
> @@ -1853,6 +1836,7 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> {
> struct alvium_dev *alvium = sd_to_alvium(sd);
> struct alvium_mode *mode = &alvium->mode;
> + struct v4l2_fract *interval;
> struct v4l2_subdev_format sd_fmt = {
> .which = V4L2_SUBDEV_FORMAT_TRY,
> .format = alvium_csi2_default_fmt,
> @@ -1870,6 +1854,11 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> *v4l2_subdev_state_get_crop(state, 0) = sd_crop.rect;
> *v4l2_subdev_state_get_format(state, 0) = sd_fmt.format;
>
> + /* Setup initial frame interval*/
> + interval = v4l2_subdev_state_get_interval(state, 0);
> + interval->numerator = 1;
> + interval->denominator = ALVIUM_DEFAULT_FR_HZ;
> +
> return 0;
> }
>
> @@ -2239,7 +2228,7 @@ static const struct v4l2_subdev_pad_ops alvium_pad_ops = {
> .set_fmt = alvium_set_fmt,
> .get_selection = alvium_get_selection,
> .set_selection = alvium_set_selection,
> - .get_frame_interval = alvium_g_frame_interval,
> + .get_frame_interval = v4l2_subdev_get_frame_interval,
> .set_frame_interval = alvium_s_frame_interval,
> };
>
> @@ -2260,11 +2249,6 @@ static int alvium_subdev_init(struct alvium_dev *alvium)
> struct v4l2_subdev *sd = &alvium->sd;
> int ret;
>
> - /* Setup initial frame interval*/
> - alvium->frame_interval.numerator = 1;
> - alvium->frame_interval.denominator = ALVIUM_DEFAULT_FR_HZ;
> - alvium->fr = ALVIUM_DEFAULT_FR_HZ;
> -
> /* Setup the initial mode */
> alvium->mode.fmt = alvium_csi2_default_fmt;
> alvium->mode.width = alvium_csi2_default_fmt.width;
> diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
> index a6529b28e7dd..f5e26257b042 100644
> --- a/drivers/media/i2c/alvium-csi2.h
> +++ b/drivers/media/i2c/alvium-csi2.h
> @@ -442,8 +442,6 @@ struct alvium_dev {
> s32 inc_sharp;
>
> struct alvium_mode mode;
> - struct v4l2_fract frame_interval;
> - u64 fr;

The fr field should have been removed by a previous patch (the one that
will go between 1/3 an 2/3, see my review of 1/3) as shown by the fact
that this patch only removes two locations where the field is set but
none where it's read.

>
> u8 h_sup_csi_lanes;
> u64 link_freq;

--
Regards,

Laurent Pinchart

2023-12-18 10:28:17

by Tommaso Merciai

[permalink] [raw]
Subject: Re: [PATCH 1/3] media: i2c: alvium: removal of dft_fr, min_fr and max_fr

Hi Laurent,
Thanks for your review.

On Mon, Dec 18, 2023 at 04:54:30AM +0200, Laurent Pinchart wrote:
> On Mon, Dec 18, 2023 at 04:50:46AM +0200, Laurent Pinchart wrote:
> > Hi Tommaso,
> >
> > Thank you for the patch.
> >
> > On Fri, Dec 15, 2023 at 09:24:50AM +0100, Tommaso Merciai wrote:
> > > Remove driver private data dft_fr, min_fr and max_fr.
> > > Those are used only in alvium_set_frame_interval function.
> > > Use local ones instead.
> >
> > The fields are used to pass data from alvium_get_frame_interval() to its
> > caller, not just in alvium_get_frame_interval(). You can write
> >
> > The dft_fr, min_fr and max_fr fields of the alvium_dev structure are
> > only used to pass results from alvium_get_frame_interval() to its
> > caller. Replace them with function parameters.

Thanks for the hint.

> >
> > > Signed-off-by: Tommaso Merciai <[email protected]>
> > > ---
> > > drivers/media/i2c/alvium-csi2.c | 45 +++++++++++++++------------------
> > > drivers/media/i2c/alvium-csi2.h | 3 ---
> > > 2 files changed, 21 insertions(+), 27 deletions(-)
> > >
> > > diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> > > index 34ff7fad3877..c4b7851045a1 100644
> > > --- a/drivers/media/i2c/alvium-csi2.c
> > > +++ b/drivers/media/i2c/alvium-csi2.c
> > > @@ -1170,40 +1170,36 @@ static int alvium_set_bayer_pattern(struct alvium_dev *alvium,
> > > return 0;
> > > }
> > >
> > > -static int alvium_get_frame_interval(struct alvium_dev *alvium)
> > > +static int alvium_get_frame_interval(struct alvium_dev *alvium,
> > > + u64 *dft_fr, u64 *min_fr, u64 *max_fr)
> > > {
> > > - u64 dft_fr, min_fr, max_fr;
> > > int ret = 0;
> > >
> > > alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW,
> > > - &dft_fr, &ret);
> > > + dft_fr, &ret);
> > > alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MIN_R,
> > > - &min_fr, &ret);
> > > + min_fr, &ret);
> > > alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MAX_R,
> > > - &max_fr, &ret);
> > > + max_fr, &ret);
> > > if (ret)
> > > return ret;
> >
> > You can just
> >
> > return ret;

I'll do this in v2, thanks.

> >
> > >
> > > - alvium->dft_fr = dft_fr;
> > > - alvium->min_fr = min_fr;
> > > - alvium->max_fr = max_fr;
> > > -
> > > return 0;
> > > }
> > >
> > > -static int alvium_set_frame_rate(struct alvium_dev *alvium)
> > > +static int alvium_set_frame_rate(struct alvium_dev *alvium, u64 fr)
> > > {
> > > struct device *dev = &alvium->i2c_client->dev;
> > > int ret;
> > >
> > > ret = alvium_write_hshake(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW,
> > > - alvium->fr);
> > > + fr);
> >
> > This is unrelated to the commit message. Please split handling of the fr
> > field to a separate patch. One change, one patch.

Right..

> >
> > > if (ret) {
> > > dev_err(dev, "Fail to set frame rate lanes reg\n");
> > > return ret;
> > > }
> > >
> > > - dev_dbg(dev, "set frame rate: %llu us\n", alvium->fr);
> > > + dev_dbg(dev, "set frame rate: %llu us\n", fr);
> > >
> > > return 0;
> > > }
> > > @@ -1667,36 +1663,36 @@ static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> > > }
> > >
> > > static int alvium_set_frame_interval(struct alvium_dev *alvium,
> > > - struct v4l2_subdev_frame_interval *fi)
> > > + struct v4l2_subdev *sd,
> > > + struct v4l2_subdev_state *sd_state,
>
> This is also unrelated to this patch.
>
> > > + struct v4l2_subdev_frame_interval *fi,
> > > + u64 *req_fr)
> > > {
> > > struct device *dev = &alvium->i2c_client->dev;
> > > - u64 req_fr, min_fr, max_fr;
> > > + u64 dft_fr, min_fr, max_fr;
> > > int ret;
> > >
> > > if (fi->interval.denominator == 0)
> > > return -EINVAL;
> > >
> > > - ret = alvium_get_frame_interval(alvium);
> > > + ret = alvium_get_frame_interval(alvium, &dft_fr, &min_fr, &max_fr);
> > > if (ret) {
> > > dev_err(dev, "Fail to get frame interval\n");
> > > return ret;
> > > }
> > >
> > > - min_fr = alvium->min_fr;
> > > - max_fr = alvium->max_fr;
> > > -
> > > dev_dbg(dev, "fi->interval.numerator = %d\n",
> > > fi->interval.numerator);
> > > dev_dbg(dev, "fi->interval.denominator = %d\n",
> > > fi->interval.denominator);
> > >
> > > - req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
> > > + *req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
> > > fi->interval.numerator);
> > >
> > > - if (req_fr >= max_fr && req_fr <= min_fr)
> > > - req_fr = alvium->dft_fr;
> > > + if (*req_fr >= max_fr && *req_fr <= min_fr)
> > > + *req_fr = dft_fr;
> > >
> > > - alvium->fr = req_fr;
> > > + alvium->fr = *req_fr;
> > > alvium->frame_interval.numerator = fi->interval.numerator;
> > > alvium->frame_interval.denominator = fi->interval.denominator;
> > >
> > > @@ -1708,6 +1704,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > struct v4l2_subdev_frame_interval *fi)
> > > {
> > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > + u64 req_fr;
> > > int ret;
> > >
> > > /*
> > > @@ -1720,9 +1717,9 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > if (alvium->streaming)
> > > return -EBUSY;
> > >
> > > - ret = alvium_set_frame_interval(alvium, fi);
> > > + ret = alvium_set_frame_interval(alvium, sd, sd_state, fi, &req_fr);
> > > if (!ret)
> > > - ret = alvium_set_frame_rate(alvium);
> > > + ret = alvium_set_frame_rate(alvium, req_fr);
> > >
> > > return ret;
> > > }
> > > diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
> > > index 8b554bffdc39..a6529b28e7dd 100644
> > > --- a/drivers/media/i2c/alvium-csi2.h
> > > +++ b/drivers/media/i2c/alvium-csi2.h
> > > @@ -443,9 +443,6 @@ struct alvium_dev {
> > >
> > > struct alvium_mode mode;
> > > struct v4l2_fract frame_interval;
> > > - u64 dft_fr;
> > > - u64 min_fr;
> > > - u64 max_fr;
> > > u64 fr;
> > >
> > > u8 h_sup_csi_lanes;

Plan for v2 is splitting this series
into another patch as you suggest:

media: i2c: alvium: removal of dft_fr, min_fr and max_fr
+ media: i2c: alvium: removal of fr field
media: i2c: alvium: store frame interval in subdev state
media: i2c: alvium: inline set_frame_interval into s_frame_interval

Thanks & Regards,
Tommaso


>
> --
> Regards,
>
> Laurent Pinchart

2023-12-18 10:30:29

by Tommaso Merciai

[permalink] [raw]
Subject: Re: [PATCH 2/3] media: i2c: alvium: inline set_frame_interval into s_frame_interval

Hi Laurent,

On Mon, Dec 18, 2023 at 04:55:07AM +0200, Laurent Pinchart wrote:
> Hi Tommaso,
>
> Thank you for the patch.
>
> On Fri, Dec 15, 2023 at 09:24:51AM +0100, Tommaso Merciai wrote:
> > Inline alvium_s_frame_interval function into alvium_s_frame_interval.
>
> I think you mean "alvium_set_frame_interval() function into
> alvium_s_frame_interval.()"
>
> > This to clean the driver code.
>
> You can describe the reason more precisely:
>
> The alvium_set_frame_interval() is called once only, by
> alvium_s_frame_interval(). The latter is a thin wrapper around the
> former. Inline the function in its caller to make the code more
> readable.
>
> The rest looks good to me.

Yep, thanks for the review and for fixing commit body.
I will fix that in v2.

Thanks & Regards,
Tommaso

>
> > Signed-off-by: Tommaso Merciai <[email protected]>
> > ---
> > drivers/media/i2c/alvium-csi2.c | 56 ++++++++++++---------------------
> > 1 file changed, 20 insertions(+), 36 deletions(-)
> >
> > diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> > index c4b7851045a1..fde456357be1 100644
> > --- a/drivers/media/i2c/alvium-csi2.c
> > +++ b/drivers/media/i2c/alvium-csi2.c
> > @@ -1662,16 +1662,25 @@ static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> > return 0;
> > }
> >
> > -static int alvium_set_frame_interval(struct alvium_dev *alvium,
> > - struct v4l2_subdev *sd,
> > - struct v4l2_subdev_state *sd_state,
> > - struct v4l2_subdev_frame_interval *fi,
> > - u64 *req_fr)
> > +static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > + struct v4l2_subdev_state *sd_state,
> > + struct v4l2_subdev_frame_interval *fi)
> > {
> > + struct alvium_dev *alvium = sd_to_alvium(sd);
> > struct device *dev = &alvium->i2c_client->dev;
> > - u64 dft_fr, min_fr, max_fr;
> > + u64 req_fr, dft_fr, min_fr, max_fr;
> > int ret;
> >
> > + /*
> > + * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
> > + * subdev active state API.
> > + */
> > + if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> > + return -EINVAL;
> > +
> > + if (alvium->streaming)
> > + return -EBUSY;
> > +
> > if (fi->interval.denominator == 0)
> > return -EINVAL;
> >
> > @@ -1686,42 +1695,17 @@ static int alvium_set_frame_interval(struct alvium_dev *alvium,
> > dev_dbg(dev, "fi->interval.denominator = %d\n",
> > fi->interval.denominator);
> >
> > - *req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
> > + req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) /
> > fi->interval.numerator);
> >
> > - if (*req_fr >= max_fr && *req_fr <= min_fr)
> > - *req_fr = dft_fr;
> > + if (req_fr >= max_fr && req_fr <= min_fr)
> > + req_fr = dft_fr;
> >
> > - alvium->fr = *req_fr;
> > + alvium->fr = req_fr;
> > alvium->frame_interval.numerator = fi->interval.numerator;
> > alvium->frame_interval.denominator = fi->interval.denominator;
> >
> > - return 0;
> > -}
> > -
> > -static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > - struct v4l2_subdev_state *sd_state,
> > - struct v4l2_subdev_frame_interval *fi)
> > -{
> > - struct alvium_dev *alvium = sd_to_alvium(sd);
> > - u64 req_fr;
> > - int ret;
> > -
> > - /*
> > - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
> > - * subdev active state API.
> > - */
> > - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> > - return -EINVAL;
> > -
> > - if (alvium->streaming)
> > - return -EBUSY;
> > -
> > - ret = alvium_set_frame_interval(alvium, sd, sd_state, fi, &req_fr);
> > - if (!ret)
> > - ret = alvium_set_frame_rate(alvium, req_fr);
> > -
> > - return ret;
> > + return alvium_set_frame_rate(alvium, req_fr);
> > }
> >
> > static int alvium_enum_mbus_code(struct v4l2_subdev *sd,
>
> --
> Regards,
>
> Laurent Pinchart

2023-12-18 10:31:45

by Tommaso Merciai

[permalink] [raw]
Subject: Re: [PATCH 3/3] media: i2c: alvium: store frame interval in subdev state

Hi Laurent,

On Mon, Dec 18, 2023 at 04:59:05AM +0200, Laurent Pinchart wrote:
> Hi Tommaso,
>
> Thank you for the patch.
>
> On Fri, Dec 15, 2023 at 09:24:52AM +0100, Tommaso Merciai wrote:
> > Use the newly added storage for frame interval in the subdev state to
> > simplify the driver.
> >
> > Signed-off-by: Tommaso Merciai <[email protected]>
> > ---
> > drivers/media/i2c/alvium-csi2.c | 40 ++++++++++-----------------------
> > drivers/media/i2c/alvium-csi2.h | 2 --
> > 2 files changed, 12 insertions(+), 30 deletions(-)
> >
> > diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> > index fde456357be1..81f683b3c849 100644
> > --- a/drivers/media/i2c/alvium-csi2.c
> > +++ b/drivers/media/i2c/alvium-csi2.c
> > @@ -1643,25 +1643,6 @@ static int alvium_hw_init(struct alvium_dev *alvium)
> > }
> >
> > /* --------------- Subdev Operations --------------- */
> > -
> > -static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> > - struct v4l2_subdev_state *sd_state,
> > - struct v4l2_subdev_frame_interval *fi)
> > -{
> > - struct alvium_dev *alvium = sd_to_alvium(sd);
> > -
> > - /*
> > - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
> > - * subdev active state API.
> > - */
> > - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> > - return -EINVAL;
> > -
> > - fi->interval = alvium->frame_interval;
> > -
> > - return 0;
> > -}
> > -
> > static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > struct v4l2_subdev_state *sd_state,
> > struct v4l2_subdev_frame_interval *fi)
> > @@ -1669,6 +1650,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > struct alvium_dev *alvium = sd_to_alvium(sd);
> > struct device *dev = &alvium->i2c_client->dev;
> > u64 req_fr, dft_fr, min_fr, max_fr;
> > + struct v4l2_fract *interval;
> > int ret;
> >
> > /*
>
> You should drop the FIXME comment here and the ACTIVE check...

Oks, thanks.

>
> > @@ -1701,9 +1683,10 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > if (req_fr >= max_fr && req_fr <= min_fr)
> > req_fr = dft_fr;
> >
> > - alvium->fr = req_fr;
> > - alvium->frame_interval.numerator = fi->interval.numerator;
> > - alvium->frame_interval.denominator = fi->interval.denominator;
> > + interval = v4l2_subdev_state_get_interval(sd_state, 0);
> > +
> > + interval->numerator = fi->interval.numerator;
> > + interval->denominator = fi->interval.denominator;
> >
>
>
> ... and here only call alvium_set_frame_rate() for the ACTIVE frame
> interval.

I don't completely got this comment, can you give me more details about
please. Thanks in advance!

Regards,
Tommaso

>
> > return alvium_set_frame_rate(alvium, req_fr);
> > }
> > @@ -1853,6 +1836,7 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > {
> > struct alvium_dev *alvium = sd_to_alvium(sd);
> > struct alvium_mode *mode = &alvium->mode;
> > + struct v4l2_fract *interval;
> > struct v4l2_subdev_format sd_fmt = {
> > .which = V4L2_SUBDEV_FORMAT_TRY,
> > .format = alvium_csi2_default_fmt,
> > @@ -1870,6 +1854,11 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > *v4l2_subdev_state_get_crop(state, 0) = sd_crop.rect;
> > *v4l2_subdev_state_get_format(state, 0) = sd_fmt.format;
> >
> > + /* Setup initial frame interval*/
> > + interval = v4l2_subdev_state_get_interval(state, 0);
> > + interval->numerator = 1;
> > + interval->denominator = ALVIUM_DEFAULT_FR_HZ;
> > +
> > return 0;
> > }
> >
> > @@ -2239,7 +2228,7 @@ static const struct v4l2_subdev_pad_ops alvium_pad_ops = {
> > .set_fmt = alvium_set_fmt,
> > .get_selection = alvium_get_selection,
> > .set_selection = alvium_set_selection,
> > - .get_frame_interval = alvium_g_frame_interval,
> > + .get_frame_interval = v4l2_subdev_get_frame_interval,
> > .set_frame_interval = alvium_s_frame_interval,
> > };
> >
> > @@ -2260,11 +2249,6 @@ static int alvium_subdev_init(struct alvium_dev *alvium)
> > struct v4l2_subdev *sd = &alvium->sd;
> > int ret;
> >
> > - /* Setup initial frame interval*/
> > - alvium->frame_interval.numerator = 1;
> > - alvium->frame_interval.denominator = ALVIUM_DEFAULT_FR_HZ;
> > - alvium->fr = ALVIUM_DEFAULT_FR_HZ;
> > -
> > /* Setup the initial mode */
> > alvium->mode.fmt = alvium_csi2_default_fmt;
> > alvium->mode.width = alvium_csi2_default_fmt.width;
> > diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
> > index a6529b28e7dd..f5e26257b042 100644
> > --- a/drivers/media/i2c/alvium-csi2.h
> > +++ b/drivers/media/i2c/alvium-csi2.h
> > @@ -442,8 +442,6 @@ struct alvium_dev {
> > s32 inc_sharp;
> >
> > struct alvium_mode mode;
> > - struct v4l2_fract frame_interval;
> > - u64 fr;
>
> The fr field should have been removed by a previous patch (the one that
> will go between 1/3 an 2/3, see my review of 1/3) as shown by the fact
> that this patch only removes two locations where the field is set but
> none where it's read.
>
> >
> > u8 h_sup_csi_lanes;
> > u64 link_freq;
>
> --
> Regards,
>
> Laurent Pinchart

2023-12-18 11:03:43

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH 3/3] media: i2c: alvium: store frame interval in subdev state

On Mon, Dec 18, 2023 at 11:30:38AM +0100, Tommaso Merciai wrote:
> Hi Laurent,
>
> On Mon, Dec 18, 2023 at 04:59:05AM +0200, Laurent Pinchart wrote:
> > Hi Tommaso,
> >
> > Thank you for the patch.
> >
> > On Fri, Dec 15, 2023 at 09:24:52AM +0100, Tommaso Merciai wrote:
> > > Use the newly added storage for frame interval in the subdev state to
> > > simplify the driver.
> > >
> > > Signed-off-by: Tommaso Merciai <[email protected]>
> > > ---
> > > drivers/media/i2c/alvium-csi2.c | 40 ++++++++++-----------------------
> > > drivers/media/i2c/alvium-csi2.h | 2 --
> > > 2 files changed, 12 insertions(+), 30 deletions(-)
> > >
> > > diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> > > index fde456357be1..81f683b3c849 100644
> > > --- a/drivers/media/i2c/alvium-csi2.c
> > > +++ b/drivers/media/i2c/alvium-csi2.c
> > > @@ -1643,25 +1643,6 @@ static int alvium_hw_init(struct alvium_dev *alvium)
> > > }
> > >
> > > /* --------------- Subdev Operations --------------- */
> > > -
> > > -static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> > > - struct v4l2_subdev_state *sd_state,
> > > - struct v4l2_subdev_frame_interval *fi)
> > > -{
> > > - struct alvium_dev *alvium = sd_to_alvium(sd);
> > > -
> > > - /*
> > > - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
> > > - * subdev active state API.
> > > - */
> > > - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> > > - return -EINVAL;
> > > -
> > > - fi->interval = alvium->frame_interval;
> > > -
> > > - return 0;
> > > -}
> > > -
> > > static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > struct v4l2_subdev_state *sd_state,
> > > struct v4l2_subdev_frame_interval *fi)
> > > @@ -1669,6 +1650,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > struct device *dev = &alvium->i2c_client->dev;
> > > u64 req_fr, dft_fr, min_fr, max_fr;
> > > + struct v4l2_fract *interval;
> > > int ret;
> > >
> > > /*
> >
> > You should drop the FIXME comment here and the ACTIVE check...
>
> Oks, thanks.
>
> >
> > > @@ -1701,9 +1683,10 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > if (req_fr >= max_fr && req_fr <= min_fr)
> > > req_fr = dft_fr;
> > >
> > > - alvium->fr = req_fr;
> > > - alvium->frame_interval.numerator = fi->interval.numerator;
> > > - alvium->frame_interval.denominator = fi->interval.denominator;
> > > + interval = v4l2_subdev_state_get_interval(sd_state, 0);
> > > +
> > > + interval->numerator = fi->interval.numerator;
> > > + interval->denominator = fi->interval.denominator;
> > >
> >
> > ... and here only call alvium_set_frame_rate() for the ACTIVE frame
> > interval.
>
> I don't completely got this comment, can you give me more details about
> please. Thanks in advance!

alvium_s_frame_interval() can be called both for the TRY and ACTIVE
status. The hardware registers should be written only for the ACTIVE
state.

> > > return alvium_set_frame_rate(alvium, req_fr);
> > > }
> > > @@ -1853,6 +1836,7 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > > {
> > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > struct alvium_mode *mode = &alvium->mode;
> > > + struct v4l2_fract *interval;
> > > struct v4l2_subdev_format sd_fmt = {
> > > .which = V4L2_SUBDEV_FORMAT_TRY,
> > > .format = alvium_csi2_default_fmt,
> > > @@ -1870,6 +1854,11 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > > *v4l2_subdev_state_get_crop(state, 0) = sd_crop.rect;
> > > *v4l2_subdev_state_get_format(state, 0) = sd_fmt.format;
> > >
> > > + /* Setup initial frame interval*/
> > > + interval = v4l2_subdev_state_get_interval(state, 0);
> > > + interval->numerator = 1;
> > > + interval->denominator = ALVIUM_DEFAULT_FR_HZ;
> > > +
> > > return 0;
> > > }
> > >
> > > @@ -2239,7 +2228,7 @@ static const struct v4l2_subdev_pad_ops alvium_pad_ops = {
> > > .set_fmt = alvium_set_fmt,
> > > .get_selection = alvium_get_selection,
> > > .set_selection = alvium_set_selection,
> > > - .get_frame_interval = alvium_g_frame_interval,
> > > + .get_frame_interval = v4l2_subdev_get_frame_interval,
> > > .set_frame_interval = alvium_s_frame_interval,
> > > };
> > >
> > > @@ -2260,11 +2249,6 @@ static int alvium_subdev_init(struct alvium_dev *alvium)
> > > struct v4l2_subdev *sd = &alvium->sd;
> > > int ret;
> > >
> > > - /* Setup initial frame interval*/
> > > - alvium->frame_interval.numerator = 1;
> > > - alvium->frame_interval.denominator = ALVIUM_DEFAULT_FR_HZ;
> > > - alvium->fr = ALVIUM_DEFAULT_FR_HZ;
> > > -
> > > /* Setup the initial mode */
> > > alvium->mode.fmt = alvium_csi2_default_fmt;
> > > alvium->mode.width = alvium_csi2_default_fmt.width;
> > > diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
> > > index a6529b28e7dd..f5e26257b042 100644
> > > --- a/drivers/media/i2c/alvium-csi2.h
> > > +++ b/drivers/media/i2c/alvium-csi2.h
> > > @@ -442,8 +442,6 @@ struct alvium_dev {
> > > s32 inc_sharp;
> > >
> > > struct alvium_mode mode;
> > > - struct v4l2_fract frame_interval;
> > > - u64 fr;
> >
> > The fr field should have been removed by a previous patch (the one that
> > will go between 1/3 an 2/3, see my review of 1/3) as shown by the fact
> > that this patch only removes two locations where the field is set but
> > none where it's read.
> >
> > >
> > > u8 h_sup_csi_lanes;
> > > u64 link_freq;

--
Regards,

Laurent Pinchart

2023-12-18 11:19:56

by Tommaso Merciai

[permalink] [raw]
Subject: Re: [PATCH 3/3] media: i2c: alvium: store frame interval in subdev state

Hi Laurent,
Thanks for your quick reply.

On Mon, Dec 18, 2023 at 01:03:31PM +0200, Laurent Pinchart wrote:
> On Mon, Dec 18, 2023 at 11:30:38AM +0100, Tommaso Merciai wrote:
> > Hi Laurent,
> >
> > On Mon, Dec 18, 2023 at 04:59:05AM +0200, Laurent Pinchart wrote:
> > > Hi Tommaso,
> > >
> > > Thank you for the patch.
> > >
> > > On Fri, Dec 15, 2023 at 09:24:52AM +0100, Tommaso Merciai wrote:
> > > > Use the newly added storage for frame interval in the subdev state to
> > > > simplify the driver.
> > > >
> > > > Signed-off-by: Tommaso Merciai <[email protected]>
> > > > ---
> > > > drivers/media/i2c/alvium-csi2.c | 40 ++++++++++-----------------------
> > > > drivers/media/i2c/alvium-csi2.h | 2 --
> > > > 2 files changed, 12 insertions(+), 30 deletions(-)
> > > >
> > > > diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> > > > index fde456357be1..81f683b3c849 100644
> > > > --- a/drivers/media/i2c/alvium-csi2.c
> > > > +++ b/drivers/media/i2c/alvium-csi2.c
> > > > @@ -1643,25 +1643,6 @@ static int alvium_hw_init(struct alvium_dev *alvium)
> > > > }
> > > >
> > > > /* --------------- Subdev Operations --------------- */
> > > > -
> > > > -static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> > > > - struct v4l2_subdev_state *sd_state,
> > > > - struct v4l2_subdev_frame_interval *fi)
> > > > -{
> > > > - struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > -
> > > > - /*
> > > > - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
> > > > - * subdev active state API.
> > > > - */
> > > > - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> > > > - return -EINVAL;
> > > > -
> > > > - fi->interval = alvium->frame_interval;
> > > > -
> > > > - return 0;
> > > > -}
> > > > -
> > > > static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > struct v4l2_subdev_state *sd_state,
> > > > struct v4l2_subdev_frame_interval *fi)
> > > > @@ -1669,6 +1650,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > struct device *dev = &alvium->i2c_client->dev;
> > > > u64 req_fr, dft_fr, min_fr, max_fr;
> > > > + struct v4l2_fract *interval;
> > > > int ret;
> > > >
> > > > /*
> > >
> > > You should drop the FIXME comment here and the ACTIVE check...
> >
> > Oks, thanks.
> >
> > >
> > > > @@ -1701,9 +1683,10 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > if (req_fr >= max_fr && req_fr <= min_fr)
> > > > req_fr = dft_fr;
> > > >
> > > > - alvium->fr = req_fr;
> > > > - alvium->frame_interval.numerator = fi->interval.numerator;
> > > > - alvium->frame_interval.denominator = fi->interval.denominator;
> > > > + interval = v4l2_subdev_state_get_interval(sd_state, 0);
> > > > +
> > > > + interval->numerator = fi->interval.numerator;
> > > > + interval->denominator = fi->interval.denominator;
> > > >
> > >
> > > ... and here only call alvium_set_frame_rate() for the ACTIVE frame
> > > interval.
> >
> > I don't completely got this comment, can you give me more details about
> > please. Thanks in advance!
>
> alvium_s_frame_interval() can be called both for the TRY and ACTIVE
> status. The hardware registers should be written only for the ACTIVE
> state.

Do you think could be sufficient an if check like this?

- return alvium_set_frame_rate(alvium, req_fr);
+ if (fi->which == V4L2_SUBDEV_FORMAT_ACTIVE)
+ return alvium_set_frame_rate(alvium, req_fr);
+
+ return ret;
}

Thanks & Regards,
Tommaso

> > > > @@ -1853,6 +1836,7 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > > > {
> > > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > struct alvium_mode *mode = &alvium->mode;
> > > > + struct v4l2_fract *interval;
> > > > struct v4l2_subdev_format sd_fmt = {
> > > > .which = V4L2_SUBDEV_FORMAT_TRY,
> > > > .format = alvium_csi2_default_fmt,
> > > > @@ -1870,6 +1854,11 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > > > *v4l2_subdev_state_get_crop(state, 0) = sd_crop.rect;
> > > > *v4l2_subdev_state_get_format(state, 0) = sd_fmt.format;
> > > >
> > > > + /* Setup initial frame interval*/
> > > > + interval = v4l2_subdev_state_get_interval(state, 0);
> > > > + interval->numerator = 1;
> > > > + interval->denominator = ALVIUM_DEFAULT_FR_HZ;
> > > > +
> > > > return 0;
> > > > }
> > > >
> > > > @@ -2239,7 +2228,7 @@ static const struct v4l2_subdev_pad_ops alvium_pad_ops = {
> > > > .set_fmt = alvium_set_fmt,
> > > > .get_selection = alvium_get_selection,
> > > > .set_selection = alvium_set_selection,
> > > > - .get_frame_interval = alvium_g_frame_interval,
> > > > + .get_frame_interval = v4l2_subdev_get_frame_interval,
> > > > .set_frame_interval = alvium_s_frame_interval,
> > > > };
> > > >
> > > > @@ -2260,11 +2249,6 @@ static int alvium_subdev_init(struct alvium_dev *alvium)
> > > > struct v4l2_subdev *sd = &alvium->sd;
> > > > int ret;
> > > >
> > > > - /* Setup initial frame interval*/
> > > > - alvium->frame_interval.numerator = 1;
> > > > - alvium->frame_interval.denominator = ALVIUM_DEFAULT_FR_HZ;
> > > > - alvium->fr = ALVIUM_DEFAULT_FR_HZ;
> > > > -
> > > > /* Setup the initial mode */
> > > > alvium->mode.fmt = alvium_csi2_default_fmt;
> > > > alvium->mode.width = alvium_csi2_default_fmt.width;
> > > > diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
> > > > index a6529b28e7dd..f5e26257b042 100644
> > > > --- a/drivers/media/i2c/alvium-csi2.h
> > > > +++ b/drivers/media/i2c/alvium-csi2.h
> > > > @@ -442,8 +442,6 @@ struct alvium_dev {
> > > > s32 inc_sharp;
> > > >
> > > > struct alvium_mode mode;
> > > > - struct v4l2_fract frame_interval;
> > > > - u64 fr;
> > >
> > > The fr field should have been removed by a previous patch (the one that
> > > will go between 1/3 an 2/3, see my review of 1/3) as shown by the fact
> > > that this patch only removes two locations where the field is set but
> > > none where it's read.
> > >
> > > >
> > > > u8 h_sup_csi_lanes;
> > > > u64 link_freq;
>
> --
> Regards,
>
> Laurent Pinchart

2023-12-18 11:38:15

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH 3/3] media: i2c: alvium: store frame interval in subdev state

On Mon, Dec 18, 2023 at 12:19:36PM +0100, Tommaso Merciai wrote:
> On Mon, Dec 18, 2023 at 01:03:31PM +0200, Laurent Pinchart wrote:
> > On Mon, Dec 18, 2023 at 11:30:38AM +0100, Tommaso Merciai wrote:
> > > On Mon, Dec 18, 2023 at 04:59:05AM +0200, Laurent Pinchart wrote:
> > > > On Fri, Dec 15, 2023 at 09:24:52AM +0100, Tommaso Merciai wrote:
> > > > > Use the newly added storage for frame interval in the subdev state to
> > > > > simplify the driver.
> > > > >
> > > > > Signed-off-by: Tommaso Merciai <[email protected]>
> > > > > ---
> > > > > drivers/media/i2c/alvium-csi2.c | 40 ++++++++++-----------------------
> > > > > drivers/media/i2c/alvium-csi2.h | 2 --
> > > > > 2 files changed, 12 insertions(+), 30 deletions(-)
> > > > >
> > > > > diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> > > > > index fde456357be1..81f683b3c849 100644
> > > > > --- a/drivers/media/i2c/alvium-csi2.c
> > > > > +++ b/drivers/media/i2c/alvium-csi2.c
> > > > > @@ -1643,25 +1643,6 @@ static int alvium_hw_init(struct alvium_dev *alvium)
> > > > > }
> > > > >
> > > > > /* --------------- Subdev Operations --------------- */
> > > > > -
> > > > > -static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> > > > > - struct v4l2_subdev_state *sd_state,
> > > > > - struct v4l2_subdev_frame_interval *fi)
> > > > > -{
> > > > > - struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > > -
> > > > > - /*
> > > > > - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
> > > > > - * subdev active state API.
> > > > > - */
> > > > > - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> > > > > - return -EINVAL;
> > > > > -
> > > > > - fi->interval = alvium->frame_interval;
> > > > > -
> > > > > - return 0;
> > > > > -}
> > > > > -
> > > > > static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > > struct v4l2_subdev_state *sd_state,
> > > > > struct v4l2_subdev_frame_interval *fi)
> > > > > @@ -1669,6 +1650,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > > struct device *dev = &alvium->i2c_client->dev;
> > > > > u64 req_fr, dft_fr, min_fr, max_fr;
> > > > > + struct v4l2_fract *interval;
> > > > > int ret;
> > > > >
> > > > > /*
> > > >
> > > > You should drop the FIXME comment here and the ACTIVE check...
> > >
> > > Oks, thanks.
> > >
> > > >
> > > > > @@ -1701,9 +1683,10 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > > if (req_fr >= max_fr && req_fr <= min_fr)
> > > > > req_fr = dft_fr;
> > > > >
> > > > > - alvium->fr = req_fr;
> > > > > - alvium->frame_interval.numerator = fi->interval.numerator;
> > > > > - alvium->frame_interval.denominator = fi->interval.denominator;
> > > > > + interval = v4l2_subdev_state_get_interval(sd_state, 0);
> > > > > +
> > > > > + interval->numerator = fi->interval.numerator;
> > > > > + interval->denominator = fi->interval.denominator;
> > > > >
> > > >
> > > > ... and here only call alvium_set_frame_rate() for the ACTIVE frame
> > > > interval.
> > >
> > > I don't completely got this comment, can you give me more details about
> > > please. Thanks in advance!
> >
> > alvium_s_frame_interval() can be called both for the TRY and ACTIVE
> > status. The hardware registers should be written only for the ACTIVE
> > state.
>
> Do you think could be sufficient an if check like this?
>
> - return alvium_set_frame_rate(alvium, req_fr);
> + if (fi->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> + return alvium_set_frame_rate(alvium, req_fr);
> +
> + return ret;

That's the idea, yes. The "return ret" can become "return 0". Or you
could write

if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
return 0;

return alvium_set_frame_rate(alvium, req_fr);

> }
>
> > > > > @@ -1853,6 +1836,7 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > > > > {
> > > > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > > struct alvium_mode *mode = &alvium->mode;
> > > > > + struct v4l2_fract *interval;
> > > > > struct v4l2_subdev_format sd_fmt = {
> > > > > .which = V4L2_SUBDEV_FORMAT_TRY,
> > > > > .format = alvium_csi2_default_fmt,
> > > > > @@ -1870,6 +1854,11 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > > > > *v4l2_subdev_state_get_crop(state, 0) = sd_crop.rect;
> > > > > *v4l2_subdev_state_get_format(state, 0) = sd_fmt.format;
> > > > >
> > > > > + /* Setup initial frame interval*/
> > > > > + interval = v4l2_subdev_state_get_interval(state, 0);
> > > > > + interval->numerator = 1;
> > > > > + interval->denominator = ALVIUM_DEFAULT_FR_HZ;
> > > > > +
> > > > > return 0;
> > > > > }
> > > > >
> > > > > @@ -2239,7 +2228,7 @@ static const struct v4l2_subdev_pad_ops alvium_pad_ops = {
> > > > > .set_fmt = alvium_set_fmt,
> > > > > .get_selection = alvium_get_selection,
> > > > > .set_selection = alvium_set_selection,
> > > > > - .get_frame_interval = alvium_g_frame_interval,
> > > > > + .get_frame_interval = v4l2_subdev_get_frame_interval,
> > > > > .set_frame_interval = alvium_s_frame_interval,
> > > > > };
> > > > >
> > > > > @@ -2260,11 +2249,6 @@ static int alvium_subdev_init(struct alvium_dev *alvium)
> > > > > struct v4l2_subdev *sd = &alvium->sd;
> > > > > int ret;
> > > > >
> > > > > - /* Setup initial frame interval*/
> > > > > - alvium->frame_interval.numerator = 1;
> > > > > - alvium->frame_interval.denominator = ALVIUM_DEFAULT_FR_HZ;
> > > > > - alvium->fr = ALVIUM_DEFAULT_FR_HZ;
> > > > > -
> > > > > /* Setup the initial mode */
> > > > > alvium->mode.fmt = alvium_csi2_default_fmt;
> > > > > alvium->mode.width = alvium_csi2_default_fmt.width;
> > > > > diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
> > > > > index a6529b28e7dd..f5e26257b042 100644
> > > > > --- a/drivers/media/i2c/alvium-csi2.h
> > > > > +++ b/drivers/media/i2c/alvium-csi2.h
> > > > > @@ -442,8 +442,6 @@ struct alvium_dev {
> > > > > s32 inc_sharp;
> > > > >
> > > > > struct alvium_mode mode;
> > > > > - struct v4l2_fract frame_interval;
> > > > > - u64 fr;
> > > >
> > > > The fr field should have been removed by a previous patch (the one that
> > > > will go between 1/3 an 2/3, see my review of 1/3) as shown by the fact
> > > > that this patch only removes two locations where the field is set but
> > > > none where it's read.
> > > >
> > > > >
> > > > > u8 h_sup_csi_lanes;
> > > > > u64 link_freq;

--
Regards,

Laurent Pinchart

2023-12-18 11:48:04

by Tommaso Merciai

[permalink] [raw]
Subject: Re: [PATCH 3/3] media: i2c: alvium: store frame interval in subdev state

On Mon, Dec 18, 2023 at 01:36:18PM +0200, Laurent Pinchart wrote:
> On Mon, Dec 18, 2023 at 12:19:36PM +0100, Tommaso Merciai wrote:
> > On Mon, Dec 18, 2023 at 01:03:31PM +0200, Laurent Pinchart wrote:
> > > On Mon, Dec 18, 2023 at 11:30:38AM +0100, Tommaso Merciai wrote:
> > > > On Mon, Dec 18, 2023 at 04:59:05AM +0200, Laurent Pinchart wrote:
> > > > > On Fri, Dec 15, 2023 at 09:24:52AM +0100, Tommaso Merciai wrote:
> > > > > > Use the newly added storage for frame interval in the subdev state to
> > > > > > simplify the driver.
> > > > > >
> > > > > > Signed-off-by: Tommaso Merciai <[email protected]>
> > > > > > ---
> > > > > > drivers/media/i2c/alvium-csi2.c | 40 ++++++++++-----------------------
> > > > > > drivers/media/i2c/alvium-csi2.h | 2 --
> > > > > > 2 files changed, 12 insertions(+), 30 deletions(-)
> > > > > >
> > > > > > diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> > > > > > index fde456357be1..81f683b3c849 100644
> > > > > > --- a/drivers/media/i2c/alvium-csi2.c
> > > > > > +++ b/drivers/media/i2c/alvium-csi2.c
> > > > > > @@ -1643,25 +1643,6 @@ static int alvium_hw_init(struct alvium_dev *alvium)
> > > > > > }
> > > > > >
> > > > > > /* --------------- Subdev Operations --------------- */
> > > > > > -
> > > > > > -static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> > > > > > - struct v4l2_subdev_state *sd_state,
> > > > > > - struct v4l2_subdev_frame_interval *fi)
> > > > > > -{
> > > > > > - struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > > > -
> > > > > > - /*
> > > > > > - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
> > > > > > - * subdev active state API.
> > > > > > - */
> > > > > > - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> > > > > > - return -EINVAL;
> > > > > > -
> > > > > > - fi->interval = alvium->frame_interval;
> > > > > > -
> > > > > > - return 0;
> > > > > > -}
> > > > > > -
> > > > > > static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > > > struct v4l2_subdev_state *sd_state,
> > > > > > struct v4l2_subdev_frame_interval *fi)
> > > > > > @@ -1669,6 +1650,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > > > struct device *dev = &alvium->i2c_client->dev;
> > > > > > u64 req_fr, dft_fr, min_fr, max_fr;
> > > > > > + struct v4l2_fract *interval;
> > > > > > int ret;
> > > > > >
> > > > > > /*
> > > > >
> > > > > You should drop the FIXME comment here and the ACTIVE check...
> > > >
> > > > Oks, thanks.
> > > >
> > > > >
> > > > > > @@ -1701,9 +1683,10 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > > > if (req_fr >= max_fr && req_fr <= min_fr)
> > > > > > req_fr = dft_fr;
> > > > > >
> > > > > > - alvium->fr = req_fr;
> > > > > > - alvium->frame_interval.numerator = fi->interval.numerator;
> > > > > > - alvium->frame_interval.denominator = fi->interval.denominator;
> > > > > > + interval = v4l2_subdev_state_get_interval(sd_state, 0);
> > > > > > +
> > > > > > + interval->numerator = fi->interval.numerator;
> > > > > > + interval->denominator = fi->interval.denominator;
> > > > > >
> > > > >
> > > > > ... and here only call alvium_set_frame_rate() for the ACTIVE frame
> > > > > interval.
> > > >
> > > > I don't completely got this comment, can you give me more details about
> > > > please. Thanks in advance!
> > >
> > > alvium_s_frame_interval() can be called both for the TRY and ACTIVE
> > > status. The hardware registers should be written only for the ACTIVE
> > > state.
> >
> > Do you think could be sufficient an if check like this?
> >
> > - return alvium_set_frame_rate(alvium, req_fr);
> > + if (fi->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> > + return alvium_set_frame_rate(alvium, req_fr);
> > +
> > + return ret;
>
> That's the idea, yes. The "return ret" can become "return 0". Or you
> could write
>
> if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> return 0;
>
> return alvium_set_frame_rate(alvium, req_fr);
>
> > }

(This is my personal idea eh :) )

Maybe better:

if (fi->which == V4L2_SUBDEV_FORMAT_ACTIVE)
ret = alvium_set_frame_rate(alvium, req_fr);

return ret;

What do you think?

Regards,
Tommaso

> >
> > > > > > @@ -1853,6 +1836,7 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > > > > > {
> > > > > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > > > struct alvium_mode *mode = &alvium->mode;
> > > > > > + struct v4l2_fract *interval;
> > > > > > struct v4l2_subdev_format sd_fmt = {
> > > > > > .which = V4L2_SUBDEV_FORMAT_TRY,
> > > > > > .format = alvium_csi2_default_fmt,
> > > > > > @@ -1870,6 +1854,11 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > > > > > *v4l2_subdev_state_get_crop(state, 0) = sd_crop.rect;
> > > > > > *v4l2_subdev_state_get_format(state, 0) = sd_fmt.format;
> > > > > >
> > > > > > + /* Setup initial frame interval*/
> > > > > > + interval = v4l2_subdev_state_get_interval(state, 0);
> > > > > > + interval->numerator = 1;
> > > > > > + interval->denominator = ALVIUM_DEFAULT_FR_HZ;
> > > > > > +
> > > > > > return 0;
> > > > > > }
> > > > > >
> > > > > > @@ -2239,7 +2228,7 @@ static const struct v4l2_subdev_pad_ops alvium_pad_ops = {
> > > > > > .set_fmt = alvium_set_fmt,
> > > > > > .get_selection = alvium_get_selection,
> > > > > > .set_selection = alvium_set_selection,
> > > > > > - .get_frame_interval = alvium_g_frame_interval,
> > > > > > + .get_frame_interval = v4l2_subdev_get_frame_interval,
> > > > > > .set_frame_interval = alvium_s_frame_interval,
> > > > > > };
> > > > > >
> > > > > > @@ -2260,11 +2249,6 @@ static int alvium_subdev_init(struct alvium_dev *alvium)
> > > > > > struct v4l2_subdev *sd = &alvium->sd;
> > > > > > int ret;
> > > > > >
> > > > > > - /* Setup initial frame interval*/
> > > > > > - alvium->frame_interval.numerator = 1;
> > > > > > - alvium->frame_interval.denominator = ALVIUM_DEFAULT_FR_HZ;
> > > > > > - alvium->fr = ALVIUM_DEFAULT_FR_HZ;
> > > > > > -
> > > > > > /* Setup the initial mode */
> > > > > > alvium->mode.fmt = alvium_csi2_default_fmt;
> > > > > > alvium->mode.width = alvium_csi2_default_fmt.width;
> > > > > > diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
> > > > > > index a6529b28e7dd..f5e26257b042 100644
> > > > > > --- a/drivers/media/i2c/alvium-csi2.h
> > > > > > +++ b/drivers/media/i2c/alvium-csi2.h
> > > > > > @@ -442,8 +442,6 @@ struct alvium_dev {
> > > > > > s32 inc_sharp;
> > > > > >
> > > > > > struct alvium_mode mode;
> > > > > > - struct v4l2_fract frame_interval;
> > > > > > - u64 fr;
> > > > >
> > > > > The fr field should have been removed by a previous patch (the one that
> > > > > will go between 1/3 an 2/3, see my review of 1/3) as shown by the fact
> > > > > that this patch only removes two locations where the field is set but
> > > > > none where it's read.
> > > > >
> > > > > >
> > > > > > u8 h_sup_csi_lanes;
> > > > > > u64 link_freq;
>
> --
> Regards,
>
> Laurent Pinchart

2023-12-18 12:03:04

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH 3/3] media: i2c: alvium: store frame interval in subdev state

On Mon, Dec 18, 2023 at 12:39:53PM +0100, Tommaso Merciai wrote:
> On Mon, Dec 18, 2023 at 01:36:18PM +0200, Laurent Pinchart wrote:
> > On Mon, Dec 18, 2023 at 12:19:36PM +0100, Tommaso Merciai wrote:
> > > On Mon, Dec 18, 2023 at 01:03:31PM +0200, Laurent Pinchart wrote:
> > > > On Mon, Dec 18, 2023 at 11:30:38AM +0100, Tommaso Merciai wrote:
> > > > > On Mon, Dec 18, 2023 at 04:59:05AM +0200, Laurent Pinchart wrote:
> > > > > > On Fri, Dec 15, 2023 at 09:24:52AM +0100, Tommaso Merciai wrote:
> > > > > > > Use the newly added storage for frame interval in the subdev state to
> > > > > > > simplify the driver.
> > > > > > >
> > > > > > > Signed-off-by: Tommaso Merciai <[email protected]>
> > > > > > > ---
> > > > > > > drivers/media/i2c/alvium-csi2.c | 40 ++++++++++-----------------------
> > > > > > > drivers/media/i2c/alvium-csi2.h | 2 --
> > > > > > > 2 files changed, 12 insertions(+), 30 deletions(-)
> > > > > > >
> > > > > > > diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> > > > > > > index fde456357be1..81f683b3c849 100644
> > > > > > > --- a/drivers/media/i2c/alvium-csi2.c
> > > > > > > +++ b/drivers/media/i2c/alvium-csi2.c
> > > > > > > @@ -1643,25 +1643,6 @@ static int alvium_hw_init(struct alvium_dev *alvium)
> > > > > > > }
> > > > > > >
> > > > > > > /* --------------- Subdev Operations --------------- */
> > > > > > > -
> > > > > > > -static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> > > > > > > - struct v4l2_subdev_state *sd_state,
> > > > > > > - struct v4l2_subdev_frame_interval *fi)
> > > > > > > -{
> > > > > > > - struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > > > > -
> > > > > > > - /*
> > > > > > > - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
> > > > > > > - * subdev active state API.
> > > > > > > - */
> > > > > > > - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> > > > > > > - return -EINVAL;
> > > > > > > -
> > > > > > > - fi->interval = alvium->frame_interval;
> > > > > > > -
> > > > > > > - return 0;
> > > > > > > -}
> > > > > > > -
> > > > > > > static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > > > > struct v4l2_subdev_state *sd_state,
> > > > > > > struct v4l2_subdev_frame_interval *fi)
> > > > > > > @@ -1669,6 +1650,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > > > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > > > > struct device *dev = &alvium->i2c_client->dev;
> > > > > > > u64 req_fr, dft_fr, min_fr, max_fr;
> > > > > > > + struct v4l2_fract *interval;
> > > > > > > int ret;
> > > > > > >
> > > > > > > /*
> > > > > >
> > > > > > You should drop the FIXME comment here and the ACTIVE check...
> > > > >
> > > > > Oks, thanks.
> > > > >
> > > > > > > @@ -1701,9 +1683,10 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > > > > if (req_fr >= max_fr && req_fr <= min_fr)
> > > > > > > req_fr = dft_fr;
> > > > > > >
> > > > > > > - alvium->fr = req_fr;
> > > > > > > - alvium->frame_interval.numerator = fi->interval.numerator;
> > > > > > > - alvium->frame_interval.denominator = fi->interval.denominator;
> > > > > > > + interval = v4l2_subdev_state_get_interval(sd_state, 0);
> > > > > > > +
> > > > > > > + interval->numerator = fi->interval.numerator;
> > > > > > > + interval->denominator = fi->interval.denominator;
> > > > > > >
> > > > > >
> > > > > > ... and here only call alvium_set_frame_rate() for the ACTIVE frame
> > > > > > interval.
> > > > >
> > > > > I don't completely got this comment, can you give me more details about
> > > > > please. Thanks in advance!
> > > >
> > > > alvium_s_frame_interval() can be called both for the TRY and ACTIVE
> > > > status. The hardware registers should be written only for the ACTIVE
> > > > state.
> > >
> > > Do you think could be sufficient an if check like this?
> > >
> > > - return alvium_set_frame_rate(alvium, req_fr);
> > > + if (fi->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> > > + return alvium_set_frame_rate(alvium, req_fr);
> > > +
> > > + return ret;
> >
> > That's the idea, yes. The "return ret" can become "return 0". Or you
> > could write
> >
> > if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> > return 0;
> >
> > return alvium_set_frame_rate(alvium, req_fr);
> >
> > > }
>
> (This is my personal idea eh :) )
>
> Maybe better:
>
> if (fi->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> ret = alvium_set_frame_rate(alvium, req_fr);
>
> return ret;

Works fine too (assuming ret gets initialized properly).

> > > > > > > @@ -1853,6 +1836,7 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > > > > > > {
> > > > > > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > > > > struct alvium_mode *mode = &alvium->mode;
> > > > > > > + struct v4l2_fract *interval;
> > > > > > > struct v4l2_subdev_format sd_fmt = {
> > > > > > > .which = V4L2_SUBDEV_FORMAT_TRY,
> > > > > > > .format = alvium_csi2_default_fmt,
> > > > > > > @@ -1870,6 +1854,11 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > > > > > > *v4l2_subdev_state_get_crop(state, 0) = sd_crop.rect;
> > > > > > > *v4l2_subdev_state_get_format(state, 0) = sd_fmt.format;
> > > > > > >
> > > > > > > + /* Setup initial frame interval*/
> > > > > > > + interval = v4l2_subdev_state_get_interval(state, 0);
> > > > > > > + interval->numerator = 1;
> > > > > > > + interval->denominator = ALVIUM_DEFAULT_FR_HZ;
> > > > > > > +
> > > > > > > return 0;
> > > > > > > }
> > > > > > >
> > > > > > > @@ -2239,7 +2228,7 @@ static const struct v4l2_subdev_pad_ops alvium_pad_ops = {
> > > > > > > .set_fmt = alvium_set_fmt,
> > > > > > > .get_selection = alvium_get_selection,
> > > > > > > .set_selection = alvium_set_selection,
> > > > > > > - .get_frame_interval = alvium_g_frame_interval,
> > > > > > > + .get_frame_interval = v4l2_subdev_get_frame_interval,
> > > > > > > .set_frame_interval = alvium_s_frame_interval,
> > > > > > > };
> > > > > > >
> > > > > > > @@ -2260,11 +2249,6 @@ static int alvium_subdev_init(struct alvium_dev *alvium)
> > > > > > > struct v4l2_subdev *sd = &alvium->sd;
> > > > > > > int ret;
> > > > > > >
> > > > > > > - /* Setup initial frame interval*/
> > > > > > > - alvium->frame_interval.numerator = 1;
> > > > > > > - alvium->frame_interval.denominator = ALVIUM_DEFAULT_FR_HZ;
> > > > > > > - alvium->fr = ALVIUM_DEFAULT_FR_HZ;
> > > > > > > -
> > > > > > > /* Setup the initial mode */
> > > > > > > alvium->mode.fmt = alvium_csi2_default_fmt;
> > > > > > > alvium->mode.width = alvium_csi2_default_fmt.width;
> > > > > > > diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
> > > > > > > index a6529b28e7dd..f5e26257b042 100644
> > > > > > > --- a/drivers/media/i2c/alvium-csi2.h
> > > > > > > +++ b/drivers/media/i2c/alvium-csi2.h
> > > > > > > @@ -442,8 +442,6 @@ struct alvium_dev {
> > > > > > > s32 inc_sharp;
> > > > > > >
> > > > > > > struct alvium_mode mode;
> > > > > > > - struct v4l2_fract frame_interval;
> > > > > > > - u64 fr;
> > > > > >
> > > > > > The fr field should have been removed by a previous patch (the one that
> > > > > > will go between 1/3 an 2/3, see my review of 1/3) as shown by the fact
> > > > > > that this patch only removes two locations where the field is set but
> > > > > > none where it's read.
> > > > > >
> > > > > > >
> > > > > > > u8 h_sup_csi_lanes;
> > > > > > > u64 link_freq;

--
Regards,

Laurent Pinchart

2023-12-18 12:03:04

by Tommaso Merciai

[permalink] [raw]
Subject: Re: [PATCH 3/3] media: i2c: alvium: store frame interval in subdev state

On Mon, Dec 18, 2023 at 01:44:37PM +0200, Laurent Pinchart wrote:
> On Mon, Dec 18, 2023 at 12:39:53PM +0100, Tommaso Merciai wrote:
> > On Mon, Dec 18, 2023 at 01:36:18PM +0200, Laurent Pinchart wrote:
> > > On Mon, Dec 18, 2023 at 12:19:36PM +0100, Tommaso Merciai wrote:
> > > > On Mon, Dec 18, 2023 at 01:03:31PM +0200, Laurent Pinchart wrote:
> > > > > On Mon, Dec 18, 2023 at 11:30:38AM +0100, Tommaso Merciai wrote:
> > > > > > On Mon, Dec 18, 2023 at 04:59:05AM +0200, Laurent Pinchart wrote:
> > > > > > > On Fri, Dec 15, 2023 at 09:24:52AM +0100, Tommaso Merciai wrote:
> > > > > > > > Use the newly added storage for frame interval in the subdev state to
> > > > > > > > simplify the driver.
> > > > > > > >
> > > > > > > > Signed-off-by: Tommaso Merciai <[email protected]>
> > > > > > > > ---
> > > > > > > > drivers/media/i2c/alvium-csi2.c | 40 ++++++++++-----------------------
> > > > > > > > drivers/media/i2c/alvium-csi2.h | 2 --
> > > > > > > > 2 files changed, 12 insertions(+), 30 deletions(-)
> > > > > > > >
> > > > > > > > diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> > > > > > > > index fde456357be1..81f683b3c849 100644
> > > > > > > > --- a/drivers/media/i2c/alvium-csi2.c
> > > > > > > > +++ b/drivers/media/i2c/alvium-csi2.c
> > > > > > > > @@ -1643,25 +1643,6 @@ static int alvium_hw_init(struct alvium_dev *alvium)
> > > > > > > > }
> > > > > > > >
> > > > > > > > /* --------------- Subdev Operations --------------- */
> > > > > > > > -
> > > > > > > > -static int alvium_g_frame_interval(struct v4l2_subdev *sd,
> > > > > > > > - struct v4l2_subdev_state *sd_state,
> > > > > > > > - struct v4l2_subdev_frame_interval *fi)
> > > > > > > > -{
> > > > > > > > - struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > > > > > -
> > > > > > > > - /*
> > > > > > > > - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
> > > > > > > > - * subdev active state API.
> > > > > > > > - */
> > > > > > > > - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> > > > > > > > - return -EINVAL;
> > > > > > > > -
> > > > > > > > - fi->interval = alvium->frame_interval;
> > > > > > > > -
> > > > > > > > - return 0;
> > > > > > > > -}
> > > > > > > > -
> > > > > > > > static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > > > > > struct v4l2_subdev_state *sd_state,
> > > > > > > > struct v4l2_subdev_frame_interval *fi)
> > > > > > > > @@ -1669,6 +1650,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > > > > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > > > > > struct device *dev = &alvium->i2c_client->dev;
> > > > > > > > u64 req_fr, dft_fr, min_fr, max_fr;
> > > > > > > > + struct v4l2_fract *interval;
> > > > > > > > int ret;
> > > > > > > >
> > > > > > > > /*
> > > > > > >
> > > > > > > You should drop the FIXME comment here and the ACTIVE check...
> > > > > >
> > > > > > Oks, thanks.
> > > > > >
> > > > > > > > @@ -1701,9 +1683,10 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> > > > > > > > if (req_fr >= max_fr && req_fr <= min_fr)
> > > > > > > > req_fr = dft_fr;
> > > > > > > >
> > > > > > > > - alvium->fr = req_fr;
> > > > > > > > - alvium->frame_interval.numerator = fi->interval.numerator;
> > > > > > > > - alvium->frame_interval.denominator = fi->interval.denominator;
> > > > > > > > + interval = v4l2_subdev_state_get_interval(sd_state, 0);
> > > > > > > > +
> > > > > > > > + interval->numerator = fi->interval.numerator;
> > > > > > > > + interval->denominator = fi->interval.denominator;
> > > > > > > >
> > > > > > >
> > > > > > > ... and here only call alvium_set_frame_rate() for the ACTIVE frame
> > > > > > > interval.
> > > > > >
> > > > > > I don't completely got this comment, can you give me more details about
> > > > > > please. Thanks in advance!
> > > > >
> > > > > alvium_s_frame_interval() can be called both for the TRY and ACTIVE
> > > > > status. The hardware registers should be written only for the ACTIVE
> > > > > state.
> > > >
> > > > Do you think could be sufficient an if check like this?
> > > >
> > > > - return alvium_set_frame_rate(alvium, req_fr);
> > > > + if (fi->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> > > > + return alvium_set_frame_rate(alvium, req_fr);
> > > > +
> > > > + return ret;
> > >
> > > That's the idea, yes. The "return ret" can become "return 0". Or you
> > > could write
> > >
> > > if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> > > return 0;
> > >
> > > return alvium_set_frame_rate(alvium, req_fr);
> > >
> > > > }
> >
> > (This is my personal idea eh :) )
> >
> > Maybe better:
> >
> > if (fi->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> > ret = alvium_set_frame_rate(alvium, req_fr);
> >
> > return ret;
>
> Works fine too (assuming ret gets initialized properly).

Arg... good catch, thanks. :)
I will take your proposal then into v2.

Thanks again! :),
Tommaso

>
> > > > > > > > @@ -1853,6 +1836,7 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > > > > > > > {
> > > > > > > > struct alvium_dev *alvium = sd_to_alvium(sd);
> > > > > > > > struct alvium_mode *mode = &alvium->mode;
> > > > > > > > + struct v4l2_fract *interval;
> > > > > > > > struct v4l2_subdev_format sd_fmt = {
> > > > > > > > .which = V4L2_SUBDEV_FORMAT_TRY,
> > > > > > > > .format = alvium_csi2_default_fmt,
> > > > > > > > @@ -1870,6 +1854,11 @@ static int alvium_init_state(struct v4l2_subdev *sd,
> > > > > > > > *v4l2_subdev_state_get_crop(state, 0) = sd_crop.rect;
> > > > > > > > *v4l2_subdev_state_get_format(state, 0) = sd_fmt.format;
> > > > > > > >
> > > > > > > > + /* Setup initial frame interval*/
> > > > > > > > + interval = v4l2_subdev_state_get_interval(state, 0);
> > > > > > > > + interval->numerator = 1;
> > > > > > > > + interval->denominator = ALVIUM_DEFAULT_FR_HZ;
> > > > > > > > +
> > > > > > > > return 0;
> > > > > > > > }
> > > > > > > >
> > > > > > > > @@ -2239,7 +2228,7 @@ static const struct v4l2_subdev_pad_ops alvium_pad_ops = {
> > > > > > > > .set_fmt = alvium_set_fmt,
> > > > > > > > .get_selection = alvium_get_selection,
> > > > > > > > .set_selection = alvium_set_selection,
> > > > > > > > - .get_frame_interval = alvium_g_frame_interval,
> > > > > > > > + .get_frame_interval = v4l2_subdev_get_frame_interval,
> > > > > > > > .set_frame_interval = alvium_s_frame_interval,
> > > > > > > > };
> > > > > > > >
> > > > > > > > @@ -2260,11 +2249,6 @@ static int alvium_subdev_init(struct alvium_dev *alvium)
> > > > > > > > struct v4l2_subdev *sd = &alvium->sd;
> > > > > > > > int ret;
> > > > > > > >
> > > > > > > > - /* Setup initial frame interval*/
> > > > > > > > - alvium->frame_interval.numerator = 1;
> > > > > > > > - alvium->frame_interval.denominator = ALVIUM_DEFAULT_FR_HZ;
> > > > > > > > - alvium->fr = ALVIUM_DEFAULT_FR_HZ;
> > > > > > > > -
> > > > > > > > /* Setup the initial mode */
> > > > > > > > alvium->mode.fmt = alvium_csi2_default_fmt;
> > > > > > > > alvium->mode.width = alvium_csi2_default_fmt.width;
> > > > > > > > diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
> > > > > > > > index a6529b28e7dd..f5e26257b042 100644
> > > > > > > > --- a/drivers/media/i2c/alvium-csi2.h
> > > > > > > > +++ b/drivers/media/i2c/alvium-csi2.h
> > > > > > > > @@ -442,8 +442,6 @@ struct alvium_dev {
> > > > > > > > s32 inc_sharp;
> > > > > > > >
> > > > > > > > struct alvium_mode mode;
> > > > > > > > - struct v4l2_fract frame_interval;
> > > > > > > > - u64 fr;
> > > > > > >
> > > > > > > The fr field should have been removed by a previous patch (the one that
> > > > > > > will go between 1/3 an 2/3, see my review of 1/3) as shown by the fact
> > > > > > > that this patch only removes two locations where the field is set but
> > > > > > > none where it's read.
> > > > > > >
> > > > > > > >
> > > > > > > > u8 h_sup_csi_lanes;
> > > > > > > > u64 link_freq;
>
> --
> Regards,
>
> Laurent Pinchart