hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/media/i2c/imx415.c
....@@ -50,6 +50,8 @@
5050 #include <media/v4l2-subdev.h>
5151 #include <linux/pinctrl/consumer.h>
5252 #include <linux/rk-preisp.h>
53
+#include <media/v4l2-fwnode.h>
54
+#include <linux/of_graph.h>
5355 #include "../platform/rockchip/isp/rkisp_tb_helper.h"
5456
5557 #define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x08)
....@@ -58,17 +60,20 @@
5860 #define V4L2_CID_DIGITAL_GAIN V4L2_CID_GAIN
5961 #endif
6062
63
+#define MIPI_FREQ_1188M 1188000000
6164 #define MIPI_FREQ_891M 891000000
6265 #define MIPI_FREQ_446M 446000000
6366 #define MIPI_FREQ_743M 743000000
6467 #define MIPI_FREQ_297M 297000000
6568
6669 #define IMX415_4LANES 4
70
+#define IMX415_2LANES 2
6771
6872 #define IMX415_MAX_PIXEL_RATE (MIPI_FREQ_891M / 10 * 2 * IMX415_4LANES)
6973 #define OF_CAMERA_HDR_MODE "rockchip,camera-hdr-mode"
7074
7175 #define IMX415_XVCLK_FREQ_37M 37125000
76
+#define IMX415_XVCLK_FREQ_27M 27000000
7277
7378 /* TODO: Get the real chip id from reg */
7479 #define CHIP_ID 0xE0
....@@ -142,6 +147,7 @@
142147 #define IMX415_FLIP_REG 0x3030
143148
144149 #define REG_NULL 0xFFFF
150
+#define REG_DELAY 0xFFFE
145151
146152 #define IMX415_REG_VALUE_08BIT 1
147153 #define IMX415_REG_VALUE_16BIT 2
....@@ -164,6 +170,7 @@
164170
165171 #define OF_CAMERA_PINCTRL_STATE_DEFAULT "rockchip,camera_default"
166172 #define OF_CAMERA_PINCTRL_STATE_SLEEP "rockchip,camera_sleep"
173
+#define RKMODULE_CAMERA_FASTBOOT_ENABLE "rockchip,camera_fastboot"
167174
168175 #define IMX415_NAME "imx415"
169176
....@@ -194,6 +201,7 @@
194201 const struct regval *reg_list;
195202 u32 hdr_mode;
196203 u32 vc[PAD_MAX];
204
+ u32 xvclk;
197205 };
198206
199207 struct imx415 {
....@@ -220,9 +228,10 @@
220228 struct mutex mutex;
221229 bool streaming;
222230 bool power_on;
223
- bool is_thunderboot;
231
+ u32 is_thunderboot;
224232 bool is_thunderboot_ng;
225233 bool is_first_streamoff;
234
+ const struct imx415_mode *supported_modes;
226235 const struct imx415_mode *cur_mode;
227236 u32 module_index;
228237 u32 cfg_num;
....@@ -232,6 +241,7 @@
232241 u32 cur_vts;
233242 bool has_init_exp;
234243 struct preisp_hdrae_exp_s init_hdrae_exp;
244
+ struct v4l2_fwnode_endpoint bus_cfg;
235245 };
236246
237247 static struct rkmodule_csi_dphy_param dcphy_param = {
....@@ -746,6 +756,311 @@
746756 };
747757
748758 /*
759
+ * Xclk 27Mhz
760
+ * 15fps
761
+ * CSI-2_2lane
762
+ * AD:12bit Output:12bit
763
+ * 891Mbps
764
+ * Master Mode
765
+ * Time 9.988ms Gain:6dB
766
+ * All-pixel
767
+ */
768
+static __maybe_unused const struct regval imx415_linear_12bit_3864x2192_891M_regs_2lane[] = {
769
+ {0x3008, 0x5D},
770
+ {0x300A, 0x42},
771
+ {0x3028, 0x98},
772
+ {0x3029, 0x08},
773
+ {0x3033, 0x05},
774
+ {0x3050, 0x79},
775
+ {0x3051, 0x07},
776
+ {0x3090, 0x14},
777
+ {0x30C1, 0x00},
778
+ {0x3116, 0x23},
779
+ {0x3118, 0xC6},
780
+ {0x311A, 0xE7},
781
+ {0x311E, 0x23},
782
+ {0x32D4, 0x21},
783
+ {0x32EC, 0xA1},
784
+ {0x344C, 0x2B},
785
+ {0x344D, 0x01},
786
+ {0x344E, 0xED},
787
+ {0x344F, 0x01},
788
+ {0x3450, 0xF6},
789
+ {0x3451, 0x02},
790
+ {0x3452, 0x7F},
791
+ {0x3453, 0x03},
792
+ {0x358A, 0x04},
793
+ {0x35A1, 0x02},
794
+ {0x35EC, 0x27},
795
+ {0x35EE, 0x8D},
796
+ {0x35F0, 0x8D},
797
+ {0x35F2, 0x29},
798
+ {0x36BC, 0x0C},
799
+ {0x36CC, 0x53},
800
+ {0x36CD, 0x00},
801
+ {0x36CE, 0x3C},
802
+ {0x36D0, 0x8C},
803
+ {0x36D1, 0x00},
804
+ {0x36D2, 0x71},
805
+ {0x36D4, 0x3C},
806
+ {0x36D6, 0x53},
807
+ {0x36D7, 0x00},
808
+ {0x36D8, 0x71},
809
+ {0x36DA, 0x8C},
810
+ {0x36DB, 0x00},
811
+ {0x3720, 0x00},
812
+ {0x3724, 0x02},
813
+ {0x3726, 0x02},
814
+ {0x3732, 0x02},
815
+ {0x3734, 0x03},
816
+ {0x3736, 0x03},
817
+ {0x3742, 0x03},
818
+ {0x3862, 0xE0},
819
+ {0x38CC, 0x30},
820
+ {0x38CD, 0x2F},
821
+ {0x395C, 0x0C},
822
+ {0x39A4, 0x07},
823
+ {0x39A8, 0x32},
824
+ {0x39AA, 0x32},
825
+ {0x39AC, 0x32},
826
+ {0x39AE, 0x32},
827
+ {0x39B0, 0x32},
828
+ {0x39B2, 0x2F},
829
+ {0x39B4, 0x2D},
830
+ {0x39B6, 0x28},
831
+ {0x39B8, 0x30},
832
+ {0x39BA, 0x30},
833
+ {0x39BC, 0x30},
834
+ {0x39BE, 0x30},
835
+ {0x39C0, 0x30},
836
+ {0x39C2, 0x2E},
837
+ {0x39C4, 0x2B},
838
+ {0x39C6, 0x25},
839
+ {0x3A42, 0xD1},
840
+ {0x3A4C, 0x77},
841
+ {0x3AE0, 0x02},
842
+ {0x3AEC, 0x0C},
843
+ {0x3B00, 0x2E},
844
+ {0x3B06, 0x29},
845
+ {0x3B98, 0x25},
846
+ {0x3B99, 0x21},
847
+ {0x3B9B, 0x13},
848
+ {0x3B9C, 0x13},
849
+ {0x3B9D, 0x13},
850
+ {0x3B9E, 0x13},
851
+ {0x3BA1, 0x00},
852
+ {0x3BA2, 0x06},
853
+ {0x3BA3, 0x0B},
854
+ {0x3BA4, 0x10},
855
+ {0x3BA5, 0x14},
856
+ {0x3BA6, 0x18},
857
+ {0x3BA7, 0x1A},
858
+ {0x3BA8, 0x1A},
859
+ {0x3BA9, 0x1A},
860
+ {0x3BAC, 0xED},
861
+ {0x3BAD, 0x01},
862
+ {0x3BAE, 0xF6},
863
+ {0x3BAF, 0x02},
864
+ {0x3BB0, 0xA2},
865
+ {0x3BB1, 0x03},
866
+ {0x3BB2, 0xE0},
867
+ {0x3BB3, 0x03},
868
+ {0x3BB4, 0xE0},
869
+ {0x3BB5, 0x03},
870
+ {0x3BB6, 0xE0},
871
+ {0x3BB7, 0x03},
872
+ {0x3BB8, 0xE0},
873
+ {0x3BBA, 0xE0},
874
+ {0x3BBC, 0xDA},
875
+ {0x3BBE, 0x88},
876
+ {0x3BC0, 0x44},
877
+ {0x3BC2, 0x7B},
878
+ {0x3BC4, 0xA2},
879
+ {0x3BC8, 0xBD},
880
+ {0x3BCA, 0xBD},
881
+ {0x4001, 0x01},
882
+ {0x4004, 0xC0},
883
+ {0x4005, 0x06},
884
+ {0x400C, 0x00},
885
+ {0x4018, 0x7F},
886
+ {0x401A, 0x37},
887
+ {0x401C, 0x37},
888
+ {0x401E, 0xF7},
889
+ {0x401F, 0x00},
890
+ {0x4020, 0x3F},
891
+ {0x4022, 0x6F},
892
+ {0x4024, 0x3F},
893
+ {0x4026, 0x5F},
894
+ {0x4028, 0x2F},
895
+ {0x4074, 0x01},
896
+ {0x3002, 0x00},
897
+ //{0x3000, 0x00},
898
+ {REG_DELAY, 0x1E},//wait_ms(30)
899
+ {REG_NULL, 0x00},
900
+};
901
+
902
+/*
903
+ * Xclk 27Mhz
904
+ * 90.059fps
905
+ * CSI-2_2lane
906
+ * AD:10bit Output:12bit
907
+ * 2376Mbps
908
+ * Master Mode
909
+ * Time 9.999ms Gain:6dB
910
+ * 2568x1440 2/2-line binning & Window cropping
911
+ */
912
+static __maybe_unused const struct regval imx415_linear_12bit_1284x720_2376M_regs_2lane[] = {
913
+ {0x3008, 0x5D},
914
+ {0x300A, 0x42},
915
+ {0x301C, 0x04},
916
+ {0x3020, 0x01},
917
+ {0x3021, 0x01},
918
+ {0x3022, 0x01},
919
+ {0x3024, 0xAB},
920
+ {0x3025, 0x07},
921
+ {0x3028, 0xA4},
922
+ {0x3029, 0x01},
923
+ {0x3031, 0x00},
924
+ {0x3033, 0x00},
925
+ {0x3040, 0x88},
926
+ {0x3041, 0x02},
927
+ {0x3042, 0x08},
928
+ {0x3043, 0x0A},
929
+ {0x3044, 0xF0},
930
+ {0x3045, 0x02},
931
+ {0x3046, 0x40},
932
+ {0x3047, 0x0B},
933
+ {0x3050, 0xC4},
934
+ {0x3090, 0x14},
935
+ {0x30C1, 0x00},
936
+ {0x30D9, 0x02},
937
+ {0x30DA, 0x01},
938
+ {0x3116, 0x23},
939
+ {0x3118, 0x08},
940
+ {0x3119, 0x01},
941
+ {0x311A, 0xE7},
942
+ {0x311E, 0x23},
943
+ {0x32D4, 0x21},
944
+ {0x32EC, 0xA1},
945
+ {0x344C, 0x2B},
946
+ {0x344D, 0x01},
947
+ {0x344E, 0xED},
948
+ {0x344F, 0x01},
949
+ {0x3450, 0xF6},
950
+ {0x3451, 0x02},
951
+ {0x3452, 0x7F},
952
+ {0x3453, 0x03},
953
+ {0x358A, 0x04},
954
+ {0x35A1, 0x02},
955
+ {0x35EC, 0x27},
956
+ {0x35EE, 0x8D},
957
+ {0x35F0, 0x8D},
958
+ {0x35F2, 0x29},
959
+ {0x36BC, 0x0C},
960
+ {0x36CC, 0x53},
961
+ {0x36CD, 0x00},
962
+ {0x36CE, 0x3C},
963
+ {0x36D0, 0x8C},
964
+ {0x36D1, 0x00},
965
+ {0x36D2, 0x71},
966
+ {0x36D4, 0x3C},
967
+ {0x36D6, 0x53},
968
+ {0x36D7, 0x00},
969
+ {0x36D8, 0x71},
970
+ {0x36DA, 0x8C},
971
+ {0x36DB, 0x00},
972
+ {0x3701, 0x00},
973
+ {0x3720, 0x00},
974
+ {0x3724, 0x02},
975
+ {0x3726, 0x02},
976
+ {0x3732, 0x02},
977
+ {0x3734, 0x03},
978
+ {0x3736, 0x03},
979
+ {0x3742, 0x03},
980
+ {0x3862, 0xE0},
981
+ {0x38CC, 0x30},
982
+ {0x38CD, 0x2F},
983
+ {0x395C, 0x0C},
984
+ {0x39A4, 0x07},
985
+ {0x39A8, 0x32},
986
+ {0x39AA, 0x32},
987
+ {0x39AC, 0x32},
988
+ {0x39AE, 0x32},
989
+ {0x39B0, 0x32},
990
+ {0x39B2, 0x2F},
991
+ {0x39B4, 0x2D},
992
+ {0x39B6, 0x28},
993
+ {0x39B8, 0x30},
994
+ {0x39BA, 0x30},
995
+ {0x39BC, 0x30},
996
+ {0x39BE, 0x30},
997
+ {0x39C0, 0x30},
998
+ {0x39C2, 0x2E},
999
+ {0x39C4, 0x2B},
1000
+ {0x39C6, 0x25},
1001
+ {0x3A42, 0xD1},
1002
+ {0x3A4C, 0x77},
1003
+ {0x3AE0, 0x02},
1004
+ {0x3AEC, 0x0C},
1005
+ {0x3B00, 0x2E},
1006
+ {0x3B06, 0x29},
1007
+ {0x3B98, 0x25},
1008
+ {0x3B99, 0x21},
1009
+ {0x3B9B, 0x13},
1010
+ {0x3B9C, 0x13},
1011
+ {0x3B9D, 0x13},
1012
+ {0x3B9E, 0x13},
1013
+ {0x3BA1, 0x00},
1014
+ {0x3BA2, 0x06},
1015
+ {0x3BA3, 0x0B},
1016
+ {0x3BA4, 0x10},
1017
+ {0x3BA5, 0x14},
1018
+ {0x3BA6, 0x18},
1019
+ {0x3BA7, 0x1A},
1020
+ {0x3BA8, 0x1A},
1021
+ {0x3BA9, 0x1A},
1022
+ {0x3BAC, 0xED},
1023
+ {0x3BAD, 0x01},
1024
+ {0x3BAE, 0xF6},
1025
+ {0x3BAF, 0x02},
1026
+ {0x3BB0, 0xA2},
1027
+ {0x3BB1, 0x03},
1028
+ {0x3BB2, 0xE0},
1029
+ {0x3BB3, 0x03},
1030
+ {0x3BB4, 0xE0},
1031
+ {0x3BB5, 0x03},
1032
+ {0x3BB6, 0xE0},
1033
+ {0x3BB7, 0x03},
1034
+ {0x3BB8, 0xE0},
1035
+ {0x3BBA, 0xE0},
1036
+ {0x3BBC, 0xDA},
1037
+ {0x3BBE, 0x88},
1038
+ {0x3BC0, 0x44},
1039
+ {0x3BC2, 0x7B},
1040
+ {0x3BC4, 0xA2},
1041
+ {0x3BC8, 0xBD},
1042
+ {0x3BCA, 0xBD},
1043
+ {0x4001, 0x01},
1044
+ {0x4004, 0xC0},
1045
+ {0x4005, 0x06},
1046
+ {0x4018, 0xE7},
1047
+ {0x401A, 0x8F},
1048
+ {0x401C, 0x8F},
1049
+ {0x401E, 0x7F},
1050
+ {0x401F, 0x02},
1051
+ {0x4020, 0x97},
1052
+ {0x4022, 0x0F},
1053
+ {0x4023, 0x01},
1054
+ {0x4024, 0x97},
1055
+ {0x4026, 0xF7},
1056
+ {0x4028, 0x7F},
1057
+ {0x3002, 0x00},
1058
+ //{0x3000, 0x00},
1059
+ {REG_DELAY, 0x1E},//wait_ms(30)
1060
+ {REG_NULL, 0x00},
1061
+};
1062
+
1063
+/*
7491064 * The width and height must be configured to be
7501065 * the same as the current output resolution of the sensor.
7511066 * The input width of the isp needs to be 16 aligned.
....@@ -779,6 +1094,7 @@
7791094 .mipi_freq_idx = 1,
7801095 .bpp = 10,
7811096 .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
1097
+ .xvclk = IMX415_XVCLK_FREQ_37M,
7821098 },
7831099 {
7841100 .bus_fmt = MEDIA_BUS_FMT_SGBRG10_1X10,
....@@ -804,6 +1120,7 @@
8041120 .vc[PAD1] = V4L2_MBUS_CSI2_CHANNEL_0,//L->csi wr0
8051121 .vc[PAD2] = V4L2_MBUS_CSI2_CHANNEL_1,
8061122 .vc[PAD3] = V4L2_MBUS_CSI2_CHANNEL_1,//M->csi wr2
1123
+ .xvclk = IMX415_XVCLK_FREQ_37M,
8071124 },
8081125 {
8091126 .bus_fmt = MEDIA_BUS_FMT_SGBRG10_1X10,
....@@ -829,6 +1146,7 @@
8291146 .vc[PAD1] = V4L2_MBUS_CSI2_CHANNEL_1,//M->csi wr0
8301147 .vc[PAD2] = V4L2_MBUS_CSI2_CHANNEL_0,//L->csi wr0
8311148 .vc[PAD3] = V4L2_MBUS_CSI2_CHANNEL_2,//S->csi wr2
1149
+ .xvclk = IMX415_XVCLK_FREQ_37M,
8321150 },
8331151 {
8341152 .bus_fmt = MEDIA_BUS_FMT_SGBRG10_1X10,
....@@ -854,6 +1172,7 @@
8541172 .vc[PAD1] = V4L2_MBUS_CSI2_CHANNEL_1,//M->csi wr0
8551173 .vc[PAD2] = V4L2_MBUS_CSI2_CHANNEL_0,//L->csi wr0
8561174 .vc[PAD3] = V4L2_MBUS_CSI2_CHANNEL_2,//S->csi wr2
1175
+ .xvclk = IMX415_XVCLK_FREQ_37M,
8571176 },
8581177 {
8591178 /* 1H period = (1100 clock) = (1100 * 1 / 74.25MHz) */
....@@ -873,6 +1192,7 @@
8731192 .mipi_freq_idx = 1,
8741193 .bpp = 12,
8751194 .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
1195
+ .xvclk = IMX415_XVCLK_FREQ_37M,
8761196 },
8771197 {
8781198 .bus_fmt = MEDIA_BUS_FMT_SGBRG12_1X12,
....@@ -898,6 +1218,7 @@
8981218 .vc[PAD1] = V4L2_MBUS_CSI2_CHANNEL_0,//L->csi wr0
8991219 .vc[PAD2] = V4L2_MBUS_CSI2_CHANNEL_1,
9001220 .vc[PAD3] = V4L2_MBUS_CSI2_CHANNEL_1,//M->csi wr2
1221
+ .xvclk = IMX415_XVCLK_FREQ_37M,
9011222 },
9021223 {
9031224 .bus_fmt = MEDIA_BUS_FMT_SGBRG12_1X12,
....@@ -923,6 +1244,7 @@
9231244 .vc[PAD1] = V4L2_MBUS_CSI2_CHANNEL_1,//M->csi wr0
9241245 .vc[PAD2] = V4L2_MBUS_CSI2_CHANNEL_0,//L->csi wr0
9251246 .vc[PAD3] = V4L2_MBUS_CSI2_CHANNEL_2,//S->csi wr2
1247
+ .xvclk = IMX415_XVCLK_FREQ_37M,
9261248 },
9271249 {
9281250 .bus_fmt = MEDIA_BUS_FMT_SGBRG12_1X12,
....@@ -941,6 +1263,7 @@
9411263 .mipi_freq_idx = 0,
9421264 .bpp = 12,
9431265 .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
1266
+ .xvclk = IMX415_XVCLK_FREQ_37M,
9441267 },
9451268 {
9461269 .bus_fmt = MEDIA_BUS_FMT_SGBRG12_1X12,
....@@ -966,6 +1289,50 @@
9661289 .vc[PAD1] = V4L2_MBUS_CSI2_CHANNEL_0,//L->csi wr0
9671290 .vc[PAD2] = V4L2_MBUS_CSI2_CHANNEL_1,
9681291 .vc[PAD3] = V4L2_MBUS_CSI2_CHANNEL_1,//M->csi wr2
1292
+ .xvclk = IMX415_XVCLK_FREQ_37M,
1293
+ },
1294
+};
1295
+
1296
+static const struct imx415_mode supported_modes_2lane[] = {
1297
+ {
1298
+ /* 1H period = (1100 clock) = (1100 * 1 / 74.25MHz) */
1299
+ .bus_fmt = MEDIA_BUS_FMT_SGBRG12_1X12,
1300
+ .width = 3864,
1301
+ .height = 2192,
1302
+ .max_fps = {
1303
+ .numerator = 10000,
1304
+ .denominator = 150000,
1305
+ },
1306
+ .exp_def = 0x08ca - 0x08,
1307
+ .hts_def = 0x0898 * IMX415_2LANES * 2,
1308
+ .vts_def = 0x08ca,
1309
+ .global_reg_list = NULL,
1310
+ .reg_list = imx415_linear_12bit_3864x2192_891M_regs_2lane,
1311
+ .hdr_mode = NO_HDR,
1312
+ .mipi_freq_idx = 1,
1313
+ .bpp = 12,
1314
+ .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
1315
+ .xvclk = IMX415_XVCLK_FREQ_27M,
1316
+ },
1317
+ {
1318
+ /* 1H period = (1100 clock) = (1100 * 1 / 74.25MHz) */
1319
+ .bus_fmt = MEDIA_BUS_FMT_SGBRG12_1X12,
1320
+ .width = 1284,
1321
+ .height = 720,
1322
+ .max_fps = {
1323
+ .numerator = 10000,
1324
+ .denominator = 900000,
1325
+ },
1326
+ .exp_def = 0x07AB-8,
1327
+ .hts_def = 0x01A4 * IMX415_2LANES * 2,
1328
+ .vts_def = 0x07AB,
1329
+ .global_reg_list = NULL,
1330
+ .reg_list = imx415_linear_12bit_1284x720_2376M_regs_2lane,
1331
+ .hdr_mode = NO_HDR,
1332
+ .mipi_freq_idx = 4,
1333
+ .bpp = 12,
1334
+ .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
1335
+ .xvclk = IMX415_XVCLK_FREQ_27M,
9691336 },
9701337 };
9711338
....@@ -974,6 +1341,7 @@
9741341 MIPI_FREQ_446M,
9751342 MIPI_FREQ_743M,
9761343 MIPI_FREQ_891M,
1344
+ MIPI_FREQ_1188M,
9771345 };
9781346
9791347 /* Write registers up to 4 at a time */
....@@ -1010,10 +1378,18 @@
10101378 {
10111379 u32 i;
10121380 int ret = 0;
1013
-
1381
+ if (!regs) {
1382
+ dev_err(&client->dev, "write reg array error\n");
1383
+ return ret;
1384
+ }
10141385 for (i = 0; ret == 0 && regs[i].addr != REG_NULL; i++) {
1015
- ret = imx415_write_reg(client, regs[i].addr,
1016
- IMX415_REG_VALUE_08BIT, regs[i].val);
1386
+ if (regs[i].addr == REG_DELAY) {
1387
+ usleep_range(regs[i].val * 1000, regs[i].val * 1000 + 500);
1388
+ dev_info(&client->dev, "write reg array, sleep %dms\n", regs[i].val);
1389
+ } else {
1390
+ ret = imx415_write_reg(client, regs[i].addr,
1391
+ IMX415_REG_VALUE_08BIT, regs[i].val);
1392
+ }
10171393 }
10181394 return ret;
10191395 }
....@@ -1070,9 +1446,9 @@
10701446 unsigned int i;
10711447
10721448 for (i = 0; i < imx415->cfg_num; i++) {
1073
- dist = imx415_get_reso_dist(&supported_modes[i], framefmt);
1449
+ dist = imx415_get_reso_dist(&imx415->supported_modes[i], framefmt);
10741450 if ((cur_best_fit_dist == -1 || dist < cur_best_fit_dist) &&
1075
- supported_modes[i].bus_fmt == framefmt->code) {
1451
+ imx415->supported_modes[i].bus_fmt == framefmt->code) {
10761452 cur_best_fit_dist = dist;
10771453 cur_best_fit = i;
10781454 }
....@@ -1080,7 +1456,7 @@
10801456 dev_info(&imx415->client->dev, "%s: cur_best_fit(%d)",
10811457 __func__, cur_best_fit);
10821458
1083
- return &supported_modes[cur_best_fit];
1459
+ return &imx415->supported_modes[cur_best_fit];
10841460 }
10851461
10861462 static int __imx415_power_on(struct imx415 *imx415);
....@@ -1094,8 +1470,8 @@
10941470 }
10951471 imx415->cur_mode = mode;
10961472 imx415->cur_vts = imx415->cur_mode->vts_def;
1097
- dev_dbg(&imx415->client->dev, "set fmt: cur_mode: %dx%d, hdr: %d\n",
1098
- mode->width, mode->height, mode->hdr_mode);
1473
+ dev_info(&imx415->client->dev, "set fmt: cur_mode: %dx%d, hdr: %d, bpp: %d\n",
1474
+ mode->width, mode->height, mode->hdr_mode, mode->bpp);
10991475 }
11001476
11011477 static int imx415_set_fmt(struct v4l2_subdev *sd,
....@@ -1106,6 +1482,7 @@
11061482 const struct imx415_mode *mode;
11071483 s64 h_blank, vblank_def, vblank_min;
11081484 u64 pixel_rate = 0;
1485
+ u8 lanes = imx415->bus_cfg.bus.mipi_csi2.num_data_lanes;
11091486
11101487 mutex_lock(&imx415->mutex);
11111488
....@@ -1134,7 +1511,8 @@
11341511 1, vblank_def);
11351512 __v4l2_ctrl_s_ctrl(imx415->vblank, vblank_def);
11361513 __v4l2_ctrl_s_ctrl(imx415->link_freq, mode->mipi_freq_idx);
1137
- pixel_rate = (u32)link_freq_items[mode->mipi_freq_idx] / mode->bpp * 2 * IMX415_4LANES;
1514
+ pixel_rate = (u32)link_freq_items[mode->mipi_freq_idx] /
1515
+ mode->bpp * 2 * lanes;
11381516 __v4l2_ctrl_s_ctrl_int64(imx415->pixel_rate,
11391517 pixel_rate);
11401518 }
....@@ -1185,7 +1563,7 @@
11851563 if (code->index >= imx415->cfg_num)
11861564 return -EINVAL;
11871565
1188
- code->code = supported_modes[code->index].bus_fmt;
1566
+ code->code = imx415->supported_modes[code->index].bus_fmt;
11891567
11901568 return 0;
11911569 }
....@@ -1199,13 +1577,13 @@
11991577 if (fse->index >= imx415->cfg_num)
12001578 return -EINVAL;
12011579
1202
- if (fse->code != supported_modes[fse->index].bus_fmt)
1580
+ if (fse->code != imx415->supported_modes[fse->index].bus_fmt)
12031581 return -EINVAL;
12041582
1205
- fse->min_width = supported_modes[fse->index].width;
1206
- fse->max_width = supported_modes[fse->index].width;
1207
- fse->max_height = supported_modes[fse->index].height;
1208
- fse->min_height = supported_modes[fse->index].height;
1583
+ fse->min_width = imx415->supported_modes[fse->index].width;
1584
+ fse->max_width = imx415->supported_modes[fse->index].width;
1585
+ fse->max_height = imx415->supported_modes[fse->index].height;
1586
+ fse->min_height = imx415->supported_modes[fse->index].height;
12091587
12101588 return 0;
12111589 }
....@@ -1227,8 +1605,9 @@
12271605 struct imx415 *imx415 = to_imx415(sd);
12281606 const struct imx415_mode *mode = imx415->cur_mode;
12291607 u32 val = 0;
1608
+ u8 lanes = imx415->bus_cfg.bus.mipi_csi2.num_data_lanes;
12301609
1231
- val = 1 << (IMX415_4LANES - 1) |
1610
+ val = 1 << (lanes - 1) |
12321611 V4L2_MBUS_CSI2_CHANNEL_0 |
12331612 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
12341613 if (mode->hdr_mode != NO_HDR)
....@@ -1687,6 +2066,7 @@
16872066 const struct imx415_mode *mode;
16882067 u64 pixel_rate = 0;
16892068 struct rkmodule_csi_dphy_param *dphy_param;
2069
+ u8 lanes = imx415->bus_cfg.bus.mipi_csi2.num_data_lanes;
16902070
16912071 switch (cmd) {
16922072 case PREISP_CMD_SET_HDRAE_EXP:
....@@ -1708,10 +2088,11 @@
17082088 w = imx415->cur_mode->width;
17092089 h = imx415->cur_mode->height;
17102090 for (i = 0; i < imx415->cfg_num; i++) {
1711
- if (w == supported_modes[i].width &&
1712
- h == supported_modes[i].height &&
1713
- supported_modes[i].hdr_mode == hdr->hdr_mode) {
1714
- imx415_change_mode(imx415, &supported_modes[i]);
2091
+ if (w == imx415->supported_modes[i].width &&
2092
+ h == imx415->supported_modes[i].height &&
2093
+ imx415->supported_modes[i].hdr_mode == hdr->hdr_mode) {
2094
+ dev_info(&imx415->client->dev, "set hdr cfg, set mode to %d\n", i);
2095
+ imx415_change_mode(imx415, &imx415->supported_modes[i]);
17152096 break;
17162097 }
17172098 }
....@@ -1741,7 +2122,8 @@
17412122 IMX415_VTS_MAX - mode->height,
17422123 1, h);
17432124 __v4l2_ctrl_s_ctrl(imx415->link_freq, mode->mipi_freq_idx);
1744
- pixel_rate = (u32)link_freq_items[mode->mipi_freq_idx] / mode->bpp * 2 * IMX415_4LANES;
2125
+ pixel_rate = (u32)link_freq_items[mode->mipi_freq_idx] /
2126
+ mode->bpp * 2 * lanes;
17452127 __v4l2_ctrl_s_ctrl_int64(imx415->pixel_rate,
17462128 pixel_rate);
17472129 mutex_unlock(&imx415->mutex);
....@@ -2045,10 +2427,6 @@
20452427 {
20462428 int ret;
20472429 struct device *dev = &imx415->client->dev;
2048
-
2049
- if (imx415->is_thunderboot)
2050
- return 0;
2051
-
20522430 if (!IS_ERR_OR_NULL(imx415->pins_default)) {
20532431 ret = pinctrl_select_state(imx415->pinctrl,
20542432 imx415->pins_default);
....@@ -2056,26 +2434,28 @@
20562434 dev_err(dev, "could not set pins\n");
20572435 }
20582436
2059
- ret = regulator_bulk_enable(IMX415_NUM_SUPPLIES, imx415->supplies);
2060
- if (ret < 0) {
2061
- dev_err(dev, "Failed to enable regulators\n");
2062
- goto err_pinctrl;
2063
- }
2064
- if (!IS_ERR(imx415->power_gpio))
2065
- gpiod_direction_output(imx415->power_gpio, 1);
2066
- /* At least 500ns between power raising and XCLR */
2067
- /* fix power on timing if insmod this ko */
2068
- usleep_range(10 * 1000, 20 * 1000);
2069
- if (!IS_ERR(imx415->reset_gpio))
2070
- gpiod_direction_output(imx415->reset_gpio, 0);
2437
+ if (!imx415->is_thunderboot) {
2438
+ ret = regulator_bulk_enable(IMX415_NUM_SUPPLIES, imx415->supplies);
2439
+ if (ret < 0) {
2440
+ dev_err(dev, "Failed to enable regulators\n");
2441
+ goto err_pinctrl;
2442
+ }
2443
+ if (!IS_ERR(imx415->power_gpio))
2444
+ gpiod_direction_output(imx415->power_gpio, 1);
2445
+ /* At least 500ns between power raising and XCLR */
2446
+ /* fix power on timing if insmod this ko */
2447
+ usleep_range(10 * 1000, 20 * 1000);
2448
+ if (!IS_ERR(imx415->reset_gpio))
2449
+ gpiod_direction_output(imx415->reset_gpio, 0);
20712450
2072
- /* At least 1us between XCLR and clk */
2073
- /* fix power on timing if insmod this ko */
2074
- usleep_range(10 * 1000, 20 * 1000);
2075
- ret = clk_set_rate(imx415->xvclk, IMX415_XVCLK_FREQ_37M);
2451
+ /* At least 1us between XCLR and clk */
2452
+ /* fix power on timing if insmod this ko */
2453
+ usleep_range(10 * 1000, 20 * 1000);
2454
+ }
2455
+ ret = clk_set_rate(imx415->xvclk, imx415->cur_mode->xvclk);
20762456 if (ret < 0)
20772457 dev_warn(dev, "Failed to set xvclk rate\n");
2078
- if (clk_get_rate(imx415->xvclk) != IMX415_XVCLK_FREQ_37M)
2458
+ if (clk_get_rate(imx415->xvclk) != imx415->cur_mode->xvclk)
20792459 dev_warn(dev, "xvclk mismatched\n");
20802460 ret = clk_prepare_enable(imx415->xvclk);
20812461 if (ret < 0) {
....@@ -2084,7 +2464,8 @@
20842464 }
20852465
20862466 /* At least 20us between XCLR and I2C communication */
2087
- usleep_range(20*1000, 30*1000);
2467
+ if (!imx415->is_thunderboot)
2468
+ usleep_range(20*1000, 30*1000);
20882469
20892470 return 0;
20902471
....@@ -2154,7 +2535,7 @@
21542535 struct imx415 *imx415 = to_imx415(sd);
21552536 struct v4l2_mbus_framefmt *try_fmt =
21562537 v4l2_subdev_get_try_format(sd, fh->pad, 0);
2157
- const struct imx415_mode *def_mode = &supported_modes[0];
2538
+ const struct imx415_mode *def_mode = &imx415->supported_modes[0];
21582539
21592540 mutex_lock(&imx415->mutex);
21602541 /* Initialize try_fmt */
....@@ -2179,11 +2560,11 @@
21792560 if (fie->index >= imx415->cfg_num)
21802561 return -EINVAL;
21812562
2182
- fie->code = supported_modes[fie->index].bus_fmt;
2183
- fie->width = supported_modes[fie->index].width;
2184
- fie->height = supported_modes[fie->index].height;
2185
- fie->interval = supported_modes[fie->index].max_fps;
2186
- fie->reserved[0] = supported_modes[fie->index].hdr_mode;
2563
+ fie->code = imx415->supported_modes[fie->index].bus_fmt;
2564
+ fie->width = imx415->supported_modes[fie->index].width;
2565
+ fie->height = imx415->supported_modes[fie->index].height;
2566
+ fie->interval = imx415->supported_modes[fie->index].max_fps;
2567
+ fie->reserved[0] = imx415->supported_modes[fie->index].hdr_mode;
21872568 return 0;
21882569 }
21892570
....@@ -2401,8 +2782,10 @@
24012782 struct v4l2_ctrl_handler *handler;
24022783 s64 exposure_max, vblank_def;
24032784 u64 pixel_rate;
2785
+ u64 max_pixel_rate;
24042786 u32 h_blank;
24052787 int ret;
2788
+ u8 lanes = imx415->bus_cfg.bus.mipi_csi2.num_data_lanes;
24062789
24072790 handler = &imx415->ctrl_handler;
24082791 mode = imx415->cur_mode;
....@@ -2418,9 +2801,10 @@
24182801 v4l2_ctrl_s_ctrl(imx415->link_freq, mode->mipi_freq_idx);
24192802
24202803 /* pixel rate = link frequency * 2 * lanes / BITS_PER_SAMPLE */
2421
- pixel_rate = (u32)link_freq_items[mode->mipi_freq_idx] / mode->bpp * 2 * IMX415_4LANES;
2804
+ pixel_rate = (u32)link_freq_items[mode->mipi_freq_idx] / mode->bpp * 2 * lanes;
2805
+ max_pixel_rate = MIPI_FREQ_1188M / mode->bpp * 2 * lanes;
24222806 imx415->pixel_rate = v4l2_ctrl_new_std(handler, NULL,
2423
- V4L2_CID_PIXEL_RATE, 0, IMX415_MAX_PIXEL_RATE,
2807
+ V4L2_CID_PIXEL_RATE, 0, max_pixel_rate,
24242808 1, pixel_rate);
24252809
24262810 h_blank = mode->hts_def - mode->width;
....@@ -2511,6 +2895,7 @@
25112895 struct device_node *node = dev->of_node;
25122896 struct imx415 *imx415;
25132897 struct v4l2_subdev *sd;
2898
+ struct device_node *endpoint;
25142899 char facing[2];
25152900 int ret;
25162901 u32 i, hdr_mode = 0;
....@@ -2542,16 +2927,41 @@
25422927 hdr_mode = NO_HDR;
25432928 dev_warn(dev, " Get hdr mode failed! no hdr default\n");
25442929 }
2930
+
2931
+ endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
2932
+ if (!endpoint) {
2933
+ dev_err(dev, "Failed to get endpoint\n");
2934
+ return -EINVAL;
2935
+ }
2936
+
2937
+ ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(endpoint),
2938
+ &imx415->bus_cfg);
2939
+ of_node_put(endpoint);
2940
+ if (ret) {
2941
+ dev_err(dev, "Failed to get bus config\n");
2942
+ return -EINVAL;
2943
+ }
2944
+
25452945 imx415->client = client;
2546
- imx415->cfg_num = ARRAY_SIZE(supported_modes);
2946
+ if (imx415->bus_cfg.bus.mipi_csi2.num_data_lanes == IMX415_4LANES) {
2947
+ imx415->supported_modes = supported_modes;
2948
+ imx415->cfg_num = ARRAY_SIZE(supported_modes);
2949
+ } else {
2950
+ imx415->supported_modes = supported_modes_2lane;
2951
+ imx415->cfg_num = ARRAY_SIZE(supported_modes_2lane);
2952
+ }
2953
+ dev_info(dev, "detect imx415 lane %d\n",
2954
+ imx415->bus_cfg.bus.mipi_csi2.num_data_lanes);
2955
+
25472956 for (i = 0; i < imx415->cfg_num; i++) {
2548
- if (hdr_mode == supported_modes[i].hdr_mode) {
2549
- imx415->cur_mode = &supported_modes[i];
2957
+ if (hdr_mode == imx415->supported_modes[i].hdr_mode) {
2958
+ imx415->cur_mode = &imx415->supported_modes[i];
25502959 break;
25512960 }
25522961 }
25532962
2554
- imx415->is_thunderboot = IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP);
2963
+ of_property_read_u32(node, RKMODULE_CAMERA_FASTBOOT_ENABLE,
2964
+ &imx415->is_thunderboot);
25552965
25562966 imx415->xvclk = devm_clk_get(dev, "xvclk");
25572967 if (IS_ERR(imx415->xvclk)) {