This source file includes following definitions.
- gemtek_bu2614_transmit
- gemtek_convfreq
- gemtek_alloc
- gemtek_s_frequency
- gemtek_s_mute_volume
- gemtek_g_rxsubchans
- gemtek_probe
- gemtek_init
- gemtek_exit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/ioport.h>
29 #include <linux/delay.h>
30 #include <linux/videodev2.h>
31 #include <linux/mutex.h>
32 #include <linux/io.h>
33 #include <linux/pnp.h>
34 #include <linux/slab.h>
35 #include <media/v4l2-ioctl.h>
36 #include <media/v4l2-device.h>
37 #include "radio-isa.h"
38
39
40
41
42
43 MODULE_AUTHOR("Jonas Munsin, Pekka Seppänen <pexu@kapsi.fi>");
44 MODULE_DESCRIPTION("A driver for the GemTek Radio card.");
45 MODULE_LICENSE("GPL");
46 MODULE_VERSION("1.0.0");
47
48
49
50
51
52 #ifndef CONFIG_RADIO_GEMTEK_PORT
53 #define CONFIG_RADIO_GEMTEK_PORT -1
54 #endif
55 #ifndef CONFIG_RADIO_GEMTEK_PROBE
56 #define CONFIG_RADIO_GEMTEK_PROBE 1
57 #endif
58
59 #define GEMTEK_MAX 4
60
61 static bool probe = CONFIG_RADIO_GEMTEK_PROBE;
62 static bool hardmute;
63 static int io[GEMTEK_MAX] = { [0] = CONFIG_RADIO_GEMTEK_PORT,
64 [1 ... (GEMTEK_MAX - 1)] = -1 };
65 static int radio_nr[GEMTEK_MAX] = { [0 ... (GEMTEK_MAX - 1)] = -1 };
66
67 module_param(probe, bool, 0444);
68 MODULE_PARM_DESC(probe, "Enable automatic device probing.");
69
70 module_param(hardmute, bool, 0644);
71 MODULE_PARM_DESC(hardmute, "Enable 'hard muting' by shutting down PLL, may reduce static noise.");
72
73 module_param_array(io, int, NULL, 0444);
74 MODULE_PARM_DESC(io, "Force I/O ports for the GemTek Radio card if automatic probing is disabled or fails. The most common I/O ports are: 0x20c 0x30c, 0x24c or 0x34c (0x20c, 0x248 and 0x28c have been reported to work for the combined sound/radiocard).");
75
76 module_param_array(radio_nr, int, NULL, 0444);
77 MODULE_PARM_DESC(radio_nr, "Radio device numbers");
78
79
80
81
82
83 #define FSCALE 8
84 #define IF_OFFSET ((unsigned int)(10.52 * 16000 * (1<<FSCALE)))
85 #define REF_FREQ ((unsigned int)(6.39 * 16 * (1<<FSCALE)))
86
87 #define GEMTEK_CK 0x01
88 #define GEMTEK_DA 0x02
89 #define GEMTEK_CE 0x04
90 #define GEMTEK_NS 0x08
91 #define GEMTEK_MT 0x10
92 #define GEMTEK_STDF_3_125_KHZ 0x01
93 #define GEMTEK_PLL_OFF 0x07
94
95 #define BU2614_BUS_SIZE 32
96
97 #define SHORT_DELAY 5
98 #define LONG_DELAY 75
99
100 struct gemtek {
101 struct radio_isa_card isa;
102 bool muted;
103 u32 bu2614data;
104 };
105
106 #define BU2614_FREQ_BITS 16
107 #define BU2614_PORT_BITS 3
108 #define BU2614_VOID_BITS 4
109 #define BU2614_FMES_BITS 1
110 #define BU2614_STDF_BITS 3
111 #define BU2614_SWIN_BITS 1
112 #define BU2614_SWAL_BITS 1
113 #define BU2614_VOID2_BITS 1
114 #define BU2614_FMUN_BITS 1
115 #define BU2614_TEST_BITS 1
116
117 #define BU2614_FREQ_SHIFT 0
118 #define BU2614_PORT_SHIFT (BU2614_FREQ_BITS + BU2614_FREQ_SHIFT)
119 #define BU2614_VOID_SHIFT (BU2614_PORT_BITS + BU2614_PORT_SHIFT)
120 #define BU2614_FMES_SHIFT (BU2614_VOID_BITS + BU2614_VOID_SHIFT)
121 #define BU2614_STDF_SHIFT (BU2614_FMES_BITS + BU2614_FMES_SHIFT)
122 #define BU2614_SWIN_SHIFT (BU2614_STDF_BITS + BU2614_STDF_SHIFT)
123 #define BU2614_SWAL_SHIFT (BU2614_SWIN_BITS + BU2614_SWIN_SHIFT)
124 #define BU2614_VOID2_SHIFT (BU2614_SWAL_BITS + BU2614_SWAL_SHIFT)
125 #define BU2614_FMUN_SHIFT (BU2614_VOID2_BITS + BU2614_VOID2_SHIFT)
126 #define BU2614_TEST_SHIFT (BU2614_FMUN_BITS + BU2614_FMUN_SHIFT)
127
128 #define MKMASK(field) (((1UL<<BU2614_##field##_BITS) - 1) << \
129 BU2614_##field##_SHIFT)
130 #define BU2614_PORT_MASK MKMASK(PORT)
131 #define BU2614_FREQ_MASK MKMASK(FREQ)
132 #define BU2614_VOID_MASK MKMASK(VOID)
133 #define BU2614_FMES_MASK MKMASK(FMES)
134 #define BU2614_STDF_MASK MKMASK(STDF)
135 #define BU2614_SWIN_MASK MKMASK(SWIN)
136 #define BU2614_SWAL_MASK MKMASK(SWAL)
137 #define BU2614_VOID2_MASK MKMASK(VOID2)
138 #define BU2614_FMUN_MASK MKMASK(FMUN)
139 #define BU2614_TEST_MASK MKMASK(TEST)
140
141
142
143
144 #define gemtek_bu2614_set(dev, field, data) ((dev)->bu2614data = \
145 ((dev)->bu2614data & ~field##_MASK) | ((data) << field##_SHIFT))
146
147
148
149
150 static void gemtek_bu2614_transmit(struct gemtek *gt)
151 {
152 struct radio_isa_card *isa = >->isa;
153 int i, bit, q, mute;
154
155 mute = gt->muted ? GEMTEK_MT : 0x00;
156
157 outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, isa->io);
158 udelay(LONG_DELAY);
159
160 for (i = 0, q = gt->bu2614data; i < 32; i++, q >>= 1) {
161 bit = (q & 1) ? GEMTEK_DA : 0;
162 outb_p(mute | GEMTEK_CE | bit, isa->io);
163 udelay(SHORT_DELAY);
164 outb_p(mute | GEMTEK_CE | bit | GEMTEK_CK, isa->io);
165 udelay(SHORT_DELAY);
166 }
167
168 outb_p(mute | GEMTEK_DA | GEMTEK_CK, isa->io);
169 udelay(SHORT_DELAY);
170 }
171
172
173
174
175 static unsigned long gemtek_convfreq(unsigned long freq)
176 {
177 return ((freq << FSCALE) + IF_OFFSET + REF_FREQ / 2) / REF_FREQ;
178 }
179
180 static struct radio_isa_card *gemtek_alloc(void)
181 {
182 struct gemtek *gt = kzalloc(sizeof(*gt), GFP_KERNEL);
183
184 if (gt)
185 gt->muted = true;
186 return gt ? >->isa : NULL;
187 }
188
189
190
191
192 static int gemtek_s_frequency(struct radio_isa_card *isa, u32 freq)
193 {
194 struct gemtek *gt = container_of(isa, struct gemtek, isa);
195
196 if (hardmute && gt->muted)
197 return 0;
198
199 gemtek_bu2614_set(gt, BU2614_PORT, 0);
200 gemtek_bu2614_set(gt, BU2614_FMES, 0);
201 gemtek_bu2614_set(gt, BU2614_SWIN, 0);
202 gemtek_bu2614_set(gt, BU2614_SWAL, 0);
203 gemtek_bu2614_set(gt, BU2614_FMUN, 1);
204 gemtek_bu2614_set(gt, BU2614_TEST, 0);
205 gemtek_bu2614_set(gt, BU2614_STDF, GEMTEK_STDF_3_125_KHZ);
206 gemtek_bu2614_set(gt, BU2614_FREQ, gemtek_convfreq(freq));
207 gemtek_bu2614_transmit(gt);
208 return 0;
209 }
210
211
212
213
214 static int gemtek_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
215 {
216 struct gemtek *gt = container_of(isa, struct gemtek, isa);
217 int i;
218
219 gt->muted = mute;
220 if (hardmute) {
221 if (!mute)
222 return gemtek_s_frequency(isa, isa->freq);
223
224
225 gemtek_bu2614_set(gt, BU2614_PORT, 0);
226 gemtek_bu2614_set(gt, BU2614_FMES, 0);
227 gemtek_bu2614_set(gt, BU2614_SWIN, 0);
228 gemtek_bu2614_set(gt, BU2614_SWAL, 0);
229 gemtek_bu2614_set(gt, BU2614_FMUN, 0);
230 gemtek_bu2614_set(gt, BU2614_TEST, 0);
231 gemtek_bu2614_set(gt, BU2614_STDF, GEMTEK_PLL_OFF);
232 gemtek_bu2614_set(gt, BU2614_FREQ, 0);
233 gemtek_bu2614_transmit(gt);
234 return 0;
235 }
236
237
238 i = inb_p(isa->io);
239
240 outb_p((i >> 5) | (mute ? GEMTEK_MT : 0), isa->io);
241 udelay(SHORT_DELAY);
242 return 0;
243 }
244
245 static u32 gemtek_g_rxsubchans(struct radio_isa_card *isa)
246 {
247 if (inb_p(isa->io) & GEMTEK_NS)
248 return V4L2_TUNER_SUB_MONO;
249 return V4L2_TUNER_SUB_STEREO;
250 }
251
252
253
254
255 static bool gemtek_probe(struct radio_isa_card *isa, int io)
256 {
257 int i, q;
258
259 q = inb_p(io);
260
261
262 for (i = 0; i < 3; ++i) {
263 outb_p(1 << i, io);
264 udelay(SHORT_DELAY);
265
266 if ((inb_p(io) & ~GEMTEK_NS) != (0x17 | (1 << (i + 5))))
267 return false;
268 }
269 outb_p(q >> 5, io);
270 udelay(SHORT_DELAY);
271 return true;
272 }
273
274 static const struct radio_isa_ops gemtek_ops = {
275 .alloc = gemtek_alloc,
276 .probe = gemtek_probe,
277 .s_mute_volume = gemtek_s_mute_volume,
278 .s_frequency = gemtek_s_frequency,
279 .g_rxsubchans = gemtek_g_rxsubchans,
280 };
281
282 static const int gemtek_ioports[] = { 0x20c, 0x30c, 0x24c, 0x34c, 0x248, 0x28c };
283
284 #ifdef CONFIG_PNP
285 static const struct pnp_device_id gemtek_pnp_devices[] = {
286
287 {.id = "ADS7183", .driver_data = 0},
288 {.id = ""}
289 };
290
291 MODULE_DEVICE_TABLE(pnp, gemtek_pnp_devices);
292 #endif
293
294 static struct radio_isa_driver gemtek_driver = {
295 .driver = {
296 .match = radio_isa_match,
297 .probe = radio_isa_probe,
298 .remove = radio_isa_remove,
299 .driver = {
300 .name = "radio-gemtek",
301 },
302 },
303 #ifdef CONFIG_PNP
304 .pnp_driver = {
305 .name = "radio-gemtek",
306 .id_table = gemtek_pnp_devices,
307 .probe = radio_isa_pnp_probe,
308 .remove = radio_isa_pnp_remove,
309 },
310 #endif
311 .io_params = io,
312 .radio_nr_params = radio_nr,
313 .io_ports = gemtek_ioports,
314 .num_of_io_ports = ARRAY_SIZE(gemtek_ioports),
315 .region_size = 1,
316 .card = "GemTek Radio",
317 .ops = &gemtek_ops,
318 .has_stereo = true,
319 };
320
321 static int __init gemtek_init(void)
322 {
323 gemtek_driver.probe = probe;
324 #ifdef CONFIG_PNP
325 pnp_register_driver(&gemtek_driver.pnp_driver);
326 #endif
327 return isa_register_driver(&gemtek_driver.driver, GEMTEK_MAX);
328 }
329
330 static void __exit gemtek_exit(void)
331 {
332 hardmute = true;
333 #ifdef CONFIG_PNP
334 pnp_unregister_driver(&gemtek_driver.pnp_driver);
335 #endif
336 isa_unregister_driver(&gemtek_driver.driver);
337 }
338
339 module_init(gemtek_init);
340 module_exit(gemtek_exit);