This source file includes following definitions.
- zoltrix_alloc
- zoltrix_s_mute_volume
- zoltrix_s_frequency
- zoltrix_g_rxsubchans
- zoltrix_g_signal
- zoltrix_s_stereo
- zoltrix_init
- zoltrix_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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 #include <linux/module.h>
43 #include <linux/init.h>
44 #include <linux/ioport.h>
45 #include <linux/delay.h>
46 #include <linux/videodev2.h>
47 #include <linux/mutex.h>
48 #include <linux/io.h>
49 #include <linux/slab.h>
50 #include <media/v4l2-device.h>
51 #include <media/v4l2-ioctl.h>
52 #include "radio-isa.h"
53
54 MODULE_AUTHOR("C. van Schaik");
55 MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
56 MODULE_LICENSE("GPL");
57 MODULE_VERSION("0.1.99");
58
59 #ifndef CONFIG_RADIO_ZOLTRIX_PORT
60 #define CONFIG_RADIO_ZOLTRIX_PORT -1
61 #endif
62
63 #define ZOLTRIX_MAX 2
64
65 static int io[ZOLTRIX_MAX] = { [0] = CONFIG_RADIO_ZOLTRIX_PORT,
66 [1 ... (ZOLTRIX_MAX - 1)] = -1 };
67 static int radio_nr[ZOLTRIX_MAX] = { [0 ... (ZOLTRIX_MAX - 1)] = -1 };
68
69 module_param_array(io, int, NULL, 0444);
70 MODULE_PARM_DESC(io, "I/O addresses of the Zoltrix Radio Plus card (0x20c or 0x30c)");
71 module_param_array(radio_nr, int, NULL, 0444);
72 MODULE_PARM_DESC(radio_nr, "Radio device numbers");
73
74 struct zoltrix {
75 struct radio_isa_card isa;
76 int curvol;
77 bool muted;
78 };
79
80 static struct radio_isa_card *zoltrix_alloc(void)
81 {
82 struct zoltrix *zol = kzalloc(sizeof(*zol), GFP_KERNEL);
83
84 return zol ? &zol->isa : NULL;
85 }
86
87 static int zoltrix_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
88 {
89 struct zoltrix *zol = container_of(isa, struct zoltrix, isa);
90
91 zol->curvol = vol;
92 zol->muted = mute;
93 if (mute || vol == 0) {
94 outb(0, isa->io);
95 outb(0, isa->io);
96 inb(isa->io + 3);
97 return 0;
98 }
99
100 outb(vol - 1, isa->io);
101 msleep(10);
102 inb(isa->io + 2);
103 return 0;
104 }
105
106
107 static int zoltrix_s_frequency(struct radio_isa_card *isa, u32 freq)
108 {
109 struct zoltrix *zol = container_of(isa, struct zoltrix, isa);
110 struct v4l2_device *v4l2_dev = &isa->v4l2_dev;
111 unsigned long long bitmask, f, m;
112 bool stereo = isa->stereo;
113 int i;
114
115 if (freq == 0) {
116 v4l2_warn(v4l2_dev, "cannot set a frequency of 0.\n");
117 return -EINVAL;
118 }
119
120 m = (freq / 160 - 8800) * 2;
121 f = (unsigned long long)m + 0x4d1c;
122
123 bitmask = 0xc480402c10080000ull;
124 i = 45;
125
126 outb(0, isa->io);
127 outb(0, isa->io);
128 inb(isa->io + 3);
129
130 outb(0x40, isa->io);
131 outb(0xc0, isa->io);
132
133 bitmask = (bitmask ^ ((f & 0xff) << 47) ^ ((f & 0xff00) << 30) ^ (stereo << 31));
134 while (i--) {
135 if ((bitmask & 0x8000000000000000ull) != 0) {
136 outb(0x80, isa->io);
137 udelay(50);
138 outb(0x00, isa->io);
139 udelay(50);
140 outb(0x80, isa->io);
141 udelay(50);
142 } else {
143 outb(0xc0, isa->io);
144 udelay(50);
145 outb(0x40, isa->io);
146 udelay(50);
147 outb(0xc0, isa->io);
148 udelay(50);
149 }
150 bitmask *= 2;
151 }
152
153 outb(0x80, isa->io);
154 outb(0xc0, isa->io);
155 outb(0x40, isa->io);
156 udelay(1000);
157 inb(isa->io + 2);
158 udelay(1000);
159
160 return zoltrix_s_mute_volume(isa, zol->muted, zol->curvol);
161 }
162
163
164 static u32 zoltrix_g_rxsubchans(struct radio_isa_card *isa)
165 {
166 struct zoltrix *zol = container_of(isa, struct zoltrix, isa);
167 int a, b;
168
169 outb(0x00, isa->io);
170 outb(zol->curvol, isa->io);
171 msleep(20);
172
173 a = inb(isa->io);
174 msleep(10);
175 b = inb(isa->io);
176
177 return (a == b && a == 0xcf) ?
178 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
179 }
180
181 static u32 zoltrix_g_signal(struct radio_isa_card *isa)
182 {
183 struct zoltrix *zol = container_of(isa, struct zoltrix, isa);
184 int a, b;
185
186 outb(0x00, isa->io);
187 outb(zol->curvol, isa->io);
188 msleep(20);
189
190 a = inb(isa->io);
191 msleep(10);
192 b = inb(isa->io);
193
194 if (a != b)
195 return 0;
196
197
198 return (a == 0xcf || a == 0xdf || a == 0xef) ? 0xffff : 0;
199 }
200
201 static int zoltrix_s_stereo(struct radio_isa_card *isa, bool stereo)
202 {
203 return zoltrix_s_frequency(isa, isa->freq);
204 }
205
206 static const struct radio_isa_ops zoltrix_ops = {
207 .alloc = zoltrix_alloc,
208 .s_mute_volume = zoltrix_s_mute_volume,
209 .s_frequency = zoltrix_s_frequency,
210 .s_stereo = zoltrix_s_stereo,
211 .g_rxsubchans = zoltrix_g_rxsubchans,
212 .g_signal = zoltrix_g_signal,
213 };
214
215 static const int zoltrix_ioports[] = { 0x20c, 0x30c };
216
217 static struct radio_isa_driver zoltrix_driver = {
218 .driver = {
219 .match = radio_isa_match,
220 .probe = radio_isa_probe,
221 .remove = radio_isa_remove,
222 .driver = {
223 .name = "radio-zoltrix",
224 },
225 },
226 .io_params = io,
227 .radio_nr_params = radio_nr,
228 .io_ports = zoltrix_ioports,
229 .num_of_io_ports = ARRAY_SIZE(zoltrix_ioports),
230 .region_size = 2,
231 .card = "Zoltrix Radio Plus",
232 .ops = &zoltrix_ops,
233 .has_stereo = true,
234 .max_volume = 15,
235 };
236
237 static int __init zoltrix_init(void)
238 {
239 return isa_register_driver(&zoltrix_driver.driver, ZOLTRIX_MAX);
240 }
241
242 static void __exit zoltrix_exit(void)
243 {
244 isa_unregister_driver(&zoltrix_driver.driver);
245 }
246
247 module_init(zoltrix_init);
248 module_exit(zoltrix_exit);
249