Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* radio-cadet.c - A video4linux driver for the ADS Cadet AM/FM Radio Card |
| 2 | * |
| 3 | * by Fred Gleason <fredg@wava.com> |
| 4 | * Version 0.3.3 |
| 5 | * |
| 6 | * (Loosely) based on code for the Aztech radio card by |
| 7 | * |
| 8 | * Russell Kroll (rkroll@exploits.org) |
| 9 | * Quay Ly |
| 10 | * Donald Song |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 11 | * Jason Lewis (jlewis@twilight.vtc.vsc.edu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) |
| 13 | * William McGrath (wmcgrath@twilight.vtc.vsc.edu) |
| 14 | * |
| 15 | * History: |
| 16 | * 2000-04-29 Russell Kroll <rkroll@exploits.org> |
| 17 | * Added ISAPnP detection for Linux 2.3/2.4 |
| 18 | * |
| 19 | * 2001-01-10 Russell Kroll <rkroll@exploits.org> |
| 20 | * Removed dead CONFIG_RADIO_CADET_PORT code |
| 21 | * PnP detection on load is now default (no args necessary) |
| 22 | * |
| 23 | * 2002-01-17 Adam Belay <ambx1@neo.rr.com> |
| 24 | * Updated to latest pnp code |
| 25 | * |
Alan Cox | d9b0144 | 2008-10-27 15:13:47 -0300 | [diff] [blame] | 26 | * 2003-01-31 Alan Cox <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * Cleaned up locking, delay code, general odds and ends |
Hans J. Koch | c0c7fa0 | 2006-08-08 09:10:12 -0300 | [diff] [blame] | 28 | * |
| 29 | * 2006-07-30 Hans J. Koch <koch@hjk-az.de> |
| 30 | * Changed API to V4L2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | */ |
| 32 | |
Andrew Morton | d591b9c | 2006-08-08 10:52:22 -0300 | [diff] [blame] | 33 | #include <linux/version.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/module.h> /* Modules */ |
| 35 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 36 | #include <linux/ioport.h> /* request_region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/delay.h> /* udelay */ |
Hans J. Koch | c0c7fa0 | 2006-08-08 09:10:12 -0300 | [diff] [blame] | 38 | #include <linux/videodev2.h> /* V4L2 API defs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/param.h> |
| 40 | #include <linux/pnp.h> |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 41 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 42 | #include <media/v4l2-device.h> |
| 43 | #include <media/v4l2-ioctl.h> |
| 44 | |
| 45 | MODULE_AUTHOR("Fred Gleason, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath"); |
| 46 | MODULE_DESCRIPTION("A driver for the ADS Cadet AM/FM/RDS radio card."); |
| 47 | MODULE_LICENSE("GPL"); |
| 48 | |
| 49 | static int io = -1; /* default to isapnp activation */ |
| 50 | static int radio_nr = -1; |
| 51 | |
| 52 | module_param(io, int, 0); |
| 53 | MODULE_PARM_DESC(io, "I/O address of Cadet card (0x330,0x332,0x334,0x336,0x338,0x33a,0x33c,0x33e)"); |
| 54 | module_param(radio_nr, int, 0); |
| 55 | |
| 56 | #define CADET_VERSION KERNEL_VERSION(0, 3, 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | #define RDS_BUFFER 256 |
Hans J. Koch | c0c7fa0 | 2006-08-08 09:10:12 -0300 | [diff] [blame] | 59 | #define RDS_RX_FLAG 1 |
| 60 | #define MBS_RX_FLAG 2 |
| 61 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 62 | struct cadet { |
| 63 | struct v4l2_device v4l2_dev; |
| 64 | struct video_device vdev; |
| 65 | int io; |
| 66 | int users; |
| 67 | int curtuner; |
| 68 | int tunestat; |
| 69 | int sigstrength; |
| 70 | wait_queue_head_t read_queue; |
| 71 | struct timer_list readtimer; |
| 72 | __u8 rdsin, rdsout, rdsstat; |
| 73 | unsigned char rdsbuf[RDS_BUFFER]; |
| 74 | struct mutex lock; |
| 75 | int reading; |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 76 | }; |
| 77 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 78 | static struct cadet cadet_card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * Signal Strength Threshold Values |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 82 | * The V4L API spec does not define any particular unit for the signal |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | * strength value. These values are in microvolts of RF at the tuner's input. |
| 84 | */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 85 | static __u16 sigtable[2][4] = { |
| 86 | { 5, 10, 30, 150 }, |
| 87 | { 28, 40, 63, 1000 } |
| 88 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Hans J. Koch | c0c7fa0 | 2006-08-08 09:10:12 -0300 | [diff] [blame] | 90 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 91 | static int cadet_getstereo(struct cadet *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Hans J. Koch | c0c7fa0 | 2006-08-08 09:10:12 -0300 | [diff] [blame] | 93 | int ret = V4L2_TUNER_SUB_MONO; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 94 | |
| 95 | if (dev->curtuner != 0) /* Only FM has stereo capability! */ |
Hans J. Koch | c0c7fa0 | 2006-08-08 09:10:12 -0300 | [diff] [blame] | 96 | return V4L2_TUNER_SUB_MONO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 98 | mutex_lock(&dev->lock); |
| 99 | outb(7, dev->io); /* Select tuner control */ |
| 100 | if ((inb(dev->io + 1) & 0x40) == 0) |
Hans J. Koch | c0c7fa0 | 2006-08-08 09:10:12 -0300 | [diff] [blame] | 101 | ret = V4L2_TUNER_SUB_STEREO; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 102 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 103 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 106 | static unsigned cadet_gettune(struct cadet *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 108 | int curvol, i; |
| 109 | unsigned fifo = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 111 | /* |
| 112 | * Prepare for read |
| 113 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 115 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 116 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 117 | outb(7, dev->io); /* Select tuner control */ |
| 118 | curvol = inb(dev->io + 1); /* Save current volume/mute setting */ |
| 119 | outb(0x00, dev->io + 1); /* Ensure WRITE-ENABLE is LOW */ |
| 120 | dev->tunestat = 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 122 | /* |
| 123 | * Read the shift register |
| 124 | */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 125 | for (i = 0; i < 25; i++) { |
| 126 | fifo = (fifo << 1) | ((inb(dev->io + 1) >> 7) & 0x01); |
| 127 | if (i < 24) { |
| 128 | outb(0x01, dev->io + 1); |
| 129 | dev->tunestat &= inb(dev->io + 1); |
| 130 | outb(0x00, dev->io + 1); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 131 | } |
| 132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 134 | /* |
| 135 | * Restore volume/mute setting |
| 136 | */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 137 | outb(curvol, dev->io + 1); |
| 138 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | return fifo; |
| 141 | } |
| 142 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 143 | static unsigned cadet_getfreq(struct cadet *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 145 | int i; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 146 | unsigned freq = 0, test, fifo = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | /* |
| 149 | * Read current tuning |
| 150 | */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 151 | fifo = cadet_gettune(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 153 | /* |
| 154 | * Convert to actual frequency |
| 155 | */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 156 | if (dev->curtuner == 0) { /* FM */ |
| 157 | test = 12500; |
| 158 | for (i = 0; i < 14; i++) { |
| 159 | if ((fifo & 0x01) != 0) |
| 160 | freq += test; |
| 161 | test = test << 1; |
| 162 | fifo = fifo >> 1; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 163 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 164 | freq -= 10700000; /* IF frequency is 10.7 MHz */ |
| 165 | freq = (freq * 16) / 1000000; /* Make it 1/16 MHz */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 167 | if (dev->curtuner == 1) /* AM */ |
| 168 | freq = ((fifo & 0x7fff) - 2010) * 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 170 | return freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 173 | static void cadet_settune(struct cadet *dev, unsigned fifo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 175 | int i; |
| 176 | unsigned test; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 178 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 179 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 180 | outb(7, dev->io); /* Select tuner control */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /* |
| 182 | * Write the shift register |
| 183 | */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 184 | test = 0; |
| 185 | test = (fifo >> 23) & 0x02; /* Align data for SDO */ |
| 186 | test |= 0x1c; /* SDM=1, SWE=1, SEN=1, SCK=0 */ |
| 187 | outb(7, dev->io); /* Select tuner control */ |
| 188 | outb(test, dev->io + 1); /* Initialize for write */ |
| 189 | for (i = 0; i < 25; i++) { |
| 190 | test |= 0x01; /* Toggle SCK High */ |
| 191 | outb(test, dev->io + 1); |
| 192 | test &= 0xfe; /* Toggle SCK Low */ |
| 193 | outb(test, dev->io + 1); |
| 194 | fifo = fifo << 1; /* Prepare the next bit */ |
| 195 | test = 0x1c | ((fifo >> 23) & 0x02); |
| 196 | outb(test, dev->io + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 198 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 201 | static void cadet_setfreq(struct cadet *dev, unsigned freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 203 | unsigned fifo; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 204 | int i, j, test; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 205 | int curvol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 207 | /* |
| 208 | * Formulate a fifo command |
| 209 | */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 210 | fifo = 0; |
| 211 | if (dev->curtuner == 0) { /* FM */ |
| 212 | test = 102400; |
| 213 | freq = (freq * 1000) / 16; /* Make it kHz */ |
| 214 | freq += 10700; /* IF is 10700 kHz */ |
| 215 | for (i = 0; i < 14; i++) { |
| 216 | fifo = fifo << 1; |
| 217 | if (freq >= test) { |
| 218 | fifo |= 0x01; |
| 219 | freq -= test; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 220 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 221 | test = test >> 1; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 224 | if (dev->curtuner == 1) { /* AM */ |
| 225 | fifo = (freq / 16) + 2010; /* Make it kHz */ |
| 226 | fifo |= 0x100000; /* Select AM Band */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 229 | /* |
| 230 | * Save current volume/mute setting |
| 231 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 233 | mutex_lock(&dev->lock); |
| 234 | outb(7, dev->io); /* Select tuner control */ |
| 235 | curvol = inb(dev->io + 1); |
| 236 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | /* |
| 239 | * Tune the card |
| 240 | */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 241 | for (j = 3; j > -1; j--) { |
| 242 | cadet_settune(dev, fifo | (j << 16)); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 243 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 244 | mutex_lock(&dev->lock); |
| 245 | outb(7, dev->io); /* Select tuner control */ |
| 246 | outb(curvol, dev->io + 1); |
| 247 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | msleep(100); |
| 250 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 251 | cadet_gettune(dev); |
| 252 | if ((dev->tunestat & 0x40) == 0) { /* Tuned */ |
| 253 | dev->sigstrength = sigtable[dev->curtuner][j]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | return; |
| 255 | } |
| 256 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 257 | dev->sigstrength = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 261 | static int cadet_getvol(struct cadet *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | { |
| 263 | int ret = 0; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 264 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 265 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 266 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 267 | outb(7, dev->io); /* Select tuner control */ |
| 268 | if ((inb(dev->io + 1) & 0x20) != 0) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 269 | ret = 0xffff; |
| 270 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 271 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 272 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 276 | static void cadet_setvol(struct cadet *dev, int vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 278 | mutex_lock(&dev->lock); |
| 279 | outb(7, dev->io); /* Select tuner control */ |
| 280 | if (vol > 0) |
| 281 | outb(0x20, dev->io + 1); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 282 | else |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 283 | outb(0x00, dev->io + 1); |
| 284 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 285 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 287 | static void cadet_handler(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 289 | struct cadet *dev = (void *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 291 | /* Service the RDS fifo */ |
| 292 | if (mutex_trylock(&dev->lock)) { |
| 293 | outb(0x3, dev->io); /* Select RDS Decoder Control */ |
| 294 | if ((inb(dev->io + 1) & 0x20) != 0) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 295 | printk(KERN_CRIT "cadet: RDS fifo overflow\n"); |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 296 | outb(0x80, dev->io); /* Select RDS fifo */ |
| 297 | while ((inb(dev->io) & 0x80) != 0) { |
| 298 | dev->rdsbuf[dev->rdsin] = inb(dev->io + 1); |
| 299 | if (dev->rdsin == dev->rdsout) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 300 | printk(KERN_WARNING "cadet: RDS buffer overflow\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | else |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 302 | dev->rdsin++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 304 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /* |
| 308 | * Service pending read |
| 309 | */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 310 | if (dev->rdsin != dev->rdsout) |
| 311 | wake_up_interruptible(&dev->read_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 313 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | * Clean up and exit |
| 315 | */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 316 | init_timer(&dev->readtimer); |
| 317 | dev->readtimer.function = cadet_handler; |
| 318 | dev->readtimer.data = (unsigned long)0; |
| 319 | dev->readtimer.expires = jiffies + msecs_to_jiffies(50); |
| 320 | add_timer(&dev->readtimer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 324 | static ssize_t cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 326 | struct cadet *dev = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | unsigned char readbuf[RDS_BUFFER]; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 328 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 330 | if (dev->rdsstat == 0) { |
| 331 | mutex_lock(&dev->lock); |
| 332 | dev->rdsstat = 1; |
| 333 | outb(0x80, dev->io); /* Select RDS fifo */ |
| 334 | mutex_unlock(&dev->lock); |
| 335 | init_timer(&dev->readtimer); |
| 336 | dev->readtimer.function = cadet_handler; |
| 337 | dev->readtimer.data = (unsigned long)dev; |
| 338 | dev->readtimer.expires = jiffies + msecs_to_jiffies(50); |
| 339 | add_timer(&dev->readtimer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 341 | if (dev->rdsin == dev->rdsout) { |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 342 | if (file->f_flags & O_NONBLOCK) |
| 343 | return -EWOULDBLOCK; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 344 | interruptible_sleep_on(&dev->read_queue); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 345 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 346 | while (i < count && dev->rdsin != dev->rdsout) |
| 347 | readbuf[i++] = dev->rdsbuf[dev->rdsout++]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 349 | if (copy_to_user(data, readbuf, i)) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 350 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | return i; |
| 352 | } |
| 353 | |
| 354 | |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 355 | static int vidioc_querycap(struct file *file, void *priv, |
| 356 | struct v4l2_capability *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 358 | strlcpy(v->driver, "ADS Cadet", sizeof(v->driver)); |
| 359 | strlcpy(v->card, "ADS Cadet", sizeof(v->card)); |
| 360 | strlcpy(v->bus_info, "ISA", sizeof(v->bus_info)); |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 361 | v->version = CADET_VERSION; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 362 | v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO | V4L2_CAP_READWRITE; |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 363 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 366 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 367 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 369 | struct cadet *dev = video_drvdata(file); |
| 370 | |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 371 | v->type = V4L2_TUNER_RADIO; |
| 372 | switch (v->index) { |
| 373 | case 0: |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 374 | strlcpy(v->name, "FM", sizeof(v->name)); |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 375 | v->capability = V4L2_TUNER_CAP_STEREO; |
| 376 | v->rangelow = 1400; /* 87.5 MHz */ |
| 377 | v->rangehigh = 1728; /* 108.0 MHz */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 378 | v->rxsubchans = cadet_getstereo(dev); |
| 379 | switch (v->rxsubchans) { |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 380 | case V4L2_TUNER_SUB_MONO: |
| 381 | v->audmode = V4L2_TUNER_MODE_MONO; |
| 382 | break; |
| 383 | case V4L2_TUNER_SUB_STEREO: |
| 384 | v->audmode = V4L2_TUNER_MODE_STEREO; |
| 385 | break; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 386 | default: |
| 387 | break; |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 388 | } |
| 389 | break; |
| 390 | case 1: |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 391 | strlcpy(v->name, "AM", sizeof(v->name)); |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 392 | v->capability = V4L2_TUNER_CAP_LOW; |
| 393 | v->rangelow = 8320; /* 520 kHz */ |
| 394 | v->rangehigh = 26400; /* 1650 kHz */ |
| 395 | v->rxsubchans = V4L2_TUNER_SUB_MONO; |
| 396 | v->audmode = V4L2_TUNER_MODE_MONO; |
| 397 | break; |
| 398 | default: |
| 399 | return -EINVAL; |
| 400 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 401 | v->signal = dev->sigstrength; /* We might need to modify scaling of this */ |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 406 | struct v4l2_tuner *v) |
| 407 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 408 | struct cadet *dev = video_drvdata(file); |
| 409 | |
| 410 | if (v->index != 0 && v->index != 1) |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 411 | return -EINVAL; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 412 | dev->curtuner = v->index; |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 417 | struct v4l2_frequency *f) |
| 418 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 419 | struct cadet *dev = video_drvdata(file); |
| 420 | |
| 421 | f->tuner = dev->curtuner; |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 422 | f->type = V4L2_TUNER_RADIO; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 423 | f->frequency = cadet_getfreq(dev); |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | |
| 428 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 429 | struct v4l2_frequency *f) |
| 430 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 431 | struct cadet *dev = video_drvdata(file); |
| 432 | |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 433 | if (f->type != V4L2_TUNER_RADIO) |
| 434 | return -EINVAL; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 435 | if (dev->curtuner == 0 && (f->frequency < 1400 || f->frequency > 1728)) |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 436 | return -EINVAL; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 437 | if (dev->curtuner == 1 && (f->frequency < 8320 || f->frequency > 26400)) |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 438 | return -EINVAL; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 439 | cadet_setfreq(dev, f->frequency); |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 444 | struct v4l2_queryctrl *qc) |
| 445 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 446 | switch (qc->id) { |
| 447 | case V4L2_CID_AUDIO_MUTE: |
| 448 | return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1); |
| 449 | case V4L2_CID_AUDIO_VOLUME: |
| 450 | return v4l2_ctrl_query_fill(qc, 0, 0xff, 1, 0xff); |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 451 | } |
| 452 | return -EINVAL; |
| 453 | } |
| 454 | |
| 455 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 456 | struct v4l2_control *ctrl) |
| 457 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 458 | struct cadet *dev = video_drvdata(file); |
| 459 | |
| 460 | switch (ctrl->id) { |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 461 | case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */ |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 462 | ctrl->value = (cadet_getvol(dev) == 0); |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 463 | break; |
| 464 | case V4L2_CID_AUDIO_VOLUME: |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 465 | ctrl->value = cadet_getvol(dev); |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 466 | break; |
| 467 | default: |
| 468 | return -EINVAL; |
| 469 | } |
| 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 474 | struct v4l2_control *ctrl) |
| 475 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 476 | struct cadet *dev = video_drvdata(file); |
| 477 | |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 478 | switch (ctrl->id){ |
| 479 | case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */ |
| 480 | if (ctrl->value) |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 481 | cadet_setvol(dev, 0); |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 482 | else |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 483 | cadet_setvol(dev, 0xffff); |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 484 | break; |
| 485 | case V4L2_CID_AUDIO_VOLUME: |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 486 | cadet_setvol(dev, ctrl->value); |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 487 | break; |
| 488 | default: |
| 489 | return -EINVAL; |
| 490 | } |
| 491 | return 0; |
| 492 | } |
| 493 | |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 494 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 495 | { |
| 496 | *i = 0; |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 501 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 502 | return i ? -EINVAL : 0; |
| 503 | } |
| 504 | |
| 505 | static int vidioc_g_audio(struct file *file, void *priv, |
| 506 | struct v4l2_audio *a) |
| 507 | { |
| 508 | a->index = 0; |
| 509 | strlcpy(a->name, "Radio", sizeof(a->name)); |
| 510 | a->capability = V4L2_AUDCAP_STEREO; |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | static int vidioc_s_audio(struct file *file, void *priv, |
| 515 | struct v4l2_audio *a) |
| 516 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 517 | return a->index ? -EINVAL : 0; |
| 518 | } |
| 519 | |
| 520 | static int cadet_open(struct file *file) |
| 521 | { |
| 522 | struct cadet *dev = video_drvdata(file); |
| 523 | |
| 524 | dev->users++; |
| 525 | if (1 == dev->users) |
| 526 | init_waitqueue_head(&dev->read_queue); |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 527 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 530 | static int cadet_release(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 532 | struct cadet *dev = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 534 | dev->users--; |
| 535 | if (0 == dev->users) { |
| 536 | del_timer_sync(&dev->readtimer); |
| 537 | dev->rdsstat = 0; |
Hans J. Koch | c0c7fa0 | 2006-08-08 09:10:12 -0300 | [diff] [blame] | 538 | } |
| 539 | return 0; |
| 540 | } |
| 541 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 542 | static unsigned int cadet_poll(struct file *file, struct poll_table_struct *wait) |
Hans J. Koch | c0c7fa0 | 2006-08-08 09:10:12 -0300 | [diff] [blame] | 543 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 544 | struct cadet *dev = video_drvdata(file); |
| 545 | |
| 546 | poll_wait(file, &dev->read_queue, wait); |
| 547 | if (dev->rdsin != dev->rdsout) |
Hans J. Koch | c0c7fa0 | 2006-08-08 09:10:12 -0300 | [diff] [blame] | 548 | return POLLIN | POLLRDNORM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 553 | static const struct v4l2_file_operations cadet_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | .owner = THIS_MODULE, |
| 555 | .open = cadet_open, |
| 556 | .release = cadet_release, |
| 557 | .read = cadet_read, |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 558 | .ioctl = video_ioctl2, |
Hans J. Koch | c0c7fa0 | 2006-08-08 09:10:12 -0300 | [diff] [blame] | 559 | .poll = cadet_poll, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | }; |
| 561 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 562 | static const struct v4l2_ioctl_ops cadet_ioctl_ops = { |
Douglas Landgraf | c1c4fd3 | 2007-05-07 16:17:16 -0300 | [diff] [blame] | 563 | .vidioc_querycap = vidioc_querycap, |
| 564 | .vidioc_g_tuner = vidioc_g_tuner, |
| 565 | .vidioc_s_tuner = vidioc_s_tuner, |
| 566 | .vidioc_g_frequency = vidioc_g_frequency, |
| 567 | .vidioc_s_frequency = vidioc_s_frequency, |
| 568 | .vidioc_queryctrl = vidioc_queryctrl, |
| 569 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 570 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 571 | .vidioc_g_audio = vidioc_g_audio, |
| 572 | .vidioc_s_audio = vidioc_s_audio, |
| 573 | .vidioc_g_input = vidioc_g_input, |
| 574 | .vidioc_s_input = vidioc_s_input, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | }; |
| 576 | |
Bjorn Helgaas | 044dfc9 | 2008-03-31 21:21:48 -0300 | [diff] [blame] | 577 | #ifdef CONFIG_PNP |
| 578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | static struct pnp_device_id cadet_pnp_devices[] = { |
| 580 | /* ADS Cadet AM/FM Radio Card */ |
| 581 | {.id = "MSM0c24", .driver_data = 0}, |
| 582 | {.id = ""} |
| 583 | }; |
| 584 | |
| 585 | MODULE_DEVICE_TABLE(pnp, cadet_pnp_devices); |
| 586 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 587 | static int cadet_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | { |
| 589 | if (!dev) |
| 590 | return -ENODEV; |
| 591 | /* only support one device */ |
| 592 | if (io > 0) |
| 593 | return -EBUSY; |
| 594 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 595 | if (!pnp_port_valid(dev, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | io = pnp_port_start(dev, 0); |
| 599 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 600 | printk(KERN_INFO "radio-cadet: PnP reports device at %#x\n", io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
| 602 | return io; |
| 603 | } |
| 604 | |
| 605 | static struct pnp_driver cadet_pnp_driver = { |
| 606 | .name = "radio-cadet", |
| 607 | .id_table = cadet_pnp_devices, |
| 608 | .probe = cadet_pnp_probe, |
| 609 | .remove = NULL, |
| 610 | }; |
| 611 | |
Bjorn Helgaas | 044dfc9 | 2008-03-31 21:21:48 -0300 | [diff] [blame] | 612 | #else |
| 613 | static struct pnp_driver cadet_pnp_driver; |
| 614 | #endif |
| 615 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 616 | static void cadet_probe(struct cadet *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 618 | static int iovals[8] = { 0x330, 0x332, 0x334, 0x336, 0x338, 0x33a, 0x33c, 0x33e }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | int i; |
| 620 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 621 | for (i = 0; i < 8; i++) { |
| 622 | dev->io = iovals[i]; |
| 623 | if (request_region(dev->io, 2, "cadet-probe")) { |
| 624 | cadet_setfreq(dev, 1410); |
| 625 | if (cadet_getfreq(dev) == 1410) { |
| 626 | release_region(dev->io, 2); |
| 627 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 629 | release_region(dev->io, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | } |
| 631 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 632 | dev->io = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 635 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | * io should only be set if the user has used something like |
| 637 | * isapnp (the userspace program) to initialize this card for us |
| 638 | */ |
| 639 | |
| 640 | static int __init cadet_init(void) |
| 641 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 642 | struct cadet *dev = &cadet_card; |
| 643 | struct v4l2_device *v4l2_dev = &dev->v4l2_dev; |
| 644 | int res; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 645 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 646 | strlcpy(v4l2_dev->name, "cadet", sizeof(v4l2_dev->name)); |
| 647 | mutex_init(&dev->lock); |
| 648 | |
| 649 | /* If a probe was requested then probe ISAPnP first (safest) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | if (io < 0) |
| 651 | pnp_register_driver(&cadet_pnp_driver); |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 652 | dev->io = io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 654 | /* If that fails then probe unsafely if probe is requested */ |
| 655 | if (dev->io < 0) |
| 656 | cadet_probe(dev); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 657 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 658 | /* Else we bail out */ |
| 659 | if (dev->io < 0) { |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 660 | #ifdef MODULE |
Hans Verkuil | b24c20cc | 2009-03-09 08:11:21 -0300 | [diff] [blame] | 661 | v4l2_err(v4l2_dev, "you must set an I/O address with io=0x330, 0x332, 0x334,\n"); |
| 662 | v4l2_err(v4l2_dev, "0x336, 0x338, 0x33a, 0x33c or 0x33e\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | #endif |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 664 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 666 | if (!request_region(dev->io, 2, "cadet")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | goto fail; |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 668 | |
| 669 | res = v4l2_device_register(NULL, v4l2_dev); |
| 670 | if (res < 0) { |
| 671 | release_region(dev->io, 2); |
| 672 | v4l2_err(v4l2_dev, "could not register v4l2_device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | goto fail; |
| 674 | } |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 675 | |
| 676 | strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name)); |
| 677 | dev->vdev.v4l2_dev = v4l2_dev; |
| 678 | dev->vdev.fops = &cadet_fops; |
| 679 | dev->vdev.ioctl_ops = &cadet_ioctl_ops; |
| 680 | dev->vdev.release = video_device_release_empty; |
| 681 | video_set_drvdata(&dev->vdev, dev); |
| 682 | |
| 683 | if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { |
| 684 | v4l2_device_unregister(v4l2_dev); |
| 685 | release_region(dev->io, 2); |
| 686 | goto fail; |
| 687 | } |
| 688 | v4l2_info(v4l2_dev, "ADS Cadet Radio Card at 0x%x\n", dev->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | return 0; |
| 690 | fail: |
| 691 | pnp_unregister_driver(&cadet_pnp_driver); |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 692 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 695 | static void __exit cadet_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | { |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 697 | struct cadet *dev = &cadet_card; |
| 698 | |
| 699 | video_unregister_device(&dev->vdev); |
| 700 | v4l2_device_unregister(&dev->v4l2_dev); |
| 701 | release_region(dev->io, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | pnp_unregister_driver(&cadet_pnp_driver); |
| 703 | } |
| 704 | |
| 705 | module_init(cadet_init); |
Hans Verkuil | bec2aec | 2009-03-06 13:48:47 -0300 | [diff] [blame] | 706 | module_exit(cadet_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |