aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/debugobjects.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/debugobjects.h')
0 files changed, 0 insertions, 0 deletions
ile promotions <svcmobile_promotions@nvidia.com> 2018-05-10 13:53:07 -0400 drivers: i2c: imx268: add limits to controls' href='/cgit/cgit.cgi/nvidia-tegra-modules.git/commit/drivers/media/i2c/imx268.c?h=gpu-paging&id=53b1a0d53f573b6c2979323a69ef9d4c58994aa2'>53b1a0d53
4393b3627



bc30d6d23

4393b3627
bc30d6d23

3068f295e
bc30d6d23
3068f295e
3068f295e
bc30d6d23











53b1a0d53
bc30d6d23


53b1a0d53



bc30d6d23
53b1a0d53
bc30d6d23














3068f295e
bc30d6d23
3068f295e


bc30d6d23







4393b3627
bc30d6d23

53b1a0d53


bc30d6d23

















3068f295e
bc30d6d23
3068f295e


4393b3627







53b1a0d53
4393b3627
53b1a0d53

4393b3627
53b1a0d53

4393b3627

53b1a0d53

4393b3627

53b1a0d53

4393b3627













bc30d6d23




bc30d6d23


4393b3627
bc30d6d23







































































bc30d6d23























3068f295e
bc30d6d23
3068f295e
bc30d6d23
























3068f295e
bc30d6d23
3068f295e

bc30d6d23



















































3068f295e
bc30d6d23
3068f295e
bc30d6d23




dfe70c942
bc30d6d23


















dfe70c942


bc30d6d23



dfe70c942
bc30d6d23





























0e15664e4
bc30d6d23
0e15664e4

bc30d6d23

bc30d6d23

0e15664e4
bc30d6d23


0e15664e4
bc30d6d23

bc30d6d23

0e15664e4
bc30d6d23
0e15664e4

bc30d6d23
0e15664e4


bc30d6d23



0e15664e4
bc30d6d23
0e15664e4

bc30d6d23
0e15664e4









bc30d6d23
0e15664e4
bc30d6d23

0e15664e4












bc30d6d23
















































bc30d6d23


























bc30d6d23
bc30d6d23




























































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727


                                  
                                                                     




























                                                                            






                                              
 
                                            
                                                      
















                                                      










































































                                                                              
                                                                          
 
                                                           
                                         
                    
 


                                                            



                                                                         

         
                 

 
                                                                   
 
                                                           
                                         











                                                                            
                                                           


                                                                         



                                               
 
                                                                               














                                                                           
                                                                         
 


                                                            







                                                                            
                                                                

                                                          


                                                                           

















                                                                              
                                                                       
 


                                                            







                                                                            
                                                                
                                                          

                                                                              
 

                                                         

                                                 

                                                                          

         

                                                                     













                                                                             




                                                   


                                                
                                                







































































                                                                        























                                                                         
                                                           
 
                                                           
























                                                                
                                                           
 

                                                           



















































                                                                                
                                                                                  
 
                                         




                                                     
                 


















                                                                                


                                                       



                                                                
                                                          





























                                                        
                                                          
 

                                                                             

                

                                                                       
                           


                                                                 
                           

                 

 
                                                                 
 

                                                                             
 


                                                                             



                 
                                                                
 

                                                                             
 









                                                                              
 
                 

 












                                                            
















































                                                                           


























                                                                               
                                                                  




























































                                                                                
/*
 * imx268.c - imx268 sensor driver
 *
 * Copyright (c) 2016-2019, NVIDIA CORPORATION.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/gpio.h>
#include <linux/module.h>
#include <linux/seq_file.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_gpio.h>

#include <media/tegra_v4l2_camera.h>
#include <media/tegracam_core.h>

#include "../platform/tegra/camera/camera_gpio.h"
#include "imx268_mode_tbls.h"

/* imx268 - sensor parameter limits */
#define IMX268_MIN_ANALOG_GAIN		0
#define IMX268_MAX_ANALOG_GAIN		480
#define IMX268_MAX_FRAME_LENGTH		0xFFFF
#define IMX268_MIN_COARSE_EXPOSURE	0x0001
#define IMX268_MAX_COARSE_DIFF		0x0A
#define IMX268_FINE_INTEG_TIME		0x0298

/* imx268 - sensor i2c register addresses */
#define IMX268_GROUP_HOLD_ADDR			0x0104
#define IMX268_COARSE_INTEG_TIME_ADDR_MSB	0x0202
#define IMX268_COARSE_INTEG_TIME_ADDR_LSB	0x0203
#define IMX268_GAIN_ADDR_MSB			0x0204
#define IMX268_GAIN_ADDR_LSB			0x0205
#define IMX268_FRAME_LENGTH_ADDR_MSB		0x0340
#define IMX268_FRAME_LENGTH_ADDR_LSB		0x0341

