[PATCH 4/6] radio-cadet: upgrade to latest frameworks.

2012-07-05 Thread Hans Verkuil
From: Hans Verkuil 

- add control framework
- use core locking
- use V4L2_TUNER_CAP_LOW
- remove volume support: there is no hardware volume control

Signed-off-by: Hans Verkuil 
---
 drivers/media/radio/radio-cadet.c |  243 +
 1 file changed, 83 insertions(+), 160 deletions(-)

diff --git a/drivers/media/radio/radio-cadet.c 
b/drivers/media/radio/radio-cadet.c
index 16a089f..93536b7 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -41,6 +41,9 @@
 #include   /* outb, outb_p */
 #include 
 #include 
+#include 
+#include 
+#include 
 
 MODULE_AUTHOR("Fred Gleason, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, 
Scott McGrath, William McGrath");
 MODULE_DESCRIPTION("A driver for the ADS Cadet AM/FM/RDS radio card.");
@@ -61,8 +64,8 @@ module_param(radio_nr, int, 0);
 struct cadet {
struct v4l2_device v4l2_dev;
struct video_device vdev;
+   struct v4l2_ctrl_handler ctrl_handler;
int io;
-   int users;
int curtuner;
int tunestat;
int sigstrength;
@@ -94,11 +97,9 @@ static int cadet_getstereo(struct cadet *dev)
if (dev->curtuner != 0) /* Only FM has stereo capability! */
return V4L2_TUNER_SUB_MONO;
 
-   mutex_lock(&dev->lock);
outb(7, dev->io);  /* Select tuner control */
if ((inb(dev->io + 1) & 0x40) == 0)
ret = V4L2_TUNER_SUB_STEREO;
-   mutex_unlock(&dev->lock);
return ret;
 }
 
@@ -111,8 +112,6 @@ static unsigned cadet_gettune(struct cadet *dev)
 * Prepare for read
 */
 
-   mutex_lock(&dev->lock);
-
outb(7, dev->io);   /* Select tuner control */
curvol = inb(dev->io + 1); /* Save current volume/mute setting */
outb(0x00, dev->io + 1);  /* Ensure WRITE-ENABLE is LOW */
@@ -134,8 +133,6 @@ static unsigned cadet_gettune(struct cadet *dev)
 * Restore volume/mute setting
 */
outb(curvol, dev->io + 1);
-   mutex_unlock(&dev->lock);
-
return fifo;
 }
 
@@ -161,7 +158,7 @@ static unsigned cadet_getfreq(struct cadet *dev)
fifo = fifo >> 1;
}
freq -= 1070;   /* IF frequency is 10.7 MHz */
-   freq = (freq * 16) / 100;   /* Make it 1/16 MHz */
+   freq = (freq * 16) / 1000;   /* Make it 1/16 kHz */
}
if (dev->curtuner == 1)/* AM */
freq = ((fifo & 0x7fff) - 2010) * 16;
@@ -174,8 +171,6 @@ static void cadet_settune(struct cadet *dev, unsigned fifo)
int i;
unsigned test;
 
-   mutex_lock(&dev->lock);
-
outb(7, dev->io);/* Select tuner control */
/*
 * Write the shift register
@@ -194,7 +189,6 @@ static void cadet_settune(struct cadet *dev, unsigned fifo)
test = 0x1c | ((fifo >> 23) & 0x02);
outb(test, dev->io + 1);
}
-   mutex_unlock(&dev->lock);
 }
 
 static void cadet_setfreq(struct cadet *dev, unsigned freq)
@@ -209,7 +203,7 @@ static void cadet_setfreq(struct cadet *dev, unsigned freq)
fifo = 0;
if (dev->curtuner == 0) {/* FM */
test = 102400;
-   freq = (freq * 1000) / 16;   /* Make it kHz */
+   freq = freq / 16;   /* Make it kHz */
freq += 10700;   /* IF is 10700 kHz */
for (i = 0; i < 14; i++) {
fifo = fifo << 1;
@@ -229,10 +223,8 @@ static void cadet_setfreq(struct cadet *dev, unsigned freq)
 * Save current volume/mute setting
 */
 
-   mutex_lock(&dev->lock);
outb(7, dev->io);/* Select tuner control */
curvol = inb(dev->io + 1);
-   mutex_unlock(&dev->lock);
 
/*
 * Tune the card
@@ -240,10 +232,8 @@ static void cadet_setfreq(struct cadet *dev, unsigned freq)
for (j = 3; j > -1; j--) {
cadet_settune(dev, fifo | (j << 16));
 
-   mutex_lock(&dev->lock);
outb(7, dev->io); /* Select tuner control */
outb(curvol, dev->io + 1);
-   mutex_unlock(&dev->lock);
 
msleep(100);
 
@@ -257,32 +247,6 @@ static void cadet_setfreq(struct cadet *dev, unsigned freq)
 }
 
 
