1 From 35e50ee3d66e014d869f0d7a3468bef964d26d32 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 14 Nov 2024 13:14:02 +0000
4 Subject: [PATCH] media: i2c: imx477: Add options for slightly modifying the
7 The default link frequency of 450MHz has been noted to interfere
8 with GPS if they are in close proximty.
9 Add the option for 453 and 456MHz to move the signal slightly out
10 of the band. (447MHz can not be offered as corruption is then observed
11 on the 133x992 10bit mode).
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
17 drivers/media/i2c/imx477.c | 86 +++++++++++++++++++++++++++++---------
18 1 file changed, 67 insertions(+), 19 deletions(-)
20 --- a/drivers/media/i2c/imx477.c
21 +++ b/drivers/media/i2c/imx477.c
22 @@ -164,8 +164,48 @@ struct imx477_mode {
23 struct imx477_reg_list reg_list;
26 -static const s64 imx477_link_freq_menu[] = {
27 - IMX477_DEFAULT_LINK_FREQ,
28 +/* Link frequency setup */
30 + IMX477_LINK_FREQ_450MHZ,
31 + IMX477_LINK_FREQ_453MHZ,
32 + IMX477_LINK_FREQ_456MHZ,
35 +static const s64 link_freqs[] = {
36 + [IMX477_LINK_FREQ_450MHZ] = 450000000,
37 + [IMX477_LINK_FREQ_453MHZ] = 453000000,
38 + [IMX477_LINK_FREQ_456MHZ] = 456000000,
41 +/* 450MHz is the nominal "default" link frequency */
42 +static const struct imx477_reg link_450Mhz_regs[] = {
47 +static const struct imx477_reg link_453Mhz_regs[] = {
52 +static const struct imx477_reg link_456Mhz_regs[] = {
57 +static const struct imx477_reg_list link_freq_regs[] = {
58 + [IMX477_LINK_FREQ_450MHZ] = {
59 + .regs = link_450Mhz_regs,
60 + .num_of_regs = ARRAY_SIZE(link_450Mhz_regs)
62 + [IMX477_LINK_FREQ_453MHZ] = {
63 + .regs = link_453Mhz_regs,
64 + .num_of_regs = ARRAY_SIZE(link_453Mhz_regs)
66 + [IMX477_LINK_FREQ_456MHZ] = {
67 + .regs = link_456Mhz_regs,
68 + .num_of_regs = ARRAY_SIZE(link_456Mhz_regs)
72 static const struct imx477_reg mode_common_regs[] = {
73 @@ -558,8 +598,6 @@ static const struct imx477_reg mode_4056
82 @@ -659,8 +697,6 @@ static const struct imx477_reg mode_2028
91 @@ -760,8 +796,6 @@ static const struct imx477_reg mode_2028
100 @@ -890,8 +924,6 @@ static const struct imx477_reg mode_1332
109 @@ -1121,6 +1153,8 @@ struct imx477 {
110 struct v4l2_ctrl *vblank;
111 struct v4l2_ctrl *hblank;
113 + unsigned int link_freq_idx;
116 const struct imx477_mode *mode;
118 @@ -1712,7 +1746,7 @@ static int imx477_get_selection(struct v
119 static int imx477_start_streaming(struct imx477 *imx477)
121 struct i2c_client *client = v4l2_get_subdevdata(&imx477->sd);
122 - const struct imx477_reg_list *reg_list;
123 + const struct imx477_reg_list *reg_list, *freq_regs;
124 const struct imx477_reg_list *extra_regs;
127 @@ -1725,6 +1759,13 @@ static int imx477_start_streaming(struct
128 extra_regs->num_of_regs);
132 + /* Update the link frequency registers */
133 + freq_regs = &link_freq_regs[imx477->link_freq_idx];
134 + ret = imx477_write_regs(imx477, freq_regs->regs,
135 + freq_regs->num_of_regs);
139 dev_err(&client->dev, "%s failed to set common settings\n",
141 @@ -2010,9 +2051,8 @@ static int imx477_init_controls(struct i
142 /* LINK_FREQ is also read only */
144 v4l2_ctrl_new_int_menu(ctrl_hdlr, &imx477_ctrl_ops,
145 - V4L2_CID_LINK_FREQ,
146 - ARRAY_SIZE(imx477_link_freq_menu) - 1, 0,
147 - imx477_link_freq_menu);
148 + V4L2_CID_LINK_FREQ, 1, 0,
149 + &link_freqs[imx477->link_freq_idx]);
150 if (imx477->link_freq)
151 imx477->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
153 @@ -2110,13 +2150,14 @@ static void imx477_free_controls(struct
154 mutex_destroy(&imx477->mutex);
157 -static int imx477_check_hwcfg(struct device *dev)
158 +static int imx477_check_hwcfg(struct device *dev, struct imx477 *imx477)
160 struct fwnode_handle *endpoint;
161 struct v4l2_fwnode_endpoint ep_cfg = {
162 .bus_type = V4L2_MBUS_CSI2_DPHY
167 endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
169 @@ -2141,11 +2182,18 @@ static int imx477_check_hwcfg(struct dev
173 - if (ep_cfg.nr_of_link_frequencies != 1 ||
174 - ep_cfg.link_frequencies[0] != IMX477_DEFAULT_LINK_FREQ) {
175 + for (i = 0; i < ARRAY_SIZE(link_freqs); i++) {
176 + if (link_freqs[i] == ep_cfg.link_frequencies[0]) {
177 + imx477->link_freq_idx = i;
182 + if (i == ARRAY_SIZE(link_freqs)) {
183 dev_err(dev, "Link frequency not supported: %lld\n",
184 ep_cfg.link_frequencies[0]);
191 @@ -2206,7 +2254,7 @@ static int imx477_probe(struct i2c_clien
192 (const struct imx477_compatible_data *)match->data;
194 /* Check the hardware configuration in device tree */
195 - if (imx477_check_hwcfg(dev))
196 + if (imx477_check_hwcfg(dev, imx477))
199 /* Default the trigger mode from OF to -1, which means invalid */