hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/media/i2c/techpoint/techpoint_dev.c
....@@ -2,7 +2,7 @@
22 /*
33 * techpoint dev driver
44 *
5
- * Copyright (C) 2022 Rockchip Electronics Co., Ltd.
5
+ * Copyright (C) 2023 Rockchip Electronics Co., Ltd.
66 *
77 * V0.0X01.0X00 first version.
88 */
....@@ -13,7 +13,7 @@
1313 #include "techpoint_tp2855.h"
1414 #include "techpoint_tp2815.h"
1515
16
-static struct semaphore reg_sem;
16
+static DEFINE_MUTEX(reg_sem);
1717
1818 int techpoint_write_reg(struct i2c_client *client, u8 reg, u8 val)
1919 {
....@@ -126,10 +126,9 @@
126126 techpoint->chip_id = CHIP_TP9950;
127127 techpoint->input_type = TECHPOINT_MIPI;
128128 return 0;
129
- } else {
130
- dev_info(&client->dev, "techpoint check chip id failed !\n");
131129 }
132130
131
+ dev_info(&client->dev, "techpoint check chip id failed !\n");
133132 return -1;
134133 }
135134
....@@ -138,15 +137,12 @@
138137 if (check_chip_id(techpoint))
139138 return -1;
140139
141
- if (techpoint->chip_id == CHIP_TP9930) {
140
+ if (techpoint->chip_id == CHIP_TP9930)
142141 tp9930_initialize(techpoint);
143
- } else if (techpoint->chip_id == CHIP_TP2855) {
142
+ else if (techpoint->chip_id == CHIP_TP2855)
144143 tp2855_initialize(techpoint);
145
- } else if (techpoint->chip_id == CHIP_TP9950) {
144
+ else if (techpoint->chip_id == CHIP_TP9950)
146145 tp9950_initialize(techpoint);
147
- }
148
-
149
- sema_init(&reg_sem, 1);
150146
151147 return 0;
152148 }
....@@ -159,7 +155,7 @@
159155 int need_reset_wait = -1;
160156
161157 if (techpoint->power_on) {
162
- down(&reg_sem);
158
+ mutex_lock(&reg_sem);
163159 if (techpoint->chip_id == CHIP_TP9930) {
164160 tp9930_get_all_input_status(techpoint,
165161 techpoint->detect_status);
....@@ -173,12 +169,12 @@
173169 tp2855_set_decoder_mode(client, i,
174170 techpoint->detect_status[i]);
175171 }
176
- up(&reg_sem);
172
+ mutex_unlock(&reg_sem);
177173 techpoint->do_reset = 0;
178174 }
179175
180176 while (!kthread_should_stop()) {
181
- down(&reg_sem);
177
+ mutex_lock(&reg_sem);
182178 if (techpoint->power_on) {
183179 for (i = 0; i < PAD_MAX; i++) {
184180 if (techpoint->chip_id == CHIP_TP9930)
....@@ -220,7 +216,7 @@
220216 "trigger reset time up\n");
221217 }
222218 }
223
- up(&reg_sem);
219
+ mutex_unlock(&reg_sem);
224220 set_current_state(TASK_INTERRUPTIBLE);
225221 schedule_timeout(msecs_to_jiffies(200));
226222 }
....@@ -260,7 +256,7 @@
260256 enum techpoint_support_reso reso = 0xff;
261257 struct i2c_client *client = techpoint->client;
262258
263
- down(&reg_sem);
259
+ mutex_lock(&reg_sem);
264260
265261 for (ch = 0; ch < PAD_MAX; ch++) {
266262 if (techpoint->chip_id == CHIP_TP9930) {
....@@ -277,7 +273,7 @@
277273 tp9950_set_channel_reso(client, 0, reso);
278274 }
279275
280
- up(&reg_sem);
276
+ mutex_unlock(&reg_sem);
281277
282278 return 0;
283279 }
....@@ -290,7 +286,7 @@
290286 enum techpoint_support_reso reso = 0xff;
291287 struct i2c_client *client = techpoint->client;
292288
293
- down(&reg_sem);
289
+ mutex_lock(&reg_sem);
294290
295291 for (ch = 0; ch < PAD_MAX; ch++) {
296292 if (techpoint->chip_id == CHIP_TP9930) {
....@@ -341,27 +337,25 @@
341337 }
342338 }
343339
344
- up(&reg_sem);
340
+ mutex_unlock(&reg_sem);
345341 }
346342
347343 void techpoint_get_vc_fmt_inf(struct techpoint *techpoint,
348344 struct rkmodule_vc_fmt_info *inf)
349345 {
350
- down(&reg_sem);
346
+ mutex_lock(&reg_sem);
351347
352
- if (techpoint->chip_id == CHIP_TP9930) {
348
+ if (techpoint->chip_id == CHIP_TP9930)
353349 tp9930_pll_reset(techpoint->client);
354
- }
355350
356351 techpoint_write_array(techpoint->client,
357352 techpoint->cur_video_mode->common_reg_list,
358353 techpoint->cur_video_mode->common_reg_size);
359354
360
- if (techpoint->chip_id == CHIP_TP9930) {
355
+ if (techpoint->chip_id == CHIP_TP9930)
361356 tp9930_do_reset_pll(techpoint->client);
362
- }
363357
364
- up(&reg_sem);
358
+ mutex_unlock(&reg_sem);
365359
366360 __techpoint_get_vc_fmt_inf(techpoint, inf);
367361 }
....@@ -374,7 +368,7 @@
374368
375369 memset(inf, 0, sizeof(*inf));
376370
377
- down(&reg_sem);
371
+ mutex_lock(&reg_sem);
378372
379373 for (ch = 0; ch < 4; ch++) {
380374 if (techpoint->chip_id == CHIP_TP9930)
....@@ -387,14 +381,13 @@
387381 inf->detect_status |= detect_status << ch;
388382 }
389383
390
- up(&reg_sem);
384
+ mutex_unlock(&reg_sem);
391385 }
392386
393387 void techpoint_set_quick_stream(struct techpoint *techpoint, u32 stream)
394388 {
395
- if (techpoint->chip_id == CHIP_TP2855) {
389
+ if (techpoint->chip_id == CHIP_TP2855)
396390 tp2855_set_quick_stream(techpoint, stream);
397
- }
398391 }
399392
400393 int techpoint_start_video_stream(struct techpoint *techpoint)
....@@ -402,11 +395,10 @@
402395 int ret = 0;
403396 struct i2c_client *client = techpoint->client;
404397
405
- down(&reg_sem);
406
- if (techpoint->chip_id == CHIP_TP9930) {
398
+ mutex_lock(&reg_sem);
399
+ if (techpoint->chip_id == CHIP_TP9930)
407400 tp9930_pll_reset(techpoint->client);
408
- }
409
- up(&reg_sem);
401
+ mutex_unlock(&reg_sem);
410402
411403 auto_detect_channel_fmt(techpoint);
412404 ret = techpoint_write_array(techpoint->client,
....@@ -414,15 +406,14 @@
414406 techpoint->cur_video_mode->common_reg_size);
415407 if (ret) {
416408 dev_err(&client->dev,
417
- "techpoint_start_video_stream common_reg_list failed");
409
+ "%s common_reg_list failed", __func__);
418410 return ret;
419411 }
420412
421
- down(&reg_sem);
422
- if (techpoint->chip_id == CHIP_TP9930) {
413
+ mutex_lock(&reg_sem);
414
+ if (techpoint->chip_id == CHIP_TP9930)
423415 tp9930_do_reset_pll(techpoint->client);
424
- }
425
- up(&reg_sem);
416
+ mutex_unlock(&reg_sem);
426417
427418 usleep_range(500 * 1000, 1000 * 1000);
428419
....@@ -434,11 +425,5 @@
434425 int techpoint_stop_video_stream(struct techpoint *techpoint)
435426 {
436427 detect_thread_stop(techpoint);
437
-
438
- if (techpoint->chip_id == CHIP_TP9930) {
439
-
440
- } else if (techpoint->chip_id == CHIP_TP2855) {
441
-
442
- }
443428 return 0;
444429 }