1 /* RadioTrack II driver for Linux radio support (C) 1998 Ben Pfaff
3 * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
4 * Converted to new API by Alan Cox <Alan.Cox@linux.org>
5 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
7 * TODO: Allow for more than one of these foolish entities :-)
11 #include <linux/module.h> /* Modules */
12 #include <linux/init.h> /* Initdata */
13 #include <linux/ioport.h> /* request_region */
14 #include <linux/delay.h> /* udelay */
15 #include <asm/io.h> /* outb, outb_p */
16 #include <asm/uaccess.h> /* copy to/from user */
17 #include <linux/videodev.h> /* kernel radio structs */
18 #include <media/v4l2-common.h>
19 #include <linux/config.h> /* CONFIG_RADIO_RTRACK2_PORT */
20 #include <linux/spinlock.h>
22 #ifndef CONFIG_RADIO_RTRACK2_PORT
23 #define CONFIG_RADIO_RTRACK2_PORT -1
26 static int io
= CONFIG_RADIO_RTRACK2_PORT
;
27 static int radio_nr
= -1;
28 static spinlock_t lock
;
33 unsigned long curfreq
;
40 static void rt_mute(struct rt_device
*dev
)
50 static void rt_unmute(struct rt_device
*dev
)
60 static void zero(void)
74 static int rt_setfreq(struct rt_device
*dev
, unsigned long freq
)
78 freq
= freq
/ 200 + 856;
86 for (i
= 0; i
< 10; i
++)
89 for (i
= 14; i
>= 0; i
--)
103 static int rt_getsigstr(struct rt_device
*dev
)
105 if (inb(io
) & 2) /* bit set = no signal present */
107 return 1; /* signal present */
110 static int rt_do_ioctl(struct inode
*inode
, struct file
*file
,
111 unsigned int cmd
, void *arg
)
113 struct video_device
*dev
= video_devdata(file
);
114 struct rt_device
*rt
=dev
->priv
;
120 struct video_capability
*v
= arg
;
121 memset(v
,0,sizeof(*v
));
122 v
->type
=VID_TYPE_TUNER
;
125 strcpy(v
->name
, "RadioTrack II");
130 struct video_tuner
*v
= arg
;
131 if(v
->tuner
) /* Only 1 tuner */
133 v
->rangelow
=88*16000;
134 v
->rangehigh
=108*16000;
135 v
->flags
=VIDEO_TUNER_LOW
;
136 v
->mode
=VIDEO_MODE_AUTO
;
137 v
->signal
=0xFFFF*rt_getsigstr(rt
);
138 strcpy(v
->name
, "FM");
143 struct video_tuner
*v
= arg
;
146 /* Only 1 tuner so no setting needed ! */
151 unsigned long *freq
= arg
;
157 unsigned long *freq
= arg
;
159 rt_setfreq(rt
, rt
->curfreq
);
164 struct video_audio
*v
= arg
;
165 memset(v
,0, sizeof(*v
));
166 v
->flags
|=VIDEO_AUDIO_MUTABLE
;
169 strcpy(v
->name
, "Radio");
174 struct video_audio
*v
= arg
;
178 if(v
->flags
&VIDEO_AUDIO_MUTE
)
190 static int rt_ioctl(struct inode
*inode
, struct file
*file
,
191 unsigned int cmd
, unsigned long arg
)
193 return video_usercopy(inode
, file
, cmd
, arg
, rt_do_ioctl
);
196 static struct rt_device rtrack2_unit
;
198 static struct file_operations rtrack2_fops
= {
199 .owner
= THIS_MODULE
,
200 .open
= video_exclusive_open
,
201 .release
= video_exclusive_release
,
203 .compat_ioctl
= v4l_compat_ioctl32
,
207 static struct video_device rtrack2_radio
=
209 .owner
= THIS_MODULE
,
210 .name
= "RadioTrack II radio",
211 .type
= VID_TYPE_TUNER
,
212 .hardware
= VID_HARDWARE_RTRACK2
,
213 .fops
= &rtrack2_fops
,
216 static int __init
rtrack2_init(void)
220 printk(KERN_ERR
"You must set an I/O address with io=0x20c or io=0x30c\n");
223 if (!request_region(io
, 4, "rtrack2"))
225 printk(KERN_ERR
"rtrack2: port 0x%x already in use\n", io
);
229 rtrack2_radio
.priv
=&rtrack2_unit
;
231 spin_lock_init(&lock
);
232 if(video_register_device(&rtrack2_radio
, VFL_TYPE_RADIO
, radio_nr
)==-1)
234 release_region(io
, 4);
238 printk(KERN_INFO
"AIMSlab Radiotrack II card driver.\n");
240 /* mute card - prevents noisy bootups */
242 rtrack2_unit
.muted
= 1;
247 MODULE_AUTHOR("Ben Pfaff");
248 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
249 MODULE_LICENSE("GPL");
251 module_param(io
, int, 0);
252 MODULE_PARM_DESC(io
, "I/O address of the RadioTrack card (0x20c or 0x30c)");
253 module_param(radio_nr
, int, 0);
255 static void __exit
rtrack2_cleanup_module(void)
257 video_unregister_device(&rtrack2_radio
);
258 release_region(io
,4);
261 module_init(rtrack2_init
);
262 module_exit(rtrack2_cleanup_module
);
266 compile-command: "mmake"