All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/17] SDR API - controls, stream formats
@ 2014-02-01 14:24 Antti Palosaari
  2014-02-01 14:24 ` [PATCH 01/17] e4000: add manual gain controls Antti Palosaari
                   ` (16 more replies)
  0 siblings, 17 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

RF tuner gains, RF tuner channel bandwidth, stream formats.

regards
Antti

Antti Palosaari (17):
  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

 Documentation/DocBook/media/v4l/controls.xml       |  91 +++++++++
 .../DocBook/media/v4l/pixfmt-sdr-cu08.xml          |  44 +++++
 .../DocBook/media/v4l/pixfmt-sdr-cu16le.xml        |  46 +++++
 Documentation/DocBook/media/v4l/pixfmt.xml         |   3 +
 .../DocBook/media/v4l/vidioc-g-ext-ctrls.xml       |   7 +-
 drivers/media/tuners/e4000.c                       |  82 +++++++-
 drivers/media/tuners/e4000.h                       |   6 +
 drivers/media/tuners/e4000_priv.h                  |  63 ++++++
 drivers/media/tuners/r820t.c                       |  38 ++++
 drivers/media/tuners/r820t.h                       |   7 +
 drivers/media/tuners/tuner-xc2028.c                |   3 +
 drivers/media/v4l2-core/v4l2-ctrls.c               |   4 +
 drivers/staging/media/msi3101/sdr-msi3101.c        |  64 ++++---
 drivers/staging/media/rtl2832u_sdr/Makefile        |   1 +
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c   | 211 +++++++++++++++------
 include/uapi/linux/v4l2-controls.h                 |   2 +
 16 files changed, 580 insertions(+), 92 deletions(-)
 create mode 100644 Documentation/DocBook/media/v4l/pixfmt-sdr-cu08.xml
 create mode 100644 Documentation/DocBook/media/v4l/pixfmt-sdr-cu16le.xml

-- 
1.8.5.3


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 01/17] e4000: add manual gain controls
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 19:43   ` Mauro Carvalho Chehab
  2014-02-01 14:24 ` [PATCH 02/17] rtl2832_sdr: expose E4000 gain controls to user space Antti Palosaari
                   ` (15 subsequent siblings)
  16 siblings, 1 reply; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Add gain control for LNA, Mixer and IF. Expose controls via DVB
frontend .set_config callback.

Signed-off-by: Antti Palosaari <crope@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[] = {
 	{ 0xffffffff, 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},
+	{0x5f, 0x24},
+	{0x7f, 0x24},
+};
+
 #endif
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 02/17] rtl2832_sdr: expose E4000 gain controls to user space
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
  2014-02-01 14:24 ` [PATCH 01/17] e4000: add manual gain controls Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 03/17] r820t: add manual gain controls Antti Palosaari
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: 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 <crope@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;
 	}
@@ -1318,7 +1369,7 @@ static void rtl2832_sdr_video_release(struct v4l2_device *v)
 	struct rtl2832_sdr_state *s =
 			container_of(v, struct rtl2832_sdr_state, v4l2_dev);
 
-	v4l2_ctrl_handler_free(&s->ctrl_handler);
+	v4l2_ctrl_handler_free(&s->hdl);
 	v4l2_device_unregister(&s->v4l2_dev);
 	kfree(s);
 }