static const struct of_device_id imx268_of_match[] = {
	{ .compatible = "nvidia,imx268", },
	{ },
};
MODULE_DEVICE_TABLE(of, imx268_of_match);

static const u32 ctrl_cid_list[] = {
	TEGRA_CAMERA_CID_GAIN,
	TEGRA_CAMERA_CID_EXPOSURE,
	TEGRA_CAMERA_CID_FRAME_RATE,
};

struct imx268 {
	struct i2c_client *i2c_client;
	struct v4l2_subdev *subdev;
	u32 frame_length;
	struct camera_common_data *s_data;
	struct tegracam_device *tc_dev;
};

static const struct regmap_config sensor_regmap_config = {
	.reg_bits = 16,
	.val_bits = 8,
	.cache_type = REGCACHE_RBTREE,
	.use_single_rw = true,
};

static inline void imx268_get_coarse_time_regs(imx268_reg *regs,
	u32 coarse_time)
{
	regs->addr = IMX268_COARSE_INTEG_TIME_ADDR_MSB;
	regs->val = (coarse_time >> 8) & 0xff;
	(regs + 1)->addr = IMX268_COARSE_INTEG_TIME_ADDR_LSB;
	(regs + 1)->val = (coarse_time) & 0xff;
}

static inline void imx268_get_gain_regs(imx268_reg *regs, s16 gain)
{
	regs->addr = IMX268_GAIN_ADDR_MSB;
	regs->val = (gain >> 8) & 0x01;
	(regs + 1)->addr = IMX268_GAIN_ADDR_LSB;
	(regs + 1)->val = (gain) & 0xff;
}

static inline void imx268_get_frame_length_regs(imx268_reg *regs,
	u32 frame_length)
{
	regs->addr = IMX268_FRAME_LENGTH_ADDR_MSB;
	regs->val = (frame_length >> 8) & 0xff;
	(regs + 1)->addr = IMX268_FRAME_LENGTH_ADDR_LSB;
	(regs + 1)->val = (frame_length) & 0xff;
}

static inline int imx268_read_reg(struct camera_common_data *s_data,
	u16 addr, u8 *val)
{
	int err = 0;
	u32 reg_val = 0;

	err = regmap_read(s_data->regmap, addr, &reg_val);
	*val = reg_val & 0xff;

	return err;
}

static inline int imx268_write_reg(struct camera_common_data *s_data,
	u16 addr, u8 val)
{
	int err;

	err = regmap_write(s_data->regmap, addr, val);
	if (err)
		dev_err(s_data->dev, "%s: i2c write failed, 0x%x = %x",
			__func__, addr, val);

	return err;
}

static inline int imx268_write_table(struct imx268 *priv,
	const imx268_reg table[])
{
	return regmap_util_write_table_8(priv->s_data->regmap, table, NULL, 0,
		IMX268_TABLE_WAIT_MS, IMX268_TABLE_END);
}

static int imx268_set_group_hold(struct tegracam_device *tc_dev, bool val)
{
	struct camera_common_data *s_data = tc_dev->s_data;
	struct device *dev = tc_dev->dev;
	int err = 0;

	dev_dbg(dev, "%s: %s group_hold\n",
		__func__, (val ? "enabling" : "disabling"));

	err = imx268_write_reg(s_data, IMX268_GROUP_HOLD_ADDR, val);
	if (err) {
		dev_dbg(dev, "%s: group hold control error\n", __func__);
		return err;
	}

	return 0;
}

static int imx268_set_gain(struct tegracam_device *tc_dev, s64 val)
{
	struct camera_common_data *s_data = tc_dev->s_data;
	struct device *dev = tc_dev->dev;
	const struct sensor_mode_properties *mode =
		&(s_data->sensor_props.sensor_modes[s_data->mode_prop_idx]);
	imx268_reg reg_list[2];
	int err = 0;
	s16 gain;
	int i;

	if (val < mode->control_properties.min_gain_val)
		val = mode->control_properties.min_gain_val;
	else if (val > mode->control_properties.max_gain_val)
		val = mode->control_properties.max_gain_val;

	/* translate value (from normalized analog gain) */
	gain = (s16)((512 * mode->control_properties.gain_factor) / val);
	gain = 512 - gain;

	if (gain < IMX268_MIN_ANALOG_GAIN)
		gain = IMX268_MIN_ANALOG_GAIN;
	else if (gain > IMX268_MAX_ANALOG_GAIN)
		gain = IMX268_MAX_ANALOG_GAIN;

	dev_dbg(dev, "%s: val: %lld [times], gain: %d\n", __func__, val, gain);

	imx268_get_gain_regs(reg_list, gain);

	for (i = 0; i < 2; i++) {
		err = imx268_write_reg(s_data, reg_list[i].addr,
			reg_list[i].val);
		if (err) {
			dev_dbg(dev, "%s: gain control error\n", __func__);
			return err;
		}
	}

	return err;
}

