1 /* Terratec ActiveRadio ISA Standalone card driver for Linux radio support
2 * (c) 1999 R. Offermanns (rolf@offermanns.de)
3 * based on the aimslab radio driver from M. Kirkwood
4 * many thanks to Michael Becker and Friedhelm Birth (from TerraTec)
8 * 1999-05-21 First preview release
10 * Notes on the hardware:
11 * There are two "main" chips on the card:
12 * - Philips OM5610 (http://www-us.semiconductors.philips.com/acrobat/datasheets/OM5610_2.pdf)
13 * - Philips SAA6588 (http://www-us.semiconductors.philips.com/acrobat/datasheets/SAA6588_1.pdf)
14 * (you can get the datasheet at the above links)
16 * Frequency control is done digitally -- ie out(port,encodefreq(95.8));
17 * Volume Control is done digitally
19 * there is a I2C controlled RDS decoder (SAA6588) onboard, which i would like to support someday
20 * (as soon i have understand how to get started :)
21 * If you can help me out with that, please contact me!!
24 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
27 #include <linux/module.h> /* Modules */
28 #include <linux/init.h> /* Initdata */
29 #include <linux/ioport.h> /* request_region */
30 #include <linux/delay.h> /* udelay */
31 #include <asm/io.h> /* outb, outb_p */
32 #include <asm/uaccess.h> /* copy to/from user */
33 #include <linux/videodev2.h> /* kernel radio structs */
34 #include <media/v4l2-common.h>
35 #include <media/v4l2-ioctl.h>
36 #include <linux/spinlock.h>
38 #include <linux/version.h> /* for KERNEL_VERSION MACRO */
39 #define RADIO_VERSION KERNEL_VERSION(0,0,2)
41 static struct v4l2_queryctrl radio_qctrl
[] = {
43 .id
= V4L2_CID_AUDIO_MUTE
,
48 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
50 .id
= V4L2_CID_AUDIO_VOLUME
,
55 .default_value
= 0xff,
56 .type
= V4L2_CTRL_TYPE_INTEGER
,
60 #ifndef CONFIG_RADIO_TERRATEC_PORT
61 #define CONFIG_RADIO_TERRATEC_PORT 0x590
64 /**************** this ones are for the terratec *******************/
65 #define BASEPORT 0x590
74 /*******************************************************************/
76 static int io
= CONFIG_RADIO_TERRATEC_PORT
;
77 static int radio_nr
= -1;
78 static spinlock_t lock
;
85 unsigned long curfreq
;
92 static void cardWriteVol(int volume
)
95 volume
= volume
+(volume
* 32); // change both channels
99 if (volume
& (0x80>>i
))
101 else outb(0x00, VOLPORT
);
108 static void tt_mute(struct tt_device
*dev
)
114 static int tt_setvol(struct tt_device
*dev
, int vol
)
117 // printk(KERN_ERR "setvol called, vol = %d\n", vol);
119 if(vol
== dev
->curvol
) { /* requested volume = current */
120 if (dev
->muted
) { /* user is unmuting the card */
122 cardWriteVol(vol
); /* enable card */
128 if(vol
== 0) { /* volume = 0 means mute the card */
129 cardWriteVol(0); /* "turn off card" by setting vol to 0 */
130 dev
->curvol
= vol
; /* track the volume state! */
145 /* this is the worst part in this driver */
146 /* many more or less strange things are going on here, but hey, it works :) */
148 static int tt_setfreq(struct tt_device
*dev
, unsigned long freq1
)
156 unsigned char buffer
[25]; /* we have to bit shift 25 registers */
157 freq
= freq1
/160; /* convert the freq. to a nice to handle value */
161 rest
= freq
*10+10700; /* i once had understood what is going on here */
162 /* maybe some wise guy (friedhelm?) can comment this stuff */
168 if (rest
%temp
== rest
)
182 for (i
=24;i
>-1;i
--) /* bit shift the values to the radiocard */
186 outb(WRT_EN
|DATA
, BASEPORT
);
187 outb(WRT_EN
|DATA
|CLK_ON
, BASEPORT
);
188 outb(WRT_EN
|DATA
, BASEPORT
);
192 outb(WRT_EN
|0x00, BASEPORT
);
193 outb(WRT_EN
|0x00|CLK_ON
, BASEPORT
);
196 outb(0x00, BASEPORT
);
203 static int tt_getsigstr(struct tt_device
*dev
) /* TODO */
205 if (inb(io
) & 2) /* bit set = no signal present */
207 return 1; /* signal present */
210 static int vidioc_querycap(struct file
*file
, void *priv
,
211 struct v4l2_capability
*v
)
213 strlcpy(v
->driver
, "radio-terratec", sizeof(v
->driver
));
214 strlcpy(v
->card
, "ActiveRadio", sizeof(v
->card
));
215 sprintf(v
->bus_info
, "ISA");
216 v
->version
= RADIO_VERSION
;
217 v
->capabilities
= V4L2_CAP_TUNER
;
221 static int vidioc_g_tuner(struct file
*file
, void *priv
,
222 struct v4l2_tuner
*v
)
224 struct tt_device
*tt
= video_drvdata(file
);
229 strcpy(v
->name
, "FM");
230 v
->type
= V4L2_TUNER_RADIO
;
231 v
->rangelow
= (87*16000);
232 v
->rangehigh
= (108*16000);
233 v
->rxsubchans
= V4L2_TUNER_SUB_MONO
;
234 v
->capability
= V4L2_TUNER_CAP_LOW
;
235 v
->audmode
= V4L2_TUNER_MODE_MONO
;
236 v
->signal
= 0xFFFF*tt_getsigstr(tt
);
240 static int vidioc_s_tuner(struct file
*file
, void *priv
,
241 struct v4l2_tuner
*v
)
248 static int vidioc_s_frequency(struct file
*file
, void *priv
,
249 struct v4l2_frequency
*f
)
251 struct tt_device
*tt
= video_drvdata(file
);
253 tt
->curfreq
= f
->frequency
;
254 tt_setfreq(tt
, tt
->curfreq
);
258 static int vidioc_g_frequency(struct file
*file
, void *priv
,
259 struct v4l2_frequency
*f
)
261 struct tt_device
*tt
= video_drvdata(file
);
263 f
->type
= V4L2_TUNER_RADIO
;
264 f
->frequency
= tt
->curfreq
;
268 static int vidioc_queryctrl(struct file
*file
, void *priv
,
269 struct v4l2_queryctrl
*qc
)
273 for (i
= 0; i
< ARRAY_SIZE(radio_qctrl
); i
++) {
274 if (qc
->id
&& qc
->id
== radio_qctrl
[i
].id
) {
275 memcpy(qc
, &(radio_qctrl
[i
]),
283 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
284 struct v4l2_control
*ctrl
)
286 struct tt_device
*tt
= video_drvdata(file
);
289 case V4L2_CID_AUDIO_MUTE
:
295 case V4L2_CID_AUDIO_VOLUME
:
296 ctrl
->value
= tt
->curvol
* 6554;
302 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
303 struct v4l2_control
*ctrl
)
305 struct tt_device
*tt
= video_drvdata(file
);
308 case V4L2_CID_AUDIO_MUTE
:
312 tt_setvol(tt
,tt
->curvol
);
314 case V4L2_CID_AUDIO_VOLUME
:
315 tt_setvol(tt
,ctrl
->value
);
321 static int vidioc_g_audio(struct file
*file
, void *priv
,
322 struct v4l2_audio
*a
)
327 strcpy(a
->name
, "Radio");
328 a
->capability
= V4L2_AUDCAP_STEREO
;
332 static int vidioc_g_input(struct file
*filp
, void *priv
, unsigned int *i
)
338 static int vidioc_s_input(struct file
*filp
, void *priv
, unsigned int i
)
345 static int vidioc_s_audio(struct file
*file
, void *priv
,
346 struct v4l2_audio
*a
)
353 static struct tt_device terratec_unit
;
355 static int terratec_exclusive_open(struct file
*file
)
357 return test_and_set_bit(0, &terratec_unit
.in_use
) ? -EBUSY
: 0;
360 static int terratec_exclusive_release(struct file
*file
)
362 clear_bit(0, &terratec_unit
.in_use
);
366 static const struct v4l2_file_operations terratec_fops
= {
367 .owner
= THIS_MODULE
,
368 .open
= terratec_exclusive_open
,
369 .release
= terratec_exclusive_release
,
370 .ioctl
= video_ioctl2
,
373 static const struct v4l2_ioctl_ops terratec_ioctl_ops
= {
374 .vidioc_querycap
= vidioc_querycap
,
375 .vidioc_g_tuner
= vidioc_g_tuner
,
376 .vidioc_s_tuner
= vidioc_s_tuner
,
377 .vidioc_g_frequency
= vidioc_g_frequency
,
378 .vidioc_s_frequency
= vidioc_s_frequency
,
379 .vidioc_queryctrl
= vidioc_queryctrl
,
380 .vidioc_g_ctrl
= vidioc_g_ctrl
,
381 .vidioc_s_ctrl
= vidioc_s_ctrl
,
382 .vidioc_g_audio
= vidioc_g_audio
,
383 .vidioc_s_audio
= vidioc_s_audio
,
384 .vidioc_g_input
= vidioc_g_input
,
385 .vidioc_s_input
= vidioc_s_input
,
388 static struct video_device terratec_radio
= {
389 .name
= "TerraTec ActiveRadio",
390 .fops
= &terratec_fops
,
391 .ioctl_ops
= &terratec_ioctl_ops
,
392 .release
= video_device_release_empty
,
395 static int __init
terratec_init(void)
399 printk(KERN_ERR
"You must set an I/O address with io=0x???\n");
402 if (!request_region(io
, 2, "terratec"))
404 printk(KERN_ERR
"TerraTec: port 0x%x already in use\n", io
);
408 video_set_drvdata(&terratec_radio
, &terratec_unit
);
410 spin_lock_init(&lock
);
412 if (video_register_device(&terratec_radio
, VFL_TYPE_RADIO
, radio_nr
) < 0) {
413 release_region(io
,2);
417 printk(KERN_INFO
"TERRATEC ActivRadio Standalone card driver.\n");
419 /* mute card - prevents noisy bootups */
421 /* this ensures that the volume is all the way down */
423 terratec_unit
.curvol
= 0;
428 MODULE_AUTHOR("R.OFFERMANNS & others");
429 MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
430 MODULE_LICENSE("GPL");
431 module_param(io
, int, 0);
432 MODULE_PARM_DESC(io
, "I/O address of the TerraTec ActiveRadio card (0x590 or 0x591)");
433 module_param(radio_nr
, int, 0);
435 static void __exit
terratec_cleanup_module(void)
437 video_unregister_device(&terratec_radio
);
438 release_region(io
,2);
439 printk(KERN_INFO
"TERRATEC ActivRadio Standalone card driver unloaded.\n");
442 module_init(terratec_init
);
443 module_exit(terratec_cleanup_module
);