@@ -1328,6 +1379,7 @@ struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe,
 {
 	int ret;
 	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,
@@ -1339,16 +1391,6 @@ struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe,
 		.def    = 0,
 		.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,
-		.def    = 0,
-		.step   = 1,
-	};
 
 	s = kzalloc(sizeof(struct rtl2832_sdr_state), GFP_KERNEL);
 	if (s == NULL) {
@@ -1386,11 +1428,28 @@ struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe,
 	}
 
 	/* 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);
-	s->ctrl_tuner_gain = v4l2_ctrl_new_custom(&s->ctrl_handler, &ctrl_tuner_gain, NULL);
-	if (s->ctrl_handler.error) {
-		ret = s->ctrl_handler.error;
+	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);
+		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);
+		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, 1, 1, 1);
+		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, 54, 1, 0);
+		v4l2_ctrl_auto_cluster(2, &s->if_gain_auto, 0, false);
+		break;
+	default:
+		v4l2_ctrl_handler_init(&s->hdl, 1);
+		s->ctrl_tuner_bw = v4l2_ctrl_new_custom(&s->hdl, &ctrl_tuner_bw, NULL);
+		break;
+	}
+
+	if (s->hdl.error) {
+		ret = s->hdl.error;
 		dev_err(&s->udev->dev, "Could not initialize controls\n");
 		goto err_free_controls;
 	}
@@ -1411,7 +1470,7 @@ struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe,
 		goto err_free_controls;
 	}
 
-	s->v4l2_dev.ctrl_handler = &s->ctrl_handler;
+	s->v4l2_dev.ctrl_handler = &s->hdl;
 	s->vdev.v4l2_dev = &s->v4l2_dev;
 	s->vdev.lock = &s->v4l2_lock;
 	s->vdev.vfl_dir = VFL_DIR_RX;
@@ -1436,7 +1495,7 @@ struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe,
 err_unregister_v4l2_dev:
 	v4l2_device_unregister(&s->v4l2_dev);
 err_free_controls:
-	v4l2_ctrl_handler_free(&s->ctrl_handler);
+	v4l2_ctrl_handler_free(&s->hdl);
 err_free_mem:
 	kfree(s);
 	return NULL;
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 03/17] r820t: add manual gain controls
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
  2014-02-01 14:24 ` [PATCH 01/17] e4000: add manual gain controls Antti Palosaari
  2014-02-01 14:24 ` [PATCH 02/17] rtl2832_sdr: expose E4000 gain controls to user space Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 04/17] rtl2832_sdr: expose R820 gain controls to user space Antti Palosaari
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari, Mauro Carvalho Chehab

Add gain control for LNA, Mixer and IF. Expose controls via DVB
frontend .set_config callback.

Cc: Mauro Carvalho Chehab <m.chehab@samsung.com>
Signed-off-by: Antti Palosaari <crope@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 d9ee43f..5a926a3 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


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 04/17] rtl2832_sdr: expose R820 gain controls to user space
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (2 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 03/17] r820t: add manual gain controls Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 05/17] e4000: fix PLL calc to allow higher frequencies Antti Palosaari
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: 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 <crope@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


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 05/17] e4000: fix PLL calc to allow higher frequencies
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (3 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 04/17] rtl2832_sdr: expose R820 gain controls to user space Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 06/17] msi3101: fix device caps to advertise SDR receiver Antti Palosaari
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: 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 <crope@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(0x10000ULL * (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


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 06/17] msi3101: fix device caps to advertise SDR receiver
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (4 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 05/17] e4000: fix PLL calc to allow higher frequencies Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 07/17] rtl2832_sdr: " Antti Palosaari
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Advertise device as a SDR receiver, not video. After that libv4l
accepts opening device.

Signed-off-by: Antti Palosaari <crope@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


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 07/17] rtl2832_sdr: fix device caps to advertise SDR receiver
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (5 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 06/17] msi3101: fix device caps to advertise SDR receiver Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 08/17] msi3101: add default FMT and ADC frequency Antti Palosaari
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Advertise device as a SDR receiver, not video. After that libv4l
accepts opening device.

Signed-off-by: Antti Palosaari <crope@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


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 08/17] msi3101: add default FMT and ADC frequency
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (6 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 07/17] rtl2832_sdr: " Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 09/17] msi3101: sleep USB ADC and tuner when streaming is stopped Antti Palosaari
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Default ADC to smallest/worst possible configuration on probe.
Also enhance some FMT debug logs.

Signed-off-by: Antti Palosaari <crope@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


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 09/17] msi3101: sleep USB ADC and tuner when streaming is stopped
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (7 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 08/17] msi3101: add default FMT and ADC frequency Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 10/17] DocBook: document RF tuner gain controls Antti Palosaari
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: 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 <crope@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, 0x01000003);
+
+	/* sleep tuner */
+	msi3101_tuner_write(s, 0x000000);
+
 	mutex_unlock(&s->v4l2_lock);
 
 	return 0;
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 10/17] DocBook: document RF tuner gain controls
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (8 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 09/17] msi3101: sleep USB ADC and tuner when streaming is stopped Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 11/17] DocBook: V4L: add V4L2_SDR_FMT_CU8 - 'CU08' Antti Palosaari
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari, Hans Verkuil

Add documentation for LNA, mixer and IF gain controls. These
controls are RF tuner specific.

