linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] dvb-usb-v2: add frontend_detach callback
@ 2014-09-04 21:43 Antti Palosaari
  2014-09-04 21:43 ` [PATCH 2/3] dvb-usb-v2: add tuner_detach callback Antti Palosaari
  2014-09-04 21:43 ` [PATCH 3/3] af9035: remove I2C client differently Antti Palosaari
  0 siblings, 2 replies; 6+ messages in thread
From: Antti Palosaari @ 2014-09-04 21:43 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Add frontend_detach callback in order to allow custom detach. It is
needed when demod driver is implemented I2C client or some other
kernel bus, but not proprietary dvb_attach / dvb_detach.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/usb/dvb-usb-v2/dvb_usb.h      |  2 ++
 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c | 16 +++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb.h b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
index 124b4ba..7e36ee0 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb.h
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
@@ -214,6 +214,7 @@ struct dvb_usb_adapter_properties {
  * @read_config: called to resolve device configuration
  * @read_mac_address: called to resolve adapter mac-address
  * @frontend_attach: called to attach the possible frontends
+ * @frontend_detach: called to detach the possible frontends
  * @tuner_attach: called to attach the possible tuners
  * @frontend_ctrl: called to power on/off active frontend
  * @streaming_ctrl: called to start/stop the usb streaming of adapter
@@ -254,6 +255,7 @@ struct dvb_usb_device_properties {
 	int (*read_config) (struct dvb_usb_device *d);
 	int (*read_mac_address) (struct dvb_usb_adapter *, u8 []);
 	int (*frontend_attach) (struct dvb_usb_adapter *);
+	int (*frontend_detach)(struct dvb_usb_adapter *);
 	int (*tuner_attach) (struct dvb_usb_adapter *);
 	int (*frontend_ctrl) (struct dvb_frontend *, int);
 	int (*streaming_ctrl) (struct dvb_frontend *, int);
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
index 6c33d85..92bb297 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
@@ -664,9 +664,10 @@ err:
 
 static int dvb_usbv2_adapter_frontend_exit(struct dvb_usb_adapter *adap)
 {
-	int i;
-	dev_dbg(&adap_to_d(adap)->udev->dev, "%s: adap=%d\n", __func__,
-			adap->id);
+	int ret, i;
+	struct dvb_usb_device *d = adap_to_d(adap);
+
+	dev_dbg(&d->udev->dev, "%s: adap=%d\n", __func__, adap->id);
 
 	for (i = MAX_NO_OF_FE_PER_ADAP - 1; i >= 0; i--) {
 		if (adap->fe[i]) {
@@ -675,6 +676,15 @@ static int dvb_usbv2_adapter_frontend_exit(struct dvb_usb_adapter *adap)
 		}
 	}
 
+	if (d->props->frontend_detach) {
+		ret = d->props->frontend_detach(adap);
+		if (ret < 0) {
+			dev_dbg(&d->udev->dev,
+					"%s: frontend_detach() failed=%d\n",
+					__func__, ret);
+		}
+	}
+
 	return 0;
 }
 
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] dvb-usb-v2: add tuner_detach callback
  2014-09-04 21:43 [PATCH 1/3] dvb-usb-v2: add frontend_detach callback Antti Palosaari
@ 2014-09-04 21:43 ` Antti Palosaari
  2014-09-04 21:43 ` [PATCH 3/3] af9035: remove I2C client differently Antti Palosaari
  1 sibling, 0 replies; 6+ messages in thread
From: Antti Palosaari @ 2014-09-04 21:43 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Add tuner_detach callback in order to allow custom detach. It is
needed when tuner driver is implemented I2C client or some other
kernel bus, but not proprietary dvb_attach / dvb_detach.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/usb/dvb-usb-v2/dvb_usb.h      | 1 +
 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb.h b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
index 7e36ee0..14e111e 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb.h
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
@@ -257,6 +257,7 @@ struct dvb_usb_device_properties {
 	int (*frontend_attach) (struct dvb_usb_adapter *);
 	int (*frontend_detach)(struct dvb_usb_adapter *);
 	int (*tuner_attach) (struct dvb_usb_adapter *);
+	int (*tuner_detach)(struct dvb_usb_adapter *);
 	int (*frontend_ctrl) (struct dvb_frontend *, int);
 	int (*streaming_ctrl) (struct dvb_frontend *, int);
 	int (*init) (struct dvb_usb_device *);
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
index 92bb297..a05be7d 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
@@ -676,6 +676,14 @@ static int dvb_usbv2_adapter_frontend_exit(struct dvb_usb_adapter *adap)
 		}
 	}
 
