Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * RadioTrack II driver
0004  * Copyright 1998 Ben Pfaff
0005  *
0006  * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
0007  * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
0008  * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
0009  *
0010  * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
0011  * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@kernel.org>
0012  *
0013  * Fully tested with actual hardware and the v4l2-compliance tool.
0014  */
0015 
0016 #include <linux/module.h>   /* Modules          */
0017 #include <linux/init.h>     /* Initdata         */
0018 #include <linux/ioport.h>   /* request_region       */
0019 #include <linux/delay.h>    /* udelay           */
0020 #include <linux/videodev2.h>    /* kernel radio structs     */
0021 #include <linux/mutex.h>
0022 #include <linux/io.h>       /* outb, outb_p         */
0023 #include <linux/slab.h>
0024 #include <media/v4l2-device.h>
0025 #include <media/v4l2-ioctl.h>
0026 #include "radio-isa.h"
0027 
0028 MODULE_AUTHOR("Ben Pfaff");
0029 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
0030 MODULE_LICENSE("GPL");
0031 MODULE_VERSION("0.1.99");
0032 
0033 #ifndef CONFIG_RADIO_RTRACK2_PORT
0034 #define CONFIG_RADIO_RTRACK2_PORT -1
0035 #endif
0036 
0037 #define RTRACK2_MAX 2
0038 
0039 static int io[RTRACK2_MAX] = { [0] = CONFIG_RADIO_RTRACK2_PORT,
0040                   [1 ... (RTRACK2_MAX - 1)] = -1 };
0041 static int radio_nr[RTRACK2_MAX] = { [0 ... (RTRACK2_MAX - 1)] = -1 };
0042 
0043 module_param_array(io, int, NULL, 0444);
0044 MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
0045 module_param_array(radio_nr, int, NULL, 0444);
0046 MODULE_PARM_DESC(radio_nr, "Radio device numbers");
0047 
0048 static struct radio_isa_card *rtrack2_alloc(void)
0049 {
0050     return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
0051 }
0052 
0053 static void zero(struct radio_isa_card *isa)
0054 {
0055     outb_p(1, isa->io);
0056     outb_p(3, isa->io);
0057     outb_p(1, isa->io);
0058 }
0059 
0060 static void one(struct radio_isa_card *isa)
0061 {
0062     outb_p(5, isa->io);
0063     outb_p(7, isa->io);
0064     outb_p(5, isa->io);
0065 }
0066 
0067 static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq)
0068 {
0069     int i;
0070 
0071     freq = freq / 200 + 856;
0072 
0073     outb_p(0xc8, isa->io);
0074     outb_p(0xc9, isa->io);
0075     outb_p(0xc9, isa->io);
0076 
0077     for (i = 0; i < 10; i++)
0078         zero(isa);
0079 
0080     for (i = 14; i >= 0; i--)
0081         if (freq & (1 << i))
0082             one(isa);
0083         else
0084             zero(isa);
0085 
0086     outb_p(0xc8, isa->io);
0087     outb_p(v4l2_ctrl_g_ctrl(isa->mute), isa->io);
0088     return 0;
0089 }
0090 
0091 static u32 rtrack2_g_signal(struct radio_isa_card *isa)
0092 {
0093     /* bit set = no signal present  */
0094     return (inb(isa->io) & 2) ? 0 : 0xffff;
0095 }
0096 
0097 static int rtrack2_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
0098 {
0099     outb(mute, isa->io);
0100     return 0;
0101 }
0102 
0103 static const struct radio_isa_ops rtrack2_ops = {
0104     .alloc = rtrack2_alloc,
0105     .s_mute_volume = rtrack2_s_mute_volume,
0106     .s_frequency = rtrack2_s_frequency,
0107     .g_signal = rtrack2_g_signal,
0108 };
0109 
0110 static const int rtrack2_ioports[] = { 0x20f, 0x30f };
0111 
0112 static struct radio_isa_driver rtrack2_driver = {
0113     .driver = {
0114         .match      = radio_isa_match,
0115         .probe      = radio_isa_probe,
0116         .remove     = radio_isa_remove,
0117         .driver     = {
0118             .name   = "radio-rtrack2",
0119         },
0120     },
0121     .io_params = io,
0122     .radio_nr_params = radio_nr,
0123     .io_ports = rtrack2_ioports,
0124     .num_of_io_ports = ARRAY_SIZE(rtrack2_ioports),
0125     .region_size = 4,
0126     .card = "AIMSlab RadioTrack II",
0127     .ops = &rtrack2_ops,
0128     .has_stereo = true,
0129 };
0130 
0131 static int __init rtrack2_init(void)
0132 {
0133     return isa_register_driver(&rtrack2_driver.driver, RTRACK2_MAX);
0134 }
0135 
0136 static void __exit rtrack2_exit(void)
0137 {
0138     isa_unregister_driver(&rtrack2_driver.driver);
0139 }
0140 
0141 module_init(rtrack2_init);
0142 module_exit(rtrack2_exit);