Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* Typhoon Radio Card driver for radio support |
| 3 | * (c) 1999 Dr. Henrik Seidel <Henrik.Seidel@gmx.de> |
| 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Notes on the hardware |
| 6 | * |
| 7 | * This card has two output sockets, one for speakers and one for line. |
| 8 | * The speaker output has volume control, but only in four discrete |
| 9 | * steps. The line output has neither volume control nor mute. |
| 10 | * |
| 11 | * The card has auto-stereo according to its manual, although it all |
| 12 | * sounds mono to me (even with the Win/DOS drivers). Maybe it's my |
| 13 | * antenna - I really don't know for sure. |
| 14 | * |
| 15 | * Frequency control is done digitally. |
| 16 | * |
| 17 | * Volume control is done digitally, but there are only four different |
| 18 | * possible values. So you should better always turn the volume up and |
| 19 | * use line control. I got the best results by connecting line output |
| 20 | * to the sound card microphone input. For such a configuration the |
| 21 | * volume control has no effect, since volume control only influences |
| 22 | * the speaker output. |
| 23 | * |
| 24 | * There is no explicit mute/unmute. So I set the radio frequency to a |
| 25 | * value where I do expect just noise and turn the speaker volume down. |
| 26 | * The frequency change is necessary since the card never seems to be |
| 27 | * completely silent. |
Mauro Carvalho Chehab | 30c4830 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 28 | * |
Mauro Carvalho Chehab | 3259081 | 2018-04-25 05:34:48 -0400 | [diff] [blame] | 29 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@kernel.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | #include <linux/module.h> /* Modules */ |
| 33 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 34 | #include <linux/ioport.h> /* request_region */ |
Mauro Carvalho Chehab | 30c4830 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 35 | #include <linux/videodev2.h> /* kernel radio structs */ |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 36 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | 9f1dfcc | 2012-02-29 05:50:27 -0300 | [diff] [blame] | 37 | #include <linux/slab.h> |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 38 | #include <media/v4l2-device.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 39 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 40 | #include "radio-isa.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Mauro Carvalho Chehab | 29834c1 | 2011-06-25 10:15:42 -0300 | [diff] [blame] | 42 | #define DRIVER_VERSION "0.1.2" |
| 43 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 44 | MODULE_AUTHOR("Dr. Henrik Seidel"); |
| 45 | MODULE_DESCRIPTION("A driver for the Typhoon radio card (a.k.a. EcoRadio)."); |
| 46 | MODULE_LICENSE("GPL"); |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 47 | MODULE_VERSION("0.1.99"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #ifndef CONFIG_RADIO_TYPHOON_PORT |
| 50 | #define CONFIG_RADIO_TYPHOON_PORT -1 |
| 51 | #endif |
| 52 | |
| 53 | #ifndef CONFIG_RADIO_TYPHOON_MUTEFREQ |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 54 | #define CONFIG_RADIO_TYPHOON_MUTEFREQ 87000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #endif |
| 56 | |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 57 | #define TYPHOON_MAX 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 59 | static int io[TYPHOON_MAX] = { [0] = CONFIG_RADIO_TYPHOON_PORT, |
| 60 | [1 ... (TYPHOON_MAX - 1)] = -1 }; |
| 61 | static int radio_nr[TYPHOON_MAX] = { [0 ... (TYPHOON_MAX - 1)] = -1 }; |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 62 | static unsigned long mutefreq = CONFIG_RADIO_TYPHOON_MUTEFREQ; |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 63 | |
| 64 | module_param_array(io, int, NULL, 0444); |
| 65 | MODULE_PARM_DESC(io, "I/O addresses of the Typhoon card (0x316 or 0x336)"); |
| 66 | module_param_array(radio_nr, int, NULL, 0444); |
| 67 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 68 | module_param(mutefreq, ulong, 0); |
| 69 | MODULE_PARM_DESC(mutefreq, "Frequency used when muting the card (in kHz)"); |
| 70 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 71 | struct typhoon { |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 72 | struct radio_isa_card isa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | int muted; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 76 | static struct radio_isa_card *typhoon_alloc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 78 | struct typhoon *ty = kzalloc(sizeof(*ty), GFP_KERNEL); |
| 79 | |
| 80 | return ty ? &ty->isa : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 83 | static int typhoon_s_frequency(struct radio_isa_card *isa, u32 freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
| 85 | unsigned long outval; |
| 86 | unsigned long x; |
| 87 | |
| 88 | /* |
| 89 | * The frequency transfer curve is not linear. The best fit I could |
| 90 | * get is |
| 91 | * |
| 92 | * outval = -155 + exp((f + 15.55) * 0.057)) |
| 93 | * |
| 94 | * where frequency f is in MHz. Since we don't have exp in the kernel, |
| 95 | * I approximate this function by a third order polynomial. |
| 96 | * |
| 97 | */ |
| 98 | |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 99 | x = freq / 160; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | outval = (x * x + 2500) / 5000; |
| 101 | outval = (outval * x + 5000) / 10000; |
| 102 | outval -= (10 * x * x + 10433) / 20866; |
| 103 | outval += 4 * x - 11505; |
| 104 | |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 105 | outb_p((outval >> 8) & 0x01, isa->io + 4); |
| 106 | outb_p(outval >> 9, isa->io + 6); |
| 107 | outb_p(outval & 0xff, isa->io + 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | return 0; |
| 109 | } |
| 110 | |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 111 | static int typhoon_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 113 | struct typhoon *ty = container_of(isa, struct typhoon, isa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 115 | if (mute) |
| 116 | vol = 0; |
| 117 | vol >>= 14; /* Map 16 bit to 2 bit */ |
| 118 | vol &= 3; |
| 119 | outb_p(vol / 2, isa->io); /* Set the volume, high bit. */ |
| 120 | outb_p(vol % 2, isa->io + 2); /* Set the volume, low bit. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 122 | if (vol == 0 && !ty->muted) { |
| 123 | ty->muted = true; |
| 124 | return typhoon_s_frequency(isa, mutefreq << 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 126 | if (vol && ty->muted) { |
| 127 | ty->muted = false; |
| 128 | return typhoon_s_frequency(isa, isa->freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 133 | static const struct radio_isa_ops typhoon_ops = { |
| 134 | .alloc = typhoon_alloc, |
| 135 | .s_mute_volume = typhoon_s_mute_volume, |
| 136 | .s_frequency = typhoon_s_frequency, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 139 | static const int typhoon_ioports[] = { 0x316, 0x336 }; |
| 140 | |
| 141 | static struct radio_isa_driver typhoon_driver = { |
| 142 | .driver = { |
| 143 | .match = radio_isa_match, |
| 144 | .probe = radio_isa_probe, |
| 145 | .remove = radio_isa_remove, |
| 146 | .driver = { |
| 147 | .name = "radio-typhoon", |
| 148 | }, |
| 149 | }, |
| 150 | .io_params = io, |
| 151 | .radio_nr_params = radio_nr, |
| 152 | .io_ports = typhoon_ioports, |
| 153 | .num_of_io_ports = ARRAY_SIZE(typhoon_ioports), |
| 154 | .region_size = 8, |
| 155 | .card = "Typhoon Radio", |
| 156 | .ops = &typhoon_ops, |
| 157 | .has_stereo = true, |
| 158 | .max_volume = 3, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | static int __init typhoon_init(void) |
| 162 | { |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 163 | if (mutefreq < 87000 || mutefreq > 108000) { |
| 164 | printk(KERN_ERR "%s: You must set a frequency (in kHz) used when muting the card,\n", |
| 165 | typhoon_driver.driver.driver.name); |
| 166 | printk(KERN_ERR "%s: e.g. with \"mutefreq=87500\" (87000 <= mutefreq <= 108000)\n", |
| 167 | typhoon_driver.driver.driver.name); |
| 168 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 170 | return isa_register_driver(&typhoon_driver.driver, TYPHOON_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 173 | static void __exit typhoon_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 175 | isa_unregister_driver(&typhoon_driver.driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Hans Verkuil | da1ff35 | 2012-01-16 05:17:32 -0300 | [diff] [blame] | 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | module_init(typhoon_init); |
Hans Verkuil | f1bfe89 | 2009-03-06 13:54:52 -0300 | [diff] [blame] | 180 | module_exit(typhoon_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |