All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 0/4] SDR API set ADC and RF frequency
@ 2013-12-11 23:53 Antti Palosaari
  2013-12-11 23:54 ` [PATCH RFC 1/4] v4l2-core: don't clear VIDIOC_G_FREQUENCY tuner type Antti Palosaari
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Antti Palosaari @ 2013-12-11 23:53 UTC (permalink / raw)
  To: linux-media; +Cc: Mauro Carvalho Chehab, Hans Verkuil, Antti Palosaari

Here is small example what it looks like when v4l2-ctl is used.

[crope@localhost v4l2-ctl]$ 
[crope@localhost v4l2-ctl]$ ./v4l2-ctl -d /dev/sdr0 --all
Driver Info (not using libv4l2):
	Driver name   : rtl2832_sdr
	Card type     : Realtek RTL2832U SDR
	Bus info      : usb-0000:00:13.2-2
	Driver version: 3.13.0
	Capabilities  : 0x85010001
		Video Capture
		Tuner
		Read/Write
		Streaming
		Device Capabilities
	Device Caps   : 0x05010001
		Video Capture
		Tuner
		Read/Write
		Streaming
Priority: 2
Frequency for tuner 0: 0 (0.000000 MHz)
Tuner 0:
	Name                 : ADC
	Capabilities         : 1 Hz freq-bands 
	Frequency range      : 0.300000 MHz - 3.200000 MHz
Video input : 0 (SDR data: ok)

User Controls
                     tuner_gain (int)    : min=0 max=102 step=1 default=0 value=0
[crope@localhost v4l2-ctl]$ ./v4l2-ctl -d /dev/sdr0 --tuner-index=1 --all
Driver Info (not using libv4l2):
	Driver name   : rtl2832_sdr
	Card type     : Realtek RTL2832U SDR
	Bus info      : usb-0000:00:13.2-2
	Driver version: 3.13.0
	Capabilities  : 0x85010001
		Video Capture
		Tuner
		Read/Write
		Streaming
		Device Capabilities
	Device Caps   : 0x05010001
		Video Capture
		Tuner
		Read/Write
		Streaming
Priority: 2
Frequency for tuner 1: 0 (0.000000 MHz)
Tuner 1:
	Name                 : RF
	Capabilities         : 62.5 Hz freq-bands 
	Frequency range      : 50.000 MHz - 1500.000 MHz
Video input : 0 (SDR data: ok)

User Controls
                     tuner_gain (int)    : min=0 max=102 step=1 default=0 value=0
(reverse-i-search)`en': gedit drivers/media/radio/radio-ke^Ce.c
[crope@localhost v4l2-ctl]$ ./v4l2-ctl -d /dev/sdr0 --tuner-index=0 --list-freq-bands
ioctl: VIDIOC_ENUM_FREQ_BANDS
	Index          : 0
	Modulation     : Unknown
	Capability     : 1 Hz freq-bands 
	Frequency Range: 0.300000 MHz - 0.300000 MHz

	Index          : 1
	Modulation     : Unknown
	Capability     : 1 Hz freq-bands 
	Frequency Range: 0.900001 MHz - 2.800000 MHz

	Index          : 2
	Modulation     : Unknown
	Capability     : 1 Hz freq-bands 
	Frequency Range: 3.200000 MHz - 3.200000 MHz
[crope@localhost v4l2-ctl]$ ./v4l2-ctl -d /dev/sdr0 --tuner-index=1 --list-freq-bands
ioctl: VIDIOC_ENUM_FREQ_BANDS
	Index          : 0
	Modulation     : Unknown
	Capability     : 62.5 Hz freq-bands 
	Frequency Range: 50.000 MHz - 1500.000 MHz
[crope@localhost v4l2-ctl]$ ./v4l2-ctl -d /dev/sdr0 --tuner-index=0 --set-freq=0.300000
Frequency for tuner 0 set to 300000 (0.300000 MHz)
[crope@localhost v4l2-ctl]$ ./v4l2-ctl -d /dev/sdr0 --tuner-index=0 --get-freq
Frequency for tuner 0: 300000 (0.300000 MHz)
[crope@localhost v4l2-ctl]$ ./v4l2-ctl -d /dev/sdr0 --tuner-index=1 --set-freq=100
Frequency for tuner 1 set to 1600000 (100.000000 MHz)
[crope@localhost v4l2-ctl]$ ./v4l2-ctl -d /dev/sdr0 --tuner-index=1 --get-freq
Frequency for tuner 1: 1600000 (100.000000 MHz)
[crope@localhost v4l2-ctl]$ ./v4l2-ctl -d /dev/sdr0 --tuner-index=1 --all
Driver Info (not using libv4l2):
	Driver name   : rtl2832_sdr
	Card type     : Realtek RTL2832U SDR
	Bus info      : usb-0000:00:13.2-2
	Driver version: 3.13.0
	Capabilities  : 0x85010001
		Video Capture
		Tuner
		Read/Write
		Streaming
		Device Capabilities
	Device Caps   : 0x05010001
		Video Capture
		Tuner
		Read/Write
		Streaming
Priority: 2
Frequency for tuner 1: 1600000 (100.000000 MHz)
Tuner 1:
	Name                 : RF
	Capabilities         : 62.5 Hz freq-bands 
	Frequency range      : 50.000 MHz - 1500.000 MHz
Video input : 0 (SDR data: ok)

User Controls
                     tuner_gain (int)    : min=0 max=102 step=1 default=0 value=0
[crope@localhost v4l2-ctl]$ ./v4l2-ctl -d /dev/sdr0 --tuner-index=0 --all
Driver Info (not using libv4l2):
	Driver name   : rtl2832_sdr
	Card type     : Realtek RTL2832U SDR
	Bus info      : usb-0000:00:13.2-2
	Driver version: 3.13.0
	Capabilities  : 0x85010001
		Video Capture
		Tuner
		Read/Write
		Streaming
		Device Capabilities
	Device Caps   : 0x05010001
		Video Capture
		Tuner
		Read/Write
		Streaming
Priority: 2
Frequency for tuner 0: 300000 (0.300000 MHz)
Tuner 0:
	Name                 : ADC
	Capabilities         : 1 Hz freq-bands 
	Frequency range      : 0.300000 MHz - 3.200000 MHz
Video input : 0 (SDR data: ok)

User Controls
                     tuner_gain (int)    : min=0 max=102 step=1 default=0 value=0
[crope@localhost v4l2-ctl]$ 



Antti Palosaari (4):
  v4l2-core: don't clear VIDIOC_G_FREQUENCY tuner type
  v4l2: add new device type for Software Defined Radio
  v4l: add new tuner types for SDR
  v4l: 1 Hz resolution flag for tuners

 drivers/media/v4l2-core/v4l2-dev.c   |  5 +++++
 drivers/media/v4l2-core/v4l2-ioctl.c | 40 +++++++++++++++++++++++++-----------
 include/media/v4l2-dev.h             |  3 ++-
 include/uapi/linux/videodev2.h       |  3 +++
 4 files changed, 38 insertions(+), 13 deletions(-)

-- 
1.8.4.2


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

* [PATCH RFC 1/4] v4l2-core: don't clear VIDIOC_G_FREQUENCY tuner type
  2013-12-11 23:53 [PATCH RFC 0/4] SDR API set ADC and RF frequency Antti Palosaari
