blob: 2b82dd76a83b39b422738ecc1e415184f8a8ef16 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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)
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -03005 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * History:
8 * 1999-05-21 First preview release
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -03009 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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)
15 *
16 * Frequency control is done digitally -- ie out(port,encodefreq(95.8));
17 * Volume Control is done digitally
18 *
Hans Verkuil32c51832012-01-16 05:15:09 -030019 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
Mauro Carvalho Chehab55ac7b62006-08-08 09:10:03 -030020 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 */
22
23#include <linux/module.h> /* Modules */
24#include <linux/init.h> /* Initdata */
Peter Osterlundfb911ee2005-09-13 01:25:15 -070025#include <linux/ioport.h> /* request_region */
Mauro Carvalho Chehab55ac7b62006-08-08 09:10:03 -030026#include <linux/videodev2.h> /* kernel radio structs */
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030027#include <linux/mutex.h>
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030028#include <linux/io.h> /* outb, outb_p */
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030029#include <media/v4l2-device.h>
30#include <media/v4l2-ioctl.h>
Hans Verkuil32c51832012-01-16 05:15:09 -030031#include "radio-isa.h"
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030032
Hans Verkuil32c51832012-01-16 05:15:09 -030033MODULE_AUTHOR("R. Offermans & others");
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030034MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
35MODULE_LICENSE("GPL");
Hans Verkuil32c51832012-01-16 05:15:09 -030036MODULE_VERSION("0.1.99");
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030037
Hans Verkuil32c51832012-01-16 05:15:09 -030038/* Note: there seems to be only one possible port (0x590), but without
39 hardware this is hard to verify. For now, this is the only one we will
40 support. */
41static int io = 0x590;
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030042static int radio_nr = -1;
43
Hans Verkuil32c51832012-01-16 05:15:09 -030044module_param(radio_nr, int, 0444);
45MODULE_PARM_DESC(radio_nr, "Radio device number");
Mauro Carvalho Chehab55ac7b62006-08-08 09:10:03 -030046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define WRT_DIS 0x00
48#define CLK_OFF 0x00
49#define IIC_DATA 0x01
50#define IIC_CLK 0x02
51#define DATA 0x04
52#define CLK_ON 0x08
53#define WRT_EN 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Hans Verkuil32c51832012-01-16 05:15:09 -030055static struct radio_isa_card *terratec_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
Hans Verkuil32c51832012-01-16 05:15:09 -030057 return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
58}
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Hans Verkuil32c51832012-01-16 05:15:09 -030060static int terratec_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
62 int i;
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030063
Hans Verkuil32c51832012-01-16 05:15:09 -030064 if (mute)
65 vol = 0;
66 vol = vol + (vol * 32); /* change both channels */
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030067 for (i = 0; i < 8; i++) {
Hans Verkuil32c51832012-01-16 05:15:09 -030068 if (vol & (0x80 >> i))
69 outb(0x80, isa->io + 1);
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030070 else
Hans Verkuil32c51832012-01-16 05:15:09 -030071 outb(0x00, isa->io + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
76
77/* this is the worst part in this driver */
78/* many more or less strange things are going on here, but hey, it works :) */
79
Hans Verkuil32c51832012-01-16 05:15:09 -030080static int terratec_s_frequency(struct radio_isa_card *isa, u32 freq)
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030081{
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 int i;
83 int p;
Hans Verkuil32c51832012-01-16 05:15:09 -030084 int temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 long rest;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned char buffer[25]; /* we have to bit shift 25 registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Hans Verkuil32c51832012-01-16 05:15:09 -030088 freq = freq / 160; /* convert the freq. to a nice to handle value */
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030089 memset(buffer, 0, sizeof(buffer));
90
91 rest = freq * 10 + 10700; /* I once had understood what is going on here */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 /* maybe some wise guy (friedhelm?) can comment this stuff */
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030093 i = 13;
94 p = 10;
95 temp = 102400;
96 while (rest != 0) {
97 if (rest % temp == rest)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 buffer[i] = 0;
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030099 else {
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300100 buffer[i] = 1;
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300101 rest = rest - temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 }
103 i--;
104 p--;
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300105 temp = temp / 2;
Michael Krufkyb930e1d2007-08-27 18:16:54 -0300106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300108 for (i = 24; i > -1; i--) { /* bit shift the values to the radiocard */
109 if (buffer[i] == 1) {
Hans Verkuil32c51832012-01-16 05:15:09 -0300110 outb(WRT_EN | DATA, isa->io);
111 outb(WRT_EN | DATA | CLK_ON, isa->io);
112 outb(WRT_EN | DATA, isa->io);
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300113 } else {
Hans Verkuil32c51832012-01-16 05:15:09 -0300114 outb(WRT_EN | 0x00, isa->io);
115 outb(WRT_EN | 0x00 | CLK_ON, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
117 }
Hans Verkuil32c51832012-01-16 05:15:09 -0300118 outb(0x00, isa->io);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300119 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}
121
Hans Verkuil32c51832012-01-16 05:15:09 -0300122static u32 terratec_g_signal(struct radio_isa_card *isa)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Hans Verkuil32c51832012-01-16 05:15:09 -0300124 /* bit set = no signal present */
125 return (inb(isa->io) & 2) ? 0 : 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Hans Verkuil32c51832012-01-16 05:15:09 -0300128static const struct radio_isa_ops terratec_ops = {
129 .alloc = terratec_alloc,
130 .s_mute_volume = terratec_s_mute_volume,
131 .s_frequency = terratec_s_frequency,
132 .g_signal = terratec_g_signal,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133};
134
Hans Verkuil32c51832012-01-16 05:15:09 -0300135static const int terratec_ioports[] = { 0x590 };
136
137static struct radio_isa_driver terratec_driver = {
138 .driver = {
139 .match = radio_isa_match,
140 .probe = radio_isa_probe,
141 .remove = radio_isa_remove,
142 .driver = {
143 .name = "radio-terratec",
144 },
145 },
146 .io_params = &io,
147 .radio_nr_params = &radio_nr,
148 .io_ports = terratec_ioports,
149 .num_of_io_ports = ARRAY_SIZE(terratec_ioports),
150 .region_size = 2,
151 .card = "TerraTec ActiveRadio",
152 .ops = &terratec_ops,
153 .has_stereo = true,
154 .max_volume = 10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155};
156
157static int __init terratec_init(void)
158{
Hans Verkuil32c51832012-01-16 05:15:09 -0300159 return isa_register_driver(&terratec_driver.driver, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300162static void __exit terratec_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
Hans Verkuil32c51832012-01-16 05:15:09 -0300164 isa_unregister_driver(&terratec_driver.driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165}
166
167module_init(terratec_init);
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300168module_exit(terratec_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169