1 // SPDX-License-Identifier: GPL-2.0-only
3 * AimsLab RadioTrack (aka RadioVeveal) driver
5 * Copyright 1997 M. Kirkwood
7 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
8 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@kernel.org>
9 * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
10 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
12 * Notes on the hardware (reverse engineered from other peoples'
13 * reverse engineering of AIMS' code :-)
15 * Frequency control is done digitally -- ie out(port,encodefreq(95.8));
17 * The signal strength query is unsurprisingly inaccurate. And it seems
18 * to indicate that (on my card, at least) the frequency setting isn't
19 * too great. (I have to tune up .025MHz from what the freq should be
20 * to get a report that the thing is tuned.)
22 * Volume control is (ugh) analogue:
23 * out(port, start_increasing_volume);
25 * out(port, stop_changing_the_volume);
27 * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
30 #include <linux/module.h> /* Modules */
31 #include <linux/init.h> /* Initdata */
32 #include <linux/ioport.h> /* request_region */
33 #include <linux/delay.h> /* msleep */
34 #include <linux/videodev2.h> /* kernel radio structs */
35 #include <linux/io.h> /* outb, outb_p */
36 #include <linux/slab.h>
37 #include <media/v4l2-device.h>
38 #include <media/v4l2-ioctl.h>
39 #include <media/v4l2-ctrls.h>
40 #include "radio-isa.h"
43 MODULE_AUTHOR("M. Kirkwood");
44 MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
45 MODULE_LICENSE("GPL");
46 MODULE_VERSION("1.0.0");
48 #ifndef CONFIG_RADIO_RTRACK_PORT
49 #define CONFIG_RADIO_RTRACK_PORT -1
54 static int io
[RTRACK_MAX
] = { [0] = CONFIG_RADIO_RTRACK_PORT
,
55 [1 ... (RTRACK_MAX
- 1)] = -1 };
56 static int radio_nr
[RTRACK_MAX
] = { [0 ... (RTRACK_MAX
- 1)] = -1 };
58 module_param_array(io
, int, NULL
, 0444);
59 MODULE_PARM_DESC(io
, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
60 module_param_array(radio_nr
, int, NULL
, 0444);
61 MODULE_PARM_DESC(radio_nr
, "Radio device numbers");
64 struct radio_isa_card isa
;
68 static struct radio_isa_card
*rtrack_alloc(void)
70 struct rtrack
*rt
= kzalloc(sizeof(struct rtrack
), GFP_KERNEL
);
74 return rt
? &rt
->isa
: NULL
;
77 #define AIMS_BIT_TUN_CE (1 << 0)
78 #define AIMS_BIT_TUN_CLK (1 << 1)
79 #define AIMS_BIT_TUN_DATA (1 << 2)
80 #define AIMS_BIT_VOL_CE (1 << 3)
81 #define AIMS_BIT_TUN_STRQ (1 << 4)
82 /* bit 5 is not connected */
83 #define AIMS_BIT_VOL_UP (1 << 6) /* active low */
84 #define AIMS_BIT_VOL_DN (1 << 7) /* active low */
86 static void rtrack_set_pins(void *handle
, u8 pins
)
88 struct radio_isa_card
*isa
= handle
;
89 struct rtrack
*rt
= container_of(isa
, struct rtrack
, isa
);
90 u8 bits
= AIMS_BIT_VOL_DN
| AIMS_BIT_VOL_UP
| AIMS_BIT_TUN_STRQ
;
92 if (!v4l2_ctrl_g_ctrl(rt
->isa
.mute
))
93 bits
|= AIMS_BIT_VOL_CE
;
95 if (pins
& LM7000_DATA
)
96 bits
|= AIMS_BIT_TUN_DATA
;
97 if (pins
& LM7000_CLK
)
98 bits
|= AIMS_BIT_TUN_CLK
;
100 bits
|= AIMS_BIT_TUN_CE
;
102 outb_p(bits
, rt
->isa
.io
);
105 static int rtrack_s_frequency(struct radio_isa_card
*isa
, u32 freq
)
107 lm7000_set_freq(freq
, isa
, rtrack_set_pins
);
112 static u32
rtrack_g_signal(struct radio_isa_card
*isa
)
114 /* bit set = no signal present */
115 return 0xffff * !(inb(isa
->io
) & 2);
118 static int rtrack_s_mute_volume(struct radio_isa_card
*isa
, bool mute
, int vol
)
120 struct rtrack
*rt
= container_of(isa
, struct rtrack
, isa
);
121 int curvol
= rt
->curvol
;
124 outb(0xd0, isa
->io
); /* volume steady + sigstr + off */
127 if (vol
== 0) { /* volume = 0 means mute the card */
128 outb(0x48, isa
->io
); /* volume down but still "on" */
129 msleep(curvol
* 3); /* make sure it's totally down */
130 } else if (curvol
< vol
) {
131 outb(0x98, isa
->io
); /* volume up + sigstr + on */
132 for (; curvol
< vol
; curvol
++)
134 } else if (curvol
> vol
) {
135 outb(0x58, isa
->io
); /* volume down + sigstr + on */
136 for (; curvol
> vol
; curvol
--)
139 outb(0xd8, isa
->io
); /* volume steady + sigstr + on */
144 /* Mute card - prevents noisy bootups */
145 static int rtrack_initialize(struct radio_isa_card
*isa
)
147 /* this ensures that the volume is all the way up */
148 outb(0x90, isa
->io
); /* volume up but still "on" */
149 msleep(3000); /* make sure it's totally up */
150 outb(0xc0, isa
->io
); /* steady volume, mute card */
154 static const struct radio_isa_ops rtrack_ops
= {
155 .alloc
= rtrack_alloc
,
156 .init
= rtrack_initialize
,
157 .s_mute_volume
= rtrack_s_mute_volume
,
158 .s_frequency
= rtrack_s_frequency
,
159 .g_signal
= rtrack_g_signal
,
162 static const int rtrack_ioports
[] = { 0x20f, 0x30f };
164 static struct radio_isa_driver rtrack_driver
= {
166 .match
= radio_isa_match
,
167 .probe
= radio_isa_probe
,
168 .remove
= radio_isa_remove
,
170 .name
= "radio-aimslab",
174 .radio_nr_params
= radio_nr
,
175 .io_ports
= rtrack_ioports
,
176 .num_of_io_ports
= ARRAY_SIZE(rtrack_ioports
),
178 .card
= "AIMSlab RadioTrack/RadioReveal",
184 static int __init
rtrack_init(void)
186 return isa_register_driver(&rtrack_driver
.driver
, RTRACK_MAX
);
189 static void __exit
rtrack_exit(void)
191 isa_unregister_driver(&rtrack_driver
.driver
);
194 module_init(rtrack_init
);
195 module_exit(rtrack_exit
);