static int imx268_set_frame_rate(struct tegracam_device *tc_dev, s64 val)
{
	struct camera_common_data *s_data = tc_dev->s_data;
	struct imx268 *priv = (struct imx268 *)tc_dev->priv;
	struct device *dev = tc_dev->dev;
	const struct sensor_mode_properties *mode =
		&(s_data->sensor_props.sensor_modes[s_data->mode_prop_idx]);
	imx268_reg reg_list[2];
	int err = 0;
	u32 frame_length;
	int i;

	frame_length = (u32)(mode->signal_properties.pixel_clock.val *
		(u64)mode->control_properties.framerate_factor /
		mode->image_properties.line_length / val);

	dev_dbg(dev,
		"%s: val: %llde-6 [fps], frame_length: %u [lines/frame]\n",
		__func__, val, frame_length);

	imx268_get_frame_length_regs(reg_list, frame_length);

	for (i = 0; i < 2; i++) {
		err = imx268_write_reg(s_data, reg_list[i].addr,
			reg_list[i].val);
		if (err) {
			dev_dbg(dev,
				"%s: frame_length control error\n", __func__);
			return err;
		}
	}

	priv->frame_length = frame_length;

	return 0;
}

static int imx268_set_exposure(struct tegracam_device *tc_dev, s64 val)
{
	struct camera_common_data *s_data = tc_dev->s_data;
	struct imx268 *priv = (struct imx268 *)tc_dev->priv;
	struct device *dev = tc_dev->dev;
	const struct sensor_mode_properties *mode =
		&(s_data->sensor_props.sensor_modes[s_data->mode_prop_idx]);
	imx268_reg reg_list[2];
	int err = 0;
	u32 coarse_time;
	s32 max_coarse_time = priv->frame_length - IMX268_MAX_COARSE_DIFF;
	int i;

	coarse_time = (mode->signal_properties.pixel_clock.val *
		val / mode->image_properties.line_length /
		mode->control_properties.exposure_factor) -
		(IMX268_FINE_INTEG_TIME / mode->image_properties.line_length);

	if (coarse_time < IMX268_MIN_COARSE_EXPOSURE)
		coarse_time = IMX268_MIN_COARSE_EXPOSURE;
	else if (coarse_time > max_coarse_time) {
		coarse_time = max_coarse_time;
		dev_dbg(dev, "%s: exposure limited by frame_length: %d " \
			"[lines/frame]\n", __func__, max_coarse_time);
	}

	dev_dbg(dev, "%s: val: %lld [us], coarse_time: %u [lines]\n",
		__func__, val, coarse_time);

	imx268_get_coarse_time_regs(reg_list, coarse_time);

	for (i = 0; i < 2; i++) {
		err = imx268_write_reg(s_data, reg_list[i].addr,
			reg_list[i].val);
		if (err) {
			dev_dbg(dev,
				"%s: coarse_time control error\n", __func__);
			return err;
		}
	}

	return err;
}

static struct tegracam_ctrl_ops imx268_ctrl_ops = {
	.numctrls = ARRAY_SIZE(ctrl_cid_list),
	.ctrl_cid_list = ctrl_cid_list,
	.set_gain = imx268_set_gain,
	.set_exposure = imx268_set_exposure,
	.set_frame_rate = imx268_set_frame_rate,
	.set_group_hold = imx268_set_group_hold,
};

