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>
25 * - removed support for multiple devices as it didn't work anyway
28 * - card unmutes if you change frequency
33 #include <linux/module.h>
34 #include <linux/init.h>
35 #include <linux/ioport.h>
36 #include <linux/delay.h>
37 #include <linux/sched.h>
39 #include <asm/uaccess.h>
40 #include <linux/mutex.h>
42 #include <linux/pci.h>
43 #include <linux/videodev.h>
44 #include <media/v4l2-common.h>
46 /* version 0.75 Sun Feb 4 22:51:27 EET 2001 */
47 #define DRIVER_VERSION "0.75"
49 #ifndef PCI_VENDOR_ID_GUILLEMOT
50 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
53 #ifndef PCI_DEVICE_ID_GUILLEMOT
54 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
58 /* TEA5757 pin mappings */
59 static const int clk
= 1, data
= 2, wren
= 4, mo_st
= 8, power
= 16 ;
61 static int radio_nr
= -1;
62 module_param(radio_nr
, int, 0);
65 #define FREQ_LO 50*16000
66 #define FREQ_HI 150*16000
68 #define FREQ_IF 171200 /* 10.7*16000 */
69 #define FREQ_STEP 200 /* 12.5*16 */
71 #define FREQ2BITS(x) ((( (unsigned int)(x)+FREQ_IF+(FREQ_STEP<<1))\
72 /(FREQ_STEP<<2))<<2) /* (x==fmhz*16*1000) -> bits */
74 #define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF)
77 static int radio_ioctl(struct inode
*inode
, struct file
*file
,
78 unsigned int cmd
, unsigned long arg
);
80 static struct file_operations maxiradio_fops
= {
82 .open
= video_exclusive_open
,
83 .release
= video_exclusive_release
,
85 .compat_ioctl
= v4l_compat_ioctl32
,
88 static struct video_device maxiradio_radio
=
91 .name
= "Maxi Radio FM2000 radio",
92 .type
= VID_TYPE_TUNER
,
93 .hardware
= VID_HARDWARE_SF16MI
,
94 .fops
= &maxiradio_fops
,
97 static struct radio_device
99 __u16 io
, /* base of radio io */
100 muted
, /* VIDEO_AUDIO_MUTE */
101 stereo
, /* VIDEO_TUNER_STEREO_ON */
102 tuned
; /* signal strength (0 or 0xffff) */
107 } radio_unit
= {0, 0, 0, 0, };
110 static void outbit(unsigned long bit
, __u16 io
)
114 outb( power
|wren
|data
,io
); udelay(4);
115 outb( power
|wren
|data
|clk
,io
); udelay(4);
116 outb( power
|wren
|data
,io
); udelay(4);
120 outb( power
|wren
,io
); udelay(4);
121 outb( power
|wren
|clk
,io
); udelay(4);
122 outb( power
|wren
,io
); udelay(4);
126 static void turn_power(__u16 io
, int p
)
128 if(p
!= 0) outb(power
, io
); else outb(0,io
);
132 static void set_freq(__u16 io
, __u32 data
)
134 unsigned long int si
;
137 /* TEA5757 shift register bits (see pdf) */
139 outbit(0,io
); // 24 search
140 outbit(1,io
); // 23 search up/down
142 outbit(0,io
); // 22 stereo/mono
144 outbit(0,io
); // 21 band
145 outbit(0,io
); // 20 band (only 00=FM works I think)
147 outbit(0,io
); // 19 port ?
148 outbit(0,io
); // 18 port ?
150 outbit(0,io
); // 17 search level
151 outbit(0,io
); // 16 search level
154 for(bl
= 1; bl
<= 16 ; bl
++) { outbit(data
& si
,io
); si
>>=1; }
159 static int get_stereo(__u16 io
)
161 outb(power
,io
); udelay(4);
162 return !(inb(io
) & mo_st
);
165 static int get_tune(__u16 io
)
167 outb(power
+clk
,io
); udelay(4);
168 return !(inb(io
) & mo_st
);
172 static inline int radio_function(struct inode
*inode
, struct file
*file
,
173 unsigned int cmd
, void *arg
)
175 struct video_device
*dev
= video_devdata(file
);
176 struct radio_device
*card
=dev
->priv
;
180 struct video_capability
*v
= arg
;
182 memset(v
,0,sizeof(*v
));
183 strcpy(v
->name
, "Maxi Radio FM2000 radio");
184 v
->type
=VID_TYPE_TUNER
;
185 v
->channels
=v
->audios
=1;
189 struct video_tuner
*v
= arg
;
194 card
->stereo
= 0xffff * get_stereo(card
->io
);
195 card
->tuned
= 0xffff * get_tune(card
->io
);
197 v
->flags
= VIDEO_TUNER_LOW
| card
->stereo
;
198 v
->signal
= card
->tuned
;
200 strcpy(v
->name
, "FM");
202 v
->rangelow
= FREQ_LO
;
203 v
->rangehigh
= FREQ_HI
;
204 v
->mode
= VIDEO_MODE_AUTO
;
209 struct video_tuner
*v
= arg
;
215 unsigned long *freq
= arg
;
221 unsigned long *freq
= arg
;
223 if (*freq
< FREQ_LO
|| *freq
> FREQ_HI
)
226 set_freq(card
->io
, FREQ2BITS(card
->freq
));
231 struct video_audio
*v
= arg
;
232 memset(v
,0,sizeof(*v
));
233 strcpy(v
->name
, "Radio");
234 v
->flags
=VIDEO_AUDIO_MUTABLE
| card
->muted
;
235 v
->mode
=VIDEO_SOUND_STEREO
;
240 struct video_audio
*v
= arg
;
244 card
->muted
= v
->flags
& VIDEO_AUDIO_MUTE
;
246 turn_power(card
->io
, 0);
248 set_freq(card
->io
, FREQ2BITS(card
->freq
));
252 struct video_unit
*v
= arg
;
254 v
->video
=VIDEO_NO_UNIT
;
255 v
->vbi
=VIDEO_NO_UNIT
;
258 v
->teletext
=VIDEO_NO_UNIT
;
261 default: return -ENOIOCTLCMD
;
265 static int radio_ioctl(struct inode
*inode
, struct file
*file
,
266 unsigned int cmd
, unsigned long arg
)
268 struct video_device
*dev
= video_devdata(file
);
269 struct radio_device
*card
=dev
->priv
;
272 mutex_lock(&card
->lock
);
273 ret
= video_usercopy(inode
, file
, cmd
, arg
, radio_function
);
274 mutex_unlock(&card
->lock
);
278 MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net");
279 MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000 radio.");
280 MODULE_LICENSE("GPL");
283 static int __devinit
maxiradio_init_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
285 if(!request_region(pci_resource_start(pdev
, 0),
286 pci_resource_len(pdev
, 0), "Maxi Radio FM 2000")) {
287 printk(KERN_ERR
"radio-maxiradio: can't reserve I/O ports\n");
291 if (pci_enable_device(pdev
))
292 goto err_out_free_region
;
294 radio_unit
.io
= pci_resource_start(pdev
, 0);
295 mutex_init(&radio_unit
.lock
);
296 maxiradio_radio
.priv
= &radio_unit
;
298 if(video_register_device(&maxiradio_radio
, VFL_TYPE_RADIO
, radio_nr
)==-1) {
299 printk("radio-maxiradio: can't register device!");
300 goto err_out_free_region
;
303 printk(KERN_INFO
"radio-maxiradio: version "
310 printk(KERN_INFO
"radio-maxiradio: found Guillemot MAXI Radio device (io = 0x%x)\n",
315 release_region(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
320 static void __devexit
maxiradio_remove_one(struct pci_dev
*pdev
)
322 video_unregister_device(&maxiradio_radio
);
323 release_region(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
326 static struct pci_device_id maxiradio_pci_tbl
[] = {
327 { PCI_VENDOR_ID_GUILLEMOT
, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO
,
328 PCI_ANY_ID
, PCI_ANY_ID
, },
332 MODULE_DEVICE_TABLE(pci
, maxiradio_pci_tbl
);
334 static struct pci_driver maxiradio_driver
= {
335 .name
= "radio-maxiradio",
336 .id_table
= maxiradio_pci_tbl
,
337 .probe
= maxiradio_init_one
,
338 .remove
= __devexit_p(maxiradio_remove_one
),
341 static int __init
maxiradio_radio_init(void)
343 return pci_register_driver(&maxiradio_driver
);
346 static void __exit
maxiradio_radio_exit(void)
348 pci_unregister_driver(&maxiradio_driver
);
351 module_init(maxiradio_radio_init
);
352 module_exit(maxiradio_radio_exit
);