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" |
Ondrej Zary | bece083 | 2012-06-12 14:38:00 -0300 | [diff] [blame] | 40 | #include "lm7000.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 42 | MODULE_AUTHOR("M. Kirkwood"); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 43 | MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card."); |
| 44 | MODULE_LICENSE("GPL"); |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 45 | MODULE_VERSION("1.0.0"); |
Mauro Carvalho Chehab | 46ff2c7 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #ifndef CONFIG_RADIO_RTRACK_PORT |
| 48 | #define CONFIG_RADIO_RTRACK_PORT -1 |
| 49 | #endif |
| 50 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 51 | #define RTRACK_MAX 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 53 | static int io[RTRACK_MAX] = { [0] = CONFIG_RADIO_RTRACK_PORT, |
| 54 | [1 ... (RTRACK_MAX - 1)] = -1 }; |
| 55 | static int radio_nr[RTRACK_MAX] = { [0 ... (RTRACK_MAX - 1)] = -1 }; |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 56 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 57 | module_param_array(io, int, NULL, 0444); |
| 58 | MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)"); |
| 59 | module_param_array(radio_nr, int, NULL, 0444); |
| 60 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); |
| 61 | |
| 62 | struct rtrack { |
| 63 | struct radio_isa_card isa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | int curvol; |
Ondrej Zary | bece083 | 2012-06-12 14:38:00 -0300 | [diff] [blame] | 65 | struct lm7000 lm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Ondrej Zary | bece083 | 2012-06-12 14:38:00 -0300 | [diff] [blame] | 68 | #define AIMS_BIT_TUN_CE (1 << 0) |
| 69 | #define AIMS_BIT_TUN_CLK (1 << 1) |
| 70 | #define AIMS_BIT_TUN_DATA (1 << 2) |
| 71 | #define AIMS_BIT_VOL_CE (1 << 3) |
| 72 | #define AIMS_BIT_TUN_STRQ (1 << 4) |
| 73 | /* bit 5 is not connected */ |
| 74 | #define AIMS_BIT_VOL_UP (1 << 6) /* active low */ |
| 75 | #define AIMS_BIT_VOL_DN (1 << 7) /* active low */ |
| 76 | |
| 77 | void rtrack_set_pins(struct lm7000 *lm, u8 pins) |
| 78 | { |
| 79 | struct rtrack *rt = container_of(lm, struct rtrack, lm); |
| 80 | u8 bits = AIMS_BIT_VOL_DN | AIMS_BIT_VOL_UP | AIMS_BIT_TUN_STRQ; |
| 81 | |
| 82 | if (!v4l2_ctrl_g_ctrl(rt->isa.mute)) |
| 83 | bits |= AIMS_BIT_VOL_CE; |
| 84 | |
| 85 | if (pins & LM7000_DATA) |
| 86 | bits |= AIMS_BIT_TUN_DATA; |
| 87 | if (pins & LM7000_CLK) |
| 88 | bits |= AIMS_BIT_TUN_CLK; |
| 89 | if (pins & LM7000_CE) |
| 90 | bits |= AIMS_BIT_TUN_CE; |
| 91 | |
| 92 | outb_p(bits, rt->isa.io); |
| 93 | } |
| 94 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 95 | static struct radio_isa_card *rtrack_alloc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 97 | struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL); |
| 98 | |
Ondrej Zary | bece083 | 2012-06-12 14:38:00 -0300 | [diff] [blame] | 99 | if (rt) { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 100 | rt->curvol = 0xff; |
Ondrej Zary | bece083 | 2012-06-12 14:38:00 -0300 | [diff] [blame] | 101 | rt->lm.set_pins = rtrack_set_pins; |
| 102 | } |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 103 | return rt ? &rt->isa : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 106 | static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Ondrej Zary | bece083 | 2012-06-12 14:38:00 -0300 | [diff] [blame] | 108 | struct rtrack *rt = container_of(isa, struct rtrack, isa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Ondrej Zary | bece083 | 2012-06-12 14:38:00 -0300 | [diff] [blame] | 110 | lm7000_set_freq(&rt->lm, freq); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | return 0; |
| 113 | } |
| 114 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 115 | static u32 rtrack_g_signal(struct radio_isa_card *isa) |
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 | /* bit set = no signal present */ |
| 118 | return 0xffff * !(inb(isa->io) & 2); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 119 | } |
Mauro Carvalho Chehab | 46ff2c7 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 120 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 121 | 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] | 122 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 123 | struct rtrack *rt = container_of(isa, struct rtrack, isa); |
| 124 | int curvol = rt->curvol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 126 | if (mute) { |
| 127 | outb(0xd0, isa->io); /* volume steady + sigstr + off */ |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 128 | return 0; |
| 129 | } |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 130 | if (vol == 0) { /* volume = 0 means mute the card */ |
| 131 | outb(0x48, isa->io); /* volume down but still "on" */ |
| 132 | msleep(curvol * 3); /* make sure it's totally down */ |
| 133 | } else if (curvol < vol) { |
| 134 | outb(0x98, isa->io); /* volume up + sigstr + on */ |
| 135 | for (; curvol < vol; curvol++) |
| 136 | udelay(3000); |
| 137 | } else if (curvol > vol) { |
| 138 | outb(0x58, isa->io); /* volume down + sigstr + on */ |
| 139 | for (; curvol > vol; curvol--) |
| 140 | udelay(3000); |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 141 | } |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 142 | outb(0xd8, isa->io); /* volume steady + sigstr + on */ |
| 143 | rt->curvol = vol; |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 144 | return 0; |
| 145 | } |
| 146 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 147 | /* Mute card - prevents noisy bootups */ |
| 148 | static int rtrack_initialize(struct radio_isa_card *isa) |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 149 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 150 | /* this ensures that the volume is all the way up */ |
| 151 | outb(0x90, isa->io); /* volume up but still "on" */ |
| 152 | msleep(3000); /* make sure it's totally up */ |
| 153 | outb(0xc0, isa->io); /* steady volume, mute card */ |
Douglas Landgraf | 385e8d8 | 2007-04-25 00:14:36 -0300 | [diff] [blame] | 154 | return 0; |
| 155 | } |
| 156 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 157 | static const struct radio_isa_ops rtrack_ops = { |
| 158 | .alloc = rtrack_alloc, |
| 159 | .init = rtrack_initialize, |
| 160 | .s_mute_volume = rtrack_s_mute_volume, |
| 161 | .s_frequency = rtrack_s_frequency, |
| 162 | .g_signal = rtrack_g_signal, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | }; |
| 164 | |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 165 | static const int rtrack_ioports[] = { 0x20f, 0x30f }; |
| 166 | |
| 167 | static struct radio_isa_driver rtrack_driver = { |
| 168 | .driver = { |
| 169 | .match = radio_isa_match, |
| 170 | .probe = radio_isa_probe, |
| 171 | .remove = radio_isa_remove, |
| 172 | .driver = { |
| 173 | .name = "radio-aimslab", |
| 174 | }, |
| 175 | }, |
| 176 | .io_params = io, |
| 177 | .radio_nr_params = radio_nr, |
| 178 | .io_ports = rtrack_ioports, |
| 179 | .num_of_io_ports = ARRAY_SIZE(rtrack_ioports), |
| 180 | .region_size = 2, |
| 181 | .card = "AIMSlab RadioTrack/RadioReveal", |
| 182 | .ops = &rtrack_ops, |
| 183 | .has_stereo = true, |
| 184 | .max_volume = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | static int __init rtrack_init(void) |
| 188 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 189 | return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 192 | static void __exit rtrack_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
Hans Verkuil | cc3c6df | 2012-01-16 04:55:10 -0300 | [diff] [blame] | 194 | isa_unregister_driver(&rtrack_driver.driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | module_init(rtrack_init); |
Hans Verkuil | 151c3f8 | 2009-03-06 13:45:27 -0300 | [diff] [blame] | 198 | module_exit(rtrack_exit); |