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 | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 35 | #include <media/v4l2-device.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 36 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 37 | #include <media/v4l2-ctrls.h> |
| 38 | #include "radio-isa.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 40 | MODULE_AUTHOR("M. Kirkwood"); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 41 | MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card."); |
| 42 | MODULE_LICENSE("GPL"); |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 43 | MODULE_VERSION("1.0.0"); |
Mauro Carvalho Chehab | 46ff2c7 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #ifndef CONFIG_RADIO_RTRACK_PORT |
| 46 | #define CONFIG_RADIO_RTRACK_PORT -1 |
| 47 | #endif |
| 48 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 49 | #define RTRACK_MAX 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 51 | static int io[RTRACK_MAX] = { [0] = CONFIG_RADIO_RTRACK_PORT, |
| 52 | [1 ... (RTRACK_MAX - 1)] = -1 }; |
| 53 | static int radio_nr[RTRACK_MAX] = { [0 ... (RTRACK_MAX - 1)] = -1 }; |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 54 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 55 | module_param_array(io, int, NULL, 0444); |
| 56 | MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)"); |
| 57 | module_param_array(radio_nr, int, NULL, 0444); |
| 58 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); |
| 59 | |
| 60 | struct rtrack { |
| 61 | struct radio_isa_card isa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | int curvol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 65 | static struct radio_isa_card *rtrack_alloc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 67 | struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL); |
| 68 | |
| 69 | if (rt) |
| 70 | rt->curvol = 0xff; |
| 71 | return rt ? &rt->isa : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 74 | /* The 128+64 on these outb's is to keep the volume stable while tuning. |
| 75 | * Without them, the volume _will_ creep up with each frequency change |
| 76 | * and bit 4 (+16) is to keep the signal strength meter enabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | */ |
| 78 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 79 | static void send_0_byte(struct radio_isa_card *isa, int on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 81 | outb_p(128+64+16+on+1, isa->io); /* wr-enable + data low */ |
| 82 | outb_p(128+64+16+on+2+1, isa->io); /* clock */ |
Mauro Carvalho Chehab | e3c9221 | 2011-01-06 08:16:04 -0200 | [diff] [blame] | 83 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 86 | static void send_1_byte(struct radio_isa_card *isa, int on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 88 | outb_p(128+64+16+on+4+1, isa->io); /* wr-enable+data high */ |
| 89 | outb_p(128+64+16+on+4+2+1, isa->io); /* clock */ |
Mauro Carvalho Chehab | e3c9221 | 2011-01-06 08:16:04 -0200 | [diff] [blame] | 90 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 93 | static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 95 | int on = v4l2_ctrl_g_ctrl(isa->mute) ? 0 : 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | int i; |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | freq += 171200; /* Add 10.7 MHz IF */ |
| 99 | freq /= 800; /* Convert to 50 kHz units */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 100 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 101 | send_0_byte(isa, on); /* 0: LSB of frequency */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | for (i = 0; i < 13; i++) /* : frequency bits (1-13) */ |
| 104 | if (freq & (1 << i)) |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 105 | send_1_byte(isa, on); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | else |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 107 | send_0_byte(isa, on); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 109 | send_0_byte(isa, on); /* 14: test bit - always 0 */ |
| 110 | send_0_byte(isa, on); /* 15: test bit - always 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 112 | send_0_byte(isa, on); /* 16: band data 0 - always 0 */ |
| 113 | send_0_byte(isa, on); /* 17: band data 1 - always 0 */ |
| 114 | send_0_byte(isa, on); /* 18: band data 2 - always 0 */ |
| 115 | send_0_byte(isa, on); /* 19: time base - always 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 117 | send_0_byte(isa, on); /* 20: spacing (0 = 25 kHz) */ |
| 118 | send_1_byte(isa, on); /* 21: spacing (1 = 25 kHz) */ |
| 119 | send_0_byte(isa, on); /* 22: spacing (0 = 25 kHz) */ |
| 120 | send_1_byte(isa, on); /* 23: AM/FM (FM = 1, always) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 122 | outb(0xd0 + on, isa->io); /* volume steady + sigstr */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 126 | static u32 rtrack_g_signal(struct radio_isa_card *isa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 128 | /* bit set = no signal present */ |
| 129 | return 0xffff * !(inb(isa->io) & 2); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 130 | } |
Mauro Carvalho Chehab | 46ff2c7 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 131 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 132 | 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] | 133 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 134 | struct rtrack *rt = container_of(isa, struct rtrack, isa); |
| 135 | int curvol = rt->curvol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 137 | if (mute) { |
| 138 | outb(0xd0, isa->io); /* volume steady + sigstr + off */ |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 139 | return 0; |
| 140 | } |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 141 | if (vol == 0) { /* volume = 0 means mute the card */ |
| 142 | outb(0x48, isa->io); /* volume down but still "on" */ |
| 143 | msleep(curvol * 3); /* make sure it's totally down */ |
| 144 | } else if (curvol < vol) { |
| 145 | outb(0x98, isa->io); /* volume up + sigstr + on */ |
| 146 | for (; curvol < vol; curvol++) |
| 147 | udelay(3000); |
| 148 | } else if (curvol > vol) { |
| 149 | outb(0x58, isa->io); /* volume down + sigstr + on */ |
| 150 | for (; curvol > vol; curvol--) |
| 151 | udelay(3000); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 152 | } |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 153 | outb(0xd8, isa->io); /* volume steady + sigstr + on */ |
| 154 | rt->curvol = vol; |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 158 | /* Mute card - prevents noisy bootups */ |
| 159 | static int rtrack_initialize(struct radio_isa_card *isa) |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 160 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 161 | /* this ensures that the volume is all the way up */ |
| 162 | outb(0x90, isa->io); /* volume up but still "on" */ |
| 163 | msleep(3000); /* make sure it's totally up */ |
| 164 | outb(0xc0, isa->io); /* steady volume, mute card */ |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 165 | return 0; |
| 166 | } |
| 167 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 168 | static const struct radio_isa_ops rtrack_ops = { |
| 169 | .alloc = rtrack_alloc, |
| 170 | .init = rtrack_initialize, |
| 171 | .s_mute_volume = rtrack_s_mute_volume, |
| 172 | .s_frequency = rtrack_s_frequency, |
| 173 | .g_signal = rtrack_g_signal, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 176 | static const int rtrack_ioports[] = { 0x20f, 0x30f }; |
| 177 | |
| 178 | static struct radio_isa_driver rtrack_driver = { |
| 179 | .driver = { |
| 180 | .match = radio_isa_match, |
| 181 | .probe = radio_isa_probe, |
| 182 | .remove = radio_isa_remove, |
| 183 | .driver = { |
| 184 | .name = "radio-aimslab", |
| 185 | }, |
| 186 | }, |
| 187 | .io_params = io, |
| 188 | .radio_nr_params = radio_nr, |
| 189 | .io_ports = rtrack_ioports, |
| 190 | .num_of_io_ports = ARRAY_SIZE(rtrack_ioports), |
| 191 | .region_size = 2, |
| 192 | .card = "AIMSlab RadioTrack/RadioReveal", |
| 193 | .ops = &rtrack_ops, |
| 194 | .has_stereo = true, |
| 195 | .max_volume = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | static int __init rtrack_init(void) |
| 199 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 200 | return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 203 | static void __exit rtrack_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame^] | 205 | isa_unregister_driver(&rtrack_driver.driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | module_init(rtrack_init); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 209 | module_exit(rtrack_exit); |