]>
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" | |
39cca6b8 | 40 | #include "lm7000.h" |
1da177e4 | 41 | |
cc3c6df1 | 42 | MODULE_AUTHOR("M. Kirkwood"); |
151c3f82 HV |
43 | MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card."); |
44 | MODULE_LICENSE("GPL"); | |
cc3c6df1 | 45 | MODULE_VERSION("1.0.0"); |
46ff2c72 | 46 | |
1da177e4 LT |
47 | #ifndef CONFIG_RADIO_RTRACK_PORT |
48 | #define CONFIG_RADIO_RTRACK_PORT -1 | |
49 | #endif | |
50 | ||
cc3c6df1 | 51 | #define RTRACK_MAX 2 |
1da177e4 | 52 | |
cc3c6df1 HV |
53 | static int io[RTRACK_MAX] = { [0] = CONFIG_RADIO_RTRACK_PORT, |
54 | [1 ... (RTRACK_MAX - 1)] = -1 }; | |
55 | static int radio_nr[RTRACK_MAX] = { [0 ... (RTRACK_MAX - 1)] = -1 }; | |
151c3f82 | 56 | |
cc3c6df1 HV |
57 | module_param_array(io, int, NULL, 0444); |
58 | MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)"); | |
59 | module_param_array(radio_nr, int, NULL, 0444); | |
60 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); | |
61 | ||
62 | struct rtrack { | |
63 | struct radio_isa_card isa; | |
1da177e4 | 64 | int curvol; |
1da177e4 LT |
65 | }; |
66 | ||
8f7fa3c8 | 67 | static struct radio_isa_card *rtrack_alloc(void) |
1da177e4 | 68 | { |
8f7fa3c8 | 69 | struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL); |
1da177e4 | 70 | |
8f7fa3c8 MCC |
71 | if (rt) |
72 | rt->curvol = 0xff; | |
73 | return rt ? &rt->isa : NULL; | |
74 | } | |
1da177e4 | 75 | |
39cca6b8 OZ |
76 | #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 */ | |
1da177e4 | 84 | |
39cca6b8 | 85 | void rtrack_set_pins(void *handle, u8 pins) |
8f7fa3c8 | 86 | { |
39cca6b8 OZ |
87 | 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; | |
1da177e4 | 90 | |
39cca6b8 OZ |
91 | 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); | |
1da177e4 LT |
102 | } |
103 | ||
cc3c6df1 | 104 | static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq) |
1da177e4 | 105 | { |
39cca6b8 | 106 | lm7000_set_freq(freq, isa, rtrack_set_pins); |
46ff2c72 | 107 | |
385e8d8f DL |
108 | return 0; |
109 | } | |
46ff2c72 | 110 | |
cc3c6df1 | 111 | static u32 rtrack_g_signal(struct radio_isa_card *isa) |
385e8d8f | 112 | { |
cc3c6df1 HV |
113 | /* bit set = no signal present */ |
114 | return 0xffff * !(inb(isa->io) & 2); | |
385e8d8f | 115 | } |
46ff2c72 | 116 | |
cc3c6df1 | 117 | static int rtrack_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) |
385e8d8f | 118 | { |
cc3c6df1 HV |
119 | struct rtrack *rt = container_of(isa, struct rtrack, isa); |
120 | int curvol = rt->curvol; | |
46ff2c72 | 121 | |
cc3c6df1 HV |
122 | if (mute) { |
123 | outb(0xd0, isa->io); /* volume steady + sigstr + off */ | |
385e8d8f DL |
124 | return 0; |
125 | } | |
cc3c6df1 HV |
126 | 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++) | |
132 | udelay(3000); | |
133 | } else if (curvol > vol) { | |
134 | outb(0x58, isa->io); /* volume down + sigstr + on */ | |
135 | for (; curvol > vol; curvol--) | |
136 | udelay(3000); | |
1da177e4 | 137 | } |
cc3c6df1 HV |
138 | outb(0xd8, isa->io); /* volume steady + sigstr + on */ |
139 | rt->curvol = vol; | |
385e8d8f DL |
140 | return 0; |
141 | } | |
142 | ||
cc3c6df1 HV |
143 | /* Mute card - prevents noisy bootups */ |
144 | static int rtrack_initialize(struct radio_isa_card *isa) | |
385e8d8f | 145 | { |
cc3c6df1 HV |
146 | /* 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 */ | |
385e8d8f | 150 | return 0; |
1da177e4 LT |
151 | } |
152 | ||
cc3c6df1 HV |
153 | static 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, | |
1da177e4 LT |
159 | }; |
160 | ||
cc3c6df1 HV |
161 | static const int rtrack_ioports[] = { 0x20f, 0x30f }; |
162 | ||
163 | static 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, | |
1da177e4 LT |
181 | }; |
182 | ||
183 | static int __init rtrack_init(void) | |
184 | { | |
cc3c6df1 | 185 | return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX); |
1da177e4 LT |
186 | } |
187 | ||
151c3f82 | 188 | static void __exit rtrack_exit(void) |
1da177e4 | 189 | { |
cc3c6df1 | 190 | isa_unregister_driver(&rtrack_driver.driver); |
1da177e4 LT |
191 | } |
192 | ||
193 | module_init(rtrack_init); | |
151c3f82 | 194 | module_exit(rtrack_exit); |