diff mbox

add support for the dvb-t part of CT-3650 v3

Message ID 4E260E4A.2020707@iki.fi (mailing list archive)
State RFC
Headers show

Commit Message

Antti Palosaari July 19, 2011, 11:07 p.m. UTC
On 07/19/2011 11:25 AM, Jose Alberto Reguero wrote:
> On Martes, 19 de Julio de 2011 01:44:54 Antti Palosaari escribió:
>> On 07/19/2011 02:00 AM, Jose Alberto Reguero wrote:
>>> On Lunes, 18 de Julio de 2011 22:28:41 Antti Palosaari escribió:

>>> There are two problems:
>>>
>>> First, the two frontends (tda10048 and tda10023)  use tda10023 i2c gate
>>> to talk with the tuner.
>>
>> Very easy to implement correctly. Attach tda10023 first and after that
>> tda10048. Override tda10048 .i2c_gate_ctrl() with tda10023
>> .i2c_gate_ctrl() immediately after tda10048 attach inside ttusb2.c. Now
>> you have both demods (FEs) .i2c_gate_ctrl() which will control
>> physically tda10023 I2C-gate as tuner is behind it.
>>
>
> I try that, but don't work. I get an oops. Because the i2c gate function of
> the tda10023 driver use:
>
> struct tda10023_state* state = fe->demodulator_priv;
>
> to get the i2c adress. When called from tda10048, don't work.
>
> Jose Alberto
>
>>> The second is that with dvb-usb, there is only one frontend, and if you
>>> wake up the second frontend, the adapter is not wake up. That can be
>>> avoided the way I do in the patch, or mantaining the adapter alwais on.
>>
>> I think that could be also avoided similarly overriding demod callbacks
>> and adding some more logic inside ttusb2.c.
>>
>> Proper fix that later problem is surely correct MFE support for
>> DVB-USB-framework. I am now looking for it, lets see how difficult it
>> will be.


Signed-off-by: Antti Palosaari <crope@iki.fi>

Test attached patches and try to fix if they are not working. Most 
likely not working since I don't have HW to test... I tested MFE parts 
using Anysee, so it should be working. I changed rather much your ttusb2 
and tda10048 patches, size reduced something like 50% or more. Still 
ttusb2 I2C-adapter changes made looks rather complex. Try to double 
check if those can be done easier. There is many drivers to look example 
from.

DVB USB MFE is something like RFC. I know FE exclusive lock is missing, 
no need to mention that :) But other comments are welcome! I left three 
old "unneeded" pointers to struct dvb_usb_adapter to reduce changing all 
the drivers.


regards
Antti

Comments

Antti Palosaari July 22, 2011, 11:32 a.m. UTC | #1
Have you had to time test these?

And about I2C adapter, I don't see why changes are needed. As far as I 
understand it is already working with TDA10023 and you have done changes 
for TDA10048 support. I compared TDA10048 and TDA10023 I2C functions and 
those are ~similar. Both uses most typical access, for reg write {u8 
REG, u8 VAL} and for reg read {u8 REG}/{u8 VAL}.

regards
Antti


On 07/20/2011 02:07 AM, Antti Palosaari wrote:
> On 07/19/2011 11:25 AM, Jose Alberto Reguero wrote:
>> On Martes, 19 de Julio de 2011 01:44:54 Antti Palosaari escribió:
>>> On 07/19/2011 02:00 AM, Jose Alberto Reguero wrote:
>>>> On Lunes, 18 de Julio de 2011 22:28:41 Antti Palosaari escribió:
>
>>>> There are two problems:
>>>>
>>>> First, the two frontends (tda10048 and tda10023) use tda10023 i2c gate
>>>> to talk with the tuner.
>>>
>>> Very easy to implement correctly. Attach tda10023 first and after that
>>> tda10048. Override tda10048 .i2c_gate_ctrl() with tda10023
>>> .i2c_gate_ctrl() immediately after tda10048 attach inside ttusb2.c. Now
>>> you have both demods (FEs) .i2c_gate_ctrl() which will control
>>> physically tda10023 I2C-gate as tuner is behind it.
>>>
>>
>> I try that, but don't work. I get an oops. Because the i2c gate
>> function of
>> the tda10023 driver use:
>>
>> struct tda10023_state* state = fe->demodulator_priv;
>>
>> to get the i2c adress. When called from tda10048, don't work.
>>
>> Jose Alberto
>>
>>>> The second is that with dvb-usb, there is only one frontend, and if you
>>>> wake up the second frontend, the adapter is not wake up. That can be
>>>> avoided the way I do in the patch, or mantaining the adapter alwais on.
>>>
>>> I think that could be also avoided similarly overriding demod callbacks
>>> and adding some more logic inside ttusb2.c.
>>>
>>> Proper fix that later problem is surely correct MFE support for
>>> DVB-USB-framework. I am now looking for it, lets see how difficult it
>>> will be.
>
>
> Signed-off-by: Antti Palosaari <crope@iki.fi>
>
> Test attached patches and try to fix if they are not working. Most
> likely not working since I don't have HW to test... I tested MFE parts
> using Anysee, so it should be working. I changed rather much your ttusb2
> and tda10048 patches, size reduced something like 50% or more. Still
> ttusb2 I2C-adapter changes made looks rather complex. Try to double
> check if those can be done easier. There is many drivers to look example
> from.
>
> DVB USB MFE is something like RFC. I know FE exclusive lock is missing,
> no need to mention that :) But other comments are welcome! I left three
> old "unneeded" pointers to struct dvb_usb_adapter to reduce changing all
> the drivers.
>
>
> regards
> Antti
>
diff mbox

Patch

diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
index b3cb626..51c716f 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
@@ -162,8 +162,8 @@  static int dvb_usb_fe_wakeup(struct dvb_frontend *fe)
 
 	dvb_usb_device_power_ctrl(adap->dev, 1);
 
-	if (adap->fe_init)
-		adap->fe_init(fe);
+	if (adap->mfe_init[fe->id])
+		adap->mfe_init[fe->id](fe);
 
 	return 0;
 }
@@ -172,35 +172,66 @@  static int dvb_usb_fe_sleep(struct dvb_frontend *fe)
 {
 	struct dvb_usb_adapter *adap = fe->dvb->priv;
 
-	if (adap->fe_sleep)
-		adap->fe_sleep(fe);
+	if (adap->mfe_sleep[fe->id])
+		adap->mfe_sleep[fe->id](fe);
 
 	return dvb_usb_device_power_ctrl(adap->dev, 0);
 }
 
 int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap)
 {
+	int ret, i, num_frontends;
+
 	if (adap->props.frontend_attach == NULL) {
-		err("strange: '%s' #%d doesn't want to attach a frontend.",adap->dev->desc->name, adap->id);
+		err("strange: '%s' #%d doesn't want to attach a frontend.",
+			adap->dev->desc->name, adap->id);
 		return 0;
 	}
 
-	/* re-assign sleep and wakeup functions */
-	if (adap->props.frontend_attach(adap) == 0 && adap->fe != NULL) {
-		adap->fe_init  = adap->fe->ops.init;  adap->fe->ops.init  = dvb_usb_fe_wakeup;
-		adap->fe_sleep = adap->fe->ops.sleep; adap->fe->ops.sleep = dvb_usb_fe_sleep;
+	if (adap->props.num_frontends)
+		num_frontends = adap->props.num_frontends;
+	else
+		num_frontends = 1;
+
+	for (i = 0; i < num_frontends; i++) {
+
+		ret = adap->props.frontend_attach(adap);
+		if (ret)
+			break;
+
+		/* glue for backward compatibility */
+		if (i == 0) {
+			if (adap->mfe[i])
+				adap->fe = adap->mfe[i];
+			else
+				adap->mfe[i] = adap->fe;
+		}
+
+		if (adap->mfe[i] == NULL)
+			break;
+
+		/* re-assign sleep and wakeup functions */
+		adap->mfe_init[i]  = adap->mfe[i]->ops.init;
+		adap->mfe_sleep[i] = adap->mfe[i]->ops.sleep;
+		adap->mfe[i]->ops.init  = dvb_usb_fe_wakeup;
+		adap->mfe[i]->ops.sleep = dvb_usb_fe_sleep;
 
-		if (dvb_register_frontend(&adap->dvb_adap, adap->fe)) {
-			err("Frontend registration failed.");
+		adap->mfe[i]->id = i;
+		if (dvb_register_frontend(&adap->dvb_adap, adap->mfe[i])) {
+			err("Frontend %d registration failed.", i);
 			dvb_frontend_detach(adap->fe);
-			adap->fe = NULL;
+			adap->mfe[i] = NULL;
+			if (adap->mfe[0] == NULL)
+				adap->fe = NULL;
 			return -ENODEV;
 		}
 
 		/* only attach the tuner if the demod is there */
 		if (adap->props.tuner_attach != NULL)
 			adap->props.tuner_attach(adap);
-	} else
+	}
+
+	if (adap->mfe[0] == NULL)
 		err("no frontend was attached by '%s'",adap->dev->desc->name);
 
 	return 0;
@@ -208,9 +239,22 @@  int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap)
 
 int dvb_usb_adapter_frontend_exit(struct dvb_usb_adapter *adap)
 {
-	if (adap->fe != NULL) {
-		dvb_unregister_frontend(adap->fe);
-		dvb_frontend_detach(adap->fe);
+	int i, num_frontends;
+
+	if (adap->props.num_frontends)
+		num_frontends = adap->props.num_frontends;
+	else
+		num_frontends = 1;
+
+	for (i = 0; i < num_frontends; i++) {
+		if (adap->mfe[i] != NULL) {
+			dvb_unregister_frontend(adap->mfe[i]);
+			dvb_frontend_detach(adap->mfe[i]);
+		}
 	}
+
+	if (adap->mfe[0] == NULL)
+		adap->fe = NULL;
+
 	return 0;
 }
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index 7d35d07..05d7032 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -146,6 +146,7 @@  struct dvb_usb_adapter_properties {
 	int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
 	int (*pid_filter)      (struct dvb_usb_adapter *, int, u16, int);
 
+	int num_frontends;
 	int (*frontend_attach) (struct dvb_usb_adapter *);
 	int (*tuner_attach)    (struct dvb_usb_adapter *);
 
@@ -359,15 +360,19 @@  struct dvb_usb_adapter {
 	int pid_filtering;
 
 	/* dvb */
+#define DVB_USB_FE_MAX_NUM 2
 	struct dvb_adapter   dvb_adap;
 	struct dmxdev        dmxdev;
 	struct dvb_demux     demux;
 	struct dvb_net       dvb_net;
 	struct dvb_frontend *fe;
+	struct dvb_frontend *mfe[DVB_USB_FE_MAX_NUM];
 	int                  max_feed_count;
 
 	int (*fe_init)  (struct dvb_frontend *);
 	int (*fe_sleep) (struct dvb_frontend *);
+	int (*mfe_init[DVB_USB_FE_MAX_NUM]) (struct dvb_frontend *);
+	int (*mfe_sleep[DVB_USB_FE_MAX_NUM]) (struct dvb_frontend *);
 
 	struct usb_data_stream stream;