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