blob: adab964b2a39aa24d7ce04de35bff739d14fa4cc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Maestro PCI sound card radio driver for Linux support
2 * (c) 2000 A. Tlalka, atlka@pg.gda.pl
3 * Notes on the hardware
4 *
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -03005 * + Frequency control is done digitally
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * + No volume control - only mute/unmute - you have to use Aux line volume
7 * control on Maestro card to set the volume
8 * + Radio status (tuned/not_tuned and stereo/mono) is valid some time after
9 * frequency setting (>100ms) and only when the radio is unmuted.
10 * version 0.02
11 * + io port is automatically detected - only the first radio is used
12 * version 0.03
13 * + thread access locking additions
14 * version 0.04
15 * + code improvements
16 * + VIDEO_TUNER_LOW is permanent
Mauro Carvalho Chehabb6055d72006-08-08 09:10:02 -030017 *
18 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 */
20
21#include <linux/module.h>
22#include <linux/init.h>
23#include <linux/ioport.h>
24#include <linux/delay.h>
Hans Verkuil087c6182009-03-06 13:51:08 -030025#include <linux/version.h> /* for KERNEL_VERSION MACRO */
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/pci.h>
Mauro Carvalho Chehabb6055d72006-08-08 09:10:02 -030027#include <linux/videodev2.h>
Hans Verkuil087c6182009-03-06 13:51:08 -030028#include <linux/io.h>
29#include <linux/uaccess.h>
30#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030031#include <media/v4l2-ioctl.h>
Ingo Molnar3593cab2006-02-07 06:49:14 -020032
Hans Verkuil087c6182009-03-06 13:51:08 -030033MODULE_AUTHOR("Adam Tlalka, atlka@pg.gda.pl");
34MODULE_DESCRIPTION("Radio driver for the Maestro PCI sound card radio.");
35MODULE_LICENSE("GPL");
Mauro Carvalho Chehabb6055d72006-08-08 09:10:02 -030036
Hans Verkuil087c6182009-03-06 13:51:08 -030037static int radio_nr = -1;
38module_param(radio_nr, int, 0);
39
40#define RADIO_VERSION KERNEL_VERSION(0, 0, 6)
41#define DRIVER_VERSION "0.06"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -080043#define GPIO_DATA 0x60 /* port offset from ESS_IO_BASE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#define IO_MASK 4 /* mask register offset from GPIO_DATA
46 bits 1=unmask write to given bit */
47#define IO_DIR 8 /* direction register offset from GPIO_DATA
48 bits 0/1=read/write direction */
49
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -080050#define GPIO6 0x0040 /* mask bits for GPIO lines */
51#define GPIO7 0x0080
52#define GPIO8 0x0100
53#define GPIO9 0x0200
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -080055#define STR_DATA GPIO6 /* radio TEA5757 pins and GPIO bits */
56#define STR_CLK GPIO7
57#define STR_WREN GPIO8
58#define STR_MOST GPIO9
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define FREQ_LO 50*16000
61#define FREQ_HI 150*16000
62
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -080063#define FREQ_IF 171200 /* 10.7*16000 */
64#define FREQ_STEP 200 /* 12.5*16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66#define FREQ2BITS(x) ((((unsigned int)(x)+FREQ_IF+(FREQ_STEP<<1))\
67 /(FREQ_STEP<<2))<<2) /* (x==fmhz*16*1000) -> bits */
68
69#define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF)
70
Hans Verkuil087c6182009-03-06 13:51:08 -030071struct maestro {
72 struct v4l2_device v4l2_dev;
73 struct video_device vdev;
74 struct pci_dev *pdev;
75 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Hans Verkuil087c6182009-03-06 13:51:08 -030077 u16 io; /* base of Maestro card radio io (GPIO_DATA)*/
78 u16 muted; /* VIDEO_AUDIO_MUTE */
79 u16 stereo; /* VIDEO_TUNER_STEREO_ON */
80 u16 tuned; /* signal strength (0 or 0xffff) */
81};
Hans Verkuil3ca685a2008-08-23 04:49:13 -030082
Hans Verkuil087c6182009-03-06 13:51:08 -030083static inline struct maestro *to_maestro(struct v4l2_device *v4l2_dev)
Hans Verkuil3ca685a2008-08-23 04:49:13 -030084{
Hans Verkuil087c6182009-03-06 13:51:08 -030085 return container_of(v4l2_dev, struct maestro, v4l2_dev);
Hans Verkuil3ca685a2008-08-23 04:49:13 -030086}
87
Hans Verkuil087c6182009-03-06 13:51:08 -030088static u32 radio_bits_get(struct maestro *dev)
Hans Verkuil3ca685a2008-08-23 04:49:13 -030089{
Hans Verkuil087c6182009-03-06 13:51:08 -030090 u16 io = dev->io, l, rdata;
91 u32 data = 0;
Jiri Slaby0eaa21f2006-01-09 20:52:49 -080092 u16 omask;
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -080093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 omask = inw(io + IO_MASK);
95 outw(~(STR_CLK | STR_WREN), io + IO_MASK);
96 outw(0, io);
97 udelay(16);
98
Hans Verkuil087c6182009-03-06 13:51:08 -030099 for (l = 24; l--;) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 outw(STR_CLK, io); /* HI state */
101 udelay(2);
Hans Verkuil087c6182009-03-06 13:51:08 -0300102 if (!l)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 dev->tuned = inw(io) & STR_MOST ? 0 : 0xffff;
104 outw(0, io); /* LO state */
105 udelay(2);
106 data <<= 1; /* shift data */
107 rdata = inw(io);
Hans Verkuil087c6182009-03-06 13:51:08 -0300108 if (!l)
109 dev->stereo = (rdata & STR_MOST) ? 0 : 1;
110 else if (rdata & STR_DATA)
111 data++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 udelay(2);
113 }
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800114
Hans Verkuil087c6182009-03-06 13:51:08 -0300115 if (dev->muted)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 outw(STR_WREN, io);
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 udelay(4);
119 outw(omask, io + IO_MASK);
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 return data & 0x3ffe;
122}
123
Hans Verkuil087c6182009-03-06 13:51:08 -0300124static void radio_bits_set(struct maestro *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
Hans Verkuil087c6182009-03-06 13:51:08 -0300126 u16 io = dev->io, l, bits;
Jiri Slaby0eaa21f2006-01-09 20:52:49 -0800127 u16 omask, odir;
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 omask = inw(io + IO_MASK);
Hans Verkuil087c6182009-03-06 13:51:08 -0300130 odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 outw(odir | STR_DATA, io + IO_DIR);
132 outw(~(STR_DATA | STR_CLK | STR_WREN), io + IO_MASK);
133 udelay(16);
Hans Verkuil087c6182009-03-06 13:51:08 -0300134 for (l = 25; l; l--) {
135 bits = ((data >> 18) & STR_DATA) | STR_WREN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 data <<= 1; /* shift data */
137 outw(bits, io); /* start strobe */
138 udelay(2);
139 outw(bits | STR_CLK, io); /* HI level */
140 udelay(2);
141 outw(bits, io); /* LO level */
142 udelay(4);
143 }
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800144
Hans Verkuil087c6182009-03-06 13:51:08 -0300145 if (!dev->muted)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 outw(0, io);
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 udelay(4);
149 outw(omask, io + IO_MASK);
150 outw(odir, io + IO_DIR);
151 msleep(125);
152}
153
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300154static int vidioc_querycap(struct file *file, void *priv,
155 struct v4l2_capability *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Hans Verkuil087c6182009-03-06 13:51:08 -0300157 struct maestro *dev = video_drvdata(file);
158
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300159 strlcpy(v->driver, "radio-maestro", sizeof(v->driver));
160 strlcpy(v->card, "Maestro Radio", sizeof(v->card));
Hans Verkuil087c6182009-03-06 13:51:08 -0300161 snprintf(v->bus_info, sizeof(v->bus_info), "PCI:%s", pci_name(dev->pdev));
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300162 v->version = RADIO_VERSION;
Hans Verkuil087c6182009-03-06 13:51:08 -0300163 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300164 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165}
166
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300167static int vidioc_g_tuner(struct file *file, void *priv,
168 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
Hans Verkuil087c6182009-03-06 13:51:08 -0300170 struct maestro *dev = video_drvdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300172 if (v->index > 0)
173 return -EINVAL;
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800174
Hans Verkuil087c6182009-03-06 13:51:08 -0300175 mutex_lock(&dev->lock);
176 radio_bits_get(dev);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300177
Hans Verkuil087c6182009-03-06 13:51:08 -0300178 strlcpy(v->name, "FM", sizeof(v->name));
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300179 v->type = V4L2_TUNER_RADIO;
180 v->rangelow = FREQ_LO;
181 v->rangehigh = FREQ_HI;
Hans Verkuil087c6182009-03-06 13:51:08 -0300182 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300183 v->capability = V4L2_TUNER_CAP_LOW;
Hans Verkuil087c6182009-03-06 13:51:08 -0300184 if (dev->stereo)
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300185 v->audmode = V4L2_TUNER_MODE_STEREO;
186 else
187 v->audmode = V4L2_TUNER_MODE_MONO;
Hans Verkuil087c6182009-03-06 13:51:08 -0300188 v->signal = dev->tuned;
189 mutex_unlock(&dev->lock);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300190 return 0;
191}
192
193static int vidioc_s_tuner(struct file *file, void *priv,
194 struct v4l2_tuner *v)
195{
Hans Verkuil087c6182009-03-06 13:51:08 -0300196 return v->index ? -EINVAL : 0;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300197}
198
199static int vidioc_s_frequency(struct file *file, void *priv,
200 struct v4l2_frequency *f)
201{
Hans Verkuil087c6182009-03-06 13:51:08 -0300202 struct maestro *dev = video_drvdata(file);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300203
204 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
205 return -EINVAL;
Hans Verkuil087c6182009-03-06 13:51:08 -0300206 mutex_lock(&dev->lock);
207 radio_bits_set(dev, FREQ2BITS(f->frequency));
208 mutex_unlock(&dev->lock);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300209 return 0;
210}
211
212static int vidioc_g_frequency(struct file *file, void *priv,
213 struct v4l2_frequency *f)
214{
Hans Verkuil087c6182009-03-06 13:51:08 -0300215 struct maestro *dev = video_drvdata(file);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300216
217 f->type = V4L2_TUNER_RADIO;
Hans Verkuil087c6182009-03-06 13:51:08 -0300218 mutex_lock(&dev->lock);
219 f->frequency = BITS2FREQ(radio_bits_get(dev));
220 mutex_unlock(&dev->lock);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300221 return 0;
222}
223
224static int vidioc_queryctrl(struct file *file, void *priv,
225 struct v4l2_queryctrl *qc)
226{
Hans Verkuil087c6182009-03-06 13:51:08 -0300227 switch (qc->id) {
228 case V4L2_CID_AUDIO_MUTE:
229 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300230 }
231 return -EINVAL;
232}
233
234static int vidioc_g_ctrl(struct file *file, void *priv,
235 struct v4l2_control *ctrl)
236{
Hans Verkuil087c6182009-03-06 13:51:08 -0300237 struct maestro *dev = video_drvdata(file);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300238
239 switch (ctrl->id) {
240 case V4L2_CID_AUDIO_MUTE:
Hans Verkuil087c6182009-03-06 13:51:08 -0300241 ctrl->value = dev->muted;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300242 return 0;
243 }
244 return -EINVAL;
245}
246
247static int vidioc_s_ctrl(struct file *file, void *priv,
248 struct v4l2_control *ctrl)
249{
Hans Verkuil087c6182009-03-06 13:51:08 -0300250 struct maestro *dev = video_drvdata(file);
251 u16 io = dev->io;
252 u16 omask;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300253
254 switch (ctrl->id) {
255 case V4L2_CID_AUDIO_MUTE:
Hans Verkuil087c6182009-03-06 13:51:08 -0300256 mutex_lock(&dev->lock);
257 omask = inw(io + IO_MASK);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300258 outw(~STR_WREN, io + IO_MASK);
Hans Verkuil087c6182009-03-06 13:51:08 -0300259 dev->muted = ctrl->value;
260 outw(dev->muted ? STR_WREN : 0, io);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300261 udelay(4);
262 outw(omask, io + IO_MASK);
263 msleep(125);
Hans Verkuil087c6182009-03-06 13:51:08 -0300264 mutex_unlock(&dev->lock);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300265 return 0;
266 }
267 return -EINVAL;
268}
269
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300270static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
271{
272 *i = 0;
273 return 0;
274}
275
276static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
277{
Hans Verkuil087c6182009-03-06 13:51:08 -0300278 return i ? -EINVAL : 0;
279}
280
281static int vidioc_g_audio(struct file *file, void *priv,
282 struct v4l2_audio *a)
283{
284 a->index = 0;
285 strlcpy(a->name, "Radio", sizeof(a->name));
286 a->capability = V4L2_AUDCAP_STEREO;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300287 return 0;
288}
289
290static int vidioc_s_audio(struct file *file, void *priv,
291 struct v4l2_audio *a)
292{
Hans Verkuil087c6182009-03-06 13:51:08 -0300293 return a->index ? -EINVAL : 0;
294}
295
296static int maestro_open(struct file *file)
297{
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300298 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
300
Hans Verkuil087c6182009-03-06 13:51:08 -0300301static int maestro_release(struct file *file)
302{
303 return 0;
304}
305
306static const struct v4l2_file_operations maestro_fops = {
307 .owner = THIS_MODULE,
308 .open = maestro_open,
309 .release = maestro_release,
310 .ioctl = video_ioctl2,
311};
312
313static const struct v4l2_ioctl_ops maestro_ioctl_ops = {
314 .vidioc_querycap = vidioc_querycap,
315 .vidioc_g_tuner = vidioc_g_tuner,
316 .vidioc_s_tuner = vidioc_s_tuner,
317 .vidioc_g_audio = vidioc_g_audio,
318 .vidioc_s_audio = vidioc_s_audio,
319 .vidioc_g_input = vidioc_g_input,
320 .vidioc_s_input = vidioc_s_input,
321 .vidioc_g_frequency = vidioc_g_frequency,
322 .vidioc_s_frequency = vidioc_s_frequency,
323 .vidioc_queryctrl = vidioc_queryctrl,
324 .vidioc_g_ctrl = vidioc_g_ctrl,
325 .vidioc_s_ctrl = vidioc_s_ctrl,
326};
327
328static u16 __devinit radio_power_on(struct maestro *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Jiri Slaby0eaa21f2006-01-09 20:52:49 -0800330 register u16 io = dev->io;
331 register u32 ofreq;
332 u16 omask, odir;
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 omask = inw(io + IO_MASK);
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800335 odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 outw(odir & ~STR_WREN, io + IO_DIR);
Mauro Carvalho Chehabb6055d72006-08-08 09:10:02 -0300337 dev->muted = inw(io) & STR_WREN ? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 outw(odir, io + IO_DIR);
339 outw(~(STR_WREN | STR_CLK), io + IO_MASK);
340 outw(dev->muted ? 0 : STR_WREN, io);
341 udelay(16);
342 outw(omask, io + IO_MASK);
343 ofreq = radio_bits_get(dev);
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800344
345 if ((ofreq < FREQ2BITS(FREQ_LO)) || (ofreq > FREQ2BITS(FREQ_HI)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 ofreq = FREQ2BITS(FREQ_LO);
347 radio_bits_set(dev, ofreq);
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 return (ofreq == radio_bits_get(dev));
350}
351
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800352static int __devinit maestro_probe(struct pci_dev *pdev,
353 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354{
Hans Verkuil087c6182009-03-06 13:51:08 -0300355 struct maestro *dev;
356 struct v4l2_device *v4l2_dev;
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800357 int retval;
358
359 retval = pci_enable_device(pdev);
360 if (retval) {
361 dev_err(&pdev->dev, "enabling pci device failed!\n");
362 goto err;
363 }
364
365 retval = -ENOMEM;
366
Hans Verkuil087c6182009-03-06 13:51:08 -0300367 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
368 if (dev == NULL) {
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800369 dev_err(&pdev->dev, "not enough memory\n");
370 goto err;
371 }
372
Hans Verkuil087c6182009-03-06 13:51:08 -0300373 v4l2_dev = &dev->v4l2_dev;
374 mutex_init(&dev->lock);
375 dev->pdev = pdev;
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800376
Hans Verkuil087c6182009-03-06 13:51:08 -0300377 strlcpy(v4l2_dev->name, "maestro", sizeof(v4l2_dev->name));
378
379 retval = v4l2_device_register(&pdev->dev, v4l2_dev);
380 if (retval < 0) {
381 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800382 goto errfr;
383 }
384
Hans Verkuil087c6182009-03-06 13:51:08 -0300385 dev->io = pci_resource_start(pdev, 0) + GPIO_DATA;
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800386
Hans Verkuil087c6182009-03-06 13:51:08 -0300387 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
388 dev->vdev.v4l2_dev = v4l2_dev;
389 dev->vdev.fops = &maestro_fops;
390 dev->vdev.ioctl_ops = &maestro_ioctl_ops;
391 dev->vdev.release = video_device_release_empty;
392 video_set_drvdata(&dev->vdev, dev);
393
394 retval = video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr);
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800395 if (retval) {
Hans Verkuil087c6182009-03-06 13:51:08 -0300396 v4l2_err(v4l2_dev, "can't register video device!\n");
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800397 goto errfr1;
398 }
399
Hans Verkuil087c6182009-03-06 13:51:08 -0300400 if (!radio_power_on(dev)) {
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800401 retval = -EIO;
402 goto errunr;
403 }
404
Hans Verkuil087c6182009-03-06 13:51:08 -0300405 v4l2_info(v4l2_dev, "version " DRIVER_VERSION "\n");
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800406
407 return 0;
408errunr:
Hans Verkuil087c6182009-03-06 13:51:08 -0300409 video_unregister_device(&dev->vdev);
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800410errfr1:
Hans Verkuil087c6182009-03-06 13:51:08 -0300411 v4l2_device_unregister(v4l2_dev);
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800412errfr:
Hans Verkuil087c6182009-03-06 13:51:08 -0300413 kfree(dev);
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800414err:
415 return retval;
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417}
418
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800419static void __devexit maestro_remove(struct pci_dev *pdev)
420{
Hans Verkuil087c6182009-03-06 13:51:08 -0300421 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
422 struct maestro *dev = to_maestro(v4l2_dev);
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800423
Hans Verkuil087c6182009-03-06 13:51:08 -0300424 video_unregister_device(&dev->vdev);
425 v4l2_device_unregister(&dev->v4l2_dev);
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800426}
427
Hans Verkuil087c6182009-03-06 13:51:08 -0300428static struct pci_device_id maestro_r_pci_tbl[] = {
429 { PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1968),
430 .class = PCI_CLASS_MULTIMEDIA_AUDIO << 8,
431 .class_mask = 0xffff00 },
432 { PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1978),
433 .class = PCI_CLASS_MULTIMEDIA_AUDIO << 8,
434 .class_mask = 0xffff00 },
435 { 0 }
436};
437MODULE_DEVICE_TABLE(pci, maestro_r_pci_tbl);
438
439static struct pci_driver maestro_r_driver = {
440 .name = "maestro_radio",
441 .id_table = maestro_r_pci_tbl,
442 .probe = maestro_probe,
443 .remove = __devexit_p(maestro_remove),
444};
445
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800446static int __init maestro_radio_init(void)
447{
448 int retval = pci_register_driver(&maestro_r_driver);
449
450 if (retval)
451 printk(KERN_ERR "error during registration pci driver\n");
452
453 return retval;
454}
455
456static void __exit maestro_radio_exit(void)
457{
458 pci_unregister_driver(&maestro_r_driver);
459}
460
461module_init(maestro_radio_init);
462module_exit(maestro_radio_exit);