Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* Typhoon Radio Card driver for radio support |
| 2 | * (c) 1999 Dr. Henrik Seidel <Henrik.Seidel@gmx.de> |
| 3 | * |
| 4 | * Card manufacturer: |
| 5 | * http://194.18.155.92/idc/prod2.idc?nr=50753&lang=e |
| 6 | * |
| 7 | * Notes on the hardware |
| 8 | * |
| 9 | * This card has two output sockets, one for speakers and one for line. |
| 10 | * The speaker output has volume control, but only in four discrete |
| 11 | * steps. The line output has neither volume control nor mute. |
| 12 | * |
| 13 | * The card has auto-stereo according to its manual, although it all |
| 14 | * sounds mono to me (even with the Win/DOS drivers). Maybe it's my |
| 15 | * antenna - I really don't know for sure. |
| 16 | * |
| 17 | * Frequency control is done digitally. |
| 18 | * |
| 19 | * Volume control is done digitally, but there are only four different |
| 20 | * possible values. So you should better always turn the volume up and |
| 21 | * use line control. I got the best results by connecting line output |
| 22 | * to the sound card microphone input. For such a configuration the |
| 23 | * volume control has no effect, since volume control only influences |
| 24 | * the speaker output. |
| 25 | * |
| 26 | * There is no explicit mute/unmute. So I set the radio frequency to a |
| 27 | * value where I do expect just noise and turn the speaker volume down. |
| 28 | * The frequency change is necessary since the card never seems to be |
| 29 | * completely silent. |
Mauro Carvalho Chehab | 30c4830 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 30 | * |
| 31 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | */ |
| 33 | |
| 34 | #include <linux/module.h> /* Modules */ |
| 35 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 36 | #include <linux/ioport.h> /* request_region */ |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 37 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ |
Mauro Carvalho Chehab | 30c4830 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 38 | #include <linux/videodev2.h> /* kernel radio structs */ |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 39 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 40 | #include <media/v4l2-device.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 41 | #include <media/v4l2-ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 43 | MODULE_AUTHOR("Dr. Henrik Seidel"); |
| 44 | MODULE_DESCRIPTION("A driver for the Typhoon radio card (a.k.a. EcoRadio)."); |
| 45 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | #ifndef CONFIG_RADIO_TYPHOON_PORT |
| 48 | #define CONFIG_RADIO_TYPHOON_PORT -1 |
| 49 | #endif |
| 50 | |
| 51 | #ifndef CONFIG_RADIO_TYPHOON_MUTEFREQ |
| 52 | #define CONFIG_RADIO_TYPHOON_MUTEFREQ 0 |
| 53 | #endif |
| 54 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 55 | static int io = CONFIG_RADIO_TYPHOON_PORT; |
| 56 | static int radio_nr = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 58 | module_param(io, int, 0); |
| 59 | MODULE_PARM_DESC(io, "I/O address of the Typhoon card (0x316 or 0x336)"); |
| 60 | |
| 61 | module_param(radio_nr, int, 0); |
| 62 | |
| 63 | static unsigned long mutefreq = CONFIG_RADIO_TYPHOON_MUTEFREQ; |
| 64 | module_param(mutefreq, ulong, 0); |
| 65 | MODULE_PARM_DESC(mutefreq, "Frequency used when muting the card (in kHz)"); |
| 66 | |
| 67 | #define RADIO_VERSION KERNEL_VERSION(0, 1, 1) |
| 68 | |
| 69 | #define BANNER "Typhoon Radio Card driver v0.1.1\n" |
| 70 | |
| 71 | struct typhoon { |
| 72 | struct v4l2_device v4l2_dev; |
| 73 | struct video_device vdev; |
| 74 | int io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | int curvol; |
| 76 | int muted; |
| 77 | unsigned long curfreq; |
| 78 | unsigned long mutefreq; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 79 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 82 | static struct typhoon typhoon_card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 84 | static void typhoon_setvol_generic(struct typhoon *dev, int vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 86 | mutex_lock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | vol >>= 14; /* Map 16 bit to 2 bit */ |
| 88 | vol &= 3; |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 89 | outb_p(vol / 2, dev->io); /* Set the volume, high bit. */ |
| 90 | outb_p(vol % 2, dev->io + 2); /* Set the volume, low bit. */ |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 91 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 94 | static int typhoon_setfreq_generic(struct typhoon *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | unsigned long frequency) |
| 96 | { |
| 97 | unsigned long outval; |
| 98 | unsigned long x; |
| 99 | |
| 100 | /* |
| 101 | * The frequency transfer curve is not linear. The best fit I could |
| 102 | * get is |
| 103 | * |
| 104 | * outval = -155 + exp((f + 15.55) * 0.057)) |
| 105 | * |
| 106 | * where frequency f is in MHz. Since we don't have exp in the kernel, |
| 107 | * I approximate this function by a third order polynomial. |
| 108 | * |
| 109 | */ |
| 110 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 111 | mutex_lock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | x = frequency / 160; |
| 113 | outval = (x * x + 2500) / 5000; |
| 114 | outval = (outval * x + 5000) / 10000; |
| 115 | outval -= (10 * x * x + 10433) / 20866; |
| 116 | outval += 4 * x - 11505; |
| 117 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 118 | outb_p((outval >> 8) & 0x01, dev->io + 4); |
| 119 | outb_p(outval >> 9, dev->io + 6); |
| 120 | outb_p(outval & 0xff, dev->io + 8); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 121 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 126 | static int typhoon_setfreq(struct typhoon *dev, unsigned long frequency) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { |
| 128 | typhoon_setfreq_generic(dev, frequency); |
| 129 | dev->curfreq = frequency; |
| 130 | return 0; |
| 131 | } |
| 132 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 133 | static void typhoon_mute(struct typhoon *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
| 135 | if (dev->muted == 1) |
| 136 | return; |
| 137 | typhoon_setvol_generic(dev, 0); |
| 138 | typhoon_setfreq_generic(dev, dev->mutefreq); |
| 139 | dev->muted = 1; |
| 140 | } |
| 141 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 142 | static void typhoon_unmute(struct typhoon *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
| 144 | if (dev->muted == 0) |
| 145 | return; |
| 146 | typhoon_setfreq_generic(dev, dev->curfreq); |
| 147 | typhoon_setvol_generic(dev, dev->curvol); |
| 148 | dev->muted = 0; |
| 149 | } |
| 150 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 151 | static int typhoon_setvol(struct typhoon *dev, int vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
| 153 | if (dev->muted && vol != 0) { /* user is unmuting the card */ |
| 154 | dev->curvol = vol; |
| 155 | typhoon_unmute(dev); |
| 156 | return 0; |
| 157 | } |
| 158 | if (vol == dev->curvol) /* requested volume == current */ |
| 159 | return 0; |
| 160 | |
| 161 | if (vol == 0) { /* volume == 0 means mute the card */ |
| 162 | typhoon_mute(dev); |
| 163 | dev->curvol = vol; |
| 164 | return 0; |
| 165 | } |
| 166 | typhoon_setvol_generic(dev, vol); |
| 167 | dev->curvol = vol; |
| 168 | return 0; |
| 169 | } |
| 170 | |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 171 | static int vidioc_querycap(struct file *file, void *priv, |
| 172 | struct v4l2_capability *v) |
| 173 | { |
| 174 | strlcpy(v->driver, "radio-typhoon", sizeof(v->driver)); |
| 175 | strlcpy(v->card, "Typhoon Radio", sizeof(v->card)); |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 176 | strlcpy(v->bus_info, "ISA", sizeof(v->bus_info)); |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 177 | v->version = RADIO_VERSION; |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 178 | v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 179 | return 0; |
| 180 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 182 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 183 | struct v4l2_tuner *v) |
| 184 | { |
| 185 | if (v->index > 0) |
| 186 | return -EINVAL; |
| 187 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 188 | strlcpy(v->name, "FM", sizeof(v->name)); |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 189 | v->type = V4L2_TUNER_RADIO; |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 190 | v->rangelow = 87.5 * 16000; |
| 191 | v->rangehigh = 108 * 16000; |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 192 | v->rxsubchans = V4L2_TUNER_SUB_MONO; |
| 193 | v->capability = V4L2_TUNER_CAP_LOW; |
| 194 | v->audmode = V4L2_TUNER_MODE_MONO; |
| 195 | v->signal = 0xFFFF; /* We can't get the signal strength */ |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 200 | struct v4l2_tuner *v) |
| 201 | { |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 202 | return v->index ? -EINVAL : 0; |
| 203 | } |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 204 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 205 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 206 | struct v4l2_frequency *f) |
| 207 | { |
| 208 | struct typhoon *dev = video_drvdata(file); |
| 209 | |
Hans Verkuil | a3a9e28 | 2009-11-27 04:33:25 -0300 | [diff] [blame] | 210 | if (f->tuner != 0) |
| 211 | return -EINVAL; |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 212 | f->type = V4L2_TUNER_RADIO; |
| 213 | f->frequency = dev->curfreq; |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 218 | struct v4l2_frequency *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 220 | struct typhoon *dev = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Hans Verkuil | a3a9e28 | 2009-11-27 04:33:25 -0300 | [diff] [blame] | 222 | if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) |
| 223 | return -EINVAL; |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 224 | dev->curfreq = f->frequency; |
| 225 | typhoon_setfreq(dev, dev->curfreq); |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 230 | struct v4l2_queryctrl *qc) |
| 231 | { |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 232 | switch (qc->id) { |
| 233 | case V4L2_CID_AUDIO_MUTE: |
| 234 | return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1); |
| 235 | case V4L2_CID_AUDIO_VOLUME: |
| 236 | return v4l2_ctrl_query_fill(qc, 0, 65535, 16384, 65535); |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 237 | } |
| 238 | return -EINVAL; |
| 239 | } |
| 240 | |
| 241 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 242 | struct v4l2_control *ctrl) |
| 243 | { |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 244 | struct typhoon *dev = video_drvdata(file); |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 245 | |
| 246 | switch (ctrl->id) { |
| 247 | case V4L2_CID_AUDIO_MUTE: |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 248 | ctrl->value = dev->muted; |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 249 | return 0; |
| 250 | case V4L2_CID_AUDIO_VOLUME: |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 251 | ctrl->value = dev->curvol; |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 252 | return 0; |
| 253 | } |
| 254 | return -EINVAL; |
| 255 | } |
| 256 | |
| 257 | static int vidioc_s_ctrl (struct file *file, void *priv, |
| 258 | struct v4l2_control *ctrl) |
| 259 | { |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 260 | struct typhoon *dev = video_drvdata(file); |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 261 | |
| 262 | switch (ctrl->id) { |
| 263 | case V4L2_CID_AUDIO_MUTE: |
| 264 | if (ctrl->value) |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 265 | typhoon_mute(dev); |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 266 | else |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 267 | typhoon_unmute(dev); |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 268 | return 0; |
| 269 | case V4L2_CID_AUDIO_VOLUME: |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 270 | typhoon_setvol(dev, ctrl->value); |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 271 | return 0; |
| 272 | } |
| 273 | return -EINVAL; |
| 274 | } |
| 275 | |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 276 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 277 | { |
| 278 | *i = 0; |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 283 | { |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 284 | return i ? -EINVAL : 0; |
| 285 | } |
| 286 | |
| 287 | static int vidioc_g_audio(struct file *file, void *priv, |
| 288 | struct v4l2_audio *a) |
| 289 | { |
| 290 | a->index = 0; |
| 291 | strlcpy(a->name, "Radio", sizeof(a->name)); |
| 292 | a->capability = V4L2_AUDCAP_STEREO; |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | static int vidioc_s_audio(struct file *file, void *priv, |
| 297 | struct v4l2_audio *a) |
| 298 | { |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 299 | return a->index ? -EINVAL : 0; |
| 300 | } |
| 301 | |
| 302 | static int vidioc_log_status(struct file *file, void *priv) |
| 303 | { |
| 304 | struct typhoon *dev = video_drvdata(file); |
| 305 | struct v4l2_device *v4l2_dev = &dev->v4l2_dev; |
| 306 | |
| 307 | v4l2_info(v4l2_dev, BANNER); |
| 308 | #ifdef MODULE |
| 309 | v4l2_info(v4l2_dev, "Load type: Driver loaded as a module\n\n"); |
| 310 | #else |
| 311 | v4l2_info(v4l2_dev, "Load type: Driver compiled into kernel\n\n"); |
| 312 | #endif |
| 313 | v4l2_info(v4l2_dev, "frequency = %lu kHz\n", dev->curfreq >> 4); |
| 314 | v4l2_info(v4l2_dev, "volume = %d\n", dev->curvol); |
| 315 | v4l2_info(v4l2_dev, "mute = %s\n", dev->muted ? "on" : "off"); |
| 316 | v4l2_info(v4l2_dev, "io = 0x%x\n", dev->io); |
| 317 | v4l2_info(v4l2_dev, "mute frequency = %lu kHz\n", dev->mutefreq >> 4); |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 318 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 321 | static const struct v4l2_file_operations typhoon_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | .owner = THIS_MODULE, |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 323 | .ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | }; |
| 325 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 326 | static const struct v4l2_ioctl_ops typhoon_ioctl_ops = { |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 327 | .vidioc_log_status = vidioc_log_status, |
Douglas Landgraf | 3f6892a | 2007-04-24 08:40:06 -0300 | [diff] [blame] | 328 | .vidioc_querycap = vidioc_querycap, |
| 329 | .vidioc_g_tuner = vidioc_g_tuner, |
| 330 | .vidioc_s_tuner = vidioc_s_tuner, |
| 331 | .vidioc_g_audio = vidioc_g_audio, |
| 332 | .vidioc_s_audio = vidioc_s_audio, |
| 333 | .vidioc_g_input = vidioc_g_input, |
| 334 | .vidioc_s_input = vidioc_s_input, |
| 335 | .vidioc_g_frequency = vidioc_g_frequency, |
| 336 | .vidioc_s_frequency = vidioc_s_frequency, |
| 337 | .vidioc_queryctrl = vidioc_queryctrl, |
| 338 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 339 | .vidioc_s_ctrl = vidioc_s_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | }; |
| 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | static int __init typhoon_init(void) |
| 343 | { |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 344 | struct typhoon *dev = &typhoon_card; |
| 345 | struct v4l2_device *v4l2_dev = &dev->v4l2_dev; |
| 346 | int res; |
| 347 | |
| 348 | strlcpy(v4l2_dev->name, "typhoon", sizeof(v4l2_dev->name)); |
| 349 | dev->io = io; |
| 350 | dev->curfreq = dev->mutefreq = mutefreq; |
| 351 | |
| 352 | if (dev->io == -1) { |
| 353 | v4l2_err(v4l2_dev, "You must set an I/O address with io=0x316 or io=0x336\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | return -EINVAL; |
| 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 357 | if (dev->mutefreq < 87000 || dev->mutefreq > 108500) { |
| 358 | v4l2_err(v4l2_dev, "You must set a frequency (in kHz) used when muting the card,\n"); |
| 359 | v4l2_err(v4l2_dev, "e.g. with \"mutefreq=87500\" (87000 <= mutefreq <= 108500)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | return -EINVAL; |
| 361 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 363 | mutex_init(&dev->lock); |
| 364 | if (!request_region(dev->io, 8, "typhoon")) { |
| 365 | v4l2_err(v4l2_dev, "port 0x%x already in use\n", |
| 366 | dev->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | return -EBUSY; |
| 368 | } |
| 369 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 370 | res = v4l2_device_register(NULL, v4l2_dev); |
| 371 | if (res < 0) { |
| 372 | release_region(dev->io, 8); |
| 373 | v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); |
| 374 | return res; |
| 375 | } |
| 376 | v4l2_info(v4l2_dev, BANNER); |
| 377 | |
| 378 | strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name)); |
| 379 | dev->vdev.v4l2_dev = v4l2_dev; |
| 380 | dev->vdev.fops = &typhoon_fops; |
| 381 | dev->vdev.ioctl_ops = &typhoon_ioctl_ops; |
| 382 | dev->vdev.release = video_device_release_empty; |
| 383 | video_set_drvdata(&dev->vdev, dev); |
| 384 | if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { |
| 385 | v4l2_device_unregister(&dev->v4l2_dev); |
| 386 | release_region(dev->io, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | return -EINVAL; |
| 388 | } |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 389 | v4l2_info(v4l2_dev, "port 0x%x.\n", dev->io); |
| 390 | v4l2_info(v4l2_dev, "mute frequency is %lu kHz.\n", dev->mutefreq); |
| 391 | dev->mutefreq <<= 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
| 393 | /* mute card - prevents noisy bootups */ |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 394 | typhoon_mute(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
| 396 | return 0; |
| 397 | } |
| 398 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 399 | static void __exit typhoon_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 401 | struct typhoon *dev = &typhoon_card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 403 | video_unregister_device(&dev->vdev); |
| 404 | v4l2_device_unregister(&dev->v4l2_dev); |
| 405 | release_region(dev->io, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | module_init(typhoon_init); |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 409 | module_exit(typhoon_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |