^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Terratec ActiveRadio ISA Standalone card driver for Linux radio support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * (c) 1999 R. Offermanns (rolf@offermanns.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * based on the aimslab radio driver from M. Kirkwood
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * many thanks to Michael Becker and Friedhelm Birth (from TerraTec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * History:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * 1999-05-21 First preview release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Notes on the hardware:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * There are two "main" chips on the card:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * - Philips OM5610 (http://www-us.semiconductors.philips.com/acrobat/datasheets/OM5610_2.pdf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * - Philips SAA6588 (http://www-us.semiconductors.philips.com/acrobat/datasheets/SAA6588_1.pdf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * (you can get the datasheet at the above links)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Frequency control is done digitally -- ie out(port,encodefreq(95.8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Volume Control is done digitally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/module.h> /* Modules */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/init.h> /* Initdata */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/ioport.h> /* request_region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/videodev2.h> /* kernel radio structs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/io.h> /* outb, outb_p */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <media/v4l2-device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <media/v4l2-ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "radio-isa.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) MODULE_AUTHOR("R. Offermans & others");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) MODULE_VERSION("0.1.99");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* Note: there seems to be only one possible port (0x590), but without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) hardware this is hard to verify. For now, this is the only one we will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) support. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int io = 0x590;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static int radio_nr = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) module_param(radio_nr, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) MODULE_PARM_DESC(radio_nr, "Radio device number");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define WRT_DIS 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define CLK_OFF 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define IIC_DATA 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define IIC_CLK 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define DATA 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define CLK_ON 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define WRT_EN 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static struct radio_isa_card *terratec_alloc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int terratec_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (mute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) vol = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) vol = vol + (vol * 32); /* change both channels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (vol & (0x80 >> i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) outb(0x80, isa->io + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) outb(0x00, isa->io + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* this is the worst part in this driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /* many more or less strange things are going on here, but hey, it works :) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static int terratec_s_frequency(struct radio_isa_card *isa, u32 freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) long rest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) unsigned char buffer[25]; /* we have to bit shift 25 registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) freq = freq / 160; /* convert the freq. to a nice to handle value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) memset(buffer, 0, sizeof(buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) rest = freq * 10 + 10700; /* I once had understood what is going on here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* maybe some wise guy (friedhelm?) can comment this stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) i = 13;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) p = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) temp = 102400;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) while (rest != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (rest % temp == rest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) buffer[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) buffer[i] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) rest = rest - temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) i--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) p--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) temp = temp / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) for (i = 24; i > -1; i--) { /* bit shift the values to the radiocard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (buffer[i] == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) outb(WRT_EN | DATA, isa->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) outb(WRT_EN | DATA | CLK_ON, isa->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) outb(WRT_EN | DATA, isa->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) outb(WRT_EN | 0x00, isa->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) outb(WRT_EN | 0x00 | CLK_ON, isa->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) outb(0x00, isa->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static u32 terratec_g_signal(struct radio_isa_card *isa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /* bit set = no signal present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return (inb(isa->io) & 2) ? 0 : 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static const struct radio_isa_ops terratec_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .alloc = terratec_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .s_mute_volume = terratec_s_mute_volume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .s_frequency = terratec_s_frequency,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .g_signal = terratec_g_signal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static const int terratec_ioports[] = { 0x590 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static struct radio_isa_driver terratec_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .match = radio_isa_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .probe = radio_isa_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .remove = radio_isa_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .name = "radio-terratec",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .io_params = &io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .radio_nr_params = &radio_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .io_ports = terratec_ioports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .num_of_io_ports = ARRAY_SIZE(terratec_ioports),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .region_size = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .card = "TerraTec ActiveRadio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .ops = &terratec_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) .has_stereo = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .max_volume = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static int __init terratec_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return isa_register_driver(&terratec_driver.driver, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static void __exit terratec_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) isa_unregister_driver(&terratec_driver.driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) module_init(terratec_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) module_exit(terratec_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)