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 <linux/spinlock.h>
37 #include <linux/version.h> /* for KERNEL_VERSION MACRO */
38 #define RADIO_VERSION KERNEL_VERSION(0,0,2)
40 static struct v4l2_queryctrl radio_qctrl
[] = {
42 .id
= V4L2_CID_AUDIO_MUTE
,
47 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
49 .id
= V4L2_CID_AUDIO_VOLUME
,
54 .default_value
= 0xff,
55 .type
= V4L2_CTRL_TYPE_INTEGER
,
59 #ifndef CONFIG_RADIO_TERRATEC_PORT
60 #define CONFIG_RADIO_TERRATEC_PORT 0x590
63 /**************** this ones are for the terratec *******************/
64 #define BASEPORT 0x590
73 /*******************************************************************/
75 static int io
= CONFIG_RADIO_TERRATEC_PORT
;
76 static int radio_nr
= -1;
77 static spinlock_t lock
;
83 unsigned long curfreq
;
90 static void cardWriteVol(int volume
)
93 volume
= volume
+(volume
* 32); // change both channels
97 if (volume
& (0x80>>i
))
99 else outb(0x00, VOLPORT
);
106 static void tt_mute(struct tt_device
*dev
)
112 static int tt_setvol(struct tt_device
*dev
, int vol
)
115 // printk(KERN_ERR "setvol called, vol = %d\n", vol);
117 if(vol
== dev
->curvol
) { /* requested volume = current */
118 if (dev
->muted
) { /* user is unmuting the card */
120 cardWriteVol(vol
); /* enable card */
126 if(vol
== 0) { /* volume = 0 means mute the card */
127 cardWriteVol(0); /* "turn off card" by setting vol to 0 */
128 dev
->curvol
= vol
; /* track the volume state! */
143 /* this is the worst part in this driver */
144 /* many more or less strange things are going on here, but hey, it works :) */
146 static int tt_setfreq(struct tt_device
*dev
, unsigned long freq1
)
154 unsigned char buffer
[25]; /* we have to bit shift 25 registers */
155 freq
= freq1
/160; /* convert the freq. to a nice to handle value */
159 rest
= freq
*10+10700; /* i once had understood what is going on here */
160 /* maybe some wise guy (friedhelm?) can comment this stuff */
166 if (rest
%temp
== rest
)
180 for (i
=24;i
>-1;i
--) /* bit shift the values to the radiocard */
184 outb(WRT_EN
|DATA
, BASEPORT
);
185 outb(WRT_EN
|DATA
|CLK_ON
, BASEPORT
);
186 outb(WRT_EN
|DATA
, BASEPORT
);
190 outb(WRT_EN
|0x00, BASEPORT
);
191 outb(WRT_EN
|0x00|CLK_ON
, BASEPORT
);
194 outb(0x00, BASEPORT
);
201 static int tt_getsigstr(struct tt_device
*dev
) /* TODO */
203 if (inb(io
) & 2) /* bit set = no signal present */
205 return 1; /* signal present */
208 static int vidioc_querycap(struct file
*file
, void *priv
,
209 struct v4l2_capability
*v
)
211 strlcpy(v
->driver
, "radio-terratec", sizeof(v
->driver
));
212 strlcpy(v
->card
, "ActiveRadio", sizeof(v
->card
));
213 sprintf(v
->bus_info
, "ISA");
214 v
->version
= RADIO_VERSION
;
215 v
->capabilities
= V4L2_CAP_TUNER
;
219 static int vidioc_g_tuner(struct file
*file
, void *priv
,
220 struct v4l2_tuner
*v
)
222 struct video_device
*dev
= video_devdata(file
);
223 struct tt_device
*tt
= dev
->priv
;
228 strcpy(v
->name
, "FM");
229 v
->type
= V4L2_TUNER_RADIO
;
230 v
->rangelow
= (87*16000);
231 v
->rangehigh
= (108*16000);
232 v
->rxsubchans
= V4L2_TUNER_SUB_MONO
;
233 v
->capability
= V4L2_TUNER_CAP_LOW
;
234 v
->audmode
= V4L2_TUNER_MODE_MONO
;
235 v
->signal
= 0xFFFF*tt_getsigstr(tt
);
239 static int vidioc_s_tuner(struct file
*file
, void *priv
,
240 struct v4l2_tuner
*v
)
247 static int vidioc_s_frequency(struct file
*file
, void *priv
,
248 struct v4l2_frequency
*f
)
250 struct video_device
*dev
= video_devdata(file
);
251 struct tt_device
*tt
= dev
->priv
;
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 video_device
*dev
= video_devdata(file
);
262 struct tt_device
*tt
= dev
->priv
;
264 f
->type
= V4L2_TUNER_RADIO
;
265 f
->frequency
= tt
->curfreq
;
269 static int vidioc_queryctrl(struct file
*file
, void *priv
,
270 struct v4l2_queryctrl
*qc
)
274 for (i
= 0; i
< ARRAY_SIZE(radio_qctrl
); i
++) {
275 if (qc
->id
&& qc
->id
== radio_qctrl
[i
].id
) {
276 memcpy(qc
, &(radio_qctrl
[i
]),
284 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
285 struct v4l2_control
*ctrl
)
287 struct video_device
*dev
= video_devdata(file
);
288 struct tt_device
*tt
= dev
->priv
;
291 case V4L2_CID_AUDIO_MUTE
:
297 case V4L2_CID_AUDIO_VOLUME
:
298 ctrl
->value
= tt
->curvol
* 6554;
304 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
305 struct v4l2_control
*ctrl
)
307 struct video_device
*dev
= video_devdata(file
);
308 struct tt_device
*tt
= dev
->priv
;
311 case V4L2_CID_AUDIO_MUTE
:
315 tt_setvol(tt
,tt
->curvol
);
317 case V4L2_CID_AUDIO_VOLUME
:
318 tt_setvol(tt
,ctrl
->value
);
324 static int vidioc_g_audio(struct file
*file
, void *priv
,
325 struct v4l2_audio
*a
)
330 strcpy(a
->name
, "Radio");
331 a
->capability
= V4L2_AUDCAP_STEREO
;
335 static int vidioc_g_input(struct file
*filp
, void *priv
, unsigned int *i
)
341 static int vidioc_s_input(struct file
*filp
, void *priv
, unsigned int i
)
348 static int vidioc_s_audio(struct file
*file
, void *priv
,
349 struct v4l2_audio
*a
)
356 static struct tt_device terratec_unit
;
358 static const struct file_operations terratec_fops
= {
359 .owner
= THIS_MODULE
,
360 .open
= video_exclusive_open
,
361 .release
= video_exclusive_release
,
362 .ioctl
= video_ioctl2
,
363 .compat_ioctl
= v4l_compat_ioctl32
,
367 static struct video_device terratec_radio
=
369 .owner
= THIS_MODULE
,
370 .name
= "TerraTec ActiveRadio",
371 .type
= VID_TYPE_TUNER
,
372 .fops
= &terratec_fops
,
373 .vidioc_querycap
= vidioc_querycap
,
374 .vidioc_g_tuner
= vidioc_g_tuner
,
375 .vidioc_s_tuner
= vidioc_s_tuner
,
376 .vidioc_g_frequency
= vidioc_g_frequency
,
377 .vidioc_s_frequency
= vidioc_s_frequency
,
378 .vidioc_queryctrl
= vidioc_queryctrl
,
379 .vidioc_g_ctrl
= vidioc_g_ctrl
,
380 .vidioc_s_ctrl
= vidioc_s_ctrl
,
381 .vidioc_g_audio
= vidioc_g_audio
,
382 .vidioc_s_audio
= vidioc_s_audio
,
383 .vidioc_g_input
= vidioc_g_input
,
384 .vidioc_s_input
= vidioc_s_input
,
387 static int __init
terratec_init(void)
391 printk(KERN_ERR
"You must set an I/O address with io=0x???\n");
394 if (!request_region(io
, 2, "terratec"))
396 printk(KERN_ERR
"TerraTec: port 0x%x already in use\n", io
);
400 terratec_radio
.priv
=&terratec_unit
;
402 spin_lock_init(&lock
);
404 if(video_register_device(&terratec_radio
, VFL_TYPE_RADIO
, radio_nr
)==-1)
406 release_region(io
,2);
410 printk(KERN_INFO
"TERRATEC ActivRadio Standalone card driver.\n");
412 /* mute card - prevents noisy bootups */
414 /* this ensures that the volume is all the way down */
416 terratec_unit
.curvol
= 0;
421 MODULE_AUTHOR("R.OFFERMANNS & others");
422 MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
423 MODULE_LICENSE("GPL");
424 module_param(io
, int, 0);
425 MODULE_PARM_DESC(io
, "I/O address of the TerraTec ActiveRadio card (0x590 or 0x591)");
426 module_param(radio_nr
, int, 0);
428 static void __exit
terratec_cleanup_module(void)
430 video_unregister_device(&terratec_radio
);
431 release_region(io
,2);
432 printk(KERN_INFO
"TERRATEC ActivRadio Standalone card driver unloaded.\n");
435 module_init(terratec_init
);
436 module_exit(terratec_cleanup_module
);