hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
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 */
....@@ -12,8 +12,9 @@
1212 #include "techpoint_tp9950.h"
1313 #include "techpoint_tp2855.h"
1414 #include "techpoint_tp2815.h"
15
+#include "techpoint_tp9951.h"
1516
16
-static struct semaphore reg_sem;
17
+static DEFINE_MUTEX(reg_sem);
1718
1819 int techpoint_write_reg(struct i2c_client *client, u8 reg, u8 val)
1920 {
....@@ -99,37 +100,43 @@
99100 techpoint_read_reg(client, CHIP_ID_L_REG, &chip_id_l);
100101 dev_err(dev, "chip_id_h:0x%2x chip_id_l:0x%2x\n", chip_id_h, chip_id_l);
101102 if (chip_id_h == TP9930_CHIP_ID_H_VALUE &&
102
- chip_id_l == TP9930_CHIP_ID_L_VALUE) {
103
+ chip_id_l == TP9930_CHIP_ID_L_VALUE) { //tp2832
103104 dev_info(&client->dev,
104105 "techpoint check chip id CHIP_TP9930 !\n");
105106 techpoint->chip_id = CHIP_TP9930;
106107 techpoint->input_type = TECHPOINT_DVP_BT1120;
107108 return 0;
108109 } else if (chip_id_h == TP2855_CHIP_ID_H_VALUE &&
109
- chip_id_l == TP2855_CHIP_ID_L_VALUE) {
110
+ chip_id_l == TP2855_CHIP_ID_L_VALUE) { //tp2855
110111 dev_info(&client->dev,
111112 "techpoint check chip id CHIP_TP2855 !\n");
112113 techpoint->chip_id = CHIP_TP2855;
113114 techpoint->input_type = TECHPOINT_MIPI;
114115 return 0;
115116 } else if (chip_id_h == TP2815_CHIP_ID_H_VALUE &&
116
- chip_id_l == TP2815_CHIP_ID_L_VALUE) {
117
+ chip_id_l == TP2815_CHIP_ID_L_VALUE) { //tp2815
117118 dev_info(&client->dev,
118119 "techpoint check chip id CHIP_TP2815 !\n");
119120 techpoint->chip_id = CHIP_TP2855;
120121 techpoint->input_type = TECHPOINT_MIPI;
121122 return 0;
122123 } else if (chip_id_h == TP9950_CHIP_ID_H_VALUE &&
123
- chip_id_l == TP9950_CHIP_ID_L_VALUE) {
124
+ chip_id_l == TP9950_CHIP_ID_L_VALUE) { //tp2850
124125 dev_info(&client->dev,
125126 "techpoint check chip id CHIP_TP9950 !\n");
126127 techpoint->chip_id = CHIP_TP9950;
127128 techpoint->input_type = TECHPOINT_MIPI;
128129 return 0;
129
- } else {
130
- dev_info(&client->dev, "techpoint check chip id failed !\n");
130
+ } else if (chip_id_h == TP9951_CHIP_ID_H_VALUE &&
131
+ chip_id_l == TP9951_CHIP_ID_L_VALUE) { //tp2860
132
+ dev_info(&client->dev,
133
+ "techpoint check chip id CHIP_TP9951 !\n");
134
+ techpoint->chip_id = CHIP_TP9951;
135
+ techpoint->input_type = TECHPOINT_MIPI;
136
+ return 0;
131137 }
132138
139
+ dev_info(&client->dev, "techpoint check chip id failed !\n");
133140 return -1;
134141 }
135142
....@@ -138,15 +145,14 @@
138145 if (check_chip_id(techpoint))
139146 return -1;
140147
141
- if (techpoint->chip_id == CHIP_TP9930) {
148
+ if (techpoint->chip_id == CHIP_TP9930)
142149 tp9930_initialize(techpoint);
143
- } else if (techpoint->chip_id == CHIP_TP2855) {
150
+ else if (techpoint->chip_id == CHIP_TP2855)
144151 tp2855_initialize(techpoint);
145
- } else if (techpoint->chip_id == CHIP_TP9950) {
152
+ else if (techpoint->chip_id == CHIP_TP9950)
146153 tp9950_initialize(techpoint);
147
- }
148
-
149
- sema_init(&reg_sem, 1);
154
+ else if (techpoint->chip_id == CHIP_TP9951)
155
+ tp9951_initialize(techpoint);
150156
151157 return 0;
152158 }
....@@ -159,7 +165,7 @@
159165 int need_reset_wait = -1;
160166
161167 if (techpoint->power_on) {
162
- down(&reg_sem);
168
+ mutex_lock(&reg_sem);
163169 if (techpoint->chip_id == CHIP_TP9930) {
164170 tp9930_get_all_input_status(techpoint,
165171 techpoint->detect_status);
....@@ -173,12 +179,12 @@
173179 tp2855_set_decoder_mode(client, i,
174180 techpoint->detect_status[i]);
175181 }
176
- up(&reg_sem);
182
+ mutex_unlock(&reg_sem);
177183 techpoint->do_reset = 0;
178184 }
179185
180186 while (!kthread_should_stop()) {
181
- down(&reg_sem);
187
+ mutex_lock(&reg_sem);
182188 if (techpoint->power_on) {
183189 for (i = 0; i < PAD_MAX; i++) {
184190 if (techpoint->chip_id == CHIP_TP9930)
....@@ -188,6 +194,10 @@
188194 else if (techpoint->chip_id == CHIP_TP2855)
189195 detect_status =
190196 tp2855_get_channel_input_status
197
+ (techpoint, i);
198
+ else if (techpoint->chip_id == CHIP_TP9951)
199
+ detect_status =
200
+ tp9951_get_channel_input_status
191201 (techpoint, i);
192202
193203 if (techpoint->detect_status[i] !=
....@@ -206,8 +216,7 @@
206216 else if (techpoint->chip_id == CHIP_TP2855)
207217 tp2855_set_decoder_mode(client, i, detect_status);
208218
209
- techpoint->detect_status[i] =
210
- detect_status;
219
+ techpoint->detect_status[i] = detect_status;
211220 need_reset_wait = 5;
212221 }
213222 }
....@@ -220,7 +229,7 @@
220229 "trigger reset time up\n");
221230 }
222231 }
223
- up(&reg_sem);
232
+ mutex_unlock(&reg_sem);
224233 set_current_state(TASK_INTERRUPTIBLE);
225234 schedule_timeout(msecs_to_jiffies(200));
226235 }
....@@ -260,7 +269,7 @@
260269 enum techpoint_support_reso reso = 0xff;
261270 struct i2c_client *client = techpoint->client;
262271
263
- down(&reg_sem);
272
+ mutex_lock(&reg_sem);
264273
265274 for (ch = 0; ch < PAD_MAX; ch++) {
266275 if (techpoint->chip_id == CHIP_TP9930) {
....@@ -277,7 +286,12 @@
277286 tp9950_set_channel_reso(client, 0, reso);
278287 }
279288
280
- up(&reg_sem);
289
+ if (techpoint->chip_id == CHIP_TP9951) {
290
+ reso = tp9951_get_channel_reso(client, 0);
291
+ tp9951_set_channel_reso(client, 0, reso);
292
+ }
293
+
294
+ mutex_unlock(&reg_sem);
281295
282296 return 0;
283297 }
....@@ -290,7 +304,7 @@
290304 enum techpoint_support_reso reso = 0xff;
291305 struct i2c_client *client = techpoint->client;
292306
293
- down(&reg_sem);
307
+ mutex_lock(&reg_sem);
294308
295309 for (ch = 0; ch < PAD_MAX; ch++) {
296310 if (techpoint->chip_id == CHIP_TP9930) {
....@@ -341,27 +355,25 @@
341355 }
342356 }
343357
344
- up(&reg_sem);
358
+ mutex_unlock(&reg_sem);
345359 }
346360
347361 void techpoint_get_vc_fmt_inf(struct techpoint *techpoint,
348362 struct rkmodule_vc_fmt_info *inf)
349363 {
350
- down(&reg_sem);
364
+ mutex_lock(&reg_sem);
351365
352
- if (techpoint->chip_id == CHIP_TP9930) {
366
+ if (techpoint->chip_id == CHIP_TP9930)
353367 tp9930_pll_reset(techpoint->client);
354
- }
355368
356369 techpoint_write_array(techpoint->client,
357370 techpoint->cur_video_mode->common_reg_list,
358371 techpoint->cur_video_mode->common_reg_size);
359372
360
- if (techpoint->chip_id == CHIP_TP9930) {
373
+ if (techpoint->chip_id == CHIP_TP9930)
361374 tp9930_do_reset_pll(techpoint->client);
362
- }
363375
364
- up(&reg_sem);
376
+ mutex_unlock(&reg_sem);
365377
366378 __techpoint_get_vc_fmt_inf(techpoint, inf);
367379 }
....@@ -374,7 +386,7 @@
374386
375387 memset(inf, 0, sizeof(*inf));
376388
377
- down(&reg_sem);
389
+ mutex_lock(&reg_sem);
378390
379391 for (ch = 0; ch < 4; ch++) {
380392 if (techpoint->chip_id == CHIP_TP9930)
....@@ -387,14 +399,13 @@
387399 inf->detect_status |= detect_status << ch;
388400 }
389401
390
- up(&reg_sem);
402
+ mutex_unlock(&reg_sem);
391403 }
392404
393405 void techpoint_set_quick_stream(struct techpoint *techpoint, u32 stream)
394406 {
395
- if (techpoint->chip_id == CHIP_TP2855) {
407
+ if (techpoint->chip_id == CHIP_TP2855)
396408 tp2855_set_quick_stream(techpoint, stream);
397
- }
398409 }
399410
400411 int techpoint_start_video_stream(struct techpoint *techpoint)
....@@ -402,11 +413,10 @@
402413 int ret = 0;
403414 struct i2c_client *client = techpoint->client;
404415
405
- down(&reg_sem);
406
- if (techpoint->chip_id == CHIP_TP9930) {
416
+ mutex_lock(&reg_sem);
417
+ if (techpoint->chip_id == CHIP_TP9930)
407418 tp9930_pll_reset(techpoint->client);
408
- }
409
- up(&reg_sem);
419
+ mutex_unlock(&reg_sem);
410420
411421 auto_detect_channel_fmt(techpoint);
412422 ret = techpoint_write_array(techpoint->client,
....@@ -414,15 +424,14 @@
414424 techpoint->cur_video_mode->common_reg_size);
415425 if (ret) {
416426 dev_err(&client->dev,
417
- "techpoint_start_video_stream common_reg_list failed");
427
+ "%s common_reg_list failed", __func__);
418428 return ret;
419429 }
420430
421
- down(&reg_sem);
422
- if (techpoint->chip_id == CHIP_TP9930) {
431
+ mutex_lock(&reg_sem);
432
+ if (techpoint->chip_id == CHIP_TP9930)
423433 tp9930_do_reset_pll(techpoint->client);
424
- }
425
- up(&reg_sem);
434
+ mutex_unlock(&reg_sem);
426435
427436 usleep_range(500 * 1000, 1000 * 1000);
428437
....@@ -434,11 +443,5 @@
434443 int techpoint_stop_video_stream(struct techpoint *techpoint)
435444 {
436445 detect_thread_stop(techpoint);
437
-
438
- if (techpoint->chip_id == CHIP_TP9930) {
439
-
440
- } else if (techpoint->chip_id == CHIP_TP2855) {
441
-
442
- }
443446 return 0;
444447 }