blob: 4349213b403b55944f0ecac6edfbd3fe9e18f2bb [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:
16 * http://www.semiconductors.philips.com/pip/TEA5757H/V1
17 *
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/version.h> /* for KERNEL_VERSION MACRO */
44#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090045#include <linux/slab.h>
Hans Verkuil2710e6a2009-03-06 13:51:33 -030046#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030047#include <media/v4l2-ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Hans Verkuil2710e6a2009-03-06 13:51:33 -030049MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net");
50MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000 radio.");
51MODULE_LICENSE("GPL");
52
53static int radio_nr = -1;
54module_param(radio_nr, int, 0);
55
56static int debug;
57
58module_param(debug, int, 0644);
59MODULE_PARM_DESC(debug, "activates debug info");
60
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -030061#define DRIVER_VERSION "0.77"
Mauro Carvalho Chehabe84fef62006-08-08 09:10:05 -030062
Hans Verkuil2710e6a2009-03-06 13:51:33 -030063#define RADIO_VERSION KERNEL_VERSION(0, 7, 7)
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -030064
Hans Verkuil2710e6a2009-03-06 13:51:33 -030065#define dprintk(dev, num, fmt, arg...) \
66 v4l2_dbg(num, debug, &dev->v4l2_dev, fmt, ## arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68#ifndef PCI_VENDOR_ID_GUILLEMOT
69#define PCI_VENDOR_ID_GUILLEMOT 0x5046
70#endif
71
72#ifndef PCI_DEVICE_ID_GUILLEMOT
73#define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
74#endif
75
76
77/* TEA5757 pin mappings */
Hans Verkuil2710e6a2009-03-06 13:51:33 -030078static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Hans Verkuil2710e6a2009-03-06 13:51:33 -030080#define FREQ_LO (50 * 16000)
81#define FREQ_HI (150 * 16000)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83#define FREQ_IF 171200 /* 10.7*16000 */
84#define FREQ_STEP 200 /* 12.5*16 */
85
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -030086/* (x==fmhz*16*1000) -> bits */
Hans Verkuil2710e6a2009-03-06 13:51:33 -030087#define FREQ2BITS(x) \
88 ((((unsigned int)(x) + FREQ_IF + (FREQ_STEP << 1)) / (FREQ_STEP << 2)) << 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90#define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF)
91
92
Hans Verkuil2710e6a2009-03-06 13:51:33 -030093struct maxiradio
Hans Verkuil3ca685a2008-08-23 04:49:13 -030094{
Hans Verkuil2710e6a2009-03-06 13:51:33 -030095 struct v4l2_device v4l2_dev;
96 struct video_device vdev;
97 struct pci_dev *pdev;
Hans Verkuil3ca685a2008-08-23 04:49:13 -030098
Hans Verkuil2710e6a2009-03-06 13:51:33 -030099 u16 io; /* base of radio io */
100 u16 muted; /* VIDEO_AUDIO_MUTE */
101 u16 stereo; /* VIDEO_TUNER_STEREO_ON */
102 u16 tuned; /* signal strength (0 or 0xffff) */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 unsigned long freq;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300105
Ingo Molnar3593cab2006-02-07 06:49:14 -0200106 struct mutex lock;
Mauro Carvalho Chehab712642b2007-01-26 07:33:07 -0300107};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300109static inline struct maxiradio *to_maxiradio(struct v4l2_device *v4l2_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300111 return container_of(v4l2_dev, struct maxiradio, v4l2_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300114static void outbit(unsigned long bit, u16 io)
115{
116 int val = power | wren | (bit ? data : 0);
117
118 outb(val, io);
119 udelay(4);
120 outb(val | clk, io);
121 udelay(4);
122 outb(val, io);
123 udelay(4);
124}
125
126static void turn_power(struct maxiradio *dev, int p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300128 if (p != 0) {
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300129 dprintk(dev, 1, "Radio powered on\n");
130 outb(power, dev->io);
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300131 } else {
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300132 dprintk(dev, 1, "Radio powered off\n");
133 outb(0, dev->io);
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300134 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
136
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300137static void set_freq(struct maxiradio *dev, u32 freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
139 unsigned long int si;
140 int bl;
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300141 int io = dev->io;
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300142 int val = FREQ2BITS(freq);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 /* TEA5757 shift register bits (see pdf) */
145
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300146 outbit(0, io); /* 24 search */
147 outbit(1, io); /* 23 search up/down */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300148
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300149 outbit(0, io); /* 22 stereo/mono */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300151 outbit(0, io); /* 21 band */
152 outbit(0, io); /* 20 band (only 00=FM works I think) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300154 outbit(0, io); /* 19 port ? */
155 outbit(0, io); /* 18 port ? */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300156
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300157 outbit(0, io); /* 17 search level */
158 outbit(0, io); /* 16 search level */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 si = 0x8000;
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -0300161 for (bl = 1; bl <= 16; bl++) {
162 outbit(val & si, io);
163 si >>= 1;
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300164 }
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300165
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300166 dprintk(dev, 1, "Radio freq set to %d.%02d MHz\n",
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300167 freq / 16000,
168 freq % 16000 * 100 / 16000);
169
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300170 turn_power(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300173static int get_stereo(u16 io)
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300174{
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300175 outb(power,io);
176 udelay(4);
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return !(inb(io) & mo_st);
179}
180
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300181static int get_tune(u16 io)
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300182{
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300183 outb(power+clk,io);
184 udelay(4);
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 return !(inb(io) & mo_st);
187}
188
189
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300190static int vidioc_querycap(struct file *file, void *priv,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300191 struct v4l2_capability *v)
192{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300193 struct maxiradio *dev = video_drvdata(file);
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300194
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300195 strlcpy(v->driver, "radio-maxiradio", sizeof(v->driver));
196 strlcpy(v->card, "Maxi Radio FM2000 radio", sizeof(v->card));
197 snprintf(v->bus_info, sizeof(v->bus_info), "PCI:%s", pci_name(dev->pdev));
198 v->version = RADIO_VERSION;
199 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300200 return 0;
201}
202
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300203static int vidioc_g_tuner(struct file *file, void *priv,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300204 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300206 struct maxiradio *dev = video_drvdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300208 if (v->index > 0)
209 return -EINVAL;
Mauro Carvalho Chehabe84fef62006-08-08 09:10:05 -0300210
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300211 mutex_lock(&dev->lock);
212 strlcpy(v->name, "FM", sizeof(v->name));
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300213 v->type = V4L2_TUNER_RADIO;
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300214 v->rangelow = FREQ_LO;
215 v->rangehigh = FREQ_HI;
216 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
217 v->capability = V4L2_TUNER_CAP_LOW;
218 if (get_stereo(dev->io))
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300219 v->audmode = V4L2_TUNER_MODE_STEREO;
220 else
221 v->audmode = V4L2_TUNER_MODE_MONO;
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300222 v->signal = 0xffff * get_tune(dev->io);
223 mutex_unlock(&dev->lock);
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300224
225 return 0;
226}
227
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300228static int vidioc_s_tuner(struct file *file, void *priv,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300229 struct v4l2_tuner *v)
230{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300231 return v->index ? -EINVAL : 0;
Mauro Carvalho Chehab140dcc42007-01-25 15:00:45 -0300232}
233
Mauro Carvalho Chehaba0c05ab2007-01-25 16:48:13 -0300234static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
235{
236 *i = 0;
237 return 0;
238}
239
240static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
241{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300242 return i ? -EINVAL : 0;
Mauro Carvalho Chehaba0c05ab2007-01-25 16:48:13 -0300243}
244
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300245static int vidioc_g_audio(struct file *file, void *priv,
Mauro Carvalho Chehab140dcc42007-01-25 15:00:45 -0300246 struct v4l2_audio *a)
247{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300248 a->index = 0;
249 strlcpy(a->name, "Radio", sizeof(a->name));
250 a->capability = V4L2_AUDCAP_STEREO;
Mauro Carvalho Chehab140dcc42007-01-25 15:00:45 -0300251 return 0;
252}
253
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300254
255static int vidioc_s_audio(struct file *file, void *priv,
256 struct v4l2_audio *a)
257{
258 return a->index ? -EINVAL : 0;
259}
260
261static int vidioc_s_frequency(struct file *file, void *priv,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300262 struct v4l2_frequency *f)
263{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300264 struct maxiradio *dev = video_drvdata(file);
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300265
Hans Verkuila3a9e282009-11-27 04:33:25 -0300266 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
267 return -EINVAL;
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300268 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) {
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300269 dprintk(dev, 1, "radio freq (%d.%02d MHz) out of range (%d-%d)\n",
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300270 f->frequency / 16000,
271 f->frequency % 16000 * 100 / 16000,
272 FREQ_LO / 16000, FREQ_HI / 16000);
273
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300274 return -EINVAL;
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300275 }
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300276
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300277 mutex_lock(&dev->lock);
278 dev->freq = f->frequency;
279 set_freq(dev, dev->freq);
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300280 msleep(125);
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300281 mutex_unlock(&dev->lock);
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300282
283 return 0;
284}
285
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300286static int vidioc_g_frequency(struct file *file, void *priv,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300287 struct v4l2_frequency *f)
288{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300289 struct maxiradio *dev = video_drvdata(file);
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300290
Hans Verkuila3a9e282009-11-27 04:33:25 -0300291 if (f->tuner != 0)
292 return -EINVAL;
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300293 f->type = V4L2_TUNER_RADIO;
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300294 f->frequency = dev->freq;
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300295
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300296 dprintk(dev, 4, "radio freq is %d.%02d MHz",
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300297 f->frequency / 16000,
298 f->frequency % 16000 * 100 / 16000);
299
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300300 return 0;
301}
302
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300303static int vidioc_queryctrl(struct file *file, void *priv,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300304 struct v4l2_queryctrl *qc)
305{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300306 switch (qc->id) {
307 case V4L2_CID_AUDIO_MUTE:
308 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300310 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300313static int vidioc_g_ctrl(struct file *file, void *priv,
314 struct v4l2_control *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300316 struct maxiradio *dev = video_drvdata(file);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300317
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300318 switch (ctrl->id) {
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300319 case V4L2_CID_AUDIO_MUTE:
320 ctrl->value = dev->muted;
321 return 0;
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300322 }
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300323
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300324 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
326
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300327static int vidioc_s_ctrl(struct file *file, void *priv,
328 struct v4l2_control *ctrl)
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300329{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300330 struct maxiradio *dev = video_drvdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300332 switch (ctrl->id) {
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300333 case V4L2_CID_AUDIO_MUTE:
334 mutex_lock(&dev->lock);
335 dev->muted = ctrl->value;
336 if (dev->muted)
337 turn_power(dev, 0);
338 else
339 set_freq(dev, dev->freq);
340 mutex_unlock(&dev->lock);
341 return 0;
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300342 }
Mauro Carvalho Chehabf1557ce2007-01-26 07:23:44 -0300343
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300344 return -EINVAL;
345}
346
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300347static const struct v4l2_file_operations maxiradio_fops = {
348 .owner = THIS_MODULE,
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300349 .ioctl = video_ioctl2,
350};
351
Hans Verkuila3998102008-07-21 02:57:38 -0300352static const struct v4l2_ioctl_ops maxiradio_ioctl_ops = {
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300353 .vidioc_querycap = vidioc_querycap,
354 .vidioc_g_tuner = vidioc_g_tuner,
355 .vidioc_s_tuner = vidioc_s_tuner,
Mauro Carvalho Chehab140dcc42007-01-25 15:00:45 -0300356 .vidioc_g_audio = vidioc_g_audio,
357 .vidioc_s_audio = vidioc_s_audio,
Mauro Carvalho Chehaba0c05ab2007-01-25 16:48:13 -0300358 .vidioc_g_input = vidioc_g_input,
359 .vidioc_s_input = vidioc_s_input,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300360 .vidioc_g_frequency = vidioc_g_frequency,
361 .vidioc_s_frequency = vidioc_s_frequency,
362 .vidioc_queryctrl = vidioc_queryctrl,
363 .vidioc_g_ctrl = vidioc_g_ctrl,
364 .vidioc_s_ctrl = vidioc_s_ctrl,
Mauro Carvalho Chehab06470ed2007-01-25 09:04:34 -0300365};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
368{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300369 struct maxiradio *dev;
370 struct v4l2_device *v4l2_dev;
371 int retval = -ENOMEM;
372
373 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
374 if (dev == NULL) {
375 dev_err(&pdev->dev, "not enough memory\n");
376 return -ENOMEM;
377 }
378
379 v4l2_dev = &dev->v4l2_dev;
380 mutex_init(&dev->lock);
381 dev->pdev = pdev;
382 dev->muted = 1;
383 dev->freq = FREQ_LO;
384
385 strlcpy(v4l2_dev->name, "maxiradio", sizeof(v4l2_dev->name));
386
387 retval = v4l2_device_register(&pdev->dev, v4l2_dev);
388 if (retval < 0) {
389 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
390 goto errfr;
391 }
392
393 if (!request_region(pci_resource_start(pdev, 0),
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300394 pci_resource_len(pdev, 0), "Maxi Radio FM 2000")) {
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300395 v4l2_err(v4l2_dev, "can't reserve I/O ports\n");
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300396 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 }
398
399 if (pci_enable_device(pdev))
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300400 goto err_out_free_region;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300402 dev->io = pci_resource_start(pdev, 0);
403 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
404 dev->vdev.v4l2_dev = v4l2_dev;
405 dev->vdev.fops = &maxiradio_fops;
406 dev->vdev.ioctl_ops = &maxiradio_ioctl_ops;
407 dev->vdev.release = video_device_release_empty;
408 video_set_drvdata(&dev->vdev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300410 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
411 v4l2_err(v4l2_dev, "can't register device!");
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300412 goto err_out_free_region;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 }
414
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300415 v4l2_info(v4l2_dev, "version " DRIVER_VERSION
416 " time " __TIME__ " " __DATE__ "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300418 v4l2_info(v4l2_dev, "found Guillemot MAXI Radio device (io = 0x%x)\n",
419 dev->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 return 0;
421
422err_out_free_region:
423 release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
424err_out:
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300425 v4l2_device_unregister(v4l2_dev);
426errfr:
427 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 return -ENODEV;
429}
430
431static void __devexit maxiradio_remove_one(struct pci_dev *pdev)
432{
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300433 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
434 struct maxiradio *dev = to_maxiradio(v4l2_dev);
435
436 video_unregister_device(&dev->vdev);
437 v4l2_device_unregister(&dev->v4l2_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
439}
440
441static struct pci_device_id maxiradio_pci_tbl[] = {
442 { PCI_VENDOR_ID_GUILLEMOT, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO,
443 PCI_ANY_ID, PCI_ANY_ID, },
Hans Verkuil2710e6a2009-03-06 13:51:33 -0300444 { 0 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445};
446
447MODULE_DEVICE_TABLE(pci, maxiradio_pci_tbl);
448
449static struct pci_driver maxiradio_driver = {
450 .name = "radio-maxiradio",
451 .id_table = maxiradio_pci_tbl,
452 .probe = maxiradio_init_one,
453 .remove = __devexit_p(maxiradio_remove_one),
454};
455
456static int __init maxiradio_radio_init(void)
457{
Richard Knutsson9bfab8c2005-11-30 00:59:34 +0100458 return pci_register_driver(&maxiradio_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
461static void __exit maxiradio_radio_exit(void)
462{
463 pci_unregister_driver(&maxiradio_driver);
464}
465
466module_init(maxiradio_radio_init);
467module_exit(maxiradio_radio_exit);