Re: [PATCH 1/2] media: dvb: convert tuner_info frequencies to Hz

2018-07-05 Thread Michael Büsch
On Wed,  4 Jul 2018 23:46:56 -0300
Mauro Carvalho Chehab  wrote:

> diff --git a/drivers/media/tuners/fc0011.c b/drivers/media/tuners/fc0011.c
> index 145407dee3db..a983899c6b0b 100644
> --- a/drivers/media/tuners/fc0011.c
> +++ b/drivers/media/tuners/fc0011.c
> @@ -472,10 +472,10 @@ static int fc0011_get_bandwidth(struct dvb_frontend 
> *fe, u32 *bandwidth)
>  
>  static const struct dvb_tuner_ops fc0011_tuner_ops = {
>   .info = {
> - .name   = "Fitipower FC0011",
> + .name = "Fitipower FC0011",
>  
> - .frequency_min  = 4500,
> - .frequency_max  = 10,
> + .frequency_min_hz =   45 * MHz,
> + .frequency_max_hz = 1000 * MHz,
>   },
>  
>   .release= fc0011_release,

Acked-by: Michael Büsch 

What about a GHz definition for 1000 * MHz?

-- 
Michael


pgpiV7kEiTOKJ.pgp
Description: OpenPGP digital signature


Re: [PATCH 1/4] [media] tw5864, fc0011: better handle WARN_ON()

2017-05-18 Thread Michael Büsch
On Thu, 18 May 2017 11:06:43 -0300
Mauro Carvalho Chehab  wrote:

> diff --git a/drivers/media/tuners/fc0011.c b/drivers/media/tuners/fc0011.c
> index 192b1c7740df..145407dee3db 100644
> --- a/drivers/media/tuners/fc0011.c
> +++ b/drivers/media/tuners/fc0011.c
> @@ -342,6 +342,7 @@ static int fc0011_set_params(struct dvb_frontend *fe)
>   switch (vco_sel) {
>   default:
>   WARN_ON(1);
> + return -EINVAL;
>   case 0:
>   if (vco_cal < 8) {
>   regs[FC11_REG_VCOSEL] &= ~(FC11_VCOSEL_1 | 
> FC11_VCOSEL_2);

This fall through is intentional, but I guess returning an error is OK,
too. This should not happen anyway.
I cannot test this, though.

Acked-by: Michael Büsch 

-- 
Michael


pgpfAl6Qz6id8.pgp
Description: OpenPGP digital signature


Re: [PATCH 2/2] drivers: Simplify the return code

2015-05-19 Thread Michael Büsch
On Tue, 19 May 2015 08:05:56 -0400 (EDT)
Federico Simoncelli  wrote:
> > diff --git a/drivers/media/dvb-frontends/lgs8gxx.c
> > b/drivers/media/dvb-frontends/lgs8gxx.c
> > index 3c92f36ea5c7..9b0166cdc7c2 100644
> > --- a/drivers/media/dvb-frontends/lgs8gxx.c
> > +++ b/drivers/media/dvb-frontends/lgs8gxx.c
> > @@ -544,11 +544,7 @@ static int lgs8gxx_set_mpeg_mode(struct lgs8gxx_state
> > *priv,
> > t |= clk_pol ? TS_CLK_INVERTED : TS_CLK_NORMAL;
> > t |= clk_gated ? TS_CLK_GATED : TS_CLK_FREERUN;
> >  
> > -   ret = lgs8gxx_write_reg(priv, reg_addr, t);
> > -   if (ret != 0)
> > -   return ret;
> > -
> > -   return 0;
> > +   return lgs8gxx_write_reg(priv, reg_addr, t);
> >  }
> 
> Personally I prefer the current style because it's more consistent with all
> the other calls in the same function (return ret when ret != 0).
> 
> It also allows you to easily add/remove calls without having to deal with
> the last special case return my_last_fun_call(...).
> 
> Anyway it's not a big deal, I think it's your call.


I agree. I also prefer the current style for these reasons. The compiler will 
also generate the same code in both cases.
I don't think it really simplifies the code.
But if you really insist on doing this change, go for it. You get my ack for 
fc0011

-- 
Michael


pgpTs9rqSpDag.pgp
Description: OpenPGP digital signature


Re: [git:v4l-dvb/for_v3.9] [media] fc0011: Return early, if the frequency is already tuned

2013-02-11 Thread Michael Büsch
Can you please revert this one again? It might cause issues if the dvb device
is reset/reinitialized.


On Fri, 08 Feb 2013 20:51:36 +0100
Mauro Carvalho Chehab  wrote:

> This is an automatic generated email to let you know that the following patch 
> were queued at the 
> http://git.linuxtv.org/media_tree.git tree:
> 
> Subject: [media] fc0011: Return early, if the frequency is already tuned
> Author:  Michael Büsch 
> Date:Thu Feb 7 12:21:06 2013 -0300
> 
> Return early, if we already tuned to a frequency.
> 
> Signed-off-by: Michael Buesch 
> Signed-off-by: Mauro Carvalho Chehab 
> 
>  drivers/media/tuners/fc0011.c |3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> ---
> 
> http://git.linuxtv.org/media_tree.git?a=commitdiff;h=a92591a7112042f92b609be42bc332d989776e9b
> 
> diff --git a/drivers/media/tuners/fc0011.c b/drivers/media/tuners/fc0011.c
> index 3932aa8..18caab1 100644
> --- a/drivers/media/tuners/fc0011.c
> +++ b/drivers/media/tuners/fc0011.c
> @@ -187,6 +187,9 @@ static int fc0011_set_params(struct dvb_frontend *fe)
>   u8 fa, fp, vco_sel, vco_cal;
>   u8 regs[FC11_NR_REGS] = { };
>  
> + if (priv->frequency == p->frequency)
> + return 0;
> +
>   regs[FC11_REG_7] = 0x0F;
>   regs[FC11_REG_8] = 0x3E;
>   regs[FC11_REG_10] = 0xB8;
> 



-- 
Greetings, Michael.

PGP: 908D8B0E


signature.asc
Description: PGP signature


[PATCH 1/4] fc0011: fp/fa value overflow fix

2013-02-07 Thread Michael Büsch
Assign the maximum instead of masking with the maximum on value overflow.

Signed-off-by: Michael Buesch 

---

Index: linux/drivers/media/tuners/fc0011.c
===
--- linux.orig/drivers/media/tuners/fc0011.c2012-10-22 16:11:27.634183359 
+0200
+++ linux/drivers/media/tuners/fc0011.c 2012-10-22 16:13:29.140465225 +0200
@@ -247,8 +247,8 @@
fa += 8;
}
if (fp > 0x1F) {
-   fp &= 0x1F;
-   fa &= 0xF;
+   fp = 0x1F;
+   fa = 0xF;
}
if (fa >= fp) {
dev_warn(&priv->i2c->dev,


-- 
Greetings, Michael.

PGP: 908D8B0E


signature.asc
Description: PGP signature


[PATCH 4/4] fc0011: Return early, if the frequency is already tuned

2013-02-07 Thread Michael Büsch
Return early, if we already tuned to a frequency.

Signed-off-by: Michael Buesch 

---

Index: linux/drivers/media/tuners/fc0011.c
===
--- linux.orig/drivers/media/tuners/fc0011.c2013-01-01 23:25:40.0 
+0100
+++ linux/drivers/media/tuners/fc0011.c 2013-01-01 23:27:44.985089712 +0100
@@ -187,6 +187,9 @@
u8 fa, fp, vco_sel, vco_cal;
u8 regs[FC11_NR_REGS] = { };
 
+   if (priv->frequency == p->frequency)
+   return 0;
+
regs[FC11_REG_7] = 0x0F;
regs[FC11_REG_8] = 0x3E;
regs[FC11_REG_10] = 0xB8;


-- 
Greetings, Michael.

PGP: 908D8B0E


signature.asc
Description: PGP signature


[PATCH 2/4] fc0011: Fix xin value clamping

2013-02-07 Thread Michael Büsch
Fix the xin value clamping and use clamp_t().

Signed-off-by: Michael Buesch 

---

Index: linux/drivers/media/tuners/fc0011.c
===
--- linux.orig/drivers/media/tuners/fc0011.c2012-10-22 16:13:29.140465225 
+0200
+++ linux/drivers/media/tuners/fc0011.c 2012-10-22 16:15:46.915056243 +0200
@@ -183,8 +183,7 @@
unsigned int i, vco_retries;
u32 freq = p->frequency / 1000;
u32 bandwidth = p->bandwidth_hz / 1000;
-   u32 fvco, xin, xdiv, xdivr;
-   u16 frac;
+   u32 fvco, xin, frac, xdiv, xdivr;
u8 fa, fp, vco_sel, vco_cal;
u8 regs[FC11_NR_REGS] = { };
 
@@ -227,12 +226,8 @@
frac += 32786;
if (!frac)
xin = 0;
-   else if (frac < 511)
-   xin = 512;
-   else if (frac < 65026)
-   xin = frac;
else
-   xin = 65024;
+   xin = clamp_t(u32, frac, 512, 65024);
regs[FC11_REG_XINHI] = xin >> 8;
regs[FC11_REG_XINLO] = xin;
 


-- 
Greetings, Michael.

PGP: 908D8B0E


signature.asc
Description: PGP signature


[PATCH 3/4] fc0011: Add some sanity checks and cleanups

2013-02-07 Thread Michael Büsch
Add some sanity checks to the calculations and make the REG_16 register write 
consistent
with the other ones.

Signed-off-by: Michael Buesch 

---

Index: linux/drivers/media/tuners/fc0011.c
===
--- linux.orig/drivers/media/tuners/fc0011.c2012-10-22 16:15:46.0 
+0200
+++ linux/drivers/media/tuners/fc0011.c 2012-10-22 16:17:15.280720317 +0200
@@ -220,6 +220,7 @@
 
/* Calc XIN. The PLL reference frequency is 18 MHz. */
xdiv = fvco / 18000;
+   WARN_ON(xdiv > 0xFF);
frac = fvco - xdiv * 18000;
frac = (frac << 15) / 18000;
if (frac >= 16384)
@@ -346,6 +347,8 @@
vco_cal &= FC11_VCOCAL_VALUEMASK;
 
switch (vco_sel) {
+   default:
+   WARN_ON(1);
case 0:
if (vco_cal < 8) {
regs[FC11_REG_VCOSEL] &= ~(FC11_VCOSEL_1 | 
FC11_VCOSEL_2);
@@ -427,7 +430,8 @@
err = fc0011_writereg(priv, FC11_REG_RCCAL, regs[FC11_REG_RCCAL]);
if (err)
return err;
-   err = fc0011_writereg(priv, FC11_REG_16, 0xB);
+   regs[FC11_REG_16] = 0xB;
+   err = fc0011_writereg(priv, FC11_REG_16, regs[FC11_REG_16]);
if (err)
return err;
 


-- 
Greetings, Michael.

PGP: 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH 9/13] drivers/media/tuners/fc0011.c: use macros for i2c_msg initialization

2012-10-07 Thread Michael Büsch
On Sun, 7 Oct 2012 18:50:31 +0200 (CEST)
Julia Lawall  wrote:

> >> @@ -97,10 +96,8 @@ static int fc0011_readreg(struct fc0011_priv *priv, u8 
> >> reg, u8 *val)
> >>  {
> >>u8 dummy;
> >>struct i2c_msg msg[2] = {
> >> -  { .addr = priv->addr,
> >> -.flags = 0, .buf = ®, .len = 1 },
> >> -  { .addr = priv->addr,
> >> -.flags = I2C_M_RD, .buf = val ? : &dummy, .len = 1 },
> >> +  I2C_MSG_WRITE(priv->addr, ®, sizeof(reg)),
> >> +  I2C_MSG_READ(priv->addr, val ? : &dummy, sizeof(dummy)),
> >>};
> >>
> >
> > This dummy looks strange, can it be that this is used uninitialised ?
> 
> I'm not sure to understand the question.  The read, when it happens in 
> i2c_transfer will initialize dummy.  On the other hand, I don't know what 
> i2c_transfer does when the buffer is NULL and the size is 1.  It does not 
> look very elegant at least.

Well its use case is if you only care about the side effects and not the actual 
data
returned by the read operation.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH] fc0011: Reduce number of retries

2012-05-07 Thread Michael Büsch
On Mon, 07 May 2012 21:53:23 +0300
Antti Palosaari  wrote:

> On 03.04.2012 18:33, Michael Büsch wrote:
> > On another thing:
> > The af9035 driver doesn't look multi-device safe. There are lots of static
> > variables around that keep device state. So it looks like this will
> > blow up if multiple devices are present in the system. Unlikely, but 
> > still... .
> > Are there any plans to fix this up?
> > If not, I'll probably take a look at this. But don't hold your breath.
> 
> I fixed what was possible by moving af9033 and af9035 configurations for 
> the state. That at least resolves most significant issues - like your 
> fc0011 tuner callback.

Cool, thanks a lot!

> But there is still some stuff in "static struct 
> dvb_usb_device_properties" which cannot be fixed. Like dynamic remote 
> configuration, dual mode, etc. I am going to make RFC for those maybe 
> even this week after some analysis is done.

Thanks. I'm currently lacking the time to do this kind of intrusive changes,
so I'm happy to see you looking into this.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH] Add fc0011 tuner driver

2012-05-07 Thread Michael Büsch
On Mon, 07 May 2012 22:02:18 +0300
Antti Palosaari  wrote:

> On 02.04.2012 19:14, Michael Büsch wrote:
> > This adds support for the Fitipower fc0011 DVB-t tuner.
> >
> > Signed-off-by: Michael Buesch
> 
> > +   unsigned int i, vco_retries;
> > +   u32 freq = p->frequency / 1000;
> > +   u32 bandwidth = p->bandwidth_hz / 1000;
> > +   u32 fvco, xin, xdiv, xdivr;
> > +   u16 frac;
> > +   u8 fa, fp, vco_sel, vco_cal;
> > +   u8 regs[FC11_NR_REGS] = { };
> 
> > +
> > +   dev_dbg(&priv->i2c->dev, "Tuned to "
> > +   "fa=%02X fp=%02X xin=%02X%02X vco=%02X vcosel=%02X "
> > +   "vcocal=%02X(%u) bw=%u\n",
> > +   (unsigned int)regs[FC11_REG_FA],
> > +   (unsigned int)regs[FC11_REG_FP],
> > +   (unsigned int)regs[FC11_REG_XINHI],
> > +   (unsigned int)regs[FC11_REG_XINLO],
> > +   (unsigned int)regs[FC11_REG_VCO],
> > +   (unsigned int)regs[FC11_REG_VCOSEL],
> > +   (unsigned int)vco_cal, vco_retries,
> > +   (unsigned int)bandwidth);
> 
> Just for the interest, is there any reason you use so much casting or is 
> that only your style?

Well it makes sure the types are what the format string and thus vararg code 
expects.
it is true that most (probably all) of those explicit casts could be removed 
and instead
rely on implicit casts and promotions. But I personally prefer explicit casts
in this case (and only this case).

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH] fc0011: Reduce number of retries

2012-04-03 Thread Michael Büsch
On Tue, 03 Apr 2012 18:24:20 +0300
Antti Palosaari  wrote:

> On 03.04.2012 12:05, Michael Büsch wrote:
> > Now that i2c transfers are fixed, 3 retries are enough.
> >
> > Signed-off-by: Michael Buesch
> 
> Applied, thanks!
> http://git.linuxtv.org/anttip/media_tree.git/shortlog/refs/heads/af9035_experimental
> 
> I think I will update original af9035 PULL request soon for the same 
> level as af9035_experimental is currently.

That's great. The driver really works well for me.

On another thing:
The af9035 driver doesn't look multi-device safe. There are lots of static
variables around that keep device state. So it looks like this will
blow up if multiple devices are present in the system. Unlikely, but still... .
Are there any plans to fix this up?
If not, I'll probably take a look at this. But don't hold your breath.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH] fc0011: Reduce number of retries

2012-04-03 Thread Michael Büsch
On Tue, 03 Apr 2012 12:58:16 +0300
David Cohen  wrote:
> > -   while (!(vco_cal&  FC11_VCOCAL_OK)&&  vco_retries<  6) {
> > +   while (!(vco_cal&  FC11_VCOCAL_OK)&&  vco_retries<  3) {
> 
> Do we need to retry at all?

It is not an i2c retry. It retries the whole device configuration operation
after resetting it.
I shouldn't have mentioned i2c in the commit log, because this really only was
a side effect.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


[PATCH] af9035: Use usleep_range() in fc0011 support code

2012-04-03 Thread Michael Büsch
Use usleep_range() instead of msleep() to improve power saving opportunities.

Signed-off-by: Michael Buesch 

---

Index: linux/drivers/media/dvb/dvb-usb/af9035.c
===
--- linux.orig/drivers/media/dvb/dvb-usb/af9035.c   2012-04-03 
10:49:18.270364916 +0200
+++ linux/drivers/media/dvb/dvb-usb/af9035.c2012-04-03 10:49:57.495125781 
+0200
@@ -590,7 +590,7 @@
err = af9035_wr_reg_mask(d, 0xd8d1, 1, 1);
if (err)
return err;
-   msleep(10);
+   usleep_range(1, 5);
break;
case FC0011_FE_CALLBACK_RESET:
err = af9035_wr_reg(d, 0xd8e9, 1);
@@ -602,11 +602,11 @@
err = af9035_wr_reg(d, 0xd8e7, 1);
if (err)
return err;
-   msleep(10);
+   usleep_range(1, 2);
err = af9035_wr_reg(d, 0xd8e7, 0);
if (err)
return err;
-   msleep(10);
+   usleep_range(1, 2);
break;
default:
return -EINVAL;


-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


[PATCH] fc0011: use usleep_range()

2012-04-03 Thread Michael Büsch
Use usleep_range() instead of msleep() to improve power saving opportunities.

Signed-off-by: Michael Buesch 

---

Index: linux/drivers/media/common/tuners/fc0011.c
===
--- linux.orig/drivers/media/common/tuners/fc0011.c 2012-04-03 
10:44:07.243418827 +0200
+++ linux/drivers/media/common/tuners/fc0011.c  2012-04-03 10:46:29.342851336 
+0200
@@ -167,7 +167,7 @@
err = fc0011_writereg(priv, FC11_REG_VCOCAL, FC11_VCOCAL_RUN);
if (err)
return err;
-   msleep(10);
+   usleep_range(1, 2);
err = fc0011_readreg(priv, FC11_REG_VCOCAL, value);
if (err)
return err;
@@ -423,7 +423,7 @@
err = fc0011_vcocal_read(priv, NULL);
if (err)
return err;
-   msleep(10);
+   usleep_range(1, 5);
 
err = fc0011_readreg(priv, FC11_REG_RCCAL, ®s[FC11_REG_RCCAL]);
if (err)


-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


[PATCH] fc0011: Reduce number of retries

2012-04-03 Thread Michael Büsch
Now that i2c transfers are fixed, 3 retries are enough.

Signed-off-by: Michael Buesch 

---

Index: linux/drivers/media/common/tuners/fc0011.c
===
--- linux.orig/drivers/media/common/tuners/fc0011.c 2012-04-03 
08:48:39.0 +0200
+++ linux/drivers/media/common/tuners/fc0011.c  2012-04-03 10:44:07.243418827 
+0200
@@ -314,7 +314,7 @@
if (err)
return err;
vco_retries = 0;
-   while (!(vco_cal & FC11_VCOCAL_OK) && vco_retries < 6) {
+   while (!(vco_cal & FC11_VCOCAL_OK) && vco_retries < 3) {
/* Reset the tuner and try again */
err = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
   FC0011_FE_CALLBACK_RESET, priv->addr);


-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH] af9035: fix and enhance I2C adapter

2012-04-03 Thread Michael Büsch
On Tue,  3 Apr 2012 02:32:35 +0300
Antti Palosaari  wrote:

> There was a bug I2C adapter writes and reads one byte too much.
> As the most I2C clients has auto-increment register addressing
> this leads next register from the target register overwritten by
> garbage data.
> 
> As a change remove whole register address byte usage and write
> data directly to the I2C bus without saying what are register
> address bytes to firmware.
> 
> Signed-off-by: Antti Palosaari 
> Cc: Michael Buesch 
> Cc: Hans-Frieder Vogt 
> Cc: Gianluca Gennari 

I can confirm that this fixes the issue. Thanks!

Tested-by: Michael Buesch 

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH] Add fc0011 tuner driver

2012-04-02 Thread Michael Büsch
On Tue, 03 Apr 2012 00:52:08 +0300
Antti Palosaari  wrote:

> > Well the fc0011 tuner driver still works worse on this af9035 driver
> > than on Hans' driver. I have absolutely no idea why this is the case.
> > I'm almost certain that it is not a timing issue of some sort. I tried
> > a zillion of delays and such.
> 
> And after taking sniffs and comparing those I found the reason. It is 
> I2C adapter code. It writes one byte too much => as a FC0011 is 
> auto-increment (as almost every I2C client) registers it means it writes 
> next register too. Fixing that gives normal tuner sensitivity. I will 
> try to make patch for that soon.

Awesome! Thanks a lot!

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH] Add fc0011 tuner driver

2012-04-02 Thread Michael Büsch
On Mon, 02 Apr 2012 20:40:45 +0300
Antti Palosaari  wrote:

> h, I think Mauro will at least complain when I ask he to PULL that 
> master. Personally I would like to see line len something more than 80 
> chars, but as checkpatch.pl complains it I have shortened lines despite 
> very few cases.

I'm not a friend of long lines. In fact, I'm developing on a Netbook
with split screen. So long lines will absolutely kill readability for me.
But there is "long" as in 90 or 100 chars and there is "long" as in
"uh let's stretch the 80 chars limit by a few chars, so that it's more 
readable".

I already worked on code from other kernel subsystems for quite some time
and the 80 char limit never was a hard limit there. For good reasons.

That said, iff the 80 char limit _is_ a hard limit for the DVB subsystem,
I'll honor it. I just think it would worsen the code.

> Likely tuner driver, or demod driver. But as demod tuner initialization 
> tables are likely correct I suspect it is tuner issue at first hand. And 
> secondly my other hardware with TUA9001 performs very well, better than 
> old AF9015 sticks.

Well the fc0011 tuner driver still works worse on this af9035 driver
than on Hans' driver. I have absolutely no idea why this is the case.
I'm almost certain that it is not a timing issue of some sort. I tried
a zillion of delays and such.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH] af9035: Add fc0011 tuner support

2012-04-02 Thread Michael Büsch
On Mon, 02 Apr 2012 20:03:08 +0300
Antti Palosaari  wrote:

> On 02.04.2012 19:18, Michael Büsch wrote:
> > This adds Fitipower fc0011 tuner support to the af9035 driver.
> >
> > Signed-off-by: Michael Buesch
> 
> Applied, thanks!
> http://git.linuxtv.org/anttip/media_tree.git/shortlog/refs/heads/af9035_experimental
> 
> And same checkpatch.pl issue here.
> You can ran checkpatch like that:
> git diff | ./scripts/checkpatch.pl -
> git diff --cached | ./scripts/checkpatch.pl -
> ./scripts/checkpatch.pl --file drivers/media/dvb/dvb-usb/af9035.c
> 
> For that driver it complains you are using wrong sleep (msleep(10)). 
> Correct sleep for that case is something like usleep_range(1, 
> 10); which means as sleep at least 10ms but it does not matter if 
> you sleep even 100ms. The wider range the better chance for Kernel to 
> optimize power saving. There was usleep_range() already used inside that 
> module.

Ok, the sleep warning is the only remotely sane checkpatch warning for these
patches. So I will send a separate patch to convert those sleeps.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH] af9035: Add Afatech USB PIDs

2012-04-02 Thread Michael Büsch
On Mon, 02 Apr 2012 20:04:00 +0300
Antti Palosaari  wrote:

> On 02.04.2012 19:34, Michael Büsch wrote:
> > Add some generic Afatech USB PIDs used by "Cabstone" sticks and others.
> >
> > Signed-off-by: Michael Buesch
> 
> Applied, but same checkpatch.pl comments as earlier patches!

There is not a single warning or error in this patch.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH] Add fc0011 tuner driver

