]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: v4l: Convert the users of v4l2_get_link_freq to call it on a pad
authorSakari Ailus <sakari.ailus@linux.intel.com>
Mon, 16 Dec 2024 09:25:31 +0000 (11:25 +0200)
committerHans Verkuil <hverkuil@xs4all.nl>
Sat, 15 Feb 2025 14:22:58 +0000 (15:22 +0100)
Call v4l2_get_link_freq() on a pad, instead of a control handler. This way
we can soon convert v4l2_get_link_freq() to be callable only on a pad and
remove the compatibility code.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Naushir Patuck <naush@raspberrypi.com> # rp1-cfe
Acked-by: Benjamin Mugnier <benjamin.mugnier@foss.st.com> # st-mipid02
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
15 files changed:
drivers/media/i2c/st-mipid02.c
drivers/media/i2c/tc358746.c
drivers/media/pci/intel/ipu3/ipu3-cio2.c
drivers/media/platform/cadence/cdns-csi2rx.c
drivers/media/platform/nxp/imx-mipi-csis.c
drivers/media/platform/nxp/imx8mq-mipi-csi2.c
drivers/media/platform/qcom/camss/camss-vfe-gen1.c
drivers/media/platform/qcom/camss/camss-vfe.c
drivers/media/platform/qcom/camss/camss.c
drivers/media/platform/qcom/camss/camss.h
drivers/media/platform/raspberrypi/rp1-cfe/cfe.c
drivers/media/platform/st/stm32/stm32-csi.c
drivers/media/platform/ti/cal/cal-camerarx.c
drivers/media/platform/ti/cal/cal.c
drivers/media/platform/ti/cal/cal.h