@ 2013-12-11 23:54 ` Antti Palosaari
  2013-12-11 23:54 ` [PATCH RFC 2/4] v4l2: add new device type for Software Defined Radio Antti Palosaari
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: Antti Palosaari @ 2013-12-11 23:54 UTC (permalink / raw)
  To: linux-media; +Cc: Mauro Carvalho Chehab, Hans Verkuil, Antti Palosaari

No need to clear as it will be overridden in every case when
v4l_g_frequency() is called. We will need that value later when
new tuner types are defined.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 68e6b5e..bc10684 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -2013,7 +2013,7 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_STD(VIDIOC_S_AUDOUT, vidioc_s_audout, v4l_print_audioout, INFO_FL_PRIO),
 	IOCTL_INFO_FNC(VIDIOC_G_MODULATOR, v4l_g_modulator, v4l_print_modulator, INFO_FL_CLEAR(v4l2_modulator, index)),
 	IOCTL_INFO_STD(VIDIOC_S_MODULATOR, vidioc_s_modulator, v4l_print_modulator, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_G_FREQUENCY, v4l_g_frequency, v4l_print_frequency, INFO_FL_CLEAR(v4l2_frequency, tuner)),
+	IOCTL_INFO_FNC(VIDIOC_G_FREQUENCY, v4l_g_frequency, v4l_print_frequency, INFO_FL_CLEAR(v4l2_frequency, type)),
 	IOCTL_INFO_FNC(VIDIOC_S_FREQUENCY, v4l_s_frequency, v4l_print_frequency, INFO_FL_PRIO),
 	IOCTL_INFO_FNC(VIDIOC_CROPCAP, v4l_cropcap, v4l_print_cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)),
 	IOCTL_INFO_FNC(VIDIOC_G_CROP, v4l_g_crop, v4l_print_crop, INFO_FL_CLEAR(v4l2_crop, type)),
-- 
1.8.4.2


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

* [PATCH RFC 2/4] v4l2: add new device type for Software Defined Radio
  2013-12-11 23:53 [PATCH RFC 0/4] SDR API set ADC and RF frequency Antti Palosaari
  2013-12-11 23:54 ` [PATCH RFC 1/4] v4l2-core: don't clear VIDIOC_G_FREQUENCY tuner type Antti Palosaari
@ 2013-12-11 23:54 ` Antti Palosaari
  2013-12-11 23:54 ` [PATCH RFC 3/4] v4l: add new tuner types for SDR Antti Palosaari
  2013-12-11 23:54 ` [PATCH RFC 4/4] v4l: 1 Hz resolution flag for tuners Antti Palosaari
  3 siblings, 0 replies; 16+ messages in thread
From: Antti Palosaari @ 2013-12-11 23:54 UTC (permalink / raw)
  To: linux-media; +Cc: Mauro Carvalho Chehab, Hans Verkuil, Antti Palosaari

Add new V4L device type VFL_TYPE_SDR for Software Defined Radio.
It is registered as /dev/sdr0

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/v4l2-core/v4l2-dev.c | 5 +++++
 include/media/v4l2-dev.h           | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 1cc1749..c9cf54c 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -767,6 +767,8 @@ static void determine_valid_ioctls(struct video_device *vdev)
  *	%VFL_TYPE_RADIO - A radio card
  *
  *	%VFL_TYPE_SUBDEV - A subdevice
+ *
+ *	%VFL_TYPE_SDR - Software Defined Radio
  */
 int __video_register_device(struct video_device *vdev, int type, int nr,
 		int warn_if_nr_in_use, struct module *owner)
@@ -806,6 +808,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
 	case VFL_TYPE_SUBDEV:
 		name_base = "v4l-subdev";
 		break;
+	case VFL_TYPE_SDR:
+		name_base = "sdr";
+		break;
 	default:
 		printk(KERN_ERR "%s called with unknown type: %d\n",
 		       __func__, type);
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index c768c9f..eec6e46 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -24,7 +24,8 @@
 #define VFL_TYPE_VBI		1
 #define VFL_TYPE_RADIO		2
 #define VFL_TYPE_SUBDEV		3
-#define VFL_TYPE_MAX		4
+#define VFL_TYPE_SDR		4
+#define VFL_TYPE_MAX		5
 
 /* Is this a receiver, transmitter or mem-to-mem? */
 /* Ignored for VFL_TYPE_SUBDEV. */
-- 
1.8.4.2


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

* [PATCH RFC 3/4] v4l: add new tuner types for SDR
  2013-12-11 23:53 [PATCH RFC 0/4] SDR API set ADC and RF frequency Antti Palosaari
  2013-12-11 23:54 ` [PATCH RFC 1/4] v4l2-core: don't clear VIDIOC_G_FREQUENCY tuner type Antti Palosaari
  2013-12-11 23:54 ` [PATCH RFC 2/4] v4l2: add new device type for Software Defined Radio Antti Palosaari
