Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Guillemot Maxi Radio FM 2000 PCI radio card driver for Linux |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * (C) 2001 Dimitromanolakis Apostolos <apdim@grecian.net> |
| 4 | * |
| 5 | * Based in the radio Maestro PCI driver. Actually it uses the same chip |
| 6 | * for radio but different pci controller. |
| 7 | * |
| 8 | * I didn't have any specs I reversed engineered the protocol from |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 9 | * the windows driver (radio.dll). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * The card uses the TEA5757 chip that includes a search function but it |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 12 | * is useless as I haven't found any way to read back the frequency. If |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * anybody does please mail me. |
| 14 | * |
| 15 | * For the pdf file see: |
| 16 | * http://www.semiconductors.philips.com/pip/TEA5757H/V1 |
| 17 | * |
| 18 | * |
| 19 | * CHANGES: |
| 20 | * 0.75b |
| 21 | * - better pci interface thanks to Francois Romieu <romieu@cogenit.fr> |
| 22 | * |
Mauro Carvalho Chehab | e84fef6 | 2006-08-08 09:10:05 -0300 | [diff] [blame] | 23 | * 0.75 Sun Feb 4 22:51:27 EET 2001 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | * - tiding up |
| 25 | * - removed support for multiple devices as it didn't work anyway |
| 26 | * |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 27 | * BUGS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * - card unmutes if you change frequency |
| 29 | * |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 30 | * (c) 2006, 2007 by Mauro Carvalho Chehab <mchehab@infradead.org>: |
| 31 | * - Conversion to V4L2 API |
| 32 | * - Uses video_ioctl2 for parsing and to add debug support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | */ |
| 34 | |
| 35 | |
| 36 | #include <linux/module.h> |
| 37 | #include <linux/init.h> |
| 38 | #include <linux/ioport.h> |
| 39 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/io.h> |
| 41 | #include <asm/uaccess.h> |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 42 | #include <linux/mutex.h> |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <linux/pci.h> |
Mauro Carvalho Chehab | e84fef6 | 2006-08-08 09:10:05 -0300 | [diff] [blame] | 45 | #include <linux/videodev2.h> |
Mauro Carvalho Chehab | 5e87efa | 2006-06-05 10:26:32 -0300 | [diff] [blame] | 46 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 47 | #include <media/v4l2-ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 49 | #define DRIVER_VERSION "0.77" |
Mauro Carvalho Chehab | e84fef6 | 2006-08-08 09:10:05 -0300 | [diff] [blame] | 50 | |
| 51 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 52 | #define RADIO_VERSION KERNEL_VERSION(0,7,7) |
| 53 | |
| 54 | static struct video_device maxiradio_radio; |
| 55 | |
| 56 | #define dprintk(num, fmt, arg...) \ |
| 57 | do { \ |
| 58 | if (maxiradio_radio.debug >= num) \ |
| 59 | printk(KERN_DEBUG "%s: " fmt, \ |
| 60 | maxiradio_radio.name, ## arg); } while (0) |
Mauro Carvalho Chehab | e84fef6 | 2006-08-08 09:10:05 -0300 | [diff] [blame] | 61 | |
| 62 | static struct v4l2_queryctrl radio_qctrl[] = { |
| 63 | { |
| 64 | .id = V4L2_CID_AUDIO_MUTE, |
| 65 | .name = "Mute", |
| 66 | .minimum = 0, |
| 67 | .maximum = 1, |
| 68 | .default_value = 1, |
| 69 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 70 | } |
| 71 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | #ifndef PCI_VENDOR_ID_GUILLEMOT |
| 74 | #define PCI_VENDOR_ID_GUILLEMOT 0x5046 |
| 75 | #endif |
| 76 | |
| 77 | #ifndef PCI_DEVICE_ID_GUILLEMOT |
| 78 | #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001 |
| 79 | #endif |
| 80 | |
| 81 | |
| 82 | /* TEA5757 pin mappings */ |
| 83 | static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16 ; |
| 84 | |
| 85 | static int radio_nr = -1; |
| 86 | module_param(radio_nr, int, 0); |
| 87 | |
Hans Verkuil | 3ca685a | 2008-08-23 04:49:13 -0300 | [diff] [blame] | 88 | static unsigned long in_use; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | #define FREQ_LO 50*16000 |
| 91 | #define FREQ_HI 150*16000 |
| 92 | |
| 93 | #define FREQ_IF 171200 /* 10.7*16000 */ |
| 94 | #define FREQ_STEP 200 /* 12.5*16 */ |
| 95 | |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 96 | /* (x==fmhz*16*1000) -> bits */ |
| 97 | #define FREQ2BITS(x) ((( (unsigned int)(x)+FREQ_IF+(FREQ_STEP<<1)) \ |
| 98 | /(FREQ_STEP<<2))<<2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | #define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF) |
| 101 | |
| 102 | |
Hans Verkuil | 3ca685a | 2008-08-23 04:49:13 -0300 | [diff] [blame] | 103 | static int maxiradio_exclusive_open(struct inode *inode, struct file *file) |
| 104 | { |
| 105 | return test_and_set_bit(0, &in_use) ? -EBUSY : 0; |
| 106 | } |
| 107 | |
| 108 | static int maxiradio_exclusive_release(struct inode *inode, struct file *file) |
| 109 | { |
| 110 | clear_bit(0, &in_use); |
| 111 | return 0; |
| 112 | } |
| 113 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 114 | static const struct file_operations maxiradio_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | .owner = THIS_MODULE, |
Hans Verkuil | 3ca685a | 2008-08-23 04:49:13 -0300 | [diff] [blame] | 116 | .open = maxiradio_exclusive_open, |
| 117 | .release = maxiradio_exclusive_release, |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 118 | .ioctl = video_ioctl2, |
Douglas Schilling Landgraf | 078ff79 | 2008-04-22 14:46:11 -0300 | [diff] [blame] | 119 | #ifdef CONFIG_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 120 | .compat_ioctl = v4l_compat_ioctl32, |
Douglas Schilling Landgraf | 078ff79 | 2008-04-22 14:46:11 -0300 | [diff] [blame] | 121 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | .llseek = no_llseek, |
| 123 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | static struct radio_device |
| 126 | { |
| 127 | __u16 io, /* base of radio io */ |
| 128 | muted, /* VIDEO_AUDIO_MUTE */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 129 | stereo, /* VIDEO_TUNER_STEREO_ON */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | tuned; /* signal strength (0 or 0xffff) */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | unsigned long freq; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 133 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 134 | struct mutex lock; |
Mauro Carvalho Chehab | 712642b | 2007-01-26 07:33:07 -0300 | [diff] [blame] | 135 | } radio_unit = { |
| 136 | .muted =1, |
| 137 | .freq = FREQ_LO, |
| 138 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | static void outbit(unsigned long bit, __u16 io) |
| 141 | { |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 142 | if (bit != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
| 144 | outb( power|wren|data ,io); udelay(4); |
| 145 | outb( power|wren|data|clk ,io); udelay(4); |
| 146 | outb( power|wren|data ,io); udelay(4); |
| 147 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 148 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
| 150 | outb( power|wren ,io); udelay(4); |
| 151 | outb( power|wren|clk ,io); udelay(4); |
| 152 | outb( power|wren ,io); udelay(4); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | static void turn_power(__u16 io, int p) |
| 157 | { |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 158 | if (p != 0) { |
| 159 | dprintk(1, "Radio powered on\n"); |
| 160 | outb(power, io); |
| 161 | } else { |
| 162 | dprintk(1, "Radio powered off\n"); |
| 163 | outb(0,io); |
| 164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 167 | static void set_freq(__u16 io, __u32 freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { |
| 169 | unsigned long int si; |
| 170 | int bl; |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 171 | int val = FREQ2BITS(freq); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | /* TEA5757 shift register bits (see pdf) */ |
| 174 | |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 175 | outbit(0, io); /* 24 search */ |
| 176 | outbit(1, io); /* 23 search up/down */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 177 | |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 178 | outbit(0, io); /* 22 stereo/mono */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 180 | outbit(0, io); /* 21 band */ |
| 181 | outbit(0, io); /* 20 band (only 00=FM works I think) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 183 | outbit(0, io); /* 19 port ? */ |
| 184 | outbit(0, io); /* 18 port ? */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 185 | |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 186 | outbit(0, io); /* 17 search level */ |
| 187 | outbit(0, io); /* 16 search level */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | si = 0x8000; |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 190 | for (bl = 1; bl <= 16; bl++) { |
| 191 | outbit(val & si, io); |
| 192 | si >>= 1; |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 193 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 194 | |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 195 | dprintk(1, "Radio freq set to %d.%02d MHz\n", |
| 196 | freq / 16000, |
| 197 | freq % 16000 * 100 / 16000); |
| 198 | |
| 199 | turn_power(io, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static int get_stereo(__u16 io) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 203 | { |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 204 | outb(power,io); |
| 205 | udelay(4); |
| 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | return !(inb(io) & mo_st); |
| 208 | } |
| 209 | |
| 210 | static int get_tune(__u16 io) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 211 | { |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 212 | outb(power+clk,io); |
| 213 | udelay(4); |
| 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | return !(inb(io) & mo_st); |
| 216 | } |
| 217 | |
| 218 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 219 | static int vidioc_querycap (struct file *file, void *priv, |
| 220 | struct v4l2_capability *v) |
| 221 | { |
| 222 | strlcpy(v->driver, "radio-maxiradio", sizeof (v->driver)); |
| 223 | strlcpy(v->card, "Maxi Radio FM2000 radio", sizeof (v->card)); |
| 224 | sprintf(v->bus_info,"ISA"); |
| 225 | v->version = RADIO_VERSION; |
| 226 | v->capabilities = V4L2_CAP_TUNER; |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static int vidioc_g_tuner (struct file *file, void *priv, |
| 232 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
| 234 | struct video_device *dev = video_devdata(file); |
| 235 | struct radio_device *card=dev->priv; |
| 236 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 237 | if (v->index > 0) |
| 238 | return -EINVAL; |
Mauro Carvalho Chehab | e84fef6 | 2006-08-08 09:10:05 -0300 | [diff] [blame] | 239 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 240 | memset(v,0,sizeof(*v)); |
| 241 | strcpy(v->name, "FM"); |
| 242 | v->type = V4L2_TUNER_RADIO; |
| 243 | |
| 244 | v->rangelow=FREQ_LO; |
| 245 | v->rangehigh=FREQ_HI; |
| 246 | v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; |
| 247 | v->capability=V4L2_TUNER_CAP_LOW; |
| 248 | if(get_stereo(card->io)) |
| 249 | v->audmode = V4L2_TUNER_MODE_STEREO; |
| 250 | else |
| 251 | v->audmode = V4L2_TUNER_MODE_MONO; |
| 252 | v->signal=0xffff*get_tune(card->io); |
| 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static int vidioc_s_tuner (struct file *file, void *priv, |
| 258 | struct v4l2_tuner *v) |
| 259 | { |
| 260 | if (v->index > 0) |
| 261 | return -EINVAL; |
| 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | |
Mauro Carvalho Chehab | 140dcc4 | 2007-01-25 15:00:45 -0300 | [diff] [blame] | 266 | static int vidioc_g_audio (struct file *file, void *priv, |
| 267 | struct v4l2_audio *a) |
| 268 | { |
| 269 | if (a->index > 1) |
| 270 | return -EINVAL; |
| 271 | |
Mauro Carvalho Chehab | b61f8d6 | 2007-01-26 07:07:12 -0300 | [diff] [blame] | 272 | strcpy(a->name, "FM"); |
Mauro Carvalho Chehab | 140dcc4 | 2007-01-25 15:00:45 -0300 | [diff] [blame] | 273 | a->capability = V4L2_AUDCAP_STEREO; |
| 274 | return 0; |
| 275 | } |
| 276 | |
Mauro Carvalho Chehab | a0c05ab | 2007-01-25 16:48:13 -0300 | [diff] [blame] | 277 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 278 | { |
| 279 | *i = 0; |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 280 | |
Mauro Carvalho Chehab | a0c05ab | 2007-01-25 16:48:13 -0300 | [diff] [blame] | 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 285 | { |
| 286 | if (i != 0) |
| 287 | return -EINVAL; |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 288 | |
Mauro Carvalho Chehab | a0c05ab | 2007-01-25 16:48:13 -0300 | [diff] [blame] | 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | |
Mauro Carvalho Chehab | 140dcc4 | 2007-01-25 15:00:45 -0300 | [diff] [blame] | 293 | static int vidioc_s_audio (struct file *file, void *priv, |
| 294 | struct v4l2_audio *a) |
| 295 | { |
| 296 | if (a->index != 0) |
| 297 | return -EINVAL; |
| 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 302 | static int vidioc_s_frequency (struct file *file, void *priv, |
| 303 | struct v4l2_frequency *f) |
| 304 | { |
| 305 | struct video_device *dev = video_devdata(file); |
| 306 | struct radio_device *card=dev->priv; |
| 307 | |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 308 | if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) { |
| 309 | dprintk(1, "radio freq (%d.%02d MHz) out of range (%d-%d)\n", |
| 310 | f->frequency / 16000, |
| 311 | f->frequency % 16000 * 100 / 16000, |
| 312 | FREQ_LO / 16000, FREQ_HI / 16000); |
| 313 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 314 | return -EINVAL; |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 315 | } |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 316 | |
| 317 | card->freq = f->frequency; |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 318 | set_freq(card->io, card->freq); |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 319 | msleep(125); |
| 320 | |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | static int vidioc_g_frequency (struct file *file, void *priv, |
| 325 | struct v4l2_frequency *f) |
| 326 | { |
| 327 | struct video_device *dev = video_devdata(file); |
| 328 | struct radio_device *card=dev->priv; |
| 329 | |
| 330 | f->type = V4L2_TUNER_RADIO; |
| 331 | f->frequency = card->freq; |
| 332 | |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 333 | dprintk(4, "radio freq is %d.%02d MHz", |
| 334 | f->frequency / 16000, |
| 335 | f->frequency % 16000 * 100 / 16000); |
| 336 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static int vidioc_queryctrl (struct file *file, void *priv, |
| 341 | struct v4l2_queryctrl *qc) |
| 342 | { |
| 343 | int i; |
| 344 | |
| 345 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { |
| 346 | if (qc->id && qc->id == radio_qctrl[i].id) { |
| 347 | memcpy(qc, &(radio_qctrl[i]), sizeof(*qc)); |
| 348 | return (0); |
Mauro Carvalho Chehab | e84fef6 | 2006-08-08 09:10:05 -0300 | [diff] [blame] | 349 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 351 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 352 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 355 | static int vidioc_g_ctrl (struct file *file, void *priv, |
| 356 | struct v4l2_control *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
| 358 | struct video_device *dev = video_devdata(file); |
| 359 | struct radio_device *card=dev->priv; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 360 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 361 | switch (ctrl->id) { |
| 362 | case V4L2_CID_AUDIO_MUTE: |
| 363 | ctrl->value=card->muted; |
| 364 | return (0); |
| 365 | } |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 366 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 367 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 370 | static int vidioc_s_ctrl (struct file *file, void *priv, |
| 371 | struct v4l2_control *ctrl) |
| 372 | { |
| 373 | struct video_device *dev = video_devdata(file); |
| 374 | struct radio_device *card=dev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 376 | switch (ctrl->id) { |
| 377 | case V4L2_CID_AUDIO_MUTE: |
| 378 | card->muted = ctrl->value; |
| 379 | if(card->muted) |
| 380 | turn_power(card->io, 0); |
| 381 | else |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 382 | set_freq(card->io, card->freq); |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 383 | return 0; |
| 384 | } |
Mauro Carvalho Chehab | f1557ce | 2007-01-26 07:23:44 -0300 | [diff] [blame] | 385 | |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 386 | return -EINVAL; |
| 387 | } |
| 388 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 389 | static const struct v4l2_ioctl_ops maxiradio_ioctl_ops = { |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 390 | .vidioc_querycap = vidioc_querycap, |
| 391 | .vidioc_g_tuner = vidioc_g_tuner, |
| 392 | .vidioc_s_tuner = vidioc_s_tuner, |
Mauro Carvalho Chehab | 140dcc4 | 2007-01-25 15:00:45 -0300 | [diff] [blame] | 393 | .vidioc_g_audio = vidioc_g_audio, |
| 394 | .vidioc_s_audio = vidioc_s_audio, |
Mauro Carvalho Chehab | a0c05ab | 2007-01-25 16:48:13 -0300 | [diff] [blame] | 395 | .vidioc_g_input = vidioc_g_input, |
| 396 | .vidioc_s_input = vidioc_s_input, |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 397 | .vidioc_g_frequency = vidioc_g_frequency, |
| 398 | .vidioc_s_frequency = vidioc_s_frequency, |
| 399 | .vidioc_queryctrl = vidioc_queryctrl, |
| 400 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 401 | .vidioc_s_ctrl = vidioc_s_ctrl, |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 402 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 404 | static struct video_device maxiradio_radio = { |
Hans Verkuil | aa5e90a | 2008-08-23 06:23:55 -0300 | [diff] [blame^] | 405 | .name = "Maxi Radio FM2000 radio", |
| 406 | .fops = &maxiradio_fops, |
| 407 | .ioctl_ops = &maxiradio_ioctl_ops, |
| 408 | .release = video_device_release_empty, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 409 | }; |
| 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 412 | { |
| 413 | if(!request_region(pci_resource_start(pdev, 0), |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 414 | pci_resource_len(pdev, 0), "Maxi Radio FM 2000")) { |
| 415 | printk(KERN_ERR "radio-maxiradio: can't reserve I/O ports\n"); |
| 416 | goto err_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | if (pci_enable_device(pdev)) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 420 | goto err_out_free_region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | radio_unit.io = pci_resource_start(pdev, 0); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 423 | mutex_init(&radio_unit.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | maxiradio_radio.priv = &radio_unit; |
| 425 | |
Hans Verkuil | cba99ae | 2008-09-03 17:11:58 -0300 | [diff] [blame] | 426 | if (video_register_device(&maxiradio_radio, VFL_TYPE_RADIO, radio_nr) < 0) { |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 427 | printk("radio-maxiradio: can't register device!"); |
| 428 | goto err_out_free_region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | printk(KERN_INFO "radio-maxiradio: version " |
| 432 | DRIVER_VERSION |
| 433 | " time " |
| 434 | __TIME__ " " |
| 435 | __DATE__ |
| 436 | "\n"); |
| 437 | |
| 438 | printk(KERN_INFO "radio-maxiradio: found Guillemot MAXI Radio device (io = 0x%x)\n", |
| 439 | radio_unit.io); |
| 440 | return 0; |
| 441 | |
| 442 | err_out_free_region: |
| 443 | release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); |
| 444 | err_out: |
| 445 | return -ENODEV; |
| 446 | } |
| 447 | |
| 448 | static void __devexit maxiradio_remove_one(struct pci_dev *pdev) |
| 449 | { |
| 450 | video_unregister_device(&maxiradio_radio); |
| 451 | release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); |
| 452 | } |
| 453 | |
| 454 | static struct pci_device_id maxiradio_pci_tbl[] = { |
| 455 | { PCI_VENDOR_ID_GUILLEMOT, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO, |
| 456 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 457 | { 0,} |
| 458 | }; |
| 459 | |
| 460 | MODULE_DEVICE_TABLE(pci, maxiradio_pci_tbl); |
| 461 | |
| 462 | static struct pci_driver maxiradio_driver = { |
| 463 | .name = "radio-maxiradio", |
| 464 | .id_table = maxiradio_pci_tbl, |
| 465 | .probe = maxiradio_init_one, |
| 466 | .remove = __devexit_p(maxiradio_remove_one), |
| 467 | }; |
| 468 | |
| 469 | static int __init maxiradio_radio_init(void) |
| 470 | { |
Richard Knutsson | 9bfab8c | 2005-11-30 00:59:34 +0100 | [diff] [blame] | 471 | return pci_register_driver(&maxiradio_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | static void __exit maxiradio_radio_exit(void) |
| 475 | { |
| 476 | pci_unregister_driver(&maxiradio_driver); |
| 477 | } |
| 478 | |
| 479 | module_init(maxiradio_radio_init); |
| 480 | module_exit(maxiradio_radio_exit); |
Mauro Carvalho Chehab | 06470ed | 2007-01-25 09:04:34 -0300 | [diff] [blame] | 481 | |
| 482 | MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net"); |
| 483 | MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000 radio."); |
| 484 | MODULE_LICENSE("GPL"); |
| 485 | |
| 486 | module_param_named(debug,maxiradio_radio.debug, int, 0644); |
| 487 | MODULE_PARM_DESC(debug,"activates debug info"); |