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
27
28
29
30
31
32#include <linux/module.h>
33#include <linux/init.h>
34#include <linux/ioport.h>
35#include <linux/videodev2.h>
36#include <linux/io.h>
37#include <linux/slab.h>
38#include <media/v4l2-device.h>
39#include <media/v4l2-ioctl.h>
40#include "radio-isa.h"
41
42#define DRIVER_VERSION "0.1.2"
43
44MODULE_AUTHOR("Dr. Henrik Seidel");
45MODULE_DESCRIPTION("A driver for the Typhoon radio card (a.k.a. EcoRadio).");
46MODULE_LICENSE("GPL");
47MODULE_VERSION("0.1.99");
48
49#ifndef CONFIG_RADIO_TYPHOON_PORT
50#define CONFIG_RADIO_TYPHOON_PORT -1
51#endif
52
53#ifndef CONFIG_RADIO_TYPHOON_MUTEFREQ
54#define CONFIG_RADIO_TYPHOON_MUTEFREQ 87000
55#endif
56
57#define TYPHOON_MAX 2
58
59static int io[TYPHOON_MAX] = { [0] = CONFIG_RADIO_TYPHOON_PORT,
60 [1 ... (TYPHOON_MAX - 1)] = -1 };
61static int radio_nr[TYPHOON_MAX] = { [0 ... (TYPHOON_MAX - 1)] = -1 };
62static unsigned long mutefreq = CONFIG_RADIO_TYPHOON_MUTEFREQ;
63
64module_param_array(io, int, NULL, 0444);
65MODULE_PARM_DESC(io, "I/O addresses of the Typhoon card (0x316 or 0x336)");
66module_param_array(radio_nr, int, NULL, 0444);
67MODULE_PARM_DESC(radio_nr, "Radio device numbers");
68module_param(mutefreq, ulong, 0);
69MODULE_PARM_DESC(mutefreq, "Frequency used when muting the card (in kHz)");
70
71struct typhoon {
72 struct radio_isa_card isa;
73 int muted;
74};
75
76static struct radio_isa_card *typhoon_alloc(void)
77{
78 struct typhoon *ty = kzalloc(sizeof(*ty), GFP_KERNEL);
79
80 return ty ? &ty->isa : NULL;
81}
82
83static int typhoon_s_frequency(struct radio_isa_card *isa, u32 freq)
84{
85 unsigned long outval;
86 unsigned long x;
87
88
89
90
91
92
93
94
95
96
97
98
99 x = freq / 160;
100 outval = (x * x + 2500) / 5000;
101 outval = (outval * x + 5000) / 10000;
102 outval -= (10 * x * x + 10433) / 20866;
103 outval += 4 * x - 11505;
104
105 outb_p((outval >> 8) & 0x01, isa->io + 4);
106 outb_p(outval >> 9, isa->io + 6);
107 outb_p(outval & 0xff, isa->io + 8);
108 return 0;
109}
110
111static int typhoon_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
112{
113 struct typhoon *ty = container_of(isa, struct typhoon, isa);
114
115 if (mute)
116 vol = 0;
117 vol >>= 14;
118 vol &= 3;
119 outb_p(vol / 2, isa->io);
120 outb_p(vol % 2, isa->io + 2);
121
122 if (vol == 0 && !ty->muted) {
123 ty->muted = true;
124 return typhoon_s_frequency(isa, mutefreq << 4);
125 }
126 if (vol && ty->muted) {
127 ty->muted = false;
128 return typhoon_s_frequency(isa, isa->freq);
129 }
130 return 0;
131}
132
133static const struct radio_isa_ops typhoon_ops = {
134 .alloc = typhoon_alloc,
135 .s_mute_volume = typhoon_s_mute_volume,
136 .s_frequency = typhoon_s_frequency,
137};
138
139static const int typhoon_ioports[] = { 0x316, 0x336 };
140
141static struct radio_isa_driver typhoon_driver = {
142 .driver = {
143 .match = radio_isa_match,
144 .probe = radio_isa_probe,
145 .remove = radio_isa_remove,
146 .driver = {
147 .name = "radio-typhoon",
148 },
149 },
150 .io_params = io,
151 .radio_nr_params = radio_nr,
152 .io_ports = typhoon_ioports,
153 .num_of_io_ports = ARRAY_SIZE(typhoon_ioports),
154 .region_size = 8,
155 .card = "Typhoon Radio",
156 .ops = &typhoon_ops,
157 .has_stereo = true,
158 .max_volume = 3,
159};
160
161static int __init typhoon_init(void)
162{
163 if (mutefreq < 87000 || mutefreq > 108000) {
164 printk(KERN_ERR "%s: You must set a frequency (in kHz) used when muting the card,\n",
165 typhoon_driver.driver.driver.name);
166 printk(KERN_ERR "%s: e.g. with \"mutefreq=87500\" (87000 <= mutefreq <= 108000)\n",
167 typhoon_driver.driver.driver.name);
168 return -ENODEV;
169 }
170 return isa_register_driver(&typhoon_driver.driver, TYPHOON_MAX);
171}
172
173static void __exit typhoon_exit(void)
174{
175 isa_unregister_driver(&typhoon_driver.driver);
176}
177
178
179module_init(typhoon_init);
180module_exit(typhoon_exit);
181
182