Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* Terratec ActiveRadio ISA Standalone card driver for Linux radio support |
| 2 | * (c) 1999 R. Offermanns (rolf@offermanns.de) |
| 3 | * based on the aimslab radio driver from M. Kirkwood |
| 4 | * many thanks to Michael Becker and Friedhelm Birth (from TerraTec) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 5 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * History: |
| 8 | * 1999-05-21 First preview release |
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 | * Notes on the hardware: |
| 11 | * There are two "main" chips on the card: |
| 12 | * - Philips OM5610 (http://www-us.semiconductors.philips.com/acrobat/datasheets/OM5610_2.pdf) |
| 13 | * - Philips SAA6588 (http://www-us.semiconductors.philips.com/acrobat/datasheets/SAA6588_1.pdf) |
| 14 | * (you can get the datasheet at the above links) |
| 15 | * |
| 16 | * Frequency control is done digitally -- ie out(port,encodefreq(95.8)); |
| 17 | * Volume Control is done digitally |
| 18 | * |
| 19 | * there is a I2C controlled RDS decoder (SAA6588) onboard, which i would like to support someday |
| 20 | * (as soon i have understand how to get started :) |
| 21 | * If you can help me out with that, please contact me!! |
| 22 | * |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 23 | * |
Mauro Carvalho Chehab | 55ac7b6 | 2006-08-08 09:10:03 -0300 | [diff] [blame] | 24 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #include <linux/module.h> /* Modules */ |
| 28 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 29 | #include <linux/ioport.h> /* request_region */ |
Mauro Carvalho Chehab | 55ac7b6 | 2006-08-08 09:10:03 -0300 | [diff] [blame] | 30 | #include <linux/videodev2.h> /* kernel radio structs */ |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 31 | #include <linux/mutex.h> |
Mauro Carvalho Chehab | 55ac7b6 | 2006-08-08 09:10:03 -0300 | [diff] [blame] | 32 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 33 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 34 | #include <media/v4l2-device.h> |
| 35 | #include <media/v4l2-ioctl.h> |
| 36 | |
| 37 | MODULE_AUTHOR("R.OFFERMANNS & others"); |
| 38 | MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card."); |
| 39 | MODULE_LICENSE("GPL"); |
| 40 | |
| 41 | #ifndef CONFIG_RADIO_TERRATEC_PORT |
| 42 | #define CONFIG_RADIO_TERRATEC_PORT 0x590 |
| 43 | #endif |
| 44 | |
| 45 | static int io = CONFIG_RADIO_TERRATEC_PORT; |
| 46 | static int radio_nr = -1; |
| 47 | |
| 48 | module_param(io, int, 0); |
| 49 | MODULE_PARM_DESC(io, "I/O address of the TerraTec ActiveRadio card (0x590 or 0x591)"); |
| 50 | module_param(radio_nr, int, 0); |
| 51 | |
| 52 | #define RADIO_VERSION KERNEL_VERSION(0, 0, 2) |
Mauro Carvalho Chehab | 55ac7b6 | 2006-08-08 09:10:03 -0300 | [diff] [blame] | 53 | |
| 54 | static struct v4l2_queryctrl radio_qctrl[] = { |
| 55 | { |
| 56 | .id = V4L2_CID_AUDIO_MUTE, |
| 57 | .name = "Mute", |
| 58 | .minimum = 0, |
| 59 | .maximum = 1, |
| 60 | .default_value = 1, |
| 61 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 62 | },{ |
| 63 | .id = V4L2_CID_AUDIO_VOLUME, |
| 64 | .name = "Volume", |
| 65 | .minimum = 0, |
| 66 | .maximum = 0xff, |
| 67 | .step = 1, |
| 68 | .default_value = 0xff, |
| 69 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 70 | } |
| 71 | }; |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #define WRT_DIS 0x00 |
| 74 | #define CLK_OFF 0x00 |
| 75 | #define IIC_DATA 0x01 |
| 76 | #define IIC_CLK 0x02 |
| 77 | #define DATA 0x04 |
| 78 | #define CLK_ON 0x08 |
| 79 | #define WRT_EN 0x10 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 81 | struct terratec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 83 | struct v4l2_device v4l2_dev; |
| 84 | struct video_device vdev; |
| 85 | int io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | int curvol; |
| 87 | unsigned long curfreq; |
| 88 | int muted; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 89 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 92 | static struct terratec terratec_card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* local things */ |
| 95 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 96 | static void tt_write_vol(struct terratec *tt, int volume) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
| 98 | int i; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 99 | |
| 100 | volume = volume + (volume * 32); /* change both channels */ |
| 101 | mutex_lock(&tt->lock); |
| 102 | for (i = 0; i < 8; i++) { |
| 103 | if (volume & (0x80 >> i)) |
| 104 | outb(0x80, tt->io + 1); |
| 105 | else |
| 106 | outb(0x00, tt->io + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 108 | mutex_unlock(&tt->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | |
| 112 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 113 | static void tt_mute(struct terratec *tt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 115 | tt->muted = 1; |
| 116 | tt_write_vol(tt, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 119 | static int tt_setvol(struct terratec *tt, int vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 121 | if (vol == tt->curvol) { /* requested volume = current */ |
| 122 | if (tt->muted) { /* user is unmuting the card */ |
| 123 | tt->muted = 0; |
| 124 | tt_write_vol(tt, vol); /* enable card */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 125 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 129 | if (vol == 0) { /* volume = 0 means mute the card */ |
| 130 | tt_write_vol(tt, 0); /* "turn off card" by setting vol to 0 */ |
| 131 | tt->curvol = vol; /* track the volume state! */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | return 0; |
| 133 | } |
| 134 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 135 | tt->muted = 0; |
| 136 | tt_write_vol(tt, vol); |
| 137 | tt->curvol = vol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
| 142 | /* this is the worst part in this driver */ |
| 143 | /* many more or less strange things are going on here, but hey, it works :) */ |
| 144 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 145 | static int tt_setfreq(struct terratec *tt, unsigned long freq1) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 146 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | int freq; |
| 148 | int i; |
| 149 | int p; |
| 150 | int temp; |
| 151 | long rest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | unsigned char buffer[25]; /* we have to bit shift 25 registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 154 | mutex_lock(&tt->lock); |
| 155 | |
| 156 | tt->curfreq = freq1; |
| 157 | |
| 158 | freq = freq1 / 160; /* convert the freq. to a nice to handle value */ |
| 159 | memset(buffer, 0, sizeof(buffer)); |
| 160 | |
| 161 | rest = freq * 10 + 10700; /* I once had understood what is going on here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | /* maybe some wise guy (friedhelm?) can comment this stuff */ |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 163 | i = 13; |
| 164 | p = 10; |
| 165 | temp = 102400; |
| 166 | while (rest != 0) { |
| 167 | if (rest % temp == rest) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | buffer[i] = 0; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 169 | else { |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 170 | buffer[i] = 1; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 171 | rest = rest - temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | i--; |
| 174 | p--; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 175 | temp = temp / 2; |
Michael Krufky | b930e1d | 2007-08-27 18:16:54 -0300 | [diff] [blame] | 176 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 178 | for (i = 24; i > -1; i--) { /* bit shift the values to the radiocard */ |
| 179 | if (buffer[i] == 1) { |
| 180 | outb(WRT_EN | DATA, tt->io); |
| 181 | outb(WRT_EN | DATA | CLK_ON, tt->io); |
| 182 | outb(WRT_EN | DATA, tt->io); |
| 183 | } else { |
| 184 | outb(WRT_EN | 0x00, tt->io); |
| 185 | outb(WRT_EN | 0x00 | CLK_ON, tt->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 188 | outb(0x00, tt->io); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 189 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 190 | mutex_unlock(&tt->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 191 | |
| 192 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 195 | static int tt_getsigstr(struct terratec *tt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 197 | if (inb(tt->io) & 2) /* bit set = no signal present */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | return 0; |
| 199 | return 1; /* signal present */ |
| 200 | } |
| 201 | |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 202 | static int vidioc_querycap(struct file *file, void *priv, |
| 203 | struct v4l2_capability *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 205 | strlcpy(v->driver, "radio-terratec", sizeof(v->driver)); |
| 206 | strlcpy(v->card, "ActiveRadio", sizeof(v->card)); |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 207 | strlcpy(v->bus_info, "ISA", sizeof(v->bus_info)); |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 208 | v->version = RADIO_VERSION; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 209 | v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 210 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 213 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 214 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 216 | struct terratec *tt = video_drvdata(file); |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 217 | |
| 218 | if (v->index > 0) |
| 219 | return -EINVAL; |
| 220 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 221 | strlcpy(v->name, "FM", sizeof(v->name)); |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 222 | v->type = V4L2_TUNER_RADIO; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 223 | v->rangelow = 87 * 16000; |
| 224 | v->rangehigh = 108 * 16000; |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 225 | v->rxsubchans = V4L2_TUNER_SUB_MONO; |
| 226 | v->capability = V4L2_TUNER_CAP_LOW; |
| 227 | v->audmode = V4L2_TUNER_MODE_MONO; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 228 | v->signal = 0xFFFF * tt_getsigstr(tt); |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 233 | struct v4l2_tuner *v) |
| 234 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 235 | return v->index ? -EINVAL : 0; |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 239 | struct v4l2_frequency *f) |
| 240 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 241 | struct terratec *tt = video_drvdata(file); |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 242 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 243 | tt_setfreq(tt, f->frequency); |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 248 | struct v4l2_frequency *f) |
| 249 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 250 | struct terratec *tt = video_drvdata(file); |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 251 | |
| 252 | f->type = V4L2_TUNER_RADIO; |
| 253 | f->frequency = tt->curfreq; |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 258 | struct v4l2_queryctrl *qc) |
| 259 | { |
| 260 | int i; |
| 261 | |
| 262 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { |
| 263 | if (qc->id && qc->id == radio_qctrl[i].id) { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 264 | memcpy(qc, &(radio_qctrl[i]), sizeof(*qc)); |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 265 | return 0; |
| 266 | } |
| 267 | } |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | |
| 271 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 272 | struct v4l2_control *ctrl) |
| 273 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 274 | struct terratec *tt = video_drvdata(file); |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 275 | |
| 276 | switch (ctrl->id) { |
| 277 | case V4L2_CID_AUDIO_MUTE: |
| 278 | if (tt->muted) |
| 279 | ctrl->value = 1; |
| 280 | else |
| 281 | ctrl->value = 0; |
| 282 | return 0; |
| 283 | case V4L2_CID_AUDIO_VOLUME: |
| 284 | ctrl->value = tt->curvol * 6554; |
| 285 | return 0; |
| 286 | } |
| 287 | return -EINVAL; |
| 288 | } |
| 289 | |
| 290 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 291 | struct v4l2_control *ctrl) |
| 292 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 293 | struct terratec *tt = video_drvdata(file); |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 294 | |
| 295 | switch (ctrl->id) { |
| 296 | case V4L2_CID_AUDIO_MUTE: |
| 297 | if (ctrl->value) |
| 298 | tt_mute(tt); |
| 299 | else |
| 300 | tt_setvol(tt,tt->curvol); |
| 301 | return 0; |
| 302 | case V4L2_CID_AUDIO_VOLUME: |
| 303 | tt_setvol(tt,ctrl->value); |
| 304 | return 0; |
| 305 | } |
| 306 | return -EINVAL; |
| 307 | } |
| 308 | |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 309 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 310 | { |
| 311 | *i = 0; |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 316 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 317 | return i ? -EINVAL : 0; |
| 318 | } |
| 319 | |
| 320 | static int vidioc_g_audio(struct file *file, void *priv, |
| 321 | struct v4l2_audio *a) |
| 322 | { |
| 323 | a->index = 0; |
| 324 | strlcpy(a->name, "Radio", sizeof(a->name)); |
| 325 | a->capability = V4L2_AUDCAP_STEREO; |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | static int vidioc_s_audio(struct file *file, void *priv, |
| 330 | struct v4l2_audio *a) |
| 331 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 332 | return a->index ? -EINVAL : 0; |
| 333 | } |
| 334 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 335 | static const struct v4l2_file_operations terratec_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | .owner = THIS_MODULE, |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 337 | .ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | }; |
| 339 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 340 | static const struct v4l2_ioctl_ops terratec_ioctl_ops = { |
Douglas Landgraf | 1de6923 | 2007-04-22 23:15:47 -0300 | [diff] [blame] | 341 | .vidioc_querycap = vidioc_querycap, |
| 342 | .vidioc_g_tuner = vidioc_g_tuner, |
| 343 | .vidioc_s_tuner = vidioc_s_tuner, |
| 344 | .vidioc_g_frequency = vidioc_g_frequency, |
| 345 | .vidioc_s_frequency = vidioc_s_frequency, |
| 346 | .vidioc_queryctrl = vidioc_queryctrl, |
| 347 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 348 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 349 | .vidioc_g_audio = vidioc_g_audio, |
| 350 | .vidioc_s_audio = vidioc_s_audio, |
| 351 | .vidioc_g_input = vidioc_g_input, |
| 352 | .vidioc_s_input = vidioc_s_input, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | }; |
| 354 | |
| 355 | static int __init terratec_init(void) |
| 356 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 357 | struct terratec *tt = &terratec_card; |
| 358 | struct v4l2_device *v4l2_dev = &tt->v4l2_dev; |
| 359 | int res; |
| 360 | |
| 361 | strlcpy(v4l2_dev->name, "terratec", sizeof(v4l2_dev->name)); |
| 362 | tt->io = io; |
| 363 | if (tt->io == -1) { |
Hans Verkuil | b24c20cc | 2009-03-09 08:11:21 -0300 | [diff] [blame] | 364 | v4l2_err(v4l2_dev, "you must set an I/O address with io=0x590 or 0x591\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | return -EINVAL; |
| 366 | } |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 367 | if (!request_region(tt->io, 2, "terratec")) { |
| 368 | v4l2_err(v4l2_dev, "port 0x%x already in use\n", io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return -EBUSY; |
| 370 | } |
| 371 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 372 | res = v4l2_device_register(NULL, v4l2_dev); |
| 373 | if (res < 0) { |
| 374 | release_region(tt->io, 2); |
| 375 | v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); |
| 376 | return res; |
| 377 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 378 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 379 | strlcpy(tt->vdev.name, v4l2_dev->name, sizeof(tt->vdev.name)); |
| 380 | tt->vdev.v4l2_dev = v4l2_dev; |
| 381 | tt->vdev.fops = &terratec_fops; |
| 382 | tt->vdev.ioctl_ops = &terratec_ioctl_ops; |
| 383 | tt->vdev.release = video_device_release_empty; |
| 384 | video_set_drvdata(&tt->vdev, tt); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 385 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 386 | mutex_init(&tt->lock); |
| 387 | |
| 388 | if (video_register_device(&tt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { |
| 389 | v4l2_device_unregister(&tt->v4l2_dev); |
| 390 | release_region(tt->io, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | return -EINVAL; |
| 392 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 393 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 394 | v4l2_info(v4l2_dev, "TERRATEC ActivRadio Standalone card driver.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 396 | /* mute card - prevents noisy bootups */ |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 397 | tt_write_vol(tt, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | return 0; |
| 399 | } |
| 400 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 401 | static void __exit terratec_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 403 | struct terratec *tt = &terratec_card; |
| 404 | struct v4l2_device *v4l2_dev = &tt->v4l2_dev; |
| 405 | |
| 406 | video_unregister_device(&tt->vdev); |
| 407 | v4l2_device_unregister(&tt->v4l2_dev); |
| 408 | release_region(tt->io, 2); |
| 409 | v4l2_info(v4l2_dev, "TERRATEC ActivRadio Standalone card driver unloaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | module_init(terratec_init); |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 413 | module_exit(terratec_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |