media: rcar-csi2: Prepare for C-PHY support
authorNiklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Mon, 24 Apr 2023 18:59:33 +0000 (20:59 +0200)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Thu, 25 May 2023 14:21:23 +0000 (16:21 +0200)
Gen4 will support both D-PHY and C-PHY, while Gen3 only supports D-PHY.
Add two flags to the device information structure to be able to record
what each SoC supports.

Extend the device node parsing to accept both CSI_2 D-PHY and C-PHY
buses, while at the same time taking the SoC support into account.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
[Sakari Ailus: Line wrap.]
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/platform/renesas/rcar-vin/rcar-csi2.c

index 1fe85db87d61b8b13734bfde7587679a420088e6..7a134c0eff571b0238b5835051766b01bdced037 100644 (file)
@@ -490,6 +490,8 @@ struct rcar_csi2_info {
        unsigned int num_channels;
        bool clear_ulps;
        bool use_isp;
+       bool support_dphy;
+       bool support_cphy;
 };
 
 struct rcar_csi2 {
@@ -511,6 +513,7 @@ struct rcar_csi2 {
        struct v4l2_mbus_framefmt mf;
        int stream_count;
 
+       bool cphy;
        unsigned short lanes;
        unsigned char lane_swap[4];
 };
@@ -665,7 +668,16 @@ static int rcsi2_get_active_lanes(struct rcar_csi2 *priv,
                return ret;
        }
 
-       if (mbus_config.type != V4L2_MBUS_CSI2_DPHY) {
+       switch (mbus_config.type) {
+       case V4L2_MBUS_CSI2_CPHY:
+               if (!priv->cphy)
+                       return -EINVAL;
+               break;
+       case V4L2_MBUS_CSI2_DPHY:
+               if (priv->cphy)
+                       return -EINVAL;
+               break;
+       default:
                dev_err(priv->dev, "Unsupported media bus type %u\n",
                        mbus_config.type);
                return -EINVAL;
@@ -1025,15 +1037,41 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
        if (vep->base.port || vep->base.id)
                return -ENOTCONN;
 
-       if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) {
-               dev_err(priv->dev, "Unsupported bus: %u\n", vep->bus_type);
-               return -EINVAL;
-       }
-
        priv->lanes = vep->bus.mipi_csi2.num_data_lanes;
-       if (priv->lanes != 1 && priv->lanes != 2 && priv->lanes != 4) {
-               dev_err(priv->dev, "Unsupported number of data-lanes: %u\n",
-                       priv->lanes);
+
+       switch (vep->bus_type) {
+       case V4L2_MBUS_CSI2_DPHY:
+               if (!priv->info->support_dphy) {
+                       dev_err(priv->dev, "D-PHY not supported\n");
+                       return -EINVAL;
+               }
+
+               if (priv->lanes != 1 && priv->lanes != 2 && priv->lanes != 4) {
+                       dev_err(priv->dev,
+                               "Unsupported number of data-lanes for D-PHY: %u\n",
+                               priv->lanes);
+                       return -EINVAL;
+               }
+
+               priv->cphy = false;
+               break;
+       case V4L2_MBUS_CSI2_CPHY:
+               if (!priv->info->support_cphy) {
+                       dev_err(priv->dev, "C-PHY not supported\n");
+                       return -EINVAL;
+               }
+
+               if (priv->lanes != 3) {
+                       dev_err(priv->dev,
+                               "Unsupported number of data-lanes for C-PHY: %u\n",
+                               priv->lanes);
+                       return -EINVAL;
+               }
+
+               priv->cphy = true;
+               break;
+       default:
+               dev_err(priv->dev, "Unsupported bus: %u\n", vep->bus_type);
                return -EINVAL;
        }
 
@@ -1057,7 +1095,7 @@ static int rcsi2_parse_dt(struct rcar_csi2 *priv)
        struct fwnode_handle *fwnode;
        struct fwnode_handle *ep;
        struct v4l2_fwnode_endpoint v4l2_ep = {
-               .bus_type = V4L2_MBUS_CSI2_DPHY
+               .bus_type = V4L2_MBUS_UNKNOWN,
        };
        int ret;
 
@@ -1378,6 +1416,7 @@ static const struct rcar_csi2_info rcar_csi2_info_r8a7795 = {
        .csi0clkfreqrange = 0x20,
        .num_channels = 4,
        .clear_ulps = true,
+       .support_dphy = true,
 };
 
 static const struct rcar_csi2_info rcar_csi2_info_r8a7795es2 = {
@@ -1388,6 +1427,7 @@ static const struct rcar_csi2_info rcar_csi2_info_r8a7795es2 = {
        .csi0clkfreqrange = 0x20,
        .num_channels = 4,
        .clear_ulps = true,
+       .support_dphy = true,
 };
 
 static const struct rcar_csi2_info rcar_csi2_info_r8a7796 = {
@@ -1395,6 +1435,7 @@ static const struct rcar_csi2_info rcar_csi2_info_r8a7796 = {
        .enter_standby = rcsi2_enter_standby_gen3,
        .hsfreqrange = hsfreqrange_m3w,
        .num_channels = 4,
+       .support_dphy = true,
 };
 
 static const struct rcar_csi2_info rcar_csi2_info_r8a77961 = {
@@ -1402,6 +1443,7 @@ static const struct rcar_csi2_info rcar_csi2_info_r8a77961 = {
        .enter_standby = rcsi2_enter_standby_gen3,
        .hsfreqrange = hsfreqrange_m3w,
        .num_channels = 4,
+       .support_dphy = true,
 };
 
 static const struct rcar_csi2_info rcar_csi2_info_r8a77965 = {
@@ -1412,6 +1454,7 @@ static const struct rcar_csi2_info rcar_csi2_info_r8a77965 = {
        .csi0clkfreqrange = 0x20,
        .num_channels = 4,
        .clear_ulps = true,
+       .support_dphy = true,
 };
 
 static const struct rcar_csi2_info rcar_csi2_info_r8a77970 = {
@@ -1420,6 +1463,7 @@ static const struct rcar_csi2_info rcar_csi2_info_r8a77970 = {
        .start_receiver = rcsi2_start_receiver_gen3,
        .enter_standby = rcsi2_enter_standby_gen3,
        .num_channels = 4,
+       .support_dphy = true,
 };
 
 static const struct rcar_csi2_info rcar_csi2_info_r8a77980 = {
@@ -1429,6 +1473,7 @@ static const struct rcar_csi2_info rcar_csi2_info_r8a77980 = {
        .hsfreqrange = hsfreqrange_h3_v3h_m3n,
        .csi0clkfreqrange = 0x20,
        .clear_ulps = true,
+       .support_dphy = true,
 };
 
 static const struct rcar_csi2_info rcar_csi2_info_r8a77990 = {
@@ -1437,6 +1482,7 @@ static const struct rcar_csi2_info rcar_csi2_info_r8a77990 = {
        .start_receiver = rcsi2_start_receiver_gen3,
        .enter_standby = rcsi2_enter_standby_gen3,
        .num_channels = 2,
+       .support_dphy = true,
 };
 
 static const struct rcar_csi2_info rcar_csi2_info_r8a779a0 = {
@@ -1447,6 +1493,7 @@ static const struct rcar_csi2_info rcar_csi2_info_r8a779a0 = {
        .csi0clkfreqrange = 0x20,
        .clear_ulps = true,
        .use_isp = true,
+       .support_dphy = true,
 };
 
 static const struct of_device_id rcar_csi2_of_table[] = {