blob: 98e0c8c20312a5f547f8b175a30182b2e799590a [file] [log] [blame]
Hans Verkuilcc3c6df2012-01-16 04:55:10 -03001/*
2 * AimsLab RadioTrack (aka RadioVeveal) driver
3 *
4 * Copyright 1997 M. Kirkwood
5 *
6 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -03007 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
Alan Coxd9b01442008-10-27 15:13:47 -03008 * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
10 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * Notes on the hardware (reverse engineered from other peoples'
12 * reverse engineering of AIMS' code :-)
13 *
14 * Frequency control is done digitally -- ie out(port,encodefreq(95.8));
15 *
16 * The signal strength query is unsurprisingly inaccurate. And it seems
17 * to indicate that (on my card, at least) the frequency setting isn't
18 * too great. (I have to tune up .025MHz from what the freq should be
19 * to get a report that the thing is tuned.)
20 *
21 * Volume control is (ugh) analogue:
22 * out(port, start_increasing_volume);
23 * wait(a_wee_while);
24 * out(port, stop_changing_the_volume);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030025 *
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030026 * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 */
28
29#include <linux/module.h> /* Modules */
30#include <linux/init.h> /* Initdata */
Peter Osterlundfb911ee2005-09-13 01:25:15 -070031#include <linux/ioport.h> /* request_region */
Geert Uytterhoeven24009822011-01-16 10:09:13 -030032#include <linux/delay.h> /* msleep */
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -030033#include <linux/videodev2.h> /* kernel radio structs */
Hans Verkuil151c3f82009-03-06 13:45:27 -030034#include <linux/io.h> /* outb, outb_p */
Hans Verkuil9f1dfcc2012-02-29 05:50:27 -030035#include <linux/slab.h>
Hans Verkuil151c3f82009-03-06 13:45:27 -030036#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030037#include <media/v4l2-ioctl.h>
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030038#include <media/v4l2-ctrls.h>
39#include "radio-isa.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030041MODULE_AUTHOR("M. Kirkwood");
Hans Verkuil151c3f82009-03-06 13:45:27 -030042MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
43MODULE_LICENSE("GPL");
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030044MODULE_VERSION("1.0.0");
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -030045
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#ifndef CONFIG_RADIO_RTRACK_PORT
47#define CONFIG_RADIO_RTRACK_PORT -1
48#endif
49
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030050#define RTRACK_MAX 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030052static int io[RTRACK_MAX] = { [0] = CONFIG_RADIO_RTRACK_PORT,
53 [1 ... (RTRACK_MAX - 1)] = -1 };
54static int radio_nr[RTRACK_MAX] = { [0 ... (RTRACK_MAX - 1)] = -1 };
Hans Verkuil151c3f82009-03-06 13:45:27 -030055
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030056module_param_array(io, int, NULL, 0444);
57MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
58module_param_array(radio_nr, int, NULL, 0444);
59MODULE_PARM_DESC(radio_nr, "Radio device numbers");
60
61struct rtrack {
62 struct radio_isa_card isa;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 int curvol;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064};
65
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030066static struct radio_isa_card *rtrack_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030068 struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL);
69
Mauro Carvalho Chehab8f7fa3c2012-06-25 11:06:54 -030070 if (rt)
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030071 rt->curvol = 0xff;
72 return rt ? &rt->isa : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
74
Mauro Carvalho Chehab8f7fa3c2012-06-25 11:06:54 -030075/* The 128+64 on these outb's is to keep the volume stable while tuning.
76 * Without them, the volume _will_ creep up with each frequency change
77 * and bit 4 (+16) is to keep the signal strength meter enabled.
78 */
79
80static void send_0_byte(struct radio_isa_card *isa, int on)
81{
82 outb_p(128+64+16+on+1, isa->io); /* wr-enable + data low */
83 outb_p(128+64+16+on+2+1, isa->io); /* clock */
84 msleep(1);
85}
86
87static void send_1_byte(struct radio_isa_card *isa, int on)
88{
89 outb_p(128+64+16+on+4+1, isa->io); /* wr-enable+data high */
90 outb_p(128+64+16+on+4+2+1, isa->io); /* clock */
91 msleep(1);
92}
93
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030094static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Mauro Carvalho Chehab8f7fa3c2012-06-25 11:06:54 -030096 int on = v4l2_ctrl_g_ctrl(isa->mute) ? 0 : 8;
97 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Mauro Carvalho Chehab8f7fa3c2012-06-25 11:06:54 -030099 freq += 171200; /* Add 10.7 MHz IF */
100 freq /= 800; /* Convert to 50 kHz units */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300101
Mauro Carvalho Chehab8f7fa3c2012-06-25 11:06:54 -0300102 send_0_byte(isa, on); /* 0: LSB of frequency */
103
104 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
105 if (freq & (1 << i))
106 send_1_byte(isa, on);
107 else
108 send_0_byte(isa, on);
109
110 send_0_byte(isa, on); /* 14: test bit - always 0 */
111 send_0_byte(isa, on); /* 15: test bit - always 0 */
112
113 send_0_byte(isa, on); /* 16: band data 0 - always 0 */
114 send_0_byte(isa, on); /* 17: band data 1 - always 0 */
115 send_0_byte(isa, on); /* 18: band data 2 - always 0 */
116 send_0_byte(isa, on); /* 19: time base - always 0 */
117
118 send_0_byte(isa, on); /* 20: spacing (0 = 25 kHz) */
119 send_1_byte(isa, on); /* 21: spacing (1 = 25 kHz) */
120 send_0_byte(isa, on); /* 22: spacing (0 = 25 kHz) */
121 send_1_byte(isa, on); /* 23: AM/FM (FM = 1, always) */
122
123 outb(0xd0 + on, isa->io); /* volume steady + sigstr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 return 0;
125}
126
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300127static u32 rtrack_g_signal(struct radio_isa_card *isa)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300129 /* bit set = no signal present */
130 return 0xffff * !(inb(isa->io) & 2);
Hans Verkuil151c3f82009-03-06 13:45:27 -0300131}
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -0300132
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300133static int rtrack_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300135 struct rtrack *rt = container_of(isa, struct rtrack, isa);
136 int curvol = rt->curvol;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300138 if (mute) {
139 outb(0xd0, isa->io); /* volume steady + sigstr + off */
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300140 return 0;
141 }
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300142 if (vol == 0) { /* volume = 0 means mute the card */
143 outb(0x48, isa->io); /* volume down but still "on" */
144 msleep(curvol * 3); /* make sure it's totally down */
145 } else if (curvol < vol) {
146 outb(0x98, isa->io); /* volume up + sigstr + on */
147 for (; curvol < vol; curvol++)
148 udelay(3000);
149 } else if (curvol > vol) {
150 outb(0x58, isa->io); /* volume down + sigstr + on */
151 for (; curvol > vol; curvol--)
152 udelay(3000);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300153 }
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300154 outb(0xd8, isa->io); /* volume steady + sigstr + on */
155 rt->curvol = vol;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300156 return 0;
157}
158
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300159/* Mute card - prevents noisy bootups */
160static int rtrack_initialize(struct radio_isa_card *isa)
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300161{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300162 /* this ensures that the volume is all the way up */
163 outb(0x90, isa->io); /* volume up but still "on" */
164 msleep(3000); /* make sure it's totally up */
165 outb(0xc0, isa->io); /* steady volume, mute card */
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300166 return 0;
167}
168
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300169static const struct radio_isa_ops rtrack_ops = {
170 .alloc = rtrack_alloc,
171 .init = rtrack_initialize,
172 .s_mute_volume = rtrack_s_mute_volume,
173 .s_frequency = rtrack_s_frequency,
174 .g_signal = rtrack_g_signal,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175};
176
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300177static const int rtrack_ioports[] = { 0x20f, 0x30f };
178
179static struct radio_isa_driver rtrack_driver = {
180 .driver = {
181 .match = radio_isa_match,
182 .probe = radio_isa_probe,
183 .remove = radio_isa_remove,
184 .driver = {
185 .name = "radio-aimslab",
186 },
187 },
188 .io_params = io,
189 .radio_nr_params = radio_nr,
190 .io_ports = rtrack_ioports,
191 .num_of_io_ports = ARRAY_SIZE(rtrack_ioports),
192 .region_size = 2,
193 .card = "AIMSlab RadioTrack/RadioReveal",
194 .ops = &rtrack_ops,
195 .has_stereo = true,
196 .max_volume = 0xff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197};
198
199static int __init rtrack_init(void)
200{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300201 return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202}
203
Hans Verkuil151c3f82009-03-06 13:45:27 -0300204static void __exit rtrack_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300206 isa_unregister_driver(&rtrack_driver.driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208
209module_init(rtrack_init);
Hans Verkuil151c3f82009-03-06 13:45:27 -0300210module_exit(rtrack_exit);