Re: [RFC PATCH 1/3] tea575x-tuner: various improvements

2011-03-29 Thread Ondrej Zary
On Saturday 26 March 2011 11:19:31 Hans Verkuil wrote:
 On Friday, March 25, 2011 22:40:12 Ondrej Zary wrote:
  On Tuesday 22 March 2011 20:02:30 Hans Verkuil wrote:
   BTW, can you run the v4l2-compliance utility for the two boards that
   use this radio tuner?
  
   This utility is part of the v4l-utils repository
   (http://git.linuxtv.org/v4l-utils.git).
  
   Run as 'v4l2-compliance -r /dev/radioX -v2'.
  
   I'm sure there will be some errors/warnings (warnings regarding
   G/S_PRIORITY are to be expected). But I can use it to make a patch for
   2.6.40 that fixes any issues.
 
  The output is the same for both fm801 and es1968 (see below). Seems that
  there are 4 errors:
   1. multiple-open does not work
   2. something bad with s_frequency
   3. input functions are present
   4. no extended controls

 Thanks for testing! Some comments are below...

  Running on 2.6.38
 
  Driver Info:
  Driver name   : tea575x-tuner
  Card type : TEA5757
  Bus info  : PCI
  Driver version: 0.0.2
  Capabilities  : 0x0005
  Tuner
  Radio
 
  Compliance test for device /dev/radio0 (not using libv4l2):
 
  Required ioctls:
  test VIDIOC_QUERYCAP: OK
 
  Allow for multiple opens:
  test second radio open: FAIL

 I will fix this. Once 2.6.39-rc1 is released I can make a patch fixing
 this.

  Debug ioctls:
  test VIDIOC_DBG_G_CHIP_IDENT: Not Supported
  test VIDIOC_DBG_G/S_REGISTER: Not Supported
  test VIDIOC_LOG_STATUS: Not Supported
 
  Input ioctls:
  test VIDIOC_G/S_TUNER: OK
  fail: set rangehigh+1 frequency did not return EINVAL
  test VIDIOC_G/S_FREQUENCY: FAIL

 Hmm, S_FREQUENCY apparently fails to check for valid frequency values.
 Can you take a quick look at the code?

The driver code is OK. But there is a bug in v4l2-test-input-output.cpp at 
line 214:
if (ret)
return fail(set rangehigh+1 frequency did not return EINVAL\n);

There should be if (ret != EINVAL) instead of if (ret).

-- 
Ondrej Zary
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH 1/3] tea575x-tuner: various improvements

2011-03-29 Thread Hans Verkuil
On Tuesday, March 29, 2011 21:25:55 Ondrej Zary wrote:
 On Saturday 26 March 2011 11:19:31 Hans Verkuil wrote:
  On Friday, March 25, 2011 22:40:12 Ondrej Zary wrote:
   On Tuesday 22 March 2011 20:02:30 Hans Verkuil wrote:
BTW, can you run the v4l2-compliance utility for the two boards that
use this radio tuner?
   
This utility is part of the v4l-utils repository
(http://git.linuxtv.org/v4l-utils.git).
   
Run as 'v4l2-compliance -r /dev/radioX -v2'.
   
I'm sure there will be some errors/warnings (warnings regarding
G/S_PRIORITY are to be expected). But I can use it to make a patch for
2.6.40 that fixes any issues.
  
   The output is the same for both fm801 and es1968 (see below). Seems that
   there are 4 errors:
1. multiple-open does not work
2. something bad with s_frequency
3. input functions are present
4. no extended controls
 
  Thanks for testing! Some comments are below...
 
   Running on 2.6.38
  
   Driver Info:
 Driver name   : tea575x-tuner
 Card type : TEA5757
 Bus info  : PCI
 Driver version: 0.0.2
 Capabilities  : 0x0005
 Tuner
 Radio
  
   Compliance test for device /dev/radio0 (not using libv4l2):
  
   Required ioctls:
 test VIDIOC_QUERYCAP: OK
  
   Allow for multiple opens:
 test second radio open: FAIL
 
  I will fix this. Once 2.6.39-rc1 is released I can make a patch fixing
  this.
 
   Debug ioctls:
 test VIDIOC_DBG_G_CHIP_IDENT: Not Supported
 test VIDIOC_DBG_G/S_REGISTER: Not Supported
 test VIDIOC_LOG_STATUS: Not Supported
  
   Input ioctls:
 test VIDIOC_G/S_TUNER: OK
 fail: set rangehigh+1 frequency did not return EINVAL
 test VIDIOC_G/S_FREQUENCY: FAIL
 
  Hmm, S_FREQUENCY apparently fails to check for valid frequency values.
  Can you take a quick look at the code?
 
 The driver code is OK. But there is a bug in v4l2-test-input-output.cpp at 
 line 214:
 if (ret)
   return fail(set rangehigh+1 frequency did not return EINVAL\n);
 
 There should be if (ret != EINVAL) instead of if (ret).

