linux/drivers/media/radio/radio-rtrack2.c
<<
>>
Prefs
   1/*
   2 * RadioTrack II driver
   3 * Copyright 1998 Ben Pfaff
   4 *
   5 * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
   6 * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
   7 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
   8 *
   9 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
  10 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
  11 */
  12
  13#include <linux/module.h>       /* Modules                      */
  14#include <linux/init.h>         /* Initdata                     */
  15#include <linux/ioport.h>       /* request_region               */
  16#include <linux/delay.h>        /* udelay                       */
  17#include <linux/videodev2.h>    /* kernel radio structs         */
  18#include <linux/mutex.h>
  19#include <linux/io.h>           /* outb, outb_p                 */
  20#include <linux/slab.h>
  21#include <media/v4l2-device.h>
  22#include <media/v4l2-ioctl.h>
  23#include "radio-isa.h"
  24
  25MODULE_AUTHOR("Ben Pfaff");
  26MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
  27MODULE_LICENSE("GPL");
  28MODULE_VERSION("0.1.99");
  29
  30#ifndef CONFIG_RADIO_RTRACK2_PORT
  31#define CONFIG_RADIO_RTRACK2_PORT -1
  32#endif
  33
  34#define RTRACK2_MAX 2
  35
  36static int io[RTRACK2_MAX] = { [0] = CONFIG_RADIO_RTRACK2_PORT,
  37                              [1 ... (RTRACK2_MAX - 1)] = -1 };
  38static int radio_nr[RTRACK2_MAX] = { [0 ... (RTRACK2_MAX - 1)] = -1 };
  39
  40module_param_array(io, int, NULL, 0444);
  41MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
  42module_param_array(radio_nr, int, NULL, 0444);
  43MODULE_PARM_DESC(radio_nr, "Radio device numbers");
  44
  45static struct radio_isa_card *rtrack2_alloc(void)
  46{
  47        return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
  48}
  49
  50static void zero(struct radio_isa_card *isa)
  51{
  52        outb_p(1, isa->io);
  53        outb_p(3, isa->io);
  54        outb_p(1, isa->io);
  55}
  56
  57static void one(struct radio_isa_card *isa)
  58{
  59        outb_p(5, isa->io);
  60        outb_p(7, isa->io);
  61        outb_p(5, isa->io);
  62}
  63
  64static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq)
  65{
  66        int i;
  67
  68        freq = freq / 200 + 856;
  69
  70        outb_p(0xc8, isa->io);
  71        outb_p(0xc9, isa->io);
  72        outb_p(0xc9, isa->io);
  73
  74        for (i = 0; i < 10; i++)
  75                zero(isa);
  76
  77        for (i = 14; i >= 0; i--)
  78                if (freq & (1 << i))
  79                        one(isa);
  80                else
  81                        zero(isa);
  82
  83        outb_p(0xc8, isa->io);
  84        if (!v4l2_ctrl_g_ctrl(isa->mute))
  85                outb_p(0, isa->io);
  86        return 0;
  87}
  88
  89static u32 rtrack2_g_signal(struct radio_isa_card *isa)
  90{
  91        /* bit set = no signal present  */
  92        return (inb(isa->io) & 2) ? 0 : 0xffff;
  93}
  94
  95static int rtrack2_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
  96{
  97        outb(mute, isa->io);
  98        return 0;
  99}
 100
 101static const struct radio_isa_ops rtrack2_ops = {
 102        .alloc = rtrack2_alloc,
 103        .s_mute_volume = rtrack2_s_mute_volume,
 104        .s_frequency = rtrack2_s_frequency,
 105        .g_signal = rtrack2_g_signal,
 106};
 107
 108static const int rtrack2_ioports[] = { 0x20f, 0x30f };
 109
 110static struct radio_isa_driver rtrack2_driver = {
 111        .driver = {
 112                .match          = radio_isa_match,
 113                .probe          = radio_isa_probe,
 114                .remove         = radio_isa_remove,
 115                .driver         = {
 116                        .name   = "radio-rtrack2",
 117                },
 118        },
 119        .io_params = io,
 120        .radio_nr_params = radio_nr,
 121        .io_ports = rtrack2_ioports,
 122        .num_of_io_ports = ARRAY_SIZE(rtrack2_ioports),
 123        .region_size = 4,
 124        .card = "AIMSlab RadioTrack II",
 125        .ops = &rtrack2_ops,
 126        .has_stereo = true,
 127};
 128
 129static int __init rtrack2_init(void)
 130{
 131        return isa_register_driver(&rtrack2_driver.driver, RTRACK2_MAX);
 132}
 133
 134static void __exit rtrack2_exit(void)
 135{
 136        isa_unregister_driver(&rtrack2_driver.driver);
 137}
 138
 139module_init(rtrack2_init);
 140module_exit(rtrack2_exit);
 141