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