blob: 000f4d34087ce2352fbd9c4ae8b47846f49aaa82 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 ***************************************************************************
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -03003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * radio-gemtek-pci.c - Gemtek PCI Radio driver
5 * (C) 2001 Vladimir Shebordaev <vshebordaev@mail.ru>
6 *
7 ***************************************************************************
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
22 * USA.
23 *
24 ***************************************************************************
25 *
26 * Gemtek Corp still silently refuses to release any specifications
27 * of their multimedia devices, so the protocol still has to be
28 * reverse engineered.
29 *
30 * The v4l code was inspired by Jonas Munsin's Gemtek serial line
31 * radio device driver.
32 *
33 * Please, let me know if this piece of code was useful :)
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030034 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 * TODO: multiple device support and portability were not tested
36 *
Mauro Carvalho Chehab52afbc22006-08-08 09:10:01 -030037 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
38 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 ***************************************************************************
40 */
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/types.h>
43#include <linux/list.h>
44#include <linux/module.h>
45#include <linux/init.h>
46#include <linux/pci.h>
Mauro Carvalho Chehab52afbc22006-08-08 09:10:01 -030047#include <linux/videodev2.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/errno.h>
Mauro Carvalho Chehab52afbc22006-08-08 09:10:01 -030049#include <linux/version.h> /* for KERNEL_VERSION MACRO */
Hans Verkuil79f94872009-03-06 13:50:07 -030050#include <linux/io.h>
Hans Verkuil79f94872009-03-06 13:50:07 -030051#include <media/v4l2-device.h>
52#include <media/v4l2-ioctl.h>
Mauro Carvalho Chehab52afbc22006-08-08 09:10:01 -030053
Hans Verkuil79f94872009-03-06 13:50:07 -030054MODULE_AUTHOR("Vladimir Shebordaev <vshebordaev@mail.ru>");
55MODULE_DESCRIPTION("The video4linux driver for the Gemtek PCI Radio Card");
56MODULE_LICENSE("GPL");
Mauro Carvalho Chehab52afbc22006-08-08 09:10:01 -030057
Hans Verkuil79f94872009-03-06 13:50:07 -030058static int nr_radio = -1;
59static int mx = 1;
60
61module_param(mx, bool, 0);
62MODULE_PARM_DESC(mx, "single digit: 1 - turn off the turner upon module exit (default), 0 - do not");
63module_param(nr_radio, int, 0);
64MODULE_PARM_DESC(nr_radio, "video4linux device number to use");
65
66#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68#ifndef PCI_VENDOR_ID_GEMTEK
69#define PCI_VENDOR_ID_GEMTEK 0x5046
70#endif
71
72#ifndef PCI_DEVICE_ID_GEMTEK_PR103
73#define PCI_DEVICE_ID_GEMTEK_PR103 0x1001
74#endif
75
76#ifndef GEMTEK_PCI_RANGE_LOW
77#define GEMTEK_PCI_RANGE_LOW (87*16000)
78#endif
79
80#ifndef GEMTEK_PCI_RANGE_HIGH
81#define GEMTEK_PCI_RANGE_HIGH (108*16000)
82#endif
83
Hans Verkuil79f94872009-03-06 13:50:07 -030084struct gemtek_pci {
85 struct v4l2_device v4l2_dev;
86 struct video_device vdev;
87 struct mutex lock;
88 struct pci_dev *pdev;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030089
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 u32 iobase;
91 u32 length;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 u32 current_frequency;
94 u8 mute;
95};
96
Hans Verkuil79f94872009-03-06 13:50:07 -030097static inline struct gemtek_pci *to_gemtek_pci(struct v4l2_device *v4l2_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Hans Verkuil79f94872009-03-06 13:50:07 -030099 return container_of(v4l2_dev, struct gemtek_pci, v4l2_dev);
100}
101
102static inline u8 gemtek_pci_out(u16 value, u32 port)
103{
104 outw(value, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 return (u8)value;
107}
108
Hans Verkuil79f94872009-03-06 13:50:07 -0300109#define _b0(v) (*((u8 *)&v))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Hans Verkuil79f94872009-03-06 13:50:07 -0300111static void __gemtek_pci_cmd(u16 value, u32 port, u8 *last_byte, int keep)
112{
113 u8 byte = *last_byte;
114
115 if (!value) {
116 if (!keep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 value = (u16)port;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300118 byte &= 0xfd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 } else
120 byte |= 2;
121
Hans Verkuil79f94872009-03-06 13:50:07 -0300122 _b0(value) = byte;
123 outw(value, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 byte |= 1;
Hans Verkuil79f94872009-03-06 13:50:07 -0300125 _b0(value) = byte;
126 outw(value, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 byte &= 0xfe;
Hans Verkuil79f94872009-03-06 13:50:07 -0300128 _b0(value) = byte;
129 outw(value, port);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 *last_byte = byte;
132}
133
Hans Verkuil79f94872009-03-06 13:50:07 -0300134static inline void gemtek_pci_nil(u32 port, u8 *last_byte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
Hans Verkuil79f94872009-03-06 13:50:07 -0300136 __gemtek_pci_cmd(0x00, port, last_byte, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
Hans Verkuil79f94872009-03-06 13:50:07 -0300139static inline void gemtek_pci_cmd(u16 cmd, u32 port, u8 *last_byte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
Hans Verkuil79f94872009-03-06 13:50:07 -0300141 __gemtek_pci_cmd(cmd, port, last_byte, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
143
Hans Verkuil79f94872009-03-06 13:50:07 -0300144static void gemtek_pci_setfrequency(struct gemtek_pci *card, unsigned long frequency)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Hans Verkuil79f94872009-03-06 13:50:07 -0300146 int i;
147 u32 value = frequency / 200 + 856;
148 u16 mask = 0x8000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 u8 last_byte;
150 u32 port = card->iobase;
151
Hans Verkuil79f94872009-03-06 13:50:07 -0300152 mutex_lock(&card->lock);
153 card->current_frequency = frequency;
154 last_byte = gemtek_pci_out(0x06, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 i = 0;
157 do {
Hans Verkuil79f94872009-03-06 13:50:07 -0300158 gemtek_pci_nil(port, &last_byte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 i++;
Hans Verkuil79f94872009-03-06 13:50:07 -0300160 } while (i < 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 i = 0;
163 do {
Hans Verkuil79f94872009-03-06 13:50:07 -0300164 gemtek_pci_cmd(value & mask, port, &last_byte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 mask >>= 1;
166 i++;
Hans Verkuil79f94872009-03-06 13:50:07 -0300167 } while (i < 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Hans Verkuil79f94872009-03-06 13:50:07 -0300169 outw(0x10, port);
170 mutex_unlock(&card->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
173
Hans Verkuil79f94872009-03-06 13:50:07 -0300174static void gemtek_pci_mute(struct gemtek_pci *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
Hans Verkuil79f94872009-03-06 13:50:07 -0300176 mutex_lock(&card->lock);
177 outb(0x1f, card->iobase);
Richard Knutssonfd4bc442007-02-06 21:55:07 -0300178 card->mute = true;
Hans Verkuil79f94872009-03-06 13:50:07 -0300179 mutex_unlock(&card->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180}
181
Hans Verkuil79f94872009-03-06 13:50:07 -0300182static void gemtek_pci_unmute(struct gemtek_pci *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
Hans Verkuil79f94872009-03-06 13:50:07 -0300184 if (card->mute) {
185 gemtek_pci_setfrequency(card, card->current_frequency);
Richard Knutssonfd4bc442007-02-06 21:55:07 -0300186 card->mute = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188}
189
Hans Verkuil79f94872009-03-06 13:50:07 -0300190static int gemtek_pci_getsignal(struct gemtek_pci *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
Hans Verkuil79f94872009-03-06 13:50:07 -0300192 int sig;
193
194 mutex_lock(&card->lock);
195 sig = (inb(card->iobase) & 0x08) ? 0 : 1;
196 mutex_unlock(&card->lock);
197 return sig;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
Douglas Landgraf6f664462007-04-26 10:42:12 -0300200static int vidioc_querycap(struct file *file, void *priv,
201 struct v4l2_capability *v)
202{
Hans Verkuil79f94872009-03-06 13:50:07 -0300203 struct gemtek_pci *card = video_drvdata(file);
204
Douglas Landgraf6f664462007-04-26 10:42:12 -0300205 strlcpy(v->driver, "radio-gemtek-pci", sizeof(v->driver));
206 strlcpy(v->card, "GemTek PCI Radio", sizeof(v->card));
Hans Verkuil79f94872009-03-06 13:50:07 -0300207 snprintf(v->bus_info, sizeof(v->bus_info), "PCI:%s", pci_name(card->pdev));
Douglas Landgraf6f664462007-04-26 10:42:12 -0300208 v->version = RADIO_VERSION;
Hans Verkuil79f94872009-03-06 13:50:07 -0300209 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
Douglas Landgraf6f664462007-04-26 10:42:12 -0300210 return 0;
211}
212
213static int vidioc_g_tuner(struct file *file, void *priv,
214 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
Hans Verkuil79f94872009-03-06 13:50:07 -0300216 struct gemtek_pci *card = video_drvdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Douglas Landgraf6f664462007-04-26 10:42:12 -0300218 if (v->index > 0)
219 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Hans Verkuil79f94872009-03-06 13:50:07 -0300221 strlcpy(v->name, "FM", sizeof(v->name));
Douglas Landgraf6f664462007-04-26 10:42:12 -0300222 v->type = V4L2_TUNER_RADIO;
223 v->rangelow = GEMTEK_PCI_RANGE_LOW;
224 v->rangehigh = GEMTEK_PCI_RANGE_HIGH;
225 v->rxsubchans = V4L2_TUNER_SUB_MONO;
226 v->capability = V4L2_TUNER_CAP_LOW;
227 v->audmode = V4L2_TUNER_MODE_MONO;
228 v->signal = 0xffff * gemtek_pci_getsignal(card);
229 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230}
231
Douglas Landgraf6f664462007-04-26 10:42:12 -0300232static int vidioc_s_tuner(struct file *file, void *priv,
233 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Hans Verkuil79f94872009-03-06 13:50:07 -0300235 return v->index ? -EINVAL : 0;
Douglas Landgraf6f664462007-04-26 10:42:12 -0300236}
237
238static int vidioc_s_frequency(struct file *file, void *priv,
239 struct v4l2_frequency *f)
240{
Hans Verkuil79f94872009-03-06 13:50:07 -0300241 struct gemtek_pci *card = video_drvdata(file);
Douglas Landgraf6f664462007-04-26 10:42:12 -0300242
Hans Verkuila3a9e282009-11-27 04:33:25 -0300243 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
244 return -EINVAL;
Hans Verkuil79f94872009-03-06 13:50:07 -0300245 if (f->frequency < GEMTEK_PCI_RANGE_LOW ||
246 f->frequency > GEMTEK_PCI_RANGE_HIGH)
Douglas Landgraf6f664462007-04-26 10:42:12 -0300247 return -EINVAL;
248 gemtek_pci_setfrequency(card, f->frequency);
Douglas Landgraf6f664462007-04-26 10:42:12 -0300249 card->mute = false;
250 return 0;
251}
252
253static int vidioc_g_frequency(struct file *file, void *priv,
254 struct v4l2_frequency *f)
255{
Hans Verkuil79f94872009-03-06 13:50:07 -0300256 struct gemtek_pci *card = video_drvdata(file);
Douglas Landgraf6f664462007-04-26 10:42:12 -0300257
Hans Verkuila3a9e282009-11-27 04:33:25 -0300258 if (f->tuner != 0)
259 return -EINVAL;
Douglas Landgraf6f664462007-04-26 10:42:12 -0300260 f->type = V4L2_TUNER_RADIO;
261 f->frequency = card->current_frequency;
262 return 0;
263}
264
265static int vidioc_queryctrl(struct file *file, void *priv,
266 struct v4l2_queryctrl *qc)
267{
Hans Verkuil79f94872009-03-06 13:50:07 -0300268 switch (qc->id) {
269 case V4L2_CID_AUDIO_MUTE:
270 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
271 case V4L2_CID_AUDIO_VOLUME:
272 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535, 65535);
Douglas Landgraf6f664462007-04-26 10:42:12 -0300273 }
274 return -EINVAL;
275}
276
277static int vidioc_g_ctrl(struct file *file, void *priv,
278 struct v4l2_control *ctrl)
279{
Hans Verkuil79f94872009-03-06 13:50:07 -0300280 struct gemtek_pci *card = video_drvdata(file);
Douglas Landgraf6f664462007-04-26 10:42:12 -0300281
282 switch (ctrl->id) {
283 case V4L2_CID_AUDIO_MUTE:
284 ctrl->value = card->mute;
285 return 0;
286 case V4L2_CID_AUDIO_VOLUME:
287 if (card->mute)
288 ctrl->value = 0;
289 else
290 ctrl->value = 65535;
291 return 0;
292 }
293 return -EINVAL;
294}
295
296static int vidioc_s_ctrl(struct file *file, void *priv,
297 struct v4l2_control *ctrl)
298{
Hans Verkuil79f94872009-03-06 13:50:07 -0300299 struct gemtek_pci *card = video_drvdata(file);
Douglas Landgraf6f664462007-04-26 10:42:12 -0300300
301 switch (ctrl->id) {
302 case V4L2_CID_AUDIO_MUTE:
303 if (ctrl->value)
304 gemtek_pci_mute(card);
305 else
306 gemtek_pci_unmute(card);
307 return 0;
308 case V4L2_CID_AUDIO_VOLUME:
309 if (ctrl->value)
310 gemtek_pci_unmute(card);
311 else
312 gemtek_pci_mute(card);
313 return 0;
314 }
315 return -EINVAL;
316}
317
Douglas Landgraf6f664462007-04-26 10:42:12 -0300318static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
319{
320 *i = 0;
321 return 0;
322}
323
324static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
325{
Hans Verkuil79f94872009-03-06 13:50:07 -0300326 return i ? -EINVAL : 0;
327}
328
329static int vidioc_g_audio(struct file *file, void *priv,
330 struct v4l2_audio *a)
331{
332 a->index = 0;
333 strlcpy(a->name, "Radio", sizeof(a->name));
334 a->capability = V4L2_AUDCAP_STEREO;
Douglas Landgraf6f664462007-04-26 10:42:12 -0300335 return 0;
336}
337
338static int vidioc_s_audio(struct file *file, void *priv,
339 struct v4l2_audio *a)
340{
Hans Verkuil79f94872009-03-06 13:50:07 -0300341 return a->index ? -EINVAL : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343
344enum {
345 GEMTEK_PR103
346};
347
348static char *card_names[] __devinitdata = {
349 "GEMTEK_PR103"
350};
351
352static struct pci_device_id gemtek_pci_id[] =
353{
354 { PCI_VENDOR_ID_GEMTEK, PCI_DEVICE_ID_GEMTEK_PR103,
355 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GEMTEK_PR103 },
356 { 0 }
357};
358
Hans Verkuil79f94872009-03-06 13:50:07 -0300359MODULE_DEVICE_TABLE(pci, gemtek_pci_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Hans Verkuilbec43662008-12-30 06:58:20 -0300361static const struct v4l2_file_operations gemtek_pci_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 .owner = THIS_MODULE,
Douglas Landgraf6f664462007-04-26 10:42:12 -0300363 .ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364};
365
Hans Verkuila3998102008-07-21 02:57:38 -0300366static const struct v4l2_ioctl_ops gemtek_pci_ioctl_ops = {
Douglas Landgraf6f664462007-04-26 10:42:12 -0300367 .vidioc_querycap = vidioc_querycap,
368 .vidioc_g_tuner = vidioc_g_tuner,
369 .vidioc_s_tuner = vidioc_s_tuner,
370 .vidioc_g_audio = vidioc_g_audio,
371 .vidioc_s_audio = vidioc_s_audio,
372 .vidioc_g_input = vidioc_g_input,
373 .vidioc_s_input = vidioc_s_input,
374 .vidioc_g_frequency = vidioc_g_frequency,
375 .vidioc_s_frequency = vidioc_s_frequency,
376 .vidioc_queryctrl = vidioc_queryctrl,
377 .vidioc_g_ctrl = vidioc_g_ctrl,
378 .vidioc_s_ctrl = vidioc_s_ctrl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379};
380
Hans Verkuil79f94872009-03-06 13:50:07 -0300381static int __devinit gemtek_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
Hans Verkuil79f94872009-03-06 13:50:07 -0300383 struct gemtek_pci *card;
384 struct v4l2_device *v4l2_dev;
385 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Hans Verkuil79f94872009-03-06 13:50:07 -0300387 card = kzalloc(sizeof(struct gemtek_pci), GFP_KERNEL);
388 if (card == NULL) {
389 dev_err(&pdev->dev, "out of memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 return -ENOMEM;
391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Hans Verkuil79f94872009-03-06 13:50:07 -0300393 v4l2_dev = &card->v4l2_dev;
394 mutex_init(&card->lock);
395 card->pdev = pdev;
396
397 strlcpy(v4l2_dev->name, "gemtek_pci", sizeof(v4l2_dev->name));
398
399 res = v4l2_device_register(&pdev->dev, v4l2_dev);
400 if (res < 0) {
401 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
402 kfree(card);
403 return res;
404 }
405
406 if (pci_enable_device(pdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 goto err_pci;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300408
Hans Verkuil79f94872009-03-06 13:50:07 -0300409 card->iobase = pci_resource_start(pdev, 0);
410 card->length = pci_resource_len(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Hans Verkuil79f94872009-03-06 13:50:07 -0300412 if (request_region(card->iobase, card->length, card_names[pci_id->driver_data]) == NULL) {
413 v4l2_err(v4l2_dev, "i/o port already in use\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 goto err_pci;
415 }
416
Hans Verkuil79f94872009-03-06 13:50:07 -0300417 strlcpy(card->vdev.name, v4l2_dev->name, sizeof(card->vdev.name));
418 card->vdev.v4l2_dev = v4l2_dev;
419 card->vdev.fops = &gemtek_pci_fops;
420 card->vdev.ioctl_ops = &gemtek_pci_ioctl_ops;
421 card->vdev.release = video_device_release_empty;
422 video_set_drvdata(&card->vdev, card);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300423
Hans Verkuil79f94872009-03-06 13:50:07 -0300424 if (video_register_device(&card->vdev, VFL_TYPE_RADIO, nr_radio) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 goto err_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Hans Verkuil79f94872009-03-06 13:50:07 -0300427 gemtek_pci_mute(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Hans Verkuil79f94872009-03-06 13:50:07 -0300429 v4l2_info(v4l2_dev, "Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n",
430 pdev->revision, card->iobase, card->iobase + card->length - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 return 0;
433
434err_video:
Hans Verkuil79f94872009-03-06 13:50:07 -0300435 release_region(card->iobase, card->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437err_pci:
Hans Verkuil79f94872009-03-06 13:50:07 -0300438 v4l2_device_unregister(v4l2_dev);
439 kfree(card);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300440 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441}
442
Hans Verkuil79f94872009-03-06 13:50:07 -0300443static void __devexit gemtek_pci_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Hans Verkuil79f94872009-03-06 13:50:07 -0300445 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
446 struct gemtek_pci *card = to_gemtek_pci(v4l2_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Hans Verkuil79f94872009-03-06 13:50:07 -0300448 video_unregister_device(&card->vdev);
449 v4l2_device_unregister(v4l2_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Hans Verkuil79f94872009-03-06 13:50:07 -0300451 release_region(card->iobase, card->length);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300452
Hans Verkuil79f94872009-03-06 13:50:07 -0300453 if (mx)
454 gemtek_pci_mute(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Hans Verkuil79f94872009-03-06 13:50:07 -0300456 kfree(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457}
458
Hans Verkuil79f94872009-03-06 13:50:07 -0300459static struct pci_driver gemtek_pci_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 .name = "gemtek_pci",
461 .id_table = gemtek_pci_id,
462 .probe = gemtek_pci_probe,
463 .remove = __devexit_p(gemtek_pci_remove),
464};
465
Hans Verkuil79f94872009-03-06 13:50:07 -0300466static int __init gemtek_pci_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
Hans Verkuil79f94872009-03-06 13:50:07 -0300468 return pci_register_driver(&gemtek_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
470
Hans Verkuil79f94872009-03-06 13:50:07 -0300471static void __exit gemtek_pci_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Tobias Klauser13962752006-10-04 08:09:10 -0300473 pci_unregister_driver(&gemtek_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474}
475
Hans Verkuil79f94872009-03-06 13:50:07 -0300476module_init(gemtek_pci_init);
477module_exit(gemtek_pci_exit);