2012-04-02 Thread Michael Büsch
On Mon, 02 Apr 2012 19:56:50 +0300
Antti Palosaari  wrote:

> On 02.04.2012 19:14, Michael Büsch wrote:
> > This adds support for the Fitipower fc0011 DVB-t tuner.
> >
> > Signed-off-by: Michael Buesch
> 
> Applied, thanks!
> http://git.linuxtv.org/anttip/media_tree.git/shortlog/refs/heads/af9035_experimental
> 
> I looked it through quickly, no big issues. Anyhow, when I ran 
> checkpatch.pl and it complains rather much. All Kernel developers must 
> use checkpatch.pl before sent patches and fix findings if possible, 
> errors must be fixed and warnings too if there is no good reason to 
> leave as it is.

Well, I _did_ run it on the patch.
There is no error. Only (IMO bogus) warnings. Most of them
are about the 80 char limit. Which isn't really a hard limit. And those lines
only exceed the 80 char limit by a few chars (one, two or such). Splitting
those line serves no readability purpose. In fact, it just worsens it.

> And one note about tuner driver, my AF9035 + FC0011 device founds only 1 
> mux of 4. Looks like some performance issues still to resolve.

I have no idea what this means.
So I have no remote idea of what could possibly be wrong here.
Is this a bug on af903x or the tuner driver?

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


[PATCH] af9035: Add Afatech USB PIDs

2012-04-02 Thread Michael Büsch
Add some generic Afatech USB PIDs used by "Cabstone" sticks and others.

