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>
45 /* version 0.75 Sun Feb 4 22:51:27 EET 2001 */
46 #define DRIVER_VERSION "0.75"
48 #ifndef PCI_VENDOR_ID_GUILLEMOT
49 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
52 #ifndef PCI_DEVICE_ID_GUILLEMOT
53 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
57 /* TEA5757 pin mappings */
58 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16 ;
60 static int radio_nr = -1;
61 module_param(radio_nr, int, 0);
64 #define FREQ_LO 50*16000
65 #define FREQ_HI 150*16000
67 #define FREQ_IF 171200 /* 10.7*16000 */
68 #define FREQ_STEP 200 /* 12.5*16 */
70 #define FREQ2BITS(x) ((( (unsigned int)(x)+FREQ_IF+(FREQ_STEP<<1))\
71 /(FREQ_STEP<<2))<<2) /* (x==fmhz*16*1000) -> bits */
73 #define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF)
76 static int radio_ioctl(struct inode *inode, struct file *file,
77 unsigned int cmd, unsigned long arg);
79 static struct file_operations maxiradio_fops = {
81 .open = video_exclusive_open,
82 .release = video_exclusive_release,
84 .compat_ioctl = v4l_compat_ioctl32,
87 static struct video_device maxiradio_radio =
90 .name = "Maxi Radio FM2000 radio",
91 .type = VID_TYPE_TUNER,
92 .hardware = VID_HARDWARE_SF16MI,
93 .fops = &maxiradio_fops,
96 static struct radio_device
98 __u16 io, /* base of radio io */
99 muted, /* VIDEO_AUDIO_MUTE */
100 stereo, /* VIDEO_TUNER_STEREO_ON */
101 tuned; /* signal strength (0 or 0xffff) */
106 } radio_unit = {0, 0, 0, 0, };
109 static void outbit(unsigned long bit, __u16 io)
113 outb( power|wren|data ,io); udelay(4);
114 outb( power|wren|data|clk ,io); udelay(4);
115 outb( power|wren|data ,io); udelay(4);
119 outb( power|wren ,io); udelay(4);
120 outb( power|wren|clk ,io); udelay(4);
121 outb( power|wren ,io); udelay(4);
125 static void turn_power(__u16 io, int p)
127 if(p != 0) outb(power, io); else outb(0,io);
131 static void set_freq(__u16 io, __u32 data)
133 unsigned long int si;
136 /* TEA5757 shift register bits (see pdf) */
138 outbit(0,io); // 24 search
139 outbit(1,io); // 23 search up/down
141 outbit(0,io); // 22 stereo/mono
143 outbit(0,io); // 21 band
144 outbit(0,io); // 20 band (only 00=FM works I think)
146 outbit(0,io); // 19 port ?
147 outbit(0,io); // 18 port ?
149 outbit(0,io); // 17 search level
150 outbit(0,io); // 16 search level
153 for(bl = 1; bl <= 16 ; bl++) { outbit(data & si,io); si >>=1; }
158 static int get_stereo(__u16 io)
160 outb(power,io); udelay(4);
161 return !(inb(io) & mo_st);
164 static int get_tune(__u16 io)
166 outb(power+clk,io); udelay(4);
167 return !(inb(io) & mo_st);
171 static inline int radio_function(struct inode *inode, struct file *file,
172 unsigned int cmd, void *arg)
174 struct video_device *dev = video_devdata(file);
175 struct radio_device *card=dev->priv;
179 struct video_capability *v = arg;
181 memset(v,0,sizeof(*v));
182 strcpy(v->name, "Maxi Radio FM2000 radio");
183 v->type=VID_TYPE_TUNER;
184 v->channels=v->audios=1;
188 struct video_tuner *v = arg;
193 card->stereo = 0xffff * get_stereo(card->io);
194 card->tuned = 0xffff * get_tune(card->io);
196 v->flags = VIDEO_TUNER_LOW | card->stereo;
197 v->signal = card->tuned;
199 strcpy(v->name, "FM");
201 v->rangelow = FREQ_LO;
202 v->rangehigh = FREQ_HI;
203 v->mode = VIDEO_MODE_AUTO;
208 struct video_tuner *v = arg;
214 unsigned long *freq = arg;
220 unsigned long *freq = arg;
222 if (*freq < FREQ_LO || *freq > FREQ_HI)
225 set_freq(card->io, FREQ2BITS(card->freq));
230 struct video_audio *v = arg;
231 memset(v,0,sizeof(*v));
232 strcpy(v->name, "Radio");
233 v->flags=VIDEO_AUDIO_MUTABLE | card->muted;
234 v->mode=VIDEO_SOUND_STEREO;
239 struct video_audio *v = arg;
243 card->muted = v->flags & VIDEO_AUDIO_MUTE;
245 turn_power(card->io, 0);
247 set_freq(card->io, FREQ2BITS(card->freq));
251 struct video_unit *v = arg;
253 v->video=VIDEO_NO_UNIT;
254 v->vbi=VIDEO_NO_UNIT;
257 v->teletext=VIDEO_NO_UNIT;
260 default: return -ENOIOCTLCMD;
264 static int radio_ioctl(struct inode *inode, struct file *file,
265 unsigned int cmd, unsigned long arg)
267 struct video_device *dev = video_devdata(file);
268 struct radio_device *card=dev->priv;
271 mutex_lock(&card->lock);
272 ret = video_usercopy(inode, file, cmd, arg, radio_function);
273 mutex_unlock(&card->lock);
277 MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net");
278 MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000 radio.");
279 MODULE_LICENSE("GPL");
282 static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
284 if(!request_region(pci_resource_start(pdev, 0),
285 pci_resource_len(pdev, 0), "Maxi Radio FM 2000")) {
286 printk(KERN_ERR "radio-maxiradio: can't reserve I/O ports\n");
290 if (pci_enable_device(pdev))
291 goto err_out_free_region;
293 radio_unit.io = pci_resource_start(pdev, 0);
294 mutex_init(&radio_unit.lock);
295 maxiradio_radio.priv = &radio_unit;
297 if(video_register_device(&maxiradio_radio, VFL_TYPE_RADIO, radio_nr)==-1) {
298 printk("radio-maxiradio: can't register device!");
299 goto err_out_free_region;
302 printk(KERN_INFO "radio-maxiradio: version "
309 printk(KERN_INFO "radio-maxiradio: found Guillemot MAXI Radio device (io = 0x%x)\n",
314 release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
319 static void __devexit maxiradio_remove_one(struct pci_dev *pdev)
321 video_unregister_device(&maxiradio_radio);
322 release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
325 static struct pci_device_id maxiradio_pci_tbl[] = {
326 { PCI_VENDOR_ID_GUILLEMOT, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO,
327 PCI_ANY_ID, PCI_ANY_ID, },
331 MODULE_DEVICE_TABLE(pci, maxiradio_pci_tbl);
333 static struct pci_driver maxiradio_driver = {
334 .name = "radio-maxiradio",
335 .id_table = maxiradio_pci_tbl,
336 .probe = maxiradio_init_one,
337 .remove = __devexit_p(maxiradio_remove_one),
340 static int __init maxiradio_radio_init(void)
342 return pci_register_driver(&maxiradio_driver);
345 static void __exit maxiradio_radio_exit(void)
347 pci_unregister_driver(&maxiradio_driver);
350 module_init(maxiradio_radio_init);
351 module_exit(maxiradio_radio_exit);