index f08db3cfe076b8d573f26c1ed5323ca1550559e8..f4568e87f0187dc669b6cd6ae924ad866bcc35b3 100644 (file)
@@ -301,8 +301,9 @@ static int mipid02_detect(struct mipid02_dev *bridge)
 static int mipid02_configure_from_rx_speed(struct mipid02_dev *bridge,
                                           struct v4l2_mbus_framefmt *fmt)
 {
+       struct media_pad *remote =
+               &bridge->s_subdev->entity.pads[bridge->s_subdev_pad_id];
        struct i2c_client *client = bridge->i2c_client;
-       struct v4l2_subdev *subdev = bridge->s_subdev;
        struct v4l2_fwnode_endpoint *ep = &bridge->rx;
        u32 bpp = bpp_from_code(fmt->code);
        /*
@@ -312,7 +313,7 @@ static int mipid02_configure_from_rx_speed(struct mipid02_dev *bridge,
        u64 ui_4 = 2000000000;
        s64 link_freq;
 
-       link_freq = v4l2_get_link_freq(subdev->ctrl_handler, bpp,
+       link_freq = v4l2_get_link_freq(remote, bpp,
                                       2 * ep->bus.mipi_csi2.num_data_lanes);
        if (link_freq < 0) {
                dev_err(&client->dev, "Failed to get link frequency");
index 389582420ba78204a5e55c17dea0f14569fe6721..31586f8e4be4e5c06296a4806aed3c77d10f433e 100644 (file)
@@ -896,6 +896,7 @@ tc358746_link_validate(struct v4l2_subdev *sd, struct media_link *link,
        const struct tc358746_format *fmt;
        unsigned int fifo_sz, tmp, n;
        struct v4l2_subdev *source;
+       struct media_pad *src_pad;
        s64 source_link_freq;
        int err;
 
@@ -910,7 +911,8 @@ tc358746_link_validate(struct v4l2_subdev *sd, struct media_link *link,
        fmt = tc358746_get_format_by_code(TC358746_SINK, mbusfmt->code);
 
        source = media_entity_to_v4l2_subdev(link->source->entity);
-       source_link_freq = v4l2_get_link_freq(source->ctrl_handler, 0, 0);
+       src_pad = &source->entity.pads[source_fmt->pad];
+       source_link_freq = v4l2_get_link_freq(src_pad, 0, 0);
        if (source_link_freq <= 0) {
                dev_err(tc358746->sd.dev,
                        "Failed to query or invalid source link frequency\n");
index dd73d534ac490b2d88f709d4c34801fb04728ee3..0c365eb59085f4cb4763963dfe1055c1d5cad62e 100644 (file)
@@ -309,12 +309,17 @@ static int cio2_csi2_calc_timing(struct cio2_device *cio2, struct cio2_queue *q,
                                 unsigned int bpp, unsigned int lanes)
 {
        struct device *dev = &cio2->pci_dev->dev;
+       struct media_pad *src_pad;
        s64 freq;
 
-       if (!q->sensor)
-               return -ENODEV;
+       src_pad = media_entity_remote_source_pad_unique(&q->subdev.entity);
+       if (IS_ERR(src_pad)) {
+               dev_err(dev, "can't get source pad of %s (%ld)\n",
+                       q->subdev.name, PTR_ERR(src_pad));
+               return PTR_ERR(src_pad);
+       }
 
-       freq = v4l2_get_link_freq(q->sensor->ctrl_handler, bpp, lanes * 2);
+       freq = v4l2_get_link_freq(src_pad, bpp, lanes * 2);
        if (freq < 0) {
                dev_err(dev, "error %lld, invalid link_freq\n", freq);
                return freq;
index 4d64df829e7585b6e305651f3ff9bdd008508ec5..cebcae196eeccc65548d2c8e14bcba4799415beb 100644 (file)
@@ -164,6 +164,8 @@ static void csi2rx_reset(struct csi2rx_priv *csi2rx)
 
 static int csi2rx_configure_ext_dphy(struct csi2rx_priv *csi2rx)
 {
+       struct media_pad *src_pad =
+               &csi2rx->source_subdev->entity.pads[csi2rx->source_pad];
        union phy_configure_opts opts = { };
        struct phy_configure_opts_mipi_dphy *cfg = &opts.mipi_dphy;
        struct v4l2_subdev_format sd_fmt = {
@@ -181,7 +183,7 @@ static int csi2rx_configure_ext_dphy(struct csi2rx_priv *csi2rx)
 
        fmt = csi2rx_get_fmt_by_code(sd_fmt.format.code);
 
-       link_freq = v4l2_get_link_freq(csi2rx->source_subdev->ctrl_handler,
+       link_freq = v4l2_get_link_freq(src_pad,
                                       fmt->bpp, 2 * csi2rx->num_lanes);
        if (link_freq < 0)
                return link_freq;
index 29523bb84d9563e71a4175e8b6d87df2db06b5ea..d060eadebc7a63bbc2d92d0b5e3503cdc4c775bc 100644 (file)
@@ -597,12 +597,13 @@ static void __mipi_csis_set_format(struct mipi_csis_device *csis,
 static int mipi_csis_calculate_params(struct mipi_csis_device *csis,
                                      const struct csis_pix_format *csis_fmt)
 {
+       struct media_pad *src_pad =
+               &csis->source.sd->entity.pads[csis->source.pad->index];
        s64 link_freq;
        u32 lane_rate;
 
        /* Calculate the line rate from the pixel rate. */
-       link_freq = v4l2_get_link_freq(csis->source.sd->ctrl_handler,
-                                      csis_fmt->width,
+       link_freq = v4l2_get_link_freq(src_pad, csis_fmt->width,
                                       csis->bus.num_data_lanes * 2);
        if (link_freq < 0) {
                dev_err(csis->dev, "Unable to obtain link frequency: %d\n",
index 1f2657cf6e824248748b91f0909fd5bb740afc21..a8bcf60e2f37df6ff34add04124b60c3bc9933ed 100644 (file)
@@ -287,6 +287,7 @@ static int imx8mq_mipi_csi_calc_hs_settle(struct csi_state *state,
                                          struct v4l2_subdev_state *sd_state,
                                          u32 *hs_settle)
 {
+       struct media_pad *src_pad;
        s64 link_freq;
        u32 lane_rate;
        unsigned long esc_clk_rate;
@@ -294,13 +295,19 @@ static int imx8mq_mipi_csi_calc_hs_settle(struct csi_state *state,
        const struct v4l2_mbus_framefmt *fmt;
        const struct csi2_pix_format *csi2_fmt;
 
+       src_pad = media_entity_remote_source_pad_unique(&sd_state->sd->entity);
+       if (IS_ERR(src_pad)) {
+               dev_err(state->dev, "can't get source pad of %s (%ld)\n",
+                       sd_state->sd->name, PTR_ERR(src_pad));
+               return PTR_ERR(src_pad);
+       }
+
        /* Calculate the line rate from the pixel rate. */
 
        fmt = v4l2_subdev_state_get_format(sd_state, MIPI_CSI2_PAD_SINK);
        csi2_fmt = find_csi2_format(fmt->code);
 
-       link_freq = v4l2_get_link_freq(state->src_sd->ctrl_handler,
-                                      csi2_fmt->width,
+       link_freq = v4l2_get_link_freq(src_pad, csi2_fmt->width,
                                       state->bus.num_data_lanes * 2);
        if (link_freq < 0) {
                dev_err(state->dev, "Unable to obtain link frequency: %d\n",
index eb33c03df27e55ea9bb1778ccae25df433e7a85c..d84a375e331878acec839966513553eb534b08ce 100644 (file)
@@ -170,7 +170,7 @@ static int vfe_enable_output(struct vfe_line *line)
        struct vfe_device *vfe = to_vfe(line);
        struct vfe_output *output = &line->output;
        const struct vfe_hw_ops *ops = vfe->res->hw_ops;
-       struct media_entity *sensor;
+       struct media_pad *sensor_pad;
        unsigned long flags;
        unsigned int frame_skip = 0;
        unsigned int i;
@@ -180,9 +180,10 @@ static int vfe_enable_output(struct vfe_line *line)
        if (!ub_size)
                return -EINVAL;
 
-       sensor = camss_find_sensor(&line->subdev.entity);
-       if (sensor) {
-               struct v4l2_subdev *subdev = media_entity_to_v4l2_subdev(sensor);
+       sensor_pad = camss_find_sensor_pad(&line->subdev.entity);
+       if (sensor_pad) {
+               struct v4l2_subdev *subdev =
+                       media_entity_to_v4l2_subdev(sensor_pad->entity);
 
                v4l2_subdev_call(subdev, sensor, g_skip_frames, &frame_skip);
                /* Max frame skip is 29 frames */
index 9ffa6bc72cf1e6d6741eb11c00a02f1a89e9c43e..cf0e8f5c004a20381e05fc8b67e068282fa08c41 100644 (file)
@@ -499,14 +499,15 @@ int vfe_enable_output_v2(struct vfe_line *line)
        struct vfe_device *vfe = to_vfe(line);
        struct vfe_output *output = &line->output;
        const struct vfe_hw_ops *ops = vfe->res->hw_ops;
-       struct media_entity *sensor;
+       struct media_pad *sensor_pad;
        unsigned long flags;
        unsigned int frame_skip = 0;
        unsigned int i;
 
-       sensor = camss_find_sensor(&line->subdev.entity);
-       if (sensor) {
-               struct v4l2_subdev *subdev = media_entity_to_v4l2_subdev(sensor);
+       sensor_pad = camss_find_sensor_pad(&line->subdev.entity);
+       if (sensor_pad) {
+               struct v4l2_subdev *subdev =
+                       media_entity_to_v4l2_subdev(sensor_pad->entity);
 
                v4l2_subdev_call(subdev, sensor, g_skip_frames, &frame_skip);
                /* Max frame skip is 29 frames */
index 497235f47188e8487b2a3d58f83ab66ec66d832f..c0a75b81d870fb4e8b457807d6bb9b14ef813746 100644 (file)
@@ -2501,12 +2501,12 @@ void camss_disable_clocks(int nclocks, struct camss_clock *clock)
 }
 
 /*
- * camss_find_sensor - Find a linked media entity which represents a sensor
+ * camss_find_sensor_pad - Find the media pad via which the sensor is linked
  * @entity: Media entity to start searching from
  *
- * Return a pointer to sensor media entity or NULL if not found
+ * Return a pointer to sensor media pad or NULL if not found
  */
-struct media_entity *camss_find_sensor(struct media_entity *entity)
+struct media_pad *camss_find_sensor_pad(struct media_entity *entity)
 {
        struct media_pad *pad;
 
@@ -2522,7 +2522,7 @@ struct media_entity *camss_find_sensor(struct media_entity *entity)
                entity = pad->entity;
 
                if (entity->function == MEDIA_ENT_F_CAM_SENSOR)
-                       return entity;
+                       return pad;
        }
 }
 
@@ -2537,16 +2537,13 @@ struct media_entity *camss_find_sensor(struct media_entity *entity)
 s64 camss_get_link_freq(struct media_entity *entity, unsigned int bpp,
                        unsigned int lanes)
 {
-       struct media_entity *sensor;
-       struct v4l2_subdev *subdev;
+       struct media_pad *sensor_pad;
 
-       sensor = camss_find_sensor(entity);
-       if (!sensor)
+       sensor_pad = camss_find_sensor_pad(entity);
+       if (!sensor_pad)
                return -ENODEV;
 
-       subdev = media_entity_to_v4l2_subdev(sensor);
-
-       return v4l2_get_link_freq(subdev->ctrl_handler, bpp, 2 * lanes);
+       return v4l2_get_link_freq(sensor_pad, bpp, 2 * lanes);
 }
 
 /*
@@ -2558,15 +2555,15 @@ s64 camss_get_link_freq(struct media_entity *entity, unsigned int bpp,
  */
 int camss_get_pixel_clock(struct media_entity *entity, u64 *pixel_clock)
 {
-       struct media_entity *sensor;
+       struct media_pad *sensor_pad;
        struct v4l2_subdev *subdev;
        struct v4l2_ctrl *ctrl;
 
-       sensor = camss_find_sensor(entity);
-       if (!sensor)
+       sensor_pad = camss_find_sensor_pad(entity);
+       if (!sensor_pad)
                return -ENODEV;
 
-       subdev = media_entity_to_v4l2_subdev(sensor);
+       subdev = media_entity_to_v4l2_subdev(sensor_pad->entity);
 
        ctrl = v4l2_ctrl_find(subdev->ctrl_handler, V4L2_CID_PIXEL_RATE);
 
index 58fc61e7cf7ad4a28e7e1dea3cf7f22a0ff5c825..b284b910ce421c98df5e77f942f82486342bfcec 100644 (file)
@@ -154,7 +154,7 @@ void camss_add_clock_margin(u64 *rate);
 int camss_enable_clocks(int nclocks, struct camss_clock *clock,
                        struct device *dev);
 void camss_disable_clocks(int nclocks, struct camss_clock *clock);
-struct media_entity *camss_find_sensor(struct media_entity *entity);
+struct media_pad *camss_find_sensor_pad(struct media_entity *entity);
 s64 camss_get_link_freq(struct media_entity *entity, unsigned int bpp,
                        unsigned int lanes);
 int camss_get_pixel_clock(struct media_entity *entity, u64 *pixel_clock);
index 12660087b12f229a910041e3b6bd3d4525165020..ed3d18917f2d7d35efe64b1ed22f6258d2e763b7 100644 (file)
@@ -1102,6 +1102,8 @@ static void cfe_buffer_queue(struct vb2_buffer *vb)
 
 static s64 cfe_get_source_link_freq(struct cfe_device *cfe)
 {
+       struct media_pad *src_pad =
+               &cfe->source_sd->entity.pads[cfe->source_pad];
        struct v4l2_subdev_state *state;
        s64 link_freq;
        u32 bpp;
@@ -1136,7 +1138,7 @@ static s64 cfe_get_source_link_freq(struct cfe_device *cfe)
                bpp = 0;
        }
 
-       link_freq = v4l2_get_link_freq(cfe->source_sd->ctrl_handler, bpp,
+       link_freq = v4l2_get_link_freq(src_pad, bpp,
                                       2 * cfe->csi2.dphy.active_lanes);
        if (link_freq < 0)
                cfe_err(cfe, "failed to get link freq for subdev '%s'\n",
index 602b0879f21e21be5de580dbb30773e0c0817da6..b69048144cc12b90467a4807031314daf2cbefd0 100644 (file)
@@ -443,6 +443,8 @@ static void stm32_csi_phy_reg_write(struct stm32_csi_dev *csidev,
 static int stm32_csi_start(struct stm32_csi_dev *csidev,
                           struct v4l2_subdev_state *state)
 {
+       struct media_pad *src_pad =
+               &csidev->s_subdev->entity.pads[csidev->s_subdev_pad_nb];
        const struct stm32_csi_mbps_phy_reg *phy_regs = NULL;
        struct v4l2_mbus_framefmt *sink_fmt;
        const struct stm32_csi_fmts *fmt;
@@ -464,7 +466,7 @@ static int stm32_csi_start(struct stm32_csi_dev *csidev,
        if (!csidev->s_subdev)
                return -EIO;
 
-       link_freq = v4l2_get_link_freq(csidev->s_subdev->ctrl_handler,
+       link_freq = v4l2_get_link_freq(src_pad,
                                       fmt->bpp, 2 * csidev->num_lanes);
        if (link_freq < 0)
                return link_freq;
index 42dfe08b765f6bbdb0ab8cca0f7d6d87f2ff18eb..9cc875665695625963e37bcdf93bc4b918291d42 100644 (file)
@@ -65,7 +65,8 @@ static s64 cal_camerarx_get_ext_link_freq(struct cal_camerarx *phy)
 
        bpp = fmtinfo->bpp;
 
-       freq = v4l2_get_link_freq(phy->source->ctrl_handler, bpp, 2 * num_lanes);
+       freq = v4l2_get_link_freq(&phy->source->entity.pads[phy->source_pad],
+                                 bpp, 2 * num_lanes);
        if (freq < 0) {
                phy_err(phy, "failed to get link freq for subdev '%s'\n",
                        phy->source->name);
index 4bd2092e0255f701010bb82e8dbc1fed26121108..6cb3e5f4968623aef06927d8ec7b130f1000d286 100644 (file)
@@ -798,7 +798,6 @@ static int cal_async_notifier_bound(struct v4l2_async_notifier *notifier,
                return 0;
        }
 
-       phy->source = subdev;
        phy_dbg(1, phy, "Using source %s for capture\n", subdev->name);
 
        pad = media_entity_get_fwnode_pad(&subdev->entity,
@@ -820,6 +819,9 @@ static int cal_async_notifier_bound(struct v4l2_async_notifier *notifier,
                return ret;
        }
 
+       phy->source = subdev;
+       phy->source_pad = pad;
+
        return 0;
 }
 
index 0856297adc0bb2d5876b9fbfd75ba1cdf9009796..72a246a64d9e136d22054078b39202e338e35ab8 100644 (file)
@@ -174,6 +174,7 @@ struct cal_camerarx {
        struct device_node      *source_ep_node;
        struct device_node      *source_node;
        struct v4l2_subdev      *source;
+       unsigned int            source_pad;
 
        struct v4l2_subdev      subdev;
        struct media_pad        pads[CAL_CAMERARX_NUM_PADS];