blob: f872a54cf3d9ae9baa03bdf9c5170664b9295d8f [file] [log] [blame]
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -03001/*
2 * Guillemot Maxi Radio FM 2000 PCI radio card driver for Linux
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * (C) 2001 Dimitromanolakis Apostolos <apdim@grecian.net>
4 *
5 * Based in the radio Maestro PCI driver. Actually it uses the same chip
6 * for radio but different pci controller.
7 *
8 * I didn't have any specs I reversed engineered the protocol from
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -03009 * the windows driver (radio.dll).
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * The card uses the TEA5757 chip that includes a search function but it
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030012 * is useless as I haven't found any way to read back the frequency. If
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * anybody does please mail me.
14 *
15 * For the pdf file see:
Justin P. Mattock631dd1a2010-10-18 11:03:14 +020016 * http://www.nxp.com/acrobat_download2/expired_datasheets/TEA5757_5759_3.pdf
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 *
18 *
19 * CHANGES:
20 * 0.75b
21 * - better pci interface thanks to Francois Romieu <romieu@cogenit.fr>
22 *
Mauro Carvalho Chehabe84fef62006-08-08 09:10:05 -030023 * 0.75 Sun Feb 4 22:51:27 EET 2001
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 * - tiding up
25 * - removed support for multiple devices as it didn't work anyway
26 *
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030027 * BUGS:
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * - card unmutes if you change frequency
29 *
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -030030 * (c) 2006, 2007 by Mauro Carvalho Chehab <mchehab@infradead.org>:
31 * - Conversion to V4L2 API
32 * - Uses video_ioctl2 for parsing and to add debug support
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 */
34
35
36#include <linux/module.h>
37#include <linux/init.h>
38#include <linux/ioport.h>
39#include <linux/delay.h>
Ingo Molnar3593cab2006-02-07 06:49:14 -020040#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/pci.h>
Mauro Carvalho Chehabe84fef62006-08-08 09:10:05 -030042#include <linux/videodev2.h>
Hans Verkuil2710e6a2009-03-06 13:51:33 -030043#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090044#include <linux/slab.h>
Hans Verkuil2710e6a2009-03-06 13:51:33 -030045#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030046#include <media/v4l2-ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Mauro Carvalho Chehab29834c12011-06-25 10:15:42 -030048#define DRIVER_VERSION "0.7.8"
49
50
Hans Verkuil2710e6a2009-03-06 13:51:33 -030051MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net");
52MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000 radio.");
53MODULE_LICENSE("GPL");
Mauro Carvalho Chehab29834c12011-06-25 10:15:42 -030054MODULE_VERSION(DRIVER_VERSION);
Hans Verkuil2710e6a2009-03-06 13:51:33 -030055
56static int radio_nr = -1;
57module_param(radio_nr, int, 0);
58
59static int debug;
60
61module_param(debug, int, 0644);
62MODULE_PARM_DESC(debug, "activates debug info");
63
Hans Verkuil2710e6a2009-03-06 13:51:33 -030064#define dprintk(dev, num, fmt, arg...) \
65 v4l2_dbg(num, debug, &dev->v4l2_dev, fmt, ## arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#ifndef PCI_VENDOR_ID_GUILLEMOT
68#define PCI_VENDOR_ID_GUILLEMOT 0x5046
69#endif
70
71#ifndef PCI_DEVICE_ID_GUILLEMOT
72#define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
73#endif
74
75
76/* TEA5757 pin mappings */
Hans Verkuil2710e6a2009-03-06 13:51:33 -030077static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Hans Verkuil90d873a2011-01-05 14:40:07 -030079#define FREQ_LO (87 * 16000)
80#define FREQ_HI (108 * 16000)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82#define FREQ_IF 171200 /* 10.7*16000 */
83#define FREQ_STEP 200 /* 12.5*16 */
84
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -030085/* (x==fmhz*16*1000) -> bits */
Hans Verkuil2710e6a2009-03-06 13:51:33 -030086#define FREQ2BITS(x) \
87 ((((unsigned int)(x) + FREQ_IF + (FREQ_STEP << 1)) / (FREQ_STEP << 2)) << 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89#define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF)
90
91
Hans Verkuil2710e6a2009-03-06 13:51:33 -030092struct maxiradio
Hans Verkuil3ca685a2008-08-23 04:49:13 -030093{
Hans Verkuil2710e6a2009-03-06 13:51:33 -030094 struct v4l2_device v4l2_dev;
95 struct video_device vdev;
96 struct pci_dev *pdev;
Hans Verkuil3ca685a2008-08-23 04:49:13 -030097
Hans Verkuil2710e6a2009-03-06 13:51:33 -030098 u16 io; /* base of radio io */
99 u16 muted; /* VIDEO_AUDIO_MUTE */
100 u16 stereo; /* VIDEO_TUNER_STEREO_ON */
101 u16 tuned; /* signal strength (0 or 0xffff) */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 unsigned long freq;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300104
Ingo Molnar3593cab2006-02-07 06:49:14 -0200105 struct mutex lock;
Mauro Carvalho Chehab712642b2007-01-26 07:33:07 -0300106};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300108static inline struct maxiradio *to_maxiradio(struct v4l2_device *v4l2_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300110 return container_of(v4l2_dev, struct maxiradio, v4l2_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300113static void outbit(unsigned long bit, u16 io)
114{
115 int val = power | wren | (bit ? data : 0);
116
117 outb(val, io);
118 udelay(4);
119 outb(val | clk, io);
120 udelay(4);
121 outb(val, io);
122 udelay(4);
123}
124
125static void turn_power(struct maxiradio *dev, int p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300127 if (p != 0) {
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300128 dprintk(dev, 1, "Radio powered on\n");
129 outb(power, dev->io);
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300130 } else {
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300131 dprintk(dev, 1, "Radio powered off\n");
132 outb(0, dev->io);
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300136static void set_freq(struct maxiradio *dev, u32 freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
138 unsigned long int si;
139 int bl;
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300140 int io = dev->io;
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300141 int val = FREQ2BITS(freq);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 /* TEA5757 shift register bits (see pdf) */
144
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300145 outbit(0, io); /* 24 search */
146 outbit(1, io); /* 23 search up/down */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300147
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300148 outbit(0, io); /* 22 stereo/mono */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300150 outbit(0, io); /* 21 band */
151 outbit(0, io); /* 20 band (only 00=FM works I think) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300153 outbit(0, io); /* 19 port ? */
154 outbit(0, io); /* 18 port ? */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300155
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300156 outbit(0, io); /* 17 search level */
157 outbit(0, io); /* 16 search level */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 si = 0x8000;
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300160 for (bl = 1; bl <= 16; bl++) {
161 outbit(val & si, io);
162 si >>= 1;
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300163 }
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300164
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300165 dprintk(dev, 1, "Radio freq set to %d.%02d MHz\n",
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300166 freq / 16000,
167 freq % 16000 * 100 / 16000);
168
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300169 turn_power(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170}
171
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300172static int get_stereo(u16 io)
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300173{
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300174 outb(power,io);
175 udelay(4);
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 return !(inb(io) & mo_st);
178}
179
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300180static int get_tune(u16 io)
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300181{
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300182 outb(power+clk,io);
183 udelay(4);
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return !(inb(io) & mo_st);
186}
187
188
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300189static int vidioc_querycap(struct file *file, void *priv,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300190 struct v4l2_capability *v)
191{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300192 struct maxiradio *dev = video_drvdata(file);
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300193
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300194 strlcpy(v->driver, "radio-maxiradio", sizeof(v->driver));
195 strlcpy(v->card, "Maxi Radio FM2000 radio", sizeof(v->card));
196 snprintf(v->bus_info, sizeof(v->bus_info), "PCI:%s", pci_name(dev->pdev));
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300197 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300198 return 0;
199}
200
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300201static int vidioc_g_tuner(struct file *file, void *priv,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300202 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300204 struct maxiradio *dev = video_drvdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300206 if (v->index > 0)
207 return -EINVAL;
Mauro Carvalho Chehabe84fef62006-08-08 09:10:05 -0300208
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300209 mutex_lock(&dev->lock);
210 strlcpy(v->name, "FM", sizeof(v->name));
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300211 v->type = V4L2_TUNER_RADIO;
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300212 v->rangelow = FREQ_LO;
213 v->rangehigh = FREQ_HI;
214 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
215 v->capability = V4L2_TUNER_CAP_LOW;
216 if (get_stereo(dev->io))
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300217 v->audmode = V4L2_TUNER_MODE_STEREO;
218 else
219 v->audmode = V4L2_TUNER_MODE_MONO;
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300220 v->signal = 0xffff * get_tune(dev->io);
221 mutex_unlock(&dev->lock);
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300222
223 return 0;
224}
225
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300226static int vidioc_s_tuner(struct file *file, void *priv,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300227 struct v4l2_tuner *v)
228{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300229 return v->index ? -EINVAL : 0;
Mauro Carvalho Chehab140dcc42007-01-25 15:00:45 -0300230}
231
Mauro Carvalho Chehaba0c05ab2007-01-25 16:48:13 -0300232static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
233{
234 *i = 0;
235 return 0;
236}
237
238static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
239{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300240 return i ? -EINVAL : 0;
Mauro Carvalho Chehaba0c05ab2007-01-25 16:48:13 -0300241}
242
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300243static int vidioc_g_audio(struct file *file, void *priv,
Mauro Carvalho Chehab140dcc42007-01-25 15:00:45 -0300244 struct v4l2_audio *a)
245{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300246 a->index = 0;
247 strlcpy(a->name, "Radio", sizeof(a->name));
248 a->capability = V4L2_AUDCAP_STEREO;
Mauro Carvalho Chehab140dcc42007-01-25 15:00:45 -0300249 return 0;
250}
251
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300252
253static int vidioc_s_audio(struct file *file, void *priv,
254 struct v4l2_audio *a)
255{
256 return a->index ? -EINVAL : 0;
257}
258
259static int vidioc_s_frequency(struct file *file, void *priv,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300260 struct v4l2_frequency *f)
261{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300262 struct maxiradio *dev = video_drvdata(file);
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300263
Hans Verkuila3a9e282009-11-27 04:33:25 -0300264 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
265 return -EINVAL;
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300266 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) {
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300267 dprintk(dev, 1, "radio freq (%d.%02d MHz) out of range (%d-%d)\n",
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300268 f->frequency / 16000,
269 f->frequency % 16000 * 100 / 16000,
270 FREQ_LO / 16000, FREQ_HI / 16000);
271
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300272 return -EINVAL;
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300273 }
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300274
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300275 mutex_lock(&dev->lock);
276 dev->freq = f->frequency;
277 set_freq(dev, dev->freq);
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300278 msleep(125);
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300279 mutex_unlock(&dev->lock);
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300280
281 return 0;
282}
283
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300284static int vidioc_g_frequency(struct file *file, void *priv,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300285 struct v4l2_frequency *f)
286{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300287 struct maxiradio *dev = video_drvdata(file);
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300288
Hans Verkuila3a9e282009-11-27 04:33:25 -0300289 if (f->tuner != 0)
290 return -EINVAL;
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300291 f->type = V4L2_TUNER_RADIO;
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300292 f->frequency = dev->freq;
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300293
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300294 dprintk(dev, 4, "radio freq is %d.%02d MHz",
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300295 f->frequency / 16000,
296 f->frequency % 16000 * 100 / 16000);
297
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300298 return 0;
299}
300
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300301static int vidioc_queryctrl(struct file *file, void *priv,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300302 struct v4l2_queryctrl *qc)
303{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300304 switch (qc->id) {
305 case V4L2_CID_AUDIO_MUTE:
306 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300308 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300311static int vidioc_g_ctrl(struct file *file, void *priv,
312 struct v4l2_control *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300314 struct maxiradio *dev = video_drvdata(file);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300315
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300316 switch (ctrl->id) {
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300317 case V4L2_CID_AUDIO_MUTE:
318 ctrl->value = dev->muted;
319 return 0;
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300320 }
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300321
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300322 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323}
324
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300325static int vidioc_s_ctrl(struct file *file, void *priv,
326 struct v4l2_control *ctrl)
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300327{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300328 struct maxiradio *dev = video_drvdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300330 switch (ctrl->id) {
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300331 case V4L2_CID_AUDIO_MUTE:
332 mutex_lock(&dev->lock);
333 dev->muted = ctrl->value;
334 if (dev->muted)
335 turn_power(dev, 0);
336 else
337 set_freq(dev, dev->freq);
338 mutex_unlock(&dev->lock);
339 return 0;
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300340 }
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300341
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300342 return -EINVAL;
343}
344
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300345static const struct v4l2_file_operations maxiradio_fops = {
346 .owner = THIS_MODULE,
Hans Verkuil32958fd2010-11-14 09:36:23 -0300347 .unlocked_ioctl = video_ioctl2,
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300348};
349
Hans Verkuila3998102008-07-21 02:57:38 -0300350static const struct v4l2_ioctl_ops maxiradio_ioctl_ops = {
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300351 .vidioc_querycap = vidioc_querycap,
352 .vidioc_g_tuner = vidioc_g_tuner,
353 .vidioc_s_tuner = vidioc_s_tuner,
Mauro Carvalho Chehab140dcc42007-01-25 15:00:45 -0300354 .vidioc_g_audio = vidioc_g_audio,
355 .vidioc_s_audio = vidioc_s_audio,
Mauro Carvalho Chehaba0c05ab2007-01-25 16:48:13 -0300356 .vidioc_g_input = vidioc_g_input,
357 .vidioc_s_input = vidioc_s_input,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300358 .vidioc_g_frequency = vidioc_g_frequency,
359 .vidioc_s_frequency = vidioc_s_frequency,
360 .vidioc_queryctrl = vidioc_queryctrl,
361 .vidioc_g_ctrl = vidioc_g_ctrl,
362 .vidioc_s_ctrl = vidioc_s_ctrl,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300363};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
365static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
366{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300367 struct maxiradio *dev;
368 struct v4l2_device *v4l2_dev;
369 int retval = -ENOMEM;
370
371 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
372 if (dev == NULL) {
373 dev_err(&pdev->dev, "not enough memory\n");
374 return -ENOMEM;
375 }
376
377 v4l2_dev = &dev->v4l2_dev;
378 mutex_init(&dev->lock);
379 dev->pdev = pdev;
380 dev->muted = 1;
381 dev->freq = FREQ_LO;
382
383 strlcpy(v4l2_dev->name, "maxiradio", sizeof(v4l2_dev->name));
384
385 retval = v4l2_device_register(&pdev->dev, v4l2_dev);
386 if (retval < 0) {
387 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
388 goto errfr;
389 }
390
391 if (!request_region(pci_resource_start(pdev, 0),
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300392 pci_resource_len(pdev, 0), "Maxi Radio FM 2000")) {
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300393 v4l2_err(v4l2_dev, "can't reserve I/O ports\n");
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300394 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 }
396
397 if (pci_enable_device(pdev))
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300398 goto err_out_free_region;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300400 dev->io = pci_resource_start(pdev, 0);
401 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
402 dev->vdev.v4l2_dev = v4l2_dev;
403 dev->vdev.fops = &maxiradio_fops;
404 dev->vdev.ioctl_ops = &maxiradio_ioctl_ops;
405 dev->vdev.release = video_device_release_empty;
406 video_set_drvdata(&dev->vdev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300408 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
409 v4l2_err(v4l2_dev, "can't register device!");
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300410 goto err_out_free_region;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 }
412
Michal Marek372c05c2011-04-01 12:41:20 +0200413 v4l2_info(v4l2_dev, "version " DRIVER_VERSION "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300415 v4l2_info(v4l2_dev, "found Guillemot MAXI Radio device (io = 0x%x)\n",
416 dev->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 return 0;
418
419err_out_free_region:
420 release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
421err_out:
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300422 v4l2_device_unregister(v4l2_dev);
423errfr:
424 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 return -ENODEV;
426}
427
428static void __devexit maxiradio_remove_one(struct pci_dev *pdev)
429{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300430 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
431 struct maxiradio *dev = to_maxiradio(v4l2_dev);
432
433 video_unregister_device(&dev->vdev);
434 v4l2_device_unregister(&dev->v4l2_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
436}
437
438static struct pci_device_id maxiradio_pci_tbl[] = {
439 { PCI_VENDOR_ID_GUILLEMOT, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO,
440 PCI_ANY_ID, PCI_ANY_ID, },
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300441 { 0 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442};
443
444MODULE_DEVICE_TABLE(pci, maxiradio_pci_tbl);
445
446static struct pci_driver maxiradio_driver = {
447 .name = "radio-maxiradio",
448 .id_table = maxiradio_pci_tbl,
449 .probe = maxiradio_init_one,
450 .remove = __devexit_p(maxiradio_remove_one),
451};
452
453static int __init maxiradio_radio_init(void)
454{
Richard Knutsson9bfab8c2005-11-30 00:59:34 +0100455 return pci_register_driver(&maxiradio_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456}
457
458static void __exit maxiradio_radio_exit(void)
459{
460 pci_unregister_driver(&maxiradio_driver);
461}
462
463module_init(maxiradio_radio_init);
464module_exit(maxiradio_radio_exit);