Grrr. I hate it when test code has bugs :-)

Thanks for finding this. I've fixed it in the code and pushed it to the 
v4l-utils
repository.

Regards,

Hans
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH 1/3] tea575x-tuner: various improvements

2011-03-26 Thread Hans Verkuil
On Friday, March 25, 2011 22:40:12 Ondrej Zary wrote:
 On Tuesday 22 March 2011 20:02:30 Hans Verkuil wrote:
  BTW, can you run the v4l2-compliance utility for the two boards that use
  this radio tuner?
 
  This utility is part of the v4l-utils repository
  (http://git.linuxtv.org/v4l-utils.git).
 
  Run as 'v4l2-compliance -r /dev/radioX -v2'.
 
  I'm sure there will be some errors/warnings (warnings regarding
  G/S_PRIORITY are to be expected). But I can use it to make a patch for
  2.6.40 that fixes any issues.
 
 The output is the same for both fm801 and es1968 (see below). Seems that
 there are 4 errors:
  1. multiple-open does not work
  2. something bad with s_frequency
  3. input functions are present
  4. no extended controls

Thanks for testing! Some comments are below...

 
 
 
 Running on 2.6.38
 
 Driver Info:
   Driver name   : tea575x-tuner
   Card type : TEA5757
   Bus info  : PCI
   Driver version: 0.0.2
   Capabilities  : 0x0005
   Tuner
   Radio
 
 Compliance test for device /dev/radio0 (not using libv4l2):
 
 Required ioctls:
   test VIDIOC_QUERYCAP: OK
 
 Allow for multiple opens:
   test second radio open: FAIL

I will fix this. Once 2.6.39-rc1 is released I can make a patch fixing this.

 
 Debug ioctls:
   test VIDIOC_DBG_G_CHIP_IDENT: Not Supported
   test VIDIOC_DBG_G/S_REGISTER: Not Supported
   test VIDIOC_LOG_STATUS: Not Supported
 
 Input ioctls:
   test VIDIOC_G/S_TUNER: OK
   fail: set rangehigh+1 frequency did not return EINVAL
   test VIDIOC_G/S_FREQUENCY: FAIL

Hmm, S_FREQUENCY apparently fails to check for valid frequency values.
Can you take a quick look at the code?

   test VIDIOC_ENUMAUDIO: Not Supported
   fail: radio can't have input support
   test VIDIOC_G/S/ENUMINPUT: FAIL

ENUMINPUT/G/S_INPUT are not allowed for radio devices. These ioctls are specific
for video. 90% of all radio driver use it, though :-)

I'll fix this when I go through all radio drivers.

   test VIDIOC_G/S_AUDIO: Not Supported
   Inputs: 0 Audio Inputs: 0 Tuners: 1
 
 Output ioctls:
   test VIDIOC_G/S_MODULATOR: Not Supported
   test VIDIOC_G/S_FREQUENCY: OK
   test VIDIOC_ENUMAUDOUT: Not Supported
   test VIDIOC_G/S/ENUMOUTPUT: Not Supported
   test VIDIOC_G/S_AUDOUT: Not Supported
   Outputs: 0 Audio Outputs: 0 Modulators: 0
 
 Control ioctls:
   fail: does not support V4L2_CTRL_FLAG_NEXT_CTRL
   test VIDIOC_QUERYCTRL/MENU: FAIL

I'll fix this as well. The drivers needs to be converted to the control
framework.

Regards,

Hans


   test VIDIOC_G/S_CTRL: OK
   test VIDIOC_G/S/TRY_EXT_CTRLS: Not Supported
   Standard Controls: 0 Private Controls: 0
 
 Input/Output configuration ioctls:
   test VIDIOC_ENUM/G/S/QUERY_STD: Not Supported
   test VIDIOC_ENUM/G/S/QUERY_DV_PRESETS: Not Supported
   test VIDIOC_G/S_DV_TIMINGS: Not Supported
 
 Total: 21 Succeeded: 17 Failed: 4 Warnings: 0
 
 

