blob: 862dfce1f2fdbee5fcbd0320853daaf6f40d8843 [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 Verkuil151c3f82009-03-06 13:45:27 -030035#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030036#include <media/v4l2-ioctl.h>
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030037#include <media/v4l2-ctrls.h>
38#include "radio-isa.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030040MODULE_AUTHOR("M. Kirkwood");
Hans Verkuil151c3f82009-03-06 13:45:27 -030041MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
42MODULE_LICENSE("GPL");
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030043MODULE_VERSION("1.0.0");
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -030044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#ifndef CONFIG_RADIO_RTRACK_PORT
46#define CONFIG_RADIO_RTRACK_PORT -1
47#endif
48
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030049#define RTRACK_MAX 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030051static int io[RTRACK_MAX] = { [0] = CONFIG_RADIO_RTRACK_PORT,
52 [1 ... (RTRACK_MAX - 1)] = -1 };
53static int radio_nr[RTRACK_MAX] = { [0 ... (RTRACK_MAX - 1)] = -1 };
Hans Verkuil151c3f82009-03-06 13:45:27 -030054
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030055module_param_array(io, int, NULL, 0444);
56MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
57module_param_array(radio_nr, int, NULL, 0444);
58MODULE_PARM_DESC(radio_nr, "Radio device numbers");
59
60struct rtrack {
61 struct radio_isa_card isa;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 int curvol;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063};
64
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030065static struct radio_isa_card *rtrack_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030067 struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL);
68
69 if (rt)
70 rt->curvol = 0xff;
71 return rt ? &rt->isa : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030074/* The 128+64 on these outb's is to keep the volume stable while tuning.
75 * Without them, the volume _will_ creep up with each frequency change
76 * and bit 4 (+16) is to keep the signal strength meter enabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 */
78
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030079static void send_0_byte(struct radio_isa_card *isa, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030081 outb_p(128+64+16+on+1, isa->io); /* wr-enable + data low */
82 outb_p(128+64+16+on+2+1, isa->io); /* clock */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -020083 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030086static void send_1_byte(struct radio_isa_card *isa, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030088 outb_p(128+64+16+on+4+1, isa->io); /* wr-enable+data high */
89 outb_p(128+64+16+on+4+2+1, isa->io); /* clock */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -020090 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
92
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030093static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030095 int on = v4l2_ctrl_g_ctrl(isa->mute) ? 0 : 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 int i;
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 freq += 171200; /* Add 10.7 MHz IF */
99 freq /= 800; /* Convert to 50 kHz units */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300100
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300101 send_0_byte(isa, on); /* 0: LSB of frequency */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
104 if (freq & (1 << i))
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300105 send_1_byte(isa, on);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 else
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300107 send_0_byte(isa, on);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300109 send_0_byte(isa, on); /* 14: test bit - always 0 */
110 send_0_byte(isa, on); /* 15: test bit - always 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300112 send_0_byte(isa, on); /* 16: band data 0 - always 0 */
113 send_0_byte(isa, on); /* 17: band data 1 - always 0 */
114 send_0_byte(isa, on); /* 18: band data 2 - always 0 */
115 send_0_byte(isa, on); /* 19: time base - always 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300117 send_0_byte(isa, on); /* 20: spacing (0 = 25 kHz) */
118 send_1_byte(isa, on); /* 21: spacing (1 = 25 kHz) */
119 send_0_byte(isa, on); /* 22: spacing (0 = 25 kHz) */
120 send_1_byte(isa, on); /* 23: AM/FM (FM = 1, always) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300122 outb(0xd0 + on, isa->io); /* volume steady + sigstr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 return 0;
124}
125
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300126static u32 rtrack_g_signal(struct radio_isa_card *isa)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300128 /* bit set = no signal present */
129 return 0xffff * !(inb(isa->io) & 2);
Hans Verkuil151c3f82009-03-06 13:45:27 -0300130}
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -0300131
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300132static int rtrack_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300134 struct rtrack *rt = container_of(isa, struct rtrack, isa);
135 int curvol = rt->curvol;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300137 if (mute) {
138 outb(0xd0, isa->io); /* volume steady + sigstr + off */
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300139 return 0;
140 }
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300141 if (vol == 0) { /* volume = 0 means mute the card */
142 outb(0x48, isa->io); /* volume down but still "on" */
143 msleep(curvol * 3); /* make sure it's totally down */
144 } else if (curvol < vol) {
145 outb(0x98, isa->io); /* volume up + sigstr + on */
146 for (; curvol < vol; curvol++)
147 udelay(3000);
148 } else if (curvol > vol) {
149 outb(0x58, isa->io); /* volume down + sigstr + on */
150 for (; curvol > vol; curvol--)
151 udelay(3000);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300152 }
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300153 outb(0xd8, isa->io); /* volume steady + sigstr + on */
154 rt->curvol = vol;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300155 return 0;
156}
157
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300158/* Mute card - prevents noisy bootups */
159static int rtrack_initialize(struct radio_isa_card *isa)
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300160{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300161 /* this ensures that the volume is all the way up */
162 outb(0x90, isa->io); /* volume up but still "on" */
163 msleep(3000); /* make sure it's totally up */
164 outb(0xc0, isa->io); /* steady volume, mute card */
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300165 return 0;
166}
167
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300168static const struct radio_isa_ops rtrack_ops = {
169 .alloc = rtrack_alloc,
170 .init = rtrack_initialize,
171 .s_mute_volume = rtrack_s_mute_volume,
172 .s_frequency = rtrack_s_frequency,
173 .g_signal = rtrack_g_signal,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174};
175
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300176static const int rtrack_ioports[] = { 0x20f, 0x30f };
177
178static struct radio_isa_driver rtrack_driver = {
179 .driver = {
180 .match = radio_isa_match,
181 .probe = radio_isa_probe,
182 .remove = radio_isa_remove,
183 .driver = {
184 .name = "radio-aimslab",
185 },
186 },
187 .io_params = io,
188 .radio_nr_params = radio_nr,
189 .io_ports = rtrack_ioports,
190 .num_of_io_ports = ARRAY_SIZE(rtrack_ioports),
191 .region_size = 2,
192 .card = "AIMSlab RadioTrack/RadioReveal",
193 .ops = &rtrack_ops,
194 .has_stereo = true,
195 .max_volume = 0xff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196};
197
198static int __init rtrack_init(void)
199{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300200 return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
202
Hans Verkuil151c3f82009-03-06 13:45:27 -0300203static void __exit rtrack_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300205 isa_unregister_driver(&rtrack_driver.driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
207
208module_init(rtrack_init);
Hans Verkuil151c3f82009-03-06 13:45:27 -0300209module_exit(rtrack_exit);