blob: 8cc3bdb7f608c855f55e9f6c877ed07d7d2b3bd9 [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001/*
2 * imx274.c - IMX274 CMOS Image Sensor driver
3 *
4 * Copyright (C) 2017, Leopard Imaging, Inc.
5 *
6 * Leon Luo <leonl@leopardimaging.com>
7 * Edwin Zou <edwinz@leopardimaging.com>
8 * Luca Ceresoli <luca@lucaceresoli.net>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms and conditions of the GNU General Public License,
12 * version 2, as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#include <linux/clk.h>
24#include <linux/delay.h>
25#include <linux/gpio.h>
26#include <linux/gpio/consumer.h>
27#include <linux/i2c.h>
28#include <linux/init.h>
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/of_gpio.h>
32#include <linux/regmap.h>
33#include <linux/slab.h>
34#include <linux/v4l2-mediabus.h>
35#include <linux/videodev2.h>
36
37#include <media/v4l2-ctrls.h>
38#include <media/v4l2-device.h>
39#include <media/v4l2-subdev.h>
40
41/*
42 * See "SHR, SVR Setting" in datasheet
43 */
44#define IMX274_DEFAULT_FRAME_LENGTH (4550)
45#define IMX274_MAX_FRAME_LENGTH (0x000fffff)
46
47/*
48 * See "Frame Rate Adjustment" in datasheet
49 */
50#define IMX274_PIXCLK_CONST1 (72000000)
51#define IMX274_PIXCLK_CONST2 (1000000)
52
53/*
54 * The input gain is shifted by IMX274_GAIN_SHIFT to get
55 * decimal number. The real gain is
56 * (float)input_gain_value / (1 << IMX274_GAIN_SHIFT)
57 */
58#define IMX274_GAIN_SHIFT (8)
59#define IMX274_GAIN_SHIFT_MASK ((1 << IMX274_GAIN_SHIFT) - 1)
60
61/*
62 * See "Analog Gain" and "Digital Gain" in datasheet
63 * min gain is 1X
64 * max gain is calculated based on IMX274_GAIN_REG_MAX
65 */
66#define IMX274_GAIN_REG_MAX (1957)
67#define IMX274_MIN_GAIN (0x01 << IMX274_GAIN_SHIFT)
68#define IMX274_MAX_ANALOG_GAIN ((2048 << IMX274_GAIN_SHIFT)\
69 / (2048 - IMX274_GAIN_REG_MAX))
70#define IMX274_MAX_DIGITAL_GAIN (8)
71#define IMX274_DEF_GAIN (20 << IMX274_GAIN_SHIFT)
72#define IMX274_GAIN_CONST (2048) /* for gain formula */
73
74/*
75 * 1 line time in us = (HMAX / 72), minimal is 4 lines
76 */
77#define IMX274_MIN_EXPOSURE_TIME (4 * 260 / 72)
78
79#define IMX274_DEFAULT_MODE IMX274_BINNING_OFF
80#define IMX274_MAX_WIDTH (3840)
81#define IMX274_MAX_HEIGHT (2160)
82#define IMX274_MAX_FRAME_RATE (120)
83#define IMX274_MIN_FRAME_RATE (5)
84#define IMX274_DEF_FRAME_RATE (60)
85
86/*
87 * register SHR is limited to (SVR value + 1) x VMAX value - 4
88 */
89#define IMX274_SHR_LIMIT_CONST (4)
90
91/*
92 * Min and max sensor reset delay (microseconds)
93 */
94#define IMX274_RESET_DELAY1 (2000)
95#define IMX274_RESET_DELAY2 (2200)
96
97/*
98 * shift and mask constants
99 */
100#define IMX274_SHIFT_8_BITS (8)
101#define IMX274_SHIFT_16_BITS (16)
102#define IMX274_MASK_LSB_2_BITS (0x03)
103#define IMX274_MASK_LSB_3_BITS (0x07)
104#define IMX274_MASK_LSB_4_BITS (0x0f)
105#define IMX274_MASK_LSB_8_BITS (0x00ff)
106
107#define DRIVER_NAME "IMX274"
108
109/*
110 * IMX274 register definitions
111 */
112#define IMX274_SHR_REG_MSB 0x300D /* SHR */
113#define IMX274_SHR_REG_LSB 0x300C /* SHR */
114#define IMX274_SVR_REG_MSB 0x300F /* SVR */
115#define IMX274_SVR_REG_LSB 0x300E /* SVR */
116#define IMX274_HTRIM_EN_REG 0x3037
117#define IMX274_HTRIM_START_REG_LSB 0x3038
118#define IMX274_HTRIM_START_REG_MSB 0x3039
119#define IMX274_HTRIM_END_REG_LSB 0x303A
120#define IMX274_HTRIM_END_REG_MSB 0x303B
121#define IMX274_VWIDCUTEN_REG 0x30DD
122#define IMX274_VWIDCUT_REG_LSB 0x30DE
123#define IMX274_VWIDCUT_REG_MSB 0x30DF
124#define IMX274_VWINPOS_REG_LSB 0x30E0
125#define IMX274_VWINPOS_REG_MSB 0x30E1
126#define IMX274_WRITE_VSIZE_REG_LSB 0x3130
127#define IMX274_WRITE_VSIZE_REG_MSB 0x3131
128#define IMX274_Y_OUT_SIZE_REG_LSB 0x3132
129#define IMX274_Y_OUT_SIZE_REG_MSB 0x3133
130#define IMX274_VMAX_REG_1 0x30FA /* VMAX, MSB */
131#define IMX274_VMAX_REG_2 0x30F9 /* VMAX */
132#define IMX274_VMAX_REG_3 0x30F8 /* VMAX, LSB */
133#define IMX274_HMAX_REG_MSB 0x30F7 /* HMAX */
134#define IMX274_HMAX_REG_LSB 0x30F6 /* HMAX */
135#define IMX274_ANALOG_GAIN_ADDR_LSB 0x300A /* ANALOG GAIN LSB */
136#define IMX274_ANALOG_GAIN_ADDR_MSB 0x300B /* ANALOG GAIN MSB */
137#define IMX274_DIGITAL_GAIN_REG 0x3012 /* Digital Gain */
138#define IMX274_VFLIP_REG 0x301A /* VERTICAL FLIP */
139#define IMX274_TEST_PATTERN_REG 0x303D /* TEST PATTERN */
140#define IMX274_STANDBY_REG 0x3000 /* STANDBY */
141
142#define IMX274_TABLE_WAIT_MS 0
143#define IMX274_TABLE_END 1
144
145/*
146 * imx274 I2C operation related structure
147 */
148struct reg_8 {
149 u16 addr;
150 u8 val;
151};
152
153static const struct regmap_config imx274_regmap_config = {
154 .reg_bits = 16,
155 .val_bits = 8,
156 .cache_type = REGCACHE_RBTREE,
157};
158
159enum imx274_binning {
160 IMX274_BINNING_OFF,
161 IMX274_BINNING_2_1,
162 IMX274_BINNING_3_1,
163};
164
165/*
166 * Parameters for each imx274 readout mode.
167 *
168 * These are the values to configure the sensor in one of the
169 * implemented modes.
170 *
171 * @init_regs: registers to initialize the mode
172 * @bin_ratio: downscale factor (e.g. 3 for 3:1 binning)
173 * @min_frame_len: Minimum frame length for each mode (see "Frame Rate
174 * Adjustment (CSI-2)" in the datasheet)
175 * @min_SHR: Minimum SHR register value (see "Shutter Setting (CSI-2)" in the
176 * datasheet)
177 * @max_fps: Maximum frames per second
178 * @nocpiop: Number of clocks per internal offset period (see "Integration Time
179 * in Each Readout Drive Mode (CSI-2)" in the datasheet)
180 */
181struct imx274_frmfmt {
182 const struct reg_8 *init_regs;
183 unsigned int bin_ratio;
184 int min_frame_len;
185 int min_SHR;
186 int max_fps;
187 int nocpiop;
188};
189
190/*
191 * imx274 test pattern related structure
192 */
193enum {
194 TEST_PATTERN_DISABLED = 0,
195 TEST_PATTERN_ALL_000H,
196 TEST_PATTERN_ALL_FFFH,
197 TEST_PATTERN_ALL_555H,
198 TEST_PATTERN_ALL_AAAH,
199 TEST_PATTERN_VSP_5AH, /* VERTICAL STRIPE PATTERN 555H/AAAH */
200 TEST_PATTERN_VSP_A5H, /* VERTICAL STRIPE PATTERN AAAH/555H */
201 TEST_PATTERN_VSP_05H, /* VERTICAL STRIPE PATTERN 000H/555H */
202 TEST_PATTERN_VSP_50H, /* VERTICAL STRIPE PATTERN 555H/000H */
203 TEST_PATTERN_VSP_0FH, /* VERTICAL STRIPE PATTERN 000H/FFFH */
204 TEST_PATTERN_VSP_F0H, /* VERTICAL STRIPE PATTERN FFFH/000H */
205 TEST_PATTERN_H_COLOR_BARS,
206 TEST_PATTERN_V_COLOR_BARS,
207};
208
209static const char * const tp_qmenu[] = {
210 "Disabled",
211 "All 000h Pattern",
212 "All FFFh Pattern",
213 "All 555h Pattern",
214 "All AAAh Pattern",
215 "Vertical Stripe (555h / AAAh)",
216 "Vertical Stripe (AAAh / 555h)",
217 "Vertical Stripe (000h / 555h)",
218 "Vertical Stripe (555h / 000h)",
219 "Vertical Stripe (000h / FFFh)",
220 "Vertical Stripe (FFFh / 000h)",
221 "Horizontal Color Bars",
222 "Vertical Color Bars",
223};
224
225/*
226 * All-pixel scan mode (10-bit)
227 * imx274 mode1(refer to datasheet) register configuration with
228 * 3840x2160 resolution, raw10 data and mipi four lane output
229 */
230static const struct reg_8 imx274_mode1_3840x2160_raw10[] = {
231 {0x3004, 0x01},
232 {0x3005, 0x01},
233 {0x3006, 0x00},
234 {0x3007, 0xa2},
235
236 {0x3018, 0xA2}, /* output XVS, HVS */
237
238 {0x306B, 0x05},
239 {0x30E2, 0x01},
240
241 {0x30EE, 0x01},
242 {0x3342, 0x0A},
243 {0x3343, 0x00},
244 {0x3344, 0x16},
245 {0x3345, 0x00},
246 {0x33A6, 0x01},
247 {0x3528, 0x0E},
248 {0x3554, 0x1F},
249 {0x3555, 0x01},
250 {0x3556, 0x01},
251 {0x3557, 0x01},
252 {0x3558, 0x01},
253 {0x3559, 0x00},
254 {0x355A, 0x00},
255 {0x35BA, 0x0E},
256 {0x366A, 0x1B},
257 {0x366B, 0x1A},
258 {0x366C, 0x19},
259 {0x366D, 0x17},
260 {0x3A41, 0x08},
261
262 {IMX274_TABLE_END, 0x00}
263};
264
265/*
266 * Horizontal/vertical 2/2-line binning
267 * (Horizontal and vertical weightedbinning, 10-bit)
268 * imx274 mode3(refer to datasheet) register configuration with
269 * 1920x1080 resolution, raw10 data and mipi four lane output
270 */
271static const struct reg_8 imx274_mode3_1920x1080_raw10[] = {
272 {0x3004, 0x02},
273 {0x3005, 0x21},
274 {0x3006, 0x00},
275 {0x3007, 0xb1},
276
277 {0x3018, 0xA2}, /* output XVS, HVS */
278
279 {0x306B, 0x05},
280 {0x30E2, 0x02},
281
282 {0x30EE, 0x01},
283 {0x3342, 0x0A},
284 {0x3343, 0x00},
285 {0x3344, 0x1A},
286 {0x3345, 0x00},
287 {0x33A6, 0x01},
288 {0x3528, 0x0E},
289 {0x3554, 0x00},
290 {0x3555, 0x01},
291 {0x3556, 0x01},
292 {0x3557, 0x01},
293 {0x3558, 0x01},
294 {0x3559, 0x00},
295 {0x355A, 0x00},
296 {0x35BA, 0x0E},
297 {0x366A, 0x1B},
298 {0x366B, 0x1A},
299 {0x366C, 0x19},
300 {0x366D, 0x17},
301 {0x3A41, 0x08},
302
303 {IMX274_TABLE_END, 0x00}
304};
305
306/*
307 * Vertical 2/3 subsampling binning horizontal 3 binning
308 * imx274 mode5(refer to datasheet) register configuration with
309 * 1280x720 resolution, raw10 data and mipi four lane output
310 */
311static const struct reg_8 imx274_mode5_1280x720_raw10[] = {
312 {0x3004, 0x03},
313 {0x3005, 0x31},
314 {0x3006, 0x00},
315 {0x3007, 0xa9},
316
317 {0x3018, 0xA2}, /* output XVS, HVS */
318
319 {0x306B, 0x05},
320 {0x30E2, 0x03},
321
322 {0x30EE, 0x01},
323 {0x3342, 0x0A},
324 {0x3343, 0x00},
325 {0x3344, 0x1B},
326 {0x3345, 0x00},
327 {0x33A6, 0x01},
328 {0x3528, 0x0E},
329 {0x3554, 0x00},
330 {0x3555, 0x01},
331 {0x3556, 0x01},
332 {0x3557, 0x01},
333 {0x3558, 0x01},
334 {0x3559, 0x00},
335 {0x355A, 0x00},
336 {0x35BA, 0x0E},
337 {0x366A, 0x1B},
338 {0x366B, 0x19},
339 {0x366C, 0x17},
340 {0x366D, 0x17},
341 {0x3A41, 0x04},
342
343 {IMX274_TABLE_END, 0x00}
344};
345
346/*
347 * imx274 first step register configuration for
348 * starting stream
349 */
350static const struct reg_8 imx274_start_1[] = {
351 {IMX274_STANDBY_REG, 0x12},
352 {IMX274_TABLE_END, 0x00}
353};
354
355/*
356 * imx274 second step register configuration for
357 * starting stream
358 */
359static const struct reg_8 imx274_start_2[] = {
360 {0x3120, 0xF0}, /* clock settings */
361 {0x3121, 0x00}, /* clock settings */
362 {0x3122, 0x02}, /* clock settings */
363 {0x3129, 0x9C}, /* clock settings */
364 {0x312A, 0x02}, /* clock settings */
365 {0x312D, 0x02}, /* clock settings */
366
367 {0x310B, 0x00},
368
369 /* PLSTMG */
370 {0x304C, 0x00}, /* PLSTMG01 */
371 {0x304D, 0x03},
372 {0x331C, 0x1A},
373 {0x331D, 0x00},
374 {0x3502, 0x02},
375 {0x3529, 0x0E},
376 {0x352A, 0x0E},
377 {0x352B, 0x0E},
378 {0x3538, 0x0E},
379 {0x3539, 0x0E},
380 {0x3553, 0x00},
381 {0x357D, 0x05},
382 {0x357F, 0x05},
383 {0x3581, 0x04},
384 {0x3583, 0x76},
385 {0x3587, 0x01},
386 {0x35BB, 0x0E},
387 {0x35BC, 0x0E},
388 {0x35BD, 0x0E},
389 {0x35BE, 0x0E},
390 {0x35BF, 0x0E},
391 {0x366E, 0x00},
392 {0x366F, 0x00},
393 {0x3670, 0x00},
394 {0x3671, 0x00},
395
396 /* PSMIPI */
397 {0x3304, 0x32}, /* PSMIPI1 */
398 {0x3305, 0x00},
399 {0x3306, 0x32},
400 {0x3307, 0x00},
401 {0x3590, 0x32},
402 {0x3591, 0x00},
403 {0x3686, 0x32},
404 {0x3687, 0x00},
405
406 {IMX274_TABLE_END, 0x00}
407};
408
409/*
410 * imx274 third step register configuration for
411 * starting stream
412 */
413static const struct reg_8 imx274_start_3[] = {
414 {IMX274_STANDBY_REG, 0x00},
415 {0x303E, 0x02}, /* SYS_MODE = 2 */
416 {IMX274_TABLE_END, 0x00}
417};
418
419/*
420 * imx274 forth step register configuration for
421 * starting stream
422 */
423static const struct reg_8 imx274_start_4[] = {
424 {0x30F4, 0x00},
425 {0x3018, 0xA2}, /* XHS VHS OUTUPT */
426 {IMX274_TABLE_END, 0x00}
427};
428
429/*
430 * imx274 register configuration for stoping stream
431 */
432static const struct reg_8 imx274_stop[] = {
433 {IMX274_STANDBY_REG, 0x01},
434 {IMX274_TABLE_END, 0x00}
435};
436
437/*
438 * imx274 disable test pattern register configuration
439 */
440static const struct reg_8 imx274_tp_disabled[] = {
441 {0x303C, 0x00},
442 {0x377F, 0x00},
443 {0x3781, 0x00},
444 {0x370B, 0x00},
445 {IMX274_TABLE_END, 0x00}
446};
447
448/*
449 * imx274 test pattern register configuration
450 * reg 0x303D defines the test pattern modes
451 */
452static const struct reg_8 imx274_tp_regs[] = {
453 {0x303C, 0x11},
454 {0x370E, 0x01},
455 {0x377F, 0x01},
456 {0x3781, 0x01},
457 {0x370B, 0x11},
458 {IMX274_TABLE_END, 0x00}
459};
460
461/* nocpiop happens to be the same number for the implemented modes */
462static const struct imx274_frmfmt imx274_formats[] = {
463 {
464 /* mode 1, 4K */
465 .bin_ratio = 1,
466 .init_regs = imx274_mode1_3840x2160_raw10,
467 .min_frame_len = 4550,
468 .min_SHR = 12,
469 .max_fps = 60,
470 .nocpiop = 112,
471 },
472 {
473 /* mode 3, 1080p */
474 .bin_ratio = 2,
475 .init_regs = imx274_mode3_1920x1080_raw10,
476 .min_frame_len = 2310,
477 .min_SHR = 8,
478 .max_fps = 120,
479 .nocpiop = 112,
480 },
481 {
482 /* mode 5, 720p */
483 .bin_ratio = 3,
484 .init_regs = imx274_mode5_1280x720_raw10,
485 .min_frame_len = 2310,
486 .min_SHR = 8,
487 .max_fps = 120,
488 .nocpiop = 112,
489 },
490};
491
492/*
493 * struct imx274_ctrls - imx274 ctrl structure
494 * @handler: V4L2 ctrl handler structure
495 * @exposure: Pointer to expsure ctrl structure
496 * @gain: Pointer to gain ctrl structure
497 * @vflip: Pointer to vflip ctrl structure
498 * @test_pattern: Pointer to test pattern ctrl structure
499 */
500struct imx274_ctrls {
501 struct v4l2_ctrl_handler handler;
502 struct v4l2_ctrl *exposure;
503 struct v4l2_ctrl *gain;
504 struct v4l2_ctrl *vflip;
505 struct v4l2_ctrl *test_pattern;
506};
507
508/*
509 * struct stim274 - imx274 device structure
510 * @sd: V4L2 subdevice structure
511 * @pad: Media pad structure
512 * @client: Pointer to I2C client
513 * @ctrls: imx274 control structure
514 * @crop: rect to be captured
515 * @compose: compose rect, i.e. output resolution
516 * @format: V4L2 media bus frame format structure
517 * (width and height are in sync with the compose rect)
518 * @frame_rate: V4L2 frame rate structure
519 * @regmap: Pointer to regmap structure
520 * @reset_gpio: Pointer to reset gpio
521 * @lock: Mutex structure
522 * @mode: Parameters for the selected readout mode
523 */
524struct stimx274 {
525 struct v4l2_subdev sd;
526 struct media_pad pad;
527 struct i2c_client *client;
528 struct imx274_ctrls ctrls;
529 struct v4l2_rect crop;
530 struct v4l2_mbus_framefmt format;
531 struct v4l2_fract frame_interval;
532 struct regmap *regmap;
533 struct gpio_desc *reset_gpio;
534 struct mutex lock; /* mutex lock for operations */
535 const struct imx274_frmfmt *mode;
536};
537
538#define IMX274_ROUND(dim, step, flags) \
539 ((flags) & V4L2_SEL_FLAG_GE \
540 ? roundup((dim), (step)) \
541 : ((flags) & V4L2_SEL_FLAG_LE \
542 ? rounddown((dim), (step)) \
543 : rounddown((dim) + (step) / 2, (step))))
544
545/*
546 * Function declaration
547 */
548static int imx274_set_gain(struct stimx274 *priv, struct v4l2_ctrl *ctrl);
549static int imx274_set_exposure(struct stimx274 *priv, int val);
550static int imx274_set_vflip(struct stimx274 *priv, int val);
551static int imx274_set_test_pattern(struct stimx274 *priv, int val);
552static int imx274_set_frame_interval(struct stimx274 *priv,
553 struct v4l2_fract frame_interval);
554
555static inline void msleep_range(unsigned int delay_base)
556{
557 usleep_range(delay_base * 1000, delay_base * 1000 + 500);
558}
559
560/*
561 * v4l2_ctrl and v4l2_subdev related operations
562 */
563static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl)
564{
565 return &container_of(ctrl->handler,
566 struct stimx274, ctrls.handler)->sd;
567}
568
569static inline struct stimx274 *to_imx274(struct v4l2_subdev *sd)
570{
571 return container_of(sd, struct stimx274, sd);
572}
573
574/*
575 * Writing a register table
576 *
577 * @priv: Pointer to device
578 * @table: Table containing register values (with optional delays)
579 *
580 * This is used to write register table into sensor's reg map.
581 *
582 * Return: 0 on success, errors otherwise
583 */
584static int imx274_write_table(struct stimx274 *priv, const struct reg_8 table[])
585{
586 struct regmap *regmap = priv->regmap;
587 int err = 0;
588 const struct reg_8 *next;
589 u8 val;
590
591 int range_start = -1;
592 int range_count = 0;
593 u8 range_vals[16];
594 int max_range_vals = ARRAY_SIZE(range_vals);
595
596 for (next = table;; next++) {
597 if ((next->addr != range_start + range_count) ||
598 (next->addr == IMX274_TABLE_END) ||
599 (next->addr == IMX274_TABLE_WAIT_MS) ||
600 (range_count == max_range_vals)) {
601 if (range_count == 1)
602 err = regmap_write(regmap,
603 range_start, range_vals[0]);
604 else if (range_count > 1)
605 err = regmap_bulk_write(regmap, range_start,
606 &range_vals[0],
607 range_count);
608 else
609 err = 0;
610
611 if (err)
612 return err;
613
614 range_start = -1;
615 range_count = 0;
616
617 /* Handle special address values */
618 if (next->addr == IMX274_TABLE_END)
619 break;
620
621 if (next->addr == IMX274_TABLE_WAIT_MS) {
622 msleep_range(next->val);
623 continue;
624 }
625 }
626
627 val = next->val;
628
629 if (range_start == -1)
630 range_start = next->addr;
631
632 range_vals[range_count++] = val;
633 }
634 return 0;
635}
636
637static inline int imx274_read_reg(struct stimx274 *priv, u16 addr, u8 *val)
638{
639 unsigned int uint_val;
640 int err;
641
642 err = regmap_read(priv->regmap, addr, &uint_val);
643 if (err)
644 dev_err(&priv->client->dev,
645 "%s : i2c read failed, addr = %x\n", __func__, addr);
646 else
647 dev_dbg(&priv->client->dev,
648 "%s : addr 0x%x, val=0x%x\n", __func__,
649 addr, uint_val);
650
651 *val = uint_val;
652 return err;
653}
654
655static inline int imx274_write_reg(struct stimx274 *priv, u16 addr, u8 val)
656{
657 int err;
658
659 err = regmap_write(priv->regmap, addr, val);
660 if (err)
661 dev_err(&priv->client->dev,
662 "%s : i2c write failed, %x = %x\n", __func__,
663 addr, val);
664 else
665 dev_dbg(&priv->client->dev,
666 "%s : addr 0x%x, val=0x%x\n", __func__,
667 addr, val);
668 return err;
669}
670
671/**
672 * Write a multibyte register.
673 *
674 * Uses a bulk write where possible.
675 *
676 * @priv: Pointer to device structure
677 * @addr: Address of the LSB register. Other registers must be
678 * consecutive, least-to-most significant.
679 * @val: Value to be written to the register (cpu endianness)
680 * @nbytes: Number of bits to write (range: [1..3])
681 */
682static int imx274_write_mbreg(struct stimx274 *priv, u16 addr, u32 val,
683 size_t nbytes)
684{
685 __le32 val_le = cpu_to_le32(val);
686 int err;
687
688 err = regmap_bulk_write(priv->regmap, addr, &val_le, nbytes);
689 if (err)
690 dev_err(&priv->client->dev,
691 "%s : i2c bulk write failed, %x = %x (%zu bytes)\n",
692 __func__, addr, val, nbytes);
693 else
694 dev_dbg(&priv->client->dev,
695 "%s : addr 0x%x, val=0x%x (%zu bytes)\n",
696 __func__, addr, val, nbytes);
697 return err;
698}
699
700/*
701 * Set mode registers to start stream.
702 * @priv: Pointer to device structure
703 *
704 * Return: 0 on success, errors otherwise
705 */
706static int imx274_mode_regs(struct stimx274 *priv)
707{
708 int err = 0;
709
710 err = imx274_write_table(priv, imx274_start_1);
711 if (err)
712 return err;
713
714 err = imx274_write_table(priv, imx274_start_2);
715 if (err)
716 return err;
717
718 err = imx274_write_table(priv, priv->mode->init_regs);
719
720 return err;
721}
722
723/*
724 * imx274_start_stream - Function for starting stream per mode index
725 * @priv: Pointer to device structure
726 *
727 * Return: 0 on success, errors otherwise
728 */
729static int imx274_start_stream(struct stimx274 *priv)
730{
731 int err = 0;
732
733 /*
734 * Refer to "Standby Cancel Sequence when using CSI-2" in
735 * imx274 datasheet, it should wait 10ms or more here.
736 * give it 1 extra ms for margin
737 */
738 msleep_range(11);
739 err = imx274_write_table(priv, imx274_start_3);
740 if (err)
741 return err;
742
743 /*
744 * Refer to "Standby Cancel Sequence when using CSI-2" in
745 * imx274 datasheet, it should wait 7ms or more here.
746 * give it 1 extra ms for margin
747 */
748 msleep_range(8);
749 err = imx274_write_table(priv, imx274_start_4);
750 if (err)
751 return err;
752
753 return 0;
754}
755
756/*
757 * imx274_reset - Function called to reset the sensor
758 * @priv: Pointer to device structure
759 * @rst: Input value for determining the sensor's end state after reset
760 *
761 * Set the senor in reset and then
762 * if rst = 0, keep it in reset;
763 * if rst = 1, bring it out of reset.
764 *
765 */
766static void imx274_reset(struct stimx274 *priv, int rst)
767{
768 gpiod_set_value_cansleep(priv->reset_gpio, 0);
769 usleep_range(IMX274_RESET_DELAY1, IMX274_RESET_DELAY2);
770 gpiod_set_value_cansleep(priv->reset_gpio, !!rst);
771 usleep_range(IMX274_RESET_DELAY1, IMX274_RESET_DELAY2);
772}
773
774/**
775 * imx274_s_ctrl - This is used to set the imx274 V4L2 controls
776 * @ctrl: V4L2 control to be set
777 *
778 * This function is used to set the V4L2 controls for the imx274 sensor.
779 *
780 * Return: 0 on success, errors otherwise
781 */
782static int imx274_s_ctrl(struct v4l2_ctrl *ctrl)
783{
784 struct v4l2_subdev *sd = ctrl_to_sd(ctrl);
785 struct stimx274 *imx274 = to_imx274(sd);
786 int ret = -EINVAL;
787
788 dev_dbg(&imx274->client->dev,
789 "%s : s_ctrl: %s, value: %d\n", __func__,
790 ctrl->name, ctrl->val);
791
792 switch (ctrl->id) {
793 case V4L2_CID_EXPOSURE:
794 dev_dbg(&imx274->client->dev,
795 "%s : set V4L2_CID_EXPOSURE\n", __func__);
796 ret = imx274_set_exposure(imx274, ctrl->val);
797 break;
798
799 case V4L2_CID_GAIN:
800 dev_dbg(&imx274->client->dev,
801 "%s : set V4L2_CID_GAIN\n", __func__);
802 ret = imx274_set_gain(imx274, ctrl);
803 break;
804
805 case V4L2_CID_VFLIP:
806 dev_dbg(&imx274->client->dev,
807 "%s : set V4L2_CID_VFLIP\n", __func__);
808 ret = imx274_set_vflip(imx274, ctrl->val);
809 break;
810
811 case V4L2_CID_TEST_PATTERN:
812 dev_dbg(&imx274->client->dev,
813 "%s : set V4L2_CID_TEST_PATTERN\n", __func__);
814 ret = imx274_set_test_pattern(imx274, ctrl->val);
815 break;
816 }
817
818 return ret;
819}
820
821static int imx274_binning_goodness(struct stimx274 *imx274,
822 int w, int ask_w,
823 int h, int ask_h, u32 flags)
824{
825 struct device *dev = &imx274->client->dev;
826 const int goodness = 100000;
827 int val = 0;
828
829 if (flags & V4L2_SEL_FLAG_GE) {
830 if (w < ask_w)
831 val -= goodness;
832 if (h < ask_h)
833 val -= goodness;
834 }
835
836 if (flags & V4L2_SEL_FLAG_LE) {
837 if (w > ask_w)
838 val -= goodness;
839 if (h > ask_h)
840 val -= goodness;
841 }
842
843 val -= abs(w - ask_w);
844 val -= abs(h - ask_h);
845
846 dev_dbg(dev, "%s: ask %dx%d, size %dx%d, goodness %d\n",
847 __func__, ask_w, ask_h, w, h, val);
848
849 return val;
850}
851
852/**
853 * Helper function to change binning and set both compose and format.
854 *
855 * We have two entry points to change binning: set_fmt and
856 * set_selection(COMPOSE). Both have to compute the new output size
857 * and set it in both the compose rect and the frame format size. We
858 * also need to do the same things after setting cropping to restore
859 * 1:1 binning.
860 *
861 * This function contains the common code for these three cases, it
862 * has many arguments in order to accommodate the needs of all of
863 * them.
864 *
865 * Must be called with imx274->lock locked.
866 *
867 * @imx274: The device object
868 * @cfg: The pad config we are editing for TRY requests
869 * @which: V4L2_SUBDEV_FORMAT_ACTIVE or V4L2_SUBDEV_FORMAT_TRY from the caller
870 * @width: Input-output parameter: set to the desired width before
871 * the call, contains the chosen value after returning successfully
872 * @height: Input-output parameter for height (see @width)
873 * @flags: Selection flags from struct v4l2_subdev_selection, or 0 if not
874 * available (when called from set_fmt)
875 */
876static int __imx274_change_compose(struct stimx274 *imx274,
877 struct v4l2_subdev_pad_config *cfg,
878 u32 which,
879 u32 *width,
880 u32 *height,
881 u32 flags)
882{
883 struct device *dev = &imx274->client->dev;
884 const struct v4l2_rect *cur_crop;
885 struct v4l2_mbus_framefmt *tgt_fmt;
886 unsigned int i;
887 const struct imx274_frmfmt *best_mode = &imx274_formats[0];
888 int best_goodness = INT_MIN;
889
890 if (which == V4L2_SUBDEV_FORMAT_TRY) {
891 cur_crop = &cfg->try_crop;
892 tgt_fmt = &cfg->try_fmt;
893 } else {
894 cur_crop = &imx274->crop;
895 tgt_fmt = &imx274->format;
896 }
897
898 for (i = 0; i < ARRAY_SIZE(imx274_formats); i++) {
899 unsigned int ratio = imx274_formats[i].bin_ratio;
900
901 int goodness = imx274_binning_goodness(
902 imx274,
903 cur_crop->width / ratio, *width,
904 cur_crop->height / ratio, *height,
905 flags);
906
907 if (goodness >= best_goodness) {
908 best_goodness = goodness;
909 best_mode = &imx274_formats[i];
910 }
911 }
912
913 *width = cur_crop->width / best_mode->bin_ratio;
914 *height = cur_crop->height / best_mode->bin_ratio;
915
916 if (which == V4L2_SUBDEV_FORMAT_ACTIVE)
917 imx274->mode = best_mode;
918
919 dev_dbg(dev, "%s: selected %u:1 binning\n",
920 __func__, best_mode->bin_ratio);
921
922 tgt_fmt->width = *width;
923 tgt_fmt->height = *height;
924 tgt_fmt->field = V4L2_FIELD_NONE;
925
926 return 0;
927}
928
929/**
930 * imx274_get_fmt - Get the pad format
931 * @sd: Pointer to V4L2 Sub device structure
932 * @cfg: Pointer to sub device pad information structure
933 * @fmt: Pointer to pad level media bus format
934 *
935 * This function is used to get the pad format information.
936 *
937 * Return: 0 on success
938 */
939static int imx274_get_fmt(struct v4l2_subdev *sd,
940 struct v4l2_subdev_pad_config *cfg,
941 struct v4l2_subdev_format *fmt)
942{
943 struct stimx274 *imx274 = to_imx274(sd);
944
945 mutex_lock(&imx274->lock);
946 fmt->format = imx274->format;
947 mutex_unlock(&imx274->lock);
948 return 0;
949}
950
951/**
952 * imx274_set_fmt - This is used to set the pad format
953 * @sd: Pointer to V4L2 Sub device structure
954 * @cfg: Pointer to sub device pad information structure
955 * @format: Pointer to pad level media bus format
956 *
957 * This function is used to set the pad format.
958 *
959 * Return: 0 on success
960 */
961static int imx274_set_fmt(struct v4l2_subdev *sd,
962 struct v4l2_subdev_pad_config *cfg,
963 struct v4l2_subdev_format *format)
964{
965 struct v4l2_mbus_framefmt *fmt = &format->format;
966 struct stimx274 *imx274 = to_imx274(sd);
967 int err = 0;
968
969 mutex_lock(&imx274->lock);
970
971 err = __imx274_change_compose(imx274, cfg, format->which,
972 &fmt->width, &fmt->height, 0);
973
974 if (err)
975 goto out;
976
977 /*
978 * __imx274_change_compose already set width and height in the
979 * applicable format, but we need to keep all other format
980 * values, so do a full copy here
981 */
982 fmt->field = V4L2_FIELD_NONE;
983 if (format->which == V4L2_SUBDEV_FORMAT_TRY)
984 cfg->try_fmt = *fmt;
985 else
986 imx274->format = *fmt;
987
988out:
989 mutex_unlock(&imx274->lock);
990
991 return err;
992}
993
994static int imx274_get_selection(struct v4l2_subdev *sd,
995 struct v4l2_subdev_pad_config *cfg,
996 struct v4l2_subdev_selection *sel)
997{
998 struct stimx274 *imx274 = to_imx274(sd);
999 const struct v4l2_rect *src_crop;
1000 const struct v4l2_mbus_framefmt *src_fmt;
1001 int ret = 0;
1002
1003 if (sel->pad != 0)
1004 return -EINVAL;
1005
1006 if (sel->target == V4L2_SEL_TGT_CROP_BOUNDS) {
1007 sel->r.left = 0;
1008 sel->r.top = 0;
1009 sel->r.width = IMX274_MAX_WIDTH;
1010 sel->r.height = IMX274_MAX_HEIGHT;
1011 return 0;
1012 }
1013
1014 if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
1015 src_crop = &cfg->try_crop;
1016 src_fmt = &cfg->try_fmt;
1017 } else {
1018 src_crop = &imx274->crop;
1019 src_fmt = &imx274->format;
1020 }
1021
1022 mutex_lock(&imx274->lock);
1023
1024 switch (sel->target) {
1025 case V4L2_SEL_TGT_CROP:
1026 sel->r = *src_crop;
1027 break;
1028 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
1029 sel->r.top = 0;
1030 sel->r.left = 0;
1031 sel->r.width = src_crop->width;
1032 sel->r.height = src_crop->height;
1033 break;
1034 case V4L2_SEL_TGT_COMPOSE:
1035 sel->r.top = 0;
1036 sel->r.left = 0;
1037 sel->r.width = src_fmt->width;
1038 sel->r.height = src_fmt->height;
1039 break;
1040 default:
1041 ret = -EINVAL;
1042 }
1043
1044 mutex_unlock(&imx274->lock);
1045
1046 return ret;
1047}
1048
1049static int imx274_set_selection_crop(struct stimx274 *imx274,
1050 struct v4l2_subdev_pad_config *cfg,
1051 struct v4l2_subdev_selection *sel)
1052{
1053 struct v4l2_rect *tgt_crop;
1054 struct v4l2_rect new_crop;
1055 bool size_changed;
1056
1057 /*
1058 * h_step could be 12 or 24 depending on the binning. But we
1059 * won't know the binning until we choose the mode later in
1060 * __imx274_change_compose(). Thus let's be safe and use the
1061 * most conservative value in all cases.
1062 */
1063 const u32 h_step = 24;
1064
1065 new_crop.width = min_t(u32,
1066 IMX274_ROUND(sel->r.width, h_step, sel->flags),
1067 IMX274_MAX_WIDTH);
1068
1069 /* Constraint: HTRIMMING_END - HTRIMMING_START >= 144 */
1070 if (new_crop.width < 144)
1071 new_crop.width = 144;
1072
1073 new_crop.left = min_t(u32,
1074 IMX274_ROUND(sel->r.left, h_step, 0),
1075 IMX274_MAX_WIDTH - new_crop.width);
1076
1077 new_crop.height = min_t(u32,
1078 IMX274_ROUND(sel->r.height, 2, sel->flags),
1079 IMX274_MAX_HEIGHT);
1080
1081 new_crop.top = min_t(u32, IMX274_ROUND(sel->r.top, 2, 0),
1082 IMX274_MAX_HEIGHT - new_crop.height);
1083
1084 sel->r = new_crop;
1085
1086 if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
1087 tgt_crop = &cfg->try_crop;
1088 else
1089 tgt_crop = &imx274->crop;
1090
1091 mutex_lock(&imx274->lock);
1092
1093 size_changed = (new_crop.width != tgt_crop->width ||
1094 new_crop.height != tgt_crop->height);
1095
1096 /* __imx274_change_compose needs the new size in *tgt_crop */
1097 *tgt_crop = new_crop;
1098
1099 /* if crop size changed then reset the output image size */
1100 if (size_changed)
1101 __imx274_change_compose(imx274, cfg, sel->which,
1102 &new_crop.width, &new_crop.height,
1103 sel->flags);
1104
1105 mutex_unlock(&imx274->lock);
1106
1107 return 0;
1108}
1109
1110static int imx274_set_selection(struct v4l2_subdev *sd,
1111 struct v4l2_subdev_pad_config *cfg,
1112 struct v4l2_subdev_selection *sel)
1113{
1114 struct stimx274 *imx274 = to_imx274(sd);
1115
1116 if (sel->pad != 0)
1117 return -EINVAL;
1118
1119 if (sel->target == V4L2_SEL_TGT_CROP)
1120 return imx274_set_selection_crop(imx274, cfg, sel);
1121
1122 if (sel->target == V4L2_SEL_TGT_COMPOSE) {
1123 int err;
1124
1125 mutex_lock(&imx274->lock);
1126 err = __imx274_change_compose(imx274, cfg, sel->which,
1127 &sel->r.width, &sel->r.height,
1128 sel->flags);
1129 mutex_unlock(&imx274->lock);
1130
1131 /*
1132 * __imx274_change_compose already set width and
1133 * height in set->r, we still need to set top-left
1134 */
1135 if (!err) {
1136 sel->r.top = 0;
1137 sel->r.left = 0;
1138 }
1139
1140 return err;
1141 }
1142
1143 return -EINVAL;
1144}
1145
1146static int imx274_apply_trimming(struct stimx274 *imx274)
1147{
1148 u32 h_start;
1149 u32 h_end;
1150 u32 hmax;
1151 u32 v_cut;
1152 s32 v_pos;
1153 u32 write_v_size;
1154 u32 y_out_size;
1155 int err;
1156
1157 h_start = imx274->crop.left + 12;
1158 h_end = h_start + imx274->crop.width;
1159
1160 /* Use the minimum allowed value of HMAX */
1161 /* Note: except in mode 1, (width / 16 + 23) is always < hmax_min */
1162 /* Note: 260 is the minimum HMAX in all implemented modes */
1163 hmax = max_t(u32, 260, (imx274->crop.width) / 16 + 23);
1164
1165 /* invert v_pos if VFLIP */
1166 v_pos = imx274->ctrls.vflip->cur.val ?
1167 (-imx274->crop.top / 2) : (imx274->crop.top / 2);
1168 v_cut = (IMX274_MAX_HEIGHT - imx274->crop.height) / 2;
1169 write_v_size = imx274->crop.height + 22;
1170 y_out_size = imx274->crop.height + 14;
1171
1172 err = imx274_write_mbreg(imx274, IMX274_HMAX_REG_LSB, hmax, 2);
1173 if (!err)
1174 err = imx274_write_mbreg(imx274, IMX274_HTRIM_EN_REG, 1, 1);
1175 if (!err)
1176 err = imx274_write_mbreg(imx274, IMX274_HTRIM_START_REG_LSB,
1177 h_start, 2);
1178 if (!err)
1179 err = imx274_write_mbreg(imx274, IMX274_HTRIM_END_REG_LSB,
1180 h_end, 2);
1181 if (!err)
1182 err = imx274_write_mbreg(imx274, IMX274_VWIDCUTEN_REG, 1, 1);
1183 if (!err)
1184 err = imx274_write_mbreg(imx274, IMX274_VWIDCUT_REG_LSB,
1185 v_cut, 2);
1186 if (!err)
1187 err = imx274_write_mbreg(imx274, IMX274_VWINPOS_REG_LSB,
1188 v_pos, 2);
1189 if (!err)
1190 err = imx274_write_mbreg(imx274, IMX274_WRITE_VSIZE_REG_LSB,
1191 write_v_size, 2);
1192 if (!err)
1193 err = imx274_write_mbreg(imx274, IMX274_Y_OUT_SIZE_REG_LSB,
1194 y_out_size, 2);
1195
1196 return err;
1197}
1198
1199/**
1200 * imx274_g_frame_interval - Get the frame interval
1201 * @sd: Pointer to V4L2 Sub device structure
1202 * @fi: Pointer to V4l2 Sub device frame interval structure
1203 *
1204 * This function is used to get the frame interval.
1205 *
1206 * Return: 0 on success
1207 */
1208static int imx274_g_frame_interval(struct v4l2_subdev *sd,
1209 struct v4l2_subdev_frame_interval *fi)
1210{
1211 struct stimx274 *imx274 = to_imx274(sd);
1212
1213 fi->interval = imx274->frame_interval;
1214 dev_dbg(&imx274->client->dev, "%s frame rate = %d / %d\n",
1215 __func__, imx274->frame_interval.numerator,
1216 imx274->frame_interval.denominator);
1217
1218 return 0;
1219}
1220
1221/**
1222 * imx274_s_frame_interval - Set the frame interval
1223 * @sd: Pointer to V4L2 Sub device structure
1224 * @fi: Pointer to V4l2 Sub device frame interval structure
1225 *
1226 * This function is used to set the frame intervavl.
1227 *
1228 * Return: 0 on success
1229 */
1230static int imx274_s_frame_interval(struct v4l2_subdev *sd,
1231 struct v4l2_subdev_frame_interval *fi)
1232{
1233 struct stimx274 *imx274 = to_imx274(sd);
1234 struct v4l2_ctrl *ctrl = imx274->ctrls.exposure;
1235 int min, max, def;
1236 int ret;
1237
1238 mutex_lock(&imx274->lock);
1239 ret = imx274_set_frame_interval(imx274, fi->interval);
1240
1241 if (!ret) {
1242 /*
1243 * exposure time range is decided by frame interval
1244 * need to update it after frame interval changes
1245 */
1246 min = IMX274_MIN_EXPOSURE_TIME;
1247 max = fi->interval.numerator * 1000000
1248 / fi->interval.denominator;
1249 def = max;
1250 if (__v4l2_ctrl_modify_range(ctrl, min, max, 1, def)) {
1251 dev_err(&imx274->client->dev,
1252 "Exposure ctrl range update failed\n");
1253 goto unlock;
1254 }
1255
1256 /* update exposure time accordingly */
1257 imx274_set_exposure(imx274, ctrl->val);
1258
1259 dev_dbg(&imx274->client->dev, "set frame interval to %uus\n",
1260 fi->interval.numerator * 1000000
1261 / fi->interval.denominator);
1262 }
1263
1264unlock:
1265 mutex_unlock(&imx274->lock);
1266
1267 return ret;
1268}
1269
1270/**
1271 * imx274_load_default - load default control values
1272 * @priv: Pointer to device structure
1273 *
1274 * Return: 0 on success, errors otherwise
1275 */
1276static int imx274_load_default(struct stimx274 *priv)
1277{
1278 int ret;
1279
1280 /* load default control values */
1281 priv->frame_interval.numerator = 1;
1282 priv->frame_interval.denominator = IMX274_DEF_FRAME_RATE;
1283 priv->ctrls.exposure->val = 1000000 / IMX274_DEF_FRAME_RATE;
1284 priv->ctrls.gain->val = IMX274_DEF_GAIN;
1285 priv->ctrls.vflip->val = 0;
1286 priv->ctrls.test_pattern->val = TEST_PATTERN_DISABLED;
1287
1288 /* update frame rate */
1289 ret = imx274_set_frame_interval(priv,
1290 priv->frame_interval);
1291 if (ret)
1292 return ret;
1293
1294 /* update exposure time */
1295 ret = v4l2_ctrl_s_ctrl(priv->ctrls.exposure, priv->ctrls.exposure->val);
1296 if (ret)
1297 return ret;
1298
1299 /* update gain */
1300 ret = v4l2_ctrl_s_ctrl(priv->ctrls.gain, priv->ctrls.gain->val);
1301 if (ret)
1302 return ret;
1303
1304 /* update vflip */
1305 ret = v4l2_ctrl_s_ctrl(priv->ctrls.vflip, priv->ctrls.vflip->val);
1306 if (ret)
1307 return ret;
1308
1309 return 0;
1310}
1311
1312/**
1313 * imx274_s_stream - It is used to start/stop the streaming.
1314 * @sd: V4L2 Sub device
1315 * @on: Flag (True / False)
1316 *
1317 * This function controls the start or stop of streaming for the
1318 * imx274 sensor.
1319 *
1320 * Return: 0 on success, errors otherwise
1321 */
1322static int imx274_s_stream(struct v4l2_subdev *sd, int on)
1323{
1324 struct stimx274 *imx274 = to_imx274(sd);
1325 int ret = 0;
1326
1327 dev_dbg(&imx274->client->dev, "%s : %s, mode index = %td\n", __func__,
1328 on ? "Stream Start" : "Stream Stop",
1329 imx274->mode - &imx274_formats[0]);
1330
1331 mutex_lock(&imx274->lock);
1332
1333 if (on) {
1334 /* load mode registers */
1335 ret = imx274_mode_regs(imx274);
1336 if (ret)
1337 goto fail;
1338
1339 ret = imx274_apply_trimming(imx274);
1340 if (ret)
1341 goto fail;
1342
1343 /*
1344 * update frame rate & expsoure. if the last mode is different,
1345 * HMAX could be changed. As the result, frame rate & exposure
1346 * are changed.
1347 * gain is not affected.
1348 */
1349 ret = imx274_set_frame_interval(imx274,
1350 imx274->frame_interval);
1351 if (ret)
1352 goto fail;
1353
1354 /* update exposure time */
1355 ret = __v4l2_ctrl_s_ctrl(imx274->ctrls.exposure,
1356 imx274->ctrls.exposure->val);
1357 if (ret)
1358 goto fail;
1359
1360 /* start stream */
1361 ret = imx274_start_stream(imx274);
1362 if (ret)
1363 goto fail;
1364 } else {
1365 /* stop stream */
1366 ret = imx274_write_table(imx274, imx274_stop);
1367 if (ret)
1368 goto fail;
1369 }
1370
1371 mutex_unlock(&imx274->lock);
1372 dev_dbg(&imx274->client->dev, "%s : Done\n", __func__);
1373 return 0;
1374
1375fail:
1376 mutex_unlock(&imx274->lock);
1377 dev_err(&imx274->client->dev, "s_stream failed\n");
1378 return ret;
1379}
1380
1381/*
1382 * imx274_get_frame_length - Function for obtaining current frame length
1383 * @priv: Pointer to device structure
1384 * @val: Pointer to obainted value
1385 *
1386 * frame_length = vmax x (svr + 1), in unit of hmax.
1387 *
1388 * Return: 0 on success
1389 */
1390static int imx274_get_frame_length(struct stimx274 *priv, u32 *val)
1391{
1392 int err;
1393 u16 svr;
1394 u32 vmax;
1395 u8 reg_val[3];
1396
1397 /* svr */
1398 err = imx274_read_reg(priv, IMX274_SVR_REG_LSB, &reg_val[0]);
1399 if (err)
1400 goto fail;
1401
1402 err = imx274_read_reg(priv, IMX274_SVR_REG_MSB, &reg_val[1]);
1403 if (err)
1404 goto fail;
1405
1406 svr = (reg_val[1] << IMX274_SHIFT_8_BITS) + reg_val[0];
1407
1408 /* vmax */
1409 err = imx274_read_reg(priv, IMX274_VMAX_REG_3, &reg_val[0]);
1410 if (err)
1411 goto fail;
1412
1413 err = imx274_read_reg(priv, IMX274_VMAX_REG_2, &reg_val[1]);
1414 if (err)
1415 goto fail;
1416
1417 err = imx274_read_reg(priv, IMX274_VMAX_REG_1, &reg_val[2]);
1418 if (err)
1419 goto fail;
1420
1421 vmax = ((reg_val[2] & IMX274_MASK_LSB_3_BITS) << IMX274_SHIFT_16_BITS)
1422 + (reg_val[1] << IMX274_SHIFT_8_BITS) + reg_val[0];
1423
1424 *val = vmax * (svr + 1);
1425
1426 return 0;
1427
1428fail:
1429 dev_err(&priv->client->dev, "%s error = %d\n", __func__, err);
1430 return err;
1431}
1432
1433static int imx274_clamp_coarse_time(struct stimx274 *priv, u32 *val,
1434 u32 *frame_length)
1435{
1436 int err;
1437
1438 err = imx274_get_frame_length(priv, frame_length);
1439 if (err)
1440 return err;
1441
1442 if (*frame_length < priv->mode->min_frame_len)
1443 *frame_length = priv->mode->min_frame_len;
1444
1445 *val = *frame_length - *val; /* convert to raw shr */
1446 if (*val > *frame_length - IMX274_SHR_LIMIT_CONST)
1447 *val = *frame_length - IMX274_SHR_LIMIT_CONST;
1448 else if (*val < priv->mode->min_SHR)
1449 *val = priv->mode->min_SHR;
1450
1451 return 0;
1452}
1453
1454/*
1455 * imx274_set_digital gain - Function called when setting digital gain
1456 * @priv: Pointer to device structure
1457 * @dgain: Value of digital gain.
1458 *
1459 * Digital gain has only 4 steps: 1x, 2x, 4x, and 8x
1460 *
1461 * Return: 0 on success
1462 */
1463static int imx274_set_digital_gain(struct stimx274 *priv, u32 dgain)
1464{
1465 u8 reg_val;
1466
1467 reg_val = ffs(dgain);
1468
1469 if (reg_val)
1470 reg_val--;
1471
1472 reg_val = clamp(reg_val, (u8)0, (u8)3);
1473
1474 return imx274_write_reg(priv, IMX274_DIGITAL_GAIN_REG,
1475 reg_val & IMX274_MASK_LSB_4_BITS);
1476}
1477
1478/*
1479 * imx274_set_gain - Function called when setting gain
1480 * @priv: Pointer to device structure
1481 * @val: Value of gain. the real value = val << IMX274_GAIN_SHIFT;
1482 * @ctrl: v4l2 control pointer
1483 *
1484 * Set the gain based on input value.
1485 * The caller should hold the mutex lock imx274->lock if necessary
1486 *
1487 * Return: 0 on success
1488 */
1489static int imx274_set_gain(struct stimx274 *priv, struct v4l2_ctrl *ctrl)
1490{
1491 int err;
1492 u32 gain, analog_gain, digital_gain, gain_reg;
1493
1494 gain = (u32)(ctrl->val);
1495
1496 dev_dbg(&priv->client->dev,
1497 "%s : input gain = %d.%d\n", __func__,
1498 gain >> IMX274_GAIN_SHIFT,
1499 ((gain & IMX274_GAIN_SHIFT_MASK) * 100) >> IMX274_GAIN_SHIFT);
1500
1501 if (gain > IMX274_MAX_DIGITAL_GAIN * IMX274_MAX_ANALOG_GAIN)
1502 gain = IMX274_MAX_DIGITAL_GAIN * IMX274_MAX_ANALOG_GAIN;
1503 else if (gain < IMX274_MIN_GAIN)
1504 gain = IMX274_MIN_GAIN;
1505
1506 if (gain <= IMX274_MAX_ANALOG_GAIN)
1507 digital_gain = 1;
1508 else if (gain <= IMX274_MAX_ANALOG_GAIN * 2)
1509 digital_gain = 2;
1510 else if (gain <= IMX274_MAX_ANALOG_GAIN * 4)
1511 digital_gain = 4;
1512 else
1513 digital_gain = IMX274_MAX_DIGITAL_GAIN;
1514
1515 analog_gain = gain / digital_gain;
1516
1517 dev_dbg(&priv->client->dev,
1518 "%s : digital gain = %d, analog gain = %d.%d\n",
1519 __func__, digital_gain, analog_gain >> IMX274_GAIN_SHIFT,
1520 ((analog_gain & IMX274_GAIN_SHIFT_MASK) * 100)
1521 >> IMX274_GAIN_SHIFT);
1522
1523 err = imx274_set_digital_gain(priv, digital_gain);
1524 if (err)
1525 goto fail;
1526
1527 /* convert to register value, refer to imx274 datasheet */
1528 gain_reg = (u32)IMX274_GAIN_CONST -
1529 (IMX274_GAIN_CONST << IMX274_GAIN_SHIFT) / analog_gain;
1530 if (gain_reg > IMX274_GAIN_REG_MAX)
1531 gain_reg = IMX274_GAIN_REG_MAX;
1532
1533 err = imx274_write_mbreg(priv, IMX274_ANALOG_GAIN_ADDR_LSB, gain_reg,
1534 2);
1535 if (err)
1536 goto fail;
1537
1538 if (IMX274_GAIN_CONST - gain_reg == 0) {
1539 err = -EINVAL;
1540 goto fail;
1541 }
1542
1543 /* convert register value back to gain value */
1544 ctrl->val = (IMX274_GAIN_CONST << IMX274_GAIN_SHIFT)
1545 / (IMX274_GAIN_CONST - gain_reg) * digital_gain;
1546
1547 dev_dbg(&priv->client->dev,
1548 "%s : GAIN control success, gain_reg = %d, new gain = %d\n",
1549 __func__, gain_reg, ctrl->val);
1550
1551 return 0;
1552
1553fail:
1554 dev_err(&priv->client->dev, "%s error = %d\n", __func__, err);
1555 return err;
1556}
1557
1558/*
1559 * imx274_set_coarse_time - Function called when setting SHR value
1560 * @priv: Pointer to device structure
1561 * @val: Value for exposure time in number of line_length, or [HMAX]
1562 *
1563 * Set SHR value based on input value.
1564 *
1565 * Return: 0 on success
1566 */
1567static int imx274_set_coarse_time(struct stimx274 *priv, u32 *val)
1568{
1569 int err;
1570 u32 coarse_time, frame_length;
1571
1572 coarse_time = *val;
1573
1574 /* convert exposure_time to appropriate SHR value */
1575 err = imx274_clamp_coarse_time(priv, &coarse_time, &frame_length);
1576 if (err)
1577 goto fail;
1578
1579 err = imx274_write_mbreg(priv, IMX274_SHR_REG_LSB, coarse_time, 2);
1580 if (err)
1581 goto fail;
1582
1583 *val = frame_length - coarse_time;
1584 return 0;
1585
1586fail:
1587 dev_err(&priv->client->dev, "%s error = %d\n", __func__, err);
1588 return err;
1589}
1590
1591/*
1592 * imx274_set_exposure - Function called when setting exposure time
1593 * @priv: Pointer to device structure
1594 * @val: Variable for exposure time, in the unit of micro-second
1595 *
1596 * Set exposure time based on input value.
1597 * The caller should hold the mutex lock imx274->lock if necessary
1598 *
1599 * Return: 0 on success
1600 */
1601static int imx274_set_exposure(struct stimx274 *priv, int val)
1602{
1603 int err;
1604 u16 hmax;
1605 u8 reg_val[2];
1606 u32 coarse_time; /* exposure time in unit of line (HMAX)*/
1607
1608 dev_dbg(&priv->client->dev,
1609 "%s : EXPOSURE control input = %d\n", __func__, val);
1610
1611 /* step 1: convert input exposure_time (val) into number of 1[HMAX] */
1612
1613 /* obtain HMAX value */
1614 err = imx274_read_reg(priv, IMX274_HMAX_REG_LSB, &reg_val[0]);
1615 if (err)
1616 goto fail;
1617 err = imx274_read_reg(priv, IMX274_HMAX_REG_MSB, &reg_val[1]);
1618 if (err)
1619 goto fail;
1620 hmax = (reg_val[1] << IMX274_SHIFT_8_BITS) + reg_val[0];
1621 if (hmax == 0) {
1622 err = -EINVAL;
1623 goto fail;
1624 }
1625
1626 coarse_time = (IMX274_PIXCLK_CONST1 / IMX274_PIXCLK_CONST2 * val
1627 - priv->mode->nocpiop) / hmax;
1628
1629 /* step 2: convert exposure_time into SHR value */
1630
1631 /* set SHR */
1632 err = imx274_set_coarse_time(priv, &coarse_time);
1633 if (err)
1634 goto fail;
1635
1636 priv->ctrls.exposure->val =
1637 (coarse_time * hmax + priv->mode->nocpiop)
1638 / (IMX274_PIXCLK_CONST1 / IMX274_PIXCLK_CONST2);
1639
1640 dev_dbg(&priv->client->dev,
1641 "%s : EXPOSURE control success\n", __func__);
1642 return 0;
1643
1644fail:
1645 dev_err(&priv->client->dev, "%s error = %d\n", __func__, err);
1646
1647 return err;
1648}
1649
1650/*
1651 * imx274_set_vflip - Function called when setting vertical flip
1652 * @priv: Pointer to device structure
1653 * @val: Value for vflip setting
1654 *
1655 * Set vertical flip based on input value.
1656 * val = 0: normal, no vertical flip
1657 * val = 1: vertical flip enabled
1658 * The caller should hold the mutex lock imx274->lock if necessary
1659 *
1660 * Return: 0 on success
1661 */
1662static int imx274_set_vflip(struct stimx274 *priv, int val)
1663{
1664 int err;
1665
1666 err = imx274_write_reg(priv, IMX274_VFLIP_REG, val);
1667 if (err) {
1668 dev_err(&priv->client->dev, "VFLIP control error\n");
1669 return err;
1670 }
1671
1672 dev_dbg(&priv->client->dev,
1673 "%s : VFLIP control success\n", __func__);
1674
1675 return 0;
1676}
1677
1678/*
1679 * imx274_set_test_pattern - Function called when setting test pattern
1680 * @priv: Pointer to device structure
1681 * @val: Variable for test pattern
1682 *
1683 * Set to different test patterns based on input value.
1684 *
1685 * Return: 0 on success
1686 */
1687static int imx274_set_test_pattern(struct stimx274 *priv, int val)
1688{
1689 int err = 0;
1690
1691 if (val == TEST_PATTERN_DISABLED) {
1692 err = imx274_write_table(priv, imx274_tp_disabled);
1693 } else if (val <= TEST_PATTERN_V_COLOR_BARS) {
1694 err = imx274_write_reg(priv, IMX274_TEST_PATTERN_REG, val - 1);
1695 if (!err)
1696 err = imx274_write_table(priv, imx274_tp_regs);
1697 } else {
1698 err = -EINVAL;
1699 }
1700
1701 if (!err)
1702 dev_dbg(&priv->client->dev,
1703 "%s : TEST PATTERN control success\n", __func__);
1704 else
1705 dev_err(&priv->client->dev, "%s error = %d\n", __func__, err);
1706
1707 return err;
1708}
1709
1710/*
1711 * imx274_set_frame_length - Function called when setting frame length
1712 * @priv: Pointer to device structure
1713 * @val: Variable for frame length (= VMAX, i.e. vertical drive period length)
1714 *
1715 * Set frame length based on input value.
1716 *
1717 * Return: 0 on success
1718 */
1719static int imx274_set_frame_length(struct stimx274 *priv, u32 val)
1720{
1721 int err;
1722 u32 frame_length;
1723
1724 dev_dbg(&priv->client->dev, "%s : input length = %d\n",
1725 __func__, val);
1726
1727 frame_length = (u32)val;
1728
1729 err = imx274_write_mbreg(priv, IMX274_VMAX_REG_3, frame_length, 3);
1730 if (err)
1731 goto fail;
1732
1733 return 0;
1734
1735fail:
1736 dev_err(&priv->client->dev, "%s error = %d\n", __func__, err);
1737 return err;
1738}
1739
1740/*
1741 * imx274_set_frame_interval - Function called when setting frame interval
1742 * @priv: Pointer to device structure
1743 * @frame_interval: Variable for frame interval
1744 *
1745 * Change frame interval by updating VMAX value
1746 * The caller should hold the mutex lock imx274->lock if necessary
1747 *
1748 * Return: 0 on success
1749 */
1750static int imx274_set_frame_interval(struct stimx274 *priv,
1751 struct v4l2_fract frame_interval)
1752{
1753 int err;
1754 u32 frame_length, req_frame_rate;
1755 u16 svr;
1756 u16 hmax;
1757 u8 reg_val[2];
1758
1759 dev_dbg(&priv->client->dev, "%s: input frame interval = %d / %d",
1760 __func__, frame_interval.numerator,
1761 frame_interval.denominator);
1762
1763 if (frame_interval.numerator == 0) {
1764 err = -EINVAL;
1765 goto fail;
1766 }
1767
1768 req_frame_rate = (u32)(frame_interval.denominator
1769 / frame_interval.numerator);
1770
1771 /* boundary check */
1772 if (req_frame_rate > priv->mode->max_fps) {
1773 frame_interval.numerator = 1;
1774 frame_interval.denominator = priv->mode->max_fps;
1775 } else if (req_frame_rate < IMX274_MIN_FRAME_RATE) {
1776 frame_interval.numerator = 1;
1777 frame_interval.denominator = IMX274_MIN_FRAME_RATE;
1778 }
1779
1780 /*
1781 * VMAX = 1/frame_rate x 72M / (SVR+1) / HMAX
1782 * frame_length (i.e. VMAX) = (frame_interval) x 72M /(SVR+1) / HMAX
1783 */
1784
1785 /* SVR */
1786 err = imx274_read_reg(priv, IMX274_SVR_REG_LSB, &reg_val[0]);
1787 if (err)
1788 goto fail;
1789 err = imx274_read_reg(priv, IMX274_SVR_REG_MSB, &reg_val[1]);
1790 if (err)
1791 goto fail;
1792 svr = (reg_val[1] << IMX274_SHIFT_8_BITS) + reg_val[0];
1793 dev_dbg(&priv->client->dev,
1794 "%s : register SVR = %d\n", __func__, svr);
1795
1796 /* HMAX */
1797 err = imx274_read_reg(priv, IMX274_HMAX_REG_LSB, &reg_val[0]);
1798 if (err)
1799 goto fail;
1800 err = imx274_read_reg(priv, IMX274_HMAX_REG_MSB, &reg_val[1]);
1801 if (err)
1802 goto fail;
1803 hmax = (reg_val[1] << IMX274_SHIFT_8_BITS) + reg_val[0];
1804 dev_dbg(&priv->client->dev,
1805 "%s : register HMAX = %d\n", __func__, hmax);
1806
1807 if (hmax == 0 || frame_interval.denominator == 0) {
1808 err = -EINVAL;
1809 goto fail;
1810 }
1811
1812 frame_length = IMX274_PIXCLK_CONST1 / (svr + 1) / hmax
1813 * frame_interval.numerator
1814 / frame_interval.denominator;
1815
1816 err = imx274_set_frame_length(priv, frame_length);
1817 if (err)
1818 goto fail;
1819
1820 priv->frame_interval = frame_interval;
1821 return 0;
1822
1823fail:
1824 dev_err(&priv->client->dev, "%s error = %d\n", __func__, err);
1825 return err;
1826}
1827
1828static const struct v4l2_subdev_pad_ops imx274_pad_ops = {
1829 .get_fmt = imx274_get_fmt,
1830 .set_fmt = imx274_set_fmt,
1831 .get_selection = imx274_get_selection,
1832 .set_selection = imx274_set_selection,
1833};
1834
1835static const struct v4l2_subdev_video_ops imx274_video_ops = {
1836 .g_frame_interval = imx274_g_frame_interval,
1837 .s_frame_interval = imx274_s_frame_interval,
1838 .s_stream = imx274_s_stream,
1839};
1840
1841static const struct v4l2_subdev_ops imx274_subdev_ops = {
1842 .pad = &imx274_pad_ops,
1843 .video = &imx274_video_ops,
1844};
1845
1846static const struct v4l2_ctrl_ops imx274_ctrl_ops = {
1847 .s_ctrl = imx274_s_ctrl,
1848};
1849
1850static const struct of_device_id imx274_of_id_table[] = {
1851 { .compatible = "sony,imx274" },
1852 { }
1853};
1854MODULE_DEVICE_TABLE(of, imx274_of_id_table);
1855
1856static const struct i2c_device_id imx274_id[] = {
1857 { "IMX274", 0 },
1858 { }
1859};
1860MODULE_DEVICE_TABLE(i2c, imx274_id);
1861
1862static int imx274_probe(struct i2c_client *client,
1863 const struct i2c_device_id *id)
1864{
1865 struct v4l2_subdev *sd;
1866 struct stimx274 *imx274;
1867 int ret;
1868
1869 /* initialize imx274 */
1870 imx274 = devm_kzalloc(&client->dev, sizeof(*imx274), GFP_KERNEL);
1871 if (!imx274)
1872 return -ENOMEM;
1873
1874 mutex_init(&imx274->lock);
1875
1876 /* initialize format */
1877 imx274->mode = &imx274_formats[IMX274_DEFAULT_MODE];
1878 imx274->crop.width = IMX274_MAX_WIDTH;
1879 imx274->crop.height = IMX274_MAX_HEIGHT;
1880 imx274->format.width = imx274->crop.width / imx274->mode->bin_ratio;
1881 imx274->format.height = imx274->crop.height / imx274->mode->bin_ratio;
1882 imx274->format.field = V4L2_FIELD_NONE;
1883 imx274->format.code = MEDIA_BUS_FMT_SRGGB10_1X10;
1884 imx274->format.colorspace = V4L2_COLORSPACE_SRGB;
1885 imx274->frame_interval.numerator = 1;
1886 imx274->frame_interval.denominator = IMX274_DEF_FRAME_RATE;
1887
1888 /* initialize regmap */
1889 imx274->regmap = devm_regmap_init_i2c(client, &imx274_regmap_config);
1890 if (IS_ERR(imx274->regmap)) {
1891 dev_err(&client->dev,
1892 "regmap init failed: %ld\n", PTR_ERR(imx274->regmap));
1893 ret = -ENODEV;
1894 goto err_regmap;
1895 }
1896
1897 /* initialize subdevice */
1898 imx274->client = client;
1899 sd = &imx274->sd;
1900 v4l2_i2c_subdev_init(sd, client, &imx274_subdev_ops);
1901 strlcpy(sd->name, DRIVER_NAME, sizeof(sd->name));
1902 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
1903
1904 /* initialize subdev media pad */
1905 imx274->pad.flags = MEDIA_PAD_FL_SOURCE;
1906 sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
1907 ret = media_entity_pads_init(&sd->entity, 1, &imx274->pad);
1908 if (ret < 0) {
1909 dev_err(&client->dev,
1910 "%s : media entity init Failed %d\n", __func__, ret);
1911 goto err_regmap;
1912 }
1913
1914 /* initialize sensor reset gpio */
1915 imx274->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
1916 GPIOD_OUT_HIGH);
1917 if (IS_ERR(imx274->reset_gpio)) {
1918 if (PTR_ERR(imx274->reset_gpio) != -EPROBE_DEFER)
1919 dev_err(&client->dev, "Reset GPIO not setup in DT");
1920 ret = PTR_ERR(imx274->reset_gpio);
1921 goto err_me;
1922 }
1923
1924 /* pull sensor out of reset */
1925 imx274_reset(imx274, 1);
1926
1927 /* initialize controls */
1928 ret = v4l2_ctrl_handler_init(&imx274->ctrls.handler, 2);
1929 if (ret < 0) {
1930 dev_err(&client->dev,
1931 "%s : ctrl handler init Failed\n", __func__);
1932 goto err_me;
1933 }
1934
1935 imx274->ctrls.handler.lock = &imx274->lock;
1936
1937 /* add new controls */
1938 imx274->ctrls.test_pattern = v4l2_ctrl_new_std_menu_items(
1939 &imx274->ctrls.handler, &imx274_ctrl_ops,
1940 V4L2_CID_TEST_PATTERN,
1941 ARRAY_SIZE(tp_qmenu) - 1, 0, 0, tp_qmenu);
1942
1943 imx274->ctrls.gain = v4l2_ctrl_new_std(
1944 &imx274->ctrls.handler,
1945 &imx274_ctrl_ops,
1946 V4L2_CID_GAIN, IMX274_MIN_GAIN,
1947 IMX274_MAX_DIGITAL_GAIN * IMX274_MAX_ANALOG_GAIN, 1,
1948 IMX274_DEF_GAIN);
1949
1950 imx274->ctrls.exposure = v4l2_ctrl_new_std(
1951 &imx274->ctrls.handler,
1952 &imx274_ctrl_ops,
1953 V4L2_CID_EXPOSURE, IMX274_MIN_EXPOSURE_TIME,
1954 1000000 / IMX274_DEF_FRAME_RATE, 1,
1955 IMX274_MIN_EXPOSURE_TIME);
1956
1957 imx274->ctrls.vflip = v4l2_ctrl_new_std(
1958 &imx274->ctrls.handler,
1959 &imx274_ctrl_ops,
1960 V4L2_CID_VFLIP, 0, 1, 1, 0);
1961
1962 imx274->sd.ctrl_handler = &imx274->ctrls.handler;
1963 if (imx274->ctrls.handler.error) {
1964 ret = imx274->ctrls.handler.error;
1965 goto err_ctrls;
1966 }
1967
1968 /* setup default controls */
1969 ret = v4l2_ctrl_handler_setup(&imx274->ctrls.handler);
1970 if (ret) {
1971 dev_err(&client->dev,
1972 "Error %d setup default controls\n", ret);
1973 goto err_ctrls;
1974 }
1975
1976 /* load default control values */
1977 ret = imx274_load_default(imx274);
1978 if (ret) {
1979 dev_err(&client->dev,
1980 "%s : imx274_load_default failed %d\n",
1981 __func__, ret);
1982 goto err_ctrls;
1983 }
1984
1985 /* register subdevice */
1986 ret = v4l2_async_register_subdev(sd);
1987 if (ret < 0) {
1988 dev_err(&client->dev,
1989 "%s : v4l2_async_register_subdev failed %d\n",
1990 __func__, ret);
1991 goto err_ctrls;
1992 }
1993
1994 dev_info(&client->dev, "imx274 : imx274 probe success !\n");
1995 return 0;
1996
1997err_ctrls:
1998 v4l2_ctrl_handler_free(&imx274->ctrls.handler);
1999err_me:
2000 media_entity_cleanup(&sd->entity);
2001err_regmap:
2002 mutex_destroy(&imx274->lock);
2003 return ret;
2004}
2005
2006static int imx274_remove(struct i2c_client *client)
2007{
2008 struct v4l2_subdev *sd = i2c_get_clientdata(client);
2009 struct stimx274 *imx274 = to_imx274(sd);
2010
2011 /* stop stream */
2012 imx274_write_table(imx274, imx274_stop);
2013
2014 v4l2_async_unregister_subdev(sd);
2015 v4l2_ctrl_handler_free(&imx274->ctrls.handler);
2016 media_entity_cleanup(&sd->entity);
2017 mutex_destroy(&imx274->lock);
2018 return 0;
2019}
2020
2021static struct i2c_driver imx274_i2c_driver = {
2022 .driver = {
2023 .name = DRIVER_NAME,
2024 .of_match_table = imx274_of_id_table,
2025 },
2026 .probe = imx274_probe,
2027 .remove = imx274_remove,
2028 .id_table = imx274_id,
2029};
2030
2031module_i2c_driver(imx274_i2c_driver);
2032
2033MODULE_AUTHOR("Leon Luo <leonl@leopardimaging.com>");
2034MODULE_DESCRIPTION("IMX274 CMOS Image Sensor driver");
2035MODULE_LICENSE("GPL v2");