static inline int imx268_power_on(struct camera_common_data *s_data)
{
	int err = 0;
	struct camera_common_power_rail *pw = s_data->power;
	struct camera_common_pdata *pdata = s_data->pdata;
	struct device *dev = s_data->dev;

	dev_dbg(dev, "%s: power on\n", __func__);
	if (pdata && pdata->power_on) {
		err = pdata->power_on(pw);
		if (err)
			dev_err(dev, "%s: power on failed\n", __func__);
		else
			pw->state = SWITCH_ON;
		return err;
	}

	if (pw->reset_gpio)
		gpio_set_value(pw->reset_gpio, 0);

	usleep_range(15, 20);

	if (pw->avdd)
		err = regulator_enable(pw->avdd);
	if (err)
		goto imx268_avdd_fail;

	if (pw->iovdd)
		err = regulator_enable(pw->iovdd);
	if (err)
		goto imx268_iovdd_fail;

	if (pw->dvdd)
		err = regulator_enable(pw->dvdd);
	if (err)
		goto imx268_dvdd_fail;

	usleep_range(5000, 5010);

	if (pw->reset_gpio)
		gpio_set_value(pw->reset_gpio, 1);

	usleep_range(12000, 12010);

	pw->state = SWITCH_ON;

	return 0;

imx268_dvdd_fail:
	regulator_disable(pw->iovdd);

imx268_iovdd_fail:
	regulator_disable(pw->avdd);

imx268_avdd_fail:
	dev_err(dev, "%s: power on failed\n", __func__);

	return err;
}

static int imx268_power_off(struct camera_common_data *s_data)
{
	int err = 0;
	struct camera_common_power_rail *pw = s_data->power;
	struct camera_common_pdata *pdata = s_data->pdata;
	struct device *dev = s_data->dev;

	dev_dbg(dev, "%s: power off\n", __func__);

	if (pdata && pdata->power_off) {
		err = pdata->power_off(pw);
		if (err) {
			dev_err(dev, "%s: power off failed\n", __func__);
			return err;
		}
	} else {
		if (pw->reset_gpio)
			gpio_set_value(pw->reset_gpio, 0);

		usleep_range(15, 20);

		if (pw->avdd)
			regulator_disable(pw->avdd);
		if (pw->iovdd)
			regulator_disable(pw->iovdd);
		if (pw->dvdd)
			regulator_disable(pw->dvdd);
	}

	pw->state = SWITCH_OFF;

	return 0;
}

static int imx268_power_put(struct tegracam_device *tc_dev)
{
	struct camera_common_data *s_data = tc_dev->s_data;
	struct camera_common_power_rail *pw = s_data->power;
	struct camera_common_pdata *pdata = s_data->pdata;

	if (unlikely(!pw))
		return -EFAULT;

	if (likely(pw->avdd))
		regulator_put(pw->avdd);

	if (likely(pw->iovdd))
		regulator_put(pw->iovdd);

	pw->avdd = NULL;
	pw->iovdd = NULL;

	if (pdata && pdata->use_cam_gpio) {
		cam_gpio_deregister(s_data->dev, pw->pwdn_gpio);
	} else {
		gpio_free(pw->pwdn_gpio);
		gpio_free(pw->reset_gpio);
	}

	return 0;
}

static int imx268_power_get(struct tegracam_device *tc_dev)
{
	struct device *dev = tc_dev->dev;
	struct camera_common_data *s_data = tc_dev->s_data;
	struct camera_common_power_rail *pw = s_data->power;
	struct camera_common_pdata *pdata = s_data->pdata;
	const char *mclk_name;
	const char *parentclk_name;
	struct clk *parent;
	int err = 0, ret = 0;

	if (!pdata) {
		dev_err(dev, "pdata missing\n");
		return -EFAULT;
	}

	mclk_name = pdata->mclk_name ? pdata->mclk_name : "cam_mclk1";
	pw->mclk = devm_clk_get(dev, mclk_name);
	if (IS_ERR(pw->mclk)) {
		dev_err(dev, "unable to get clock %s\n", mclk_name);
		return PTR_ERR(pw->mclk);
	}

	parentclk_name = pdata->parentclk_name;
	if (parentclk_name) {
		parent = devm_clk_get(dev, parentclk_name);
		if (IS_ERR(parent)) {
			dev_err(dev, "unable to get parent clock %s",
				parentclk_name);
		} else {
			clk_set_parent(pw->mclk, parent);
		}
	}

	/* analog 2.8v */
	err |= camera_common_regulator_get(dev,
		&pw->avdd, pdata->regulators.avdd);
	/* IO 1.8v */
	err |= camera_common_regulator_get(dev,
		&pw->iovdd, pdata->regulators.iovdd);
	/* dig 1.2v */
	err |= camera_common_regulator_get(dev,
		&pw->dvdd, pdata->regulators.dvdd);

	if (!err)
		pw->reset_gpio = pdata->reset_gpio;

	ret = gpio_request(pw->reset_gpio, "cam_reset_gpio");
	if (ret < 0)
		dev_dbg(dev, "%s can't request reset_gpio %d\n", __func__, ret);

	pw->state = SWITCH_OFF;

	return err;
}

