Re: [PATCH 1/3] FCI FC2580 silicon tuner driver

2012-09-09 Thread Oliver Schinagl
According to the 'spec sheet' [1] The min frequency goes as low as 
170MHz (opposed to the 172MHz in this patch). Maximum frequency 'should' 
be only 860MHz though. Don't know if the L Band needs to be included 
into this min/max thing, as that one runs from 1350 - 1750MHz :)



[1] http://www.digitimes.com.tw/PDF/DTF960807/2007080702.pdf

On 09/09/12 04:07, Antti Palosaari wrote:

Signed-off-by: Antti Palosaari
---
  drivers/media/tuners/Kconfig   |   7 +
  drivers/media/tuners/Makefile  |   1 +
  drivers/media/tuners/fc2580.c  | 524 +
  drivers/media/tuners/fc2580.h  |  52 
  drivers/media/tuners/fc2580_priv.h | 134 ++
  5 files changed, 718 insertions(+)
  create mode 100644 drivers/media/tuners/fc2580.c
  create mode 100644 drivers/media/tuners/fc2580.h
  create mode 100644 drivers/media/tuners/fc2580_priv.h

diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig
index f9e299c..622375e 100644
--- a/drivers/media/tuners/Kconfig
+++ b/drivers/media/tuners/Kconfig
@@ -229,6 +229,13 @@ config MEDIA_TUNER_E4000
help
  Elonics E4000 silicon tuner driver.

+config MEDIA_TUNER_FC2580
+   tristate "FCI FC2580 silicon tuner"
+   depends on MEDIA_SUPPORT&&  I2C
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ FCI FC2580 silicon tuner driver.
+
  config MEDIA_TUNER_TUA9001
tristate "Infineon TUA 9001 silicon tuner"
depends on MEDIA_SUPPORT&&  I2C
diff --git a/drivers/media/tuners/Makefile b/drivers/media/tuners/Makefile
index 9f7b2c2..5e569b1 100644
--- a/drivers/media/tuners/Makefile
+++ b/drivers/media/tuners/Makefile
@@ -29,6 +29,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_E4000) += e4000.o
+obj-$(CONFIG_MEDIA_TUNER_FC2580) += fc2580.o
  obj-$(CONFIG_MEDIA_TUNER_TUA9001) += tua9001.o
  obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o
  obj-$(CONFIG_MEDIA_TUNER_FC0012) += fc0012.o
