Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* Terratec ActiveRadio ISA Standalone card driver for Linux radio support
0003  * (c) 1999 R. Offermanns (rolf@offermanns.de)
0004  * based on the aimslab radio driver from M. Kirkwood
0005  * many thanks to Michael Becker and Friedhelm Birth (from TerraTec)
0006  *
0007  *
0008  * History:
0009  * 1999-05-21   First preview release
0010  *
0011  *  Notes on the hardware:
0012  *  There are two "main" chips on the card:
0013  *  - Philips OM5610 (http://www-us.semiconductors.philips.com/acrobat/datasheets/OM5610_2.pdf)
0014  *  - Philips SAA6588 (http://www-us.semiconductors.philips.com/acrobat/datasheets/SAA6588_1.pdf)
0015  *  (you can get the datasheet at the above links)
0016  *
0017  *  Frequency control is done digitally -- ie out(port,encodefreq(95.8));
0018  *  Volume Control is done digitally
0019  *
0020  * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
0021  * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@kernel.org>
0022  */
0023 
0024 #include <linux/module.h>   /* Modules          */
0025 #include <linux/init.h>     /* Initdata         */
0026 #include <linux/ioport.h>   /* request_region       */
0027 #include <linux/videodev2.h>    /* kernel radio structs     */
0028 #include <linux/mutex.h>
0029 #include <linux/io.h>       /* outb, outb_p         */
0030 #include <linux/slab.h>
0031 #include <media/v4l2-device.h>
0032 #include <media/v4l2-ioctl.h>
0033 #include "radio-isa.h"
0034 
0035 MODULE_AUTHOR("R. Offermans & others");
0036 MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
0037 MODULE_LICENSE("GPL");
0038 MODULE_VERSION("0.1.99");
0039 
0040 /* Note: there seems to be only one possible port (0x590), but without
0041    hardware this is hard to verify. For now, this is the only one we will
0042    support. */
0043 static int io = 0x590;
0044 static int radio_nr = -1;
0045 
0046 module_param(radio_nr, int, 0444);
0047 MODULE_PARM_DESC(radio_nr, "Radio device number");
0048 
0049 #define WRT_DIS     0x00
0050 #define CLK_OFF     0x00
0051 #define IIC_DATA    0x01
0052 #define IIC_CLK     0x02
0053 #define DATA        0x04
0054 #define CLK_ON      0x08
0055 #define WRT_EN      0x10
0056 
0057 static struct radio_isa_card *terratec_alloc(void)
0058 {
0059     return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
0060 }
0061 
0062 static int terratec_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
0063 {
0064     int i;
0065 
0066     if (mute)
0067         vol = 0;
0068     vol = vol + (vol * 32); /* change both channels */
0069     for (i = 0; i < 8; i++) {
0070         if (vol & (0x80 >> i))
0071             outb(0x80, isa->io + 1);
0072         else
0073             outb(0x00, isa->io + 1);
0074     }
0075     return 0;
0076 }
0077 
0078 
0079 /* this is the worst part in this driver */
0080 /* many more or less strange things are going on here, but hey, it works :) */
0081 
0082 static int terratec_s_frequency(struct radio_isa_card *isa, u32 freq)
0083 {
0084     int i;
0085     int p;
0086     int temp;
0087     long rest;
0088     unsigned char buffer[25];       /* we have to bit shift 25 registers */
0089 
0090     freq = freq / 160;          /* convert the freq. to a nice to handle value */
0091     memset(buffer, 0, sizeof(buffer));
0092 
0093     rest = freq * 10 + 10700;   /* I once had understood what is going on here */
0094                     /* maybe some wise guy (friedhelm?) can comment this stuff */
0095     i = 13;
0096     p = 10;
0097     temp = 102400;
0098     while (rest != 0) {
0099         if (rest % temp  == rest)
0100             buffer[i] = 0;
0101         else {
0102             buffer[i] = 1;
0103             rest = rest - temp;
0104         }
0105         i--;
0106         p--;
0107         temp = temp / 2;
0108     }
0109 
0110     for (i = 24; i > -1; i--) { /* bit shift the values to the radiocard */
0111         if (buffer[i] == 1) {
0112             outb(WRT_EN | DATA, isa->io);
0113             outb(WRT_EN | DATA | CLK_ON, isa->io);
0114             outb(WRT_EN | DATA, isa->io);
0115         } else {
0116             outb(WRT_EN | 0x00, isa->io);
0117             outb(WRT_EN | 0x00 | CLK_ON, isa->io);
0118         }
0119     }
0120     outb(0x00, isa->io);
0121     return 0;
0122 }
0123 
0124 static u32 terratec_g_signal(struct radio_isa_card *isa)
0125 {
0126     /* bit set = no signal present  */
0127     return (inb(isa->io) & 2) ? 0 : 0xffff;
0128 }
0129 
0130 static const struct radio_isa_ops terratec_ops = {
0131     .alloc = terratec_alloc,
0132     .s_mute_volume = terratec_s_mute_volume,
0133     .s_frequency = terratec_s_frequency,
0134     .g_signal = terratec_g_signal,
0135 };
0136 
0137 static const int terratec_ioports[] = { 0x590 };
0138 
0139 static struct radio_isa_driver terratec_driver = {
0140     .driver = {
0141         .match      = radio_isa_match,
0142         .probe      = radio_isa_probe,
0143         .remove     = radio_isa_remove,
0144         .driver     = {
0145             .name   = "radio-terratec",
0146         },
0147     },
0148     .io_params = &io,
0149     .radio_nr_params = &radio_nr,
0150     .io_ports = terratec_ioports,
0151     .num_of_io_ports = ARRAY_SIZE(terratec_ioports),
0152     .region_size = 2,
0153     .card = "TerraTec ActiveRadio",
0154     .ops = &terratec_ops,
0155     .has_stereo = true,
0156     .max_volume = 10,
0157 };
0158 
0159 static int __init terratec_init(void)
0160 {
0161     return isa_register_driver(&terratec_driver.driver, 1);
0162 }
0163 
0164 static void __exit terratec_exit(void)
0165 {
0166     isa_unregister_driver(&terratec_driver.driver);
0167 }
0168 
0169 module_init(terratec_init);
0170 module_exit(terratec_exit);
0171