| 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> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/errno.h> | 
|  | 50 |  | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 51 | #include <linux/version.h>      /* for KERNEL_VERSION MACRO     */ | 
|  | 52 | #define RADIO_VERSION KERNEL_VERSION(0,0,2) | 
|  | 53 |  | 
|  | 54 | static struct v4l2_queryctrl radio_qctrl[] = { | 
|  | 55 | { | 
|  | 56 | .id            = V4L2_CID_AUDIO_MUTE, | 
|  | 57 | .name          = "Mute", | 
|  | 58 | .minimum       = 0, | 
|  | 59 | .maximum       = 1, | 
|  | 60 | .default_value = 1, | 
|  | 61 | .type          = V4L2_CTRL_TYPE_BOOLEAN, | 
|  | 62 | },{ | 
|  | 63 | .id            = V4L2_CID_AUDIO_VOLUME, | 
|  | 64 | .name          = "Volume", | 
|  | 65 | .minimum       = 0, | 
|  | 66 | .maximum       = 65535, | 
|  | 67 | .step          = 65535, | 
|  | 68 | .default_value = 0xff, | 
|  | 69 | .type          = V4L2_CTRL_TYPE_INTEGER, | 
|  | 70 | } | 
|  | 71 | }; | 
|  | 72 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #include <asm/io.h> | 
|  | 74 | #include <asm/uaccess.h> | 
|  | 75 |  | 
|  | 76 | #ifndef PCI_VENDOR_ID_GEMTEK | 
|  | 77 | #define PCI_VENDOR_ID_GEMTEK 0x5046 | 
|  | 78 | #endif | 
|  | 79 |  | 
|  | 80 | #ifndef PCI_DEVICE_ID_GEMTEK_PR103 | 
|  | 81 | #define PCI_DEVICE_ID_GEMTEK_PR103 0x1001 | 
|  | 82 | #endif | 
|  | 83 |  | 
|  | 84 | #ifndef GEMTEK_PCI_RANGE_LOW | 
|  | 85 | #define GEMTEK_PCI_RANGE_LOW (87*16000) | 
|  | 86 | #endif | 
|  | 87 |  | 
|  | 88 | #ifndef GEMTEK_PCI_RANGE_HIGH | 
|  | 89 | #define GEMTEK_PCI_RANGE_HIGH (108*16000) | 
|  | 90 | #endif | 
|  | 91 |  | 
|  | 92 | #ifndef TRUE | 
|  | 93 | #define TRUE (1) | 
|  | 94 | #endif | 
|  | 95 |  | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 96 | #ifndef FALSE | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | #define FALSE (0) | 
|  | 98 | #endif | 
|  | 99 |  | 
|  | 100 | struct gemtek_pci_card { | 
|  | 101 | struct video_device *videodev; | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 102 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | u32 iobase; | 
|  | 104 | u32 length; | 
|  | 105 | u8  chiprev; | 
|  | 106 | u16 model; | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 107 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | u32 current_frequency; | 
|  | 109 | u8  mute; | 
|  | 110 | }; | 
|  | 111 |  | 
|  | 112 | static const char rcsid[] = "$Id: radio-gemtek-pci.c,v 1.1 2001/07/23 08:08:16 ted Exp ted $"; | 
|  | 113 |  | 
|  | 114 | static int nr_radio = -1; | 
|  | 115 |  | 
|  | 116 | static inline u8 gemtek_pci_out( u16 value, u32 port ) | 
|  | 117 | { | 
|  | 118 | outw( value, port ); | 
|  | 119 |  | 
|  | 120 | return (u8)value; | 
|  | 121 | } | 
|  | 122 |  | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 123 | #define _b0( v ) *((u8 *)&v) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | static void __gemtek_pci_cmd( u16 value, u32 port, u8 *last_byte, int keep ) | 
|  | 125 | { | 
|  | 126 | register u8 byte = *last_byte; | 
|  | 127 |  | 
|  | 128 | if ( !value ) { | 
|  | 129 | if ( !keep ) | 
|  | 130 | value = (u16)port; | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 131 | byte &= 0xfd; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } else | 
|  | 133 | byte |= 2; | 
|  | 134 |  | 
|  | 135 | _b0( value ) = byte; | 
|  | 136 | outw( value, port ); | 
|  | 137 | byte |= 1; | 
|  | 138 | _b0( value ) = byte; | 
|  | 139 | outw( value, port ); | 
|  | 140 | byte &= 0xfe; | 
|  | 141 | _b0( value ) = byte; | 
|  | 142 | outw( value, port ); | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 143 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | *last_byte = byte; | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | static inline void gemtek_pci_nil( u32 port, u8 *last_byte ) | 
|  | 148 | { | 
|  | 149 | __gemtek_pci_cmd( 0x00, port, last_byte, FALSE ); | 
|  | 150 | } | 
|  | 151 |  | 
|  | 152 | static inline void gemtek_pci_cmd( u16 cmd, u32 port, u8 *last_byte ) | 
|  | 153 | { | 
|  | 154 | __gemtek_pci_cmd( cmd, port, last_byte, TRUE ); | 
|  | 155 | } | 
|  | 156 |  | 
|  | 157 | static void gemtek_pci_setfrequency( struct gemtek_pci_card *card, unsigned long frequency ) | 
|  | 158 | { | 
|  | 159 | register int i; | 
|  | 160 | register u32 value = frequency / 200 + 856; | 
|  | 161 | register u16 mask = 0x8000; | 
|  | 162 | u8 last_byte; | 
|  | 163 | u32 port = card->iobase; | 
|  | 164 |  | 
|  | 165 | last_byte = gemtek_pci_out( 0x06, port ); | 
|  | 166 |  | 
|  | 167 | i = 0; | 
|  | 168 | do { | 
|  | 169 | gemtek_pci_nil( port, &last_byte ); | 
|  | 170 | i++; | 
|  | 171 | } while ( i < 9 ); | 
|  | 172 |  | 
|  | 173 | i = 0; | 
|  | 174 | do { | 
|  | 175 | gemtek_pci_cmd( value & mask, port, &last_byte ); | 
|  | 176 | mask >>= 1; | 
|  | 177 | i++; | 
|  | 178 | } while ( i < 16 ); | 
|  | 179 |  | 
|  | 180 | outw( 0x10, port ); | 
|  | 181 | } | 
|  | 182 |  | 
|  | 183 |  | 
|  | 184 | static inline void gemtek_pci_mute( struct gemtek_pci_card *card ) | 
|  | 185 | { | 
|  | 186 | outb( 0x1f, card->iobase ); | 
|  | 187 | card->mute = TRUE; | 
|  | 188 | } | 
|  | 189 |  | 
|  | 190 | static inline void gemtek_pci_unmute( struct gemtek_pci_card *card ) | 
|  | 191 | { | 
|  | 192 | if ( card->mute ) { | 
|  | 193 | gemtek_pci_setfrequency( card, card->current_frequency ); | 
|  | 194 | card->mute = FALSE; | 
|  | 195 | } | 
|  | 196 | } | 
|  | 197 |  | 
|  | 198 | static inline unsigned int gemtek_pci_getsignal( struct gemtek_pci_card *card ) | 
|  | 199 | { | 
|  | 200 | return ( inb( card->iobase ) & 0x08 ) ? 0 : 1; | 
|  | 201 | } | 
|  | 202 |  | 
|  | 203 | static int gemtek_pci_do_ioctl(struct inode *inode, struct file *file, | 
|  | 204 | unsigned int cmd, void *arg) | 
|  | 205 | { | 
|  | 206 | struct video_device *dev = video_devdata(file); | 
|  | 207 | struct gemtek_pci_card *card = dev->priv; | 
|  | 208 |  | 
|  | 209 | switch ( cmd ) { | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 210 | case VIDIOC_QUERYCAP: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 212 | struct v4l2_capability *v = arg; | 
|  | 213 | memset(v,0,sizeof(*v)); | 
|  | 214 | strlcpy(v->driver, "radio-gemtek-pci", sizeof (v->driver)); | 
|  | 215 | strlcpy(v->card, "GemTek PCI Radio", sizeof (v->card)); | 
|  | 216 | sprintf(v->bus_info,"ISA"); | 
|  | 217 | v->version = RADIO_VERSION; | 
|  | 218 | v->capabilities = V4L2_CAP_TUNER; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | return 0; | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 221 | } | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 222 | case VIDIOC_G_TUNER: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | { | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 224 | struct v4l2_tuner *v = arg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 |  | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 226 | if (v->index > 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | return -EINVAL; | 
|  | 228 |  | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 229 | memset(v,0,sizeof(*v)); | 
|  | 230 | strcpy(v->name, "FM"); | 
|  | 231 | v->type = V4L2_TUNER_RADIO; | 
|  | 232 |  | 
|  | 233 | v->rangelow = GEMTEK_PCI_RANGE_LOW; | 
|  | 234 | v->rangehigh = GEMTEK_PCI_RANGE_HIGH; | 
|  | 235 | v->rxsubchans =V4L2_TUNER_SUB_MONO; | 
|  | 236 | v->capability=V4L2_TUNER_CAP_LOW; | 
|  | 237 | v->audmode = V4L2_TUNER_MODE_MONO; | 
|  | 238 | v->signal=0xFFFF*gemtek_pci_getsignal( card ); | 
|  | 239 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | return 0; | 
|  | 241 | } | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 242 | case VIDIOC_S_TUNER: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 244 | struct v4l2_tuner *v = arg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 |  | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 246 | if (v->index > 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return -EINVAL; | 
|  | 248 |  | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 249 | return 0; | 
|  | 250 | } | 
|  | 251 | case VIDIOC_S_FREQUENCY: | 
|  | 252 | { | 
|  | 253 | struct v4l2_frequency *f = arg; | 
|  | 254 |  | 
|  | 255 | if ( (f->frequency < GEMTEK_PCI_RANGE_LOW) || | 
|  | 256 | (f->frequency > GEMTEK_PCI_RANGE_HIGH) ) | 
|  | 257 | return -EINVAL; | 
|  | 258 |  | 
|  | 259 |  | 
|  | 260 | gemtek_pci_setfrequency( card, f->frequency ); | 
|  | 261 | card->current_frequency = f->frequency; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | card->mute = FALSE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | return 0; | 
|  | 264 | } | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 265 | case VIDIOC_QUERYCTRL: | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 266 | { | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 267 | struct v4l2_queryctrl *qc = arg; | 
|  | 268 | int i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 |  | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 270 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { | 
|  | 271 | if (qc->id && qc->id == radio_qctrl[i].id) { | 
|  | 272 | memcpy(qc, &(radio_qctrl[i]), | 
|  | 273 | sizeof(*qc)); | 
|  | 274 | return (0); | 
|  | 275 | } | 
|  | 276 | } | 
|  | 277 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 279 | case VIDIOC_G_CTRL: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | { | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 281 | struct v4l2_control *ctrl= arg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 |  | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 283 | switch (ctrl->id) { | 
|  | 284 | case V4L2_CID_AUDIO_MUTE: | 
|  | 285 | ctrl->value=card->mute; | 
|  | 286 | return (0); | 
|  | 287 | case V4L2_CID_AUDIO_VOLUME: | 
|  | 288 | if (card->mute) | 
|  | 289 | ctrl->value=0; | 
|  | 290 | else | 
|  | 291 | ctrl->value=65535; | 
|  | 292 | return (0); | 
|  | 293 | } | 
|  | 294 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 296 | case VIDIOC_S_CTRL: | 
|  | 297 | { | 
|  | 298 | struct v4l2_control *ctrl= arg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 |  | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 300 | switch (ctrl->id) { | 
|  | 301 | case V4L2_CID_AUDIO_MUTE: | 
|  | 302 | if (ctrl->value) { | 
|  | 303 | gemtek_pci_mute(card); | 
|  | 304 | } else { | 
|  | 305 | gemtek_pci_unmute(card); | 
|  | 306 | } | 
|  | 307 | return (0); | 
|  | 308 | case V4L2_CID_AUDIO_VOLUME: | 
|  | 309 | if (ctrl->value) { | 
|  | 310 | gemtek_pci_unmute(card); | 
|  | 311 | } else { | 
|  | 312 | gemtek_pci_mute(card); | 
|  | 313 | } | 
|  | 314 | return (0); | 
|  | 315 | } | 
|  | 316 | return -EINVAL; | 
|  | 317 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | default: | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 319 | return v4l_compat_translate_ioctl(inode,file,cmd,arg, | 
| Mauro Carvalho Chehab | 3ca5716 | 2006-08-08 09:10:06 -0300 | [diff] [blame] | 320 | gemtek_pci_do_ioctl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } | 
|  | 322 | } | 
|  | 323 |  | 
|  | 324 | static int gemtek_pci_ioctl(struct inode *inode, struct file *file, | 
|  | 325 | unsigned int cmd, unsigned long arg) | 
|  | 326 | { | 
|  | 327 | return video_usercopy(inode, file, cmd, arg, gemtek_pci_do_ioctl); | 
|  | 328 | } | 
|  | 329 |  | 
|  | 330 | enum { | 
|  | 331 | GEMTEK_PR103 | 
|  | 332 | }; | 
|  | 333 |  | 
|  | 334 | static char *card_names[] __devinitdata = { | 
|  | 335 | "GEMTEK_PR103" | 
|  | 336 | }; | 
|  | 337 |  | 
|  | 338 | static struct pci_device_id gemtek_pci_id[] = | 
|  | 339 | { | 
|  | 340 | { PCI_VENDOR_ID_GEMTEK, PCI_DEVICE_ID_GEMTEK_PR103, | 
|  | 341 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, GEMTEK_PR103 }, | 
|  | 342 | { 0 } | 
|  | 343 | }; | 
|  | 344 |  | 
|  | 345 | MODULE_DEVICE_TABLE( pci, gemtek_pci_id ); | 
|  | 346 |  | 
|  | 347 | static int mx = 1; | 
|  | 348 |  | 
|  | 349 | static struct file_operations gemtek_pci_fops = { | 
|  | 350 | .owner		= THIS_MODULE, | 
|  | 351 | .open           = video_exclusive_open, | 
|  | 352 | .release        = video_exclusive_release, | 
|  | 353 | .ioctl		= gemtek_pci_ioctl, | 
| Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 354 | .compat_ioctl	= v4l_compat_ioctl32, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | .llseek         = no_llseek, | 
|  | 356 | }; | 
|  | 357 |  | 
|  | 358 | static struct video_device vdev_template = { | 
|  | 359 | .owner         = THIS_MODULE, | 
|  | 360 | .name          = "Gemtek PCI Radio", | 
|  | 361 | .type          = VID_TYPE_TUNER, | 
| Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 362 | .hardware      = 0, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | .fops          = &gemtek_pci_fops, | 
|  | 364 | }; | 
|  | 365 |  | 
|  | 366 | static int __devinit gemtek_pci_probe( struct pci_dev *pci_dev, const struct pci_device_id *pci_id ) | 
|  | 367 | { | 
|  | 368 | struct gemtek_pci_card *card; | 
|  | 369 | struct video_device *devradio; | 
|  | 370 |  | 
| Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 371 | if ( (card = kzalloc( sizeof( struct gemtek_pci_card ), GFP_KERNEL )) == NULL ) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | printk( KERN_ERR "gemtek_pci: out of memory\n" ); | 
|  | 373 | return -ENOMEM; | 
|  | 374 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 |  | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 376 | if ( pci_enable_device( pci_dev ) ) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | goto err_pci; | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 378 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | card->iobase = pci_resource_start( pci_dev, 0 ); | 
|  | 380 | card->length = pci_resource_len( pci_dev, 0 ); | 
|  | 381 |  | 
|  | 382 | if ( request_region( card->iobase, card->length, card_names[pci_id->driver_data] ) == NULL ) { | 
|  | 383 | printk( KERN_ERR "gemtek_pci: i/o port already in use\n" ); | 
|  | 384 | goto err_pci; | 
|  | 385 | } | 
|  | 386 |  | 
|  | 387 | pci_read_config_byte( pci_dev, PCI_REVISION_ID, &card->chiprev ); | 
|  | 388 | pci_read_config_word( pci_dev, PCI_SUBSYSTEM_ID, &card->model ); | 
|  | 389 |  | 
|  | 390 | pci_set_drvdata( pci_dev, card ); | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 391 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | if ( (devradio = kmalloc( sizeof( struct video_device ), GFP_KERNEL )) == NULL ) { | 
|  | 393 | printk( KERN_ERR "gemtek_pci: out of memory\n" ); | 
|  | 394 | goto err_video; | 
|  | 395 | } | 
|  | 396 | *devradio = vdev_template; | 
|  | 397 |  | 
|  | 398 | if ( video_register_device( devradio, VFL_TYPE_RADIO , nr_radio) == -1 ) { | 
|  | 399 | kfree( devradio ); | 
|  | 400 | goto err_video; | 
|  | 401 | } | 
|  | 402 |  | 
|  | 403 | card->videodev = devradio; | 
|  | 404 | devradio->priv = card; | 
|  | 405 | gemtek_pci_mute( card ); | 
|  | 406 |  | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 407 | printk( KERN_INFO "Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | card->chiprev, card->iobase, card->iobase + card->length - 1 ); | 
|  | 409 |  | 
|  | 410 | return 0; | 
|  | 411 |  | 
|  | 412 | err_video: | 
|  | 413 | release_region( card->iobase, card->length ); | 
|  | 414 |  | 
|  | 415 | err_pci: | 
|  | 416 | kfree( card ); | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 417 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } | 
|  | 419 |  | 
|  | 420 | static void __devexit gemtek_pci_remove( struct pci_dev *pci_dev ) | 
|  | 421 | { | 
|  | 422 | struct gemtek_pci_card *card = pci_get_drvdata( pci_dev ); | 
|  | 423 |  | 
|  | 424 | video_unregister_device( card->videodev ); | 
|  | 425 | kfree( card->videodev ); | 
|  | 426 |  | 
|  | 427 | release_region( card->iobase, card->length ); | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 428 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | if ( mx ) | 
|  | 430 | gemtek_pci_mute( card ); | 
|  | 431 |  | 
|  | 432 | kfree( card ); | 
| Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 433 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | pci_set_drvdata( pci_dev, NULL ); | 
|  | 435 | } | 
|  | 436 |  | 
|  | 437 | static struct pci_driver gemtek_pci_driver = | 
|  | 438 | { | 
|  | 439 | .name		= "gemtek_pci", | 
|  | 440 | .id_table	= gemtek_pci_id, | 
|  | 441 | .probe		= gemtek_pci_probe, | 
|  | 442 | .remove		= __devexit_p(gemtek_pci_remove), | 
|  | 443 | }; | 
|  | 444 |  | 
|  | 445 | static int __init gemtek_pci_init_module( void ) | 
|  | 446 | { | 
| Richard Knutsson | 9bfab8c | 2005-11-30 00:59:34 +0100 | [diff] [blame] | 447 | return pci_register_driver( &gemtek_pci_driver ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } | 
|  | 449 |  | 
|  | 450 | static void __exit gemtek_pci_cleanup_module( void ) | 
|  | 451 | { | 
| Tobias Klauser | 1396275 | 2006-10-04 08:09:10 -0300 | [diff] [blame] | 452 | pci_unregister_driver(&gemtek_pci_driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } | 
|  | 454 |  | 
|  | 455 | MODULE_AUTHOR( "Vladimir Shebordaev <vshebordaev@mail.ru>" ); | 
|  | 456 | MODULE_DESCRIPTION( "The video4linux driver for the Gemtek PCI Radio Card" ); | 
|  | 457 | MODULE_LICENSE("GPL"); | 
|  | 458 |  | 
|  | 459 | module_param(mx, bool, 0); | 
|  | 460 | MODULE_PARM_DESC( mx, "single digit: 1 - turn off the turner upon module exit (default), 0 - do not" ); | 
|  | 461 | module_param(nr_radio, int, 0); | 
|  | 462 | MODULE_PARM_DESC( nr_radio, "video4linux device number to use"); | 
|  | 463 |  | 
|  | 464 | module_init( gemtek_pci_init_module ); | 
|  | 465 | module_exit( gemtek_pci_cleanup_module ); | 
|  | 466 |  |