Signed-off-by: Michael Buesch 

---

Index: linux/drivers/media/dvb/dvb-usb/af9035.c
===
--- linux.orig/drivers/media/dvb/dvb-usb/af9035.c   2012-04-02 
18:15:46.946952566 +0200
+++ linux/drivers/media/dvb/dvb-usb/af9035.c2012-04-02 18:27:59.672754125 
+0200
@@ -738,11 +738,17 @@
 
 enum af9035_id_entry {
AF9035_0CCD_0093,
+   AF9035_15A4_9035,
+   AF9035_15A4_1001,
 };
 
 static struct usb_device_id af9035_id[] = {
[AF9035_0CCD_0093] = {
USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK)},
+   [AF9035_15A4_9035] = {
+   USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035)},
+   [AF9035_15A4_1001] = {
+   USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_2)},
{},
 };
 
@@ -785,14 +791,20 @@
 
.i2c_algo = &af9035_i2c_algo,
 
-   .num_device_descs = 1,
+   .num_device_descs = 2,
.devices = {
{
.name = "TerraTec Cinergy T Stick",
.cold_ids = {
&af9035_id[AF9035_0CCD_0093],
},
-   },
+   }, {
+   .name = "Afatech Technologies DVB-T stick",
+   .cold_ids = {
+   &af9035_id[AF9035_15A4_9035],
+   &af9035_id[AF9035_15A4_1001],
+   },
+   }
}
},
 };
Index: linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
===
--- linux.orig/drivers/media/dvb/dvb-usb/dvb-usb-ids.h  2012-04-01 
11:41:29.094353520 +0200
+++ linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h   2012-04-02 
18:26:34.386272276 +0200
@@ -76,6 +76,8 @@
 #define USB_PID_AFATECH_AF9005 0x9020
 #define USB_PID_AFATECH_AF9015_90150x9015
 #define USB_PID_AFATECH_AF9015_90160x9016
+#define USB_PID_AFATECH_AF9035 0x9035
+#define USB_PID_AFATECH_AF9035_2   0x1001
 #define USB_PID_TREKSTOR_DVBT  0x901b
 #define USB_VID_ALINK_DTU  0xf170
 #define USB_PID_ANSONIC_DVBT_USB   0x6000


-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


[PATCH] af9035: Add fc0011 tuner support

2012-04-02 Thread Michael Büsch
This adds Fitipower fc0011 tuner support to the af9035 driver.

Signed-off-by: Michael Buesch 

---

Index: linux/drivers/media/dvb/dvb-usb/af9035.c
===
--- linux.orig/drivers/media/dvb/dvb-usb/af9035.c   2012-04-02 
18:11:09.975605484 +0200
+++ linux/drivers/media/dvb/dvb-usb/af9035.c2012-04-02 18:15:46.946952566 
+0200
@@ -22,6 +22,7 @@
 #include "af9035.h"
 #include "af9033.h"
 #include "tua9001.h"
+#include "fc0011.h"
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 static DEFINE_MUTEX(af9035_usb_mutex);
@@ -498,6 +499,7 @@
 
switch (tmp) {
case AF9033_TUNER_TUA9001:
+   case AF9033_TUNER_FC0011:
af9035_af9033_config[i].spec_inv = 1;
break;
default:
@@ -542,6 +544,83 @@
return ret;
 }
 
+static int af9035_fc0011_tuner_callback(struct dvb_usb_device *d,
+   int cmd, int arg)
+{
+   int err;
+
+   switch (cmd) {
+   case FC0011_FE_CALLBACK_POWER:
+   /* Tuner enable */
+   err = af9035_wr_reg_mask(d, 0xd8eb, 1, 1);
+   if (err)
+   return err;
+   err = af9035_wr_reg_mask(d, 0xd8ec, 1, 1);
+   if (err)
+   return err;
+   err = af9035_wr_reg_mask(d, 0xd8ed, 1, 1);
+   if (err)
+   return err;
+   /* LED */
+   err = af9035_wr_reg_mask(d, 0xd8d0, 1, 1);
+   if (err)
+   return err;
+   err = af9035_wr_reg_mask(d, 0xd8d1, 1, 1);
+   if (err)
+   return err;
+   msleep(10);
+   break;
+   case FC0011_FE_CALLBACK_RESET:
+   err = af9035_wr_reg(d, 0xd8e9, 1);
+   if (err)
+   return err;
+   err = af9035_wr_reg(d, 0xd8e8, 1);
+   if (err)
+   return err;
+   err = af9035_wr_reg(d, 0xd8e7, 1);
+   if (err)
+   return err;
+   msleep(10);
+   err = af9035_wr_reg(d, 0xd8e7, 0);
+   if (err)
+   return err;
+   msleep(10);
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int af9035_tuner_callback(struct dvb_usb_device *d, int cmd, int arg)
+{
+   switch (af9035_af9033_config[0].tuner) {
+   case AF9033_TUNER_FC0011:
+   return af9035_fc0011_tuner_callback(d, cmd, arg);
+   default:
+   break;
+   }
+
+   return -ENODEV;
+}
+
+static int af9035_frontend_callback(void *adapter_priv, int component,
+   int cmd, int arg)
+{
+   struct i2c_adapter *adap = adapter_priv;
+   struct dvb_usb_device *d = i2c_get_adapdata(adap);
+
+   switch (component) {
+   case DVB_FRONTEND_COMPONENT_TUNER:
+   return af9035_tuner_callback(d, cmd, arg);
+   default:
+   break;
+   }
+
+   return -EINVAL;
+}
+
 static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
 {
int ret;
@@ -570,6 +649,7 @@
ret = -ENODEV;
goto err;
}
+   adap->fe_adap[0].fe->callback = af9035_frontend_callback;
 
return 0;
 
@@ -583,6 +663,10 @@
.i2c_addr = 0x60,
 };
 
+static const struct fc0011_config af9035_fc0011_config = {
+   .i2c_address = 0x60,
+};
+
 static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
 {
int ret;
@@ -631,6 +715,10 @@
fe = dvb_attach(tua9001_attach, adap->fe_adap[0].fe,
&adap->dev->i2c_adap, &af9035_tua9001_config);
break;
+   case AF9033_TUNER_FC0011:
+   fe = dvb_attach(fc0011_attach, adap->fe_adap[0].fe,
+   &adap->dev->i2c_adap, &af9035_fc0011_config);
+   break;
default:
fe = NULL;
}
Index: linux/drivers/media/dvb/frontends/af9033.c
===
--- linux.orig/drivers/media/dvb/frontends/af9033.c 2012-04-02 
18:11:08.551563486 +0200
+++ linux/drivers/media/dvb/frontends/af9033.c  2012-04-02 18:11:18.827865444 
+0200
@@ -297,6 +297,10 @@
len = ARRAY_SIZE(tuner_init_tua9001);
init = tuner_init_tua9001;
break;
+   case AF9033_TUNER_FC0011:
+   len = ARRAY_SIZE(tuner_init_fc0011);
+   init = tuner_init_fc0011;
+   break;
default:
pr_debug("%s: unsupported tuner ID=%d\n", __func__,
state->cfg.tuner);
Index: linux/drivers/media/dvb/frontends/af9033_priv.h
=

[PATCH] Add fc0011 tuner driver

2012-04-02 Thread Michael Büsch
This adds support for the Fitipower fc0011 DVB-t tuner.

Signed-off-by: Michael Buesch 

---


Index: linux/drivers/media/common/tuners/Kconfig
===
--- linux.orig/drivers/media/common/tuners/Kconfig  2012-04-02 
15:55:51.155296579 +0200
+++ linux/drivers/media/common/tuners/Kconfig   2012-04-02 16:00:14.464066789 
+0200
@@ -204,6 +204,13 @@
help
  NXP TDA18218 silicon tuner driver.
 
+config MEDIA_TUNER_FC0011
+   tristate "Fitipower FC0011 silicon tuner"
+   depends on VIDEO_MEDIA && I2C
+   default m if MEDIA_TUNER_CUSTOMISE
+   help
+ Fitipower FC0011 silicon tuner driver.
+
 config MEDIA_TUNER_TDA18212
tristate "NXP TDA18212 silicon tuner"
depends on VIDEO_MEDIA && I2C
Index: linux/drivers/media/common/tuners/Makefile
===
--- linux.orig/drivers/media/common/tuners/Makefile 2012-04-02 
15:55:51.155296579 +0200
+++ linux/drivers/media/common/tuners/Makefile  2012-04-02 16:00:14.464066789 
+0200
@@ -29,6 +29,7 @@
 obj-$(CONFIG_MEDIA_TUNER_TDA18218) += tda18218.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18212) += tda18212.o
 obj-$(CONFIG_MEDIA_TUNER_TUA9001) += tua9001.o
+obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o
 
 ccflags-y += -I$(srctree)/drivers/media/dvb/dvb-core
 ccflags-y += -I$(srctree)/drivers/media/dvb/frontends
