Commit | Line | Data |
---|---|---|
cc3c6df1 HV |
1 | /* |
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> | |
46ff2c72 | 7 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
d9b01449 | 8 | * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk> |
1da177e4 LT |
9 | * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org> |
10 | * | |
1da177e4 LT |
11 | * 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); | |
4286c6f6 | 25 | * |
cc3c6df1 | 26 | * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool. |
1da177e4 LT |
27 | */ |
28 | ||
29 | #include <linux/module.h> /* Modules */ | |
30 | #include <linux/init.h> /* Initdata */ | |
fb911ee8 | 31 | #include <linux/ioport.h> /* request_region */ |
2400982a | 32 | #include <linux/delay.h> /* msleep */ |
46ff2c72 | 33 | #include <linux/videodev2.h> /* kernel radio structs */ |
151c3f82 | 34 | #include <linux/io.h> /* outb, outb_p */ |
9f1dfccf | 35 | #include <linux/slab.h> |
151c3f82 | 36 | #include <media/v4l2-device.h> |
35ea11ff | 37 | #include <media/v4l2-ioctl.h> |
cc3c6df1 HV |
38 | #include <media/v4l2-ctrls.h> |
39 | #include "radio-isa.h" | |
1da177e4 | 40 | |
cc3c6df1 | 41 | MODULE_AUTHOR("M. Kirkwood"); |
151c3f82 HV |
42 | MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card."); |
43 | MODULE_LICENSE("GPL"); | |
cc3c6df1 | 44 | MODULE_VERSION("1.0.0"); |
46ff2c72 | 45 | |
1da177e4 LT |
46 | #ifndef CONFIG_RADIO_RTRACK_PORT |
47 | #define CONFIG_RADIO_RTRACK_PORT -1 | |
48 | #endif | |
49 | ||
cc3c6df1 | 50 | #define RTRACK_MAX 2 |
1da177e4 | 51 | |
cc3c6df1 HV |
52 | static int io[RTRACK_MAX] = { [0] = CONFIG_RADIO_RTRACK_PORT, |
53 | [1 ... (RTRACK_MAX - 1)] = -1 }; | |
54 | static int radio_nr[RTRACK_MAX] = { [0 ... (RTRACK_MAX - 1)] = -1 }; | |
151c3f82 | 55 | |
cc3c6df1 HV |
56 | module_param_array(io, int, NULL, 0444); |
57 | MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)"); | |
58 | module_param_array(radio_nr, int, NULL, 0444); | |
59 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); | |
60 | ||
61 | struct rtrack { | |
62 | struct radio_isa_card isa; | |
1da177e4 | 63 | int curvol; |
1da177e4 LT |
64 | }; |
65 | ||
8f7fa3c8 | 66 | static struct radio_isa_card *rtrack_alloc(void) |
1da177e4 | 67 | { |
8f7fa3c8 | 68 | struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL); |
1da177e4 | 69 | |
8f7fa3c8 MCC |
70 | if (rt) |
71 | rt->curvol = 0xff; | |
72 | return rt ? &rt->isa : NULL; | |
73 | } | |
1da177e4 | 74 | |
8f7fa3c8 MCC |
75 | /* 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 | */ | |
1da177e4 | 79 | |
8f7fa3c8 MCC |
80 | static 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); | |
1da177e4 LT |
85 | } |
86 | ||
8f7fa3c8 | 87 | static void send_1_byte(struct radio_isa_card *isa, int on) |
1da177e4 | 88 | { |
8f7fa3c8 MCC |
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); | |
1da177e4 LT |
92 | } |
93 | ||
cc3c6df1 | 94 | static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq) |
1da177e4 | 95 | { |
8f7fa3c8 MCC |
96 | int on = v4l2_ctrl_g_ctrl(isa->mute) ? 0 : 8; |
97 | int i; | |
98 | ||
99 | freq += 171200; /* Add 10.7 MHz IF */ | |
100 | freq /= 800; /* Convert to 50 kHz units */ | |
101 | ||
102 | 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 */ | |
46ff2c72 | 117 | |
8f7fa3c8 MCC |
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) */ | |
46ff2c72 | 122 | |
8f7fa3c8 | 123 | outb(0xd0 + on, isa->io); /* volume steady + sigstr */ |
385e8d8f DL |
124 | return 0; |
125 | } | |
46ff2c72 | 126 | |
cc3c6df1 | 127 | static u32 rtrack_g_signal(struct radio_isa_card *isa) |
385e8d8f | 128 | { |
cc3c6df1 HV |
129 | /* bit set = no signal present */ |
130 | return 0xffff * !(inb(isa->io) & 2); | |
385e8d8f | 131 | } |
46ff2c72 | 132 | |
cc3c6df1 | 133 | static int rtrack_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) |
385e8d8f | 134 | { |
cc3c6df1 HV |
135 | struct rtrack *rt = container_of(isa, struct rtrack, isa); |
136 | int curvol = rt->curvol; | |
46ff2c72 | 137 | |
cc3c6df1 HV |
138 | if (mute) { |
139 | outb(0xd0, isa->io); /* volume steady + sigstr + off */ | |
385e8d8f DL |
140 | return 0; |
141 | } | |
cc3c6df1 HV |
142 | 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); | |
1da177e4 | 153 | } |
cc3c6df1 HV |
154 | outb(0xd8, isa->io); /* volume steady + sigstr + on */ |
155 | rt->curvol = vol; | |
385e8d8f DL |
156 | return 0; |
157 | } | |
158 | ||
cc3c6df1 HV |
159 | /* Mute card - prevents noisy bootups */ |
160 | static int rtrack_initialize(struct radio_isa_card *isa) | |
385e8d8f | 161 | { |
cc3c6df1 HV |
162 | /* 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 */ | |
385e8d8f | 166 | return 0; |
1da177e4 LT |
167 | } |
168 | ||
cc3c6df1 HV |
169 | static 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, | |
1da177e4 LT |
175 | }; |
176 | ||
cc3c6df1 HV |
177 | static const int rtrack_ioports[] = { 0x20f, 0x30f }; |
178 | ||
179 | static 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, | |
1da177e4 LT |
197 | }; |
198 | ||
199 | static int __init rtrack_init(void) | |
200 | { | |
cc3c6df1 | 201 | return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX); |
1da177e4 LT |
202 | } |
203 | ||
151c3f82 | 204 | static void __exit rtrack_exit(void) |
1da177e4 | 205 | { |
cc3c6df1 | 206 | isa_unregister_driver(&rtrack_driver.driver); |
1da177e4 LT |
207 | } |
208 | ||
209 | module_init(rtrack_init); | |
151c3f82 | 210 | module_exit(rtrack_exit); |