+	if (d->props->tuner_detach) {
+		ret = d->props->tuner_detach(adap);
+		if (ret < 0) {
+			dev_dbg(&d->udev->dev, "%s: tuner_detach() failed=%d\n",
+					__func__, ret);
+		}
+	}
+
 	if (d->props->frontend_detach) {
 		ret = d->props->frontend_detach(adap);
 		if (ret < 0) {
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] af9035: remove I2C client differently
  2014-09-04 21:43 [PATCH 1/3] dvb-usb-v2: add frontend_detach callback Antti Palosaari
  2014-09-04 21:43 ` [PATCH 2/3] dvb-usb-v2: add tuner_detach callback Antti Palosaari
@ 2014-09-04 21:43 ` Antti Palosaari
  2014-09-04 22:50   ` Daniel Glöckner
  1 sibling, 1 reply; 6+ messages in thread
From: Antti Palosaari @ 2014-09-04 21:43 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

It crash kernel when device was removed while it was streaming.
That is because we removed driver and frontend thread was still
running. Use new callback which allows I2C driver removal just
after frontend is unregistered.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/usb/dvb-usb-v2/af9035.c | 90 +++++++++++++++++++++++++----------
 1 file changed, 64 insertions(+), 26 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
index 94563b2..aadabea 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -1074,15 +1074,13 @@ static int af9035_get_adapter_count(struct dvb_usb_device *d)
 	return state->dual_mode + 1;
 }
 
-static void af9035_exit(struct dvb_usb_device *d);
-
 static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
 {
 	struct state *state = adap_to_priv(adap);
 	struct dvb_usb_device *d = adap_to_d(adap);
 	int ret;
 
-	dev_dbg(&d->udev->dev, "%s:\n", __func__);
+	dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id);
 
 	if (!state->af9033_config[adap->id].tuner) {
 		/* unsupported tuner */
@@ -1109,12 +1107,46 @@ static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
 	return 0;
 
 err:
-	af9035_exit(d); /* remove I2C clients */
 	dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
 
 	return ret;
 }
 
+static int af9035_frontend_detach(struct dvb_usb_adapter *adap)
+{
+	struct state *state = adap_to_priv(adap);
+	struct dvb_usb_device *d = adap_to_d(adap);
+	int demod2;
+
+	dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id);
+
+	/*
+	 * For dual tuner devices we have to resolve 2nd demod client, as there
+	 * is two different kind of tuner drivers; one is using I2C binding
+	 * and the other is using DVB attach/detach binding.
+	 */
+	switch (state->af9033_config[adap->id].tuner) {
+	case AF9033_TUNER_IT9135_38:
+	case AF9033_TUNER_IT9135_51:
+	case AF9033_TUNER_IT9135_52:
+	case AF9033_TUNER_IT9135_60:
+	case AF9033_TUNER_IT9135_61:
+	case AF9033_TUNER_IT9135_62:
+		demod2 = 2;
+	default:
+		demod2 = 1;
+	}
+
+	if (adap->id == 1)
+		if (state->i2c_client[demod2])
+			af9035_del_i2c_dev(d);
+	if (adap->id == 0)
+		if (state->i2c_client[0])
+			af9035_del_i2c_dev(d);
+
+	return 0;
+}
+
 static struct tua9001_config af9035_tua9001_config = {
 	.i2c_addr = 0x60,
 };
@@ -1174,7 +1206,7 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
 	struct i2c_msg msg[1];
 	u8 tuner_addr;
 
-	dev_dbg(&d->udev->dev, "%s:\n", __func__);
+	dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id);
 
 	/*
 	 * XXX: Hack used in that function: we abuse unused I2C address bit [7]
@@ -1392,12 +1424,36 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
 	return 0;
 
 err:
-	af9035_exit(d); /* remove I2C clients */
 	dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
 
 	return ret;
 }
 
+static int af9035_tuner_detach(struct dvb_usb_adapter *adap)
+{
+	struct state *state = adap_to_priv(adap);
+	struct dvb_usb_device *d = adap_to_d(adap);
+
+	dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id);
+
+	switch (state->af9033_config[adap->id].tuner) {
+	case AF9033_TUNER_IT9135_38:
+	case AF9033_TUNER_IT9135_51:
+	case AF9033_TUNER_IT9135_52:
+	case AF9033_TUNER_IT9135_60:
+	case AF9033_TUNER_IT9135_61:
+	case AF9033_TUNER_IT9135_62:
+		if (adap->id == 1)
+			if (state->i2c_client[3])
+				af9035_del_i2c_dev(d);
+		if (adap->id == 0)
+			if (state->i2c_client[1])
+				af9035_del_i2c_dev(d);
+	}
+
+	return 0;
+}
+
 static int af9035_init(struct dvb_usb_device *d)
 {
 	struct state *state = d_to_priv(d);
@@ -1445,25 +1501,6 @@ err:
 	return ret;
 }
 
-static void af9035_exit(struct dvb_usb_device *d)
-{
-	struct state *state = d_to_priv(d);
-
-	dev_dbg(&d->udev->dev, "%s:\n", __func__);
-
-	if (state->i2c_client[3])
-		af9035_del_i2c_dev(d);
-
-	if (state->i2c_client[2])
-		af9035_del_i2c_dev(d);
-
-	if (state->i2c_client[1])
-		af9035_del_i2c_dev(d);
-
-	if (state->i2c_client[0])
-		af9035_del_i2c_dev(d);
-}
-
 #if IS_ENABLED(CONFIG_RC_CORE)
 static int af9035_rc_query(struct dvb_usb_device *d)
 {
@@ -1636,11 +1673,12 @@ static const struct dvb_usb_device_properties af9035_props = {
 	.i2c_algo = &af9035_i2c_algo,
 	.read_config = af9035_read_config,
 	.frontend_attach = af9035_frontend_attach,
+	.frontend_detach = af9035_frontend_detach,
 	.tuner_attach = af9035_tuner_attach,
+	.tuner_detach = af9035_tuner_detach,
 	.init = af9035_init,
 	.get_rc_config = af9035_get_rc_config,
 	.get_stream_config = af9035_get_stream_config,
-	.exit = af9035_exit,
 
 	.get_adapter_count = af9035_get_adapter_count,
 	.adapter = {
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] af9035: remove I2C client differently
  2014-09-04 21:43 ` [PATCH 3/3] af9035: remove I2C client differently Antti Palosaari
@ 2014-09-04 22:50   ` Daniel Glöckner
  2014-09-04 23:02     ` Antti Palosaari
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Glöckner @ 2014-09-04 22:50 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media

On Fri, Sep 05, 2014 at 12:43:43AM +0300, Antti Palosaari wrote:
> +	switch (state->af9033_config[adap->id].tuner) {
> +	case AF9033_TUNER_IT9135_38:
> +	case AF9033_TUNER_IT9135_51:
> +	case AF9033_TUNER_IT9135_52:
> +	case AF9033_TUNER_IT9135_60:
> +	case AF9033_TUNER_IT9135_61:
> +	case AF9033_TUNER_IT9135_62:
> +		demod2 = 2;
> +	default:
> +		demod2 = 1;
> +	}

Missing break?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] af9035: remove I2C client differently
  2014-09-04 22:50   ` Daniel Glöckner
@ 2014-09-04 23:02     ` Antti Palosaari
  2014-09-05  7:51       ` Antti Palosaari
  0 siblings, 1 reply; 6+ messages in thread
From: Antti Palosaari @ 2014-09-04 23:02 UTC (permalink / raw)
  To: linux-media



On 09/05/2014 01:50 AM, Daniel Glöckner wrote:
> On Fri, Sep 05, 2014 at 12:43:43AM +0300, Antti Palosaari wrote:
>> +	switch (state->af9033_config[adap->id].tuner) {
>> +	case AF9033_TUNER_IT9135_38:
>> +	case AF9033_TUNER_IT9135_51:
>> +	case AF9033_TUNER_IT9135_52:
>> +	case AF9033_TUNER_IT9135_60:
>> +	case AF9033_TUNER_IT9135_61:
>> +	case AF9033_TUNER_IT9135_62:
>> +		demod2 = 2;
>> +	default:
>> +		demod2 = 1;
>> +	}
>
> Missing break?
>

YES! will fix...
It does not have functionality error in that case, but sure it is wrong 
and may jump up later when some changes are done.

regards
Antti

-- 
http://palosaari.fi/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] af9035: remove I2C client differently
  2014-09-04 23:02     ` Antti Palosaari
