Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* radiotrack (radioreveal) driver for Linux radio support |
| 2 | * (c) 1997 M. Kirkwood |
Mauro Carvalho Chehab | 46ff2c7 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 3 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Alan Cox | d9b0144 | 2008-10-27 15:13:47 -0300 | [diff] [blame] | 4 | * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org> |
| 6 | * |
| 7 | * History: |
| 8 | * 1999-02-24 Russell Kroll <rkroll@exploits.org> |
| 9 | * Fine tuning/VIDEO_TUNER_LOW |
| 10 | * Frequency range expanded to start at 87 MHz |
| 11 | * |
| 12 | * TODO: Allow for more than one of these foolish entities :-) |
| 13 | * |
| 14 | * Notes on the hardware (reverse engineered from other peoples' |
| 15 | * reverse engineering of AIMS' code :-) |
| 16 | * |
| 17 | * Frequency control is done digitally -- ie out(port,encodefreq(95.8)); |
| 18 | * |
| 19 | * The signal strength query is unsurprisingly inaccurate. And it seems |
| 20 | * to indicate that (on my card, at least) the frequency setting isn't |
| 21 | * too great. (I have to tune up .025MHz from what the freq should be |
| 22 | * to get a report that the thing is tuned.) |
| 23 | * |
| 24 | * Volume control is (ugh) analogue: |
| 25 | * out(port, start_increasing_volume); |
| 26 | * wait(a_wee_while); |
| 27 | * out(port, stop_changing_the_volume); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 28 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | #include <linux/module.h> /* Modules */ |
| 32 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 33 | #include <linux/ioport.h> /* request_region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/delay.h> /* udelay */ |
Mauro Carvalho Chehab | 46ff2c7 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 35 | #include <linux/videodev2.h> /* kernel radio structs */ |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 36 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ |
| 37 | #include <linux/io.h> /* outb, outb_p */ |
| 38 | #include <linux/uaccess.h> /* copy to/from user */ |
| 39 | #include <media/v4l2-device.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 40 | #include <media/v4l2-ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 42 | MODULE_AUTHOR("M.Kirkwood"); |
| 43 | MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card."); |
| 44 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 46ff2c7 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #ifndef CONFIG_RADIO_RTRACK_PORT |
| 47 | #define CONFIG_RADIO_RTRACK_PORT -1 |
| 48 | #endif |
| 49 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 50 | static int io = CONFIG_RADIO_RTRACK_PORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | static int radio_nr = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 53 | module_param(io, int, 0); |
| 54 | MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20f or 0x30f)"); |
| 55 | module_param(radio_nr, int, 0); |
| 56 | |
| 57 | #define RADIO_VERSION KERNEL_VERSION(0, 0, 2) |
| 58 | |
| 59 | struct rtrack |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 61 | struct v4l2_device v4l2_dev; |
| 62 | struct video_device vdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | int port; |
| 64 | int curvol; |
| 65 | unsigned long curfreq; |
| 66 | int muted; |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 67 | int io; |
| 68 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 71 | static struct rtrack rtrack_card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | /* local things */ |
| 74 | |
| 75 | static void sleep_delay(long n) |
| 76 | { |
| 77 | /* Sleep nicely for 'n' uS */ |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 78 | int d = n / msecs_to_jiffies(1000); |
| 79 | if (!d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | udelay(n); |
| 81 | else |
| 82 | msleep(jiffies_to_msecs(d)); |
| 83 | } |
| 84 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 85 | static void rt_decvol(struct rtrack *rt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 87 | outb(0x58, rt->io); /* volume down + sigstr + on */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | sleep_delay(100000); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 89 | outb(0xd8, rt->io); /* volume steady + sigstr + on */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 92 | static void rt_incvol(struct rtrack *rt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 94 | outb(0x98, rt->io); /* volume up + sigstr + on */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | sleep_delay(100000); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 96 | outb(0xd8, rt->io); /* volume steady + sigstr + on */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 99 | static void rt_mute(struct rtrack *rt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 101 | rt->muted = 1; |
| 102 | mutex_lock(&rt->lock); |
| 103 | outb(0xd0, rt->io); /* volume steady, off */ |
| 104 | mutex_unlock(&rt->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 107 | static int rt_setvol(struct rtrack *rt, int vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
| 109 | int i; |
| 110 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 111 | mutex_lock(&rt->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 112 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 113 | if (vol == rt->curvol) { /* requested volume = current */ |
| 114 | if (rt->muted) { /* user is unmuting the card */ |
| 115 | rt->muted = 0; |
| 116 | outb(0xd8, rt->io); /* enable card */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 117 | } |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 118 | mutex_unlock(&rt->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | return 0; |
| 120 | } |
| 121 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 122 | if (vol == 0) { /* volume = 0 means mute the card */ |
| 123 | outb(0x48, rt->io); /* volume down but still "on" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | sleep_delay(2000000); /* make sure it's totally down */ |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 125 | outb(0xd0, rt->io); /* volume steady, off */ |
| 126 | rt->curvol = 0; /* track the volume state! */ |
| 127 | mutex_unlock(&rt->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | return 0; |
| 129 | } |
| 130 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 131 | rt->muted = 0; |
| 132 | if (vol > rt->curvol) |
| 133 | for (i = rt->curvol; i < vol; i++) |
| 134 | rt_incvol(rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | else |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 136 | for (i = rt->curvol; i > vol; i--) |
| 137 | rt_decvol(rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 139 | rt->curvol = vol; |
| 140 | mutex_unlock(&rt->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | return 0; |
| 142 | } |
| 143 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 144 | /* the 128+64 on these outb's is to keep the volume stable while tuning |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | * without them, the volume _will_ creep up with each frequency change |
| 146 | * and bit 4 (+16) is to keep the signal strength meter enabled |
| 147 | */ |
| 148 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 149 | static void send_0_byte(struct rtrack *rt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 151 | if (rt->curvol == 0 || rt->muted) { |
| 152 | outb_p(128+64+16+ 1, rt->io); /* wr-enable + data low */ |
| 153 | outb_p(128+64+16+2+1, rt->io); /* clock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } |
| 155 | else { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 156 | outb_p(128+64+16+8+ 1, rt->io); /* on + wr-enable + data low */ |
| 157 | outb_p(128+64+16+8+2+1, rt->io); /* clock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 159 | sleep_delay(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 162 | static void send_1_byte(struct rtrack *rt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 164 | if (rt->curvol == 0 || rt->muted) { |
| 165 | outb_p(128+64+16+4 +1, rt->io); /* wr-enable+data high */ |
| 166 | outb_p(128+64+16+4+2+1, rt->io); /* clock */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | else { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 169 | outb_p(128+64+16+8+4 +1, rt->io); /* on+wr-enable+data high */ |
| 170 | outb_p(128+64+16+8+4+2+1, rt->io); /* clock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 173 | sleep_delay(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 176 | static int rt_setfreq(struct rtrack *rt, unsigned long freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | { |
| 178 | int i; |
| 179 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 180 | mutex_lock(&rt->lock); /* Stop other ops interfering */ |
| 181 | |
| 182 | rt->curfreq = freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | /* now uses VIDEO_TUNER_LOW for fine tuning */ |
| 185 | |
| 186 | freq += 171200; /* Add 10.7 MHz IF */ |
| 187 | freq /= 800; /* Convert to 50 kHz units */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 188 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 189 | send_0_byte(rt); /* 0: LSB of frequency */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | for (i = 0; i < 13; i++) /* : frequency bits (1-13) */ |
| 192 | if (freq & (1 << i)) |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 193 | send_1_byte(rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | else |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 195 | send_0_byte(rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 197 | send_0_byte(rt); /* 14: test bit - always 0 */ |
| 198 | send_0_byte(rt); /* 15: test bit - always 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 200 | send_0_byte(rt); /* 16: band data 0 - always 0 */ |
| 201 | send_0_byte(rt); /* 17: band data 1 - always 0 */ |
| 202 | send_0_byte(rt); /* 18: band data 2 - always 0 */ |
| 203 | send_0_byte(rt); /* 19: time base - always 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 205 | send_0_byte(rt); /* 20: spacing (0 = 25 kHz) */ |
| 206 | send_1_byte(rt); /* 21: spacing (1 = 25 kHz) */ |
| 207 | send_0_byte(rt); /* 22: spacing (0 = 25 kHz) */ |
| 208 | send_1_byte(rt); /* 23: AM/FM (FM = 1, always) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 210 | if (rt->curvol == 0 || rt->muted) |
| 211 | outb(0xd0, rt->io); /* volume steady + sigstr */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | else |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 213 | outb(0xd8, rt->io); /* volume steady + sigstr + on */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 214 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 215 | mutex_unlock(&rt->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 220 | static int rt_getsigstr(struct rtrack *rt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 222 | int sig = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 224 | mutex_lock(&rt->lock); |
| 225 | if (inb(rt->io) & 2) /* bit set = no signal present */ |
| 226 | sig = 0; |
| 227 | mutex_unlock(&rt->lock); |
| 228 | return sig; |
| 229 | } |
Mauro Carvalho Chehab | 46ff2c7 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 230 | |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 231 | static int vidioc_querycap(struct file *file, void *priv, |
| 232 | struct v4l2_capability *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 234 | strlcpy(v->driver, "radio-aimslab", sizeof(v->driver)); |
| 235 | strlcpy(v->card, "RadioTrack", sizeof(v->card)); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 236 | strlcpy(v->bus_info, "ISA", sizeof(v->bus_info)); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 237 | v->version = RADIO_VERSION; |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 238 | v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 239 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 242 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 243 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 245 | struct rtrack *rt = video_drvdata(file); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 246 | |
| 247 | if (v->index > 0) |
| 248 | return -EINVAL; |
| 249 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 250 | strlcpy(v->name, "FM", sizeof(v->name)); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 251 | v->type = V4L2_TUNER_RADIO; |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 252 | v->rangelow = 87 * 16000; |
| 253 | v->rangehigh = 108 * 16000; |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 254 | v->rxsubchans = V4L2_TUNER_SUB_MONO; |
| 255 | v->capability = V4L2_TUNER_CAP_LOW; |
| 256 | v->audmode = V4L2_TUNER_MODE_MONO; |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 257 | v->signal = 0xffff * rt_getsigstr(rt); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 262 | struct v4l2_tuner *v) |
| 263 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 264 | return v->index ? -EINVAL : 0; |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 268 | struct v4l2_frequency *f) |
| 269 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 270 | struct rtrack *rt = video_drvdata(file); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 271 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 272 | rt_setfreq(rt, f->frequency); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 277 | struct v4l2_frequency *f) |
| 278 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 279 | struct rtrack *rt = video_drvdata(file); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 280 | |
| 281 | f->type = V4L2_TUNER_RADIO; |
| 282 | f->frequency = rt->curfreq; |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 287 | struct v4l2_queryctrl *qc) |
| 288 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 289 | switch (qc->id) { |
| 290 | case V4L2_CID_AUDIO_MUTE: |
| 291 | return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1); |
| 292 | case V4L2_CID_AUDIO_VOLUME: |
| 293 | return v4l2_ctrl_query_fill(qc, 0, 0xff, 1, 0xff); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 294 | } |
| 295 | return -EINVAL; |
| 296 | } |
| 297 | |
| 298 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 299 | struct v4l2_control *ctrl) |
| 300 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 301 | struct rtrack *rt = video_drvdata(file); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 302 | |
| 303 | switch (ctrl->id) { |
| 304 | case V4L2_CID_AUDIO_MUTE: |
| 305 | ctrl->value = rt->muted; |
| 306 | return 0; |
| 307 | case V4L2_CID_AUDIO_VOLUME: |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 308 | ctrl->value = rt->curvol; |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 309 | return 0; |
| 310 | } |
| 311 | return -EINVAL; |
| 312 | } |
| 313 | |
| 314 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 315 | struct v4l2_control *ctrl) |
| 316 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 317 | struct rtrack *rt = video_drvdata(file); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 318 | |
| 319 | switch (ctrl->id) { |
| 320 | case V4L2_CID_AUDIO_MUTE: |
| 321 | if (ctrl->value) |
| 322 | rt_mute(rt); |
| 323 | else |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 324 | rt_setvol(rt, rt->curvol); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 325 | return 0; |
| 326 | case V4L2_CID_AUDIO_VOLUME: |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 327 | rt_setvol(rt, ctrl->value); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | return -EINVAL; |
| 331 | } |
| 332 | |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 333 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 334 | { |
| 335 | *i = 0; |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 340 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 341 | return i ? -EINVAL : 0; |
| 342 | } |
| 343 | |
| 344 | static int vidioc_g_audio(struct file *file, void *priv, |
| 345 | struct v4l2_audio *a) |
| 346 | { |
| 347 | a->index = 0; |
| 348 | strlcpy(a->name, "Radio", sizeof(a->name)); |
| 349 | a->capability = V4L2_AUDCAP_STEREO; |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static int vidioc_s_audio(struct file *file, void *priv, |
| 354 | struct v4l2_audio *a) |
| 355 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 356 | return a->index ? -EINVAL : 0; |
| 357 | } |
| 358 | |
| 359 | static int rtrack_open(struct file *file) |
| 360 | { |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 361 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 364 | static int rtrack_release(struct file *file) |
Hans Verkuil | 3ca685a | 2008-08-23 04:49:13 -0300 | [diff] [blame] | 365 | { |
Hans Verkuil | 3ca685a | 2008-08-23 04:49:13 -0300 | [diff] [blame] | 366 | return 0; |
| 367 | } |
| 368 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 369 | static const struct v4l2_file_operations rtrack_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | .owner = THIS_MODULE, |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 371 | .open = rtrack_open, |
| 372 | .release = rtrack_release, |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 373 | .ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | }; |
| 375 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 376 | static const struct v4l2_ioctl_ops rtrack_ioctl_ops = { |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 377 | .vidioc_querycap = vidioc_querycap, |
| 378 | .vidioc_g_tuner = vidioc_g_tuner, |
| 379 | .vidioc_s_tuner = vidioc_s_tuner, |
| 380 | .vidioc_g_audio = vidioc_g_audio, |
| 381 | .vidioc_s_audio = vidioc_s_audio, |
| 382 | .vidioc_g_input = vidioc_g_input, |
| 383 | .vidioc_s_input = vidioc_s_input, |
| 384 | .vidioc_g_frequency = vidioc_g_frequency, |
| 385 | .vidioc_s_frequency = vidioc_s_frequency, |
| 386 | .vidioc_queryctrl = vidioc_queryctrl, |
| 387 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 388 | .vidioc_s_ctrl = vidioc_s_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | }; |
| 390 | |
| 391 | static int __init rtrack_init(void) |
| 392 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 393 | struct rtrack *rt = &rtrack_card; |
| 394 | struct v4l2_device *v4l2_dev = &rt->v4l2_dev; |
| 395 | int res; |
| 396 | |
| 397 | strlcpy(v4l2_dev->name, "rtrack", sizeof(v4l2_dev->name)); |
| 398 | rt->io = io; |
| 399 | |
| 400 | if (rt->io == -1) { |
Hans Verkuil | b24c20cc | 2009-03-09 08:11:21 -0300 | [diff] [blame^] | 401 | v4l2_err(v4l2_dev, "you must set an I/O address with io=0x20f or 0x30f\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return -EINVAL; |
| 403 | } |
| 404 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 405 | if (!request_region(rt->io, 2, "rtrack")) { |
| 406 | v4l2_err(v4l2_dev, "port 0x%x already in use\n", rt->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | return -EBUSY; |
| 408 | } |
| 409 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 410 | res = v4l2_device_register(NULL, v4l2_dev); |
| 411 | if (res < 0) { |
| 412 | release_region(rt->io, 2); |
| 413 | v4l2_err(v4l2_dev, "could not register v4l2_device\n"); |
| 414 | return res; |
| 415 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 416 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 417 | strlcpy(rt->vdev.name, v4l2_dev->name, sizeof(rt->vdev.name)); |
| 418 | rt->vdev.v4l2_dev = v4l2_dev; |
| 419 | rt->vdev.fops = &rtrack_fops; |
| 420 | rt->vdev.ioctl_ops = &rtrack_ioctl_ops; |
| 421 | rt->vdev.release = video_device_release_empty; |
| 422 | video_set_drvdata(&rt->vdev, rt); |
| 423 | |
| 424 | if (video_register_device(&rt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { |
| 425 | v4l2_device_unregister(&rt->v4l2_dev); |
| 426 | release_region(rt->io, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | return -EINVAL; |
| 428 | } |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 429 | v4l2_info(v4l2_dev, "AIMSlab RadioTrack/RadioReveal card driver.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | /* Set up the I/O locking */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 432 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 433 | mutex_init(&rt->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 434 | |
| 435 | /* mute card - prevents noisy bootups */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
| 437 | /* this ensures that the volume is all the way down */ |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 438 | outb(0x48, rt->io); /* volume down but still "on" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | sleep_delay(2000000); /* make sure it's totally down */ |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 440 | outb(0xc0, rt->io); /* steady volume, mute card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 445 | static void __exit rtrack_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 447 | struct rtrack *rt = &rtrack_card; |
| 448 | |
| 449 | video_unregister_device(&rt->vdev); |
| 450 | v4l2_device_unregister(&rt->v4l2_dev); |
| 451 | release_region(rt->io, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | module_init(rtrack_init); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 455 | module_exit(rtrack_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |