2 ***************************************************************************
4 * radio-gemtek-pci.c - Gemtek PCI Radio driver
5 * (C) 2001 Vladimir Shebordaev <vshebordaev@mail.ru>
7 ***************************************************************************
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.
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.
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,
24 ***************************************************************************
26 * Gemtek Corp still silently refuses to release any specifications
27 * of their multimedia devices, so the protocol still has to be
30 * The v4l code was inspired by Jonas Munsin's Gemtek serial line
31 * radio device driver.
33 * Please, let me know if this piece of code was useful :)
35 * TODO: multiple device support and portability were not tested
37 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
39 ***************************************************************************
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>
47 #include <linux/videodev2.h>
48 #include <media/v4l2-common.h>
49 #include <linux/errno.h>
51 #include <linux/version.h> /* for KERNEL_VERSION MACRO */
52 #define RADIO_VERSION KERNEL_VERSION(0,0,2)
54 static struct v4l2_queryctrl radio_qctrl
[] = {
56 .id
= V4L2_CID_AUDIO_MUTE
,
61 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
63 .id
= V4L2_CID_AUDIO_VOLUME
,
68 .default_value
= 0xff,
69 .type
= V4L2_CTRL_TYPE_INTEGER
,
74 #include <asm/uaccess.h>
76 #ifndef PCI_VENDOR_ID_GEMTEK
77 #define PCI_VENDOR_ID_GEMTEK 0x5046
80 #ifndef PCI_DEVICE_ID_GEMTEK_PR103
81 #define PCI_DEVICE_ID_GEMTEK_PR103 0x1001
84 #ifndef GEMTEK_PCI_RANGE_LOW
85 #define GEMTEK_PCI_RANGE_LOW (87*16000)
88 #ifndef GEMTEK_PCI_RANGE_HIGH
89 #define GEMTEK_PCI_RANGE_HIGH (108*16000)
100 struct gemtek_pci_card
{
101 struct video_device
*videodev
;
108 u32 current_frequency
;
112 static const char rcsid
[] = "$Id: radio-gemtek-pci.c,v 1.1 2001/07/23 08:08:16 ted Exp ted $";
114 static int nr_radio
= -1;
116 static inline u8
gemtek_pci_out( u16 value
, u32 port
)
123 #define _b0( v ) *((u8 *)&v)
124 static void __gemtek_pci_cmd( u16 value
, u32 port
, u8
*last_byte
, int keep
)
126 register u8 byte
= *last_byte
;
147 static inline void gemtek_pci_nil( u32 port
, u8
*last_byte
)
149 __gemtek_pci_cmd( 0x00, port
, last_byte
, FALSE
);
152 static inline void gemtek_pci_cmd( u16 cmd
, u32 port
, u8
*last_byte
)
154 __gemtek_pci_cmd( cmd
, port
, last_byte
, TRUE
);
157 static void gemtek_pci_setfrequency( struct gemtek_pci_card
*card
, unsigned long frequency
)
160 register u32 value
= frequency
/ 200 + 856;
161 register u16 mask
= 0x8000;
163 u32 port
= card
->iobase
;
165 last_byte
= gemtek_pci_out( 0x06, port
);
169 gemtek_pci_nil( port
, &last_byte
);
175 gemtek_pci_cmd( value
& mask
, port
, &last_byte
);
184 static inline void gemtek_pci_mute( struct gemtek_pci_card
*card
)
186 outb( 0x1f, card
->iobase
);
190 static inline void gemtek_pci_unmute( struct gemtek_pci_card
*card
)
193 gemtek_pci_setfrequency( card
, card
->current_frequency
);
198 static inline unsigned int gemtek_pci_getsignal( struct gemtek_pci_card
*card
)
200 return ( inb( card
->iobase
) & 0x08 ) ? 0 : 1;
203 static int gemtek_pci_do_ioctl(struct inode
*inode
, struct file
*file
,
204 unsigned int cmd
, void *arg
)
206 struct video_device
*dev
= video_devdata(file
);
207 struct gemtek_pci_card
*card
= dev
->priv
;
210 case VIDIOC_QUERYCAP
:
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
;
224 struct v4l2_tuner
*v
= arg
;
229 memset(v
,0,sizeof(*v
));
230 strcpy(v
->name
, "FM");
231 v
->type
= V4L2_TUNER_RADIO
;
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
);
244 struct v4l2_tuner
*v
= arg
;
251 case VIDIOC_S_FREQUENCY
:
253 struct v4l2_frequency
*f
= arg
;
255 if ( (f
->frequency
< GEMTEK_PCI_RANGE_LOW
) ||
256 (f
->frequency
> GEMTEK_PCI_RANGE_HIGH
) )
260 gemtek_pci_setfrequency( card
, f
->frequency
);
261 card
->current_frequency
= f
->frequency
;
265 case VIDIOC_QUERYCTRL
:
267 struct v4l2_queryctrl
*qc
= arg
;
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
]),
281 struct v4l2_control
*ctrl
= arg
;
284 case V4L2_CID_AUDIO_MUTE
:
285 ctrl
->value
=card
->mute
;
287 case V4L2_CID_AUDIO_VOLUME
:
298 struct v4l2_control
*ctrl
= arg
;
301 case V4L2_CID_AUDIO_MUTE
:
303 gemtek_pci_mute(card
);
305 gemtek_pci_unmute(card
);
308 case V4L2_CID_AUDIO_VOLUME
:
310 gemtek_pci_unmute(card
);
312 gemtek_pci_mute(card
);
319 return v4l_compat_translate_ioctl(inode
,file
,cmd
,arg
,
320 gemtek_pci_do_ioctl
);
324 static int gemtek_pci_ioctl(struct inode
*inode
, struct file
*file
,
325 unsigned int cmd
, unsigned long arg
)
327 return video_usercopy(inode
, file
, cmd
, arg
, gemtek_pci_do_ioctl
);
334 static char *card_names
[] __devinitdata
= {
338 static struct pci_device_id gemtek_pci_id
[] =
340 { PCI_VENDOR_ID_GEMTEK
, PCI_DEVICE_ID_GEMTEK_PR103
,
341 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, GEMTEK_PR103
},
345 MODULE_DEVICE_TABLE( pci
, gemtek_pci_id
);
349 static const 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
,
354 .compat_ioctl
= v4l_compat_ioctl32
,
358 static struct video_device vdev_template
= {
359 .owner
= THIS_MODULE
,
360 .name
= "Gemtek PCI Radio",
361 .type
= VID_TYPE_TUNER
,
363 .fops
= &gemtek_pci_fops
,
366 static int __devinit
gemtek_pci_probe( struct pci_dev
*pci_dev
, const struct pci_device_id
*pci_id
)
368 struct gemtek_pci_card
*card
;
369 struct video_device
*devradio
;
371 if ( (card
= kzalloc( sizeof( struct gemtek_pci_card
), GFP_KERNEL
)) == NULL
) {
372 printk( KERN_ERR
"gemtek_pci: out of memory\n" );
376 if ( pci_enable_device( pci_dev
) )
379 card
->iobase
= pci_resource_start( pci_dev
, 0 );
380 card
->length
= pci_resource_len( pci_dev
, 0 );
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" );
387 pci_read_config_byte( pci_dev
, PCI_REVISION_ID
, &card
->chiprev
);
388 pci_read_config_word( pci_dev
, PCI_SUBSYSTEM_ID
, &card
->model
);
390 pci_set_drvdata( pci_dev
, card
);
392 if ( (devradio
= kmalloc( sizeof( struct video_device
), GFP_KERNEL
)) == NULL
) {
393 printk( KERN_ERR
"gemtek_pci: out of memory\n" );
396 *devradio
= vdev_template
;
398 if ( video_register_device( devradio
, VFL_TYPE_RADIO
, nr_radio
) == -1 ) {
403 card
->videodev
= devradio
;
404 devradio
->priv
= card
;
405 gemtek_pci_mute( card
);
407 printk( KERN_INFO
"Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n",
408 card
->chiprev
, card
->iobase
, card
->iobase
+ card
->length
- 1 );
413 release_region( card
->iobase
, card
->length
);
420 static void __devexit
gemtek_pci_remove( struct pci_dev
*pci_dev
)
422 struct gemtek_pci_card
*card
= pci_get_drvdata( pci_dev
);
424 video_unregister_device( card
->videodev
);
425 kfree( card
->videodev
);
427 release_region( card
->iobase
, card
->length
);
430 gemtek_pci_mute( card
);
434 pci_set_drvdata( pci_dev
, NULL
);
437 static struct pci_driver gemtek_pci_driver
=
439 .name
= "gemtek_pci",
440 .id_table
= gemtek_pci_id
,
441 .probe
= gemtek_pci_probe
,
442 .remove
= __devexit_p(gemtek_pci_remove
),
445 static int __init
gemtek_pci_init_module( void )
447 return pci_register_driver( &gemtek_pci_driver
);
450 static void __exit
gemtek_pci_cleanup_module( void )
452 pci_unregister_driver(&gemtek_pci_driver
);
455 MODULE_AUTHOR( "Vladimir Shebordaev <vshebordaev@mail.ru>" );
456 MODULE_DESCRIPTION( "The video4linux driver for the Gemtek PCI Radio Card" );
457 MODULE_LICENSE("GPL");
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");
464 module_init( gemtek_pci_init_module
);
465 module_exit( gemtek_pci_cleanup_module
);