1 From dcef754861ddd47e88f722abefc768410f1a17d1 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 16 Feb 2023 00:30:01 +0200
4 Subject: [PATCH] media: i2c: imx290: Add support for 74.25MHz external
7 Should be upstream commit b8b86dfe1aee
9 The sensor supports either a 37.125 or 74.25MHz external, but
10 the driver only supported 37.125MHz.
12 Add the relevant register configuration for either clock
15 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
16 Reviewed-by: Alexander Stein <alexander.stein@ew.tq-group.com>
17 Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
18 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
19 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
21 drivers/media/i2c/imx290.c | 132 ++++++++++++++++++++++++++++++++-----
22 1 file changed, 116 insertions(+), 16 deletions(-)
24 --- a/drivers/media/i2c/imx290.c
25 +++ b/drivers/media/i2c/imx290.c
27 #define IMX290_TCLKPREPARE IMX290_REG_16BIT(0x3452)
28 #define IMX290_TLPX IMX290_REG_16BIT(0x3454)
29 #define IMX290_X_OUT_SIZE IMX290_REG_16BIT(0x3472)
30 +#define IMX290_INCKSEL7 IMX290_REG_8BIT(0x3480)
32 #define IMX290_PGCTRL_REGEN BIT(0)
33 #define IMX290_PGCTRL_THRU BIT(1)
34 @@ -181,11 +182,29 @@ struct imx290_model_info {
35 enum imx290_colour_variant colour_variant;
38 +enum imx290_clk_freq {
44 struct imx290_regval {
50 + * Clock configuration for registers INCKSEL1 to INCKSEL6.
52 +struct imx290_clk_cfg {
64 @@ -195,6 +214,8 @@ struct imx290_mode {
66 const struct imx290_regval *data;
69 + const struct imx290_clk_cfg *clk_cfg;
72 struct imx290_csi_cfg {
73 @@ -213,6 +234,7 @@ struct imx290 {
76 struct regmap *regmap;
77 + enum imx290_clk_freq xclk_idx;
79 const struct imx290_model_info *model;
81 @@ -241,7 +263,6 @@ static inline struct imx290 *to_imx290(s
84 static const struct imx290_regval imx290_global_init_settings[] = {
85 - { IMX290_EXTCK_FREQ, 0x2520 },
86 { IMX290_WINWV_OB, 12 },
89 @@ -291,7 +312,18 @@ static const struct imx290_regval imx290
90 { IMX290_REG_8BIT(0x33b0), 0x50 },
91 { IMX290_REG_8BIT(0x33b2), 0x1a },
92 { IMX290_REG_8BIT(0x33b3), 0x04 },
93 - { IMX290_REG_8BIT(0x3480), 0x49 },
96 +#define IMX290_NUM_CLK_REGS 2
97 +static const struct imx290_regval xclk_regs[][IMX290_NUM_CLK_REGS] = {
98 + [IMX290_CLK_37_125] = {
99 + { IMX290_EXTCK_FREQ, (37125 * 256) / 1000 },
100 + { IMX290_INCKSEL7, 0x49 },
102 + [IMX290_CLK_74_25] = {
103 + { IMX290_EXTCK_FREQ, (74250 * 256) / 1000 },
104 + { IMX290_INCKSEL7, 0x92 },
108 static const struct imx290_regval imx290_1080p_settings[] = {
109 @@ -301,12 +333,6 @@ static const struct imx290_regval imx290
110 { IMX290_OPB_SIZE_V, 10 },
111 { IMX290_X_OUT_SIZE, 1920 },
112 { IMX290_Y_OUT_SIZE, 1080 },
113 - { IMX290_INCKSEL1, 0x18 },
114 - { IMX290_INCKSEL2, 0x03 },
115 - { IMX290_INCKSEL3, 0x20 },
116 - { IMX290_INCKSEL4, 0x01 },
117 - { IMX290_INCKSEL5, 0x1a },
118 - { IMX290_INCKSEL6, 0x1a },
121 static const struct imx290_regval imx290_720p_settings[] = {
122 @@ -316,12 +342,6 @@ static const struct imx290_regval imx290
123 { IMX290_OPB_SIZE_V, 4 },
124 { IMX290_X_OUT_SIZE, 1280 },
125 { IMX290_Y_OUT_SIZE, 720 },
126 - { IMX290_INCKSEL1, 0x20 },
127 - { IMX290_INCKSEL2, 0x00 },
128 - { IMX290_INCKSEL3, 0x20 },
129 - { IMX290_INCKSEL4, 0x01 },
130 - { IMX290_INCKSEL5, 0x1a },
131 - { IMX290_INCKSEL6, 0x1a },
134 static const struct imx290_regval imx290_10bit_settings[] = {
135 @@ -427,6 +447,48 @@ static inline int imx290_link_freqs_num(
136 return ARRAY_SIZE(imx290_link_freq_4lanes);
139 +static const struct imx290_clk_cfg imx290_1080p_clock_config[] = {
140 + [IMX290_CLK_37_125] = {
141 + /* 37.125MHz clock config */
149 + [IMX290_CLK_74_25] = {
150 + /* 74.25MHz clock config */
160 +static const struct imx290_clk_cfg imx290_720p_clock_config[] = {
161 + [IMX290_CLK_37_125] = {
162 + /* 37.125MHz clock config */
170 + [IMX290_CLK_74_25] = {
171 + /* 74.25MHz clock config */
182 static const struct imx290_mode imx290_modes_2lanes[] = {
184 @@ -437,6 +499,7 @@ static const struct imx290_mode imx290_m
185 .link_freq_index = FREQ_INDEX_1080P,
186 .data = imx290_1080p_settings,
187 .data_size = ARRAY_SIZE(imx290_1080p_settings),
188 + .clk_cfg = imx290_1080p_clock_config,
192 @@ -446,6 +509,7 @@ static const struct imx290_mode imx290_m
193 .link_freq_index = FREQ_INDEX_720P,
194 .data = imx290_720p_settings,
195 .data_size = ARRAY_SIZE(imx290_720p_settings),
196 + .clk_cfg = imx290_720p_clock_config,
200 @@ -458,6 +522,7 @@ static const struct imx290_mode imx290_m
201 .link_freq_index = FREQ_INDEX_1080P,
202 .data = imx290_1080p_settings,
203 .data_size = ARRAY_SIZE(imx290_1080p_settings),
204 + .clk_cfg = imx290_1080p_clock_config,
208 @@ -467,6 +532,7 @@ static const struct imx290_mode imx290_m
209 .link_freq_index = FREQ_INDEX_720P,
210 .data = imx290_720p_settings,
211 .data_size = ARRAY_SIZE(imx290_720p_settings),
212 + .clk_cfg = imx290_720p_clock_config,
216 @@ -592,6 +658,26 @@ static int imx290_set_register_array(str
220 +static int imx290_set_clock(struct imx290 *imx290)
222 + const struct imx290_mode *mode = imx290->current_mode;
223 + enum imx290_clk_freq clk_idx = imx290->xclk_idx;
224 + const struct imx290_clk_cfg *clk_cfg = &mode->clk_cfg[clk_idx];
227 + ret = imx290_set_register_array(imx290, xclk_regs[clk_idx],
228 + IMX290_NUM_CLK_REGS);
230 + imx290_write(imx290, IMX290_INCKSEL1, clk_cfg->incksel1, &ret);
231 + imx290_write(imx290, IMX290_INCKSEL2, clk_cfg->incksel2, &ret);
232 + imx290_write(imx290, IMX290_INCKSEL3, clk_cfg->incksel3, &ret);
233 + imx290_write(imx290, IMX290_INCKSEL4, clk_cfg->incksel4, &ret);
234 + imx290_write(imx290, IMX290_INCKSEL5, clk_cfg->incksel5, &ret);
235 + imx290_write(imx290, IMX290_INCKSEL6, clk_cfg->incksel6, &ret);
240 static int imx290_set_data_lanes(struct imx290 *imx290)
243 @@ -896,6 +982,13 @@ static int imx290_start_streaming(struct
247 + /* Set clock parameters based on mode and xclk */
248 + ret = imx290_set_clock(imx290);
250 + dev_err(imx290->dev, "Could not set clocks\n");
254 /* Set data lane count */
255 ret = imx290_set_data_lanes(imx290);
257 @@ -1295,8 +1388,15 @@ static int imx290_init_clk(struct imx290
261 - /* external clock must be 37.125 MHz */
262 - if (xclk_freq != 37125000) {
263 + /* external clock must be 37.125 MHz or 74.25MHz */
264 + switch (xclk_freq) {
266 + imx290->xclk_idx = IMX290_CLK_37_125;
269 + imx290->xclk_idx = IMX290_CLK_74_25;
272 dev_err(imx290->dev, "External clock frequency %u is not supported\n",