Index: linux/drivers/media/common/tuners/fc0011.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux/drivers/media/common/tuners/fc0011.c  2012-04-02 18:01:25.978477833 
+0200
@@ -0,0 +1,524 @@
+/*
+ * Fitipower FC0011 tuner driver
+ *
+ * Copyright (C) 2012 Michael Buesch 
+ *
+ * Derived from FC0012 tuner driver:
+ * Copyright (C) 2012 Hans-Frieder Vogt 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "fc0011.h"
+
+
+/* Tuner registers */
+enum {
+   FC11_REG_0,
+   FC11_REG_FA,/* FA */
+   FC11_REG_FP,/* FP */
+   FC11_REG_XINHI, /* XIN high 8 bit */
+   FC11_REG_XINLO, /* XIN low 8 bit */
+   FC11_REG_VCO,   /* VCO */
+   FC11_REG_VCOSEL,/* VCO select */
+   FC11_REG_7, /* Unknown tuner reg 7 */
+   FC11_REG_8, /* Unknown tuner reg 8 */
+   FC11_REG_9,
+   FC11_REG_10,/* Unknown tuner reg 10 */
+   FC11_REG_11,/* Unknown tuner reg 11 */
+   FC11_REG_12,
+   FC11_REG_RCCAL, /* RC calibrate */
+   FC11_REG_VCOCAL,/* VCO calibrate */
+   FC11_REG_15,
+   FC11_REG_16,/* Unknown tuner reg 16 */
+   FC11_REG_17,
+
+   FC11_NR_REGS,   /* Number of registers */
+};
+
+enum FC11_REG_VCOSEL_bits {
+   FC11_VCOSEL_2   = 0x08, /* VCO select 2 */
+   FC11_VCOSEL_1   = 0x10, /* VCO select 1 */
+   FC11_VCOSEL_CLKOUT  = 0x20, /* Fix clock out */
+   FC11_VCOSEL_BW7M= 0x40, /* 7MHz bw */
+   FC11_VCOSEL_BW6M= 0x80, /* 6MHz bw */
+};
+
+enum FC11_REG_RCCAL_bits {
+   FC11_RCCAL_FORCE= 0x10, /* force */
+};
+
+enum FC11_REG_VCOCAL_bits {
+   FC11_VCOCAL_RUN = 0,/* VCO calibration run */
+   FC11_VCOCAL_VALUEMASK   = 0x3F, /* VCO calibration value mask */
+   FC11_VCOCAL_OK  = 0x40, /* VCO calibration Ok */
+   FC11_VCOCAL_RESET   = 0x80, /* VCO calibration reset */
+};
+
+
+struct fc0011_priv {
+   struct i2c_adapter *i2c;
+   u8 addr;
+
+   u32 frequency;
+   u32 bandwidth;
+};
+
+
+static int fc0011_writereg(struct fc0011_priv *priv, u8 reg, u8 val)
+{
+   u8 buf[2] = { reg, val };
+   struct i2c_msg msg = { .addr = priv->addr,
+   .flags = 0, .buf = buf, .len = 2 };
+
+   if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
+   dev_err(&priv->i2c->dev,
+   "I2C write reg failed, reg: %02x, val: %02x\n",
+   reg, val);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int fc0011_readreg(struct fc0011_priv *priv, u8 reg, u8 *val)
+{
+   u8 dummy;
+   struct i2c_msg msg[2] = {
+   { .addr = priv->addr,
+ .flags = 0, .b

[PATCH] af9035: Add USB read checksumming

2012-04-01 Thread Michael Büsch
This adds USB message read checksumming to protect against
device and bus errors.
It also adds a read length check to avoid returning garbage from
the buffer, if the device truncated the message.

Signed-off-by: Michael Buesch 

---

Index: linux/drivers/media/dvb/dvb-usb/af9035.c
===
--- linux.orig/drivers/media/dvb/dvb-usb/af9035.c   2012-04-01 
21:44:27.767000731 +0200
+++ linux/drivers/media/dvb/dvb-usb/af9035.c2012-04-01 22:26:46.020185359 
+0200
@@ -37,6 +37,22 @@
}
 };
 
+static u16 af9035_checksum(const u8 *buf, size_t len)
+{
+   size_t i;
+   u16 checksum = 0;
+
+   for (i = 1; i < len; i++) {
+   if (i % 2)
+   checksum += buf[i] << 8;
+   else
+   checksum += buf[i];
+   }
+   checksum = ~checksum;
+
+   return checksum;
+}
+
 static int af9035_ctrl_msg(struct usb_device *udev, struct usb_req *req)
 {
 #define BUF_LEN 63
@@ -45,11 +61,11 @@
 #define CHECKSUM_LEN 2
 #define USB_TIMEOUT 2000
 
-   int ret, i, act_len;
+   int ret, act_len;
u8 buf[BUF_LEN];
u32 msg_len;
static u8 seq; /* packet sequence number */
-   u16 checksum = 0;
+   u16 checksum, tmpsum;
 
/* buffer overflow check */
if (req->wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) ||
@@ -70,14 +86,7 @@
memcpy(&buf[4], req->wbuf, req->wlen);
 
/* calc and add checksum */
-   for (i = 1; i < buf[0]-1; i++) {
-   if (i % 2)
-   checksum += buf[i] << 8;
-   else
-   checksum += buf[i];
-   }
-   checksum = ~checksum;
-
+   checksum = af9035_checksum(buf, buf[0] - 1);
buf[buf[0]-1] = (checksum >> 8);
buf[buf[0]-0] = (checksum & 0xff);
 
@@ -107,7 +116,23 @@
ret = -EIO;
goto err_mutex_unlock;
}
+   if (act_len != msg_len) {
+   err("recv bulk message truncated (%d != %u)\n",
+   act_len, (unsigned int)msg_len);
+   ret = -EIO;
+   goto err_mutex_unlock;
+   }
 
+   /* verify checksum */
+   checksum = af9035_checksum(buf, act_len - 2);
+   tmpsum = (buf[act_len - 2] << 8) | buf[act_len - 1];
+   if (tmpsum != checksum) {
+   err("%s: command=%02X checksum mismatch (%04X != %04X)\n",
+   __func__, req->cmd,
+   (unsigned int)tmpsum, (unsigned int)checksum);
+   ret = -EIO;
+   goto err_mutex_unlock;
+   }
/* check status */
if (buf[2]) {
pr_debug("%s: command=%02x failed fw error=%d\n", __func__,


-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-04-01 Thread Michael Büsch
On Sun, 01 Apr 2012 19:39:56 +0300
Antti Palosaari  wrote:

> > Well I didn't retry at that level, but at the fc0011 driver level.
> > It does already retry once in fc0011 (with complete tuner reset).
> > I increased it to 6 times (3 was not enough).
> 
> Maybe some delay is needed in order to wait tuner wakes up after the 
> reset. Reason it does not occur the other driver is likely there is some 
> delay somewhere...

Yep, I suspect that, too. However, I already tried lots of things that didn't
really work. Such as adding 100ms delay before and after all i2c reads
and writes inside of the fc0011 driver.
I'll investigate further...

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-04-01 Thread Michael Büsch
On Sun, 1 Apr 2012 18:24:09 +0200
"Hans-Frieder Vogt"  wrote:
> However, I found the problem: the buffer 
> length needs to be msg[1].len, see below.

I spotted this bug, too, but it didn't fix the problem, as len is 1 for
both packets in my specific case. So it doesn't make a difference in this case.

But as I said in the previous mail: I did more debugging and I'm pretty sure 
that
the actual i2c reads and writes work as expected. The problem is at another 
level.

>  --- old/af9035.c 2012-04-01 16:41:53.694103691 +0200
> +++ new/af9035.c2012-04-01 18:22:25.026930784 +0200
> @@ -209,24 +209,15 @@
> msg[1].len);
> } else {
> /* I2C */
> -#if 0
> -   /*
> -* FIXME: Keep that code. It should work but as it is
> -* not tested I left it disabled and return -
> EOPNOTSUPP
> -* for the sure.
> -*/
> u8 buf[4 + msg[0].len];
> struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf),
> buf, msg[1].len, msg[1].buf };
> -   buf[0] = msg[0].len;
> +   buf[0] = msg[1].len;
> buf[1] = msg[0].addr << 1;
> buf[2] = 0x01;
> buf[3] = 0x00;
> memcpy(&buf[4], msg[0].buf, msg[0].len);
> ret = af9035_ctrl_msg(d->udev, &req);
> -#endif
> -   pr_debug("%s: I2C operation not supported\n", 
> __func__);
> -   ret = -EOPNOTSUPP;
> }
> } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
> if (msg[0].len > 40) {

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-04-01 Thread Michael Büsch
On Sun, 01 Apr 2012 19:20:21 +0300
Antti Palosaari  wrote:

> On 01.04.2012 19:15, Michael Büsch wrote:
> > On Sun, 1 Apr 2012 15:11:53 +0200
> > Michael Büsch  wrote:
> >
> >> [ 3101.940765] i2c i2c-8: Failed to read VCO calibration value (got 20)
> >
> > Ok, it turns out that it doesn't fail all the time, but only sporadically.
> > So increasing the number of retries fixes (or at least works around) it.
> 
> OK, feel free to add ~3 retries inside af9035_ctrl_msg() i think.

Well I didn't retry at that level, but at the fc0011 driver level.
It does already retry once in fc0011 (with complete tuner reset).
I increased it to 6 times (3 was not enough).

I think we can't retry at af9035_ctrl_msg() level, because the
actual i2c/usb transfer does not fail. The received packet checksum even
is ok (although we currently don't check it. I'll send a patch for that later).

> You didn't mention if error is coming from af9035 firmware or from USB 
> stack. Just for the interest...

I don't know how much the firmware is involved in this, but _maybe_ this
glitch is caused by it.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-04-01 Thread Michael Büsch
On Sun, 1 Apr 2012 15:11:53 +0200
Michael Büsch  wrote:

> [ 3101.940765] i2c i2c-8: Failed to read VCO calibration value (got 20)

Ok, it turns out that it doesn't fail all the time, but only sporadically.
So increasing the number of retries fixes (or at least works around) it.

No idea why this behaves differently from fc0011 on Hans' driver, though.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-04-01 Thread Michael Büsch
On Sun, 1 Apr 2012 16:42:34 +0200
"Hans-Frieder Vogt"  wrote:
> > [ 3101.940765] i2c i2c-8: Failed to read VCO calibration value (got 20)
> > 
> > It doesn't run into this check on the other af903x driver.
> > So I suspect an i2c read issue here.
> 
> I would first uncomment the i2c read functionality in Antti's driver!

I did this.

> > Attached: The patches.

See the patches.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-04-01 Thread Michael Büsch
On Sun, 01 Apr 2012 15:29:07 +0300
Antti Palosaari  wrote:
> buf[1] = msg[0].addr << 1;
> Maybe you have given I2C address as a "8bit" format?

Uhh, the address is leftshifted by one.
So I changed the i2c address from 0xC0 to 0x60.

The i2c write seems to work now. At least it doesn't complain anymore
and it sorta seems to tune to the right frequency.
But i2c read may be broken.
I had to enable the commented read code, but it still fails to read
the VCO calibration value:

[ 3101.940765] i2c i2c-8: Failed to read VCO calibration value (got 20)

It doesn't run into this check on the other af903x driver.
So I suspect an i2c read issue here.

Attached: The patches.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E
Index: linux/drivers/media/common/tuners/Kconfig
===
--- linux.orig/drivers/media/common/tuners/Kconfig	2012-04-01 11:42:36.539532984 +0200
+++ linux/drivers/media/common/tuners/Kconfig	2012-04-01 11:42:38.803572117 +0200
@@ -204,6 +204,13 @@
 	help
 	  NXP TDA18218 silicon tuner driver.
 
+config MEDIA_TUNER_FC0011
+	tristate "Fitipower FC0011 silicon tuner"
+	depends on VIDEO_MEDIA && I2C
+	default m if MEDIA_TUNER_CUSTOMISE
+	help
+	  Fitipower FC0011 silicon tuner driver.
+
 config MEDIA_TUNER_TDA18212
 	tristate "NXP TDA18212 silicon tuner"
 	depends on VIDEO_MEDIA && I2C
Index: linux/drivers/media/common/tuners/Makefile
===
--- linux.orig/drivers/media/common/tuners/Makefile	2012-04-01 11:42:36.539532984 +0200
+++ linux/drivers/media/common/tuners/Makefile	2012-04-01 11:42:38.803572117 +0200
@@ -29,6 +29,7 @@
 obj-$(CONFIG_MEDIA_TUNER_TDA18218) += tda18218.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18212) += tda18212.o
 obj-$(CONFIG_MEDIA_TUNER_TUA9001) += tua9001.o
+obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o
 
 ccflags-y += -I$(srctree)/drivers/media/dvb/dvb-core
 ccflags-y += -I$(srctree)/drivers/media/dvb/frontends
