V4L/DVB (5035): Pvrusb2: Enable radio mode round #2
authorPantelis Koukousoulas <pakt223@freemail.gr>
Thu, 28 Dec 2006 02:06:04 +0000 (23:06 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Wed, 21 Feb 2007 15:34:22 +0000 (13:34 -0200)
This is the logic that:
  a) Ensures /sys/class/pvrusb2/sn-*/ctl_frequency/{max,min}_val are
     "automagically" reset to sane values on each mode change.

  b) Allows tuning to a radio frequency by something like:
     echo `perl -e "print int(94.9*16000 + 0.5)"` \
       > /sys/class/pvrusb2/sn-*/ctl_input/cur_val

The trick was to take advantage of the already existing .get_{min,max}_value
function pointers in pvr2_ctrl, to "dynamically override" the hardcoded values
for min/max frequency at runtime.

For a moment I thought to dispose of the hardcoded MIN/MAX_FREQ and use the
hirange/lowrange fields of the v4l2_tuner struct instead, but then I see that
tuner-core.c kinda hardcodes these as well, so I decided to not bother.

Signed-off-by: Pantelis Koukousoulas <pakt223@freemail.gr>
Signed-off-by: Mike Isely <isely@pobox.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
drivers/media/video/pvrusb2/pvrusb2-hdw.c
drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c

index 5f6ab998bbe76ed5c0f9b1a590f978fe085bbb3f..ca4ef95996bec513812a32c84b6184464233626f 100644 (file)
 #include "pvrusb2-encoder.h"
 #include "pvrusb2-debug.h"
 
+#define TV_MIN_FREQ 55250000L
+#define TV_MAX_FREQ 850000000L
+
+#define RADIO_MIN_FREQ 1392000L //87MHz
+#define RADIO_MAX_FREQ 1728000L //108MHz
+
 struct usb_device_id pvr2_device_table[] = {
        [PVR2_HDW_TYPE_29XXX] = { USB_DEVICE(0x2040, 0x2900) },
        [PVR2_HDW_TYPE_24XXX] = { USB_DEVICE(0x2040, 0x2400) },
@@ -375,6 +381,28 @@ static int ctrl_vres_min_get(struct pvr2_ctrl *cptr,int *vp)
        return 0;
 }
 
+static int ctrl_freq_max_get(struct pvr2_ctrl *cptr, int *vp)
+{
+       /* Actual maximum depends on radio/tv mode */
+       if (cptr->hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
+               *vp = RADIO_MAX_FREQ;
+       } else {
+               *vp = TV_MAX_FREQ;
+       }
+       return 0;
+}
+
+static int ctrl_freq_min_get(struct pvr2_ctrl *cptr, int *vp)
+{
+       /* Actual minimum depends on radio/tv mode */
+       if (cptr->hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
+               *vp = RADIO_MIN_FREQ;
+       } else {
+               *vp = TV_MIN_FREQ;
+       }
+       return 0;
+}
+
 static int ctrl_cx2341x_is_dirty(struct pvr2_ctrl *cptr)
 {
        return cptr->hdw->enc_stale != 0;
@@ -644,9 +672,6 @@ VCREATE_FUNCS(res_hor)
 VCREATE_FUNCS(res_ver)
 VCREATE_FUNCS(srate)
 
-#define MIN_FREQ 55250000L
-#define MAX_FREQ 850000000L
-
 /* Table definition of all controls which can be manipulated */
 static const struct pvr2_ctl_info control_defs[] = {
        {
@@ -760,7 +785,11 @@ static const struct pvr2_ctl_info control_defs[] = {
                .get_value = ctrl_freq_get,
                .is_dirty = ctrl_freq_is_dirty,
                .clear_dirty = ctrl_freq_clear_dirty,
-               DEFINT(MIN_FREQ,MAX_FREQ),
+               DEFINT(TV_MIN_FREQ,TV_MAX_FREQ),
+               /* Hook in check for input value (tv/radio) and adjust
+                  max/min values accordingly */
+               .get_max_value = ctrl_freq_max_get,
+               .get_min_value = ctrl_freq_min_get,
        },{
                .desc = "Channel",
                .name = "channel",
@@ -772,7 +801,7 @@ static const struct pvr2_ctl_info control_defs[] = {
                .name = "freq_table_value",
                .set_value = ctrl_channelfreq_set,
                .get_value = ctrl_channelfreq_get,
-               DEFINT(MIN_FREQ,MAX_FREQ),
+               DEFINT(TV_MIN_FREQ,TV_MAX_FREQ),
        },{
                .desc = "Channel Program ID",
                .name = "freq_table_channel",
index 50fcceb15d512220b89d964572fcd3a730119178..ed4eed4d55c4a4b65d5839fefc4a343df174eb2f 100644 (file)
@@ -169,7 +169,9 @@ static void set_frequency(struct pvr2_hdw *hdw)
        fv = hdw->freqVal;
        pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
        memset(&freq,0,sizeof(freq));
-       freq.frequency = fv / 62500;
+       if (hdw->input_val == PVR2_CVAL_INPUT_TV)
+               fv /= 62500;
+       freq.frequency = fv;
        freq.tuner = 0;
        freq.type = (hdw->input_val == PVR2_CVAL_INPUT_RADIO) ?
                     V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;