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