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>
7 * 1999-02-24 Russell Kroll <rkroll@exploits.org>
8 * Fine tuning/VIDEO_TUNER_LOW
9 * Frequency range expanded to start at 87 MHz
11 * TODO: Allow for more than one of these foolish entities :-)
13 * Notes on the hardware (reverse engineered from other peoples'
14 * reverse engineering of AIMS' code :-)
16 * Frequency control is done digitally -- ie out(port,encodefreq(95.8));
18 * The signal strength query is unsurprisingly inaccurate. And it seems
19 * to indicate that (on my card, at least) the frequency setting isn't
20 * too great. (I have to tune up .025MHz from what the freq should be
21 * to get a report that the thing is tuned.)
23 * Volume control is (ugh) analogue:
24 * out(port, start_increasing_volume);
26 * out(port, stop_changing_the_volume);
30 #include <linux/module.h> /* Modules */
31 #include <linux/init.h> /* Initdata */
32 #include <linux/ioport.h> /* check_region, request_region */
33 #include <linux/delay.h> /* udelay */
34 #include <asm/io.h> /* outb, outb_p */
35 #include <asm/uaccess.h> /* copy to/from user */
36 #include <linux/videodev.h> /* kernel radio structs */
37 #include <linux/config.h> /* CONFIG_RADIO_RTRACK_PORT */
39 #ifndef CONFIG_RADIO_RTRACK_PORT
40 #define CONFIG_RADIO_RTRACK_PORT -1
43 static int io
= CONFIG_RADIO_RTRACK_PORT
;
50 unsigned long curfreq
;
57 static void sleep_delay(long n
)
59 /* Sleep nicely for 'n' uS */
66 unsigned long x
=jiffies
;
72 static void rt_decvol(void)
74 outb(0x58, io
); /* volume down + sigstr + on */
76 outb(0xd8, io
); /* volume steady + sigstr + on */
79 static void rt_incvol(void)
81 outb(0x98, io
); /* volume up + sigstr + on */
83 outb(0xd8, io
); /* volume steady + sigstr + on */
86 static void rt_mute(struct rt_device
*dev
)
89 outb(0xd0, io
); /* volume steady, off */
92 static int rt_setvol(struct rt_device
*dev
, int vol
)
96 if(vol
== dev
->curvol
) { /* requested volume = current */
97 if (dev
->muted
) { /* user is unmuting the card */
99 outb (0xd8, io
); /* enable card */
105 if(vol
== 0) { /* volume = 0 means mute the card */
106 outb(0x48, io
); /* volume down but still "on" */
107 sleep_delay(2000000); /* make sure it's totally down */
108 outb(0xd0, io
); /* volume steady, off */
109 dev
->curvol
= 0; /* track the volume state! */
114 if(vol
> dev
->curvol
)
115 for(i
= dev
->curvol
; i
< vol
; i
++)
118 for(i
= dev
->curvol
; i
> vol
; i
--)
126 /* the 128+64 on these outb's is to keep the volume stable while tuning
127 * without them, the volume _will_ creep up with each frequency change
128 * and bit 4 (+16) is to keep the signal strength meter enabled
131 void send_0_byte(int port
, struct rt_device
*dev
)
133 if ((dev
->curvol
== 0) || (dev
->muted
)) {
134 outb_p(128+64+16+ 1, port
); /* wr-enable + data low */
135 outb_p(128+64+16+2+1, port
); /* clock */
138 outb_p(128+64+16+8+ 1, port
); /* on + wr-enable + data low */
139 outb_p(128+64+16+8+2+1, port
); /* clock */
144 void send_1_byte(int port
, struct rt_device
*dev
)
146 if ((dev
->curvol
== 0) || (dev
->muted
)) {
147 outb_p(128+64+16+4 +1, port
); /* wr-enable+data high */
148 outb_p(128+64+16+4+2+1, port
); /* clock */
151 outb_p(128+64+16+8+4 +1, port
); /* on+wr-enable+data high */
152 outb_p(128+64+16+8+4+2+1, port
); /* clock */
158 static int rt_setfreq(struct rt_device
*dev
, unsigned long freq
)
162 /* adapted from radio-aztech.c */
164 /* now uses VIDEO_TUNER_LOW for fine tuning */
166 freq
+= 171200; /* Add 10.7 MHz IF */
167 freq
/= 800; /* Convert to 50 kHz units */
169 send_0_byte (io
, dev
); /* 0: LSB of frequency */
171 for (i
= 0; i
< 13; i
++) /* : frequency bits (1-13) */
173 send_1_byte (io
, dev
);
175 send_0_byte (io
, dev
);
177 send_0_byte (io
, dev
); /* 14: test bit - always 0 */
178 send_0_byte (io
, dev
); /* 15: test bit - always 0 */
180 send_0_byte (io
, dev
); /* 16: band data 0 - always 0 */
181 send_0_byte (io
, dev
); /* 17: band data 1 - always 0 */
182 send_0_byte (io
, dev
); /* 18: band data 2 - always 0 */
183 send_0_byte (io
, dev
); /* 19: time base - always 0 */
185 send_0_byte (io
, dev
); /* 20: spacing (0 = 25 kHz) */
186 send_1_byte (io
, dev
); /* 21: spacing (1 = 25 kHz) */
187 send_0_byte (io
, dev
); /* 22: spacing (0 = 25 kHz) */
188 send_1_byte (io
, dev
); /* 23: AM/FM (FM = 1, always) */
190 if ((dev
->curvol
== 0) || (dev
->muted
))
191 outb (0xd0, io
); /* volume steady + sigstr */
193 outb (0xd8, io
); /* volume steady + sigstr + on */
198 int rt_getsigstr(struct rt_device
*dev
)
200 if (inb(io
) & 2) /* bit set = no signal present */
202 return 1; /* signal present */
205 static int rt_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
207 struct rt_device
*rt
=dev
->priv
;
213 struct video_capability v
;
214 v
.type
=VID_TYPE_TUNER
;
217 /* No we don't do pictures */
222 strcpy(v
.name
, "RadioTrack");
223 if(copy_to_user(arg
,&v
,sizeof(v
)))
229 struct video_tuner v
;
230 if(copy_from_user(&v
, arg
,sizeof(v
))!=0)
232 if(v
.tuner
) /* Only 1 tuner */
234 v
.rangelow
=(87*16000);
235 v
.rangehigh
=(108*16000);
236 v
.flags
=VIDEO_TUNER_LOW
;
237 v
.mode
=VIDEO_MODE_AUTO
;
238 strcpy(v
.name
, "FM");
239 v
.signal
=0xFFFF*rt_getsigstr(rt
);
240 if(copy_to_user(arg
,&v
, sizeof(v
)))
246 struct video_tuner v
;
247 if(copy_from_user(&v
, arg
, sizeof(v
)))
251 /* Only 1 tuner so no setting needed ! */
255 if(copy_to_user(arg
, &rt
->curfreq
, sizeof(rt
->curfreq
)))
259 if(copy_from_user(&rt
->curfreq
, arg
,sizeof(rt
->curfreq
)))
261 rt_setfreq(rt
, rt
->curfreq
);
265 struct video_audio v
;
266 memset(&v
,0, sizeof(v
));
267 v
.flags
|=VIDEO_AUDIO_MUTABLE
|VIDEO_AUDIO_VOLUME
;
268 v
.volume
=rt
->curvol
* 6554;
270 strcpy(v
.name
, "Radio");
271 if(copy_to_user(arg
,&v
, sizeof(v
)))
277 struct video_audio v
;
278 if(copy_from_user(&v
, arg
, sizeof(v
)))
283 if(v
.flags
&VIDEO_AUDIO_MUTE
)
286 rt_setvol(rt
,v
.volume
/6554);
295 static int rt_open(struct video_device
*dev
, int flags
)
304 static void rt_close(struct video_device
*dev
)
310 static struct rt_device rtrack_unit
;
312 static struct video_device rtrack_radio
=
319 NULL
, /* Can't read (no capture ability) */
320 NULL
, /* Can't write */
327 __initfunc(int rtrack_init(struct video_init
*v
))
329 if (check_region(io
, 2))
331 printk(KERN_ERR
"rtrack: port 0x%x already in use\n", io
);
335 rtrack_radio
.priv
=&rtrack_unit
;
337 if(video_register_device(&rtrack_radio
, VFL_TYPE_RADIO
)==-1)
340 request_region(io
, 2, "rtrack");
341 printk(KERN_INFO
"AIMSlab Radiotrack/radioreveal card driver.\n");
343 /* mute card - prevents noisy bootups */
345 /* this ensures that the volume is all the way down */
346 outb(0x48, io
); /* volume down but still "on" */
347 sleep_delay(2000000); /* make sure it's totally down */
348 outb(0xc0, io
); /* steady volume, mute card */
349 rtrack_unit
.curvol
= 0;
356 MODULE_AUTHOR("M.Kirkwood");
357 MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
358 MODULE_PARM(io
, "i");
359 MODULE_PARM_DESC(io
, "I/O address of the RadioTrack card (0x20f or 0x30f)");
363 int init_module(void)
367 printk(KERN_ERR
"You must set an I/O address with io=0x???\n");
370 return rtrack_init(NULL
);
373 void cleanup_module(void)
375 video_unregister_device(&rtrack_radio
);
376 release_region(io
,2);