@ 2014-09-05  7:51       ` Antti Palosaari
  0 siblings, 0 replies; 6+ messages in thread
From: Antti Palosaari @ 2014-09-05  7:51 UTC (permalink / raw)
  To: linux-media



On 09/05/2014 02:02 AM, Antti Palosaari wrote:
>
>
> On 09/05/2014 01:50 AM, Daniel Glöckner wrote:
>> On Fri, Sep 05, 2014 at 12:43:43AM +0300, Antti Palosaari wrote:
>>> +    switch (state->af9033_config[adap->id].tuner) {
>>> +    case AF9033_TUNER_IT9135_38:
>>> +    case AF9033_TUNER_IT9135_51:
>>> +    case AF9033_TUNER_IT9135_52:
>>> +    case AF9033_TUNER_IT9135_60:
>>> +    case AF9033_TUNER_IT9135_61:
>>> +    case AF9033_TUNER_IT9135_62:
>>> +        demod2 = 2;
>>> +    default:
>>> +        demod2 = 1;
>>> +    }
>>
>> Missing break?
>>
>
> YES! will fix...
> It does not have functionality error in that case, but sure it is wrong
> and may jump up later when some changes are done.

It is also good example what happens when checking tools, maybe 
checkpatch.pl, started whining if switch-case statement has unneeded 
break. So lets stop adding break to last case, and this kind of copy 
paste mistakes happens surely more often....

regards
Antti

-- 
http://palosaari.fi/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-09-05  7:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-04 21:43 [PATCH 1/3] dvb-usb-v2: add frontend_detach callback Antti Palosaari
2014-09-04 21:43 ` [PATCH 2/3] dvb-usb-v2: add tuner_detach callback Antti Palosaari
2014-09-04 21:43 ` [PATCH 3/3] af9035: remove I2C client differently Antti Palosaari
2014-09-04 22:50   ` Daniel Glöckner
2014-09-04 23:02     ` Antti Palosaari
2014-09-05  7:51       ` Antti Palosaari

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).