Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | *************************************************************************** |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * radio-gemtek-pci.c - Gemtek PCI Radio driver |
| 5 | * (C) 2001 Vladimir Shebordaev <vshebordaev@mail.ru> |
| 6 | * |
| 7 | *************************************************************************** |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public |
| 20 | * License along with this program; if not, write to the Free |
| 21 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, |
| 22 | * USA. |
| 23 | * |
| 24 | *************************************************************************** |
| 25 | * |
| 26 | * Gemtek Corp still silently refuses to release any specifications |
| 27 | * of their multimedia devices, so the protocol still has to be |
| 28 | * reverse engineered. |
| 29 | * |
| 30 | * The v4l code was inspired by Jonas Munsin's Gemtek serial line |
| 31 | * radio device driver. |
| 32 | * |
| 33 | * Please, let me know if this piece of code was useful :) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 34 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | * TODO: multiple device support and portability were not tested |
| 36 | * |
Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 37 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
| 38 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | *************************************************************************** |
| 40 | */ |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/types.h> |
| 43 | #include <linux/list.h> |
| 44 | #include <linux/module.h> |
| 45 | #include <linux/init.h> |
| 46 | #include <linux/pci.h> |
Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 47 | #include <linux/videodev2.h> |
Mauro Carvalho Chehab | 5e87efa | 2006-06-05 10:26:32 -0300 | [diff] [blame] | 48 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 49 | #include <media/v4l2-ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <linux/errno.h> |
| 51 | |
Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 52 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ |
| 53 | #define RADIO_VERSION KERNEL_VERSION(0,0,2) |
| 54 | |
| 55 | static struct v4l2_queryctrl radio_qctrl[] = { |
| 56 | { |
| 57 | .id = V4L2_CID_AUDIO_MUTE, |
| 58 | .name = "Mute", |
| 59 | .minimum = 0, |
| 60 | .maximum = 1, |
| 61 | .default_value = 1, |
| 62 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 63 | },{ |
| 64 | .id = V4L2_CID_AUDIO_VOLUME, |
| 65 | .name = "Volume", |
| 66 | .minimum = 0, |
| 67 | .maximum = 65535, |
| 68 | .step = 65535, |
| 69 | .default_value = 0xff, |
| 70 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 71 | } |
| 72 | }; |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #include <asm/io.h> |
| 75 | #include <asm/uaccess.h> |
| 76 | |
| 77 | #ifndef PCI_VENDOR_ID_GEMTEK |
| 78 | #define PCI_VENDOR_ID_GEMTEK 0x5046 |
| 79 | #endif |
| 80 | |
| 81 | #ifndef PCI_DEVICE_ID_GEMTEK_PR103 |
| 82 | #define PCI_DEVICE_ID_GEMTEK_PR103 0x1001 |
| 83 | #endif |
| 84 | |
| 85 | #ifndef GEMTEK_PCI_RANGE_LOW |
| 86 | #define GEMTEK_PCI_RANGE_LOW (87*16000) |
| 87 | #endif |
| 88 | |
| 89 | #ifndef GEMTEK_PCI_RANGE_HIGH |
| 90 | #define GEMTEK_PCI_RANGE_HIGH (108*16000) |
| 91 | #endif |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | struct gemtek_pci_card { |
| 94 | struct video_device *videodev; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | u32 iobase; |
| 97 | u32 length; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | u32 current_frequency; |
| 100 | u8 mute; |
| 101 | }; |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | static int nr_radio = -1; |
Hans Verkuil | 3ca685a | 2008-08-23 04:49:13 -0300 | [diff] [blame] | 104 | static unsigned long in_use; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | static inline u8 gemtek_pci_out( u16 value, u32 port ) |
| 107 | { |
| 108 | outw( value, port ); |
| 109 | |
| 110 | return (u8)value; |
| 111 | } |
| 112 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 113 | #define _b0( v ) *((u8 *)&v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | static void __gemtek_pci_cmd( u16 value, u32 port, u8 *last_byte, int keep ) |
| 115 | { |
| 116 | register u8 byte = *last_byte; |
| 117 | |
| 118 | if ( !value ) { |
| 119 | if ( !keep ) |
| 120 | value = (u16)port; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 121 | byte &= 0xfd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } else |
| 123 | byte |= 2; |
| 124 | |
| 125 | _b0( value ) = byte; |
| 126 | outw( value, port ); |
| 127 | byte |= 1; |
| 128 | _b0( value ) = byte; |
| 129 | outw( value, port ); |
| 130 | byte &= 0xfe; |
| 131 | _b0( value ) = byte; |
| 132 | outw( value, port ); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | *last_byte = byte; |
| 135 | } |
| 136 | |
| 137 | static inline void gemtek_pci_nil( u32 port, u8 *last_byte ) |
| 138 | { |
Richard Knutsson | fd4bc44 | 2007-02-06 21:55:07 -0300 | [diff] [blame] | 139 | __gemtek_pci_cmd( 0x00, port, last_byte, false ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static inline void gemtek_pci_cmd( u16 cmd, u32 port, u8 *last_byte ) |
| 143 | { |
Richard Knutsson | fd4bc44 | 2007-02-06 21:55:07 -0300 | [diff] [blame] | 144 | __gemtek_pci_cmd( cmd, port, last_byte, true ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static void gemtek_pci_setfrequency( struct gemtek_pci_card *card, unsigned long frequency ) |
| 148 | { |
| 149 | register int i; |
| 150 | register u32 value = frequency / 200 + 856; |
| 151 | register u16 mask = 0x8000; |
| 152 | u8 last_byte; |
| 153 | u32 port = card->iobase; |
| 154 | |
| 155 | last_byte = gemtek_pci_out( 0x06, port ); |
| 156 | |
| 157 | i = 0; |
| 158 | do { |
| 159 | gemtek_pci_nil( port, &last_byte ); |
| 160 | i++; |
| 161 | } while ( i < 9 ); |
| 162 | |
| 163 | i = 0; |
| 164 | do { |
| 165 | gemtek_pci_cmd( value & mask, port, &last_byte ); |
| 166 | mask >>= 1; |
| 167 | i++; |
| 168 | } while ( i < 16 ); |
| 169 | |
| 170 | outw( 0x10, port ); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | static inline void gemtek_pci_mute( struct gemtek_pci_card *card ) |
| 175 | { |
| 176 | outb( 0x1f, card->iobase ); |
Richard Knutsson | fd4bc44 | 2007-02-06 21:55:07 -0300 | [diff] [blame] | 177 | card->mute = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static inline void gemtek_pci_unmute( struct gemtek_pci_card *card ) |
| 181 | { |
| 182 | if ( card->mute ) { |
| 183 | gemtek_pci_setfrequency( card, card->current_frequency ); |
Richard Knutsson | fd4bc44 | 2007-02-06 21:55:07 -0300 | [diff] [blame] | 184 | card->mute = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
| 188 | static inline unsigned int gemtek_pci_getsignal( struct gemtek_pci_card *card ) |
| 189 | { |
| 190 | return ( inb( card->iobase ) & 0x08 ) ? 0 : 1; |
| 191 | } |
| 192 | |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 193 | static int vidioc_querycap(struct file *file, void *priv, |
| 194 | struct v4l2_capability *v) |
| 195 | { |
| 196 | strlcpy(v->driver, "radio-gemtek-pci", sizeof(v->driver)); |
| 197 | strlcpy(v->card, "GemTek PCI Radio", sizeof(v->card)); |
| 198 | sprintf(v->bus_info, "ISA"); |
| 199 | v->version = RADIO_VERSION; |
| 200 | v->capabilities = V4L2_CAP_TUNER; |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 205 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 207 | struct gemtek_pci_card *card = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 209 | if (v->index > 0) |
| 210 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 212 | strcpy(v->name, "FM"); |
| 213 | v->type = V4L2_TUNER_RADIO; |
| 214 | v->rangelow = GEMTEK_PCI_RANGE_LOW; |
| 215 | v->rangehigh = GEMTEK_PCI_RANGE_HIGH; |
| 216 | v->rxsubchans = V4L2_TUNER_SUB_MONO; |
| 217 | v->capability = V4L2_TUNER_CAP_LOW; |
| 218 | v->audmode = V4L2_TUNER_MODE_MONO; |
| 219 | v->signal = 0xffff * gemtek_pci_getsignal(card); |
| 220 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 223 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 224 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 226 | if (v->index > 0) |
| 227 | return -EINVAL; |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 232 | struct v4l2_frequency *f) |
| 233 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 234 | struct gemtek_pci_card *card = video_drvdata(file); |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 235 | |
| 236 | if ( (f->frequency < GEMTEK_PCI_RANGE_LOW) || |
| 237 | (f->frequency > GEMTEK_PCI_RANGE_HIGH) ) |
| 238 | return -EINVAL; |
| 239 | gemtek_pci_setfrequency(card, f->frequency); |
| 240 | card->current_frequency = f->frequency; |
| 241 | card->mute = false; |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 246 | struct v4l2_frequency *f) |
| 247 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 248 | struct gemtek_pci_card *card = video_drvdata(file); |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 249 | |
| 250 | f->type = V4L2_TUNER_RADIO; |
| 251 | f->frequency = card->current_frequency; |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 256 | struct v4l2_queryctrl *qc) |
| 257 | { |
| 258 | int i; |
| 259 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { |
| 260 | if (qc->id && qc->id == radio_qctrl[i].id) { |
| 261 | memcpy(qc, &(radio_qctrl[i]), |
| 262 | sizeof(*qc)); |
| 263 | return 0; |
| 264 | } |
| 265 | } |
| 266 | return -EINVAL; |
| 267 | } |
| 268 | |
| 269 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 270 | struct v4l2_control *ctrl) |
| 271 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 272 | struct gemtek_pci_card *card = video_drvdata(file); |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 273 | |
| 274 | switch (ctrl->id) { |
| 275 | case V4L2_CID_AUDIO_MUTE: |
| 276 | ctrl->value = card->mute; |
| 277 | return 0; |
| 278 | case V4L2_CID_AUDIO_VOLUME: |
| 279 | if (card->mute) |
| 280 | ctrl->value = 0; |
| 281 | else |
| 282 | ctrl->value = 65535; |
| 283 | return 0; |
| 284 | } |
| 285 | return -EINVAL; |
| 286 | } |
| 287 | |
| 288 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 289 | struct v4l2_control *ctrl) |
| 290 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 291 | struct gemtek_pci_card *card = video_drvdata(file); |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 292 | |
| 293 | switch (ctrl->id) { |
| 294 | case V4L2_CID_AUDIO_MUTE: |
| 295 | if (ctrl->value) |
| 296 | gemtek_pci_mute(card); |
| 297 | else |
| 298 | gemtek_pci_unmute(card); |
| 299 | return 0; |
| 300 | case V4L2_CID_AUDIO_VOLUME: |
| 301 | if (ctrl->value) |
| 302 | gemtek_pci_unmute(card); |
| 303 | else |
| 304 | gemtek_pci_mute(card); |
| 305 | return 0; |
| 306 | } |
| 307 | return -EINVAL; |
| 308 | } |
| 309 | |
| 310 | static int vidioc_g_audio(struct file *file, void *priv, |
| 311 | struct v4l2_audio *a) |
| 312 | { |
| 313 | if (a->index > 1) |
| 314 | return -EINVAL; |
| 315 | |
| 316 | strcpy(a->name, "Radio"); |
| 317 | a->capability = V4L2_AUDCAP_STEREO; |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 322 | { |
| 323 | *i = 0; |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 328 | { |
| 329 | if (i != 0) |
| 330 | return -EINVAL; |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | static int vidioc_s_audio(struct file *file, void *priv, |
| 335 | struct v4l2_audio *a) |
| 336 | { |
| 337 | if (a->index != 0) |
| 338 | return -EINVAL; |
| 339 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | enum { |
| 343 | GEMTEK_PR103 |
| 344 | }; |
| 345 | |
| 346 | static char *card_names[] __devinitdata = { |
| 347 | "GEMTEK_PR103" |
| 348 | }; |
| 349 | |
| 350 | static struct pci_device_id gemtek_pci_id[] = |
| 351 | { |
| 352 | { PCI_VENDOR_ID_GEMTEK, PCI_DEVICE_ID_GEMTEK_PR103, |
| 353 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, GEMTEK_PR103 }, |
| 354 | { 0 } |
| 355 | }; |
| 356 | |
| 357 | MODULE_DEVICE_TABLE( pci, gemtek_pci_id ); |
| 358 | |
| 359 | static int mx = 1; |
| 360 | |
Hans Verkuil | 3ca685a | 2008-08-23 04:49:13 -0300 | [diff] [blame] | 361 | static int gemtek_pci_exclusive_open(struct inode *inode, struct file *file) |
| 362 | { |
| 363 | return test_and_set_bit(0, &in_use) ? -EBUSY : 0; |
| 364 | } |
| 365 | |
| 366 | static int gemtek_pci_exclusive_release(struct inode *inode, struct file *file) |
| 367 | { |
| 368 | clear_bit(0, &in_use); |
| 369 | return 0; |
| 370 | } |
| 371 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 372 | static const struct file_operations gemtek_pci_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | .owner = THIS_MODULE, |
Hans Verkuil | 3ca685a | 2008-08-23 04:49:13 -0300 | [diff] [blame] | 374 | .open = gemtek_pci_exclusive_open, |
| 375 | .release = gemtek_pci_exclusive_release, |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 376 | .ioctl = video_ioctl2, |
Douglas Schilling Landgraf | 078ff79 | 2008-04-22 14:46:11 -0300 | [diff] [blame] | 377 | #ifdef CONFIG_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 378 | .compat_ioctl = v4l_compat_ioctl32, |
Douglas Schilling Landgraf | 078ff79 | 2008-04-22 14:46:11 -0300 | [diff] [blame] | 379 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | .llseek = no_llseek, |
| 381 | }; |
| 382 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 383 | static const struct v4l2_ioctl_ops gemtek_pci_ioctl_ops = { |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 384 | .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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | }; |
| 397 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 398 | static struct video_device vdev_template = { |
Hans Verkuil | aa5e90a | 2008-08-23 06:23:55 -0300 | [diff] [blame] | 399 | .name = "Gemtek PCI Radio", |
| 400 | .fops = &gemtek_pci_fops, |
| 401 | .ioctl_ops = &gemtek_pci_ioctl_ops, |
| 402 | .release = video_device_release_empty, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 403 | }; |
| 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | static int __devinit gemtek_pci_probe( struct pci_dev *pci_dev, const struct pci_device_id *pci_id ) |
| 406 | { |
| 407 | struct gemtek_pci_card *card; |
| 408 | struct video_device *devradio; |
| 409 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 410 | if ( (card = kzalloc( sizeof( struct gemtek_pci_card ), GFP_KERNEL )) == NULL ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | printk( KERN_ERR "gemtek_pci: out of memory\n" ); |
| 412 | return -ENOMEM; |
| 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 415 | if ( pci_enable_device( pci_dev ) ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | goto err_pci; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | card->iobase = pci_resource_start( pci_dev, 0 ); |
| 419 | card->length = pci_resource_len( pci_dev, 0 ); |
| 420 | |
| 421 | if ( request_region( card->iobase, card->length, card_names[pci_id->driver_data] ) == NULL ) { |
| 422 | printk( KERN_ERR "gemtek_pci: i/o port already in use\n" ); |
| 423 | goto err_pci; |
| 424 | } |
| 425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | pci_set_drvdata( pci_dev, card ); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | if ( (devradio = kmalloc( sizeof( struct video_device ), GFP_KERNEL )) == NULL ) { |
| 429 | printk( KERN_ERR "gemtek_pci: out of memory\n" ); |
| 430 | goto err_video; |
| 431 | } |
| 432 | *devradio = vdev_template; |
| 433 | |
Hans Verkuil | cba99ae | 2008-09-03 17:11:58 -0300 | [diff] [blame] | 434 | if (video_register_device(devradio, VFL_TYPE_RADIO, nr_radio) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | kfree( devradio ); |
| 436 | goto err_video; |
| 437 | } |
| 438 | |
| 439 | card->videodev = devradio; |
Hans Verkuil | 601e944 | 2008-08-23 07:24:07 -0300 | [diff] [blame] | 440 | video_set_drvdata(devradio, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | gemtek_pci_mute( card ); |
| 442 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 443 | printk( KERN_INFO "Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n", |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 444 | pci_dev->revision, card->iobase, card->iobase + card->length - 1 ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
| 446 | return 0; |
| 447 | |
| 448 | err_video: |
| 449 | release_region( card->iobase, card->length ); |
| 450 | |
| 451 | err_pci: |
| 452 | kfree( card ); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 453 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | static void __devexit gemtek_pci_remove( struct pci_dev *pci_dev ) |
| 457 | { |
| 458 | struct gemtek_pci_card *card = pci_get_drvdata( pci_dev ); |
| 459 | |
| 460 | video_unregister_device( card->videodev ); |
| 461 | kfree( card->videodev ); |
| 462 | |
| 463 | release_region( card->iobase, card->length ); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | if ( mx ) |
| 466 | gemtek_pci_mute( card ); |
| 467 | |
| 468 | kfree( card ); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | pci_set_drvdata( pci_dev, NULL ); |
| 471 | } |
| 472 | |
| 473 | static struct pci_driver gemtek_pci_driver = |
| 474 | { |
| 475 | .name = "gemtek_pci", |
| 476 | .id_table = gemtek_pci_id, |
| 477 | .probe = gemtek_pci_probe, |
| 478 | .remove = __devexit_p(gemtek_pci_remove), |
| 479 | }; |
| 480 | |
| 481 | static int __init gemtek_pci_init_module( void ) |
| 482 | { |
Richard Knutsson | 9bfab8c | 2005-11-30 00:59:34 +0100 | [diff] [blame] | 483 | return pci_register_driver( &gemtek_pci_driver ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static void __exit gemtek_pci_cleanup_module( void ) |
| 487 | { |
Tobias Klauser | 1396275 | 2006-10-04 08:09:10 -0300 | [diff] [blame] | 488 | pci_unregister_driver(&gemtek_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | MODULE_AUTHOR( "Vladimir Shebordaev <vshebordaev@mail.ru>" ); |
| 492 | MODULE_DESCRIPTION( "The video4linux driver for the Gemtek PCI Radio Card" ); |
| 493 | MODULE_LICENSE("GPL"); |
| 494 | |
| 495 | module_param(mx, bool, 0); |
| 496 | MODULE_PARM_DESC( mx, "single digit: 1 - turn off the turner upon module exit (default), 0 - do not" ); |
| 497 | module_param(nr_radio, int, 0); |
| 498 | MODULE_PARM_DESC( nr_radio, "video4linux device number to use"); |
| 499 | |
| 500 | module_init( gemtek_pci_init_module ); |
| 501 | module_exit( gemtek_pci_cleanup_module ); |
| 502 | |