@ 2013-12-11 23:54 ` Antti Palosaari
  2013-12-12  7:50   ` Hans Verkuil
  2013-12-11 23:54 ` [PATCH RFC 4/4] v4l: 1 Hz resolution flag for tuners Antti Palosaari
  3 siblings, 1 reply; 16+ messages in thread
From: Antti Palosaari @ 2013-12-11 23:54 UTC (permalink / raw)
  To: linux-media; +Cc: Mauro Carvalho Chehab, Hans Verkuil, Antti Palosaari

Define tuner types V4L2_TUNER_ADC and V4L2_TUNER_SDR for SDR usage.

ADC is used for setting sampling rate (sampling frequency) to SDR
device.

Another tuner type, SDR, is possible RF tuner. Is is used to
down-convert RF frequency to range ADC could sample. It is optional
for SDR device.

Also add checks to VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY and
VIDIOC_ENUM_FREQ_BANDS only allow these two tuner types when device
type is SDR (VFL_TYPE_SDR).

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 38 +++++++++++++++++++++++++-----------
 include/uapi/linux/videodev2.h       |  2 ++
 2 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index bc10684..ee91a9f 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1288,8 +1288,13 @@ static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_frequency *p = arg;
 
-	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
-			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
+	if (vfd->vfl_type == VFL_TYPE_SDR) {
+		if (p->type != V4L2_TUNER_ADC && p->type != V4L2_TUNER_SDR)
+			return -EINVAL;
+	} else {
+		p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
+				V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
+	}
 	return ops->vidioc_g_frequency(file, fh, p);
 }
 
@@ -1300,10 +1305,16 @@ static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
 	const struct v4l2_frequency *p = arg;
 	enum v4l2_tuner_type type;
 
-	type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
-			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-	if (p->type != type)
-		return -EINVAL;
+	if (vfd->vfl_type == VFL_TYPE_SDR) {
+		if (p->type != V4L2_TUNER_ADC && p->type != V4L2_TUNER_SDR)
+			return -EINVAL;
+		type = p->type;
+	} else {
+		type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
+				V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
+		if (type != p->type)
+			return -EINVAL;
+	}
 	return ops->vidioc_s_frequency(file, fh, p);
 }
 
@@ -1882,11 +1893,16 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
 	enum v4l2_tuner_type type;
 	int err;
 
-	type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
-			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-
-	if (type != p->type)
-		return -EINVAL;
+	if (vfd->vfl_type == VFL_TYPE_SDR) {
+		if (p->type != V4L2_TUNER_ADC && p->type != V4L2_TUNER_SDR)
+			return -EINVAL;
+		type = p->type;
+	} else {
+		type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
+				V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
+		if (type != p->type)
+			return -EINVAL;
+	}
 	if (ops->vidioc_enum_freq_bands)
 		return ops->vidioc_enum_freq_bands(file, fh, p);
 	if (is_valid_ioctl(vfd, VIDIOC_G_TUNER)) {
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index b8ee9048..6c6a601 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -159,6 +159,8 @@ enum v4l2_tuner_type {
 	V4L2_TUNER_RADIO	     = 1,
 	V4L2_TUNER_ANALOG_TV	     = 2,
 	V4L2_TUNER_DIGITAL_TV	     = 3,
+	V4L2_TUNER_ADC               = 4,
+	V4L2_TUNER_SDR               = 5,
 };
 
 enum v4l2_memory {
-- 
1.8.4.2


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

* [PATCH RFC 4/4] v4l: 1 Hz resolution flag for tuners
  2013-12-11 23:53 [PATCH RFC 0/4] SDR API set ADC and RF frequency Antti Palosaari
                   ` (2 preceding siblings ...)
  2013-12-11 23:54 ` [PATCH RFC 3/4] v4l: add new tuner types for SDR Antti Palosaari
@ 2013-12-11 23:54 ` Antti Palosaari
  2013-12-12  7:55   ` Hans Verkuil
  3 siblings, 1 reply; 16+ messages in thread
From: Antti Palosaari @ 2013-12-11 23:54 UTC (permalink / raw)
  To: linux-media; +Cc: Mauro Carvalho Chehab, Hans Verkuil, Antti Palosaari

Add V4L2_TUNER_CAP_1HZ for 1 Hz resolution.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 include/uapi/linux/videodev2.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 6c6a601..1bac6c4 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -1349,6 +1349,7 @@ struct v4l2_modulator {
 #define V4L2_TUNER_CAP_RDS_CONTROLS	0x0200
 #define V4L2_TUNER_CAP_FREQ_BANDS	0x0400
 #define V4L2_TUNER_CAP_HWSEEK_PROG_LIM	0x0800
+#define V4L2_TUNER_CAP_1HZ		0x1000
 
 /*  Flags for the 'rxsubchans' field */
 #define V4L2_TUNER_SUB_MONO		0x0001
-- 
1.8.4.2


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

* Re: [PATCH RFC 3/4] v4l: add new tuner types for SDR
  2013-12-11 23:54 ` [PATCH RFC 3/4] v4l: add new tuner types for SDR Antti Palosaari
@ 2013-12-12  7:50   ` Hans Verkuil
  2013-12-12 17:12     ` Antti Palosaari
  0 siblings, 1 reply; 16+ messages in thread
From: Hans Verkuil @ 2013-12-12  7:50 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media, Mauro Carvalho Chehab

On 12/12/2013 12:54 AM, Antti Palosaari wrote:
> Define tuner types V4L2_TUNER_ADC and V4L2_TUNER_SDR for SDR usage.
> 
> ADC is used for setting sampling rate (sampling frequency) to SDR
> device.
> 
> Another tuner type, SDR, is possible RF tuner. Is is used to
> down-convert RF frequency to range ADC could sample. It is optional
> for SDR device.
> 
> Also add checks to VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY and
> VIDIOC_ENUM_FREQ_BANDS only allow these two tuner types when device
> type is SDR (VFL_TYPE_SDR).

Shouldn't you also adapt s_hw_freq_seek?

