Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 1 | /* radio-aztech.c - Aztech radio card driver for Linux 2.2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
Mauro Carvalho Chehab | a4366af | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 3 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 4 | * Adapted to support the Video for Linux API by |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by: |
| 6 | * |
| 7 | * Quay Ly |
| 8 | * Donald Song |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 9 | * Jason Lewis (jlewis@twilight.vtc.vsc.edu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) |
| 11 | * William McGrath (wmcgrath@twilight.vtc.vsc.edu) |
| 12 | * |
| 13 | * The basis for this code may be found at http://bigbang.vtc.vsc.edu/fmradio/ |
| 14 | * along with more information on the card itself. |
| 15 | * |
| 16 | * History: |
| 17 | * 1999-02-24 Russell Kroll <rkroll@exploits.org> |
| 18 | * Fine tuning/VIDEO_TUNER_LOW |
| 19 | * Range expanded to 87-108 MHz (from 87.9-107.8) |
| 20 | * |
| 21 | * Notable changes from the original source: |
| 22 | * - includes stripped down to the essentials |
| 23 | * - for loops used as delays replaced with udelay() |
| 24 | * - #defines removed, changed to static values |
| 25 | * - tuning structure changed - no more character arrays, other changes |
| 26 | */ |
| 27 | |
| 28 | #include <linux/module.h> /* Modules */ |
| 29 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 30 | #include <linux/ioport.h> /* request_region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/delay.h> /* udelay */ |
Mauro Carvalho Chehab | a4366af | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 32 | #include <linux/videodev2.h> /* kernel radio structs */ |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 33 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 34 | #include <media/v4l2-device.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 35 | #include <media/v4l2-ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 37 | MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath"); |
| 38 | MODULE_DESCRIPTION("A driver for the Aztech radio card."); |
| 39 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 29834c1 | 2011-06-25 10:15:42 -0300 | [diff] [blame] | 40 | MODULE_VERSION("0.0.3"); |
Mauro Carvalho Chehab | a4366af | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ |
| 43 | |
| 44 | #ifndef CONFIG_RADIO_AZTECH_PORT |
| 45 | #define CONFIG_RADIO_AZTECH_PORT -1 |
| 46 | #endif |
| 47 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 48 | static int io = CONFIG_RADIO_AZTECH_PORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | static int radio_nr = -1; |
| 50 | static int radio_wait_time = 1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 52 | module_param(io, int, 0); |
| 53 | module_param(radio_nr, int, 0); |
| 54 | MODULE_PARM_DESC(io, "I/O address of the Aztech card (0x350 or 0x358)"); |
| 55 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 56 | struct aztech |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 58 | struct v4l2_device v4l2_dev; |
| 59 | struct video_device vdev; |
| 60 | int io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | int curvol; |
| 62 | unsigned long curfreq; |
| 63 | int stereo; |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 64 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 67 | static struct aztech aztech_card; |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | static int volconvert(int level) |
| 70 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 71 | level >>= 14; /* Map 16bits down to 2 bit */ |
| 72 | level &= 3; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /* convert to card-friendly values */ |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 75 | switch (level) { |
| 76 | case 0: |
| 77 | return 0; |
| 78 | case 1: |
| 79 | return 1; |
| 80 | case 2: |
| 81 | return 4; |
| 82 | case 3: |
| 83 | return 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | return 0; /* Quieten gcc */ |
| 86 | } |
| 87 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 88 | static void send_0_byte(struct aztech *az) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
| 90 | udelay(radio_wait_time); |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 91 | outb_p(2 + volconvert(az->curvol), az->io); |
| 92 | outb_p(64 + 2 + volconvert(az->curvol), az->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 95 | static void send_1_byte(struct aztech *az) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
| 97 | udelay (radio_wait_time); |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 98 | outb_p(128 + 2 + volconvert(az->curvol), az->io); |
| 99 | outb_p(128 + 64 + 2 + volconvert(az->curvol), az->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 102 | static int az_setvol(struct aztech *az, int vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 104 | mutex_lock(&az->lock); |
| 105 | outb(volconvert(vol), az->io); |
| 106 | mutex_unlock(&az->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | /* thanks to Michael Dwyer for giving me a dose of clues in |
| 111 | * the signal strength department.. |
| 112 | * |
| 113 | * This card has a stereo bit - bit 0 set = mono, not set = stereo |
| 114 | * It also has a "signal" bit - bit 1 set = bad signal, not set = good |
| 115 | * |
| 116 | */ |
| 117 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 118 | static int az_getsigstr(struct aztech *az) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 120 | int sig = 1; |
| 121 | |
| 122 | mutex_lock(&az->lock); |
| 123 | if (inb(az->io) & 2) /* bit set = no signal present */ |
| 124 | sig = 0; |
| 125 | mutex_unlock(&az->lock); |
| 126 | return sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 129 | static int az_getstereo(struct aztech *az) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 131 | int stereo = 1; |
| 132 | |
| 133 | mutex_lock(&az->lock); |
| 134 | if (inb(az->io) & 1) /* bit set = mono */ |
| 135 | stereo = 0; |
| 136 | mutex_unlock(&az->lock); |
| 137 | return stereo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 140 | static int az_setfreq(struct aztech *az, unsigned long frequency) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
| 142 | int i; |
| 143 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 144 | mutex_lock(&az->lock); |
| 145 | |
| 146 | az->curfreq = frequency; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | frequency += 171200; /* Add 10.7 MHz IF */ |
| 148 | frequency /= 800; /* Convert to 50 kHz units */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 149 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 150 | send_0_byte(az); /* 0: LSB of frequency */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | for (i = 0; i < 13; i++) /* : frequency bits (1-13) */ |
| 153 | if (frequency & (1 << i)) |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 154 | send_1_byte(az); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | else |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 156 | send_0_byte(az); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 158 | send_0_byte(az); /* 14: test bit - always 0 */ |
| 159 | send_0_byte(az); /* 15: test bit - always 0 */ |
| 160 | send_0_byte(az); /* 16: band data 0 - always 0 */ |
| 161 | if (az->stereo) /* 17: stereo (1 to enable) */ |
| 162 | send_1_byte(az); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | else |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 164 | send_0_byte(az); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 166 | send_1_byte(az); /* 18: band data 1 - unknown */ |
| 167 | send_0_byte(az); /* 19: time base - always 0 */ |
| 168 | send_0_byte(az); /* 20: spacing (0 = 25 kHz) */ |
| 169 | send_1_byte(az); /* 21: spacing (1 = 25 kHz) */ |
| 170 | send_0_byte(az); /* 22: spacing (0 = 25 kHz) */ |
| 171 | send_1_byte(az); /* 23: AM/FM (FM = 1, always) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | /* latch frequency */ |
| 174 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 175 | udelay(radio_wait_time); |
| 176 | outb_p(128 + 64 + volconvert(az->curvol), az->io); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 177 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 178 | mutex_unlock(&az->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 183 | static int vidioc_querycap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 184 | struct v4l2_capability *v) |
| 185 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 186 | strlcpy(v->driver, "radio-aztech", sizeof(v->driver)); |
| 187 | strlcpy(v->card, "Aztech Radio", sizeof(v->card)); |
| 188 | strlcpy(v->bus_info, "ISA", sizeof(v->bus_info)); |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 189 | v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 190 | return 0; |
| 191 | } |
| 192 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 193 | static int vidioc_g_tuner(struct file *file, void *priv, |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 194 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 196 | struct aztech *az = video_drvdata(file); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 197 | |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 198 | if (v->index > 0) |
| 199 | return -EINVAL; |
Mauro Carvalho Chehab | a4366af | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 200 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 201 | strlcpy(v->name, "FM", sizeof(v->name)); |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 202 | v->type = V4L2_TUNER_RADIO; |
Mauro Carvalho Chehab | a4366af | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 203 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 204 | v->rangelow = 87 * 16000; |
| 205 | v->rangehigh = 108 * 16000; |
| 206 | v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; |
| 207 | v->capability = V4L2_TUNER_CAP_LOW; |
| 208 | if (az_getstereo(az)) |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 209 | v->audmode = V4L2_TUNER_MODE_STEREO; |
| 210 | else |
| 211 | v->audmode = V4L2_TUNER_MODE_MONO; |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 212 | v->signal = 0xFFFF * az_getsigstr(az); |
Mauro Carvalho Chehab | a4366af | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 213 | |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 214 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 217 | static int vidioc_s_tuner(struct file *file, void *priv, |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 218 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 220 | return v->index ? -EINVAL : 0; |
Mauro Carvalho Chehab | 676b0ac | 2007-01-25 15:10:31 -0300 | [diff] [blame] | 221 | } |
| 222 | |
Mauro Carvalho Chehab | a0c05ab | 2007-01-25 16:48:13 -0300 | [diff] [blame] | 223 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 224 | { |
| 225 | *i = 0; |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 230 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 231 | return i ? -EINVAL : 0; |
Mauro Carvalho Chehab | a0c05ab | 2007-01-25 16:48:13 -0300 | [diff] [blame] | 232 | } |
| 233 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 234 | static int vidioc_g_audio(struct file *file, void *priv, |
Mauro Carvalho Chehab | 676b0ac | 2007-01-25 15:10:31 -0300 | [diff] [blame] | 235 | struct v4l2_audio *a) |
| 236 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 237 | a->index = 0; |
| 238 | strlcpy(a->name, "Radio", sizeof(a->name)); |
| 239 | a->capability = V4L2_AUDCAP_STEREO; |
Mauro Carvalho Chehab | 676b0ac | 2007-01-25 15:10:31 -0300 | [diff] [blame] | 240 | return 0; |
| 241 | } |
| 242 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 243 | static int vidioc_s_audio(struct file *file, void *priv, |
| 244 | struct v4l2_audio *a) |
| 245 | { |
| 246 | return a->index ? -EINVAL : 0; |
| 247 | } |
| 248 | |
| 249 | static int vidioc_s_frequency(struct file *file, void *priv, |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 250 | struct v4l2_frequency *f) |
| 251 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 252 | struct aztech *az = video_drvdata(file); |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 253 | |
Hans Verkuil | a3a9e28 | 2009-11-27 04:33:25 -0300 | [diff] [blame] | 254 | if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) |
| 255 | return -EINVAL; |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 256 | az_setfreq(az, f->frequency); |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 257 | return 0; |
| 258 | } |
| 259 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 260 | static int vidioc_g_frequency(struct file *file, void *priv, |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 261 | struct v4l2_frequency *f) |
| 262 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 263 | struct aztech *az = video_drvdata(file); |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 264 | |
Hans Verkuil | a3a9e28 | 2009-11-27 04:33:25 -0300 | [diff] [blame] | 265 | if (f->tuner != 0) |
| 266 | return -EINVAL; |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 267 | f->type = V4L2_TUNER_RADIO; |
| 268 | f->frequency = az->curfreq; |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 269 | return 0; |
| 270 | } |
| 271 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 272 | static int vidioc_queryctrl(struct file *file, void *priv, |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 273 | struct v4l2_queryctrl *qc) |
| 274 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 275 | switch (qc->id) { |
| 276 | case V4L2_CID_AUDIO_MUTE: |
| 277 | return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1); |
| 278 | case V4L2_CID_AUDIO_VOLUME: |
| 279 | return v4l2_ctrl_query_fill(qc, 0, 0xff, 1, 0xff); |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 280 | } |
| 281 | return -EINVAL; |
| 282 | } |
| 283 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 284 | static int vidioc_g_ctrl(struct file *file, void *priv, |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 285 | struct v4l2_control *ctrl) |
| 286 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 287 | struct aztech *az = video_drvdata(file); |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 288 | |
| 289 | switch (ctrl->id) { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 290 | case V4L2_CID_AUDIO_MUTE: |
| 291 | if (az->curvol == 0) |
| 292 | ctrl->value = 1; |
| 293 | else |
| 294 | ctrl->value = 0; |
| 295 | return 0; |
| 296 | case V4L2_CID_AUDIO_VOLUME: |
| 297 | ctrl->value = az->curvol * 6554; |
| 298 | return 0; |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 299 | } |
| 300 | return -EINVAL; |
| 301 | } |
| 302 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 303 | static int vidioc_s_ctrl(struct file *file, void *priv, |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 304 | struct v4l2_control *ctrl) |
| 305 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 306 | struct aztech *az = video_drvdata(file); |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 307 | |
| 308 | switch (ctrl->id) { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 309 | case V4L2_CID_AUDIO_MUTE: |
| 310 | if (ctrl->value) |
| 311 | az_setvol(az, 0); |
| 312 | else |
| 313 | az_setvol(az, az->curvol); |
| 314 | return 0; |
| 315 | case V4L2_CID_AUDIO_VOLUME: |
| 316 | az_setvol(az, ctrl->value); |
| 317 | return 0; |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 318 | } |
| 319 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 322 | static const struct v4l2_file_operations aztech_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | .owner = THIS_MODULE, |
Hans Verkuil | 32958fd | 2010-11-14 09:36:23 -0300 | [diff] [blame] | 324 | .unlocked_ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | }; |
| 326 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 327 | static const struct v4l2_ioctl_ops aztech_ioctl_ops = { |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 328 | .vidioc_querycap = vidioc_querycap, |
| 329 | .vidioc_g_tuner = vidioc_g_tuner, |
| 330 | .vidioc_s_tuner = vidioc_s_tuner, |
Mauro Carvalho Chehab | 676b0ac | 2007-01-25 15:10:31 -0300 | [diff] [blame] | 331 | .vidioc_g_audio = vidioc_g_audio, |
| 332 | .vidioc_s_audio = vidioc_s_audio, |
Mauro Carvalho Chehab | a0c05ab | 2007-01-25 16:48:13 -0300 | [diff] [blame] | 333 | .vidioc_g_input = vidioc_g_input, |
| 334 | .vidioc_s_input = vidioc_s_input, |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 335 | .vidioc_g_frequency = vidioc_g_frequency, |
| 336 | .vidioc_s_frequency = vidioc_s_frequency, |
| 337 | .vidioc_queryctrl = vidioc_queryctrl, |
| 338 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 339 | .vidioc_s_ctrl = vidioc_s_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | }; |
| 341 | |
| 342 | static int __init aztech_init(void) |
| 343 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 344 | struct aztech *az = &aztech_card; |
| 345 | struct v4l2_device *v4l2_dev = &az->v4l2_dev; |
| 346 | int res; |
| 347 | |
| 348 | strlcpy(v4l2_dev->name, "aztech", sizeof(v4l2_dev->name)); |
| 349 | az->io = io; |
| 350 | |
| 351 | if (az->io == -1) { |
Hans Verkuil | b24c20cc | 2009-03-09 08:11:21 -0300 | [diff] [blame] | 352 | v4l2_err(v4l2_dev, "you must set an I/O address with io=0x350 or 0x358\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return -EINVAL; |
| 354 | } |
| 355 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 356 | if (!request_region(az->io, 2, "aztech")) { |
| 357 | v4l2_err(v4l2_dev, "port 0x%x already in use\n", az->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | return -EBUSY; |
| 359 | } |
| 360 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 361 | res = v4l2_device_register(NULL, v4l2_dev); |
| 362 | if (res < 0) { |
| 363 | release_region(az->io, 2); |
| 364 | v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); |
| 365 | return res; |
| 366 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 367 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 368 | mutex_init(&az->lock); |
| 369 | strlcpy(az->vdev.name, v4l2_dev->name, sizeof(az->vdev.name)); |
| 370 | az->vdev.v4l2_dev = v4l2_dev; |
| 371 | az->vdev.fops = &aztech_fops; |
| 372 | az->vdev.ioctl_ops = &aztech_ioctl_ops; |
| 373 | az->vdev.release = video_device_release_empty; |
| 374 | video_set_drvdata(&az->vdev, az); |
Hans Verkuil | 32958fd | 2010-11-14 09:36:23 -0300 | [diff] [blame] | 375 | /* mute card - prevents noisy bootups */ |
| 376 | outb(0, az->io); |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 377 | |
| 378 | if (video_register_device(&az->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { |
| 379 | v4l2_device_unregister(v4l2_dev); |
| 380 | release_region(az->io, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | return -EINVAL; |
| 382 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 383 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 384 | v4l2_info(v4l2_dev, "Aztech radio card driver v1.00/19990224 rkroll@exploits.org\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | return 0; |
| 386 | } |
| 387 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 388 | static void __exit aztech_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | { |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 390 | struct aztech *az = &aztech_card; |
| 391 | |
| 392 | video_unregister_device(&az->vdev); |
| 393 | v4l2_device_unregister(&az->v4l2_dev); |
| 394 | release_region(az->io, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | module_init(aztech_init); |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 398 | module_exit(aztech_exit); |