Cc: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Antti Palosaari <crope@iki.fi>
Acked-by: Hans Verkuil <hans.verkuil@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">
+      <title>RF Tuner Control Reference</title>
+
+      <para>The 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">
+        <title>RF_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="left">ID</entry>
+              <entry align="left">Type</entry>
+            </row>
+            <row rowsep="1">
+              <entry spanname="descr" align="left">Description</entry>
+            </row>
+          </thead>
+          <tbody valign="top">
+            <row><entry></entry></row>
+            <row>
+              <entry spanname="id"><constant>V4L2_CID_RF_TUNER_CLASS</constant>&nbsp;</entry>
+              <entry>class</entry>
+            </row><row><entry spanname="descr">The RF_TUNER class
+descriptor. Calling &VIDIOC-QUERYCTRL; for this control will return a
+description of this control class.</entry>
+            </row>
+            <row>
+              <entry spanname="id"><constant>V4L2_CID_LNA_GAIN_AUTO</constant>&nbsp;</entry>
+              <entry>boolean</entry>
+            </row>
+            <row>
+              <entry spanname="descr">Enables/disables LNA automatic gain control (AGC)</entry>
+            </row>
+            <row>
+              <entry spanname="id"><constant>V4L2_CID_MIXER_GAIN_AUTO</constant>&nbsp;</entry>
+              <entry>boolean</entry>
+            </row>
+            <row>
+              <entry spanname="descr">Enables/disables mixer automatic gain control (AGC)</entry>
+            </row>
+            <row>
+              <entry spanname="id"><constant>V4L2_CID_IF_GAIN_AUTO</constant>&nbsp;</entry>
+              <entry>boolean</entry>
+            </row>
+            <row>
+              <entry spanname="descr">Enables/disables IF automatic gain control (AGC)</entry>
+            </row>
+            <row>
+              <entry spanname="id"><constant>V4L2_CID_LNA_GAIN</constant>&nbsp;</entry>
+              <entry>integer</entry>
+            </row>
+            <row>
+              <entry spanname="descr">LNA (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 <constant>V4L2_CID_LNA_GAIN_AUTO</constant> is not set.
+The range and step are driver-specific.</entry>
+            </row>
+            <row>
+              <entry spanname="id"><constant>V4L2_CID_MIXER_GAIN</constant>&nbsp;</entry>
+              <entry>integer</entry>
+            </row>
+            <row>
+              <entry spanname="descr">Mixer 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 <constant>V4L2_CID_MIXER_GAIN_AUTO</constant>
+is not set. The range and step are driver-specific.</entry>
+            </row>
+            <row>
+              <entry spanname="id"><constant>V4L2_CID_IF_GAIN</constant>&nbsp;</entry>
+              <entry>integer</entry>
+            </row>
+            <row>
+              <entry spanname="descr">IF 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
+<constant>V4L2_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


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 11/17] DocBook: V4L: add V4L2_SDR_FMT_CU8 - 'CU08'
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (9 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 10/17] DocBook: document RF tuner gain controls Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 12/17] DocBook: V4L: add V4L2_SDR_FMT_CU16LE - 'CU16' Antti Palosaari
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari, Hans Verkuil

Document V4L2_SDR_FMT_CU8 SDR format.
It is complex unsigned 8-bit IQ sample. Used by software defined
radio devices.

Cc: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Antti Palosaari <crope@iki.fi>
Acked-by: Hans Verkuil <hans.verkuil@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 0000000..2d80104
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/pixfmt-sdr-cu08.xml
@@ -0,0 +1,44 @@
+<refentry id="V4L2-SDR-FMT-CU08">
+  <refmeta>
+    <refentrytitle>V4L2_SDR_FMT_CU8 ('CU08')</refentrytitle>
+    &manvol;
+  </refmeta>
+    <refnamediv>
+      <refname>
+        <constant>V4L2_SDR_FMT_CU8</constant>
+      </refname>
+      <refpurpose>Complex unsigned 8-bit IQ sample</refpurpose>
+    </refnamediv>
+    <refsect1>
+      <title>Description</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>
+      <title><constant>V4L2_SDR_FMT_CU8</constant> 1 sample</title>
+      <formalpara>
+        <title>Byte Order.</title>
+        <para>Each cell is one byte.
+          <informaltable frame="none">
+            <tgroup cols="2" align="center">
+              <colspec align="left" colwidth="2*" />
+              <tbody valign="top">
+                <row>
+                  <entry>start&nbsp;+&nbsp;0:</entry>
+                  <entry>I'<subscript>0</subscript></entry>
+                </row>
+                <row>
+                  <entry>start&nbsp;+&nbsp;1:</entry>
+                  <entry>Q'<subscript>0</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 <constant>V4L2_CID_MPEG_STREAM_TYPE</constant>, see
     <para>These formats are used for <link linkend="sdr">SDR Capture</link>
 interface only.</para>
 
