blob: f8213b7c8ddc2a6c97ac94e8c52846fe9606711a [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>
Hans Verkuil087c6182009-03-06 13:51:08 -030029#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030030#include <media/v4l2-ioctl.h>
Ingo Molnar3593cab2006-02-07 06:49:14 -020031
Hans Verkuil087c6182009-03-06 13:51:08 -030032MODULE_AUTHOR("Adam Tlalka, atlka@pg.gda.pl");
33MODULE_DESCRIPTION("Radio driver for the Maestro PCI sound card radio.");
34MODULE_LICENSE("GPL");
Mauro Carvalho Chehabb6055d72006-08-08 09:10:02 -030035
Hans Verkuil087c6182009-03-06 13:51:08 -030036static int radio_nr = -1;
37module_param(radio_nr, int, 0);
38
39#define RADIO_VERSION KERNEL_VERSION(0, 0, 6)
40#define DRIVER_VERSION "0.06"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -080042#define GPIO_DATA 0x60 /* port offset from ESS_IO_BASE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#define IO_MASK 4 /* mask register offset from GPIO_DATA
45 bits 1=unmask write to given bit */
46#define IO_DIR 8 /* direction register offset from GPIO_DATA
47 bits 0/1=read/write direction */
48
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -080049#define GPIO6 0x0040 /* mask bits for GPIO lines */
50#define GPIO7 0x0080
51#define GPIO8 0x0100
52#define GPIO9 0x0200
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -080054#define STR_DATA GPIO6 /* radio TEA5757 pins and GPIO bits */
55#define STR_CLK GPIO7
56#define STR_WREN GPIO8
57#define STR_MOST GPIO9
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59#define FREQ_LO 50*16000
60#define FREQ_HI 150*16000
61
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -080062#define FREQ_IF 171200 /* 10.7*16000 */
63#define FREQ_STEP 200 /* 12.5*16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65#define FREQ2BITS(x) ((((unsigned int)(x)+FREQ_IF+(FREQ_STEP<<1))\
66 /(FREQ_STEP<<2))<<2) /* (x==fmhz*16*1000) -> bits */
67
68#define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF)
69
Hans Verkuil087c6182009-03-06 13:51:08 -030070struct maestro {
71 struct v4l2_device v4l2_dev;
72 struct video_device vdev;
73 struct pci_dev *pdev;
74 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Hans Verkuil087c6182009-03-06 13:51:08 -030076 u16 io; /* base of Maestro card radio io (GPIO_DATA)*/
77 u16 muted; /* VIDEO_AUDIO_MUTE */
78 u16 stereo; /* VIDEO_TUNER_STEREO_ON */
79 u16 tuned; /* signal strength (0 or 0xffff) */
80};
Hans Verkuil3ca685a2008-08-23 04:49:13 -030081
Hans Verkuil087c6182009-03-06 13:51:08 -030082static inline struct maestro *to_maestro(struct v4l2_device *v4l2_dev)
Hans Verkuil3ca685a2008-08-23 04:49:13 -030083{
Hans Verkuil087c6182009-03-06 13:51:08 -030084 return container_of(v4l2_dev, struct maestro, v4l2_dev);
Hans Verkuil3ca685a2008-08-23 04:49:13 -030085}
86
Hans Verkuil087c6182009-03-06 13:51:08 -030087static u32 radio_bits_get(struct maestro *dev)
Hans Verkuil3ca685a2008-08-23 04:49:13 -030088{
Hans Verkuil087c6182009-03-06 13:51:08 -030089 u16 io = dev->io, l, rdata;
90 u32 data = 0;
Jiri Slaby0eaa21f2006-01-09 20:52:49 -080091 u16 omask;
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -080092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 omask = inw(io + IO_MASK);
94 outw(~(STR_CLK | STR_WREN), io + IO_MASK);
95 outw(0, io);
96 udelay(16);
97
Hans Verkuil087c6182009-03-06 13:51:08 -030098 for (l = 24; l--;) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 outw(STR_CLK, io); /* HI state */
100 udelay(2);
Hans Verkuil087c6182009-03-06 13:51:08 -0300101 if (!l)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 dev->tuned = inw(io) & STR_MOST ? 0 : 0xffff;
103 outw(0, io); /* LO state */
104 udelay(2);
105 data <<= 1; /* shift data */
106 rdata = inw(io);
Hans Verkuil087c6182009-03-06 13:51:08 -0300107 if (!l)
108 dev->stereo = (rdata & STR_MOST) ? 0 : 1;
109 else if (rdata & STR_DATA)
110 data++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 udelay(2);
112 }
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800113
Hans Verkuil087c6182009-03-06 13:51:08 -0300114 if (dev->muted)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 outw(STR_WREN, io);
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 udelay(4);
118 outw(omask, io + IO_MASK);
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return data & 0x3ffe;
121}
122
Hans Verkuil087c6182009-03-06 13:51:08 -0300123static void radio_bits_set(struct maestro *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Hans Verkuil087c6182009-03-06 13:51:08 -0300125 u16 io = dev->io, l, bits;
Jiri Slaby0eaa21f2006-01-09 20:52:49 -0800126 u16 omask, odir;
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 omask = inw(io + IO_MASK);
Hans Verkuil087c6182009-03-06 13:51:08 -0300129 odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 outw(odir | STR_DATA, io + IO_DIR);
131 outw(~(STR_DATA | STR_CLK | STR_WREN), io + IO_MASK);
132 udelay(16);
Hans Verkuil087c6182009-03-06 13:51:08 -0300133 for (l = 25; l; l--) {
134 bits = ((data >> 18) & STR_DATA) | STR_WREN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 data <<= 1; /* shift data */
136 outw(bits, io); /* start strobe */
137 udelay(2);
138 outw(bits | STR_CLK, io); /* HI level */
139 udelay(2);
140 outw(bits, io); /* LO level */
141 udelay(4);
142 }
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800143
Hans Verkuil087c6182009-03-06 13:51:08 -0300144 if (!dev->muted)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 outw(0, io);
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 udelay(4);
148 outw(omask, io + IO_MASK);
149 outw(odir, io + IO_DIR);
150 msleep(125);
151}
152
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300153static int vidioc_querycap(struct file *file, void *priv,
154 struct v4l2_capability *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Hans Verkuil087c6182009-03-06 13:51:08 -0300156 struct maestro *dev = video_drvdata(file);
157
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300158 strlcpy(v->driver, "radio-maestro", sizeof(v->driver));
159 strlcpy(v->card, "Maestro Radio", sizeof(v->card));
Hans Verkuil087c6182009-03-06 13:51:08 -0300160 snprintf(v->bus_info, sizeof(v->bus_info), "PCI:%s", pci_name(dev->pdev));
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300161 v->version = RADIO_VERSION;
Hans Verkuil087c6182009-03-06 13:51:08 -0300162 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300163 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300166static int vidioc_g_tuner(struct file *file, void *priv,
167 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
Hans Verkuil087c6182009-03-06 13:51:08 -0300169 struct maestro *dev = video_drvdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300171 if (v->index > 0)
172 return -EINVAL;
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800173
Hans Verkuil087c6182009-03-06 13:51:08 -0300174 mutex_lock(&dev->lock);
175 radio_bits_get(dev);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300176
Hans Verkuil087c6182009-03-06 13:51:08 -0300177 strlcpy(v->name, "FM", sizeof(v->name));
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300178 v->type = V4L2_TUNER_RADIO;
179 v->rangelow = FREQ_LO;
180 v->rangehigh = FREQ_HI;
Hans Verkuil087c6182009-03-06 13:51:08 -0300181 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300182 v->capability = V4L2_TUNER_CAP_LOW;
Hans Verkuil087c6182009-03-06 13:51:08 -0300183 if (dev->stereo)
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300184 v->audmode = V4L2_TUNER_MODE_STEREO;
185 else
186 v->audmode = V4L2_TUNER_MODE_MONO;
Hans Verkuil087c6182009-03-06 13:51:08 -0300187 v->signal = dev->tuned;
188 mutex_unlock(&dev->lock);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300189 return 0;
190}
191
192static int vidioc_s_tuner(struct file *file, void *priv,
193 struct v4l2_tuner *v)
194{
Hans Verkuil087c6182009-03-06 13:51:08 -0300195 return v->index ? -EINVAL : 0;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300196}
197
198static int vidioc_s_frequency(struct file *file, void *priv,
199 struct v4l2_frequency *f)
200{
Hans Verkuil087c6182009-03-06 13:51:08 -0300201 struct maestro *dev = video_drvdata(file);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300202
Hans Verkuila3a9e282009-11-27 04:33:25 -0300203 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
204 return -EINVAL;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300205 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
206 return -EINVAL;
Hans Verkuil087c6182009-03-06 13:51:08 -0300207 mutex_lock(&dev->lock);
208 radio_bits_set(dev, FREQ2BITS(f->frequency));
209 mutex_unlock(&dev->lock);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300210 return 0;
211}
212
213static int vidioc_g_frequency(struct file *file, void *priv,
214 struct v4l2_frequency *f)
215{
Hans Verkuil087c6182009-03-06 13:51:08 -0300216 struct maestro *dev = video_drvdata(file);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300217
Hans Verkuila3a9e282009-11-27 04:33:25 -0300218 if (f->tuner != 0)
219 return -EINVAL;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300220 f->type = V4L2_TUNER_RADIO;
Hans Verkuil087c6182009-03-06 13:51:08 -0300221 mutex_lock(&dev->lock);
222 f->frequency = BITS2FREQ(radio_bits_get(dev));
223 mutex_unlock(&dev->lock);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300224 return 0;
225}
226
227static int vidioc_queryctrl(struct file *file, void *priv,
228 struct v4l2_queryctrl *qc)
229{
Hans Verkuil087c6182009-03-06 13:51:08 -0300230 switch (qc->id) {
231 case V4L2_CID_AUDIO_MUTE:
232 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300233 }
234 return -EINVAL;
235}
236
237static int vidioc_g_ctrl(struct file *file, void *priv,
238 struct v4l2_control *ctrl)
239{
Hans Verkuil087c6182009-03-06 13:51:08 -0300240 struct maestro *dev = video_drvdata(file);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300241
242 switch (ctrl->id) {
243 case V4L2_CID_AUDIO_MUTE:
Hans Verkuil087c6182009-03-06 13:51:08 -0300244 ctrl->value = dev->muted;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300245 return 0;
246 }
247 return -EINVAL;
248}
249
250static int vidioc_s_ctrl(struct file *file, void *priv,
251 struct v4l2_control *ctrl)
252{
Hans Verkuil087c6182009-03-06 13:51:08 -0300253 struct maestro *dev = video_drvdata(file);
254 u16 io = dev->io;
255 u16 omask;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300256
257 switch (ctrl->id) {
258 case V4L2_CID_AUDIO_MUTE:
Hans Verkuil087c6182009-03-06 13:51:08 -0300259 mutex_lock(&dev->lock);
260 omask = inw(io + IO_MASK);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300261 outw(~STR_WREN, io + IO_MASK);
Hans Verkuil087c6182009-03-06 13:51:08 -0300262 dev->muted = ctrl->value;
263 outw(dev->muted ? STR_WREN : 0, io);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300264 udelay(4);
265 outw(omask, io + IO_MASK);
266 msleep(125);
Hans Verkuil087c6182009-03-06 13:51:08 -0300267 mutex_unlock(&dev->lock);
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300268 return 0;
269 }
270 return -EINVAL;
271}
272
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300273static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
274{
275 *i = 0;
276 return 0;
277}
278
279static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
280{
Hans Verkuil087c6182009-03-06 13:51:08 -0300281 return i ? -EINVAL : 0;
282}
283
284static 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;
Douglas Landgrafd455cf52007-04-26 16:44:55 -0300290 return 0;
291}
292
293static int vidioc_s_audio(struct file *file, void *priv,
294 struct v4l2_audio *a)
295{
Hans Verkuil087c6182009-03-06 13:51:08 -0300296 return a->index ? -EINVAL : 0;
297}
298
Hans Verkuil087c6182009-03-06 13:51:08 -0300299static const struct v4l2_file_operations maestro_fops = {
300 .owner = THIS_MODULE,
Hans Verkuil087c6182009-03-06 13:51:08 -0300301 .ioctl = video_ioctl2,
302};
303
304static const struct v4l2_ioctl_ops maestro_ioctl_ops = {
305 .vidioc_querycap = vidioc_querycap,
306 .vidioc_g_tuner = vidioc_g_tuner,
307 .vidioc_s_tuner = vidioc_s_tuner,
308 .vidioc_g_audio = vidioc_g_audio,
309 .vidioc_s_audio = vidioc_s_audio,
310 .vidioc_g_input = vidioc_g_input,
311 .vidioc_s_input = vidioc_s_input,
312 .vidioc_g_frequency = vidioc_g_frequency,
313 .vidioc_s_frequency = vidioc_s_frequency,
314 .vidioc_queryctrl = vidioc_queryctrl,
315 .vidioc_g_ctrl = vidioc_g_ctrl,
316 .vidioc_s_ctrl = vidioc_s_ctrl,
317};
318
319static u16 __devinit radio_power_on(struct maestro *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
Jiri Slaby0eaa21f2006-01-09 20:52:49 -0800321 register u16 io = dev->io;
322 register u32 ofreq;
323 u16 omask, odir;
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 omask = inw(io + IO_MASK);
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800326 odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 outw(odir & ~STR_WREN, io + IO_DIR);
Mauro Carvalho Chehabb6055d72006-08-08 09:10:02 -0300328 dev->muted = inw(io) & STR_WREN ? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 outw(odir, io + IO_DIR);
330 outw(~(STR_WREN | STR_CLK), io + IO_MASK);
331 outw(dev->muted ? 0 : STR_WREN, io);
332 udelay(16);
333 outw(omask, io + IO_MASK);
334 ofreq = radio_bits_get(dev);
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800335
336 if ((ofreq < FREQ2BITS(FREQ_LO)) || (ofreq > FREQ2BITS(FREQ_HI)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 ofreq = FREQ2BITS(FREQ_LO);
338 radio_bits_set(dev, ofreq);
Jiri Slaby6a2cf8e2006-01-09 20:52:48 -0800339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return (ofreq == radio_bits_get(dev));
341}
342
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800343static int __devinit maestro_probe(struct pci_dev *pdev,
344 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Hans Verkuil087c6182009-03-06 13:51:08 -0300346 struct maestro *dev;
347 struct v4l2_device *v4l2_dev;
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800348 int retval;
349
350 retval = pci_enable_device(pdev);
351 if (retval) {
352 dev_err(&pdev->dev, "enabling pci device failed!\n");
353 goto err;
354 }
355
356 retval = -ENOMEM;
357
Hans Verkuil087c6182009-03-06 13:51:08 -0300358 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
359 if (dev == NULL) {
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800360 dev_err(&pdev->dev, "not enough memory\n");
361 goto err;
362 }
363
Hans Verkuil087c6182009-03-06 13:51:08 -0300364 v4l2_dev = &dev->v4l2_dev;
365 mutex_init(&dev->lock);
366 dev->pdev = pdev;
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800367
Hans Verkuil087c6182009-03-06 13:51:08 -0300368 strlcpy(v4l2_dev->name, "maestro", sizeof(v4l2_dev->name));
369
370 retval = v4l2_device_register(&pdev->dev, v4l2_dev);
371 if (retval < 0) {
372 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800373 goto errfr;
374 }
375
Hans Verkuil087c6182009-03-06 13:51:08 -0300376 dev->io = pci_resource_start(pdev, 0) + GPIO_DATA;
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800377
Hans Verkuil087c6182009-03-06 13:51:08 -0300378 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
379 dev->vdev.v4l2_dev = v4l2_dev;
380 dev->vdev.fops = &maestro_fops;
381 dev->vdev.ioctl_ops = &maestro_ioctl_ops;
382 dev->vdev.release = video_device_release_empty;
383 video_set_drvdata(&dev->vdev, dev);
384
385 retval = video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr);
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800386 if (retval) {
Hans Verkuil087c6182009-03-06 13:51:08 -0300387 v4l2_err(v4l2_dev, "can't register video device!\n");
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800388 goto errfr1;
389 }
390
Hans Verkuil087c6182009-03-06 13:51:08 -0300391 if (!radio_power_on(dev)) {
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800392 retval = -EIO;
393 goto errunr;
394 }
395
Hans Verkuil087c6182009-03-06 13:51:08 -0300396 v4l2_info(v4l2_dev, "version " DRIVER_VERSION "\n");
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800397
398 return 0;
399errunr:
Hans Verkuil087c6182009-03-06 13:51:08 -0300400 video_unregister_device(&dev->vdev);
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800401errfr1:
Hans Verkuil087c6182009-03-06 13:51:08 -0300402 v4l2_device_unregister(v4l2_dev);
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800403errfr:
Hans Verkuil087c6182009-03-06 13:51:08 -0300404 kfree(dev);
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800405err:
406 return retval;
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800410static void __devexit maestro_remove(struct pci_dev *pdev)
411{
Hans Verkuil087c6182009-03-06 13:51:08 -0300412 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
413 struct maestro *dev = to_maestro(v4l2_dev);
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800414
Hans Verkuil087c6182009-03-06 13:51:08 -0300415 video_unregister_device(&dev->vdev);
416 v4l2_device_unregister(&dev->v4l2_dev);
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800417}
418
Hans Verkuil087c6182009-03-06 13:51:08 -0300419static struct pci_device_id maestro_r_pci_tbl[] = {
420 { PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1968),
421 .class = PCI_CLASS_MULTIMEDIA_AUDIO << 8,
422 .class_mask = 0xffff00 },
423 { PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1978),
424 .class = PCI_CLASS_MULTIMEDIA_AUDIO << 8,
425 .class_mask = 0xffff00 },
426 { 0 }
427};
428MODULE_DEVICE_TABLE(pci, maestro_r_pci_tbl);
429
430static struct pci_driver maestro_r_driver = {
431 .name = "maestro_radio",
432 .id_table = maestro_r_pci_tbl,
433 .probe = maestro_probe,
434 .remove = __devexit_p(maestro_remove),
435};
436
Jiri Slaby89dad8f2006-01-09 20:52:47 -0800437static int __init maestro_radio_init(void)
438{
439 int retval = pci_register_driver(&maestro_r_driver);
440
441 if (retval)
442 printk(KERN_ERR "error during registration pci driver\n");
443
444 return retval;
445}
446
447static void __exit maestro_radio_exit(void)
448{
449 pci_unregister_driver(&maestro_r_driver);
450}
451
452module_init(maestro_radio_init);
453module_exit(maestro_radio_exit);