[REVIEW PATCH 47/86] msi3101: add default FMT and ADC frequency

2014-02-09 Thread Antti Palosaari
Default ADC to smallest/worst possible configuration on probe.
Also enhance some FMT debug logs.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 0a2bb12..061c705 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -1339,7 +1339,7 @@ static int msi3101_enum_fmt_sdr_cap(struct file *file, 
void *priv,
struct v4l2_fmtdesc *f)
 {
struct msi3101_state *s = video_drvdata(file);
-   dev_dbg(s-udev-dev, %s:\n, __func__);
+   dev_dbg(s-udev-dev, %s: index=%d\n, __func__, f-index);
 
if (f-index = NUM_FORMATS)
return -EINVAL;
@@ -1354,7 +1354,8 @@ static int msi3101_g_fmt_sdr_cap(struct file *file, void 
*priv,
struct v4l2_format *f)
 {
struct msi3101_state *s = video_drvdata(file);
-   dev_dbg(s-udev-dev, %s:\n, __func__);
+   dev_dbg(s-udev-dev, %s: pixelformat fourcc %4.4s\n, __func__,
+   (char *)s-pixelformat);
 
f-fmt.sdr.pixelformat = s-pixelformat;
 
@@ -1631,8 +1632,9 @@ static int msi3101_probe(struct usb_interface *intf,
mutex_init(s-vb_queue_lock);
spin_lock_init(s-queued_bufs_lock);
INIT_LIST_HEAD(s-queued_bufs);
-
s-udev = udev;
+   s-f_adc = bands_adc[0].rangelow;
+   s-pixelformat = V4L2_PIX_FMT_SDR_U8;
 
/* Init videobuf2 queue structure */
s-vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE;
-- 
1.8.5.3

--
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


[REVIEW PATCH 49/86] DocBook: document RF tuner gain controls

2014-02-09 Thread Antti Palosaari
Add documentation for LNA, mixer and IF gain controls. These
controls are RF tuner specific.

Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
Acked-by: Hans Verkuil hans.verk...@cisco.com
---
 Documentation/DocBook/media/v4l/controls.xml | 91 
 1 file changed, 91 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/controls.xml 
b/Documentation/DocBook/media/v4l/controls.xml
index a5a3188..0145341 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -4971,4 +4971,95 @@ defines possible values for de-emphasis. Here they 
are:/entry
   /table
 
   /section
+
+section id=rf-tuner-controls
+  titleRF Tuner Control Reference/title
+
+  paraThe RF Tuner (RF_TUNER) class includes controls for common features
+of devices having RF tuner./para
+
+  table pgwide=1 frame=none id=rf-tuner-control-id
+titleRF_TUNER Control IDs/title
+
+tgroup cols=4
+  colspec colname=c1 colwidth=1* /
+  colspec colname=c2 colwidth=6* /
+  colspec colname=c3 colwidth=2* /
+  colspec colname=c4 colwidth=6* /
+  spanspec namest=c1 nameend=c2 spanname=id /
+  spanspec namest=c2 nameend=c4 spanname=descr /
+  thead
+row
+  entry spanname=id align=leftID/entry
+  entry align=leftType/entry
+/row
+row rowsep=1
+  entry spanname=descr align=leftDescription/entry
+/row
+  /thead
+  tbody valign=top
+rowentry/entry/row
+row
+  entry 
spanname=idconstantV4L2_CID_RF_TUNER_CLASS/constantnbsp;/entry
+  entryclass/entry
+/rowrowentry spanname=descrThe RF_TUNER class
+descriptor. Calling VIDIOC-QUERYCTRL; for this control will return a
+description of this control class./entry
+/row
+row
+  entry 
spanname=idconstantV4L2_CID_LNA_GAIN_AUTO/constantnbsp;/entry
+  entryboolean/entry
+/row
+row
+  entry spanname=descrEnables/disables LNA automatic gain 
control (AGC)/entry
+/row
+row
+  entry 
spanname=idconstantV4L2_CID_MIXER_GAIN_AUTO/constantnbsp;/entry
+  entryboolean/entry
+/row
+row
+  entry spanname=descrEnables/disables mixer automatic gain 
control (AGC)/entry
+/row
+row
+  entry 
spanname=idconstantV4L2_CID_IF_GAIN_AUTO/constantnbsp;/entry
+  entryboolean/entry
+/row
+row
+  entry spanname=descrEnables/disables IF automatic gain 
control (AGC)/entry
+/row
+row
+  entry 
spanname=idconstantV4L2_CID_LNA_GAIN/constantnbsp;/entry
+  entryinteger/entry
+/row
+row
+  entry spanname=descrLNA (low noise amplifier) gain is first
+gain stage on the RF tuner signal path. It is located very close to tuner
+antenna input. Used when constantV4L2_CID_LNA_GAIN_AUTO/constant is not 
set.
+The range and step are driver-specific./entry
+/row
+row
+  entry 
spanname=idconstantV4L2_CID_MIXER_GAIN/constantnbsp;/entry
+  entryinteger/entry
+/row
+row
+  entry spanname=descrMixer gain is second gain stage on the RF
+tuner signal path. It is located inside mixer block, where RF signal is
+down-converted by the mixer. Used when 
constantV4L2_CID_MIXER_GAIN_AUTO/constant
+is not set. The range and step are driver-specific./entry
+/row
+row
+  entry 
spanname=idconstantV4L2_CID_IF_GAIN/constantnbsp;/entry
+  entryinteger/entry
+/row
+row
+  entry spanname=descrIF gain is last gain stage on the RF 
tuner
+signal path. It is located on output of RF tuner. It controls signal level of
+intermediate frequency output or baseband output. Used when
+constantV4L2_CID_IF_GAIN_AUTO/constant is not set. The range and step are
+driver-specific./entry
+/row
+  /tbody
+/tgroup
+  /table
+/section
 /section
-- 
1.8.5.3

--
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


[REVIEW PATCH 40/86] e4000: add manual gain controls

2014-02-09 Thread Antti Palosaari
Add gain control for LNA, Mixer and IF. Expose controls via DVB
frontend .set_config callback.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/e4000.c  | 68 +++
 drivers/media/tuners/e4000.h  |  6 
 drivers/media/tuners/e4000_priv.h | 63 
 3 files changed, 137 insertions(+)

diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index 0153169..651de11 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -385,6 +385,73 @@ static int e4000_get_if_frequency(struct dvb_frontend *fe, 
u32 *frequency)
return 0;
 }
 
+static int e4000_set_config(struct dvb_frontend *fe, void *priv_cfg)
+{
+   struct e4000_priv *priv = fe-tuner_priv;
+   struct e4000_ctrl *ctrl = priv_cfg;
+   int ret;
+   u8 buf[2];
+   u8 u8tmp;
+   dev_dbg(priv-client-dev, %s: lna=%d mixer=%d if=%d\n, __func__,
+   ctrl-lna_gain, ctrl-mixer_gain, ctrl-if_gain);
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 1);
+
+   if (ctrl-lna_gain == INT_MIN  ctrl-if_gain == INT_MIN)
+   u8tmp = 0x17;
+   else if (ctrl-lna_gain == INT_MIN)
+   u8tmp = 0x19;
+   else if (ctrl-if_gain == INT_MIN)
+   u8tmp = 0x16;
+   else
+   u8tmp = 0x10;
+
+   ret = e4000_wr_reg(priv, 0x1a, u8tmp);
+   if (ret)
+   goto err;
+
+   if (ctrl-mixer_gain == INT_MIN)
+   u8tmp = 0x15;
+   else
+   u8tmp = 0x14;
+
+   ret = e4000_wr_reg(priv, 0x20, u8tmp);
+   if (ret)
+   goto err;
+
+   if (ctrl-lna_gain != INT_MIN) {
+   ret = e4000_wr_reg(priv, 0x14, ctrl-lna_gain);
+   if (ret)
+   goto err;
+   }
+
+   if (ctrl-mixer_gain != INT_MIN) {
+   ret = e4000_wr_reg(priv, 0x15, ctrl-mixer_gain);
+   if (ret)
+   goto err;
+   }
+
+   if (ctrl-if_gain != INT_MIN) {
+   buf[0] = e4000_if_gain_lut[ctrl-if_gain].reg16_val;
+   buf[1] = e4000_if_gain_lut[ctrl-if_gain].reg17_val;
+   ret = e4000_wr_regs(priv, 0x16, buf, 2);
+   if (ret)
+   goto err;
+   }
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 0);
+
+   return 0;
+err:
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 0);
+
+   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
+   return ret;
+}
+
 static const struct dvb_tuner_ops e4000_tuner_ops = {
.info = {
.name   = Elonics E4000,
@@ -395,6 +462,7 @@ static const struct dvb_tuner_ops e4000_tuner_ops = {
.init = e4000_init,
.sleep = e4000_sleep,
.set_params = e4000_set_params,
+   .set_config = e4000_set_config,
 
.get_if_frequency = e4000_get_if_frequency,
 };
diff --git a/drivers/media/tuners/e4000.h b/drivers/media/tuners/e4000.h
index e74b8b2..d95c472 100644
--- a/drivers/media/tuners/e4000.h
+++ b/drivers/media/tuners/e4000.h
@@ -40,4 +40,10 @@ struct e4000_config {
u32 clock;
 };
 
+struct e4000_ctrl {
+   int lna_gain;
+   int mixer_gain;
+   int if_gain;
+};
+
 #endif
diff --git a/drivers/media/tuners/e4000_priv.h 
b/drivers/media/tuners/e4000_priv.h
index 8f45a30..a75a383 100644
--- a/drivers/media/tuners/e4000_priv.h
+++ b/drivers/media/tuners/e4000_priv.h
@@ -145,4 +145,67 @@ static const struct e4000_if_filter e4000_if_filter_lut[] 
= {
{ 0x, 0x00, 0x20 },
 };
 
+struct e4000_if_gain {
+   u8 reg16_val;
+   u8 reg17_val;
+};
+
+static const struct e4000_if_gain e4000_if_gain_lut[] = {
+   {0x00, 0x00},
+   {0x20, 0x00},
+   {0x40, 0x00},
+   {0x02, 0x00},
+   {0x22, 0x00},
+   {0x42, 0x00},
+   {0x04, 0x00},
+   {0x24, 0x00},
+   {0x44, 0x00},
+   {0x01, 0x00},
+   {0x21, 0x00},
+   {0x41, 0x00},
+   {0x03, 0x00},
+   {0x23, 0x00},
+   {0x43, 0x00},
+   {0x05, 0x00},
+   {0x25, 0x00},
+   {0x45, 0x00},
+   {0x07, 0x00},
+   {0x27, 0x00},
+   {0x47, 0x00},
+   {0x0f, 0x00},
+   {0x2f, 0x00},
+   {0x4f, 0x00},
+   {0x17, 0x00},
+   {0x37, 0x00},
+   {0x57, 0x00},
+   {0x1f, 0x00},
+   {0x3f, 0x00},
+   {0x5f, 0x00},
+   {0x1f, 0x01},
+   {0x3f, 0x01},
+   {0x5f, 0x01},
+   {0x1f, 0x02},
+   {0x3f, 0x02},
+   {0x5f, 0x02},
+   {0x1f, 0x03},
+   {0x3f, 0x03},
+   {0x5f, 0x03},
+   {0x1f, 0x04},
+   {0x3f, 0x04},
+   {0x5f, 0x04},
+   {0x1f, 0x0c},
+   {0x3f, 0x0c},
+   {0x5f, 0x0c},
+   {0x1f, 0x14},
+   {0x3f, 0x14},
+   {0x5f, 0x14},
+   {0x1f, 0x1c},
+   {0x3f, 0x1c},
+   {0x5f, 0x1c},
+   {0x1f, 0x24},
+   {0x3f, 0x24},
+   

[REVIEW PATCH 41/86] rtl2832_sdr: expose E4000 gain controls to user space

2014-02-09 Thread Antti Palosaari
Provide E4000 gain controls to userspace via V4L2 API. LNA, Mixer
and IF gain controls are offered, each one both manual and automode.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/Makefile  |   1 +
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 115 +--
 2 files changed, 88 insertions(+), 28 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/Makefile 
b/drivers/staging/media/rtl2832u_sdr/Makefile
index 1009276..7e00a0d 100644
--- a/drivers/staging/media/rtl2832u_sdr/Makefile
+++ b/drivers/staging/media/rtl2832u_sdr/Makefile
@@ -2,4 +2,5 @@ obj-$(CONFIG_DVB_RTL2832_SDR) += rtl2832_sdr.o
 
 ccflags-y += -Idrivers/media/dvb-core
 ccflags-y += -Idrivers/media/dvb-frontends
+ccflags-y += -Idrivers/media/tuners
 ccflags-y += -Idrivers/media/usb/dvb-usb-v2
diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index fccb16f..ee72233 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -25,6 +25,7 @@
 #include dvb_frontend.h
 #include rtl2832_sdr.h
 #include dvb_usb.h
+#include e4000.h
 
 #include media/v4l2-device.h
 #include media/v4l2-ioctl.h
@@ -147,9 +148,14 @@ struct rtl2832_sdr_state {
u32 pixelformat;
 
/* Controls */
-   struct v4l2_ctrl_handler ctrl_handler;
+   struct v4l2_ctrl_handler hdl;
+   struct v4l2_ctrl *lna_gain_auto;
+   struct v4l2_ctrl *lna_gain;
+   struct v4l2_ctrl *mixer_gain_auto;
+   struct v4l2_ctrl *mixer_gain;
+   struct v4l2_ctrl *if_gain_auto;
+   struct v4l2_ctrl *if_gain;
struct v4l2_ctrl *ctrl_tuner_bw;
-   struct v4l2_ctrl *ctrl_tuner_gain;
 
/* for sample rate calc */
unsigned int sample;
@@ -917,10 +923,49 @@ err:
return;
 };
 
+static int rtl2832_sdr_set_gain_e4000(struct rtl2832_sdr_state *s)
+{
+   int ret;
+   struct dvb_frontend *fe = s-fe;
+   struct e4000_ctrl ctrl;
+   dev_dbg(s-udev-dev, %s: lna=%d mixer=%d if=%d\n, __func__,
+   s-lna_gain-val, s-mixer_gain-val, s-if_gain-val);
+
+   ctrl.lna_gain = s-lna_gain_auto-val ? INT_MIN : s-lna_gain-val;
+   ctrl.mixer_gain = s-mixer_gain_auto-val ? INT_MIN : 
s-mixer_gain-val;
+   ctrl.if_gain = s-if_gain_auto-val ? INT_MIN : s-if_gain-val;
+
+   if (fe-ops.tuner_ops.set_config) {
+   ret = fe-ops.tuner_ops.set_config(fe, ctrl);
+   if (ret)
+   goto err;
+   }
+
+   return 0;
+err:
+   dev_dbg(s-udev-dev, %s: failed %d\n, __func__, ret);
+   return ret;
+};
+
+static int rtl2832_sdr_set_gain(struct rtl2832_sdr_state *s)
+{
+   int ret;
+
+   switch (s-cfg-tuner) {
+   case RTL2832_TUNER_E4000:
+   ret = rtl2832_sdr_set_gain_e4000(s);
+   break;
+   default:
+   ret = 0;
+   }
+   return ret;
+}
+
 static int rtl2832_sdr_set_tuner(struct rtl2832_sdr_state *s)
 {
struct dvb_frontend *fe = s-fe;
struct dtv_frontend_properties *c = fe-dtv_property_cache;
+   int ret;
 
/*
 * tuner RF (Hz)
@@ -932,14 +977,9 @@ static int rtl2832_sdr_set_tuner(struct rtl2832_sdr_state 
*s)
 */
unsigned int bandwidth = s-ctrl_tuner_bw-val;
 
-   /*
-* gain (dB)
-*/
-   int gain = s-ctrl_tuner_gain-val;
-
dev_dbg(s-udev-dev,
-   %s: f_rf=%u bandwidth=%d gain=%d\n,
-   __func__, f_rf, bandwidth, gain);
+   %s: f_rf=%u bandwidth=%d\n,
+   __func__, f_rf, bandwidth);
 
if (f_rf == 0)
return 0;
@@ -961,6 +1001,8 @@ static int rtl2832_sdr_set_tuner(struct rtl2832_sdr_state 
*s)
if (fe-ops.tuner_ops.set_params)
fe-ops.tuner_ops.set_params(fe);
 
+   ret = rtl2832_sdr_set_gain(s);
+
return 0;
 };
 
@@ -1290,7 +1332,7 @@ static int rtl2832_sdr_s_ctrl(struct v4l2_ctrl *ctrl)
 {
struct rtl2832_sdr_state *s =
container_of(ctrl-handler, struct rtl2832_sdr_state,
-   ctrl_handler);
+   hdl);
int ret;
dev_dbg(s-udev-dev,
%s: id=%d name=%s val=%d min=%d max=%d step=%d\n,
@@ -1302,6 +1344,15 @@ static int rtl2832_sdr_s_ctrl(struct v4l2_ctrl *ctrl)
case RTL2832_SDR_CID_TUNER_GAIN:
ret = rtl2832_sdr_set_tuner(s);
break;
+   case  V4L2_CID_LNA_GAIN_AUTO:
+   case  V4L2_CID_LNA_GAIN:
+   case  V4L2_CID_MIXER_GAIN_AUTO:
+   case  V4L2_CID_MIXER_GAIN:
+   case  V4L2_CID_IF_GAIN_AUTO:
+   case  V4L2_CID_IF_GAIN:
+   dev_dbg(s-udev-dev, %s: GAIN IOCTL\n, __func__);
+   ret = rtl2832_sdr_set_gain(s);
+   break;
default:
ret = -EINVAL;
 

[REVIEW PATCH 43/86] rtl2832_sdr: expose R820 gain controls to user space

2014-02-09 Thread Antti Palosaari
Provide R820 gain controls to userspace via V4L2 API. LNA, Mixer
and IF gain controls are offered, each one both manual and automode.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 41 
 1 file changed, 41 insertions(+)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index ee72233..69fc996 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -26,6 +26,7 @@
 #include rtl2832_sdr.h
 #include dvb_usb.h
 #include e4000.h
+#include r820t.h
 
 #include media/v4l2-device.h
 #include media/v4l2-ioctl.h
@@ -947,6 +948,30 @@ err:
return ret;
 };
 
+static int rtl2832_sdr_set_gain_r820t(struct rtl2832_sdr_state *s)
+{
+   int ret;
+   struct dvb_frontend *fe = s-fe;
+   struct r820t_ctrl ctrl;
+   dev_dbg(s-udev-dev, %s: lna=%d mixer=%d if=%d\n, __func__,
+   s-lna_gain-val, s-mixer_gain-val, s-if_gain-val);
+
+   ctrl.lna_gain = s-lna_gain_auto-val ? INT_MIN : s-lna_gain-val;
+   ctrl.mixer_gain = s-mixer_gain_auto-val ? INT_MIN : 
s-mixer_gain-val;
+   ctrl.if_gain = s-if_gain_auto-val ? INT_MIN : s-if_gain-val;
+
+   if (fe-ops.tuner_ops.set_config) {
+   ret = fe-ops.tuner_ops.set_config(fe, ctrl);
+   if (ret)
+   goto err;
+   }
+
+   return 0;
+err:
+   dev_dbg(s-udev-dev, %s: failed %d\n, __func__, ret);
+   return ret;
+};
+
 static int rtl2832_sdr_set_gain(struct rtl2832_sdr_state *s)
 {
int ret;
@@ -955,6 +980,9 @@ static int rtl2832_sdr_set_gain(struct rtl2832_sdr_state *s)
case RTL2832_TUNER_E4000:
ret = rtl2832_sdr_set_gain_e4000(s);
break;
+   case RTL2832_TUNER_R820T:
+   ret = rtl2832_sdr_set_gain_r820t(s);
+   break;
default:
ret = 0;
}
@@ -1442,6 +1470,19 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
s-if_gain = v4l2_ctrl_new_std(s-hdl, ops, V4L2_CID_IF_GAIN, 
0, 54, 1, 0);
v4l2_ctrl_auto_cluster(2, s-if_gain_auto, 0, false);
break;
+   case RTL2832_TUNER_R820T:
+   v4l2_ctrl_handler_init(s-hdl, 7);
+   s-lna_gain_auto = v4l2_ctrl_new_std(s-hdl, ops, 
V4L2_CID_LNA_GAIN_AUTO, 0, 1, 1, 1);
+   s-lna_gain = v4l2_ctrl_new_std(s-hdl, ops, 
V4L2_CID_LNA_GAIN, 0, 15, 1, 6);
+   v4l2_ctrl_auto_cluster(2, s-lna_gain_auto, 0, false);
+   s-mixer_gain_auto = v4l2_ctrl_new_std(s-hdl, ops, 
V4L2_CID_MIXER_GAIN_AUTO, 0, 1, 1, 1);
+   s-mixer_gain = v4l2_ctrl_new_std(s-hdl, ops, 
V4L2_CID_MIXER_GAIN, 0, 15, 1, 5);
+   v4l2_ctrl_auto_cluster(2, s-mixer_gain_auto, 0, false);
+   s-if_gain_auto = v4l2_ctrl_new_std(s-hdl, ops, 
V4L2_CID_IF_GAIN_AUTO, 0, 1, 1, 1);
+   s-if_gain = v4l2_ctrl_new_std(s-hdl, ops, V4L2_CID_IF_GAIN, 
0, 15, 1, 4);
+   v4l2_ctrl_auto_cluster(2, s-if_gain_auto, 0, false);
+   s-ctrl_tuner_bw = v4l2_ctrl_new_custom(s-hdl, 
ctrl_tuner_bw, NULL);
+   break;
default:
v4l2_ctrl_handler_init(s-hdl, 1);
s-ctrl_tuner_bw = v4l2_ctrl_new_custom(s-hdl, 
ctrl_tuner_bw, NULL);
-- 
1.8.5.3

--
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


[REVIEW PATCH 45/86] msi3101: fix device caps to advertise SDR receiver

2014-02-09 Thread Antti Palosaari
Advertise device as a SDR receiver, not video. After that libv4l
accepts opening device.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index e8dfcac..0a2bb12 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -843,7 +843,7 @@ static int msi3101_querycap(struct file *file, void *fh,
strlcpy(cap-driver, KBUILD_MODNAME, sizeof(cap-driver));
strlcpy(cap-card, s-vdev.name, sizeof(cap-card));
usb_make_path(s-udev, cap-bus_info, sizeof(cap-bus_info));
-   cap-device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
+   cap-device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_STREAMING |
V4L2_CAP_READWRITE | V4L2_CAP_TUNER;
cap-capabilities = cap-device_caps | V4L2_CAP_DEVICE_CAPS;
return 0;
-- 
1.8.5.3

--
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


[REVIEW PATCH 09/86] rtl28xxu: constify demod config structs

2014-02-09 Thread Antti Palosaari
Optimize a little bit from data to text.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index ec6ab0f..c0e651a 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -514,7 +514,7 @@ err:
return ret;
 }
 
-static struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = {
+static const struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = {
.i2c_addr = 0x10, /* 0x20 */
.xtal = 2880,
.ts_mode = 0,
@@ -525,7 +525,7 @@ static struct rtl2830_config rtl28xxu_rtl2830_mt2060_config 
= {
 
 };
 
-static struct rtl2830_config rtl28xxu_rtl2830_qt1010_config = {
+static const struct rtl2830_config rtl28xxu_rtl2830_qt1010_config = {
.i2c_addr = 0x10, /* 0x20 */
.xtal = 2880,
.ts_mode = 0,
@@ -535,7 +535,7 @@ static struct rtl2830_config rtl28xxu_rtl2830_qt1010_config 
= {
.agc_targ_val = 0x2d,
 };
 
-static struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = {
+static const struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = {
.i2c_addr = 0x10, /* 0x20 */
.xtal = 2880,
.ts_mode = 0,
@@ -549,7 +549,7 @@ static int rtl2831u_frontend_attach(struct dvb_usb_adapter 
*adap)
 {
struct dvb_usb_device *d = adap_to_d(adap);
struct rtl28xxu_priv *priv = d_to_priv(d);
-   struct rtl2830_config *rtl2830_config;
+   const struct rtl2830_config *rtl2830_config;
int ret;
 
dev_dbg(d-udev-dev, %s:\n, __func__);
@@ -584,33 +584,33 @@ err:
return ret;
 }
 
-static struct rtl2832_config rtl28xxu_rtl2832_fc0012_config = {
+static const struct rtl2832_config rtl28xxu_rtl2832_fc0012_config = {
.i2c_addr = 0x10, /* 0x20 */
.xtal = 2880,
.if_dvbt = 0,
.tuner = TUNER_RTL2832_FC0012
 };
 
-static struct rtl2832_config rtl28xxu_rtl2832_fc0013_config = {
+static const struct rtl2832_config rtl28xxu_rtl2832_fc0013_config = {
.i2c_addr = 0x10, /* 0x20 */
.xtal = 2880,
.if_dvbt = 0,
.tuner = TUNER_RTL2832_FC0013
 };
 
-static struct rtl2832_config rtl28xxu_rtl2832_tua9001_config = {
+static const struct rtl2832_config rtl28xxu_rtl2832_tua9001_config = {
.i2c_addr = 0x10, /* 0x20 */
.xtal = 2880,
.tuner = TUNER_RTL2832_TUA9001,
 };
 
-static struct rtl2832_config rtl28xxu_rtl2832_e4000_config = {
+static const struct rtl2832_config rtl28xxu_rtl2832_e4000_config = {
.i2c_addr = 0x10, /* 0x20 */
.xtal = 2880,
.tuner = TUNER_RTL2832_E4000,
 };
 
-static struct rtl2832_config rtl28xxu_rtl2832_r820t_config = {
+static const struct rtl2832_config rtl28xxu_rtl2832_r820t_config = {
.i2c_addr = 0x10,
.xtal = 2880,
.tuner = TUNER_RTL2832_R820T,
@@ -734,7 +734,7 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter 
*adap)
int ret;
struct dvb_usb_device *d = adap_to_d(adap);
struct rtl28xxu_priv *priv = d_to_priv(d);
-   struct rtl2832_config *rtl2832_config;
+   const struct rtl2832_config *rtl2832_config;
 
dev_dbg(d-udev-dev, %s:\n, __func__);
 
-- 
1.8.5.3

--
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


[REVIEW PATCH 12/86] rtl2832_sdr: pixel format for SDR

2014-02-09 Thread Antti Palosaari
These are used for converting / streaming I/Q data from SDR.
* unsigned 8-bit

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 2c84654..d3db859 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -49,6 +49,8 @@
 #define RTL2832_SDR_CID_TUNER_IF((V4L2_CID_USER_BASE | 0xf000) + 
12)
 #define RTL2832_SDR_CID_TUNER_GAIN  ((V4L2_CID_USER_BASE | 0xf000) + 
13)
 
+#define V4L2_PIX_FMT_SDR_U8 v4l2_fourcc('D', 'U', '0', '8') /* unsigned 
8-bit */
+
 #define MAX_BULK_BUFS(8)
 #define BULK_BUFFER_SIZE (8 * 512)
 
-- 
1.8.5.3

--
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


[REVIEW PATCH 10/86] rtl2832: remove unused if_dvbt config parameter

2014-02-09 Thread Antti Palosaari
All used tuners has get_if_frequency() callback and that parameter
is not needed and will not needed as all upcoming tuner drivers
should implement get_if_frequency().

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/dvb-frontends/rtl2832.c   | 6 --
 drivers/media/dvb-frontends/rtl2832.h   | 7 ---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 2 --
 3 files changed, 15 deletions(-)

diff --git a/drivers/media/dvb-frontends/rtl2832.c 
b/drivers/media/dvb-frontends/rtl2832.c
index ff73da9..61d4ecb 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -514,12 +514,6 @@ static int rtl2832_init(struct dvb_frontend *fe)
goto err;
}
 
-   if (!fe-ops.tuner_ops.get_if_frequency) {
-   ret = rtl2832_set_if(fe, priv-cfg.if_dvbt);
-   if (ret)
-   goto err;
-   }
-
/*
 * r820t NIM code does a software reset here at the demod -
 * may not be needed, as there's already a software reset at 
set_params()
diff --git a/drivers/media/dvb-frontends/rtl2832.h 
b/drivers/media/dvb-frontends/rtl2832.h
index 2cfbb6a..e543081 100644
--- a/drivers/media/dvb-frontends/rtl2832.h
+++ b/drivers/media/dvb-frontends/rtl2832.h
@@ -38,13 +38,6 @@ struct rtl2832_config {
u32 xtal;
 
/*
-* IFs for all used modes.
-* Hz
-* 457, 4571429, 3600, 36125000, 3617, 4400
-*/
-   u32 if_dvbt;
-
-   /*
 * tuner
 * XXX: This must be keep sync with dvb_usb_rtl28xxu demod driver.
 */
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index c0e651a..6a5eb0f 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -587,14 +587,12 @@ err:
 static const struct rtl2832_config rtl28xxu_rtl2832_fc0012_config = {
.i2c_addr = 0x10, /* 0x20 */
.xtal = 2880,
-   .if_dvbt = 0,
.tuner = TUNER_RTL2832_FC0012
 };
 
 static const struct rtl2832_config rtl28xxu_rtl2832_fc0013_config = {
.i2c_addr = 0x10, /* 0x20 */
.xtal = 2880,
-   .if_dvbt = 0,
.tuner = TUNER_RTL2832_FC0013
 };
 
-- 
1.8.5.3

--
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


[REVIEW PATCH 39/86] e4000: convert DVB tuner to I2C driver model

2014-02-09 Thread Antti Palosaari
Driver conversion from proprietary DVB tuner model to more
general I2C driver model.

Cc: Jean Delvare kh...@linux-fr.org
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/e4000.c| 115 
 drivers/media/tuners/e4000.h|  21 ++
 drivers/media/tuners/e4000_priv.h   |   5 +-
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c |  41 +---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.h |   1 +
 5 files changed, 111 insertions(+), 72 deletions(-)

diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index 40c1da7..0153169 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -31,7 +31,7 @@ static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 
*val, int len)
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[1] = {
{
-   .addr = priv-cfg-i2c_addr,
+   .addr = priv-client-addr,
.flags = 0,
.len = 1 + len,
.buf = buf,
@@ -39,7 +39,7 @@ static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 
*val, int len)
};
 
if (1 + len  sizeof(buf)) {
-   dev_warn(priv-i2c-dev,
+   dev_warn(priv-client-dev,
 %s: i2c wr reg=%04x: len=%d is too big!\n,
 KBUILD_MODNAME, reg, len);
return -EINVAL;
@@ -48,11 +48,11 @@ static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, 
u8 *val, int len)
buf[0] = reg;
memcpy(buf[1], val, len);
 
-   ret = i2c_transfer(priv-i2c, msg, 1);
+   ret = i2c_transfer(priv-client-adapter, msg, 1);
if (ret == 1) {
ret = 0;
} else {
-   dev_warn(priv-i2c-dev,
+   dev_warn(priv-client-dev,
%s: i2c wr failed=%d reg=%02x len=%d\n,
KBUILD_MODNAME, ret, reg, len);
ret = -EREMOTEIO;
@@ -67,12 +67,12 @@ static int e4000_rd_regs(struct e4000_priv *priv, u8 reg, 
u8 *val, int len)
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[2] = {
{
-   .addr = priv-cfg-i2c_addr,
+   .addr = priv-client-addr,
.flags = 0,
.len = 1,
.buf = reg,
}, {
-   .addr = priv-cfg-i2c_addr,
+   .addr = priv-client-addr,
.flags = I2C_M_RD,
.len = len,
.buf = buf,
@@ -80,18 +80,18 @@ static int e4000_rd_regs(struct e4000_priv *priv, u8 reg, 
u8 *val, int len)
};
 
if (len  sizeof(buf)) {
-   dev_warn(priv-i2c-dev,
+   dev_warn(priv-client-dev,
 %s: i2c rd reg=%04x: len=%d is too big!\n,
 KBUILD_MODNAME, reg, len);
return -EINVAL;
}
 
-   ret = i2c_transfer(priv-i2c, msg, 2);
+   ret = i2c_transfer(priv-client-adapter, msg, 2);
if (ret == 2) {
memcpy(val, buf, len);
ret = 0;
} else {
-   dev_warn(priv-i2c-dev,
+   dev_warn(priv-client-dev,
%s: i2c rd failed=%d reg=%02x len=%d\n,
KBUILD_MODNAME, ret, reg, len);
ret = -EREMOTEIO;
@@ -117,7 +117,7 @@ static int e4000_init(struct dvb_frontend *fe)
struct e4000_priv *priv = fe-tuner_priv;
int ret;
 
-   dev_dbg(priv-i2c-dev, %s:\n, __func__);
+   dev_dbg(priv-client-dev, %s:\n, __func__);
 
if (fe-ops.i2c_gate_ctrl)
fe-ops.i2c_gate_ctrl(fe, 1);
@@ -186,7 +186,7 @@ err:
if (fe-ops.i2c_gate_ctrl)
fe-ops.i2c_gate_ctrl(fe, 0);
 
-   dev_dbg(priv-i2c-dev, %s: failed=%d\n, __func__, ret);
+   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
return ret;
 }
 
@@ -195,7 +195,7 @@ static int e4000_sleep(struct dvb_frontend *fe)
struct e4000_priv *priv = fe-tuner_priv;
int ret;
 
-   dev_dbg(priv-i2c-dev, %s:\n, __func__);
+   dev_dbg(priv-client-dev, %s:\n, __func__);
 
if (fe-ops.i2c_gate_ctrl)
fe-ops.i2c_gate_ctrl(fe, 1);
@@ -212,7 +212,7 @@ err:
if (fe-ops.i2c_gate_ctrl)
fe-ops.i2c_gate_ctrl(fe, 0);
 
-   dev_dbg(priv-i2c-dev, %s: failed=%d\n, __func__, ret);
+   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
return ret;
 }
 
@@ -224,7 +224,7 @@ static int e4000_set_params(struct dvb_frontend *fe)
unsigned int f_vco;
u8 buf[5], i_data[4], q_data[4];
 
-   dev_dbg(priv-i2c-dev,
+   dev_dbg(priv-client-dev,
%s: delivery_system=%d frequency=%d bandwidth_hz=%d\n,

[REVIEW PATCH 48/86] msi3101: sleep USB ADC and tuner when streaming is stopped

2014-02-09 Thread Antti Palosaari
Put USB IF / ADC and RF tuner to sleep when device is not streaming.
It uses around 115 mA power from USB when active, which drops to
32 mA on idle after that patch.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 061c705..0606941 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -977,8 +977,8 @@ static int msi3101_set_usb_adc(struct msi3101_state *s)
 * Synthesizer config is just a educated guess...
 *
 * [7:0]   0x03, register address
-* [8] 1, always
-* [9] ?
+* [8] 1, power control
+* [9] ?, power control
 * [12:10] output divider
 * [13]0 ?
 * [14]0 ?
@@ -1321,6 +1321,12 @@ static int msi3101_stop_streaming(struct vb2_queue *vq)
msleep(20);
msi3101_ctrl_msg(s, CMD_STOP_STREAMING, 0);
 
+   /* sleep USB IF / ADC */
+   msi3101_ctrl_msg(s, CMD_WREG, 0x0103);
+
+   /* sleep tuner */
+   msi3101_tuner_write(s, 0x00);
+
mutex_unlock(s-v4l2_lock);
 
return 0;
-- 
1.8.5.3

--
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


[REVIEW PATCH 08/86] rtl2832_sdr: initial support for FC0013 tuner

2014-02-09 Thread Antti Palosaari
Use tuner via internal DVB API.
It is about same tuner than FC0012 and uses just same settings.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index c088957..2c84654 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -753,7 +753,8 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
ret = rtl2832_sdr_wr_regs(s, 0x104, \xcc, 1);
ret = rtl2832_sdr_wr_regs(s, 0x105, \xbe, 1);
ret = rtl2832_sdr_wr_regs(s, 0x1c8, \x14, 1);
-   } else if (s-cfg-tuner == RTL2832_TUNER_FC0012) {
+   } else if (s-cfg-tuner == RTL2832_TUNER_FC0012 ||
+   s-cfg-tuner == RTL2832_TUNER_FC0013) {
ret = rtl2832_sdr_wr_regs(s, 0x103, \x5a, 1);
ret = rtl2832_sdr_wr_regs(s, 0x1c7, \x2c, 1);
ret = rtl2832_sdr_wr_regs(s, 0x104, \xcc, 1);
@@ -788,7 +789,8 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
ret = rtl2832_sdr_wr_regs(s, 0x019, \x21, 1);
ret = rtl2832_sdr_wr_regs(s, 0x116, \x00\x00, 2);
ret = rtl2832_sdr_wr_regs(s, 0x118, \x00, 1);
-   } else if (s-cfg-tuner == RTL2832_TUNER_FC0012) {
+   } else if (s-cfg-tuner == RTL2832_TUNER_FC0012 ||
+   s-cfg-tuner == RTL2832_TUNER_FC0013) {
ret = rtl2832_sdr_wr_regs(s, 0x011, \xe9\xbf, 2);
ret = rtl2832_sdr_wr_regs(s, 0x1e5, \xf0, 1);
ret = rtl2832_sdr_wr_regs(s, 0x1d9, \x00, 1);
-- 
1.8.5.3

--
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


[REVIEW PATCH 35/86] msi3101: clamp ADC and RF to valid range

2014-02-09 Thread Antti Palosaari
Clamp both sampling frequency and RF frequency to valid range to
meet V4L2 API spec. It is caller responsibility to check valid ranges
using VIDIOC_ENUM_FREQ_BANDS IOCTL.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index ba37fce..2b812fe 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -1779,17 +1779,26 @@ static int msi3101_s_frequency(struct file *file, void 
*priv,
const struct v4l2_frequency *f)
 {
struct msi3101_state *s = video_drvdata(file);
-   int ret;
+   int ret, band;
dev_dbg(s-udev-dev, %s: tuner=%d type=%d frequency=%u\n,
__func__, f-tuner, f-type, f-frequency);
 
if (f-tuner == 0) {
-   s-f_adc = f-frequency;
+   s-f_adc = clamp_t(unsigned int, f-frequency,
+   bands_adc[0].rangelow,
+   bands_adc[0].rangehigh);
dev_dbg(s-udev-dev, %s: ADC frequency=%u Hz\n,
__func__, s-f_adc);
ret = msi3101_set_usb_adc(s);
} else if (f-tuner == 1) {
-   s-f_tuner = f-frequency;
+   #define BAND_RF_0 ((bands_rf[0].rangehigh + 
bands_rf[1].rangelow) / 2)
+   if (f-frequency  BAND_RF_0)
+   band = 0;
+   else
+   band = 1;
+   s-f_tuner = clamp_t(unsigned int, f-frequency,
+   bands_rf[band].rangelow,
+   bands_rf[band].rangehigh);
dev_dbg(s-udev-dev, %s: RF frequency=%u Hz\n,
__func__, f-frequency);
ret = msi3101_set_tuner(s);
-- 
1.8.5.3

--
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


[REVIEW PATCH 38/86] msi3101: use standard V4L gain controls

2014-02-09 Thread Antti Palosaari
Use LNA, Mixer and IF gain controls offered by V4L API.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 433 
 1 file changed, 56 insertions(+), 377 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index e6b7cba..e8dfcac 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -34,317 +34,6 @@
 #include linux/usb.h
 #include media/videobuf2-vmalloc.h
 
-struct msi3101_gain {
-   u8 tot:7;
-   u8 baseband:6;
-   bool lna:1;
-   bool mixer:1;
-};
-
-/* 60 – 120 MHz band, lna 24dB, mixer 19dB */
-static const struct msi3101_gain msi3101_gain_lut_120[] = {
-   {  0,  0,  0,  0},
-   {  1,  1,  0,  0},
-   {  2,  2,  0,  0},
-   {  3,  3,  0,  0},
-   {  4,  4,  0,  0},
-   {  5,  5,  0,  0},
-   {  6,  6,  0,  0},
-   {  7,  7,  0,  0},
-   {  8,  8,  0,  0},
-   {  9,  9,  0,  0},
-   { 10, 10,  0,  0},
-   { 11, 11,  0,  0},
-   { 12, 12,  0,  0},
-   { 13, 13,  0,  0},
-   { 14, 14,  0,  0},
-   { 15, 15,  0,  0},
-   { 16, 16,  0,  0},
-   { 17, 17,  0,  0},
-   { 18, 18,  0,  0},
-   { 19, 19,  0,  0},
-   { 20, 20,  0,  0},
-   { 21, 21,  0,  0},
-   { 22, 22,  0,  0},
-   { 23, 23,  0,  0},
-   { 24, 24,  0,  0},
-   { 25, 25,  0,  0},
-   { 26, 26,  0,  0},
-   { 27, 27,  0,  0},
-   { 28, 28,  0,  0},
-   { 29,  5,  1,  0},
-   { 30,  6,  1,  0},
-   { 31,  7,  1,  0},
-   { 32,  8,  1,  0},
-   { 33,  9,  1,  0},
-   { 34, 10,  1,  0},
-   { 35, 11,  1,  0},
-   { 36, 12,  1,  0},
-   { 37, 13,  1,  0},
-   { 38, 14,  1,  0},
-   { 39, 15,  1,  0},
-   { 40, 16,  1,  0},
-   { 41, 17,  1,  0},
-   { 42, 18,  1,  0},
-   { 43, 19,  1,  0},
-   { 44, 20,  1,  0},
-   { 45, 21,  1,  0},
-   { 46, 22,  1,  0},
-   { 47, 23,  1,  0},
-   { 48, 24,  1,  0},
-   { 49, 25,  1,  0},
-   { 50, 26,  1,  0},
-   { 51, 27,  1,  0},
-   { 52, 28,  1,  0},
-   { 53, 29,  1,  0},
-   { 54, 30,  1,  0},
-   { 55, 31,  1,  0},
-   { 56, 32,  1,  0},
-   { 57, 33,  1,  0},
-   { 58, 34,  1,  0},
-   { 59, 35,  1,  0},
-   { 60, 36,  1,  0},
-   { 61, 37,  1,  0},
-   { 62, 38,  1,  0},
-   { 63, 39,  1,  0},
-   { 64, 40,  1,  0},
-   { 65, 41,  1,  0},
-   { 66, 42,  1,  0},
-   { 67, 43,  1,  0},
-   { 68, 44,  1,  0},
-   { 69, 45,  1,  0},
-   { 70, 46,  1,  0},
-   { 71, 47,  1,  0},
-   { 72, 48,  1,  0},
-   { 73, 49,  1,  0},
-   { 74, 50,  1,  0},
-   { 75, 51,  1,  0},
-   { 76, 52,  1,  0},
-   { 77, 53,  1,  0},
-   { 78, 54,  1,  0},
-   { 79, 55,  1,  0},
-   { 80, 56,  1,  0},
-   { 81, 57,  1,  0},
-   { 82, 58,  1,  0},
-   { 83, 40,  1,  1},
-   { 84, 41,  1,  1},
-   { 85, 42,  1,  1},
-   { 86, 43,  1,  1},
-   { 87, 44,  1,  1},
-   { 88, 45,  1,  1},
-   { 89, 46,  1,  1},
-   { 90, 47,  1,  1},
-   { 91, 48,  1,  1},
-   { 92, 49,  1,  1},
-   { 93, 50,  1,  1},
-   { 94, 51,  1,  1},
-   { 95, 52,  1,  1},
-   { 96, 53,  1,  1},
-   { 97, 54,  1,  1},
-   { 98, 55,  1,  1},
-   { 99, 56,  1,  1},
-   {100, 57,  1,  1},
-   {101, 58,  1,  1},
-   {102, 59,  1,  1},
-};
-
-/* 120 – 245 MHz band, lna 24dB, mixer 19dB */
-static const struct msi3101_gain msi3101_gain_lut_245[] = {
-   {  0,  0,  0,  0},
-   {  1,  1,  0,  0},
-   {  2,  2,  0,  0},
-   {  3,  3,  0,  0},
-   {  4,  4,  0,  0},
-   {  5,  5,  0,  0},
-   {  6,  6,  0,  0},
-   {  7,  7,  0,  0},
-   {  8,  8,  0,  0},
-   {  9,  9,  0,  0},
-   { 10, 10,  0,  0},
-   { 11, 11,  0,  0},
-   { 12, 12,  0,  0},
-   { 13, 13,  0,  0},
-   { 14, 14,  0,  0},
-   { 15, 15,  0,  0},
-   { 16, 16,  0,  0},
-   { 17, 17,  0,  0},
-   { 18, 18,  0,  0},
-   { 19, 19,  0,  0},
-   { 20, 20,  0,  0},
-   { 21, 21,  0,  0},
-   { 22, 22,  0,  0},
-   { 23, 23,  0,  0},
-   { 24, 24,  0,  0},
-   { 25, 25,  0,  0},
-   { 26, 26,  0,  0},
-   { 27, 27,  0,  0},
-   { 28, 28,  0,  0},
-   { 29,  5,  1,  0},
-   { 30,  6,  1,  0},
-   { 31,  7,  1,  0},
-   { 32,  8,  1,  0},
-   { 33,  9,  1,  0},
-   { 34, 10,  1,  0},
-   { 35, 11,  1,  0},
-   { 36, 12,  1,  0},
-   { 37, 13,  1,  0},
-   { 38, 14,  1,  0},
-   { 39, 15,  1,  0},
-   { 40, 16,  1,  0},
-   { 41, 17,  1,  0},
-   { 42, 18,  1,  0},
-   { 43, 19,  1,  0},
-   { 44, 20,  1,  0},
-   { 45, 21,  1,  0},
-   { 46, 22,  1,  0},
-   { 47, 23,  1,  0},
-   { 48, 24,  1,  0},
-   

[REVIEW PATCH 44/86] e4000: fix PLL calc to allow higher frequencies

2014-02-09 Thread Antti Palosaari
There was 32-bit overflow on VCO frequency calculation which blocks
tuning to 1073 - 1104 MHz. Use 64 bit number in order to avoid VCO
frequency overflow.

After that fix device in question tunes to following range:
60 - 1104 MHz
1250 - 2207 MHz

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/e4000.c | 14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index 651de11..9187190 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -221,11 +221,11 @@ static int e4000_set_params(struct dvb_frontend *fe)
struct e4000_priv *priv = fe-tuner_priv;
struct dtv_frontend_properties *c = fe-dtv_property_cache;
int ret, i, sigma_delta;
-   unsigned int f_vco;
+   u64 f_vco;
u8 buf[5], i_data[4], q_data[4];
 
dev_dbg(priv-client-dev,
-   %s: delivery_system=%d frequency=%d bandwidth_hz=%d\n,
+   %s: delivery_system=%d frequency=%u bandwidth_hz=%u\n,
__func__, c-delivery_system, c-frequency,
c-bandwidth_hz);
 
@@ -248,20 +248,16 @@ static int e4000_set_params(struct dvb_frontend *fe)
goto err;
}
 
-   /*
-* Note: Currently f_vco overflows when c-frequency is 1 073 741 824 Hz
-* or more.
-*/
-   f_vco = c-frequency * e4000_pll_lut[i].mul;
+   f_vco = 1ull * c-frequency * e4000_pll_lut[i].mul;
sigma_delta = div_u64(0x1ULL * (f_vco % priv-clock), priv-clock);
-   buf[0] = f_vco / priv-clock;
+   buf[0] = div_u64(f_vco, priv-clock);
buf[1] = (sigma_delta  0)  0xff;
buf[2] = (sigma_delta  8)  0xff;
buf[3] = 0x00;
buf[4] = e4000_pll_lut[i].div;
 
dev_dbg(priv-client-dev,
-   %s: f_vco=%u pll div=%d sigma_delta=%04x\n,
+   %s: f_vco=%llu pll div=%d sigma_delta=%04x\n,
__func__, f_vco, buf[0], sigma_delta);
 
ret = e4000_wr_regs(priv, 0x09, buf, 5);
-- 
1.8.5.3

--
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


[REVIEW PATCH 42/86] r820t: add manual gain controls

2014-02-09 Thread Antti Palosaari
Add gain control for LNA, Mixer and IF. Expose controls via DVB
frontend .set_config callback.

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/r820t.c | 38 ++
 drivers/media/tuners/r820t.h |  7 +++
 2 files changed, 45 insertions(+)

diff --git a/drivers/media/tuners/r820t.c b/drivers/media/tuners/r820t.c
index 319adc4..231c614 100644
--- a/drivers/media/tuners/r820t.c
+++ b/drivers/media/tuners/r820t.c
@@ -1251,6 +1251,43 @@ static int r820t_set_gain_mode(struct r820t_priv *priv,
 }
 #endif
 
+static int r820t_set_config(struct dvb_frontend *fe, void *priv_cfg)
+{
+   struct r820t_priv *priv = fe-tuner_priv;
+   struct r820t_ctrl *ctrl = priv_cfg;
+   int rc;
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 1);
+
+   if (ctrl-lna_gain == INT_MIN)
+   rc = r820t_write_reg_mask(priv, 0x05, 0x00, 0x10);
+   else
+   rc = r820t_write_reg_mask(priv, 0x05,
+   0x10 | ctrl-lna_gain, 0x1f);
+   if (rc  0)
+   goto err;
+
+   if (ctrl-mixer_gain == INT_MIN)
+   rc = r820t_write_reg_mask(priv, 0x07, 0x10, 0x10);
+   else
+   rc = r820t_write_reg_mask(priv, 0x07,
+   0x00 | ctrl-mixer_gain, 0x1f);
+   if (rc  0)
+   goto err;
+
+   if (ctrl-if_gain == INT_MIN)
+   rc = r820t_write_reg_mask(priv, 0x0c, 0x10, 0x10);
+   else
+   rc = r820t_write_reg_mask(priv, 0x0c,
+   0x00 | ctrl-if_gain, 0x1f);
+err:
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 0);
+
+   return rc;
+}
+
 static int generic_set_freq(struct dvb_frontend *fe,
u32 freq /* in HZ */,
unsigned bw,
@@ -2275,6 +2312,7 @@ static const struct dvb_tuner_ops r820t_tuner_ops = {
.release = r820t_release,
.sleep = r820t_sleep,
.set_params = r820t_set_params,
+   .set_config = r820t_set_config,
.set_analog_params = r820t_set_analog_freq,
.get_if_frequency = r820t_get_if_frequency,
.get_rf_strength = r820t_signal,
diff --git a/drivers/media/tuners/r820t.h b/drivers/media/tuners/r820t.h
index 48af354..42c0d8e 100644
--- a/drivers/media/tuners/r820t.h
+++ b/drivers/media/tuners/r820t.h
@@ -42,6 +42,13 @@ struct r820t_config {
bool use_predetect;
 };
 
+/* set INT_MIN for automode */
+struct r820t_ctrl {
+   int lna_gain;
+   int mixer_gain;
+   int if_gain;
+};
+
 #if IS_ENABLED(CONFIG_MEDIA_TUNER_R820T)
 struct dvb_frontend *r820t_attach(struct dvb_frontend *fe,
  struct i2c_adapter *i2c,
-- 
1.8.5.3

--
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


[REVIEW PATCH 02/86] rtl28xxu: attach SDR extension module

2014-02-09 Thread Antti Palosaari
With that extension module it supports SDR.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/Makefile   | 1 +
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 8 
 2 files changed, 9 insertions(+)

diff --git a/drivers/media/usb/dvb-usb-v2/Makefile 
b/drivers/media/usb/dvb-usb-v2/Makefile
index 2c06714..bfe67f9 100644
--- a/drivers/media/usb/dvb-usb-v2/Makefile
+++ b/drivers/media/usb/dvb-usb-v2/Makefile
@@ -44,3 +44,4 @@ ccflags-y += -I$(srctree)/drivers/media/dvb-core
 ccflags-y += -I$(srctree)/drivers/media/dvb-frontends
 ccflags-y += -I$(srctree)/drivers/media/tuners
 ccflags-y += -I$(srctree)/drivers/media/common
+ccflags-y += -I$(srctree)/drivers/staging/media/rtl2832u_sdr
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index fda5c64..b398ebf 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -24,6 +24,7 @@
 
 #include rtl2830.h
 #include rtl2832.h
+#include rtl2832_sdr.h
 
 #include qt1010.h
 #include mt2060.h
@@ -734,6 +735,9 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter 
*adap)
struct dvb_usb_device *d = adap_to_d(adap);
struct rtl28xxu_priv *priv = d_to_priv(d);
struct rtl2832_config *rtl2832_config;
+   static const struct rtl2832_sdr_config rtl2832_sdr_config = {
+   .i2c_addr = 0x10,
+   };
 
dev_dbg(d-udev-dev, %s:\n, __func__);
 
@@ -775,6 +779,10 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter 
*adap)
/* set fe callback */
adap-fe[0]-callback = rtl2832u_frontend_callback;
 
+   /* attach SDR */
+   dvb_attach(rtl2832_sdr_attach, adap-fe[0], d-i2c_adap,
+   rtl2832_sdr_config);
+
return 0;
 err:
dev_dbg(d-udev-dev, %s: failed=%d\n, __func__, ret);
-- 
1.8.5.3

--
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


[REVIEW PATCH 03/86] rtl2832_sdr: use config struct from rtl2832 module

2014-02-09 Thread Antti Palosaari
There is absolutely no need to define own configuration struct as
same params are used demod main module. So use existing config.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c  | 5 +
 drivers/staging/media/rtl2832u_sdr/Makefile  | 1 +
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 4 ++--
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.h | 9 -
 4 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index b398ebf..ec6ab0f 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -735,9 +735,6 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter 
*adap)
struct dvb_usb_device *d = adap_to_d(adap);
struct rtl28xxu_priv *priv = d_to_priv(d);
struct rtl2832_config *rtl2832_config;
-   static const struct rtl2832_sdr_config rtl2832_sdr_config = {
-   .i2c_addr = 0x10,
-   };
 
dev_dbg(d-udev-dev, %s:\n, __func__);
 
@@ -781,7 +778,7 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter 
*adap)
 
/* attach SDR */
dvb_attach(rtl2832_sdr_attach, adap-fe[0], d-i2c_adap,
-   rtl2832_sdr_config);
+   rtl2832_config);
 
return 0;
 err:
diff --git a/drivers/staging/media/rtl2832u_sdr/Makefile 
b/drivers/staging/media/rtl2832u_sdr/Makefile
index 684546776..1009276 100644
--- a/drivers/staging/media/rtl2832u_sdr/Makefile
+++ b/drivers/staging/media/rtl2832u_sdr/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_DVB_RTL2832_SDR) += rtl2832_sdr.o
 
 ccflags-y += -Idrivers/media/dvb-core
+ccflags-y += -Idrivers/media/dvb-frontends
 ccflags-y += -Idrivers/media/usb/dvb-usb-v2
diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 0b110a3..208520e 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -61,7 +61,7 @@ struct rtl2832_sdr_state {
 #define URB_BUF(1  2)
unsigned long flags;
 
-   const struct rtl2832_sdr_config *cfg;
+   const struct rtl2832_config *cfg;
struct dvb_frontend *fe;
struct dvb_usb_device *d;
struct i2c_adapter *i2c;
@@ -1004,7 +1004,7 @@ static void rtl2832_sdr_video_release(struct v4l2_device 
*v)
 }
 
 struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe,
-   struct i2c_adapter *i2c, const struct rtl2832_sdr_config *cfg)
+   struct i2c_adapter *i2c, const struct rtl2832_config *cfg)
 {
int ret;
struct rtl2832_sdr_state *s;
diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.h 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.h
index 69d97c1..0803e45 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.h
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.h
@@ -33,16 +33,15 @@
 
 #include linux/kconfig.h
 
-struct rtl2832_sdr_config {
-   u8 i2c_addr;
-};
+/* for config struct */
+#include rtl2832.h
 
 #if IS_ENABLED(CONFIG_DVB_RTL2832_SDR)
 extern struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe,
-   struct i2c_adapter *i2c, const struct rtl2832_sdr_config *cfg);
+   struct i2c_adapter *i2c, const struct rtl2832_config *cfg);
 #else
 static inline struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe,
-   struct i2c_adapter *i2c, const struct rtl2832_sdr_config *cfg)
+   struct i2c_adapter *i2c, const struct rtl2832_config *cfg)
 {
dev_warn(i2c-dev, %s: driver disabled by Kconfig\n, __func__);
return NULL;
-- 
1.8.5.3

--
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


[REVIEW PATCH 46/86] rtl2832_sdr: fix device caps to advertise SDR receiver

2014-02-09 Thread Antti Palosaari
Advertise device as a SDR receiver, not video. After that libv4l
accepts opening device.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 69fc996..15c562e3 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -609,7 +609,7 @@ static int rtl2832_sdr_querycap(struct file *file, void *fh,
strlcpy(cap-driver, KBUILD_MODNAME, sizeof(cap-driver));
strlcpy(cap-card, s-vdev.name, sizeof(cap-card));
usb_make_path(s-udev, cap-bus_info, sizeof(cap-bus_info));
-   cap-device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
+   cap-device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_STREAMING |
V4L2_CAP_READWRITE | V4L2_CAP_TUNER;
cap-capabilities = cap-device_caps | V4L2_CAP_DEVICE_CAPS;
return 0;
-- 
1.8.5.3

--
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


[REVIEW PATCH 59/86] MAINTAINERS: add msi001 driver

2014-02-09 Thread Antti Palosaari
Mirics MSi001 silicon tuner driver. Currently in staging as SDR API
is not ready.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index b2cf5cf..15ebabb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5757,6 +5757,16 @@ L:   platform-driver-...@vger.kernel.org
 S: Supported
 F: drivers/platform/x86/msi-wmi.c
 
+MSI001 MEDIA DRIVER
+M: Antti Palosaari cr...@iki.fi
+L: linux-media@vger.kernel.org
+W: http://linuxtv.org/
+W: http://palosaari.fi/linux/
+Q: http://patchwork.linuxtv.org/project/linux-media/list/
+T: git git://linuxtv.org/anttip/media_tree.git
+S: Maintained
+F: drivers/staging/media/msi3101/msi001*
+
 MT9M032 APTINA SENSOR DRIVER
 M: Laurent Pinchart laurent.pinch...@ideasonboard.com
 L: linux-media@vger.kernel.org
-- 
1.8.5.3

--
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


[REVIEW PATCH 20/86] rtl2832_sdr: increase USB buffers

2014-02-09 Thread Antti Palosaari
Increase USB xfer buffers heavily in order handle wider data stream.
Stream is quite heavy, over 50Mbit/sec, when sampling rates are
increased up to 3.2Msps. With remote controller interrupts disabled
and huge USB buffers it seems to perform even 3.2Msps rather well.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 348df05..4b8c016 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -51,8 +51,8 @@
 
 #define V4L2_PIX_FMT_SDR_U8 v4l2_fourcc('D', 'U', '0', '8') /* unsigned 
8-bit */
 
-#define MAX_BULK_BUFS(8)
-#define BULK_BUFFER_SIZE (8 * 512)
+#define MAX_BULK_BUFS(10)
+#define BULK_BUFFER_SIZE (128 * 512)
 
 /* intermediate buffers with raw data from the USB device */
 struct rtl2832_sdr_frame_buf {
-- 
1.8.5.3

--
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


[REVIEW PATCH 23/86] msi3101: add u8 sample format

2014-02-09 Thread Antti Palosaari
Add unsigned 8-bit sample format. Format is got directly from
hardware, but it is converted from signed to unsigned. It is worst
known sampling resolution hardware offer.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 67 -
 1 file changed, 66 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 502d35d..c50402d 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -385,6 +385,7 @@ static const struct msi3101_gain msi3101_gain_lut_1000[] = {
 #define MSI3101_CID_TUNER_IF  ((V4L2_CID_USER_BASE | 0xf000) + 12)
 #define MSI3101_CID_TUNER_GAIN((V4L2_CID_USER_BASE | 0xf000) + 13)
 
+#define V4L2_PIX_FMT_SDR_U8 v4l2_fourcc('D', 'U', '0', '8') /* unsigned 
8-bit */
 #define V4L2_PIX_FMT_SDR_S8 v4l2_fourcc('D', 'S', '0', '8') /* signed 
8-bit */
 #define V4L2_PIX_FMT_SDR_S12v4l2_fourcc('D', 'S', '1', '2') /* signed 
12-bit */
 #define V4L2_PIX_FMT_SDR_S14v4l2_fourcc('D', 'S', '1', '4') /* signed 
14-bit */
@@ -428,6 +429,9 @@ struct msi3101_format {
 /* format descriptions for capture and preview */
 static struct msi3101_format formats[] = {
{
+   .name   = I/Q 8-bit unsigned,
+   .pixelformat= V4L2_PIX_FMT_SDR_U8,
+   }, {
.name   = I/Q 8-bit signed,
.pixelformat= V4L2_PIX_FMT_SDR_S8,
}, {
@@ -487,6 +491,7 @@ struct msi3101_state {
u32 next_sample; /* for track lost packets */
u32 sample; /* for sample rate calc */
unsigned long jiffies;
+   unsigned long jiffies_next;
unsigned int sample_ctrl_bit[4];
 };
 
@@ -572,6 +577,63 @@ static int msi3101_convert_stream_504(struct msi3101_state 
*s, u8 *dst,
return dst_len;
 }
 
+static int msi3101_convert_stream_504_u8(struct msi3101_state *s, u8 *dst,
+   u8 *src, unsigned int src_len)
+{
+   int i, j, i_max, dst_len = 0;
+   u32 sample_num[3];
+   s8 *s8src;
+   u8 *u8dst;
+
+   /* There could be 1-3 1024 bytes URB frames */
+   i_max = src_len / 1024;
+   u8dst = (u8 *) dst;
+
+   for (i = 0; i  i_max; i++) {
+   sample_num[i] = src[3]  24 | src[2]  16 | src[1]  8 | 
src[0]  0;
+   if (i == 0  s-next_sample != sample_num[0]) {
+   dev_dbg_ratelimited(s-udev-dev,
+   %d samples lost, %d %08x:%08x\n,
+   sample_num[0] - s-next_sample,
+   src_len, s-next_sample, sample_num[0]);
+   }
+
+   /*
+* Dump all unknown 'garbage' data - maybe we will discover
+* someday if there is something rational...
+*/
+   dev_dbg_ratelimited(s-udev-dev, %*ph\n, 12, src[4]);
+
+   /* 504 x I+Q samples */
+   src += 16;
+
+   s8src = (s8 *) src;
+   for (j = 0; j  1008; j++)
+   *u8dst++ = *s8src++ + 128;
+
+   src += 1008;
+   dst += 1008;
+   dst_len += 1008;
+   }
+
+   /* calculate samping rate and output it in 10 seconds intervals */
+   if (unlikely(time_is_before_jiffies(s-jiffies_next))) {
+#define MSECS 1UL
+   unsigned int samples = sample_num[i_max - 1] - s-sample;
+   s-jiffies_next = jiffies + msecs_to_jiffies(MSECS);
+   s-sample = sample_num[i_max - 1];
+   dev_dbg(s-udev-dev,
+   slen=%d samples=%u msecs=%lu sampling 
rate=%lu\n,
+   src_len, samples, MSECS,
+   samples * 1000UL / MSECS);
+   }
+
+   /* next sample (sample = sample + i * 504) */
+   s-next_sample = sample_num[i_max - 1] + 504;
+
+   return dst_len;
+}
+
 /*
  * +===
  * |   00-1023 | USB packet type '384'
@@ -1159,7 +1221,10 @@ static int msi3101_set_usb_adc(struct msi3101_state *s)
reg7 = 0x000c9407;
}
 
-   if (s-pixelformat == V4L2_PIX_FMT_SDR_S8) {
+   if (s-pixelformat == V4L2_PIX_FMT_SDR_U8) {
+   s-convert_stream = msi3101_convert_stream_504_u8;
+   reg7 = 0x000c9407;
+   } else if (s-pixelformat == V4L2_PIX_FMT_SDR_S8) {
s-convert_stream = msi3101_convert_stream_504;
reg7 = 0x000c9407;
} else if (s-pixelformat == V4L2_PIX_FMT_SDR_MSI2500_384) {
-- 
1.8.5.3

--
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


[REVIEW PATCH 27/86] rtl2832_sdr: calculate bandwidth if not set by user

2014-02-09 Thread Antti Palosaari
Calculate bandwidth from sampling rate if it is not set by user.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 1cc7bf7..2c9b703 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -881,6 +881,10 @@ static int rtl2832_sdr_set_tuner(struct rtl2832_sdr_state 
*s)
if (fe-ops.tuner_ops.init)
fe-ops.tuner_ops.init(fe);
 
+   /* user has not requested bandwidth so calculate automatically */
+   if (bandwidth == 0)
+   bandwidth = s-f_adc;
+
c-bandwidth_hz = bandwidth;
c-frequency = f_rf;
 
@@ -1254,9 +1258,9 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
.id = RTL2832_SDR_CID_TUNER_BW,
.type   = V4L2_CTRL_TYPE_INTEGER,
.name   = Tuner BW,
-   .min=  20,
-   .max= 800,
-   .def=  60,
+   .min= 0,
+   .max= INT_MAX,
+   .def= 0,
.step   = 1,
};
static const struct v4l2_ctrl_config ctrl_tuner_gain = {
-- 
1.8.5.3

--
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


[REVIEW PATCH 33/86] msi3101: remove FMT buffer type checks

2014-02-09 Thread Antti Palosaari
Remove unneeded buffer type checks from FMT IOTCL handlers. Checks
are already done by V4L core.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 02960c7..6b9f0da 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -1679,9 +1679,6 @@ static int msi3101_g_fmt_sdr_cap(struct file *file, void 
*priv,
struct msi3101_state *s = video_drvdata(file);
dev_dbg(s-udev-dev, %s:\n, __func__);
 
-   if (f-type != V4L2_BUF_TYPE_SDR_CAPTURE)
-   return -EINVAL;
-
f-fmt.sdr.pixelformat = s-pixelformat;
 
return 0;
@@ -1696,9 +1693,6 @@ static int msi3101_s_fmt_sdr_cap(struct file *file, void 
*priv,
dev_dbg(s-udev-dev, %s: pixelformat fourcc %4.4s\n, __func__,
(char *)f-fmt.sdr.pixelformat);
 
-   if (f-type != V4L2_BUF_TYPE_SDR_CAPTURE)
-   return -EINVAL;
-
if (vb2_is_busy(q))
return -EBUSY;
 
@@ -1723,9 +1717,6 @@ static int msi3101_try_fmt_sdr_cap(struct file *file, 
void *priv,
dev_dbg(s-udev-dev, %s: pixelformat fourcc %4.4s\n, __func__,
(char *)f-fmt.sdr.pixelformat);
 
-   if (f-type != V4L2_BUF_TYPE_SDR_CAPTURE)
-   return -EINVAL;
-
for (i = 0; i  NUM_FORMATS; i++) {
if (formats[i].pixelformat == f-fmt.sdr.pixelformat)
return 0;
-- 
1.8.5.3

--
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


[REVIEW PATCH 19/86] rtl28xxu: add module parameter to disable IR

2014-02-09 Thread Antti Palosaari
Disable IR interrupts in order to avoid SDR sample loss.
IR interrupts causes some extra load for device and it seems
be one reason to loss samples when sampling rate is high.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index 6a5eb0f..77f1fc9 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -36,6 +36,9 @@
 #include tua9001.h
 #include r820t.h
 
+static int rtl28xxu_disable_rc;
+module_param_named(disable_rc, rtl28xxu_disable_rc, int, 0644);
+MODULE_PARM_DESC(disable_rc, disable RTL2832U remote controller);
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req 
*req)
@@ -1325,6 +1328,10 @@ err:
 static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
struct dvb_usb_rc *rc)
 {
+   /* disable IR interrupts in order to avoid SDR sample loss */
+   if (rtl28xxu_disable_rc)
+   return rtl28xx_wr_reg(d, IR_RX_IE, 0x00);
+
/* load empty to enable rc */
if (!rc-map_name)
rc-map_name = RC_MAP_EMPTY;
-- 
1.8.5.3

--
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


[REVIEW PATCH 17/86] msi3101: move format 336 conversion to libv4lconvert

2014-02-09 Thread Antti Palosaari
Move format 384 conversion to libv4lconvert as a fourcc DS12.
It is 12-bit sample pairs packed to 3 bytes.

msi3101: move format 336 conversion 336 to libv4l

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 66 +++--
 1 file changed, 24 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 37fea45..7c1dc43 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -386,6 +386,7 @@ static const struct msi3101_gain msi3101_gain_lut_1000[] = {
 #define MSI3101_CID_TUNER_GAIN((V4L2_CID_USER_BASE | 0xf000) + 13)
 
 #define V4L2_PIX_FMT_SDR_S8 v4l2_fourcc('D', 'S', '0', '8') /* signed 
8-bit */
+#define V4L2_PIX_FMT_SDR_S12 v4l2_fourcc('D', 'S', '1', '2') /* signed 
12-bit */
 #define V4L2_PIX_FMT_SDR_MSI2500_384 v4l2_fourcc('M', '3', '8', '4') /* Mirics 
MSi2500 format 384 */
 
 /* stream formats */
@@ -399,10 +400,12 @@ static struct msi3101_format formats[] = {
{
.name   = I/Q 8-bit signed,
.pixelformat= V4L2_PIX_FMT_SDR_S8,
-   },
-   {
+   }, {
.name   = I/Q 10+2-bit signed,
.pixelformat= V4L2_PIX_FMT_SDR_MSI2500_384,
+   }, {
+   .name   = I/Q 12-bit signed,
+   .pixelformat= V4L2_PIX_FMT_SDR_S12,
},
 };
 
@@ -643,40 +646,21 @@ static int msi3101_convert_stream_384(struct 
msi3101_state *s, u8 *dst,
 }
 
 /*
- * Converts signed 12-bit integer into 32-bit IEEE floating point
- * representation.
+ * +===
+ * |   00-1023 | USB packet type '336'
+ * +===
+ * |   00-  03 | sequence number of first sample in that USB packet
+ * +---
+ * |   04-  15 | garbage
+ * +---
+ * |   16-1023 | samples
+ * +---
+ * signed 12-bit sample
  */
-static u32 msi3101_convert_sample_336(struct msi3101_state *s, u16 x)
-{
-   u32 msb, exponent, fraction, sign;
-
-   /* Zero is special */
-   if (!x)
-   return 0;
-
-   /* Negative / positive value */
-   if (x  (1  11)) {
-   x = -x;
-   x = 0x7ff; /* result is 11 bit ... + sign */
-   sign = 1  31;
-   } else {
-   sign = 0  31;
-   }
-
-   /* Get location of the most significant bit */
-   msb = __fls(x);
-
-   fraction = ror32(x, (msb - I2F_FRAC_BITS)  0x1f)  I2F_MASK;
-   exponent = (127 + msb)  I2F_FRAC_BITS;
-
-   return (fraction + exponent) | sign;
-}
-
-static int msi3101_convert_stream_336(struct msi3101_state *s, u32 *dst,
+static int msi3101_convert_stream_336(struct msi3101_state *s, u8 *dst,
u8 *src, unsigned int src_len)
 {
-   int i, j, i_max, dst_len = 0;
-   u16 sample[2];
+   int i, i_max, dst_len = 0;
u32 sample_num[3];
 
/* There could be 1-3 1024 bytes URB frames */
@@ -697,17 +681,12 @@ static int msi3101_convert_stream_336(struct 
msi3101_state *s, u32 *dst,
 */
dev_dbg_ratelimited(s-udev-dev, %*ph\n, 12, src[4]);
 
+   /* 336 x I+Q samples */
src += 16;
-   for (j = 0; j  1008; j += 3) {
-   sample[0] = (src[j + 0]  0xff)  0 | (src[j + 1]  
0x0f)  8;
-   sample[1] = (src[j + 1]  0xf0)  4 | (src[j + 2]  
0xff)  4;
-
-   *dst++ = msi3101_convert_sample_336(s, sample[0]);
-   *dst++ = msi3101_convert_sample_336(s, sample[1]);
-   }
-   /* 336 x I+Q 32bit float samples */
-   dst_len += 336 * 2 * 4;
+   memcpy(dst, src, 1008);
src += 1008;
+   dst += 1008;
+   dst_len += 1008;
}
 
/* calculate samping rate and output it in 10 seconds intervals */
@@ -1187,6 +1166,9 @@ static int msi3101_set_usb_adc(struct msi3101_state *s)
} else if (s-pixelformat == V4L2_PIX_FMT_SDR_MSI2500_384) {
s-convert_stream = msi3101_convert_stream_384;
reg7 = 0xa507;
+   } else if (s-pixelformat == V4L2_PIX_FMT_SDR_S12) {
+   s-convert_stream = msi3101_convert_stream_336;
+   reg7 = 0x8507;
}
 
/*
-- 
1.8.5.3

--
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


[REVIEW PATCH 26/86] rtl2832_sdr: return NULL on rtl2832_sdr_attach failure

2014-02-09 Thread Antti Palosaari
dvb_attach() expects NULL on attach failure.
Do some style changes also while we are here.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 50 
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index a26125c..1cc7bf7 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -1250,31 +1250,31 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
struct rtl2832_sdr_state *s;
struct dvb_usb_device *d = i2c_get_adapdata(i2c);
static const struct v4l2_ctrl_config ctrl_tuner_bw = {
-   .ops= rtl2832_sdr_ctrl_ops,
-   .id = RTL2832_SDR_CID_TUNER_BW,
-   .type   = V4L2_CTRL_TYPE_INTEGER,
-   .name   = Tuner BW,
-   .min=  20,
-   .max= 800,
+   .ops= rtl2832_sdr_ctrl_ops,
+   .id = RTL2832_SDR_CID_TUNER_BW,
+   .type   = V4L2_CTRL_TYPE_INTEGER,
+   .name   = Tuner BW,
+   .min=  20,
+   .max= 800,
.def=  60,
-   .step   = 1,
+   .step   = 1,
};
static const struct v4l2_ctrl_config ctrl_tuner_gain = {
-   .ops= rtl2832_sdr_ctrl_ops,
-   .id = RTL2832_SDR_CID_TUNER_GAIN,
-   .type   = V4L2_CTRL_TYPE_INTEGER,
-   .name   = Tuner Gain,
-   .min= 0,
-   .max= 102,
+   .ops= rtl2832_sdr_ctrl_ops,
+   .id = RTL2832_SDR_CID_TUNER_GAIN,
+   .type   = V4L2_CTRL_TYPE_INTEGER,
+   .name   = Tuner Gain,
+   .min= 0,
+   .max= 102,
.def= 0,
-   .step   = 1,
+   .step   = 1,
};
 
s = kzalloc(sizeof(struct rtl2832_sdr_state), GFP_KERNEL);
if (s == NULL) {
dev_err(d-udev-dev,
Could not allocate memory for 
rtl2832_sdr_state\n);
-   return ERR_PTR(-ENOMEM);
+   return NULL;
}
 
/* setup the state */
@@ -1298,18 +1298,11 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
s-vb_queue.mem_ops = vb2_vmalloc_memops;
s-vb_queue.timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
ret = vb2_queue_init(s-vb_queue);
-   if (ret  0) {
+   if (ret) {
dev_err(s-udev-dev, Could not initialize vb2 queue\n);
goto err_free_mem;
}
 
-   /* Init video_device structure */
-   s-vdev = rtl2832_sdr_template;
-   s-vdev.queue = s-vb_queue;
-   s-vdev.queue-lock = s-vb_queue_lock;
-   set_bit(V4L2_FL_USE_FH_PRIO, s-vdev.flags);
-   video_set_drvdata(s-vdev, s);
-
/* Register controls */
v4l2_ctrl_handler_init(s-ctrl_handler, 2);
s-ctrl_tuner_bw = v4l2_ctrl_new_custom(s-ctrl_handler, 
ctrl_tuner_bw, NULL);
@@ -1320,6 +1313,13 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
goto err_free_controls;
}
 
+   /* Init video_device structure */
+   s-vdev = rtl2832_sdr_template;
+   s-vdev.queue = s-vb_queue;
+   s-vdev.queue-lock = s-vb_queue_lock;
+   set_bit(V4L2_FL_USE_FH_PRIO, s-vdev.flags);
+   video_set_drvdata(s-vdev, s);
+
/* Register the v4l2_device structure */
s-v4l2_dev.release = rtl2832_sdr_video_release;
ret = v4l2_device_register(s-udev-dev, s-v4l2_dev);
@@ -1335,7 +1335,7 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
s-vdev.vfl_dir = VFL_DIR_RX;
 
ret = video_register_device(s-vdev, VFL_TYPE_SDR, -1);
-   if (ret  0) {
+   if (ret) {
dev_err(s-udev-dev,
Failed to register as video device (%d)\n,
ret);
@@ -1357,7 +1357,7 @@ err_free_controls:
v4l2_ctrl_handler_free(s-ctrl_handler);
 err_free_mem:
kfree(s);
-   return ERR_PTR(ret);
+   return NULL;
 }
 EXPORT_SYMBOL(rtl2832_sdr_attach);
 
-- 
1.8.5.3

--
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


[REVIEW PATCH 31/86] rtl2832_sdr: switch FM to DAB mode

2014-02-09 Thread Antti Palosaari
It seems to perform a little bit better on weak signals when mode
is DAB. It looks like weak signals are faded out by squelch(?) in
FM mode as voice was silenced under one sec when tuned to weak FM
station.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index d101409..fccb16f 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -748,12 +748,12 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state 
*s)
if (ret)
goto err;
 
-   /* mode */
ret = rtl2832_sdr_wr_regs(s, 0x017, \x11\x10, 2);
if (ret)
goto err;
 
-   ret = rtl2832_sdr_wr_regs(s, 0x019, \x21, 1);
+   /* mode */
+   ret = rtl2832_sdr_wr_regs(s, 0x019, \x05, 1);
if (ret)
goto err;
 
-- 
1.8.5.3

--
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


[REVIEW PATCH 18/86] msi3101: move format 252 conversion to libv4lconvert

2014-02-09 Thread Antti Palosaari
Move format 252 conversion to libv4lconvert as a fourcc DS14.
It is 14-bit sample pairs packed to 4 bytes.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 65 +++--
 1 file changed, 24 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 7c1dc43..16ce417 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -387,6 +387,7 @@ static const struct msi3101_gain msi3101_gain_lut_1000[] = {
 
 #define V4L2_PIX_FMT_SDR_S8 v4l2_fourcc('D', 'S', '0', '8') /* signed 
8-bit */
 #define V4L2_PIX_FMT_SDR_S12 v4l2_fourcc('D', 'S', '1', '2') /* signed 
12-bit */
+#define V4L2_PIX_FMT_SDR_S14 v4l2_fourcc('D', 'S', '1', '4') /* signed 
14-bit */
 #define V4L2_PIX_FMT_SDR_MSI2500_384 v4l2_fourcc('M', '3', '8', '4') /* Mirics 
MSi2500 format 384 */
 
 /* stream formats */
@@ -406,6 +407,9 @@ static struct msi3101_format formats[] = {
}, {
.name   = I/Q 12-bit signed,
.pixelformat= V4L2_PIX_FMT_SDR_S12,
+   }, {
+   .name   = I/Q 14-bit signed,
+   .pixelformat= V4L2_PIX_FMT_SDR_S14,
},
 };
 
@@ -439,7 +443,7 @@ struct msi3101_state {
unsigned int vb_full; /* vb is full and packets dropped */
 
struct urb *urbs[MAX_ISO_BUFS];
-   int (*convert_stream) (struct msi3101_state *s, u32 *dst, u8 *src,
+   int (*convert_stream) (struct msi3101_state *s, u8 *dst, u8 *src,
unsigned int src_len);
 
/* Controls */
@@ -709,40 +713,21 @@ static int msi3101_convert_stream_336(struct 
msi3101_state *s, u8 *dst,
 }
 
 /*
- * Converts signed 14-bit integer into 32-bit IEEE floating point
- * representation.
+ * +===
+ * |   00-1023 | USB packet type '252'
+ * +===
+ * |   00-  03 | sequence number of first sample in that USB packet
+ * +---
+ * |   04-  15 | garbage
+ * +---
+ * |   16-1023 | samples
+ * +---
+ * signed 14-bit sample
  */
-static u32 msi3101_convert_sample_252(struct msi3101_state *s, u16 x)
-{
-   u32 msb, exponent, fraction, sign;
-
-   /* Zero is special */
-   if (!x)
-   return 0;
-
-   /* Negative / positive value */
-   if (x  (1  13)) {
-   x = -x;
-   x = 0x1fff; /* result is 13 bit ... + sign */
-   sign = 1  31;
-   } else {
-   sign = 0  31;
-   }
-
-   /* Get location of the most significant bit */
-   msb = __fls(x);
-
-   fraction = ror32(x, (msb - I2F_FRAC_BITS)  0x1f)  I2F_MASK;
-   exponent = (127 + msb)  I2F_FRAC_BITS;
-
-   return (fraction + exponent) | sign;
-}
-
-static int msi3101_convert_stream_252(struct msi3101_state *s, u32 *dst,
+static int msi3101_convert_stream_252(struct msi3101_state *s, u8 *dst,
u8 *src, unsigned int src_len)
 {
-   int i, j, i_max, dst_len = 0;
-   u16 sample[2];
+   int i, i_max, dst_len = 0;
u32 sample_num[3];
 
/* There could be 1-3 1024 bytes URB frames */
@@ -763,17 +748,12 @@ static int msi3101_convert_stream_252(struct 
msi3101_state *s, u32 *dst,
 */
dev_dbg_ratelimited(s-udev-dev, %*ph\n, 12, src[4]);
 
+   /* 252 x I+Q samples */
src += 16;
-   for (j = 0; j  1008; j += 4) {
-   sample[0] = src[j + 0]  0 | src[j + 1]  8;
-   sample[1] = src[j + 2]  0 | src[j + 3]  8;
-
-   *dst++ = msi3101_convert_sample_252(s, sample[0]);
-   *dst++ = msi3101_convert_sample_252(s, sample[1]);
-   }
-   /* 252 x I+Q 32bit float samples */
-   dst_len += 252 * 2 * 4;
+   memcpy(dst, src, 1008);
src += 1008;
+   dst += 1008;
+   dst_len += 1008;
}
 
/* calculate samping rate and output it in 10 seconds intervals */
@@ -1169,6 +1149,9 @@ static int msi3101_set_usb_adc(struct msi3101_state *s)
} else if (s-pixelformat == V4L2_PIX_FMT_SDR_S12) {
s-convert_stream = msi3101_convert_stream_336;
reg7 = 0x8507;
+   } else if (s-pixelformat == V4L2_PIX_FMT_SDR_S14) {
+   s-convert_stream = msi3101_convert_stream_252;
+   reg7 = 0x9407;
}
 
/*
-- 
1.8.5.3

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to 

[REVIEW PATCH 16/86] msi3101: move format 384 conversion to libv4lconvert

2014-02-09 Thread Antti Palosaari
Move format 384 conversion to libv4lconvert as a fourcc M384.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 163 ++--
 1 file changed, 57 insertions(+), 106 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index ba68ea9..37fea45 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -386,6 +386,7 @@ static const struct msi3101_gain msi3101_gain_lut_1000[] = {
 #define MSI3101_CID_TUNER_GAIN((V4L2_CID_USER_BASE | 0xf000) + 13)
 
 #define V4L2_PIX_FMT_SDR_S8 v4l2_fourcc('D', 'S', '0', '8') /* signed 
8-bit */
+#define V4L2_PIX_FMT_SDR_MSI2500_384 v4l2_fourcc('M', '3', '8', '4') /* Mirics 
MSi2500 format 384 */
 
 /* stream formats */
 struct msi3101_format {
@@ -399,6 +400,10 @@ static struct msi3101_format formats[] = {
.name   = I/Q 8-bit signed,
.pixelformat= V4L2_PIX_FMT_SDR_S8,
},
+   {
+   .name   = I/Q 10+2-bit signed,
+   .pixelformat= V4L2_PIX_FMT_SDR_MSI2500_384,
+   },
 };
 
 static const int NUM_FORMATS = sizeof(formats) / sizeof(struct msi3101_format);
@@ -465,50 +470,6 @@ leave:
spin_unlock_irqrestore(s-queued_bufs_lock, flags);
return buf;
 }
-/*
- * +===
- * |   00-1023 | USB packet type '384'
- * +===
- * |   00-  03 | sequence number of first sample in that USB packet
- * +---
- * |   04-  15 | garbage
- * +---
- * |   16- 175 | samples
- * +---
- * |  176- 179 | control bits for previous samples
- * +---
- * |  180- 339 | samples
- * +---
- * |  340- 343 | control bits for previous samples
- * +---
- * |  344- 503 | samples
- * +---
- * |  504- 507 | control bits for previous samples
- * +---
- * |  508- 667 | samples
- * +---
- * |  668- 671 | control bits for previous samples
- * +---
- * |  672- 831 | samples
- * +---
- * |  832- 835 | control bits for previous samples
- * +---
- * |  836- 995 | samples
- * +---
- * |  996- 999 | control bits for previous samples
- * +---
- * | 1000-1023 | garbage
- * +---
- *
- * Bytes 4 - 7 could have some meaning?
- *
- * Control bits for previous samples is 32-bit field, containing 16 x 2-bit
- * numbers. This results one 2-bit number for 8 samples. It is likely used for
- * for bit shifting sample by given bits, increasing actual sampling 
resolution.
- * Number 2 (0b10) was never seen.
- *
- * 6 * 16 * 2 * 4 = 768 samples. 768 * 4 = 3072 bytes
- */
 
 /*
  * Integer to 32-bit IEEE floating point representation routine is taken
@@ -585,48 +546,53 @@ static int msi3101_convert_stream_504(struct 
msi3101_state *s, u8 *dst,
 }
 
 /*
- * Converts signed ~10+2-bit integer into 32-bit IEEE floating point
- * representation.
+ * +===
+ * |   00-1023 | USB packet type '384'
+ * +===
+ * |   00-  03 | sequence number of first sample in that USB packet
+ * +---
+ * |   04-  15 | garbage
+ * +---
+ * |   16- 175 | samples
+ * +---
+ * |  176- 179 | control bits for previous samples
+ * +---
+ * |  180- 339 | samples
+ * +---
+ * |  340- 343 | control bits for previous samples
+ * 

[REVIEW PATCH 32/86] msi3101: calculate tuner filters

2014-02-09 Thread Antti Palosaari
Calculate tuner filters from sampling rate and use it if not
defined manually.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index cb66f81..02960c7 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -1416,7 +1416,7 @@ static int msi3101_set_tuner(struct msi3101_state *s)
{500, 0x04}, /* 5 MHz */
{600, 0x05}, /* 6 MHz */
{700, 0x06}, /* 7 MHz */
-   {800, 0x07}, /* 8 MHz */
+   {~0U, 0x07}, /* 8 MHz */
};
 
unsigned int f_rf = s-f_tuner;
@@ -1473,8 +1473,12 @@ static int msi3101_set_tuner(struct msi3101_state *s)
if (i == ARRAY_SIZE(if_freq_lut))
goto err;
 
+   /* user has not requested bandwidth, set some reasonable */
+   if (bandwidth == 0)
+   bandwidth = s-f_adc;
+
for (i = 0; i  ARRAY_SIZE(bandwidth_lut); i++) {
-   if (bandwidth == bandwidth_lut[i].freq) {
+   if (bandwidth = bandwidth_lut[i].freq) {
bandwidth = bandwidth_lut[i].val;
break;
}
@@ -1483,6 +1487,9 @@ static int msi3101_set_tuner(struct msi3101_state *s)
if (i == ARRAY_SIZE(bandwidth_lut))
goto err;
 
+   dev_dbg(s-udev-dev, %s: bandwidth selected=%d\n,
+   __func__, bandwidth_lut[i].freq);
+
 #define F_OUT_STEP 1
 #define R_REF 4
f_vco = (f_rf + f_if + f_if1) * lo_div;
@@ -1925,9 +1932,9 @@ static int msi3101_probe(struct usb_interface *intf,
.id = MSI3101_CID_TUNER_BW,
.type   = V4L2_CTRL_TYPE_INTEGER,
.name   = Tuner Bandwidth,
-   .min= 20,
+   .min= 0,
.max= 800,
-   .def= 60,
+   .def= 0,
.step   = 1,
};
static const struct v4l2_ctrl_config ctrl_tuner_gain = {
-- 
1.8.5.3

--
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


[REVIEW PATCH 30/86] rtl2832_sdr: remove FMT buffer type checks

2014-02-09 Thread Antti Palosaari
Remove unneeded buffer type checks from FMT IOTCL handlers. Checks
are already done by V4L core.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 0bc417d..d101409 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -1191,9 +1191,6 @@ static int rtl2832_sdr_g_fmt_sdr_cap(struct file *file, 
void *priv,
struct rtl2832_sdr_state *s = video_drvdata(file);
dev_dbg(s-udev-dev, %s:\n, __func__);
 
-   if (f-type != V4L2_BUF_TYPE_SDR_CAPTURE)
-   return -EINVAL;
-
f-fmt.sdr.pixelformat = s-pixelformat;
 
return 0;
@@ -1208,9 +1205,6 @@ static int rtl2832_sdr_s_fmt_sdr_cap(struct file *file, 
void *priv,
dev_dbg(s-udev-dev, %s: pixelformat fourcc %4.4s\n, __func__,
(char *)f-fmt.sdr.pixelformat);
 
-   if (f-type != V4L2_BUF_TYPE_SDR_CAPTURE)
-   return -EINVAL;
-
if (vb2_is_busy(q))
return -EBUSY;
 
@@ -1235,9 +1229,6 @@ static int rtl2832_sdr_try_fmt_sdr_cap(struct file *file, 
void *priv,
dev_dbg(s-udev-dev, %s: pixelformat fourcc %4.4s\n, __func__,
(char *)f-fmt.sdr.pixelformat);
 
-   if (f-type != V4L2_BUF_TYPE_SDR_CAPTURE)
-   return -EINVAL;
-
for (i = 0; i  NUM_FORMATS; i++) {
if (formats[i].pixelformat == f-fmt.sdr.pixelformat)
return 0;
-- 
1.8.5.3

--
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


[REVIEW PATCH 29/86] rtl2832_sdr: improve ADC device programming logic

2014-02-09 Thread Antti Palosaari
Refactor and implement properly RTL2832 programming logic. Implement
some things more correctly. Restore some critical registers to POR
default state, making it possible to use it as a DVB-T device without
resetting or replugging.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 283 ++-
 1 file changed, 177 insertions(+), 106 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index ddacfd2..0bc417d 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -187,7 +187,6 @@ static int rtl2832_sdr_wr(struct rtl2832_sdr_state *s, u8 
reg, const u8 *val,
return ret;
 }
 
-#if 0
 /* read multiple hardware registers */
 static int rtl2832_sdr_rd(struct rtl2832_sdr_state *s, u8 reg, u8 *val, int 
len)
 {
@@ -217,7 +216,6 @@ static int rtl2832_sdr_rd(struct rtl2832_sdr_state *s, u8 
reg, u8 *val, int len)
}
return ret;
 }
-#endif
 
 /* write multiple registers */
 static int rtl2832_sdr_wr_regs(struct rtl2832_sdr_state *s, u16 reg,
@@ -239,7 +237,6 @@ static int rtl2832_sdr_wr_regs(struct rtl2832_sdr_state *s, 
u16 reg,
return rtl2832_sdr_wr(s, reg2, val, len);
 }
 
-#if 0
 /* read multiple registers */
 static int rtl2832_sdr_rd_regs(struct rtl2832_sdr_state *s, u16 reg, u8 *val,
int len)
@@ -259,7 +256,6 @@ static int rtl2832_sdr_rd_regs(struct rtl2832_sdr_state *s, 
u16 reg, u8 *val,
 
return rtl2832_sdr_rd(s, reg2, val, len);
 }
-#endif
 
 /* write single register */
 static int rtl2832_sdr_wr_reg(struct rtl2832_sdr_state *s, u16 reg, u8 val)
@@ -273,6 +269,7 @@ static int rtl2832_sdr_rd_reg(struct rtl2832_sdr_state *s, 
u16 reg, u8 *val)
 {
return rtl2832_sdr_rd_regs(s, reg, val, 1);
 }
+#endif
 
 /* write single register with mask */
 static int rtl2832_sdr_wr_reg_mask(struct rtl2832_sdr_state *s, u16 reg,
@@ -295,6 +292,7 @@ static int rtl2832_sdr_wr_reg_mask(struct rtl2832_sdr_state 
*s, u16 reg,
return rtl2832_sdr_wr_regs(s, reg, val, 1);
 }
 
+#if 0
 /* read single register with mask */
 static int rtl2832_sdr_rd_reg_mask(struct rtl2832_sdr_state *s, u16 reg,
u8 *val, u8 mask)
@@ -662,10 +660,9 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
struct dvb_frontend *fe = s-fe;
int ret;
unsigned int f_sr, f_if;
-   u8 buf[4], tmp;
+   u8 buf[4], u8tmp1, u8tmp2;
u64 u64tmp;
u32 u32tmp;
-
dev_dbg(s-udev-dev, %s: f_adc=%u\n, __func__, s-f_adc);
 
if (!test_bit(POWER_ON, s-flags))
@@ -677,9 +674,12 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
f_sr = s-f_adc;
 
ret = rtl2832_sdr_wr_regs(s, 0x13e, \x00\x00, 2);
-   ret = rtl2832_sdr_wr_regs(s, 0x115, \x00, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x116, \x00\x00, 2);
-   ret = rtl2832_sdr_wr_regs(s, 0x118, \x00, 1);
+   if (ret)
+   goto err;
+
+   ret = rtl2832_sdr_wr_regs(s, 0x115, \x00\x00\x00\x00, 4);
+   if (ret)
+   goto err;
 
/* get IF from tuner */
if (fe-ops.tuner_ops.get_if_frequency)
@@ -708,13 +708,25 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state 
*s)
if (ret)
goto err;
 
-   /* program BB / IF mode */
-   if (f_if)
-   tmp = 0x00;
-   else
-   tmp = 0x01;
+   /* BB / IF mode */
+   /* POR: 0x1b1=0x1f, 0x008=0x0d, 0x006=0x80 */
+   if (f_if) {
+   u8tmp1 = 0x1a; /* disable Zero-IF */
+   u8tmp2 = 0x8d; /* enable ADC I */
+   } else {
+   u8tmp1 = 0x1b; /* enable Zero-IF, DC, IQ */
+   u8tmp2 = 0xcd; /* enable ADC I, ADC Q */
+   }
 
-   ret = rtl2832_sdr_wr_reg(s, 0x1b1, tmp);
+   ret = rtl2832_sdr_wr_reg(s, 0x1b1, u8tmp1);
+   if (ret)
+   goto err;
+
+   ret = rtl2832_sdr_wr_reg(s, 0x008, u8tmp2);
+   if (ret)
+   goto err;
+
+   ret = rtl2832_sdr_wr_reg(s, 0x006, 0x80);
if (ret)
goto err;
 
@@ -729,101 +741,59 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state 
*s)
if (ret)
goto err;
 
-   ret = rtl2832_sdr_wr_regs(s, 0x11c, \xca, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x11d, \xdc, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x11e, \xd7, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x11f, \xd8, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x120, \xe0, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x121, \xf2, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x122, \x0e, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x123, \x35, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x124, \x06, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x125, \x50, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x126, \x9c, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x127, \x0d, 1);
-   ret = 

[REVIEW PATCH 28/86] rtl2832_sdr: clamp ADC frequency to valid range always

2014-02-09 Thread Antti Palosaari
V4L2 tuner API says incorrect value should be round to nearest
legal value. Implement it for ADC frequency setting.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 24 
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 2c9b703..ddacfd2 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -666,7 +666,7 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
u64 u64tmp;
u32 u32tmp;
 
-   dev_dbg(s-udev-dev, %s:\n, __func__);
+   dev_dbg(s-udev-dev, %s: f_adc=%u\n, __func__, s-f_adc);
 
if (!test_bit(POWER_ON, s-flags))
return 0;
@@ -1064,12 +1064,26 @@ static int rtl2832_sdr_s_frequency(struct file *file, 
void *priv,
const struct v4l2_frequency *f)
 {
struct rtl2832_sdr_state *s = video_drvdata(file);
-   int ret;
+   int ret, band;
dev_dbg(s-udev-dev, %s: tuner=%d type=%d frequency=%u\n,
__func__, f-tuner, f-type, f-frequency);
 
-   if (f-tuner == 0) {
-   s-f_adc = f-frequency;
+   /* ADC band midpoints */
+   #define BAND_ADC_0 ((bands_adc[0].rangehigh + bands_adc[1].rangelow) / 
2)
+   #define BAND_ADC_1 ((bands_adc[1].rangehigh + bands_adc[2].rangelow) / 
2)
+
+   if (f-tuner == 0  f-type == V4L2_TUNER_ADC) {
+   if (f-frequency  BAND_ADC_0)
+   band = 0;
+   else if (f-frequency  BAND_ADC_1)
+   band = 1;
+   else
+   band = 2;
+
+   s-f_adc = clamp_t(unsigned int, f-frequency,
+   bands_adc[band].rangelow,
+   bands_adc[band].rangehigh);
+
dev_dbg(s-udev-dev, %s: ADC frequency=%u Hz\n,
__func__, s-f_adc);
ret = rtl2832_sdr_set_adc(s);
@@ -1287,6 +1301,8 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
s-udev = d-udev;
s-i2c = i2c;
s-cfg = cfg;
+   s-f_adc = bands_adc[0].rangelow;
+   s-pixelformat = V4L2_PIX_FMT_SDR_U8;
 
mutex_init(s-v4l2_lock);
mutex_init(s-vb_queue_lock);
-- 
1.8.5.3

--
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


[REVIEW PATCH 25/86] msi3101: tons of small changes

2014-02-09 Thread Antti Palosaari
* remove unneeded controls
* rename things
* remove unneeded callbacks
* use likely/unlikely on hot paths
* use 1Hz resolution for tuner RF frequency

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 214 +++-
 1 file changed, 55 insertions(+), 159 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 7a64f18..cb66f81 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -21,20 +21,6 @@
  *  (C) 1999-2004 Nemosoft Unv.
  *  (C) 2004-2006 Luc Saillard (l...@saillard.org)
  *  (C) 2011 Hans de Goede hdego...@redhat.com
- *
- * Development tree of that driver will be on:
- * http://git.linuxtv.org/anttip/media_tree.git/shortlog/refs/heads/mirics
- *
- * GNU Radio plugin gr-kernel for device usage will be on:
- * http://git.linuxtv.org/anttip/gr-kernel.git
- *
- * TODO:
- * Help is very highly welcome for these + all the others you could imagine:
- * - split USB ADC interface and RF tuner to own drivers (msi2500 and msi001)
- * - move controls to V4L2 API
- * - use libv4l2 for stream format conversions
- * - gr-kernel: switch to v4l2_mmap (current read eats a lot of cpu)
- * - SDRSharp support
  */
 
 #include linux/module.h
@@ -377,12 +363,7 @@ static const struct msi3101_gain msi3101_gain_lut_1000[] = 
{
 #define MAX_ISOC_ERRORS 20
 
 /* TODO: These should be moved to V4L2 API */
-#define MSI3101_CID_SAMPLING_MODE ((V4L2_CID_USER_BASE | 0xf000) + 0)
-#define MSI3101_CID_SAMPLING_RATE ((V4L2_CID_USER_BASE | 0xf000) + 1)
-#define MSI3101_CID_SAMPLING_RESOLUTION   ((V4L2_CID_USER_BASE | 0xf000) + 2)
-#define MSI3101_CID_TUNER_RF  ((V4L2_CID_USER_BASE | 0xf000) + 10)
 #define MSI3101_CID_TUNER_BW  ((V4L2_CID_USER_BASE | 0xf000) + 11)
-#define MSI3101_CID_TUNER_IF  ((V4L2_CID_USER_BASE | 0xf000) + 12)
 #define MSI3101_CID_TUNER_GAIN((V4L2_CID_USER_BASE | 0xf000) + 13)
 
 #define V4L2_PIX_FMT_SDR_U8 v4l2_fourcc('D', 'U', '0', '8') /* unsigned 
8-bit */
@@ -408,16 +389,16 @@ static const struct v4l2_frequency_band bands_rf[] = {
.tuner = 1,
.type = V4L2_TUNER_RF,
.index = 0,
-   .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_FREQ_BANDS,
-   .rangelow   =   4900 / 62.5,
-   .rangehigh  =  26300 / 62.5,
+   .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
+   .rangelow   =   4900,
+   .rangehigh  =  26300,
}, {
.tuner = 1,
.type = V4L2_TUNER_RF,
.index = 1,
-   .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_FREQ_BANDS,
-   .rangelow   =  39000 / 62.5,
-   .rangehigh  =  96000 / 62.5,
+   .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
+   .rangelow   =  39000,
+   .rangehigh  =  96000,
},
 };
 
@@ -430,27 +411,27 @@ struct msi3101_format {
 /* format descriptions for capture and preview */
 static struct msi3101_format formats[] = {
{
-   .name   = I/Q 8-bit unsigned,
+   .name   = 8-bit unsigned,
.pixelformat= V4L2_PIX_FMT_SDR_U8,
}, {
-   .name   = I/Q 16-bit unsigned little endian,
+   .name   = 16-bit unsigned little endian,
.pixelformat= V4L2_PIX_FMT_SDR_U16LE,
}, {
-   .name   = I/Q 8-bit signed,
+   .name   = 8-bit signed,
.pixelformat= V4L2_PIX_FMT_SDR_S8,
}, {
-   .name   = I/Q 10+2-bit signed,
+   .name   = 10+2-bit signed,
.pixelformat= V4L2_PIX_FMT_SDR_MSI2500_384,
}, {
-   .name   = I/Q 12-bit signed,
+   .name   = 12-bit signed,
.pixelformat= V4L2_PIX_FMT_SDR_S12,
}, {
-   .name   = I/Q 14-bit signed,
+   .name   = 14-bit signed,
.pixelformat= V4L2_PIX_FMT_SDR_S14,
},
 };
 
-static const int NUM_FORMATS = sizeof(formats) / sizeof(struct msi3101_format);
+static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats);
 
 /* intermediate buffers with raw data from the USB device */
 struct msi3101_frame_buf {
@@ -486,15 +467,11 @@ struct msi3101_state {
 
/* Controls */
struct v4l2_ctrl_handler ctrl_handler;
-   struct v4l2_ctrl *ctrl_sampling_rate;
-   struct v4l2_ctrl *ctrl_tuner_rf;
struct v4l2_ctrl *ctrl_tuner_bw;
-   struct v4l2_ctrl *ctrl_tuner_if;
struct v4l2_ctrl *ctrl_tuner_gain;
 
u32 next_sample; /* for track lost packets */
u32 sample; /* for 

[REVIEW PATCH 21/86] rtl2832_sdr: convert to SDR API

2014-02-09 Thread Antti Palosaari
It was abusing video device API. Use SDR API instead.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 387 +--
 1 file changed, 223 insertions(+), 164 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 4b8c016..a26125c 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -20,12 +20,6 @@
  * GNU Radio plugin gr-kernel for device usage will be on:
  * http://git.linuxtv.org/anttip/gr-kernel.git
  *
- * TODO:
- * Help is very highly welcome for these + all the others you could imagine:
- * - move controls to V4L2 API
- * - use libv4l2 for stream format conversions
- * - gr-kernel: switch to v4l2_mmap (current read eats a lot of cpu)
- * - SDRSharp support
  */
 
 #include dvb_frontend.h
@@ -38,22 +32,75 @@
 #include media/v4l2-event.h
 #include media/videobuf2-vmalloc.h
 
+#include linux/jiffies.h
 #include linux/math64.h
 
 /* TODO: These should be moved to V4L2 API */
-#define RTL2832_SDR_CID_SAMPLING_MODE   ((V4L2_CID_USER_BASE | 0xf000) +  
0)
-#define RTL2832_SDR_CID_SAMPLING_RATE   ((V4L2_CID_USER_BASE | 0xf000) +  
1)
-#define RTL2832_SDR_CID_SAMPLING_RESOLUTION ((V4L2_CID_USER_BASE | 0xf000) +  
2)
-#define RTL2832_SDR_CID_TUNER_RF((V4L2_CID_USER_BASE | 0xf000) + 
10)
 #define RTL2832_SDR_CID_TUNER_BW((V4L2_CID_USER_BASE | 0xf000) + 
11)
-#define RTL2832_SDR_CID_TUNER_IF((V4L2_CID_USER_BASE | 0xf000) + 
12)
 #define RTL2832_SDR_CID_TUNER_GAIN  ((V4L2_CID_USER_BASE | 0xf000) + 
13)
 
-#define V4L2_PIX_FMT_SDR_U8 v4l2_fourcc('D', 'U', '0', '8') /* unsigned 
8-bit */
+#define V4L2_PIX_FMT_SDR_U8v4l2_fourcc('D', 'U', '0', '8')
+#define V4L2_PIX_FMT_SDR_U16LE v4l2_fourcc('D', 'U', '1', '6')
 
 #define MAX_BULK_BUFS(10)
 #define BULK_BUFFER_SIZE (128 * 512)
 
+static const struct v4l2_frequency_band bands_adc[] = {
+   {
+   .tuner = 0,
+   .type = V4L2_TUNER_ADC,
+   .index = 0,
+   .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
+   .rangelow   =  30,
+   .rangehigh  =  30,
+   },
+   {
+   .tuner = 0,
+   .type = V4L2_TUNER_ADC,
+   .index = 1,
+   .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
+   .rangelow   =  91,
+   .rangehigh  = 280,
+   },
+   {
+   .tuner = 0,
+   .type = V4L2_TUNER_ADC,
+   .index = 2,
+   .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
+   .rangelow   = 320,
+   .rangehigh  = 320,
+   },
+};
+
+static const struct v4l2_frequency_band bands_fm[] = {
+   {
+   .tuner = 1,
+   .type = V4L2_TUNER_RF,
+   .index = 0,
+   .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
+   .rangelow   =5000,
+   .rangehigh  =  20,
+   },
+};
+
+/* stream formats */
+struct rtl2832_sdr_format {
+   char*name;
+   u32 pixelformat;
+};
+
+static struct rtl2832_sdr_format formats[] = {
+   {
+   .name   = 8-bit unsigned,
+   .pixelformat= V4L2_PIX_FMT_SDR_U8,
+   }, {
+   .name   = 16-bit unsigned little endian,
+   .pixelformat= V4L2_PIX_FMT_SDR_U16LE,
+   },
+};
+
+static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats);
+
 /* intermediate buffers with raw data from the USB device */
 struct rtl2832_sdr_frame_buf {
struct vb2_buffer vb;   /* common v4l buffer stuff -- must be first */
@@ -96,18 +143,18 @@ struct rtl2832_sdr_state {
int urbs_initialized;
int urbs_submitted;
 
+   unsigned int f_adc, f_tuner;
+   u32 pixelformat;
+
/* Controls */
struct v4l2_ctrl_handler ctrl_handler;
-   struct v4l2_ctrl *ctrl_sampling_rate;
-   struct v4l2_ctrl *ctrl_tuner_rf;
struct v4l2_ctrl *ctrl_tuner_bw;
-   struct v4l2_ctrl *ctrl_tuner_if;
struct v4l2_ctrl *ctrl_tuner_gain;
 
/* for sample rate calc */
unsigned int sample;
unsigned int sample_measured;
-   unsigned long jiffies;
+   unsigned long jiffies_next;
 };
 
 /* write multiple hardware registers */
@@ -292,27 +339,41 @@ leave:
 }
 
 static unsigned int rtl2832_sdr_convert_stream(struct rtl2832_sdr_state *s,
-   u8 *dst, const u8 *src, unsigned int src_len)
+   void *dst, const u8 *src, unsigned int src_len)
 {
-   memcpy(dst, src, src_len);
+   unsigned int dst_len;
+
+   if (s-pixelformat == V4L2_PIX_FMT_SDR_U8) {
+   /* native stream, no need to convert */
+   memcpy(dst, src, 

[REVIEW PATCH 34/86] msi3101: improve ADC config stream format selection

2014-02-09 Thread Antti Palosaari
Improve ADC config stream format selection. No functional changes.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 37 +
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 6b9f0da..ba37fce 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -1247,38 +1247,35 @@ static int msi3101_set_usb_adc(struct msi3101_state *s)
f_sr = s-f_adc;
 
/* select stream format */
-   if (f_sr  600) {
-   s-convert_stream = msi3101_convert_stream_252;
-   reg7 = 0x9407;
-   } else if (f_sr  800) {
-   s-convert_stream = msi3101_convert_stream_336;
-   reg7 = 0x8507;
-   } else if (f_sr  900) {
-   s-convert_stream = msi3101_convert_stream_384;
-   reg7 = 0xa507;
-   } else {
-   s-convert_stream = msi3101_convert_stream_504;
-   reg7 = 0x000c9407;
-   }
-
-   if (s-pixelformat == V4L2_PIX_FMT_SDR_U8) {
+   switch (s-pixelformat) {
+   case V4L2_PIX_FMT_SDR_U8:
s-convert_stream = msi3101_convert_stream_504_u8;
reg7 = 0x000c9407;
-   } else if (s-pixelformat == V4L2_PIX_FMT_SDR_U16LE) {
+   break;
+   case V4L2_PIX_FMT_SDR_U16LE:
s-convert_stream = msi3101_convert_stream_252_u16;
reg7 = 0x9407;
-   } else if (s-pixelformat == V4L2_PIX_FMT_SDR_S8) {
+   break;
+   case V4L2_PIX_FMT_SDR_S8:
s-convert_stream = msi3101_convert_stream_504;
reg7 = 0x000c9407;
-   } else if (s-pixelformat == V4L2_PIX_FMT_SDR_MSI2500_384) {
+   break;
+   case V4L2_PIX_FMT_SDR_MSI2500_384:
s-convert_stream = msi3101_convert_stream_384;
reg7 = 0xa507;
-   } else if (s-pixelformat == V4L2_PIX_FMT_SDR_S12) {
+   break;
+   case V4L2_PIX_FMT_SDR_S12:
s-convert_stream = msi3101_convert_stream_336;
reg7 = 0x8507;
-   } else if (s-pixelformat == V4L2_PIX_FMT_SDR_S14) {
+   break;
+   case V4L2_PIX_FMT_SDR_S14:
s-convert_stream = msi3101_convert_stream_252;
reg7 = 0x9407;
+   break;
+   default:
+   s-convert_stream = msi3101_convert_stream_504_u8;
+   reg7 = 0x000c9407;
+   break;
}
 
/*
-- 
1.8.5.3

--
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


[REVIEW PATCH 36/86] msi3101: disable all but u8 and u16le formats

2014-02-09 Thread Antti Palosaari
As for now, better to support only two general stream formats.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 2b812fe..e6b7cba 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -416,6 +416,7 @@ static struct msi3101_format formats[] = {
}, {
.name   = 16-bit unsigned little endian,
.pixelformat= V4L2_PIX_FMT_SDR_U16LE,
+#if 0
}, {
.name   = 8-bit signed,
.pixelformat= V4L2_PIX_FMT_SDR_S8,
@@ -428,6 +429,7 @@ static struct msi3101_format formats[] = {
}, {
.name   = 14-bit signed,
.pixelformat= V4L2_PIX_FMT_SDR_S14,
+#endif
},
 };
 
-- 
1.8.5.3

--
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


[REVIEW PATCH 24/86] msi3101: add u16 LE sample format

2014-02-09 Thread Antti Palosaari
Add unsigned 16-bit little endian sample format. That stream
format is scaled from hardware 14-bit signed value. That is best
known sampling resolution that MSi2500 ADC provides.

It is not guaranteed to be little endian, but host endian which is
usually little endian - room for improvement.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 79 +
 1 file changed, 79 insertions(+)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index c50402d..7a64f18 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -386,6 +386,7 @@ static const struct msi3101_gain msi3101_gain_lut_1000[] = {
 #define MSI3101_CID_TUNER_GAIN((V4L2_CID_USER_BASE | 0xf000) + 13)
 
 #define V4L2_PIX_FMT_SDR_U8 v4l2_fourcc('D', 'U', '0', '8') /* unsigned 
8-bit */
+#define V4L2_PIX_FMT_SDR_U16LE  v4l2_fourcc('D', 'U', '1', '6') /* unsigned 
16-bit LE */
 #define V4L2_PIX_FMT_SDR_S8 v4l2_fourcc('D', 'S', '0', '8') /* signed 
8-bit */
 #define V4L2_PIX_FMT_SDR_S12v4l2_fourcc('D', 'S', '1', '2') /* signed 
12-bit */
 #define V4L2_PIX_FMT_SDR_S14v4l2_fourcc('D', 'S', '1', '4') /* signed 
14-bit */
@@ -432,6 +433,9 @@ static struct msi3101_format formats[] = {
.name   = I/Q 8-bit unsigned,
.pixelformat= V4L2_PIX_FMT_SDR_U8,
}, {
+   .name   = I/Q 16-bit unsigned little endian,
+   .pixelformat= V4L2_PIX_FMT_SDR_U16LE,
+   }, {
.name   = I/Q 8-bit signed,
.pixelformat= V4L2_PIX_FMT_SDR_S8,
}, {
@@ -857,6 +861,78 @@ static int msi3101_convert_stream_252(struct msi3101_state 
*s, u8 *dst,
return dst_len;
 }
 
+static int msi3101_convert_stream_252_u16(struct msi3101_state *s, u8 *dst,
+   u8 *src, unsigned int src_len)
+{
+   int i, j, i_max, dst_len = 0;
+   u32 sample_num[3];
+   u16 *u16dst = (u16 *) dst;
+   struct {signed int x:14;} se;
+
+   /* There could be 1-3 1024 bytes URB frames */
+   i_max = src_len / 1024;
+
+   for (i = 0; i  i_max; i++) {
+   sample_num[i] = src[3]  24 | src[2]  16 | src[1]  8 | 
src[0]  0;
+   if (i == 0  s-next_sample != sample_num[0]) {
+   dev_dbg_ratelimited(s-udev-dev,
+   %d samples lost, %d %08x:%08x\n,
+   sample_num[0] - s-next_sample,
+   src_len, s-next_sample, sample_num[0]);
+   }
+
+   /*
+* Dump all unknown 'garbage' data - maybe we will discover
+* someday if there is something rational...
+*/
+   dev_dbg_ratelimited(s-udev-dev, %*ph\n, 12, src[4]);
+
+   /* 252 x I+Q samples */
+   src += 16;
+
+   for (j = 0; j  1008; j += 4) {
+   unsigned int usample[2];
+   int ssample[2];
+
+   usample[0] = src[j + 0]  0 | src[j + 1]  8;
+   usample[1] = src[j + 2]  0 | src[j + 3]  8;
+
+   /* sign extension from 14-bit to signed int */
+   ssample[0] = se.x = usample[0];
+   ssample[1] = se.x = usample[1];
+
+   /* from signed to unsigned */
+   usample[0] = ssample[0] + 8192;
+   usample[1] = ssample[1] + 8192;
+
+   /* from 14-bit to 16-bit */
+   *u16dst++ = (usample[0]  2) | (usample[0]  12);
+   *u16dst++ = (usample[1]  2) | (usample[1]  12);
+   }
+
+   src += 1008;
+   dst += 1008;
+   dst_len += 1008;
+   }
+
+   /* calculate samping rate and output it in 10 seconds intervals */
+   if (unlikely(time_is_before_jiffies(s-jiffies_next))) {
+#define MSECS 1UL
+   unsigned int samples = sample_num[i_max - 1] - s-sample;
+   s-jiffies_next = jiffies + msecs_to_jiffies(MSECS);
+   s-sample = sample_num[i_max - 1];
+   dev_dbg(s-udev-dev,
+   slen=%d samples=%u msecs=%lu sampling 
rate=%lu\n,
+   src_len, samples, MSECS,
+   samples * 1000UL / MSECS);
+   }
+
+   /* next sample (sample = sample + i * 252) */
+   s-next_sample = sample_num[i_max - 1] + 252;
+
+   return dst_len;
+}
+
 /*
  * This gets called for the Isochronous pipe (stream). This is done in 
interrupt
  * time, so it has to be fast, not crash, and not stall. Neat.
@@ -1224,6 +1300,9 @@ static int msi3101_set_usb_adc(struct msi3101_state *s)
if (s-pixelformat == V4L2_PIX_FMT_SDR_U8) {

[REVIEW PATCH 22/86] msi3101: convert to SDR API

2014-02-09 Thread Antti Palosaari
Convert to SDR API.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 218 ++--
 1 file changed, 142 insertions(+), 76 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 16ce417..502d35d 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -386,10 +386,39 @@ static const struct msi3101_gain msi3101_gain_lut_1000[] 
= {
 #define MSI3101_CID_TUNER_GAIN((V4L2_CID_USER_BASE | 0xf000) + 13)
 
 #define V4L2_PIX_FMT_SDR_S8 v4l2_fourcc('D', 'S', '0', '8') /* signed 
8-bit */
-#define V4L2_PIX_FMT_SDR_S12 v4l2_fourcc('D', 'S', '1', '2') /* signed 
12-bit */
-#define V4L2_PIX_FMT_SDR_S14 v4l2_fourcc('D', 'S', '1', '4') /* signed 
14-bit */
+#define V4L2_PIX_FMT_SDR_S12v4l2_fourcc('D', 'S', '1', '2') /* signed 
12-bit */
+#define V4L2_PIX_FMT_SDR_S14v4l2_fourcc('D', 'S', '1', '4') /* signed 
14-bit */
 #define V4L2_PIX_FMT_SDR_MSI2500_384 v4l2_fourcc('M', '3', '8', '4') /* Mirics 
MSi2500 format 384 */
 
+static const struct v4l2_frequency_band bands_adc[] = {
+   {
+   .tuner = 0,
+   .type = V4L2_TUNER_ADC,
+   .index = 0,
+   .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
+   .rangelow   =  120,
+   .rangehigh  = 1500,
+   },
+};
+
+static const struct v4l2_frequency_band bands_rf[] = {
+   {
+   .tuner = 1,
+   .type = V4L2_TUNER_RF,
+   .index = 0,
+   .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_FREQ_BANDS,
+   .rangelow   =   4900 / 62.5,
+   .rangehigh  =  26300 / 62.5,
+   }, {
+   .tuner = 1,
+   .type = V4L2_TUNER_RF,
+   .index = 1,
+   .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_FREQ_BANDS,
+   .rangelow   =  39000 / 62.5,
+   .rangehigh  =  96000 / 62.5,
+   },
+};
+
 /* stream formats */
 struct msi3101_format {
char*name;
@@ -437,6 +466,7 @@ struct msi3101_state {
/* Pointer to our usb_device, will be NULL after unplug */
struct usb_device *udev; /* Both mutexes most be hold when setting! */
 
+   unsigned int f_adc, f_tuner;
u32 pixelformat;
 
unsigned int isoc_errors; /* number of contiguous ISOC errors */
@@ -479,16 +509,6 @@ leave:
 }
 
 /*
- * Integer to 32-bit IEEE floating point representation routine is taken
- * from Radeon R600 driver (drivers/gpu/drm/radeon/r600_blit_kms.c).
- *
- * TODO: Currently we do conversion here in Kernel, but in future that will
- * be moved to the libv4l2 library as video format conversions are.
- */
-#define I2F_FRAC_BITS  23
-#define I2F_MASK ((1  I2F_FRAC_BITS) - 1)
-
-/*
  * +===
  * |   00-1023 | USB packet type '504'
  * +===
@@ -1016,12 +1036,11 @@ static int msi3101_querycap(struct file *file, void *fh,
strlcpy(cap-card, s-vdev.name, sizeof(cap-card));
usb_make_path(s-udev, cap-bus_info, sizeof(cap-bus_info));
cap-device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
-   V4L2_CAP_READWRITE;
+   V4L2_CAP_READWRITE | V4L2_CAP_TUNER;
cap-capabilities = cap-device_caps | V4L2_CAP_DEVICE_CAPS;
return 0;
 }
 
-
 /* Videobuf2 operations */
 static int msi3101_queue_setup(struct vb2_queue *vq,
const struct v4l2_format *fmt, unsigned int *nbuffers,
@@ -1037,9 +1056,9 @@ static int msi3101_queue_setup(struct vb2_queue *vq,
 *   3, wMaxPacketSize 3x 1024 bytes
 * 504, max IQ sample pairs per 1024 frame
 *   2, two samples, I and Q
-*   4, 32-bit float
+*   2, 16-bit is enough for single sample
 */
-   sizes[0] = PAGE_ALIGN(3 * 504 * 2 * 4); /* = 12096 */
+   sizes[0] = PAGE_ALIGN(3 * 504 * 2 * 2);
dev_dbg(s-udev-dev, %s: nbuffers=%d sizes[0]=%d\n,
__func__, *nbuffers, sizes[0]);
return 0;
@@ -1525,30 +1544,7 @@ static struct vb2_ops msi3101_vb2_ops = {
.wait_finish= vb2_ops_wait_finish,
 };
 
-static int msi3101_enum_input(struct file *file, void *fh, struct v4l2_input 
*i)
-{
-   if (i-index != 0)
-   return -EINVAL;
-
-   strlcpy(i-name, SDR data, sizeof(i-name));
-   i-type = V4L2_INPUT_TYPE_CAMERA;
-
-   return 0;
-}
-
-static int msi3101_g_input(struct file *file, void *fh, unsigned int *i)
-{
-   *i = 0;
-
-   return 0;
-}
-
-static int msi3101_s_input(struct file *file, void *fh, unsigned int i)
-{
-   return i ? -EINVAL : 0;
-}
-
-static int msi3101_enum_fmt_vid_cap(struct file *file, void *priv,
+static int 

[REVIEW PATCH 37/86] v4l: add RF tuner gain controls

2014-02-09 Thread Antti Palosaari
Modern silicon RF tuners used nowadays has many controllable gain
stages on signal path. Usually, but not always, there is at least
3 gain stages. Also on some cases there could be multiple gain
stages within the ones specified here. However, I think that having
these three controllable gain stages offers enough fine-tuning for
real use cases.

1) LNA gain. That is first gain just after antenna input.
2) Mixer gain. It is located quite middle of the signal path, where
RF signal is down-converted to IF/BB.
3) IF gain. That is last gain in order to adjust output signal level
to optimal level for receiving party (usually demodulator ADC).

Each gain stage could be set rather often both manual or automatic
(AGC) mode. Due to that add separate controls for controlling
operation mode.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/v4l2-core/v4l2-ctrls.c | 15 +++
 include/uapi/linux/v4l2-controls.h   | 11 +++
 2 files changed, 26 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c 
b/drivers/media/v4l2-core/v4l2-ctrls.c
index 6ff002b..d201f61 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -857,6 +857,14 @@ const char *v4l2_ctrl_get_name(u32 id)
case V4L2_CID_FM_RX_CLASS:  return FM Radio Receiver 
Controls;
case V4L2_CID_TUNE_DEEMPHASIS:  return De-Emphasis;
case V4L2_CID_RDS_RECEPTION:return RDS Reception;
+
+   case V4L2_CID_RF_TUNER_CLASS:   return RF Tuner Controls;
+   case V4L2_CID_LNA_GAIN_AUTO:return LNA Gain, Auto;
+   case V4L2_CID_LNA_GAIN: return LNA Gain;
+   case V4L2_CID_MIXER_GAIN_AUTO:  return Mixer Gain, Auto;
+   case V4L2_CID_MIXER_GAIN:   return Mixer Gain;
+   case V4L2_CID_IF_GAIN_AUTO: return IF Gain, Auto;
+   case V4L2_CID_IF_GAIN:  return IF Gain;
default:
return NULL;
}
@@ -906,6 +914,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
v4l2_ctrl_type *type,
case V4L2_CID_WIDE_DYNAMIC_RANGE:
case V4L2_CID_IMAGE_STABILIZATION:
case V4L2_CID_RDS_RECEPTION:
+   case V4L2_CID_LNA_GAIN_AUTO:
+   case V4L2_CID_MIXER_GAIN_AUTO:
+   case V4L2_CID_IF_GAIN_AUTO:
*type = V4L2_CTRL_TYPE_BOOLEAN;
*min = 0;
*max = *step = 1;
@@ -991,6 +1002,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
v4l2_ctrl_type *type,
case V4L2_CID_IMAGE_PROC_CLASS:
case V4L2_CID_DV_CLASS:
case V4L2_CID_FM_RX_CLASS:
+   case V4L2_CID_RF_TUNER_CLASS:
*type = V4L2_CTRL_TYPE_CTRL_CLASS;
/* You can neither read not write these */
*flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY;
@@ -1063,6 +1075,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
v4l2_ctrl_type *type,
case V4L2_CID_PILOT_TONE_FREQUENCY:
case V4L2_CID_TUNE_POWER_LEVEL:
case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
+   case V4L2_CID_LNA_GAIN:
+   case V4L2_CID_MIXER_GAIN:
+   case V4L2_CID_IF_GAIN:
*flags |= V4L2_CTRL_FLAG_SLIDER;
break;
case V4L2_CID_PAN_RELATIVE:
diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 2cbe605..076fa34 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -60,6 +60,7 @@
 #define V4L2_CTRL_CLASS_IMAGE_PROC 0x009f  /* Image processing 
controls */
 #define V4L2_CTRL_CLASS_DV 0x00a0  /* Digital Video 
controls */
 #define V4L2_CTRL_CLASS_FM_RX  0x00a1  /* FM Receiver controls 
*/
+#define V4L2_CTRL_CLASS_RF_TUNER   0x00a2  /* RF tuner controls */
 
 /* User-class control IDs */
 
@@ -895,4 +896,14 @@ enum v4l2_deemphasis {
 
 #define V4L2_CID_RDS_RECEPTION (V4L2_CID_FM_RX_CLASS_BASE + 2)
 
+#define V4L2_CID_RF_TUNER_CLASS_BASE   (V4L2_CTRL_CLASS_RF_TUNER | 
0x900)
+#define V4L2_CID_RF_TUNER_CLASS
(V4L2_CTRL_CLASS_RF_TUNER | 1)
+
+#define V4L2_CID_LNA_GAIN_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 
1)
+#define V4L2_CID_LNA_GAIN  (V4L2_CID_RF_TUNER_CLASS_BASE + 
2)
+#define V4L2_CID_MIXER_GAIN_AUTO   (V4L2_CID_RF_TUNER_CLASS_BASE + 
3)
+#define V4L2_CID_MIXER_GAIN(V4L2_CID_RF_TUNER_CLASS_BASE + 
4)
+#define V4L2_CID_IF_GAIN_AUTO  (V4L2_CID_RF_TUNER_CLASS_BASE + 
5)
+#define V4L2_CID_IF_GAIN   (V4L2_CID_RF_TUNER_CLASS_BASE + 
6)
+
 #endif
-- 
1.8.5.3

--
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


[REVIEW PATCH 14/86] msi3101: add signed 8-bit pixel format for SDR

2014-02-09 Thread Antti Palosaari
It is 8-bit unsigned data, byte after byte. Used for streaming SDR
I/Q data from ADC.

V4L2_PIX_FMT_SDR_S8, v4l fourcc DS08.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 4c3bf77..e208b57 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -385,6 +385,8 @@ static const struct msi3101_gain msi3101_gain_lut_1000[] = {
 #define MSI3101_CID_TUNER_IF  ((V4L2_CID_USER_BASE | 0xf000) + 12)
 #define MSI3101_CID_TUNER_GAIN((V4L2_CID_USER_BASE | 0xf000) + 13)
 
+#define V4L2_PIX_FMT_SDR_S8 v4l2_fourcc('D', 'S', '0', '8') /* signed 
8-bit */
+
 /* intermediate buffers with raw data from the USB device */
 struct msi3101_frame_buf {
struct vb2_buffer vb;   /* common v4l buffer stuff -- must be first */
-- 
1.8.5.3

--
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


[REVIEW PATCH 15/86] msi3101: implement FMT IOCTLs

2014-02-09 Thread Antti Palosaari
VIDIOC_ENUM_FMT, VIDIOC_G_FMT, VIDIOC_S_FMT and VIDIOC_TRY_FMT.

Implement 8-bit signed stream (type '504' samples per USB packet)
using FMT.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 165 +---
 1 file changed, 123 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index e208b57..ba68ea9 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -387,6 +387,22 @@ static const struct msi3101_gain msi3101_gain_lut_1000[] = 
{
 
 #define V4L2_PIX_FMT_SDR_S8 v4l2_fourcc('D', 'S', '0', '8') /* signed 
8-bit */
 
+/* stream formats */
+struct msi3101_format {
+   char*name;
+   u32 pixelformat;
+};
+
+/* format descriptions for capture and preview */
+static struct msi3101_format formats[] = {
+   {
+   .name   = I/Q 8-bit signed,
+   .pixelformat= V4L2_PIX_FMT_SDR_S8,
+   },
+};
+
+static const int NUM_FORMATS = sizeof(formats) / sizeof(struct msi3101_format);
+
 /* intermediate buffers with raw data from the USB device */
 struct msi3101_frame_buf {
struct vb2_buffer vb;   /* common v4l buffer stuff -- must be first */
@@ -409,6 +425,8 @@ struct msi3101_state {
/* Pointer to our usb_device, will be NULL after unplug */
struct usb_device *udev; /* Both mutexes most be hold when setting! */
 
+   u32 pixelformat;
+
unsigned int isoc_errors; /* number of contiguous ISOC errors */
unsigned int vb_full; /* vb is full and packets dropped */
 
@@ -447,7 +465,6 @@ leave:
spin_unlock_irqrestore(s-queued_bufs_lock, flags);
return buf;
 }
-
 /*
  * +===
  * |   00-1023 | USB packet type '384'
@@ -504,40 +521,22 @@ leave:
 #define I2F_MASK ((1  I2F_FRAC_BITS) - 1)
 
 /*
- * Converts signed 8-bit integer into 32-bit IEEE floating point
- * representation.
+ * +===
+ * |   00-1023 | USB packet type '504'
+ * +===
+ * |   00-  03 | sequence number of first sample in that USB packet
+ * +---
+ * |   04-  15 | garbage
+ * +---
+ * |   16-1023 | samples
+ * +---
+ * signed 8-bit sample
+ * 504 * 2 = 1008 samples
  */
-static u32 msi3101_convert_sample_504(struct msi3101_state *s, u16 x)
-{
-   u32 msb, exponent, fraction, sign;
-
-   /* Zero is special */
-   if (!x)
-   return 0;
-
-   /* Negative / positive value */
-   if (x  (1  7)) {
-   x = -x;
-   x = 0x7f; /* result is 7 bit ... + sign */
-   sign = 1  31;
-   } else {
-   sign = 0  31;
-   }
-
-   /* Get location of the most significant bit */
-   msb = __fls(x);
-
-   fraction = ror32(x, (msb - I2F_FRAC_BITS)  0x1f)  I2F_MASK;
-   exponent = (127 + msb)  I2F_FRAC_BITS;
-
-   return (fraction + exponent) | sign;
-}
-
-static int msi3101_convert_stream_504(struct msi3101_state *s, u32 *dst,
+static int msi3101_convert_stream_504(struct msi3101_state *s, u8 *dst,
u8 *src, unsigned int src_len)
 {
-   int i, j, i_max, dst_len = 0;
-   u16 sample[2];
+   int i, i_max, dst_len = 0;
u32 sample_num[3];
 
/* There could be 1-3 1024 bytes URB frames */
@@ -558,17 +557,12 @@ static int msi3101_convert_stream_504(struct 
msi3101_state *s, u32 *dst,
 */
dev_dbg_ratelimited(s-udev-dev, %*ph\n, 12, src[4]);
 
+   /* 504 x I+Q samples */
src += 16;
-   for (j = 0; j  1008; j += 2) {
-   sample[0] = src[j + 0];
-   sample[1] = src[j + 1];
-
-   *dst++ = msi3101_convert_sample_504(s, sample[0]);
-   *dst++ = msi3101_convert_sample_504(s, sample[1]);
-   }
-   /* 504 x I+Q 32bit float samples */
-   dst_len += 504 * 2 * 4;
+   memcpy(dst, src, 1008);
src += 1008;
+   dst += 1008;
+   dst_len += 1008;
}
 
/* calculate samping rate and output it in 10 seconds intervals */
@@ -1116,7 +1110,6 @@ static int msi3101_querycap(struct file *file, void *fh,
usb_make_path(s-udev, cap-bus_info, sizeof(cap-bus_info));
cap-device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
V4L2_CAP_READWRITE;
-   cap-device_caps = V4L2_CAP_TUNER;
cap-capabilities = cap-device_caps | 

[REVIEW PATCH 07/86] rtl2832_sdr: initial support for FC0012 tuner

2014-02-09 Thread Antti Palosaari
Use tuner via internal DVB API.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 0e12e1a..c088957 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -753,6 +753,12 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
ret = rtl2832_sdr_wr_regs(s, 0x104, \xcc, 1);
ret = rtl2832_sdr_wr_regs(s, 0x105, \xbe, 1);
ret = rtl2832_sdr_wr_regs(s, 0x1c8, \x14, 1);
+   } else if (s-cfg-tuner == RTL2832_TUNER_FC0012) {
+   ret = rtl2832_sdr_wr_regs(s, 0x103, \x5a, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1c7, \x2c, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x104, \xcc, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x105, \xbe, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1c8, \x16, 1);
} else {
ret = rtl2832_sdr_wr_regs(s, 0x103, \x5a, 1);
ret = rtl2832_sdr_wr_regs(s, 0x1c7, \x30, 1);
@@ -782,6 +788,19 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
ret = rtl2832_sdr_wr_regs(s, 0x019, \x21, 1);
ret = rtl2832_sdr_wr_regs(s, 0x116, \x00\x00, 2);
ret = rtl2832_sdr_wr_regs(s, 0x118, \x00, 1);
+   } else if (s-cfg-tuner == RTL2832_TUNER_FC0012) {
+   ret = rtl2832_sdr_wr_regs(s, 0x011, \xe9\xbf, 2);
+   ret = rtl2832_sdr_wr_regs(s, 0x1e5, \xf0, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1d9, \x00, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1db, \x00, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1dd, \x11, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1de, \xef, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1d8, \x0c, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1e6, \x02, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1d7, \x09, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x008, \xcd, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x101, \x14, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x101, \x10, 1);
} else {
ret = rtl2832_sdr_wr_regs(s, 0x011, \xd4, 1);
ret = rtl2832_sdr_wr_regs(s, 0x1e5, \xf0, 1);
-- 
1.8.5.3

--
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


[REVIEW PATCH 05/86] rtl2832_sdr: use get_if_frequency()

2014-02-09 Thread Antti Palosaari
Get IF from tuner and use it.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 60 
 1 file changed, 51 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 513da22..c4b72c1 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -208,7 +208,15 @@ static int rtl2832_sdr_rd_regs(struct rtl2832_sdr_state 
*s, u16 reg, u8 *val,
 
return rtl2832_sdr_rd(s, reg2, val, len);
 }
+#endif
 
+/* write single register */
+static int rtl2832_sdr_wr_reg(struct rtl2832_sdr_state *s, u16 reg, u8 val)
+{
+   return rtl2832_sdr_wr_regs(s, reg, val, 1);
+}
+
+#if 0
 /* read single register */
 static int rtl2832_sdr_rd_reg(struct rtl2832_sdr_state *s, u16 reg, u8 *val)
 {
@@ -632,8 +640,12 @@ static void rtl2832_sdr_buf_queue(struct vb2_buffer *vb)
 
 static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
 {
+   struct dvb_frontend *fe = s-fe;
int ret;
-   unsigned int f_sr;
+   unsigned int f_sr, f_if;
+   u8 buf[3], tmp;
+   u64 u64tmp;
+   u32 u32tmp;
 
dev_dbg(s-udev-dev, %s:\n, __func__);
 
@@ -647,14 +659,42 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state 
*s)
ret = rtl2832_sdr_wr_regs(s, 0x116, \x00\x00, 2);
ret = rtl2832_sdr_wr_regs(s, 0x118, \x00, 1);
 
-   if (s-cfg-tuner == RTL2832_TUNER_R820T) {
-   ret = rtl2832_sdr_wr_regs(s, 0x119, \x38\x11, 2);
-   ret = rtl2832_sdr_wr_regs(s, 0x11b, \x12, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x115, \x01, 1);
-   } else {
-   ret = rtl2832_sdr_wr_regs(s, 0x119, \x00\x00, 2);
-   ret = rtl2832_sdr_wr_regs(s, 0x11b, \x00, 1);
-   }
+   /* get IF from tuner */
+   if (fe-ops.tuner_ops.get_if_frequency)
+   ret = fe-ops.tuner_ops.get_if_frequency(fe, f_if);
+   else
+   ret = -EINVAL;
+
+   if (ret)
+   goto err;
+
+   /* program IF */
+   u64tmp = f_if % s-cfg-xtal;
+   u64tmp *= 0x40;
+   u64tmp = div_u64(u64tmp, s-cfg-xtal);
+   u64tmp = -u64tmp;
+   u32tmp = u64tmp  0x3f;
+
+   dev_dbg(s-udev-dev, %s: f_if=%u if_ctl=%08x\n,
+   __func__, f_if, u32tmp);
+
+   buf[0] = (u32tmp  16)  0xff;
+   buf[1] = (u32tmp   8)  0xff;
+   buf[2] = (u32tmp   0)  0xff;
+
+   ret = rtl2832_sdr_wr_regs(s, 0x119, buf, 3);
+   if (ret)
+   goto err;
+
+   /* program BB / IF mode */
+   if (f_if)
+   tmp = 0x00;
+   else
+   tmp = 0x01;
+
+   ret = rtl2832_sdr_wr_reg(s, 0x1b1, tmp);
+   if (ret)
+   goto err;
 
ret = rtl2832_sdr_wr_regs(s, 0x19f, \x03\x84, 2);
ret = rtl2832_sdr_wr_regs(s, 0x1a1, \x00\x00, 2);
@@ -696,6 +736,7 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
ret = rtl2832_sdr_wr_regs(s, 0x102, \x40, 1);
 
if (s-cfg-tuner == RTL2832_TUNER_R820T) {
+   ret = rtl2832_sdr_wr_regs(s, 0x115, \x01, 1);
ret = rtl2832_sdr_wr_regs(s, 0x103, \x80, 1);
ret = rtl2832_sdr_wr_regs(s, 0x1c7, \x24, 1);
ret = rtl2832_sdr_wr_regs(s, 0x104, \xcc, 1);
@@ -751,6 +792,7 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
ret = rtl2832_sdr_wr_regs(s, 0x101, \x10, 1);
}
 
+err:
return ret;
 };
 
-- 
1.8.5.3

--
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


[REVIEW PATCH 11/86] rtl2832: style changes and minor cleanup

2014-02-09 Thread Antti Palosaari
Most of those were reported by checkpatch.pl...

debug module parameter is not used anywhere so remove it.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/dvb-frontends/rtl2832.c  | 26 +++-
 drivers/media/dvb-frontends/rtl2832.h  |  2 +-
 drivers/media/dvb-frontends/rtl2832_priv.h | 50 +++---
 3 files changed, 38 insertions(+), 40 deletions(-)

diff --git a/drivers/media/dvb-frontends/rtl2832.c 
b/drivers/media/dvb-frontends/rtl2832.c
index 61d4ecb..00e63b9 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -24,11 +24,6 @@
 
 /* Max transfer size done by I2C transfer functions */
 #define MAX_XFER_SIZE  64
-
-int rtl2832_debug;
-module_param_named(debug, rtl2832_debug, int, 0644);
-MODULE_PARM_DESC(debug, Turn on/off frontend debugging (default:off).);
-
 #define REG_MASK(b) (BIT(b + 1) - 1)
 
 static const struct rtl2832_reg_entry registers[] = {
@@ -189,8 +184,9 @@ static int rtl2832_wr(struct rtl2832_priv *priv, u8 reg, u8 
*val, int len)
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);
+   dev_warn(priv-i2c-dev,
+   %s: i2c wr failed=%d reg=%02x len=%d\n,
+   KBUILD_MODNAME, ret, reg, len);
ret = -EREMOTEIO;
}
return ret;
@@ -218,8 +214,9 @@ static int rtl2832_rd(struct rtl2832_priv *priv, u8 reg, u8 
*val, int len)
if (ret == 2) {
ret = 0;
} else {
-   dev_warn(priv-i2c-dev, %s: i2c rd failed=%d reg=%02x  \
-   len=%d\n, KBUILD_MODNAME, ret, reg, len);
+   dev_warn(priv-i2c-dev,
+   %s: i2c rd failed=%d reg=%02x len=%d\n,
+   KBUILD_MODNAME, ret, reg, len);
ret = -EREMOTEIO;
}
return ret;
@@ -417,7 +414,7 @@ static int rtl2832_set_if(struct dvb_frontend *fe, u32 
if_freq)
 
ret = rtl2832_wr_demod_reg(priv, DVBT_PSET_IFFREQ, pset_iffreq);
 
-   return (ret);
+   return ret;
 }
 
 static int rtl2832_init(struct dvb_frontend *fe)
@@ -516,7 +513,8 @@ static int rtl2832_init(struct dvb_frontend *fe)
 
/*
 * r820t NIM code does a software reset here at the demod -
-* may not be needed, as there's already a software reset at 
set_params()
+* may not be needed, as there's already a software reset at
+* set_params()
 */
 #if 1
/* soft reset */
@@ -593,9 +591,9 @@ static int rtl2832_set_frontend(struct dvb_frontend *fe)
};
 
 
-   dev_dbg(priv-i2c-dev, %s: frequency=%d bandwidth_hz=%d  \
-   inversion=%d\n, __func__, c-frequency,
-   c-bandwidth_hz, c-inversion);
+   dev_dbg(priv-i2c-dev,
+   %s: frequency=%d bandwidth_hz=%d inversion=%d\n,
+   __func__, c-frequency, c-bandwidth_hz, c-inversion);
 
/* program tuner */
if (fe-ops.tuner_ops.set_params)
diff --git a/drivers/media/dvb-frontends/rtl2832.h 
b/drivers/media/dvb-frontends/rtl2832.h
index e543081..fa4e5f6 100644
--- a/drivers/media/dvb-frontends/rtl2832.h
+++ b/drivers/media/dvb-frontends/rtl2832.h
@@ -51,7 +51,7 @@ struct rtl2832_config {
 };
 
 #if IS_ENABLED(CONFIG_DVB_RTL2832)
-extern struct dvb_frontend *rtl2832_attach(
+struct dvb_frontend *rtl2832_attach(
const struct rtl2832_config *cfg,
struct i2c_adapter *i2c
 );
diff --git a/drivers/media/dvb-frontends/rtl2832_priv.h 
b/drivers/media/dvb-frontends/rtl2832_priv.h
index b5f2b80..4c845af 100644
--- a/drivers/media/dvb-frontends/rtl2832_priv.h
+++ b/drivers/media/dvb-frontends/rtl2832_priv.h
@@ -267,7 +267,7 @@ static const struct rtl2832_reg_value 
rtl2832_tuner_init_tua9001[] = {
{DVBT_OPT_ADC_IQ,0x1},
{DVBT_AD_AVI,0x0},
{DVBT_AD_AVQ,0x0},
-   {DVBT_SPEC_INV,  0x0},
+   {DVBT_SPEC_INV,  0x0},
 };
 
 static const struct rtl2832_reg_value rtl2832_tuner_init_fc0012[] = {
@@ -301,7 +301,7 @@ static const struct rtl2832_reg_value 
rtl2832_tuner_init_fc0012[] = {
{DVBT_GI_PGA_STATE,  0x0},
{DVBT_EN_AGC_PGA,0x1},
{DVBT_IF_AGC_MAN,0x0},
-   {DVBT_SPEC_INV,  0x0},
+   {DVBT_SPEC_INV,  0x0},
 };
 
 static const struct rtl2832_reg_value rtl2832_tuner_init_e4000[] = {
@@ -339,32 +339,32 @@ static const struct rtl2832_reg_value 
rtl2832_tuner_init_e4000[] = {
{DVBT_REG_MONSEL,0x1},
{DVBT_REG_MON,   0x1},
{DVBT_REG_4MSEL, 0x0},
-   {DVBT_SPEC_INV,  0x0},
+   

[REVIEW PATCH 06/86] rtl2832_sdr: implement sampling rate

2014-02-09 Thread Antti Palosaari
Now it is possible to set desired sampling rate via v4l2 controls.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index c4b72c1..0e12e1a 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -38,6 +38,8 @@
 #include media/v4l2-event.h
 #include media/videobuf2-vmalloc.h
 
+#include linux/math64.h
+
 /* TODO: These should be moved to V4L2 API */
 #define RTL2832_SDR_CID_SAMPLING_MODE   ((V4L2_CID_USER_BASE | 0xf000) +  
0)
 #define RTL2832_SDR_CID_SAMPLING_RATE   ((V4L2_CID_USER_BASE | 0xf000) +  
1)
@@ -643,7 +645,7 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
struct dvb_frontend *fe = s-fe;
int ret;
unsigned int f_sr, f_if;
-   u8 buf[3], tmp;
+   u8 buf[4], tmp;
u64 u64tmp;
u32 u32tmp;
 
@@ -696,8 +698,17 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
if (ret)
goto err;
 
-   ret = rtl2832_sdr_wr_regs(s, 0x19f, \x03\x84, 2);
-   ret = rtl2832_sdr_wr_regs(s, 0x1a1, \x00\x00, 2);
+   /* program sampling rate (resampling down) */
+   u32tmp = div_u64(s-cfg-xtal * 0x40ULL, f_sr * 4U);
+   u32tmp = 2;
+   buf[0] = (u32tmp  24)  0xff;
+   buf[1] = (u32tmp  16)  0xff;
+   buf[2] = (u32tmp   8)  0xff;
+   buf[3] = (u32tmp   0)  0xff;
+   ret = rtl2832_sdr_wr_regs(s, 0x19f, buf, 4);
+   if (ret)
+   goto err;
+
ret = rtl2832_sdr_wr_regs(s, 0x11c, \xca, 1);
ret = rtl2832_sdr_wr_regs(s, 0x11d, \xdc, 1);
ret = rtl2832_sdr_wr_regs(s, 0x11e, \xd7, 1);
@@ -1090,8 +1101,8 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
.id = RTL2832_SDR_CID_SAMPLING_RATE,
.type   = V4L2_CTRL_TYPE_INTEGER64,
.name   = Sampling Rate,
-   .min=  50,
-   .max= 400,
+   .min=  91,
+   .max= 280,
.def= 2048000,
.step   = 1,
};
-- 
1.8.5.3

--
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


[REVIEW PATCH 04/86] rtl2832_sdr: initial support for R820T tuner

2014-02-09 Thread Antti Palosaari
Use tuner via internal DVB API.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 84 +++-
 1 file changed, 53 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 208520e..513da22 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -646,8 +646,16 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
ret = rtl2832_sdr_wr_regs(s, 0x115, \x00, 1);
ret = rtl2832_sdr_wr_regs(s, 0x116, \x00\x00, 2);
ret = rtl2832_sdr_wr_regs(s, 0x118, \x00, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x119, \x00\x00, 2);
-   ret = rtl2832_sdr_wr_regs(s, 0x11b, \x00, 1);
+
+   if (s-cfg-tuner == RTL2832_TUNER_R820T) {
+   ret = rtl2832_sdr_wr_regs(s, 0x119, \x38\x11, 2);
+   ret = rtl2832_sdr_wr_regs(s, 0x11b, \x12, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x115, \x01, 1);
+   } else {
+   ret = rtl2832_sdr_wr_regs(s, 0x119, \x00\x00, 2);
+   ret = rtl2832_sdr_wr_regs(s, 0x11b, \x00, 1);
+   }
+
ret = rtl2832_sdr_wr_regs(s, 0x19f, \x03\x84, 2);
ret = rtl2832_sdr_wr_regs(s, 0x1a1, \x00\x00, 2);
ret = rtl2832_sdr_wr_regs(s, 0x11c, \xca, 1);
@@ -686,11 +694,21 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state 
*s)
ret = rtl2832_sdr_wr_regs(s, 0x006, \x80, 1);
ret = rtl2832_sdr_wr_regs(s, 0x112, \x5a, 1);
ret = rtl2832_sdr_wr_regs(s, 0x102, \x40, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x103, \x5a, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x1c7, \x30, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x104, \xd0, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x105, \xbe, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x1c8, \x18, 1);
+
+   if (s-cfg-tuner == RTL2832_TUNER_R820T) {
+   ret = rtl2832_sdr_wr_regs(s, 0x103, \x80, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1c7, \x24, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x104, \xcc, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x105, \xbe, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1c8, \x14, 1);
+   } else {
+   ret = rtl2832_sdr_wr_regs(s, 0x103, \x5a, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1c7, \x30, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x104, \xd0, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x105, \xbe, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1c8, \x18, 1);
+   }
+
ret = rtl2832_sdr_wr_regs(s, 0x106, \x35, 1);
ret = rtl2832_sdr_wr_regs(s, 0x1c9, \x21, 1);
ret = rtl2832_sdr_wr_regs(s, 0x1ca, \x21, 1);
@@ -704,30 +722,34 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state 
*s)
ret = rtl2832_sdr_wr_regs(s, 0x10b, \x7f, 1);
ret = rtl2832_sdr_wr_regs(s, 0x00e, \xfc, 1);
ret = rtl2832_sdr_wr_regs(s, 0x00e, \xfc, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x011, \xd4, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x1e5, \xf0, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x1d9, \x00, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x1db, \x00, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x1dd, \x14, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x1de, \xec, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x1d8, \x0c, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x1e6, \x02, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x1d7, \x09, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x00d, \x83, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x010, \x49, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x00d, \x87, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x00d, \x85, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x013, \x02, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x008, \xcd, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x1b1, \x01, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x101, \x14, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x101, \x10, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x019, \x21, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x10c, \x00, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x101, \x14, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x101, \x10, 1);
-   ret = rtl2832_sdr_wr_regs(s, 0x116, \x00\xe3, 2);
-   ret = rtl2832_sdr_wr_regs(s, 0x118, \x8e, 1);
+
+   if (s-cfg-tuner == RTL2832_TUNER_R820T) {
+   ret = rtl2832_sdr_wr_regs(s, 0x011, \xf4, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x101, \x14, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x101, \x10, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x019, \x21, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x116, \x00\x00, 2);
+   ret = rtl2832_sdr_wr_regs(s, 0x118, \x00, 1);
+   } else {
+   ret = rtl2832_sdr_wr_regs(s, 0x011, \xd4, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1e5, \xf0, 1);
+   ret = rtl2832_sdr_wr_regs(s, 0x1d9, \x00, 1);
+   ret = rtl2832_sdr_wr_regs(s, 

[REVIEW PATCH 00/86] SDR tree

2014-02-09 Thread Antti Palosaari
That is everything I have on my SDR queue. There is drivers for Mirics
MSi3101 and Realtek RTL2832U based devices. These drivers are still on
staging and I am not going to move those out of staging very soon as I
want get some experiments first.

That set is available via Git:
http://git.linuxtv.org/anttip/media_tree.git/shortlog/refs/heads/sdr_review


Simplest way to test it in practice is listen FM radio using SDRSharp as a 
radio player.
I made simple plug-in for that:
https://github.com/palosaari/sdrsharp-v4l2

That plug-in supports currently only on 64-bit Kernel...


Installation is this simple (Fedora 20):

$ sudo yum install mono-core monodevelop
$ svn co https://subversion.assembla.com/svn/sdrsharp/trunk sdrsharp
$ cd sdrsharp
$ git clone https://github.com/palosaari/sdrsharp-v4l2.git V4L2
$ sed -i 's/Format Version 12\.00/Format Version 11\.00/' SDRSharp.sln

* Add following line to SDRSharp/App.config file inside frontendPlugins tag
add key=Linux Kernel V4L2 value=SDRSharp.V4L2.LibV4LIO,SDRSharp.V4L2 /

$ monodevelop SDRSharp.sln
* View  Default
* Solution SDRSharp  Add  Add Existing Project...  V4L2  
SDRSharp.V4L2.csproj
* Select Release|x86
* Build  Build All
* File  Quit
$ mono Release/SDRSharp.exe


regards
Antti


Antti Palosaari (85):
  rtl2832_sdr: Realtek RTL2832 SDR driver module
  rtl28xxu: attach SDR extension module
  rtl2832_sdr: use config struct from rtl2832 module
  rtl2832_sdr: initial support for R820T tuner
  rtl2832_sdr: use get_if_frequency()
  rtl2832_sdr: implement sampling rate
  rtl2832_sdr: initial support for FC0012 tuner
  rtl2832_sdr: initial support for FC0013 tuner
  rtl28xxu: constify demod config structs
  rtl2832: remove unused if_dvbt config parameter
  rtl2832: style changes and minor cleanup
  rtl2832_sdr: pixel format for SDR
  rtl2832_sdr: implement FMT IOCTLs
  msi3101: add signed 8-bit pixel format for SDR
  msi3101: implement FMT IOCTLs
  msi3101: move format 384 conversion to libv4lconvert
  msi3101: move format 336 conversion to libv4lconvert
  msi3101: move format 252 conversion to libv4lconvert
  rtl28xxu: add module parameter to disable IR
  rtl2832_sdr: increase USB buffers
  rtl2832_sdr: convert to SDR API
  msi3101: convert to SDR API
  msi3101: add u8 sample format
  msi3101: add u16 LE sample format
  msi3101: tons of small changes
  rtl2832_sdr: return NULL on rtl2832_sdr_attach failure
  rtl2832_sdr: calculate bandwidth if not set by user
  rtl2832_sdr: clamp ADC frequency to valid range always
  rtl2832_sdr: improve ADC device programming logic
  rtl2832_sdr: remove FMT buffer type checks
  rtl2832_sdr: switch FM to DAB mode
  msi3101: calculate tuner filters
  msi3101: remove FMT buffer type checks
  msi3101: improve ADC config stream format selection
  msi3101: clamp ADC and RF to valid range
  msi3101: disable all but u8 and u16le formats
  v4l: add RF tuner gain controls
  msi3101: use standard V4L gain controls
  e4000: convert DVB tuner to I2C driver model
  e4000: add manual gain controls
  rtl2832_sdr: expose E4000 gain controls to user space
  r820t: add manual gain controls
  rtl2832_sdr: expose R820 gain controls to user space
  e4000: fix PLL calc to allow higher frequencies
  msi3101: fix device caps to advertise SDR receiver
  rtl2832_sdr: fix device caps to advertise SDR receiver
  msi3101: add default FMT and ADC frequency
  msi3101: sleep USB ADC and tuner when streaming is stopped
  DocBook: document RF tuner gain controls
  DocBook: V4L: add V4L2_SDR_FMT_CU8 - 'CU08'
  DocBook: V4L: add V4L2_SDR_FMT_CU16LE - 'CU16'
  DocBook: media: document V4L2_CTRL_CLASS_RF_TUNER
  xc2028: silence compiler warnings
  v4l: add RF tuner channel bandwidth control
  msi3101: implement tuner bandwidth control
  rtl2832_sdr: implement tuner bandwidth control
  msi001: Mirics MSi001 silicon tuner driver
  msi3101: use msi001 tuner driver
  MAINTAINERS: add msi001 driver
  MAINTAINERS: add msi3101 driver
  MAINTAINERS: add rtl2832_sdr driver
  rtl28xxu: attach SDR module later
  e4000: implement controls via v4l2 control framework
  rtl2832_sdr: use E4000 tuner controls via V4L framework
  e4000: remove .set_config() which was for controls
  rtl28xxu: fix switch-case style issue
  v4l: reorganize RF tuner control ID numbers
  DocBook: document RF tuner bandwidth controls
  v4l: uapi: add SDR formats CU8 and CU16LE
  msi3101: use formats defined in V4L2 API
  rtl2832_sdr: use formats defined in V4L2 API
  v4l: add enum_freq_bands support to tuner sub-device
  msi001: implement .enum_freq_bands()
  msi3101: provide RF tuner bands from sub-device
  r820t/rtl2832u_sdr: implement gains using v4l2 controls
  v4l: add control for RF tuner PLL lock flag
  e4000: implement PLL lock v4l control
  DocBook: media: document PLL lock control
  rtl2832: provide muxed I2C adapter
  rtl2832: add muxed I2C adapter for demod itself
  rtl2832: implement delayed I2C gate close
  rtl28xxu: use muxed RTL2832 I2C adapters for E4000 and RTL2832_SDR
  e4000: get 

[REVIEW PATCH 01/86] rtl2832_sdr: Realtek RTL2832 SDR driver module

2014-02-09 Thread Antti Palosaari
Implement SDR driver for Realtek RTL2832U chip as a DVB extension
module. SDR module is attached by DVB USB RTL28XXU driver as a DVB
SEC (satellite equipment controller) module. Abusing unused SEC here
has no harm as that is DVB-T only frontend.

SDR functionality is provided by RTL2832 DVB-T demodulator. I suspect
it is originally planned for DAB and FM, but it could be abused general
SDR, due to modern silicon tuners that has wide frequency range and a
lot of configurable parameters (filters, gains, ...).

http://thread.gmane.org/gmane.linux.drivers.video-input-infrastructure/44461

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/Kconfig|2 +
 drivers/staging/media/Makefile   |2 +
 drivers/staging/media/rtl2832u_sdr/Kconfig   |7 +
 drivers/staging/media/rtl2832u_sdr/Makefile  |4 +
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 1184 ++
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.h |   52 +
 6 files changed, 1251 insertions(+)
 create mode 100644 drivers/staging/media/rtl2832u_sdr/Kconfig
 create mode 100644 drivers/staging/media/rtl2832u_sdr/Makefile
 create mode 100644 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
 create mode 100644 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.h

diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig
index 22b0c9d..a9f2e63 100644
--- a/drivers/staging/media/Kconfig
+++ b/drivers/staging/media/Kconfig
@@ -41,6 +41,8 @@ source drivers/staging/media/solo6x10/Kconfig
 
 source drivers/staging/media/omap4iss/Kconfig
 
+source drivers/staging/media/rtl2832u_sdr/Kconfig
+
 # Keep LIRC at the end, as it has sub-menus
 source drivers/staging/media/lirc/Kconfig
 
diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile
index bedc62a..8e2c5d2 100644
--- a/drivers/staging/media/Makefile
+++ b/drivers/staging/media/Makefile
@@ -11,3 +11,5 @@ obj-$(CONFIG_VIDEO_OMAP4) += omap4iss/
 obj-$(CONFIG_USB_SN9C102)   += sn9c102/
 obj-$(CONFIG_VIDEO_OMAP2)   += omap24xx/
 obj-$(CONFIG_VIDEO_TCM825X) += omap24xx/
+obj-$(CONFIG_DVB_RTL2832_SDR)  += rtl2832u_sdr/
+
diff --git a/drivers/staging/media/rtl2832u_sdr/Kconfig 
b/drivers/staging/media/rtl2832u_sdr/Kconfig
new file mode 100644
index 000..3ede5fe
--- /dev/null
+++ b/drivers/staging/media/rtl2832u_sdr/Kconfig
@@ -0,0 +1,7 @@
+config DVB_RTL2832_SDR
+   tristate Realtek RTL2832 SDR
+   depends on USB  DVB_CORE  I2C  VIDEO_V4L2  DVB_USB_RTL28XXU
+   select DVB_RTL2832
+   select VIDEOBUF2_VMALLOC
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+
diff --git a/drivers/staging/media/rtl2832u_sdr/Makefile 
b/drivers/staging/media/rtl2832u_sdr/Makefile
new file mode 100644
index 000..684546776
--- /dev/null
+++ b/drivers/staging/media/rtl2832u_sdr/Makefile
@@ -0,0 +1,4 @@
+obj-$(CONFIG_DVB_RTL2832_SDR) += rtl2832_sdr.o
+
+ccflags-y += -Idrivers/media/dvb-core
+ccflags-y += -Idrivers/media/usb/dvb-usb-v2
diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
new file mode 100644
index 000..0b110a3
--- /dev/null
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -0,0 +1,1184 @@
+/*
+ * Realtek RTL2832U SDR driver
+ *
+ * Copyright (C) 2013 Antti Palosaari cr...@iki.fi
+ *
+ *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.
+ *
+ * GNU Radio plugin gr-kernel for device usage will be on:
+ * http://git.linuxtv.org/anttip/gr-kernel.git
+ *
+ * TODO:
+ * Help is very highly welcome for these + all the others you could imagine:
+ * - move controls to V4L2 API
+ * - use libv4l2 for stream format conversions
+ * - gr-kernel: switch to v4l2_mmap (current read eats a lot of cpu)
+ * - SDRSharp support
+ */
+
+#include dvb_frontend.h
+#include rtl2832_sdr.h
+#include dvb_usb.h
+
+#include media/v4l2-device.h
+#include media/v4l2-ioctl.h
+#include media/v4l2-ctrls.h
+#include media/v4l2-event.h
+#include media/videobuf2-vmalloc.h
+
+/* TODO: These should be moved to V4L2 API */
+#define RTL2832_SDR_CID_SAMPLING_MODE   ((V4L2_CID_USER_BASE | 0xf000) +  
0)
+#define RTL2832_SDR_CID_SAMPLING_RATE   ((V4L2_CID_USER_BASE | 0xf000) +  
1)
+#define RTL2832_SDR_CID_SAMPLING_RESOLUTION 

[REVIEW PATCH 13/86] rtl2832_sdr: implement FMT IOCTLs

2014-02-09 Thread Antti Palosaari
VIDIOC_ENUM_FMT, VIDIOC_G_FMT, VIDIOC_S_FMT and VIDIOC_TRY_FMT.
Return stream according to FMT.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 125 ++-
 1 file changed, 75 insertions(+), 50 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index d3db859..348df05 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -291,56 +291,10 @@ leave:
return buf;
 }
 
-/*
- * Integer to 32-bit IEEE floating point representation routine is taken
- * from Radeon R600 driver (drivers/gpu/drm/radeon/r600_blit_kms.c).
- *
- * TODO: Currently we do conversion here in Kernel, but in future that will
- * be moved to the libv4l2 library as video format conversions are.
- */
-#define I2F_FRAC_BITS  23
-#define I2F_MASK ((1  I2F_FRAC_BITS) - 1)
-
-/*
- * Converts signed 8-bit integer into 32-bit IEEE floating point
- * representation.
- */
-static u32 rtl2832_sdr_convert_sample(struct rtl2832_sdr_state *s, u16 x)
-{
-   u32 msb, exponent, fraction, sign;
-
-   /* Zero is special */
-   if (!x)
-   return 0;
-
-   /* Negative / positive value */
-   if (x  (1  7)) {
-   x = -x;
-   x = 0x7f; /* result is 7 bit ... + sign */
-   sign = 1  31;
-   } else {
-   sign = 0  31;
-   }
-
-   /* Get location of the most significant bit */
-   msb = __fls(x);
-
-   fraction = ror32(x, (msb - I2F_FRAC_BITS)  0x1f)  I2F_MASK;
-   exponent = (127 + msb)  I2F_FRAC_BITS;
-
-   return (fraction + exponent) | sign;
-}
-
 static unsigned int rtl2832_sdr_convert_stream(struct rtl2832_sdr_state *s,
-   u32 *dst, const u8 *src, unsigned int src_len)
+   u8 *dst, const u8 *src, unsigned int src_len)
 {
-   unsigned int i, dst_len = 0;
-
-   for (i = 0; i  src_len; i++)
-   *dst++ = rtl2832_sdr_convert_sample(s, src[i]);
-
-   /* 8-bit to 32-bit IEEE floating point */
-   dst_len = src_len * 4;
+   memcpy(dst, src, src_len);
 
/* calculate samping rate and output it in 10 seconds intervals */
if ((s-jiffies + msecs_to_jiffies(1)) = jiffies) {
@@ -358,7 +312,7 @@ static unsigned int rtl2832_sdr_convert_stream(struct 
rtl2832_sdr_state *s,
/* total number of I+Q pairs */
s-sample += src_len / 2;
 
-   return dst_len;
+   return src_len;
 }
 
 /*
@@ -591,7 +545,6 @@ static int rtl2832_sdr_querycap(struct file *file, void *fh,
usb_make_path(s-udev, cap-bus_info, sizeof(cap-bus_info));
cap-device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
V4L2_CAP_READWRITE;
-   cap-device_caps = V4L2_CAP_TUNER;
cap-capabilities = cap-device_caps | V4L2_CAP_DEVICE_CAPS;
return 0;
 }
@@ -1014,9 +967,81 @@ static int vidioc_s_frequency(struct file *file, void 
*priv,
f-frequency * 625UL / 10UL);
 }
 
+static int rtl2832_sdr_enum_fmt_vid_cap(struct file *file, void *priv,
+   struct v4l2_fmtdesc *f)
+{
+   struct rtl2832_sdr_state *s = video_drvdata(file);
+   dev_dbg(s-udev-dev, %s:\n, __func__);
+
+   if (f-index  0)
+   return -EINVAL;
+
+   f-flags = 0;
+   strcpy(f-description, I/Q 8-bit unsigned);
+   f-pixelformat = V4L2_PIX_FMT_SDR_U8;
+
+   return 0;
+}
+
+static int rtl2832_sdr_g_fmt_vid_cap(struct file *file, void *priv,
+   struct v4l2_format *f)
+{
+   struct rtl2832_sdr_state *s = video_drvdata(file);
+   dev_dbg(s-udev-dev, %s:\n, __func__);
+
+   if (f-type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+   return -EINVAL;
+
+   memset(f-fmt.pix, 0, sizeof(f-fmt.pix));
+   f-fmt.pix.pixelformat = V4L2_PIX_FMT_SDR_U8;
+
+   return 0;
+}
+
+static int rtl2832_sdr_s_fmt_vid_cap(struct file *file, void *priv,
+   struct v4l2_format *f)
+{
+   struct rtl2832_sdr_state *s = video_drvdata(file);
+   struct vb2_queue *q = s-vb_queue;
+   dev_dbg(s-udev-dev, %s: pixelformat fourcc %4.4s\n, __func__,
+   (char *)f-fmt.pix.pixelformat);
+
+   if (f-type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+   return -EINVAL;
+
+   if (vb2_is_busy(q))
+   return -EBUSY;
+
+   memset(f-fmt.pix, 0, sizeof(f-fmt.pix));
+   f-fmt.pix.pixelformat = V4L2_PIX_FMT_SDR_U8;
+
+   return 0;
+}
+
+static int rtl2832_sdr_try_fmt_vid_cap(struct file *file, void *priv,
+   struct v4l2_format *f)
+{
+   struct rtl2832_sdr_state *s = video_drvdata(file);
+   dev_dbg(s-udev-dev, %s: pixelformat fourcc %4.4s\n, __func__,
+   (char *)f-fmt.pix.pixelformat);
+
+   if (f-type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+   return -EINVAL;
+
+   memset(f-fmt.pix, 0, 

[REVIEW PATCH 53/86] xc2028: silence compiler warnings

2014-02-09 Thread Antti Palosaari
There is now new tuner types which are not handled on that switch-case.
Print error if unknown tuner type is meet.

drivers/media/tuners/tuner-xc2028.c: In function ‘generic_set_freq’:
drivers/media/tuners/tuner-xc2028.c:1037:2: warning: enumeration value 
‘V4L2_TUNER_ADC’ not handled in switch [-Wswitch]
  switch (new_type) {
  ^
drivers/media/tuners/tuner-xc2028.c:1037:2: warning: enumeration value 
‘V4L2_TUNER_RF’ not handled in switch [-Wswitch]

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/tuner-xc2028.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/tuners/tuner-xc2028.c 
b/drivers/media/tuners/tuner-xc2028.c
index cca508d..76a8165 100644
--- a/drivers/media/tuners/tuner-xc2028.c
+++ b/drivers/media/tuners/tuner-xc2028.c
@@ -1107,6 +1107,9 @@ static int generic_set_freq(struct dvb_frontend *fe, u32 
freq /* in HZ */,
offset += 20;
}
 #endif
+   default:
+   tuner_err(Unsupported tuner type %d.\n, new_type);
+   break;
}
 
div = (freq - offset + DIV / 2) / DIV;
-- 
1.8.5.3

--
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


[REVIEW PATCH 56/86] rtl2832_sdr: implement tuner bandwidth control

2014-02-09 Thread Antti Palosaari
Implement control that user could adjust tuner filters manually,
if he wish.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 71 
 1 file changed, 37 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 15c562e3..1dfe653 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -38,9 +38,6 @@
 #include linux/math64.h
 
 /* TODO: These should be moved to V4L2 API */
-#define RTL2832_SDR_CID_TUNER_BW((V4L2_CID_USER_BASE | 0xf000) + 
11)
-#define RTL2832_SDR_CID_TUNER_GAIN  ((V4L2_CID_USER_BASE | 0xf000) + 
13)
-
 #define V4L2_PIX_FMT_SDR_U8v4l2_fourcc('D', 'U', '0', '8')
 #define V4L2_PIX_FMT_SDR_U16LE v4l2_fourcc('D', 'U', '1', '6')
 
@@ -150,13 +147,14 @@ struct rtl2832_sdr_state {
 
/* Controls */
struct v4l2_ctrl_handler hdl;
+   struct v4l2_ctrl *bandwidth_auto;
+   struct v4l2_ctrl *bandwidth;
struct v4l2_ctrl *lna_gain_auto;
struct v4l2_ctrl *lna_gain;
struct v4l2_ctrl *mixer_gain_auto;
struct v4l2_ctrl *mixer_gain;
struct v4l2_ctrl *if_gain_auto;
struct v4l2_ctrl *if_gain;
-   struct v4l2_ctrl *ctrl_tuner_bw;
 
/* for sample rate calc */
unsigned int sample;
@@ -1003,12 +1001,23 @@ static int rtl2832_sdr_set_tuner(struct 
rtl2832_sdr_state *s)
/*
 * bandwidth (Hz)
 */
-   unsigned int bandwidth = s-ctrl_tuner_bw-val;
+   unsigned int bandwidth;
 
-   dev_dbg(s-udev-dev,
-   %s: f_rf=%u bandwidth=%d\n,
+   /* filters */
+   if (s-bandwidth_auto-val)
+   bandwidth = s-f_adc;
+   else
+   bandwidth = s-bandwidth-val;
+
+   s-bandwidth-val = bandwidth;
+
+   dev_dbg(s-udev-dev, %s: f_rf=%u bandwidth=%d\n,
__func__, f_rf, bandwidth);
 
+   c-bandwidth_hz = bandwidth;
+   c-frequency = f_rf;
+   c-delivery_system = SYS_DVBT;
+
if (f_rf == 0)
return 0;
 
@@ -1018,14 +1027,6 @@ static int rtl2832_sdr_set_tuner(struct 
rtl2832_sdr_state *s)
if (fe-ops.tuner_ops.init)
fe-ops.tuner_ops.init(fe);
 
-   /* user has not requested bandwidth so calculate automatically */
-   if (bandwidth == 0)
-   bandwidth = s-f_adc;
-
-   c-bandwidth_hz = bandwidth;
-   c-frequency = f_rf;
-   c-delivery_system = SYS_DVBT;
-
if (fe-ops.tuner_ops.set_params)
fe-ops.tuner_ops.set_params(fe);
 
@@ -1368,8 +1369,8 @@ static int rtl2832_sdr_s_ctrl(struct v4l2_ctrl *ctrl)
ctrl-minimum, ctrl-maximum, ctrl-step);
 
switch (ctrl-id) {
-   case RTL2832_SDR_CID_TUNER_BW:
-   case RTL2832_SDR_CID_TUNER_GAIN:
+   case V4L2_CID_BANDWIDTH_AUTO:
+   case V4L2_CID_BANDWIDTH:
ret = rtl2832_sdr_set_tuner(s);
break;
case  V4L2_CID_LNA_GAIN_AUTO:
@@ -1409,16 +1410,6 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
struct rtl2832_sdr_state *s;
const struct v4l2_ctrl_ops *ops = rtl2832_sdr_ctrl_ops;
struct dvb_usb_device *d = i2c_get_adapdata(i2c);
-   static const struct v4l2_ctrl_config ctrl_tuner_bw = {
-   .ops= rtl2832_sdr_ctrl_ops,
-   .id = RTL2832_SDR_CID_TUNER_BW,
-   .type   = V4L2_CTRL_TYPE_INTEGER,
-   .name   = Tuner BW,
-   .min= 0,
-   .max= INT_MAX,
-   .def= 0,
-   .step   = 1,
-   };
 
s = kzalloc(sizeof(struct rtl2832_sdr_state), GFP_KERNEL);
if (s == NULL) {
@@ -1458,8 +1449,10 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
/* Register controls */
switch (s-cfg-tuner) {
case RTL2832_TUNER_E4000:
-   v4l2_ctrl_handler_init(s-hdl, 7);
-   s-ctrl_tuner_bw = v4l2_ctrl_new_custom(s-hdl, 
ctrl_tuner_bw, NULL);
+   v4l2_ctrl_handler_init(s-hdl, 8);
+   s-bandwidth_auto = v4l2_ctrl_new_std(s-hdl, ops, 
V4L2_CID_BANDWIDTH_AUTO, 0, 1, 1, 1);
+   s-bandwidth = v4l2_ctrl_new_std(s-hdl, ops, 
V4L2_CID_BANDWIDTH, 430, 1100, 10, 430);
+   v4l2_ctrl_auto_cluster(2, s-bandwidth_auto, 0, false);
s-lna_gain_auto = v4l2_ctrl_new_std(s-hdl, ops, 
V4L2_CID_LNA_GAIN_AUTO, 0, 1, 1, 1);
s-lna_gain = v4l2_ctrl_new_std(s-hdl, ops, 
V4L2_CID_LNA_GAIN, 0, 15, 1, 10);
v4l2_ctrl_auto_cluster(2, s-lna_gain_auto, 0, false);
@@ -1471,7 +1464,10 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
v4l2_ctrl_auto_cluster(2, s-if_gain_auto, 0, false);
break;
case RTL2832_TUNER_R820T:
-  

[REVIEW PATCH 51/86] DocBook: V4L: add V4L2_SDR_FMT_CU16LE - 'CU16'

2014-02-09 Thread Antti Palosaari
Document V4L2_SDR_FMT_CU16LE format.
It is complex unsigned 16-bit little endian IQ sample. Used by
software defined radio devices.

Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
Acked-by: Hans Verkuil hans.verk...@cisco.com
---
 .../DocBook/media/v4l/pixfmt-sdr-cu16le.xml| 46 ++
 Documentation/DocBook/media/v4l/pixfmt.xml |  1 +
 2 files changed, 47 insertions(+)
 create mode 100644 Documentation/DocBook/media/v4l/pixfmt-sdr-cu16le.xml

diff --git a/Documentation/DocBook/media/v4l/pixfmt-sdr-cu16le.xml 
b/Documentation/DocBook/media/v4l/pixfmt-sdr-cu16le.xml
new file mode 100644
index 000..26288ff
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/pixfmt-sdr-cu16le.xml
@@ -0,0 +1,46 @@
+refentry id=V4L2-SDR-FMT-CU16LE
+  refmeta
+refentrytitleV4L2_SDR_FMT_CU16LE ('CU16')/refentrytitle
+manvol;
+  /refmeta
+refnamediv
+  refname
+constantV4L2_SDR_FMT_CU16LE/constant
+  /refname
+  refpurposeComplex unsigned 16-bit little endian IQ sample/refpurpose
+/refnamediv
+refsect1
+  titleDescription/title
+  para
+This format contains sequence of complex number samples. Each complex number
+consist two parts, called In-phase and Quadrature (IQ). Both I and Q are
+represented as a 16 bit unsigned little endian number. I value comes first
+and Q value after that.
+  /para
+example
+  titleconstantV4L2_SDR_FMT_CU16LE/constant 1 sample/title
+  formalpara
+titleByte Order./title
+paraEach cell is one byte.
+  informaltable frame=none
+tgroup cols=3 align=center
+  colspec align=left colwidth=2* /
+  tbody valign=top
+row
+  entrystartnbsp;+nbsp;0:/entry
+  entryI'subscript0[7:0]/subscript/entry
+  entryI'subscript0[15:8]/subscript/entry
+/row
+row
+  entrystartnbsp;+nbsp;2:/entry
+  entryQ'subscript0[7:0]/subscript/entry
+  entryQ'subscript0[15:8]/subscript/entry
+/row
+  /tbody
+/tgroup
+  /informaltable
+/para
+  /formalpara
+/example
+  /refsect1
+/refentry
diff --git a/Documentation/DocBook/media/v4l/pixfmt.xml 
b/Documentation/DocBook/media/v4l/pixfmt.xml
index 40adcb8..f535d9b 100644
--- a/Documentation/DocBook/media/v4l/pixfmt.xml
+++ b/Documentation/DocBook/media/v4l/pixfmt.xml
@@ -818,6 +818,7 @@ extended control 
constantV4L2_CID_MPEG_STREAM_TYPE/constant, see
 interface only./para
 
 sub-sdr-cu08;
+sub-sdr-cu16le;
 
   /section
 
-- 
1.8.5.3

--
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


[REVIEW PATCH 50/86] DocBook: V4L: add V4L2_SDR_FMT_CU8 - 'CU08'

2014-02-09 Thread Antti Palosaari
Document V4L2_SDR_FMT_CU8 SDR format.
It is complex unsigned 8-bit IQ sample. Used by software defined
radio devices.

Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
Acked-by: Hans Verkuil hans.verk...@cisco.com
---
 .../DocBook/media/v4l/pixfmt-sdr-cu08.xml  | 44 ++
 Documentation/DocBook/media/v4l/pixfmt.xml |  2 +
 2 files changed, 46 insertions(+)
 create mode 100644 Documentation/DocBook/media/v4l/pixfmt-sdr-cu08.xml

diff --git a/Documentation/DocBook/media/v4l/pixfmt-sdr-cu08.xml 
b/Documentation/DocBook/media/v4l/pixfmt-sdr-cu08.xml
new file mode 100644
index 000..2d80104
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/pixfmt-sdr-cu08.xml
@@ -0,0 +1,44 @@
+refentry id=V4L2-SDR-FMT-CU08
+  refmeta
+refentrytitleV4L2_SDR_FMT_CU8 ('CU08')/refentrytitle
+manvol;
+  /refmeta
+refnamediv
+  refname
+constantV4L2_SDR_FMT_CU8/constant
+  /refname
+  refpurposeComplex unsigned 8-bit IQ sample/refpurpose
+/refnamediv
+refsect1
+  titleDescription/title
+  para
+This format contains sequence of complex number samples. Each complex number
+consist two parts, called In-phase and Quadrature (IQ). Both I and Q are
+represented as a 8 bit unsigned number. I value comes first and Q value after
+that.
+  /para
+example
+  titleconstantV4L2_SDR_FMT_CU8/constant 1 sample/title
+  formalpara
+titleByte Order./title
+paraEach cell is one byte.
+  informaltable frame=none
+tgroup cols=2 align=center
+  colspec align=left colwidth=2* /
+  tbody valign=top
+row
+  entrystartnbsp;+nbsp;0:/entry
+  entryI'subscript0/subscript/entry
+/row
+row
+  entrystartnbsp;+nbsp;1:/entry
+  entryQ'subscript0/subscript/entry
+/row
+  /tbody
+/tgroup
+  /informaltable
+/para
+  /formalpara
+/example
+  /refsect1
+/refentry
diff --git a/Documentation/DocBook/media/v4l/pixfmt.xml 
b/Documentation/DocBook/media/v4l/pixfmt.xml
index f586d34..40adcb8 100644
--- a/Documentation/DocBook/media/v4l/pixfmt.xml
+++ b/Documentation/DocBook/media/v4l/pixfmt.xml
@@ -817,6 +817,8 @@ extended control 
constantV4L2_CID_MPEG_STREAM_TYPE/constant, see
 paraThese formats are used for link linkend=sdrSDR Capture/link
 interface only./para
 
+sub-sdr-cu08;
+
   /section
 
   section id=pixfmt-reserved
-- 
1.8.5.3

--
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] af9035: Move it913x single devices to af9035

2014-02-09 Thread Malcolm Priestley
On Sat, 2014-02-08 at 16:11 +, Malcolm Priestley wrote:
 The generic v1 and v2 devices have been all tested.
 
 IDs tested
 USB_PID_ITETECH_IT9135 v1  v2
 USB_PID_ITETECH_IT9135_9005 v1
 USB_PID_ITETECH_IT9135_9006 v2
 
 Current Issues
 There is no signal  on
 USB_PID_ITETECH_IT9135 v2 
 
 No SNR reported all devices.
 
 All single devices tune and scan fine.
 
 All remotes tested okay.
 
 Dual device failed to register second adapter
 USB_PID_KWORLD_UB499_2T_T09
 It is not clear what the problem is at the moment.
Hi Antti

I have found the problem here.

state-eeprom_addr + EEPROM_2ND_DEMOD_ADDR

contains no value

So on 9135 devices register 0x4bfb and the I2C address
(state-af9033_config[1].i2c_addr) need to be set to 0x3a.

I have only manually changed these and both adapters work fine.

Also, I can't find pick up for register 0xcfff although it appears
to be on by default.

I will try and do a patch later and the patch for remaining ids in
it913x.

Regards


Malcolm

--
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


[REVIEW PATCH 58/86] msi3101: use msi001 tuner driver

2014-02-09 Thread Antti Palosaari
Remove MSi001 RF tuner related code as MSi001 functionality is moved
to own driver.

Implement SPI master adapter.

Attach MSi001 driver via SPI / V4L subdev framework.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/Kconfig   |   3 +-
 drivers/staging/media/msi3101/sdr-msi3101.c | 438 
 2 files changed, 122 insertions(+), 319 deletions(-)

diff --git a/drivers/staging/media/msi3101/Kconfig 
b/drivers/staging/media/msi3101/Kconfig
index 97d5210..de0b3bb 100644
--- a/drivers/staging/media/msi3101/Kconfig
+++ b/drivers/staging/media/msi3101/Kconfig
@@ -1,8 +1,9 @@
 config USB_MSI3101
tristate Mirics MSi3101 SDR Dongle
-   depends on USB  VIDEO_DEV  VIDEO_V4L2
+   depends on USB  VIDEO_DEV  VIDEO_V4L2  SPI
select VIDEOBUF2_CORE
select VIDEOBUF2_VMALLOC
+   select MEDIA_TUNER_MSI001
 
 config MEDIA_TUNER_MSI001
tristate Mirics MSi001
diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 49e5bd1..6159d88 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -25,7 +25,6 @@
 
 #include linux/module.h
 #include linux/slab.h
-#include linux/gcd.h
 #include asm/div64.h
 #include media/v4l2-device.h
 #include media/v4l2-ioctl.h
@@ -33,6 +32,7 @@
 #include media/v4l2-event.h
 #include linux/usb.h
 #include media/videobuf2-vmalloc.h
+#include linux/spi/spi.h
 
 /*
  *   iConfiguration  0
@@ -130,6 +130,8 @@ struct msi3101_frame_buf {
 struct msi3101_state {
struct video_device vdev;
struct v4l2_device v4l2_dev;
+   struct v4l2_subdev *v4l2_subdev;
+   struct spi_master *master;
 
/* videobuf2 queue and queued buffers list */
struct vb2_queue vb_queue;
@@ -143,7 +145,7 @@ struct msi3101_state {
/* Pointer to our usb_device, will be NULL after unplug */
struct usb_device *udev; /* Both mutexes most be hold when setting! */
 
-   unsigned int f_adc, f_tuner;
+   unsigned int f_adc;
u32 pixelformat;
 
unsigned int isoc_errors; /* number of contiguous ISOC errors */
@@ -155,14 +157,6 @@ struct msi3101_state {
 
/* Controls */
struct v4l2_ctrl_handler hdl;
-   struct v4l2_ctrl *bandwidth_auto;
-   struct v4l2_ctrl *bandwidth;
-   struct v4l2_ctrl *lna_gain_auto;
-   struct v4l2_ctrl *lna_gain;
-   struct v4l2_ctrl *mixer_gain_auto;
-   struct v4l2_ctrl *mixer_gain;
-   struct v4l2_ctrl *if_gain_auto;
-   struct v4l2_ctrl *if_gain;
 
u32 next_sample; /* for track lost packets */
u32 sample; /* for sample rate calc */
@@ -824,9 +818,9 @@ static void msi3101_disconnect(struct usb_interface *intf)
mutex_lock(s-v4l2_lock);
/* No need to keep the urbs around after disconnection */
s-udev = NULL;
-
v4l2_device_disconnect(s-v4l2_dev);
video_unregister_device(s-vdev);
+   spi_unregister_master(s-master);
mutex_unlock(s-v4l2_lock);
mutex_unlock(s-vb_queue_lock);
 
@@ -926,20 +920,25 @@ static int msi3101_ctrl_msg(struct msi3101_state *s, u8 
cmd, u32 data)
return ret;
 };
 
-static int msi3101_tuner_write(struct msi3101_state *s, u32 data)
-{
-   return msi3101_ctrl_msg(s, CMD_WREG, data  8 | 0x09);
-};
-
 #define F_REF 2400
 #define DIV_R_IN 2
 static int msi3101_set_usb_adc(struct msi3101_state *s)
 {
int ret, div_n, div_m, div_r_out, f_sr, f_vco, fract;
u32 reg3, reg4, reg7;
+   struct v4l2_ctrl *bandwidth_auto;
+   struct v4l2_ctrl *bandwidth;
 
f_sr = s-f_adc;
 
+   /* set tuner, subdev, filters according to sampling rate */
+   bandwidth_auto = v4l2_ctrl_find(s-hdl, V4L2_CID_BANDWIDTH_AUTO);
+   bandwidth = v4l2_ctrl_find(s-hdl, V4L2_CID_BANDWIDTH);
+   if (v4l2_ctrl_g_ctrl(bandwidth_auto)) {
+   bandwidth = v4l2_ctrl_find(s-hdl, V4L2_CID_BANDWIDTH);
+   v4l2_ctrl_s_ctrl(bandwidth, s-f_adc);
+   }
+
/* select stream format */
switch (s-pixelformat) {
case V4L2_PIX_FMT_SDR_U8:
@@ -1068,222 +1067,6 @@ err:
return ret;
 };
 
-static int msi3101_set_gain(struct msi3101_state *s)
-{
-   int ret;
-   u32 reg;
-   dev_dbg(s-udev-dev, %s: lna=%d mixer=%d if=%d\n, __func__,
-   s-lna_gain-val, s-mixer_gain-val, s-if_gain-val);
-
-   reg = 1  0;
-   reg |= (59 - s-if_gain-val)  4;
-   reg |= 0  10;
-   reg |= (1 - s-mixer_gain-val)  12;
-   reg |= (1 - s-lna_gain-val)  13;
-   reg |= 4  14;
-   reg |= 0  17;
-   ret = msi3101_tuner_write(s, reg);
-   if (ret)
-   goto err;
-
-   return 0;
-err:
-   dev_dbg(s-udev-dev, %s: failed %d\n, __func__, ret);
-   return ret;
-};
-
-static int msi3101_set_tuner(struct msi3101_state *s)
-{
-   int ret, i;
-   unsigned int n, m, thresh, frac, vco_step, 

[REVIEW PATCH 52/86] DocBook: media: document V4L2_CTRL_CLASS_RF_TUNER

2014-02-09 Thread Antti Palosaari
It is class for RF tuner specific controls, like gain controls,
filters, signal strength.

Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml 
b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
index b3bb957..e9f6735 100644
--- a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
@@ -327,7 +327,12 @@ These controls are described in xref
 These controls are described in xref
linkend=fm-rx-controls /./entry
  /row
-
+ row
+   entryconstantV4L2_CTRL_CLASS_RF_TUNER/constant/entry
+   entry0xa2/entry
+   entryThe class containing RF tuner controls.
+These controls are described in xref linkend=rf-tuner-controls /./entry
+ /row
/tbody
   /tgroup
 /table
-- 
1.8.5.3

--
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


[REVIEW PATCH 60/86] MAINTAINERS: add msi3101 driver

2014-02-09 Thread Antti Palosaari
Mirics MSi2500 (MSi3101) SDR ADC + USB interface driver. Currently
in staging as SDR API is not ready.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 15ebabb..f03772a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5767,6 +5767,16 @@ T:   git git://linuxtv.org/anttip/media_tree.git
 S: Maintained
 F: drivers/staging/media/msi3101/msi001*
 
+MSI3101 MEDIA DRIVER
+M: Antti Palosaari cr...@iki.fi
+L: linux-media@vger.kernel.org
+W: http://linuxtv.org/
+W: http://palosaari.fi/linux/
+Q: http://patchwork.linuxtv.org/project/linux-media/list/
+T: git git://linuxtv.org/anttip/media_tree.git
+S: Maintained
+F: drivers/staging/media/msi3101/sdr-msi3101*
+
 MT9M032 APTINA SENSOR DRIVER
 M: Laurent Pinchart laurent.pinch...@ideasonboard.com
 L: linux-media@vger.kernel.org
-- 
1.8.5.3

--
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


[REVIEW PATCH 57/86] msi001: Mirics MSi001 silicon tuner driver

2014-02-09 Thread Antti Palosaari
That RF tuner driver is bound via SPI bus model and it implements V4L
subdev API. I split it out from MSi3101 SDR driver.
MSi3101 = MSi2500 + MSi001.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/Kconfig  |   4 +
 drivers/staging/media/msi3101/Makefile |   1 +
 drivers/staging/media/msi3101/msi001.c | 481 +
 3 files changed, 486 insertions(+)
 create mode 100644 drivers/staging/media/msi3101/msi001.c

diff --git a/drivers/staging/media/msi3101/Kconfig 
b/drivers/staging/media/msi3101/Kconfig
index 0c349c8..97d5210 100644
--- a/drivers/staging/media/msi3101/Kconfig
+++ b/drivers/staging/media/msi3101/Kconfig
@@ -3,3 +3,7 @@ config USB_MSI3101
depends on USB  VIDEO_DEV  VIDEO_V4L2
select VIDEOBUF2_CORE
select VIDEOBUF2_VMALLOC
+
+config MEDIA_TUNER_MSI001
+   tristate Mirics MSi001
+   depends on VIDEO_V4L2  SPI
diff --git a/drivers/staging/media/msi3101/Makefile 
b/drivers/staging/media/msi3101/Makefile
index 3730654..daf4f58 100644
--- a/drivers/staging/media/msi3101/Makefile
+++ b/drivers/staging/media/msi3101/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_USB_MSI3101) += sdr-msi3101.o
+obj-$(CONFIG_MEDIA_TUNER_MSI001)  += msi001.o
diff --git a/drivers/staging/media/msi3101/msi001.c 
b/drivers/staging/media/msi3101/msi001.c
new file mode 100644
index 000..5c5bb52
--- /dev/null
+++ b/drivers/staging/media/msi3101/msi001.c
@@ -0,0 +1,481 @@
+/*
+ * Mirics MSi001 silicon tuner driver
+ *
+ * Copyright (C) 2013 Antti Palosaari cr...@iki.fi
+ * Copyright (C) 2014 Antti Palosaari cr...@iki.fi
+ *
+ *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.
+ */
+
+#include linux/module.h
+#include linux/gcd.h
+#include media/v4l2-device.h
+#include media/v4l2-ctrls.h
+
+static const struct v4l2_frequency_band bands[] = {
+   {
+   .type = V4L2_TUNER_RF,
+   .index = 0,
+   .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
+   .rangelow   =   4900,
+   .rangehigh  =  26300,
+   }, {
+   .type = V4L2_TUNER_RF,
+   .index = 1,
+   .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
+   .rangelow   =  39000,
+   .rangehigh  =  96000,
+   },
+};
+
+struct msi001 {
+   struct spi_device *spi;
+   struct v4l2_subdev sd;
+
+   /* Controls */
+   struct v4l2_ctrl_handler hdl;
+   struct v4l2_ctrl *bandwidth_auto;
+   struct v4l2_ctrl *bandwidth;
+   struct v4l2_ctrl *lna_gain;
+   struct v4l2_ctrl *mixer_gain;
+   struct v4l2_ctrl *if_gain;
+
+   unsigned int f_tuner;
+};
+
+static inline struct msi001 *sd_to_msi001(struct v4l2_subdev *sd)
+{
+   return container_of(sd, struct msi001, sd);
+}
+
+static int msi001_wreg(struct msi001 *s, u32 data)
+{
+   /* Register format: 4 bits addr + 20 bits value */
+   return spi_write(s-spi, data, 3);
+};
+
+static int msi001_set_gain(struct msi001 *s, int lna_gain, int mixer_gain,
+   int if_gain)
+{
+   int ret;
+   u32 reg;
+   dev_dbg(s-spi-dev, %s: lna=%d mixer=%d if=%d\n, __func__,
+   lna_gain, mixer_gain, if_gain);
+
+   reg = 1  0;
+   reg |= (59 - if_gain)  4;
+   reg |= 0  10;
+   reg |= (1 - mixer_gain)  12;
+   reg |= (1 - lna_gain)  13;
+   reg |= 4  14;
+   reg |= 0  17;
+   ret = msi001_wreg(s, reg);
+   if (ret)
+   goto err;
+
+   return 0;
+err:
+   dev_dbg(s-spi-dev, %s: failed %d\n, __func__, ret);
+   return ret;
+};
+
+static int msi001_set_tuner(struct msi001 *s)
+{
+   int ret, i;
+   unsigned int n, m, thresh, frac, vco_step, tmp, f_if1;
+   u32 reg;
+   u64 f_vco, tmp64;
+   u8 mode, filter_mode, lo_div;
+   static const struct {
+   u32 rf;
+   u8 mode;
+   u8 lo_div;
+   } band_lut[] = {
+   { 5000, 0xe1, 16}, /* AM_MODE2, antenna 2 */
+   {10800, 0x42, 32}, /* VHF_MODE */
+   {33000, 0x44, 16}, /* B3_MODE */
+   {96000, 0x48,  4}, /* B45_MODE */
+   {  ~0U, 0x50,  2}, /* BL_MODE */
+   };
+   static const struct {
+   u32 freq;
+   u8 filter_mode;
+   } if_freq_lut[] = {
+   {  0, 0x03}, /* Zero IF */
+   { 45, 0x02}, /* 450 kHz IF */
+   

[REVIEW PATCH 54/86] v4l: add RF tuner channel bandwidth control

2014-02-09 Thread Antti Palosaari
Modern silicon RF tuners has one or more adjustable filters on
signal path, in order to filter noise from desired radio channel.

Add channel bandwidth control to tell the driver which is radio
channel width we want receive. Filters could be then adjusted by
the driver or hardware, using RF frequency and channel bandwidth
as a base of filter calculations.

On automatic mode (normal mode), bandwidth is calculated from sampling
rate or tuning info got from userspace. That new control gives
possibility to set manual mode and let user have more control for
filters.

Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/v4l2-core/v4l2-ctrls.c | 4 
 include/uapi/linux/v4l2-controls.h   | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c 
b/drivers/media/v4l2-core/v4l2-ctrls.c
index d201f61..e44722b 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -865,6 +865,8 @@ const char *v4l2_ctrl_get_name(u32 id)
case V4L2_CID_MIXER_GAIN:   return Mixer Gain;
case V4L2_CID_IF_GAIN_AUTO: return IF Gain, Auto;
case V4L2_CID_IF_GAIN:  return IF Gain;
+   case V4L2_CID_BANDWIDTH_AUTO:   return Channel Bandwidth, 
Auto;
+   case V4L2_CID_BANDWIDTH:return Channel Bandwidth;
default:
return NULL;
}
@@ -917,6 +919,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
v4l2_ctrl_type *type,
case V4L2_CID_LNA_GAIN_AUTO:
case V4L2_CID_MIXER_GAIN_AUTO:
case V4L2_CID_IF_GAIN_AUTO:
+   case V4L2_CID_BANDWIDTH_AUTO:
*type = V4L2_CTRL_TYPE_BOOLEAN;
*min = 0;
*max = *step = 1;
@@ -1078,6 +1081,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
v4l2_ctrl_type *type,
case V4L2_CID_LNA_GAIN:
case V4L2_CID_MIXER_GAIN:
case V4L2_CID_IF_GAIN:
+   case V4L2_CID_BANDWIDTH:
*flags |= V4L2_CTRL_FLAG_SLIDER;
break;
case V4L2_CID_PAN_RELATIVE:
diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 076fa34..3cf68a6 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -905,5 +905,7 @@ enum v4l2_deemphasis {
 #define V4L2_CID_MIXER_GAIN(V4L2_CID_RF_TUNER_CLASS_BASE + 
4)
 #define V4L2_CID_IF_GAIN_AUTO  (V4L2_CID_RF_TUNER_CLASS_BASE + 
5)
 #define V4L2_CID_IF_GAIN   (V4L2_CID_RF_TUNER_CLASS_BASE + 
6)
+#define V4L2_CID_BANDWIDTH_AUTO
(V4L2_CID_RF_TUNER_CLASS_BASE + 7)
+#define V4L2_CID_BANDWIDTH (V4L2_CID_RF_TUNER_CLASS_BASE + 
8)
 
 #endif
-- 
1.8.5.3

--
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


[REVIEW PATCH 63/86] e4000: implement controls via v4l2 control framework

2014-02-09 Thread Antti Palosaari
Implement gain and bandwidth controls using v4l2 control framework.
Pointer to control handler is provided by exported symbol.

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/e4000.c  | 210 +-
 drivers/media/tuners/e4000.h  |  14 +++
 drivers/media/tuners/e4000_priv.h |  12 +++
 3 files changed, 235 insertions(+), 1 deletion(-)

diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index 9187190..77318e9 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -448,6 +448,178 @@ err:
return ret;
 }
 
+static int e4000_set_lna_gain(struct dvb_frontend *fe)
+{
+   struct e4000_priv *priv = fe-tuner_priv;
+   int ret;
+   u8 u8tmp;
+   dev_dbg(priv-client-dev, %s: lna auto=%d-%d val=%d-%d\n,
+   __func__, priv-lna_gain_auto-cur.val,
+   priv-lna_gain_auto-val, priv-lna_gain-cur.val,
+   priv-lna_gain-val);
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 1);
+
+   if (priv-lna_gain_auto-val  priv-if_gain_auto-cur.val)
+   u8tmp = 0x17;
+   else if (priv-lna_gain_auto-val)
+   u8tmp = 0x19;
+   else if (priv-if_gain_auto-cur.val)
+   u8tmp = 0x16;
+   else
+   u8tmp = 0x10;
+
+   ret = e4000_wr_reg(priv, 0x1a, u8tmp);
+   if (ret)
+   goto err;
+
+   if (priv-lna_gain_auto-val == false) {
+   ret = e4000_wr_reg(priv, 0x14, priv-lna_gain-val);
+   if (ret)
+   goto err;
+   }
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 0);
+
+   return 0;
+err:
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 0);
+
+   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
+   return ret;
+}
+
+static int e4000_set_mixer_gain(struct dvb_frontend *fe)
+{
+   struct e4000_priv *priv = fe-tuner_priv;
+   int ret;
+   u8 u8tmp;
+   dev_dbg(priv-client-dev, %s: mixer auto=%d-%d val=%d-%d\n,
+   __func__, priv-mixer_gain_auto-cur.val,
+   priv-mixer_gain_auto-val, priv-mixer_gain-cur.val,
+   priv-mixer_gain-val);
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 1);
+
+   if (priv-mixer_gain_auto-val)
+   u8tmp = 0x15;
+   else
+   u8tmp = 0x14;
+
+   ret = e4000_wr_reg(priv, 0x20, u8tmp);
+   if (ret)
+   goto err;
+
+   if (priv-mixer_gain_auto-val == false) {
+   ret = e4000_wr_reg(priv, 0x15, priv-mixer_gain-val);
+   if (ret)
+   goto err;
+   }
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 0);
+
+   return 0;
+err:
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 0);
+
+   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
+   return ret;
+}
+
+static int e4000_set_if_gain(struct dvb_frontend *fe)
+{
+   struct e4000_priv *priv = fe-tuner_priv;
+   int ret;
+   u8 buf[2];
+   u8 u8tmp;
+   dev_dbg(priv-client-dev, %s: if auto=%d-%d val=%d-%d\n,
+   __func__, priv-if_gain_auto-cur.val,
+   priv-if_gain_auto-val, priv-if_gain-cur.val,
+   priv-if_gain-val);
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 1);
+
+   if (priv-if_gain_auto-val  priv-lna_gain_auto-cur.val)
+   u8tmp = 0x17;
+   else if (priv-lna_gain_auto-cur.val)
+   u8tmp = 0x19;
+   else if (priv-if_gain_auto-val)
+   u8tmp = 0x16;
+   else
+   u8tmp = 0x10;
+
+   ret = e4000_wr_reg(priv, 0x1a, u8tmp);
+   if (ret)
+   goto err;
+
+   if (priv-if_gain_auto-val == false) {
+   buf[0] = e4000_if_gain_lut[priv-if_gain-val].reg16_val;
+   buf[1] = e4000_if_gain_lut[priv-if_gain-val].reg17_val;
+   ret = e4000_wr_regs(priv, 0x16, buf, 2);
+   if (ret)
+   goto err;
+   }
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 0);
+
+   return 0;
+err:
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 0);
+
+   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
+   return ret;
+}
+
+static int e4000_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct e4000_priv *priv =
+   container_of(ctrl-handler, struct e4000_priv, hdl);
+   struct dvb_frontend *fe = priv-fe;
+   struct dtv_frontend_properties *c = fe-dtv_property_cache;
+   int ret;
+   dev_dbg(priv-client-dev,
+   %s: id=%d name=%s val=%d min=%d max=%d 

[REVIEW PATCH 69/86] v4l: uapi: add SDR formats CU8 and CU16LE

2014-02-09 Thread Antti Palosaari
V4L2_SDR_FMT_CU8 — Complex unsigned 8-bit IQ sample
V4L2_SDR_FMT_CU16LE — Complex unsigned 16-bit little endian IQ sample

Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 include/uapi/linux/videodev2.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 27fedfe..3411215 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -436,6 +436,10 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_SE401  v4l2_fourcc('S', '4', '0', '1') /* se401 
janggu compressed rgb */
 #define V4L2_PIX_FMT_S5C_UYVY_JPG v4l2_fourcc('S', '5', 'C', 'I') /* S5C73M3 
interleaved UYVY/JPEG */
 
+/* SDR formats - used only for Software Defined Radio devices */
+#define V4L2_SDR_FMT_CU8  v4l2_fourcc('C', 'U', '0', '8') /* IQ u8 */
+#define V4L2_SDR_FMT_CU16LE   v4l2_fourcc('C', 'U', '1', '6') /* IQ u16le 
*/
+
 /*
  * F O R M A T   E N U M E R A T I O N
  */
-- 
1.8.5.3

--
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


[REVIEW PATCH 72/86] v4l: add enum_freq_bands support to tuner sub-device

2014-02-09 Thread Antti Palosaari
Add VIDIOC_ENUM_FREQ_BANDS, enumerate supported frequency bands,
IOCTL support for sub-device tuners too.

Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 include/media/v4l2-subdev.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index d67210a..4682aad 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -192,6 +192,7 @@ struct v4l2_subdev_tuner_ops {
int (*s_radio)(struct v4l2_subdev *sd);
int (*s_frequency)(struct v4l2_subdev *sd, const struct v4l2_frequency 
*freq);
int (*g_frequency)(struct v4l2_subdev *sd, struct v4l2_frequency *freq);
+   int (*enum_freq_bands)(struct v4l2_subdev *sd, struct 
v4l2_frequency_band *band);
int (*g_tuner)(struct v4l2_subdev *sd, struct v4l2_tuner *vt);
int (*s_tuner)(struct v4l2_subdev *sd, const struct v4l2_tuner *vt);
int (*g_modulator)(struct v4l2_subdev *sd, struct v4l2_modulator *vm);
-- 
1.8.5.3

--
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


[REVIEW PATCH 75/86] r820t/rtl2832u_sdr: implement gains using v4l2 controls

2014-02-09 Thread Antti Palosaari
Implement gain controls using v4l2 control framework.
Pointer to control handler is provided by exported symbol.

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/r820t.c | 175 ++-
 drivers/media/tuners/r820t.h |  17 ++-
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c |  72 +-
 3 files changed, 151 insertions(+), 113 deletions(-)

diff --git a/drivers/media/tuners/r820t.c b/drivers/media/tuners/r820t.c
index 231c614..5150a18 100644
--- a/drivers/media/tuners/r820t.c
+++ b/drivers/media/tuners/r820t.c
@@ -36,6 +36,7 @@
 #include linux/mutex.h
 #include linux/slab.h
 #include linux/bitrev.h
+#include media/v4l2-ctrls.h
 
 #include tuner-i2c.h
 #include r820t.h
@@ -80,6 +81,7 @@ struct r820t_sect_type {
 
 struct r820t_priv {
struct list_headhybrid_tuner_instance_list;
+   struct dvb_frontend *fe;
const struct r820t_config   *cfg;
struct tuner_i2c_props  i2c_props;
struct mutexlock;
@@ -100,6 +102,15 @@ struct r820t_priv {
enum v4l2_tuner_typetype;
v4l2_std_id std;
u32 bw; /* in MHz */
+
+   /* Controls */
+   struct v4l2_ctrl_handler hdl;
+   struct v4l2_ctrl *lna_gain_auto;
+   struct v4l2_ctrl *lna_gain;
+   struct v4l2_ctrl *mixer_gain_auto;
+   struct v4l2_ctrl *mixer_gain;
+   struct v4l2_ctrl *if_gain_auto;
+   struct v4l2_ctrl *if_gain;
 };
 
 struct r820t_freq_range {
@@ -1251,43 +1262,6 @@ static int r820t_set_gain_mode(struct r820t_priv *priv,
 }
 #endif
 
-static int r820t_set_config(struct dvb_frontend *fe, void *priv_cfg)
-{
-   struct r820t_priv *priv = fe-tuner_priv;
-   struct r820t_ctrl *ctrl = priv_cfg;
-   int rc;
-
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 1);
-
-   if (ctrl-lna_gain == INT_MIN)
-   rc = r820t_write_reg_mask(priv, 0x05, 0x00, 0x10);
-   else
-   rc = r820t_write_reg_mask(priv, 0x05,
-   0x10 | ctrl-lna_gain, 0x1f);
-   if (rc  0)
-   goto err;
-
-   if (ctrl-mixer_gain == INT_MIN)
-   rc = r820t_write_reg_mask(priv, 0x07, 0x10, 0x10);
-   else
-   rc = r820t_write_reg_mask(priv, 0x07,
-   0x00 | ctrl-mixer_gain, 0x1f);
-   if (rc  0)
-   goto err;
-
-   if (ctrl-if_gain == INT_MIN)
-   rc = r820t_write_reg_mask(priv, 0x0c, 0x10, 0x10);
-   else
-   rc = r820t_write_reg_mask(priv, 0x0c,
-   0x00 | ctrl-if_gain, 0x1f);
-err:
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
-
-   return rc;
-}
-
 static int generic_set_freq(struct dvb_frontend *fe,
u32 freq /* in HZ */,
unsigned bw,
@@ -2292,8 +2266,10 @@ static int r820t_release(struct dvb_frontend *fe)
 
mutex_lock(r820t_list_mutex);
 
-   if (priv)
+   if (priv) {
+   v4l2_ctrl_handler_free(priv-hdl);
hybrid_tuner_release_state(priv);
+   }
 
mutex_unlock(r820t_list_mutex);
 
@@ -2302,6 +2278,96 @@ static int r820t_release(struct dvb_frontend *fe)
return 0;
 }
 
+static int r820t_set_lna_gain(struct r820t_priv *priv)
+{
+   struct dvb_frontend *fe = priv-fe;
+   int rc;
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 1);
+
+   if (priv-lna_gain_auto-val)
+   rc = r820t_write_reg_mask(priv, 0x05, 0x00, 0x10);
+   else
+   rc = r820t_write_reg_mask(priv, 0x05,
+   0x10 | priv-lna_gain-val, 0x1f);
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 0);
+
+   return rc;
+}
+
+static int r820t_set_mixer_gain(struct r820t_priv *priv)
+{
+   struct dvb_frontend *fe = priv-fe;
+   int rc;
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 1);
+
+   if (priv-mixer_gain_auto-val)
+   rc = r820t_write_reg_mask(priv, 0x07, 0x10, 0x10);
+   else
+   rc = r820t_write_reg_mask(priv, 0x07,
+   0x00 | priv-mixer_gain-val, 0x1f);
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 0);
+
+   return rc;
+}
+
+static int r820t_set_if_gain(struct r820t_priv *priv)
+{
+   struct dvb_frontend *fe = priv-fe;
+   int rc;
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 1);
+
+   if (priv-if_gain_auto-val)
+   rc = r820t_write_reg_mask(priv, 0x0c, 0x10, 0x10);
+   else
+   rc = r820t_write_reg_mask(priv, 0x0c,
+   0x00 | 

[REVIEW PATCH 83/86] rtl28xxu: use muxed RTL2832 I2C adapters for E4000 and RTL2832_SDR

2014-02-09 Thread Antti Palosaari
RTL2832 driver provides muxed I2C adapters for tuner bus I2C gate
control. Pass those adapters to rtl2832_sdr and e4000 modules in order
to get rid of proprietary DVB .i2c_gate_ctrl() callback use.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 12 ++--
 drivers/media/usb/dvb-usb-v2/rtl28xxu.h |  1 +
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index afafe92..e04a3e9 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -774,6 +774,9 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter 
*adap)
goto err;
}
 
+   /* RTL2832 I2C repeater */
+   priv-demod_i2c_adapter = rtl2832_get_i2c_adapter(adap-fe[0]);
+
/* set fe callback */
adap-fe[0]-callback = rtl2832u_frontend_callback;
 
@@ -920,6 +923,8 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
rtl28xxu_rtl2832_fc0013_config);
break;
case TUNER_RTL2832_E4000: {
+   struct i2c_adapter *i2c_adap_internal =
+   
rtl2832_get_private_i2c_adapter(adap-fe[0]);
struct e4000_config e4000_config = {
.fe = adap-fe[0],
.clock = 2880,
@@ -930,11 +935,14 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
info.platform_data = e4000_config;
 
request_module(e4000);
-   priv-client = i2c_new_device(d-i2c_adap, info);
+   priv-client = i2c_new_device(priv-demod_i2c_adapter,
+   info);
+
+   i2c_set_adapdata(i2c_adap_internal, d);
 
/* attach SDR */
dvb_attach(rtl2832_sdr_attach, adap-fe[0],
-   d-i2c_adap,
+   i2c_adap_internal,
rtl28xxu_rtl2832_e4000_config);
}
break;
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.h 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
index 367aca1..a26cab1 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
@@ -55,6 +55,7 @@ struct rtl28xxu_priv {
u8 tuner;
char *tuner_name;
u8 page; /* integrated demod active register page */
+   struct i2c_adapter *demod_i2c_adapter;
bool rc_active;
struct i2c_client *client;
 };
-- 
1.8.5.3

--
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 RFC 0/2] drivers/base: simplify simple DT-based components

2014-02-09 Thread Jean-Francois Moine
On Fri, 7 Feb 2014 20:23:51 +
Russell King - ARM Linux li...@arm.linux.org.uk wrote:

 Here's my changes to the TDA998x driver to add support for the component
 helper.  The TDA998x driver retains support for the old way so that
 drivers can be transitioned.  For any one DRM card the transition to

I rewrote the tda998x as a simple encoder+connector (i.e. not a
slave_encoder) with your component helper, and the code is much clearer
and simpler: the DRM driver has nothing to do except to know that the
tda998x is a component and to set the possible_crtcs.

AFAIK, only the tilcdc drm driver is using the tda998x as a
slave_encoder. It does a (encoder+connector) conversion to
(slave_encoder). Then, in your changes in the TDA998x, you do a
(slave_encoder) translation to (encoder+connector).
This seems rather complicated!

I think it would be easier to use your component helper and rewrite
(remove?) tilcdc_slave.c.

 And yes, I'm thinking that maybe moving compare_of() into the component
 support so that drivers can share this generic function may be a good
 idea.

This function exists already in drivers/of/platform.c as
of_dev_node_match(). It just needs to be exported.

-- 
Ken ar c'hentañ | ** Breizh ha Linux atav! **
Jef |   http://moinejf.free.fr/
--
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


[REVIEW PATCH 62/86] rtl28xxu: attach SDR module later

2014-02-09 Thread Antti Palosaari
SDR module was attached between demod and tuner. Change it happen
after tuner attached. We are going to implement V4L controls for
tuner drivers and those controls are loaded during SDR attach. Due to
that (tuner controls), tuner driver must be loaded before SDR module.

Also as we are here, limit SDR module loading only for those tuners
we support.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index 76cf0de..73348bf 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -777,10 +777,6 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter 
*adap)
/* set fe callback */
adap-fe[0]-callback = rtl2832u_frontend_callback;
 
-   /* attach SDR */
-   dvb_attach(rtl2832_sdr_attach, adap-fe[0], d-i2c_adap,
-   rtl2832_config);
-
return 0;
 err:
dev_dbg(d-udev-dev, %s: failed=%d\n, __func__, ret);
@@ -906,6 +902,10 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
 * that to the tuner driver */
adap-fe[0]-ops.read_signal_strength =
adap-fe[0]-ops.tuner_ops.get_rf_strength;
+
+   /* attach SDR */
+   dvb_attach(rtl2832_sdr_attach, adap-fe[0], d-i2c_adap,
+   rtl28xxu_rtl2832_fc0012_config);
return 0;
break;
case TUNER_RTL2832_FC0013:
@@ -915,6 +915,10 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
/* fc0013 also supports signal strength reading */
adap-fe[0]-ops.read_signal_strength =
adap-fe[0]-ops.tuner_ops.get_rf_strength;
+
+   /* attach SDR */
+   dvb_attach(rtl2832_sdr_attach, adap-fe[0], d-i2c_adap,
+   rtl28xxu_rtl2832_fc0013_config);
return 0;
case TUNER_RTL2832_E4000: {
struct e4000_config e4000_config = {
@@ -928,6 +932,11 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
 
request_module(e4000);
priv-client = i2c_new_device(d-i2c_adap, info);
+
+   /* attach SDR */
+   dvb_attach(rtl2832_sdr_attach, adap-fe[0],
+   d-i2c_adap,
+   rtl28xxu_rtl2832_e4000_config);
}
break;
case TUNER_RTL2832_FC2580:
@@ -954,6 +963,10 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
/* Use tuner to get the signal strength */
adap-fe[0]-ops.read_signal_strength =
adap-fe[0]-ops.tuner_ops.get_rf_strength;
+
+   /* attach SDR */
+   dvb_attach(rtl2832_sdr_attach, adap-fe[0], d-i2c_adap,
+   rtl28xxu_rtl2832_r820t_config);
break;
case TUNER_RTL2832_R828D:
/* power off mn88472 demod on GPIO0 */
-- 
1.8.5.3

--
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


[REVIEW PATCH 82/86] rtl2832: implement delayed I2C gate close

2014-02-09 Thread Antti Palosaari
Delay possible I2C gate close a little bit in order to see if there
is next message coming to tuner in a sequence.

Also, export private muxed I2C adapter. That is aimed only for SDR
extension module as SDR belongs to same RTL2832 physical I2C bus (it
is physically property of RTL2832, whilst it is own kernel module).

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/dvb-frontends/rtl2832.c  | 92 +-
 drivers/media/dvb-frontends/rtl2832.h  | 12 
 drivers/media/dvb-frontends/rtl2832_priv.h |  1 +
 3 files changed, 102 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-frontends/rtl2832.c 
b/drivers/media/dvb-frontends/rtl2832.c
index cfc5438..fdbed35 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -891,16 +891,65 @@ static void rtl2832_release(struct dvb_frontend *fe)
struct rtl2832_priv *priv = fe-demodulator_priv;
 
dev_dbg(priv-i2c-dev, %s:\n, __func__);
+   cancel_delayed_work_sync(priv-i2c_gate_work);
i2c_del_mux_adapter(priv-i2c_adapter_tuner);
i2c_del_mux_adapter(priv-i2c_adapter);
kfree(priv);
 }
 
+/*
+ * Delay mechanism to avoid unneeded I2C gate open / close. Gate close is
+ * delayed here a little bit in order to see if there is sequence of I2C
+ * messages sent to same I2C bus.
+ * We must use unlocked version of __i2c_transfer() in order to avoid deadlock
+ * as lock is already taken by calling muxed i2c_transfer().
+ */
+static void rtl2832_i2c_gate_work(struct work_struct *work)
+{
+   struct rtl2832_priv *priv = container_of(work,
+   struct rtl2832_priv, i2c_gate_work.work);
+   struct i2c_adapter *adap = priv-i2c;
+   int ret;
+   u8 buf[2];
+   struct i2c_msg msg[1] = {
+   {
+   .addr = priv-cfg.i2c_addr,
+   .flags = 0,
+   .len = sizeof(buf),
+   .buf = buf,
+   }
+   };
+
+   /* select reg bank 1 */
+   buf[0] = 0x00;
+   buf[1] = 0x01;
+   ret = __i2c_transfer(adap, msg, 1);
+   if (ret != 1)
+   goto err;
+
+   priv-page = 1;
+
+   /* close I2C repeater gate */
+   buf[0] = 0x01;
+   buf[1] = 0x10;
+   ret = __i2c_transfer(adap, msg, 1);
+   if (ret != 1)
+   goto err;
+
+   priv-i2c_gate_state = 0;
+
+   return;
+err:
+   dev_dbg(priv-i2c-dev, %s: failed=%d\n, __func__, ret);
+
+   return;
+}
+
 static int rtl2832_select(struct i2c_adapter *adap, void *mux_priv, u32 
chan_id)
 {
struct rtl2832_priv *priv = mux_priv;
int ret;
-   u8 buf[2];
+   u8 buf[2], val;
struct i2c_msg msg[1] = {
{
.addr = priv-cfg.i2c_addr,
@@ -909,6 +958,22 @@ static int rtl2832_select(struct i2c_adapter *adap, void 
*mux_priv, u32 chan_id)
.buf = buf,
}
};
+   struct i2c_msg msg_rd[2] = {
+   {
+   .addr = priv-cfg.i2c_addr,
+   .flags = 0,
+   .len = 1,
+   .buf = \x01,
+   }, {
+   .addr = priv-cfg.i2c_addr,
+   .flags = I2C_M_RD,
+   .len = 1,
+   .buf = val,
+   }
+   };
+
+   /* terminate possible gate closing */
+   cancel_delayed_work_sync(priv-i2c_gate_work);
 
if (priv-i2c_gate_state == chan_id)
return 0;
@@ -916,13 +981,17 @@ static int rtl2832_select(struct i2c_adapter *adap, void 
*mux_priv, u32 chan_id)
/* select reg bank 1 */
buf[0] = 0x00;
buf[1] = 0x01;
-
ret = __i2c_transfer(adap, msg, 1);
if (ret != 1)
goto err;
 
priv-page = 1;
 
+   /* we must read that register, otherwise there will be errors */
+   ret = __i2c_transfer(adap, msg_rd, 2);
+   if (ret != 2)
+   goto err;
+
/* open or close I2C repeater gate */
buf[0] = 0x01;
if (chan_id == 1)
@@ -939,9 +1008,18 @@ static int rtl2832_select(struct i2c_adapter *adap, void 
*mux_priv, u32 chan_id)
return 0;
 err:
dev_dbg(priv-i2c-dev, %s: failed=%d\n, __func__, ret);
+
return -EREMOTEIO;
 }
 
+static int rtl2832_deselect(struct i2c_adapter *adap, void *mux_priv,
+   u32 chan_id)
+{
+   struct rtl2832_priv *priv = mux_priv;
+   schedule_delayed_work(priv-i2c_gate_work, usecs_to_jiffies(100));
+   return 0;
+}
+
 struct i2c_adapter *rtl2832_get_i2c_adapter(struct dvb_frontend *fe)
 {
struct rtl2832_priv *priv = fe-demodulator_priv;
@@ -949,6 +1027,13 @@ struct i2c_adapter *rtl2832_get_i2c_adapter(struct 
dvb_frontend *fe)
 }
 EXPORT_SYMBOL(rtl2832_get_i2c_adapter);
 
+struct i2c_adapter *rtl2832_get_private_i2c_adapter(struct dvb_frontend *fe)

[REVIEW PATCH 79/86] rtl2832: provide muxed I2C adapter

2014-02-09 Thread Antti Palosaari
RTL2832 provides gated / repeater I2C adapter for tuner.
Implement it as a muxed I2C adapter.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/dvb-frontends/Kconfig|  2 +-
 drivers/media/dvb-frontends/rtl2832.c  | 26 ++
 drivers/media/dvb-frontends/rtl2832.h  | 13 +
 drivers/media/dvb-frontends/rtl2832_priv.h |  2 ++
 4 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index dd12a1e..d701488 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -441,7 +441,7 @@ config DVB_RTL2830
 
 config DVB_RTL2832
tristate Realtek RTL2832 DVB-T
-   depends on DVB_CORE  I2C
+   depends on DVB_CORE  I2C  I2C_MUX
default m if !MEDIA_SUBDRV_AUTOSELECT
help
  Say Y when you want to support this frontend.
diff --git a/drivers/media/dvb-frontends/rtl2832.c 
b/drivers/media/dvb-frontends/rtl2832.c
index 00e63b9..dc46cf0 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -891,9 +891,29 @@ static void rtl2832_release(struct dvb_frontend *fe)
struct rtl2832_priv *priv = fe-demodulator_priv;
 
dev_dbg(priv-i2c-dev, %s:\n, __func__);
+   i2c_del_mux_adapter(priv-i2c_adapter);
kfree(priv);
 }
 
+static int rtl2832_select(struct i2c_adapter *adap, void *mux_priv, u32 chan)
+{
+   struct rtl2832_priv *priv = mux_priv;
+   return rtl2832_i2c_gate_ctrl(priv-fe, 1);
+}
+
+static int rtl2832_deselect(struct i2c_adapter *adap, void *mux_priv, u32 chan)
+{
+   struct rtl2832_priv *priv = mux_priv;
+   return rtl2832_i2c_gate_ctrl(priv-fe, 0);
+}
+
+struct i2c_adapter *rtl2832_get_i2c_adapter(struct dvb_frontend *fe)
+{
+   struct rtl2832_priv *priv = fe-demodulator_priv;
+   return priv-i2c_adapter;
+}
+EXPORT_SYMBOL(rtl2832_get_i2c_adapter);
+
 struct dvb_frontend *rtl2832_attach(const struct rtl2832_config *cfg,
struct i2c_adapter *i2c)
 {
@@ -918,6 +938,12 @@ struct dvb_frontend *rtl2832_attach(const struct 
rtl2832_config *cfg,
if (ret)
goto err;
 
+   /* create muxed i2c adapter */
+   priv-i2c_adapter = i2c_add_mux_adapter(i2c, i2c-dev, priv, 0, 0, 0,
+   rtl2832_select, rtl2832_deselect);
+   if (priv-i2c_adapter == NULL)
+   goto err;
+
/* create dvb_frontend */
memcpy(priv-fe.ops, rtl2832_ops, sizeof(struct dvb_frontend_ops));
priv-fe.demodulator_priv = priv;
diff --git a/drivers/media/dvb-frontends/rtl2832.h 
b/drivers/media/dvb-frontends/rtl2832.h
index fa4e5f6..a9202d7 100644
--- a/drivers/media/dvb-frontends/rtl2832.h
+++ b/drivers/media/dvb-frontends/rtl2832.h
@@ -55,7 +55,13 @@ struct dvb_frontend *rtl2832_attach(
const struct rtl2832_config *cfg,
struct i2c_adapter *i2c
 );
+
+extern struct i2c_adapter *rtl2832_get_i2c_adapter(
+   struct dvb_frontend *fe
+);
+
 #else
+
 static inline struct dvb_frontend *rtl2832_attach(
const struct rtl2832_config *config,
struct i2c_adapter *i2c
@@ -64,6 +70,13 @@ static inline struct dvb_frontend *rtl2832_attach(
pr_warn(%s: driver disabled by Kconfig\n, __func__);
return NULL;
 }
+
+static inline struct i2c_adapter *rtl2832_get_i2c_adapter(
+   struct dvb_frontend *fe
+)
+{
+   return NULL;
+}
 #endif
 
 
diff --git a/drivers/media/dvb-frontends/rtl2832_priv.h 
b/drivers/media/dvb-frontends/rtl2832_priv.h
index 4c845af..ec26c92 100644
--- a/drivers/media/dvb-frontends/rtl2832_priv.h
+++ b/drivers/media/dvb-frontends/rtl2832_priv.h
@@ -23,9 +23,11 @@
 
 #include dvb_frontend.h
 #include rtl2832.h
+#include linux/i2c-mux.h
 
 struct rtl2832_priv {
struct i2c_adapter *i2c;
+   struct i2c_adapter *i2c_adapter;
struct dvb_frontend fe;
struct rtl2832_config cfg;
 
-- 
1.8.5.3

--
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


[REVIEW PATCH 80/86] rtl2832: add muxed I2C adapter for demod itself

2014-02-09 Thread Antti Palosaari
There was a deadlock between master I2C adapter and muxed I2C
adapter. Implement two I2C muxed I2C adapters and leave master
alone, just only for offering I2C adapter for these mux adapters.

Reported-by: Luis Alves lja...@gmail.com
Reported-by: Benjamin Larsson benja...@southpole.se
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/dvb-frontends/rtl2832.c  | 71 --
 drivers/media/dvb-frontends/rtl2832_priv.h |  1 +
 2 files changed, 58 insertions(+), 14 deletions(-)

diff --git a/drivers/media/dvb-frontends/rtl2832.c 
b/drivers/media/dvb-frontends/rtl2832.c
index dc46cf0..c0366a8 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -180,7 +180,7 @@ static int rtl2832_wr(struct rtl2832_priv *priv, u8 reg, u8 
*val, int len)
buf[0] = reg;
memcpy(buf[1], val, len);
 
-   ret = i2c_transfer(priv-i2c, msg, 1);
+   ret = i2c_transfer(priv-i2c_adapter, msg, 1);
if (ret == 1) {
ret = 0;
} else {
@@ -210,7 +210,7 @@ static int rtl2832_rd(struct rtl2832_priv *priv, u8 reg, u8 
*val, int len)
}
};
 
-   ret = i2c_transfer(priv-i2c, msg, 2);
+   ret = i2c_transfer(priv-i2c_adapter, msg, 2);
if (ret == 2) {
ret = 0;
} else {
@@ -891,26 +891,61 @@ static void rtl2832_release(struct dvb_frontend *fe)
struct rtl2832_priv *priv = fe-demodulator_priv;
 
dev_dbg(priv-i2c-dev, %s:\n, __func__);
+   i2c_del_mux_adapter(priv-i2c_adapter_tuner);
i2c_del_mux_adapter(priv-i2c_adapter);
kfree(priv);
 }
 
-static int rtl2832_select(struct i2c_adapter *adap, void *mux_priv, u32 chan)
+static int rtl2832_select(struct i2c_adapter *adap, void *mux_priv, u32 
chan_id)
 {
struct rtl2832_priv *priv = mux_priv;
-   return rtl2832_i2c_gate_ctrl(priv-fe, 1);
-}
+   int ret;
+   u8 buf[2];
+   struct i2c_msg msg[1] = {
+   {
+   .addr = priv-cfg.i2c_addr,
+   .flags = 0,
+   .len = sizeof(buf),
+   .buf = buf,
+   }
+   };
 
-static int rtl2832_deselect(struct i2c_adapter *adap, void *mux_priv, u32 chan)
-{
-   struct rtl2832_priv *priv = mux_priv;
-   return rtl2832_i2c_gate_ctrl(priv-fe, 0);
+   if (priv-i2c_gate_state == chan_id)
+   return 0;
+
+   /* select reg bank 1 */
+   buf[0] = 0x00;
+   buf[1] = 0x01;
+
+   ret = i2c_transfer(adap, msg, 1);
+   if (ret != 1)
+   goto err;
+
+   priv-page = 1;
+
+   /* open or close I2C repeater gate */
+   buf[0] = 0x01;
+   if (chan_id == 1)
+   buf[1] = 0x18; /* open */
+   else
+   buf[1] = 0x10; /* close */
+
+   ret = i2c_transfer(adap, msg, 1);
+   if (ret != 1)
+   goto err;
+
+   priv-i2c_gate_state = chan_id;
+
+   return 0;
+err:
+   dev_dbg(priv-i2c-dev, %s: failed=%d\n, __func__, ret);
+   return -EREMOTEIO;
 }
 
 struct i2c_adapter *rtl2832_get_i2c_adapter(struct dvb_frontend *fe)
 {
struct rtl2832_priv *priv = fe-demodulator_priv;
-   return priv-i2c_adapter;
+   return priv-i2c_adapter_tuner;
 }
 EXPORT_SYMBOL(rtl2832_get_i2c_adapter);
 
@@ -933,15 +968,21 @@ struct dvb_frontend *rtl2832_attach(const struct 
rtl2832_config *cfg,
priv-tuner = cfg-tuner;
memcpy(priv-cfg, cfg, sizeof(struct rtl2832_config));
 
+   /* create muxed i2c adapter for demod itself */
+   priv-i2c_adapter = i2c_add_mux_adapter(i2c, i2c-dev, priv, 0, 0, 0,
+   rtl2832_select, NULL);
+   if (priv-i2c_adapter == NULL)
+   goto err;
+
/* check if the demod is there */
ret = rtl2832_rd_reg(priv, 0x00, 0x0, tmp);
if (ret)
goto err;
 
-   /* create muxed i2c adapter */
-   priv-i2c_adapter = i2c_add_mux_adapter(i2c, i2c-dev, priv, 0, 0, 0,
-   rtl2832_select, rtl2832_deselect);
-   if (priv-i2c_adapter == NULL)
+   /* create muxed i2c adapter for demod tuner bus */
+   priv-i2c_adapter_tuner = i2c_add_mux_adapter(i2c, i2c-dev, priv,
+   0, 1, 0, rtl2832_select, NULL);
+   if (priv-i2c_adapter_tuner == NULL)
goto err;
 
/* create dvb_frontend */
@@ -954,6 +995,8 @@ struct dvb_frontend *rtl2832_attach(const struct 
rtl2832_config *cfg,
return priv-fe;
 err:
dev_dbg(i2c-dev, %s: failed=%d\n, __func__, ret);
+   if (priv  priv-i2c_adapter)
+   i2c_del_mux_adapter(priv-i2c_adapter);
kfree(priv);
return NULL;
 }
diff --git a/drivers/media/dvb-frontends/rtl2832_priv.h 
b/drivers/media/dvb-frontends/rtl2832_priv.h
index ec26c92..8b7c1ae 100644
--- a/drivers/media/dvb-frontends/rtl2832_priv.h
+++ b/drivers/media/dvb-frontends/rtl2832_priv.h
@@ -28,6 +28,7 @@
 struct 

[REVIEW PATCH 71/86] rtl2832_sdr: use formats defined in V4L2 API

2014-02-09 Thread Antti Palosaari
Switch new formats V4L2_SDR_FMT_CU8 and V4L2_SDR_FMT_CU16LE as those
are now defined in API.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index c26c084..e89abd8 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -37,10 +37,6 @@
 #include linux/jiffies.h
 #include linux/math64.h
 
-/* TODO: These should be moved to V4L2 API */
-#define V4L2_PIX_FMT_SDR_U8v4l2_fourcc('D', 'U', '0', '8')
-#define V4L2_PIX_FMT_SDR_U16LE v4l2_fourcc('D', 'U', '1', '6')
-
 #define MAX_BULK_BUFS(10)
 #define BULK_BUFFER_SIZE (128 * 512)
 
@@ -90,11 +86,11 @@ struct rtl2832_sdr_format {
 
 static struct rtl2832_sdr_format formats[] = {
{
-   .name   = 8-bit unsigned,
-   .pixelformat= V4L2_PIX_FMT_SDR_U8,
+   .name   = IQ U8,
+   .pixelformat=  V4L2_SDR_FMT_CU8,
}, {
-   .name   = 16-bit unsigned little endian,
-   .pixelformat= V4L2_PIX_FMT_SDR_U16LE,
+   .name   = IQ U16LE (emulated),
+   .pixelformat= V4L2_SDR_FMT_CU16LE,
},
 };
 
@@ -346,11 +342,11 @@ static unsigned int rtl2832_sdr_convert_stream(struct 
rtl2832_sdr_state *s,
 {
unsigned int dst_len;
 
-   if (s-pixelformat == V4L2_PIX_FMT_SDR_U8) {
+   if (s-pixelformat ==  V4L2_SDR_FMT_CU8) {
/* native stream, no need to convert */
memcpy(dst, src, src_len);
dst_len = src_len;
-   } else if (s-pixelformat == V4L2_PIX_FMT_SDR_U16LE) {
+   } else if (s-pixelformat == V4L2_SDR_FMT_CU16LE) {
/* convert u8 to u16 */
unsigned int i;
u16 *u16dst = dst;
@@ -1410,7 +1406,7 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
s-i2c = i2c;
s-cfg = cfg;
s-f_adc = bands_adc[0].rangelow;
-   s-pixelformat = V4L2_PIX_FMT_SDR_U8;
+   s-pixelformat =  V4L2_SDR_FMT_CU8;
 
mutex_init(s-v4l2_lock);
mutex_init(s-vb_queue_lock);
-- 
1.8.5.3

--
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


[REVIEW PATCH 84/86] e4000: get rid of DVB i2c_gate_ctrl()

2014-02-09 Thread Antti Palosaari
Gate control is now implemented by rtl2832 I2C adapter so we do not
need proprietary DVB i2c_gate_ctrl() anymore.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/e4000.c | 106 +--
 1 file changed, 21 insertions(+), 85 deletions(-)

diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index 662e19a1..e3e3b7e 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -119,9 +119,6 @@ static int e4000_init(struct dvb_frontend *fe)
 
dev_dbg(priv-client-dev, %s:\n, __func__);
 
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 1);
-
/* dummy I2C to ensure I2C wakes up */
ret = e4000_wr_reg(priv, 0x02, 0x40);
 
@@ -178,17 +175,11 @@ static int e4000_init(struct dvb_frontend *fe)
if (ret  0)
goto err;
 
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
-
priv-active = true;
-
-   return 0;
 err:
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
+   if (ret)
+   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
 
-   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
return ret;
 }
 
@@ -201,22 +192,13 @@ static int e4000_sleep(struct dvb_frontend *fe)
 
priv-active = false;
 
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 1);
-
ret = e4000_wr_reg(priv, 0x00, 0x00);
if (ret  0)
goto err;
-
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
-
-   return 0;
 err:
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
+   if (ret)
+   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
 
-   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
return ret;
 }
 
@@ -233,9 +215,6 @@ static int e4000_set_params(struct dvb_frontend *fe)
__func__, c-delivery_system, c-frequency,
c-bandwidth_hz);
 
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 1);
-
/* gain control manual */
ret = e4000_wr_reg(priv, 0x1a, 0x00);
if (ret  0)
@@ -361,16 +340,10 @@ static int e4000_set_params(struct dvb_frontend *fe)
ret = e4000_wr_reg(priv, 0x1a, 0x17);
if (ret  0)
goto err;
-
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
-
-   return 0;
 err:
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
+   if (ret)
+   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
 
-   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
return ret;
 }
 
@@ -390,14 +363,12 @@ static int e4000_set_lna_gain(struct dvb_frontend *fe)
struct e4000_priv *priv = fe-tuner_priv;
int ret;
u8 u8tmp;
+
dev_dbg(priv-client-dev, %s: lna auto=%d-%d val=%d-%d\n,
__func__, priv-lna_gain_auto-cur.val,
priv-lna_gain_auto-val, priv-lna_gain-cur.val,
priv-lna_gain-val);
 
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 1);
-
if (priv-lna_gain_auto-val  priv-if_gain_auto-cur.val)
u8tmp = 0x17;
else if (priv-lna_gain_auto-val)
@@ -416,16 +387,10 @@ static int e4000_set_lna_gain(struct dvb_frontend *fe)
if (ret)
goto err;
}
-
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
-
-   return 0;
 err:
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
+   if (ret)
+   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
 
-   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
return ret;
 }
 
@@ -434,14 +399,12 @@ static int e4000_set_mixer_gain(struct dvb_frontend *fe)
struct e4000_priv *priv = fe-tuner_priv;
int ret;
u8 u8tmp;
+
dev_dbg(priv-client-dev, %s: mixer auto=%d-%d val=%d-%d\n,
__func__, priv-mixer_gain_auto-cur.val,
priv-mixer_gain_auto-val, priv-mixer_gain-cur.val,
priv-mixer_gain-val);
 
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 1);
-
if (priv-mixer_gain_auto-val)
u8tmp = 0x15;
else
@@ -456,16 +419,10 @@ static int e4000_set_mixer_gain(struct dvb_frontend *fe)
if (ret)
goto err;
}
-
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
-
-   return 0;
 err:
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
+   if (ret)
+   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
 
-   

[REVIEW PATCH 66/86] rtl28xxu: fix switch-case style issue

2014-02-09 Thread Antti Palosaari
Use break, not return, for every case.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index 73348bf..afafe92 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -906,7 +906,6 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
/* attach SDR */
dvb_attach(rtl2832_sdr_attach, adap-fe[0], d-i2c_adap,
rtl28xxu_rtl2832_fc0012_config);
-   return 0;
break;
case TUNER_RTL2832_FC0013:
fe = dvb_attach(fc0013_attach, adap-fe[0],
@@ -919,7 +918,7 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
/* attach SDR */
dvb_attach(rtl2832_sdr_attach, adap-fe[0], d-i2c_adap,
rtl28xxu_rtl2832_fc0013_config);
-   return 0;
+   break;
case TUNER_RTL2832_E4000: {
struct e4000_config e4000_config = {
.fe = adap-fe[0],
-- 
1.8.5.3

--
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


[REVIEW PATCH 64/86] rtl2832_sdr: use E4000 tuner controls via V4L framework

2014-02-09 Thread Antti Palosaari
Use V4L2 control framework for E4000 tuner as it provides controls
that way now.

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 92 +---
 1 file changed, 34 insertions(+), 58 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 1dfe653..c26c084 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -922,30 +922,6 @@ err:
return;
 };
 
-static int rtl2832_sdr_set_gain_e4000(struct rtl2832_sdr_state *s)
-{
-   int ret;
-   struct dvb_frontend *fe = s-fe;
-   struct e4000_ctrl ctrl;
-   dev_dbg(s-udev-dev, %s: lna=%d mixer=%d if=%d\n, __func__,
-   s-lna_gain-val, s-mixer_gain-val, s-if_gain-val);
-
-   ctrl.lna_gain = s-lna_gain_auto-val ? INT_MIN : s-lna_gain-val;
-   ctrl.mixer_gain = s-mixer_gain_auto-val ? INT_MIN : 
s-mixer_gain-val;
-   ctrl.if_gain = s-if_gain_auto-val ? INT_MIN : s-if_gain-val;
-
-   if (fe-ops.tuner_ops.set_config) {
-   ret = fe-ops.tuner_ops.set_config(fe, ctrl);
-   if (ret)
-   goto err;
-   }
-
-   return 0;
-err:
-   dev_dbg(s-udev-dev, %s: failed %d\n, __func__, ret);
-   return ret;
-};
-
 static int rtl2832_sdr_set_gain_r820t(struct rtl2832_sdr_state *s)
 {
int ret;
@@ -975,9 +951,6 @@ static int rtl2832_sdr_set_gain(struct rtl2832_sdr_state *s)
int ret;
 
switch (s-cfg-tuner) {
-   case RTL2832_TUNER_E4000:
-   ret = rtl2832_sdr_set_gain_e4000(s);
-   break;
case RTL2832_TUNER_R820T:
ret = rtl2832_sdr_set_gain_r820t(s);
break;
@@ -991,35 +964,33 @@ static int rtl2832_sdr_set_tuner(struct rtl2832_sdr_state 
*s)
 {
struct dvb_frontend *fe = s-fe;
struct dtv_frontend_properties *c = fe-dtv_property_cache;
+   struct v4l2_ctrl *bandwidth_auto;
+   struct v4l2_ctrl *bandwidth;
int ret;
 
/*
 * tuner RF (Hz)
 */
-   unsigned int f_rf = s-f_tuner;
+   if (s-f_tuner == 0)
+   return 0;
 
/*
 * bandwidth (Hz)
 */
-   unsigned int bandwidth;
-
-   /* filters */
-   if (s-bandwidth_auto-val)
-   bandwidth = s-f_adc;
-   else
-   bandwidth = s-bandwidth-val;
-
-   s-bandwidth-val = bandwidth;
-
-   dev_dbg(s-udev-dev, %s: f_rf=%u bandwidth=%d\n,
-   __func__, f_rf, bandwidth);
+   bandwidth_auto = v4l2_ctrl_find(s-hdl, V4L2_CID_BANDWIDTH_AUTO);
+   bandwidth = v4l2_ctrl_find(s-hdl, V4L2_CID_BANDWIDTH);
+   if (v4l2_ctrl_g_ctrl(bandwidth_auto)) {
+   c-bandwidth_hz = s-f_adc;
+   v4l2_ctrl_s_ctrl(bandwidth, s-f_adc);
+   } else {
+   c-bandwidth_hz = v4l2_ctrl_g_ctrl(bandwidth);
+   }
 
-   c-bandwidth_hz = bandwidth;
-   c-frequency = f_rf;
+   c-frequency = s-f_tuner;
c-delivery_system = SYS_DVBT;
 
-   if (f_rf == 0)
-   return 0;
+   dev_dbg(s-udev-dev, %s: frequency=%u bandwidth=%d\n,
+   __func__, c-frequency, c-bandwidth_hz);
 
if (!test_bit(POWER_ON, s-flags))
return 0;
@@ -1362,6 +1333,8 @@ static int rtl2832_sdr_s_ctrl(struct v4l2_ctrl *ctrl)
struct rtl2832_sdr_state *s =
container_of(ctrl-handler, struct rtl2832_sdr_state,
hdl);
+   struct dvb_frontend *fe = s-fe;
+   struct dtv_frontend_properties *c = fe-dtv_property_cache;
int ret;
dev_dbg(s-udev-dev,
%s: id=%d name=%s val=%d min=%d max=%d step=%d\n,
@@ -1371,7 +1344,18 @@ static int rtl2832_sdr_s_ctrl(struct v4l2_ctrl *ctrl)
switch (ctrl-id) {
case V4L2_CID_BANDWIDTH_AUTO:
case V4L2_CID_BANDWIDTH:
-   ret = rtl2832_sdr_set_tuner(s);
+   if (s-bandwidth_auto-val)
+   s-bandwidth-val = s-f_adc;
+
+   c-bandwidth_hz = s-bandwidth-val;
+
+   if (!test_bit(POWER_ON, s-flags))
+   return 0;
+
+   if (fe-ops.tuner_ops.set_params)
+   ret = fe-ops.tuner_ops.set_params(fe);
+   else
+   ret = 0;
break;
case  V4L2_CID_LNA_GAIN_AUTO:
case  V4L2_CID_LNA_GAIN:
@@ -1410,6 +1394,7 @@ struct dvb_frontend *rtl2832_sdr_attach(struct 
dvb_frontend *fe,
struct rtl2832_sdr_state *s;
const struct v4l2_ctrl_ops *ops = rtl2832_sdr_ctrl_ops;
struct dvb_usb_device *d = i2c_get_adapdata(i2c);
+   struct v4l2_ctrl_handler *hdl;
 
s = kzalloc(sizeof(struct rtl2832_sdr_state), 

[REVIEW PATCH 78/86] DocBook: media: document PLL lock control

2014-02-09 Thread Antti Palosaari
Document PLL lock V4L2 control. It is read only RF tuner control
which is used to inform if tuner is receiving frequency or not.

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 Documentation/DocBook/media/v4l/controls.xml | 9 +
 1 file changed, 9 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/controls.xml 
b/Documentation/DocBook/media/v4l/controls.xml
index 345b6e5..e6d4b50 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -5077,6 +5077,15 @@ intermediate frequency output or baseband output. Used 
when
 constantV4L2_CID_IF_GAIN_AUTO/constant is not set. The range and step are
 driver-specific./entry
 /row
+row
+  entry 
spanname=idconstantV4L2_CID_PLL_LOCK/constantnbsp;/entry
+  entryboolean/entry
+/row
+row
+  entry spanname=descrIs synthesizer PLL locked? RF tuner is
+receiving given frequency when that control is set. This is a read-only 
control.
+/entry
+/row
   /tbody
 /tgroup
   /table
-- 
1.8.5.3

--
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


[REVIEW PATCH 85/86] rtl2832_sdr: do not init tuner when only freq is changed

2014-02-09 Thread Antti Palosaari
Initializing whole tuner every time when frequency is changed is wrong
and unnecessary. Init tuner only when streaming is started. Change
other parameters runtime.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 25 +++-
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index 0d96aea..cc554f7 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -912,7 +912,7 @@ err:
return;
 };
 
-static int rtl2832_sdr_set_tuner(struct rtl2832_sdr_state *s)
+static int rtl2832_sdr_set_tuner_freq(struct rtl2832_sdr_state *s)
 {
struct dvb_frontend *fe = s-fe;
struct dtv_frontend_properties *c = fe-dtv_property_cache;
@@ -946,15 +946,24 @@ static int rtl2832_sdr_set_tuner(struct rtl2832_sdr_state 
*s)
if (!test_bit(POWER_ON, s-flags))
return 0;
 
-   if (fe-ops.tuner_ops.init)
-   fe-ops.tuner_ops.init(fe);
-
if (fe-ops.tuner_ops.set_params)
fe-ops.tuner_ops.set_params(fe);
 
return 0;
 };
 
+static int rtl2832_sdr_set_tuner(struct rtl2832_sdr_state *s)
+{
+   struct dvb_frontend *fe = s-fe;
+
+   dev_dbg(s-udev-dev, %s:\n, __func__);
+
+   if (fe-ops.tuner_ops.init)
+   fe-ops.tuner_ops.init(fe);
+
+   return 0;
+};
+
 static void rtl2832_sdr_unset_tuner(struct rtl2832_sdr_state *s)
 {
struct dvb_frontend *fe = s-fe;
@@ -988,6 +997,10 @@ static int rtl2832_sdr_start_streaming(struct vb2_queue 
*vq, unsigned int count)
if (ret)
goto err;
 
+   ret = rtl2832_sdr_set_tuner_freq(s);
+   if (ret)
+   goto err;
+
ret = rtl2832_sdr_set_adc(s);
if (ret)
goto err;
@@ -1127,6 +1140,7 @@ static int rtl2832_sdr_s_frequency(struct file *file, 
void *priv,
 {
struct rtl2832_sdr_state *s = video_drvdata(file);
int ret, band;
+
dev_dbg(s-udev-dev, %s: tuner=%d type=%d frequency=%u\n,
__func__, f-tuner, f-type, f-frequency);
 
@@ -1153,7 +1167,8 @@ static int rtl2832_sdr_s_frequency(struct file *file, 
void *priv,
s-f_tuner = f-frequency;
dev_dbg(s-udev-dev, %s: RF frequency=%u Hz\n,
__func__, f-frequency);
-   ret = rtl2832_sdr_set_tuner(s);
+
+   ret = rtl2832_sdr_set_tuner_freq(s);
} else {
ret = -EINVAL;
}
-- 
1.8.5.3

--
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


[REVIEW PATCH 76/86] v4l: add control for RF tuner PLL lock flag

2014-02-09 Thread Antti Palosaari
Add volatile boolean control to indicate if tuner frequency synthesizer
is locked to requested frequency. That means tuner is able to receive
given frequency. Control is named as PLL lock, since frequency
synthesizers are based of phase-locked-loop. Maybe more general name
could be wise still?

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/v4l2-core/v4l2-ctrls.c | 5 +
 include/uapi/linux/v4l2-controls.h   | 1 +
 2 files changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c 
b/drivers/media/v4l2-core/v4l2-ctrls.c
index e44722b..dc6cba4 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -867,6 +867,7 @@ const char *v4l2_ctrl_get_name(u32 id)
case V4L2_CID_IF_GAIN:  return IF Gain;
case V4L2_CID_BANDWIDTH_AUTO:   return Channel Bandwidth, 
Auto;
case V4L2_CID_BANDWIDTH:return Channel Bandwidth;
+   case V4L2_CID_PLL_LOCK: return PLL Lock;
default:
return NULL;
}
@@ -920,6 +921,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
v4l2_ctrl_type *type,
case V4L2_CID_MIXER_GAIN_AUTO:
case V4L2_CID_IF_GAIN_AUTO:
case V4L2_CID_BANDWIDTH_AUTO:
+   case V4L2_CID_PLL_LOCK:
*type = V4L2_CTRL_TYPE_BOOLEAN;
*min = 0;
*max = *step = 1;
@@ -1100,6 +1102,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
v4l2_ctrl_type *type,
case V4L2_CID_DV_RX_POWER_PRESENT:
*flags |= V4L2_CTRL_FLAG_READ_ONLY;
break;
+   case V4L2_CID_PLL_LOCK:
+   *flags |= V4L2_CTRL_FLAG_VOLATILE;
+   break;
}
 }
 EXPORT_SYMBOL(v4l2_ctrl_fill);
diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index cc488c3..06918c9 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -907,5 +907,6 @@ enum v4l2_deemphasis {
 #define V4L2_CID_MIXER_GAIN(V4L2_CID_RF_TUNER_CLASS_BASE + 
52)
 #define V4L2_CID_IF_GAIN_AUTO  (V4L2_CID_RF_TUNER_CLASS_BASE + 
61)
 #define V4L2_CID_IF_GAIN   (V4L2_CID_RF_TUNER_CLASS_BASE + 
62)
+#define V4L2_CID_PLL_LOCK  (V4L2_CID_RF_TUNER_CLASS_BASE + 
91)
 
 #endif
-- 
1.8.5.3

--
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


[REVIEW PATCH 77/86] e4000: implement PLL lock v4l control

2014-02-09 Thread Antti Palosaari
Implement PLL lock control to get PLL lock flag status from tuner
synthesizer.

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/e4000.c  | 53 ++-
 drivers/media/tuners/e4000_priv.h |  2 ++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index 019dc62..662e19a1 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -181,6 +181,8 @@ static int e4000_init(struct dvb_frontend *fe)
if (fe-ops.i2c_gate_ctrl)
fe-ops.i2c_gate_ctrl(fe, 0);
 
+   priv-active = true;
+
return 0;
 err:
if (fe-ops.i2c_gate_ctrl)
@@ -197,6 +199,8 @@ static int e4000_sleep(struct dvb_frontend *fe)
 
dev_dbg(priv-client-dev, %s:\n, __func__);
 
+   priv-active = false;
+
if (fe-ops.i2c_gate_ctrl)
fe-ops.i2c_gate_ctrl(fe, 1);
 
@@ -512,6 +516,50 @@ err:
return ret;
 }
 
+static int e4000_pll_lock(struct dvb_frontend *fe)
+{
+   struct e4000_priv *priv = fe-tuner_priv;
+   int ret;
+   u8 u8tmp;
+
+   if (priv-active == false)
+   return 0;
+
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 1);
+
+   ret = e4000_rd_reg(priv, 0x07, u8tmp);
+   if (ret)
+   goto err;
+
+   priv-pll_lock-val = (u8tmp  0x01);
+err:
+   if (fe-ops.i2c_gate_ctrl)
+   fe-ops.i2c_gate_ctrl(fe, 0);
+
+   if (ret)
+   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
+
+   return ret;
+}
+
+static int e4000_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct e4000_priv *priv =
+   container_of(ctrl-handler, struct e4000_priv, hdl);
+   int ret;
+
+   switch (ctrl-id) {
+   case  V4L2_CID_PLL_LOCK:
+   ret = e4000_pll_lock(priv-fe);
+   break;
+   default:
+   ret = -EINVAL;
+   }
+
+   return ret;
+}
+
 static int e4000_s_ctrl(struct v4l2_ctrl *ctrl)
 {
struct e4000_priv *priv =
@@ -550,6 +598,7 @@ static int e4000_s_ctrl(struct v4l2_ctrl *ctrl)
 }
 
 static const struct v4l2_ctrl_ops e4000_ctrl_ops = {
+   .g_volatile_ctrl = e4000_g_volatile_ctrl,
.s_ctrl = e4000_s_ctrl,
 };
 
@@ -616,7 +665,7 @@ static int e4000_probe(struct i2c_client *client,
goto err;
 
/* Register controls */
-   v4l2_ctrl_handler_init(priv-hdl, 8);
+   v4l2_ctrl_handler_init(priv-hdl, 9);
priv-bandwidth_auto = v4l2_ctrl_new_std(priv-hdl, e4000_ctrl_ops,
V4L2_CID_BANDWIDTH_AUTO, 0, 1, 1, 1);
priv-bandwidth = v4l2_ctrl_new_std(priv-hdl, e4000_ctrl_ops,
@@ -637,6 +686,8 @@ static int e4000_probe(struct i2c_client *client,
priv-if_gain = v4l2_ctrl_new_std(priv-hdl, e4000_ctrl_ops,
V4L2_CID_IF_GAIN, 0, 54, 1, 0);
v4l2_ctrl_auto_cluster(2, priv-if_gain_auto, 0, false);
+   priv-pll_lock = v4l2_ctrl_new_std(priv-hdl, e4000_ctrl_ops,
+   V4L2_CID_PLL_LOCK,  0, 1, 1, 0);
if (priv-hdl.error) {
ret = priv-hdl.error;
dev_err(priv-client-dev, Could not initialize controls\n);
diff --git a/drivers/media/tuners/e4000_priv.h 
b/drivers/media/tuners/e4000_priv.h
index 8cc27b3..d41dbcc 100644
--- a/drivers/media/tuners/e4000_priv.h
+++ b/drivers/media/tuners/e4000_priv.h
@@ -28,6 +28,7 @@ struct e4000_priv {
struct i2c_client *client;
u32 clock;
struct dvb_frontend *fe;
+   bool active;
 
/* Controls */
struct v4l2_ctrl_handler hdl;
@@ -39,6 +40,7 @@ struct e4000_priv {
struct v4l2_ctrl *mixer_gain;
struct v4l2_ctrl *if_gain_auto;
struct v4l2_ctrl *if_gain;
+   struct v4l2_ctrl *pll_lock;
 };
 
 struct e4000_pll {
-- 
1.8.5.3

--
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


[REVIEW PATCH 65/86] e4000: remove .set_config() which was for controls

2014-02-09 Thread Antti Palosaari
That custom DVB callback is not needed anymore for setting gain
controls as those are now implemented using V4L2 control framework.

That change was proposed by Mauro.

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/e4000.c | 68 
 drivers/media/tuners/e4000.h |  6 
 2 files changed, 74 deletions(-)

diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index 77318e9..019dc62 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -381,73 +381,6 @@ static int e4000_get_if_frequency(struct dvb_frontend *fe, 
u32 *frequency)
return 0;
 }
 
-static int e4000_set_config(struct dvb_frontend *fe, void *priv_cfg)
-{
-   struct e4000_priv *priv = fe-tuner_priv;
-   struct e4000_ctrl *ctrl = priv_cfg;
-   int ret;
-   u8 buf[2];
-   u8 u8tmp;
-   dev_dbg(priv-client-dev, %s: lna=%d mixer=%d if=%d\n, __func__,
-   ctrl-lna_gain, ctrl-mixer_gain, ctrl-if_gain);
-
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 1);
-
-   if (ctrl-lna_gain == INT_MIN  ctrl-if_gain == INT_MIN)
-   u8tmp = 0x17;
-   else if (ctrl-lna_gain == INT_MIN)
-   u8tmp = 0x19;
-   else if (ctrl-if_gain == INT_MIN)
-   u8tmp = 0x16;
-   else
-   u8tmp = 0x10;
-
-   ret = e4000_wr_reg(priv, 0x1a, u8tmp);
-   if (ret)
-   goto err;
-
-   if (ctrl-mixer_gain == INT_MIN)
-   u8tmp = 0x15;
-   else
-   u8tmp = 0x14;
-
-   ret = e4000_wr_reg(priv, 0x20, u8tmp);
-   if (ret)
-   goto err;
-
-   if (ctrl-lna_gain != INT_MIN) {
-   ret = e4000_wr_reg(priv, 0x14, ctrl-lna_gain);
-   if (ret)
-   goto err;
-   }
-
-   if (ctrl-mixer_gain != INT_MIN) {
-   ret = e4000_wr_reg(priv, 0x15, ctrl-mixer_gain);
-   if (ret)
-   goto err;
-   }
-
-   if (ctrl-if_gain != INT_MIN) {
-   buf[0] = e4000_if_gain_lut[ctrl-if_gain].reg16_val;
-   buf[1] = e4000_if_gain_lut[ctrl-if_gain].reg17_val;
-   ret = e4000_wr_regs(priv, 0x16, buf, 2);
-   if (ret)
-   goto err;
-   }
-
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
-
-   return 0;
-err:
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
-
-   dev_dbg(priv-client-dev, %s: failed=%d\n, __func__, ret);
-   return ret;
-}
-
 static int e4000_set_lna_gain(struct dvb_frontend *fe)
 {
struct e4000_priv *priv = fe-tuner_priv;
@@ -630,7 +563,6 @@ static const struct dvb_tuner_ops e4000_tuner_ops = {
.init = e4000_init,
.sleep = e4000_sleep,
.set_params = e4000_set_params,
-   .set_config = e4000_set_config,
 
.get_if_frequency = e4000_get_if_frequency,
 };
diff --git a/drivers/media/tuners/e4000.h b/drivers/media/tuners/e4000.h
index d86de6d..989f2ea 100644
--- a/drivers/media/tuners/e4000.h
+++ b/drivers/media/tuners/e4000.h
@@ -40,12 +40,6 @@ struct e4000_config {
u32 clock;
 };
 
-struct e4000_ctrl {
-   int lna_gain;
-   int mixer_gain;
-   int if_gain;
-};
-
 #if IS_ENABLED(CONFIG_MEDIA_TUNER_E4000)
 extern struct v4l2_ctrl_handler *e4000_get_ctrl_handler(
struct dvb_frontend *fe
-- 
1.8.5.3

--
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


[REVIEW PATCH 70/86] msi3101: use formats defined in V4L2 API

2014-02-09 Thread Antti Palosaari
Switch new formats V4L2_SDR_FMT_CU8 and V4L2_SDR_FMT_CU16LE as those
are now defined in API.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index 6159d88..f996220 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -52,8 +52,6 @@
 #define MAX_ISOC_ERRORS 20
 
 /* TODO: These should be moved to V4L2 API */
-#define V4L2_PIX_FMT_SDR_U8 v4l2_fourcc('D', 'U', '0', '8') /* unsigned 
8-bit */
-#define V4L2_PIX_FMT_SDR_U16LE  v4l2_fourcc('D', 'U', '1', '6') /* unsigned 
16-bit LE */
 #define V4L2_PIX_FMT_SDR_S8 v4l2_fourcc('D', 'S', '0', '8') /* signed 
8-bit */
 #define V4L2_PIX_FMT_SDR_S12v4l2_fourcc('D', 'S', '1', '2') /* signed 
12-bit */
 #define V4L2_PIX_FMT_SDR_S14v4l2_fourcc('D', 'S', '1', '4') /* signed 
14-bit */
@@ -97,11 +95,11 @@ struct msi3101_format {
 /* format descriptions for capture and preview */
 static struct msi3101_format formats[] = {
{
-   .name   = 8-bit unsigned,
-   .pixelformat= V4L2_PIX_FMT_SDR_U8,
+   .name   = IQ U8,
+   .pixelformat= V4L2_SDR_FMT_CU8,
}, {
-   .name   = 16-bit unsigned little endian,
-   .pixelformat= V4L2_PIX_FMT_SDR_U16LE,
+   .name   = IQ U16LE,
+   .pixelformat=  V4L2_SDR_FMT_CU16LE,
 #if 0
}, {
.name   = 8-bit signed,
@@ -941,11 +939,11 @@ static int msi3101_set_usb_adc(struct msi3101_state *s)
 
/* select stream format */
switch (s-pixelformat) {
-   case V4L2_PIX_FMT_SDR_U8:
+   case V4L2_SDR_FMT_CU8:
s-convert_stream = msi3101_convert_stream_504_u8;
reg7 = 0x000c9407;
break;
-   case V4L2_PIX_FMT_SDR_U16LE:
+   case  V4L2_SDR_FMT_CU16LE:
s-convert_stream = msi3101_convert_stream_252_u16;
reg7 = 0x9407;
break;
@@ -1417,7 +1415,7 @@ static int msi3101_probe(struct usb_interface *intf,
INIT_LIST_HEAD(s-queued_bufs);
s-udev = udev;
s-f_adc = bands_adc[0].rangelow;
-   s-pixelformat = V4L2_PIX_FMT_SDR_U8;
+   s-pixelformat = V4L2_SDR_FMT_CU8;
 
/* Init videobuf2 queue structure */
s-vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE;
-- 
1.8.5.3

--
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


[REVIEW PATCH 67/86] v4l: reorganize RF tuner control ID numbers

2014-02-09 Thread Antti Palosaari
It appears that controls are ordered by ID number. Change order of
controls by reorganizing assigned IDs now as we can. It is not
reasonable possible after the API is released. Leave some spare
space between IDs too for future extensions.

Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 include/uapi/linux/v4l2-controls.h | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 3cf68a6..cc488c3 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -899,13 +899,13 @@ enum v4l2_deemphasis {
 #define V4L2_CID_RF_TUNER_CLASS_BASE   (V4L2_CTRL_CLASS_RF_TUNER | 
0x900)
 #define V4L2_CID_RF_TUNER_CLASS
(V4L2_CTRL_CLASS_RF_TUNER | 1)
 
-#define V4L2_CID_LNA_GAIN_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 
1)
-#define V4L2_CID_LNA_GAIN  (V4L2_CID_RF_TUNER_CLASS_BASE + 
2)
-#define V4L2_CID_MIXER_GAIN_AUTO   (V4L2_CID_RF_TUNER_CLASS_BASE + 
3)
-#define V4L2_CID_MIXER_GAIN(V4L2_CID_RF_TUNER_CLASS_BASE + 
4)
-#define V4L2_CID_IF_GAIN_AUTO  (V4L2_CID_RF_TUNER_CLASS_BASE + 
5)
-#define V4L2_CID_IF_GAIN   (V4L2_CID_RF_TUNER_CLASS_BASE + 
6)
-#define V4L2_CID_BANDWIDTH_AUTO
(V4L2_CID_RF_TUNER_CLASS_BASE + 7)
-#define V4L2_CID_BANDWIDTH (V4L2_CID_RF_TUNER_CLASS_BASE + 
8)
+#define V4L2_CID_BANDWIDTH_AUTO
(V4L2_CID_RF_TUNER_CLASS_BASE + 11)
+#define V4L2_CID_BANDWIDTH (V4L2_CID_RF_TUNER_CLASS_BASE + 
12)
+#define V4L2_CID_LNA_GAIN_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 
41)
+#define V4L2_CID_LNA_GAIN  (V4L2_CID_RF_TUNER_CLASS_BASE + 
42)
+#define V4L2_CID_MIXER_GAIN_AUTO   (V4L2_CID_RF_TUNER_CLASS_BASE + 
51)
+#define V4L2_CID_MIXER_GAIN(V4L2_CID_RF_TUNER_CLASS_BASE + 
52)
+#define V4L2_CID_IF_GAIN_AUTO  (V4L2_CID_RF_TUNER_CLASS_BASE + 
61)
+#define V4L2_CID_IF_GAIN   (V4L2_CID_RF_TUNER_CLASS_BASE + 
62)
 
 #endif
-- 
1.8.5.3

--
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


[REVIEW PATCH 74/86] msi3101: provide RF tuner bands from sub-device

2014-02-09 Thread Antti Palosaari
Let the msi001 tuner driver report its frequency bands.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 48 +
 1 file changed, 15 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c 
b/drivers/staging/media/msi3101/sdr-msi3101.c
index f996220..158cbe0 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -57,7 +57,7 @@
 #define V4L2_PIX_FMT_SDR_S14v4l2_fourcc('D', 'S', '1', '4') /* signed 
14-bit */
 #define V4L2_PIX_FMT_SDR_MSI2500_384 v4l2_fourcc('M', '3', '8', '4') /* Mirics 
MSi2500 format 384 */
 
-static const struct v4l2_frequency_band bands_adc[] = {
+static const struct v4l2_frequency_band bands[] = {
{
.tuner = 0,
.type = V4L2_TUNER_ADC,
@@ -68,24 +68,6 @@ static const struct v4l2_frequency_band bands_adc[] = {
},
 };
 
-static const struct v4l2_frequency_band bands_rf[] = {
-   {
-   .tuner = 1,
-   .type = V4L2_TUNER_RF,
-   .index = 0,
-   .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
-   .rangelow   =   4900,
-   .rangehigh  =  26300,
-   }, {
-   .tuner = 1,
-   .type = V4L2_TUNER_RF,
-   .index = 1,
-   .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
-   .rangelow   =  39000,
-   .rangehigh  =  96000,
-   },
-};
-
 /* stream formats */
 struct msi3101_format {
char*name;
@@ -1269,8 +1251,8 @@ static int msi3101_s_frequency(struct file *file, void 
*priv,
 
if (f-tuner == 0) {
s-f_adc = clamp_t(unsigned int, f-frequency,
-   bands_adc[0].rangelow,
-   bands_adc[0].rangehigh);
+   bands[0].rangelow,
+   bands[0].rangehigh);
dev_dbg(s-udev-dev, %s: ADC frequency=%u Hz\n,
__func__, s-f_adc);
ret = msi3101_set_usb_adc(s);
@@ -1287,25 +1269,25 @@ static int msi3101_enum_freq_bands(struct file *file, 
void *priv,
struct v4l2_frequency_band *band)
 {
struct msi3101_state *s = video_drvdata(file);
+   int ret;
dev_dbg(s-udev-dev, %s: tuner=%d type=%d index=%d\n,
__func__, band-tuner, band-type, band-index);
 
if (band-tuner == 0) {
-   if (band-index = ARRAY_SIZE(bands_adc))
-   return -EINVAL;
-
-   *band = bands_adc[band-index];
+   if (band-index = ARRAY_SIZE(bands)) {
+   ret = -EINVAL;
+   } else {
+   *band = bands[band-index];
+   ret = 0;
+   }
} else if (band-tuner == 1) {
-   /* TODO: add that to v4l2_subdev_tuner_ops */
-   if (band-index = ARRAY_SIZE(bands_rf))
-   return -EINVAL;
-
-   *band = bands_rf[band-index];
+   ret = v4l2_subdev_call(s-v4l2_subdev, tuner,
+   enum_freq_bands, band);
} else {
-   return -EINVAL;
+   ret = -EINVAL;
}
 
-   return 0;
+   return ret;
 }
 
 static const struct v4l2_ioctl_ops msi3101_ioctl_ops = {
@@ -1414,7 +1396,7 @@ static int msi3101_probe(struct usb_interface *intf,
spin_lock_init(s-queued_bufs_lock);
INIT_LIST_HEAD(s-queued_bufs);
s-udev = udev;
-   s-f_adc = bands_adc[0].rangelow;
+   s-f_adc = bands[0].rangelow;
s-pixelformat = V4L2_SDR_FMT_CU8;
 
/* Init videobuf2 queue structure */
-- 
1.8.5.3

--
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


[REVIEW PATCH 68/86] DocBook: document RF tuner bandwidth controls

2014-02-09 Thread Antti Palosaari
Add documentation for RF tuner bandwidth controls. These controls are
used to set filters on tuner signal path.

Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 Documentation/DocBook/media/v4l/controls.xml | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/controls.xml 
b/Documentation/DocBook/media/v4l/controls.xml
index 0145341..345b6e5 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -5007,6 +5007,25 @@ descriptor. Calling VIDIOC-QUERYCTRL; for this control 
will return a
 description of this control class./entry
 /row
 row
+  entry 
spanname=idconstantV4L2_CID_BANDWIDTH_AUTO/constantnbsp;/entry
+  entryboolean/entry
+/row
+row
+  entry spanname=descrEnables/disables tuner radio channel
+bandwidth configuration. In automatic mode bandwidth configuration is performed
+by the driver./entry
+/row
+row
+  entry 
spanname=idconstantV4L2_CID_BANDWIDTH/constantnbsp;/entry
+  entryinteger/entry
+/row
+row
+  entry spanname=descrFilter(s) on tuner signal path are used 
to
+filter signal according to receiving party needs. Driver configures filters to
+fulfill desired bandwidth requirement. Used when V4L2_CID_BANDWIDTH_AUTO is not
+set. The range and step are driver-specific./entry
+/row
+row
   entry 
spanname=idconstantV4L2_CID_LNA_GAIN_AUTO/constantnbsp;/entry
   entryboolean/entry
 /row
-- 
1.8.5.3

--
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


[REVIEW PATCH 73/86] msi001: implement .enum_freq_bands()

2014-02-09 Thread Antti Palosaari
Implement .enum_freq_bands() in order to provide
VIDIOC_ENUM_FREQ_BANDS IOCTL from sub-device.

Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/staging/media/msi3101/msi001.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/staging/media/msi3101/msi001.c 
b/drivers/staging/media/msi3101/msi001.c
index 5c5bb52..da7a34d 100644
--- a/drivers/staging/media/msi3101/msi001.c
+++ b/drivers/staging/media/msi3101/msi001.c
@@ -345,11 +345,29 @@ static int msi001_s_frequency(struct v4l2_subdev *sd,
return msi001_set_tuner(s);
 }
 
+static int msi001_enum_freq_bands(struct v4l2_subdev *sd,
+   struct v4l2_frequency_band *band)
+{
+   struct msi001 *s = sd_to_msi001(sd);
+   dev_dbg(s-spi-dev, %s: tuner=%d type=%d index=%d\n,
+   __func__, band-tuner, band-type, band-index);
+
+   if (band-index = ARRAY_SIZE(bands))
+   return -EINVAL;
+
+   band-capability = bands[band-index].capability;
+   band-rangelow = bands[band-index].rangelow;
+   band-rangehigh = bands[band-index].rangehigh;
+
+   return 0;
+}
+
 static const struct v4l2_subdev_tuner_ops msi001_tuner_ops = {
.g_tuner  = msi001_g_tuner,
.s_tuner  = msi001_s_tuner,
.g_frequency  = msi001_g_frequency,
.s_frequency  = msi001_s_frequency,
+   .enum_freq_bands  = msi001_enum_freq_bands,
 };
 
 static const struct v4l2_subdev_ops msi001_ops = {
-- 
1.8.5.3

--
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


[REVIEW PATCH 86/86] e4000: convert to Regmap API

2014-02-09 Thread Antti Palosaari
That comes possible after driver was converted to kernel I2C model
(I2C binding  proper I2C client with no gate control hack). All
nasty low level I2C routines are now covered by regmap.

Also some variable renaming and minor functionality changes.

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Hans Verkuil hverk...@xs4all.nl
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/Kconfig  |   1 +
 drivers/media/tuners/e4000.c  | 442 --
 drivers/media/tuners/e4000_priv.h |   4 +-
 3 files changed, 184 insertions(+), 263 deletions(-)

diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig
index ba2e365..a128488 100644
--- a/drivers/media/tuners/Kconfig
+++ b/drivers/media/tuners/Kconfig
@@ -204,6 +204,7 @@ config MEDIA_TUNER_TDA18212
 config MEDIA_TUNER_E4000
tristate Elonics E4000 silicon tuner
depends on MEDIA_SUPPORT  I2C
+   select REGMAP_I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
help
  Elonics E4000 silicon tuner driver.
diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index e3e3b7e..0d516ad 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -21,203 +21,112 @@
 #include e4000_priv.h
 #include linux/math64.h
 
-/* Max transfer size done by I2C transfer functions */
-#define MAX_XFER_SIZE  64
-
-/* write multiple registers */
-static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
-{
-   int ret;
-   u8 buf[MAX_XFER_SIZE];
-   struct i2c_msg msg[1] = {
-   {
-   .addr = priv-client-addr,
-   .flags = 0,
-   .len = 1 + len,
-   .buf = buf,
-   }
-   };
-
-   if (1 + len  sizeof(buf)) {
-   dev_warn(priv-client-dev,
-%s: i2c wr reg=%04x: len=%d is too big!\n,
-KBUILD_MODNAME, reg, len);
-   return -EINVAL;
-   }
-
-   buf[0] = reg;
-   memcpy(buf[1], val, len);
-
-   ret = i2c_transfer(priv-client-adapter, msg, 1);
-   if (ret == 1) {
-   ret = 0;
-   } else {
-   dev_warn(priv-client-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 e4000_rd_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
-{
-   int ret;
-   u8 buf[MAX_XFER_SIZE];
-   struct i2c_msg msg[2] = {
-   {
-   .addr = priv-client-addr,
-   .flags = 0,
-   .len = 1,
-   .buf = reg,
-   }, {
-   .addr = priv-client-addr,
-   .flags = I2C_M_RD,
-   .len = len,
-   .buf = buf,
-   }
-   };
-
-   if (len  sizeof(buf)) {
-   dev_warn(priv-client-dev,
-%s: i2c rd reg=%04x: len=%d is too big!\n,
-KBUILD_MODNAME, reg, len);
-   return -EINVAL;
-   }
-
-   ret = i2c_transfer(priv-client-adapter, msg, 2);
-   if (ret == 2) {
-   memcpy(val, buf, len);
-   ret = 0;
-   } else {
-   dev_warn(priv-client-dev,
-   %s: i2c rd failed=%d reg=%02x len=%d\n,
-   KBUILD_MODNAME, ret, reg, len);
-   ret = -EREMOTEIO;
-   }
-
-   return ret;
-}
-
-/* write single register */
-static int e4000_wr_reg(struct e4000_priv *priv, u8 reg, u8 val)
-{
-   return e4000_wr_regs(priv, reg, val, 1);
-}
-
-/* read single register */
-static int e4000_rd_reg(struct e4000_priv *priv, u8 reg, u8 *val)
-{
-   return e4000_rd_regs(priv, reg, val, 1);
-}
-
 static int e4000_init(struct dvb_frontend *fe)
 {
-   struct e4000_priv *priv = fe-tuner_priv;
+   struct e4000 *s = fe-tuner_priv;
int ret;
 
-   dev_dbg(priv-client-dev, %s:\n, __func__);
+   dev_dbg(s-client-dev, %s:\n, __func__);
 
/* dummy I2C to ensure I2C wakes up */
-   ret = e4000_wr_reg(priv, 0x02, 0x40);
+   ret = regmap_write(s-regmap, 0x02, 0x40);
 
/* reset */
-   ret = e4000_wr_reg(priv, 0x00, 0x01);
-   if (ret  0)
+   ret = regmap_write(s-regmap, 0x00, 0x01);
+   if (ret)
goto err;
 
/* disable output clock */
-   ret = e4000_wr_reg(priv, 0x06, 0x00);
-   if (ret  0)
+   ret = regmap_write(s-regmap, 0x06, 0x00);
+   if (ret)
goto err;
 
-   ret = e4000_wr_reg(priv, 0x7a, 0x96);
-   if (ret  0)
+   ret = regmap_write(s-regmap, 0x7a, 0x96);
+   if (ret)
goto err;
 
/* configure gains */
-   ret = 

[REVIEW PATCH 81/86] rtl2832: Fix deadlock on i2c mux select function.

2014-02-09 Thread Antti Palosaari
From: Luis Alves lja...@gmail.com

Signed-off-by: Luis Alves lja...@gmail.com
Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/dvb-frontends/rtl2832.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/rtl2832.c 
b/drivers/media/dvb-frontends/rtl2832.c
index c0366a8..cfc5438 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -917,7 +917,7 @@ static int rtl2832_select(struct i2c_adapter *adap, void 
*mux_priv, u32 chan_id)
buf[0] = 0x00;
buf[1] = 0x01;
 
-   ret = i2c_transfer(adap, msg, 1);
+   ret = __i2c_transfer(adap, msg, 1);
if (ret != 1)
goto err;
 
@@ -930,7 +930,7 @@ static int rtl2832_select(struct i2c_adapter *adap, void 
*mux_priv, u32 chan_id)
else
buf[1] = 0x10; /* close */
 
-   ret = i2c_transfer(adap, msg, 1);
+   ret = __i2c_transfer(adap, msg, 1);
if (ret != 1)
goto err;
 
-- 
1.8.5.3

--
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


[REVIEW PATCH 61/86] MAINTAINERS: add rtl2832_sdr driver

2014-02-09 Thread Antti Palosaari
Realtek RTL2832 SDR driver. Currently in staging as SDR API is not
ready.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index f03772a..0ed943a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7338,6 +7338,16 @@ T:   git git://linuxtv.org/anttip/media_tree.git
 S: Maintained
 F: drivers/media/dvb-frontends/rtl2832*
 
+RTL2832_SDR MEDIA DRIVER
+M: Antti Palosaari cr...@iki.fi
+L: linux-media@vger.kernel.org
+W: http://linuxtv.org/
+W: http://palosaari.fi/linux/
+Q: http://patchwork.linuxtv.org/project/linux-media/list/
+T: git git://linuxtv.org/anttip/media_tree.git
+S: Maintained
+F: drivers/staging/media/rtl2832u_sdr/rtl2832_sdr*
+
 RTL8180 WIRELESS DRIVER
 M: John W. Linville linvi...@tuxdriver.com
 L: linux-wirel...@vger.kernel.org
-- 
1.8.5.3

--
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 RFC 0/2] drivers/base: simplify simple DT-based components

2014-02-09 Thread Russell King - ARM Linux
On Sun, Feb 09, 2014 at 10:22:19AM +0100, Jean-Francois Moine wrote:
 On Fri, 7 Feb 2014 20:23:51 +
 Russell King - ARM Linux li...@arm.linux.org.uk wrote:
 
  Here's my changes to the TDA998x driver to add support for the component
  helper.  The TDA998x driver retains support for the old way so that
  drivers can be transitioned.  For any one DRM card the transition to
 
 I rewrote the tda998x as a simple encoder+connector (i.e. not a
 slave_encoder) with your component helper, and the code is much clearer
 and simpler: the DRM driver has nothing to do except to know that the
 tda998x is a component and to set the possible_crtcs.

That's exactly what I've done - the slave encoder veneer can be simply
deleted when tilcdc is converted.

 AFAIK, only the tilcdc drm driver is using the tda998x as a
 slave_encoder. It does a (encoder+connector) conversion to
 (slave_encoder). Then, in your changes in the TDA998x, you do a
 (slave_encoder) translation to (encoder+connector).
 This seems rather complicated!

No.  I first split out the slave encoder functions to be a veneer onto
the tda998x backend, and then add the encoder  connector component
support.  Later, the slave encoder veneer can be deleted.

The reason for this is that virtually all the tda998x backend is what's
required by the encoder  connector support - which is completely logical
when you realise that the generic slave encoder support is just a veneer
itself adapting the encoder  connector support to a slave encoder.

So, we're basically getting rid of two veneers, but we end up with exactly
the same functionality.

  And yes, I'm thinking that maybe moving compare_of() into the component
  support so that drivers can share this generic function may be a good
  idea.
 
 This function exists already in drivers/of/platform.c as
 of_dev_node_match(). It just needs to be exported.

Good, thanks for pointing that out.

-- 
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was up to 13.2Mbit.
--
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: Support for Empia 2980 video/audio capture chip set

2014-02-09 Thread pepijn de vos
Hey,

I signed up to this list because I found this thread in the archives when 
googling for a driver for my Dazzle. Unfortunately I can't reply to an email I 
did not get.

Like Keith Lawson I'm a developer with no kernel experience, although I have 
some experience with C and libusb. I'd be happy to help in any way possible.

If there are any Dutch linux-media developers we could do a little hackathon 
maybe?

Unrelated: How do people manage to not be ovewhelmed by such a high-volume list?

Cheers,
Pepijn de Vos

--
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] af9035: Move it913x single devices to af9035

2014-02-09 Thread Antti Palosaari

Moi Malcolm!

On 09.02.2014 10:59, Malcolm Priestley wrote:

On Sat, 2014-02-08 at 16:11 +, Malcolm Priestley wrote:

The generic v1 and v2 devices have been all tested.

IDs tested
USB_PID_ITETECH_IT9135 v1  v2
USB_PID_ITETECH_IT9135_9005 v1
USB_PID_ITETECH_IT9135_9006 v2

Current Issues
There is no signal  on
USB_PID_ITETECH_IT9135 v2

No SNR reported all devices.

All single devices tune and scan fine.

All remotes tested okay.

Dual device failed to register second adapter
USB_PID_KWORLD_UB499_2T_T09
It is not clear what the problem is at the moment.

Hi Antti

I have found the problem here.

state-eeprom_addr + EEPROM_2ND_DEMOD_ADDR

contains no value

So on 9135 devices register 0x4bfb and the I2C address
(state-af9033_config[1].i2c_addr) need to be set to 0x3a.

I have only manually changed these and both adapters work fine.

Also, I can't find pick up for register 0xcfff although it appears
to be on by default.

I will try and do a patch later and the patch for remaining ids in
it913x.


Good!
That non-working dual device must be IT9135 v2 as I have one dual 
TerraTec, which is working and is build upon version 1 of IT9135. I have 
no v2 dual device.


regards
Antti

--
http://palosaari.fi/
--
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


[PATCH 1/2] af9035: add default 0x9135 slave I2C address

2014-02-09 Thread Malcolm Priestley
On some devices the vendor has not set EEPROM_2ND_DEMOD_ADDR.

Checks tmp is not zero after call to get EEPROM_2ND_DEMOD_ADDR and sets the
default slave address of 0x3a on 0x9135 devices.

Signed-off-by: Malcolm Priestley tvbox...@gmail.com
---
 drivers/media/usb/dvb-usb-v2/af9035.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c 
b/drivers/media/usb/dvb-usb-v2/af9035.c
index 3825c2f..4f682ad 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -576,6 +576,10 @@ static int af9035_download_firmware(struct dvb_usb_device 
*d,
goto err;
 
if (state-chip_type == 0x9135) {
+   if (!tmp)
+   /* default 0x9135 slave I2C address */
+   tmp = 0x3a;
+
ret = af9035_wr_reg(d, 0x004bfb, tmp);
if (ret  0)
goto err;
@@ -684,6 +688,10 @@ static int af9035_read_config(struct dvb_usb_device *d)
if (ret  0)
goto err;
 
+   if (!tmp  state-chip_type == 0x9135)
+   /* default 0x9135 slave I2C address */
+   tmp = 0x3a;
+
state-af9033_config[1].i2c_addr = tmp;
dev_dbg(d-udev-dev, %s: 2nd demod I2C addr=%02x\n,
__func__, tmp);
-- 
1.9.rc1

--
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


[PATCH 2/2] af9035: Add remaining it913x dual ids to af9035.

2014-02-09 Thread Malcolm Priestley
As follow on to patch
af9035: Move it913x single devices to af9035
and patch 1.

SNR is reported as db/10 values.

All dual ids are added to af9035 and it913x driver disabled.

it913x/it913x-fe removal patches to follow.

Signed-off-by: Malcolm Priestley tvbox...@gmail.com
---
 drivers/media/usb/dvb-usb-v2/af9035.c | 8 
 drivers/media/usb/dvb-usb-v2/it913x.c | 5 +
 2 files changed, 13 insertions(+)

diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c 
b/drivers/media/usb/dvb-usb-v2/af9035.c
index 4f682ad..49e8360 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -1552,6 +1552,14 @@ static const struct usb_device_id af9035_id_table[] = {
af9035_props, Avermedia A835B(4835), RC_MAP_IT913X_V2) },
{ DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_H335,
af9035_props, Avermedia H335, RC_MAP_IT913X_V2) },
+   { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB499_2T_T09,
+   af9035_props, Kworld UB499-2T T09, RC_MAP_IT913X_V1) },
+   { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV22_IT9137,
+   af9035_props, Sveon STV22 Dual DVB-T HDTV,
+   RC_MAP_IT913X_V1) },
+   { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CTVDIGDUAL_V2,
+   af9035_props, Digital Dual TV Receiver CTVDIGDUAL_V2,
+   RC_MAP_IT913X_V1) },
/* XXX: that same ID [0ccd:0099] is used by af9015 driver too */
{ DVB_USB_DEVICE(USB_VID_TERRATEC, 0x0099,
af9035_props, TerraTec Cinergy T Stick Dual RC (rev. 2), 
NULL) },
diff --git a/drivers/media/usb/dvb-usb-v2/it913x.c 
b/drivers/media/usb/dvb-usb-v2/it913x.c
index 78bf8fd..39488f8 100644
--- a/drivers/media/usb/dvb-usb-v2/it913x.c
+++ b/drivers/media/usb/dvb-usb-v2/it913x.c
@@ -781,6 +781,8 @@ static const struct usb_device_id it913x_id_table[] = {
{}  /* Terminating entry */
 };
 
+#if 0
+
 MODULE_DEVICE_TABLE(usb, it913x_id_table);
 
 static struct usb_driver it913x_driver = {
@@ -792,8 +794,11 @@ static struct usb_driver it913x_driver = {
.id_table   = it913x_id_table,
 };
 
+
 module_usb_driver(it913x_driver);
 
+#endif
+
 MODULE_AUTHOR(Malcolm Priestley tvbox...@gmail.com);
 MODULE_DESCRIPTION(it913x USB 2 Driver);
 MODULE_VERSION(1.33);
-- 
1.9.rc1

--
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


[PATCH] [media] v4l: omap4iss: Remove VIDEO_OMAP4_DEBUG

2014-02-09 Thread Paul Bolle
Commit d632dfefd36f ([media] v4l: omap4iss: Add support for OMAP4
camera interface - Build system) added a Kconfig entry for
VIDEO_OMAP4_DEBUG. But nothing uses that symbol.

This entry was apparently copied from a similar entry for OMAP 3
Camera debug messages. But a corresponding Makefile line is missing.
Besides, the debug code also depends on a mysterious ISS_ISR_DEBUG
macro. This Kconfig entry can be removed.

Someone familiar with the code might be able to say what to do with the
code depending on the DEBUG and ISS_ISR_DEBUG macros.

Signed-off-by: Paul Bolle pebo...@tiscali.nl
---
Untested.

 drivers/staging/media/omap4iss/Kconfig | 6 --
 1 file changed, 6 deletions(-)

diff --git a/drivers/staging/media/omap4iss/Kconfig 
b/drivers/staging/media/omap4iss/Kconfig
index b9fe753..78b0fba 100644
--- a/drivers/staging/media/omap4iss/Kconfig
+++ b/drivers/staging/media/omap4iss/Kconfig
@@ -4,9 +4,3 @@ config VIDEO_OMAP4
select VIDEOBUF2_DMA_CONTIG
---help---
  Driver for an OMAP 4 ISS controller.
-
-config VIDEO_OMAP4_DEBUG
-   bool OMAP 4 Camera debug messages
-   depends on VIDEO_OMAP4
-   ---help---
- Enable debug messages on OMAP 4 ISS controller driver.
-- 
1.8.5.3

--
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


[PATCH] [media] si4713: Remove select SI4713

2014-02-09 Thread Paul Bolle
Commits 7391232e1215 ([media] si4713: Reorganized drivers/media/radio
directory) and b874b39fcd2f ([media] si4713: Added the USB driver for
Si4713) both added a select SI4713. But there's no Kconfig symbol
SI4713, so these selects are nops. It's not clear why they were added
but it's safe to remove them anyway.

Signed-off-by: Paul Bolle pebo...@tiscali.nl
---
Untested!

 drivers/media/radio/si4713/Kconfig | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/radio/si4713/Kconfig 
b/drivers/media/radio/si4713/Kconfig
index a7c3ba8..ed51ed0 100644
--- a/drivers/media/radio/si4713/Kconfig
+++ b/drivers/media/radio/si4713/Kconfig
@@ -1,7 +1,6 @@
 config USB_SI4713
tristate Silicon Labs Si4713 FM Radio Transmitter support with USB
depends on USB  RADIO_SI4713
-   select SI4713
---help---
  This is a driver for USB devices with the Silicon Labs SI4713
  chip. Currently these devices are known to work.
@@ -16,7 +15,6 @@ config USB_SI4713
 config PLATFORM_SI4713
tristate Silicon Labs Si4713 FM Radio Transmitter support with I2C
depends on I2C  RADIO_SI4713
-   select SI4713
---help---
  This is a driver for I2C devices with the Silicon Labs SI4713
  chip.
-- 
1.8.5.3



--
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] [media] si4713: Remove select SI4713

2014-02-09 Thread Hans Verkuil
On 02/09/2014 03:56 PM, Paul Bolle wrote:
 Commits 7391232e1215 ([media] si4713: Reorganized drivers/media/radio
 directory) and b874b39fcd2f ([media] si4713: Added the USB driver for
 Si4713) both added a select SI4713. But there's no Kconfig symbol
 SI4713, so these selects are nops. It's not clear why they were added
 but it's safe to remove them anyway.
 
 Signed-off-by: Paul Bolle pebo...@tiscali.nl

USB_SI4713 and PLATFORM_SI4713 both depend on I2C_SI4713. So the select
should be I2C_SI4713. If you can post a patch fixing that, then I'll pick
it up for 3.14.

With the addition of the USB si4713 driver things moved around and were
renamed, and these selects were missed.

Regards,

Hans

 ---
 Untested!
 
  drivers/media/radio/si4713/Kconfig | 2 --
  1 file changed, 2 deletions(-)
 
 diff --git a/drivers/media/radio/si4713/Kconfig 
 b/drivers/media/radio/si4713/Kconfig
 index a7c3ba8..ed51ed0 100644
 --- a/drivers/media/radio/si4713/Kconfig
 +++ b/drivers/media/radio/si4713/Kconfig
 @@ -1,7 +1,6 @@
  config USB_SI4713
   tristate Silicon Labs Si4713 FM Radio Transmitter support with USB
   depends on USB  RADIO_SI4713
 - select SI4713
   ---help---
 This is a driver for USB devices with the Silicon Labs SI4713
 chip. Currently these devices are known to work.
 @@ -16,7 +15,6 @@ config USB_SI4713
  config PLATFORM_SI4713
   tristate Silicon Labs Si4713 FM Radio Transmitter support with I2C
   depends on I2C  RADIO_SI4713
 - select SI4713
   ---help---
 This is a driver for I2C devices with the Silicon Labs SI4713
 chip.
 

--
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] [media] si4713: Remove select SI4713

2014-02-09 Thread Paul Bolle
Hans,

On Sun, 2014-02-09 at 16:18 +0100, Hans Verkuil wrote:
 USB_SI4713 and PLATFORM_SI4713 both depend on I2C_SI4713. So the select
 should be I2C_SI4713.

Are you sure? I've actually scanned si4713.c before submitting this
patch and I couldn't find anything in it that these other two modules
require. Have I overlooked anything?

  If you can post a patch fixing that, then I'll pick
 it up for 3.14.
 
 With the addition of the USB si4713 driver things moved around and were
 renamed, and these selects were missed.

Thanks,


Paul Bolle

--
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


RFH: Trying to implement support PCTV Quatro Stick 522e

2014-02-09 Thread Heiko Voigt
Hi,

I just purchased a PCTV QuatroStick 522e (2013:025e). Since it is the successor
of the 520e I believed that there would probably be Linux support for it, it
seems not.

But I do not want to give up so easily and since there is support for the
previous models I would like to have a go at adding support for this one.

I already tried a simple copy and paste approach from the 520e
(resulting in the attached patch[1]) but it seems too many things have been
changed, since it leads to this error[2]. To test I applied my patch on top of
Ubuntus 13.10 kernel repository so I can easily build packages.

My questions are probably mainly directed to Antti since he implemented the
support for 520e:

How did you get the information about 520e? Does it make sense to contact pctv?
I will send an email to their support anyway. Did they provide you with any
information or did you crack open the housing of the stick to find out whats on
the board? Is there anyone else doing development for this device?

Maybe someone can give me some pointers?

Thanks a lot in advance.

Cheers Heiko

[1] ---8---

Subject: [PATCH] [media] em28xx: support for 2013:0251 PCTV QuatroStick (522e)

Heavily based on copy and paste from c247d7b, fa5527c and 795cb41

Signed-off-by: Heiko Voigt hvo...@hvoigt.net
---
 drivers/media/usb/em28xx/em28xx-cards.c | 28 
 drivers/media/usb/em28xx/em28xx-dvb.c   |  1 +
 drivers/media/usb/em28xx/em28xx.h   |  1 +
 3 files changed, 30 insertions(+)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index eb39903..d91477a 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -433,6 +433,20 @@ static struct em28xx_reg_seq pctv_520e[] = {
{   -1, -1, -1, -1},
 };
 
+/* 2013:025e PCTV QuatroStick nano (522e)
+ * GPIO_2: decoder reset, 0=active
+ * GPIO_4: decoder suspend, 0=active
+ * GPIO_6: demod reset, 0=active
+ * GPIO_7: LED, 1=active
+ */
+static struct em28xx_reg_seq pctv_522e[] = {
+   {EM2874_R80_GPIO_P0_CTRL,   0x10,   0xff,   100},
+   {EM2874_R80_GPIO_P0_CTRL,   0x14,   0xff,   100}, /* GPIO_2 = 1 */
+   {EM2874_R80_GPIO_P0_CTRL,   0x54,   0xff,   050}, /* GPIO_6 = 1 */
+   {EM2874_R80_GPIO_P0_CTRL,   0xd4,   0xff,   000}, /* GPIO_7 = 1 */
+   {   -1, -1, -1, -1},
+};
+
 /* 1ae7:9003/9004 SpeedLink Vicious And Devine Laplace webcam
  * reg 0x80/0x84:
  * GPIO_0: capturing LED, 0=on, 1=off
@@ -2094,6 +2108,18 @@ struct em28xx_board em28xx_boards[] = {
.i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
EM28XX_I2C_FREQ_400_KHZ,
},
+   /* 2013:025e PCTV QuatroStick (522e)
+* Empia EM2884 + Micronas DRX 3926K + NXP TDA18271HDC2 */
+   [EM2884_BOARD_PCTV_522E] = {
+   .name  = PCTV QuatroStick nano (522e),
+   .tuner_type= TUNER_ABSENT,
+   .tuner_gpio= pctv_522e,
+   .has_dvb   = 1,
+   .ir_codes  = RC_MAP_PINNACLE_PCTV_HD,
+   .def_i2c_bus   = 1,
+   .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
+   EM28XX_I2C_FREQ_400_KHZ,
+   },
[EM2884_BOARD_TERRATEC_HTC_USB_XS] = {
.name = Terratec Cinergy HTC USB XS,
.has_dvb  = 1,
@@ -2322,6 +2348,8 @@ struct usb_device_id em28xx_id_table[] = {
.driver_info = EM2884_BOARD_PCTV_510E },
{ USB_DEVICE(0x2013, 0x0251),
.driver_info = EM2884_BOARD_PCTV_520E },
+   { USB_DEVICE(0x2013, 0x025e),
+   .driver_info = EM2884_BOARD_PCTV_522E },
{ USB_DEVICE(0x1b80, 0xe1cc),
.driver_info = EM2874_BOARD_DELOCK_61959 },
{ USB_DEVICE(0x1ae7, 0x9003),
diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c 
b/drivers/media/usb/em28xx/em28xx-dvb.c
index a0a669e..fd65825 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -1298,6 +1298,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
break;
case EM2884_BOARD_PCTV_510E:
case EM2884_BOARD_PCTV_520E:
+   case EM2884_BOARD_PCTV_522E:
pctv_520e_init(dev);
 
/* attach demodulator */
diff --git a/drivers/media/usb/em28xx/em28xx.h 
b/drivers/media/usb/em28xx/em28xx.h
index 32d8a4b..00c083e 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -137,6 +137,7 @@
 #define EM2874_BOARD_KWORLD_UB435Q_V290
 #define EM2765_BOARD_SPEEDLINK_VAD_LAPLACE   91
 #define EM28178_BOARD_PCTV_461E   92
+#define EM2884_BOARD_PCTV_522E   93
 
 /* Limits minimum and default number of buffers */
 #define EM28XX_MIN_BUF 4
-- 
1.8.5.1.44.gf92a2f6

[2] ---8
[   

[PATCH] saa7134: Add support for SnaZio TvPVR PRO

2014-02-09 Thread POJAR GEORGE
From: POJAR GEORGE geoubu...@gmail.com

Signed-off-by: POJAR GEORGE geoubu...@gmail.com
---
 Documentation/video4linux/CARDLIST.saa7134 |   1 +
 drivers/media/pci/saa7134/saa7134-cards.c  |  51 ++-
 drivers/media/pci/saa7134/saa7134-input.c  |  62 +
 drivers/media/pci/saa7134/saa7134.h|   1 +
 drivers/media/rc/keymaps/Makefile  |   1 +
 drivers/media/rc/keymaps/rc-snazio-tvpvr-pro.c | 116 +
 include/media/rc-map.h |   1 +
 7 files changed, 232 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/rc/keymaps/rc-snazio-tvpvr-pro.c

diff --git a/Documentation/video4linux/CARDLIST.saa7134 
b/Documentation/video4linux/CARDLIST.saa7134
index 8df17d0..32e4353 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -191,3 +191,4 @@
 190 - Asus My Cinema PS3-100   [1043:48cd]
 191 - Hawell HW-9004V1
 192 - AverMedia AverTV Satellite Hybrid+FM A706 [1461:2055]
+193 - SnaZio TvPVR PRO 
[0x1779:0x13cf,0x1779:0x13d0,0x1779:0x13d1]
diff --git a/drivers/media/pci/saa7134/saa7134-cards.c 
b/drivers/media/pci/saa7134/saa7134-cards.c
index d45e7f6..3476785 100644
--- a/drivers/media/pci/saa7134/saa7134-cards.c
+++ b/drivers/media/pci/saa7134/saa7134-cards.c
@@ -5827,7 +5827,37 @@ struct saa7134_board saa7134_boards[] = {
.gpio = 0x800,
},
},
-
+   [SAA7134_BOARD_SNAZIO_TVPVR_PRO] = {
+   .name   = SnaZio TvPVR PRO,
+   .audio_clock= 0x00187de7,
+   .tuner_type = TUNER_PHILIPS_TDA8290,
+   .radio_type = UNSET,
+   .tuner_addr = ADDR_UNSET,
+   .radio_addr = ADDR_UNSET,
+   .gpiomask   = 1  21,
+   .inputs = {{
+   .name = name_tv,
+   .vmux = 1,
+   .amux = TV,
+   .gpio = 0x000,
+   .tv   = 1,
+   }, {
+   .name = name_comp1, /* Composite input */
+   .vmux = 3,
+   .amux = LINE2,
+   .gpio = 0x000,
+   }, {
+   .name = name_svideo,/* S-Video input */
+   .vmux = 8,
+   .amux = LINE2,
+   .gpio = 0x000,
+   } },
+   .radio = {
+   .name = name_radio,
+   .amux = TV,
+   .gpio = 0x020,
+   },
+   },
 };
 
 const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -7080,6 +7110,24 @@ struct pci_device_id saa7134_pci_tbl[] = {
.subdevice= 0x2055, /* AverTV Satellite Hybrid+FM A706 */
.driver_data  = SAA7134_BOARD_AVERMEDIA_A706,
}, {
+   .vendor   = PCI_VENDOR_ID_PHILIPS,
+   .device   = PCI_DEVICE_ID_PHILIPS_SAA7133,
+   .subvendor= 0x1779,
+   .subdevice= 0x13cf,
+   .driver_data  = SAA7134_BOARD_SNAZIO_TVPVR_PRO,
+   }, {
+   .vendor   = PCI_VENDOR_ID_PHILIPS,
+   .device   = PCI_DEVICE_ID_PHILIPS_SAA7133,
+   .subvendor= 0x1779,
+   .subdevice= 0x13d0,
+   .driver_data  = SAA7134_BOARD_SNAZIO_TVPVR_PRO,
+   }, {
+   .vendor   = PCI_VENDOR_ID_PHILIPS,
+   .device   = PCI_DEVICE_ID_PHILIPS_SAA7133,
+   .subvendor= 0x1779,
+   .subdevice= 0x13d1,
+   .driver_data  = SAA7134_BOARD_SNAZIO_TVPVR_PRO,
+   }, {
/* --- boards without eeprom + subsystem ID --- */
.vendor   = PCI_VENDOR_ID_PHILIPS,
.device   = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -7608,6 +7656,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
case SAA7134_BOARD_BEHOLD_H7:
case SAA7134_BOARD_BEHOLD_A7:
case SAA7134_BOARD_KWORLD_PC150U:
+   case SAA7134_BOARD_SNAZIO_TVPVR_PRO:
dev-has_remote = SAA7134_REMOTE_I2C;
break;
case SAA7134_BOARD_AVERMEDIA_A169_B:
diff --git a/drivers/media/pci/saa7134/saa7134-input.c 
b/drivers/media/pci/saa7134/saa7134-input.c
index 6f43126..62ccc7d 100644
--- a/drivers/media/pci/saa7134/saa7134-input.c
+++ b/drivers/media/pci/saa7134/saa7134-input.c
@@ -416,6 +416,53 @@ static int get_key_pinnacle_color(struct IR_i2c *ir, u32 
*ir_key, u32 *ir_raw)
return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
 }
 
+/* copied and modified from get_key_msi_tvanywhere_plus() */
+static int get_key_snazio_tvpvr_pro(struct IR_i2c *ir, u32 *ir_key, u32 
*ir_raw)
+{
+   unsigned char b;
+   unsigned int gpio;
+
+   /* dev is 

Re: RFH: Trying to implement support PCTV Quatro Stick 522e

2014-02-09 Thread Antti Palosaari

Moikka Heiko,

On 09.02.2014 17:33, Heiko Voigt wrote:

Hi,

I just purchased a PCTV QuatroStick 522e (2013:025e). Since it is the successor
of the 520e I believed that there would probably be Linux support for it, it
seems not.


ah, first 292e and now that...


But I do not want to give up so easily and since there is support for the
previous models I would like to have a go at adding support for this one.

I already tried a simple copy and paste approach from the 520e
(resulting in the attached patch[1]) but it seems too many things have been
changed, since it leads to this error[2]. To test I applied my patch on top of
Ubuntus 13.10 kernel repository so I can easily build packages.


Log you attached end of that mail looks like about everything is failing 
totally badly. That means there is some other chip than em28xx.


Also DRX-K and TDA18271 used for 520e are ages old and EOL, so you will 
not see those anymore on new devices.




My questions are probably mainly directed to Antti since he implemented the
support for 520e:

How did you get the information about 520e? Does it make sense to contact pctv?
I will send an email to their support anyway. Did they provide you with any
information or did you crack open the housing of the stick to find out whats on
the board? Is there anyone else doing development for this device?


PCTV 520e support was pretty simple as there was existing driver for 
each used chips. Biggest problem was to find out GPIO bug in DRX-K 
driver, which was used to drive LNA. Sniffing windows driver and 
generate code, copy paste and test until problematic register is found.


For that certain device my role was rather small as I didn't make any 
new driver. Just got device and glued all drivers together.




Maybe someone can give me some pointers?


Generally speaking I tend to get some help from different entities as 
well as most of the other long term contributors...



You could gather needed information many ways. Inspect windows driver 
binaries, take sniffs, open the device, do error and trial tests when 
you has got control to chips and so. There is tons of methods. Writing 
new chipset driver is still rather big work in any case.



Drop windows driver to my email and I will quickly check which are 
possible chipset.


regards
Antti




Thanks a lot in advance.

Cheers Heiko

[1] ---8---

Subject: [PATCH] [media] em28xx: support for 2013:0251 PCTV QuatroStick (522e)

Heavily based on copy and paste from c247d7b, fa5527c and 795cb41

Signed-off-by: Heiko Voigt hvo...@hvoigt.net
---
  drivers/media/usb/em28xx/em28xx-cards.c | 28 
  drivers/media/usb/em28xx/em28xx-dvb.c   |  1 +
  drivers/media/usb/em28xx/em28xx.h   |  1 +
  3 files changed, 30 insertions(+)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index eb39903..d91477a 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -433,6 +433,20 @@ static struct em28xx_reg_seq pctv_520e[] = {
{   -1, -1, -1, -1},
  };

+/* 2013:025e PCTV QuatroStick nano (522e)
+ * GPIO_2: decoder reset, 0=active
+ * GPIO_4: decoder suspend, 0=active
+ * GPIO_6: demod reset, 0=active
+ * GPIO_7: LED, 1=active
+ */
+static struct em28xx_reg_seq pctv_522e[] = {
+   {EM2874_R80_GPIO_P0_CTRL,   0x10,   0xff,   100},
+   {EM2874_R80_GPIO_P0_CTRL,   0x14,   0xff,   100}, /* GPIO_2 = 1 */
+   {EM2874_R80_GPIO_P0_CTRL,   0x54,   0xff,   050}, /* GPIO_6 = 1 */
+   {EM2874_R80_GPIO_P0_CTRL,   0xd4,   0xff,   000}, /* GPIO_7 = 1 */
+   {   -1, -1, -1, -1},
+};
+
  /* 1ae7:9003/9004 SpeedLink Vicious And Devine Laplace webcam
   * reg 0x80/0x84:
   * GPIO_0: capturing LED, 0=on, 1=off
@@ -2094,6 +2108,18 @@ struct em28xx_board em28xx_boards[] = {
.i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
EM28XX_I2C_FREQ_400_KHZ,
},
+   /* 2013:025e PCTV QuatroStick (522e)
+* Empia EM2884 + Micronas DRX 3926K + NXP TDA18271HDC2 */
+   [EM2884_BOARD_PCTV_522E] = {
+   .name  = PCTV QuatroStick nano (522e),
+   .tuner_type= TUNER_ABSENT,
+   .tuner_gpio= pctv_522e,
+   .has_dvb   = 1,
+   .ir_codes  = RC_MAP_PINNACLE_PCTV_HD,
+   .def_i2c_bus   = 1,
+   .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
+   EM28XX_I2C_FREQ_400_KHZ,
+   },
[EM2884_BOARD_TERRATEC_HTC_USB_XS] = {
.name = Terratec Cinergy HTC USB XS,
.has_dvb  = 1,
@@ -2322,6 +2348,8 @@ struct usb_device_id em28xx_id_table[] = {
.driver_info = EM2884_BOARD_PCTV_510E },
{ USB_DEVICE(0x2013, 0x0251),
.driver_info = EM2884_BOARD_PCTV_520E },
+   { 

  1   2   >