+    &sub-sdr-cu08;
+
   </section>
 
   <section id="pixfmt-reserved">
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 12/17] DocBook: V4L: add V4L2_SDR_FMT_CU16LE - 'CU16'
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (10 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 11/17] DocBook: V4L: add V4L2_SDR_FMT_CU8 - 'CU08' Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 13/17] DocBook: media: document V4L2_CTRL_CLASS_RF_TUNER Antti Palosaari
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari, Hans Verkuil

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 <hverkuil@xs4all.nl>
Signed-off-by: Antti Palosaari <crope@iki.fi>
Acked-by: Hans Verkuil <hans.verkuil@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 0000000..26288ff
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/pixfmt-sdr-cu16le.xml
@@ -0,0 +1,46 @@
+<refentry id="V4L2-SDR-FMT-CU16LE">
+  <refmeta>
+    <refentrytitle>V4L2_SDR_FMT_CU16LE ('CU16')</refentrytitle>
+    &manvol;
+  </refmeta>
+    <refnamediv>
+      <refname>
+        <constant>V4L2_SDR_FMT_CU16LE</constant>
+      </refname>
+      <refpurpose>Complex unsigned 16-bit little endian IQ sample</refpurpose>
+    </refnamediv>
+    <refsect1>
+      <title>Description</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>
+      <title><constant>V4L2_SDR_FMT_CU16LE</constant> 1 sample</title>
+      <formalpara>
+        <title>Byte Order.</title>
+        <para>Each cell is one byte.
+          <informaltable frame="none">
+            <tgroup cols="3" align="center">
+              <colspec align="left" colwidth="2*" />
+              <tbody valign="top">
+                <row>
+                  <entry>start&nbsp;+&nbsp;0:</entry>
+                  <entry>I'<subscript>0[7:0]</subscript></entry>
+                  <entry>I'<subscript>0[15:8]</subscript></entry>
+                </row>
+                <row>
+                  <entry>start&nbsp;+&nbsp;2:</entry>
+                  <entry>Q'<subscript>0[7:0]</subscript></entry>
+                  <entry>Q'<subscript>0[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 <constant>V4L2_CID_MPEG_STREAM_TYPE</constant>, see
 interface only.</para>
 
     &sub-sdr-cu08;
+    &sub-sdr-cu16le;
 
   </section>
 
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 13/17] DocBook: media: document V4L2_CTRL_CLASS_RF_TUNER
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (11 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 12/17] DocBook: V4L: add V4L2_SDR_FMT_CU16LE - 'CU16' Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 14/17] xc2028: silence compiler warnings Antti Palosaari
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari, Hans Verkuil

It is class for RF tuner specific controls, like gain controls,
filters, signal strength.

Cc: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Antti Palosaari <crope@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>
+	    <entry><constant>V4L2_CTRL_CLASS_RF_TUNER</constant></entry>
+	    <entry>0xa20000</entry>
+	    <entry>The class containing RF tuner controls.
+These controls are described in <xref linkend="rf-tuner-controls" />.</entry>
+	  </row>
 	</tbody>
       </tgroup>
     </table>
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 14/17] xc2028: silence compiler warnings
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (12 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 13/17] DocBook: media: document V4L2_CTRL_CLASS_RF_TUNER Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 15/17] v4l: add RF tuner channel bandwidth control Antti Palosaari
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari, Mauro Carvalho Chehab

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.chehab@samsung.com>
Signed-off-by: Antti Palosaari <crope@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 += 200000;
 		}
 #endif
+	default:
+		tuner_err("Unsupported tuner type %d.\n", new_type);
+		break;
 	}
 
 	div = (freq - offset + DIV / 2) / DIV;
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 15/17] v4l: add RF tuner channel bandwidth control
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (13 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 14/17] xc2028: silence compiler warnings Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-03  9:08   ` Hans Verkuil
  2014-02-01 14:24 ` [PATCH 16/17] msi3101: implement tuner " Antti Palosaari
  2014-02-01 14:24 ` [PATCH 17/17] rtl2832_sdr: " Antti Palosaari
  16 siblings, 1 reply; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari, Hans Verkuil

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 <hverkuil@xs4all.nl>
Signed-off-by: Antti Palosaari <crope@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


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 16/17] msi3101: implement tuner bandwidth control
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (14 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 15/17] v4l: add RF tuner channel bandwidth control Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  2014-02-01 14:24 ` [PATCH 17/17] rtl2832_sdr: " Antti Palosaari
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Implement control that user could adjust tuner filters manually,
if he wish.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/staging/media/msi3101/sdr-msi3101.c | 44 ++++++++++++++---------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c b/drivers/staging/media/msi3101/sdr-msi3101.c
index 0606941..49e5bd1 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 MSI3101_CID_TUNER_BW              ((V4L2_CID_USER_BASE | 0xf000) + 11)
-
 #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 */
@@ -157,13 +155,14 @@ 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;
-	struct v4l2_ctrl *ctrl_tuner_bw;
 
 	u32 next_sample; /* for track lost packets */
 	u32 sample; /* for sample rate calc */
@@ -1131,7 +1130,7 @@ static int msi3101_set_tuner(struct msi3101_state *s)
 		{5000000, 0x04}, /* 5 MHz */
 		{6000000, 0x05}, /* 6 MHz */
 		{7000000, 0x06}, /* 7 MHz */
