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