blob: af99c5bd88c1f0ce15311ec63c137aeee2ce42ab [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* zoltrix radio plus driver for Linux radio support
2 * (c) 1998 C. van Schaik <carl@leg.uct.ac.za>
3 *
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -03004 * BUGS
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Due to the inconsistency in reading from the signal flags
6 * it is difficult to get an accurate tuned signal.
7 *
8 * It seems that the card is not linear to 0 volume. It cuts off
9 * at a low volume, and it is not possible (at least I have not found)
10 * to get fine volume control over the low volume range.
11 *
12 * Some code derived from code by Romolo Manfredini
13 * romolo@bicnet.it
14 *
15 * 1999-05-06 - (C. van Schaik)
16 * - Make signal strength and stereo scans
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030017 * kinder to cpu while in delay
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * 1999-01-05 - (C. van Schaik)
19 * - Changed tuning to 1/160Mhz accuracy
20 * - Added stereo support
21 * (card defaults to stereo)
22 * (can explicitly force mono on the card)
23 * (can detect if station is in stereo)
24 * - Added unmute function
25 * - Reworked ioctl functions
26 * 2002-07-15 - Fix Stereo typo
Mauro Carvalho Chehab2ab65292006-08-08 09:10:04 -030027 *
28 * 2006-07-24 - Converted to V4L2 API
29 * by Mauro Carvalho Chehab <mchehab@infradead.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 */
31
32#include <linux/module.h> /* Modules */
33#include <linux/init.h> /* Initdata */
Peter Osterlundfb911ee2005-09-13 01:25:15 -070034#include <linux/ioport.h> /* request_region */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/delay.h> /* udelay, msleep */
Mauro Carvalho Chehab2ab65292006-08-08 09:10:04 -030036#include <linux/videodev2.h> /* kernel radio structs */
Hans Verkuilec632c82009-03-06 13:55:34 -030037#include <linux/mutex.h>
38#include <linux/version.h> /* for KERNEL_VERSION MACRO */
39#include <linux/io.h> /* outb, outb_p */
Hans Verkuilec632c82009-03-06 13:55:34 -030040#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030041#include <media/v4l2-ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Hans Verkuilec632c82009-03-06 13:55:34 -030043MODULE_AUTHOR("C.van Schaik");
44MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
45MODULE_LICENSE("GPL");
Mauro Carvalho Chehab2ab65292006-08-08 09:10:04 -030046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#ifndef CONFIG_RADIO_ZOLTRIX_PORT
48#define CONFIG_RADIO_ZOLTRIX_PORT -1
49#endif
50
51static int io = CONFIG_RADIO_ZOLTRIX_PORT;
52static int radio_nr = -1;
53
Hans Verkuilec632c82009-03-06 13:55:34 -030054module_param(io, int, 0);
55MODULE_PARM_DESC(io, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
56module_param(radio_nr, int, 0);
57
58#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
59
60struct zoltrix {
61 struct v4l2_device v4l2_dev;
62 struct video_device vdev;
63 int io;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 int curvol;
65 unsigned long curfreq;
66 int muted;
67 unsigned int stereo;
Ingo Molnar3593cab2006-02-07 06:49:14 -020068 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069};
70
Hans Verkuilec632c82009-03-06 13:55:34 -030071static struct zoltrix zoltrix_card;
72
73static int zol_setvol(struct zoltrix *zol, int vol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Hans Verkuilec632c82009-03-06 13:55:34 -030075 zol->curvol = vol;
76 if (zol->muted)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 return 0;
78
Hans Verkuilec632c82009-03-06 13:55:34 -030079 mutex_lock(&zol->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 if (vol == 0) {
Hans Verkuilec632c82009-03-06 13:55:34 -030081 outb(0, zol->io);
82 outb(0, zol->io);
83 inb(zol->io + 3); /* Zoltrix needs to be read to confirm */
84 mutex_unlock(&zol->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 return 0;
86 }
87
Hans Verkuilec632c82009-03-06 13:55:34 -030088 outb(zol->curvol-1, zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 msleep(10);
Hans Verkuilec632c82009-03-06 13:55:34 -030090 inb(zol->io + 2);
91 mutex_unlock(&zol->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 return 0;
93}
94
Hans Verkuilec632c82009-03-06 13:55:34 -030095static void zol_mute(struct zoltrix *zol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Hans Verkuilec632c82009-03-06 13:55:34 -030097 zol->muted = 1;
98 mutex_lock(&zol->lock);
99 outb(0, zol->io);
100 outb(0, zol->io);
101 inb(zol->io + 3); /* Zoltrix needs to be read to confirm */
102 mutex_unlock(&zol->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
Hans Verkuilec632c82009-03-06 13:55:34 -0300105static void zol_unmute(struct zoltrix *zol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Hans Verkuilec632c82009-03-06 13:55:34 -0300107 zol->muted = 0;
108 zol_setvol(zol, zol->curvol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Hans Verkuilec632c82009-03-06 13:55:34 -0300111static int zol_setfreq(struct zoltrix *zol, unsigned long freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
113 /* tunes the radio to the desired frequency */
Hans Verkuilec632c82009-03-06 13:55:34 -0300114 struct v4l2_device *v4l2_dev = &zol->v4l2_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 unsigned long long bitmask, f, m;
Hans Verkuilec632c82009-03-06 13:55:34 -0300116 unsigned int stereo = zol->stereo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 int i;
118
Alexey Klimovb4be2042008-10-09 13:46:59 -0300119 if (freq == 0) {
Hans Verkuilec632c82009-03-06 13:55:34 -0300120 v4l2_warn(v4l2_dev, "cannot set a frequency of 0.\n");
Alexey Klimovb4be2042008-10-09 13:46:59 -0300121 return -EINVAL;
122 }
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 m = (freq / 160 - 8800) * 2;
Hans Verkuilec632c82009-03-06 13:55:34 -0300125 f = (unsigned long long)m + 0x4d1c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 bitmask = 0xc480402c10080000ull;
128 i = 45;
129
Hans Verkuilec632c82009-03-06 13:55:34 -0300130 mutex_lock(&zol->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300131
Hans Verkuilec632c82009-03-06 13:55:34 -0300132 zol->curfreq = freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Hans Verkuilec632c82009-03-06 13:55:34 -0300134 outb(0, zol->io);
135 outb(0, zol->io);
136 inb(zol->io + 3); /* Zoltrix needs to be read to confirm */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Hans Verkuilec632c82009-03-06 13:55:34 -0300138 outb(0x40, zol->io);
139 outb(0xc0, zol->io);
140
141 bitmask = (bitmask ^ ((f & 0xff) << 47) ^ ((f & 0xff00) << 30) ^ (stereo << 31));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 while (i--) {
143 if ((bitmask & 0x8000000000000000ull) != 0) {
Hans Verkuilec632c82009-03-06 13:55:34 -0300144 outb(0x80, zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 udelay(50);
Hans Verkuilec632c82009-03-06 13:55:34 -0300146 outb(0x00, zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 udelay(50);
Hans Verkuilec632c82009-03-06 13:55:34 -0300148 outb(0x80, zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 udelay(50);
150 } else {
Hans Verkuilec632c82009-03-06 13:55:34 -0300151 outb(0xc0, zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 udelay(50);
Hans Verkuilec632c82009-03-06 13:55:34 -0300153 outb(0x40, zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 udelay(50);
Hans Verkuilec632c82009-03-06 13:55:34 -0300155 outb(0xc0, zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 udelay(50);
157 }
158 bitmask *= 2;
159 }
160 /* termination sequence */
Hans Verkuilec632c82009-03-06 13:55:34 -0300161 outb(0x80, zol->io);
162 outb(0xc0, zol->io);
163 outb(0x40, zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 udelay(1000);
Hans Verkuilec632c82009-03-06 13:55:34 -0300165 inb(zol->io + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300167 udelay(1000);
168
Hans Verkuilec632c82009-03-06 13:55:34 -0300169 if (zol->muted) {
170 outb(0, zol->io);
171 outb(0, zol->io);
172 inb(zol->io + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 udelay(1000);
174 }
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300175
Hans Verkuilec632c82009-03-06 13:55:34 -0300176 mutex_unlock(&zol->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300177
Hans Verkuilec632c82009-03-06 13:55:34 -0300178 if (!zol->muted)
179 zol_setvol(zol, zol->curvol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 return 0;
181}
182
183/* Get signal strength */
Hans Verkuilec632c82009-03-06 13:55:34 -0300184static int zol_getsigstr(struct zoltrix *zol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
186 int a, b;
187
Hans Verkuilec632c82009-03-06 13:55:34 -0300188 mutex_lock(&zol->lock);
189 outb(0x00, zol->io); /* This stuff I found to do nothing */
190 outb(zol->curvol, zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 msleep(20);
192
Hans Verkuilec632c82009-03-06 13:55:34 -0300193 a = inb(zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 msleep(10);
Hans Verkuilec632c82009-03-06 13:55:34 -0300195 b = inb(zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Hans Verkuilec632c82009-03-06 13:55:34 -0300197 mutex_unlock(&zol->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if (a != b)
Hans Verkuilec632c82009-03-06 13:55:34 -0300200 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Hans Verkuilec632c82009-03-06 13:55:34 -0300202 /* I found this out by playing with a binary scanner on the card io */
203 return a == 0xcf || a == 0xdf || a == 0xef;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
205
Hans Verkuilec632c82009-03-06 13:55:34 -0300206static int zol_is_stereo(struct zoltrix *zol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
208 int x1, x2;
209
Hans Verkuilec632c82009-03-06 13:55:34 -0300210 mutex_lock(&zol->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300211
Hans Verkuilec632c82009-03-06 13:55:34 -0300212 outb(0x00, zol->io);
213 outb(zol->curvol, zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 msleep(20);
215
Hans Verkuilec632c82009-03-06 13:55:34 -0300216 x1 = inb(zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 msleep(10);
Hans Verkuilec632c82009-03-06 13:55:34 -0300218 x2 = inb(zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Hans Verkuilec632c82009-03-06 13:55:34 -0300220 mutex_unlock(&zol->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300221
Hans Verkuilec632c82009-03-06 13:55:34 -0300222 return x1 == x2 && x1 == 0xcf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300225static int vidioc_querycap(struct file *file, void *priv,
226 struct v4l2_capability *v)
227{
228 strlcpy(v->driver, "radio-zoltrix", sizeof(v->driver));
229 strlcpy(v->card, "Zoltrix Radio", sizeof(v->card));
Hans Verkuilec632c82009-03-06 13:55:34 -0300230 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300231 v->version = RADIO_VERSION;
Hans Verkuilec632c82009-03-06 13:55:34 -0300232 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300233 return 0;
234}
235
236static int vidioc_g_tuner(struct file *file, void *priv,
237 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
Hans Verkuilec632c82009-03-06 13:55:34 -0300239 struct zoltrix *zol = video_drvdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300241 if (v->index > 0)
242 return -EINVAL;
Mauro Carvalho Chehab2ab65292006-08-08 09:10:04 -0300243
Hans Verkuilec632c82009-03-06 13:55:34 -0300244 strlcpy(v->name, "FM", sizeof(v->name));
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300245 v->type = V4L2_TUNER_RADIO;
Hans Verkuilec632c82009-03-06 13:55:34 -0300246 v->rangelow = 88 * 16000;
247 v->rangehigh = 108 * 16000;
248 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300249 v->capability = V4L2_TUNER_CAP_LOW;
250 if (zol_is_stereo(zol))
251 v->audmode = V4L2_TUNER_MODE_STEREO;
252 else
253 v->audmode = V4L2_TUNER_MODE_MONO;
Hans Verkuilec632c82009-03-06 13:55:34 -0300254 v->signal = 0xFFFF * zol_getsigstr(zol);
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300255 return 0;
256}
257
258static int vidioc_s_tuner(struct file *file, void *priv,
259 struct v4l2_tuner *v)
260{
Hans Verkuilec632c82009-03-06 13:55:34 -0300261 return v->index ? -EINVAL : 0;
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300262}
263
264static int vidioc_s_frequency(struct file *file, void *priv,
265 struct v4l2_frequency *f)
266{
Hans Verkuilec632c82009-03-06 13:55:34 -0300267 struct zoltrix *zol = video_drvdata(file);
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300268
Hans Verkuila3a9e282009-11-27 04:33:25 -0300269 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
270 return -EINVAL;
Hans Verkuilec632c82009-03-06 13:55:34 -0300271 if (zol_setfreq(zol, f->frequency) != 0)
Alexey Klimovb4be2042008-10-09 13:46:59 -0300272 return -EINVAL;
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300273 return 0;
274}
275
276static int vidioc_g_frequency(struct file *file, void *priv,
277 struct v4l2_frequency *f)
278{
Hans Verkuilec632c82009-03-06 13:55:34 -0300279 struct zoltrix *zol = video_drvdata(file);
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300280
Hans Verkuila3a9e282009-11-27 04:33:25 -0300281 if (f->tuner != 0)
282 return -EINVAL;
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300283 f->type = V4L2_TUNER_RADIO;
284 f->frequency = zol->curfreq;
285 return 0;
286}
287
288static int vidioc_queryctrl(struct file *file, void *priv,
289 struct v4l2_queryctrl *qc)
290{
Hans Verkuilec632c82009-03-06 13:55:34 -0300291 switch (qc->id) {
292 case V4L2_CID_AUDIO_MUTE:
293 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
294 case V4L2_CID_AUDIO_VOLUME:
295 return v4l2_ctrl_query_fill(qc, 0, 65535, 4096, 65535);
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300296 }
297 return -EINVAL;
298}
Mauro Carvalho Chehab2ab65292006-08-08 09:10:04 -0300299
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300300static int vidioc_g_ctrl(struct file *file, void *priv,
301 struct v4l2_control *ctrl)
302{
Hans Verkuilec632c82009-03-06 13:55:34 -0300303 struct zoltrix *zol = video_drvdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300305 switch (ctrl->id) {
306 case V4L2_CID_AUDIO_MUTE:
307 ctrl->value = zol->muted;
308 return 0;
309 case V4L2_CID_AUDIO_VOLUME:
310 ctrl->value = zol->curvol * 4096;
311 return 0;
312 }
313 return -EINVAL;
314}
Mauro Carvalho Chehab2ab65292006-08-08 09:10:04 -0300315
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300316static int vidioc_s_ctrl(struct file *file, void *priv,
317 struct v4l2_control *ctrl)
318{
Hans Verkuilec632c82009-03-06 13:55:34 -0300319 struct zoltrix *zol = video_drvdata(file);
Mauro Carvalho Chehab2ab65292006-08-08 09:10:04 -0300320
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300321 switch (ctrl->id) {
322 case V4L2_CID_AUDIO_MUTE:
323 if (ctrl->value)
324 zol_mute(zol);
325 else {
326 zol_unmute(zol);
Hans Verkuilec632c82009-03-06 13:55:34 -0300327 zol_setvol(zol, zol->curvol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300329 return 0;
330 case V4L2_CID_AUDIO_VOLUME:
Hans Verkuilec632c82009-03-06 13:55:34 -0300331 zol_setvol(zol, ctrl->value / 4096);
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300332 return 0;
333 }
334 zol->stereo = 1;
Hans Verkuilec632c82009-03-06 13:55:34 -0300335 if (zol_setfreq(zol, zol->curfreq) != 0)
Alexey Klimovb4be2042008-10-09 13:46:59 -0300336 return -EINVAL;
Mauro Carvalho Chehab2ab65292006-08-08 09:10:04 -0300337#if 0
338/* FIXME: Implement stereo/mono switch on V4L2 */
Hans Verkuilec632c82009-03-06 13:55:34 -0300339 if (v->mode & VIDEO_SOUND_STEREO) {
340 zol->stereo = 1;
341 zol_setfreq(zol, zol->curfreq);
342 }
343 if (v->mode & VIDEO_SOUND_MONO) {
344 zol->stereo = 0;
345 zol_setfreq(zol, zol->curfreq);
346 }
Mauro Carvalho Chehab2ab65292006-08-08 09:10:04 -0300347#endif
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300348 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300351static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
352{
353 *i = 0;
354 return 0;
355}
356
357static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
358{
Hans Verkuilec632c82009-03-06 13:55:34 -0300359 return i ? -EINVAL : 0;
360}
361
362static int vidioc_g_audio(struct file *file, void *priv,
363 struct v4l2_audio *a)
364{
365 a->index = 0;
366 strlcpy(a->name, "Radio", sizeof(a->name));
367 a->capability = V4L2_AUDCAP_STEREO;
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300368 return 0;
369}
370
371static int vidioc_s_audio(struct file *file, void *priv,
372 struct v4l2_audio *a)
373{
Hans Verkuilec632c82009-03-06 13:55:34 -0300374 return a->index ? -EINVAL : 0;
375}
376
Hans Verkuilbec43662008-12-30 06:58:20 -0300377static const struct v4l2_file_operations zoltrix_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
379 .owner = THIS_MODULE,
Hans Verkuil32958fd2010-11-14 09:36:23 -0300380 .unlocked_ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381};
382
Hans Verkuila3998102008-07-21 02:57:38 -0300383static const struct v4l2_ioctl_ops zoltrix_ioctl_ops = {
Douglas Landgrafa1314b12007-04-20 18:23:38 -0300384 .vidioc_querycap = vidioc_querycap,
385 .vidioc_g_tuner = vidioc_g_tuner,
386 .vidioc_s_tuner = vidioc_s_tuner,
387 .vidioc_g_audio = vidioc_g_audio,
388 .vidioc_s_audio = vidioc_s_audio,
389 .vidioc_g_input = vidioc_g_input,
390 .vidioc_s_input = vidioc_s_input,
391 .vidioc_g_frequency = vidioc_g_frequency,
392 .vidioc_s_frequency = vidioc_s_frequency,
393 .vidioc_queryctrl = vidioc_queryctrl,
394 .vidioc_g_ctrl = vidioc_g_ctrl,
395 .vidioc_s_ctrl = vidioc_s_ctrl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396};
397
398static int __init zoltrix_init(void)
399{
Hans Verkuilec632c82009-03-06 13:55:34 -0300400 struct zoltrix *zol = &zoltrix_card;
401 struct v4l2_device *v4l2_dev = &zol->v4l2_dev;
402 int res;
403
404 strlcpy(v4l2_dev->name, "zoltrix", sizeof(v4l2_dev->name));
405 zol->io = io;
406 if (zol->io == -1) {
Hans Verkuilb24c20cc2009-03-09 08:11:21 -0300407 v4l2_err(v4l2_dev, "You must set an I/O address with io=0x20c or 0x30c\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 return -EINVAL;
409 }
Hans Verkuilec632c82009-03-06 13:55:34 -0300410 if (zol->io != 0x20c && zol->io != 0x30c) {
411 v4l2_err(v4l2_dev, "invalid port, try 0x20c or 0x30c\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 return -ENXIO;
413 }
414
Hans Verkuilec632c82009-03-06 13:55:34 -0300415 if (!request_region(zol->io, 2, "zoltrix")) {
416 v4l2_err(v4l2_dev, "port 0x%x already in use\n", zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 return -EBUSY;
418 }
419
Hans Verkuilec632c82009-03-06 13:55:34 -0300420 res = v4l2_device_register(NULL, v4l2_dev);
421 if (res < 0) {
422 release_region(zol->io, 2);
423 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
424 return res;
425 }
426
Hans Verkuilec632c82009-03-06 13:55:34 -0300427 mutex_init(&zol->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 /* mute card - prevents noisy bootups */
430
431 /* this ensures that the volume is all the way down */
432
Hans Verkuilec632c82009-03-06 13:55:34 -0300433 outb(0, zol->io);
434 outb(0, zol->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 msleep(20);
Hans Verkuilec632c82009-03-06 13:55:34 -0300436 inb(zol->io + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Hans Verkuilec632c82009-03-06 13:55:34 -0300438 zol->curvol = 0;
439 zol->stereo = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Hans Verkuil32958fd2010-11-14 09:36:23 -0300441 strlcpy(zol->vdev.name, v4l2_dev->name, sizeof(zol->vdev.name));
442 zol->vdev.v4l2_dev = v4l2_dev;
443 zol->vdev.fops = &zoltrix_fops;
444 zol->vdev.ioctl_ops = &zoltrix_ioctl_ops;
445 zol->vdev.release = video_device_release_empty;
446 video_set_drvdata(&zol->vdev, zol);
447
448 if (video_register_device(&zol->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
449 v4l2_device_unregister(v4l2_dev);
450 release_region(zol->io, 2);
451 return -EINVAL;
452 }
453 v4l2_info(v4l2_dev, "Zoltrix Radio Plus card driver.\n");
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 return 0;
456}
457
Hans Verkuilec632c82009-03-06 13:55:34 -0300458static void __exit zoltrix_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
Hans Verkuilec632c82009-03-06 13:55:34 -0300460 struct zoltrix *zol = &zoltrix_card;
461
462 video_unregister_device(&zol->vdev);
463 v4l2_device_unregister(&zol->v4l2_dev);
464 release_region(zol->io, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465}
466
467module_init(zoltrix_init);
Hans Verkuilec632c82009-03-06 13:55:34 -0300468module_exit(zoltrix_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469