Index: linux/drivers/media/common/tuners/fc0011.c
===
--- /dev/null	1970-01-01 00:00:00.0 +
+++ linux/drivers/media/common/tuners/fc0011.c	2012-04-01 14:49:08.046382661 +0200
@@ -0,0 +1,491 @@
+/*
+ * Fitipower FC0011 tuner driver
+ *
+ * Copyright (C) 2012 Michael Buesch 
+ *
+ * Derived from FC0012 tuner driver:
+ * Copyright (C) 2012 Hans-Frieder Vogt 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "fc0011.h"
+
+
+/* Tuner registers */
+enum {
+	FC11_REG_0,
+	FC11_REG_FA,		/* FA */
+	FC11_REG_FP,		/* FP */
+	FC11_REG_XINHI,		/* XIN high 8 bit */
+	FC11_REG_XINLO,		/* XIN low 8 bit */
+	FC11_REG_VCO,		/* VCO */
+	FC11_REG_VCOSEL,	/* VCO select */
+	FC11_REG_7,		/* Unknown tune reg 7 */
+	FC11_REG_8,		/* Unknown tune reg 8 */
+	FC11_REG_9,
+	FC11_REG_10,		/* Unknown tune reg 10 */
+	FC11_REG_11,		/* Unknown tune reg 11 */
+	FC11_REG_12,
+	FC11_REG_RCCAL,		/* RC calibrate */
+	FC11_REG_VCOCAL,	/* VCO calibrate */
+	FC11_REG_15,
+	FC11_REG_16,		/* Unknown tune reg 16 */
+	FC11_REG_17,
+
+	FC11_NR_REGS,		/* Number of registers */
+};
+
+enum FC11_REG_VCOSEL_bits {
+	FC11_VCOSEL_2		= 0x08, /* VCO select 2 */
+	FC11_VCOSEL_1		= 0x10, /* VCO select 1 */
+	FC11_VCOSEL_CLKOUT	= 0x20, /* Fix clock out */
+	FC11_VCOSEL_BW7M	= 0x40, /* 7MHz bw */
+	FC11_VCOSEL_BW6M	= 0x80, /* 6MHz bw */
+};
+
+enum FC11_REG_RCCAL_bits {
+	FC11_RCCAL_FORCE	= 0x10, /* force */
+};
+
+enum FC11_REG_VCOCAL_bits {
+	FC11_VCOCAL_RUN		= 0,	/* VCO calibration run */
+	FC11_VCOCAL_VALUEMASK	= 0x3F,	/* VCO calibration value mask */
+	FC11_VCOCAL_OK		= 0x40,	/* VCO calibration Ok */
+	FC11_VCOCAL_RESET	= 0x80, /* VCO calibration reset */
+};
+
+
+struct fc0011_priv {
+	struct i2c_adapter *i2c;
+	u8 addr;
+
+	u32 frequency;
+	u32 bandwidth;
+};
+
+
+static int fc0011_writereg(struct fc0011_priv *priv, u8 reg, u8 val)
+{
+	u8 buf[2] = { reg, val };
+	struct i2c_msg msg = { .addr = priv->addr,
+		.flags = 0, .buf = buf, .len = 2 };
+
+	msleep(1);
+	if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
+		dev_err(&priv->i2c->dev,
+			"I2C write reg failed, reg: %02x, val: %02x\n",
+			reg, val);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static int fc0011_readreg(struct fc0011_priv *priv, u8 reg, u8 *val)
+{
+	struct i2c_msg msg[2] = {
+		{ .addr = priv->a

Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-04-01 Thread Michael Büsch
On Sun, 1 Apr 2012 10:33:15 +0200
Michael Büsch  wrote:

> On Sun, 01 Apr 2012 07:51:33 +0300
> Antti Palosaari  wrote:
> > > I have no clue about the firmware format, so it will probably be easier
> > > if you'd dive into that stuff as you already seem to know it.
> > 
> > Done. I didn't have neither info, but there was good posting from Daniel 
> > Glöckner that documents it! Nice job Daniel, without that info I was 
> > surely implemented it differently and surely more wrong way.
> > 
> > I pushed my experimental tree out, patches are welcome top of that.
> > http://git.linuxtv.org/anttip/media_tree.git/shortlog/refs/heads/af9035_experimental
> > 
> > I extracted three firmwares from windows binaries I have. I will sent 
> > those you, Michael, for testing. First, and oldest, is TUA9001, 2nd is 
> > from FC0012 device and 3rd no idea.
> 
> Great work. I'll rebase my tree on the new branch and check those firmware 
> files asap.

Hm, none of these firmwares fix the problem. Maybe it's not a firmware
problem after all, but just incorrectly setup tuner-i2c.

Here's the dmesg log:

[  131.451556] usb 1-1.1: new high-speed USB device number 5 using ehci_hcd
[  131.550302] usb 1-1.1: New USB device found, idVendor=15a4, idProduct=9035
[  131.550315] usb 1-1.1: New USB device strings: Mfr=0, Product=0, 
SerialNumber=0
[  131.674657] af9035_usb_probe: interface=0
[  131.675169] af9035_identify_state: reply=00 00 00 00
[  131.675185] dvb-usb: found a 'Afatech Technologies DVB-T stick' in cold 
state, will try to load a firmware
[  131.691605] dvb-usb: downloading firmware from file 'dvb-usb-af9035-02.fw'
[  131.691626] af9035_download_firmware: core=1 addr=4100 data_len=3 
checksum=fbbe
[  131.692696] af9035_download_firmware: data uploaded=10
[  131.692716] af9035_download_firmware: core=1 addr=4800 data_len=15014 
checksum=587d
[  131.93] af9035_download_firmware: data uploaded=15031
[  131.777807] af9035_download_firmware: core=1 addr=83e9 data_len=4 
checksum=117c
[  131.778785] af9035_download_firmware: data uploaded=15042
[  131.778796] af9035_download_firmware: core=2 addr=4100 data_len=3 
checksum=fabe
[  131.779785] af9035_download_firmware: data uploaded=15052
[  131.779799] af9035_download_firmware: core=2 addr=4550 data_len=27252 
checksum=3950
[  131.936162] af9035_download_firmware: data uploaded=42311
[  131.999412] af9035: firmware version=11.10.10.0
[  131.999443] dvb-usb: found a 'Afatech Technologies DVB-T stick' in warm 
state.
[  131.999790] dvb-usb: will pass the complete MPEG2 transport stream to the 
software demuxer.
[  132.000122] DVB: registering new adapter (Afatech Technologies DVB-T stick)
[  132.000546] af9035_read_mac_address: dual mode=0
[  132.001027] af9035_read_mac_address: [0]tuner=28
[  132.002026] af9035_read_mac_address: [0]IF=36125
[  132.002413] dvb-usb: MAC address: 00:00:00:00:00:00
[  132.018549] af9033: firmware version: LINK=11.10.10.0 OFDM=5.33.10.0
[  132.018566] DVB: registering adapter 0 frontend 0 (Afatech AF9033 (DVB-T))...
[  132.028370] i2c i2c-8: Fitipower FC0011 tuner attached
[  132.028388] dvb-usb: Afatech Technologies DVB-T stick successfully 
initialized and connected.
[  132.028405] af9035_init: USB speed=3 frame_size=0ff9 packet_size=80
[  132.040019] usbcore: registered new interface driver dvb_usb_af9035
[  145.407991] af9035_ctrl_msg: command=03 failed fw error=2
[  145.408008] i2c i2c-8: I2C write reg failed, reg: 07, val: 0f

I also tried the other firmware. Same result.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-04-01 Thread Michael Büsch
On Sun, 01 Apr 2012 07:51:33 +0300
Antti Palosaari  wrote:
> > I have no clue about the firmware format, so it will probably be easier
> > if you'd dive into that stuff as you already seem to know it.
> 
> Done. I didn't have neither info, but there was good posting from Daniel 
> Glöckner that documents it! Nice job Daniel, without that info I was 
> surely implemented it differently and surely more wrong way.
> 
> I pushed my experimental tree out, patches are welcome top of that.
> http://git.linuxtv.org/anttip/media_tree.git/shortlog/refs/heads/af9035_experimental
> 
> I extracted three firmwares from windows binaries I have. I will sent 
> those you, Michael, for testing. First, and oldest, is TUA9001, 2nd is 
> from FC0012 device and 3rd no idea.

Great work. I'll rebase my tree on the new branch and check those firmware 
files asap.

> I need more AF903x hardware, please give links to cheap eBay devices 
> etc. Also I would like to get one device where is AF9033 but no AF9035 
> at all just for stand-alone demodulator implementation. I know there is 
> few such devices, like AverMedia A336 for example...

This is my stick. It's a AF9035 with one FC0011 tuner chip:
http://www.amazon.de/Cabstone-DVB-T-Empf%C3%A4nger-Arbeitsspeicher-schwarz/dp/B00307551E/ref=sr_1_1?ie=UTF8&qid=1333268959&sr=8-1

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-03-31 Thread Michael Büsch
On Sat, 31 Mar 2012 19:48:34 +0300
Antti Palosaari  wrote:

> And about the new FW downloader, that supports those new firmwares, feel 
> free to implement it if you wish too. I will now goto out of house and 
> will back during few hours. If you wish to do it just reply during 4 
> hours, and I will not start working for it. Instead I will continue with 
> IT9135.

I have no clue about the firmware format, so it will probably be easier
if you'd dive into that stuff as you already seem to know it.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-03-31 Thread Michael Büsch
On Sat, 31 Mar 2012 19:34:23 +0300
Antti Palosaari  wrote:

> On 31.03.2012 19:29, Michael Büsch wrote:
> > On Sat, 31 Mar 2012 17:28:38 +0300
> > Antti Palosaari  wrote:
> >
> >> Googling the filename reveals many links, here is one:
> >> http://xgazza.altervista.org/Linux/DVB/dvb-usb-af9035-01.fw
> >
> > Hm, on tuner register access I get these errors:
> >
> > [ 9259.080907] af9035_ctrl_msg: command=03 failed fw error=2
> > [ 9259.080922] i2c i2c-8: I2C write reg failed, reg: 07, val: 0f
> >
> > Is it possible that this firmware is incompatible with my stick?
> > The firmware that I successfully used with the other af9035 driver seems to
> > be incompatible with your driver, though. It crashes it somewhere
> > on firmware download in one of the USB transfer's memcpy.
> 
> Most likely it is incompatible. It is surely one of the earliest 
> firmwares. I will try to make that new fw downloaded ASAP, likely 
> tomorrow morning it is done.

Ok, thanks a lot.

Attached are my current fc0011 patches. Just for reference.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E
Index: linux/drivers/media/common/tuners/Kconfig
===
--- linux.orig/drivers/media/common/tuners/Kconfig	2012-03-31 00:32:25.0 +0200
+++ linux/drivers/media/common/tuners/Kconfig	2012-03-31 13:03:07.279334714 +0200
@@ -204,6 +204,13 @@
 	help
 	  NXP TDA18218 silicon tuner driver.
 
+config MEDIA_TUNER_FC0011
+	tristate "Fitipower FC0011 silicon tuner"
+	depends on VIDEO_MEDIA && I2C
+	default m if MEDIA_TUNER_CUSTOMISE
+	help
+	  Fitipower FC0011 silicon tuner driver.
+
 config MEDIA_TUNER_TDA18212
 	tristate "NXP TDA18212 silicon tuner"
 	depends on VIDEO_MEDIA && I2C
Index: linux/drivers/media/common/tuners/Makefile
===
--- linux.orig/drivers/media/common/tuners/Makefile	2012-03-31 00:32:25.0 +0200
+++ linux/drivers/media/common/tuners/Makefile	2012-03-31 13:03:42.444806267 +0200
@@ -29,6 +29,7 @@
 obj-$(CONFIG_MEDIA_TUNER_TDA18218) += tda18218.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18212) += tda18212.o
 obj-$(CONFIG_MEDIA_TUNER_TUA9001) += tua9001.o
+obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o
 
 ccflags-y += -I$(srctree)/drivers/media/dvb/dvb-core
 ccflags-y += -I$(srctree)/drivers/media/dvb/frontends
Index: linux/drivers/media/common/tuners/fc0011.c
===
--- /dev/null	1970-01-01 00:00:00.0 +
+++ linux/drivers/media/common/tuners/fc0011.c	2012-03-31 14:30:24.122314647 +0200
@@ -0,0 +1,489 @@
+/*
+ * Fitipower FC0011 tuner driver
+ *
+ * Copyright (C) 2012 Michael Buesch 
+ *
+ * Derived from FC0012 tuner driver:
+ * Copyright (C) 2012 Hans-Frieder Vogt 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "fc0011.h"
+
+
+/* Tuner registers */
+enum {
+	FC11_REG_0,
+	FC11_REG_FA,		/* FA */
+	FC11_REG_FP,		/* FP */
+	FC11_REG_XINHI,		/* XIN high 8 bit */
+	FC11_REG_XINLO,		/* XIN low 8 bit */
+	FC11_REG_VCO,		/* VCO */
+	FC11_REG_VCOSEL,	/* VCO select */
+	FC11_REG_7,		/* Unknown tune reg 7 */
+	FC11_REG_8,		/* Unknown tune reg 8 */
+	FC11_REG_9,
+	FC11_REG_10,		/* Unknown tune reg 10 */
+	FC11_REG_11,		/* Unknown tune reg 11 */
+	FC11_REG_12,
+	FC11_REG_RCCAL,		/* RC calibrate */
+	FC11_REG_VCOCAL,	/* VCO calibrate */
+	FC11_REG_15,
+	FC11_REG_16,		/* Unknown tune reg 16 */
+	FC11_REG_17,
+
+	FC11_NR_REGS,		/* Number of registers */
+};
+
+enum FC11_REG_VCOSEL_bits {
+	FC11_VCOSEL_2		= 0x08, /* VCO select 2 */
+	FC11_VCOSEL_1		= 0x10, /* VCO select 1 */
+	FC11_VCOSEL_CLKOUT	= 0x20, /* Fix clock out */
+	FC11_VCOSEL_BW7M	= 0x40, /* 7MHz bw */
+	FC11_VCOSEL_BW6M	= 0x80, /* 6MHz bw */
+};
+
+enum FC11_REG_RCCAL_bits {
+	FC11_RCCAL_FORCE	= 0x10, /* force */
+};
+
+enum FC11_REG_VCOCAL_bits {
+	FC11_VCOCAL_RUN		= 0,	/* VCO calibration run */
+	FC11_VCOCAL_VALUEMASK	= 0x3F,	/* VCO calibration value mask */
+	FC11_VCOCAL_OK		= 0x40,	/* VCO calibration Ok */
+	FC11_VCOCAL_RESET	= 0x80, /* VCO calibration reset */
+};
+
+
+struct fc0011_priv {
+	struct i2c_adapter *i2c;
+	u8 addr;
+
+	u32 frequency;
+

Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-03-31 Thread Michael Büsch
On Sat, 31 Mar 2012 17:28:38 +0300
Antti Palosaari  wrote:

> Googling the filename reveals many links, here is one:
> http://xgazza.altervista.org/Linux/DVB/dvb-usb-af9035-01.fw

Hm, on tuner register access I get these errors:

[ 9259.080907] af9035_ctrl_msg: command=03 failed fw error=2
[ 9259.080922] i2c i2c-8: I2C write reg failed, reg: 07, val: 0f

Is it possible that this firmware is incompatible with my stick?
The firmware that I successfully used with the other af9035 driver seems to
be incompatible with your driver, though. It crashes it somewhere
on firmware download in one of the USB transfer's memcpy.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-03-31 Thread Michael Büsch
On Sat, 31 Mar 2012 00:14:58 +0200
Michael Büsch  wrote:

> On Sat, 31 Mar 2012 01:00:21 +0300
> Antti Palosaari  wrote:
> 
> > Feel free to do that. Actually, I just tried it about 2 hours ago. But I 
> > failed, since there callbacks given as a param for tuner attach and it 
> > is wrong. There is frontend callback defined just for that. Look example 
> > from some Xceive tuners also hd29l2 demod driver contains one example. 
> > Use git grep DVB_FRONTEND_COMPONENT_ drivers/media/ to see all those 
> > existing callbacks.
> 
> Cool. Thanks for the hint. I'll fix this.

Ok, so I cooked something up here.
I'm wondering where to get the firmware file from, so I can test it.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-03-30 Thread Michael Büsch
On Sat, 31 Mar 2012 01:00:21 +0300
Antti Palosaari  wrote:

> Feel free to do that. Actually, I just tried it about 2 hours ago. But I 
> failed, since there callbacks given as a param for tuner attach and it 
> is wrong. There is frontend callback defined just for that. Look example 
> from some Xceive tuners also hd29l2 demod driver contains one example. 
> Use git grep DVB_FRONTEND_COMPONENT_ drivers/media/ to see all those 
> existing callbacks.

Cool. Thanks for the hint. I'll fix this.

> My short term plans are now
> * fix af9033 IF freq control (now Zero-IF only)
> * change firmware download to use new firmware syntax
> * dual tuner support
> * check if IT9035 is enough similar (My personal suspicion is that 
> integrated tuner is only main difference, whilst USB-interface and demod 
> are same. But someone has told that it is quite different design though.)
> * implement SNR, BER and USB counters
> * implement remote controller

Sounds good.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [GIT PULL FOR 3.5] AF9035/AF9033/TUA9001 => TerraTec Cinergy T Stick [0ccd:0093]

2012-03-30 Thread Michael Büsch
On Fri, 30 Mar 2012 15:33:02 +0300
Antti Palosaari  wrote:

> Terve Mauro and all the other hackers,
> 
> I did some massive rewrite for my old AF9035/AF9033 driver that was 
> never merged. Anyhow, here it is.
> 
> New drivers here are:
> Infineon TUA 9001 silicon tuner driver
> Afatech AF9033 DVB-T demodulator driver
> Afatech AF9035 DVB USB driver

This looks pretty nice.

I recently wrote a tuner driver for the fc0011 tuner, which is used in some
af9035 sticks:
http://patchwork.linuxtv.org/patch/10503/

It was developed against an af903x driver by Hans-Frieder Vogt.

I'll port it to your AF9035 driver, ASAP, to check whether this works
on my DVB USB stick.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH] Add Fitipower fc0011 tuner driver

2012-03-28 Thread Michael Büsch
On Thu, 29 Mar 2012 02:01:34 +0200
Michael Büsch  wrote:

> The driver is tested with the af903x driver.

For reference, here goes the af903x/fc0011 glue:

Signed-off-by: Michael Buesch 

Index: linux-3.3/drivers/media/dvb/dvb-usb/Kconfig
===
--- linux-3.3.orig/drivers/media/dvb/dvb-usb/Kconfig2012-03-28 
23:47:04.091901520 +0200
+++ linux-3.3/drivers/media/dvb/dvb-usb/Kconfig 2012-03-28 23:47:07.695965033 
+0200
@@ -342,6 +342,7 @@
 config DVB_USB_AF903X
tristate "Afatech AF903X DVB-T USB2.0 support"
depends on DVB_USB && EXPERIMENTAL
+   select MEDIA_TUNER_FC0011   if !MEDIA_TUNER_CUSTOMISE
select MEDIA_TUNER_FC0012   if !MEDIA_TUNER_CUSTOMISE
select MEDIA_TUNER_MXL5007T if !MEDIA_TUNER_CUSTOMISE
help
Index: linux-3.3/drivers/media/dvb/dvb-usb/af903x-devices.c
===
--- linux-3.3.orig/drivers/media/dvb/dvb-usb/af903x-devices.c   2012-03-28 
23:47:04.091901520 +0200
+++ linux-3.3/drivers/media/dvb/dvb-usb/af903x-devices.c2012-03-28 
23:47:07.699965103 +0200
@@ -260,6 +260,7 @@
 }
 
 extern struct tuner_desc tuner_af9007;
+extern struct tuner_desc tuner_fc0011;
 extern struct tuner_desc tuner_fc0012;
 extern struct tuner_desc tuner_mxl5007t;
 
@@ -273,6 +274,9 @@
case TUNER_AF9007:
ctx->tuner_desc = &tuner_af9007;
break;
+   case TUNER_FC0011:
+   ctx->tuner_desc = &tuner_fc0011;
+   break;
case TUNER_FC0012:
ctx->tuner_desc = &tuner_fc0012;
break;
Index: linux-3.3/drivers/media/dvb/dvb-usb/af903x-fe.c
===
--- linux-3.3.orig/drivers/media/dvb/dvb-usb/af903x-fe.c2012-03-28 
23:47:04.091901520 +0200
+++ linux-3.3/drivers/media/dvb/dvb-usb/af903x-fe.c 2012-03-28 
23:47:07.699965103 +0200
@@ -28,6 +28,7 @@
 #include "af903x-fe.h"
 #include "af903x-fe-priv.h"
 #include "dvb_frontend.h"
+#include "fc0011.h"
 #include "fc0012.h"
 #include "mxl5007t.h"
 
@@ -1967,6 +1968,8 @@
}
 };
 
