Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * AimsLab RadioTrack (aka RadioVeveal) driver
0004  *
0005  * Copyright 1997 M. Kirkwood
0006  *
0007  * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
0008  * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@kernel.org>
0009  * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
0010  * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
0011  *
0012  * Notes on the hardware (reverse engineered from other peoples'
0013  * reverse engineering of AIMS' code :-)
0014  *
0015  *  Frequency control is done digitally -- ie out(port,encodefreq(95.8));
0016  *
0017  *  The signal strength query is unsurprisingly inaccurate.  And it seems
0018  *  to indicate that (on my card, at least) the frequency setting isn't
0019  *  too great.  (I have to tune up .025MHz from what the freq should be
0020  *  to get a report that the thing is tuned.)
0021  *
0022  *  Volume control is (ugh) analogue:
0023  *   out(port, start_increasing_volume);
0024  *   wait(a_wee_while);
0025  *   out(port, stop_changing_the_volume);
0026  *
0027  * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
0028  */
0029 
0030 #include <linux/module.h>   /* Modules          */
0031 #include <linux/init.h>     /* Initdata         */
0032 #include <linux/ioport.h>   /* request_region       */
0033 #include <linux/delay.h>    /* msleep           */
0034 #include <linux/videodev2.h>    /* kernel radio structs     */
0035 #include <linux/io.h>       /* outb, outb_p         */
0036 #include <linux/slab.h>
0037 #include <media/v4l2-device.h>
0038 #include <media/v4l2-ioctl.h>
0039 #include <media/v4l2-ctrls.h>
0040 #include "radio-isa.h"
0041 #include "lm7000.h"
0042 
0043 MODULE_AUTHOR("M. Kirkwood");
0044 MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
0045 MODULE_LICENSE("GPL");
0046 MODULE_VERSION("1.0.0");
0047 
0048 #ifndef CONFIG_RADIO_RTRACK_PORT
0049 #define CONFIG_RADIO_RTRACK_PORT -1
0050 #endif
0051 
0052 #define RTRACK_MAX 2
0053 
0054 static int io[RTRACK_MAX] = { [0] = CONFIG_RADIO_RTRACK_PORT,
0055                   [1 ... (RTRACK_MAX - 1)] = -1 };
0056 static int radio_nr[RTRACK_MAX] = { [0 ... (RTRACK_MAX - 1)] = -1 };
0057 
0058 module_param_array(io, int, NULL, 0444);
0059 MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
0060 module_param_array(radio_nr, int, NULL, 0444);
0061 MODULE_PARM_DESC(radio_nr, "Radio device numbers");
0062 
0063 struct rtrack {
0064     struct radio_isa_card isa;
0065     int curvol;
0066 };
0067 
0068 static struct radio_isa_card *rtrack_alloc(void)
0069 {
0070     struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL);
0071 
0072     if (rt)
0073         rt->curvol = 0xff;
0074     return rt ? &rt->isa : NULL;
0075 }
0076 
0077 #define AIMS_BIT_TUN_CE     (1 << 0)
0078 #define AIMS_BIT_TUN_CLK    (1 << 1)
0079 #define AIMS_BIT_TUN_DATA   (1 << 2)
0080 #define AIMS_BIT_VOL_CE     (1 << 3)
0081 #define AIMS_BIT_TUN_STRQ   (1 << 4)
0082 /* bit 5 is not connected */
0083 #define AIMS_BIT_VOL_UP     (1 << 6)    /* active low */
0084 #define AIMS_BIT_VOL_DN     (1 << 7)    /* active low */
0085 
0086 static void rtrack_set_pins(void *handle, u8 pins)
0087 {
0088     struct radio_isa_card *isa = handle;
0089     struct rtrack *rt = container_of(isa, struct rtrack, isa);
0090     u8 bits = AIMS_BIT_VOL_DN | AIMS_BIT_VOL_UP | AIMS_BIT_TUN_STRQ;
0091 
0092     if (!v4l2_ctrl_g_ctrl(rt->isa.mute))
0093         bits |= AIMS_BIT_VOL_CE;
0094 
0095     if (pins & LM7000_DATA)
0096         bits |= AIMS_BIT_TUN_DATA;
0097     if (pins & LM7000_CLK)
0098         bits |= AIMS_BIT_TUN_CLK;
0099     if (pins & LM7000_CE)
0100         bits |= AIMS_BIT_TUN_CE;
0101 
0102     outb_p(bits, rt->isa.io);
0103 }
0104 
0105 static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq)
0106 {
0107     lm7000_set_freq(freq, isa, rtrack_set_pins);
0108 
0109     return 0;
0110 }
0111 
0112 static u32 rtrack_g_signal(struct radio_isa_card *isa)
0113 {
0114     /* bit set = no signal present */
0115     return 0xffff * !(inb(isa->io) & 2);
0116 }
0117 
0118 static int rtrack_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
0119 {
0120     struct rtrack *rt = container_of(isa, struct rtrack, isa);
0121     int curvol = rt->curvol;
0122 
0123     if (mute) {
0124         outb(0xd0, isa->io);    /* volume steady + sigstr + off */
0125         return 0;
0126     }
0127     if (vol == 0) {         /* volume = 0 means mute the card */
0128         outb(0x48, isa->io);    /* volume down but still "on"   */
0129         msleep(curvol * 3); /* make sure it's totally down  */
0130     } else if (curvol < vol) {
0131         outb(0x98, isa->io);    /* volume up + sigstr + on  */
0132         for (; curvol < vol; curvol++)
0133             mdelay(3);
0134     } else if (curvol > vol) {
0135         outb(0x58, isa->io);    /* volume down + sigstr + on    */
0136         for (; curvol > vol; curvol--)
0137             mdelay(3);
0138     }
0139     outb(0xd8, isa->io);        /* volume steady + sigstr + on  */
0140     rt->curvol = vol;
0141     return 0;
0142 }
0143 
0144 /* Mute card - prevents noisy bootups */
0145 static int rtrack_initialize(struct radio_isa_card *isa)
0146 {
0147     /* this ensures that the volume is all the way up  */
0148     outb(0x90, isa->io);    /* volume up but still "on" */
0149     msleep(3000);       /* make sure it's totally up    */
0150     outb(0xc0, isa->io);    /* steady volume, mute card */
0151     return 0;
0152 }
0153 
0154 static const struct radio_isa_ops rtrack_ops = {
0155     .alloc = rtrack_alloc,
0156     .init = rtrack_initialize,
0157     .s_mute_volume = rtrack_s_mute_volume,
0158     .s_frequency = rtrack_s_frequency,
0159     .g_signal = rtrack_g_signal,
0160 };
0161 
0162 static const int rtrack_ioports[] = { 0x20f, 0x30f };
0163 
0164 static struct radio_isa_driver rtrack_driver = {
0165     .driver = {
0166         .match      = radio_isa_match,
0167         .probe      = radio_isa_probe,
0168         .remove     = radio_isa_remove,
0169         .driver     = {
0170             .name   = "radio-aimslab",
0171         },
0172     },
0173     .io_params = io,
0174     .radio_nr_params = radio_nr,
0175     .io_ports = rtrack_ioports,
0176     .num_of_io_ports = ARRAY_SIZE(rtrack_ioports),
0177     .region_size = 2,
0178     .card = "AIMSlab RadioTrack/RadioReveal",
0179     .ops = &rtrack_ops,
0180     .has_stereo = true,
0181     .max_volume = 0xff,
0182 };
0183 
0184 static int __init rtrack_init(void)
0185 {
0186     return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX);
0187 }
0188 
0189 static void __exit rtrack_exit(void)
0190 {
0191     isa_unregister_driver(&rtrack_driver.driver);
0192 }
0193 
0194 module_init(rtrack_init);
0195 module_exit(rtrack_exit);