diff --git a/drivers/media/tuners/fc2580.c b/drivers/media/tuners/fc2580.c
new file mode 100644
index 000..afc0491
--- /dev/null
+++ b/drivers/media/tuners/fc2580.c
@@ -0,0 +1,524 @@
+/*
+ * FCI FC2580 silicon tuner driver
+ *
+ * Copyright (C) 2012 Antti Palosaari
+ *
+ *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.,
+ *51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "fc2580_priv.h"
+
+/*
+ * TODO:
+ * I2C write and read works only for one single register. Multiple registers
+ * could not be accessed using normal register address auto-increment.
+ * There could be (very likely) register to change that behavior
+ *
+ * Due to that limitation functions:
+ *   fc2580_wr_regs()
+ *   fc2580_rd_regs()
+ * could not be used for accessing more than one register at once.
+ *
+ * TODO:
+ * Currently it blind writes bunch of static registers from the
+ * fc2580_freq_regs_lut[] when fc2580_set_params() is called. Add some
+ * logic to reduce unneeded register writes.
+ * There is also don't-care registers, initialized with value 0xff, and those
+ * are also written to the chip currently (yes, not wise).
+ */
+
+/* write multiple registers */
+static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
+{
+   int ret;
+   u8 buf[1 + len];
+   struct i2c_msg msg[1] = {
+   {
+   .addr = priv->cfg->i2c_addr,
+   .flags = 0,
+   .len = sizeof(buf),
+   .buf = buf,
+   }
+   };
+
+   buf[0] = reg;
+   memcpy(&buf[1], val, len);
+
+   ret = i2c_transfer(priv->i2c, msg, 1);
+   if (ret == 1) {
+   ret = 0;
+   } else {
+   dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d reg=%02x " \
+   "len=%d\n", KBUILD_MODNAME, ret, reg, len);
+   ret = -EREMOTEIO;
+   }
+   return ret;
+}
+
+/* read multiple registers */
+static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
+{
+   int ret;
+   u8 buf[len];
+   struct i2c_msg msg[2] = {
+   {
+   .addr = priv->cfg->i2c_addr,
+   .flags = 0,
+  

Re: [PATCH 1/3] FCI FC2580 silicon tuner driver

2012-09-09 Thread Antti Palosaari

Hello
it does not make any sense. I just put those limits as those are DVB-T 
band lower and upper limits. Current limit values are payload from the 
history and does not suit very well newer designs. Anyhow, there should 
be some limits defined as frontend needs those to report / limit 
userspace apps.


regards
Antti

On 09/09/2012 05:33 PM, Oliver Schinagl wrote:

According to the 'spec sheet' [1] The min frequency goes as low as
170MHz (opposed to the 172MHz in this patch). Maximum frequency 'should'
be only 860MHz though. Don't know if the L Band needs to be included
into this min/max thing, as that one runs from 1350 - 1750MHz :)


[1] http://www.digitimes.com.tw/PDF/DTF960807/2007080702.pdf

On 09/09/12 04:07, Antti Palosaari wrote:

Signed-off-by: Antti Palosaari
---
  drivers/media/tuners/Kconfig   |   7 +
  drivers/media/tuners/Makefile  |   1 +
  drivers/media/tuners/fc2580.c  | 524
+
  drivers/media/tuners/fc2580.h  |  52 
  drivers/media/tuners/fc2580_priv.h | 134 ++
  5 files changed, 718 insertions(+)
  create mode 100644 drivers/media/tuners/fc2580.c
  create mode 100644 drivers/media/tuners/fc2580.h
  create mode 100644 drivers/media/tuners/fc2580_priv.h

diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig
index f9e299c..622375e 100644
--- a/drivers/media/tuners/Kconfig
+++ b/drivers/media/tuners/Kconfig
@@ -229,6 +229,13 @@ config MEDIA_TUNER_E4000
  help
Elonics E4000 silicon tuner driver.

+config MEDIA_TUNER_FC2580
+tristate "FCI FC2580 silicon tuner"
+depends on MEDIA_SUPPORT&&  I2C
+default m if !MEDIA_SUBDRV_AUTOSELECT
+help
+  FCI FC2580 silicon tuner driver.
+
  config MEDIA_TUNER_TUA9001
  tristate "Infineon TUA 9001 silicon tuner"
  depends on MEDIA_SUPPORT&&  I2C
diff --git a/drivers/media/tuners/Makefile
b/drivers/media/tuners/Makefile
index 9f7b2c2..5e569b1 100644
--- a/drivers/media/tuners/Makefile
+++ b/drivers/media/tuners/Makefile
@@ -29,6 +29,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_E4000) += e4000.o
+obj-$(CONFIG_MEDIA_TUNER_FC2580) += fc2580.o
  obj-$(CONFIG_MEDIA_TUNER_TUA9001) += tua9001.o
  obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o
  obj-$(CONFIG_MEDIA_TUNER_FC0012) += fc0012.o
diff --git a/drivers/media/tuners/fc2580.c
b/drivers/media/tuners/fc2580.c
new file mode 100644
index 000..afc0491
--- /dev/null
+++ b/drivers/media/tuners/fc2580.c
@@ -0,0 +1,524 @@
+/*
+ * FCI FC2580 silicon tuner driver
+ *
+ * Copyright (C) 2012 Antti Palosaari
+ *
+ *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.,
+ *51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "fc2580_priv.h"
+
+/*
+ * TODO:
+ * I2C write and read works only for one single register. Multiple
registers
+ * could not be accessed using normal register address auto-increment.
+ * There could be (very likely) register to change that behavior
+ *
+ * Due to that limitation functions:
+ *   fc2580_wr_regs()
+ *   fc2580_rd_regs()
+ * could not be used for accessing more than one register at once.
+ *
+ * TODO:
+ * Currently it blind writes bunch of static registers from the
+ * fc2580_freq_regs_lut[] when fc2580_set_params() is called. Add some
+ * logic to reduce unneeded register writes.
+ * There is also don't-care registers, initialized with value 0xff,
and those
+ * are also written to the chip currently (yes, not wise).
+ */
+
+/* write multiple registers */
+static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, u8 *val,
int len)
+{
+int ret;
+u8 buf[1 + len];
+struct i2c_msg msg[1] = {
+{
+.addr = priv->cfg->i2c_addr,
+.flags = 0,
+.len = sizeof(buf),
+.buf = buf,
+}
+};
+
+buf[0] = reg;
+memcpy(&buf[1], val, len);
+
+ret = i2c_transfer(priv->i2c, msg, 1);
+if (ret == 1) {
+ret = 0;
+} else {
+dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d reg=%02x " \
+"len=%d\n", KBUILD_MODNAME, ret, reg, len);
+ret = -EREMOTEIO;
+}
+return ret;
+}
+
+/* read multiple registers */
+static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, u8

