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