-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch.mbox
2898 lines (2883 loc) · 82.7 KB
/
patch.mbox
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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From [email protected] Tue Oct 3 06:31:53 2017
Return-Path: <[email protected]>
Received: from compute1.internal (compute1.nyi.internal [10.202.2.41])
by sloti37d1t30 (Cyrus fastmail-fmjessie45326-15386-git-fastmail-15386) with LMTPA;
Mon, 02 Oct 2017 15:31:53 -0400
X-Cyrus-Session-Id: sloti37d1t30-673186-1506972713-2-3620140764853254799
X-Sieve: CMU Sieve 3.0
X-Spam-known-sender: no
X-Spam-score: 0.0
X-Spam-hits: BAYES_00 -1.9, HEADER_FROM_DIFFERENT_DOMAINS 0.001, RCVD_IN_DNSWL_MED -2.3,
RCVD_IN_SORBS_SPAM 0.5, SPF_PASS -0.001, LANGUAGES en, BAYES_USED global,
SA_VERSION 3.4.0
X-Spam-source: IP='140.211.166.137', Host='smtp4.osuosl.org', Country='US',
FromHeader='com', MailFrom='org'
X-Spam-charsets: cc='UTF-8', plain='us-ascii'
X-Resolved-to: [email protected]
X-Delivered-to: [email protected]
X-Mail-from: [email protected]
Received: from mx4 ([10.202.2.203])
by compute1.internal (LMTPProxy); Mon, 02 Oct 2017 15:31:53 -0400
Received: from mx4.messagingengine.com (localhost [127.0.0.1])
by mailmx.nyi.internal (Postfix) with ESMTP id A9891C86A6
for <[email protected]>; Mon, 2 Oct 2017 15:31:50 -0400 (EDT)
Received: from mx4.messagingengine.com (localhost [127.0.0.1])
by mx4.messagingengine.com (Authentication Milter) with ESMTP
id F31F559CD7C;
Mon, 2 Oct 2017 15:31:50 -0400
Authentication-Results: mx4.messagingengine.com;
dkim=none (no signatures found);
dmarc=none (p=none;has-list-id=yes) header.from=ubuntu.com;
iprev=pass policy.iprev=140.211.166.137 (smtp4.osuosl.org);
spf=pass [email protected] smtp.helo=fraxinus.osuosl.org;
x-google-dkim=fail (message has been altered; 2048-bit rsa key) header.d=1e100.net [email protected] header.b=DTlOjdOY;
x-ptr=fail x-ptr-helo=fraxinus.osuosl.org x-ptr-lookup=smtp4.osuosl.org;
x-tls=pass version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256/256
Received-SPF: pass
(linuxdriverproject.org: 140.211.166.137 is authorized to use '[email protected]' in 'mfrom' identity (mechanism 'mx' matched))
receiver=mx4.messagingengine.com;
identity=mailfrom;
envelope-from="[email protected]";
helo=fraxinus.osuosl.org;
client-ip=140.211.166.137
Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by mx4.messagingengine.com (Postfix) with ESMTPS
for <[email protected]>; Mon, 2 Oct 2017 15:31:50 -0400 (EDT)
Received: from localhost (localhost [127.0.0.1])
by fraxinus.osuosl.org (Postfix) with ESMTP id 634A1870E1;
Mon, 2 Oct 2017 19:31:48 +0000 (UTC)
X-Virus-Scanned: amavisd-new at osuosl.org
Received: from fraxinus.osuosl.org ([127.0.0.1])
by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id C23c2lreCg45; Mon, 2 Oct 2017 19:31:41 +0000 (UTC)
Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34])
by fraxinus.osuosl.org (Postfix) with ESMTP id 133FE87078;
Mon, 2 Oct 2017 19:31:37 +0000 (UTC)
X-Original-To: [email protected]
X-Remote-Delivered-To: [email protected]
Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133])
by ash.osuosl.org (Postfix) with ESMTP id 9322E1C153C
for <[email protected]>; Mon, 2 Oct 2017 19:31:34 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
by hemlock.osuosl.org (Postfix) with ESMTP id 8C84988394
for <[email protected]>; Mon, 2 Oct 2017 19:31:34 +0000 (UTC)
X-Virus-Scanned: amavisd-new at osuosl.org
Received: from hemlock.osuosl.org ([127.0.0.1])
by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 3BkxWOjbmrRB for <[email protected]>;
Mon, 2 Oct 2017 19:31:31 +0000 (UTC)
X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6
Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com
[209.85.128.196])
by hemlock.osuosl.org (Postfix) with ESMTPS id 46ABD88392
for <[email protected]>; Mon, 2 Oct 2017 19:31:30 +0000 (UTC)
Received: by mail-wr0-f196.google.com with SMTP id v38so1484588wrc.4
for <[email protected]>; Mon, 02 Oct 2017 12:31:30 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:from:to:cc:subject:date:message-id;
bh=JKsVB2KS1Ub3708V6C7cK4W6CqTN9BDyuLJlJZQRWK0=;
b=DTlOjdOYS3L7qpShRP2XewOKWQfcgHUHUJIGUwng+RQ1ztKBFvaGYoFnT8yrHTxrWZ
8EosHCwpr4UraNnsezugn8qRaEOdc5J3K3P4MGnIbij/G43PaDrcfiPzEzrdMW7tef/2
N0V24X0rvTtH47IAzK4eArtFHAlBV9mrgoLG0LODcHYctDp5nmJ7nDEtqEQBS6qx6YfL
p7GLSan5P5ioHFy001UDEiSTUGMd77mSA4WG1hrvpOy02WMJO8tMU3v9K11SsXrzWjVl
Yim9eCZlcpVjOOpjltsbkwkr8B1Lx2mWS3SQjIFLjZsXCCaM0TK47Wrpdl1e54zKBQgy
vq9Q==
X-Gm-Message-State: AHPjjUjc175ZYGT+5hdLw0O9FcV6KgRfBu8ZroonMYfZh0+piww135bD
bRw9vGrAB7ctftpYF7Ld7j0=
X-Google-Smtp-Source: AOwi7QBPPEM/d/x5kJGy0vH0LwwV5oNV8eg3kC1ah8EeFQoIipOzZilfk8Lf8EwfjM77iGoUO1bbtA==
X-Received: by 10.223.144.71 with SMTP id h65mr15979741wrh.41.1506972687732;
Mon, 02 Oct 2017 12:31:27 -0700 (PDT)
Received: from localhost.localdomain ([5.102.12.85])
by smtp.gmail.com with ESMTPSA id o11sm9090543wrg.5.2017.10.02.12.31.25
(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
Mon, 02 Oct 2017 12:31:26 -0700 (PDT)
From: Devid Antonio Filoni <[email protected]>
To:
Subject: [PATCH v3] staging: atomisp: add a driver for ov5648 camera sensor
Date: Mon, 2 Oct 2017 21:30:14 +0200
Message-Id: <[email protected]>
X-Mailer: git-send-email 2.7.4
Greg Kroah-Hartman <[email protected]>, [email protected],
Hans Verkuil <[email protected]>, [email protected],
=?UTF-8?q?J=C3=A9r=C3=A9my=20Lefaure?= <[email protected]>,
Mauro Carvalho Chehab <[email protected]>, Alan Cox <[email protected]>
X-BeenThere: [email protected]
X-Mailman-Version: 2.1.18-1
Precedence: list
List-Id: Linux Driver Project Developer List
<driverdev-devel.linuxdriverproject.org>
List-Unsubscribe: <http://driverdev.linuxdriverproject.org/mailman/options/driverdev-devel>,
<mailto:[email protected]?subject=unsubscribe>
List-Archive: <http://driverdev.linuxdriverproject.org/pipermail/driverdev-devel/>
List-Post: <mailto:[email protected]>
List-Help: <mailto:[email protected]?subject=help>
List-Subscribe: <http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel>,
<mailto:[email protected]?subject=subscribe>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: [email protected]
Sender: "devel" <[email protected]>
X-getmail-retrieved-from-mailbox: INBOX
Status: RO
Content-Length: 77542
The ov5648 5-megapixel camera sensor from OmniVision supports up to 2592x1944
resolution and MIPI CSI-2 interface. Output format is raw sRGB/Bayer with
10 bits per colour (SGRBG10_1X10).
This patch is a port of ov5648 driver after applying following
01org/ProductionKernelQuilts patches:
- 0004-ov2680-ov5648-Fork-lift-source-from-CTS.patch
- 0005-ov2680-ov5648-gminification.patch
- 0006-ov5648-Focus-support.patch
- 0007-Fix-resolution-issues-on-rear-camera.patch
- 0008-ov2680-ov5648-Enabled-the-set_exposure-functions.patch
- 0010-IRDA-cameras-mode-list-cleanup-unification.patch
- 0012-ov5648-Add-1296x972-binned-mode.patch
- 0014-ov5648-Adapt-to-Atomisp2-Gmin-VCM-framework.patch
- 0015-dw9714-Gmin-Atomisp-specific-VCM-driver.patch
- 0017-ov5648-Fix-deadlock-on-I2C-error.patch
- 0018-gc2155-Fix-deadlock-on-error.patch
- 0019-ov5648-Add-1280x960-binned-mode.patch
- 0020-ov5648-Make-1280x960-as-default-video-resolution.patch
- 0021-MALATA-Fix-testCameraToSurfaceTextureMetadata-CTS.patch
- 0023-OV5648-Added-5MP-video-resolution.patch
New changes introduced during the port:
- Rename entity types to entity functions
- Replace v4l2_subdev_fh by v4l2_subdev_pad_config
- Make use of media_bus_format enum
- Rename media_entity_init function to media_entity_pads_init
- Replace try_mbus_fmt by set_fmt
- Replace s_mbus_fmt by set_fmt
- Replace g_mbus_fmt by get_fmt
- Use s_ctrl/g_volatile_ctrl instead of ctrl core ops
- Update gmin platform API path
- Constify acpi_device_id
- Add "INT5648" value to acpi_device_id
- Fix some checkpatch errors and warnings
- Remove FSF's mailing address from the sample GPL notice
"INT5648" ACPI device id can be found in following production hardware:
BIOS Information
Vendor: LENOVO
Version: 1HCN40WW
Release Date: 11/04/2016
...
BIOS Revision: 0.40
Firmware Revision: 0.0
...
System Information
Manufacturer: LENOVO
Product Name: 80SG
Version: MIIX 310-10ICR
...
SKU Number: LENOVO_MT_80SG_BU_idea_FM_MIIX 310-10ICR
Family: IDEAPAD
...
Device DSDT excerpt:
Device (CA00)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "INT5648") // _HID: Hardware ID
Name (_CID, "INT5648") // _CID: Compatible ID
Name (_SUB, "INTL0000") // _SUB: Subsystem ID
Name (_DDN, "ov5648") // _DDN: DOS Device Name
...
I was not able to properly test this patch on my Lenovo Miix 310 due to other
issues with atomisp, the output is the same as ov2680 driver (OVTI2680)
which is very similar.
Signed-off-by: Devid Antonio Filoni <[email protected]>
---
Changes in v2:
- Fix indentation
- Add atomisp prefix to Kconfig option
Changes in v3:
- Use module_i2c_driver() macro
- Switch i2c drivers to use ->probe_new()
- Remove unused ->gpio_ctrl() callback
- Remove unused ->power_ctrl() callback
- Remove unneeded header inclusions
- Sort header inclusions alphabetically
- Replace kzalloc with devm_kzalloc
- Remove "XXOV5648" acpi_device_id, we don't know if it's used in any production device
- Use reverse XMAS tree declarations
- Fix comments style
- Remove __func__ from all dev_{dbg,info,err}() calls
- Add missing new line chars in all dev_{dbg,info,err}() calls
- Remove useless dev_{dbg,err}() calls
- Fix all checkpatch.pl issues
drivers/staging/media/atomisp/i2c/Kconfig | 12 +
drivers/staging/media/atomisp/i2c/Makefile | 1 +
drivers/staging/media/atomisp/i2c/atomisp-ov5648.c | 1787 ++++++++++++++++++++++++++++
drivers/staging/media/atomisp/i2c/ov5648.h | 828 +++++++++++++
4 files changed, 2628 insertions(+)
create mode 100644 drivers/staging/media/atomisp/i2c/atomisp-ov5648.c
create mode 100644 drivers/staging/media/atomisp/i2c/ov5648.h
diff --git a/drivers/staging/media/atomisp/i2c/Kconfig b/drivers/staging/media/atomisp/i2c/Kconfig
index a76f17d..6bd849d 100644
--- a/drivers/staging/media/atomisp/i2c/Kconfig
+++ b/drivers/staging/media/atomisp/i2c/Kconfig
@@ -83,6 +83,18 @@ config VIDEO_ATOMISP_OV2680
It currently only works with the atomisp driver.
+config VIDEO_ATOMISP_OV5648
+ tristate "Omnivision OV5648 sensor support"
+ depends on ACPI
+ depends on I2C && VIDEO_V4L2
+ ---help---
+ This is a Video4Linux2 sensor-level driver for the Omnivision
+ OV5648 raw camera.
+
+ ov5648 is a 5M raw sensor.
+
+ It currently only works with the atomisp driver.
+
#
# Kconfig for flash drivers
#
diff --git a/drivers/staging/media/atomisp/i2c/Makefile b/drivers/staging/media/atomisp/i2c/Makefile
index f8b3505..bb9cf7b 100644
--- a/drivers/staging/media/atomisp/i2c/Makefile
+++ b/drivers/staging/media/atomisp/i2c/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_VIDEO_ATOMISP_MT9M114) += atomisp-mt9m114.o
obj-$(CONFIG_VIDEO_ATOMISP_GC2235) += atomisp-gc2235.o
obj-$(CONFIG_VIDEO_ATOMISP_OV2722) += atomisp-ov2722.o
obj-$(CONFIG_VIDEO_ATOMISP_OV2680) += atomisp-ov2680.o
+obj-$(CONFIG_VIDEO_ATOMISP_OV5648) += atomisp-ov5648.o
obj-$(CONFIG_VIDEO_ATOMISP_GC0310) += atomisp-gc0310.o
obj-$(CONFIG_VIDEO_ATOMISP_MSRLIST_HELPER) += atomisp-libmsrlisthelper.o
diff --git a/drivers/staging/media/atomisp/i2c/atomisp-ov5648.c b/drivers/staging/media/atomisp/i2c/atomisp-ov5648.c
new file mode 100644
index 0000000..15cb64b
--- /dev/null
+++ b/drivers/staging/media/atomisp/i2c/atomisp-ov5648.c
@@ -0,0 +1,1787 @@
+/*
+ * Support for OmniVision OV5648 5M camera sensor.
+ * Based on OmniVision OV2722 driver.
+ *
+ * Copyright (c) 2013 Intel Corporation. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ */
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/i2c.h>
+#include <linux/io.h>
+#include <linux/kmod.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/types.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include "../include/linux/atomisp_gmin_platform.h"
+
+#include "ov5648.h"
+
+#define OV5648_DEBUG_EN 0
+
+#define H_FLIP_DEFAULT 1
+#define V_FLIP_DEFAULT 0
+static int h_flag = H_FLIP_DEFAULT;
+static int v_flag = V_FLIP_DEFAULT;
+
+static int ov5648_read_reg(struct i2c_client *client,
+ u16 data_length, u16 reg, u16 *val)
+{
+ struct i2c_msg msg[2];
+ unsigned char data[6];
+ int err;
+
+ if (data_length != OV5648_8BIT && data_length != OV5648_16BIT &&
+ data_length != OV5648_32BIT) {
+ dev_err(&client->dev, "read_reg error, invalid data length %x\n",
+ data_length);
+ return -EINVAL;
+ }
+
+ memset(msg, 0, sizeof(msg));
+
+ msg[0].addr = client->addr;
+ msg[0].flags = 0;
+ msg[0].len = I2C_MSG_LENGTH;
+ msg[0].buf = data;
+
+ /* High byte goes out first */
+ data[0] = (u8)(reg >> 8);
+ data[1] = (u8)(reg & 0xff);
+
+ msg[1].addr = client->addr;
+ msg[1].len = data_length;
+ msg[1].flags = I2C_M_RD;
+ msg[1].buf = data;
+
+ err = i2c_transfer(client->adapter, msg, 2);
+ if (err != 2) {
+ dev_err(&client->dev,
+ "read from offset 0x%x, error: %d\n", reg, err);
+ return err < 0 ? err : -EIO;
+ }
+
+ *val = 0;
+ /* high byte comes first */
+ if (data_length == OV5648_8BIT)
+ *val = (u8)data[0];
+ else if (data_length == OV5648_16BIT)
+ *val = be16_to_cpu(*(u16 *)&data[0]);
+ else
+ *val = be32_to_cpu(*(u32 *)&data[0]);
+
+ return 0;
+}
+
+static int ov5648_i2c_write(struct i2c_client *client, u16 len, u8 *data)
+{
+ const int num_msg = 1;
+ struct i2c_msg msg;
+ int ret;
+
+ msg.addr = client->addr;
+ msg.flags = 0;
+ msg.len = len;
+ msg.buf = data;
+ ret = i2c_transfer(client->adapter, &msg, 1);
+
+ return ret == num_msg ? 0 : -EIO;
+}
+
+static int ov5648_write_reg(struct i2c_client *client, u16 data_length,
+ u16 reg, u16 val)
+{
+ const u16 len = data_length + sizeof(u16); /* 16-bit address + data */
+ unsigned char data[4] = {0};
+ u16 *wreg = (u16 *)data;
+ int ret;
+
+ if (data_length != OV5648_8BIT && data_length != OV5648_16BIT &&
+ data_length != OV5648_32BIT) {
+ dev_err(&client->dev,
+ "write_reg error, invalid data_length %x\n",
+ data_length);
+ return -EINVAL;
+ }
+
+ /* High byte goes out first */
+ *wreg = cpu_to_be16(reg);
+
+ if (data_length == OV5648_8BIT) {
+ data[2] = (u8)(val);
+ } else if (data_length == OV5648_16BIT) {
+ u16 *wdata = (u16 *)&data[2];
+ *wdata = cpu_to_be16(val);
+ } else {
+ u32 *wdata = (u32 *)&data[2];
+ *wdata = cpu_to_be32(val);
+ }
+
+ ret = ov5648_i2c_write(client, len, data);
+ if (ret)
+ dev_err(&client->dev,
+ "write error: wrote 0x%x to offset 0x%x, error: %d\n",
+ val, reg, ret);
+
+ return ret;
+}
+
+/*
+ * ov5648_write_reg_array - Initializes a list of OV5648 registers
+ * @client: i2c driver client structure
+ * @reglist: list of registers to be written
+ *
+ * This function initializes a list of registers. When consecutive addresses
+ * are found in a row on the list, this function creates a buffer and sends
+ * consecutive data in a single i2c_transfer().
+ *
+ * __ov5648_flush_reg_array, __ov5648_buf_reg_array() and
+ * __ov5648_write_reg_is_consecutive() are internal functions to
+ * ov5648_write_reg_array_fast() and should be not used anywhere else.
+ *
+ */
+static int __ov5648_flush_reg_array(struct i2c_client *client,
+ struct ov5648_write_ctrl *ctrl)
+{
+ u16 size;
+
+ if (ctrl->index == 0)
+ return 0;
+
+ size = sizeof(u16) + ctrl->index;
+ ctrl->buffer.addr = cpu_to_be16(ctrl->buffer.addr);
+ ctrl->index = 0;
+
+ return ov5648_i2c_write(client, size, (u8 *)&ctrl->buffer);
+}
+
+static int __ov5648_buf_reg_array(struct i2c_client *client,
+ struct ov5648_write_ctrl *ctrl,
+ const struct ov5648_reg *next)
+{
+ u16 *data16;
+ int size;
+
+ switch (next->type) {
+ case OV5648_8BIT:
+ size = 1;
+ ctrl->buffer.data[ctrl->index] = (u8)next->val;
+ break;
+ case OV5648_16BIT:
+ size = 2;
+ data16 = (u16 *)&ctrl->buffer.data[ctrl->index];
+ *data16 = cpu_to_be16((u16)next->val);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ /* When first item is added, we need to store its starting address */
+ if (ctrl->index == 0)
+ ctrl->buffer.addr = next->reg;
+
+ ctrl->index += size;
+
+ /*
+ * Buffer cannot guarantee free space for u32? Better flush it to avoid
+ * possible lack of memory for next item.
+ */
+ if (ctrl->index + sizeof(u16) >= OV5648_MAX_WRITE_BUF_SIZE)
+ return __ov5648_flush_reg_array(client, ctrl);
+
+ return 0;
+}
+
+static int __ov5648_write_reg_is_consecutive(struct i2c_client *client,
+ struct ov5648_write_ctrl *ctrl,
+ const struct ov5648_reg *next)
+{
+ if (ctrl->index == 0)
+ return 1;
+
+ return ctrl->buffer.addr + ctrl->index == next->reg;
+}
+
+static int ov5648_write_reg_array(struct i2c_client *client,
+ const struct ov5648_reg *reglist)
+{
+ const struct ov5648_reg *next;
+ struct ov5648_write_ctrl ctrl;
+ int err;
+
+ ctrl.index = 0;
+ for (next = reglist; next->type != OV5648_TOK_TERM; next++) {
+ switch (next->type & OV5648_TOK_MASK) {
+ case OV5648_TOK_DELAY:
+ err = __ov5648_flush_reg_array(client, &ctrl);
+ if (err)
+ return err;
+ msleep(next->val);
+ break;
+ default:
+ /*
+ * If next address is not consecutive, data needs to be
+ * flushed before proceed.
+ */
+ if (!__ov5648_write_reg_is_consecutive(client, &ctrl,
+ next)) {
+ err = __ov5648_flush_reg_array(client, &ctrl);
+ if (err)
+ return err;
+ }
+ err = __ov5648_buf_reg_array(client, &ctrl, next);
+ if (err) {
+ dev_err(&client->dev, "write error: %d, aborted\n", err);
+ return err;
+ }
+ break;
+ }
+ }
+
+ return __ov5648_flush_reg_array(client, &ctrl);
+}
+
+static int ov5648_g_focal(struct v4l2_subdev *sd, s32 *val)
+{
+ *val = (OV5648_FOCAL_LENGTH_NUM << 16) | OV5648_FOCAL_LENGTH_DEM;
+ return 0;
+}
+
+static int ov5648_g_fnumber(struct v4l2_subdev *sd, s32 *val)
+{
+ *val = (OV5648_F_NUMBER_DEFAULT_NUM << 16) | OV5648_F_NUMBER_DEM;
+ return 0;
+}
+
+static int ov5648_g_fnumber_range(struct v4l2_subdev *sd, s32 *val)
+{
+ *val = (OV5648_F_NUMBER_DEFAULT_NUM << 24) |
+ (OV5648_F_NUMBER_DEM << 16) |
+ (OV5648_F_NUMBER_DEFAULT_NUM << 8) | OV5648_F_NUMBER_DEM;
+ return 0;
+}
+
+static int ov5648_g_bin_factor_x(struct v4l2_subdev *sd, s32 *val)
+{
+ struct ov5648_device *dev = to_ov5648_sensor(sd);
+
+ *val = ov5648_res[dev->fmt_idx].bin_factor_x;
+
+ return 0;
+}
+
+static int ov5648_g_bin_factor_y(struct v4l2_subdev *sd, s32 *val)
+{
+ struct ov5648_device *dev = to_ov5648_sensor(sd);
+
+ *val = ov5648_res[dev->fmt_idx].bin_factor_y;
+
+ return 0;
+}
+
+static int ov5648_get_intg_factor(struct i2c_client *client,
+ struct camera_mipi_info *info,
+ const struct ov5648_resolution *res)
+{
+ struct v4l2_subdev *sd = i2c_get_clientdata(client);
+ struct atomisp_sensor_mode_data *buf = &info->data;
+ struct ov5648_device *dev = to_ov5648_sensor(sd);
+ unsigned int pix_clk_freq_hz;
+ u16 reg_val;
+ int ret;
+
+ if (!info)
+ return -EINVAL;
+
+ pix_clk_freq_hz = res->pix_clk_freq * 1000000;
+
+ dev->vt_pix_clk_freq_mhz = pix_clk_freq_hz;
+ buf->vt_pix_clk_freq_mhz = pix_clk_freq_hz;
+
+ buf->coarse_integration_time_min = OV5648_COARSE_INTG_TIME_MIN;
+ buf->coarse_integration_time_max_margin =
+ OV5648_COARSE_INTG_TIME_MAX_MARGIN;
+
+ buf->fine_integration_time_min = OV5648_FINE_INTG_TIME_MIN;
+ buf->fine_integration_time_max_margin =
+ OV5648_FINE_INTG_TIME_MAX_MARGIN;
+
+ buf->fine_integration_time_def = OV5648_FINE_INTG_TIME_MIN;
+ buf->frame_length_lines = res->lines_per_frame;
+ buf->line_length_pck = res->pixels_per_line;
+ buf->read_mode = res->bin_mode;
+
+ ret = ov5648_read_reg(client, OV5648_16BIT,
+ OV5648_HORIZONTAL_START_H, ®_val);
+ if (ret)
+ return ret;
+ buf->crop_horizontal_start = reg_val;
+
+ ret = ov5648_read_reg(client, OV5648_16BIT,
+ OV5648_VERTICAL_START_H, ®_val);
+ if (ret)
+ return ret;
+ buf->crop_vertical_start = reg_val;
+
+ ret = ov5648_read_reg(client, OV5648_16BIT,
+ OV5648_HORIZONTAL_END_H, ®_val);
+ if (ret)
+ return ret;
+ buf->crop_horizontal_end = reg_val;
+
+ ret = ov5648_read_reg(client, OV5648_16BIT,
+ OV5648_VERTICAL_END_H, ®_val);
+ if (ret)
+ return ret;
+ buf->crop_vertical_end = reg_val;
+
+ ret = ov5648_read_reg(client, OV5648_16BIT,
+ OV5648_HORIZONTAL_OUTPUT_SIZE_H, ®_val);
+ if (ret)
+ return ret;
+ buf->output_width = reg_val;
+
+ ret = ov5648_read_reg(client, OV5648_16BIT,
+ OV5648_VERTICAL_OUTPUT_SIZE_H, ®_val);
+ if (ret)
+ return ret;
+ buf->output_height = reg_val;
+
+ buf->binning_factor_x = res->bin_factor_x ?
+ res->bin_factor_x : 1;
+ buf->binning_factor_y = res->bin_factor_y ?
+ res->bin_factor_y : 1;
+ return 0;
+}
+
+static long __ov5648_set_exposure(struct v4l2_subdev *sd, int coarse_itg,
+ int gain, int digitgain)
+
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct ov5648_device *dev = to_ov5648_sensor(sd);
+ int ret, exp_val, vts_val, temp;
+ u16 vts, hts;
+
+ if (dev->run_mode == CI_MODE_VIDEO)
+ ov5648_res = ov5648_res_video;
+ else if (dev->run_mode == CI_MODE_STILL_CAPTURE)
+ ov5648_res = ov5648_res_still;
+ else
+ ov5648_res = ov5648_res_preview;
+
+ hts = ov5648_res[dev->fmt_idx].pixels_per_line;
+ vts = ov5648_res[dev->fmt_idx].lines_per_frame;
+
+ /* Group hold */
+ ret = ov5648_write_reg(client, OV5648_8BIT,
+ OV5648_GROUP_ACCESS, 0x00);
+ if (ret)
+ return ret;
+
+ /* Increase the VTS to match exposure + 4 */
+ if (coarse_itg + OV5648_INTEGRATION_TIME_MARGIN > vts)
+ vts_val = coarse_itg + OV5648_INTEGRATION_TIME_MARGIN;
+ else
+ vts_val = vts;
+ {
+ ret = ov5648_write_reg(client, OV5648_8BIT,
+ OV5648_TIMING_VTS_H,
+ (vts_val >> 8) & 0xFF);
+ if (ret)
+ return ret;
+ ret = ov5648_write_reg(client, OV5648_8BIT,
+ OV5648_TIMING_VTS_L,
+ vts_val & 0xFF);
+ if (ret)
+ return ret;
+ }
+
+ /* Set exposure. Lower four bit should be 0 */
+ exp_val = coarse_itg << 4;
+
+ ret = ov5648_write_reg(client, OV5648_8BIT,
+ OV5648_EXPOSURE_L, exp_val & 0xFF);
+ if (ret)
+ return ret;
+
+ ret = ov5648_write_reg(client, OV5648_8BIT,
+ OV5648_EXPOSURE_M, (exp_val >> 8) & 0xFF);
+ if (ret)
+ return ret;
+
+ ret = ov5648_write_reg(client, OV5648_8BIT,
+ OV5648_EXPOSURE_H, (exp_val >> 16) & 0x0F);
+ if (ret)
+ return ret;
+
+ /* Digital gain */
+ if (digitgain != dev->pre_digitgain) {
+ dev->pre_digitgain = digitgain;
+ temp = digitgain * dev->current_otp.R_gain >> 10;
+ if (temp >= 0x400) {
+ ret = ov5648_write_reg(client, OV5648_16BIT,
+ OV5648_MWB_RED_GAIN_H, temp);
+ if (ret)
+ return ret;
+ }
+
+ temp = digitgain * dev->current_otp.G_gain >> 10;
+ if (temp >= 0x400) {
+ ret = ov5648_write_reg(client, OV5648_16BIT,
+ OV5648_MWB_GREEN_GAIN_H, temp);
+ if (ret)
+ return ret;
+ }
+
+ temp = digitgain * dev->current_otp.B_gain >> 10;
+ if (temp >= 0x400) {
+ ret = ov5648_write_reg(client, OV5648_16BIT,
+ OV5648_MWB_BLUE_GAIN_H, temp);
+ if (ret)
+ return ret;
+ }
+ }
+
+ /* Analog gain */
+ ret = ov5648_write_reg(client, OV5648_8BIT,
+ OV5648_AGC_L, gain & 0xff);
+ if (ret)
+ return ret;
+
+ ret = ov5648_write_reg(client, OV5648_8BIT,
+ OV5648_AGC_H, (gain >> 8) & 0xff);
+ if (ret)
+ return ret;
+
+ /* End group */
+ ret = ov5648_write_reg(client, OV5648_8BIT,
+ OV5648_GROUP_ACCESS, 0x10);
+ if (ret)
+ return ret;
+
+ /* Delay launch group */
+ ret = ov5648_write_reg(client, OV5648_8BIT,
+ OV5648_GROUP_ACCESS, 0xa0);
+ if (ret)
+ return ret;
+
+ return ret;
+}
+
+static int ov5648_set_exposure(struct v4l2_subdev *sd, int exposure,
+ int gain, int digitgain)
+{
+ struct ov5648_device *dev = to_ov5648_sensor(sd);
+ int ret;
+
+ mutex_lock(&dev->input_lock);
+ ret = __ov5648_set_exposure(sd, exposure, gain, digitgain);
+ mutex_unlock(&dev->input_lock);
+
+ return ret;
+}
+
+static long ov5648_s_exposure(struct v4l2_subdev *sd,
+ struct atomisp_exposure *exposure)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ int exp = exposure->integration_time[0];
+ int digitgain = exposure->gain[1];
+ int gain = exposure->gain[0];
+
+ /* We should not accept the invalid value below */
+ if (gain == 0) {
+ dev_err(&client->dev, "invalid gain value\n");
+ return -EINVAL;
+ }
+
+ return ov5648_set_exposure(sd, exp, gain, digitgain);
+}
+
+static long ov5648_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
+{
+ switch (cmd) {
+ case ATOMISP_IOC_S_EXPOSURE:
+ return ov5648_s_exposure(sd, arg);
+ default:
+ return -EINVAL;
+ }
+ return 0;
+}
+
+/*
+ * This returns the exposure time being used. This should only be used
+ * for filling in EXIF data, not for actual image processing.
+ */
+static int ov5648_q_exposure(struct v4l2_subdev *sd, s32 *value)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ u16 reg_v, reg_v2;
+ int ret;
+
+ ret = ov5648_read_reg(client, OV5648_8BIT,
+ OV5648_EXPOSURE_L, ®_v);
+ if (ret)
+ return ret;
+
+ ret = ov5648_read_reg(client, OV5648_8BIT,
+ OV5648_EXPOSURE_M, ®_v2);
+ if (ret)
+ return ret;
+
+ reg_v += reg_v2 << 8;
+ ret = ov5648_read_reg(client, OV5648_8BIT,
+ OV5648_EXPOSURE_H, ®_v2);
+ if (ret)
+ return ret;
+
+ *value = reg_v + (((u32)reg_v2 << 16));
+ return ret;
+}
+
+static int ov5648_vcm_power_up(struct v4l2_subdev *sd)
+{
+ struct ov5648_device *dev = to_ov5648_sensor(sd);
+ struct camera_sensor_platform_data *pdata = dev->platform_data;
+ struct camera_vcm_control *vcm;
+
+ if (!dev->vcm_driver)
+ if (pdata && pdata->get_vcm_ctrl)
+ dev->vcm_driver =
+ pdata->get_vcm_ctrl(&dev->sd,
+ dev->camera_module);
+
+ vcm = dev->vcm_driver;
+ if (vcm && vcm->ops && vcm->ops->power_up)
+ return vcm->ops->power_up(sd, vcm);
+
+ return 0;
+}
+
+static int ov5648_vcm_power_down(struct v4l2_subdev *sd)
+{
+ struct ov5648_device *dev = to_ov5648_sensor(sd);
+ struct camera_vcm_control *vcm = dev->vcm_driver;
+
+ if (vcm && vcm->ops && vcm->ops->power_down)
+ return vcm->ops->power_down(sd, vcm);
+
+ return 0;
+}
+
+static int ov5648_v_flip(struct v4l2_subdev *sd, s32 value)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ int ret;
+ u16 val;
+
+ ret = ov5648_read_reg(client, OV5648_8BIT, OV5648_VFLIP_REG, &val);
+ if (ret)
+ return ret;
+
+ if (value)
+ val |= OV5648_VFLIP_VALUE;
+ else
+ val &= ~OV5648_VFLIP_VALUE;
+ ret = ov5648_write_reg(client, OV5648_8BIT,
+ OV5648_VFLIP_REG, val);
+ return ret;
+}
+
+static int ov5648_h_flip(struct v4l2_subdev *sd, s32 value)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ int ret;
+ u16 val;
+
+ ret = ov5648_read_reg(client, OV5648_8BIT, OV5648_HFLIP_REG, &val);
+ if (ret)
+ return ret;
+
+ if (value)
+ val |= OV5648_HFLIP_VALUE;
+ else
+ val &= ~OV5648_HFLIP_VALUE;
+ ret = ov5648_write_reg(client, OV5648_8BIT,
+ OV5648_HFLIP_REG, val);
+ return ret;
+}
+
+static int ov5648_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+ struct ov5648_device *dev = container_of(ctrl->handler,
+ struct ov5648_device, ctrl_handler);
+ int ret;
+
+ switch (ctrl->id) {
+ case V4L2_CID_VFLIP:
+ ret = ov5648_v_flip(&dev->sd, ctrl->val);
+ break;
+ case V4L2_CID_HFLIP:
+ ret = ov5648_h_flip(&dev->sd, ctrl->val);
+ break;
+ default:
+ ret = -EINVAL;
+ }
+ return ret;
+}
+
+static int ov5648_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
+{
+ struct ov5648_device *dev = container_of(ctrl->handler,
+ struct ov5648_device, ctrl_handler);
+ int ret;
+
+ switch (ctrl->id) {
+ case V4L2_CID_EXPOSURE_ABSOLUTE:
+ ret = ov5648_q_exposure(&dev->sd, &ctrl->val);
+ break;
+ case V4L2_CID_FOCAL_ABSOLUTE:
+ ret = ov5648_g_focal(&dev->sd, &ctrl->val);
+ break;
+ case V4L2_CID_FNUMBER_ABSOLUTE:
+ ret = ov5648_g_fnumber(&dev->sd, &ctrl->val);
+ break;
+ case V4L2_CID_FNUMBER_RANGE:
+ ret = ov5648_g_fnumber_range(&dev->sd, &ctrl->val);
+ break;
+ case V4L2_CID_BIN_FACTOR_HORZ:
+ ret = ov5648_g_bin_factor_x(&dev->sd, &ctrl->val);
+ break;
+ case V4L2_CID_BIN_FACTOR_VERT:
+ ret = ov5648_g_bin_factor_y(&dev->sd, &ctrl->val);
+ break;
+ default:
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
+
+static const struct v4l2_ctrl_ops ctrl_ops = {
+ .s_ctrl = ov5648_s_ctrl,
+ .g_volatile_ctrl = ov5648_g_volatile_ctrl
+};
+
+struct v4l2_ctrl_config ov5648_controls[] = {
+ {
+ .ops = &ctrl_ops,
+ .id = V4L2_CID_EXPOSURE_ABSOLUTE,
+ .type = V4L2_CTRL_TYPE_INTEGER,
+ .name = "exposure",
+ .min = 0x0,
+ .max = 0xffff,
+ .step = 0x01,
+ .def = 0x00,
+ .flags = 0,
+ },
+ {
+ .ops = &ctrl_ops,
+ .id = V4L2_CID_FOCAL_ABSOLUTE,
+ .type = V4L2_CTRL_TYPE_INTEGER,
+ .name = "focal length",
+ .min = OV5648_FOCAL_LENGTH_DEFAULT,
+ .max = OV5648_FOCAL_LENGTH_DEFAULT,
+ .step = 0x01,
+ .def = OV5648_FOCAL_LENGTH_DEFAULT,
+ .flags = 0,
+ },
+ {
+ .ops = &ctrl_ops,
+ .id = V4L2_CID_FNUMBER_ABSOLUTE,
+ .type = V4L2_CTRL_TYPE_INTEGER,
+ .name = "f-number",
+ .min = OV5648_F_NUMBER_DEFAULT,
+ .max = OV5648_F_NUMBER_DEFAULT,
+ .step = 0x01,
+ .def = OV5648_F_NUMBER_DEFAULT,
+ .flags = 0,
+ },
+ {
+ .ops = &ctrl_ops,
+ .id = V4L2_CID_FNUMBER_RANGE,
+ .type = V4L2_CTRL_TYPE_INTEGER,
+ .name = "f-number range",
+ .min = OV5648_F_NUMBER_RANGE,
+ .max = OV5648_F_NUMBER_RANGE,
+ .step = 0x01,
+ .def = OV5648_F_NUMBER_RANGE,
+ .flags = 0,
+ },
+ {
+ .ops = &ctrl_ops,
+ .id = V4L2_CID_BIN_FACTOR_HORZ,
+ .type = V4L2_CTRL_TYPE_INTEGER,