diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2009-03-06 11:54:52 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-03-30 11:43:13 -0400 |
commit | f1bfe89b6721ba9ad8c3c6e67cce58d5616cd012 (patch) | |
tree | ce4b08ce0541fe5971daade475c55002d7f0f5f8 /drivers/media | |
parent | 1dc8aafc79ab9bde6b53cc3696cb0b032fb2fc3d (diff) |
V4L/DVB (10892): radio-typhoon: convert to v4l2_device.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/radio/radio-typhoon.c | 350 |
1 files changed, 141 insertions, 209 deletions
diff --git a/drivers/media/radio/radio-typhoon.c b/drivers/media/radio/radio-typhoon.c index 5c3b319dab37..2090df44d508 100644 --- a/drivers/media/radio/radio-typhoon.c +++ b/drivers/media/radio/radio-typhoon.c | |||
@@ -34,37 +34,16 @@ | |||
34 | #include <linux/module.h> /* Modules */ | 34 | #include <linux/module.h> /* Modules */ |
35 | #include <linux/init.h> /* Initdata */ | 35 | #include <linux/init.h> /* Initdata */ |
36 | #include <linux/ioport.h> /* request_region */ | 36 | #include <linux/ioport.h> /* request_region */ |
37 | #include <linux/proc_fs.h> /* radio card status report */ | 37 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ |
38 | #include <linux/seq_file.h> | ||
39 | #include <asm/io.h> /* outb, outb_p */ | ||
40 | #include <asm/uaccess.h> /* copy to/from user */ | ||
41 | #include <linux/videodev2.h> /* kernel radio structs */ | 38 | #include <linux/videodev2.h> /* kernel radio structs */ |
42 | #include <media/v4l2-common.h> | 39 | #include <linux/io.h> /* outb, outb_p */ |
40 | #include <linux/uaccess.h> /* copy to/from user */ | ||
41 | #include <media/v4l2-device.h> | ||
43 | #include <media/v4l2-ioctl.h> | 42 | #include <media/v4l2-ioctl.h> |
44 | 43 | ||
45 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ | 44 | MODULE_AUTHOR("Dr. Henrik Seidel"); |
46 | #define RADIO_VERSION KERNEL_VERSION(0,1,1) | 45 | MODULE_DESCRIPTION("A driver for the Typhoon radio card (a.k.a. EcoRadio)."); |
47 | #define BANNER "Typhoon Radio Card driver v0.1.1\n" | 46 | MODULE_LICENSE("GPL"); |
48 | |||
49 | static struct v4l2_queryctrl radio_qctrl[] = { | ||
50 | { | ||
51 | .id = V4L2_CID_AUDIO_MUTE, | ||
52 | .name = "Mute", | ||
53 | .minimum = 0, | ||
54 | .maximum = 1, | ||
55 | .default_value = 1, | ||
56 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
57 | },{ | ||
58 | .id = V4L2_CID_AUDIO_VOLUME, | ||
59 | .name = "Volume", | ||
60 | .minimum = 0, | ||
61 | .maximum = 65535, | ||
62 | .step = 1<<14, | ||
63 | .default_value = 0xff, | ||
64 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
65 | } | ||
66 | }; | ||
67 | |||
68 | 47 | ||
69 | #ifndef CONFIG_RADIO_TYPHOON_PORT | 48 | #ifndef CONFIG_RADIO_TYPHOON_PORT |
70 | #define CONFIG_RADIO_TYPHOON_PORT -1 | 49 | #define CONFIG_RADIO_TYPHOON_PORT -1 |
@@ -74,13 +53,26 @@ static struct v4l2_queryctrl radio_qctrl[] = { | |||
74 | #define CONFIG_RADIO_TYPHOON_MUTEFREQ 0 | 53 | #define CONFIG_RADIO_TYPHOON_MUTEFREQ 0 |
75 | #endif | 54 | #endif |
76 | 55 | ||
77 | #ifndef CONFIG_PROC_FS | 56 | static int io = CONFIG_RADIO_TYPHOON_PORT; |
78 | #undef CONFIG_RADIO_TYPHOON_PROC_FS | 57 | static int radio_nr = -1; |
79 | #endif | ||
80 | 58 | ||
81 | struct typhoon_device { | 59 | module_param(io, int, 0); |
82 | unsigned long in_use; | 60 | MODULE_PARM_DESC(io, "I/O address of the Typhoon card (0x316 or 0x336)"); |
83 | int iobase; | 61 | |
62 | module_param(radio_nr, int, 0); | ||
63 | |||
64 | static unsigned long mutefreq = CONFIG_RADIO_TYPHOON_MUTEFREQ; | ||
65 | module_param(mutefreq, ulong, 0); | ||
66 | MODULE_PARM_DESC(mutefreq, "Frequency used when muting the card (in kHz)"); | ||
67 | |||
68 | #define RADIO_VERSION KERNEL_VERSION(0, 1, 1) | ||
69 | |||
70 | #define BANNER "Typhoon Radio Card driver v0.1.1\n" | ||
71 | |||
72 | struct typhoon { | ||
73 | struct v4l2_device v4l2_dev; | ||
74 | struct video_device vdev; | ||
75 | int io; | ||
84 | int curvol; | 76 | int curvol; |
85 | int muted; | 77 | int muted; |
86 | unsigned long curfreq; | 78 | unsigned long curfreq; |
@@ -88,25 +80,19 @@ struct typhoon_device { | |||
88 | struct mutex lock; | 80 | struct mutex lock; |
89 | }; | 81 | }; |
90 | 82 | ||
91 | static void typhoon_setvol_generic(struct typhoon_device *dev, int vol); | 83 | static struct typhoon typhoon_card; |
92 | static int typhoon_setfreq_generic(struct typhoon_device *dev, | ||
93 | unsigned long frequency); | ||
94 | static int typhoon_setfreq(struct typhoon_device *dev, unsigned long frequency); | ||
95 | static void typhoon_mute(struct typhoon_device *dev); | ||
96 | static void typhoon_unmute(struct typhoon_device *dev); | ||
97 | static int typhoon_setvol(struct typhoon_device *dev, int vol); | ||
98 | 84 | ||
99 | static void typhoon_setvol_generic(struct typhoon_device *dev, int vol) | 85 | static void typhoon_setvol_generic(struct typhoon *dev, int vol) |
100 | { | 86 | { |
101 | mutex_lock(&dev->lock); | 87 | mutex_lock(&dev->lock); |
102 | vol >>= 14; /* Map 16 bit to 2 bit */ | 88 | vol >>= 14; /* Map 16 bit to 2 bit */ |
103 | vol &= 3; | 89 | vol &= 3; |
104 | outb_p(vol / 2, dev->iobase); /* Set the volume, high bit. */ | 90 | outb_p(vol / 2, dev->io); /* Set the volume, high bit. */ |
105 | outb_p(vol % 2, dev->iobase + 2); /* Set the volume, low bit. */ | 91 | outb_p(vol % 2, dev->io + 2); /* Set the volume, low bit. */ |
106 | mutex_unlock(&dev->lock); | 92 | mutex_unlock(&dev->lock); |
107 | } | 93 | } |
108 | 94 | ||
109 | static int typhoon_setfreq_generic(struct typhoon_device *dev, | 95 | static int typhoon_setfreq_generic(struct typhoon *dev, |
110 | unsigned long frequency) | 96 | unsigned long frequency) |
111 | { | 97 | { |
112 | unsigned long outval; | 98 | unsigned long outval; |
@@ -130,22 +116,22 @@ static int typhoon_setfreq_generic(struct typhoon_device *dev, | |||
130 | outval -= (10 * x * x + 10433) / 20866; | 116 | outval -= (10 * x * x + 10433) / 20866; |
131 | outval += 4 * x - 11505; | 117 | outval += 4 * x - 11505; |
132 | 118 | ||
133 | outb_p((outval >> 8) & 0x01, dev->iobase + 4); | 119 | outb_p((outval >> 8) & 0x01, dev->io + 4); |
134 | outb_p(outval >> 9, dev->iobase + 6); | 120 | outb_p(outval >> 9, dev->io + 6); |
135 | outb_p(outval & 0xff, dev->iobase + 8); | 121 | outb_p(outval & 0xff, dev->io + 8); |
136 | mutex_unlock(&dev->lock); | 122 | mutex_unlock(&dev->lock); |
137 | 123 | ||
138 | return 0; | 124 | return 0; |
139 | } | 125 | } |
140 | 126 | ||
141 | static int typhoon_setfreq(struct typhoon_device *dev, unsigned long frequency) | 127 | static int typhoon_setfreq(struct typhoon *dev, unsigned long frequency) |
142 | { | 128 | { |
143 | typhoon_setfreq_generic(dev, frequency); | 129 | typhoon_setfreq_generic(dev, frequency); |
144 | dev->curfreq = frequency; | 130 | dev->curfreq = frequency; |
145 | return 0; | 131 | return 0; |
146 | } | 132 | } |
147 | 133 | ||
148 | static void typhoon_mute(struct typhoon_device *dev) | 134 | static void typhoon_mute(struct typhoon *dev) |
149 | { | 135 | { |
150 | if (dev->muted == 1) | 136 | if (dev->muted == 1) |
151 | return; | 137 | return; |
@@ -154,7 +140,7 @@ static void typhoon_mute(struct typhoon_device *dev) | |||
154 | dev->muted = 1; | 140 | dev->muted = 1; |
155 | } | 141 | } |
156 | 142 | ||
157 | static void typhoon_unmute(struct typhoon_device *dev) | 143 | static void typhoon_unmute(struct typhoon *dev) |
158 | { | 144 | { |
159 | if (dev->muted == 0) | 145 | if (dev->muted == 0) |
160 | return; | 146 | return; |
@@ -163,7 +149,7 @@ static void typhoon_unmute(struct typhoon_device *dev) | |||
163 | dev->muted = 0; | 149 | dev->muted = 0; |
164 | } | 150 | } |
165 | 151 | ||
166 | static int typhoon_setvol(struct typhoon_device *dev, int vol) | 152 | static int typhoon_setvol(struct typhoon *dev, int vol) |
167 | { | 153 | { |
168 | if (dev->muted && vol != 0) { /* user is unmuting the card */ | 154 | if (dev->muted && vol != 0) { /* user is unmuting the card */ |
169 | dev->curvol = vol; | 155 | dev->curvol = vol; |
@@ -188,9 +174,9 @@ static int vidioc_querycap(struct file *file, void *priv, | |||
188 | { | 174 | { |
189 | strlcpy(v->driver, "radio-typhoon", sizeof(v->driver)); | 175 | strlcpy(v->driver, "radio-typhoon", sizeof(v->driver)); |
190 | strlcpy(v->card, "Typhoon Radio", sizeof(v->card)); | 176 | strlcpy(v->card, "Typhoon Radio", sizeof(v->card)); |
191 | sprintf(v->bus_info, "ISA"); | 177 | strlcpy(v->bus_info, "ISA", sizeof(v->bus_info)); |
192 | v->version = RADIO_VERSION; | 178 | v->version = RADIO_VERSION; |
193 | v->capabilities = V4L2_CAP_TUNER; | 179 | v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
194 | return 0; | 180 | return 0; |
195 | } | 181 | } |
196 | 182 | ||
@@ -200,10 +186,10 @@ static int vidioc_g_tuner(struct file *file, void *priv, | |||
200 | if (v->index > 0) | 186 | if (v->index > 0) |
201 | return -EINVAL; | 187 | return -EINVAL; |
202 | 188 | ||
203 | strcpy(v->name, "FM"); | 189 | strlcpy(v->name, "FM", sizeof(v->name)); |
204 | v->type = V4L2_TUNER_RADIO; | 190 | v->type = V4L2_TUNER_RADIO; |
205 | v->rangelow = (87.5*16000); | 191 | v->rangelow = 87.5 * 16000; |
206 | v->rangehigh = (108*16000); | 192 | v->rangehigh = 108 * 16000; |
207 | v->rxsubchans = V4L2_TUNER_SUB_MONO; | 193 | v->rxsubchans = V4L2_TUNER_SUB_MONO; |
208 | v->capability = V4L2_TUNER_CAP_LOW; | 194 | v->capability = V4L2_TUNER_CAP_LOW; |
209 | v->audmode = V4L2_TUNER_MODE_MONO; | 195 | v->audmode = V4L2_TUNER_MODE_MONO; |
@@ -214,44 +200,37 @@ static int vidioc_g_tuner(struct file *file, void *priv, | |||
214 | static int vidioc_s_tuner(struct file *file, void *priv, | 200 | static int vidioc_s_tuner(struct file *file, void *priv, |
215 | struct v4l2_tuner *v) | 201 | struct v4l2_tuner *v) |
216 | { | 202 | { |
217 | if (v->index > 0) | 203 | return v->index ? -EINVAL : 0; |
218 | return -EINVAL; | ||
219 | |||
220 | return 0; | ||
221 | } | 204 | } |
222 | 205 | ||
223 | static int vidioc_s_frequency(struct file *file, void *priv, | 206 | static int vidioc_g_frequency(struct file *file, void *priv, |
224 | struct v4l2_frequency *f) | 207 | struct v4l2_frequency *f) |
225 | { | 208 | { |
226 | struct typhoon_device *typhoon = video_drvdata(file); | 209 | struct typhoon *dev = video_drvdata(file); |
227 | 210 | ||
228 | typhoon->curfreq = f->frequency; | 211 | f->type = V4L2_TUNER_RADIO; |
229 | typhoon_setfreq(typhoon, typhoon->curfreq); | 212 | f->frequency = dev->curfreq; |
230 | return 0; | 213 | return 0; |
231 | } | 214 | } |
232 | 215 | ||
233 | static int vidioc_g_frequency(struct file *file, void *priv, | 216 | static int vidioc_s_frequency(struct file *file, void *priv, |
234 | struct v4l2_frequency *f) | 217 | struct v4l2_frequency *f) |
235 | { | 218 | { |
236 | struct typhoon_device *typhoon = video_drvdata(file); | 219 | struct typhoon *dev = video_drvdata(file); |
237 | |||
238 | f->type = V4L2_TUNER_RADIO; | ||
239 | f->frequency = typhoon->curfreq; | ||
240 | 220 | ||
221 | dev->curfreq = f->frequency; | ||
222 | typhoon_setfreq(dev, dev->curfreq); | ||
241 | return 0; | 223 | return 0; |
242 | } | 224 | } |
243 | 225 | ||
244 | static int vidioc_queryctrl(struct file *file, void *priv, | 226 | static int vidioc_queryctrl(struct file *file, void *priv, |
245 | struct v4l2_queryctrl *qc) | 227 | struct v4l2_queryctrl *qc) |
246 | { | 228 | { |
247 | int i; | 229 | switch (qc->id) { |
248 | 230 | case V4L2_CID_AUDIO_MUTE: | |
249 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { | 231 | return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1); |
250 | if (qc->id && qc->id == radio_qctrl[i].id) { | 232 | case V4L2_CID_AUDIO_VOLUME: |
251 | memcpy(qc, &(radio_qctrl[i]), | 233 | return v4l2_ctrl_query_fill(qc, 0, 65535, 16384, 65535); |
252 | sizeof(*qc)); | ||
253 | return 0; | ||
254 | } | ||
255 | } | 234 | } |
256 | return -EINVAL; | 235 | return -EINVAL; |
257 | } | 236 | } |
@@ -259,14 +238,14 @@ static int vidioc_queryctrl(struct file *file, void *priv, | |||
259 | static int vidioc_g_ctrl(struct file *file, void *priv, | 238 | static int vidioc_g_ctrl(struct file *file, void *priv, |
260 | struct v4l2_control *ctrl) | 239 | struct v4l2_control *ctrl) |
261 | { | 240 | { |
262 | struct typhoon_device *typhoon = video_drvdata(file); | 241 | struct typhoon *dev = video_drvdata(file); |
263 | 242 | ||
264 | switch (ctrl->id) { | 243 | switch (ctrl->id) { |
265 | case V4L2_CID_AUDIO_MUTE: | 244 | case V4L2_CID_AUDIO_MUTE: |
266 | ctrl->value = typhoon->muted; | 245 | ctrl->value = dev->muted; |
267 | return 0; | 246 | return 0; |
268 | case V4L2_CID_AUDIO_VOLUME: | 247 | case V4L2_CID_AUDIO_VOLUME: |
269 | ctrl->value = typhoon->curvol; | 248 | ctrl->value = dev->curvol; |
270 | return 0; | 249 | return 0; |
271 | } | 250 | } |
272 | return -EINVAL; | 251 | return -EINVAL; |
@@ -275,33 +254,22 @@ static int vidioc_g_ctrl(struct file *file, void *priv, | |||
275 | static int vidioc_s_ctrl (struct file *file, void *priv, | 254 | static int vidioc_s_ctrl (struct file *file, void *priv, |
276 | struct v4l2_control *ctrl) | 255 | struct v4l2_control *ctrl) |
277 | { | 256 | { |
278 | struct typhoon_device *typhoon = video_drvdata(file); | 257 | struct typhoon *dev = video_drvdata(file); |
279 | 258 | ||
280 | switch (ctrl->id) { | 259 | switch (ctrl->id) { |
281 | case V4L2_CID_AUDIO_MUTE: | 260 | case V4L2_CID_AUDIO_MUTE: |
282 | if (ctrl->value) | 261 | if (ctrl->value) |
283 | typhoon_mute(typhoon); | 262 | typhoon_mute(dev); |
284 | else | 263 | else |
285 | typhoon_unmute(typhoon); | 264 | typhoon_unmute(dev); |
286 | return 0; | 265 | return 0; |
287 | case V4L2_CID_AUDIO_VOLUME: | 266 | case V4L2_CID_AUDIO_VOLUME: |
288 | typhoon_setvol(typhoon, ctrl->value); | 267 | typhoon_setvol(dev, ctrl->value); |
289 | return 0; | 268 | return 0; |
290 | } | 269 | } |
291 | return -EINVAL; | 270 | return -EINVAL; |
292 | } | 271 | } |
293 | 272 | ||
294 | static int vidioc_g_audio(struct file *file, void *priv, | ||
295 | struct v4l2_audio *a) | ||
296 | { | ||
297 | if (a->index > 1) | ||
298 | return -EINVAL; | ||
299 | |||
300 | strcpy(a->name, "Radio"); | ||
301 | a->capability = V4L2_AUDCAP_STEREO; | ||
302 | return 0; | ||
303 | } | ||
304 | |||
305 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) | 273 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
306 | { | 274 | { |
307 | *i = 0; | 275 | *i = 0; |
@@ -310,45 +278,62 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) | |||
310 | 278 | ||
311 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) | 279 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
312 | { | 280 | { |
313 | if (i != 0) | 281 | return i ? -EINVAL : 0; |
314 | return -EINVAL; | 282 | } |
283 | |||
284 | static int vidioc_g_audio(struct file *file, void *priv, | ||
285 | struct v4l2_audio *a) | ||
286 | { | ||
287 | a->index = 0; | ||
288 | strlcpy(a->name, "Radio", sizeof(a->name)); | ||
289 | a->capability = V4L2_AUDCAP_STEREO; | ||
315 | return 0; | 290 | return 0; |
316 | } | 291 | } |
317 | 292 | ||
318 | static int vidioc_s_audio(struct file *file, void *priv, | 293 | static int vidioc_s_audio(struct file *file, void *priv, |
319 | struct v4l2_audio *a) | 294 | struct v4l2_audio *a) |
320 | { | 295 | { |
321 | if (a->index != 0) | 296 | return a->index ? -EINVAL : 0; |
322 | return -EINVAL; | ||
323 | return 0; | ||
324 | } | 297 | } |
325 | 298 | ||
326 | static struct typhoon_device typhoon_unit = | 299 | static int vidioc_log_status(struct file *file, void *priv) |
327 | { | 300 | { |
328 | .iobase = CONFIG_RADIO_TYPHOON_PORT, | 301 | struct typhoon *dev = video_drvdata(file); |
329 | .curfreq = CONFIG_RADIO_TYPHOON_MUTEFREQ, | 302 | struct v4l2_device *v4l2_dev = &dev->v4l2_dev; |
330 | .mutefreq = CONFIG_RADIO_TYPHOON_MUTEFREQ, | 303 | |
331 | }; | 304 | v4l2_info(v4l2_dev, BANNER); |
305 | #ifdef MODULE | ||
306 | v4l2_info(v4l2_dev, "Load type: Driver loaded as a module\n\n"); | ||
307 | #else | ||
308 | v4l2_info(v4l2_dev, "Load type: Driver compiled into kernel\n\n"); | ||
309 | #endif | ||
310 | v4l2_info(v4l2_dev, "frequency = %lu kHz\n", dev->curfreq >> 4); | ||
311 | v4l2_info(v4l2_dev, "volume = %d\n", dev->curvol); | ||
312 | v4l2_info(v4l2_dev, "mute = %s\n", dev->muted ? "on" : "off"); | ||
313 | v4l2_info(v4l2_dev, "io = 0x%x\n", dev->io); | ||
314 | v4l2_info(v4l2_dev, "mute frequency = %lu kHz\n", dev->mutefreq >> 4); | ||
315 | return 0; | ||
316 | } | ||
332 | 317 | ||
333 | static int typhoon_exclusive_open(struct file *file) | 318 | static int typhoon_open(struct file *file) |
334 | { | 319 | { |
335 | return test_and_set_bit(0, &typhoon_unit.in_use) ? -EBUSY : 0; | 320 | return 0; |
336 | } | 321 | } |
337 | 322 | ||
338 | static int typhoon_exclusive_release(struct file *file) | 323 | static int typhoon_release(struct file *file) |
339 | { | 324 | { |
340 | clear_bit(0, &typhoon_unit.in_use); | ||
341 | return 0; | 325 | return 0; |
342 | } | 326 | } |
343 | 327 | ||
344 | static const struct v4l2_file_operations typhoon_fops = { | 328 | static const struct v4l2_file_operations typhoon_fops = { |
345 | .owner = THIS_MODULE, | 329 | .owner = THIS_MODULE, |
346 | .open = typhoon_exclusive_open, | 330 | .open = typhoon_open, |
347 | .release = typhoon_exclusive_release, | 331 | .release = typhoon_release, |
348 | .ioctl = video_ioctl2, | 332 | .ioctl = video_ioctl2, |
349 | }; | 333 | }; |
350 | 334 | ||
351 | static const struct v4l2_ioctl_ops typhoon_ioctl_ops = { | 335 | static const struct v4l2_ioctl_ops typhoon_ioctl_ops = { |
336 | .vidioc_log_status = vidioc_log_status, | ||
352 | .vidioc_querycap = vidioc_querycap, | 337 | .vidioc_querycap = vidioc_querycap, |
353 | .vidioc_g_tuner = vidioc_g_tuner, | 338 | .vidioc_g_tuner = vidioc_g_tuner, |
354 | .vidioc_s_tuner = vidioc_s_tuner, | 339 | .vidioc_s_tuner = vidioc_s_tuner, |
@@ -363,125 +348,72 @@ static const struct v4l2_ioctl_ops typhoon_ioctl_ops = { | |||
363 | .vidioc_s_ctrl = vidioc_s_ctrl, | 348 | .vidioc_s_ctrl = vidioc_s_ctrl, |
364 | }; | 349 | }; |
365 | 350 | ||
366 | static struct video_device typhoon_radio = { | 351 | static int __init typhoon_init(void) |
367 | .name = "Typhoon Radio", | ||
368 | .fops = &typhoon_fops, | ||
369 | .ioctl_ops = &typhoon_ioctl_ops, | ||
370 | .release = video_device_release_empty, | ||
371 | }; | ||
372 | |||
373 | #ifdef CONFIG_RADIO_TYPHOON_PROC_FS | ||
374 | |||
375 | static int typhoon_proc_show(struct seq_file *m, void *v) | ||
376 | { | ||
377 | #ifdef MODULE | ||
378 | #define MODULEPROCSTRING "Driver loaded as a module" | ||
379 | #else | ||
380 | #define MODULEPROCSTRING "Driver compiled into kernel" | ||
381 | #endif | ||
382 | |||
383 | seq_puts(m, BANNER); | ||
384 | seq_puts(m, "Load type: " MODULEPROCSTRING "\n\n"); | ||
385 | seq_printf(m, "frequency = %lu kHz\n", | ||
386 | typhoon_unit.curfreq >> 4); | ||
387 | seq_printf(m, "volume = %d\n", typhoon_unit.curvol); | ||
388 | seq_printf(m, "mute = %s\n", typhoon_unit.muted ? | ||
389 | "on" : "off"); | ||
390 | seq_printf(m, "iobase = 0x%x\n", typhoon_unit.iobase); | ||
391 | seq_printf(m, "mute frequency = %lu kHz\n", | ||
392 | typhoon_unit.mutefreq >> 4); | ||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | static int typhoon_proc_open(struct inode *inode, struct file *file) | ||
397 | { | 352 | { |
398 | return single_open(file, typhoon_proc_show, NULL); | 353 | struct typhoon *dev = &typhoon_card; |
399 | } | 354 | struct v4l2_device *v4l2_dev = &dev->v4l2_dev; |
400 | 355 | int res; | |
401 | static const struct file_operations typhoon_proc_fops = { | ||
402 | .owner = THIS_MODULE, | ||
403 | .open = typhoon_proc_open, | ||
404 | .read = seq_read, | ||
405 | .llseek = seq_lseek, | ||
406 | .release = single_release, | ||
407 | }; | ||
408 | #endif /* CONFIG_RADIO_TYPHOON_PROC_FS */ | ||
409 | |||
410 | MODULE_AUTHOR("Dr. Henrik Seidel"); | ||
411 | MODULE_DESCRIPTION("A driver for the Typhoon radio card (a.k.a. EcoRadio)."); | ||
412 | MODULE_LICENSE("GPL"); | ||
413 | |||
414 | static int io = -1; | ||
415 | static int radio_nr = -1; | ||
416 | |||
417 | module_param(io, int, 0); | ||
418 | MODULE_PARM_DESC(io, "I/O address of the Typhoon card (0x316 or 0x336)"); | ||
419 | module_param(radio_nr, int, 0); | ||
420 | 356 | ||
421 | #ifdef MODULE | 357 | strlcpy(v4l2_dev->name, "typhoon", sizeof(v4l2_dev->name)); |
422 | static unsigned long mutefreq; | 358 | dev->io = io; |
423 | module_param(mutefreq, ulong, 0); | 359 | dev->curfreq = dev->mutefreq = mutefreq; |
424 | MODULE_PARM_DESC(mutefreq, "Frequency used when muting the card (in kHz)"); | ||
425 | #endif | ||
426 | 360 | ||
427 | static int __init typhoon_init(void) | 361 | if (dev->io == -1) { |
428 | { | 362 | v4l2_err(v4l2_dev, "You must set an I/O address with io=0x316 or io=0x336\n"); |
429 | #ifdef MODULE | ||
430 | if (io == -1) { | ||
431 | printk(KERN_ERR "radio-typhoon: You must set an I/O address with io=0x316 or io=0x336\n"); | ||
432 | return -EINVAL; | 363 | return -EINVAL; |
433 | } | 364 | } |
434 | typhoon_unit.iobase = io; | ||
435 | 365 | ||
436 | if (mutefreq < 87000 || mutefreq > 108500) { | 366 | if (dev->mutefreq < 87000 || dev->mutefreq > 108500) { |
437 | printk(KERN_ERR "radio-typhoon: You must set a frequency (in kHz) used when muting the card,\n"); | 367 | v4l2_err(v4l2_dev, "You must set a frequency (in kHz) used when muting the card,\n"); |
438 | printk(KERN_ERR "radio-typhoon: e.g. with \"mutefreq=87500\" (87000 <= mutefreq <= 108500)\n"); | 368 | v4l2_err(v4l2_dev, "e.g. with \"mutefreq=87500\" (87000 <= mutefreq <= 108500)\n"); |
439 | return -EINVAL; | 369 | return -EINVAL; |
440 | } | 370 | } |
441 | typhoon_unit.mutefreq = mutefreq; | 371 | |
442 | #endif /* MODULE */ | 372 | mutex_init(&dev->lock); |
443 | 373 | if (!request_region(dev->io, 8, "typhoon")) { | |
444 | printk(KERN_INFO BANNER); | 374 | v4l2_err(v4l2_dev, "port 0x%x already in use\n", |
445 | mutex_init(&typhoon_unit.lock); | 375 | dev->io); |
446 | io = typhoon_unit.iobase; | ||
447 | if (!request_region(io, 8, "typhoon")) { | ||
448 | printk(KERN_ERR "radio-typhoon: port 0x%x already in use\n", | ||
449 | typhoon_unit.iobase); | ||
450 | return -EBUSY; | 376 | return -EBUSY; |
451 | } | 377 | } |
452 | 378 | ||
453 | video_set_drvdata(&typhoon_radio, &typhoon_unit); | 379 | res = v4l2_device_register(NULL, v4l2_dev); |
454 | if (video_register_device(&typhoon_radio, VFL_TYPE_RADIO, radio_nr) < 0) { | 380 | if (res < 0) { |
455 | release_region(io, 8); | 381 | release_region(dev->io, 8); |
382 | v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); | ||
383 | return res; | ||
384 | } | ||
385 | v4l2_info(v4l2_dev, BANNER); | ||
386 | |||
387 | strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name)); | ||
388 | dev->vdev.v4l2_dev = v4l2_dev; | ||
389 | dev->vdev.fops = &typhoon_fops; | ||
390 | dev->vdev.ioctl_ops = &typhoon_ioctl_ops; | ||
391 | dev->vdev.release = video_device_release_empty; | ||
392 | video_set_drvdata(&dev->vdev, dev); | ||
393 | if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { | ||
394 | v4l2_device_unregister(&dev->v4l2_dev); | ||
395 | release_region(dev->io, 8); | ||
456 | return -EINVAL; | 396 | return -EINVAL; |
457 | } | 397 | } |
458 | printk(KERN_INFO "radio-typhoon: port 0x%x.\n", typhoon_unit.iobase); | 398 | v4l2_info(v4l2_dev, "port 0x%x.\n", dev->io); |
459 | printk(KERN_INFO "radio-typhoon: mute frequency is %lu kHz.\n", | 399 | v4l2_info(v4l2_dev, "mute frequency is %lu kHz.\n", dev->mutefreq); |
460 | typhoon_unit.mutefreq); | 400 | dev->mutefreq <<= 4; |
461 | typhoon_unit.mutefreq <<= 4; | ||
462 | 401 | ||
463 | /* mute card - prevents noisy bootups */ | 402 | /* mute card - prevents noisy bootups */ |
464 | typhoon_mute(&typhoon_unit); | 403 | typhoon_mute(dev); |
465 | |||
466 | #ifdef CONFIG_RADIO_TYPHOON_PROC_FS | ||
467 | if (!proc_create("driver/radio-typhoon", 0, NULL, &typhoon_proc_fops)) | ||
468 | printk(KERN_ERR "radio-typhoon: registering /proc/driver/radio-typhoon failed\n"); | ||
469 | #endif | ||
470 | 404 | ||
471 | return 0; | 405 | return 0; |
472 | } | 406 | } |
473 | 407 | ||
474 | static void __exit typhoon_cleanup_module(void) | 408 | static void __exit typhoon_exit(void) |
475 | { | 409 | { |
410 | struct typhoon *dev = &typhoon_card; | ||
476 | 411 | ||
477 | #ifdef CONFIG_RADIO_TYPHOON_PROC_FS | 412 | video_unregister_device(&dev->vdev); |
478 | remove_proc_entry("driver/radio-typhoon", NULL); | 413 | v4l2_device_unregister(&dev->v4l2_dev); |
479 | #endif | 414 | release_region(dev->io, 8); |
480 | |||
481 | video_unregister_device(&typhoon_radio); | ||
482 | release_region(io, 8); | ||
483 | } | 415 | } |
484 | 416 | ||
485 | module_init(typhoon_init); | 417 | module_init(typhoon_init); |
486 | module_exit(typhoon_cleanup_module); | 418 | module_exit(typhoon_exit); |
487 | 419 | ||