Commit | Line | Data |
---|---|---|
09c434b8 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
cc3c6df1 HV |
2 | /* |
3 | * AimsLab RadioTrack (aka RadioVeveal) driver | |
4 | * | |
5 | * Copyright 1997 M. Kirkwood | |
6 | * | |
7 | * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com> | |
32590819 | 8 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@kernel.org> |
d9b01449 | 9 | * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk> |
1da177e4 LT |
10 | * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org> |
11 | * | |
1da177e4 LT |
12 | * Notes on the hardware (reverse engineered from other peoples' |
13 | * reverse engineering of AIMS' code :-) | |
14 | * | |
15 | * Frequency control is done digitally -- ie out(port,encodefreq(95.8)); | |
16 | * | |
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.) | |
21 | * | |
22 | * Volume control is (ugh) analogue: | |
23 | * out(port, start_increasing_volume); | |
24 | * wait(a_wee_while); | |
25 | * out(port, stop_changing_the_volume); | |
4286c6f6 | 26 | * |
cc3c6df1 | 27 | * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool. |
1da177e4 LT |
28 | */ |
29 | ||
6e6a8b5a | 30 | #include <linux/module.h> /* Modules */ |
1da177e4 | 31 | #include <linux/init.h> /* Initdata */ |
fb911ee8 | 32 | #include <linux/ioport.h> /* request_region */ |
2400982a | 33 | #include <linux/delay.h> /* msleep */ |
46ff2c72 | 34 | #include <linux/videodev2.h> /* kernel radio structs */ |
151c3f82 | 35 | #include <linux/io.h> /* outb, outb_p */ |
9f1dfccf | 36 | #include <linux/slab.h> |
151c3f82 | 37 | #include <media/v4l2-device.h> |
35ea11ff | 38 | #include <media/v4l2-ioctl.h> |
cc3c6df1 HV |
39 | #include <media/v4l2-ctrls.h> |
40 | #include "radio-isa.h" | |
39cca6b8 | 41 | #include "lm7000.h" |
1da177e4 | 42 | |
cc3c6df1 | 43 | MODULE_AUTHOR("M. Kirkwood"); |
151c3f82 HV |
44 | MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card."); |
45 | MODULE_LICENSE("GPL"); | |
cc3c6df1 | 46 | MODULE_VERSION("1.0.0"); |
46ff2c72 | 47 | |
1da177e4 LT |
48 | #ifndef CONFIG_RADIO_RTRACK_PORT |
49 | #define CONFIG_RADIO_RTRACK_PORT -1 | |
50 | #endif | |
51 | ||
cc3c6df1 | 52 | #define RTRACK_MAX 2 |
1da177e4 | 53 | |
cc3c6df1 HV |
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 }; | |
151c3f82 | 57 | |
cc3c6df1 HV |
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"); | |
62 | ||
63 | struct rtrack { | |
64 | struct radio_isa_card isa; | |
1da177e4 | 65 | int curvol; |
1da177e4 LT |
66 | }; |
67 | ||
8f7fa3c8 | 68 | static struct radio_isa_card *rtrack_alloc(void) |
1da177e4 | 69 | { |
8f7fa3c8 | 70 | struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL); |
1da177e4 | 71 | |
8f7fa3c8 MCC |
72 | if (rt) |
73 | rt->curvol = 0xff; | |
74 | return rt ? &rt->isa : NULL; | |
75 | } | |
1da177e4 | 76 | |
39cca6b8 OZ |
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 */ | |
1da177e4 | 85 | |
f6d15e09 | 86 | static void rtrack_set_pins(void *handle, u8 pins) |
8f7fa3c8 | 87 | { |
39cca6b8 OZ |
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; | |
1da177e4 | 91 | |
39cca6b8 OZ |
92 | if (!v4l2_ctrl_g_ctrl(rt->isa.mute)) |
93 | bits |= AIMS_BIT_VOL_CE; | |
94 | ||
95 | if (pins & LM7000_DATA) | |
96 | bits |= AIMS_BIT_TUN_DATA; | |
97 | if (pins & LM7000_CLK) | |
98 | bits |= AIMS_BIT_TUN_CLK; | |
99 | if (pins & LM7000_CE) | |
100 | bits |= AIMS_BIT_TUN_CE; | |
101 | ||
102 | outb_p(bits, rt->isa.io); | |
1da177e4 LT |
103 | } |
104 | ||
cc3c6df1 | 105 | static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq) |
1da177e4 | 106 | { |
39cca6b8 | 107 | lm7000_set_freq(freq, isa, rtrack_set_pins); |
46ff2c72 | 108 | |
385e8d8f DL |
109 | return 0; |
110 | } | |
46ff2c72 | 111 | |
cc3c6df1 | 112 | static u32 rtrack_g_signal(struct radio_isa_card *isa) |
385e8d8f | 113 | { |
cc3c6df1 HV |
114 | /* bit set = no signal present */ |
115 | return 0xffff * !(inb(isa->io) & 2); | |
385e8d8f | 116 | } |
46ff2c72 | 117 | |
cc3c6df1 | 118 | static int rtrack_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) |
385e8d8f | 119 | { |
cc3c6df1 HV |
120 | struct rtrack *rt = container_of(isa, struct rtrack, isa); |
121 | int curvol = rt->curvol; | |
46ff2c72 | 122 | |
cc3c6df1 HV |
123 | if (mute) { |
124 | outb(0xd0, isa->io); /* volume steady + sigstr + off */ | |
385e8d8f DL |
125 | return 0; |
126 | } | |
cc3c6df1 HV |
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++) | |
cc287f7c | 133 | mdelay(3); |
cc3c6df1 HV |
134 | } else if (curvol > vol) { |
135 | outb(0x58, isa->io); /* volume down + sigstr + on */ | |
136 | for (; curvol > vol; curvol--) | |
cc287f7c | 137 | mdelay(3); |
1da177e4 | 138 | } |
cc3c6df1 HV |
139 | outb(0xd8, isa->io); /* volume steady + sigstr + on */ |
140 | rt->curvol = vol; | |
385e8d8f DL |
141 | return 0; |
142 | } | |
143 | ||
cc3c6df1 HV |
144 | /* Mute card - prevents noisy bootups */ |
145 | static int rtrack_initialize(struct radio_isa_card *isa) | |
385e8d8f | 146 | { |
cc3c6df1 HV |
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 */ | |
385e8d8f | 151 | return 0; |
1da177e4 LT |
152 | } |
153 | ||
cc3c6df1 HV |
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, | |
1da177e4 LT |
160 | }; |
161 | ||
cc3c6df1 HV |
162 | static const int rtrack_ioports[] = { 0x20f, 0x30f }; |
163 | ||
164 | static struct radio_isa_driver rtrack_driver = { | |
165 | .driver = { | |
166 | .match = radio_isa_match, | |
167 | .probe = radio_isa_probe, | |
168 | .remove = radio_isa_remove, | |
169 | .driver = { | |
170 | .name = "radio-aimslab", | |
171 | }, | |
172 | }, | |
173 | .io_params = io, | |
174 | .radio_nr_params = radio_nr, | |
175 | .io_ports = rtrack_ioports, | |
176 | .num_of_io_ports = ARRAY_SIZE(rtrack_ioports), | |
177 | .region_size = 2, | |
178 | .card = "AIMSlab RadioTrack/RadioReveal", | |
179 | .ops = &rtrack_ops, | |
180 | .has_stereo = true, | |
181 | .max_volume = 0xff, | |
1da177e4 LT |
182 | }; |
183 | ||
184 | static int __init rtrack_init(void) | |
185 | { | |
cc3c6df1 | 186 | return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX); |
1da177e4 LT |
187 | } |
188 | ||
151c3f82 | 189 | static void __exit rtrack_exit(void) |
1da177e4 | 190 | { |
cc3c6df1 | 191 | isa_unregister_driver(&rtrack_driver.driver); |
1da177e4 LT |
192 | } |
193 | ||
194 | module_init(rtrack_init); | |
151c3f82 | 195 | module_exit(rtrack_exit); |