+extern int af903x_fc0011_reset(unsigned long arg0, unsigned long arg1);
+
 static struct dvb_frontend_ops af903x_ops;
 struct dvb_frontend *af903x_fe_attach(struct i2c_adapter *i2c_adap, int id,
struct af903x_dev_ctx *ctx)
@@ -1990,6 +1993,14 @@
switch(ctx->tuner_desc->tunerId) {
case TUNER_AF9007:
break;
+   case TUNER_FC0011:
+   ret = dvb_attach(fc0011_attach, frontend, i2c_adap,
+   id == 0 ? ctx->tuner_desc->tuner_addr :
+   ctx->tuner_desc->tuner_addr + 1,
+   af903x_fc0011_reset,
+   (unsigned long)ctx, (unsigned long)id)
+   == NULL ?  -ENODEV : 0;
+   break;
case TUNER_FC0012:
ret = dvb_attach(fc0012_attach, frontend, i2c_adap,
id == 0 ? ctx->tuner_desc->tuner_addr :
Index: linux-3.3/drivers/media/dvb/dvb-usb/af903x-tuners.c
===
--- linux-3.3.orig/drivers/media/dvb/dvb-usb/af903x-tuners.c2012-03-28 
23:47:04.091901520 +0200
+++ linux-3.3/drivers/media/dvb/dvb-usb/af903x-tuners.c 2012-03-28 
23:47:07.699965103 +0200
@@ -189,6 +189,69 @@
{0xf1e6, 0x00},
 };
 
+static struct af903x_val_set fc0011_scripts[] = {
+   {0x0046, 0x28}, /* TUNER_ID */
+   {0x0057, 0x00},
+   {0x0058, 0x01},
+   {0x005f, 0x00},
+   {0x0060, 0x00},
+   {0x0068, 0xa5},
+   {0x006e, 0x01},
+   {0x0071, 0x0A},
+   {0x0072, 0x02},
+   {0x0074, 0x01},
+   {0x0079, 0x01},
+   {0x0093, 0x00},
+   {0x0094, 0x00},
+   {0x0095, 0x00},
+   {0x0096, 0x00},
+   {0x009b, 0x2D},
+   {0x009c, 0x60},
+   {0x009d, 0x23},
+   {0x00a4, 0x50},
+   {0x00ad, 0x50},
+   {0x00b3, 0x01},
+   {0x00b7, 0x88},
+   {0x00b8, 0xa6},
+   {0x00c3, 0x01},
+   {0x00c4, 0x01},
+   {0x00c7, 0x69},
+   {0xF007, 0x00},
+   {0xF00A, 0x1B},
+   {0xF00B, 0x1B},
+   {0xF00C, 0x1B},
+   {0xF00D, 0x1B},
+   {0xF00E, 0xFF},
+   {0xF00F, 0x01},
+   {0xF010, 0x00},
+   {0xF011, 0x02},
+   {0xF012, 0xFF},
+   {0xF013, 0x01},
+   {0xF014, 0x00},
+   {0xF015, 0x02},
+   {0xF01B, 0xEF},
+   {0xF01C, 0x01},
+   {0xF01D, 0x0f},
+   {0xF01E, 0x02},
+   {0xF01F, 0x6E},
+   {0xF020, 0x00},
+   {0xF025, 0xDE},
+   {0xF026, 0x00},
+   {0xF027, 0x0A},
+   {0xF028, 0x03},
+   {0xF029, 0x6E},
+   {0xF02A, 0x00},
+   {0xF047, 0x00},
+   {0xF054, 0x0},
+   {0xF055, 0x0},
+   {0xF077, 0x01},
+   {0xF1E6, 0x0

[PATCH] Add Fitipower fc0011 tuner driver

2012-03-28 Thread Michael Büsch
This adds a driver for the Fitipower fc0011 DVB-t tuner.

Signed-off-by: Michael Buesch 

---

The driver is tested with the af903x driver.

Mauro Carvalho Chehab, I'm actually aiming on getting this driver
merged into the media-tree now.

Hans-Frieder Vogt, what are your plans on getting af903x merged?
As the driver does actually work, we should focus on merging it ASAP.
That would help further development a _lot_.


Index: linux/drivers/media/common/tuners/Kconfig
===
--- linux.orig/drivers/media/common/tuners/Kconfig  2012-02-28 
14:26:19.0 +0100
+++ linux/drivers/media/common/tuners/Kconfig   2012-03-28 23:53:55.942050978 
+0200
@@ -204,6 +204,13 @@
help
  NXP TDA18218 silicon tuner driver.
 
+config MEDIA_TUNER_FC0011
+   tristate "Fitipower FC0011 silicon tuner"
+   depends on VIDEO_MEDIA && I2C
+   default m if MEDIA_TUNER_CUSTOMISE
+   help
+ Fitipower FC0011 silicon tuner driver.
+
 config MEDIA_TUNER_TDA18212
tristate "NXP TDA18212 silicon tuner"
depends on VIDEO_MEDIA && I2C
Index: linux/drivers/media/common/tuners/Makefile
===
--- linux.orig/drivers/media/common/tuners/Makefile 2012-03-28 
23:51:43.0 +0200
+++ linux/drivers/media/common/tuners/Makefile  2012-03-28 23:55:08.838315202 
+0200
@@ -28,6 +28,7 @@
 obj-$(CONFIG_MEDIA_TUNER_MAX2165) += max2165.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18218) += tda18218.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18212) += tda18212.o
+obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o
 
 ccflags-y += -I$(srctree)/drivers/media/dvb/dvb-core
 ccflags-y += -I$(srctree)/drivers/media/dvb/frontends
Index: linux/drivers/media/common/tuners/fc0011.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux/drivers/media/common/tuners/fc0011.c  2012-03-28 23:53:42.662004812 
+0200
@@ -0,0 +1,495 @@
+/*
+ * Fitipower FC0011 tuner driver
+ *
+ * Copyright (C) 2012 Michael Buesch 
+ *
+ * Derived from FC0012 tuner driver:
+ * Copyright (C) 2012 Hans-Frieder Vogt 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "fc0011.h"
+
+
+/* Tuner registers */
+enum {
+   FC11_REG_0,
+   FC11_REG_FA,/* FA */
+   FC11_REG_FP,/* FP */
+   FC11_REG_XINHI, /* XIN high 8 bit */
+   FC11_REG_XINLO, /* XIN low 8 bit */
+   FC11_REG_VCO,   /* VCO */
+   FC11_REG_VCOSEL,/* VCO select */
+   FC11_REG_7, /* Unknown tune reg 7 */
+   FC11_REG_8, /* Unknown tune reg 8 */
+   FC11_REG_9,
+   FC11_REG_10,/* Unknown tune reg 10 */
+   FC11_REG_11,/* Unknown tune reg 11 */
+   FC11_REG_12,
+   FC11_REG_RCCAL, /* RC calibrate */
+   FC11_REG_VCOCAL,/* VCO calibrate */
+   FC11_REG_15,
+   FC11_REG_16,/* Unknown tune reg 16 */
+   FC11_REG_17,
+
+   FC11_NR_REGS,   /* Number of registers */
+};
+
+enum FC11_REG_VCOSEL_bits {
+   FC11_VCOSEL_2   = 0x08, /* VCO select 2 */
+   FC11_VCOSEL_1   = 0x10, /* VCO select 1 */
+   FC11_VCOSEL_CLKOUT  = 0x20, /* Fix clock out */
+   FC11_VCOSEL_BW7M= 0x40, /* 7MHz bw */
+   FC11_VCOSEL_BW6M= 0x80, /* 6MHz bw */
+};
+
+enum FC11_REG_RCCAL_bits {
+   FC11_RCCAL_FORCE= 0x10, /* force */
+};
+
+enum FC11_REG_VCOCAL_bits {
+   FC11_VCOCAL_RUN = 0,/* VCO calibration run */
+   FC11_VCOCAL_VALUEMASK   = 0x3F, /* VCO calibration value mask */
+   FC11_VCOCAL_OK  = 0x40, /* VCO calibration Ok */
+   FC11_VCOCAL_RESET   = 0x80, /* VCO calibration reset */
+};
+
+
+struct fc0011_priv {
+   struct i2c_adapter *i2c;
+   u8 addr;
+
+   u32 frequency;
+   u32 bandwidth;
+
+   int (*tuner_reset)(unsigned long, unsigned long);
+   unsigned long tuner_reset_arg0;
+   unsigned long tuner_reset_arg1;
+};
+
+
+static int fc0011_writereg(struct fc0011_priv *priv, u8 reg, u8 val)
+{
+   u8 buf[2] = { reg, val };
+   struct i2c_msg msg = { .addr = priv->addr,
+   .flags = 0, .buf = buf, .len = 2 };

Re: [PATCH 1/2] Fitipower fc0011 driver

2012-03-21 Thread Michael Büsch
On Wed, 21 Mar 2012 20:12:03 +0100
Gianluca Gennari  wrote:

> > +#if 0 //TODO 3.3
> > +   struct dtv_frontend_properties *p = &fe->dtv_property_cache;
> > +   u32 freq = p->frequency / 1000;
> > +   u32 delsys = p->delivery_system;
> 
> The "delsys" variable is unused, you can delete it.

Thanks for your review. I fixed this.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


[PATCH 2/2] Integrate Fitipower fc0011 into af903x

2012-03-21 Thread Michael Büsch
This adds fc0011 support to the af903x driver.

Signed-off-by: Michael Buesch 

---


Index: linux-source-3.2/drivers/media/dvb/dvb-usb/Kconfig
===
--- linux-source-3.2.orig/drivers/media/dvb/dvb-usb/Kconfig 2012-03-20 
22:48:14.025859279 +0100
+++ linux-source-3.2/drivers/media/dvb/dvb-usb/Kconfig  2012-03-21 
15:31:43.266801632 +0100
@@ -342,6 +342,7 @@
 config DVB_USB_AF903X
tristate "Afatech AF903X DVB-T USB2.0 support"
depends on DVB_USB && EXPERIMENTAL
+   select MEDIA_TUNER_FC0011   if !MEDIA_TUNER_CUSTOMISE
select MEDIA_TUNER_FC0012   if !MEDIA_TUNER_CUSTOMISE
select MEDIA_TUNER_MXL5007T if !MEDIA_TUNER_CUSTOMISE
help
Index: linux-source-3.2/drivers/media/dvb/dvb-usb/af903x-devices.c
===
--- linux-source-3.2.orig/drivers/media/dvb/dvb-usb/af903x-devices.c
2012-03-20 22:48:14.025859279 +0100
+++ linux-source-3.2/drivers/media/dvb/dvb-usb/af903x-devices.c 2012-03-21 
15:31:43.270801692 +0100
@@ -260,6 +260,7 @@
 }
 
 extern struct tuner_desc tuner_af9007;
+extern struct tuner_desc tuner_fc0011;
 extern struct tuner_desc tuner_fc0012;
 extern struct tuner_desc tuner_mxl5007t;
 
@@ -273,6 +274,9 @@
case TUNER_AF9007:
ctx->tuner_desc = &tuner_af9007;
break;
+   case TUNER_FC0011:
+   ctx->tuner_desc = &tuner_fc0011;
+   break;
case TUNER_FC0012:
ctx->tuner_desc = &tuner_fc0012;
break;
Index: linux-source-3.2/drivers/media/dvb/dvb-usb/af903x-fe.c
===
--- linux-source-3.2.orig/drivers/media/dvb/dvb-usb/af903x-fe.c 2012-03-20 
22:48:14.025859279 +0100
+++ linux-source-3.2/drivers/media/dvb/dvb-usb/af903x-fe.c  2012-03-21 
15:37:04.968319280 +0100
@@ -28,6 +28,7 @@
 #include "af903x-fe.h"
 #include "af903x-fe-priv.h"
 #include "dvb_frontend.h"
+#include "fc0011.h"
 #include "fc0012.h"
 #include "mxl5007t.h"
 
@@ -1967,6 +1968,8 @@
}
 };
 
