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 */
20 #ifndef CONFIG_RADIO_RTRACK2_PORT
21 #define CONFIG_RADIO_RTRACK2_PORT -1
24 static int io
= CONFIG_RADIO_RTRACK2_PORT
;
30 unsigned long curfreq
;
37 static void rt_mute(struct rt_device
*dev
)
45 static void rt_unmute(struct rt_device
*dev
)
53 static void zero(void)
67 static int rt_setfreq(struct rt_device
*dev
, unsigned long freq
)
71 freq
= freq
/ 200 + 856;
77 for (i
= 0; i
< 10; i
++)
80 for (i
= 14; i
>= 0; i
--)
92 int rt_getsigstr(struct rt_device
*dev
)
94 if (inb(io
) & 2) /* bit set = no signal present */
96 return 1; /* signal present */
99 static int rt_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
101 struct rt_device
*rt
=dev
->priv
;
107 struct video_capability v
;
108 v
.type
=VID_TYPE_TUNER
;
111 /* No we don't do pictures */
116 strcpy(v
.name
, "RadioTrack II");
117 if(copy_to_user(arg
,&v
,sizeof(v
)))
123 struct video_tuner v
;
124 if(copy_from_user(&v
, arg
,sizeof(v
))!=0)
126 if(v
.tuner
) /* Only 1 tuner */
129 v
.rangehigh
=108*16000;
130 v
.flags
=VIDEO_TUNER_LOW
;
131 v
.mode
=VIDEO_MODE_AUTO
;
132 v
.signal
=0xFFFF*rt_getsigstr(rt
);
133 strcpy(v
.name
, "FM");
134 if(copy_to_user(arg
,&v
, sizeof(v
)))
140 struct video_tuner v
;
141 if(copy_from_user(&v
, arg
, sizeof(v
)))
145 /* Only 1 tuner so no setting needed ! */
149 if(copy_to_user(arg
, &rt
->curfreq
, sizeof(rt
->curfreq
)))
153 if(copy_from_user(&rt
->curfreq
, arg
,sizeof(rt
->curfreq
)))
155 rt_setfreq(rt
, rt
->curfreq
);
159 struct video_audio v
;
160 memset(&v
,0, sizeof(v
));
161 v
.flags
|=VIDEO_AUDIO_MUTABLE
;
164 strcpy(v
.name
, "Radio");
165 if(copy_to_user(arg
,&v
, sizeof(v
)))
171 struct video_audio v
;
172 if(copy_from_user(&v
, arg
, sizeof(v
)))
177 if(v
.flags
&VIDEO_AUDIO_MUTE
)
189 static int rt_open(struct video_device
*dev
, int flags
)
198 static void rt_close(struct video_device
*dev
)
204 static struct rt_device rtrack2_unit
;
206 static struct video_device rtrack2_radio
=
208 "RadioTrack II radio",
210 VID_HARDWARE_RTRACK2
,
213 NULL
, /* Can't read (no capture ability) */
214 NULL
, /* Can't write */
215 NULL
, /* Can't poll */
221 __initfunc(int rtrack2_init(struct video_init
*v
))
223 if (check_region(io
, 4))
225 printk(KERN_ERR
"rtrack2: port 0x%x already in use\n", io
);
229 rtrack2_radio
.priv
=&rtrack2_unit
;
231 if(video_register_device(&rtrack2_radio
, VFL_TYPE_RADIO
)==-1)
234 request_region(io
, 4, "rtrack2");
235 printk(KERN_INFO
"AIMSlab Radiotrack II card driver.\n");
237 /* mute card - prevents noisy bootups */
239 rtrack2_unit
.muted
= 1;
246 MODULE_AUTHOR("Ben Pfaff");
247 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
248 MODULE_PARM(io
, "i");
249 MODULE_PARM_DESC(io
, "I/O address of the RadioTrack card (0x20c or 0x30c)");
253 int init_module(void)
257 printk(KERN_ERR
"You must set an I/O address with io=0x20c or io=0x30c\n");
260 return rtrack2_init(NULL
);
263 void cleanup_module(void)
265 video_unregister_device(&rtrack2_radio
);
266 release_region(io
,4);
273 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"