[PATCH 1/3] FCI FC2580 silicon tuner driver

2012-09-08 Thread Antti Palosaari
Signed-off-by: Antti Palosaari 
---
 drivers/media/tuners/Kconfig   |   7 +
 drivers/media/tuners/Makefile  |   1 +
 drivers/media/tuners/fc2580.c  | 524 +
 drivers/media/tuners/fc2580.h  |  52 
 drivers/media/tuners/fc2580_priv.h | 134 ++
 5 files changed, 718 insertions(+)
 create mode 100644 drivers/media/tuners/fc2580.c
 create mode 100644 drivers/media/tuners/fc2580.h
 create mode 100644 drivers/media/tuners/fc2580_priv.h

diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig
index f9e299c..622375e 100644
--- a/drivers/media/tuners/Kconfig
+++ b/drivers/media/tuners/Kconfig
@@ -229,6 +229,13 @@ config MEDIA_TUNER_E4000
help
  Elonics E4000 silicon tuner driver.
 
+config MEDIA_TUNER_FC2580
+   tristate "FCI FC2580 silicon tuner"
+   depends on MEDIA_SUPPORT && I2C
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ FCI FC2580 silicon tuner driver.
+
 config MEDIA_TUNER_TUA9001
tristate "Infineon TUA 9001 silicon tuner"
depends on MEDIA_SUPPORT && I2C
diff --git a/drivers/media/tuners/Makefile b/drivers/media/tuners/Makefile
index 9f7b2c2..5e569b1 100644
--- a/drivers/media/tuners/Makefile
+++ b/drivers/media/tuners/Makefile
@@ -29,6 +29,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_E4000) += e4000.o
+obj-$(CONFIG_MEDIA_TUNER_FC2580) += fc2580.o
 obj-$(CONFIG_MEDIA_TUNER_TUA9001) += tua9001.o
 obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o
 obj-$(CONFIG_MEDIA_TUNER_FC0012) += fc0012.o
diff --git a/drivers/media/tuners/fc2580.c b/drivers/media/tuners/fc2580.c
new file mode 100644
index 000..afc0491
--- /dev/null
+++ b/drivers/media/tuners/fc2580.c
@@ -0,0 +1,524 @@
+/*
+ * FCI FC2580 silicon tuner driver
+ *
+ * Copyright (C) 2012 Antti Palosaari 
+ *
+ *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.,
+ *51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "fc2580_priv.h"
+
+/*
+ * TODO:
+ * I2C write and read works only for one single register. Multiple registers
+ * could not be accessed using normal register address auto-increment.
+ * There could be (very likely) register to change that behavior
+ *
+ * Due to that limitation functions:
+ *   fc2580_wr_regs()
+ *   fc2580_rd_regs()
+ * could not be used for accessing more than one register at once.
+ *
+ * TODO:
+ * Currently it blind writes bunch of static registers from the
+ * fc2580_freq_regs_lut[] when fc2580_set_params() is called. Add some
+ * logic to reduce unneeded register writes.
+ * There is also don't-care registers, initialized with value 0xff, and those
+ * are also written to the chip currently (yes, not wise).
+ */
+
+/* write multiple registers */
+static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
+{
+   int ret;
+   u8 buf[1 + len];
+   struct i2c_msg msg[1] = {
+   {
+   .addr = priv->cfg->i2c_addr,
+   .flags = 0,
+   .len = sizeof(buf),
+   .buf = buf,
+   }
+   };
+
+   buf[0] = reg;
+   memcpy(&buf[1], val, len);
+
+   ret = i2c_transfer(priv->i2c, msg, 1);
+   if (ret == 1) {
+   ret = 0;
+   } else {
+   dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d reg=%02x " \
+   "len=%d\n", KBUILD_MODNAME, ret, reg, len);
+   ret = -EREMOTEIO;
+   }
+   return ret;
+}
+
+/* read multiple registers */
+static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
+{
+   int ret;
+   u8 buf[len];
+   struct i2c_msg msg[2] = {
+   {
+   .addr = priv->cfg->i2c_addr,
+   .flags = 0,
+   .len = 1,
+   .buf = ®,
+   }, {
+   .addr = priv->cfg->i2c_addr,
+   .flags = I2C_M_RD,
+   .len = sizeof(buf),
+   .buf = buf,
+   }
+   };
+
+   ret = i2c_transfer(priv->i2c, msg, 2);
+   if (ret == 2) {
+   memcpy(val, buf, len);
+