Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 1 | /* |
| 2 | * AimsLab RadioTrack (aka RadioVeveal) driver |
| 3 | * |
| 4 | * Copyright 1997 M. Kirkwood |
| 5 | * |
| 6 | * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com> |
Mauro Carvalho Chehab | 46ff2c7 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 7 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Alan Cox | d9b0144 | 2008-10-27 15:13:47 -0300 | [diff] [blame] | 8 | * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org> |
| 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * Notes on the hardware (reverse engineered from other peoples' |
| 12 | * reverse engineering of AIMS' code :-) |
| 13 | * |
| 14 | * Frequency control is done digitally -- ie out(port,encodefreq(95.8)); |
| 15 | * |
| 16 | * The signal strength query is unsurprisingly inaccurate. And it seems |
| 17 | * to indicate that (on my card, at least) the frequency setting isn't |
| 18 | * too great. (I have to tune up .025MHz from what the freq should be |
| 19 | * to get a report that the thing is tuned.) |
| 20 | * |
| 21 | * Volume control is (ugh) analogue: |
| 22 | * out(port, start_increasing_volume); |
| 23 | * wait(a_wee_while); |
| 24 | * out(port, stop_changing_the_volume); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 25 | * |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 26 | * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <linux/module.h> /* Modules */ |
| 30 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 31 | #include <linux/ioport.h> /* request_region */ |
Geert Uytterhoeven | 2400982 | 2011-01-16 10:09:13 -0300 | [diff] [blame] | 32 | #include <linux/delay.h> /* msleep */ |
Mauro Carvalho Chehab | 46ff2c7 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 33 | #include <linux/videodev2.h> /* kernel radio structs */ |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 34 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | 9f1dfcc | 2012-02-29 05:50:27 -0300 | [diff] [blame] | 35 | #include <linux/slab.h> |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 36 | #include <media/v4l2-device.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 37 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 38 | #include <media/v4l2-ctrls.h> |
| 39 | #include "radio-isa.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 41 | MODULE_AUTHOR("M. Kirkwood"); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 42 | MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card."); |
| 43 | MODULE_LICENSE("GPL"); |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 44 | MODULE_VERSION("1.0.0"); |
Mauro Carvalho Chehab | 46ff2c7 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #ifndef CONFIG_RADIO_RTRACK_PORT |
| 47 | #define CONFIG_RADIO_RTRACK_PORT -1 |
| 48 | #endif |
| 49 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 50 | #define RTRACK_MAX 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 52 | static int io[RTRACK_MAX] = { [0] = CONFIG_RADIO_RTRACK_PORT, |
| 53 | [1 ... (RTRACK_MAX - 1)] = -1 }; |
| 54 | static int radio_nr[RTRACK_MAX] = { [0 ... (RTRACK_MAX - 1)] = -1 }; |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 55 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 56 | module_param_array(io, int, NULL, 0444); |
| 57 | MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)"); |
| 58 | module_param_array(radio_nr, int, NULL, 0444); |
| 59 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); |
| 60 | |
| 61 | struct rtrack { |
| 62 | struct radio_isa_card isa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | int curvol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 66 | static struct radio_isa_card *rtrack_alloc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 68 | struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL); |
| 69 | |
Mauro Carvalho Chehab | 8f7fa3c | 2012-06-25 11:06:54 -0300 | [diff] [blame^] | 70 | if (rt) |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 71 | rt->curvol = 0xff; |
| 72 | return rt ? &rt->isa : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Mauro Carvalho Chehab | 8f7fa3c | 2012-06-25 11:06:54 -0300 | [diff] [blame^] | 75 | /* The 128+64 on these outb's is to keep the volume stable while tuning. |
| 76 | * Without them, the volume _will_ creep up with each frequency change |
| 77 | * and bit 4 (+16) is to keep the signal strength meter enabled. |
| 78 | */ |
| 79 | |
| 80 | static void send_0_byte(struct radio_isa_card *isa, int on) |
| 81 | { |
| 82 | outb_p(128+64+16+on+1, isa->io); /* wr-enable + data low */ |
| 83 | outb_p(128+64+16+on+2+1, isa->io); /* clock */ |
| 84 | msleep(1); |
| 85 | } |
| 86 | |
| 87 | static void send_1_byte(struct radio_isa_card *isa, int on) |
| 88 | { |
| 89 | outb_p(128+64+16+on+4+1, isa->io); /* wr-enable+data high */ |
| 90 | outb_p(128+64+16+on+4+2+1, isa->io); /* clock */ |
| 91 | msleep(1); |
| 92 | } |
| 93 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 94 | static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
Mauro Carvalho Chehab | 8f7fa3c | 2012-06-25 11:06:54 -0300 | [diff] [blame^] | 96 | int on = v4l2_ctrl_g_ctrl(isa->mute) ? 0 : 8; |
| 97 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Mauro Carvalho Chehab | 8f7fa3c | 2012-06-25 11:06:54 -0300 | [diff] [blame^] | 99 | freq += 171200; /* Add 10.7 MHz IF */ |
| 100 | freq /= 800; /* Convert to 50 kHz units */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 101 | |
Mauro Carvalho Chehab | 8f7fa3c | 2012-06-25 11:06:54 -0300 | [diff] [blame^] | 102 | send_0_byte(isa, on); /* 0: LSB of frequency */ |
| 103 | |
| 104 | for (i = 0; i < 13; i++) /* : frequency bits (1-13) */ |
| 105 | if (freq & (1 << i)) |
| 106 | send_1_byte(isa, on); |
| 107 | else |
| 108 | send_0_byte(isa, on); |
| 109 | |
| 110 | send_0_byte(isa, on); /* 14: test bit - always 0 */ |
| 111 | send_0_byte(isa, on); /* 15: test bit - always 0 */ |
| 112 | |
| 113 | send_0_byte(isa, on); /* 16: band data 0 - always 0 */ |
| 114 | send_0_byte(isa, on); /* 17: band data 1 - always 0 */ |
| 115 | send_0_byte(isa, on); /* 18: band data 2 - always 0 */ |
| 116 | send_0_byte(isa, on); /* 19: time base - always 0 */ |
| 117 | |
| 118 | send_0_byte(isa, on); /* 20: spacing (0 = 25 kHz) */ |
| 119 | send_1_byte(isa, on); /* 21: spacing (1 = 25 kHz) */ |
| 120 | send_0_byte(isa, on); /* 22: spacing (0 = 25 kHz) */ |
| 121 | send_1_byte(isa, on); /* 23: AM/FM (FM = 1, always) */ |
| 122 | |
| 123 | outb(0xd0 + on, isa->io); /* volume steady + sigstr */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | return 0; |
| 125 | } |
| 126 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 127 | static u32 rtrack_g_signal(struct radio_isa_card *isa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 129 | /* bit set = no signal present */ |
| 130 | return 0xffff * !(inb(isa->io) & 2); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 131 | } |
Mauro Carvalho Chehab | 46ff2c7 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 132 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 133 | static int rtrack_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 135 | struct rtrack *rt = container_of(isa, struct rtrack, isa); |
| 136 | int curvol = rt->curvol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 138 | if (mute) { |
| 139 | outb(0xd0, isa->io); /* volume steady + sigstr + off */ |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 140 | return 0; |
| 141 | } |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 142 | if (vol == 0) { /* volume = 0 means mute the card */ |
| 143 | outb(0x48, isa->io); /* volume down but still "on" */ |
| 144 | msleep(curvol * 3); /* make sure it's totally down */ |
| 145 | } else if (curvol < vol) { |
| 146 | outb(0x98, isa->io); /* volume up + sigstr + on */ |
| 147 | for (; curvol < vol; curvol++) |
| 148 | udelay(3000); |
| 149 | } else if (curvol > vol) { |
| 150 | outb(0x58, isa->io); /* volume down + sigstr + on */ |
| 151 | for (; curvol > vol; curvol--) |
| 152 | udelay(3000); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 153 | } |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 154 | outb(0xd8, isa->io); /* volume steady + sigstr + on */ |
| 155 | rt->curvol = vol; |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 156 | return 0; |
| 157 | } |
| 158 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 159 | /* Mute card - prevents noisy bootups */ |
| 160 | static int rtrack_initialize(struct radio_isa_card *isa) |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 161 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 162 | /* this ensures that the volume is all the way up */ |
| 163 | outb(0x90, isa->io); /* volume up but still "on" */ |
| 164 | msleep(3000); /* make sure it's totally up */ |
| 165 | outb(0xc0, isa->io); /* steady volume, mute card */ |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 166 | return 0; |
| 167 | } |
| 168 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 169 | static const struct radio_isa_ops rtrack_ops = { |
| 170 | .alloc = rtrack_alloc, |
| 171 | .init = rtrack_initialize, |
| 172 | .s_mute_volume = rtrack_s_mute_volume, |
| 173 | .s_frequency = rtrack_s_frequency, |
| 174 | .g_signal = rtrack_g_signal, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | }; |
| 176 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 177 | static const int rtrack_ioports[] = { 0x20f, 0x30f }; |
| 178 | |
| 179 | static struct radio_isa_driver rtrack_driver = { |
| 180 | .driver = { |
| 181 | .match = radio_isa_match, |
| 182 | .probe = radio_isa_probe, |
| 183 | .remove = radio_isa_remove, |
| 184 | .driver = { |
| 185 | .name = "radio-aimslab", |
| 186 | }, |
| 187 | }, |
| 188 | .io_params = io, |
| 189 | .radio_nr_params = radio_nr, |
| 190 | .io_ports = rtrack_ioports, |
| 191 | .num_of_io_ports = ARRAY_SIZE(rtrack_ioports), |
| 192 | .region_size = 2, |
| 193 | .card = "AIMSlab RadioTrack/RadioReveal", |
| 194 | .ops = &rtrack_ops, |
| 195 | .has_stereo = true, |
| 196 | .max_volume = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | static int __init rtrack_init(void) |
| 200 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 201 | return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 204 | static void __exit rtrack_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 206 | isa_unregister_driver(&rtrack_driver.driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | module_init(rtrack_init); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 210 | module_exit(rtrack_exit); |