forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/media/usb/pvrusb2/pvrusb2-dvb.c
....@@ -1,17 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * pvrusb2-dvb.c - linux-dvb api interface to the pvrusb2 driver.
34 *
45 * Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
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
- *
156 */
167
178 #include <linux/kthread.h>
....@@ -343,26 +334,19 @@
343334 goto done;
344335 }
345336
346
- if ((dvb_props->frontend_attach(adap) == 0) && (adap->fe)) {
347
-
348
- if (dvb_register_frontend(&adap->dvb_adap, adap->fe)) {
337
+ if (dvb_props->frontend_attach(adap) == 0 && adap->fe[0]) {
338
+ if (dvb_register_frontend(&adap->dvb_adap, adap->fe[0])) {
349339 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
350340 "frontend registration failed!");
351
- dvb_frontend_detach(adap->fe);
352
- adap->fe = NULL;
353341 ret = -ENODEV;
354
- goto done;
342
+ goto fail_frontend0;
355343 }
344
+ if (adap->fe[0]->ops.analog_ops.standby)
345
+ adap->fe[0]->ops.analog_ops.standby(adap->fe[0]);
356346
357
- if (dvb_props->tuner_attach)
358
- dvb_props->tuner_attach(adap);
359
-
360
- if (adap->fe->ops.analog_ops.standby)
361
- adap->fe->ops.analog_ops.standby(adap->fe);
362
-
363
- /* Ensure all frontends negotiate bus access */
364
- adap->fe->ops.ts_bus_ctrl = pvr2_dvb_bus_ctrl;
365
-
347
+ pvr2_trace(PVR2_TRACE_INFO, "transferring fe[%d] ts_bus_ctrl() to pvr2_dvb_bus_ctrl()",
348
+ adap->fe[0]->id);
349
+ adap->fe[0]->ops.ts_bus_ctrl = pvr2_dvb_bus_ctrl;
366350 } else {
367351 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
368352 "no frontend was attached!");
....@@ -370,17 +354,74 @@
370354 return ret;
371355 }
372356
373
- done:
357
+ if (dvb_props->tuner_attach && dvb_props->tuner_attach(adap)) {
358
+ pvr2_trace(PVR2_TRACE_ERROR_LEGS, "tuner attach failed");
359
+ ret = -ENODEV;
360
+ goto fail_tuner;
361
+ }
362
+
363
+ if (adap->fe[1]) {
364
+ adap->fe[1]->id = 1;
365
+ adap->fe[1]->tuner_priv = adap->fe[0]->tuner_priv;
366
+ memcpy(&adap->fe[1]->ops.tuner_ops,
367
+ &adap->fe[0]->ops.tuner_ops,
368
+ sizeof(struct dvb_tuner_ops));
369
+
370
+ if (dvb_register_frontend(&adap->dvb_adap, adap->fe[1])) {
371
+ pvr2_trace(PVR2_TRACE_ERROR_LEGS,
372
+ "frontend registration failed!");
373
+ ret = -ENODEV;
374
+ goto fail_frontend1;
375
+ }
376
+ /* MFE lock */
377
+ adap->dvb_adap.mfe_shared = 1;
378
+
379
+ if (adap->fe[1]->ops.analog_ops.standby)
380
+ adap->fe[1]->ops.analog_ops.standby(adap->fe[1]);
381
+
382
+ pvr2_trace(PVR2_TRACE_INFO, "transferring fe[%d] ts_bus_ctrl() to pvr2_dvb_bus_ctrl()",
383
+ adap->fe[1]->id);
384
+ adap->fe[1]->ops.ts_bus_ctrl = pvr2_dvb_bus_ctrl;
385
+ }
386
+done:
374387 pvr2_channel_limit_inputs(&adap->channel, 0);
388
+ return ret;
389
+
390
+fail_frontend1:
391
+ dvb_frontend_detach(adap->fe[1]);
392
+ adap->fe[1] = NULL;
393
+fail_tuner:
394
+ dvb_unregister_frontend(adap->fe[0]);
395
+fail_frontend0:
396
+ dvb_frontend_detach(adap->fe[0]);
397
+ adap->fe[0] = NULL;
398
+ dvb_module_release(adap->i2c_client_tuner);
399
+ dvb_module_release(adap->i2c_client_demod[1]);
400
+ dvb_module_release(adap->i2c_client_demod[0]);
401
+
375402 return ret;
376403 }
377404
378405 static int pvr2_dvb_frontend_exit(struct pvr2_dvb_adapter *adap)
379406 {
380
- if (adap->fe != NULL) {
381
- dvb_unregister_frontend(adap->fe);
382
- dvb_frontend_detach(adap->fe);
407
+ if (adap->fe[1]) {
408
+ dvb_unregister_frontend(adap->fe[1]);
409
+ dvb_frontend_detach(adap->fe[1]);
410
+ adap->fe[1] = NULL;
383411 }
412
+ if (adap->fe[0]) {
413
+ dvb_unregister_frontend(adap->fe[0]);
414
+ dvb_frontend_detach(adap->fe[0]);
415
+ adap->fe[0] = NULL;
416
+ }
417
+
418
+ dvb_module_release(adap->i2c_client_tuner);
419
+ adap->i2c_client_tuner = NULL;
420
+ dvb_module_release(adap->i2c_client_demod[1]);
421
+ adap->i2c_client_demod[1] = NULL;
422
+ dvb_module_release(adap->i2c_client_demod[0]);
423
+ adap->i2c_client_demod[0] = NULL;
424
+
384425 return 0;
385426 }
386427