+extern int af903x_fc0011_reset(void *_ctx);
+
 static struct dvb_frontend_ops af903x_ops;
 struct dvb_frontend *af903x_fe_attach(struct i2c_adapter *i2c_adap, int id,
struct af903x_dev_ctx *ctx)
@@ -1990,6 +1993,13 @@
switch(ctx->tuner_desc->tunerId) {
case TUNER_AF9007:
break;
+   case TUNER_FC0011:
+   ret = dvb_attach(fc0011_attach, frontend, i2c_adap,
+   id == 0 ? ctx->tuner_desc->tuner_addr :
+   ctx->tuner_desc->tuner_addr + 1,
+   af903x_fc0011_reset, ctx)
+   == NULL ?  -ENODEV : 0;
+   break;
case TUNER_FC0012:
ret = dvb_attach(fc0012_attach, frontend, i2c_adap,
id == 0 ? ctx->tuner_desc->tuner_addr :
Index: linux-source-3.2/drivers/media/dvb/dvb-usb/af903x-tuners.c
===
--- linux-source-3.2.orig/drivers/media/dvb/dvb-usb/af903x-tuners.c 
2012-03-20 22:48:14.025859279 +0100
+++ linux-source-3.2/drivers/media/dvb/dvb-usb/af903x-tuners.c  2012-03-21 
15:42:42.214115654 +0100
@@ -189,6 +189,69 @@
{0xf1e6, 0x00},
 };
 
+static u16 fc0011_script_sets[] = {
+   0x38,
+};
+
+static struct af903x_val_set fc0011_scripts[] = {
+   {0x0046, 0x28}, /* TUNER_ID */
+   {0x0057, 0x00},
+   {0x0058, 0x01},
+   {0x005f, 0x00},
+   {0x0060, 0x00},
+   {0x0068, 0xa5},
+   {0x006e, 0x01},
+   {0x0071, 0x0A},
+   {0x0072, 0x02},
+   {0x0074, 0x01},
+   {0x0079, 0x01},
+   {0x0093, 0x00},
+   {0x0094, 0x00},
+   {0x0095, 0x00},
+   {0x0096, 0x00},
+   {0x009b, 0x2D},
+   {0x009c, 0x60},
+   {0x009d, 0x23},
+   {0x00a4, 0x50},
+   {0x00ad, 0x50},
+   {0x00b3, 0x01},
+   {0x00b7, 0x88},
+   {0x00b8, 0xa6},
+   {0x00c3, 0x01},
+   {0x00c4, 0x01},
+   {0x00c7, 0x69},
+   {0xF007, 0x00},
+   {0xF00A, 0x1B},
+   {0xF00B, 0x1B},
+   {0xF00C, 0x1B},
+   {0xF00D, 0x1B},
+   {0xF00E, 0xFF},
+   {0xF00F, 0x01},
+   {0xF010, 0x00},
+   {0xF011, 0x02},
+   {0xF012, 0xFF},
+   {0xF013, 0x01},
+   {0xF014, 0x00},
+   {0xF015, 0x02},
+   {0xF01B, 0xEF},
+   {0xF01C, 0x01},
+   {0xF01D, 0x0f},
+   {0xF01E, 0x02},
+   {0xF01F, 0x6E},
+   {0xF020, 0x00},
+   {0xF025, 0xDE},
+   {0xF026, 0x00},
+   {0xF027, 0x0A},
+   {0xF028, 0x03},
+   {0xF029, 0x6E},
+   {0xF02A, 0x00},
+   {0xF047, 0x00},
+   {0xF054, 0x0},
+   {0xF055, 0x0},
+   {0xF077, 0x01},
+   {0xF1E6, 0x00},
+};
+
 static int af903x_fc0012_init(struct af903x_dev_ctx *ctx, int chip)
 {
int ret;
@@ -338,6 +401,43 @@
TUNER_FC0012,
 };
 
+int af903x_fc0011_reset(void *_ctx)
+{
+  

[PATCH 1/2] Fitipower fc0011 driver

2012-03-21 Thread Michael Büsch
This adds the Fitipower fc0011 tuner driver.

Note: The '#if 0' statements will be removed on the final submission.

Signed-off-by: Michael Buesch 

---

Index: linux-source-3.2/drivers/media/common/tuners/Kconfig
===
--- linux-source-3.2.orig/drivers/media/common/tuners/Kconfig   2012-03-21 
15:43:23.658828874 +0100
+++ linux-source-3.2/drivers/media/common/tuners/Kconfig2012-03-21 
15:43:27.442894007 +0100
@@ -204,6 +204,13 @@
help
  NXP TDA18212 silicon tuner driver.
 
+config MEDIA_TUNER_FC0011
+   tristate "Fitipower FC0011 silicon tuner"
+   depends on VIDEO_MEDIA && I2C
+   default m if MEDIA_TUNER_CUSTOMISE
+   help
+ Fitipower FC0011 silicon tuner driver.
+
 config MEDIA_TUNER_FC0012
tristate "Fitipower FC0012 silicon tuner"
depends on VIDEO_MEDIA && I2C
Index: linux-source-3.2/drivers/media/common/tuners/Makefile
===
--- linux-source-3.2.orig/drivers/media/common/tuners/Makefile  2012-03-21 
15:43:23.658828874 +0100
+++ linux-source-3.2/drivers/media/common/tuners/Makefile   2012-03-21 
15:43:27.446894082 +0100
@@ -27,6 +27,7 @@
 obj-$(CONFIG_MEDIA_TUNER_MAX2165) += max2165.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18218) += tda18218.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18212) += tda18212.o
+obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o
 obj-$(CONFIG_MEDIA_TUNER_FC0012) += fc0012.o
 
 ccflags-y += -Idrivers/media/dvb/dvb-core
Index: linux-source-3.2/drivers/media/common/tuners/fc0011.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux-source-3.2/drivers/media/common/tuners/fc0011.c   2012-03-21 
15:52:28.048214689 +0100
@@ -0,0 +1,501 @@
+/*
+ * Fitipower FC0011 tuner driver
+ *
+ * Copyright (C) 2012 Michael Buesch 
+ *
+ * Derived from FC0012 tuner driver:
+ * Copyright (C) 2012 Hans-Frieder Vogt 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "fc0011.h"
+
+
+/* Tuner registers */
+enum {
+   FC11_REG_0,
+   FC11_REG_FA,/* FA */
+   FC11_REG_FP,/* FP */
+   FC11_REG_XINHI, /* XIN high 8 bit */
+   FC11_REG_XINLO, /* XIN low 8 bit */
+   FC11_REG_VCO,   /* VCO */
+   FC11_REG_VCOSEL,/* VCO select */
+   FC11_REG_7, /* Unknown tune reg 7 */
+   FC11_REG_8, /* Unknown tune reg 8 */
+   FC11_REG_9,
+   FC11_REG_10,/* Unknown tune reg 10 */
+   FC11_REG_11,/* Unknown tune reg 11 */
+   FC11_REG_12,
+   FC11_REG_RCCAL, /* RC calibrate */
+   FC11_REG_VCOCAL,/* VCO calibrate */
+   FC11_REG_15,
+   FC11_REG_16,/* Unknown tune reg 16 */
+   FC11_REG_17,
+
+   FC11_NR_REGS,   /* Number of registers */
+};
+
+enum FC11_REG_VCOSEL_bits {
+   FC11_VCOSEL_2   = 0x08, /* VCO select 2 */
+   FC11_VCOSEL_1   = 0x10, /* VCO select 1 */
+   FC11_VCOSEL_CLKOUT  = 0x20, /* Fix clock out */
+   FC11_VCOSEL_BW7M= 0x40, /* 7MHz bw */
+   FC11_VCOSEL_BW6M= 0x80, /* 6MHz bw */
+};
+
+enum FC11_REG_RCCAL_bits {
+   FC11_RCCAL_FORCE= 0x10, /* force */
+};
+
+enum FC11_REG_VCOCAL_bits {
+   FC11_VCOCAL_RUN = 0,/* VCO calibration run */
+   FC11_VCOCAL_VALUEMASK   = 0x3F, /* VCO calibration value mask */
+   FC11_VCOCAL_OK  = 0x40, /* VCO calibration Ok */
+   FC11_VCOCAL_RESET   = 0x80, /* VCO calibration reset */
+};
+
+
+struct fc0011_priv {
+   struct i2c_adapter *i2c;
+   u8 addr;
+
+   u32 frequency;
+   u32 bandwidth;
+
+   int (*tuner_reset)(void *data);
+   void *tuner_reset_data;
+};
+
+
+static int fc0011_writereg(struct fc0011_priv *priv, u8 reg, u8 val)
+{
+   u8 buf[2] = { reg, val };
+   struct i2c_msg msg = { .addr = priv->addr,
+   .flags = 0, .buf = buf, .len = 2 };
+
+   msleep(1);
+   if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
+   dev_err(&priv->i2c->dev,
+   "I2C write reg failed, reg: %02x, val: %02x\n",
+   reg, val);
+   return -EIO;
+   

[PATCH 0/2] Fitipower fc0011 support

2012-03-21 Thread Michael Büsch
This patchset adds support for the Fitipower fc0011 DVB tuner.

Version 2 of this patchset fixes several small bugs and adds
some descriptive register names.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH] v0.3 Support for tuner FC0012

2012-03-20 Thread Michael Büsch
On Tue, 20 Mar 2012 23:14:35 +0100
"Hans-Frieder Vogt"  wrote:

> +/*
> +   buf[0] is the first register address
> + */

Just for me to understand this:
How does this work? Does the hardware auto-increment the register address
automatically after each received byte? If so, we could probably document
that here in the comment.

