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