blob: ea93087967410be04d15cae74c99d14e26d6325d [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"
Ondrej Zary39cca6b2012-06-13 17:25:39 -030040#include "lm7000.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030042MODULE_AUTHOR("M. Kirkwood");
Hans Verkuil151c3f82009-03-06 13:45:27 -030043MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
44MODULE_LICENSE("GPL");
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030045MODULE_VERSION("1.0.0");
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -030046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#ifndef CONFIG_RADIO_RTRACK_PORT
48#define CONFIG_RADIO_RTRACK_PORT -1
49#endif
50
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030051#define RTRACK_MAX 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030053static int io[RTRACK_MAX] = { [0] = CONFIG_RADIO_RTRACK_PORT,
54 [1 ... (RTRACK_MAX - 1)] = -1 };
55static int radio_nr[RTRACK_MAX] = { [0 ... (RTRACK_MAX - 1)] = -1 };
Hans Verkuil151c3f82009-03-06 13:45:27 -030056
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030057module_param_array(io, int, NULL, 0444);
58MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
59module_param_array(radio_nr, int, NULL, 0444);
60MODULE_PARM_DESC(radio_nr, "Radio device numbers");
61
62struct rtrack {
63 struct radio_isa_card isa;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 int curvol;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065};
66
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030067static struct radio_isa_card *rtrack_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030069 struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL);
70
Mauro Carvalho Chehab8f7fa3c2012-06-25 11:06:54 -030071 if (rt)
Hans Verkuilcc3c6df2012-01-16 04:55:10 -030072 rt->curvol = 0xff;
73 return rt ? &rt->isa : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
Ondrej Zary39cca6b2012-06-13 17:25:39 -030076#define AIMS_BIT_TUN_CE (1 << 0)
77#define AIMS_BIT_TUN_CLK (1 << 1)
78#define AIMS_BIT_TUN_DATA (1 << 2)
79#define AIMS_BIT_VOL_CE (1 << 3)
80#define AIMS_BIT_TUN_STRQ (1 << 4)
81/* bit 5 is not connected */
82#define AIMS_BIT_VOL_UP (1 << 6) /* active low */
83#define AIMS_BIT_VOL_DN (1 << 7) /* active low */
Mauro Carvalho Chehab8f7fa3c2012-06-25 11:06:54 -030084
Mauro Carvalho Chehabf6d15e02012-10-27 13:42:06 -030085static void rtrack_set_pins(void *handle, u8 pins)
Mauro Carvalho Chehab8f7fa3c2012-06-25 11:06:54 -030086{
Ondrej Zary39cca6b2012-06-13 17:25:39 -030087 struct radio_isa_card *isa = handle;
88 struct rtrack *rt = container_of(isa, struct rtrack, isa);
89 u8 bits = AIMS_BIT_VOL_DN | AIMS_BIT_VOL_UP | AIMS_BIT_TUN_STRQ;
Mauro Carvalho Chehab8f7fa3c2012-06-25 11:06:54 -030090
Ondrej Zary39cca6b2012-06-13 17:25:39 -030091 if (!v4l2_ctrl_g_ctrl(rt->isa.mute))
92 bits |= AIMS_BIT_VOL_CE;
93
94 if (pins & LM7000_DATA)
95 bits |= AIMS_BIT_TUN_DATA;
96 if (pins & LM7000_CLK)
97 bits |= AIMS_BIT_TUN_CLK;
98 if (pins & LM7000_CE)
99 bits |= AIMS_BIT_TUN_CE;
100
101 outb_p(bits, rt->isa.io);
Mauro Carvalho Chehab8f7fa3c2012-06-25 11:06:54 -0300102}
103
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300104static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Ondrej Zary39cca6b2012-06-13 17:25:39 -0300106 lm7000_set_freq(freq, isa, rtrack_set_pins);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 return 0;
109}
110
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300111static u32 rtrack_g_signal(struct radio_isa_card *isa)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300113 /* bit set = no signal present */
114 return 0xffff * !(inb(isa->io) & 2);
Hans Verkuil151c3f82009-03-06 13:45:27 -0300115}
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -0300116
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300117static int rtrack_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300119 struct rtrack *rt = container_of(isa, struct rtrack, isa);
120 int curvol = rt->curvol;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300122 if (mute) {
123 outb(0xd0, isa->io); /* volume steady + sigstr + off */
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300124 return 0;
125 }
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300126 if (vol == 0) { /* volume = 0 means mute the card */
127 outb(0x48, isa->io); /* volume down but still "on" */
128 msleep(curvol * 3); /* make sure it's totally down */
129 } else if (curvol < vol) {
130 outb(0x98, isa->io); /* volume up + sigstr + on */
131 for (; curvol < vol; curvol++)
Arnd Bergmanncc287f72015-01-28 18:17:42 -0300132 mdelay(3);
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300133 } else if (curvol > vol) {
134 outb(0x58, isa->io); /* volume down + sigstr + on */
135 for (; curvol > vol; curvol--)
Arnd Bergmanncc287f72015-01-28 18:17:42 -0300136 mdelay(3);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300137 }
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300138 outb(0xd8, isa->io); /* volume steady + sigstr + on */
139 rt->curvol = vol;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300140 return 0;
141}
142
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300143/* Mute card - prevents noisy bootups */
144static int rtrack_initialize(struct radio_isa_card *isa)
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300145{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300146 /* this ensures that the volume is all the way up */
147 outb(0x90, isa->io); /* volume up but still "on" */
148 msleep(3000); /* make sure it's totally up */
149 outb(0xc0, isa->io); /* steady volume, mute card */
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300150 return 0;
151}
152
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300153static const struct radio_isa_ops rtrack_ops = {
154 .alloc = rtrack_alloc,
155 .init = rtrack_initialize,
156 .s_mute_volume = rtrack_s_mute_volume,
157 .s_frequency = rtrack_s_frequency,
158 .g_signal = rtrack_g_signal,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159};
160
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300161static const int rtrack_ioports[] = { 0x20f, 0x30f };
162
163static struct radio_isa_driver rtrack_driver = {
164 .driver = {
165 .match = radio_isa_match,
166 .probe = radio_isa_probe,
167 .remove = radio_isa_remove,
168 .driver = {
169 .name = "radio-aimslab",
170 },
171 },
172 .io_params = io,
173 .radio_nr_params = radio_nr,
174 .io_ports = rtrack_ioports,
175 .num_of_io_ports = ARRAY_SIZE(rtrack_ioports),
176 .region_size = 2,
177 .card = "AIMSlab RadioTrack/RadioReveal",
178 .ops = &rtrack_ops,
179 .has_stereo = true,
180 .max_volume = 0xff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181};
182
183static int __init rtrack_init(void)
184{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300185 return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}
187
Hans Verkuil151c3f82009-03-06 13:45:27 -0300188static void __exit rtrack_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
Hans Verkuilcc3c6df2012-01-16 04:55:10 -0300190 isa_unregister_driver(&rtrack_driver.driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
192
193module_init(rtrack_init);
Hans Verkuil151c3f82009-03-06 13:45:27 -0300194module_exit(rtrack_exit);