blob: 79039674a0e0bddff9976de584437a60b948e789 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090051#include <linux/slab.h>
Hans Verkuil79f94872009-03-06 13:50:07 -030052#include <media/v4l2-device.h>
53#include <media/v4l2-ioctl.h>
Mauro Carvalho Chehab52afbc22006-08-08 09:10:01 -030054
Hans Verkuil79f94872009-03-06 13:50:07 -030055MODULE_AUTHOR("Vladimir Shebordaev <vshebordaev@mail.ru>");
56MODULE_DESCRIPTION("The video4linux driver for the Gemtek PCI Radio Card");
57MODULE_LICENSE("GPL");
Mauro Carvalho Chehab52afbc22006-08-08 09:10:01 -030058
Hans Verkuil79f94872009-03-06 13:50:07 -030059static int nr_radio = -1;
60static int mx = 1;
61
62module_param(mx, bool, 0);
63MODULE_PARM_DESC(mx, "single digit: 1 - turn off the turner upon module exit (default), 0 - do not");
64module_param(nr_radio, int, 0);
65MODULE_PARM_DESC(nr_radio, "video4linux device number to use");
66
67#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69#ifndef PCI_VENDOR_ID_GEMTEK
70#define PCI_VENDOR_ID_GEMTEK 0x5046
71#endif
72
73#ifndef PCI_DEVICE_ID_GEMTEK_PR103
74#define PCI_DEVICE_ID_GEMTEK_PR103 0x1001
75#endif
76
77#ifndef GEMTEK_PCI_RANGE_LOW
78#define GEMTEK_PCI_RANGE_LOW (87*16000)
79#endif
80
81#ifndef GEMTEK_PCI_RANGE_HIGH
82#define GEMTEK_PCI_RANGE_HIGH (108*16000)
83#endif
84
Hans Verkuil79f94872009-03-06 13:50:07 -030085struct gemtek_pci {
86 struct v4l2_device v4l2_dev;
87 struct video_device vdev;
88 struct mutex lock;
89 struct pci_dev *pdev;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030090
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 u32 iobase;
92 u32 length;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 u32 current_frequency;
95 u8 mute;
96};
97
Hans Verkuil79f94872009-03-06 13:50:07 -030098static inline struct gemtek_pci *to_gemtek_pci(struct v4l2_device *v4l2_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
Hans Verkuil79f94872009-03-06 13:50:07 -0300100 return container_of(v4l2_dev, struct gemtek_pci, v4l2_dev);
101}
102
103static inline u8 gemtek_pci_out(u16 value, u32 port)
104{
105 outw(value, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 return (u8)value;
108}
109
Hans Verkuil79f94872009-03-06 13:50:07 -0300110#define _b0(v) (*((u8 *)&v))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Hans Verkuil79f94872009-03-06 13:50:07 -0300112static void __gemtek_pci_cmd(u16 value, u32 port, u8 *last_byte, int keep)
113{
114 u8 byte = *last_byte;
115
116 if (!value) {
117 if (!keep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 value = (u16)port;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300119 byte &= 0xfd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 } else
121 byte |= 2;
122
Hans Verkuil79f94872009-03-06 13:50:07 -0300123 _b0(value) = byte;
124 outw(value, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 byte |= 1;
Hans Verkuil79f94872009-03-06 13:50:07 -0300126 _b0(value) = byte;
127 outw(value, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 byte &= 0xfe;
Hans Verkuil79f94872009-03-06 13:50:07 -0300129 _b0(value) = byte;
130 outw(value, port);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 *last_byte = byte;
133}
134
Hans Verkuil79f94872009-03-06 13:50:07 -0300135static inline void gemtek_pci_nil(u32 port, u8 *last_byte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Hans Verkuil79f94872009-03-06 13:50:07 -0300137 __gemtek_pci_cmd(0x00, port, last_byte, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138}
139
Hans Verkuil79f94872009-03-06 13:50:07 -0300140static inline void gemtek_pci_cmd(u16 cmd, u32 port, u8 *last_byte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
Hans Verkuil79f94872009-03-06 13:50:07 -0300142 __gemtek_pci_cmd(cmd, port, last_byte, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143}
144
Hans Verkuil79f94872009-03-06 13:50:07 -0300145static void gemtek_pci_setfrequency(struct gemtek_pci *card, unsigned long frequency)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
Hans Verkuil79f94872009-03-06 13:50:07 -0300147 int i;
148 u32 value = frequency / 200 + 856;
149 u16 mask = 0x8000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 u8 last_byte;
151 u32 port = card->iobase;
152
Hans Verkuil79f94872009-03-06 13:50:07 -0300153 mutex_lock(&card->lock);
154 card->current_frequency = frequency;
155 last_byte = gemtek_pci_out(0x06, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 i = 0;
158 do {
Hans Verkuil79f94872009-03-06 13:50:07 -0300159 gemtek_pci_nil(port, &last_byte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 i++;
Hans Verkuil79f94872009-03-06 13:50:07 -0300161 } while (i < 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 i = 0;
164 do {
Hans Verkuil79f94872009-03-06 13:50:07 -0300165 gemtek_pci_cmd(value & mask, port, &last_byte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 mask >>= 1;
167 i++;
Hans Verkuil79f94872009-03-06 13:50:07 -0300168 } while (i < 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Hans Verkuil79f94872009-03-06 13:50:07 -0300170 outw(0x10, port);
171 mutex_unlock(&card->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
174
Hans Verkuil79f94872009-03-06 13:50:07 -0300175static void gemtek_pci_mute(struct gemtek_pci *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
Hans Verkuil79f94872009-03-06 13:50:07 -0300177 mutex_lock(&card->lock);
178 outb(0x1f, card->iobase);
Richard Knutssonfd4bc442007-02-06 21:55:07 -0300179 card->mute = true;
Hans Verkuil79f94872009-03-06 13:50:07 -0300180 mutex_unlock(&card->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
Hans Verkuil79f94872009-03-06 13:50:07 -0300183static void gemtek_pci_unmute(struct gemtek_pci *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
Hans Verkuil79f94872009-03-06 13:50:07 -0300185 if (card->mute) {
186 gemtek_pci_setfrequency(card, card->current_frequency);
Richard Knutssonfd4bc442007-02-06 21:55:07 -0300187 card->mute = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
189}
190
Hans Verkuil79f94872009-03-06 13:50:07 -0300191static int gemtek_pci_getsignal(struct gemtek_pci *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Hans Verkuil79f94872009-03-06 13:50:07 -0300193 int sig;
194
195 mutex_lock(&card->lock);
196 sig = (inb(card->iobase) & 0x08) ? 0 : 1;
197 mutex_unlock(&card->lock);
198 return sig;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
Douglas Landgraf6f664462007-04-26 10:42:12 -0300201static int vidioc_querycap(struct file *file, void *priv,
202 struct v4l2_capability *v)
203{
Hans Verkuil79f94872009-03-06 13:50:07 -0300204 struct gemtek_pci *card = video_drvdata(file);
205
Douglas Landgraf6f664462007-04-26 10:42:12 -0300206 strlcpy(v->driver, "radio-gemtek-pci", sizeof(v->driver));
207 strlcpy(v->card, "GemTek PCI Radio", sizeof(v->card));
Hans Verkuil79f94872009-03-06 13:50:07 -0300208 snprintf(v->bus_info, sizeof(v->bus_info), "PCI:%s", pci_name(card->pdev));
Douglas Landgraf6f664462007-04-26 10:42:12 -0300209 v->version = RADIO_VERSION;
Hans Verkuil79f94872009-03-06 13:50:07 -0300210 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
Douglas Landgraf6f664462007-04-26 10:42:12 -0300211 return 0;
212}
213
214static int vidioc_g_tuner(struct file *file, void *priv,
215 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
Hans Verkuil79f94872009-03-06 13:50:07 -0300217 struct gemtek_pci *card = video_drvdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Douglas Landgraf6f664462007-04-26 10:42:12 -0300219 if (v->index > 0)
220 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Hans Verkuil79f94872009-03-06 13:50:07 -0300222 strlcpy(v->name, "FM", sizeof(v->name));
Douglas Landgraf6f664462007-04-26 10:42:12 -0300223 v->type = V4L2_TUNER_RADIO;
224 v->rangelow = GEMTEK_PCI_RANGE_LOW;
225 v->rangehigh = GEMTEK_PCI_RANGE_HIGH;
226 v->rxsubchans = V4L2_TUNER_SUB_MONO;
227 v->capability = V4L2_TUNER_CAP_LOW;
228 v->audmode = V4L2_TUNER_MODE_MONO;
229 v->signal = 0xffff * gemtek_pci_getsignal(card);
230 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
Douglas Landgraf6f664462007-04-26 10:42:12 -0300233static int vidioc_s_tuner(struct file *file, void *priv,
234 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
Hans Verkuil79f94872009-03-06 13:50:07 -0300236 return v->index ? -EINVAL : 0;
Douglas Landgraf6f664462007-04-26 10:42:12 -0300237}
238
239static int vidioc_s_frequency(struct file *file, void *priv,
240 struct v4l2_frequency *f)
241{
Hans Verkuil79f94872009-03-06 13:50:07 -0300242 struct gemtek_pci *card = video_drvdata(file);
Douglas Landgraf6f664462007-04-26 10:42:12 -0300243
Hans Verkuila3a9e282009-11-27 04:33:25 -0300244 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
245 return -EINVAL;
Hans Verkuil79f94872009-03-06 13:50:07 -0300246 if (f->frequency < GEMTEK_PCI_RANGE_LOW ||
247 f->frequency > GEMTEK_PCI_RANGE_HIGH)
Douglas Landgraf6f664462007-04-26 10:42:12 -0300248 return -EINVAL;
249 gemtek_pci_setfrequency(card, f->frequency);
Douglas Landgraf6f664462007-04-26 10:42:12 -0300250 card->mute = false;
251 return 0;
252}
253
254static int vidioc_g_frequency(struct file *file, void *priv,
255 struct v4l2_frequency *f)
256{
Hans Verkuil79f94872009-03-06 13:50:07 -0300257 struct gemtek_pci *card = video_drvdata(file);
Douglas Landgraf6f664462007-04-26 10:42:12 -0300258
Hans Verkuila3a9e282009-11-27 04:33:25 -0300259 if (f->tuner != 0)
260 return -EINVAL;
Douglas Landgraf6f664462007-04-26 10:42:12 -0300261 f->type = V4L2_TUNER_RADIO;
262 f->frequency = card->current_frequency;
263 return 0;
264}
265
266static int vidioc_queryctrl(struct file *file, void *priv,
267 struct v4l2_queryctrl *qc)
268{
Hans Verkuil79f94872009-03-06 13:50:07 -0300269 switch (qc->id) {
270 case V4L2_CID_AUDIO_MUTE:
271 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
272 case V4L2_CID_AUDIO_VOLUME:
273 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535, 65535);
Douglas Landgraf6f664462007-04-26 10:42:12 -0300274 }
275 return -EINVAL;
276}
277
278static int vidioc_g_ctrl(struct file *file, void *priv,
279 struct v4l2_control *ctrl)
280{
Hans Verkuil79f94872009-03-06 13:50:07 -0300281 struct gemtek_pci *card = video_drvdata(file);
Douglas Landgraf6f664462007-04-26 10:42:12 -0300282
283 switch (ctrl->id) {
284 case V4L2_CID_AUDIO_MUTE:
285 ctrl->value = card->mute;
286 return 0;
287 case V4L2_CID_AUDIO_VOLUME:
288 if (card->mute)
289 ctrl->value = 0;
290 else
291 ctrl->value = 65535;
292 return 0;
293 }
294 return -EINVAL;
295}
296
297static int vidioc_s_ctrl(struct file *file, void *priv,
298 struct v4l2_control *ctrl)
299{
Hans Verkuil79f94872009-03-06 13:50:07 -0300300 struct gemtek_pci *card = video_drvdata(file);
Douglas Landgraf6f664462007-04-26 10:42:12 -0300301
302 switch (ctrl->id) {
303 case V4L2_CID_AUDIO_MUTE:
304 if (ctrl->value)
305 gemtek_pci_mute(card);
306 else
307 gemtek_pci_unmute(card);
308 return 0;
309 case V4L2_CID_AUDIO_VOLUME:
310 if (ctrl->value)
311 gemtek_pci_unmute(card);
312 else
313 gemtek_pci_mute(card);
314 return 0;
315 }
316 return -EINVAL;
317}
318
Douglas Landgraf6f664462007-04-26 10:42:12 -0300319static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
320{
321 *i = 0;
322 return 0;
323}
324
325static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
326{
Hans Verkuil79f94872009-03-06 13:50:07 -0300327 return i ? -EINVAL : 0;
328}
329
330static int vidioc_g_audio(struct file *file, void *priv,
331 struct v4l2_audio *a)
332{
333 a->index = 0;
334 strlcpy(a->name, "Radio", sizeof(a->name));
335 a->capability = V4L2_AUDCAP_STEREO;
Douglas Landgraf6f664462007-04-26 10:42:12 -0300336 return 0;
337}
338
339static int vidioc_s_audio(struct file *file, void *priv,
340 struct v4l2_audio *a)
341{
Hans Verkuil79f94872009-03-06 13:50:07 -0300342 return a->index ? -EINVAL : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343}
344
345enum {
346 GEMTEK_PR103
347};
348
349static char *card_names[] __devinitdata = {
350 "GEMTEK_PR103"
351};
352
353static struct pci_device_id gemtek_pci_id[] =
354{
355 { PCI_VENDOR_ID_GEMTEK, PCI_DEVICE_ID_GEMTEK_PR103,
356 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GEMTEK_PR103 },
357 { 0 }
358};
359
Hans Verkuil79f94872009-03-06 13:50:07 -0300360MODULE_DEVICE_TABLE(pci, gemtek_pci_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Hans Verkuilbec43662008-12-30 06:58:20 -0300362static const struct v4l2_file_operations gemtek_pci_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 .owner = THIS_MODULE,
Douglas Landgraf6f664462007-04-26 10:42:12 -0300364 .ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365};
366
Hans Verkuila3998102008-07-21 02:57:38 -0300367static const struct v4l2_ioctl_ops gemtek_pci_ioctl_ops = {
Douglas Landgraf6f664462007-04-26 10:42:12 -0300368 .vidioc_querycap = vidioc_querycap,
369 .vidioc_g_tuner = vidioc_g_tuner,
370 .vidioc_s_tuner = vidioc_s_tuner,
371 .vidioc_g_audio = vidioc_g_audio,
372 .vidioc_s_audio = vidioc_s_audio,
373 .vidioc_g_input = vidioc_g_input,
374 .vidioc_s_input = vidioc_s_input,
375 .vidioc_g_frequency = vidioc_g_frequency,
376 .vidioc_s_frequency = vidioc_s_frequency,
377 .vidioc_queryctrl = vidioc_queryctrl,
378 .vidioc_g_ctrl = vidioc_g_ctrl,
379 .vidioc_s_ctrl = vidioc_s_ctrl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380};
381
Hans Verkuil79f94872009-03-06 13:50:07 -0300382static int __devinit gemtek_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
Hans Verkuil79f94872009-03-06 13:50:07 -0300384 struct gemtek_pci *card;
385 struct v4l2_device *v4l2_dev;
386 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Hans Verkuil79f94872009-03-06 13:50:07 -0300388 card = kzalloc(sizeof(struct gemtek_pci), GFP_KERNEL);
389 if (card == NULL) {
390 dev_err(&pdev->dev, "out of memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 return -ENOMEM;
392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Hans Verkuil79f94872009-03-06 13:50:07 -0300394 v4l2_dev = &card->v4l2_dev;
395 mutex_init(&card->lock);
396 card->pdev = pdev;
397
398 strlcpy(v4l2_dev->name, "gemtek_pci", sizeof(v4l2_dev->name));
399
400 res = v4l2_device_register(&pdev->dev, v4l2_dev);
401 if (res < 0) {
402 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
403 kfree(card);
404 return res;
405 }
406
407 if (pci_enable_device(pdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 goto err_pci;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300409
Hans Verkuil79f94872009-03-06 13:50:07 -0300410 card->iobase = pci_resource_start(pdev, 0);
411 card->length = pci_resource_len(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Hans Verkuil79f94872009-03-06 13:50:07 -0300413 if (request_region(card->iobase, card->length, card_names[pci_id->driver_data]) == NULL) {
414 v4l2_err(v4l2_dev, "i/o port already in use\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 goto err_pci;
416 }
417
Hans Verkuil79f94872009-03-06 13:50:07 -0300418 strlcpy(card->vdev.name, v4l2_dev->name, sizeof(card->vdev.name));
419 card->vdev.v4l2_dev = v4l2_dev;
420 card->vdev.fops = &gemtek_pci_fops;
421 card->vdev.ioctl_ops = &gemtek_pci_ioctl_ops;
422 card->vdev.release = video_device_release_empty;
423 video_set_drvdata(&card->vdev, card);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300424
Hans Verkuil79f94872009-03-06 13:50:07 -0300425 if (video_register_device(&card->vdev, VFL_TYPE_RADIO, nr_radio) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 goto err_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Hans Verkuil79f94872009-03-06 13:50:07 -0300428 gemtek_pci_mute(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Hans Verkuil79f94872009-03-06 13:50:07 -0300430 v4l2_info(v4l2_dev, "Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n",
431 pdev->revision, card->iobase, card->iobase + card->length - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 return 0;
434
435err_video:
Hans Verkuil79f94872009-03-06 13:50:07 -0300436 release_region(card->iobase, card->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438err_pci:
Hans Verkuil79f94872009-03-06 13:50:07 -0300439 v4l2_device_unregister(v4l2_dev);
440 kfree(card);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300441 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442}
443
Hans Verkuil79f94872009-03-06 13:50:07 -0300444static void __devexit gemtek_pci_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
Hans Verkuil79f94872009-03-06 13:50:07 -0300446 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
447 struct gemtek_pci *card = to_gemtek_pci(v4l2_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Hans Verkuil79f94872009-03-06 13:50:07 -0300449 video_unregister_device(&card->vdev);
450 v4l2_device_unregister(v4l2_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Hans Verkuil79f94872009-03-06 13:50:07 -0300452 release_region(card->iobase, card->length);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300453
Hans Verkuil79f94872009-03-06 13:50:07 -0300454 if (mx)
455 gemtek_pci_mute(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Hans Verkuil79f94872009-03-06 13:50:07 -0300457 kfree(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
459
Hans Verkuil79f94872009-03-06 13:50:07 -0300460static struct pci_driver gemtek_pci_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 .name = "gemtek_pci",
462 .id_table = gemtek_pci_id,
463 .probe = gemtek_pci_probe,
464 .remove = __devexit_p(gemtek_pci_remove),
465};
466
Hans Verkuil79f94872009-03-06 13:50:07 -0300467static int __init gemtek_pci_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468{
Hans Verkuil79f94872009-03-06 13:50:07 -0300469 return pci_register_driver(&gemtek_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470}
471
Hans Verkuil79f94872009-03-06 13:50:07 -0300472static void __exit gemtek_pci_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
Tobias Klauser13962752006-10-04 08:09:10 -0300474 pci_unregister_driver(&gemtek_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475}
476
Hans Verkuil79f94872009-03-06 13:50:07 -0300477module_init(gemtek_pci_init);
478module_exit(gemtek_pci_exit);