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 media_stage tree[1]:
- media: i2c: mt9m114: use fsleep() in place of udelay() (02d4e62ae245)
- [1] https://git.linuxtv.org/media_stage.git/log/
Tommaso Merciai (4):
media: i2c: alvium: removal of dft_fr, min_fr and max_fr
media: i2c: alvium: removal of fr field
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 | 99 ++++++++++-----------------------
drivers/media/i2c/alvium-csi2.h | 5 --
2 files changed, 29 insertions(+), 75 deletions(-)
--
2.34.1
Use the newly added storage for frame interval in the subdev state to
simplify the driver.
Signed-off-by: Tommaso Merciai <[email protected]>
---
Changes Since v1:
- Removed FIXME comment and active state check into alvium_s_frame_interval
as suggested by LPinchart.
- Fixed call alvium_set_frame_rate() only for active state into alvium_s_frame_interval
as suggested by LPinchart.
drivers/media/i2c/alvium-csi2.c | 51 +++++++++++----------------------
drivers/media/i2c/alvium-csi2.h | 1 -
2 files changed, 16 insertions(+), 36 deletions(-)
diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
index b234d74454bf..240bf991105e 100644
--- a/drivers/media/i2c/alvium-csi2.c
+++ b/drivers/media/i2c/alvium-csi2.c
@@ -1641,42 +1641,16 @@ 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)
{
struct alvium_dev *alvium = sd_to_alvium(sd);
struct device *dev = &alvium->i2c_client->dev;
- u64 req_fr = ALVIUM_DEFAULT_FR_HZ;
- u64 dft_fr, min_fr, max_fr;
+ u64 req_fr, dft_fr, min_fr, max_fr;
+ struct v4l2_fract *interval;
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;
@@ -1700,8 +1674,13 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
if (req_fr >= max_fr && req_fr <= min_fr)
req_fr = dft_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;
+
+ if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
+ return 0;
return alvium_set_frame_rate(alvium, req_fr);
}
@@ -1851,6 +1830,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,
@@ -1868,6 +1848,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;
}
@@ -2237,7 +2222,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,
};
@@ -2258,10 +2243,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;
-
/* 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 80066ac25047..9463f8604fbc 100644
--- a/drivers/media/i2c/alvium-csi2.h
+++ b/drivers/media/i2c/alvium-csi2.h
@@ -442,7 +442,6 @@ struct alvium_dev {
s32 inc_sharp;
struct alvium_mode mode;
- struct v4l2_fract frame_interval;
u8 h_sup_csi_lanes;
u64 link_freq;
--
2.34.1
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]>
---
Changes Since v1:
- Fixed commit body as suggested by LPinchart
- Fixed alvium_get_frame_interval just return ret as suggested by LPinchart
- Removed unrelated chnages from the commit as suggested by LPinchart
drivers/media/i2c/alvium-csi2.c | 27 +++++++++------------------
drivers/media/i2c/alvium-csi2.h | 3 ---
2 files changed, 9 insertions(+), 21 deletions(-)
diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
index 34ff7fad3877..0dcd69bf9f92 100644
--- a/drivers/media/i2c/alvium-csi2.c
+++ b/drivers/media/i2c/alvium-csi2.c
@@ -1170,25 +1170,19 @@ 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);
- if (ret)
- return ret;
-
- alvium->dft_fr = dft_fr;
- alvium->min_fr = min_fr;
- alvium->max_fr = max_fr;
+ max_fr, &ret);
- return 0;
+ return ret;
}
static int alvium_set_frame_rate(struct alvium_dev *alvium)
@@ -1670,21 +1664,18 @@ static int alvium_set_frame_interval(struct alvium_dev *alvium,
struct v4l2_subdev_frame_interval *fi)
{
struct device *dev = &alvium->i2c_client->dev;
- u64 req_fr, min_fr, max_fr;
+ u64 req_fr, 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",
@@ -1694,7 +1685,7 @@ static int alvium_set_frame_interval(struct alvium_dev *alvium,
fi->interval.numerator);
if (req_fr >= max_fr && req_fr <= min_fr)
- req_fr = alvium->dft_fr;
+ req_fr = dft_fr;
alvium->fr = req_fr;
alvium->frame_interval.numerator = fi->interval.numerator;
diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
index b85a25169e79..17f0bbbd1839 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
Inline alvium_set_frame_interval() into alvium_s_frame_interval().
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.
Signed-off-by: Tommaso Merciai <[email protected]>
---
Changes Since v1:
- Now this commit is the 3/4 of the series
- Fixed commit body as suggested by LPinchart
drivers/media/i2c/alvium-csi2.c | 51 ++++++++++++---------------------
1 file changed, 19 insertions(+), 32 deletions(-)
diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
index a9ff6cc97cff..b234d74454bf 100644
--- a/drivers/media/i2c/alvium-csi2.c
+++ b/drivers/media/i2c/alvium-csi2.c
@@ -1660,14 +1660,26 @@ 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_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 req_fr = ALVIUM_DEFAULT_FR_HZ;
u64 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;
@@ -1682,41 +1694,16 @@ 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->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 = ALVIUM_DEFAULT_FR_HZ;
- 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, 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
Hi Tommaso,
Thank you for the patch.
On Wed, Dec 20, 2023 at 09:56:06AM +0100, Tommaso Merciai wrote:
> 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]>
Reviewed-by: Laurent Pinchart <[email protected]>
> ---
> Changes Since v1:
> - Fixed commit body as suggested by LPinchart
> - Fixed alvium_get_frame_interval just return ret as suggested by LPinchart
> - Removed unrelated chnages from the commit as suggested by LPinchart
>
> drivers/media/i2c/alvium-csi2.c | 27 +++++++++------------------
> drivers/media/i2c/alvium-csi2.h | 3 ---
> 2 files changed, 9 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> index 34ff7fad3877..0dcd69bf9f92 100644
> --- a/drivers/media/i2c/alvium-csi2.c
> +++ b/drivers/media/i2c/alvium-csi2.c
> @@ -1170,25 +1170,19 @@ 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);
> - if (ret)
> - return ret;
> -
> - alvium->dft_fr = dft_fr;
> - alvium->min_fr = min_fr;
> - alvium->max_fr = max_fr;
> + max_fr, &ret);
>
> - return 0;
> + return ret;
> }
>
> static int alvium_set_frame_rate(struct alvium_dev *alvium)
> @@ -1670,21 +1664,18 @@ static int alvium_set_frame_interval(struct alvium_dev *alvium,
> struct v4l2_subdev_frame_interval *fi)
> {
> struct device *dev = &alvium->i2c_client->dev;
> - u64 req_fr, min_fr, max_fr;
> + u64 req_fr, 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",
> @@ -1694,7 +1685,7 @@ static int alvium_set_frame_interval(struct alvium_dev *alvium,
> fi->interval.numerator);
>
> if (req_fr >= max_fr && req_fr <= min_fr)
> - req_fr = alvium->dft_fr;
> + req_fr = dft_fr;
>
> alvium->fr = req_fr;
> alvium->frame_interval.numerator = fi->interval.numerator;
> diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h
> index b85a25169e79..17f0bbbd1839 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
Hi Tommaso,
Thank you for the patch.
On Wed, Dec 20, 2023 at 09:56:08AM +0100, Tommaso Merciai wrote:
> Inline alvium_set_frame_interval() into alvium_s_frame_interval().
> 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.
>
> Signed-off-by: Tommaso Merciai <[email protected]>
> ---
> Changes Since v1:
> - Now this commit is the 3/4 of the series
> - Fixed commit body as suggested by LPinchart
>
> drivers/media/i2c/alvium-csi2.c | 51 ++++++++++++---------------------
> 1 file changed, 19 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> index a9ff6cc97cff..b234d74454bf 100644
> --- a/drivers/media/i2c/alvium-csi2.c
> +++ b/drivers/media/i2c/alvium-csi2.c
> @@ -1660,14 +1660,26 @@ 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_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 req_fr = ALVIUM_DEFAULT_FR_HZ;
No need to initialize the variable. With this fixed,
Reviewed-by: Laurent Pinchart <[email protected]>
> u64 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;
>
> @@ -1682,41 +1694,16 @@ 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->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 = ALVIUM_DEFAULT_FR_HZ;
> - 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, 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
Hi Tommaso,
Thank you for the patch.
On Wed, Dec 20, 2023 at 09:56:09AM +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]>
Reviewed-by: Laurent Pinchart <[email protected]>
> ---
> Changes Since v1:
> - Removed FIXME comment and active state check into alvium_s_frame_interval
> as suggested by LPinchart.
> - Fixed call alvium_set_frame_rate() only for active state into alvium_s_frame_interval
> as suggested by LPinchart.
>
> drivers/media/i2c/alvium-csi2.c | 51 +++++++++++----------------------
> drivers/media/i2c/alvium-csi2.h | 1 -
> 2 files changed, 16 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> index b234d74454bf..240bf991105e 100644
> --- a/drivers/media/i2c/alvium-csi2.c
> +++ b/drivers/media/i2c/alvium-csi2.c
> @@ -1641,42 +1641,16 @@ 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)
> {
> struct alvium_dev *alvium = sd_to_alvium(sd);
> struct device *dev = &alvium->i2c_client->dev;
> - u64 req_fr = ALVIUM_DEFAULT_FR_HZ;
> - u64 dft_fr, min_fr, max_fr;
> + u64 req_fr, dft_fr, min_fr, max_fr;
> + struct v4l2_fract *interval;
> 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;
>
> @@ -1700,8 +1674,13 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd,
> if (req_fr >= max_fr && req_fr <= min_fr)
> req_fr = dft_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;
> +
> + if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> + return 0;
>
> return alvium_set_frame_rate(alvium, req_fr);
> }
> @@ -1851,6 +1830,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,
> @@ -1868,6 +1848,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;
> }
>
> @@ -2237,7 +2222,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,
> };
>
> @@ -2258,10 +2243,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;
> -
> /* 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 80066ac25047..9463f8604fbc 100644
> --- a/drivers/media/i2c/alvium-csi2.h
> +++ b/drivers/media/i2c/alvium-csi2.h
> @@ -442,7 +442,6 @@ struct alvium_dev {
> s32 inc_sharp;
>
> struct alvium_mode mode;
> - struct v4l2_fract frame_interval;
>
> u8 h_sup_csi_lanes;
> u64 link_freq;
--
Regards,
Laurent Pinchart
Hi Laurent,
Thanks for your review.
On Wed, Dec 20, 2023 at 11:14:13AM +0200, Laurent Pinchart wrote:
> Hi Tommaso,
>
> Thank you for the patch.
>
> On Wed, Dec 20, 2023 at 09:56:08AM +0100, Tommaso Merciai wrote:
> > Inline alvium_set_frame_interval() into alvium_s_frame_interval().
> > 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.
> >
> > Signed-off-by: Tommaso Merciai <[email protected]>
> > ---
> > Changes Since v1:
> > - Now this commit is the 3/4 of the series
> > - Fixed commit body as suggested by LPinchart
> >
> > drivers/media/i2c/alvium-csi2.c | 51 ++++++++++++---------------------
> > 1 file changed, 19 insertions(+), 32 deletions(-)
> >
> > diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
> > index a9ff6cc97cff..b234d74454bf 100644
> > --- a/drivers/media/i2c/alvium-csi2.c
> > +++ b/drivers/media/i2c/alvium-csi2.c
> > @@ -1660,14 +1660,26 @@ 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_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 req_fr = ALVIUM_DEFAULT_FR_HZ;
>
> No need to initialize the variable. With this fixed,
Perfect, thanks I will drop this in v3.
Regards,
Tommaso
>
> Reviewed-by: Laurent Pinchart <[email protected]>
>
> > u64 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;
> >
> > @@ -1682,41 +1694,16 @@ 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->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 = ALVIUM_DEFAULT_FR_HZ;
> > - 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, 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