1e6457f51deb0d1356b938760f71d8afc2d5469e
[openwrt/staging/linusw.git] /
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
5 variants of the sensor
6
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.
10
11 There is no available run-time detection for the variant, so add
12 configuration via the DT compatible string.
13
14 The Vision Components imx258 module supports PDAF, so add the
15 register differences for that variant
16
17 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
18 ---
19 drivers/media/i2c/imx258.c | 64 ++++++++++++++++++++++++++++++--------
20 1 file changed, 51 insertions(+), 13 deletions(-)
21
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
25
26 static const struct imx258_reg mode_4208x3120_regs[] = {
27 { 0x3051, 0x00 },
28 - { 0x3052, 0x00 },
29 - { 0x4E21, 0x14 },
30 { 0x6B11, 0xCF },
31 { 0x7FF0, 0x08 },
32 { 0x7FF1, 0x0F },
33 @@ -344,7 +342,6 @@ static const struct imx258_reg mode_4208
34 { 0x7FA8, 0x03 },
35 { 0x7FA9, 0xFE },
36 { 0x7B24, 0x81 },
37 - { 0x7B25, 0x00 },
38 { 0x6564, 0x07 },
39 { 0x6B0D, 0x41 },
40 { 0x653D, 0x04 },
41 @@ -432,8 +429,6 @@ static const struct imx258_reg mode_4208
42
43 static const struct imx258_reg mode_2104_1560_regs[] = {
44 { 0x3051, 0x00 },
45 - { 0x3052, 0x00 },
46 - { 0x4E21, 0x14 },
47 { 0x6B11, 0xCF },
48 { 0x7FF0, 0x08 },
49 { 0x7FF1, 0x0F },
50 @@ -456,7 +451,6 @@ static const struct imx258_reg mode_2104
51 { 0x7FA8, 0x03 },
52 { 0x7FA9, 0xFE },
53 { 0x7B24, 0x81 },
54 - { 0x7B25, 0x00 },
55 { 0x6564, 0x07 },
56 { 0x6B0D, 0x41 },
57 { 0x653D, 0x04 },
58 @@ -544,8 +538,6 @@ static const struct imx258_reg mode_2104
59
60 static const struct imx258_reg mode_1048_780_regs[] = {
61 { 0x3051, 0x00 },
62 - { 0x3052, 0x00 },
63 - { 0x4E21, 0x14 },
64 { 0x6B11, 0xCF },
65 { 0x7FF0, 0x08 },
66 { 0x7FF1, 0x0F },
67 @@ -568,7 +560,6 @@ static const struct imx258_reg mode_1048
68 { 0x7FA8, 0x03 },
69 { 0x7FA9, 0xFE },
70 { 0x7B24, 0x81 },
71 - { 0x7B25, 0x00 },
72 { 0x6564, 0x07 },
73 { 0x6B0D, 0x41 },
74 { 0x653D, 0x04 },
75 @@ -654,6 +645,33 @@ static const struct imx258_reg mode_1048
76 { 0x0220, 0x00 },
77 };
78
79 +struct imx258_variant_cfg {
80 + const struct imx258_reg *regs;
81 + unsigned int num_regs;
82 +};
83 +
84 +static const struct imx258_reg imx258_cfg_regs[] = {
85 + { 0x3052, 0x00 },
86 + { 0x4E21, 0x14 },
87 + { 0x7B25, 0x00 },
88 +};
89 +
90 +static const struct imx258_variant_cfg imx258_cfg = {
91 + .regs = imx258_cfg_regs,
92 + .num_regs = ARRAY_SIZE(imx258_cfg_regs),
93 +};
94 +
95 +static const struct imx258_reg imx258_pdaf_cfg_regs[] = {
96 + { 0x3052, 0x01 },
97 + { 0x4E21, 0x10 },
98 + { 0x7B25, 0x01 },
99 +};
100 +
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),
104 +};
105 +
106 static const char * const imx258_test_pattern_menu[] = {
107 "Disabled",
108 "Solid Colour",
109 @@ -838,6 +856,8 @@ struct imx258 {
110 struct v4l2_subdev sd;
111 struct media_pad pad;
112
113 + const struct imx258_variant_cfg *variant_cfg;
114 +
115 struct v4l2_ctrl_handler ctrl_handler;
116 /* V4L2 Controls */
117 struct v4l2_ctrl *link_freq;
118 @@ -1322,6 +1342,14 @@ static int imx258_start_streaming(struct
119 return ret;
120 }
121
122 + ret = imx258_write_regs(imx258, imx258->variant_cfg->regs,
123 + imx258->variant_cfg->num_regs);
124 + if (ret) {
125 + dev_err(&client->dev, "%s failed to set variant config\n",
126 + __func__);
127 + return ret;
128 + }
129 +
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
134 imx258->supplies);
135 }
136
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 },
140 + { /* sentinel */ }
141 +};
142 +
143 static int imx258_probe(struct i2c_client *client)
144 {
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
149 };
150 + const struct of_device_id *match;
151 int ret;
152 u32 val = 0;
153
154 @@ -1753,6 +1788,13 @@ static int imx258_probe(struct i2c_clien
155
156 imx258->csi2_flags = ep.bus.mipi_csi2.flags;
157
158 + match = i2c_of_match_device(imx258_dt_ids, client);
159 + if (!match || !match->data)
160 + imx258->variant_cfg = &imx258_cfg;
161 + else
162 + imx258->variant_cfg =
163 + (const struct imx258_variant_cfg *)match->data;
164 +
165 /* Initialize subdev */
166 v4l2_i2c_subdev_init(&imx258->sd, client, &imx258_subdev_ops);
167
168 @@ -1839,10 +1881,6 @@ static const struct acpi_device_id imx25
169 MODULE_DEVICE_TABLE(acpi, imx258_acpi_ids);
170 #endif
171
172 -static const struct of_device_id imx258_dt_ids[] = {
173 - { .compatible = "sony,imx258" },
174 - { /* sentinel */ }
175 -};
176 MODULE_DEVICE_TABLE(of, imx258_dt_ids);
177
178 static struct i2c_driver imx258_i2c_driver = {