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