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