2 * Guillemot Maxi Radio FM 2000 PCI radio card driver for Linux
3 * (C) 2001 Dimitromanolakis Apostolos <apdim@grecian.net>
5 * Based in the radio Maestro PCI driver. Actually it uses the same chip
6 * for radio but different pci controller.
8 * I didn't have any specs I reversed engineered the protocol from
9 * the windows driver (radio.dll).
11 * The card uses the TEA5757 chip that includes a search function but it
12 * is useless as I haven't found any way to read back the frequency. If
13 * anybody does please mail me.
15 * For the pdf file see:
16 * http://www.semiconductors.philips.com/pip/TEA5757H/V1
21 * - better pci interface thanks to Francois Romieu <romieu@cogenit.fr>
23 * 0.75 Sun Feb 4 22:51:27 EET 2001
25 * - removed support for multiple devices as it didn't work anyway
28 * - card unmutes if you change frequency
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
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/ioport.h>
39 #include <linux/delay.h>
41 #include <asm/uaccess.h>
42 #include <linux/mutex.h>
44 #include <linux/pci.h>
45 #include <linux/videodev2.h>
46 #include <media/v4l2-common.h>
48 #define DRIVER_VERSION "0.77"
50 #include <linux/version.h> /* for KERNEL_VERSION MACRO */
51 #define RADIO_VERSION KERNEL_VERSION(0,7,7)
53 static struct video_device maxiradio_radio
;
55 #define dprintk(num, fmt, arg...) \
57 if (maxiradio_radio.debug >= num) \
58 printk(KERN_DEBUG "%s: " fmt, \
59 maxiradio_radio.name, ## arg); } while (0)
61 static struct v4l2_queryctrl radio_qctrl
[] = {
63 .id
= V4L2_CID_AUDIO_MUTE
,
68 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
72 #ifndef PCI_VENDOR_ID_GUILLEMOT
73 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
76 #ifndef PCI_DEVICE_ID_GUILLEMOT
77 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
81 /* TEA5757 pin mappings */
82 static const int clk
= 1, data
= 2, wren
= 4, mo_st
= 8, power
= 16 ;
84 static int radio_nr
= -1;
85 module_param(radio_nr
, int, 0);
88 #define FREQ_LO 50*16000
89 #define FREQ_HI 150*16000
91 #define FREQ_IF 171200 /* 10.7*16000 */
92 #define FREQ_STEP 200 /* 12.5*16 */
94 /* (x==fmhz*16*1000) -> bits */
95 #define FREQ2BITS(x) ((( (unsigned int)(x)+FREQ_IF+(FREQ_STEP<<1)) \
98 #define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF)
101 static const struct file_operations maxiradio_fops
= {
102 .owner
= THIS_MODULE
,
103 .open
= video_exclusive_open
,
104 .release
= video_exclusive_release
,
105 .ioctl
= video_ioctl2
,
106 .compat_ioctl
= v4l_compat_ioctl32
,
110 static struct radio_device
112 __u16 io
, /* base of radio io */
113 muted
, /* VIDEO_AUDIO_MUTE */
114 stereo
, /* VIDEO_TUNER_STEREO_ON */
115 tuned
; /* signal strength (0 or 0xffff) */
125 static void outbit(unsigned long bit
, __u16 io
)
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);
135 outb( power
|wren
,io
); udelay(4);
136 outb( power
|wren
|clk
,io
); udelay(4);
137 outb( power
|wren
,io
); udelay(4);
141 static void turn_power(__u16 io
, int p
)
144 dprintk(1, "Radio powered on\n");
147 dprintk(1, "Radio powered off\n");
152 static void set_freq(__u16 io
, __u32 freq
)
154 unsigned long int si
;
156 int data
= FREQ2BITS(freq
);
158 /* TEA5757 shift register bits (see pdf) */
160 outbit(0,io
); // 24 search
161 outbit(1,io
); // 23 search up/down
163 outbit(0,io
); // 22 stereo/mono
165 outbit(0,io
); // 21 band
166 outbit(0,io
); // 20 band (only 00=FM works I think)
168 outbit(0,io
); // 19 port ?
169 outbit(0,io
); // 18 port ?
171 outbit(0,io
); // 17 search level
172 outbit(0,io
); // 16 search level
175 for (bl
= 1; bl
<= 16 ; bl
++) {
176 outbit(data
& si
,io
);
180 dprintk(1, "Radio freq set to %d.%02d MHz\n",
182 freq
% 16000 * 100 / 16000);
187 static int get_stereo(__u16 io
)
192 return !(inb(io
) & mo_st
);
195 static int get_tune(__u16 io
)
200 return !(inb(io
) & mo_st
);
204 static int vidioc_querycap (struct file
*file
, void *priv
,
205 struct v4l2_capability
*v
)
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
;
216 static int vidioc_g_tuner (struct file
*file
, void *priv
,
217 struct v4l2_tuner
*v
)
219 struct video_device
*dev
= video_devdata(file
);
220 struct radio_device
*card
=dev
->priv
;
225 memset(v
,0,sizeof(*v
));
226 strcpy(v
->name
, "FM");
227 v
->type
= V4L2_TUNER_RADIO
;
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
;
236 v
->audmode
= V4L2_TUNER_MODE_MONO
;
237 v
->signal
=0xffff*get_tune(card
->io
);
242 static int vidioc_s_tuner (struct file
*file
, void *priv
,
243 struct v4l2_tuner
*v
)
251 static int vidioc_g_audio (struct file
*file
, void *priv
,
252 struct v4l2_audio
*a
)
257 strcpy(a
->name
, "FM");
258 a
->capability
= V4L2_AUDCAP_STEREO
;
262 static int vidioc_g_input(struct file
*filp
, void *priv
, unsigned int *i
)
269 static int vidioc_s_input(struct file
*filp
, void *priv
, unsigned int i
)
278 static int vidioc_s_audio (struct file
*file
, void *priv
,
279 struct v4l2_audio
*a
)
287 static int vidioc_s_frequency (struct file
*file
, void *priv
,
288 struct v4l2_frequency
*f
)
290 struct video_device
*dev
= video_devdata(file
);
291 struct radio_device
*card
=dev
->priv
;
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);
302 card
->freq
= f
->frequency
;
303 set_freq(card
->io
, card
->freq
);
309 static int vidioc_g_frequency (struct file
*file
, void *priv
,
310 struct v4l2_frequency
*f
)
312 struct video_device
*dev
= video_devdata(file
);
313 struct radio_device
*card
=dev
->priv
;
315 f
->type
= V4L2_TUNER_RADIO
;
316 f
->frequency
= card
->freq
;
318 dprintk(4, "radio freq is %d.%02d MHz",
319 f
->frequency
/ 16000,
320 f
->frequency
% 16000 * 100 / 16000);
325 static int vidioc_queryctrl (struct file
*file
, void *priv
,
326 struct v4l2_queryctrl
*qc
)
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
));
340 static int vidioc_g_ctrl (struct file
*file
, void *priv
,
341 struct v4l2_control
*ctrl
)
343 struct video_device
*dev
= video_devdata(file
);
344 struct radio_device
*card
=dev
->priv
;
347 case V4L2_CID_AUDIO_MUTE
:
348 ctrl
->value
=card
->muted
;
355 static int vidioc_s_ctrl (struct file
*file
, void *priv
,
356 struct v4l2_control
*ctrl
)
358 struct video_device
*dev
= video_devdata(file
);
359 struct radio_device
*card
=dev
->priv
;
362 case V4L2_CID_AUDIO_MUTE
:
363 card
->muted
= ctrl
->value
;
365 turn_power(card
->io
, 0);
367 set_freq(card
->io
, card
->freq
);
374 static struct video_device maxiradio_radio
=
376 .owner
= THIS_MODULE
,
377 .name
= "Maxi Radio FM2000 radio",
378 .type
= VID_TYPE_TUNER
,
379 .fops
= &maxiradio_fops
,
381 .vidioc_querycap
= vidioc_querycap
,
382 .vidioc_g_tuner
= vidioc_g_tuner
,
383 .vidioc_s_tuner
= vidioc_s_tuner
,
384 .vidioc_g_audio
= vidioc_g_audio
,
385 .vidioc_s_audio
= vidioc_s_audio
,
386 .vidioc_g_input
= vidioc_g_input
,
387 .vidioc_s_input
= vidioc_s_input
,
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
,
395 static int __devinit
maxiradio_init_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
397 if(!request_region(pci_resource_start(pdev
, 0),
398 pci_resource_len(pdev
, 0), "Maxi Radio FM 2000")) {
399 printk(KERN_ERR
"radio-maxiradio: can't reserve I/O ports\n");
403 if (pci_enable_device(pdev
))
404 goto err_out_free_region
;
406 radio_unit
.io
= pci_resource_start(pdev
, 0);
407 mutex_init(&radio_unit
.lock
);
408 maxiradio_radio
.priv
= &radio_unit
;
410 if (video_register_device(&maxiradio_radio
, VFL_TYPE_RADIO
, radio_nr
)==-1) {
411 printk("radio-maxiradio: can't register device!");
412 goto err_out_free_region
;
415 printk(KERN_INFO
"radio-maxiradio: version "
422 printk(KERN_INFO
"radio-maxiradio: found Guillemot MAXI Radio device (io = 0x%x)\n",
427 release_region(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
432 static void __devexit
maxiradio_remove_one(struct pci_dev
*pdev
)
434 video_unregister_device(&maxiradio_radio
);
435 release_region(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
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
, },
444 MODULE_DEVICE_TABLE(pci
, maxiradio_pci_tbl
);
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
),
453 static int __init
maxiradio_radio_init(void)
455 return pci_register_driver(&maxiradio_driver
);
458 static void __exit
maxiradio_radio_exit(void)
460 pci_unregister_driver(&maxiradio_driver
);
463 module_init(maxiradio_radio_init
);
464 module_exit(maxiradio_radio_exit
);
466 MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net");
467 MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000 radio.");
468 MODULE_LICENSE("GPL");
470 module_param_named(debug
,maxiradio_radio
.debug
, int, 0644);
471 MODULE_PARM_DESC(debug
,"activates debug info");