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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
|
From 9b20808b904563590556e0a86e5d6186047ef54f Mon Sep 17 00:00:00 2001
From: Andrey Konovalov <andrey.konovalov@linaro.org>
Date: Fri, 12 Jun 2020 15:53:46 +0200
Subject: [PATCH] media: i2c: imx290: Support for the Sony IMX290
sensor
media: i2c: imx290: set the format before VIDIOC_SUBDEV_G_FMT is called
Commit d46cfdc86c30d5ec768924f0b1e2683c8d20b671 upstream.
With the current driver 'media-ctl -p' issued right after the imx290 driver
is loaded prints:
pad0: Source
[fmt:unknown/0x0]
The format value of zero is due to the current_format field of the imx290
struct not being initialized yet.
As imx290_entity_init_cfg() calls imx290_set_fmt(), the current_mode field
is also initialized, so the line which set current_mode to a default value
in driver's probe() function is no longer needed.
Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
media: i2c: imx290: Add support for 74.25MHz clock
The existing driver only supported a clock of 37.125MHz, but the
sensor also supports 74.25MHz.
Add the relevant register modifications to support this alternate
clock frequency.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Correct range for V4L2_CID_GAIN to 0-238
The datasheet lists the gain as being 0.0 to 72.0dB in 0.3dB steps, which
makes 238 steps total.
Correct the 0-72 range defined in the driver.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Convert HMAX setting into V4L2_CID_HBLANK
Userspace needs to know HBLANK if it is to work out exposure times
and frame rates, therefore convert it to map onto V4L2_CID_HBLANK
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Add support for V4L2_CID_VBLANK
In order to calculate framerate and durations userspace needs
the vertical blanking information. This can be configurable,
and indeed the datasheet lists different values for VBLANK for
the 1080p and 720p modes.
Add the new control, and adopt the datasheet values for each mode.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Add exposure control to the driver.
Adds support for V4L2_CID_EXPOSURE so that userspace can control
the sensor exposure time.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Add H and V flip controls
The sensor supports horizontal and vertical flips, so support them
through V4L2_CID_HFLIP and V4L2_CID_VFLIP.
This sensor does NOT change the Bayer order when changing the
direction of readout, therefore no special handling is required for
that.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: dt-bindings: media: i2c: Add mono version to IMX290 bindings
The IMX290 module is available as either monochrome or colour and
the variant is not detectable at runtime.
Add a new compatible string for the monochrome version.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media : i2c: imx290: Add support for the mono sensor variant.
The IMX290 module is available as either mono or colour (Bayer).
Update the driver so that it can advertise the correct mono
formats instead of the colour ones.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Switch set_hmax to use imx290_write_buffered_reg
imx290_set_hmax was using two independent writes to set up hmax,
when all other multi-register writes were using imx290_write_buffered_reg
which claims the group hold first.
Switch imx290_set_hmax to using imx290_write_buffered_reg too.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Add support for g_selection to report cropping
Userspace needs to know the cropping arrangements for each mode,
so expose this through g_selection.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Set the colorspace fields in the format
The colorspace fields were left untouched in imx290_set_fmt
which lead to a v4l2-compliance failure.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Replace V4L2_CID_GAIN with V4L2_CID_ANALOGUE_GAIN
Most software (including libcamera) requires V4L2_CID_ANALOGUE_GAIN,
not V4L2_CID_GAIN.
The range for the control is 0 to 100 for which the sensor uses only
analogue gain; higher values would involve digital gain which this
control should not apply.
Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
media: i2c: imx290: Fix number of controls in v4l2_ctrl_handler_init
The number is only a hint, but may as well be correct.
Fixes: 471e0029e98aa ("media: i2c: imx290: Convert HMAX setting into V4L2_CID_HBLANK")
Fixes: be0b9b7ad1c27 ("media: i2c: imx290: Add support for V4L2_CID_VBLANK")
Fixes: 8483f0d7599aa ("media: i2c: imx290: Add exposure control to the driver.")
Fixes: 9764f3459c401 ("media: i2c: imx290: Add H and V flip controls")
Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
media: i2c: imx290: Fix up exposure calcuations and ranges
Should now correspond exactly to the datasheet.
Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
media: i2c: imx290: Handle exposure correctly when vblank changes
When vblank changes we must modify the exposure range. Also, with this
sensor, the effective exposure time implicitly changes when vblank
does, so we have to reset it after every vblank update.
Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
media: i2c: imx290: Support 60fps in 2 lane operation
Commit "97589ad61c73 media: i2c: imx290: Add support for 2 data lanes"
added support for running in two lane mode (instead of 4), but
without changing the link frequency that resulted in a max of 30fps.
Commit "98e0500eadb7 media: i2c: imx290: Add configurable link frequency
and pixel rate" then doubled the link frequency when in 2 lane mode,
but didn't undo the correction for running at only 30fps, just extending
horizontal blanking instead.
It also didn't update the CSI timing registers in accordance with the
datasheet.
Remove the 30fps limit on 2 lane by correcting the register config
in accordance with the datasheet for 60fps operation over 2 lanes.
Frame rate control (via V4L2_CID_VBLANK or HBLANK) can still reduce
the frame rate on 2 lanes back to 30fps.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Fix the pixel rate at 148.5Mpix/s
Whilst the datasheet lists the link frequency changing between
1080p and 720p modes, reality is that with the default blanking
we have
(1920 + 280) * (1080 + 45) * 60fps = 148.5MPix/s
and
(1280 + 2020) * (720 + 30) * 60fps = 148.5MPix/s
and this reflects reality whether in 10 or 12 bit readout modes.
How this relates to link frequency is unclear as it differs
from the datasheet, but all exposure and frame rate calcs need
the pixel rate to be correct, so make it so.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Fix clock setup register assignments
When the clock setups were added for the alternate external clocks,
the settings for 2 lane 720p and 4 lane 1080p were transposed.
2 lane 720p still worked, but 4 lane 1080p didn't.
Correct the assignments.
Fixes: 6b0c094a5b58 (media: i2c: imx290: Add support for 74.25MHz clock")
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Add fwnode properties controls
Add call to v4l2_ctrl_new_fwnode_properties to read and
create the fwnode based controls.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Sensor should report RAW color space
Tested on Raspberry Pi running libcamera.
Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
media: i2c: imx290: Add compatible strings for IMX327 and IMX462
IMX327 is the previous generation to IMX290, and supports up to 1080p60
as 10 or 12 bit.
IMX290 adds 1080p120 in 10 bit mode.
IMX462 adds 1080p120 in both 10 and 12 bit modes.
Add compatible strings for all variants.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Updating VBLANK should update exposure in all states
The code to update the range of the exposure control was after a
check that the sensor was powered up. This is incorrect as the
range should be updated under all conditions.
Move the range update code to the correct place.
Fixes: 52d076ea221e "media: i2c: imx290: Handle exposure correctly when vblank changes"
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Drop incorrect comment about pixelrate
commit b5eca6fd4284 ("media: i2c: imx290: Fix the pixel rate at 148.5Mpix/s")
corrected imx290_calc_pixel_rate to always return the correct
pixle rate of 148.5Mpix/s, but didn't remove the comment that said
it relied on some other parameters.
Drop that comment.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Do not reset exposure time from set_fmt
V4L2 controls are meant to be persistent, and only altered if
the values break hardware constraints.
In imx290_set_fmt the CID_VBLANK parameter was being reset to
the mode default, and therefore the maximum exposure value
potentially also changed.
VBLANK is no longer reset, and even if it is, then the set_ctrl
that will be called will alter the range for the exposure
control. Therefore there is no need to reset the exposure time
from set_fmt.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
media: i2c: imx290: Correct min HBLANK.
In the 720p mode the CSI link is run at a lower frequency, and
the minimum HBLANK value has to be increased to avoid generating
more data from the sensor than the link can carry.
Set the minimum based on the mode.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
.../devicetree/bindings/media/i2c/imx290.txt | 7 +-
drivers/media/i2c/imx290.c | 620 ++++++++++++++----
2 files changed, 491 insertions(+), 136 deletions(-)
--- a/Documentation/devicetree/bindings/media/i2c/imx290.txt
+++ b/Documentation/devicetree/bindings/media/i2c/imx290.txt
@@ -1,13 +1,14 @@
* Sony IMX290 1/2.8-Inch CMOS Image Sensor
The Sony IMX290 is a 1/2.8-Inch CMOS Solid-state image sensor with
-Square Pixel for Color Cameras. It is programmable through I2C and 4-wire
-interfaces. The sensor output is available via CMOS logic parallel SDR output,
+Square Pixel for Color or Monochrome Cameras. It is programmable through I2C
+and 4-wire interfaces.
+The sensor output is available via CMOS logic parallel SDR output,
Low voltage LVDS DDR output and CSI-2 serial data output. The CSI-2 bus is the
default. No bindings have been defined for the other busses.
Required Properties:
-- compatible: Should be "sony,imx290"
+- compatible: Should be "sony,imx290", or "sony,imx290-mono"
- reg: I2C bus address of the device
- clocks: Reference to the xclk clock.
- clock-names: Should be "xclk".
--- a/drivers/media/i2c/imx290.c
+++ b/drivers/media/i2c/imx290.c
@@ -1,6 +1,16 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * Sony IMX290 CMOS Image Sensor Driver
+ * Sony IMX462 / IMX290 / IMX327 CMOS Image Sensor Driver
+ *
+ * The IMX462, IMX290,and IMX327 are very similar 1920x1080 1/2.8 CMOS image
+ * sensors.
+ * IMX327 can support up to 60fps with 10 or 12bit readout.
+ * IMX290 adds support for 120fps, but only 10bit and when connected over 4
+ * CSI-2 lanes.
+ * IMX462 adds support for 120fps in both 10 and 12bit readout modes.
+ *
+ * The modules don't appear to have a mechanism to identify whether the mono or
+ * colour variant is connected, therefore it is done via compatible string.
*
* Copyright (C) 2019 FRAMOS GmbH.
*
@@ -13,6 +23,7 @@
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/module.h>
+#include <linux/of_device.h>
#include <linux/pm_runtime.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
@@ -22,15 +33,28 @@
#include <media/v4l2-fwnode.h>
#include <media/v4l2-subdev.h>
+enum imx290_clk_index {
+ CLK_37_125,
+ CLK_74_25,
+};
+
#define IMX290_STANDBY 0x3000
#define IMX290_REGHOLD 0x3001
#define IMX290_XMSTA 0x3002
+#define IMX290_FLIP_WINMODE 0x3007
#define IMX290_FR_FDG_SEL 0x3009
#define IMX290_BLKLEVEL_LOW 0x300a
#define IMX290_BLKLEVEL_HIGH 0x300b
#define IMX290_GAIN 0x3014
+#define IMX290_VMAX_LOW 0x3018
+#define IMX290_VMAX_MAX 0x3fff
#define IMX290_HMAX_LOW 0x301c
#define IMX290_HMAX_HIGH 0x301d
+#define IMX290_HMAX_MAX 0xffff
+
+#define IMX290_EXPOSURE_MIN 1
+#define IMX290_EXPOSURE_STEP 1
+#define IMX290_EXPOSURE_LOW 0x3020
#define IMX290_PGCTRL 0x308c
#define IMX290_PHY_LANE_NUM 0x3407
#define IMX290_CSI_LANE_MODE 0x3443
@@ -39,6 +63,13 @@
#define IMX290_PGCTRL_THRU BIT(1)
#define IMX290_PGCTRL_MODE(n) ((n) << 4)
+#define IMX290_NATIVE_WIDTH 1945U
+#define IMX290_NATIVE_HEIGHT 1109U
+#define IMX290_PIXEL_ARRAY_LEFT 4U
+#define IMX290_PIXEL_ARRAY_TOP 12U
+#define IMX290_PIXEL_ARRAY_WIDTH 1937U
+#define IMX290_PIXEL_ARRAY_HEIGHT 1097U
+
static const char * const imx290_supply_name[] = {
"vdda",
"vddd",
@@ -56,19 +87,31 @@ struct imx290_mode {
u32 width;
u32 height;
u32 hmax;
+ u32 vmax;
u8 link_freq_index;
+ struct v4l2_rect crop;
+
+ const struct imx290_regval *mode_data;
+ u32 mode_data_size;
+ const struct imx290_regval *lane_data;
+ u32 lane_data_size;
- const struct imx290_regval *data;
- u32 data_size;
+
+ /* Clock setup can vary. Index as enum imx290_clk_index */
+ const struct imx290_regval *clk_data[2];
+ u32 clk_size;
};
struct imx290 {
struct device *dev;
struct clk *xclk;
+ u32 xclk_freq;
struct regmap *regmap;
u8 nlanes;
u8 bpp;
+ const struct imx290_pixfmt *formats;
+
struct v4l2_subdev sd;
struct media_pad pad;
struct v4l2_mbus_framefmt current_format;
@@ -80,6 +123,11 @@ struct imx290 {
struct v4l2_ctrl_handler ctrls;
struct v4l2_ctrl *link_freq;
struct v4l2_ctrl *pixel_rate;
+ struct v4l2_ctrl *hblank;
+ struct v4l2_ctrl *vblank;
+ struct v4l2_ctrl *hflip;
+ struct v4l2_ctrl *vflip;
+ struct v4l2_ctrl *exposure;
struct mutex lock;
};
@@ -89,11 +137,18 @@ struct imx290_pixfmt {
u8 bpp;
};
-static const struct imx290_pixfmt imx290_formats[] = {
+#define IMX290_NUM_FORMATS 2
+
+static const struct imx290_pixfmt imx290_colour_formats[IMX290_NUM_FORMATS] = {
{ MEDIA_BUS_FMT_SRGGB10_1X10, 10 },
{ MEDIA_BUS_FMT_SRGGB12_1X12, 12 },
};
+static const struct imx290_pixfmt imx290_mono_formats[IMX290_NUM_FORMATS] = {
+ { MEDIA_BUS_FMT_Y10_1X10, 10 },
+ { MEDIA_BUS_FMT_Y12_1X12, 12 },
+};
+
static const struct regmap_config imx290_regmap_config = {
.reg_bits = 16,
.val_bits = 8,
@@ -113,11 +168,7 @@ static const char * const imx290_test_pa
static const struct imx290_regval imx290_global_init_settings[] = {
{ 0x3007, 0x00 },
- { 0x3018, 0x65 },
- { 0x3019, 0x04 },
{ 0x301a, 0x00 },
- { 0x3444, 0x20 },
- { 0x3445, 0x25 },
{ 0x303a, 0x0c },
{ 0x3040, 0x00 },
{ 0x3041, 0x00 },
@@ -171,8 +222,33 @@ static const struct imx290_regval imx290
{ 0x33b3, 0x04 },
};
-static const struct imx290_regval imx290_1080p_settings[] = {
+static const struct imx290_regval imx290_37_125mhz_clock_1080p[] = {
+ { 0x305c, 0x18 },
+ { 0x305d, 0x03 },
+ { 0x305e, 0x20 },
+ { 0x305f, 0x01 },
+ { 0x315e, 0x1a },
+ { 0x3164, 0x1a },
+ { 0x3444, 0x20 },
+ { 0x3445, 0x25 },
+ { 0x3480, 0x49 },
+};
+
+static const struct imx290_regval imx290_74_250mhz_clock_1080p[] = {
+ { 0x305c, 0x0c },
+ { 0x305d, 0x03 },
+ { 0x305e, 0x10 },
+ { 0x305f, 0x01 },
+ { 0x315e, 0x1b },
+ { 0x3164, 0x1b },
+ { 0x3444, 0x40 },
+ { 0x3445, 0x4a },
+ { 0x3480, 0x92 },
+};
+
+static const struct imx290_regval imx290_1080p_common_settings[] = {
/* mode settings */
+ { IMX290_FR_FDG_SEL, 0x01 },
{ 0x3007, 0x00 },
{ 0x303a, 0x0c },
{ 0x3414, 0x0a },
@@ -182,15 +258,36 @@ static const struct imx290_regval imx290
{ 0x3419, 0x04 },
{ 0x3012, 0x64 },
{ 0x3013, 0x00 },
- { 0x305c, 0x18 },
- { 0x305d, 0x03 },
- { 0x305e, 0x20 },
- { 0x305f, 0x01 },
- { 0x315e, 0x1a },
- { 0x3164, 0x1a },
- { 0x3480, 0x49 },
+};
+
+static const struct imx290_regval imx290_1080p_2lane_settings[] = {
+ { 0x3405, 0x00 },
/* data rate settings */
+ { IMX290_PHY_LANE_NUM, 0x01 },
+ { IMX290_CSI_LANE_MODE, 0x01 },
+ { 0x3446, 0x77 },
+ { 0x3447, 0x00 },
+ { 0x3448, 0x67 },
+ { 0x3449, 0x00 },
+ { 0x344a, 0x47 },
+ { 0x344b, 0x00 },
+ { 0x344c, 0x37 },
+ { 0x344d, 0x00 },
+ { 0x344e, 0x3f },
+ { 0x344f, 0x00 },
+ { 0x3450, 0xff },
+ { 0x3451, 0x00 },
+ { 0x3452, 0x3f },
+ { 0x3453, 0x00 },
+ { 0x3454, 0x37 },
+ { 0x3455, 0x00 },
+};
+
+static const struct imx290_regval imx290_1080p_4lane_settings[] = {
{ 0x3405, 0x10 },
+ /* data rate settings */
+ { IMX290_PHY_LANE_NUM, 0x03 },
+ { IMX290_CSI_LANE_MODE, 0x03 },
{ 0x3446, 0x57 },
{ 0x3447, 0x00 },
{ 0x3448, 0x37 },
@@ -209,8 +306,33 @@ static const struct imx290_regval imx290
{ 0x3455, 0x00 },
};
-static const struct imx290_regval imx290_720p_settings[] = {
+static const struct imx290_regval imx290_37_125mhz_clock_720p[] = {
+ { 0x305c, 0x20 },
+ { 0x305d, 0x00 },
+ { 0x305e, 0x20 },
+ { 0x305f, 0x01 },
+ { 0x315e, 0x1a },
+ { 0x3164, 0x1a },
+ { 0x3444, 0x20 },
+ { 0x3445, 0x25 },
+ { 0x3480, 0x49 },
+};
+
+static const struct imx290_regval imx290_74_250mhz_clock_720p[] = {
+ { 0x305c, 0x10 },
+ { 0x305d, 0x00 },
+ { 0x305e, 0x10 },
+ { 0x305f, 0x01 },
+ { 0x315e, 0x1b },
+ { 0x3164, 0x1b },
+ { 0x3444, 0x40 },
+ { 0x3445, 0x4a },
+ { 0x3480, 0x92 },
+};
+
+static const struct imx290_regval imx290_720p_common_settings[] = {
/* mode settings */
+ { IMX290_FR_FDG_SEL, 0x01 },
{ 0x3007, 0x10 },
{ 0x303a, 0x06 },
{ 0x3414, 0x04 },
@@ -220,15 +342,36 @@ static const struct imx290_regval imx290
{ 0x3419, 0x02 },
{ 0x3012, 0x64 },
{ 0x3013, 0x00 },
- { 0x305c, 0x20 },
- { 0x305d, 0x00 },
- { 0x305e, 0x20 },
- { 0x305f, 0x01 },
- { 0x315e, 0x1a },
- { 0x3164, 0x1a },
- { 0x3480, 0x49 },
+};
+
+static const struct imx290_regval imx290_720p_2lane_settings[] = {
+ { 0x3405, 0x00 },
+ { IMX290_PHY_LANE_NUM, 0x01 },
+ { IMX290_CSI_LANE_MODE, 0x01 },
/* data rate settings */
+ { 0x3446, 0x67 },
+ { 0x3447, 0x00 },
+ { 0x3448, 0x57 },
+ { 0x3449, 0x00 },
+ { 0x344a, 0x2f },
+ { 0x344b, 0x00 },
+ { 0x344c, 0x27 },
+ { 0x344d, 0x00 },
+ { 0x344e, 0x2f },
+ { 0x344f, 0x00 },
+ { 0x3450, 0xbf },
+ { 0x3451, 0x00 },
+ { 0x3452, 0x2f },
+ { 0x3453, 0x00 },
+ { 0x3454, 0x27 },
+ { 0x3455, 0x00 },
+};
+
+static const struct imx290_regval imx290_720p_4lane_settings[] = {
{ 0x3405, 0x10 },
+ { IMX290_PHY_LANE_NUM, 0x03 },
+ { IMX290_CSI_LANE_MODE, 0x03 },
+ /* data rate settings */
{ 0x3446, 0x4f },
{ 0x3447, 0x00 },
{ 0x3448, 0x2f },
@@ -308,18 +451,46 @@ static const struct imx290_mode imx290_m
{
.width = 1920,
.height = 1080,
- .hmax = 0x1130,
+ .hmax = 0x0898,
+ .vmax = 0x0465,
.link_freq_index = FREQ_INDEX_1080P,
- .data = imx290_1080p_settings,
- .data_size = ARRAY_SIZE(imx290_1080p_settings),
+ .crop = {
+ .left = 4 + 8,
+ .top = 12 + 8,
+ .width = 1920,
+ .height = 1080,
+ },
+ .mode_data = imx290_1080p_common_settings,
+ .mode_data_size = ARRAY_SIZE(imx290_1080p_common_settings),
+ .lane_data = imx290_1080p_2lane_settings,
+ .lane_data_size = ARRAY_SIZE(imx290_1080p_2lane_settings),
+ .clk_data = {
+ [CLK_37_125] = imx290_37_125mhz_clock_1080p,
+ [CLK_74_25] = imx290_74_250mhz_clock_1080p,
+ },
+ .clk_size = ARRAY_SIZE(imx290_37_125mhz_clock_1080p),
},
{
.width = 1280,
.height = 720,
- .hmax = 0x19c8,
+ .hmax = 0x0ce4,
+ .vmax = 0x02ee,
.link_freq_index = FREQ_INDEX_720P,
- .data = imx290_720p_settings,
- .data_size = ARRAY_SIZE(imx290_720p_settings),
+ .crop = {
+ .left = 4 + 8 + 320,
+ .top = 12 + 8 + 180,
+ .width = 1280,
+ .height = 720,
+ },
+ .mode_data = imx290_720p_common_settings,
+ .mode_data_size = ARRAY_SIZE(imx290_720p_common_settings),
+ .lane_data = imx290_720p_2lane_settings,
+ .lane_data_size = ARRAY_SIZE(imx290_720p_2lane_settings),
+ .clk_data = {
+ [CLK_37_125] = imx290_37_125mhz_clock_720p,
+ [CLK_74_25] = imx290_74_250mhz_clock_720p,
+ },
+ .clk_size = ARRAY_SIZE(imx290_37_125mhz_clock_720p),
},
};
@@ -328,17 +499,45 @@ static const struct imx290_mode imx290_m
.width = 1920,
.height = 1080,
.hmax = 0x0898,
+ .vmax = 0x0465,
.link_freq_index = FREQ_INDEX_1080P,
- .data = imx290_1080p_settings,
- .data_size = ARRAY_SIZE(imx290_1080p_settings),
+ .crop = {
+ .left = 4 + 8,
+ .top = 12 + 8,
+ .width = 1920,
+ .height = 1080,
+ },
+ .mode_data = imx290_1080p_common_settings,
+ .mode_data_size = ARRAY_SIZE(imx290_1080p_common_settings),
+ .lane_data = imx290_1080p_4lane_settings,
+ .lane_data_size = ARRAY_SIZE(imx290_1080p_4lane_settings),
+ .clk_data = {
+ [CLK_37_125] = imx290_37_125mhz_clock_1080p,
+ [CLK_74_25] = imx290_74_250mhz_clock_1080p,
+ },
+ .clk_size = ARRAY_SIZE(imx290_37_125mhz_clock_1080p),
},
{
.width = 1280,
.height = 720,
.hmax = 0x0ce4,
+ .vmax = 0x02ee,
.link_freq_index = FREQ_INDEX_720P,
- .data = imx290_720p_settings,
- .data_size = ARRAY_SIZE(imx290_720p_settings),
+ .crop = {
+ .left = 4 + 8 + 320,
+ .top = 12 + 8 + 180,
+ .width = 1280,
+ .height = 720,
+ },
+ .mode_data = imx290_720p_common_settings,
+ .mode_data_size = ARRAY_SIZE(imx290_720p_common_settings),
+ .lane_data = imx290_720p_4lane_settings,
+ .lane_data_size = ARRAY_SIZE(imx290_720p_4lane_settings),
+ .clk_data = {
+ [CLK_37_125] = imx290_37_125mhz_clock_720p,
+ [CLK_74_25] = imx290_74_250mhz_clock_720p,
+ },
+ .clk_size = ARRAY_SIZE(imx290_37_125mhz_clock_720p),
},
};
@@ -452,6 +651,53 @@ static int imx290_set_gain(struct imx290
return ret;
}
+static int imx290_set_exposure(struct imx290 *imx290, u32 value)
+{
+ u32 exposure = (imx290->current_mode->height + imx290->vblank->val) -
+ value - 1;
+ int ret;
+
+ ret = imx290_write_buffered_reg(imx290, IMX290_EXPOSURE_LOW, 3,
+ exposure);
+ if (ret)
+ dev_err(imx290->dev, "Unable to write exposure\n");
+
+ return ret;
+}
+
+static int imx290_set_hmax(struct imx290 *imx290, u32 val)
+{
+ u32 hmax = val + imx290->current_mode->width;
+ int ret;
+
+ ret = imx290_write_buffered_reg(imx290, IMX290_HMAX_LOW, 2,
+ hmax);
+ if (ret)
+ dev_err(imx290->dev, "Error setting HMAX register\n");
+
+ return ret;
+}
+
+static int imx290_set_vmax(struct imx290 *imx290, u32 val)
+{
+ u32 vmax = val + imx290->current_mode->height;
+ int ret;
+
+ ret = imx290_write_buffered_reg(imx290, IMX290_VMAX_LOW, 3,
+ vmax);
+ if (ret)
+ dev_err(imx290->dev, "Unable to write vmax\n");
+
+ /*
+ * Becuse of the way exposure works for this sensor, updating
+ * vblank causes the effective exposure to change, so we must
+ * set it back to the "new" correct value.
+ */
+ imx290_set_exposure(imx290, imx290->exposure->val);
+
+ return ret;
+}
+
/* Stop streaming */
static int imx290_stop_streaming(struct imx290 *imx290)
{
@@ -471,15 +717,50 @@ static int imx290_set_ctrl(struct v4l2_c
struct imx290 *imx290 = container_of(ctrl->handler,
struct imx290, ctrls);
int ret = 0;
+ u8 val;
+
+ if (ctrl->id == V4L2_CID_VBLANK) {
+ u32 vmax = ctrl->val + imx290->current_mode->height;
+
+ /*
+ * Changing vblank changes the allowed range for exposure.
+ * We don't supply the current exposure as default here as it
+ * may lie outside the new range. We will reset it just below.
+ */
+ __v4l2_ctrl_modify_range(imx290->exposure,
+ IMX290_EXPOSURE_MIN,
+ vmax - 2,
+ IMX290_EXPOSURE_STEP,
+ vmax - 2);
+ }
/* V4L2 controls values will be applied only when power is already up */
if (!pm_runtime_get_if_in_use(imx290->dev))
return 0;
switch (ctrl->id) {
- case V4L2_CID_GAIN:
+ case V4L2_CID_ANALOGUE_GAIN:
ret = imx290_set_gain(imx290, ctrl->val);
break;
+ case V4L2_CID_EXPOSURE:
+ ret = imx290_set_exposure(imx290, ctrl->val);
+ break;
+ case V4L2_CID_HBLANK:
+ ret = imx290_set_hmax(imx290, ctrl->val);
+ break;
+ case V4L2_CID_VBLANK:
+ ret = imx290_set_vmax(imx290, ctrl->val);
+ break;
+ case V4L2_CID_HFLIP:
+ case V4L2_CID_VFLIP:
+ /* WINMODE is in bits [6:4], so need to read-modify-write */
+ ret = imx290_read_reg(imx290, IMX290_FLIP_WINMODE, &val);
+ if (ret)
+ break;
+ val &= ~0x03;
+ val |= imx290->vflip->val | (imx290->hflip->val << 1);
+ ret = imx290_write_reg(imx290, IMX290_FLIP_WINMODE, val);
+ break;
case V4L2_CID_TEST_PATTERN:
if (ctrl->val) {
imx290_write_reg(imx290, IMX290_BLKLEVEL_LOW, 0x00);
@@ -519,10 +800,12 @@ static int imx290_enum_mbus_code(struct
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_mbus_code_enum *code)
{
- if (code->index >= ARRAY_SIZE(imx290_formats))
+ const struct imx290 *imx290 = to_imx290(sd);
+
+ if (code->index >= IMX290_NUM_FORMATS)
return -EINVAL;
- code->code = imx290_formats[code->index].code;
+ code->code = imx290->formats[code->index].code;
return 0;
}
@@ -534,8 +817,8 @@ static int imx290_enum_frame_size(struct
const struct imx290 *imx290 = to_imx290(sd);
const struct imx290_mode *imx290_modes = imx290_modes_ptr(imx290);
- if ((fse->code != imx290_formats[0].code) &&
- (fse->code != imx290_formats[1].code))
+ if (fse->code != imx290->formats[0].code &&
+ fse->code != imx290->formats[1].code)
return -EINVAL;
if (fse->index >= imx290_modes_num(imx290))
@@ -576,23 +859,9 @@ static inline u8 imx290_get_link_freq_in
return imx290->current_mode->link_freq_index;
}
-static s64 imx290_get_link_freq(struct imx290 *imx290)
-{
- u8 index = imx290_get_link_freq_index(imx290);
-
- return *(imx290_link_freqs_ptr(imx290) + index);
-}
-
static u64 imx290_calc_pixel_rate(struct imx290 *imx290)
{
- s64 link_freq = imx290_get_link_freq(imx290);
- u8 nlanes = imx290->nlanes;
- u64 pixel_rate;
-
- /* pixel rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
- pixel_rate = link_freq * 2 * nlanes;
- do_div(pixel_rate, imx290->bpp);
- return pixel_rate;
+ return 148500000;
}
static int imx290_set_fmt(struct v4l2_subdev *sd,
@@ -613,22 +882,30 @@ static int imx290_set_fmt(struct v4l2_su
fmt->format.width = mode->width;
fmt->format.height = mode->height;
- for (i = 0; i < ARRAY_SIZE(imx290_formats); i++)
- if (imx290_formats[i].code == fmt->format.code)
+ for (i = 0; i < IMX290_NUM_FORMATS; i++)
+ if (imx290->formats[i].code == fmt->format.code)
break;
- if (i >= ARRAY_SIZE(imx290_formats))
+ if (i >= IMX290_NUM_FORMATS)
i = 0;
- fmt->format.code = imx290_formats[i].code;
+ fmt->format.code = imx290->formats[i].code;
fmt->format.field = V4L2_FIELD_NONE;
+ fmt->format.colorspace = V4L2_COLORSPACE_RAW;
+ fmt->format.ycbcr_enc =
+ V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->format.colorspace);
+ fmt->format.quantization =
+ V4L2_MAP_QUANTIZATION_DEFAULT(true, fmt->format.colorspace,
+ fmt->format.ycbcr_enc);
+ fmt->format.xfer_func =
+ V4L2_MAP_XFER_FUNC_DEFAULT(fmt->format.colorspace);
if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
format = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
} else {
format = &imx290->current_format;
imx290->current_mode = mode;
- imx290->bpp = imx290_formats[i].bpp;
+ imx290->bpp = imx290->formats[i].bpp;
if (imx290->link_freq)
__v4l2_ctrl_s_ctrl(imx290->link_freq,
@@ -636,6 +913,18 @@ static int imx290_set_fmt(struct v4l2_su
if (imx290->pixel_rate)
__v4l2_ctrl_s_ctrl_int64(imx290->pixel_rate,
imx290_calc_pixel_rate(imx290));
+
+ if (imx290->hblank)
+ __v4l2_ctrl_modify_range(imx290->hblank,
+ mode->hmax - mode->width,
+ IMX290_HMAX_MAX - mode->width,
+ 1, mode->hmax - mode->width);
+ if (imx290->vblank)
+ __v4l2_ctrl_modify_range(imx290->vblank,
+ mode->vmax - mode->height,
+ IMX290_VMAX_MAX - mode->height,
+ 1,
+ mode->vmax - mode->height);
}
*format = fmt->format;
@@ -665,6 +954,7 @@ static int imx290_write_current_format(s
switch (imx290->current_format.code) {
case MEDIA_BUS_FMT_SRGGB10_1X10:
+ case MEDIA_BUS_FMT_Y10_1X10:
ret = imx290_set_register_array(imx290, imx290_10bit_settings,
ARRAY_SIZE(
imx290_10bit_settings));
@@ -674,6 +964,7 @@ static int imx290_write_current_format(s
}
break;
case MEDIA_BUS_FMT_SRGGB12_1X12:
+ case MEDIA_BUS_FMT_Y12_1X12:
ret = imx290_set_register_array(imx290, imx290_12bit_settings,
ARRAY_SIZE(
imx290_12bit_settings));
@@ -690,28 +981,62 @@ static int imx290_write_current_format(s
return 0;
}
-static int imx290_set_hmax(struct imx290 *imx290, u32 val)
+static const struct v4l2_rect *
+__imx290_get_pad_crop(struct imx290 *imx290, struct v4l2_subdev_pad_config *cfg,
+ unsigned int pad, enum v4l2_subdev_format_whence which)
{
- int ret;
+ switch (which) {
+ case V4L2_SUBDEV_FORMAT_TRY:
+ return v4l2_subdev_get_try_crop(&imx290->sd, cfg, pad);
+ case V4L2_SUBDEV_FORMAT_ACTIVE:
+ return &imx290->current_mode->crop;
+ }
- ret = imx290_write_reg(imx290, IMX290_HMAX_LOW, (val & 0xff));
- if (ret) {
- dev_err(imx290->dev, "Error setting HMAX register\n");
- return ret;
+ return NULL;
+}
+
+static int imx290_get_selection(struct v4l2_subdev *sd,
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_selection *sel)
+{
+ switch (sel->target) {
+ case V4L2_SEL_TGT_CROP: {
+ struct imx290 *imx290 = to_imx290(sd);
+
+ mutex_lock(&imx290->lock);
+ sel->r = *__imx290_get_pad_crop(imx290, cfg, sel->pad,
+ sel->which);
+ mutex_unlock(&imx290->lock);
+
+ return 0;
}
- ret = imx290_write_reg(imx290, IMX290_HMAX_HIGH, ((val >> 8) & 0xff));
- if (ret) {
- dev_err(imx290->dev, "Error setting HMAX register\n");
- return ret;
+ case V4L2_SEL_TGT_NATIVE_SIZE:
+ sel->r.top = 0;
+ sel->r.left = 0;
+ sel->r.width = IMX290_NATIVE_WIDTH;
+ sel->r.height = IMX290_NATIVE_HEIGHT;
+
+ return 0;
+
+ case V4L2_SEL_TGT_CROP_DEFAULT:
+ case V4L2_SEL_TGT_CROP_BOUNDS:
+ sel->r.top = IMX290_PIXEL_ARRAY_TOP;
+ sel->r.left = IMX290_PIXEL_ARRAY_LEFT;
+ sel->r.width = IMX290_PIXEL_ARRAY_WIDTH;
+ sel->r.height = IMX290_PIXEL_ARRAY_HEIGHT;
+
+ return 0;
}
- return 0;
+ return -EINVAL;
}
/* Start streaming */
static int imx290_start_streaming(struct imx290 *imx290)
{
+ enum imx290_clk_index clk_idx = imx290->xclk_freq == 37125000 ?
+ CLK_37_125 : CLK_74_25;
int ret;
/* Set init register settings */
@@ -723,6 +1048,14 @@ static int imx290_start_streaming(struct
return ret;
}
+ ret = imx290_set_register_array(imx290,
+ imx290->current_mode->clk_data[clk_idx],
+ imx290->current_mode->clk_size);
+ if (ret < 0) {
+ dev_err(imx290->dev, "Could not set clock registers\n");
+ return ret;
+ }
+
/* Apply the register values related to current frame format */
ret = imx290_write_current_format(imx290);
if (ret < 0) {
@@ -731,15 +1064,22 @@ static int imx290_start_streaming(struct
}
/* Apply default values of current mode */
- ret = imx290_set_register_array(imx290, imx290->current_mode->data,
- imx290->current_mode->data_size);
+ ret = imx290_set_register_array(imx290,
+ imx290->current_mode->mode_data,
+ imx290->current_mode->mode_data_size);
if (ret < 0) {
dev_err(imx290->dev, "Could not set current mode\n");
return ret;
}
- ret = imx290_set_hmax(imx290, imx290->current_mode->hmax);
- if (ret < 0)
+
+ /* Apply lane config registers of current mode */
+ ret = imx290_set_register_array(imx290,
+ imx290->current_mode->lane_data,
+ imx290->current_mode->lane_data_size);
+ if (ret < 0) {
+ dev_err(imx290->dev, "Could not set current mode\n");
return ret;
+ }
/* Apply customized values from user */
ret = v4l2_ctrl_handler_setup(imx290->sd.ctrl_handler);
@@ -778,6 +1118,9 @@ static int imx290_set_stream(struct v4l2
imx290_stop_streaming(imx290);
pm_runtime_put(imx290->dev);
}
+ /* vflip and hflip cannot change during streaming */
+ __v4l2_ctrl_grab(imx290->vflip, enable);
+ __v4l2_ctrl_grab(imx290->hflip, enable);
unlock_and_return:
@@ -795,49 +1138,6 @@ static int imx290_get_regulators(struct
imx290->supplies);
}
-static int imx290_set_data_lanes(struct imx290 *imx290)
-{
- int ret = 0, laneval, frsel;
-
- switch (imx290->nlanes) {
- case 2:
- laneval = 0x01;
- frsel = 0x02;
- break;
- case 4:
- laneval = 0x03;
- frsel = 0x01;
- break;
- default:
- /*
- * We should never hit this since the data lane count is
- * validated in probe itself
- */
- dev_err(imx290->dev, "Lane configuration not supported\n");
- ret = -EINVAL;
- goto exit;
- }
-
- ret = imx290_write_reg(imx290, IMX290_PHY_LANE_NUM, laneval);
- if (ret) {
- dev_err(imx290->dev, "Error setting Physical Lane number register\n");
- goto exit;
- }
-
- ret = imx290_write_reg(imx290, IMX290_CSI_LANE_MODE, laneval);
- if (ret) {
- dev_err(imx290->dev, "Error setting CSI Lane mode register\n");
- goto exit;
- }
-
- ret = imx290_write_reg(imx290, IMX290_FR_FDG_SEL, frsel);
- if (ret)
- dev_err(imx290->dev, "Error setting FR/FDG SEL register\n");
-
-exit:
- return ret;
-}
-
static int imx290_power_on(struct device *dev)
{
struct v4l2_subdev *sd = dev_get_drvdata(dev);
@@ -861,9 +1161,6 @@ static int imx290_power_on(struct device
gpiod_set_value_cansleep(imx290->rst_gpio, 0);
usleep_range(30000, 31000);
- /* Set data lane count */
- imx290_set_data_lanes(imx290);
-
return 0;
}
@@ -893,6 +1190,7 @@ static const struct v4l2_subdev_pad_ops
.enum_frame_size = imx290_enum_frame_size,
.get_fmt = imx290_get_fmt,
.set_fmt = imx290_set_fmt,
+ .get_selection = imx290_get_selection,
};
static const struct v4l2_subdev_ops imx290_subdev_ops = {
@@ -926,16 +1224,35 @@ static s64 imx290_check_link_freqs(const
return 0;
}
+static const struct of_device_id imx290_of_match[] = {
+ /*
+ * imx327 supports 1080p60 at 10 and 12bit.
+ * imx290 adds 10bit 1080p120.
+ * imx462 adds 10 and 12bit 1080p120.
+ * This driver currently maxes out at 1080p60, which is supported by all
+ * of them, but add the compatible strings for future implementation.
+ */
+ { .compatible = "sony,imx327", .data = imx290_colour_formats },
+ { .compatible = "sony,imx327-mono", .data = imx290_mono_formats },
+ { .compatible = "sony,imx290", .data = imx290_colour_formats },
+ { .compatible = "sony,imx290-mono", .data = imx290_mono_formats },
+ { .compatible = "sony,imx462", .data = imx290_colour_formats },
+ { .compatible = "sony,imx462-mono", .data = imx290_mono_formats },
+ { /* sentinel */ }
+};
+
static int imx290_probe(struct i2c_client *client)
{
+ struct v4l2_fwnode_device_properties props;
struct device *dev = &client->dev;
struct fwnode_handle *endpoint;
/* Only CSI2 is supported for now: */
struct v4l2_fwnode_endpoint ep = {
.bus_type = V4L2_MBUS_CSI2_DPHY
};
+ const struct of_device_id *match;
+ const struct imx290_mode *mode;
struct imx290 *imx290;
- u32 xclk_freq;
s64 fq;
int ret;
@@ -950,6 +1267,11 @@ static int imx290_probe(struct i2c_clien
return -ENODEV;
}
+ match = of_match_device(imx290_of_match, dev);
+ if (!match)
+ return -ENODEV;
+ imx290->formats = (const struct imx290_pixfmt *)match->data;
+
endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
if (!endpoint) {
dev_err(dev, "Endpoint node not found\n");
@@ -999,21 +1321,21 @@ static int imx290_probe(struct i2c_clien
}
ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
- &xclk_freq);
+ &imx290->xclk_freq);
if (ret) {
dev_err(dev, "Could not get xclk frequency\n");
goto free_err;
}
/* external clock must be 37.125 MHz */
- if (xclk_freq != 37125000) {
+ if (imx290->xclk_freq != 37125000 && imx290->xclk_freq != 74250000) {
dev_err(dev, "External clock frequency %u is not supported\n",
- xclk_freq);
+ imx290->xclk_freq);
ret = -EINVAL;
goto free_err;
}
- ret = clk_set_rate(imx290->xclk, xclk_freq);
+ ret = clk_set_rate(imx290->xclk, imx290->xclk_freq);
if (ret) {
dev_err(dev, "Could not set xclk frequency\n");
goto free_err;
@@ -1037,15 +1359,39 @@ static int imx290_probe(struct i2c_clien
/*
* Initialize the frame format. In particular, imx290->current_mode
- * and imx290->bpp are set to defaults: imx290_calc_pixel_rate() call
- * below relies on these fields.
+ * and imx290->bpp are set to defaults.
*/
imx290_entity_init_cfg(&imx290->sd, NULL);
- v4l2_ctrl_handler_init(&imx290->ctrls, 4);
+ v4l2_ctrl_handler_init(&imx290->ctrls, 11);
v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
- V4L2_CID_GAIN, 0, 72, 1, 0);
+ V4L2_CID_ANALOGUE_GAIN, 0, 100, 1, 0);
+
+ mode = imx290->current_mode;
+ imx290->hblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
+ V4L2_CID_HBLANK,
+ mode->hmax - mode->width,
+ IMX290_HMAX_MAX - mode->width, 1,
+ mode->hmax - mode->width);
+
+ imx290->vblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
+ V4L2_CID_VBLANK,
+ mode->vmax - mode->height,
+ IMX290_VMAX_MAX - mode->height, 1,
+ mode->vmax - mode->height);
+
+ imx290->exposure = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
+ V4L2_CID_EXPOSURE,
+ IMX290_EXPOSURE_MIN,
+ mode->vmax - 2,
+ IMX290_EXPOSURE_STEP,
+ mode->vmax - 2);
+
+ imx290->hflip = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
+ V4L2_CID_HFLIP, 0, 1, 1, 0);
+ imx290->vflip = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
+ V4L2_CID_VFLIP, 0, 1, 1, 0);
imx290->link_freq =
v4l2_ctrl_new_int_menu(&imx290->ctrls, &imx290_ctrl_ops,
@@ -1065,6 +1411,15 @@ static int imx290_probe(struct i2c_clien
ARRAY_SIZE(imx290_test_pattern_menu) - 1,
0, 0, imx290_test_pattern_menu);
+ ret = v4l2_fwnode_device_parse(&client->dev, &props);
+ if (ret)
+ goto free_ctrl;
+
+ ret = v4l2_ctrl_new_fwnode_properties(&imx290->ctrls, &imx290_ctrl_ops,
+ &props);
+ if (ret)
+ goto free_ctrl;
+
imx290->sd.ctrl_handler = &imx290->ctrls;
if (imx290->ctrls.error) {
@@ -1087,6 +1442,9 @@ static int imx290_probe(struct i2c_clien
goto free_ctrl;
}
+ /* Initialize the frame format (this also sets imx290->current_mode) */
+ imx290_entity_init_cfg(&imx290->sd, NULL);
+
ret = v4l2_async_register_subdev(&imx290->sd);
if (ret < 0) {
dev_err(dev, "Could not register v4l2 device\n");
@@ -1136,10 +1494,6 @@ static void imx290_remove(struct i2c_cli
pm_runtime_set_suspended(imx290->dev);
}
-static const struct of_device_id imx290_of_match[] = {
- { .compatible = "sony,imx290" },
- { /* sentinel */ }
-};
MODULE_DEVICE_TABLE(of, imx290_of_match);
static struct i2c_driver imx290_i2c_driver = {
|