1 /* RadioTrack II driver for Linux radio support (C) 1998 Ben Pfaff
3 * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
4 * Coverted 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> /* check_region, 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 <linux/config.h> /* CONFIG_RADIO_RTRACK2_PORT */
19 #include <linux/spinlock.h>
21 #ifndef CONFIG_RADIO_RTRACK2_PORT
22 #define CONFIG_RADIO_RTRACK2_PORT -1
25 static int io
= CONFIG_RADIO_RTRACK2_PORT
;
27 static spinlock_t lock
;
32 unsigned long curfreq
;
39 static void rt_mute(struct rt_device
*dev
)
49 static void rt_unmute(struct rt_device
*dev
)
59 static void zero(void)
73 static int rt_setfreq(struct rt_device
*dev
, unsigned long freq
)
77 freq
= freq
/ 200 + 856;
85 for (i
= 0; i
< 10; i
++)
88 for (i
= 14; i
>= 0; i
--)
102 static int rt_getsigstr(struct rt_device
*dev
)
104 if (inb(io
) & 2) /* bit set = no signal present */
106 return 1; /* signal present */
109 static int rt_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
111 struct rt_device
*rt
=dev
->priv
;
117 struct video_capability v
;
118 v
.type
=VID_TYPE_TUNER
;
121 /* No we don't do pictures */
126 strcpy(v
.name
, "RadioTrack II");
127 if(copy_to_user(arg
,&v
,sizeof(v
)))
133 struct video_tuner v
;
134 if(copy_from_user(&v
, arg
,sizeof(v
))!=0)
136 if(v
.tuner
) /* Only 1 tuner */
139 v
.rangehigh
=108*16000;
140 v
.flags
=VIDEO_TUNER_LOW
;
141 v
.mode
=VIDEO_MODE_AUTO
;
142 v
.signal
=0xFFFF*rt_getsigstr(rt
);
143 strcpy(v
.name
, "FM");
144 if(copy_to_user(arg
,&v
, sizeof(v
)))
150 struct video_tuner v
;
151 if(copy_from_user(&v
, arg
, sizeof(v
)))
155 /* Only 1 tuner so no setting needed ! */
159 if(copy_to_user(arg
, &rt
->curfreq
, sizeof(rt
->curfreq
)))
163 if(copy_from_user(&rt
->curfreq
, arg
,sizeof(rt
->curfreq
)))
165 rt_setfreq(rt
, rt
->curfreq
);
169 struct video_audio v
;
170 memset(&v
,0, sizeof(v
));
171 v
.flags
|=VIDEO_AUDIO_MUTABLE
;
174 strcpy(v
.name
, "Radio");
175 if(copy_to_user(arg
,&v
, sizeof(v
)))
181 struct video_audio v
;
182 if(copy_from_user(&v
, arg
, sizeof(v
)))
187 if(v
.flags
&VIDEO_AUDIO_MUTE
)
199 static int rt_open(struct video_device
*dev
, int flags
)
208 static void rt_close(struct video_device
*dev
)
214 static struct rt_device rtrack2_unit
;
216 static struct video_device rtrack2_radio
=
218 name
: "RadioTrack II radio",
219 type
: VID_TYPE_TUNER
,
220 hardware
: VID_HARDWARE_RTRACK2
,
226 static int __init
rtrack2_init(void)
230 printk(KERN_ERR
"You must set an I/O address with io=0x20c or io=0x30c\n");
233 if (request_region(io
, 4, "rtrack2"))
235 printk(KERN_ERR
"rtrack2: port 0x%x already in use\n", io
);
239 rtrack2_radio
.priv
=&rtrack2_unit
;
241 spin_lock_init(&lock
);
242 if(video_register_device(&rtrack2_radio
, VFL_TYPE_RADIO
)==-1)
244 release_region(io
, 4);
248 printk(KERN_INFO
"AIMSlab Radiotrack II card driver.\n");
250 /* mute card - prevents noisy bootups */
252 rtrack2_unit
.muted
= 1;
257 MODULE_AUTHOR("Ben Pfaff");
258 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
259 MODULE_PARM(io
, "i");
260 MODULE_PARM_DESC(io
, "I/O address of the RadioTrack card (0x20c or 0x30c)");
264 static void __exit
rtrack2_cleanup_module(void)
266 video_unregister_device(&rtrack2_radio
);
267 release_region(io
,4);
270 module_init(rtrack2_init
);
271 module_exit(rtrack2_cleanup_module
);
275 compile-command: "gcc -c -DMODVERSIONS -D__KERNEL__ -DMODULE -O6 -Wall -Wstrict-prototypes -I /home/blp/tmp/linux-2.1.111-rtrack/include radio-rtrack2.c"