-		{    ~0U, 0x07}, /* 8 MHz */
+		{8000000, 0x07}, /* 8 MHz */
 	};
 
 	unsigned int f_rf = s->f_tuner;
@@ -1140,7 +1139,7 @@ static int msi3101_set_tuner(struct msi3101_state *s)
 	 * bandwidth (Hz)
 	 * 200000, 300000, 600000, 1536000, 5000000, 6000000, 7000000, 8000000
 	 */
-	unsigned int bandwidth = s->ctrl_tuner_bw->val;
+	unsigned int bandwidth;
 
 	/*
 	 * intermediate frequency (Hz)
@@ -1149,8 +1148,8 @@ static int msi3101_set_tuner(struct msi3101_state *s)
 	unsigned int f_if = 0;
 
 	dev_dbg(&s->udev->dev,
-			"%s: f_rf=%d bandwidth=%d f_if=%d\n",
-			__func__, f_rf, bandwidth, f_if);
+			"%s: f_rf=%d f_if=%d\n",
+			__func__, f_rf, f_if);
 
 	ret = -EINVAL;
 
@@ -1181,9 +1180,13 @@ 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)
+	/* filters */
+	if (s->bandwidth_auto->val)
 		bandwidth = s->f_adc;
+	else
+		bandwidth = s->bandwidth->val;
+
+	bandwidth = clamp(bandwidth, 200000U, 8000000U);
 
 	for (i = 0; i < ARRAY_SIZE(bandwidth_lut); i++) {
 		if (bandwidth <= bandwidth_lut[i].freq) {
@@ -1195,6 +1198,8 @@ static int msi3101_set_tuner(struct msi3101_state *s)
 	if (i == ARRAY_SIZE(bandwidth_lut))
 		goto err;
 
+	s->bandwidth->val = bandwidth_lut[i].freq;
+
 	dev_dbg(&s->udev->dev, "%s: bandwidth selected=%d\n",
 			__func__, bandwidth_lut[i].freq);
 
@@ -1580,7 +1585,8 @@ static int msi3101_s_ctrl(struct v4l2_ctrl *ctrl)
 			ctrl->minimum, ctrl->maximum, ctrl->step);
 
 	switch (ctrl->id) {
-	case MSI3101_CID_TUNER_BW:
+	case V4L2_CID_BANDWIDTH_AUTO:
+	case V4L2_CID_BANDWIDTH:
 		ret = msi3101_set_tuner(s);
 		break;
 	case  V4L2_CID_LNA_GAIN:
@@ -1617,16 +1623,6 @@ static int msi3101_probe(struct usb_interface *intf,
 	struct msi3101_state *s = NULL;
 	const struct v4l2_ctrl_ops *ops = &msi3101_ctrl_ops;
 	int ret;
-	static const struct v4l2_ctrl_config ctrl_tuner_bw = {
-		.ops	= &msi3101_ctrl_ops,
-		.id	= MSI3101_CID_TUNER_BW,
-		.type	= V4L2_CTRL_TYPE_INTEGER,
-		.name	= "Tuner Bandwidth",
-		.min	= 0,
-		.max	= 8000000,
-		.def    = 0,
-		.step	= 1,
-	};
 
 	s = kzalloc(sizeof(struct msi3101_state), GFP_KERNEL);
 	if (s == NULL) {
@@ -1664,8 +1660,12 @@ static int msi3101_probe(struct usb_interface *intf,
 	video_set_drvdata(&s->vdev, s);
 
 	/* Register controls */
-	v4l2_ctrl_handler_init(&s->hdl, 4);
-	s->ctrl_tuner_bw = v4l2_ctrl_new_custom(&s->hdl, &ctrl_tuner_bw, NULL);
+	v4l2_ctrl_handler_init(&s->hdl, 5);
+	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, 0, 8000000, 1, 0);
+	v4l2_ctrl_auto_cluster(2, &s->bandwidth_auto, 0, false);
 	s->lna_gain = v4l2_ctrl_new_std(&s->hdl, ops,
 			V4L2_CID_LNA_GAIN, 0, 1, 1, 1);
 	s->mixer_gain = v4l2_ctrl_new_std(&s->hdl, ops,
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 17/17] rtl2832_sdr: implement tuner bandwidth control
  2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
                   ` (15 preceding siblings ...)
  2014-02-01 14:24 ` [PATCH 16/17] msi3101: implement tuner " Antti Palosaari
@ 2014-02-01 14:24 ` Antti Palosaari
  16 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 14:24 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Implement control that user could adjust tuner filters manually,
if he wish.

Signed-off-by: Antti Palosaari <crope@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_U8    v4l2_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, 4300000, 11000000, 100000, 4300000);
+		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:
-		v4l2_ctrl_handler_init(&s->hdl, 7);
+		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, 0, 8000000, 100000, 0);
+		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, 6);
 		v4l2_ctrl_auto_cluster(2, &s->lna_gain_auto, 0, false);
@@ -1481,12 +1477,19 @@ struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe,
 		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);
+	case RTL2832_TUNER_FC0012:
+	case RTL2832_TUNER_FC0013:
+		v4l2_ctrl_handler_init(&s->hdl, 2);
+		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, 6000000, 8000000, 1000000, 6000000);
+		v4l2_ctrl_auto_cluster(2, &s->bandwidth_auto, 0, false);
 		break;
+	default:
+		v4l2_ctrl_handler_init(&s->hdl, 0);
+		dev_notice(&s->udev->dev, "%s: Unsupported tuner\n",
+				KBUILD_MODNAME);
+		goto err_free_controls;
 	}
 
 	if (s->hdl.error) {
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 01/17] e4000: add manual gain controls
  2014-02-01 14:24 ` [PATCH 01/17] e4000: add manual gain controls Antti Palosaari
@ 2014-02-01 19:43   ` Mauro Carvalho Chehab
  2014-02-01 20:15     ` Antti Palosaari
  0 siblings, 1 reply; 25+ messages in thread
From: Mauro Carvalho Chehab @ 2014-02-01 19:43 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media

Em Sat,  1 Feb 2014 16:24:18 +0200
Antti Palosaari <crope@iki.fi> escreveu:

> Add gain control for LNA, Mixer and IF. Expose controls via DVB
> frontend .set_config callback.

This is not a full review of this patch (or this series), but please
see below.

> Signed-off-by: Antti Palosaari <crope@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)
> +{

Hmm... that looks weird to me... the set_config() callback should
be used only be those parameters that never change and are required for
the device initialization. It is similar to the parameters passed during
a DVB attach.

So, it is for those things that you won't be exposing to userspace.

Normal control parameters are, instead, implemented using something
like:

static int tvp5150_s_ctrl(struct v4l2_ctrl *ctrl)
{
	struct v4l2_subdev *sd = to_sd(ctrl);

	switch (ctrl->id) {
	case V4L2_CID_BRIGHTNESS:
		tvp5150_write(sd, TVP5150_BRIGHT_CTL, ctrl->val);
		return 0;
	case V4L2_CID_CONTRAST:
		tvp5150_write(sd, TVP5150_CONTRAST_CTL, ctrl->val);
		return 0;
	case V4L2_CID_SATURATION:
		tvp5150_write(sd, TVP5150_SATURATION_CTL, ctrl->val);
		return 0;
	case V4L2_CID_HUE:
		tvp5150_write(sd, TVP5150_HUE_CTL, ctrl->val);
		return 0;
	}
	return -EINVAL;
}

static const struct v4l2_ctrl_ops tvp5150_ctrl_ops = {
	.s_ctrl = tvp5150_s_ctrl,
};

That allows them to be independently set, with reduces the I2C
traffic and makes their updates faster.

It also benefits from V4L controls core implementation.

Are there any reason why not using it here?

> +	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[] = {
>  	{ 0xffffffff, 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},
> +	{0x5f, 0x24},
> +	{0x7f, 0x24},
> +};
> +
>  #endif


-- 

Cheers,
Mauro

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 01/17] e4000: add manual gain controls
  2014-02-01 19:43   ` Mauro Carvalho Chehab
@ 2014-02-01 20:15     ` Antti Palosaari
  0 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-01 20:15 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: linux-media

On 01.02.2014 21:43, Mauro Carvalho Chehab wrote:
> Em Sat,  1 Feb 2014 16:24:18 +0200
> Antti Palosaari <crope@iki.fi> escreveu:
>
>> Add gain control for LNA, Mixer and IF. Expose controls via DVB
>> frontend .set_config callback.
>
> This is not a full review of this patch (or this series), but please
> see below.
>
>> Signed-off-by: Antti Palosaari <crope@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)
>> +{
>
> Hmm... that looks weird to me... the set_config() callback should
> be used only be those parameters that never change and are required for
> the device initialization. It is similar to the parameters passed during
> a DVB attach.
>
> So, it is for those things that you won't be exposing to userspace.

It was about the only existing callback which was suitable for that. Why 
there is that callback if same parameters could be passed using attach() 
as normally is done?

The main problem, behind all of these things, is mixed use of DVB and 
V4L API. Tuner implements internal DVB API, whilst userspace API offered 
is V4L. So I have hooked all calls to DVB tuner.

> Normal control parameters are, instead, implemented using something
> like:
>
> static int tvp5150_s_ctrl(struct v4l2_ctrl *ctrl)
> {
> 	struct v4l2_subdev *sd = to_sd(ctrl);
>
> 	switch (ctrl->id) {
> 	case V4L2_CID_BRIGHTNESS:
> 		tvp5150_write(sd, TVP5150_BRIGHT_CTL, ctrl->val);
> 		return 0;
> 	case V4L2_CID_CONTRAST:
> 		tvp5150_write(sd, TVP5150_CONTRAST_CTL, ctrl->val);
> 		return 0;
> 	case V4L2_CID_SATURATION:
> 		tvp5150_write(sd, TVP5150_SATURATION_CTL, ctrl->val);
> 		return 0;
> 	case V4L2_CID_HUE:
> 		tvp5150_write(sd, TVP5150_HUE_CTL, ctrl->val);
> 		return 0;
> 	}
> 	return -EINVAL;
> }
>
> static const struct v4l2_ctrl_ops tvp5150_ctrl_ops = {
> 	.s_ctrl = tvp5150_s_ctrl,
> };
>
> That allows them to be independently set, with reduces the I2C
> traffic and makes their updates faster.
>
> It also benefits from V4L controls core implementation.
>
> Are there any reason why not using it here?

Because it is DVB only tuner driver and exporting controls from tuner 
driver natively means it have to implement V4L subdev API too.

That is one big thing to be resolved, but I haven't yet studied ways how 
to do it. Likely I will try to split MSi3101 driver first as it is 
easiest starting point (mentioned already in MSi3101 TODO).


Antti

>
>> +	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[] = {
>>   	{ 0xffffffff, 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},
>> +	{0x5f, 0x24},
>> +	{0x7f, 0x24},
>> +};
>> +
>>   #endif
>
>


-- 
http://palosaari.fi/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 15/17] v4l: add RF tuner channel bandwidth control
  2014-02-01 14:24 ` [PATCH 15/17] v4l: add RF tuner channel bandwidth control Antti Palosaari
@ 2014-02-03  9:08   ` Hans Verkuil
  2014-02-03  9:11     ` Hans Verkuil
  2014-02-03 10:13     ` Antti Palosaari
  0 siblings, 2 replies; 25+ messages in thread
From: Hans Verkuil @ 2014-02-03  9:08 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media

Hi Antti,

On 02/01/2014 03:24 PM, Antti Palosaari wrote:
> 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 <hverkuil@xs4all.nl>
> Signed-off-by: Antti Palosaari <crope@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:

Booleans never have the slider flag set (they are represented as a checkbox, so a slider
makes no sense).

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

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 15/17] v4l: add RF tuner channel bandwidth control
  2014-02-03  9:08   ` Hans Verkuil
@ 2014-02-03  9:11     ` Hans Verkuil
  2014-02-03 10:17       ` Antti Palosaari
  2014-02-03 10:13     ` Antti Palosaari
  1 sibling, 1 reply; 25+ messages in thread
From: Hans Verkuil @ 2014-02-03  9:11 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media



On 02/03/2014 10:08 AM, Hans Verkuil wrote:
> Hi Antti,
> 
> On 02/01/2014 03:24 PM, Antti Palosaari wrote:
>> 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 <hverkuil@xs4all.nl>
>> Signed-off-by: Antti Palosaari <crope@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:
> 
> Booleans never have the slider flag set (they are represented as a checkbox, so a slider
> makes no sense).

v4l2-compliance will actually complain about this. It is useful to add support for
swradio to v4l2-compliance as it helps you test v4l2 compliance of drivers.

Regards,

	Hans

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 15/17] v4l: add RF tuner channel bandwidth control
  2014-02-03  9:08   ` Hans Verkuil
  2014-02-03  9:11     ` Hans Verkuil
@ 2014-02-03 10:13     ` Antti Palosaari
  2014-02-03 10:24       ` Hans Verkuil
  1 sibling, 1 reply; 25+ messages in thread
From: Antti Palosaari @ 2014-02-03 10:13 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media

On 03.02.2014 11:08, Hans Verkuil wrote:
> Hi Antti,
>
> On 02/01/2014 03:24 PM, Antti Palosaari wrote:
>> 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 <hverkuil@xs4all.nl>
>> Signed-off-by: Antti Palosaari <crope@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:
>
> Booleans never have the slider flag set (they are represented as a checkbox, so a slider
> makes no sense).
>
>>   		*flags |= V4L2_CTRL_FLAG_SLIDER;

These are two different controls, as it is controls groups with auto 
mode (boolean) and value (slider).

regards
Antti

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


-- 
http://palosaari.fi/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 15/17] v4l: add RF tuner channel bandwidth control
  2014-02-03  9:11     ` Hans Verkuil
@ 2014-02-03 10:17       ` Antti Palosaari
  0 siblings, 0 replies; 25+ messages in thread
From: Antti Palosaari @ 2014-02-03 10:17 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media

On 03.02.2014 11:11, Hans Verkuil wrote:
>
>
> On 02/03/2014 10:08 AM, Hans Verkuil wrote:
>> Hi Antti,
>>
>> On 02/01/2014 03:24 PM, Antti Palosaari wrote:
>>> 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 <hverkuil@xs4all.nl>
>>> Signed-off-by: Antti Palosaari <crope@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:
>>
>> Booleans never have the slider flag set (they are represented as a checkbox, so a slider
>> makes no sense).
>
> v4l2-compliance will actually complain about this. It is useful to add support for
> swradio to v4l2-compliance as it helps you test v4l2 compliance of drivers.

mmm, I already tested it and there was maybe 4 errors or so. Those were 
related to tuner / device types. Seems like quite many changes are needed...

regards
Antti


-- 
http://palosaari.fi/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 15/17] v4l: add RF tuner channel bandwidth control
  2014-02-03 10:13     ` Antti Palosaari
@ 2014-02-03 10:24       ` Hans Verkuil
  0 siblings, 0 replies; 25+ messages in thread
From: Hans Verkuil @ 2014-02-03 10:24 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media



On 02/03/2014 11:13 AM, Antti Palosaari wrote:
> On 03.02.2014 11:08, Hans Verkuil wrote:
>> Hi Antti,
>>
>> On 02/01/2014 03:24 PM, Antti Palosaari wrote:
>>> 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 <hverkuil@xs4all.nl>
>>> Signed-off-by: Antti Palosaari <crope@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:
>>
>> Booleans never have the slider flag set (they are represented as a checkbox, so a slider
>> makes no sense).
>>
>>>           *flags |= V4L2_CTRL_FLAG_SLIDER;
> 
> These are two different controls, as it is controls groups with auto mode (boolean) and value (slider).

Oops, my fault. I misread.

	Hans

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2014-02-03 10:24 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-01 14:24 [PATCH 00/17] SDR API - controls, stream formats Antti Palosaari
2014-02-01 14:24 ` [PATCH 01/17] e4000: add manual gain controls Antti Palosaari
2014-02-01 19:43   ` Mauro Carvalho Chehab
2014-02-01 20:15     ` Antti Palosaari
2014-02-01 14:24 ` [PATCH 02/17] rtl2832_sdr: expose E4000 gain controls to user space Antti Palosaari
2014-02-01 14:24 ` [PATCH 03/17] r820t: add manual gain controls Antti Palosaari
2014-02-01 14:24 ` [PATCH 04/17] rtl2832_sdr: expose R820 gain controls to user space Antti Palosaari
2014-02-01 14:24 ` [PATCH 05/17] e4000: fix PLL calc to allow higher frequencies Antti Palosaari
2014-02-01 14:24 ` [PATCH 06/17] msi3101: fix device caps to advertise SDR receiver Antti Palosaari
2014-02-01 14:24 ` [PATCH 07/17] rtl2832_sdr: " Antti Palosaari
2014-02-01 14:24 ` [PATCH 08/17] msi3101: add default FMT and ADC frequency Antti Palosaari
2014-02-01 14:24 ` [PATCH 09/17] msi3101: sleep USB ADC and tuner when streaming is stopped Antti Palosaari
2014-02-01 14:24 ` [PATCH 10/17] DocBook: document RF tuner gain controls Antti Palosaari
2014-02-01 14:24 ` [PATCH 11/17] DocBook: V4L: add V4L2_SDR_FMT_CU8 - 'CU08' Antti Palosaari
2014-02-01 14:24 ` [PATCH 12/17] DocBook: V4L: add V4L2_SDR_FMT_CU16LE - 'CU16' Antti Palosaari
2014-02-01 14:24 ` [PATCH 13/17] DocBook: media: document V4L2_CTRL_CLASS_RF_TUNER Antti Palosaari
2014-02-01 14:24 ` [PATCH 14/17] xc2028: silence compiler warnings Antti Palosaari
2014-02-01 14:24 ` [PATCH 15/17] v4l: add RF tuner channel bandwidth control Antti Palosaari
2014-02-03  9:08   ` Hans Verkuil
2014-02-03  9:11     ` Hans Verkuil
2014-02-03 10:17       ` Antti Palosaari
2014-02-03 10:13     ` Antti Palosaari
2014-02-03 10:24       ` Hans Verkuil
2014-02-01 14:24 ` [PATCH 16/17] msi3101: implement tuner " Antti Palosaari
2014-02-01 14:24 ` [PATCH 17/17] rtl2832_sdr: " Antti Palosaari

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.