Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 1 | /* |
| 2 | * GemTek radio card driver |
| 3 | * |
| 4 | * Copyright 1998 Jonas Munsin <jmunsin@iki.fi> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * GemTek hasn't released any specs on the card, so the protocol had to |
| 7 | * be reverse engineered with dosemu. |
| 8 | * |
| 9 | * Besides the protocol changes, this is mostly a copy of: |
| 10 | * |
| 11 | * RadioTrack II driver for Linux radio support (C) 1998 Ben Pfaff |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood |
Alan Cox | d9b0144 | 2008-10-27 15:13:47 -0300 | [diff] [blame] | 14 | * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org> |
| 16 | * |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 17 | * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com> |
Mauro Carvalho Chehab | d1c4ecd | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 18 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 19 | * |
| 20 | * Note: this card seems to swap the left and right audio channels! |
| 21 | * |
| 22 | * 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] | 23 | */ |
| 24 | |
| 25 | #include <linux/module.h> /* Modules */ |
| 26 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 27 | #include <linux/ioport.h> /* request_region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/delay.h> /* udelay */ |
Mauro Carvalho Chehab | d1c4ecd | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 29 | #include <linux/videodev2.h> /* kernel radio structs */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 30 | #include <linux/mutex.h> |
| 31 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | 9f1dfcc | 2012-02-29 05:50:27 -0300 | [diff] [blame^] | 32 | #include <linux/slab.h> |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 33 | #include <media/v4l2-ioctl.h> |
| 34 | #include <media/v4l2-device.h> |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 35 | #include "radio-isa.h" |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 36 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 37 | /* |
| 38 | * Module info. |
| 39 | */ |
| 40 | |
Mauro Carvalho Chehab | 29834c1 | 2011-06-25 10:15:42 -0300 | [diff] [blame] | 41 | MODULE_AUTHOR("Jonas Munsin, Pekka Seppänen <pexu@kapsi.fi>"); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 42 | MODULE_DESCRIPTION("A driver for the GemTek Radio card."); |
| 43 | MODULE_LICENSE("GPL"); |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 44 | MODULE_VERSION("1.0.0"); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * Module params. |
| 48 | */ |
Mauro Carvalho Chehab | d1c4ecd | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #ifndef CONFIG_RADIO_GEMTEK_PORT |
| 51 | #define CONFIG_RADIO_GEMTEK_PORT -1 |
| 52 | #endif |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 53 | #ifndef CONFIG_RADIO_GEMTEK_PROBE |
| 54 | #define CONFIG_RADIO_GEMTEK_PROBE 1 |
| 55 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 57 | #define GEMTEK_MAX 4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 59 | static bool probe = CONFIG_RADIO_GEMTEK_PROBE; |
| 60 | static bool hardmute; |
| 61 | static int io[GEMTEK_MAX] = { [0] = CONFIG_RADIO_GEMTEK_PORT, |
| 62 | [1 ... (GEMTEK_MAX - 1)] = -1 }; |
| 63 | static int radio_nr[GEMTEK_MAX] = { [0 ... (GEMTEK_MAX - 1)] = -1 }; |
| 64 | |
| 65 | module_param(probe, bool, 0444); |
| 66 | MODULE_PARM_DESC(probe, "Enable automatic device probing."); |
| 67 | |
| 68 | module_param(hardmute, bool, 0644); |
| 69 | MODULE_PARM_DESC(hardmute, "Enable 'hard muting' by shutting down PLL, may " |
| 70 | "reduce static noise."); |
| 71 | |
| 72 | module_param_array(io, int, NULL, 0444); |
| 73 | MODULE_PARM_DESC(io, "Force I/O ports for the GemTek Radio card if automatic " |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 74 | "probing is disabled or fails. The most common I/O ports are: 0x20c " |
| 75 | "0x30c, 0x24c or 0x34c (0x20c, 0x248 and 0x28c have been reported to " |
Joe Perches | 13d9701 | 2007-11-19 22:48:16 -0300 | [diff] [blame] | 76 | "work for the combined sound/radiocard)."); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 77 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 78 | module_param_array(radio_nr, int, NULL, 0444); |
| 79 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 80 | |
Trent Piepho | 857e594 | 2007-10-01 00:32:25 -0300 | [diff] [blame] | 81 | /* |
| 82 | * Frequency calculation constants. Intermediate frequency 10.52 MHz (nominal |
| 83 | * value 10.7 MHz), reference divisor 6.39 kHz (nominal 6.25 kHz). |
| 84 | */ |
| 85 | #define FSCALE 8 |
| 86 | #define IF_OFFSET ((unsigned int)(10.52 * 16000 * (1<<FSCALE))) |
| 87 | #define REF_FREQ ((unsigned int)(6.39 * 16 * (1<<FSCALE))) |
| 88 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 89 | #define GEMTEK_CK 0x01 /* Clock signal */ |
| 90 | #define GEMTEK_DA 0x02 /* Serial data */ |
| 91 | #define GEMTEK_CE 0x04 /* Chip enable */ |
| 92 | #define GEMTEK_NS 0x08 /* No signal */ |
| 93 | #define GEMTEK_MT 0x10 /* Line mute */ |
| 94 | #define GEMTEK_STDF_3_125_KHZ 0x01 /* Standard frequency 3.125 kHz */ |
| 95 | #define GEMTEK_PLL_OFF 0x07 /* PLL off */ |
| 96 | |
| 97 | #define BU2614_BUS_SIZE 32 /* BU2614 / BU2614FS bus size */ |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 98 | |
| 99 | #define SHORT_DELAY 5 /* usec */ |
| 100 | #define LONG_DELAY 75 /* usec */ |
| 101 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 102 | struct gemtek { |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 103 | struct radio_isa_card isa; |
| 104 | bool muted; |
Trent Piepho | b25be97 | 2007-10-01 00:38:30 -0300 | [diff] [blame] | 105 | u32 bu2614data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Trent Piepho | b25be97 | 2007-10-01 00:38:30 -0300 | [diff] [blame] | 108 | #define BU2614_FREQ_BITS 16 /* D0..D15, Frequency data */ |
| 109 | #define BU2614_PORT_BITS 3 /* P0..P2, Output port control data */ |
| 110 | #define BU2614_VOID_BITS 4 /* unused */ |
| 111 | #define BU2614_FMES_BITS 1 /* CT, Frequency measurement beginning data */ |
| 112 | #define BU2614_STDF_BITS 3 /* R0..R2, Standard frequency data */ |
| 113 | #define BU2614_SWIN_BITS 1 /* S, Switch between FMIN / AMIN */ |
| 114 | #define BU2614_SWAL_BITS 1 /* PS, Swallow counter division (AMIN only)*/ |
| 115 | #define BU2614_VOID2_BITS 1 /* unused */ |
| 116 | #define BU2614_FMUN_BITS 1 /* GT, Frequency measurement time & unlock */ |
| 117 | #define BU2614_TEST_BITS 1 /* TS, Test data is input */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Trent Piepho | b25be97 | 2007-10-01 00:38:30 -0300 | [diff] [blame] | 119 | #define BU2614_FREQ_SHIFT 0 |
| 120 | #define BU2614_PORT_SHIFT (BU2614_FREQ_BITS + BU2614_FREQ_SHIFT) |
| 121 | #define BU2614_VOID_SHIFT (BU2614_PORT_BITS + BU2614_PORT_SHIFT) |
| 122 | #define BU2614_FMES_SHIFT (BU2614_VOID_BITS + BU2614_VOID_SHIFT) |
| 123 | #define BU2614_STDF_SHIFT (BU2614_FMES_BITS + BU2614_FMES_SHIFT) |
| 124 | #define BU2614_SWIN_SHIFT (BU2614_STDF_BITS + BU2614_STDF_SHIFT) |
| 125 | #define BU2614_SWAL_SHIFT (BU2614_SWIN_BITS + BU2614_SWIN_SHIFT) |
| 126 | #define BU2614_VOID2_SHIFT (BU2614_SWAL_BITS + BU2614_SWAL_SHIFT) |
| 127 | #define BU2614_FMUN_SHIFT (BU2614_VOID2_BITS + BU2614_VOID2_SHIFT) |
| 128 | #define BU2614_TEST_SHIFT (BU2614_FMUN_BITS + BU2614_FMUN_SHIFT) |
| 129 | |
| 130 | #define MKMASK(field) (((1<<BU2614_##field##_BITS) - 1) << \ |
| 131 | BU2614_##field##_SHIFT) |
| 132 | #define BU2614_PORT_MASK MKMASK(PORT) |
| 133 | #define BU2614_FREQ_MASK MKMASK(FREQ) |
| 134 | #define BU2614_VOID_MASK MKMASK(VOID) |
| 135 | #define BU2614_FMES_MASK MKMASK(FMES) |
| 136 | #define BU2614_STDF_MASK MKMASK(STDF) |
| 137 | #define BU2614_SWIN_MASK MKMASK(SWIN) |
| 138 | #define BU2614_SWAL_MASK MKMASK(SWAL) |
| 139 | #define BU2614_VOID2_MASK MKMASK(VOID2) |
| 140 | #define BU2614_FMUN_MASK MKMASK(FMUN) |
| 141 | #define BU2614_TEST_MASK MKMASK(TEST) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 143 | /* |
| 144 | * Set data which will be sent to BU2614FS. |
| 145 | */ |
Trent Piepho | b25be97 | 2007-10-01 00:38:30 -0300 | [diff] [blame] | 146 | #define gemtek_bu2614_set(dev, field, data) ((dev)->bu2614data = \ |
| 147 | ((dev)->bu2614data & ~field##_MASK) | ((data) << field##_SHIFT)) |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 148 | |
| 149 | /* |
| 150 | * Transmit settings to BU2614FS over GemTek IC. |
| 151 | */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 152 | static void gemtek_bu2614_transmit(struct gemtek *gt) |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 153 | { |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 154 | struct radio_isa_card *isa = >->isa; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 155 | int i, bit, q, mute; |
| 156 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 157 | mute = gt->muted ? GEMTEK_MT : 0x00; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 158 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 159 | outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, isa->io); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 160 | udelay(LONG_DELAY); |
| 161 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 162 | for (i = 0, q = gt->bu2614data; i < 32; i++, q >>= 1) { |
| 163 | bit = (q & 1) ? GEMTEK_DA : 0; |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 164 | outb_p(mute | GEMTEK_CE | bit, isa->io); |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 165 | udelay(SHORT_DELAY); |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 166 | outb_p(mute | GEMTEK_CE | bit | GEMTEK_CK, isa->io); |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 167 | udelay(SHORT_DELAY); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 168 | } |
| 169 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 170 | outb_p(mute | GEMTEK_DA | GEMTEK_CK, isa->io); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 171 | udelay(SHORT_DELAY); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /* |
Trent Piepho | 857e594 | 2007-10-01 00:32:25 -0300 | [diff] [blame] | 175 | * Calculate divisor from FM-frequency for BU2614FS (3.125 KHz STDF expected). |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 176 | */ |
Trent Piepho | 857e594 | 2007-10-01 00:32:25 -0300 | [diff] [blame] | 177 | static unsigned long gemtek_convfreq(unsigned long freq) |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 178 | { |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 179 | return ((freq << FSCALE) + IF_OFFSET + REF_FREQ / 2) / REF_FREQ; |
| 180 | } |
| 181 | |
| 182 | static struct radio_isa_card *gemtek_alloc(void) |
| 183 | { |
| 184 | struct gemtek *gt = kzalloc(sizeof(*gt), GFP_KERNEL); |
| 185 | |
| 186 | if (gt) |
| 187 | gt->muted = true; |
| 188 | return gt ? >->isa : NULL; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /* |
| 192 | * Set FM-frequency. |
| 193 | */ |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 194 | static int gemtek_s_frequency(struct radio_isa_card *isa, u32 freq) |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 195 | { |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 196 | struct gemtek *gt = container_of(isa, struct gemtek, isa); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 197 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 198 | if (hardmute && gt->muted) |
| 199 | return 0; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 200 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 201 | gemtek_bu2614_set(gt, BU2614_PORT, 0); |
| 202 | gemtek_bu2614_set(gt, BU2614_FMES, 0); |
| 203 | gemtek_bu2614_set(gt, BU2614_SWIN, 0); /* FM-mode */ |
| 204 | gemtek_bu2614_set(gt, BU2614_SWAL, 0); |
| 205 | gemtek_bu2614_set(gt, BU2614_FMUN, 1); /* GT bit set */ |
| 206 | gemtek_bu2614_set(gt, BU2614_TEST, 0); |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 207 | gemtek_bu2614_set(gt, BU2614_STDF, GEMTEK_STDF_3_125_KHZ); |
| 208 | gemtek_bu2614_set(gt, BU2614_FREQ, gemtek_convfreq(freq)); |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 209 | gemtek_bu2614_transmit(gt); |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 210 | return 0; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /* |
| 214 | * Set mute flag. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | */ |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 216 | static int gemtek_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 218 | struct gemtek *gt = container_of(isa, struct gemtek, isa); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 219 | int i; |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 220 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 221 | gt->muted = mute; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 222 | if (hardmute) { |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 223 | if (!mute) |
| 224 | return gemtek_s_frequency(isa, isa->freq); |
| 225 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 226 | /* Turn off PLL, disable data output */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 227 | gemtek_bu2614_set(gt, BU2614_PORT, 0); |
| 228 | gemtek_bu2614_set(gt, BU2614_FMES, 0); /* CT bit off */ |
| 229 | gemtek_bu2614_set(gt, BU2614_SWIN, 0); /* FM-mode */ |
| 230 | gemtek_bu2614_set(gt, BU2614_SWAL, 0); |
| 231 | gemtek_bu2614_set(gt, BU2614_FMUN, 0); /* GT bit off */ |
| 232 | gemtek_bu2614_set(gt, BU2614_TEST, 0); |
| 233 | gemtek_bu2614_set(gt, BU2614_STDF, GEMTEK_PLL_OFF); |
| 234 | gemtek_bu2614_set(gt, BU2614_FREQ, 0); |
| 235 | gemtek_bu2614_transmit(gt); |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 236 | return 0; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 237 | } |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 238 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 239 | /* Read bus contents (CE, CK and DA). */ |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 240 | i = inb_p(isa->io); |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 241 | /* Write it back with mute flag set. */ |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 242 | outb_p((i >> 5) | (mute ? GEMTEK_MT : 0), isa->io); |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 243 | udelay(SHORT_DELAY); |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 244 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 247 | static u32 gemtek_g_rxsubchans(struct radio_isa_card *isa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 249 | if (inb_p(isa->io) & GEMTEK_NS) |
| 250 | return V4L2_TUNER_SUB_MONO; |
| 251 | return V4L2_TUNER_SUB_STEREO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 254 | /* |
| 255 | * Check if requested card acts like GemTek Radio card. |
| 256 | */ |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 257 | static bool gemtek_probe(struct radio_isa_card *isa, int io) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 259 | int i, q; |
| 260 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 261 | q = inb_p(io); /* Read bus contents before probing. */ |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 262 | /* Try to turn on CE, CK and DA respectively and check if card responds |
| 263 | properly. */ |
| 264 | for (i = 0; i < 3; ++i) { |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 265 | outb_p(1 << i, io); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 266 | udelay(SHORT_DELAY); |
| 267 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 268 | if ((inb_p(io) & ~GEMTEK_NS) != (0x17 | (1 << (i + 5)))) |
| 269 | return false; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 270 | } |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 271 | outb_p(q >> 5, io); /* Write bus contents back. */ |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 272 | udelay(SHORT_DELAY); |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 273 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 276 | static const struct radio_isa_ops gemtek_ops = { |
| 277 | .alloc = gemtek_alloc, |
| 278 | .probe = gemtek_probe, |
| 279 | .s_mute_volume = gemtek_s_mute_volume, |
| 280 | .s_frequency = gemtek_s_frequency, |
| 281 | .g_rxsubchans = gemtek_g_rxsubchans, |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 282 | }; |
| 283 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 284 | static const int gemtek_ioports[] = { 0x20c, 0x30c, 0x24c, 0x34c, 0x248, 0x28c }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 286 | static struct radio_isa_driver gemtek_driver = { |
| 287 | .driver = { |
| 288 | .match = radio_isa_match, |
| 289 | .probe = radio_isa_probe, |
| 290 | .remove = radio_isa_remove, |
| 291 | .driver = { |
| 292 | .name = "radio-gemtek", |
| 293 | }, |
| 294 | }, |
| 295 | .io_params = io, |
| 296 | .radio_nr_params = radio_nr, |
| 297 | .io_ports = gemtek_ioports, |
| 298 | .num_of_io_ports = ARRAY_SIZE(gemtek_ioports), |
| 299 | .region_size = 1, |
| 300 | .card = "GemTek Radio", |
| 301 | .ops = &gemtek_ops, |
| 302 | .has_stereo = true, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | }; |
| 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | static int __init gemtek_init(void) |
| 306 | { |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 307 | gemtek_driver.probe = probe; |
| 308 | return isa_register_driver(&gemtek_driver.driver, GEMTEK_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 311 | static void __exit gemtek_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
Hans Verkuil | f8c0852 | 2012-01-16 05:00:26 -0300 | [diff] [blame] | 313 | hardmute = 1; /* Turn off PLL */ |
| 314 | isa_unregister_driver(&gemtek_driver.driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | module_init(gemtek_init); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 318 | module_exit(gemtek_exit); |