hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/media/i2c/sc301iot.c
....@@ -1,6 +1,6 @@
11 // SPDX-License-Identifier: GPL-2.0
22 /*
3
- * SC301IOT driver
3
+ * sc301iot driver
44 *
55 * Copyright (C) 2022 Fuzhou Rockchip Electronics Co., Ltd.
66 *
....@@ -110,7 +110,7 @@
110110 #define OF_CAMERA_PINCTRL_STATE_DEFAULT "rockchip,camera_default"
111111 #define OF_CAMERA_PINCTRL_STATE_SLEEP "rockchip,camera_sleep"
112112 #define OF_CAMERA_HDR_MODE "rockchip,camera-hdr-mode"
113
-#define SC301IOT_NAME "SC301IOT"
113
+#define SC301IOT_NAME "sc301iot"
114114
115115 static const char * const SC301IOT_supply_names[] = {
116116 "avdd", /* Analog power */
....@@ -125,7 +125,7 @@
125125 u8 val;
126126 };
127127
128
-struct SC301IOT_mode {
128
+struct sc301iot_mode {
129129 u32 bus_fmt;
130130 u32 width;
131131 u32 height;
....@@ -138,7 +138,7 @@
138138 u32 vc[PAD_MAX];
139139 };
140140
141
-struct SC301IOT {
141
+struct sc301iot {
142142 struct i2c_client *client;
143143 struct clk *xvclk;
144144 struct gpio_desc *reset_gpio;
....@@ -162,7 +162,7 @@
162162 struct v4l2_fract cur_fps;
163163 bool streaming;
164164 bool power_on;
165
- const struct SC301IOT_mode *cur_mode;
165
+ const struct sc301iot_mode *cur_mode;
166166 u32 module_index;
167167 const char *module_facing;
168168 const char *module_name;
....@@ -175,12 +175,12 @@
175175 u32 sync_mode;
176176 };
177177
178
-#define to_SC301IOT(sd) container_of(sd, struct SC301IOT, subdev)
178
+#define to_sc301iot(sd) container_of(sd, struct sc301iot, subdev)
179179
180180 /*
181181 * Xclk 24Mhz
182182 */
183
-static const struct regval SC301IOT_global_regs[] = {
183
+static const struct regval sc301iot_global_regs[] = {
184184 {REG_NULL, 0x00},
185185 };
186186
....@@ -189,7 +189,7 @@
189189 * max_framerate 30fps
190190 * mipi_datarate per lane 540Mbps, 2lane
191191 */
192
-static const struct regval SC301IOT_linear_10_2048x1536_regs[] = {
192
+static const struct regval sc301iot_linear_10_2048x1536_regs[] = {
193193 {0x0103, 0x01},
194194 {0x0100, 0x00},
195195 {0x36e9, 0x80},
....@@ -344,7 +344,7 @@
344344 * max_framerate 30fps
345345 * mipi_datarate per lane 1080Mbps, HDR 2lane
346346 */
347
-static const struct regval SC301IOT_hdr_10_2048x1536_regs[] = {
347
+static const struct regval sc301iot_hdr_10_2048x1536_regs[] = {
348348 {0x0103, 0x01},
349349 {0x0100, 0x00},
350350 {0x36e9, 0x80},
....@@ -508,7 +508,7 @@
508508 * max_framerate 30fps
509509 * mipi_datarate per lane 540Mbps, 2lane
510510 */
511
-static const struct regval SC301IOT_linear_10_1536x1536_regs[] = {
511
+static const struct regval sc301iot_linear_10_1536x1536_regs[] = {
512512 {0x0103, 0x01},
513513 {0x0100, 0x00},
514514 {0x36e9, 0x80},
....@@ -664,7 +664,7 @@
664664 * max_framerate 30fps
665665 * mipi_datarate per lane 1080Mbps, HDR 2lane
666666 */
667
-static const struct regval SC301IOT_hdr_10_1536x1536_regs[] = {
667
+static const struct regval sc301iot_hdr_10_1536x1536_regs[] = {
668668 {0x0103, 0x01},
669669 {0x0100, 0x00},
670670 {0x36e9, 0x80},
....@@ -824,7 +824,7 @@
824824 {REG_NULL, 0x00},
825825 };
826826
827
-static const struct SC301IOT_mode supported_modes[] = {
827
+static const struct sc301iot_mode supported_modes[] = {
828828 {
829829 .width = 2048,
830830 .height = 1536,
....@@ -836,7 +836,7 @@
836836 .hts_def = 0x8ca,
837837 .vts_def = 0x640,
838838 .bus_fmt = MEDIA_BUS_FMT_SBGGR10_1X10,
839
- .reg_list = SC301IOT_linear_10_2048x1536_regs,
839
+ .reg_list = sc301iot_linear_10_2048x1536_regs,
840840 .hdr_mode = NO_HDR,
841841 .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
842842 }, {
....@@ -850,7 +850,7 @@
850850 .hts_def = 0x8ca,
851851 .vts_def = 0xc80,
852852 .bus_fmt = MEDIA_BUS_FMT_SBGGR10_1X10,
853
- .reg_list = SC301IOT_hdr_10_2048x1536_regs,
853
+ .reg_list = sc301iot_hdr_10_2048x1536_regs,
854854 .hdr_mode = HDR_X2,
855855 .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_1,
856856 .vc[PAD1] = V4L2_MBUS_CSI2_CHANNEL_0,//L->csi wr0
....@@ -867,7 +867,7 @@
867867 .hts_def = 0x8ca,
868868 .vts_def = 0x640,
869869 .bus_fmt = MEDIA_BUS_FMT_SBGGR10_1X10,
870
- .reg_list = SC301IOT_linear_10_1536x1536_regs,
870
+ .reg_list = sc301iot_linear_10_1536x1536_regs,
871871 .hdr_mode = NO_HDR,
872872 .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
873873 }, {
....@@ -881,7 +881,7 @@
881881 .hts_def = 0x8ca,
882882 .vts_def = 0xc80,
883883 .bus_fmt = MEDIA_BUS_FMT_SBGGR10_1X10,
884
- .reg_list = SC301IOT_hdr_10_1536x1536_regs,
884
+ .reg_list = sc301iot_hdr_10_1536x1536_regs,
885885 .hdr_mode = HDR_X2,
886886 .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_1,
887887 .vc[PAD1] = V4L2_MBUS_CSI2_CHANNEL_0,//L->csi wr0
....@@ -894,7 +894,7 @@
894894 SC301IOT_LINK_FREQ_594
895895 };
896896
897
-static const char * const SC301IOT_test_pattern_menu[] = {
897
+static const char * const sc301iot_test_pattern_menu[] = {
898898 "Disabled",
899899 "Vertical Color Bar Type 1",
900900 "Vertical Color Bar Type 2",
....@@ -903,7 +903,7 @@
903903 };
904904
905905 /* Write registers up to 4 at a time */
906
-static int SC301IOT_write_reg(struct i2c_client *client, u16 reg,
906
+static int sc301iot_write_reg(struct i2c_client *client, u16 reg,
907907 u32 len, u32 val)
908908 {
909909 u32 buf_i, val_i;
....@@ -931,21 +931,21 @@
931931 return 0;
932932 }
933933
934
-static int SC301IOT_write_array(struct i2c_client *client,
934
+static int sc301iot_write_array(struct i2c_client *client,
935935 const struct regval *regs)
936936 {
937937 u32 i;
938938 int ret = 0;
939939
940940 for (i = 0; ret == 0 && regs[i].addr != REG_NULL; i++)
941
- ret = SC301IOT_write_reg(client, regs[i].addr,
941
+ ret = sc301iot_write_reg(client, regs[i].addr,
942942 SC301IOT_REG_VALUE_08BIT, regs[i].val);
943943
944944 return ret;
945945 }
946946
947947 /* Read registers up to 4 at a time */
948
-static int SC301IOT_read_reg(struct i2c_client *client, u16 reg, unsigned int len,
948
+static int sc301iot_read_reg(struct i2c_client *client, u16 reg, unsigned int len,
949949 u32 *val)
950950 {
951951 struct i2c_msg msgs[2];
....@@ -983,7 +983,7 @@
983983
984984
985985 /* mode: 0 = lgain 1 = sgain */
986
-static int SC301IOT_set_gain_reg(struct SC301IOT *SC301IOT, u32 gain, int mode)
986
+static int sc301iot_set_gain_reg(struct sc301iot *sc301iot, u32 gain, int mode)
987987 {
988988 u8 ANA_Coarse_gain_reg = 0x00, DIG_Fine_gain_reg = 0x80;
989989 u32 ANA_Coarse_gain = 1024, DIG_gain_reg = 0x00;
....@@ -1026,28 +1026,28 @@
10261026 DIG_Fine_gain_reg = gain/8;
10271027
10281028 if (mode == SC301IOT_LGAIN) {
1029
- ret = SC301IOT_write_reg(SC301IOT->client,
1029
+ ret = sc301iot_write_reg(sc301iot->client,
10301030 SC301IOT_REG_DIG_GAIN,
10311031 SC301IOT_REG_VALUE_08BIT,
10321032 DIG_gain_reg & 0xF);
1033
- ret |= SC301IOT_write_reg(SC301IOT->client,
1033
+ ret |= sc301iot_write_reg(sc301iot->client,
10341034 SC301IOT_REG_DIG_FINE_GAIN,
10351035 SC301IOT_REG_VALUE_08BIT,
10361036 DIG_Fine_gain_reg);
1037
- ret |= SC301IOT_write_reg(SC301IOT->client,
1037
+ ret |= sc301iot_write_reg(sc301iot->client,
10381038 SC301IOT_REG_ANA_GAIN,
10391039 SC301IOT_REG_VALUE_08BIT,
10401040 ANA_Coarse_gain_reg);
10411041 } else {
1042
- ret = SC301IOT_write_reg(SC301IOT->client,
1042
+ ret = sc301iot_write_reg(sc301iot->client,
10431043 SC301IOT_REG_SDIG_GAIN,
10441044 SC301IOT_REG_VALUE_08BIT,
10451045 DIG_gain_reg & 0xF);
1046
- ret |= SC301IOT_write_reg(SC301IOT->client,
1046
+ ret |= sc301iot_write_reg(sc301iot->client,
10471047 SC301IOT_REG_SDIG_FINE_GAIN,
10481048 SC301IOT_REG_VALUE_08BIT,
10491049 DIG_Fine_gain_reg);
1050
- ret |= SC301IOT_write_reg(SC301IOT->client,
1050
+ ret |= sc301iot_write_reg(sc301iot->client,
10511051 SC301IOT_REG_SANA_GAIN,
10521052 SC301IOT_REG_VALUE_08BIT,
10531053 ANA_Coarse_gain_reg);
....@@ -1055,17 +1055,17 @@
10551055 return ret;
10561056 }
10571057
1058
-static int SC301IOT_set_hdrae(struct SC301IOT *SC301IOT,
1058
+static int sc301iot_set_hdrae(struct sc301iot *sc301iot,
10591059 struct preisp_hdrae_exp_s *ae)
10601060 {
10611061 int ret = 0;
10621062 u32 l_exp_time, m_exp_time, s_exp_time;
10631063 u32 l_a_gain, m_a_gain, s_a_gain;
10641064
1065
- if (!SC301IOT->has_init_exp && !SC301IOT->streaming) {
1066
- SC301IOT->init_hdrae_exp = *ae;
1067
- SC301IOT->has_init_exp = true;
1068
- dev_dbg(&SC301IOT->client->dev, "SC301IOT don't stream, record exp for hdr!\n");
1065
+ if (!sc301iot->has_init_exp && !sc301iot->streaming) {
1066
+ sc301iot->init_hdrae_exp = *ae;
1067
+ sc301iot->has_init_exp = true;
1068
+ dev_dbg(&sc301iot->client->dev, "sc301iot don't stream, record exp for hdr!\n");
10691069 return ret;
10701070 }
10711071 l_exp_time = ae->long_exp_reg;
....@@ -1075,12 +1075,12 @@
10751075 m_a_gain = ae->middle_gain_reg;
10761076 s_a_gain = ae->short_gain_reg;
10771077
1078
- dev_dbg(&SC301IOT->client->dev,
1078
+ dev_dbg(&sc301iot->client->dev,
10791079 "rev exp req: L_exp: 0x%x, 0x%x, M_exp: 0x%x, 0x%x S_exp: 0x%x, 0x%x\n",
10801080 l_exp_time, m_exp_time, s_exp_time,
10811081 l_a_gain, m_a_gain, s_a_gain);
10821082
1083
- if (SC301IOT->cur_mode->hdr_mode == HDR_X2) {
1083
+ if (sc301iot->cur_mode->hdr_mode == HDR_X2) {
10841084 //2 stagger
10851085 l_a_gain = m_a_gain;
10861086 l_exp_time = m_exp_time;
....@@ -1097,42 +1097,42 @@
10971097 if (s_exp_time > 182) //(191 - 9)
10981098 s_exp_time = 182;
10991099
1100
- ret = SC301IOT_write_reg(SC301IOT->client,
1100
+ ret = sc301iot_write_reg(sc301iot->client,
11011101 SC301IOT_REG_EXPOSURE_H,
11021102 SC301IOT_REG_VALUE_08BIT,
11031103 SC301IOT_FETCH_EXP_H(l_exp_time));
1104
- ret |= SC301IOT_write_reg(SC301IOT->client,
1104
+ ret |= sc301iot_write_reg(sc301iot->client,
11051105 SC301IOT_REG_EXPOSURE_M,
11061106 SC301IOT_REG_VALUE_08BIT,
11071107 SC301IOT_FETCH_EXP_M(l_exp_time));
1108
- ret |= SC301IOT_write_reg(SC301IOT->client,
1108
+ ret |= sc301iot_write_reg(sc301iot->client,
11091109 SC301IOT_REG_EXPOSURE_L,
11101110 SC301IOT_REG_VALUE_08BIT,
11111111 SC301IOT_FETCH_EXP_L(l_exp_time));
1112
- ret |= SC301IOT_write_reg(SC301IOT->client,
1112
+ ret |= sc301iot_write_reg(sc301iot->client,
11131113 SC301IOT_REG_SEXPOSURE_M,
11141114 SC301IOT_REG_VALUE_08BIT,
11151115 SC301IOT_FETCH_EXP_M(s_exp_time));
1116
- ret |= SC301IOT_write_reg(SC301IOT->client,
1116
+ ret |= sc301iot_write_reg(sc301iot->client,
11171117 SC301IOT_REG_SEXPOSURE_L,
11181118 SC301IOT_REG_VALUE_08BIT,
11191119 SC301IOT_FETCH_EXP_L(s_exp_time));
11201120
11211121
1122
- ret |= SC301IOT_set_gain_reg(SC301IOT, l_a_gain, SC301IOT_LGAIN);
1123
- ret |= SC301IOT_set_gain_reg(SC301IOT, s_a_gain, SC301IOT_SGAIN);
1122
+ ret |= sc301iot_set_gain_reg(sc301iot, l_a_gain, SC301IOT_LGAIN);
1123
+ ret |= sc301iot_set_gain_reg(sc301iot, s_a_gain, SC301IOT_SGAIN);
11241124 return ret;
11251125 }
11261126
1127
-static int SC301IOT_get_reso_dist(const struct SC301IOT_mode *mode,
1127
+static int sc301iot_get_reso_dist(const struct sc301iot_mode *mode,
11281128 struct v4l2_mbus_framefmt *framefmt)
11291129 {
11301130 return abs(mode->width - framefmt->width) +
11311131 abs(mode->height - framefmt->height);
11321132 }
11331133
1134
-static const struct SC301IOT_mode *
1135
-SC301IOT_find_best_fit(struct v4l2_subdev_format *fmt)
1134
+static const struct sc301iot_mode *
1135
+sc301iot_find_best_fit(struct v4l2_subdev_format *fmt)
11361136 {
11371137 struct v4l2_mbus_framefmt *framefmt = &fmt->format;
11381138 int dist;
....@@ -1141,7 +1141,7 @@
11411141 unsigned int i;
11421142
11431143 for (i = 0; i < ARRAY_SIZE(supported_modes); i++) {
1144
- dist = SC301IOT_get_reso_dist(&supported_modes[i], framefmt);
1144
+ dist = sc301iot_get_reso_dist(&supported_modes[i], framefmt);
11451145 if (cur_best_fit_dist == -1 || dist < cur_best_fit_dist) {
11461146 cur_best_fit_dist = dist;
11471147 cur_best_fit = i;
....@@ -1151,17 +1151,17 @@
11511151 return &supported_modes[cur_best_fit];
11521152 }
11531153
1154
-static int SC301IOT_set_fmt(struct v4l2_subdev *sd,
1154
+static int sc301iot_set_fmt(struct v4l2_subdev *sd,
11551155 struct v4l2_subdev_pad_config *cfg,
11561156 struct v4l2_subdev_format *fmt)
11571157 {
1158
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
1159
- const struct SC301IOT_mode *mode;
1158
+ struct sc301iot *sc301iot = to_sc301iot(sd);
1159
+ const struct sc301iot_mode *mode;
11601160 s64 h_blank, vblank_def;
11611161
1162
- mutex_lock(&SC301IOT->mutex);
1162
+ mutex_lock(&sc301iot->mutex);
11631163
1164
- mode = SC301IOT_find_best_fit(fmt);
1164
+ mode = sc301iot_find_best_fit(fmt);
11651165 fmt->format.code = mode->bus_fmt;
11661166 fmt->format.width = mode->width;
11671167 fmt->format.height = mode->height;
....@@ -1170,40 +1170,40 @@
11701170 #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
11711171 *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
11721172 #else
1173
- mutex_unlock(&SC301IOT->mutex);
1173
+ mutex_unlock(&sc301iot->mutex);
11741174 return -ENOTTY;
11751175 #endif
11761176 } else {
1177
- SC301IOT->cur_mode = mode;
1177
+ sc301iot->cur_mode = mode;
11781178 h_blank = mode->hts_def - mode->width;
1179
- __v4l2_ctrl_modify_range(SC301IOT->hblank, h_blank,
1179
+ __v4l2_ctrl_modify_range(sc301iot->hblank, h_blank,
11801180 h_blank, 1, h_blank);
11811181 vblank_def = mode->vts_def - mode->height;
1182
- __v4l2_ctrl_modify_range(SC301IOT->vblank, vblank_def,
1182
+ __v4l2_ctrl_modify_range(sc301iot->vblank, vblank_def,
11831183 SC301IOT_VTS_MAX - mode->height,
11841184 1, vblank_def);
1185
- SC301IOT->cur_fps = mode->max_fps;
1186
- SC301IOT->cur_vts = mode->vts_def;
1185
+ sc301iot->cur_fps = mode->max_fps;
1186
+ sc301iot->cur_vts = mode->vts_def;
11871187 }
11881188
1189
- mutex_unlock(&SC301IOT->mutex);
1189
+ mutex_unlock(&sc301iot->mutex);
11901190
11911191 return 0;
11921192 }
11931193
1194
-static int SC301IOT_get_fmt(struct v4l2_subdev *sd,
1194
+static int sc301iot_get_fmt(struct v4l2_subdev *sd,
11951195 struct v4l2_subdev_pad_config *cfg,
11961196 struct v4l2_subdev_format *fmt)
11971197 {
1198
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
1199
- const struct SC301IOT_mode *mode = SC301IOT->cur_mode;
1198
+ struct sc301iot *sc301iot = to_sc301iot(sd);
1199
+ const struct sc301iot_mode *mode = sc301iot->cur_mode;
12001200
1201
- mutex_lock(&SC301IOT->mutex);
1201
+ mutex_lock(&sc301iot->mutex);
12021202 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
12031203 #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
12041204 fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
12051205 #else
1206
- mutex_unlock(&SC301IOT->mutex);
1206
+ mutex_unlock(&sc301iot->mutex);
12071207 return -ENOTTY;
12081208 #endif
12091209 } else {
....@@ -1217,24 +1217,24 @@
12171217 else
12181218 fmt->reserved[0] = mode->vc[PAD0];
12191219 }
1220
- mutex_unlock(&SC301IOT->mutex);
1220
+ mutex_unlock(&sc301iot->mutex);
12211221 return 0;
12221222 }
12231223
1224
-static int SC301IOT_enum_mbus_code(struct v4l2_subdev *sd,
1224
+static int sc301iot_enum_mbus_code(struct v4l2_subdev *sd,
12251225 struct v4l2_subdev_pad_config *cfg,
12261226 struct v4l2_subdev_mbus_code_enum *code)
12271227 {
1228
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
1228
+ struct sc301iot *sc301iot = to_sc301iot(sd);
12291229
12301230 if (code->index != 0)
12311231 return -EINVAL;
1232
- code->code = SC301IOT->cur_mode->bus_fmt;
1232
+ code->code = sc301iot->cur_mode->bus_fmt;
12331233
12341234 return 0;
12351235 }
12361236
1237
-static int SC301IOT_enum_frame_sizes(struct v4l2_subdev *sd,
1237
+static int sc301iot_enum_frame_sizes(struct v4l2_subdev *sd,
12381238 struct v4l2_subdev_pad_config *cfg,
12391239 struct v4l2_subdev_frame_size_enum *fse)
12401240 {
....@@ -1252,42 +1252,42 @@
12521252 return 0;
12531253 }
12541254
1255
-static int SC301IOT_enable_test_pattern(struct SC301IOT *SC301IOT, u32 pattern)
1255
+static int sc301iot_enable_test_pattern(struct sc301iot *sc301iot, u32 pattern)
12561256 {
12571257 u32 val = 0;
12581258 int ret = 0;
12591259
1260
- ret = SC301IOT_read_reg(SC301IOT->client, SC301IOT_REG_TEST_PATTERN,
1260
+ ret = sc301iot_read_reg(sc301iot->client, SC301IOT_REG_TEST_PATTERN,
12611261 SC301IOT_REG_VALUE_08BIT, &val);
12621262 if (pattern)
12631263 val |= SC301IOT_TEST_PATTERN_BIT_MASK;
12641264 else
12651265 val &= ~SC301IOT_TEST_PATTERN_BIT_MASK;
12661266
1267
- ret |= SC301IOT_write_reg(SC301IOT->client, SC301IOT_REG_TEST_PATTERN,
1267
+ ret |= sc301iot_write_reg(sc301iot->client, SC301IOT_REG_TEST_PATTERN,
12681268 SC301IOT_REG_VALUE_08BIT, val);
12691269 return ret;
12701270 }
12711271
1272
-static int SC301IOT_g_frame_interval(struct v4l2_subdev *sd,
1272
+static int sc301iot_g_frame_interval(struct v4l2_subdev *sd,
12731273 struct v4l2_subdev_frame_interval *fi)
12741274 {
1275
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
1276
- const struct SC301IOT_mode *mode = SC301IOT->cur_mode;
1275
+ struct sc301iot *sc301iot = to_sc301iot(sd);
1276
+ const struct sc301iot_mode *mode = sc301iot->cur_mode;
12771277
1278
- if (SC301IOT->streaming)
1279
- fi->interval = SC301IOT->cur_fps;
1278
+ if (sc301iot->streaming)
1279
+ fi->interval = sc301iot->cur_fps;
12801280 else
12811281 fi->interval = mode->max_fps;
12821282
12831283 return 0;
12841284 }
12851285
1286
-static int SC301IOT_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
1286
+static int sc301iot_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
12871287 struct v4l2_mbus_config *config)
12881288 {
1289
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
1290
- const struct SC301IOT_mode *mode = SC301IOT->cur_mode;
1289
+ struct sc301iot *sc301iot = to_sc301iot(sd);
1290
+ const struct sc301iot_mode *mode = sc301iot->cur_mode;
12911291 u32 val = 1 << (SC301IOT_LANES - 1) |
12921292 V4L2_MBUS_CSI2_CHANNEL_0 |
12931293 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
....@@ -1303,31 +1303,31 @@
13031303 return 0;
13041304 }
13051305
1306
-static void SC301IOT_get_module_inf(struct SC301IOT *SC301IOT,
1306
+static void sc301iot_get_module_inf(struct sc301iot *sc301iot,
13071307 struct rkmodule_inf *inf)
13081308 {
13091309 memset(inf, 0, sizeof(*inf));
13101310 strscpy(inf->base.sensor, SC301IOT_NAME, sizeof(inf->base.sensor));
1311
- strscpy(inf->base.module, SC301IOT->module_name,
1311
+ strscpy(inf->base.module, sc301iot->module_name,
13121312 sizeof(inf->base.module));
1313
- strscpy(inf->base.lens, SC301IOT->len_name, sizeof(inf->base.lens));
1313
+ strscpy(inf->base.lens, sc301iot->len_name, sizeof(inf->base.lens));
13141314 }
13151315
1316
-static int SC301IOT_get_channel_info(struct SC301IOT *SC301IOT,
1316
+static int sc301iot_get_channel_info(struct sc301iot *sc301iot,
13171317 struct rkmodule_channel_info *ch_info)
13181318 {
13191319 if (ch_info->index < PAD0 || ch_info->index >= PAD_MAX)
13201320 return -EINVAL;
1321
- ch_info->vc = SC301IOT->cur_mode->vc[ch_info->index];
1322
- ch_info->width = SC301IOT->cur_mode->width;
1323
- ch_info->height = SC301IOT->cur_mode->height;
1324
- ch_info->bus_fmt = SC301IOT->cur_mode->bus_fmt;
1321
+ ch_info->vc = sc301iot->cur_mode->vc[ch_info->index];
1322
+ ch_info->width = sc301iot->cur_mode->width;
1323
+ ch_info->height = sc301iot->cur_mode->height;
1324
+ ch_info->bus_fmt = sc301iot->cur_mode->bus_fmt;
13251325 return 0;
13261326 }
13271327
1328
-static long SC301IOT_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1328
+static long sc301iot_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
13291329 {
1330
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
1330
+ struct sc301iot *sc301iot = to_sc301iot(sd);
13311331 struct rkmodule_hdr_cfg *hdr;
13321332 struct rkmodule_channel_info *ch_info;
13331333 u32 i, h, w;
....@@ -1337,68 +1337,68 @@
13371337
13381338 switch (cmd) {
13391339 case RKMODULE_GET_MODULE_INFO:
1340
- SC301IOT_get_module_inf(SC301IOT, (struct rkmodule_inf *)arg);
1340
+ sc301iot_get_module_inf(sc301iot, (struct rkmodule_inf *)arg);
13411341 break;
13421342 case RKMODULE_GET_HDR_CFG:
13431343 hdr = (struct rkmodule_hdr_cfg *)arg;
13441344 hdr->esp.mode = HDR_NORMAL_VC;
1345
- hdr->hdr_mode = SC301IOT->cur_mode->hdr_mode;
1345
+ hdr->hdr_mode = sc301iot->cur_mode->hdr_mode;
13461346 break;
13471347 case RKMODULE_SET_HDR_CFG:
13481348 hdr = (struct rkmodule_hdr_cfg *)arg;
1349
- w = SC301IOT->cur_mode->width;
1350
- h = SC301IOT->cur_mode->height;
1349
+ w = sc301iot->cur_mode->width;
1350
+ h = sc301iot->cur_mode->height;
13511351 for (i = 0; i < ARRAY_SIZE(supported_modes); i++) {
13521352 if (w == supported_modes[i].width &&
13531353 h == supported_modes[i].height &&
13541354 supported_modes[i].hdr_mode == hdr->hdr_mode) {
1355
- SC301IOT->cur_mode = &supported_modes[i];
1355
+ sc301iot->cur_mode = &supported_modes[i];
13561356 break;
13571357 }
13581358 }
13591359 if (i == ARRAY_SIZE(supported_modes)) {
1360
- dev_err(&SC301IOT->client->dev,
1360
+ dev_err(&sc301iot->client->dev,
13611361 "not find hdr mode:%d %dx%d config\n",
13621362 hdr->hdr_mode, w, h);
13631363 ret = -EINVAL;
13641364 } else {
1365
- w = SC301IOT->cur_mode->hts_def - SC301IOT->cur_mode->width;
1366
- h = SC301IOT->cur_mode->vts_def - SC301IOT->cur_mode->height;
1367
- __v4l2_ctrl_modify_range(SC301IOT->hblank, w, w, 1, w);
1368
- __v4l2_ctrl_modify_range(SC301IOT->vblank,
1365
+ w = sc301iot->cur_mode->hts_def - sc301iot->cur_mode->width;
1366
+ h = sc301iot->cur_mode->vts_def - sc301iot->cur_mode->height;
1367
+ __v4l2_ctrl_modify_range(sc301iot->hblank, w, w, 1, w);
1368
+ __v4l2_ctrl_modify_range(sc301iot->vblank,
13691369 h,
1370
- SC301IOT_VTS_MAX - SC301IOT->cur_mode->height, 1, h);
1371
- SC301IOT->cur_fps = SC301IOT->cur_mode->max_fps;
1372
- SC301IOT->cur_vts = SC301IOT->cur_mode->vts_def;
1370
+ SC301IOT_VTS_MAX - sc301iot->cur_mode->height, 1, h);
1371
+ sc301iot->cur_fps = sc301iot->cur_mode->max_fps;
1372
+ sc301iot->cur_vts = sc301iot->cur_mode->vts_def;
13731373 }
13741374 break;
13751375 case PREISP_CMD_SET_HDRAE_EXP:
1376
- SC301IOT_set_hdrae(SC301IOT, arg);
1376
+ sc301iot_set_hdrae(sc301iot, arg);
13771377 break;
13781378 case RKMODULE_SET_QUICK_STREAM:
13791379
13801380 stream = *((u32 *)arg);
13811381
13821382 if (stream)
1383
- ret = SC301IOT_write_reg(SC301IOT->client, SC301IOT_REG_CTRL_MODE,
1383
+ ret = sc301iot_write_reg(sc301iot->client, SC301IOT_REG_CTRL_MODE,
13841384 SC301IOT_REG_VALUE_08BIT, SC301IOT_MODE_STREAMING);
13851385 else
1386
- ret = SC301IOT_write_reg(SC301IOT->client, SC301IOT_REG_CTRL_MODE,
1386
+ ret = sc301iot_write_reg(sc301iot->client, SC301IOT_REG_CTRL_MODE,
13871387 SC301IOT_REG_VALUE_08BIT, SC301IOT_MODE_SW_STANDBY);
13881388 break;
13891389 case RKMODULE_GET_SYNC_MODE:
1390
- *((u32 *)arg) = SC301IOT->sync_mode;
1390
+ *((u32 *)arg) = sc301iot->sync_mode;
13911391 break;
13921392 case RKMODULE_SET_SYNC_MODE:
13931393 sync_mode = *((u32 *)arg);
13941394 if (sync_mode > 3)
13951395 break;
1396
- SC301IOT->sync_mode = sync_mode;
1397
- dev_info(&SC301IOT->client->dev, "sync_mode = [%u]\n", SC301IOT->sync_mode);
1396
+ sc301iot->sync_mode = sync_mode;
1397
+ dev_info(&sc301iot->client->dev, "sync_mode = [%u]\n", sc301iot->sync_mode);
13981398 break;
13991399 case RKMODULE_GET_CHANNEL_INFO:
14001400 ch_info = (struct rkmodule_channel_info *)arg;
1401
- ret = SC301IOT_get_channel_info(SC301IOT, ch_info);
1401
+ ret = sc301iot_get_channel_info(sc301iot, ch_info);
14021402 break;
14031403 default:
14041404 ret = -ENOIOCTLCMD;
....@@ -1409,7 +1409,7 @@
14091409 }
14101410
14111411 #ifdef CONFIG_COMPAT
1412
-static long SC301IOT_compat_ioctl32(struct v4l2_subdev *sd,
1412
+static long sc301iot_compat_ioctl32(struct v4l2_subdev *sd,
14131413 unsigned int cmd, unsigned long arg)
14141414 {
14151415 void __user *up = compat_ptr(arg);
....@@ -1429,7 +1429,7 @@
14291429 return ret;
14301430 }
14311431
1432
- ret = SC301IOT_ioctl(sd, cmd, inf);
1432
+ ret = sc301iot_ioctl(sd, cmd, inf);
14331433 if (!ret) {
14341434 if (copy_to_user(up, inf, sizeof(*inf))) {
14351435 kfree(inf);
....@@ -1448,7 +1448,7 @@
14481448 kfree(cfg);
14491449 return -EFAULT;
14501450 }
1451
- ret = SC301IOT_ioctl(sd, cmd, cfg);
1451
+ ret = sc301iot_ioctl(sd, cmd, cfg);
14521452 kfree(cfg);
14531453 break;
14541454 case RKMODULE_GET_HDR_CFG:
....@@ -1458,7 +1458,7 @@
14581458 return ret;
14591459 }
14601460
1461
- ret = SC301IOT_ioctl(sd, cmd, hdr);
1461
+ ret = sc301iot_ioctl(sd, cmd, hdr);
14621462 if (!ret) {
14631463 if (copy_to_user(up, hdr, sizeof(*hdr))) {
14641464 kfree(hdr);
....@@ -1477,7 +1477,7 @@
14771477 kfree(hdr);
14781478 return -EFAULT;
14791479 }
1480
- ret = SC301IOT_ioctl(sd, cmd, hdr);
1480
+ ret = sc301iot_ioctl(sd, cmd, hdr);
14811481 kfree(hdr);
14821482 break;
14831483 case PREISP_CMD_SET_HDRAE_EXP:
....@@ -1490,13 +1490,13 @@
14901490 kfree(hdrae);
14911491 return -EFAULT;
14921492 }
1493
- ret = SC301IOT_ioctl(sd, cmd, hdrae);
1493
+ ret = sc301iot_ioctl(sd, cmd, hdrae);
14941494 kfree(hdrae);
14951495 break;
14961496 case RKMODULE_SET_QUICK_STREAM:
14971497 if (copy_from_user(&stream, up, sizeof(u32)))
14981498 return -EFAULT;
1499
- ret = SC301IOT_ioctl(sd, cmd, &stream);
1499
+ ret = sc301iot_ioctl(sd, cmd, &stream);
15001500 break;
15011501 case RKMODULE_GET_CHANNEL_INFO:
15021502 ch_info = kzalloc(sizeof(*ch_info), GFP_KERNEL);
....@@ -1505,7 +1505,7 @@
15051505 return ret;
15061506 }
15071507
1508
- ret = SC301IOT_ioctl(sd, cmd, ch_info);
1508
+ ret = sc301iot_ioctl(sd, cmd, ch_info);
15091509 if (!ret) {
15101510 ret = copy_to_user(up, ch_info, sizeof(*ch_info));
15111511 if (ret)
....@@ -1522,10 +1522,10 @@
15221522 }
15231523 #endif
15241524
1525
-static int SC301IOT_s_frame_interval(struct v4l2_subdev *sd,
1525
+static int sc301iot_s_frame_interval(struct v4l2_subdev *sd,
15261526 struct v4l2_subdev_frame_interval *fi)
15271527 {
1528
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
1528
+ struct sc301iot *sc301iot = to_sc301iot(sd);
15291529 struct device *dev = sd->dev;
15301530 int ret = -1;
15311531 s64 vblank_def;
....@@ -1534,100 +1534,102 @@
15341534 fps_set = DIV_ROUND_CLOSEST(fi->interval.denominator, fi->interval.numerator);
15351535 dev_info(dev, "%s set fps = %u\n", __func__, fps_set);
15361536
1537
- mutex_lock(&SC301IOT->mutex);
1537
+ mutex_lock(&sc301iot->mutex);
15381538
1539
- current_fps = DIV_ROUND_CLOSEST(SC301IOT->cur_mode->max_fps.denominator,
1540
- SC301IOT->cur_mode->max_fps.numerator);
1541
- vblank_def = SC301IOT->cur_mode->vts_def * current_fps / fps_set -
1542
- SC301IOT->cur_mode->height;
1543
- if (SC301IOT->sync_mode == SLAVE_MODE)
1539
+ current_fps = DIV_ROUND_CLOSEST(sc301iot->cur_mode->max_fps.denominator,
1540
+ sc301iot->cur_mode->max_fps.numerator);
1541
+ vblank_def = sc301iot->cur_mode->vts_def * current_fps / fps_set -
1542
+ sc301iot->cur_mode->height;
1543
+ if (sc301iot->sync_mode == SLAVE_MODE)
15441544 vblank_def -= 3; // adjust vts
1545
- ret = __v4l2_ctrl_s_ctrl(SC301IOT->vblank, vblank_def);
1546
- mutex_unlock(&SC301IOT->mutex);
1545
+ ret = __v4l2_ctrl_s_ctrl(sc301iot->vblank, vblank_def);
1546
+ mutex_unlock(&sc301iot->mutex);
15471547 if (ret < 0)
15481548 dev_err(dev, "%s __v4l2_ctrl_s_ctrl error - %d\n", __func__, ret);
15491549 return ret;
15501550 }
15511551
1552
-static int __SC301IOT_start_stream(struct SC301IOT *SC301IOT)
1552
+static int __sc301iot_start_stream(struct sc301iot *sc301iot)
15531553 {
15541554 int ret;
15551555
1556
- if (!SC301IOT->is_thunderboot) {
1557
- ret = SC301IOT_write_array(SC301IOT->client, SC301IOT->cur_mode->reg_list);
1556
+ if (!sc301iot->is_thunderboot) {
1557
+ ret = sc301iot_write_array(sc301iot->client, sc301iot->cur_mode->reg_list);
15581558 if (ret)
15591559 return ret;
15601560
15611561 /* In case these controls are set before streaming */
1562
- ret = __v4l2_ctrl_handler_setup(&SC301IOT->ctrl_handler);
1562
+ ret = __v4l2_ctrl_handler_setup(&sc301iot->ctrl_handler);
15631563 if (ret)
15641564 return ret;
1565
- if (SC301IOT->has_init_exp && SC301IOT->cur_mode->hdr_mode != NO_HDR) {
1566
- ret = SC301IOT_ioctl(&SC301IOT->subdev, PREISP_CMD_SET_HDRAE_EXP,
1567
- &SC301IOT->init_hdrae_exp);
1565
+ if (sc301iot->has_init_exp && sc301iot->cur_mode->hdr_mode != NO_HDR) {
1566
+ ret = sc301iot_ioctl(&sc301iot->subdev, PREISP_CMD_SET_HDRAE_EXP,
1567
+ &sc301iot->init_hdrae_exp);
15681568 if (ret) {
1569
- dev_err(&SC301IOT->client->dev,
1569
+ dev_err(&sc301iot->client->dev,
15701570 "init exp fail in hdr mode\n");
15711571 return ret;
15721572 }
15731573 }
15741574
1575
- if (SC301IOT->sync_mode == SLAVE_MODE) {
1576
- SC301IOT_write_reg(SC301IOT->client, 0x3222,
1575
+ if (sc301iot->sync_mode == SLAVE_MODE) {
1576
+ sc301iot_write_reg(sc301iot->client, 0x3222,
15771577 SC301IOT_REG_VALUE_08BIT, 0x01);
1578
- SC301IOT_write_reg(SC301IOT->client, 0x3223,
1578
+ sc301iot_write_reg(sc301iot->client, 0x3223,
15791579 SC301IOT_REG_VALUE_08BIT, 0xc8);
1580
- SC301IOT_write_reg(SC301IOT->client, 0x3225,
1580
+ sc301iot_write_reg(sc301iot->client, 0x3225,
15811581 SC301IOT_REG_VALUE_08BIT, 0x10);
1582
- SC301IOT_write_reg(SC301IOT->client, 0x322e,
1583
- SC301IOT_REG_VALUE_08BIT, (SC301IOT->cur_vts - 4) >> 8);
1584
- SC301IOT_write_reg(SC301IOT->client, 0x322f,
1585
- SC301IOT_REG_VALUE_08BIT, (SC301IOT->cur_vts - 4) & 0xff);
1586
- } else if (SC301IOT->sync_mode == NO_SYNC_MODE) {
1587
- SC301IOT_write_reg(SC301IOT->client, 0x3222,
1582
+ sc301iot_write_reg(sc301iot->client, 0x322e,
1583
+ SC301IOT_REG_VALUE_08BIT, (sc301iot->cur_vts - 4) >> 8);
1584
+ sc301iot_write_reg(sc301iot->client, 0x322f,
1585
+ SC301IOT_REG_VALUE_08BIT, (sc301iot->cur_vts - 4) & 0xff);
1586
+ } else if (sc301iot->sync_mode == NO_SYNC_MODE) {
1587
+ sc301iot_write_reg(sc301iot->client, 0x3222,
15881588 SC301IOT_REG_VALUE_08BIT, 0x00);
1589
- SC301IOT_write_reg(SC301IOT->client, 0x3223,
1589
+ sc301iot_write_reg(sc301iot->client, 0x3223,
15901590 SC301IOT_REG_VALUE_08BIT, 0xd0);
1591
- SC301IOT_write_reg(SC301IOT->client, 0x3225,
1591
+ sc301iot_write_reg(sc301iot->client, 0x3225,
15921592 SC301IOT_REG_VALUE_08BIT, 0x00);
1593
- SC301IOT_write_reg(SC301IOT->client, 0x322e,
1593
+ sc301iot_write_reg(sc301iot->client, 0x322e,
15941594 SC301IOT_REG_VALUE_08BIT, 0x00);
1595
- SC301IOT_write_reg(SC301IOT->client, 0x322f,
1595
+ sc301iot_write_reg(sc301iot->client, 0x322f,
15961596 SC301IOT_REG_VALUE_08BIT, 0x02);
15971597 }
15981598 }
15991599
1600
- dev_dbg(&SC301IOT->client->dev, "start stream\n");
1601
- return SC301IOT_write_reg(SC301IOT->client, SC301IOT_REG_CTRL_MODE,
1600
+ dev_dbg(&sc301iot->client->dev, "start stream\n");
1601
+ return sc301iot_write_reg(sc301iot->client, SC301IOT_REG_CTRL_MODE,
16021602 SC301IOT_REG_VALUE_08BIT, SC301IOT_MODE_STREAMING);
16031603 }
16041604
1605
-static int __SC301IOT_stop_stream(struct SC301IOT *SC301IOT)
1605
+static int __sc301iot_stop_stream(struct sc301iot *sc301iot)
16061606 {
1607
- SC301IOT->has_init_exp = false;
1608
- dev_dbg(&SC301IOT->client->dev, "stop stream\n");
1609
- if (SC301IOT->is_thunderboot)
1610
- SC301IOT->is_first_streamoff = true;
1611
- return SC301IOT_write_reg(SC301IOT->client, SC301IOT_REG_CTRL_MODE,
1607
+ sc301iot->has_init_exp = false;
1608
+ dev_dbg(&sc301iot->client->dev, "stop stream\n");
1609
+ if (sc301iot->is_thunderboot) {
1610
+ sc301iot->is_first_streamoff = true;
1611
+ pm_runtime_put(&sc301iot->client->dev);
1612
+ }
1613
+ return sc301iot_write_reg(sc301iot->client, SC301IOT_REG_CTRL_MODE,
16121614 SC301IOT_REG_VALUE_08BIT, SC301IOT_MODE_SW_STANDBY);
16131615 }
16141616
1615
-static int __SC301IOT_power_on(struct SC301IOT *SC301IOT);
1616
-static int SC301IOT_s_stream(struct v4l2_subdev *sd, int on)
1617
+static int __sc301iot_power_on(struct sc301iot *sc301iot);
1618
+static int sc301iot_s_stream(struct v4l2_subdev *sd, int on)
16171619 {
1618
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
1619
- struct i2c_client *client = SC301IOT->client;
1620
+ struct sc301iot *sc301iot = to_sc301iot(sd);
1621
+ struct i2c_client *client = sc301iot->client;
16201622 int ret = 0;
16211623
1622
- mutex_lock(&SC301IOT->mutex);
1624
+ mutex_lock(&sc301iot->mutex);
16231625 on = !!on;
1624
- if (on == SC301IOT->streaming)
1626
+ if (on == sc301iot->streaming)
16251627 goto unlock_and_return;
16261628
16271629 if (on) {
1628
- if (SC301IOT->is_thunderboot && rkisp_tb_get_state() == RKISP_TB_NG) {
1629
- SC301IOT->is_thunderboot = false;
1630
- __SC301IOT_power_on(SC301IOT);
1630
+ if (sc301iot->is_thunderboot && rkisp_tb_get_state() == RKISP_TB_NG) {
1631
+ sc301iot->is_thunderboot = false;
1632
+ __sc301iot_power_on(sc301iot);
16311633 }
16321634
16331635 ret = pm_runtime_get_sync(&client->dev);
....@@ -1636,35 +1638,35 @@
16361638 goto unlock_and_return;
16371639 }
16381640
1639
- ret = __SC301IOT_start_stream(SC301IOT);
1641
+ ret = __sc301iot_start_stream(sc301iot);
16401642 if (ret) {
16411643 v4l2_err(sd, "start stream failed while write regs\n");
16421644 pm_runtime_put(&client->dev);
16431645 goto unlock_and_return;
16441646 }
16451647 } else {
1646
- __SC301IOT_stop_stream(SC301IOT);
1648
+ __sc301iot_stop_stream(sc301iot);
16471649 pm_runtime_put(&client->dev);
16481650 }
16491651
1650
- SC301IOT->streaming = on;
1652
+ sc301iot->streaming = on;
16511653
16521654 unlock_and_return:
1653
- mutex_unlock(&SC301IOT->mutex);
1655
+ mutex_unlock(&sc301iot->mutex);
16541656
16551657 return ret;
16561658 }
16571659
1658
-static int SC301IOT_s_power(struct v4l2_subdev *sd, int on)
1660
+static int sc301iot_s_power(struct v4l2_subdev *sd, int on)
16591661 {
1660
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
1661
- struct i2c_client *client = SC301IOT->client;
1662
+ struct sc301iot *sc301iot = to_sc301iot(sd);
1663
+ struct i2c_client *client = sc301iot->client;
16621664 int ret = 0;
16631665
1664
- mutex_lock(&SC301IOT->mutex);
1666
+ mutex_lock(&sc301iot->mutex);
16651667
16661668 /* If the power state is not modified - no work to do. */
1667
- if (SC301IOT->power_on == !!on)
1669
+ if (sc301iot->power_on == !!on)
16681670 goto unlock_and_return;
16691671
16701672 if (on) {
....@@ -1674,8 +1676,8 @@
16741676 goto unlock_and_return;
16751677 }
16761678
1677
- if (!SC301IOT->is_thunderboot) {
1678
- ret = SC301IOT_write_array(SC301IOT->client, SC301IOT_global_regs);
1679
+ if (!sc301iot->is_thunderboot) {
1680
+ ret = sc301iot_write_array(sc301iot->client, sc301iot_global_regs);
16791681 if (ret) {
16801682 v4l2_err(sd, "could not set init registers\n");
16811683 pm_runtime_put_noidle(&client->dev);
....@@ -1683,152 +1685,152 @@
16831685 }
16841686 }
16851687
1686
- SC301IOT->power_on = true;
1688
+ sc301iot->power_on = true;
16871689 } else {
16881690 pm_runtime_put(&client->dev);
1689
- SC301IOT->power_on = false;
1691
+ sc301iot->power_on = false;
16901692 }
16911693
16921694 unlock_and_return:
1693
- mutex_unlock(&SC301IOT->mutex);
1695
+ mutex_unlock(&sc301iot->mutex);
16941696
16951697 return ret;
16961698 }
16971699
16981700 /* Calculate the delay in us by clock rate and clock cycles */
1699
-static inline u32 SC301IOT_cal_delay(u32 cycles)
1701
+static inline u32 sc301iot_cal_delay(u32 cycles)
17001702 {
17011703 return DIV_ROUND_UP(cycles, SC301IOT_XVCLK_FREQ / 1000 / 1000);
17021704 }
17031705
1704
-static int __SC301IOT_power_on(struct SC301IOT *SC301IOT)
1706
+static int __sc301iot_power_on(struct sc301iot *sc301iot)
17051707 {
17061708 int ret;
17071709 u32 delay_us;
1708
- struct device *dev = &SC301IOT->client->dev;
1710
+ struct device *dev = &sc301iot->client->dev;
17091711
1710
- if (!IS_ERR_OR_NULL(SC301IOT->pins_default)) {
1711
- ret = pinctrl_select_state(SC301IOT->pinctrl,
1712
- SC301IOT->pins_default);
1712
+ if (!IS_ERR_OR_NULL(sc301iot->pins_default)) {
1713
+ ret = pinctrl_select_state(sc301iot->pinctrl,
1714
+ sc301iot->pins_default);
17131715 if (ret < 0)
17141716 dev_err(dev, "could not set pins\n");
17151717 }
1716
- ret = clk_set_rate(SC301IOT->xvclk, SC301IOT_XVCLK_FREQ);
1718
+ ret = clk_set_rate(sc301iot->xvclk, SC301IOT_XVCLK_FREQ);
17171719 if (ret < 0)
17181720 dev_warn(dev, "Failed to set xvclk rate (24MHz)\n");
1719
- if (clk_get_rate(SC301IOT->xvclk) != SC301IOT_XVCLK_FREQ)
1721
+ if (clk_get_rate(sc301iot->xvclk) != SC301IOT_XVCLK_FREQ)
17201722 dev_warn(dev, "xvclk mismatched, modes are based on 24MHz\n");
1721
- ret = clk_prepare_enable(SC301IOT->xvclk);
1723
+ ret = clk_prepare_enable(sc301iot->xvclk);
17221724 if (ret < 0) {
17231725 dev_err(dev, "Failed to enable xvclk\n");
17241726 goto disable_clk;
17251727 }
1726
- if (SC301IOT->is_thunderboot)
1728
+ if (sc301iot->is_thunderboot)
17271729 return 0;
1728
- if (!IS_ERR(SC301IOT->reset_gpio))
1729
- gpiod_set_value_cansleep(SC301IOT->reset_gpio, 0);
1730
+ if (!IS_ERR(sc301iot->reset_gpio))
1731
+ gpiod_set_value_cansleep(sc301iot->reset_gpio, 0);
17301732
1731
- ret = regulator_bulk_enable(SC301IOT_NUM_SUPPLIES, SC301IOT->supplies);
1733
+ ret = regulator_bulk_enable(SC301IOT_NUM_SUPPLIES, sc301iot->supplies);
17321734 if (ret < 0) {
17331735 dev_err(dev, "Failed to enable regulators\n");
17341736 goto disable_clk;
17351737 }
1736
- if (!IS_ERR(SC301IOT->reset_gpio))
1737
- gpiod_set_value_cansleep(SC301IOT->reset_gpio, 1);
1738
+ if (!IS_ERR(sc301iot->reset_gpio))
1739
+ gpiod_set_value_cansleep(sc301iot->reset_gpio, 1);
17381740
17391741 usleep_range(500, 1000);
1740
- if (!IS_ERR(SC301IOT->pwdn_gpio))
1741
- gpiod_set_value_cansleep(SC301IOT->pwdn_gpio, 1);
1742
+ if (!IS_ERR(sc301iot->pwdn_gpio))
1743
+ gpiod_set_value_cansleep(sc301iot->pwdn_gpio, 1);
17421744 usleep_range(4500, 5000);
17431745
1744
- if (!IS_ERR(SC301IOT->reset_gpio))
1746
+ if (!IS_ERR(sc301iot->reset_gpio))
17451747 usleep_range(6000, 8000);
17461748 else
17471749 usleep_range(12000, 16000);
17481750
17491751 /* 8192 cycles prior to first SCCB transaction */
1750
- delay_us = SC301IOT_cal_delay(8192);
1752
+ delay_us = sc301iot_cal_delay(8192);
17511753 usleep_range(delay_us, delay_us * 2);
17521754
17531755 return 0;
17541756
17551757 disable_clk:
1756
- clk_disable_unprepare(SC301IOT->xvclk);
1758
+ clk_disable_unprepare(sc301iot->xvclk);
17571759
17581760 return ret;
17591761 }
17601762
1761
-static void __SC301IOT_power_off(struct SC301IOT *SC301IOT)
1763
+static void __sc301iot_power_off(struct sc301iot *sc301iot)
17621764 {
17631765 int ret;
1764
- struct device *dev = &SC301IOT->client->dev;
1766
+ struct device *dev = &sc301iot->client->dev;
17651767
1766
- clk_disable_unprepare(SC301IOT->xvclk);
1767
- if (SC301IOT->is_thunderboot) {
1768
- if (SC301IOT->is_first_streamoff) {
1769
- SC301IOT->is_thunderboot = false;
1770
- SC301IOT->is_first_streamoff = false;
1768
+ clk_disable_unprepare(sc301iot->xvclk);
1769
+ if (sc301iot->is_thunderboot) {
1770
+ if (sc301iot->is_first_streamoff) {
1771
+ sc301iot->is_thunderboot = false;
1772
+ sc301iot->is_first_streamoff = false;
17711773 } else {
17721774 return;
17731775 }
17741776 }
17751777
1776
- if (!IS_ERR(SC301IOT->pwdn_gpio))
1777
- gpiod_set_value_cansleep(SC301IOT->pwdn_gpio, 0);
1778
- if (!IS_ERR(SC301IOT->reset_gpio))
1779
- gpiod_set_value_cansleep(SC301IOT->reset_gpio, 0);
1780
- if (!IS_ERR_OR_NULL(SC301IOT->pins_sleep)) {
1781
- ret = pinctrl_select_state(SC301IOT->pinctrl,
1782
- SC301IOT->pins_sleep);
1778
+ if (!IS_ERR(sc301iot->pwdn_gpio))
1779
+ gpiod_set_value_cansleep(sc301iot->pwdn_gpio, 0);
1780
+ if (!IS_ERR(sc301iot->reset_gpio))
1781
+ gpiod_set_value_cansleep(sc301iot->reset_gpio, 0);
1782
+ if (!IS_ERR_OR_NULL(sc301iot->pins_sleep)) {
1783
+ ret = pinctrl_select_state(sc301iot->pinctrl,
1784
+ sc301iot->pins_sleep);
17831785 if (ret < 0)
17841786 dev_dbg(dev, "could not set pins\n");
17851787 }
1786
- regulator_bulk_disable(SC301IOT_NUM_SUPPLIES, SC301IOT->supplies);
1788
+ regulator_bulk_disable(SC301IOT_NUM_SUPPLIES, sc301iot->supplies);
17871789 }
17881790
1789
-static int SC301IOT_runtime_resume(struct device *dev)
1791
+static int sc301iot_runtime_resume(struct device *dev)
17901792 {
17911793 struct i2c_client *client = to_i2c_client(dev);
17921794 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1793
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
1795
+ struct sc301iot *sc301iot = to_sc301iot(sd);
17941796
1795
- return __SC301IOT_power_on(SC301IOT);
1797
+ return __sc301iot_power_on(sc301iot);
17961798 }
17971799
1798
-static int SC301IOT_runtime_suspend(struct device *dev)
1800
+static int sc301iot_runtime_suspend(struct device *dev)
17991801 {
18001802 struct i2c_client *client = to_i2c_client(dev);
18011803 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1802
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
1804
+ struct sc301iot *sc301iot = to_sc301iot(sd);
18031805
1804
- __SC301IOT_power_off(SC301IOT);
1806
+ __sc301iot_power_off(sc301iot);
18051807
18061808 return 0;
18071809 }
18081810
18091811 #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1810
-static int SC301IOT_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1812
+static int sc301iot_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
18111813 {
1812
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
1814
+ struct sc301iot *sc301iot = to_sc301iot(sd);
18131815 struct v4l2_mbus_framefmt *try_fmt =
18141816 v4l2_subdev_get_try_format(sd, fh->pad, 0);
1815
- const struct SC301IOT_mode *def_mode = &supported_modes[0];
1817
+ const struct sc301iot_mode *def_mode = &supported_modes[0];
18161818
1817
- mutex_lock(&SC301IOT->mutex);
1819
+ mutex_lock(&sc301iot->mutex);
18181820 /* Initialize try_fmt */
18191821 try_fmt->width = def_mode->width;
18201822 try_fmt->height = def_mode->height;
18211823 try_fmt->code = def_mode->bus_fmt;
18221824 try_fmt->field = V4L2_FIELD_NONE;
18231825
1824
- mutex_unlock(&SC301IOT->mutex);
1826
+ mutex_unlock(&sc301iot->mutex);
18251827 /* No crop or compose */
18261828
18271829 return 0;
18281830 }
18291831 #endif
18301832
1831
-static int SC301IOT_enum_frame_interval(struct v4l2_subdev *sd,
1833
+static int sc301iot_enum_frame_interval(struct v4l2_subdev *sd,
18321834 struct v4l2_subdev_pad_config *cfg,
18331835 struct v4l2_subdev_frame_interval_enum *fie)
18341836 {
....@@ -1843,59 +1845,59 @@
18431845 return 0;
18441846 }
18451847
1846
-static const struct dev_pm_ops SC301IOT_pm_ops = {
1847
- SET_RUNTIME_PM_OPS(SC301IOT_runtime_suspend,
1848
- SC301IOT_runtime_resume, NULL)
1848
+static const struct dev_pm_ops sc301iot_pm_ops = {
1849
+ SET_RUNTIME_PM_OPS(sc301iot_runtime_suspend,
1850
+ sc301iot_runtime_resume, NULL)
18491851 };
18501852
18511853 #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1852
-static const struct v4l2_subdev_internal_ops SC301IOT_internal_ops = {
1853
- .open = SC301IOT_open,
1854
+static const struct v4l2_subdev_internal_ops sc301iot_internal_ops = {
1855
+ .open = sc301iot_open,
18541856 };
18551857 #endif
18561858
1857
-static const struct v4l2_subdev_core_ops SC301IOT_core_ops = {
1858
- .s_power = SC301IOT_s_power,
1859
- .ioctl = SC301IOT_ioctl,
1859
+static const struct v4l2_subdev_core_ops sc301iot_core_ops = {
1860
+ .s_power = sc301iot_s_power,
1861
+ .ioctl = sc301iot_ioctl,
18601862 #ifdef CONFIG_COMPAT
1861
- .compat_ioctl32 = SC301IOT_compat_ioctl32,
1863
+ .compat_ioctl32 = sc301iot_compat_ioctl32,
18621864 #endif
18631865 };
18641866
1865
-static const struct v4l2_subdev_video_ops SC301IOT_video_ops = {
1866
- .s_stream = SC301IOT_s_stream,
1867
- .g_frame_interval = SC301IOT_g_frame_interval,
1868
- .s_frame_interval = SC301IOT_s_frame_interval,
1867
+static const struct v4l2_subdev_video_ops sc301iot_video_ops = {
1868
+ .s_stream = sc301iot_s_stream,
1869
+ .g_frame_interval = sc301iot_g_frame_interval,
1870
+ .s_frame_interval = sc301iot_s_frame_interval,
18691871 };
18701872
1871
-static const struct v4l2_subdev_pad_ops SC301IOT_pad_ops = {
1872
- .enum_mbus_code = SC301IOT_enum_mbus_code,
1873
- .enum_frame_size = SC301IOT_enum_frame_sizes,
1874
- .enum_frame_interval = SC301IOT_enum_frame_interval,
1875
- .get_fmt = SC301IOT_get_fmt,
1876
- .set_fmt = SC301IOT_set_fmt,
1877
- .get_mbus_config = SC301IOT_g_mbus_config,
1873
+static const struct v4l2_subdev_pad_ops sc301iot_pad_ops = {
1874
+ .enum_mbus_code = sc301iot_enum_mbus_code,
1875
+ .enum_frame_size = sc301iot_enum_frame_sizes,
1876
+ .enum_frame_interval = sc301iot_enum_frame_interval,
1877
+ .get_fmt = sc301iot_get_fmt,
1878
+ .set_fmt = sc301iot_set_fmt,
1879
+ .get_mbus_config = sc301iot_g_mbus_config,
18781880 };
18791881
1880
-static const struct v4l2_subdev_ops SC301IOT_subdev_ops = {
1881
- .core = &SC301IOT_core_ops,
1882
- .video = &SC301IOT_video_ops,
1883
- .pad = &SC301IOT_pad_ops,
1882
+static const struct v4l2_subdev_ops sc301iot_subdev_ops = {
1883
+ .core = &sc301iot_core_ops,
1884
+ .video = &sc301iot_video_ops,
1885
+ .pad = &sc301iot_pad_ops,
18841886 };
18851887
1886
-static void SC301IOT_modify_fps_info(struct SC301IOT *SC301IOT)
1888
+static void sc301iot_modify_fps_info(struct sc301iot *sc301iot)
18871889 {
1888
- const struct SC301IOT_mode *mode = SC301IOT->cur_mode;
1890
+ const struct sc301iot_mode *mode = sc301iot->cur_mode;
18891891
1890
- SC301IOT->cur_fps.denominator = mode->max_fps.denominator * mode->vts_def /
1891
- SC301IOT->cur_vts;
1892
+ sc301iot->cur_fps.denominator = mode->max_fps.denominator * mode->vts_def /
1893
+ sc301iot->cur_vts;
18921894 }
18931895
1894
-static int SC301IOT_set_ctrl(struct v4l2_ctrl *ctrl)
1896
+static int sc301iot_set_ctrl(struct v4l2_ctrl *ctrl)
18951897 {
1896
- struct SC301IOT *SC301IOT = container_of(ctrl->handler,
1897
- struct SC301IOT, ctrl_handler);
1898
- struct i2c_client *client = SC301IOT->client;
1898
+ struct sc301iot *sc301iot = container_of(ctrl->handler,
1899
+ struct sc301iot, ctrl_handler);
1900
+ struct i2c_client *client = sc301iot->client;
18991901 s64 max;
19001902 int ret = 0;
19011903 u32 val = 0;
....@@ -1904,11 +1906,11 @@
19041906 switch (ctrl->id) {
19051907 case V4L2_CID_VBLANK:
19061908 /* Update max exposure while meeting expected vblanking */
1907
- max = SC301IOT->cur_mode->height + ctrl->val - 4;
1908
- __v4l2_ctrl_modify_range(SC301IOT->exposure,
1909
- SC301IOT->exposure->minimum, max,
1910
- SC301IOT->exposure->step,
1911
- SC301IOT->exposure->default_value);
1909
+ max = sc301iot->cur_mode->height + ctrl->val - 4;
1910
+ __v4l2_ctrl_modify_range(sc301iot->exposure,
1911
+ sc301iot->exposure->minimum, max,
1912
+ sc301iot->exposure->step,
1913
+ sc301iot->exposure->default_value);
19121914 break;
19131915 }
19141916
....@@ -1917,57 +1919,56 @@
19171919
19181920 switch (ctrl->id) {
19191921 case V4L2_CID_EXPOSURE:
1920
- if (SC301IOT->cur_mode->hdr_mode == NO_HDR) {
1922
+ if (sc301iot->cur_mode->hdr_mode == NO_HDR) {
19211923 ctrl->val = ctrl->val;
19221924 /* 4 least significant bits of expsoure are fractional part */
1923
- ret = SC301IOT_write_reg(SC301IOT->client,
1925
+ ret = sc301iot_write_reg(sc301iot->client,
19241926 SC301IOT_REG_EXPOSURE_H,
19251927 SC301IOT_REG_VALUE_08BIT,
19261928 SC301IOT_FETCH_EXP_H(ctrl->val));
1927
- ret |= SC301IOT_write_reg(SC301IOT->client,
1929
+ ret |= sc301iot_write_reg(sc301iot->client,
19281930 SC301IOT_REG_EXPOSURE_M,
19291931 SC301IOT_REG_VALUE_08BIT,
19301932 SC301IOT_FETCH_EXP_M(ctrl->val));
1931
- ret |= SC301IOT_write_reg(SC301IOT->client,
1933
+ ret |= sc301iot_write_reg(sc301iot->client,
19321934 SC301IOT_REG_EXPOSURE_L,
19331935 SC301IOT_REG_VALUE_08BIT,
19341936 SC301IOT_FETCH_EXP_L(ctrl->val));
19351937 }
19361938 break;
19371939 case V4L2_CID_ANALOGUE_GAIN:
1938
- if (SC301IOT->cur_mode->hdr_mode == NO_HDR)
1939
- ret = SC301IOT_set_gain_reg(SC301IOT, ctrl->val, SC301IOT_LGAIN);
1940
+ if (sc301iot->cur_mode->hdr_mode == NO_HDR)
1941
+ ret = sc301iot_set_gain_reg(sc301iot, ctrl->val, SC301IOT_LGAIN);
19401942 break;
19411943 case V4L2_CID_VBLANK:
1942
- ret = SC301IOT_write_reg(SC301IOT->client,
1944
+ ret = sc301iot_write_reg(sc301iot->client,
19431945 SC301IOT_REG_VTS_H,
19441946 SC301IOT_REG_VALUE_08BIT,
1945
- (ctrl->val + SC301IOT->cur_mode->height)
1947
+ (ctrl->val + sc301iot->cur_mode->height)
19461948 >> 8);
1947
- ret |= SC301IOT_write_reg(SC301IOT->client,
1949
+ ret |= sc301iot_write_reg(sc301iot->client,
19481950 SC301IOT_REG_VTS_L,
19491951 SC301IOT_REG_VALUE_08BIT,
1950
- (ctrl->val + SC301IOT->cur_mode->height)
1952
+ (ctrl->val + sc301iot->cur_mode->height)
19511953 & 0xff);
19521954 if (!ret)
1953
- SC301IOT->cur_vts = ctrl->val + SC301IOT->cur_mode->height;
1954
- if (SC301IOT->cur_vts != SC301IOT->cur_mode->vts_def)
1955
- SC301IOT_modify_fps_info(SC301IOT);
1955
+ sc301iot->cur_vts = ctrl->val + sc301iot->cur_mode->height;
1956
+ sc301iot_modify_fps_info(sc301iot);
19561957 break;
19571958 case V4L2_CID_TEST_PATTERN:
1958
- ret = SC301IOT_enable_test_pattern(SC301IOT, ctrl->val);
1959
+ ret = sc301iot_enable_test_pattern(sc301iot, ctrl->val);
19591960 break;
19601961 case V4L2_CID_HFLIP:
1961
- ret = SC301IOT_read_reg(SC301IOT->client, SC301IOT_FLIP_MIRROR_REG,
1962
+ ret = sc301iot_read_reg(sc301iot->client, SC301IOT_FLIP_MIRROR_REG,
19621963 SC301IOT_REG_VALUE_08BIT, &val);
1963
- ret |= SC301IOT_write_reg(SC301IOT->client, SC301IOT_FLIP_MIRROR_REG,
1964
+ ret |= sc301iot_write_reg(sc301iot->client, SC301IOT_FLIP_MIRROR_REG,
19641965 SC301IOT_REG_VALUE_08BIT,
19651966 SC301IOT_FETCH_MIRROR(val, ctrl->val));
19661967 break;
19671968 case V4L2_CID_VFLIP:
1968
- ret = SC301IOT_read_reg(SC301IOT->client, SC301IOT_FLIP_MIRROR_REG,
1969
+ ret = sc301iot_read_reg(sc301iot->client, SC301IOT_FLIP_MIRROR_REG,
19691970 SC301IOT_REG_VALUE_08BIT, &val);
1970
- ret |= SC301IOT_write_reg(SC301IOT->client, SC301IOT_FLIP_MIRROR_REG,
1971
+ ret |= sc301iot_write_reg(sc301iot->client, SC301IOT_FLIP_MIRROR_REG,
19711972 SC301IOT_REG_VALUE_08BIT,
19721973 SC301IOT_FETCH_FLIP(val, ctrl->val));
19731974 break;
....@@ -1982,25 +1983,25 @@
19821983 return ret;
19831984 }
19841985
1985
-static const struct v4l2_ctrl_ops SC301IOT_ctrl_ops = {
1986
- .s_ctrl = SC301IOT_set_ctrl,
1986
+static const struct v4l2_ctrl_ops sc301iot_ctrl_ops = {
1987
+ .s_ctrl = sc301iot_set_ctrl,
19871988 };
19881989
1989
-static int SC301IOT_initialize_controls(struct SC301IOT *SC301IOT)
1990
+static int sc301iot_initialize_controls(struct sc301iot *sc301iot)
19901991 {
1991
- const struct SC301IOT_mode *mode;
1992
+ const struct sc301iot_mode *mode;
19921993 struct v4l2_ctrl_handler *handler;
19931994 struct v4l2_ctrl *ctrl;
19941995 s64 exposure_max, vblank_def;
19951996 u32 h_blank;
19961997 int ret;
19971998
1998
- handler = &SC301IOT->ctrl_handler;
1999
- mode = SC301IOT->cur_mode;
1999
+ handler = &sc301iot->ctrl_handler;
2000
+ mode = sc301iot->cur_mode;
20002001 ret = v4l2_ctrl_handler_init(handler, 9);
20012002 if (ret)
20022003 return ret;
2003
- handler->lock = &SC301IOT->mutex;
2004
+ handler->lock = &sc301iot->mutex;
20042005
20052006 ctrl = v4l2_ctrl_new_int_menu(handler, NULL, V4L2_CID_LINK_FREQ,
20062007 0, 0, link_freq_menu_items);
....@@ -2011,46 +2012,46 @@
20112012 0, PIXEL_RATE_WITH_594M_10BIT, 1, PIXEL_RATE_WITH_594M_10BIT);
20122013
20132014 h_blank = mode->hts_def - mode->width;
2014
- SC301IOT->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK,
2015
+ sc301iot->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK,
20152016 h_blank, h_blank, 1, h_blank);
2016
- if (SC301IOT->hblank)
2017
- SC301IOT->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
2017
+ if (sc301iot->hblank)
2018
+ sc301iot->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
20182019 vblank_def = mode->vts_def - mode->height;
2019
- SC301IOT->vblank = v4l2_ctrl_new_std(handler, &SC301IOT_ctrl_ops,
2020
+ sc301iot->vblank = v4l2_ctrl_new_std(handler, &sc301iot_ctrl_ops,
20202021 V4L2_CID_VBLANK, vblank_def,
20212022 SC301IOT_VTS_MAX - mode->height,
20222023 1, vblank_def);
20232024 exposure_max = mode->vts_def - 8;
2024
- SC301IOT->exposure = v4l2_ctrl_new_std(handler, &SC301IOT_ctrl_ops,
2025
+ sc301iot->exposure = v4l2_ctrl_new_std(handler, &sc301iot_ctrl_ops,
20252026 V4L2_CID_EXPOSURE, SC301IOT_EXPOSURE_MIN,
20262027 exposure_max, SC301IOT_EXPOSURE_STEP,
20272028 mode->exp_def);
2028
- SC301IOT->anal_gain = v4l2_ctrl_new_std(handler, &SC301IOT_ctrl_ops,
2029
+ sc301iot->anal_gain = v4l2_ctrl_new_std(handler, &sc301iot_ctrl_ops,
20292030 V4L2_CID_ANALOGUE_GAIN, SC301IOT_GAIN_MIN,
20302031 SC301IOT_GAIN_MAX, SC301IOT_GAIN_STEP,
20312032 SC301IOT_GAIN_DEFAULT);
2032
- SC301IOT->test_pattern = v4l2_ctrl_new_std_menu_items(handler,
2033
- &SC301IOT_ctrl_ops,
2033
+ sc301iot->test_pattern = v4l2_ctrl_new_std_menu_items(handler,
2034
+ &sc301iot_ctrl_ops,
20342035 V4L2_CID_TEST_PATTERN,
2035
- ARRAY_SIZE(SC301IOT_test_pattern_menu) - 1,
2036
- 0, 0, SC301IOT_test_pattern_menu);
2037
- v4l2_ctrl_new_std(handler, &SC301IOT_ctrl_ops,
2036
+ ARRAY_SIZE(sc301iot_test_pattern_menu) - 1,
2037
+ 0, 0, sc301iot_test_pattern_menu);
2038
+ v4l2_ctrl_new_std(handler, &sc301iot_ctrl_ops,
20382039 V4L2_CID_HFLIP, 0, 1, 1, 0);
20392040
2040
- v4l2_ctrl_new_std(handler, &SC301IOT_ctrl_ops,
2041
+ v4l2_ctrl_new_std(handler, &sc301iot_ctrl_ops,
20412042 V4L2_CID_VFLIP, 0, 1, 1, 0);
20422043
20432044 if (handler->error) {
20442045 ret = handler->error;
2045
- dev_err(&SC301IOT->client->dev,
2046
+ dev_err(&sc301iot->client->dev,
20462047 "Failed to init controls(%d)\n", ret);
20472048 goto err_free_handler;
20482049 }
20492050
2050
- SC301IOT->subdev.ctrl_handler = handler;
2051
- SC301IOT->has_init_exp = false;
2052
- SC301IOT->cur_fps = mode->max_fps;
2053
- SC301IOT->cur_vts = mode->vts_def;
2051
+ sc301iot->subdev.ctrl_handler = handler;
2052
+ sc301iot->has_init_exp = false;
2053
+ sc301iot->cur_fps = mode->max_fps;
2054
+ sc301iot->cur_vts = mode->vts_def;
20542055
20552056 return 0;
20562057
....@@ -2060,19 +2061,19 @@
20602061 return ret;
20612062 }
20622063
2063
-static int SC301IOT_check_sensor_id(struct SC301IOT *SC301IOT,
2064
+static int sc301iot_check_sensor_id(struct sc301iot *sc301iot,
20642065 struct i2c_client *client)
20652066 {
2066
- struct device *dev = &SC301IOT->client->dev;
2067
+ struct device *dev = &sc301iot->client->dev;
20672068 u32 id = 0;
20682069 int ret;
20692070
2070
- if (SC301IOT->is_thunderboot) {
2071
+ if (sc301iot->is_thunderboot) {
20712072 dev_info(dev, "Enable thunderboot mode, skip sensor id check\n");
20722073 return 0;
20732074 }
20742075
2075
- ret = SC301IOT_read_reg(client, SC301IOT_REG_CHIP_ID,
2076
+ ret = sc301iot_read_reg(client, SC301IOT_REG_CHIP_ID,
20762077 SC301IOT_REG_VALUE_16BIT, &id);
20772078 if (id != CHIP_ID) {
20782079 dev_err(dev, "Unexpected chip id(0x%04x), ret(%d)\n", id, ret);
....@@ -2084,24 +2085,24 @@
20842085 return 0;
20852086 }
20862087
2087
-static int SC301IOT_configure_regulators(struct SC301IOT *SC301IOT)
2088
+static int sc301iot_configure_regulators(struct sc301iot *sc301iot)
20882089 {
20892090 unsigned int i;
20902091
20912092 for (i = 0; i < SC301IOT_NUM_SUPPLIES; i++)
2092
- SC301IOT->supplies[i].supply = SC301IOT_supply_names[i];
2093
+ sc301iot->supplies[i].supply = SC301IOT_supply_names[i];
20932094
2094
- return devm_regulator_bulk_get(&SC301IOT->client->dev,
2095
+ return devm_regulator_bulk_get(&sc301iot->client->dev,
20952096 SC301IOT_NUM_SUPPLIES,
2096
- SC301IOT->supplies);
2097
+ sc301iot->supplies);
20972098 }
20982099
2099
-static int SC301IOT_probe(struct i2c_client *client,
2100
+static int sc301iot_probe(struct i2c_client *client,
21002101 const struct i2c_device_id *id)
21012102 {
21022103 struct device *dev = &client->dev;
21032104 struct device_node *node = dev->of_node;
2104
- struct SC301IOT *SC301IOT;
2105
+ struct sc301iot *sc301iot;
21052106 struct v4l2_subdev *sd;
21062107 char facing[2];
21072108 int ret;
....@@ -2113,39 +2114,39 @@
21132114 (DRIVER_VERSION & 0xff00) >> 8,
21142115 DRIVER_VERSION & 0x00ff);
21152116
2116
- SC301IOT = devm_kzalloc(dev, sizeof(*SC301IOT), GFP_KERNEL);
2117
- if (!SC301IOT)
2117
+ sc301iot = devm_kzalloc(dev, sizeof(*sc301iot), GFP_KERNEL);
2118
+ if (!sc301iot)
21182119 return -ENOMEM;
21192120
21202121 of_property_read_u32(node, OF_CAMERA_HDR_MODE, &hdr_mode);
21212122 ret = of_property_read_u32(node, RKMODULE_CAMERA_MODULE_INDEX,
2122
- &SC301IOT->module_index);
2123
+ &sc301iot->module_index);
21232124 ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_FACING,
2124
- &SC301IOT->module_facing);
2125
+ &sc301iot->module_facing);
21252126 ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_NAME,
2126
- &SC301IOT->module_name);
2127
+ &sc301iot->module_name);
21272128 ret |= of_property_read_string(node, RKMODULE_CAMERA_LENS_NAME,
2128
- &SC301IOT->len_name);
2129
+ &sc301iot->len_name);
21292130 if (ret) {
21302131 dev_err(dev, "could not get module information!\n");
21312132 return -EINVAL;
21322133 }
21332134
2134
- SC301IOT->is_thunderboot = IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP);
2135
- SC301IOT->sync_mode = NO_SYNC_MODE;
2135
+ sc301iot->is_thunderboot = IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP);
2136
+ sc301iot->sync_mode = NO_SYNC_MODE;
21362137 ret = of_property_read_string(node, RKMODULE_CAMERA_SYNC_MODE, &sync_mode_name);
21372138 if (!ret) {
21382139 if (strcmp(sync_mode_name, RKMODULE_EXTERNAL_MASTER_MODE) == 0)
2139
- SC301IOT->sync_mode = EXTERNAL_MASTER_MODE;
2140
+ sc301iot->sync_mode = EXTERNAL_MASTER_MODE;
21402141 else if (strcmp(sync_mode_name, RKMODULE_INTERNAL_MASTER_MODE) == 0)
2141
- SC301IOT->sync_mode = INTERNAL_MASTER_MODE;
2142
+ sc301iot->sync_mode = INTERNAL_MASTER_MODE;
21422143 else if (strcmp(sync_mode_name, RKMODULE_SLAVE_MODE) == 0)
2143
- SC301IOT->sync_mode = SLAVE_MODE;
2144
+ sc301iot->sync_mode = SLAVE_MODE;
21442145 }
21452146
2146
- switch (SC301IOT->sync_mode) {
2147
+ switch (sc301iot->sync_mode) {
21472148 default:
2148
- SC301IOT->sync_mode = NO_SYNC_MODE; break;
2149
+ sc301iot->sync_mode = NO_SYNC_MODE; break;
21492150 case NO_SYNC_MODE:
21502151 dev_info(dev, "sync_mode = [NO_SYNC_MODE]\n"); break;
21512152 case EXTERNAL_MASTER_MODE:
....@@ -2155,100 +2156,100 @@
21552156 dev_info(dev, "sync_mode = [SLAVE_MODE]\n"); break;
21562157 }
21572158
2158
- SC301IOT->client = client;
2159
+ sc301iot->client = client;
21592160 for (i = 0; i < ARRAY_SIZE(supported_modes); i++) {
21602161 if (hdr_mode == supported_modes[i].hdr_mode) {
2161
- SC301IOT->cur_mode = &supported_modes[i];
2162
+ sc301iot->cur_mode = &supported_modes[i];
21622163 break;
21632164 }
21642165 }
21652166 if (i == ARRAY_SIZE(supported_modes))
2166
- SC301IOT->cur_mode = &supported_modes[0];
2167
+ sc301iot->cur_mode = &supported_modes[0];
21672168
2168
- SC301IOT->xvclk = devm_clk_get(dev, "xvclk");
2169
- if (IS_ERR(SC301IOT->xvclk)) {
2169
+ sc301iot->xvclk = devm_clk_get(dev, "xvclk");
2170
+ if (IS_ERR(sc301iot->xvclk)) {
21702171 dev_err(dev, "Failed to get xvclk\n");
21712172 return -EINVAL;
21722173 }
21732174
2174
- if (SC301IOT->is_thunderboot) {
2175
- SC301IOT->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS);
2176
- if (IS_ERR(SC301IOT->reset_gpio))
2175
+ if (sc301iot->is_thunderboot) {
2176
+ sc301iot->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS);
2177
+ if (IS_ERR(sc301iot->reset_gpio))
21772178 dev_warn(dev, "Failed to get reset-gpios\n");
21782179
2179
- SC301IOT->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_ASIS);
2180
- if (IS_ERR(SC301IOT->pwdn_gpio))
2180
+ sc301iot->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_ASIS);
2181
+ if (IS_ERR(sc301iot->pwdn_gpio))
21812182 dev_warn(dev, "Failed to get pwdn-gpios\n");
21822183 } else {
2183
- SC301IOT->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
2184
- if (IS_ERR(SC301IOT->reset_gpio))
2184
+ sc301iot->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
2185
+ if (IS_ERR(sc301iot->reset_gpio))
21852186 dev_warn(dev, "Failed to get reset-gpios\n");
21862187
2187
- SC301IOT->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW);
2188
- if (IS_ERR(SC301IOT->pwdn_gpio))
2188
+ sc301iot->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW);
2189
+ if (IS_ERR(sc301iot->pwdn_gpio))
21892190 dev_warn(dev, "Failed to get pwdn-gpios\n");
21902191 }
21912192
2192
- SC301IOT->pinctrl = devm_pinctrl_get(dev);
2193
- if (!IS_ERR(SC301IOT->pinctrl)) {
2194
- SC301IOT->pins_default =
2195
- pinctrl_lookup_state(SC301IOT->pinctrl,
2193
+ sc301iot->pinctrl = devm_pinctrl_get(dev);
2194
+ if (!IS_ERR(sc301iot->pinctrl)) {
2195
+ sc301iot->pins_default =
2196
+ pinctrl_lookup_state(sc301iot->pinctrl,
21962197 OF_CAMERA_PINCTRL_STATE_DEFAULT);
2197
- if (IS_ERR(SC301IOT->pins_default))
2198
+ if (IS_ERR(sc301iot->pins_default))
21982199 dev_err(dev, "could not get default pinstate\n");
21992200
2200
- SC301IOT->pins_sleep =
2201
- pinctrl_lookup_state(SC301IOT->pinctrl,
2201
+ sc301iot->pins_sleep =
2202
+ pinctrl_lookup_state(sc301iot->pinctrl,
22022203 OF_CAMERA_PINCTRL_STATE_SLEEP);
2203
- if (IS_ERR(SC301IOT->pins_sleep))
2204
+ if (IS_ERR(sc301iot->pins_sleep))
22042205 dev_err(dev, "could not get sleep pinstate\n");
22052206 } else {
22062207 dev_err(dev, "no pinctrl\n");
22072208 }
22082209
2209
- ret = SC301IOT_configure_regulators(SC301IOT);
2210
+ ret = sc301iot_configure_regulators(sc301iot);
22102211 if (ret) {
22112212 dev_err(dev, "Failed to get power regulators\n");
22122213 return ret;
22132214 }
22142215
2215
- mutex_init(&SC301IOT->mutex);
2216
+ mutex_init(&sc301iot->mutex);
22162217
2217
- sd = &SC301IOT->subdev;
2218
- v4l2_i2c_subdev_init(sd, client, &SC301IOT_subdev_ops);
2219
- ret = SC301IOT_initialize_controls(SC301IOT);
2218
+ sd = &sc301iot->subdev;
2219
+ v4l2_i2c_subdev_init(sd, client, &sc301iot_subdev_ops);
2220
+ ret = sc301iot_initialize_controls(sc301iot);
22202221 if (ret)
22212222 goto err_destroy_mutex;
22222223
2223
- ret = __SC301IOT_power_on(SC301IOT);
2224
+ ret = __sc301iot_power_on(sc301iot);
22242225 if (ret)
22252226 goto err_free_handler;
22262227
2227
- ret = SC301IOT_check_sensor_id(SC301IOT, client);
2228
+ ret = sc301iot_check_sensor_id(sc301iot, client);
22282229 if (ret)
22292230 goto err_power_off;
22302231
22312232 #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
2232
- sd->internal_ops = &SC301IOT_internal_ops;
2233
+ sd->internal_ops = &sc301iot_internal_ops;
22332234 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
22342235 V4L2_SUBDEV_FL_HAS_EVENTS;
22352236 #endif
22362237 #if defined(CONFIG_MEDIA_CONTROLLER)
2237
- SC301IOT->pad.flags = MEDIA_PAD_FL_SOURCE;
2238
+ sc301iot->pad.flags = MEDIA_PAD_FL_SOURCE;
22382239 sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
2239
- ret = media_entity_pads_init(&sd->entity, 1, &SC301IOT->pad);
2240
+ ret = media_entity_pads_init(&sd->entity, 1, &sc301iot->pad);
22402241 if (ret < 0)
22412242 goto err_power_off;
22422243 #endif
22432244
22442245 memset(facing, 0, sizeof(facing));
2245
- if (strcmp(SC301IOT->module_facing, "back") == 0)
2246
+ if (strcmp(sc301iot->module_facing, "back") == 0)
22462247 facing[0] = 'b';
22472248 else
22482249 facing[0] = 'f';
22492250
22502251 snprintf(sd->name, sizeof(sd->name), "m%02d_%s_%s %s",
2251
- SC301IOT->module_index, facing,
2252
+ sc301iot->module_index, facing,
22522253 SC301IOT_NAME, dev_name(sd->dev));
22532254 ret = v4l2_async_register_subdev_sensor_common(sd);
22542255 if (ret) {
....@@ -2258,7 +2259,10 @@
22582259
22592260 pm_runtime_set_active(dev);
22602261 pm_runtime_enable(dev);
2261
- pm_runtime_idle(dev);
2262
+ if (sc301iot->is_thunderboot)
2263
+ pm_runtime_get_sync(dev);
2264
+ else
2265
+ pm_runtime_idle(dev);
22622266
22632267 return 0;
22642268
....@@ -2267,67 +2271,67 @@
22672271 media_entity_cleanup(&sd->entity);
22682272 #endif
22692273 err_power_off:
2270
- __SC301IOT_power_off(SC301IOT);
2274
+ __sc301iot_power_off(sc301iot);
22712275 err_free_handler:
2272
- v4l2_ctrl_handler_free(&SC301IOT->ctrl_handler);
2276
+ v4l2_ctrl_handler_free(&sc301iot->ctrl_handler);
22732277 err_destroy_mutex:
2274
- mutex_destroy(&SC301IOT->mutex);
2278
+ mutex_destroy(&sc301iot->mutex);
22752279
22762280 return ret;
22772281 }
22782282
2279
-static int SC301IOT_remove(struct i2c_client *client)
2283
+static int sc301iot_remove(struct i2c_client *client)
22802284 {
22812285 struct v4l2_subdev *sd = i2c_get_clientdata(client);
2282
- struct SC301IOT *SC301IOT = to_SC301IOT(sd);
2286
+ struct sc301iot *sc301iot = to_sc301iot(sd);
22832287
22842288 v4l2_async_unregister_subdev(sd);
22852289 #if defined(CONFIG_MEDIA_CONTROLLER)
22862290 media_entity_cleanup(&sd->entity);
22872291 #endif
2288
- v4l2_ctrl_handler_free(&SC301IOT->ctrl_handler);
2289
- mutex_destroy(&SC301IOT->mutex);
2292
+ v4l2_ctrl_handler_free(&sc301iot->ctrl_handler);
2293
+ mutex_destroy(&sc301iot->mutex);
22902294
22912295 pm_runtime_disable(&client->dev);
22922296 if (!pm_runtime_status_suspended(&client->dev))
2293
- __SC301IOT_power_off(SC301IOT);
2297
+ __sc301iot_power_off(sc301iot);
22942298 pm_runtime_set_suspended(&client->dev);
22952299
22962300 return 0;
22972301 }
22982302
22992303 #if IS_ENABLED(CONFIG_OF)
2300
-static const struct of_device_id SC301IOT_of_match[] = {
2301
- { .compatible = "smartsens,SC301IOT" },
2304
+static const struct of_device_id sc301iot_of_match[] = {
2305
+ { .compatible = "smartsens,sc301iot" },
23022306 {},
23032307 };
2304
-MODULE_DEVICE_TABLE(of, SC301IOT_of_match);
2308
+MODULE_DEVICE_TABLE(of, sc301iot_of_match);
23052309 #endif
23062310
2307
-static const struct i2c_device_id SC301IOT_match_id[] = {
2308
- { "smartsens,SC301IOT", 0 },
2311
+static const struct i2c_device_id sc301iot_match_id[] = {
2312
+ { "smartsens,sc301iot", 0 },
23092313 { },
23102314 };
23112315
2312
-static struct i2c_driver SC301IOT_i2c_driver = {
2316
+static struct i2c_driver sc301iot_i2c_driver = {
23132317 .driver = {
23142318 .name = SC301IOT_NAME,
2315
- .pm = &SC301IOT_pm_ops,
2316
- .of_match_table = of_match_ptr(SC301IOT_of_match),
2319
+ .pm = &sc301iot_pm_ops,
2320
+ .of_match_table = of_match_ptr(sc301iot_of_match),
23172321 },
2318
- .probe = &SC301IOT_probe,
2319
- .remove = &SC301IOT_remove,
2320
- .id_table = SC301IOT_match_id,
2322
+ .probe = &sc301iot_probe,
2323
+ .remove = &sc301iot_remove,
2324
+ .id_table = sc301iot_match_id,
23212325 };
23222326
23232327 static int __init sensor_mod_init(void)
23242328 {
2325
- return i2c_add_driver(&SC301IOT_i2c_driver);
2329
+ return i2c_add_driver(&sc301iot_i2c_driver);
23262330 }
23272331
23282332 static void __exit sensor_mod_exit(void)
23292333 {
2330
- i2c_del_driver(&SC301IOT_i2c_driver);
2334
+ i2c_del_driver(&sc301iot_i2c_driver);
23312335 }
23322336
23332337 #if defined(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP) && !defined(CONFIG_INITCALL_ASYNC)
....@@ -2337,5 +2341,5 @@
23372341 #endif
23382342 module_exit(sensor_mod_exit);
23392343
2340
-MODULE_DESCRIPTION("smartsens SC301IOT sensor driver");
2344
+MODULE_DESCRIPTION("smartsens sc301iot sensor driver");
23412345 MODULE_LICENSE("GPL");