-static int cadet_getvol(struct cadet *dev)
-{
-   int ret = 0;
-
-   mutex_lock(&dev->lock);
-
-   outb(7, dev->io);/* Select tuner control */
-   if ((inb(dev->io + 1) & 0x20) != 0)
-   ret = 0x;
-
-   mutex_unlock(&dev->lock);
-   return ret;
-}
-
-
-static void cadet_setvol(struct cadet *dev, int vol)
-{
-   mutex_lock(&dev->lock);
-   outb(7, dev->io);/* Select tuner control */
-   if (vol > 0)
-   outb(0x20, dev->io + 1);
-   else
-   outb(0x00, dev->io + 1);
-   mutex_unlock(&dev->

[RFC PATCH 4/6] radio-cadet: upgrade to latest frameworks.

2012-07-02 Thread Hans Verkuil
From: Hans Verkuil 

- add control framework
- use core locking
- use V4L2_TUNER_CAP_LOW
- remove volume support: there is no hardware volume control

Signed-off-by: Hans Verkuil 
---
 drivers/media/radio/radio-cadet.c |  243 +
 1 file changed, 83 insertions(+), 160 deletions(-)

diff --git a/drivers/media/radio/radio-cadet.c 
b/drivers/media/radio/radio-cadet.c
index 16a089f..93536b7 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -41,6 +41,9 @@
 #include   /* outb, outb_p */
 #include 
 #include 
+#include 
+#include 
+#include 
 
 MODULE_AUTHOR("Fred Gleason, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, 
Scott McGrath, William McGrath");
 MODULE_DESCRIPTION("A driver for the ADS Cadet AM/FM/RDS radio card.");
@@ -61,8 +64,8 @@ module_param(radio_nr, int, 0);
 struct cadet {
struct v4l2_device v4l2_dev;
struct video_device vdev;
+   struct v4l2_ctrl_handler ctrl_handler;
int io;
-   int users;
int curtuner;
int tunestat;
int sigstrength;
@@ -94,11 +97,9 @@ static int cadet_getstereo(struct cadet *dev)
if (dev->curtuner != 0) /* Only FM has stereo capability! */
return V4L2_TUNER_SUB_MONO;
 
-   mutex_lock(&dev->lock);
outb(7, dev->io);  /* Select tuner control */
if ((inb(dev->io + 1) & 0x40) == 0)
ret = V4L2_TUNER_SUB_STEREO;
-   mutex_unlock(&dev->lock);
return ret;
 }
 
@@ -111,8 +112,6 @@ static unsigned cadet_gettune(struct cadet *dev)
 * Prepare for read
 */
 
-   mutex_lock(&dev->lock);
-
outb(7, dev->io);   /* Select tuner control */
curvol = inb(dev->io + 1); /* Save current volume/mute setting */
outb(0x00, dev->io + 1);  /* Ensure WRITE-ENABLE is LOW */
@@ -134,8 +133,6 @@ static unsigned cadet_gettune(struct cadet *dev)
 * Restore volume/mute setting
 */
outb(curvol, dev->io + 1);
-   mutex_unlock(&dev->lock);
-
return fifo;
 }
 
@@ -161,7 +158,7 @@ static unsigned cadet_getfreq(struct cadet *dev)
fifo = fifo >> 1;
}
freq -= 1070;   /* IF frequency is 10.7 MHz */
-   freq = (freq * 16) / 100;   /* Make it 1/16 MHz */
+   freq = (freq * 16) / 1000;   /* Make it 1/16 kHz */
}
if (dev->curtuner == 1)/* AM */
freq = ((fifo & 0x7fff) - 2010) * 16;
@@ -174,8 +171,6 @@ static void cadet_settune(struct cadet *dev, unsigned fifo)
int i;
unsigned test;
 
-   mutex_lock(&dev->lock);
-
outb(7, dev->io);/* Select tuner control */
/*
 * Write the shift register
@@ -194,7 +189,6 @@ static void cadet_settune(struct cadet *dev, unsigned fifo)
test = 0x1c | ((fifo >> 23) & 0x02);
outb(test, dev->io + 1);
}
-   mutex_unlock(&dev->lock);
 }
 
 static void cadet_setfreq(struct cadet *dev, unsigned freq)
@@ -209,7 +203,7 @@ static void cadet_setfreq(struct cadet *dev, unsigned freq)
fifo = 0;
if (dev->curtuner == 0) {/* FM */
test = 102400;
-   freq = (freq * 1000) / 16;   /* Make it kHz */
+   freq = freq / 16;   /* Make it kHz */
freq += 10700;   /* IF is 10700 kHz */
for (i = 0; i < 14; i++) {
fifo = fifo << 1;
@@ -229,10 +223,8 @@ static void cadet_setfreq(struct cadet *dev, unsigned freq)
 * Save current volume/mute setting
 */
 
-   mutex_lock(&dev->lock);
outb(7, dev->io);/* Select tuner control */
curvol = inb(dev->io + 1);
-   mutex_unlock(&dev->lock);
 
/*
 * Tune the card
@@ -240,10 +232,8 @@ static void cadet_setfreq(struct cadet *dev, unsigned freq)
for (j = 3; j > -1; j--) {
cadet_settune(dev, fifo | (j << 16));
 
-   mutex_lock(&dev->lock);
outb(7, dev->io); /* Select tuner control */
outb(curvol, dev->io + 1);
-   mutex_unlock(&dev->lock);
 
msleep(100);
 
@@ -257,32 +247,6 @@ static void cadet_setfreq(struct cadet *dev, unsigned freq)
 }
 
 
-static int cadet_getvol(struct cadet *dev)
-{
-   int ret = 0;
-
-   mutex_lock(&dev->lock);
-
-   outb(7, dev->io);/* Select tuner control */
-   if ((inb(dev->io + 1) & 0x20) != 0)
-   ret = 0x;
-
-   mutex_unlock(&dev->lock);
-   return ret;
-}
-
-
-static void cadet_setvol(struct cadet *dev, int vol)
-{
-   mutex_lock(&dev->lock);
-   outb(7, dev->io);/* Select tuner control */
-   if (vol > 0)
-   outb(0x20, dev->io + 1);
-   else
-   outb(0x00, dev->io + 1);
-   mutex_unlock(&dev->