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 <asm/semaphore.h>
41 #include <linux/pci.h>
42 #include <linux/videodev.h>
44 /* version 0.75 Sun Feb 4 22:51:27 EET 2001 */
45 #define DRIVER_VERSION "0.75"
47 #ifndef PCI_VENDOR_ID_GUILLEMOT
48 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
51 #ifndef PCI_DEVICE_ID_GUILLEMOT
52 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
56 /* TEA5757 pin mappings */
57 const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16 ;
59 static int radio_nr = -1;
60 MODULE_PARM(radio_nr, "i");
63 #define FREQ_LO 50*16000
64 #define FREQ_HI 150*16000
66 #define FREQ_IF 171200 /* 10.7*16000 */
67 #define FREQ_STEP 200 /* 12.5*16 */
69 #define FREQ2BITS(x) ((( (unsigned int)(x)+FREQ_IF+(FREQ_STEP<<1))\
70 /(FREQ_STEP<<2))<<2) /* (x==fmhz*16*1000) -> bits */
72 #define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF)
75 static int radio_open(struct video_device *, int);
76 static int radio_ioctl(struct video_device *, unsigned int, void *);
77 static void radio_close(struct video_device *);
79 static struct video_device maxiradio_radio=
82 name: "Maxi Radio FM2000 radio",
84 hardware: VID_HARDWARE_SF16MI,
90 static struct radio_device
92 __u16 io, /* base of radio io */
93 muted, /* VIDEO_AUDIO_MUTE */
94 stereo, /* VIDEO_TUNER_STEREO_ON */
95 tuned; /* signal strength (0 or 0xffff) */
99 struct semaphore lock;
100 } radio_unit = {0, 0, 0, 0, };
103 static void sleep_125ms(void)
105 current->state = TASK_INTERRUPTIBLE;
106 schedule_timeout(HZ >> 3);
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 inline static int radio_function(struct video_device *dev,
173 unsigned int cmd, void *arg)
175 struct radio_device *card=dev->priv;
178 struct video_capability v;
180 strcpy(v.name, "Maxi Radio FM2000 radio");
181 v.type=VID_TYPE_TUNER;
182 v.channels=v.audios=1;
183 v.maxwidth=v.maxheight=v.minwidth=v.minheight=0;
185 if(copy_to_user(arg,&v,sizeof(v)))
191 struct video_tuner v;
193 if(copy_from_user(&v, arg,sizeof(v))!=0)
199 card->stereo = 0xffff * get_stereo(card->io);
200 card->tuned = 0xffff * get_tune(card->io);
202 v.flags = VIDEO_TUNER_LOW | card->stereo;
203 v.signal = card->tuned;
205 strcpy(v.name, "FM");
207 v.rangelow = FREQ_LO;
208 v.rangehigh = FREQ_HI;
209 v.mode = VIDEO_MODE_AUTO;
211 if(copy_to_user(arg,&v, sizeof(v)))
217 struct video_tuner v;
219 if(copy_from_user(&v, arg, sizeof(v)))
228 unsigned long tmp=card->freq;
230 if(copy_to_user(arg, &tmp, sizeof(tmp)))
239 if(copy_from_user(&tmp, arg, sizeof(tmp)))
242 if ( tmp<FREQ_LO || tmp>FREQ_HI )
247 set_freq(card->io, FREQ2BITS(card->freq));
253 struct video_audio v;
254 strcpy(v.name, "Radio");
255 v.audio=v.volume=v.bass=v.treble=v.balance=v.step=0;
256 v.flags=VIDEO_AUDIO_MUTABLE | card->muted;
257 v.mode=VIDEO_SOUND_STEREO;
258 if(copy_to_user(arg,&v, sizeof(v)))
264 struct video_audio v;
266 if(copy_from_user(&v, arg, sizeof(v)))
273 card->muted = v.flags & VIDEO_AUDIO_MUTE;
276 turn_power(card->io, 0);
278 set_freq(card->io, FREQ2BITS(card->freq));
285 v.video=VIDEO_NO_UNIT;
289 v.teletext=VIDEO_NO_UNIT;
290 if(copy_to_user(arg, &v, sizeof(v)))
294 default: return -ENOIOCTLCMD;
298 static int radio_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
300 struct radio_device *card=dev->priv;
303 ret = radio_function(dev, cmd, arg);
308 static int radio_open(struct video_device *dev, int flags)
313 static void radio_close(struct video_device *dev)
317 MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net");
318 MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000 radio.");
319 MODULE_LICENSE("GPL");
324 static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
326 if(!request_region(pci_resource_start(pdev, 0),
327 pci_resource_len(pdev, 0), "Maxi Radio FM 2000")) {
328 printk(KERN_ERR "radio-maxiradio: can't reserve I/O ports\n");
332 if (pci_enable_device(pdev))
333 goto err_out_free_region;
335 radio_unit.io = pci_resource_start(pdev, 0);
336 init_MUTEX(&radio_unit.lock);
337 maxiradio_radio.priv = &radio_unit;
339 if(video_register_device(&maxiradio_radio, VFL_TYPE_RADIO, radio_nr)==-1) {
340 printk("radio-maxiradio: can't register device!");
341 goto err_out_free_region;
344 printk(KERN_INFO "radio-maxiradio: version "
351 printk(KERN_INFO "radio-maxiradio: found Guillemot MAXI Radio device (io = 0x%x)\n",
356 release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
361 static void __devexit maxiradio_remove_one(struct pci_dev *pdev)
363 video_unregister_device(&maxiradio_radio);
364 release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
367 static struct pci_device_id maxiradio_pci_tbl[] __devinitdata = {
368 { PCI_VENDOR_ID_GUILLEMOT, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO,
369 PCI_ANY_ID, PCI_ANY_ID, },
373 MODULE_DEVICE_TABLE(pci, maxiradio_pci_tbl);
375 static struct pci_driver maxiradio_driver = {
376 name: "radio-maxiradio",
377 id_table: maxiradio_pci_tbl,
378 probe: maxiradio_init_one,
379 remove: __devexit_p(maxiradio_remove_one),
382 int __init maxiradio_radio_init(void)
384 return pci_module_init(&maxiradio_driver);
387 void __exit maxiradio_radio_exit(void)
389 pci_unregister_driver(&maxiradio_driver);
392 module_init(maxiradio_radio_init);
393 module_exit(maxiradio_radio_exit);