-- 
Hans Verkuil - video4linux developer - sponsored by Cisco
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH 1/3] tea575x-tuner: various improvements

2011-03-25 Thread Ondrej Zary
On Tuesday 22 March 2011 20:02:30 Hans Verkuil wrote:
 BTW, can you run the v4l2-compliance utility for the two boards that use
 this radio tuner?

 This utility is part of the v4l-utils repository
 (http://git.linuxtv.org/v4l-utils.git).

 Run as 'v4l2-compliance -r /dev/radioX -v2'.

 I'm sure there will be some errors/warnings (warnings regarding
 G/S_PRIORITY are to be expected). But I can use it to make a patch for
 2.6.40 that fixes any issues.

The output is the same for both fm801 and es1968 (see below). Seems that
there are 4 errors:
 1. multiple-open does not work
 2. something bad with s_frequency
 3. input functions are present
 4. no extended controls



Running on 2.6.38

Driver Info:
Driver name   : tea575x-tuner
Card type : TEA5757
Bus info  : PCI
Driver version: 0.0.2
Capabilities  : 0x0005
Tuner
Radio

Compliance test for device /dev/radio0 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second radio open: FAIL

Debug ioctls:
test VIDIOC_DBG_G_CHIP_IDENT: Not Supported
test VIDIOC_DBG_G/S_REGISTER: Not Supported
test VIDIOC_LOG_STATUS: Not Supported

Input ioctls:
test VIDIOC_G/S_TUNER: OK
fail: set rangehigh+1 frequency did not return EINVAL
test VIDIOC_G/S_FREQUENCY: FAIL
test VIDIOC_ENUMAUDIO: Not Supported
fail: radio can't have input support
test VIDIOC_G/S/ENUMINPUT: FAIL
test VIDIOC_G/S_AUDIO: Not Supported
Inputs: 0 Audio Inputs: 0 Tuners: 1

Output ioctls:
test VIDIOC_G/S_MODULATOR: Not Supported
test VIDIOC_G/S_FREQUENCY: OK
test VIDIOC_ENUMAUDOUT: Not Supported
test VIDIOC_G/S/ENUMOUTPUT: Not Supported
test VIDIOC_G/S_AUDOUT: Not Supported
Outputs: 0 Audio Outputs: 0 Modulators: 0

Control ioctls:
fail: does not support V4L2_CTRL_FLAG_NEXT_CTRL
test VIDIOC_QUERYCTRL/MENU: FAIL
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: Not Supported
Standard Controls: 0 Private Controls: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: Not Supported
test VIDIOC_ENUM/G/S/QUERY_DV_PRESETS: Not Supported
test VIDIOC_G/S_DV_TIMINGS: Not Supported

Total: 21 Succeeded: 17 Failed: 4 Warnings: 0

-- 
Ondrej Zary
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH 1/3] tea575x-tuner: various improvements

2011-03-22 Thread Mauro Carvalho Chehab
Em 21-03-2011 08:48, Takashi Iwai escreveu:
 At Sat, 19 Mar 2011 16:32:53 +0100,
 Ondrej Zary wrote:

 Improve tea575x-tuner with various good things from radio-maestro:
 - extend frequency range to 50-150MHz
 - fix querycap(): card name, CAP_RADIO
 - improve g_tuner(): CAP_STEREO, stereo and tuned indication
 - improve g_frequency(): tuner index checking and reading frequency from HW
 - improve s_frequency(): tuner index and type checking

 Signed-off-by: Ondrej Zary li...@rainbow-software.org
 
 Applied these 3 patches now to topic/misc branch of sound git tree
 (i.e. for 2.6.40 kernel).

Patches look sane to me, you may add my ACK if you want.

