[PATCH v3 3/3] FC0012 tuner driver.

2012-05-06 Thread Thomas Mair
This driver is based on the driver written by Hans-Frieder Vogt. The
following modifications hav been made
- added callback for UHF/VFH band selection in fc0012_set_params
(needed by Cinergy T Stick Black)
- modified some parameters when initialiting the tuner (maybe the
initialization should be done by passing parameters to the init
functions to be usable with different demods)

Signed-off-by: Thomas Mair 
---
 drivers/media/common/tuners/fc0012-priv.h |   42 +++
 drivers/media/common/tuners/fc0012.c  |  398 +
 drivers/media/common/tuners/fc0012.h  |   60 +
 3 files changed, 500 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/common/tuners/fc0012-priv.h
 create mode 100644 drivers/media/common/tuners/fc0012.c
 create mode 100644 drivers/media/common/tuners/fc0012.h

diff --git a/drivers/media/common/tuners/fc0012-priv.h
b/drivers/media/common/tuners/fc0012-priv.h
new file mode 100644
index 000..c2c3c47
--- /dev/null
+++ b/drivers/media/common/tuners/fc0012-priv.h
@@ -0,0 +1,42 @@
+/*
+ * Fitipower FC0012 tuner driver - private includes
+ *
+ * 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.
+ */
+
+#ifndef _FC0012_PRIV_H_
+#define _FC0012_PRIV_H_
+
+#define LOG_PREFIX "fc0012"
+
+#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)
+
+struct fc0012_priv {
+   struct i2c_adapter *i2c;
+   u8 addr;
+   u8 xtal_freq;
+
+   u32 frequency;
+   u32 bandwidth;
+};
+
+#endif
diff --git a/drivers/media/common/tuners/fc0012.c
b/drivers/media/common/tuners/fc0012.c
new file mode 100644
index 000..5beae31
--- /dev/null
+++ b/drivers/media/common/tuners/fc0012.c
@@ -0,0 +1,398 @@
+/*
+ * Fitipower 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 "fc0012.h"
+#include "fc0012-priv.h"
+
+static int fc0012_writereg(struct fc0012_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) {
+   err("I2C write reg failed, reg: %02x, val: %02x", reg, val);
+   return -EREMOTEIO;
+   }
+   return 0;
+}
+
+static int fc0012_readreg(struct fc0012_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) {
+   err("I2C read failed, reg: %02x", reg);
+   return -EREMOTEIO;
+   }
+   return 0;
+}
+
+static int fc0012_release(struct dvb_frontend *fe)
+{
+   kfree(fe->tuner_priv);
+   fe->tuner_priv = NULL;
+   return 0;
+}
+
+static int fc0012_init(struct dvb_frontend *fe)
+{
+   struct fc0012_priv *priv = fe->tuner_priv;
+   int i, ret = 0;
+   unsigned char reg[] = {
+   0x00,   /* dummy reg. 0 */
+   0x05,   /* reg. 0x01 */
+   0x10,   /* reg. 0x02 */
+   0x00,   /* reg. 0x03 */
+   0x00,   /* reg. 0x04 */
+   0x0f,   /* reg. 0x05 CHECK: correct? */
+   /* changed for rtl2832 */
+   0x00,   /* reg. 0x06: divider 2, VCO slow */
+

Re: [PATCH v3 3/3] FC0012 tuner driver.

2012-05-06 Thread Thomas Mair
This driver is based on the driver written by Hans-Frieder Vogt. The following 
modifications hav been made
- added callback for UHF/VFH band selection in fc0012_set_params (needed by 
Cinergy T Stick Black)
- modified some parameters when initialiting the tuner (maybe the 
initialization should be done by passing parameters to the init functions to be 
usable with different demods)

Signed-off-by: Thomas Mair 
---
 drivers/media/common/tuners/fc0012-priv.h |   42 +++
 drivers/media/common/tuners/fc0012.c  |  398 +
 drivers/media/common/tuners/fc0012.h  |   60 +
 3 files changed, 500 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/common/tuners/fc0012-priv.h
 create mode 100644 drivers/media/common/tuners/fc0012.c
 create mode 100644 drivers/media/common/tuners/fc0012.h

diff --git a/drivers/media/common/tuners/fc0012-priv.h 
b/drivers/media/common/tuners/fc0012-priv.h
new file mode 100644
index 000..c2c3c47
--- /dev/null
+++ b/drivers/media/common/tuners/fc0012-priv.h
@@ -0,0 +1,42 @@
+/*
+ * Fitipower FC0012 tuner driver - private includes
+ *
+ * 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.
+ */
+
+#ifndef _FC0012_PRIV_H_
+#define _FC0012_PRIV_H_
+
+#define LOG_PREFIX "fc0012"
+
+#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)
+
+struct fc0012_priv {
+   struct i2c_adapter *i2c;
+   u8 addr;
+   u8 xtal_freq;
+
+   u32 frequency;
+   u32 bandwidth;
+};
+
+#endif
diff --git a/drivers/media/common/tuners/fc0012.c 
b/drivers/media/common/tuners/fc0012.c
new file mode 100644
index 000..5beae31
--- /dev/null
+++ b/drivers/media/common/tuners/fc0012.c
@@ -0,0 +1,398 @@
+/*
+ * Fitipower 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 "fc0012.h"
+#include "fc0012-priv.h"
+
+static int fc0012_writereg(struct fc0012_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) {
+   err("I2C write reg failed, reg: %02x, val: %02x", reg, val);
+   return -EREMOTEIO;
+   }
+   return 0;
+}
+
+static int fc0012_readreg(struct fc0012_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) {
+   err("I2C read failed, reg: %02x", reg);
+   return -EREMOTEIO;
+   }
+   return 0;
+}
+
+static int fc0012_release(struct dvb_frontend *fe)
+{
+   kfree(fe->tuner_priv);
+   fe->tuner_priv = NULL;
+   return 0;
+}
+
+static int fc0012_init(struct dvb_frontend *fe)
+{
+   struct fc0012_priv *priv = fe->tuner_priv;
+   int i, ret = 0;
+   unsigned char reg[] = {
+   0x00,   /* dummy reg. 0 */
+   0x05,   /* reg. 0x01 */
+   0x10,   /* reg. 0x02 */
+   0x00,   /* reg. 0x03 */
+   0x00,   /* reg. 0x04 */
+   0x0f,   /* reg. 0x05 CHECK: correct? */
+   /* changed for rtl2832 */
+   0x00,   /* reg. 0x06: divider 2, VCO slow */
+