> 
> Signed-off-by: Antti Palosaari <crope@iki.fi>
> ---
>  drivers/media/v4l2-core/v4l2-ioctl.c | 38 +++++++++++++++++++++++++-----------
>  include/uapi/linux/videodev2.h       |  2 ++
>  2 files changed, 29 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index bc10684..ee91a9f 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -1288,8 +1288,13 @@ static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
>  	struct video_device *vfd = video_devdata(file);
>  	struct v4l2_frequency *p = arg;
>  
> -	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
> -			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
> +	if (vfd->vfl_type == VFL_TYPE_SDR) {
> +		if (p->type != V4L2_TUNER_ADC && p->type != V4L2_TUNER_SDR)
> +			return -EINVAL;

This isn't right. p->type is returned by the driver, not set by the user.
In the case of TYPE_SDR I would just set it to TUNER_SDR and let the driver
update it for ADC tuners. You can also just leave it alone. This does make
the assumption that SDR and ADC tuners are always separate tuners. I.e., not
like radio and TV tuners that can be one physical tuner with two mutually
exclusive modes. It's my understanding that that is by definition true for
SDR.

> +	} else {
> +		p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
> +				V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
> +	}
>  	return ops->vidioc_g_frequency(file, fh, p);
>  }
>  
> @@ -1300,10 +1305,16 @@ static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
>  	const struct v4l2_frequency *p = arg;
>  	enum v4l2_tuner_type type;
>  
> -	type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
> -			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
> -	if (p->type != type)
> -		return -EINVAL;
> +	if (vfd->vfl_type == VFL_TYPE_SDR) {
> +		if (p->type != V4L2_TUNER_ADC && p->type != V4L2_TUNER_SDR)
> +			return -EINVAL;
> +		type = p->type;
> +	} else {
> +		type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
> +				V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
> +		if (type != p->type)
> +			return -EINVAL;
> +	}
>  	return ops->vidioc_s_frequency(file, fh, p);
>  }
>  
> @@ -1882,11 +1893,16 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
>  	enum v4l2_tuner_type type;
>  	int err;
>  
> -	type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
> -			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
> -
> -	if (type != p->type)
> -		return -EINVAL;
> +	if (vfd->vfl_type == VFL_TYPE_SDR) {
> +		if (p->type != V4L2_TUNER_ADC && p->type != V4L2_TUNER_SDR)
> +			return -EINVAL;
> +		type = p->type;
> +	} else {
> +		type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
> +				V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
> +		if (type != p->type)
> +			return -EINVAL;
> +	}
>  	if (ops->vidioc_enum_freq_bands)
>  		return ops->vidioc_enum_freq_bands(file, fh, p);
>  	if (is_valid_ioctl(vfd, VIDIOC_G_TUNER)) {
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index b8ee9048..6c6a601 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -159,6 +159,8 @@ enum v4l2_tuner_type {
>  	V4L2_TUNER_RADIO	     = 1,
>  	V4L2_TUNER_ANALOG_TV	     = 2,
>  	V4L2_TUNER_DIGITAL_TV	     = 3,
> +	V4L2_TUNER_ADC               = 4,
> +	V4L2_TUNER_SDR               = 5,
>  };
>  
>  enum v4l2_memory {
> 

Regards,

	Hans

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

* Re: [PATCH RFC 4/4] v4l: 1 Hz resolution flag for tuners
  2013-12-11 23:54 ` [PATCH RFC 4/4] v4l: 1 Hz resolution flag for tuners Antti Palosaari
@ 2013-12-12  7:55   ` Hans Verkuil
  2013-12-12 17:22     ` Antti Palosaari
  0 siblings, 1 reply; 16+ messages in thread
From: Hans Verkuil @ 2013-12-12  7:55 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media, Mauro Carvalho Chehab

On 12/12/2013 12:54 AM, Antti Palosaari wrote:
> Add V4L2_TUNER_CAP_1HZ for 1 Hz resolution.
> 
> Signed-off-by: Antti Palosaari <crope@iki.fi>
> ---
>  include/uapi/linux/videodev2.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index 6c6a601..1bac6c4 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -1349,6 +1349,7 @@ struct v4l2_modulator {
>  #define V4L2_TUNER_CAP_RDS_CONTROLS	0x0200
>  #define V4L2_TUNER_CAP_FREQ_BANDS	0x0400
>  #define V4L2_TUNER_CAP_HWSEEK_PROG_LIM	0x0800
> +#define V4L2_TUNER_CAP_1HZ		0x1000
>  
>  /*  Flags for the 'rxsubchans' field */
>  #define V4L2_TUNER_SUB_MONO		0x0001
> 

I was wondering, do the band modulation systems (V4L2_BAND_MODULATION_VSB etc.) cover SDR?

Anyway, I'm happy with this patch series. As far as I am concerned, the next step would
be to add documention and I would also recommend updating v4l2-compliance. Writing docs
and adding compliance tests has proven useful in the past to discover ambiguous API specs.

Regards,

	Hans

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

* Re: [PATCH RFC 3/4] v4l: add new tuner types for SDR
  2013-12-12  7:50   ` Hans Verkuil
@ 2013-12-12 17:12     ` Antti Palosaari
  2013-12-12 19:14       ` Antti Palosaari
  2013-12-13 13:58       ` Hans Verkuil
  0 siblings, 2 replies; 16+ messages in thread
From: Antti Palosaari @ 2013-12-12 17:12 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, Mauro Carvalho Chehab

On 12.12.2013 09:50, Hans Verkuil wrote:
> On 12/12/2013 12:54 AM, Antti Palosaari wrote:
>> Define tuner types V4L2_TUNER_ADC and V4L2_TUNER_SDR for SDR usage.
>>
>> ADC is used for setting sampling rate (sampling frequency) to SDR
>> device.
>>
>> Another tuner type, SDR, is possible RF tuner. Is is used to
>> down-convert RF frequency to range ADC could sample. It is optional
>> for SDR device.
>>
>> Also add checks to VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY and
>> VIDIOC_ENUM_FREQ_BANDS only allow these two tuner types when device
>> type is SDR (VFL_TYPE_SDR).
>
> Shouldn't you also adapt s_hw_freq_seek?

nope! I don't see how SDR could do hardware seek as demodulator is 
needed to make decision if radio channel is valid or not. On SDR 
receiver that demodulator is implemented by application software, DSP, 
thus name software defined radio.

Maybe it could be mapped to signal strength measurement, but it is 
another story to think.


>> Signed-off-by: Antti Palosaari <crope@iki.fi>
>> ---
>>   drivers/media/v4l2-core/v4l2-ioctl.c | 38 +++++++++++++++++++++++++-----------
>>   include/uapi/linux/videodev2.h       |  2 ++
>>   2 files changed, 29 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
>> index bc10684..ee91a9f 100644
>> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
>> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
>> @@ -1288,8 +1288,13 @@ static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
>>   	struct video_device *vfd = video_devdata(file);
>>   	struct v4l2_frequency *p = arg;
>>
>> -	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
>> -			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
>> +	if (vfd->vfl_type == VFL_TYPE_SDR) {
>> +		if (p->type != V4L2_TUNER_ADC && p->type != V4L2_TUNER_SDR)
>> +			return -EINVAL;
>
> This isn't right. p->type is returned by the driver, not set by the user.
> In the case of TYPE_SDR I would just set it to TUNER_SDR and let the driver
> update it for ADC tuners. You can also just leave it alone. This does make
> the assumption that SDR and ADC tuners are always separate tuners. I.e., not
> like radio and TV tuners that can be one physical tuner with two mutually
> exclusive modes. It's my understanding that that is by definition true for
> SDR.

Aaah, so it is possible to use same tuner and that type is aimed for 
selecting tuner operation mode. Makes sense.

So if I now understand V4L2 driver model correctly, there should be one 
tuner that implements different functionality by using tuner type field.

I could change it easily, no problem.


>> +	} else {
>> +		p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
>> +				V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
>> +	}
>>   	return ops->vidioc_g_frequency(file, fh, p);
>>   }
>>
>> @@ -1300,10 +1305,16 @@ static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
>>   	const struct v4l2_frequency *p = arg;
>>   	enum v4l2_tuner_type type;
>>
>> -	type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
>> -			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
>> -	if (p->type != type)
>> -		return -EINVAL;
>> +	if (vfd->vfl_type == VFL_TYPE_SDR) {
>> +		if (p->type != V4L2_TUNER_ADC && p->type != V4L2_TUNER_SDR)
>> +			return -EINVAL;
>> +		type = p->type;
>> +	} else {
>> +		type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
>> +				V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
>> +		if (type != p->type)
>> +			return -EINVAL;
>> +	}
>>   	return ops->vidioc_s_frequency(file, fh, p);
>>   }
>>
>> @@ -1882,11 +1893,16 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
>>   	enum v4l2_tuner_type type;
>>   	int err;
>>
>> -	type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
>> -			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
>> -
>> -	if (type != p->type)
>> -		return -EINVAL;
>> +	if (vfd->vfl_type == VFL_TYPE_SDR) {
>> +		if (p->type != V4L2_TUNER_ADC && p->type != V4L2_TUNER_SDR)
>> +			return -EINVAL;
>> +		type = p->type;
>> +	} else {
>> +		type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
>> +				V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
>> +		if (type != p->type)
>> +			return -EINVAL;
>> +	}
>>   	if (ops->vidioc_enum_freq_bands)
>>   		return ops->vidioc_enum_freq_bands(file, fh, p);
>>   	if (is_valid_ioctl(vfd, VIDIOC_G_TUNER)) {
>> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
>> index b8ee9048..6c6a601 100644
>> --- a/include/uapi/linux/videodev2.h
>> +++ b/include/uapi/linux/videodev2.h
>> @@ -159,6 +159,8 @@ enum v4l2_tuner_type {
>>   	V4L2_TUNER_RADIO	     = 1,
>>   	V4L2_TUNER_ANALOG_TV	     = 2,
>>   	V4L2_TUNER_DIGITAL_TV	     = 3,
>> +	V4L2_TUNER_ADC               = 4,
>> +	V4L2_TUNER_SDR               = 5,
>>   };
>>
>>   enum v4l2_memory {
>>
>
> Regards,
>
> 	Hans
>

regards
Antti


-- 
http://palosaari.fi/

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

* Re: [PATCH RFC 4/4] v4l: 1 Hz resolution flag for tuners
  2013-12-12  7:55   ` Hans Verkuil
@ 2013-12-12 17:22     ` Antti Palosaari
  2013-12-13 14:05       ` Hans Verkuil
  0 siblings, 1 reply; 16+ messages in thread
From: Antti Palosaari @ 2013-12-12 17:22 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, Mauro Carvalho Chehab

Hi Hans!

On 12.12.2013 09:55, Hans Verkuil wrote:
> On 12/12/2013 12:54 AM, Antti Palosaari wrote:
>> Add V4L2_TUNER_CAP_1HZ for 1 Hz resolution.
>>
>> Signed-off-by: Antti Palosaari <crope@iki.fi>
>> ---
>>   include/uapi/linux/videodev2.h | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
>> index 6c6a601..1bac6c4 100644
>> --- a/include/uapi/linux/videodev2.h
>> +++ b/include/uapi/linux/videodev2.h
>> @@ -1349,6 +1349,7 @@ struct v4l2_modulator {
>>   #define V4L2_TUNER_CAP_RDS_CONTROLS	0x0200
>>   #define V4L2_TUNER_CAP_FREQ_BANDS	0x0400
>>   #define V4L2_TUNER_CAP_HWSEEK_PROG_LIM	0x0800
>> +#define V4L2_TUNER_CAP_1HZ		0x1000
>>
>>   /*  Flags for the 'rxsubchans' field */
>>   #define V4L2_TUNER_SUB_MONO		0x0001
>>
>
> I was wondering, do the band modulation systems (V4L2_BAND_MODULATION_VSB etc.) cover SDR?

There is no such modulations defined for SDR hardware level. SDR 
demodulation is done by software called DSP (digital signal processing) 
in host computer.

In ideal case, SDR receiver has only 1 property: ADC (analog to digital 
converter) sampling rate.

But as digital signal processing is very CPU intensive when sampling 
rates are increased, there is very often RF tuner used to down-convert 
actual radio frequency to low-IF / BB. Then ADC is used to sample that 
baseband / low-IF signal and only small sampling rate is needed => 
stream is smaller => DSP does not need so much CPU.

> Anyway, I'm happy with this patch series. As far as I am concerned, the next step would
> be to add documention and I would also recommend updating v4l2-compliance. Writing docs
> and adding compliance tests has proven useful in the past to discover ambiguous API specs.

I will do these at finally when I drivers and applications are tested to 
be working.

regards
Antti

-- 
http://palosaari.fi/

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

* Re: [PATCH RFC 3/4] v4l: add new tuner types for SDR
  2013-12-12 17:12     ` Antti Palosaari
@ 2013-12-12 19:14       ` Antti Palosaari
  2013-12-13 14:31         ` Hans Verkuil
  2013-12-13 13:58       ` Hans Verkuil
  1 sibling, 1 reply; 16+ messages in thread
From: Antti Palosaari @ 2013-12-12 19:14 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, Mauro Carvalho Chehab

On 12.12.2013 19:12, Antti Palosaari wrote:
> On 12.12.2013 09:50, Hans Verkuil wrote:
>> On 12/12/2013 12:54 AM, Antti Palosaari wrote:

>>> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c
>>> b/drivers/media/v4l2-core/v4l2-ioctl.c
>>> index bc10684..ee91a9f 100644
>>> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
>>> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
>>> @@ -1288,8 +1288,13 @@ static int v4l_g_frequency(const struct
>>> v4l2_ioctl_ops *ops,
>>>       struct video_device *vfd = video_devdata(file);
>>>       struct v4l2_frequency *p = arg;
>>>
>>> -    p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
>>> -            V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
>>> +    if (vfd->vfl_type == VFL_TYPE_SDR) {
>>> +        if (p->type != V4L2_TUNER_ADC && p->type != V4L2_TUNER_SDR)
>>> +            return -EINVAL;
>>
>> This isn't right. p->type is returned by the driver, not set by the user.
>> In the case of TYPE_SDR I would just set it to TUNER_SDR and let the
>> driver
>> update it for ADC tuners. You can also just leave it alone. This does
>> make
>> the assumption that SDR and ADC tuners are always separate tuners.
>> I.e., not
>> like radio and TV tuners that can be one physical tuner with two mutually
>> exclusive modes. It's my understanding that that is by definition true
>> for
>> SDR.
>
> Aaah, so it is possible to use same tuner and that type is aimed for
> selecting tuner operation mode. Makes sense.
>
> So if I now understand V4L2 driver model correctly, there should be one
> tuner that implements different functionality by using tuner type field.
>
> I could change it easily, no problem.

http://hverkuil.home.xs4all.nl/spec/media.html#vidioc-g-frequency
I still don't understand that. Why both index and type should be defined 
for VIDIOC_S_FREQUENCY, but the opposite command VIDIOC_G_FREQUENCY 
requires only index and returns type too? It does not sound correct 
behavior.
If S_FREQUENCY/G_FREQUENCY should be able to handle multiple tuner types 
for same tuner index, then type must be also given that driver could 
detect required mode.

http://hverkuil.home.xs4all.nl/spec/media.html#vidioc-g-tuner
How I can enumerate tuners. There is G_TUNER/S_TUNER for enumerating, 
but documentation of these IOCTLs looks like only one tuner type per 
tuner index is supported. That offers enumeration per tuner index.

regards
Antti

-- 
http://palosaari.fi/

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

* Re: [PATCH RFC 3/4] v4l: add new tuner types for SDR
  2013-12-12 17:12     ` Antti Palosaari
  2013-12-12 19:14       ` Antti Palosaari
@ 2013-12-13 13:58       ` Hans Verkuil
  1 sibling, 0 replies; 16+ messages in thread
From: Hans Verkuil @ 2013-12-13 13:58 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media, Mauro Carvalho Chehab

On 12/12/2013 06:12 PM, Antti Palosaari wrote:
> On 12.12.2013 09:50, Hans Verkuil wrote:
>> On 12/12/2013 12:54 AM, Antti Palosaari wrote:
>>> Define tuner types V4L2_TUNER_ADC and V4L2_TUNER_SDR for SDR usage.
>>>
>>> ADC is used for setting sampling rate (sampling frequency) to SDR
>>> device.
>>>
>>> Another tuner type, SDR, is possible RF tuner. Is is used to
>>> down-convert RF frequency to range ADC could sample. It is optional
>>> for SDR device.
>>>
>>> Also add checks to VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY and
>>> VIDIOC_ENUM_FREQ_BANDS only allow these two tuner types when device
>>> type is SDR (VFL_TYPE_SDR).
>>
>> Shouldn't you also adapt s_hw_freq_seek?
> 
> nope! I don't see how SDR could do hardware seek as demodulator is 
> needed to make decision if radio channel is valid or not. On SDR 
> receiver that demodulator is implemented by application software, DSP, 
> thus name software defined radio.
> 
> Maybe it could be mapped to signal strength measurement, but it is 
> another story to think.

Fair enough, but in that case I would add:

	/* s_hw_freq_seek is not supported for SDR for now */
	if (vfd->vfl_type == VFL_TYPE_SDR)
		return -EINVAL;

at the beginning of v4l_s_hw_freq_seek().

Regards,

	Hans

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

* Re: [PATCH RFC 4/4] v4l: 1 Hz resolution flag for tuners
  2013-12-12 17:22     ` Antti Palosaari
@ 2013-12-13 14:05       ` Hans Verkuil
  2013-12-13 15:42         ` Antti Palosaari
  0 siblings, 1 reply; 16+ messages in thread
From: Hans Verkuil @ 2013-12-13 14:05 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media, Mauro Carvalho Chehab

On 12/12/2013 06:22 PM, Antti Palosaari wrote:
> Hi Hans!
> 
> On 12.12.2013 09:55, Hans Verkuil wrote:
>> On 12/12/2013 12:54 AM, Antti Palosaari wrote:
>>> Add V4L2_TUNER_CAP_1HZ for 1 Hz resolution.
>>>
>>> Signed-off-by: Antti Palosaari <crope@iki.fi>
>>> ---
>>>   include/uapi/linux/videodev2.h | 1 +
>>>   1 file changed, 1 insertion(+)
>>>
>>> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
>>> index 6c6a601..1bac6c4 100644
>>> --- a/include/uapi/linux/videodev2.h
>>> +++ b/include/uapi/linux/videodev2.h
>>> @@ -1349,6 +1349,7 @@ struct v4l2_modulator {
>>>   #define V4L2_TUNER_CAP_RDS_CONTROLS	0x0200
>>>   #define V4L2_TUNER_CAP_FREQ_BANDS	0x0400
>>>   #define V4L2_TUNER_CAP_HWSEEK_PROG_LIM	0x0800
>>> +#define V4L2_TUNER_CAP_1HZ		0x1000
>>>
>>>   /*  Flags for the 'rxsubchans' field */
>>>   #define V4L2_TUNER_SUB_MONO		0x0001
>>>
>>
>> I was wondering, do the band modulation systems (V4L2_BAND_MODULATION_VSB etc.) cover SDR?
> 
> There is no such modulations defined for SDR hardware level. SDR 
> demodulation is done by software called DSP (digital signal processing) 
> in host computer.
> 
> In ideal case, SDR receiver has only 1 property: ADC (analog to digital 
> converter) sampling rate.

So in that case the band modulation would be 0, right?

> 
> But as digital signal processing is very CPU intensive when sampling 
> rates are increased, there is very often RF tuner used to down-convert 
> actual radio frequency to low-IF / BB. Then ADC is used to sample that 
> baseband / low-IF signal and only small sampling rate is needed => 
> stream is smaller => DSP does not need so much CPU.

How does the application know that there is an RF tuner? I assume that
the app needs to know this?

As you can probably tell, I basically know nothing about SDR, so forgive
me if I am asking stupid questions. I just want to make sure all bases
are covered when it comes to the V4L2 API.

Regards,

	Hans

>> Anyway, I'm happy with this patch series. As far as I am concerned, the next step would
>> be to add documention and I would also recommend updating v4l2-compliance. Writing docs
>> and adding compliance tests has proven useful in the past to discover ambiguous API specs.
> 
> I will do these at finally when I drivers and applications are tested to 
> be working.
> 
> regards
> Antti
> 


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

* Re: [PATCH RFC 3/4] v4l: add new tuner types for SDR
  2013-12-12 19:14       ` Antti Palosaari
@ 2013-12-13 14:31         ` Hans Verkuil
  0 siblings, 0 replies; 16+ messages in thread
From: Hans Verkuil @ 2013-12-13 14:31 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media, Mauro Carvalho Chehab

On 12/12/2013 08:14 PM, Antti Palosaari wrote:
> On 12.12.2013 19:12, Antti Palosaari wrote:
>> On 12.12.2013 09:50, Hans Verkuil wrote:
>>> On 12/12/2013 12:54 AM, Antti Palosaari wrote:
> 
>>>> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c
>>>> b/drivers/media/v4l2-core/v4l2-ioctl.c
>>>> index bc10684..ee91a9f 100644
>>>> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
>>>> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
>>>> @@ -1288,8 +1288,13 @@ static int v4l_g_frequency(const struct
>>>> v4l2_ioctl_ops *ops,
>>>>       struct video_device *vfd = video_devdata(file);
>>>>       struct v4l2_frequency *p = arg;
>>>>
>>>> -    p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
>>>> -            V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
>>>> +    if (vfd->vfl_type == VFL_TYPE_SDR) {
>>>> +        if (p->type != V4L2_TUNER_ADC && p->type != V4L2_TUNER_SDR)
>>>> +            return -EINVAL;
>>>
>>> This isn't right. p->type is returned by the driver, not set by the user.
>>> In the case of TYPE_SDR I would just set it to TUNER_SDR and let the
>>> driver
>>> update it for ADC tuners. You can also just leave it alone. This does
>>> make
>>> the assumption that SDR and ADC tuners are always separate tuners.
>>> I.e., not
>>> like radio and TV tuners that can be one physical tuner with two mutually
>>> exclusive modes. It's my understanding that that is by definition true
>>> for
>>> SDR.
>>
>> Aaah, so it is possible to use same tuner and that type is aimed for
>> selecting tuner operation mode. Makes sense.
>>
>> So if I now understand V4L2 driver model correctly, there should be one
>> tuner that implements different functionality by using tuner type field.
>>
>> I could change it easily, no problem.
> 
> http://hverkuil.home.xs4all.nl/spec/media.html#vidioc-g-frequency
> I still don't understand that. Why both index and type should be defined 
> for VIDIOC_S_FREQUENCY, but the opposite command VIDIOC_G_FREQUENCY 
> requires only index and returns type too? It does not sound correct 
> behavior.
> If S_FREQUENCY/G_FREQUENCY should be able to handle multiple tuner types 
> for same tuner index, then type must be also given that driver could 
> detect required mode.
> 
> http://hverkuil.home.xs4all.nl/spec/media.html#vidioc-g-tuner
> How I can enumerate tuners. There is G_TUNER/S_TUNER for enumerating, 
> but documentation of these IOCTLs looks like only one tuner type per 
> tuner index is supported. That offers enumeration per tuner index.

I can imagine it is confusing. According to the spec the ENUM_FREQ_BANDS,
S_HW_FREQ_SEEK and S_FREQUENCY ioctls all require the type field to be set
by the user before calling, but G_FREQUENCY and G/S_TUNER do not. And the
G/S_MODULATOR ioctls do not use a type field at all.

Frankly, I consider this a bug in the API. All of these ioctls should have
required that userspace sets the type field.

The idea behind the original API design was that a tuner can be in either
radio or TV mode, and that's determined by the type. The only ioctl that
can change the tuner mode is S_FREQUENCY where the type tells the tuner
whether to select radio or TV mode. Note that originally it didn't matter
whether S_FREQ was called on a radio or a video node, it was the type field
that determined the tuner mode, not the node it was called on. At least,
that was the theory.

In practice drivers often didn't check the type field and instead depended
on whether the ioctl came from a radio or a video node. Applications certainly
never mixed radio and video nodes. Also, calling e.g. S_STD would also switch
the tuner mode back to the TV mode, requiring drivers to keep track of the
last used radio and TV frequencies, to be restored when switching back and
forth between radio and TV mode. Frankly, the tuner type handling was a
major nightmare and few drivers handled it correctly.

The practical result of all this was that, even though an internal tuner
could operate in either TV or radio mode, from the outside world it would
look as two separate tuners. So calling G_FREQ from a radio node gives
back the last set radio frequency and from a video node the last set TV
frequency, regardless of the actual tuner mode. Ditto for G/S_TUNER: if
the tuner is in the wrong mode, the tuner data is just faked.

So the tuner type now depends on the device node that is used: it does
not have to be set by userspace (except for those ioctls where the spec
explicitly requires it) but it is filled in by the core based on the
device node used.

This scheme works fine as long as each tuner has either only one mode
or the mode can be deduced from the device node used to access it.

If we ever get tuners with multiple modes that can all be used from the
same device node, then we have a problem.

My understanding from your SDR proposal is that this doesn't happen:
you have only one or two tuners, and each tuner has only one mode.

I hope this helps instead of confusing you even more :-)

Regards,

	Hans

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

* Re: [PATCH RFC 4/4] v4l: 1 Hz resolution flag for tuners
  2013-12-13 14:05       ` Hans Verkuil
@ 2013-12-13 15:42         ` Antti Palosaari
  2013-12-13 16:08           ` Hans Verkuil
  0 siblings, 1 reply; 16+ messages in thread
From: Antti Palosaari @ 2013-12-13 15:42 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, Mauro Carvalho Chehab

On 13.12.2013 16:05, Hans Verkuil wrote:
> On 12/12/2013 06:22 PM, Antti Palosaari wrote:
>> Hi Hans!
>>
>> On 12.12.2013 09:55, Hans Verkuil wrote:
>>> On 12/12/2013 12:54 AM, Antti Palosaari wrote:
>>>> Add V4L2_TUNER_CAP_1HZ for 1 Hz resolution.
>>>>
>>>> Signed-off-by: Antti Palosaari <crope@iki.fi>
>>>> ---
>>>>    include/uapi/linux/videodev2.h | 1 +
>>>>    1 file changed, 1 insertion(+)
>>>>
>>>> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
>>>> index 6c6a601..1bac6c4 100644
>>>> --- a/include/uapi/linux/videodev2.h
>>>> +++ b/include/uapi/linux/videodev2.h
>>>> @@ -1349,6 +1349,7 @@ struct v4l2_modulator {
>>>>    #define V4L2_TUNER_CAP_RDS_CONTROLS	0x0200
>>>>    #define V4L2_TUNER_CAP_FREQ_BANDS	0x0400
>>>>    #define V4L2_TUNER_CAP_HWSEEK_PROG_LIM	0x0800
>>>> +#define V4L2_TUNER_CAP_1HZ		0x1000
>>>>
>>>>    /*  Flags for the 'rxsubchans' field */
>>>>    #define V4L2_TUNER_SUB_MONO		0x0001
>>>>
>>>
>>> I was wondering, do the band modulation systems (V4L2_BAND_MODULATION_VSB etc.) cover SDR?
>>
>> There is no such modulations defined for SDR hardware level. SDR
>> demodulation is done by software called DSP (digital signal processing)
>> in host computer.
>>
>> In ideal case, SDR receiver has only 1 property: ADC (analog to digital
>> converter) sampling rate.
>
> So in that case the band modulation would be 0, right?

Yes. If you split that radio receiver to some logic blocs, from antenna 
to host computer:
1. Antenna is here
2. RF tuner (RF frontend): tuner "band" belongs here
3. ADC: sampling rate
4. demodulator (modulation lives here)

In a case of traditional hw based demodulator PC/host computer is 
located as a number 5. In a case of a software defined radio receiver 
host computer is next to ADC, between 3-4. Demodulator itself is DSP 
software running on host computer.


>> But as digital signal processing is very CPU intensive when sampling
>> rates are increased, there is very often RF tuner used to down-convert
>> actual radio frequency to low-IF / BB. Then ADC is used to sample that
>> baseband / low-IF signal and only small sampling rate is needed =>
>> stream is smaller => DSP does not need so much CPU.
>
> How does the application know that there is an RF tuner? I assume that
> the app needs to know this?

Yes, that indeed needs to be know. It is one key issue to resolve. 
Something like a capability flag works or application could test it 
when. Like if tuner type is "ADC" then enumerate if there is tuner type 
"SDR" also. Or expect there is always RF tuner and frequency is 
programmed as a 0 Hz when it is not really there. Enumeration of RF 
tuner returns only supported frequency as a 0Hz to tell there is only ADC.


> As you can probably tell, I basically know nothing about SDR, so forgive
> me if I am asking stupid questions. I just want to make sure all bases
> are covered when it comes to the V4L2 API.

I really appreciate that as simply has no enough knowledge from V4L2 API 
and API changes are needed. I will try to list here shortly some SDR 
devices in general level enough.

ant = antenna
host = host computer, PC (SW modulator/demodulator)
ADC = analog to digital converter
DAC = digital to analog converter
amp = amplifier
mixer = "TX tuner"

receiver:
ant <> RF tuner <> ADC <> bridge <> host
ant <>ADC <> bridge <> host
ant <> up-converter <> RF tuner <> ADC <> bridge <> host

transmitter:
ant <> amp <> mixer <> DAC <> bridge <> host
ant <> mixer <> DAC <> bridge <> host
ant <> DAC <> bridge <> host

Those are the used building blocks in some general view. ADC (DAC) is 
most important hardware block, but RF tuner is also critical in practice.

So what I understood, V4L2 API "tuner" is kinda logical entity that 
represent single radio device, containing RF tuner, demodulator and so. 
That same logical entity in DVB API side is frontend, which is mostly 
implemented by demodulator with a help of RF tuner.

So what is needed is to make V4L2 API entity (tuner I guess) that could 
represent both ADC and RF tuner.

regards
Antti

-- 
http://palosaari.fi/

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

* Re: [PATCH RFC 4/4] v4l: 1 Hz resolution flag for tuners
  2013-12-13 15:42         ` Antti Palosaari
@ 2013-12-13 16:08           ` Hans Verkuil
  2013-12-13 19:27             ` Antti Palosaari
  0 siblings, 1 reply; 16+ messages in thread
From: Hans Verkuil @ 2013-12-13 16:08 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media, Mauro Carvalho Chehab

On 12/13/2013 04:42 PM, Antti Palosaari wrote:
> On 13.12.2013 16:05, Hans Verkuil wrote:
>> On 12/12/2013 06:22 PM, Antti Palosaari wrote:
>>> Hi Hans!
>>>
>>> On 12.12.2013 09:55, Hans Verkuil wrote:
>>>> On 12/12/2013 12:54 AM, Antti Palosaari wrote:
>>>>> Add V4L2_TUNER_CAP_1HZ for 1 Hz resolution.
>>>>>
>>>>> Signed-off-by: Antti Palosaari <crope@iki.fi>
>>>>> ---
>>>>>    include/uapi/linux/videodev2.h | 1 +
>>>>>    1 file changed, 1 insertion(+)
>>>>>
>>>>> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
>>>>> index 6c6a601..1bac6c4 100644
>>>>> --- a/include/uapi/linux/videodev2.h
>>>>> +++ b/include/uapi/linux/videodev2.h
>>>>> @@ -1349,6 +1349,7 @@ struct v4l2_modulator {
>>>>>    #define V4L2_TUNER_CAP_RDS_CONTROLS	0x0200
>>>>>    #define V4L2_TUNER_CAP_FREQ_BANDS	0x0400
>>>>>    #define V4L2_TUNER_CAP_HWSEEK_PROG_LIM	0x0800
>>>>> +#define V4L2_TUNER_CAP_1HZ		0x1000
>>>>>
>>>>>    /*  Flags for the 'rxsubchans' field */
>>>>>    #define V4L2_TUNER_SUB_MONO		0x0001
>>>>>
>>>>
>>>> I was wondering, do the band modulation systems (V4L2_BAND_MODULATION_VSB etc.) cover SDR?
>>>
>>> There is no such modulations defined for SDR hardware level. SDR
>>> demodulation is done by software called DSP (digital signal processing)
>>> in host computer.
>>>
>>> In ideal case, SDR receiver has only 1 property: ADC (analog to digital
>>> converter) sampling rate.
>>
>> So in that case the band modulation would be 0, right?
> 
> Yes. If you split that radio receiver to some logic blocs, from antenna 
> to host computer:
> 1. Antenna is here
> 2. RF tuner (RF frontend): tuner "band" belongs here
> 3. ADC: sampling rate
> 4. demodulator (modulation lives here)
> 
> In a case of traditional hw based demodulator PC/host computer is 
> located as a number 5. In a case of a software defined radio receiver 
> host computer is next to ADC, between 3-4. Demodulator itself is DSP 
> software running on host computer.
> 
> 
>>> But as digital signal processing is very CPU intensive when sampling
>>> rates are increased, there is very often RF tuner used to down-convert
>>> actual radio frequency to low-IF / BB. Then ADC is used to sample that
>>> baseband / low-IF signal and only small sampling rate is needed =>
>>> stream is smaller => DSP does not need so much CPU.
>>
>> How does the application know that there is an RF tuner? I assume that
>> the app needs to know this?
> 
> Yes, that indeed needs to be know. It is one key issue to resolve. 
> Something like a capability flag works or application could test it 
> when. Like if tuner type is "ADC" then enumerate if there is tuner type 
> "SDR" also.

Instead of calling it TUNER_TYPE_SDR, shouldn't it be called TUNER_TYPE_RF?
Or perhaps _SDR_RF?

> Or expect there is always RF tuner and frequency is 
> programmed as a 0 Hz when it is not really there. Enumeration of RF 
> tuner returns only supported frequency as a 0Hz to tell there is only ADC.

I think just enumerating tuners to see if there is a RF tuner would be
sufficient.

> 
> 
>> As you can probably tell, I basically know nothing about SDR, so forgive
>> me if I am asking stupid questions. I just want to make sure all bases
>> are covered when it comes to the V4L2 API.
> 
> I really appreciate that as simply has no enough knowledge from V4L2 API 
> and API changes are needed. I will try to list here shortly some SDR 
> devices in general level enough.
> 
> ant = antenna
> host = host computer, PC (SW modulator/demodulator)
> ADC = analog to digital converter
> DAC = digital to analog converter
> amp = amplifier
> mixer = "TX tuner"
> 
> receiver:
> ant <> RF tuner <> ADC <> bridge <> host
> ant <>ADC <> bridge <> host
> ant <> up-converter <> RF tuner <> ADC <> bridge <> host
> 
> transmitter:
> ant <> amp <> mixer <> DAC <> bridge <> host
> ant <> mixer <> DAC <> bridge <> host
> ant <> DAC <> bridge <> host
> 
> Those are the used building blocks in some general view. ADC (DAC) is 
> most important hardware block, but RF tuner is also critical in practice.
> 
> So what I understood, V4L2 API "tuner" is kinda logical entity that 
> represent single radio device, containing RF tuner, demodulator and so. 
> That same logical entity in DVB API side is frontend, which is mostly 
> implemented by demodulator with a help of RF tuner.
> 
> So what is needed is to make V4L2 API entity (tuner I guess) that could 
> represent both ADC and RF tuner.

Well, a V4L2 tuner represents the hardware that requires a frequency.
Which for typical radio and TV devices means the RF tuner + demodulator
combo. So externally you see only one tuner, but internally there are
often two devices (tuner and modulator) that have to be controlled.

For SDR you have an RF Tuner with a frequency and an ADC with a frequency,
and the two frequencies can be set independently. So representing that
as two tuners seems like a sensible mapping to me.

Regards,

	Hans

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

* Re: [PATCH RFC 4/4] v4l: 1 Hz resolution flag for tuners
  2013-12-13 16:08           ` Hans Verkuil
@ 2013-12-13 19:27             ` Antti Palosaari
  0 siblings, 0 replies; 16+ messages in thread
From: Antti Palosaari @ 2013-12-13 19:27 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, Mauro Carvalho Chehab

On 13.12.2013 18:08, Hans Verkuil wrote:
> On 12/13/2013 04:42 PM, Antti Palosaari wrote:
>> On 13.12.2013 16:05, Hans Verkuil wrote:
>>> On 12/12/2013 06:22 PM, Antti Palosaari wrote:

>> I really appreciate that as simply has no enough knowledge from V4L2 API
>> and API changes are needed. I will try to list here shortly some SDR
>> devices in general level enough.
>>
>> ant = antenna
>> host = host computer, PC (SW modulator/demodulator)
>> ADC = analog to digital converter
>> DAC = digital to analog converter
>> amp = amplifier
>> mixer = "TX tuner"
>>
>> receiver:
>> ant <> RF tuner <> ADC <> bridge <> host
>> ant <>ADC <> bridge <> host
>> ant <> up-converter <> RF tuner <> ADC <> bridge <> host
>>
>> transmitter:
>> ant <> amp <> mixer <> DAC <> bridge <> host
>> ant <> mixer <> DAC <> bridge <> host
>> ant <> DAC <> bridge <> host
>>
>> Those are the used building blocks in some general view. ADC (DAC) is
>> most important hardware block, but RF tuner is also critical in practice.
>>
>> So what I understood, V4L2 API "tuner" is kinda logical entity that
>> represent single radio device, containing RF tuner, demodulator and so.
>> That same logical entity in DVB API side is frontend, which is mostly
>> implemented by demodulator with a help of RF tuner.
>>
>> So what is needed is to make V4L2 API entity (tuner I guess) that could
>> represent both ADC and RF tuner.
>
> Well, a V4L2 tuner represents the hardware that requires a frequency.
> Which for typical radio and TV devices means the RF tuner + demodulator
> combo. So externally you see only one tuner, but internally there are
> often two devices (tuner and modulator) that have to be controlled.
>
> For SDR you have an RF Tuner with a frequency and an ADC with a frequency,
> and the two frequencies can be set independently. So representing that
> as two tuners seems like a sensible mapping to me.

Correct. Both RF tuner and ADC are independent each others and both must 
be possible to adjust runtime.

Shortly, all-in-all, I will implement those as a tuner#0 is ADC and 
tuner#1 is RF tuner. Patches with corrections follow soon.

regards
Antti

-- 
http://palosaari.fi/

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

end of thread, other threads:[~2013-12-13 19:27 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-11 23:53 [PATCH RFC 0/4] SDR API set ADC and RF frequency Antti Palosaari
2013-12-11 23:54 ` [PATCH RFC 1/4] v4l2-core: don't clear VIDIOC_G_FREQUENCY tuner type Antti Palosaari
2013-12-11 23:54 ` [PATCH RFC 2/4] v4l2: add new device type for Software Defined Radio Antti Palosaari
2013-12-11 23:54 ` [PATCH RFC 3/4] v4l: add new tuner types for SDR Antti Palosaari
2013-12-12  7:50   ` Hans Verkuil
2013-12-12 17:12     ` Antti Palosaari
2013-12-12 19:14       ` Antti Palosaari
2013-12-13 14:31         ` Hans Verkuil
2013-12-13 13:58       ` Hans Verkuil
2013-12-11 23:54 ` [PATCH RFC 4/4] v4l: 1 Hz resolution flag for tuners Antti Palosaari
2013-12-12  7:55   ` Hans Verkuil
2013-12-12 17:22     ` Antti Palosaari
2013-12-13 14:05       ` Hans Verkuil
2013-12-13 15:42         ` Antti Palosaari
2013-12-13 16:08           ` Hans Verkuil
2013-12-13 19:27             ` 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.