forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
....@@ -1,17 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 *
3
- *
44 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
155 */
166
177 #include <linux/errno.h>
....@@ -316,6 +306,8 @@
316306 {FX2CMD_ONAIR_DTV_STREAMING_OFF, "onair dtv stream off"},
317307 {FX2CMD_ONAIR_DTV_POWER_ON, "onair dtv power on"},
318308 {FX2CMD_ONAIR_DTV_POWER_OFF, "onair dtv power off"},
309
+ {FX2CMD_HCW_DEMOD_RESET_PIN, "hcw demod reset pin"},
310
+ {FX2CMD_HCW_MAKO_SLEEP_PIN, "hcw mako sleep pin"},
319311 };
320312
321313
....@@ -668,7 +660,7 @@
668660 {
669661 if (v < 0 || v > PVR2_CVAL_INPUT_MAX)
670662 return 0;
671
- return ((1 << v) & cptr->hdw->input_allowed_mask) != 0;
663
+ return ((1UL << v) & cptr->hdw->input_allowed_mask) != 0;
672664 }
673665
674666 static int ctrl_set_input(struct pvr2_ctrl *cptr,int m,int v)
....@@ -792,7 +784,7 @@
792784
793785 static unsigned int ctrl_cx2341x_getv4lflags(struct pvr2_ctrl *cptr)
794786 {
795
- struct v4l2_queryctrl qctrl;
787
+ struct v4l2_queryctrl qctrl = {};
796788 struct pvr2_ctl_info *info;
797789 qctrl.id = cptr->info->v4l_id;
798790 cx2341x_ctrl_query(&cptr->hdw->enc_ctl_state,&qctrl);
....@@ -872,10 +864,9 @@
872864 const char *bufPtr,unsigned int bufSize,
873865 int *mskp,int *valp)
874866 {
875
- int ret;
876867 v4l2_std_id id;
877
- ret = pvr2_std_str_to_id(&id,bufPtr,bufSize);
878
- if (ret < 0) return ret;
868
+ if (!pvr2_std_str_to_id(&id, bufPtr, bufSize))
869
+ return -EINVAL;
879870 if (mskp) *mskp = id;
880871 if (valp) *valp = id;
881872 return 0;
....@@ -1700,7 +1691,7 @@
17001691 if (!hdw->flag_tripped) return 0;
17011692 hdw->flag_tripped = 0;
17021693 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1703
- "Clearing driver error statuss");
1694
+ "Clearing driver error status");
17041695 return !0;
17051696 }
17061697
....@@ -2139,9 +2130,27 @@
21392130 ((0) << 16));
21402131 }
21412132
2142
- // This step MUST happen after the earlier powerup step.
2133
+ /* This step MUST happen after the earlier powerup step */
21432134 pvr2_i2c_core_init(hdw);
21442135 if (!pvr2_hdw_dev_ok(hdw)) return;
2136
+
2137
+ /* Reset demod only on Hauppauge 160xxx platform */
2138
+ if (le16_to_cpu(hdw->usb_dev->descriptor.idVendor) == 0x2040 &&
2139
+ (le16_to_cpu(hdw->usb_dev->descriptor.idProduct) == 0x7502 ||
2140
+ le16_to_cpu(hdw->usb_dev->descriptor.idProduct) == 0x7510)) {
2141
+ pr_info("%s(): resetting 160xxx demod\n", __func__);
2142
+ /* TODO: not sure this is proper place to reset once only */
2143
+ pvr2_issue_simple_cmd(hdw,
2144
+ FX2CMD_HCW_DEMOD_RESET_PIN |
2145
+ (1 << 8) |
2146
+ ((0) << 16));
2147
+ usleep_range(10000, 10500);
2148
+ pvr2_issue_simple_cmd(hdw,
2149
+ FX2CMD_HCW_DEMOD_RESET_PIN |
2150
+ (1 << 8) |
2151
+ ((1) << 16));
2152
+ usleep_range(10000, 10500);
2153
+ }
21452154
21462155 pvr2_hdw_load_modules(hdw);
21472156 if (!pvr2_hdw_dev_ok(hdw)) return;
....@@ -2435,7 +2444,7 @@
24352444 /* Ensure that default input choice is a valid one. */
24362445 m = hdw->input_avail_mask;
24372446 if (m) for (idx = 0; idx < (sizeof(m) << 3); idx++) {
2438
- if (!((1 << idx) & m)) continue;
2447
+ if (!((1UL << idx) & m)) continue;
24392448 hdw->input_val = idx;
24402449 break;
24412450 }
....@@ -2461,9 +2470,8 @@
24612470 if (!(qctrl.flags & V4L2_CTRL_FLAG_READ_ONLY)) {
24622471 ciptr->set_value = ctrl_cx2341x_set;
24632472 }
2464
- strncpy(hdw->mpeg_ctrl_info[idx].desc,qctrl.name,
2465
- PVR2_CTLD_INFO_DESC_SIZE);
2466
- hdw->mpeg_ctrl_info[idx].desc[PVR2_CTLD_INFO_DESC_SIZE-1] = 0;
2473
+ strscpy(hdw->mpeg_ctrl_info[idx].desc, qctrl.name,
2474
+ sizeof(hdw->mpeg_ctrl_info[idx].desc));
24672475 ciptr->default_value = qctrl.default_value;
24682476 switch (qctrl.type) {
24692477 default:
....@@ -2492,11 +2500,11 @@
24922500 // Initialize control data regarding video standard masks
24932501 valid_std_mask = pvr2_std_get_usable();
24942502 for (idx = 0; idx < 32; idx++) {
2495
- if (!(valid_std_mask & (1 << idx))) continue;
2503
+ if (!(valid_std_mask & (1UL << idx))) continue;
24962504 cnt1 = pvr2_std_id_to_str(
24972505 hdw->std_mask_names[idx],
24982506 sizeof(hdw->std_mask_names[idx])-1,
2499
- 1 << idx);
2507
+ 1UL << idx);
25002508 hdw->std_mask_names[idx][cnt1] = 0;
25012509 }
25022510 cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_STDAVAIL);
....@@ -2561,6 +2569,11 @@
25612569 } while (0);
25622570 mutex_unlock(&pvr2_unit_mtx);
25632571
2572
+ INIT_WORK(&hdw->workpoll, pvr2_hdw_worker_poll);
2573
+
2574
+ if (hdw->unit_number == -1)
2575
+ goto fail;
2576
+
25642577 cnt1 = 0;
25652578 cnt2 = scnprintf(hdw->name+cnt1,sizeof(hdw->name)-cnt1,"pvrusb2");
25662579 cnt1 += cnt2;
....@@ -2571,8 +2584,6 @@
25712584 }
25722585 if (cnt1 >= sizeof(hdw->name)) cnt1 = sizeof(hdw->name)-1;
25732586 hdw->name[cnt1] = 0;
2574
-
2575
- INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll);
25762587
25772588 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s",
25782589 hdw->unit_number,hdw->name);
....@@ -2599,6 +2610,7 @@
25992610 del_timer_sync(&hdw->encoder_run_timer);
26002611 del_timer_sync(&hdw->encoder_wait_timer);
26012612 flush_work(&hdw->workpoll);
2613
+ v4l2_device_unregister(&hdw->v4l2_dev);
26022614 usb_free_urb(hdw->ctl_read_urb);
26032615 usb_free_urb(hdw->ctl_write_urb);
26042616 kfree(hdw->ctl_read_buffer);
....@@ -3295,12 +3307,12 @@
32953307 int nr = pvr2_hdw_get_unit_number(hdw);
32963308 LOCK_TAKE(hdw->big_lock);
32973309 do {
3298
- printk(KERN_INFO "pvrusb2: ================= START STATUS CARD #%d =================\n", nr);
3310
+ pr_info("pvrusb2: ================= START STATUS CARD #%d =================\n", nr);
32993311 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, log_status);
33003312 pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:");
33013313 cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2");
33023314 pvr2_hdw_state_log_state(hdw);
3303
- printk(KERN_INFO "pvrusb2: ================== END STATUS CARD #%d ==================\n", nr);
3315
+ pr_info("pvrusb2: ================== END STATUS CARD #%d ==================\n", nr);
33043316 } while (0);
33053317 LOCK_GIVE(hdw->big_lock);
33063318 }
....@@ -3320,7 +3332,7 @@
33203332 int ret;
33213333 int mode16 = 0;
33223334 unsigned pcnt,tcnt;
3323
- eeprom = kmalloc(EEPROM_SIZE,GFP_KERNEL);
3335
+ eeprom = kzalloc(EEPROM_SIZE, GFP_KERNEL);
33243336 if (!eeprom) {
33253337 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
33263338 "Failed to allocate memory required to read eeprom");
....@@ -3355,7 +3367,6 @@
33553367 (1) we're only fetching part of the eeprom, and (2) if we were
33563368 getting the whole thing our I2C driver can't grab it in one
33573369 pass - which is what tveeprom is otherwise going to attempt */
3358
- memset(eeprom,0,EEPROM_SIZE);
33593370 for (tcnt = 0; tcnt < EEPROM_SIZE; tcnt += pcnt) {
33603371 pcnt = 16;
33613372 if (pcnt + tcnt > EEPROM_SIZE) pcnt = EEPROM_SIZE-tcnt;
....@@ -4013,6 +4024,20 @@
40134024 static int pvr2_hdw_cmd_hcw_demod_reset(struct pvr2_hdw *hdw, int onoff)
40144025 {
40154026 hdw->flag_ok = !0;
4027
+
4028
+ /* Use this for Hauppauge 160xxx only */
4029
+ if (le16_to_cpu(hdw->usb_dev->descriptor.idVendor) == 0x2040 &&
4030
+ (le16_to_cpu(hdw->usb_dev->descriptor.idProduct) == 0x7502 ||
4031
+ le16_to_cpu(hdw->usb_dev->descriptor.idProduct) == 0x7510)) {
4032
+ pr_debug("%s(): resetting demod on Hauppauge 160xxx platform skipped\n",
4033
+ __func__);
4034
+ /* Can't reset 160xxx or it will trash Demod tristate */
4035
+ return pvr2_issue_simple_cmd(hdw,
4036
+ FX2CMD_HCW_MAKO_SLEEP_PIN |
4037
+ (1 << 8) |
4038
+ ((onoff ? 1 : 0) << 16));
4039
+ }
4040
+
40164041 return pvr2_issue_simple_cmd(hdw,
40174042 FX2CMD_HCW_DEMOD_RESETIN |
40184043 (1 << 8) |
....@@ -4650,7 +4675,7 @@
46504675 unsigned int idx,ccnt;
46514676 unsigned int tcnt = 0;
46524677 for (idx = 0; idx < ARRAY_SIZE(control_values_input); idx++) {
4653
- if (!((1 << idx) & msk)) continue;
4678
+ if (!((1UL << idx) & msk)) continue;
46544679 ccnt = scnprintf(buf+tcnt,
46554680 acnt-tcnt,
46564681 "%s%s",
....@@ -4853,7 +4878,7 @@
48534878 for (idx = 0; ; idx++) {
48544879 ccnt = pvr2_hdw_report_unlocked(hdw,idx,buf,sizeof(buf));
48554880 if (!ccnt) break;
4856
- printk(KERN_INFO "%s %.*s\n",hdw->name,ccnt,buf);
4881
+ pr_info("%s %.*s\n", hdw->name, ccnt, buf);
48574882 }
48584883 ccnt = pvr2_hdw_report_clients(hdw, buf, sizeof(buf));
48594884 if (ccnt >= sizeof(buf))
....@@ -4865,7 +4890,7 @@
48654890 while ((lcnt + ucnt < ccnt) && (buf[lcnt + ucnt] != '\n')) {
48664891 lcnt++;
48674892 }
4868
- printk(KERN_INFO "%s %.*s\n", hdw->name, lcnt, buf + ucnt);
4893
+ pr_info("%s %.*s\n", hdw->name, lcnt, buf + ucnt);
48694894 ucnt += lcnt + 1;
48704895 }
48714896 }
....@@ -5077,7 +5102,7 @@
50775102 break;
50785103 }
50795104 hdw->input_allowed_mask = nv;
5080
- if ((1 << hdw->input_val) & hdw->input_allowed_mask) {
5105
+ if ((1UL << hdw->input_val) & hdw->input_allowed_mask) {
50815106 /* Current mode is still in the allowed mask, so
50825107 we're done. */
50835108 break;
....@@ -5090,7 +5115,7 @@
50905115 }
50915116 m = hdw->input_allowed_mask;
50925117 for (idx = 0; idx < (sizeof(m) << 3); idx++) {
5093
- if (!((1 << idx) & m)) continue;
5118
+ if (!((1UL << idx) & m)) continue;
50945119 pvr2_hdw_set_input(hdw,idx);
50955120 break;
50965121 }