Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* GemTek radio card driver for Linux (C) 1998 Jonas Munsin <jmunsin@iki.fi> |
| 2 | * |
| 3 | * GemTek hasn't released any specs on the card, so the protocol had to |
| 4 | * be reverse engineered with dosemu. |
| 5 | * |
| 6 | * Besides the protocol changes, this is mostly a copy of: |
| 7 | * |
| 8 | * RadioTrack II driver for Linux radio support (C) 1998 Ben Pfaff |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood |
Alan Cox | d9b0144 | 2008-10-27 15:13:47 -0300 | [diff] [blame] | 11 | * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org> |
| 13 | * |
| 14 | * TODO: Allow for more than one of these foolish entities :-) |
| 15 | * |
Mauro Carvalho Chehab | d1c4ecd | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 16 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <linux/module.h> /* Modules */ |
| 20 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 21 | #include <linux/ioport.h> /* request_region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/delay.h> /* udelay */ |
Mauro Carvalho Chehab | d1c4ecd | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 23 | #include <linux/videodev2.h> /* kernel radio structs */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 24 | #include <linux/mutex.h> |
| 25 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 26 | #include <media/v4l2-ioctl.h> |
| 27 | #include <media/v4l2-device.h> |
| 28 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 29 | /* |
| 30 | * Module info. |
| 31 | */ |
| 32 | |
Mauro Carvalho Chehab | 29834c1 | 2011-06-25 10:15:42 -0300 | [diff] [blame] | 33 | MODULE_AUTHOR("Jonas Munsin, Pekka Seppänen <pexu@kapsi.fi>"); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 34 | MODULE_DESCRIPTION("A driver for the GemTek Radio card."); |
| 35 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 29834c1 | 2011-06-25 10:15:42 -0300 | [diff] [blame] | 36 | MODULE_VERSION("0.0.4"); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * Module params. |
| 40 | */ |
Mauro Carvalho Chehab | d1c4ecd | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #ifndef CONFIG_RADIO_GEMTEK_PORT |
| 43 | #define CONFIG_RADIO_GEMTEK_PORT -1 |
| 44 | #endif |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 45 | #ifndef CONFIG_RADIO_GEMTEK_PROBE |
| 46 | #define CONFIG_RADIO_GEMTEK_PROBE 1 |
| 47 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 49 | static int io = CONFIG_RADIO_GEMTEK_PORT; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame^] | 50 | static bool probe = CONFIG_RADIO_GEMTEK_PROBE; |
| 51 | static bool hardmute; |
| 52 | static bool shutdown = 1; |
| 53 | static bool keepmuted = 1; |
| 54 | static bool initmute = 1; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 55 | static int radio_nr = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 57 | module_param(io, int, 0444); |
Joe Perches | 13d9701 | 2007-11-19 22:48:16 -0300 | [diff] [blame] | 58 | MODULE_PARM_DESC(io, "Force I/O port for the GemTek Radio card if automatic " |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 59 | "probing is disabled or fails. The most common I/O ports are: 0x20c " |
| 60 | "0x30c, 0x24c or 0x34c (0x20c, 0x248 and 0x28c have been reported to " |
Joe Perches | 13d9701 | 2007-11-19 22:48:16 -0300 | [diff] [blame] | 61 | "work for the combined sound/radiocard)."); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 62 | |
| 63 | module_param(probe, bool, 0444); |
| 64 | MODULE_PARM_DESC(probe, "Enable automatic device probing. Note: only the most " |
| 65 | "common I/O ports used by the card are probed."); |
| 66 | |
| 67 | module_param(hardmute, bool, 0644); |
| 68 | MODULE_PARM_DESC(hardmute, "Enable `hard muting' by shutting down PLL, may " |
| 69 | "reduce static noise."); |
| 70 | |
| 71 | module_param(shutdown, bool, 0644); |
| 72 | MODULE_PARM_DESC(shutdown, "Enable shutting down PLL and muting line when " |
| 73 | "module is unloaded."); |
| 74 | |
| 75 | module_param(keepmuted, bool, 0644); |
| 76 | MODULE_PARM_DESC(keepmuted, "Keep card muted even when frequency is changed."); |
| 77 | |
| 78 | module_param(initmute, bool, 0444); |
| 79 | MODULE_PARM_DESC(initmute, "Mute card when module is loaded."); |
| 80 | |
| 81 | module_param(radio_nr, int, 0444); |
| 82 | |
| 83 | /* |
| 84 | * Functions for controlling the card. |
| 85 | */ |
| 86 | #define GEMTEK_LOWFREQ (87*16000) |
| 87 | #define GEMTEK_HIGHFREQ (108*16000) |
| 88 | |
Trent Piepho | 857e594 | 2007-10-01 00:32:25 -0300 | [diff] [blame] | 89 | /* |
| 90 | * Frequency calculation constants. Intermediate frequency 10.52 MHz (nominal |
| 91 | * value 10.7 MHz), reference divisor 6.39 kHz (nominal 6.25 kHz). |
| 92 | */ |
| 93 | #define FSCALE 8 |
| 94 | #define IF_OFFSET ((unsigned int)(10.52 * 16000 * (1<<FSCALE))) |
| 95 | #define REF_FREQ ((unsigned int)(6.39 * 16 * (1<<FSCALE))) |
| 96 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 97 | #define GEMTEK_CK 0x01 /* Clock signal */ |
| 98 | #define GEMTEK_DA 0x02 /* Serial data */ |
| 99 | #define GEMTEK_CE 0x04 /* Chip enable */ |
| 100 | #define GEMTEK_NS 0x08 /* No signal */ |
| 101 | #define GEMTEK_MT 0x10 /* Line mute */ |
| 102 | #define GEMTEK_STDF_3_125_KHZ 0x01 /* Standard frequency 3.125 kHz */ |
| 103 | #define GEMTEK_PLL_OFF 0x07 /* PLL off */ |
| 104 | |
| 105 | #define BU2614_BUS_SIZE 32 /* BU2614 / BU2614FS bus size */ |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 106 | |
| 107 | #define SHORT_DELAY 5 /* usec */ |
| 108 | #define LONG_DELAY 75 /* usec */ |
| 109 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 110 | struct gemtek { |
| 111 | struct v4l2_device v4l2_dev; |
| 112 | struct video_device vdev; |
| 113 | struct mutex lock; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 114 | unsigned long lastfreq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | int muted; |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 116 | int verified; |
| 117 | int io; |
Trent Piepho | b25be97 | 2007-10-01 00:38:30 -0300 | [diff] [blame] | 118 | u32 bu2614data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 121 | static struct gemtek gemtek_card; |
| 122 | |
Trent Piepho | b25be97 | 2007-10-01 00:38:30 -0300 | [diff] [blame] | 123 | #define BU2614_FREQ_BITS 16 /* D0..D15, Frequency data */ |
| 124 | #define BU2614_PORT_BITS 3 /* P0..P2, Output port control data */ |
| 125 | #define BU2614_VOID_BITS 4 /* unused */ |
| 126 | #define BU2614_FMES_BITS 1 /* CT, Frequency measurement beginning data */ |
| 127 | #define BU2614_STDF_BITS 3 /* R0..R2, Standard frequency data */ |
| 128 | #define BU2614_SWIN_BITS 1 /* S, Switch between FMIN / AMIN */ |
| 129 | #define BU2614_SWAL_BITS 1 /* PS, Swallow counter division (AMIN only)*/ |
| 130 | #define BU2614_VOID2_BITS 1 /* unused */ |
| 131 | #define BU2614_FMUN_BITS 1 /* GT, Frequency measurement time & unlock */ |
| 132 | #define BU2614_TEST_BITS 1 /* TS, Test data is input */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Trent Piepho | b25be97 | 2007-10-01 00:38:30 -0300 | [diff] [blame] | 134 | #define BU2614_FREQ_SHIFT 0 |
| 135 | #define BU2614_PORT_SHIFT (BU2614_FREQ_BITS + BU2614_FREQ_SHIFT) |
| 136 | #define BU2614_VOID_SHIFT (BU2614_PORT_BITS + BU2614_PORT_SHIFT) |
| 137 | #define BU2614_FMES_SHIFT (BU2614_VOID_BITS + BU2614_VOID_SHIFT) |
| 138 | #define BU2614_STDF_SHIFT (BU2614_FMES_BITS + BU2614_FMES_SHIFT) |
| 139 | #define BU2614_SWIN_SHIFT (BU2614_STDF_BITS + BU2614_STDF_SHIFT) |
| 140 | #define BU2614_SWAL_SHIFT (BU2614_SWIN_BITS + BU2614_SWIN_SHIFT) |
| 141 | #define BU2614_VOID2_SHIFT (BU2614_SWAL_BITS + BU2614_SWAL_SHIFT) |
| 142 | #define BU2614_FMUN_SHIFT (BU2614_VOID2_BITS + BU2614_VOID2_SHIFT) |
| 143 | #define BU2614_TEST_SHIFT (BU2614_FMUN_BITS + BU2614_FMUN_SHIFT) |
| 144 | |
| 145 | #define MKMASK(field) (((1<<BU2614_##field##_BITS) - 1) << \ |
| 146 | BU2614_##field##_SHIFT) |
| 147 | #define BU2614_PORT_MASK MKMASK(PORT) |
| 148 | #define BU2614_FREQ_MASK MKMASK(FREQ) |
| 149 | #define BU2614_VOID_MASK MKMASK(VOID) |
| 150 | #define BU2614_FMES_MASK MKMASK(FMES) |
| 151 | #define BU2614_STDF_MASK MKMASK(STDF) |
| 152 | #define BU2614_SWIN_MASK MKMASK(SWIN) |
| 153 | #define BU2614_SWAL_MASK MKMASK(SWAL) |
| 154 | #define BU2614_VOID2_MASK MKMASK(VOID2) |
| 155 | #define BU2614_FMUN_MASK MKMASK(FMUN) |
| 156 | #define BU2614_TEST_MASK MKMASK(TEST) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 158 | /* |
| 159 | * Set data which will be sent to BU2614FS. |
| 160 | */ |
Trent Piepho | b25be97 | 2007-10-01 00:38:30 -0300 | [diff] [blame] | 161 | #define gemtek_bu2614_set(dev, field, data) ((dev)->bu2614data = \ |
| 162 | ((dev)->bu2614data & ~field##_MASK) | ((data) << field##_SHIFT)) |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 163 | |
| 164 | /* |
| 165 | * Transmit settings to BU2614FS over GemTek IC. |
| 166 | */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 167 | static void gemtek_bu2614_transmit(struct gemtek *gt) |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 168 | { |
| 169 | int i, bit, q, mute; |
| 170 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 171 | mutex_lock(>->lock); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 172 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 173 | mute = gt->muted ? GEMTEK_MT : 0x00; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 174 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 175 | outb_p(mute | GEMTEK_DA | GEMTEK_CK, gt->io); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 176 | udelay(SHORT_DELAY); |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 177 | outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, gt->io); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 178 | udelay(LONG_DELAY); |
| 179 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 180 | for (i = 0, q = gt->bu2614data; i < 32; i++, q >>= 1) { |
| 181 | bit = (q & 1) ? GEMTEK_DA : 0; |
| 182 | outb_p(mute | GEMTEK_CE | bit, gt->io); |
| 183 | udelay(SHORT_DELAY); |
| 184 | outb_p(mute | GEMTEK_CE | bit | GEMTEK_CK, gt->io); |
| 185 | udelay(SHORT_DELAY); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 186 | } |
| 187 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 188 | outb_p(mute | GEMTEK_DA | GEMTEK_CK, gt->io); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 189 | udelay(SHORT_DELAY); |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 190 | outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, gt->io); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 191 | udelay(LONG_DELAY); |
| 192 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 193 | mutex_unlock(>->lock); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* |
Trent Piepho | 857e594 | 2007-10-01 00:32:25 -0300 | [diff] [blame] | 197 | * Calculate divisor from FM-frequency for BU2614FS (3.125 KHz STDF expected). |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 198 | */ |
Trent Piepho | 857e594 | 2007-10-01 00:32:25 -0300 | [diff] [blame] | 199 | static unsigned long gemtek_convfreq(unsigned long freq) |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 200 | { |
Trent Piepho | 857e594 | 2007-10-01 00:32:25 -0300 | [diff] [blame] | 201 | return ((freq<<FSCALE) + IF_OFFSET + REF_FREQ/2) / REF_FREQ; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /* |
| 205 | * Set FM-frequency. |
| 206 | */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 207 | static void gemtek_setfreq(struct gemtek *gt, unsigned long freq) |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 208 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 209 | if (keepmuted && hardmute && gt->muted) |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 210 | return; |
| 211 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 212 | freq = clamp_val(freq, GEMTEK_LOWFREQ, GEMTEK_HIGHFREQ); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 213 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 214 | gt->lastfreq = freq; |
| 215 | gt->muted = 0; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 216 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 217 | gemtek_bu2614_set(gt, BU2614_PORT, 0); |
| 218 | gemtek_bu2614_set(gt, BU2614_FMES, 0); |
| 219 | gemtek_bu2614_set(gt, BU2614_SWIN, 0); /* FM-mode */ |
| 220 | gemtek_bu2614_set(gt, BU2614_SWAL, 0); |
| 221 | gemtek_bu2614_set(gt, BU2614_FMUN, 1); /* GT bit set */ |
| 222 | gemtek_bu2614_set(gt, BU2614_TEST, 0); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 223 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 224 | gemtek_bu2614_set(gt, BU2614_STDF, GEMTEK_STDF_3_125_KHZ); |
| 225 | gemtek_bu2614_set(gt, BU2614_FREQ, gemtek_convfreq(freq)); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 226 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 227 | gemtek_bu2614_transmit(gt); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /* |
| 231 | * Set mute flag. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 233 | static void gemtek_mute(struct gemtek *gt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 235 | int i; |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 236 | |
| 237 | gt->muted = 1; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 238 | |
| 239 | if (hardmute) { |
| 240 | /* Turn off PLL, disable data output */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 241 | gemtek_bu2614_set(gt, BU2614_PORT, 0); |
| 242 | gemtek_bu2614_set(gt, BU2614_FMES, 0); /* CT bit off */ |
| 243 | gemtek_bu2614_set(gt, BU2614_SWIN, 0); /* FM-mode */ |
| 244 | gemtek_bu2614_set(gt, BU2614_SWAL, 0); |
| 245 | gemtek_bu2614_set(gt, BU2614_FMUN, 0); /* GT bit off */ |
| 246 | gemtek_bu2614_set(gt, BU2614_TEST, 0); |
| 247 | gemtek_bu2614_set(gt, BU2614_STDF, GEMTEK_PLL_OFF); |
| 248 | gemtek_bu2614_set(gt, BU2614_FREQ, 0); |
| 249 | gemtek_bu2614_transmit(gt); |
| 250 | return; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 251 | } |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 252 | |
| 253 | mutex_lock(>->lock); |
| 254 | |
| 255 | /* Read bus contents (CE, CK and DA). */ |
| 256 | i = inb_p(gt->io); |
| 257 | /* Write it back with mute flag set. */ |
| 258 | outb_p((i >> 5) | GEMTEK_MT, gt->io); |
| 259 | udelay(SHORT_DELAY); |
| 260 | |
| 261 | mutex_unlock(>->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 264 | /* |
| 265 | * Unset mute flag. |
| 266 | */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 267 | static void gemtek_unmute(struct gemtek *gt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 269 | int i; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 270 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 271 | gt->muted = 0; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 272 | if (hardmute) { |
| 273 | /* Turn PLL back on. */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 274 | gemtek_setfreq(gt, gt->lastfreq); |
| 275 | return; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 276 | } |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 277 | mutex_lock(>->lock); |
| 278 | |
| 279 | i = inb_p(gt->io); |
| 280 | outb_p(i >> 5, gt->io); |
| 281 | udelay(SHORT_DELAY); |
| 282 | |
| 283 | mutex_unlock(>->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 286 | /* |
| 287 | * Get signal strength (= stereo status). |
| 288 | */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 289 | static inline int gemtek_getsigstr(struct gemtek *gt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 291 | int sig; |
| 292 | |
| 293 | mutex_lock(>->lock); |
| 294 | sig = inb_p(gt->io) & GEMTEK_NS ? 0 : 1; |
| 295 | mutex_unlock(>->lock); |
| 296 | return sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 299 | /* |
| 300 | * Check if requested card acts like GemTek Radio card. |
| 301 | */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 302 | static int gemtek_verify(struct gemtek *gt, int port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 304 | int i, q; |
| 305 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 306 | if (gt->verified == port) |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 307 | return 1; |
| 308 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 309 | mutex_lock(>->lock); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 310 | |
| 311 | q = inb_p(port); /* Read bus contents before probing. */ |
| 312 | /* Try to turn on CE, CK and DA respectively and check if card responds |
| 313 | properly. */ |
| 314 | for (i = 0; i < 3; ++i) { |
| 315 | outb_p(1 << i, port); |
| 316 | udelay(SHORT_DELAY); |
| 317 | |
| 318 | if ((inb_p(port) & (~GEMTEK_NS)) != (0x17 | (1 << (i + 5)))) { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 319 | mutex_unlock(>->lock); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 320 | return 0; |
| 321 | } |
| 322 | } |
| 323 | outb_p(q >> 5, port); /* Write bus contents back. */ |
| 324 | udelay(SHORT_DELAY); |
| 325 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 326 | mutex_unlock(>->lock); |
| 327 | gt->verified = port; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 328 | |
| 329 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 332 | /* |
| 333 | * Automatic probing for card. |
| 334 | */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 335 | static int gemtek_probe(struct gemtek *gt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 337 | struct v4l2_device *v4l2_dev = >->v4l2_dev; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 338 | int ioports[] = { 0x20c, 0x30c, 0x24c, 0x34c, 0x248, 0x28c }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | int i; |
| 340 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 341 | if (!probe) { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 342 | v4l2_info(v4l2_dev, "Automatic device probing disabled.\n"); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 343 | return -1; |
| 344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 346 | v4l2_info(v4l2_dev, "Automatic device probing enabled.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 348 | for (i = 0; i < ARRAY_SIZE(ioports); ++i) { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 349 | v4l2_info(v4l2_dev, "Trying I/O port 0x%x...\n", ioports[i]); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 350 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 351 | if (!request_region(ioports[i], 1, "gemtek-probe")) { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 352 | v4l2_warn(v4l2_dev, "I/O port 0x%x busy!\n", |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 353 | ioports[i]); |
| 354 | continue; |
| 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 357 | if (gemtek_verify(gt, ioports[i])) { |
| 358 | v4l2_info(v4l2_dev, "Card found from I/O port " |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 359 | "0x%x!\n", ioports[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 361 | release_region(ioports[i], 1); |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 362 | gt->io = ioports[i]; |
| 363 | return gt->io; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 364 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 365 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 366 | release_region(ioports[i], 1); |
| 367 | } |
| 368 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 369 | v4l2_err(v4l2_dev, "Automatic probing failed!\n"); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 370 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 373 | /* |
| 374 | * Video 4 Linux stuff. |
| 375 | */ |
Hans Verkuil | 3ca685a | 2008-08-23 04:49:13 -0300 | [diff] [blame] | 376 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 377 | static const struct v4l2_file_operations gemtek_fops = { |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 378 | .owner = THIS_MODULE, |
Hans Verkuil | 32958fd | 2010-11-14 09:36:23 -0300 | [diff] [blame] | 379 | .unlocked_ioctl = video_ioctl2, |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 380 | }; |
| 381 | |
| 382 | static int vidioc_querycap(struct file *file, void *priv, |
| 383 | struct v4l2_capability *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 385 | strlcpy(v->driver, "radio-gemtek", sizeof(v->driver)); |
| 386 | strlcpy(v->card, "GemTek", sizeof(v->card)); |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 387 | strlcpy(v->bus_info, "ISA", sizeof(v->bus_info)); |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 388 | v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 389 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 392 | static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 394 | struct gemtek *gt = video_drvdata(file); |
| 395 | |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 396 | if (v->index > 0) |
| 397 | return -EINVAL; |
| 398 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 399 | strlcpy(v->name, "FM", sizeof(v->name)); |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 400 | v->type = V4L2_TUNER_RADIO; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 401 | v->rangelow = GEMTEK_LOWFREQ; |
| 402 | v->rangehigh = GEMTEK_HIGHFREQ; |
| 403 | v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO; |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 404 | v->signal = 0xffff * gemtek_getsigstr(gt); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 405 | if (v->signal) { |
| 406 | v->audmode = V4L2_TUNER_MODE_STEREO; |
| 407 | v->rxsubchans = V4L2_TUNER_SUB_STEREO; |
| 408 | } else { |
| 409 | v->audmode = V4L2_TUNER_MODE_MONO; |
| 410 | v->rxsubchans = V4L2_TUNER_SUB_MONO; |
| 411 | } |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 412 | return 0; |
| 413 | } |
| 414 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 415 | static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *v) |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 416 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 417 | return (v->index != 0) ? -EINVAL : 0; |
| 418 | } |
| 419 | |
| 420 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 421 | struct v4l2_frequency *f) |
| 422 | { |
| 423 | struct gemtek *gt = video_drvdata(file); |
| 424 | |
| 425 | if (f->tuner != 0) |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 426 | return -EINVAL; |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 427 | f->type = V4L2_TUNER_RADIO; |
| 428 | f->frequency = gt->lastfreq; |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | static int vidioc_s_frequency(struct file *file, void *priv, |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 433 | struct v4l2_frequency *f) |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 434 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 435 | struct gemtek *gt = video_drvdata(file); |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 436 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 437 | if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) |
| 438 | return -EINVAL; |
| 439 | gemtek_setfreq(gt, f->frequency); |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static int vidioc_queryctrl(struct file *file, void *priv, |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 444 | struct v4l2_queryctrl *qc) |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 445 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 446 | switch (qc->id) { |
| 447 | case V4L2_CID_AUDIO_MUTE: |
| 448 | return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0); |
| 449 | default: |
| 450 | return -EINVAL; |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 451 | } |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | static int vidioc_g_ctrl(struct file *file, void *priv, |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 455 | struct v4l2_control *ctrl) |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 456 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 457 | struct gemtek *gt = video_drvdata(file); |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 458 | |
| 459 | switch (ctrl->id) { |
| 460 | case V4L2_CID_AUDIO_MUTE: |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 461 | ctrl->value = gt->muted; |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 462 | return 0; |
| 463 | } |
| 464 | return -EINVAL; |
| 465 | } |
| 466 | |
| 467 | static int vidioc_s_ctrl(struct file *file, void *priv, |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 468 | struct v4l2_control *ctrl) |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 469 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 470 | struct gemtek *gt = video_drvdata(file); |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 471 | |
| 472 | switch (ctrl->id) { |
| 473 | case V4L2_CID_AUDIO_MUTE: |
| 474 | if (ctrl->value) |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 475 | gemtek_mute(gt); |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 476 | else |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 477 | gemtek_unmute(gt); |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 478 | return 0; |
| 479 | } |
| 480 | return -EINVAL; |
| 481 | } |
| 482 | |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 483 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 484 | { |
| 485 | *i = 0; |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 490 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 491 | return (i != 0) ? -EINVAL : 0; |
| 492 | } |
| 493 | |
| 494 | static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 495 | { |
| 496 | a->index = 0; |
| 497 | strlcpy(a->name, "Radio", sizeof(a->name)); |
| 498 | a->capability = V4L2_AUDCAP_STEREO; |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 499 | return 0; |
| 500 | } |
| 501 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 502 | static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a) |
Douglas Landgraf | e9bb9c6 | 2007-04-25 00:15:46 -0300 | [diff] [blame] | 503 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 504 | return (a->index != 0) ? -EINVAL : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 507 | static const struct v4l2_ioctl_ops gemtek_ioctl_ops = { |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 508 | .vidioc_querycap = vidioc_querycap, |
| 509 | .vidioc_g_tuner = vidioc_g_tuner, |
| 510 | .vidioc_s_tuner = vidioc_s_tuner, |
| 511 | .vidioc_g_audio = vidioc_g_audio, |
| 512 | .vidioc_s_audio = vidioc_s_audio, |
| 513 | .vidioc_g_input = vidioc_g_input, |
| 514 | .vidioc_s_input = vidioc_s_input, |
| 515 | .vidioc_g_frequency = vidioc_g_frequency, |
| 516 | .vidioc_s_frequency = vidioc_s_frequency, |
| 517 | .vidioc_queryctrl = vidioc_queryctrl, |
| 518 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 519 | .vidioc_s_ctrl = vidioc_s_ctrl |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | }; |
| 521 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 522 | /* |
| 523 | * Initialization / cleanup related stuff. |
| 524 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | static int __init gemtek_init(void) |
| 527 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 528 | struct gemtek *gt = &gemtek_card; |
| 529 | struct v4l2_device *v4l2_dev = >->v4l2_dev; |
| 530 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 532 | strlcpy(v4l2_dev->name, "gemtek", sizeof(v4l2_dev->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 534 | v4l2_info(v4l2_dev, "GemTek Radio card driver: v0.0.3\n"); |
| 535 | |
| 536 | mutex_init(>->lock); |
| 537 | |
| 538 | gt->verified = -1; |
| 539 | gt->io = io; |
| 540 | gemtek_probe(gt); |
| 541 | if (gt->io) { |
| 542 | if (!request_region(gt->io, 1, "gemtek")) { |
| 543 | v4l2_err(v4l2_dev, "I/O port 0x%x already in use.\n", gt->io); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 544 | return -EBUSY; |
| 545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 547 | if (!gemtek_verify(gt, gt->io)) |
| 548 | v4l2_warn(v4l2_dev, "Card at I/O port 0x%x does not " |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 549 | "respond properly, check your " |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 550 | "configuration.\n", gt->io); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 551 | else |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 552 | v4l2_info(v4l2_dev, "Using I/O port 0x%x.\n", gt->io); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 553 | } else if (probe) { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 554 | v4l2_err(v4l2_dev, "Automatic probing failed and no " |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 555 | "fixed I/O port defined.\n"); |
| 556 | return -ENODEV; |
| 557 | } else { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 558 | v4l2_err(v4l2_dev, "Automatic probing disabled but no fixed " |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 559 | "I/O port defined."); |
| 560 | return -EINVAL; |
| 561 | } |
| 562 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 563 | res = v4l2_device_register(NULL, v4l2_dev); |
| 564 | if (res < 0) { |
| 565 | v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); |
| 566 | release_region(gt->io, 1); |
| 567 | return res; |
| 568 | } |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 569 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 570 | strlcpy(gt->vdev.name, v4l2_dev->name, sizeof(gt->vdev.name)); |
| 571 | gt->vdev.v4l2_dev = v4l2_dev; |
| 572 | gt->vdev.fops = &gemtek_fops; |
| 573 | gt->vdev.ioctl_ops = &gemtek_ioctl_ops; |
| 574 | gt->vdev.release = video_device_release_empty; |
| 575 | video_set_drvdata(>->vdev, gt); |
| 576 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 577 | /* Set defaults */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 578 | gt->lastfreq = GEMTEK_LOWFREQ; |
| 579 | gt->bu2614data = 0; |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 580 | |
| 581 | if (initmute) |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 582 | gemtek_mute(gt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
Hans Verkuil | 32958fd | 2010-11-14 09:36:23 -0300 | [diff] [blame] | 584 | if (video_register_device(>->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { |
| 585 | v4l2_device_unregister(v4l2_dev); |
| 586 | release_region(gt->io, 1); |
| 587 | return -EBUSY; |
| 588 | } |
| 589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | return 0; |
| 591 | } |
| 592 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 593 | /* |
| 594 | * Module cleanup |
| 595 | */ |
| 596 | static void __exit gemtek_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 598 | struct gemtek *gt = &gemtek_card; |
| 599 | struct v4l2_device *v4l2_dev = >->v4l2_dev; |
| 600 | |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 601 | if (shutdown) { |
| 602 | hardmute = 1; /* Turn off PLL */ |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 603 | gemtek_mute(gt); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 604 | } else { |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 605 | v4l2_info(v4l2_dev, "Module unloaded but card not muted!\n"); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 606 | } |
| 607 | |
Hans Verkuil | 502b71b | 2009-03-06 13:50:42 -0300 | [diff] [blame] | 608 | video_unregister_device(>->vdev); |
| 609 | v4l2_device_unregister(>->v4l2_dev); |
| 610 | release_region(gt->io, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | module_init(gemtek_init); |
Pekka Seppanen | 4753647 | 2007-10-01 00:27:55 -0300 | [diff] [blame] | 614 | module_exit(gemtek_exit); |