static struct camera_common_pdata *imx268_parse_dt(struct tegracam_device *tc_dev)
{
	struct device *dev = tc_dev->dev;
	struct device_node *np = dev->of_node;
	struct camera_common_pdata *board_priv_pdata;
	const struct of_device_id *match;
	int err = 0;
	struct camera_common_pdata *ret = NULL;
	int gpio;

	if (!np)
		return NULL;

	match = of_match_device(imx268_of_match, dev);
	if (!match) {
		dev_err(dev, "Failed to find matching dt id\n");
		return NULL;
	}

	board_priv_pdata = devm_kzalloc(dev,
		sizeof(*board_priv_pdata), GFP_KERNEL);
	if (!board_priv_pdata)
		return NULL;

	err = of_property_read_string(np, "mclk", &board_priv_pdata->mclk_name);
	if (err)
		dev_err(dev, "mclk not in DT\n");

	gpio = of_get_named_gpio(np, "reset-gpios", 0);
	if (gpio < 0) {
		if (gpio == -EPROBE_DEFER)
			ret = ERR_PTR(-EPROBE_DEFER);
		dev_err(dev, "reset-gpios not found %d\n", err);
		goto error;
	}
	board_priv_pdata->reset_gpio = (unsigned int)gpio;

	err = of_property_read_string(np, "avdd-reg",
		&board_priv_pdata->regulators.avdd);
	if (err) {
		dev_err(dev, "avdd-reg not in DT\n");
		goto error;
	}
	err = of_property_read_string(np, "iovdd-reg",
		&board_priv_pdata->regulators.iovdd);
	if (err) {
		dev_err(dev, "iovdd-reg not in DT\n");
		goto error;
	}
	err = of_property_read_string(np, "dvdd-reg",
		&board_priv_pdata->regulators.dvdd);
	if (err) {
		dev_err(dev, "dvdd-reg not in DT\n");
		goto error;
	}
	board_priv_pdata->has_eeprom =
		of_property_read_bool(np, "has-eeprom");

	return board_priv_pdata;

error:
	devm_kfree(dev, board_priv_pdata);

	return ret;
}

static int imx268_set_mode(struct tegracam_device *tc_dev)
{
	struct imx268 *priv = (struct imx268 *)tegracam_get_privdata(tc_dev);
	struct camera_common_data *s_data = tc_dev->s_data;
	int err;

	err = imx268_write_table(priv, mode_table[IMX268_MODE_COMMON]);
	if (err)
		return err;

	err = imx268_write_table(priv, mode_table[s_data->mode]);
	if (err)
		return err;

	return 0;
}

static int imx268_start_streaming(struct tegracam_device *tc_dev)
{
	struct imx268 *priv = (struct imx268 *)tegracam_get_privdata(tc_dev);
	int err;

	err = imx268_write_table(priv, mode_table[IMX268_MODE_STREAM_START]);
	if (err)
		return err;

	return 0;
}

static int imx268_stop_streaming(struct tegracam_device *tc_dev)
{
	struct imx268 *priv = (struct imx268 *)tegracam_get_privdata(tc_dev);
	int err;

	err = imx268_write_table(priv, mode_table[IMX268_MODE_STREAM_STOP]);
	if (err)
		return err;
	/*
	 * Wait for one frame to make sure sensor is set to
	 * software standby in V-blank
	 *
	 * delay = frame length rows * Tline (10 us)
	 */
	usleep_range(priv->frame_length * 10, priv->frame_length * 10 + 1000);

	return 0;
}

static struct camera_common_sensor_ops imx268_common_ops = {
	.numfrmfmts = ARRAY_SIZE(imx268_frmfmt),
	.frmfmt_table = imx268_frmfmt,
	.power_on = imx268_power_on,
	.power_off = imx268_power_off,
	.write_reg = imx268_write_reg,
	.read_reg = imx268_read_reg,
	.parse_dt = imx268_parse_dt,
	.power_get = imx268_power_get,
	.power_put = imx268_power_put,
	.set_mode = imx268_set_mode,
	.start_streaming = imx268_start_streaming,
	.stop_streaming = imx268_stop_streaming,
};

static int imx268_board_setup(struct imx268 *priv)
{
	int err = 0;
	struct camera_common_data *s_data = priv->s_data;
	struct device *dev = s_data->dev;
	u8 reg_val;

	dev_dbg(dev, "%s++\n", __func__);

	err = camera_common_mclk_enable(s_data);
	if (err) {
		dev_err(dev, "Error %d turning on mclk\n", err);
		return err;
	}

	err = imx268_power_on(s_data);
	if (err) {