1 From af972efc5fbaa4bd7bb26ffd868c54b71d49b4cc Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Tue, 21 Jun 2022 14:55:41 +0100
4 Subject: [PATCH 0462/1085] media: i2c: imx258: Change register settings for
7 Sony have advised that there are variants of the IMX258 sensor which
8 require slightly different register configuration to the mainline
9 imx258 driver defaults.
11 There is no available run-time detection for the variant, so add
12 configuration via the DT compatible string.
14 The Vision Components imx258 module supports PDAF, so add the
15 register differences for that variant
17 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
19 drivers/media/i2c/imx258.c | 64 ++++++++++++++++++++++++++++++--------
20 1 file changed, 51 insertions(+), 13 deletions(-)
22 --- a/drivers/media/i2c/imx258.c
23 +++ b/drivers/media/i2c/imx258.c
24 @@ -320,8 +320,6 @@ static const struct imx258_reg mipi_642m
26 static const struct imx258_reg mode_4208x3120_regs[] = {
33 @@ -344,7 +342,6 @@ static const struct imx258_reg mode_4208
41 @@ -432,8 +429,6 @@ static const struct imx258_reg mode_4208
43 static const struct imx258_reg mode_2104_1560_regs[] = {
50 @@ -456,7 +451,6 @@ static const struct imx258_reg mode_2104
58 @@ -544,8 +538,6 @@ static const struct imx258_reg mode_2104
60 static const struct imx258_reg mode_1048_780_regs[] = {
67 @@ -568,7 +560,6 @@ static const struct imx258_reg mode_1048
75 @@ -654,6 +645,33 @@ static const struct imx258_reg mode_1048
79 +struct imx258_variant_cfg {
80 + const struct imx258_reg *regs;
81 + unsigned int num_regs;
84 +static const struct imx258_reg imx258_cfg_regs[] = {
90 +static const struct imx258_variant_cfg imx258_cfg = {
91 + .regs = imx258_cfg_regs,
92 + .num_regs = ARRAY_SIZE(imx258_cfg_regs),
95 +static const struct imx258_reg imx258_pdaf_cfg_regs[] = {
101 +static const struct imx258_variant_cfg imx258_pdaf_cfg = {
102 + .regs = imx258_pdaf_cfg_regs,
103 + .num_regs = ARRAY_SIZE(imx258_pdaf_cfg_regs),
106 static const char * const imx258_test_pattern_menu[] = {
109 @@ -838,6 +856,8 @@ struct imx258 {
110 struct v4l2_subdev sd;
111 struct media_pad pad;
113 + const struct imx258_variant_cfg *variant_cfg;
115 struct v4l2_ctrl_handler ctrl_handler;
117 struct v4l2_ctrl *link_freq;
118 @@ -1322,6 +1342,14 @@ static int imx258_start_streaming(struct
122 + ret = imx258_write_regs(imx258, imx258->variant_cfg->regs,
123 + imx258->variant_cfg->num_regs);
125 + dev_err(&client->dev, "%s failed to set variant config\n",
130 ret = imx258_write_reg(imx258, IMX258_CLK_BLANK_STOP,
131 IMX258_REG_VALUE_08BIT,
132 imx258->csi2_flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK ?
133 @@ -1671,6 +1699,12 @@ static int imx258_get_regulators(struct
137 +static const struct of_device_id imx258_dt_ids[] = {
138 + { .compatible = "sony,imx258", .data = &imx258_cfg },
139 + { .compatible = "sony,imx258-pdaf", .data = &imx258_pdaf_cfg },
143 static int imx258_probe(struct i2c_client *client)
145 struct imx258 *imx258;
146 @@ -1678,6 +1712,7 @@ static int imx258_probe(struct i2c_clien
147 struct v4l2_fwnode_endpoint ep = {
148 .bus_type = V4L2_MBUS_CSI2_DPHY
150 + const struct of_device_id *match;
154 @@ -1753,6 +1788,13 @@ static int imx258_probe(struct i2c_clien
156 imx258->csi2_flags = ep.bus.mipi_csi2.flags;
158 + match = i2c_of_match_device(imx258_dt_ids, client);
159 + if (!match || !match->data)
160 + imx258->variant_cfg = &imx258_cfg;
162 + imx258->variant_cfg =
163 + (const struct imx258_variant_cfg *)match->data;
165 /* Initialize subdev */
166 v4l2_i2c_subdev_init(&imx258->sd, client, &imx258_subdev_ops);
168 @@ -1839,10 +1881,6 @@ static const struct acpi_device_id imx25
169 MODULE_DEVICE_TABLE(acpi, imx258_acpi_ids);
172 -static const struct of_device_id imx258_dt_ids[] = {
173 - { .compatible = "sony,imx258" },
176 MODULE_DEVICE_TABLE(of, imx258_dt_ids);
178 static struct i2c_driver imx258_i2c_driver = {