> +static int fc0012_writeregs(struct fc0012_priv *priv, u8 *buf, int len)
> +{
> + struct i2c_msg msg = {
> + .addr = priv->addr, .flags = 0, .buf = buf, .len = len
> + };
> +
> + if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
> + err("I2C write regs failed, reg: %02x, val[0]: %02x",
> + buf[0], len > 1 ? buf[1] : 0);
> + return -EREMOTEIO;
> + }
> + return 0;
> +}

> +static int fc0012_set_params(struct dvb_frontend *fe)
> +{

> +
> + priv->frequency = freq;

I think this either needs a freq*1000, or priv->frequency=p->frequency.

> + priv->bandwidth = p->bandwidth_hz;
> +
> +error_out:
> + return ret;
> +}


> +static const struct dvb_tuner_ops fc0012_tuner_ops = {
> +.info = {
> +.name   = "Fitipower FC0012",
> +
> +.frequency_min  = 17000,
> +.frequency_max  = 86000,
> +.frequency_step = 0,
> +},
> +
> +.release   = fc0012_release,
> +
> +.init  = fc0012_init,
> + .sleep = fc0012_sleep,
> +
> +.set_params= fc0012_set_params,
> +
> +.get_frequency = fc0012_get_frequency,
> + .get_if_frequency = fc0012_get_if_frequency,
> + .get_bandwidth = fc0012_get_bandwidth,
> +};
> +
> +struct dvb_frontend * fc0012_attach(struct dvb_frontend *fe,
> +struct i2c_adapter *i2c, u8 i2c_address,
> + enum fc0012_xtal_freq xtal_freq)
> +{
> +struct fc0012_priv *priv = NULL;

Should use tab indention here and in the tuner_ops struct above.

> +
> +#ifndef _FC0012_H_
> +#define _FC0012_H_
> +
> +#include "dvb_frontend.h"
> +
> +enum fc0012_xtal_freq {
> +FC_XTAL_27_MHZ,  /* 2700 */
> +FC_XTAL_28_8_MHZ,/* 2880 */
> +FC_XTAL_36_MHZ,  /* 3600 */
> +};
> +
> +#if defined(CONFIG_MEDIA_TUNER_FC0012) || \
> +(defined(CONFIG_MEDIA_TUNER_FC0012_MODULE) && defined(MODULE))

Why check for defined(MODULE) here?

> +extern struct dvb_frontend *fc0012_attach(struct dvb_frontend *fe,
> + struct i2c_adapter *i2c,
> + u8 i2c_address,
> + enum fc0012_xtal_freq xtal_freq);
> +#else


> +#define LOG_PREFIX "fc0012"
> +
> +#define dprintk(var, level, args...) \
> + do { \
> + if ((var & level)) \
> + printk(args); \
> + } while (0)
> +
> +#define deb_info(args...) dprintk(fc0012_debug, 0x01, args)
> +
> +#undef err
> +#define err(f, arg...)  printk(KERN_ERR LOG_PREFIX": " f "\n" , ## arg)
> +#undef info
> +#define info(f, arg...) printk(KERN_INFOLOG_PREFIX": " f "\n" , ## arg)
> +#undef warn
> +#define warn(f, arg...) printk(KERN_WARNING LOG_PREFIX": " f "\n" , ## arg)


I think you should get rid of all these custom print helpers and use dev_err,
dev_info and friends. Those are more ideomatic.

> +struct fc0012_priv {
> +struct i2c_adapter *i2c;
> + u8 addr;
> + u8 xtal_freq;
> +
> +u32 frequency;
> + u32 bandwidth;
> +};

Here seems to be some whitespace mixing. tab indention vs. space indention.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Add fc0011 tuner support (was: [PATCH 2/3] Basic AF9035/AF9033 driver)

2012-03-20 Thread Michael Büsch
Okay, here we go. These patches apply on top of the latest
af903x by Hans-Frieder Vogt. This adds support for the fc0011
tuner, which is used on a "cabstone" stick. (Its USB-id is already
in af903x's list).

I did some _very_ basic testing on this stuff and it basically seems to
work more or less.

Signed-off-by: Michael Buesch 

---

Two patches for review and testing follow (inline for commenting and attached).
(Yes, the '#if 0' sections are going to be removed. I'm currently
testing on a 3.2 kernel, so I need them for now.)

---

Index: linux-source-3.2/drivers/media/common/tuners/Kconfig
===
--- linux-source-3.2.orig/drivers/media/common/tuners/Kconfig   2012-03-20 
20:34:00.938801738 +0100
+++ linux-source-3.2/drivers/media/common/tuners/Kconfig2012-03-20 
20:34:00.986802601 +0100
@@ -204,6 +204,13 @@
help
  NXP TDA18212 silicon tuner driver.
 
+config MEDIA_TUNER_FC0011
+   tristate "Fitipower FC0011 silicon tuner"
+   depends on VIDEO_MEDIA && I2C
+   default m if MEDIA_TUNER_CUSTOMISE
+   help
+ Fitipower FC0011 silicon tuner driver.
+
 config MEDIA_TUNER_FC0012
tristate "Fitipower FC0012 silicon tuner"
depends on VIDEO_MEDIA && I2C
Index: linux-source-3.2/drivers/media/common/tuners/Makefile
===
--- linux-source-3.2.orig/drivers/media/common/tuners/Makefile  2012-03-20 
20:34:00.942801805 +0100
+++ linux-source-3.2/drivers/media/common/tuners/Makefile   2012-03-20 
20:34:00.986802601 +0100
@@ -27,6 +27,7 @@
 obj-$(CONFIG_MEDIA_TUNER_MAX2165) += max2165.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18218) += tda18218.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18212) += tda18212.o
+obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o
 obj-$(CONFIG_MEDIA_TUNER_FC0012) += fc0012.o
 
 ccflags-y += -Idrivers/media/dvb/dvb-core
Index: linux-source-3.2/drivers/media/common/tuners/fc0011.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux-source-3.2/drivers/media/common/tuners/fc0011.c   2012-03-20 
22:28:54.132458133 +0100
@@ -0,0 +1,386 @@
+/*
+ * Fitipower FC0011 tuner driver
+ *
+ * Copyright (C) 2012 Michael Buesch 
+ *
+ * Derived from FC0012 tuner driver:
+ * Copyright (C) 2012 Hans-Frieder Vogt 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "fc0011.h"
+
+
+struct fc0011_priv {
+struct i2c_adapter *i2c;
+   u8 addr;
+
+u32 frequency;
+   u32 bandwidth;
+};
+
+
+static int fc0011_writereg(struct fc0011_priv *priv, u8 reg, u8 val)
+{
+   u8 buf[2] = { reg, val };
+   struct i2c_msg msg = { .addr = priv->addr,
+   .flags = 0, .buf = buf, .len = 2 };
+
+   msleep(1);
+   if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
+   dev_err(&priv->i2c->dev,
+   "I2C write reg failed, reg: %02x, val: %02x\n",
+   reg, val);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int fc0011_readreg(struct fc0011_priv *priv, u8 reg, u8 *val)
+{
+   struct i2c_msg msg[2] = {
+   { .addr = priv->addr,
+ .flags = 0, .buf = ®, .len = 1 },
+   { .addr = priv->addr,
+ .flags = I2C_M_RD, .buf = val, .len = 1 },
+   };
+
+   if (i2c_transfer(priv->i2c, msg, 2) != 2) {
+   dev_err(&priv->i2c->dev,
+   "I2C read failed, reg: %02x\n", reg);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int fc0011_release(struct dvb_frontend *fe)
+{
+   kfree(fe->tuner_priv);
+   fe->tuner_priv = NULL;
+   return 0;
+}
+
+static int fc0011_init(struct dvb_frontend *fe)
+{
+   /* nothing to do here */
+   return 0;
+}
+
+static int fc0011_sleep(struct dvb_frontend *fe)
+{
+   /* nothing to do here */
+   return 0;
+}
+
+#if 0 //TODO 3.3
+static int fc0011_set_params(struct dvb_frontend *fe)
+#else
+static int fc0011_set_params(struct dvb_frontend *fe,
+struct dvb_frontend_parameters *params)
+#endif
+{
+struct fc0011_priv *priv = fe->tuner_priv;
+   int err;
+   unsigned int i;
+#if 0 //TODO 3.3
+   struct dtv_frontend_properties *p = &fe->d

Re: [PATCH 2/3] Basic AF9035/AF9033 driver

2012-03-20 Thread Michael Büsch
On Tue, 20 Mar 2012 17:49:51 +0100
Gianluca Gennari  wrote:

> Here it is:
> http://www.mail-archive.com/linux-media@vger.kernel.org/msg44169.html

Uh thanks. I must have been blinded by the AF903x_SRC driver. ;)

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH 2/3] Basic AF9035/AF9033 driver

2012-03-20 Thread Michael Büsch
On Tue, 20 Mar 2012 17:27:45 +0100
Gianluca Gennari  wrote:

> Hi Michael,
> 
> Il 20/03/2012 14:04, Michael Büsch ha scritto:
> > Thank you for working on a af903x driver.
> > 
> > I tried to test the driver on a debian 3.2 kernel, after applying a small 
> > fix:
> > It should be CONFIG_DVB_USB_AF903X here.
> 
> this issue is fixed in version "1.02" of the driver, posted by Hans a
> few days ago.

I can only find the post from Feb 22th, which includes this glitch.
Can you point me to the newer post in the list archives?

> > So I'm wondering how big the differences between the fc0011 and fc0012 are.
> > Can the 0011 be implemented in the 0012 driver, or does it require a 
> > separate driver?
> > Please give me a few hints, to I can work on implementing support for that 
> > tuner.
> 
> I have no idea about the real differences between the two tuner models,
> but here you can find an old "leaked" af9035 driver with support for
> several tuners, including fc0011 and fc0012:
> 
> https://bitbucket.org/voltagex/af9035/src
>
> (look under the "api" subdir for the tuners).

Yeah I know about that "thing". It makes my eyes bleed, though.

But the author of this document pointed me to this:
http://linuxtv.org/wiki/index.php/Fitipower
That seems pretty useful, in addition to the existing crap driver.

> The driver is not working with recent kernels, but probably you can
> extract the information needed to implement a proper kernel driver for
> fc0011, using the fc0012 driver written by Hans as a reference.

Yeah after looking at things it seems best to have a separate module.
I already started to put the boilerplate code together and I'm currently
putting the various device specific bits in place.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature


Re: [PATCH 2/3] Basic AF9035/AF9033 driver

2012-03-20 Thread Michael Büsch
Thank you for working on a af903x driver.

I tried to test the driver on a debian 3.2 kernel, after applying a small fix:

> diff -Nupr a/drivers/media/dvb/dvb-usb/Makefile 
> b/drivers/media/dvb/dvb-usb/Makefile
> --- a/drivers/media/dvb/dvb-usb/Makefile2012-01-22 02:53:17.0 
> +0100
> +++ b/drivers/media/dvb/dvb-usb/Makefile2012-02-20 23:22:38.385877784 
> +0100
> @@ -75,6 +75,9 @@ obj-$(CONFIG_DVB_USB_DTV5100) += dvb-usb
>  dvb-usb-af9015-objs = af9015.o
>  obj-$(CONFIG_DVB_USB_AF9015) += dvb-usb-af9015.o
>  
> +dvb-usb-af903x-objs = af903x-core.o af903x-devices.o af903x-fe.o 
> af903x-tuners.o
> +obj-$(DVB_USB_AF903X) += dvb-usb-af903x.o

It should be CONFIG_DVB_USB_AF903X here.

> +
>  dvb-usb-cinergyT2-objs = cinergyT2-core.o cinergyT2-fe.o
>  obj-$(CONFIG_DVB_USB_CINERGY_T2) += dvb-usb-cinergyT2.o


Unfortunately it turns out that my stick uses an older tuner:

[   91.396087] usb 1-1: new high-speed USB device number 4 using ehci_hcd
[   91.534709] usb 1-1: New USB device found, idVendor=15a4, idProduct=1001
[   91.534724] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   91.534735] usb 1-1: Product: AF9035A USB Device
[   91.534743] usb 1-1: Manufacturer: Afa Technologies Inc.
[   91.534752] usb 1-1: SerialNumber: AF010202071
[   91.537709] af903x: 1 Tuners of Type=0x28, Arch Mode=DCA, Remote=NEC
[   91.552954] dvb-usb: found a 'ITEtech USB2.0 DVB-T Recevier' in cold state, 
will try to load a firmware
[   91.565312] dvb-usb: downloading firmware from file 'dvb-usb-af9035-03.fw'
[   91.875659] af903x: device init ...
[   91.875671] af903x: requested tuner id 40 not enabled
[   91.875682] af903x: device_init Fail: -22

So I'm wondering how big the differences between the fc0011 and fc0012 are.
Can the 0011 be implemented in the 0012 driver, or does it require a separate 
driver?
Please give me a few hints, to I can work on implementing support for that 
tuner.

-- 
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E


signature.asc
Description: PGP signature