blob: be10a802e3a9629349382f8554a5f0300bdb97f0 [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 Verkuil9f1dfcc2012-02-29 05:50:27 -030029#include <linux/slab.h>
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030030#include <media/v4l2-device.h>
31#include <media/v4l2-ioctl.h>
Hans Verkuil32c51832012-01-16 05:15:09 -030032#include "radio-isa.h"
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030033
Hans Verkuil32c51832012-01-16 05:15:09 -030034MODULE_AUTHOR("R. Offermans & others");
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030035MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
36MODULE_LICENSE("GPL");
Hans Verkuil32c51832012-01-16 05:15:09 -030037MODULE_VERSION("0.1.99");
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030038
Hans Verkuil32c51832012-01-16 05:15:09 -030039/* Note: there seems to be only one possible port (0x590), but without
40 hardware this is hard to verify. For now, this is the only one we will
41 support. */
42static int io = 0x590;
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030043static int radio_nr = -1;
44
Hans Verkuil32c51832012-01-16 05:15:09 -030045module_param(radio_nr, int, 0444);
46MODULE_PARM_DESC(radio_nr, "Radio device number");
Mauro Carvalho Chehab55ac7b62006-08-08 09:10:03 -030047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define WRT_DIS 0x00
49#define CLK_OFF 0x00
50#define IIC_DATA 0x01
51#define IIC_CLK 0x02
52#define DATA 0x04
53#define CLK_ON 0x08
54#define WRT_EN 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Hans Verkuil32c51832012-01-16 05:15:09 -030056static struct radio_isa_card *terratec_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Hans Verkuil32c51832012-01-16 05:15:09 -030058 return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
59}
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Hans Verkuil32c51832012-01-16 05:15:09 -030061static int terratec_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
63 int i;
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030064
Hans Verkuil32c51832012-01-16 05:15:09 -030065 if (mute)
66 vol = 0;
67 vol = vol + (vol * 32); /* change both channels */
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030068 for (i = 0; i < 8; i++) {
Hans Verkuil32c51832012-01-16 05:15:09 -030069 if (vol & (0x80 >> i))
70 outb(0x80, isa->io + 1);
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030071 else
Hans Verkuil32c51832012-01-16 05:15:09 -030072 outb(0x00, isa->io + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
77
78/* this is the worst part in this driver */
79/* many more or less strange things are going on here, but hey, it works :) */
80
Hans Verkuil32c51832012-01-16 05:15:09 -030081static int terratec_s_frequency(struct radio_isa_card *isa, u32 freq)
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030082{
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 int i;
84 int p;
Hans Verkuil32c51832012-01-16 05:15:09 -030085 int temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 long rest;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 unsigned char buffer[25]; /* we have to bit shift 25 registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Hans Verkuil32c51832012-01-16 05:15:09 -030089 freq = freq / 160; /* convert the freq. to a nice to handle value */
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030090 memset(buffer, 0, sizeof(buffer));
91
92 rest = freq * 10 + 10700; /* I once had understood what is going on here */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 /* maybe some wise guy (friedhelm?) can comment this stuff */
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -030094 i = 13;
95 p = 10;
96 temp = 102400;
97 while (rest != 0) {
98 if (rest % temp == rest)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 buffer[i] = 0;
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300100 else {
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300101 buffer[i] = 1;
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300102 rest = rest - temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 }
104 i--;
105 p--;
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300106 temp = temp / 2;
Michael Krufkyb930e1d2007-08-27 18:16:54 -0300107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300109 for (i = 24; i > -1; i--) { /* bit shift the values to the radiocard */
110 if (buffer[i] == 1) {
Hans Verkuil32c51832012-01-16 05:15:09 -0300111 outb(WRT_EN | DATA, isa->io);
112 outb(WRT_EN | DATA | CLK_ON, isa->io);
113 outb(WRT_EN | DATA, isa->io);
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300114 } else {
Hans Verkuil32c51832012-01-16 05:15:09 -0300115 outb(WRT_EN | 0x00, isa->io);
116 outb(WRT_EN | 0x00 | CLK_ON, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118 }
Hans Verkuil32c51832012-01-16 05:15:09 -0300119 outb(0x00, isa->io);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300120 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
Hans Verkuil32c51832012-01-16 05:15:09 -0300123static u32 terratec_g_signal(struct radio_isa_card *isa)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Hans Verkuil32c51832012-01-16 05:15:09 -0300125 /* bit set = no signal present */
126 return (inb(isa->io) & 2) ? 0 : 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
Hans Verkuil32c51832012-01-16 05:15:09 -0300129static const struct radio_isa_ops terratec_ops = {
130 .alloc = terratec_alloc,
131 .s_mute_volume = terratec_s_mute_volume,
132 .s_frequency = terratec_s_frequency,
133 .g_signal = terratec_g_signal,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134};
135
Hans Verkuil32c51832012-01-16 05:15:09 -0300136static const int terratec_ioports[] = { 0x590 };
137
138static struct radio_isa_driver terratec_driver = {
139 .driver = {
140 .match = radio_isa_match,
141 .probe = radio_isa_probe,
142 .remove = radio_isa_remove,
143 .driver = {
144 .name = "radio-terratec",
145 },
146 },
147 .io_params = &io,
148 .radio_nr_params = &radio_nr,
149 .io_ports = terratec_ioports,
150 .num_of_io_ports = ARRAY_SIZE(terratec_ioports),
151 .region_size = 2,
152 .card = "TerraTec ActiveRadio",
153 .ops = &terratec_ops,
154 .has_stereo = true,
155 .max_volume = 10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156};
157
158static int __init terratec_init(void)
159{
Hans Verkuil32c51832012-01-16 05:15:09 -0300160 return isa_register_driver(&terratec_driver.driver, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300163static void __exit terratec_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
Hans Verkuil32c51832012-01-16 05:15:09 -0300165 isa_unregister_driver(&terratec_driver.driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166}
167
168module_init(terratec_init);
Hans Verkuil5ac3d5b2009-03-06 13:53:58 -0300169module_exit(terratec_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170