Acked-by: Mauro Carvalho Chehab mche...@redhat.com

 
 I leave the removal of radio-maestro to v4l guys, as this is fairly
 independent.
 
 
 thanks,
 
 Takashi
 
 
 --- linux-2.6.38-rc4-orig/sound/i2c/other/tea575x-tuner.c2011-02-08 
 01:03:55.0 +0100
 +++ linux-2.6.38-rc4/sound/i2c/other/tea575x-tuner.c 2011-03-19 
 15:40:14.0 +0100
 @@ -37,8 +37,8 @@ static int radio_nr = -1;
  module_param(radio_nr, int, 0);
  
  #define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
 -#define FREQ_LO  (87 * 16000)
 -#define FREQ_HI (108 * 16000)
 +#define FREQ_LO  (50UL * 16000)
 +#define FREQ_HI (150UL * 16000)
  
  /*
   * definitions
 @@ -77,15 +77,29 @@ static struct v4l2_queryctrl radio_qctrl
   * lowlevel part
   */
  
 +static void snd_tea575x_get_freq(struct snd_tea575x *tea)
 +{
 +unsigned long freq;
 +
 +freq = tea-ops-read(tea)  TEA575X_BIT_FREQ_MASK;
 +/* freq *= 12.5 */
 +freq *= 125;
 +freq /= 10;
 +/* crystal fixup */
 +if (tea-tea5759)
 +freq += tea-freq_fixup;
 +else
 +freq -= tea-freq_fixup;
 +
 +tea-freq = freq * 16;  /* from kHz */
 +}
 +
  static void snd_tea575x_set_freq(struct snd_tea575x *tea)
  {
  unsigned long freq;
  
 -freq = tea-freq / 16;  /* to kHz */
 -if (freq  108000)
 -freq = 108000;
 -if (freq  87000)
 -freq = 87000;
 +freq = clamp(tea-freq, FREQ_LO, FREQ_HI);
 +freq /= 16; /* to kHz */
  /* crystal fixup */
  if (tea-tea5759)
  freq -= tea-freq_fixup;
 @@ -109,29 +123,33 @@ static int vidioc_querycap(struct file *
  {
  struct snd_tea575x *tea = video_drvdata(file);
  
 -strcpy(v-card, tea-tea5759 ? TEA5759 : TEA5757);
  strlcpy(v-driver, tea575x-tuner, sizeof(v-driver));
 -strlcpy(v-card, Maestro Radio, sizeof(v-card));
 +strlcpy(v-card, tea-tea5759 ? TEA5759 : TEA5757, sizeof(v-card));
  sprintf(v-bus_info, PCI);
  v-version = RADIO_VERSION;
 -v-capabilities = V4L2_CAP_TUNER;
 +v-capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
  return 0;
  }
  
  static int vidioc_g_tuner(struct file *file, void *priv,
  struct v4l2_tuner *v)
  {
 +struct snd_tea575x *tea = video_drvdata(file);
 +
  if (v-index  0)
  return -EINVAL;
  
 +tea-ops-read(tea);
 +
  strcpy(v-name, FM);
  v-type = V4L2_TUNER_RADIO;
 +v-capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
  v-rangelow = FREQ_LO;
  v-rangehigh = FREQ_HI;
 -v-rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
 -v-capability = V4L2_TUNER_CAP_LOW;
 -v-audmode = V4L2_TUNER_MODE_MONO;
 -v-signal = 0x;
 +v-rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
 +v-audmode = tea-stereo ? V4L2_TUNER_MODE_STEREO : 
 V4L2_TUNER_MODE_MONO;
 +v-signal = tea-tuned ? 0x : 0;
 +
  return 0;
  }
  
 @@ -148,7 +166,10 @@ static int vidioc_g_frequency(struct fil
  {
  struct snd_tea575x *tea = video_drvdata(file);
  
 +if (f-tuner != 0)
 +return -EINVAL;
  f-type = V4L2_TUNER_RADIO;
 +snd_tea575x_get_freq(tea);
  f-frequency = tea-freq;
  return 0;
  }
 @@ -158,6 +179,9 @@ static int vidioc_s_frequency(struct fil
  {
  struct snd_tea575x *tea = video_drvdata(file);
  
 +if (f-tuner != 0 || f-type != V4L2_TUNER_RADIO)
 +return -EINVAL;
 +
  if (f-frequency  FREQ_LO || f-frequency  FREQ_HI)
  return -EINVAL;
  
 --- linux-2.6.38-rc4-orig/include/sound/tea575x-tuner.h  2011-02-08 
 01:03:55.0 +0100
 +++ linux-2.6.38-rc4/include/sound/tea575x-tuner.h   2011-03-19 
 14:18:06.0 +0100
 @@ -38,8 +38,10 @@ struct snd_tea575x {
  struct snd_card *card;
  struct video_device *vd;/* video device */
  int dev_nr; /* requested device number + 1 */
 -int tea5759;/* 5759 chip is present */
 -int mute;   /* Device is muted? */
 +bool tea5759;   /* 5759 chip is present */
 +bool mute;  /* Device is muted? */
 +bool stereo;/* receiving stereo */
 +bool tuned; /* tuned to a station 

Re: [RFC PATCH 1/3] tea575x-tuner: various improvements

2011-03-22 Thread Hans Verkuil
On Saturday, March 19, 2011 16:32:53 Ondrej Zary wrote:
 Improve tea575x-tuner with various good things from radio-maestro:
 - extend frequency range to 50-150MHz
 - fix querycap(): card name, CAP_RADIO
 - improve g_tuner(): CAP_STEREO, stereo and tuned indication
 - improve g_frequency(): tuner index checking and reading frequency from HW
 - improve s_frequency(): tuner index and type checking
 
 Signed-off-by: Ondrej Zary li...@rainbow-software.org

Acked-by: Hans Verkuil hverk...@xs4all.nl

BTW, can you run the v4l2-compliance utility for the two boards that use
this radio tuner?

This utility is part of the v4l-utils repository 
(http://git.linuxtv.org/v4l-utils.git).

Run as 'v4l2-compliance -r /dev/radioX -v2'.

I'm sure there will be some errors/warnings (warnings regarding G/S_PRIORITY
are to be expected). But I can use it to make a patch for 2.6.40 that fixes
any issues.

Regards,

Hans

 
 --- linux-2.6.38-rc4-orig/sound/i2c/other/tea575x-tuner.c 2011-02-08 
 01:03:55.0 +0100
 +++ linux-2.6.38-rc4/sound/i2c/other/tea575x-tuner.c  2011-03-19 
 15:40:14.0 +0100
 @@ -37,8 +37,8 @@ static int radio_nr = -1;
  module_param(radio_nr, int, 0);
  
  #define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
 -#define FREQ_LO   (87 * 16000)
 -#define FREQ_HI  (108 * 16000)
 +#define FREQ_LO   (50UL * 16000)
 +#define FREQ_HI  (150UL * 16000)
  
  /*
   * definitions
 @@ -77,15 +77,29 @@ static struct v4l2_queryctrl radio_qctrl
   * lowlevel part
   */
  
 +static void snd_tea575x_get_freq(struct snd_tea575x *tea)
 +{
 + unsigned long freq;
 +
 + freq = tea-ops-read(tea)  TEA575X_BIT_FREQ_MASK;
 + /* freq *= 12.5 */
 + freq *= 125;
 + freq /= 10;
 + /* crystal fixup */
 + if (tea-tea5759)
 + freq += tea-freq_fixup;
 + else
 + freq -= tea-freq_fixup;
 +
 + tea-freq = freq * 16;  /* from kHz */
 +}
 +
  static void snd_tea575x_set_freq(struct snd_tea575x *tea)
  {
   unsigned long freq;
  
 - freq = tea-freq / 16;  /* to kHz */
 - if (freq  108000)
 - freq = 108000;
 - if (freq  87000)
 - freq = 87000;
 + freq = clamp(tea-freq, FREQ_LO, FREQ_HI);
 + freq /= 16; /* to kHz */
   /* crystal fixup */
   if (tea-tea5759)
   freq -= tea-freq_fixup;
 @@ -109,29 +123,33 @@ static int vidioc_querycap(struct file *
  {
   struct snd_tea575x *tea = video_drvdata(file);
  
 - strcpy(v-card, tea-tea5759 ? TEA5759 : TEA5757);
   strlcpy(v-driver, tea575x-tuner, sizeof(v-driver));
 - strlcpy(v-card, Maestro Radio, sizeof(v-card));
 + strlcpy(v-card, tea-tea5759 ? TEA5759 : TEA5757, sizeof(v-card));
   sprintf(v-bus_info, PCI);
   v-version = RADIO_VERSION;
 - v-capabilities = V4L2_CAP_TUNER;
 + v-capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
   return 0;
  }
  
  static int vidioc_g_tuner(struct file *file, void *priv,
   struct v4l2_tuner *v)
  {
 + struct snd_tea575x *tea = video_drvdata(file);
 +
   if (v-index  0)
   return -EINVAL;
  
 + tea-ops-read(tea);
 +
   strcpy(v-name, FM);
   v-type = V4L2_TUNER_RADIO;
 + v-capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
   v-rangelow = FREQ_LO;
   v-rangehigh = FREQ_HI;
 - v-rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
 - v-capability = V4L2_TUNER_CAP_LOW;
 - v-audmode = V4L2_TUNER_MODE_MONO;
 - v-signal = 0x;
 + v-rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
 + v-audmode = tea-stereo ? V4L2_TUNER_MODE_STEREO : 
 V4L2_TUNER_MODE_MONO;
 + v-signal = tea-tuned ? 0x : 0;
 +
   return 0;
  }
  
 @@ -148,7 +166,10 @@ static int vidioc_g_frequency(struct fil
  {
   struct snd_tea575x *tea = video_drvdata(file);
  
 + if (f-tuner != 0)
 + return -EINVAL;
   f-type = V4L2_TUNER_RADIO;
 + snd_tea575x_get_freq(tea);
   f-frequency = tea-freq;
   return 0;
  }
 @@ -158,6 +179,9 @@ static int vidioc_s_frequency(struct fil
  {
   struct snd_tea575x *tea = video_drvdata(file);
  
 + if (f-tuner != 0 || f-type != V4L2_TUNER_RADIO)
 + return -EINVAL;
 +
   if (f-frequency  FREQ_LO || f-frequency  FREQ_HI)
   return -EINVAL;
  
 --- linux-2.6.38-rc4-orig/include/sound/tea575x-tuner.h   2011-02-08 
 01:03:55.0 +0100
 +++ linux-2.6.38-rc4/include/sound/tea575x-tuner.h2011-03-19 
 14:18:06.0 +0100
 @@ -38,8 +38,10 @@ struct snd_tea575x {
   struct snd_card *card;
   struct video_device *vd;/* video device */
   int dev_nr; /* requested device number + 1 */
 - int tea5759;/* 5759 chip is present */
 - int mute;   /* Device is muted? */
 + bool tea5759;   /* 5759 chip is present */
 + 

Re: [RFC PATCH 1/3] tea575x-tuner: various improvements

2011-03-21 Thread Takashi Iwai
At Sat, 19 Mar 2011 16:32:53 +0100,
Ondrej Zary wrote:
 
 Improve tea575x-tuner with various good things from radio-maestro:
 - extend frequency range to 50-150MHz
 - fix querycap(): card name, CAP_RADIO
 - improve g_tuner(): CAP_STEREO, stereo and tuned indication
 - improve g_frequency(): tuner index checking and reading frequency from HW
 - improve s_frequency(): tuner index and type checking
 
 Signed-off-by: Ondrej Zary li...@rainbow-software.org

Applied these 3 patches now to topic/misc branch of sound git tree
(i.e. for 2.6.40 kernel).

I leave the removal of radio-maestro to v4l guys, as this is fairly
independent.


thanks,

Takashi


 --- linux-2.6.38-rc4-orig/sound/i2c/other/tea575x-tuner.c 2011-02-08 
 01:03:55.0 +0100
 +++ linux-2.6.38-rc4/sound/i2c/other/tea575x-tuner.c  2011-03-19 
 15:40:14.0 +0100
 @@ -37,8 +37,8 @@ static int radio_nr = -1;
  module_param(radio_nr, int, 0);
  
  #define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
 -#define FREQ_LO   (87 * 16000)
 -#define FREQ_HI  (108 * 16000)
 +#define FREQ_LO   (50UL * 16000)
 +#define FREQ_HI  (150UL * 16000)
  
  /*
   * definitions
 @@ -77,15 +77,29 @@ static struct v4l2_queryctrl radio_qctrl
   * lowlevel part
   */
  
 +static void snd_tea575x_get_freq(struct snd_tea575x *tea)
 +{
 + unsigned long freq;
 +
 + freq = tea-ops-read(tea)  TEA575X_BIT_FREQ_MASK;
 + /* freq *= 12.5 */
 + freq *= 125;
 + freq /= 10;
 + /* crystal fixup */
 + if (tea-tea5759)
 + freq += tea-freq_fixup;
 + else
 + freq -= tea-freq_fixup;
 +
 + tea-freq = freq * 16;  /* from kHz */
 +}
 +
  static void snd_tea575x_set_freq(struct snd_tea575x *tea)
  {
   unsigned long freq;
  
 - freq = tea-freq / 16;  /* to kHz */
 - if (freq  108000)
 - freq = 108000;
 - if (freq  87000)
 - freq = 87000;
 + freq = clamp(tea-freq, FREQ_LO, FREQ_HI);
 + freq /= 16; /* to kHz */
   /* crystal fixup */
   if (tea-tea5759)
   freq -= tea-freq_fixup;
 @@ -109,29 +123,33 @@ static int vidioc_querycap(struct file *
  {
   struct snd_tea575x *tea = video_drvdata(file);
  
 - strcpy(v-card, tea-tea5759 ? TEA5759 : TEA5757);
   strlcpy(v-driver, tea575x-tuner, sizeof(v-driver));
 - strlcpy(v-card, Maestro Radio, sizeof(v-card));
 + strlcpy(v-card, tea-tea5759 ? TEA5759 : TEA5757, sizeof(v-card));
   sprintf(v-bus_info, PCI);
   v-version = RADIO_VERSION;
 - v-capabilities = V4L2_CAP_TUNER;
 + v-capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
   return 0;
  }
  
  static int vidioc_g_tuner(struct file *file, void *priv,
   struct v4l2_tuner *v)
  {
 + struct snd_tea575x *tea = video_drvdata(file);
 +
   if (v-index  0)
   return -EINVAL;
  
 + tea-ops-read(tea);
 +
   strcpy(v-name, FM);
   v-type = V4L2_TUNER_RADIO;
 + v-capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
   v-rangelow = FREQ_LO;
   v-rangehigh = FREQ_HI;
 - v-rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
 - v-capability = V4L2_TUNER_CAP_LOW;
 - v-audmode = V4L2_TUNER_MODE_MONO;
 - v-signal = 0x;
 + v-rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
 + v-audmode = tea-stereo ? V4L2_TUNER_MODE_STEREO : 
 V4L2_TUNER_MODE_MONO;
 + v-signal = tea-tuned ? 0x : 0;
 +
   return 0;
  }
  
 @@ -148,7 +166,10 @@ static int vidioc_g_frequency(struct fil
  {
   struct snd_tea575x *tea = video_drvdata(file);
  
 + if (f-tuner != 0)
 + return -EINVAL;
   f-type = V4L2_TUNER_RADIO;
 + snd_tea575x_get_freq(tea);
   f-frequency = tea-freq;
   return 0;
  }
 @@ -158,6 +179,9 @@ static int vidioc_s_frequency(struct fil
  {
   struct snd_tea575x *tea = video_drvdata(file);
  
 + if (f-tuner != 0 || f-type != V4L2_TUNER_RADIO)
 + return -EINVAL;
 +
   if (f-frequency  FREQ_LO || f-frequency  FREQ_HI)
   return -EINVAL;
  
 --- linux-2.6.38-rc4-orig/include/sound/tea575x-tuner.h   2011-02-08 
 01:03:55.0 +0100
 +++ linux-2.6.38-rc4/include/sound/tea575x-tuner.h2011-03-19 
 14:18:06.0 +0100
 @@ -38,8 +38,10 @@ struct snd_tea575x {
   struct snd_card *card;
   struct video_device *vd;/* video device */
   int dev_nr; /* requested device number + 1 */
 - int tea5759;/* 5759 chip is present */
 - int mute;   /* Device is muted? */
 + bool tea5759;   /* 5759 chip is present */
 + bool mute;  /* Device is muted? */
 + bool stereo;/* receiving stereo */
 + bool tuned; /* tuned to a station */
   unsigned int freq_fixup;/* crystal onboard */
   unsigned int val;  

[RFC PATCH 1/3] tea575x-tuner: various improvements

2011-03-19 Thread Ondrej Zary
Improve tea575x-tuner with various good things from radio-maestro:
- extend frequency range to 50-150MHz
- fix querycap(): card name, CAP_RADIO
- improve g_tuner(): CAP_STEREO, stereo and tuned indication
- improve g_frequency(): tuner index checking and reading frequency from HW
- improve s_frequency(): tuner index and type checking

Signed-off-by: Ondrej Zary li...@rainbow-software.org

--- linux-2.6.38-rc4-orig/sound/i2c/other/tea575x-tuner.c   2011-02-08 
01:03:55.0 +0100
+++ linux-2.6.38-rc4/sound/i2c/other/tea575x-tuner.c2011-03-19 
15:40:14.0 +0100
@@ -37,8 +37,8 @@ static int radio_nr = -1;
 module_param(radio_nr, int, 0);
 
 #define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
-#define FREQ_LO (87 * 16000)
-#define FREQ_HI(108 * 16000)
+#define FREQ_LO (50UL * 16000)
+#define FREQ_HI(150UL * 16000)
 
 /*
  * definitions
@@ -77,15 +77,29 @@ static struct v4l2_queryctrl radio_qctrl
  * lowlevel part
  */
 
+static void snd_tea575x_get_freq(struct snd_tea575x *tea)
+{
+   unsigned long freq;
+
+   freq = tea-ops-read(tea)  TEA575X_BIT_FREQ_MASK;
+   /* freq *= 12.5 */
+   freq *= 125;
+   freq /= 10;
+   /* crystal fixup */
+   if (tea-tea5759)
+   freq += tea-freq_fixup;
+   else
+   freq -= tea-freq_fixup;
+
+   tea-freq = freq * 16;  /* from kHz */
+}
+
 static void snd_tea575x_set_freq(struct snd_tea575x *tea)
 {
unsigned long freq;
 
-   freq = tea-freq / 16;  /* to kHz */
-   if (freq  108000)
-   freq = 108000;
-   if (freq  87000)
-   freq = 87000;
+   freq = clamp(tea-freq, FREQ_LO, FREQ_HI);
+   freq /= 16; /* to kHz */
/* crystal fixup */
if (tea-tea5759)
freq -= tea-freq_fixup;
@@ -109,29 +123,33 @@ static int vidioc_querycap(struct file *
 {
struct snd_tea575x *tea = video_drvdata(file);
 
-   strcpy(v-card, tea-tea5759 ? TEA5759 : TEA5757);
strlcpy(v-driver, tea575x-tuner, sizeof(v-driver));
-   strlcpy(v-card, Maestro Radio, sizeof(v-card));
+   strlcpy(v-card, tea-tea5759 ? TEA5759 : TEA5757, sizeof(v-card));
sprintf(v-bus_info, PCI);
v-version = RADIO_VERSION;
-   v-capabilities = V4L2_CAP_TUNER;
+   v-capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
return 0;
 }
 
 static int vidioc_g_tuner(struct file *file, void *priv,
struct v4l2_tuner *v)
 {
+   struct snd_tea575x *tea = video_drvdata(file);
+
if (v-index  0)
return -EINVAL;
 
+   tea-ops-read(tea);
+
strcpy(v-name, FM);
v-type = V4L2_TUNER_RADIO;
+   v-capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
v-rangelow = FREQ_LO;
v-rangehigh = FREQ_HI;
-   v-rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
-   v-capability = V4L2_TUNER_CAP_LOW;
-   v-audmode = V4L2_TUNER_MODE_MONO;
-   v-signal = 0x;
+   v-rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
+   v-audmode = tea-stereo ? V4L2_TUNER_MODE_STEREO : 
V4L2_TUNER_MODE_MONO;
+   v-signal = tea-tuned ? 0x : 0;
+
return 0;
 }
 
@@ -148,7 +166,10 @@ static int vidioc_g_frequency(struct fil
 {
struct snd_tea575x *tea = video_drvdata(file);
 
+   if (f-tuner != 0)
+   return -EINVAL;
f-type = V4L2_TUNER_RADIO;
+   snd_tea575x_get_freq(tea);
f-frequency = tea-freq;
return 0;
 }
@@ -158,6 +179,9 @@ static int vidioc_s_frequency(struct fil
 {
struct snd_tea575x *tea = video_drvdata(file);
 
+   if (f-tuner != 0 || f-type != V4L2_TUNER_RADIO)
+   return -EINVAL;
+
if (f-frequency  FREQ_LO || f-frequency  FREQ_HI)
return -EINVAL;
 
--- linux-2.6.38-rc4-orig/include/sound/tea575x-tuner.h 2011-02-08 
01:03:55.0 +0100
+++ linux-2.6.38-rc4/include/sound/tea575x-tuner.h  2011-03-19 
14:18:06.0 +0100
@@ -38,8 +38,10 @@ struct snd_tea575x {
struct snd_card *card;
struct video_device *vd;/* video device */
int dev_nr; /* requested device number + 1 */
-   int tea5759;/* 5759 chip is present */
-   int mute;   /* Device is muted? */
+   bool tea5759;   /* 5759 chip is present */
+   bool mute;  /* Device is muted? */
+   bool stereo;/* receiving stereo */
+   bool tuned; /* tuned to a station */
unsigned int freq_fixup;/* crystal onboard */
unsigned int val;   /* hw value */
unsigned long freq; /* frequency */


-- 
Ondrej Zary
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More