hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/media/i2c/sc3336.c
....@@ -26,6 +26,7 @@
2626 #include <media/v4l2-ctrls.h>
2727 #include <media/v4l2-subdev.h>
2828 #include <linux/pinctrl/consumer.h>
29
+#include "../platform/rockchip/isp/rkisp_tb_helper.h"
2930
3031 #define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x01)
3132
....@@ -35,11 +36,15 @@
3536
3637 #define SC3336_LANES 2
3738 #define SC3336_BITS_PER_SAMPLE 10
39
+#define SC3336_LINK_FREQ_253 253125000
3840 #define SC3336_LINK_FREQ_255 255000000
3941
42
+#define PIXEL_RATE_WITH_253M_10BIT (SC3336_LINK_FREQ_253 * 2 * \
43
+ SC3336_LANES / SC3336_BITS_PER_SAMPLE)
4044 #define PIXEL_RATE_WITH_255M_10BIT (SC3336_LINK_FREQ_255 * 2 * \
4145 SC3336_LANES / SC3336_BITS_PER_SAMPLE)
42
-#define SC3336_XVCLK_FREQ 24000000
46
+
47
+#define SC3336_XVCLK_FREQ 27000000
4348
4449 #define CHIP_ID 0xcc41
4550 #define SC3336_REG_CHIP_ID 0x3107
....@@ -110,14 +115,6 @@
110115 u8 val;
111116 };
112117
113
-enum sc3336_max_pad {
114
- PAD0,
115
- PAD1,
116
- PAD2,
117
- PAD3,
118
- PAD_MAX,
119
-};
120
-
121118 struct sc3336_mode {
122119 u32 bus_fmt;
123120 u32 width;
....@@ -128,6 +125,8 @@
128125 u32 exp_def;
129126 const struct regval *reg_list;
130127 u32 hdr_mode;
128
+ u32 xvclk_freq;
129
+ u32 link_freq_idx;
131130 u32 vc[PAD_MAX];
132131 };
133132
....@@ -150,8 +149,11 @@
150149 struct v4l2_ctrl *digi_gain;
151150 struct v4l2_ctrl *hblank;
152151 struct v4l2_ctrl *vblank;
152
+ struct v4l2_ctrl *pixel_rate;
153
+ struct v4l2_ctrl *link_freq;
153154 struct v4l2_ctrl *test_pattern;
154155 struct mutex mutex;
156
+ struct v4l2_fract cur_fps;
155157 bool streaming;
156158 bool power_on;
157159 const struct sc3336_mode *cur_mode;
....@@ -160,6 +162,10 @@
160162 const char *module_name;
161163 const char *len_name;
162164 u32 cur_vts;
165
+ bool has_init_exp;
166
+ bool is_thunderboot;
167
+ bool is_first_streamoff;
168
+ struct preisp_hdrae_exp_s init_hdrae_exp;
163169 };
164170
165171 #define to_sc3336(sd) container_of(sd, struct sc3336, subdev)
....@@ -172,11 +178,150 @@
172178 };
173179
174180 /*
181
+ * Xclk 27Mhz
182
+ * max_framerate 25fps
183
+ * mipi_datarate per lane 506.25Mbps, 2lane
184
+ */
185
+static const struct regval sc3336_linear_10_2304x1296_25fps_regs[] = {
186
+ {0x0103, 0x01},
187
+ {0x36e9, 0x80},
188
+ {0x37f9, 0x80},
189
+ {0x301f, 0x01},
190
+ {0x30b8, 0x33},
191
+ {0x320e, 0x06},
192
+ {0x320f, 0x54},
193
+ {0x3253, 0x10},
194
+ {0x325f, 0x20},
195
+ {0x3301, 0x04},
196
+ {0x3306, 0x50},
197
+ {0x3309, 0xa8},
198
+ {0x330a, 0x00},
199
+ {0x330b, 0xd8},
200
+ {0x3314, 0x13},
201
+ {0x331f, 0x99},
202
+ {0x3333, 0x10},
203
+ {0x3334, 0x40},
204
+ {0x335e, 0x06},
205
+ {0x335f, 0x0a},
206
+ {0x3364, 0x5e},
207
+ {0x337c, 0x02},
208
+ {0x337d, 0x0e},
209
+ {0x3390, 0x01},
210
+ {0x3391, 0x03},
211
+ {0x3392, 0x07},
212
+ {0x3393, 0x04},
213
+ {0x3394, 0x04},
214
+ {0x3395, 0x04},
215
+ {0x3396, 0x08},
216
+ {0x3397, 0x0b},
217
+ {0x3398, 0x1f},
218
+ {0x3399, 0x04},
219
+ {0x339a, 0x0a},
220
+ {0x339b, 0x3a},
221
+ {0x339c, 0xb4},
222
+ {0x33a2, 0x04},
223
+ {0x33ac, 0x08},
224
+ {0x33ad, 0x1c},
225
+ {0x33ae, 0x10},
226
+ {0x33af, 0x30},
227
+ {0x33b1, 0x80},
228
+ {0x33b3, 0x48},
229
+ {0x33f9, 0x60},
230
+ {0x33fb, 0x74},
231
+ {0x33fc, 0x4b},
232
+ {0x33fd, 0x5f},
233
+ {0x349f, 0x03},
234
+ {0x34a6, 0x4b},
235
+ {0x34a7, 0x5f},
236
+ {0x34a8, 0x20},
237
+ {0x34a9, 0x18},
238
+ {0x34ab, 0xe8},
239
+ {0x34ac, 0x01},
240
+ {0x34ad, 0x00},
241
+ {0x34f8, 0x5f},
242
+ {0x34f9, 0x18},
243
+ {0x3630, 0xc0},
244
+ {0x3631, 0x84},
245
+ {0x3632, 0x64},
246
+ {0x3633, 0x32},
247
+ {0x363b, 0x03},
248
+ {0x363c, 0x08},
249
+ {0x3641, 0x38},
250
+ {0x3670, 0x4e},
251
+ {0x3674, 0xc0},
252
+ {0x3675, 0xc0},
253
+ {0x3676, 0xc0},
254
+ {0x3677, 0x84},
255
+ {0x3678, 0x84},
256
+ {0x3679, 0x84},
257
+ {0x367c, 0x48},
258
+ {0x367d, 0x49},
259
+ {0x367e, 0x4b},
260
+ {0x367f, 0x5f},
261
+ {0x3690, 0x32},
262
+ {0x3691, 0x32},
263
+ {0x3692, 0x42},
264
+ {0x369c, 0x4b},
265
+ {0x369d, 0x5f},
266
+ {0x36b0, 0x87},
267
+ {0x36b1, 0x90},
268
+ {0x36b2, 0xa1},
269
+ {0x36b3, 0xd8},
270
+ {0x36b4, 0x49},
271
+ {0x36b5, 0x4b},
272
+ {0x36b6, 0x4f},
273
+ {0x370f, 0x01},
274
+ {0x3722, 0x09},
275
+ {0x3724, 0x41},
276
+ {0x3725, 0xc1},
277
+ {0x3771, 0x09},
278
+ {0x3772, 0x09},
279
+ {0x3773, 0x05},
280
+ {0x377a, 0x48},
281
+ {0x377b, 0x5f},
282
+ {0x3904, 0x04},
283
+ {0x3905, 0x8c},
284
+ {0x391d, 0x04},
285
+ {0x3921, 0x20},
286
+ {0x3926, 0x21},
287
+ {0x3933, 0x80},
288
+ {0x3934, 0x0a},
289
+ {0x3935, 0x00},
290
+ {0x3936, 0x2a},
291
+ {0x3937, 0x6a},
292
+ {0x3938, 0x6a},
293
+ {0x39dc, 0x02},
294
+ {0x3e01, 0x53},
295
+ {0x3e02, 0xe0},
296
+ {0x3e09, 0x00},
297
+ {0x440e, 0x02},
298
+ {0x4509, 0x20},
299
+ {0x5ae0, 0xfe},
300
+ {0x5ae1, 0x40},
301
+ {0x5ae2, 0x38},
302
+ {0x5ae3, 0x30},
303
+ {0x5ae4, 0x28},
304
+ {0x5ae5, 0x38},
305
+ {0x5ae6, 0x30},
306
+ {0x5ae7, 0x28},
307
+ {0x5ae8, 0x3f},
308
+ {0x5ae9, 0x34},
309
+ {0x5aea, 0x2c},
310
+ {0x5aeb, 0x3f},
311
+ {0x5aec, 0x34},
312
+ {0x5aed, 0x2c},
313
+ {0x36e9, 0x54},
314
+ {0x37f9, 0x27},
315
+ {0x3028, 0x05},
316
+ {REG_NULL, 0x00},
317
+};
318
+
319
+/*
175320 * Xclk 24Mhz
176321 * max_framerate 30fps
177322 * mipi_datarate per lane 510Mbps, 2lane
178323 */
179
-static const struct regval sc3336_linear_10_2304x1296_regs[] = {
324
+static const struct regval sc3336_linear_10_2304x1296_30fps_regs[] = {
180325 {0x0103, 0x01},
181326 {0x36e9, 0x80},
182327 {0x37f9, 0x80},
....@@ -321,20 +466,40 @@
321466 .height = 1296,
322467 .max_fps = {
323468 .numerator = 10000,
469
+ .denominator = 250000,
470
+ },
471
+ .exp_def = 0x0080,
472
+ .hts_def = 0x05dc,
473
+ .vts_def = 0x0654,
474
+ .bus_fmt = MEDIA_BUS_FMT_SBGGR10_1X10,
475
+ .reg_list = sc3336_linear_10_2304x1296_25fps_regs,
476
+ .hdr_mode = NO_HDR,
477
+ .xvclk_freq = 27000000,
478
+ .link_freq_idx = 0,
479
+ .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
480
+ },
481
+ {
482
+ .width = 2304,
483
+ .height = 1296,
484
+ .max_fps = {
485
+ .numerator = 10000,
324486 .denominator = 300000,
325487 },
326488 .exp_def = 0x0080,
327489 .hts_def = 0x0578 * 2,
328490 .vts_def = 0x0550,
329491 .bus_fmt = MEDIA_BUS_FMT_SBGGR10_1X10,
330
- .reg_list = sc3336_linear_10_2304x1296_regs,
492
+ .reg_list = sc3336_linear_10_2304x1296_30fps_regs,
331493 .hdr_mode = NO_HDR,
494
+ .xvclk_freq = 24000000,
495
+ .link_freq_idx = 1,
332496 .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
333497 }
334498 };
335499
336500 static const s64 link_freq_menu_items[] = {
337
- SC3336_LINK_FREQ_255
501
+ SC3336_LINK_FREQ_253,
502
+ SC3336_LINK_FREQ_255,
338503 };
339504
340505 static const char * const sc3336_test_pattern_menu[] = {
....@@ -342,7 +507,7 @@
342507 "Vertical Color Bar Type 1",
343508 "Vertical Color Bar Type 2",
344509 "Vertical Color Bar Type 3",
345
- "Vertical Color Bar Type 4"
510
+ "Vertical Color Bar Type 4",
346511 };
347512
348513 /* Write registers up to 4 at a time */
....@@ -423,9 +588,9 @@
423588
424589 static int sc3336_set_gain_reg(struct sc3336 *sc3336, u32 gain)
425590 {
426
- u32 coarse_again = 0, coarse_dgian = 0, fine_dgian = 0;
427
- u32 gain_factor;
428
- int ret = 0;
591
+ struct i2c_client *client = sc3336->client;
592
+ u32 coarse_again = 0, coarse_dgain = 0, fine_dgain = 0;
593
+ int ret = 0, gain_factor;
429594
430595 if (gain < 128)
431596 gain = 128;
....@@ -435,55 +600,57 @@
435600 gain_factor = gain * 1000 / 128;
436601 if (gain_factor < 1520) {
437602 coarse_again = 0x00;
438
- coarse_dgian = 0x00;
439
- fine_dgian = gain_factor * 128 / 1000;
603
+ coarse_dgain = 0x00;
604
+ fine_dgain = gain_factor * 128 / 1000;
440605 } else if (gain_factor < 3040) {
441606 coarse_again = 0x40;
442
- coarse_dgian = 0x00;
443
- fine_dgian = gain_factor * 128 / 1520;
607
+ coarse_dgain = 0x00;
608
+ fine_dgain = gain_factor * 128 / 1520;
444609 } else if (gain_factor < 6080) {
445610 coarse_again = 0x48;
446
- coarse_dgian = 0x00;
447
- fine_dgian = gain_factor * 128 / 3040;
611
+ coarse_dgain = 0x00;
612
+ fine_dgain = gain_factor * 128 / 3040;
448613 } else if (gain_factor < 12160) {
449614 coarse_again = 0x49;
450
- coarse_dgian = 0x00;
451
- fine_dgian = gain_factor * 128 / 6080;
615
+ coarse_dgain = 0x00;
616
+ fine_dgain = gain_factor * 128 / 6080;
452617 } else if (gain_factor < 24320) {
453618 coarse_again = 0x4b;
454
- coarse_dgian = 0x00;
455
- fine_dgian = gain_factor * 128 / 12160;
619
+ coarse_dgain = 0x00;
620
+ fine_dgain = gain_factor * 128 / 12160;
456621 } else if (gain_factor < 48640) {
457622 coarse_again = 0x4f;
458
- coarse_dgian = 0x00;
459
- fine_dgian = gain_factor * 128 / 24320;
623
+ coarse_dgain = 0x00;
624
+ fine_dgain = gain_factor * 128 / 24320;
460625 } else if (gain_factor < 48640 * 2) {
461626 //open dgain begin max digital gain 4X
462627 coarse_again = 0x5f;
463
- coarse_dgian = 0x00;
464
- fine_dgian = gain_factor * 128 / 48640;
628
+ coarse_dgain = 0x00;
629
+ fine_dgain = gain_factor * 128 / 48640;
465630 } else if (gain_factor < 48640 * 4) {
466631 coarse_again = 0x5f;
467
- coarse_dgian = 0x01;
468
- fine_dgian = gain_factor * 128 / 48640 / 2;
632
+ coarse_dgain = 0x01;
633
+ fine_dgain = gain_factor * 128 / 48640 / 2;
469634 } else if (gain_factor < 48640 * 8) {
470635 coarse_again = 0x5f;
471
- coarse_dgian = 0x03;
472
- fine_dgian = gain_factor * 128 / 48640 / 4;
636
+ coarse_dgain = 0x03;
637
+ fine_dgain = gain_factor * 128 / 48640 / 4;
473638 } else if (gain_factor < 48640 * 16) {
474639 coarse_again = 0x5f;
475
- coarse_dgian = 0x07;
476
- fine_dgian = gain_factor * 128 / 48640 / 8;
640
+ coarse_dgain = 0x07;
641
+ fine_dgain = gain_factor * 128 / 48640 / 8;
477642 }
643
+ dev_dbg(&client->dev, "c_again: 0x%x, c_dgain: 0x%x, f_dgain: 0x%0x\n",
644
+ coarse_again, coarse_dgain, fine_dgain);
478645
479646 ret = sc3336_write_reg(sc3336->client,
480647 SC3336_REG_DIG_GAIN,
481648 SC3336_REG_VALUE_08BIT,
482
- coarse_dgian);
649
+ coarse_dgain);
483650 ret |= sc3336_write_reg(sc3336->client,
484651 SC3336_REG_DIG_FINE_GAIN,
485652 SC3336_REG_VALUE_08BIT,
486
- fine_dgian);
653
+ fine_dgain);
487654 ret |= sc3336_write_reg(sc3336->client,
488655 SC3336_REG_ANA_GAIN,
489656 SC3336_REG_VALUE_08BIT,
....@@ -526,6 +693,8 @@
526693 struct sc3336 *sc3336 = to_sc3336(sd);
527694 const struct sc3336_mode *mode;
528695 s64 h_blank, vblank_def;
696
+ u64 dst_link_freq = 0;
697
+ u64 dst_pixel_rate = 0;
529698
530699 mutex_lock(&sc3336->mutex);
531700
....@@ -550,6 +719,14 @@
550719 __v4l2_ctrl_modify_range(sc3336->vblank, vblank_def,
551720 SC3336_VTS_MAX - mode->height,
552721 1, vblank_def);
722
+ dst_link_freq = mode->link_freq_idx;
723
+ dst_pixel_rate = (u32)link_freq_menu_items[mode->link_freq_idx] /
724
+ SC3336_BITS_PER_SAMPLE * 2 * SC3336_LANES;
725
+ __v4l2_ctrl_s_ctrl_int64(sc3336->pixel_rate,
726
+ dst_pixel_rate);
727
+ __v4l2_ctrl_s_ctrl(sc3336->link_freq,
728
+ dst_link_freq);
729
+ sc3336->cur_fps = mode->max_fps;
553730 }
554731
555732 mutex_unlock(&sc3336->mutex);
....@@ -642,18 +819,20 @@
642819 struct sc3336 *sc3336 = to_sc3336(sd);
643820 const struct sc3336_mode *mode = sc3336->cur_mode;
644821
645
- mutex_lock(&sc3336->mutex);
646
- fi->interval = mode->max_fps;
647
- mutex_unlock(&sc3336->mutex);
648
-
822
+ if (sc3336->streaming)
823
+ fi->interval = sc3336->cur_fps;
824
+ else
825
+ fi->interval = mode->max_fps;
649826 return 0;
650827 }
651828
652829 static int sc3336_g_mbus_config(struct v4l2_subdev *sd,
830
+ unsigned int pad_id,
653831 struct v4l2_mbus_config *config)
654832 {
655833 struct sc3336 *sc3336 = to_sc3336(sd);
656834 const struct sc3336_mode *mode = sc3336->cur_mode;
835
+
657836 u32 val = 1 << (SC3336_LANES - 1) |
658837 V4L2_MBUS_CSI2_CHANNEL_0 |
659838 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
....@@ -663,7 +842,7 @@
663842 if (mode->hdr_mode == HDR_X3)
664843 val |= V4L2_MBUS_CSI2_CHANNEL_2;
665844
666
- config->type = V4L2_MBUS_CSI2;
845
+ config->type = V4L2_MBUS_CSI2_DPHY;
667846 config->flags = val;
668847
669848 return 0;
....@@ -719,6 +898,7 @@
719898 __v4l2_ctrl_modify_range(sc3336->hblank, w, w, 1, w);
720899 __v4l2_ctrl_modify_range(sc3336->vblank, h,
721900 SC3336_VTS_MAX - sc3336->cur_mode->height, 1, h);
901
+ sc3336->cur_fps = sc3336->cur_mode->max_fps;
722902 }
723903 break;
724904 case PREISP_CMD_SET_HDRAE_EXP:
....@@ -830,25 +1010,39 @@
8301010 {
8311011 int ret;
8321012
833
- ret = sc3336_write_array(sc3336->client, sc3336->cur_mode->reg_list);
834
- if (ret)
835
- return ret;
836
-
837
- /* In case these controls are set before streaming */
838
- ret = __v4l2_ctrl_handler_setup(&sc3336->ctrl_handler);
839
- if (ret)
840
- return ret;
841
-
842
- return sc3336_write_reg(sc3336->client, SC3336_REG_CTRL_MODE,
1013
+ if (!sc3336->is_thunderboot) {
1014
+ ret = sc3336_write_array(sc3336->client, sc3336->cur_mode->reg_list);
1015
+ if (ret)
1016
+ return ret;
1017
+ /* In case these controls are set before streaming */
1018
+ ret = __v4l2_ctrl_handler_setup(&sc3336->ctrl_handler);
1019
+ if (ret)
1020
+ return ret;
1021
+ if (sc3336->has_init_exp && sc3336->cur_mode->hdr_mode != NO_HDR) {
1022
+ ret = sc3336_ioctl(&sc3336->subdev, PREISP_CMD_SET_HDRAE_EXP,
1023
+ &sc3336->init_hdrae_exp);
1024
+ if (ret) {
1025
+ dev_err(&sc3336->client->dev,
1026
+ "init exp fail in hdr mode\n");
1027
+ return ret;
1028
+ }
1029
+ }
1030
+ }
1031
+ ret = sc3336_write_reg(sc3336->client, SC3336_REG_CTRL_MODE,
8431032 SC3336_REG_VALUE_08BIT, SC3336_MODE_STREAMING);
1033
+ return ret;
8441034 }
8451035
8461036 static int __sc3336_stop_stream(struct sc3336 *sc3336)
8471037 {
1038
+ sc3336->has_init_exp = false;
1039
+ if (sc3336->is_thunderboot)
1040
+ sc3336->is_first_streamoff = true;
8481041 return sc3336_write_reg(sc3336->client, SC3336_REG_CTRL_MODE,
8491042 SC3336_REG_VALUE_08BIT, SC3336_MODE_SW_STANDBY);
8501043 }
8511044
1045
+static int __sc3336_power_on(struct sc3336 *sc3336);
8521046 static int sc3336_s_stream(struct v4l2_subdev *sd, int on)
8531047 {
8541048 struct sc3336 *sc3336 = to_sc3336(sd);
....@@ -859,14 +1053,16 @@
8591053 on = !!on;
8601054 if (on == sc3336->streaming)
8611055 goto unlock_and_return;
862
-
8631056 if (on) {
1057
+ if (sc3336->is_thunderboot && rkisp_tb_get_state() == RKISP_TB_NG) {
1058
+ sc3336->is_thunderboot = false;
1059
+ __sc3336_power_on(sc3336);
1060
+ }
8641061 ret = pm_runtime_get_sync(&client->dev);
8651062 if (ret < 0) {
8661063 pm_runtime_put_noidle(&client->dev);
8671064 goto unlock_and_return;
8681065 }
869
-
8701066 ret = __sc3336_start_stream(sc3336);
8711067 if (ret) {
8721068 v4l2_err(sd, "start stream failed while write regs\n");
....@@ -879,10 +1075,8 @@
8791075 }
8801076
8811077 sc3336->streaming = on;
882
-
8831078 unlock_and_return:
8841079 mutex_unlock(&sc3336->mutex);
885
-
8861080 return ret;
8871081 }
8881082
....@@ -905,11 +1099,13 @@
9051099 goto unlock_and_return;
9061100 }
9071101
908
- ret = sc3336_write_array(sc3336->client, sc3336_global_regs);
909
- if (ret) {
910
- v4l2_err(sd, "could not set init registers\n");
911
- pm_runtime_put_noidle(&client->dev);
912
- goto unlock_and_return;
1102
+ if (!sc3336->is_thunderboot) {
1103
+ ret = sc3336_write_array(sc3336->client, sc3336_global_regs);
1104
+ if (ret) {
1105
+ v4l2_err(sd, "could not set init registers\n");
1106
+ pm_runtime_put_noidle(&client->dev);
1107
+ goto unlock_and_return;
1108
+ }
9131109 }
9141110
9151111 sc3336->power_on = true;
....@@ -925,9 +1121,9 @@
9251121 }
9261122
9271123 /* Calculate the delay in us by clock rate and clock cycles */
928
-static inline u32 sc3336_cal_delay(u32 cycles)
1124
+static inline u32 sc3336_cal_delay(u32 cycles, struct sc3336 *sc3336)
9291125 {
930
- return DIV_ROUND_UP(cycles, SC3336_XVCLK_FREQ / 1000 / 1000);
1126
+ return DIV_ROUND_UP(cycles, sc3336->cur_mode->xvclk_freq / 1000 / 1000);
9311127 }
9321128
9331129 static int __sc3336_power_on(struct sc3336 *sc3336)
....@@ -942,16 +1138,21 @@
9421138 if (ret < 0)
9431139 dev_err(dev, "could not set pins\n");
9441140 }
945
- ret = clk_set_rate(sc3336->xvclk, SC3336_XVCLK_FREQ);
1141
+ ret = clk_set_rate(sc3336->xvclk, sc3336->cur_mode->xvclk_freq);
9461142 if (ret < 0)
947
- dev_warn(dev, "Failed to set xvclk rate (24MHz)\n");
948
- if (clk_get_rate(sc3336->xvclk) != SC3336_XVCLK_FREQ)
949
- dev_warn(dev, "xvclk mismatched, modes are based on 24MHz\n");
1143
+ dev_warn(dev, "Failed to set xvclk rate (%dHz)\n", sc3336->cur_mode->xvclk_freq);
1144
+ if (clk_get_rate(sc3336->xvclk) != sc3336->cur_mode->xvclk_freq)
1145
+ dev_warn(dev, "xvclk mismatched, modes are based on %dHz\n",
1146
+ sc3336->cur_mode->xvclk_freq);
9501147 ret = clk_prepare_enable(sc3336->xvclk);
9511148 if (ret < 0) {
9521149 dev_err(dev, "Failed to enable xvclk\n");
9531150 return ret;
9541151 }
1152
+
1153
+ if (sc3336->is_thunderboot)
1154
+ return 0;
1155
+
9551156 if (!IS_ERR(sc3336->reset_gpio))
9561157 gpiod_set_value_cansleep(sc3336->reset_gpio, 0);
9571158
....@@ -965,6 +1166,7 @@
9651166 gpiod_set_value_cansleep(sc3336->reset_gpio, 1);
9661167
9671168 usleep_range(500, 1000);
1169
+
9681170 if (!IS_ERR(sc3336->pwdn_gpio))
9691171 gpiod_set_value_cansleep(sc3336->pwdn_gpio, 1);
9701172
....@@ -974,7 +1176,7 @@
9741176 usleep_range(12000, 16000);
9751177
9761178 /* 8192 cycles prior to first SCCB transaction */
977
- delay_us = sc3336_cal_delay(8192);
1179
+ delay_us = sc3336_cal_delay(8192, sc3336);
9781180 usleep_range(delay_us, delay_us * 2);
9791181
9801182 return 0;
....@@ -990,6 +1192,16 @@
9901192 int ret;
9911193 struct device *dev = &sc3336->client->dev;
9921194
1195
+ clk_disable_unprepare(sc3336->xvclk);
1196
+ if (sc3336->is_thunderboot) {
1197
+ if (sc3336->is_first_streamoff) {
1198
+ sc3336->is_thunderboot = false;
1199
+ sc3336->is_first_streamoff = false;
1200
+ } else {
1201
+ return;
1202
+ }
1203
+ }
1204
+
9931205 if (!IS_ERR(sc3336->pwdn_gpio))
9941206 gpiod_set_value_cansleep(sc3336->pwdn_gpio, 0);
9951207 clk_disable_unprepare(sc3336->xvclk);
....@@ -1004,7 +1216,7 @@
10041216 regulator_bulk_disable(SC3336_NUM_SUPPLIES, sc3336->supplies);
10051217 }
10061218
1007
-static int sc3336_runtime_resume(struct device *dev)
1219
+static int __maybe_unused sc3336_runtime_resume(struct device *dev)
10081220 {
10091221 struct i2c_client *client = to_i2c_client(dev);
10101222 struct v4l2_subdev *sd = i2c_get_clientdata(client);
....@@ -1013,7 +1225,7 @@
10131225 return __sc3336_power_on(sc3336);
10141226 }
10151227
1016
-static int sc3336_runtime_suspend(struct device *dev)
1228
+static int __maybe_unused sc3336_runtime_suspend(struct device *dev)
10171229 {
10181230 struct i2c_client *client = to_i2c_client(dev);
10191231 struct v4l2_subdev *sd = i2c_get_clientdata(client);
....@@ -1061,36 +1273,6 @@
10611273 return 0;
10621274 }
10631275
1064
-#define CROP_START(SRC, DST) (((SRC) - (DST)) / 2 / 4 * 4)
1065
-#define DST_WIDTH 1920
1066
-#define DST_HEIGHT 1080
1067
-
1068
-/*
1069
- * The resolution of the driver configuration needs to be exactly
1070
- * the same as the current output resolution of the sensor,
1071
- * the input width of the isp needs to be 16 aligned,
1072
- * the input height of the isp needs to be 8 aligned.
1073
- * Can be cropped to standard resolution by this function,
1074
- * otherwise it will crop out strange resolution according
1075
- * to the alignment rules.
1076
- */
1077
-
1078
-static int sc3336_get_selection(struct v4l2_subdev *sd,
1079
- struct v4l2_subdev_pad_config *cfg,
1080
- struct v4l2_subdev_selection *sel)
1081
-{
1082
- struct sc3336 *sc3336 = to_sc3336(sd);
1083
-
1084
- if (sel->target == V4L2_SEL_TGT_CROP_BOUNDS) {
1085
- sel->r.left = CROP_START(sc3336->cur_mode->width, DST_WIDTH);
1086
- sel->r.width = DST_WIDTH;
1087
- sel->r.top = CROP_START(sc3336->cur_mode->height, DST_HEIGHT);
1088
- sel->r.height = DST_HEIGHT;
1089
- return 0;
1090
- }
1091
- return -EINVAL;
1092
-}
1093
-
10941276 static const struct dev_pm_ops sc3336_pm_ops = {
10951277 SET_RUNTIME_PM_OPS(sc3336_runtime_suspend,
10961278 sc3336_runtime_resume, NULL)
....@@ -1113,7 +1295,6 @@
11131295 static const struct v4l2_subdev_video_ops sc3336_video_ops = {
11141296 .s_stream = sc3336_s_stream,
11151297 .g_frame_interval = sc3336_g_frame_interval,
1116
- .g_mbus_config = sc3336_g_mbus_config,
11171298 };
11181299
11191300 static const struct v4l2_subdev_pad_ops sc3336_pad_ops = {
....@@ -1122,7 +1303,7 @@
11221303 .enum_frame_interval = sc3336_enum_frame_interval,
11231304 .get_fmt = sc3336_get_fmt,
11241305 .set_fmt = sc3336_set_fmt,
1125
- .get_selection = sc3336_get_selection,
1306
+ .get_mbus_config = sc3336_g_mbus_config,
11261307 };
11271308
11281309 static const struct v4l2_subdev_ops sc3336_subdev_ops = {
....@@ -1130,6 +1311,14 @@
11301311 .video = &sc3336_video_ops,
11311312 .pad = &sc3336_pad_ops,
11321313 };
1314
+
1315
+static void sc3336_modify_fps_info(struct sc3336 *sc3336)
1316
+{
1317
+ const struct sc3336_mode *mode = sc3336->cur_mode;
1318
+
1319
+ sc3336->cur_fps.denominator = mode->max_fps.denominator * mode->vts_def /
1320
+ sc3336->cur_vts;
1321
+}
11331322
11341323 static int sc3336_set_ctrl(struct v4l2_ctrl *ctrl)
11351324 {
....@@ -1193,6 +1382,7 @@
11931382 (ctrl->val + sc3336->cur_mode->height)
11941383 & 0xff);
11951384 sc3336->cur_vts = ctrl->val + sc3336->cur_mode->height;
1385
+ sc3336_modify_fps_info(sc3336);
11961386 break;
11971387 case V4L2_CID_TEST_PATTERN:
11981388 ret = sc3336_enable_test_pattern(sc3336, ctrl->val);
....@@ -1230,10 +1420,11 @@
12301420 {
12311421 const struct sc3336_mode *mode;
12321422 struct v4l2_ctrl_handler *handler;
1233
- struct v4l2_ctrl *ctrl;
12341423 s64 exposure_max, vblank_def;
12351424 u32 h_blank;
12361425 int ret;
1426
+ u64 dst_link_freq = 0;
1427
+ u64 dst_pixel_rate = 0;
12371428
12381429 handler = &sc3336->ctrl_handler;
12391430 mode = sc3336->cur_mode;
....@@ -1242,13 +1433,19 @@
12421433 return ret;
12431434 handler->lock = &sc3336->mutex;
12441435
1245
- ctrl = v4l2_ctrl_new_int_menu(handler, NULL, V4L2_CID_LINK_FREQ,
1246
- 0, 0, link_freq_menu_items);
1247
- if (ctrl)
1248
- ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1436
+ sc3336->link_freq = v4l2_ctrl_new_int_menu(handler, NULL,
1437
+ V4L2_CID_LINK_FREQ,
1438
+ ARRAY_SIZE(link_freq_menu_items) - 1, 0, link_freq_menu_items);
1439
+ if (sc3336->link_freq)
1440
+ sc3336->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
12491441
1250
- v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE,
1251
- 0, PIXEL_RATE_WITH_255M_10BIT, 1, PIXEL_RATE_WITH_255M_10BIT);
1442
+ dst_link_freq = mode->link_freq_idx;
1443
+ dst_pixel_rate = (u32)link_freq_menu_items[mode->link_freq_idx] /
1444
+ SC3336_BITS_PER_SAMPLE * 2 * SC3336_LANES;
1445
+ sc3336->pixel_rate = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE,
1446
+ 0, PIXEL_RATE_WITH_255M_10BIT, 1, dst_pixel_rate);
1447
+
1448
+ __v4l2_ctrl_s_ctrl(sc3336->link_freq, dst_link_freq);
12521449
12531450 h_blank = mode->hts_def - mode->width;
12541451 sc3336->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK,
....@@ -1286,6 +1483,8 @@
12861483 }
12871484
12881485 sc3336->subdev.ctrl_handler = handler;
1486
+ sc3336->has_init_exp = false;
1487
+ sc3336->cur_fps = mode->max_fps;
12891488
12901489 return 0;
12911490
....@@ -1301,6 +1500,11 @@
13011500 struct device *dev = &sc3336->client->dev;
13021501 u32 id = 0;
13031502 int ret;
1503
+
1504
+ if (sc3336->is_thunderboot) {
1505
+ dev_info(dev, "Enable thunderboot mode, skip sensor id check\n");
1506
+ return 0;
1507
+ }
13041508
13051509 ret = sc3336_read_reg(client, SC3336_REG_CHIP_ID,
13061510 SC3336_REG_VALUE_16BIT, &id);
....@@ -1335,6 +1539,7 @@
13351539 struct v4l2_subdev *sd;
13361540 char facing[2];
13371541 int ret;
1542
+ int i, hdr_mode = 0;
13381543
13391544 dev_info(dev, "driver version: %02x.%02x.%02x",
13401545 DRIVER_VERSION >> 16,
....@@ -1358,8 +1563,17 @@
13581563 return -EINVAL;
13591564 }
13601565
1566
+ sc3336->is_thunderboot = IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP);
1567
+
13611568 sc3336->client = client;
1362
- sc3336->cur_mode = &supported_modes[0];
1569
+ for (i = 0; i < ARRAY_SIZE(supported_modes); i++) {
1570
+ if (hdr_mode == supported_modes[i].hdr_mode) {
1571
+ sc3336->cur_mode = &supported_modes[i];
1572
+ break;
1573
+ }
1574
+ }
1575
+ if (i == ARRAY_SIZE(supported_modes))
1576
+ sc3336->cur_mode = &supported_modes[0];
13631577
13641578 sc3336->xvclk = devm_clk_get(dev, "xvclk");
13651579 if (IS_ERR(sc3336->xvclk)) {
....@@ -1367,11 +1581,17 @@
13671581 return -EINVAL;
13681582 }
13691583
1370
- sc3336->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
1584
+ if (!sc3336->is_thunderboot)
1585
+ sc3336->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
1586
+ else
1587
+ sc3336->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS);
13711588 if (IS_ERR(sc3336->reset_gpio))
13721589 dev_warn(dev, "Failed to get reset-gpios\n");
13731590
1374
- sc3336->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW);
1591
+ if (!sc3336->is_thunderboot)
1592
+ sc3336->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW);
1593
+ else
1594
+ sc3336->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_ASIS);
13751595 if (IS_ERR(sc3336->pwdn_gpio))
13761596 dev_warn(dev, "Failed to get pwdn-gpios\n");
13771597
....@@ -1516,8 +1736,12 @@
15161736 i2c_del_driver(&sc3336_i2c_driver);
15171737 }
15181738
1739
+#if defined(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP) && !defined(CONFIG_INITCALL_ASYNC)
1740
+subsys_initcall(sensor_mod_init);
1741
+#else
15191742 device_initcall_sync(sensor_mod_init);
1743
+#endif
15201744 module_exit(sensor_mod_exit);
15211745
15221746 MODULE_DESCRIPTION("smartsens sc3336 sensor driver");
1523
-MODULE_LICENSE("GPL");
1747
+MODULE_LICENSE("GPL v2");