From: André Apitzsch <g...@apitzsch.eu>

The imx214 camera is capable of either two-lane or four-lane operation.

Currently only the four-lane mode is supported, as proper pixel rates
and link frequences for the two-lane mode are unknown.

Signed-off-by: André Apitzsch <g...@apitzsch.eu>
---
 drivers/media/i2c/imx214.c | 37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/drivers/media/i2c/imx214.c b/drivers/media/i2c/imx214.c
index 4507e12dd4cd..3b422cddbdce 100644
--- a/drivers/media/i2c/imx214.c
+++ b/drivers/media/i2c/imx214.c
@@ -195,11 +195,13 @@ struct imx214 {
        struct regulator_bulk_data      supplies[IMX214_NUM_SUPPLIES];
 
        struct gpio_desc *enable_gpio;
+
+       /* Two or Four lanes */
+       u8 lanes;
 };
 
 /*From imx214_mode_tbls.h*/
 static const struct cci_reg_sequence mode_4096x2304[] = {
-       { IMX214_REG_CSI_LANE_MODE, IMX214_CSI_4_LANE_MODE },
        { IMX214_REG_HDR_MODE, IMX214_HDR_MODE_OFF },
        { IMX214_REG_HDR_RES_REDUCTION, IMX214_HDR_RES_REDU_THROUGH },
        { IMX214_REG_EXPOSURE_RATIO, 1 },
@@ -272,7 +274,6 @@ static const struct cci_reg_sequence mode_4096x2304[] = {
 };
 
 static const struct cci_reg_sequence mode_1920x1080[] = {
-       { IMX214_REG_CSI_LANE_MODE, IMX214_CSI_4_LANE_MODE },
        { IMX214_REG_HDR_MODE, IMX214_HDR_MODE_OFF },
        { IMX214_REG_HDR_RES_REDUCTION, IMX214_HDR_RES_REDU_THROUGH },
        { IMX214_REG_EXPOSURE_RATIO, 1 },
@@ -774,6 +775,13 @@ static int imx214_ctrls_init(struct imx214 *imx214)
        return 0;
 };
 
+static int imx214_configure_lanes(struct imx214 *imx214)
+{
+       return cci_write(imx214->regmap, IMX214_REG_CSI_LANE_MODE,
+                        imx214->lanes == 2 ? IMX214_CSI_2_LANE_MODE :
+                        IMX214_CSI_4_LANE_MODE, NULL);
+};
+
 static int imx214_start_streaming(struct imx214 *imx214)
 {
        const struct imx214_mode *mode;
@@ -786,6 +794,13 @@ static int imx214_start_streaming(struct imx214 *imx214)
                return ret;
        }
 
+       /* Configure two or four Lane mode */
+       ret = imx214_configure_lanes(imx214);
+       if (ret) {
+               dev_err(imx214->dev, "%s failed to configure lanes\n", 
__func__);
+               return ret;
+       }
+
        mode = v4l2_find_nearest_size(imx214_modes,
                                ARRAY_SIZE(imx214_modes), width, height,
                                imx214->fmt.width, imx214->fmt.height);
@@ -930,7 +945,7 @@ static int imx214_get_regulators(struct device *dev, struct 
imx214 *imx214)
                                       imx214->supplies);
 }
 
-static int imx214_parse_fwnode(struct device *dev)
+static int imx214_parse_fwnode(struct device *dev, struct imx214 *imx214)
 {
        struct fwnode_handle *endpoint;
        struct v4l2_fwnode_endpoint bus_cfg = {
@@ -949,6 +964,14 @@ static int imx214_parse_fwnode(struct device *dev)
                goto done;
        }
 
+       /* Check the number of MIPI CSI2 data lanes */
+       if (bus_cfg.bus.mipi_csi2.num_data_lanes != 4) {
+               dev_err_probe(dev, -EINVAL,
+                             "only 4 data lanes are currently supported\n");
+               goto done;
+       }
+       imx214->lanes = bus_cfg.bus.mipi_csi2.num_data_lanes;
+
        for (i = 0; i < bus_cfg.nr_of_link_frequencies; i++)
                if (bus_cfg.link_frequencies[i] == IMX214_DEFAULT_LINK_FREQ)
                        break;
@@ -973,14 +996,14 @@ static int imx214_probe(struct i2c_client *client)
        struct imx214 *imx214;
        int ret;
 
-       ret = imx214_parse_fwnode(dev);
-       if (ret)
-               return ret;
-
        imx214 = devm_kzalloc(dev, sizeof(*imx214), GFP_KERNEL);
        if (!imx214)
                return -ENOMEM;
 
+       ret = imx214_parse_fwnode(dev, imx214);
+       if (ret)
+               return ret;
+
        imx214->dev = dev;
 
        imx214->xclk = devm_clk_get(dev, NULL);

-- 
2.46.0



Reply via email to