1 /* radiotrack (radioreveal) driver for Linux radio support
3 * Coverted to new API by Alan Cox <Alan.Cox@linux.org>
4 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
6 * TODO: Allow for more than one of these foolish entities :-)
8 * Notes on the hardware (reverse engineered from other peoples'
9 * reverse engineering of AIMS' code :-)
11 * Frequency control is done digitally -- ie out(port,encodefreq(95.8));
13 * The signal strength query is unsurprisingly inaccurate. And it seems
14 * to indicate that (on my card, at least) the frequency setting isn't
15 * too great. (I have to tune up .025MHz from what the freq should be
16 * to get a report that the thing is tuned.)
18 * Volume control is (ugh) analogue:
19 * out(port, start_increasing_volume);
21 * out(port, stop_changing_the_volume);
25 #include <linux/module.h> /* Modules */
26 #include <linux/init.h> /* Initdata */
27 #include <linux/ioport.h> /* check_region, request_region */
28 #include <linux/delay.h> /* udelay */
29 #include <asm/io.h> /* outb, outb_p */
30 #include <asm/uaccess.h> /* copy to/from user */
31 #include <linux/videodev.h> /* kernel radio structs */
32 #include <linux/config.h> /* CONFIG_RADIO_RTRACK_PORT */
34 #ifndef CONFIG_RADIO_RTRACK_PORT
35 #define CONFIG_RADIO_RTRACK_PORT -1
38 static int io
= CONFIG_RADIO_RTRACK_PORT
;
45 unsigned long curfreq
;
52 static void sleep_delay(long n
)
54 /* Sleep nicely for 'n' uS */
61 unsigned long x
=jiffies
;
67 static void rt_decvol(void)
69 outb(0x58, io
); /* volume down + sigstr + on */
71 outb(0xd8, io
); /* volume steady + sigstr + on */
74 static void rt_incvol(void)
76 outb(0x98, io
); /* volume up + sigstr + on */
78 outb(0xd8, io
); /* volume steady + sigstr + on */
81 static void rt_mute(struct rt_device
*dev
)
84 outb(0xd0, io
); /* volume steady, off */
87 static int rt_setvol(struct rt_device
*dev
, int vol
)
91 if(vol
== dev
->curvol
) { /* requested volume = current */
92 if (dev
->muted
) { /* user is unmuting the card */
94 outb (0xd8, io
); /* enable card */
100 if(vol
== 0) { /* volume = 0 means mute the card */
101 outb(0x48, io
); /* volume down but still "on" */
102 sleep_delay(2000000); /* make sure it's totally down */
103 outb(0xd0, io
); /* volume steady, off */
108 if(vol
> dev
->curvol
)
109 for(i
= dev
->curvol
; i
< vol
; i
++)
112 for(i
= dev
->curvol
; i
> vol
; i
--)
120 /* the 128+64 on these outb's is to keep the volume stable while tuning
121 * without them, the volume _will_ creep up with each frequency change
122 * and bit 4 (+16) is to keep the signal strength meter enabled
125 void send_0_byte(int port
, struct rt_device
*dev
)
127 if ((dev
->curvol
== 0) || (dev
->muted
)) {
128 outb_p(128+64+16+ 1, port
); /* wr-enable + data low */
129 outb_p(128+64+16+2+1, port
); /* clock */
132 outb_p(128+64+16+8+ 1, port
); /* on + wr-enable + data low */
133 outb_p(128+64+16+8+2+1, port
); /* clock */
138 void send_1_byte(int port
, struct rt_device
*dev
)
140 if ((dev
->curvol
== 0) || (dev
->muted
)) {
141 outb_p(128+64+16+4 +1, port
); /* wr-enable+data high */
142 outb_p(128+64+16+4+2+1, port
); /* clock */
145 outb_p(128+64+16+8+4 +1, port
); /* on+wr-enable+data high */
146 outb_p(128+64+16+8+4+2+1, port
); /* clock */
152 static int rt_setfreq(struct rt_device
*dev
, unsigned long freq
)
156 /* adapted from radio-aztech.c */
158 /* We want to compute x * 100 / 16 without overflow
159 * So we compute x*6 + (x/100)*25 to give x*6.25
162 freq
= freq
* 6 + freq
/4; /* massage the data a little */
163 freq
+= 1070; /* IF = 10.7 MHz */
164 freq
/= 5; /* ref = 25 kHz */
166 send_0_byte (io
, dev
); /* 0: LSB of frequency */
168 for (i
= 0; i
< 13; i
++) /* : frequency bits (1-13) */
170 send_1_byte (io
, dev
);
172 send_0_byte (io
, dev
);
174 send_0_byte (io
, dev
); /* 14: test bit - always 0 */
175 send_0_byte (io
, dev
); /* 15: test bit - always 0 */
177 send_0_byte (io
, dev
); /* 16: band data 0 - always 0 */
178 send_0_byte (io
, dev
); /* 17: band data 1 - always 0 */
179 send_0_byte (io
, dev
); /* 18: band data 2 - always 0 */
180 send_0_byte (io
, dev
); /* 19: time base - always 0 */
182 send_0_byte (io
, dev
); /* 20: spacing (0 = 25 kHz) */
183 send_1_byte (io
, dev
); /* 21: spacing (1 = 25 kHz) */
184 send_0_byte (io
, dev
); /* 22: spacing (0 = 25 kHz) */
185 send_1_byte (io
, dev
); /* 23: AM/FM (FM = 1, always) */
187 if ((dev
->curvol
== 0) || (dev
->muted
))
188 outb (0xd0, io
); /* volume steady + sigstr */
190 outb (0xd8, io
); /* volume steady + sigstr + on */
195 int rt_getsigstr(struct rt_device
*dev
)
197 if (inb(io
) & 2) /* bit set = no signal present */
199 return 1; /* signal present */
202 static int rt_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
204 struct rt_device
*rt
=dev
->priv
;
210 struct video_capability v
;
211 v
.type
=VID_TYPE_TUNER
;
214 /* No we don't do pictures */
219 strcpy(v
.name
, "RadioTrack");
220 if(copy_to_user(arg
,&v
,sizeof(v
)))
226 struct video_tuner v
;
227 if(copy_from_user(&v
, arg
,sizeof(v
))!=0)
229 if(v
.tuner
) /* Only 1 tuner */
232 v
.rangehigh
=(108*16);
234 v
.mode
=VIDEO_MODE_AUTO
;
235 v
.signal
=0xFFFF*rt_getsigstr(rt
);
236 if(copy_to_user(arg
,&v
, sizeof(v
)))
242 struct video_tuner v
;
243 if(copy_from_user(&v
, arg
, sizeof(v
)))
247 /* Only 1 tuner so no setting needed ! */
251 if(copy_to_user(arg
, &rt
->curfreq
, sizeof(rt
->curfreq
)))
255 if(copy_from_user(&rt
->curfreq
, arg
,sizeof(rt
->curfreq
)))
257 rt_setfreq(rt
, rt
->curfreq
);
261 struct video_audio v
;
262 memset(&v
,0, sizeof(v
));
263 v
.flags
|=VIDEO_AUDIO_MUTABLE
|VIDEO_AUDIO_VOLUME
;
264 v
.volume
=rt
->curvol
* 6554;
266 strcpy(v
.name
, "Radio");
267 if(copy_to_user(arg
,&v
, sizeof(v
)))
273 struct video_audio v
;
274 if(copy_from_user(&v
, arg
, sizeof(v
)))
279 if(v
.flags
&VIDEO_AUDIO_MUTE
)
282 rt_setvol(rt
,v
.volume
/6554);
291 static int rt_open(struct video_device
*dev
, int flags
)
300 static void rt_close(struct video_device
*dev
)
306 static struct rt_device rtrack_unit
;
308 static struct video_device rtrack_radio
=
315 NULL
, /* Can't read (no capture ability) */
316 NULL
, /* Can't write */
323 __initfunc(int rtrack_init(struct video_init
*v
))
325 if (check_region(io
, 2))
327 printk(KERN_ERR
"rtrack: port 0x%x already in use\n", io
);
331 rtrack_radio
.priv
=&rtrack_unit
;
333 if(video_register_device(&rtrack_radio
, VFL_TYPE_RADIO
)==-1)
336 request_region(io
, 2, "rtrack");
337 printk(KERN_INFO
"AIMSlab Radiotrack/radioreveal card driver.\n");
339 /* mute card - prevents noisy bootups */
341 /* this ensures that the volume is all the way down */
342 outb(0x48, io
); /* volume down but still "on" */
343 sleep_delay(2000000); /* make sure it's totally down */
344 outb(0xc0, io
); /* steady volume, mute card */
345 rtrack_unit
.curvol
= 0;
352 MODULE_AUTHOR("M.Kirkwood");
353 MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
354 MODULE_PARM(io
, "i");
355 MODULE_PARM_DESC(io
, "I/O address of the RadioTrack card (0x20f or 0x30f)");
359 int init_module(void)
363 printk(KERN_ERR
"You must set an I/O address with io=0x???\n");
366 return rtrack_init(NULL
);
369 void cleanup_module(void)
371 video_unregister_device(&rtrack_radio
);
372 release_region(io
,2);