Re: [PATCH 3/4] tc90522: add driver for Toshiba TC90522 quad demodulator

2014-08-17 Thread Akihiro TSUKADA
On 2014年08月16日 01:09, Mauro Carvalho Chehab wrote:
 +++ b/drivers/media/dvb-frontends/tc90522.c

 +static int tc90522s_get_frontend(struct dvb_frontend *fe)
 +{
.
 +c-delivery_system = SYS_ISDBS;
 +c-symbol_rate = 2886;
 
 Hmm... symbol rate is fixed? That looks weird on my eyes.

Though I may be totally wrong,
I set it to 28.86M because ARIB STD B20 (section 2.3) defines
the speed of the modulated carrier signal be 28.860Mbaud.

But carrier is splitted into 48 slots and
they are assigned to multiple TS's, which are modulated with
(one of or a combination of) either 8PSK or QPSK or BPSK. 
Dummy slots are included in the case of QPSK/BPSK.
The output TS is chosen by TS_ID.

Should I set c-symbol_rate to
   (# of slots assigned to the output TS)/48 * 28.86Mbaud
?

 +static int tc90522t_get_frontend(struct dvb_frontend *fe)
 +{
 +static const fe_transmit_mode_t tm_conv[] = {
 +TRANSMISSION_MODE_2K,
 +TRANSMISSION_MODE_4K,
 +TRANSMISSION_MODE_8K, 0
 
 Better to put the final 0 on a separate line, to be consistent.
 
 I would also move those tables out of get_frontend, as this improves
 readability.

Do those tables include generally other static const tables in other 
functions?
there are lots of small, function-scoped const tables which define register 
values
and just used in one function, like the following ones.

 +static int tc90522_set_frontend(struct dvb_frontend *fe)
 +{
 +static const struct reg_val reset_sat = { 0x03, 0x01 };
 +static const struct reg_val reset_ter = { 0x01, 0x40 };


 +state = fe-demodulator_priv;
 +
 +if (fe-ops.tuner_ops.set_params)
 +ret = fe-ops.tuner_ops.set_params(fe);
 
 Hmm... I'm not seeing any part of the driver parsing the ISDB
 parameters (except for the frequency).
(and TS_ID, layers).
As this demod looks into TMCC and adjusts lots of parameters automatically,
with preset defaults (for Japanese ISDB-S/T).
Thus the frequency is the minimum and sufficient parameter to demodulate.
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/4] tc90522: add driver for Toshiba TC90522 quad demodulator

2014-08-15 Thread Mauro Carvalho Chehab
Em Tue, 15 Jul 2014 00:43:46 +0900
tsk...@gmail.com escreveu:

 From: Akihiro Tsukada tsk...@gmail.com
 
 This patch adds driver for tc90522 demodulator chips.
 The chip contains 4 demod modules that run in parallel and are independently
 controllable via separate I2C addresses.
 Two of the modules are for ISDB-T and the rest for ISDB-S.
 It is used in earthsoft pt3 cards.
 
 Note that this driver does not init the chip,
 because the initilization sequence / register setting is not disclosed.
 Thus, the driver assumes that the chips are initilized externally
 by its parent board driver before fe-ops-init() are called.
 Earthsoft PT3 PCIe card, for example, contains the init sequence
 in its private memory and provides a command to trigger the sequence.
 
 Signed-off-by: Akihiro Tsukada tsk...@gmail.com
 ---
  drivers/media/dvb-frontends/Kconfig   |   8 +
  drivers/media/dvb-frontends/Makefile  |   1 +
  drivers/media/dvb-frontends/tc90522.c | 843 
 ++
  drivers/media/dvb-frontends/tc90522.h |  63 +++
  4 files changed, 915 insertions(+)
  create mode 100644 drivers/media/dvb-frontends/tc90522.c
  create mode 100644 drivers/media/dvb-frontends/tc90522.h
 
 diff --git a/drivers/media/dvb-frontends/Kconfig 
 b/drivers/media/dvb-frontends/Kconfig
 index 1469d44..0244571 100644
 --- a/drivers/media/dvb-frontends/Kconfig
 +++ b/drivers/media/dvb-frontends/Kconfig
 @@ -625,6 +625,14 @@ config DVB_MB86A20S
 A driver for Fujitsu mb86a20s ISDB-T/ISDB-Tsb demodulator.
 Say Y when you want to support this frontend.
  
 +config DVB_TC90522
 + tristate Toshiba TC90522
 + depends on DVB_CORE  I2C
 + default m if !MEDIA_SUBDRV_AUTOSELECT
 + help
 +   A Toshiba TC90522 2xISDB-T + 2xISDB-S demodulator.
 +   Say Y when you want to support this frontend.
 +
  comment Digital terrestrial only tuners/PLL
   depends on DVB_CORE
  
 diff --git a/drivers/media/dvb-frontends/Makefile 
 b/drivers/media/dvb-frontends/Makefile
 index dda0bee..5da7a25 100644
 --- a/drivers/media/dvb-frontends/Makefile
 +++ b/drivers/media/dvb-frontends/Makefile
 @@ -106,4 +106,5 @@ obj-$(CONFIG_DVB_RTL2830) += rtl2830.o
  obj-$(CONFIG_DVB_RTL2832) += rtl2832.o
  obj-$(CONFIG_DVB_M88RS2000) += m88rs2000.o
  obj-$(CONFIG_DVB_AF9033) += af9033.o
 +obj-$(CONFIG_DVB_TC90522) += tc90522.o
  
 diff --git a/drivers/media/dvb-frontends/tc90522.c 
 b/drivers/media/dvb-frontends/tc90522.c
 new file mode 100644
 index 000..6a9ecfa
 --- /dev/null
 +++ b/drivers/media/dvb-frontends/tc90522.c
 @@ -0,0 +1,843 @@
 +/*
 + * Toshiba TC90522 Demodulator
 + *
 + * Copyright (C) 2014 Akihiro Tsukada tsk...@gmail.com
 + *
 + * 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 version 2.
 + *
 + *
 + * 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.
 + */
 +
 +#include linux/kernel.h
 +#include linux/dvb/frontend.h
 +#include dvb_math.h
 +#include tc90522.h
 +
 +#define TC90522_I2C_THRU_REG 0xfe
 +
 +#define TC90522_MODULE_IDX(addr) (((u8)(addr)  0x02U)  1)
 +
 +enum tc90522_tuning_status {
 + STATUS_IDLE,
 + STATUS_SET_FREQ,
 + STATUS_CHECK_TUNER,
 + STATUS_CHECK_DEMOD,
 + STATUS_TRACK,
 +};
 +
 +struct tc90522_state {
 + struct dvb_frontend dvb_fe;
 +
 + struct tc90522_config cfg;
 + struct i2c_adapter *i2c;
 + struct i2c_adapter tuner_i2c;
 + enum tc90522_tuning_status tuning_status;
 + int retry_count;
 +
 + bool lna;
 +};
 +
 +struct reg_val {
 + u8 reg;
 + u8 val;
 +};
 +
 +
 +static int
 +reg_write(struct tc90522_state *state, const struct reg_val *regs, int num)
 +{
 + int i, ret;
 + struct i2c_msg msg;
 +
 + ret = 0;
 + msg.addr = state-cfg.addr;
 + msg.flags = 0;
 + msg.len = 2;
 + for (i = 0; i  num; i++) {
 + msg.buf = (u8 *)regs[i];
 + ret = i2c_transfer(state-i2c, msg, 1);
 + if (ret  0)
 + break;
 + }
 + return ret;
 +}
 +
 +static int reg_read(struct tc90522_state *state, u8 reg, u8 *val, u8 len)
 +{
 + struct i2c_msg msgs[2] = {
 + {
 + .addr = state-cfg.addr,
 + .flags = 0,
 + .buf = reg,
 + .len = 1,
 + },
 + {
 + .addr = state-cfg.addr,
 + .flags = I2C_M_RD,
 + .buf = val,
 + .len = len,
 + },
 + };
 +
 + return i2c_transfer(state-i2c, msgs, ARRAY_SIZE(msgs));
 +}
 +
 +static int enable_lna(struct dvb_frontend *fe, bool on)
 +{
 + struct tc90522_state *state;
 +
 + state = 

[PATCH 3/4] tc90522: add driver for Toshiba TC90522 quad demodulator

2014-07-14 Thread tskd08
From: Akihiro Tsukada tsk...@gmail.com

This patch adds driver for tc90522 demodulator chips.
The chip contains 4 demod modules that run in parallel and are independently
controllable via separate I2C addresses.
Two of the modules are for ISDB-T and the rest for ISDB-S.
It is used in earthsoft pt3 cards.

Note that this driver does not init the chip,
because the initilization sequence / register setting is not disclosed.
Thus, the driver assumes that the chips are initilized externally
by its parent board driver before fe-ops-init() are called.
Earthsoft PT3 PCIe card, for example, contains the init sequence
in its private memory and provides a command to trigger the sequence.

Signed-off-by: Akihiro Tsukada tsk...@gmail.com
---
 drivers/media/dvb-frontends/Kconfig   |   8 +
 drivers/media/dvb-frontends/Makefile  |   1 +
 drivers/media/dvb-frontends/tc90522.c | 843 ++
 drivers/media/dvb-frontends/tc90522.h |  63 +++
 4 files changed, 915 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/tc90522.c
 create mode 100644 drivers/media/dvb-frontends/tc90522.h

diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index 1469d44..0244571 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -625,6 +625,14 @@ config DVB_MB86A20S
  A driver for Fujitsu mb86a20s ISDB-T/ISDB-Tsb demodulator.
  Say Y when you want to support this frontend.
 
+config DVB_TC90522
+   tristate Toshiba TC90522
+   depends on DVB_CORE  I2C
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ A Toshiba TC90522 2xISDB-T + 2xISDB-S demodulator.
+ Say Y when you want to support this frontend.
+
 comment Digital terrestrial only tuners/PLL
depends on DVB_CORE
 
diff --git a/drivers/media/dvb-frontends/Makefile 
b/drivers/media/dvb-frontends/Makefile
index dda0bee..5da7a25 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -106,4 +106,5 @@ obj-$(CONFIG_DVB_RTL2830) += rtl2830.o
 obj-$(CONFIG_DVB_RTL2832) += rtl2832.o
 obj-$(CONFIG_DVB_M88RS2000) += m88rs2000.o
 obj-$(CONFIG_DVB_AF9033) += af9033.o
+obj-$(CONFIG_DVB_TC90522) += tc90522.o
 
diff --git a/drivers/media/dvb-frontends/tc90522.c 
b/drivers/media/dvb-frontends/tc90522.c
new file mode 100644
index 000..6a9ecfa
--- /dev/null
+++ b/drivers/media/dvb-frontends/tc90522.c
@@ -0,0 +1,843 @@
+/*
+ * Toshiba TC90522 Demodulator
+ *
+ * Copyright (C) 2014 Akihiro Tsukada tsk...@gmail.com
+ *
+ * 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 version 2.
+ *
+ *
+ * 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.
+ */
+
+#include linux/kernel.h
+#include linux/dvb/frontend.h
+#include dvb_math.h
+#include tc90522.h
+
+#define TC90522_I2C_THRU_REG 0xfe
+
+#define TC90522_MODULE_IDX(addr) (((u8)(addr)  0x02U)  1)
+
+enum tc90522_tuning_status {
+   STATUS_IDLE,
+   STATUS_SET_FREQ,
+   STATUS_CHECK_TUNER,
+   STATUS_CHECK_DEMOD,
+   STATUS_TRACK,
+};
+
+struct tc90522_state {
+   struct dvb_frontend dvb_fe;
+
+   struct tc90522_config cfg;
+   struct i2c_adapter *i2c;
+   struct i2c_adapter tuner_i2c;
+   enum tc90522_tuning_status tuning_status;
+   int retry_count;
+
+   bool lna;
+};
+
+struct reg_val {
+   u8 reg;
+   u8 val;
+};
+
+
+static int
+reg_write(struct tc90522_state *state, const struct reg_val *regs, int num)
+{
+   int i, ret;
+   struct i2c_msg msg;
+
+   ret = 0;
+   msg.addr = state-cfg.addr;
+   msg.flags = 0;
+   msg.len = 2;
+   for (i = 0; i  num; i++) {
+   msg.buf = (u8 *)regs[i];
+   ret = i2c_transfer(state-i2c, msg, 1);
+   if (ret  0)
+   break;
+   }
+   return ret;
+}
+
+static int reg_read(struct tc90522_state *state, u8 reg, u8 *val, u8 len)
+{
+   struct i2c_msg msgs[2] = {
+   {
+   .addr = state-cfg.addr,
+   .flags = 0,
+   .buf = reg,
+   .len = 1,
+   },
+   {
+   .addr = state-cfg.addr,
+   .flags = I2C_M_RD,
+   .buf = val,
+   .len = len,
+   },
+   };
+
+   return i2c_transfer(state-i2c, msgs, ARRAY_SIZE(msgs));
+}
+
+static int enable_lna(struct dvb_frontend *fe, bool on)
+{
+   struct tc90522_state *state;
+
+   state = fe-demodulator_priv;
+   /* delegate to the parent board */
+   if (fe-callback)
+   fe-callback(fe,