radio-trust.c (b59b36db9e8f441868c9907d6ea8fe0cdcb77f39) | radio-trust.c (982eddb911b772295d5efc11f7c2b34c7fd6e60e) |
---|---|
1/* radio-trust.c - Trust FM Radio card driver for Linux 2.2 2 * by Eric Lammerts <eric@scintilla.utwente.nl> 3 * 4 * Based on radio-aztech.c. Original notes: 5 * 6 * Adapted to support the Video for Linux API by 7 * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by: 8 * 9 * Quay Ly 10 * Donald Song 11 * Jason Lewis (jlewis@twilight.vtc.vsc.edu) 12 * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) 13 * William McGrath (wmcgrath@twilight.vtc.vsc.edu) 14 * | 1/* radio-trust.c - Trust FM Radio card driver for Linux 2.2 2 * by Eric Lammerts <eric@scintilla.utwente.nl> 3 * 4 * Based on radio-aztech.c. Original notes: 5 * 6 * Adapted to support the Video for Linux API by 7 * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by: 8 * 9 * Quay Ly 10 * Donald Song 11 * Jason Lewis (jlewis@twilight.vtc.vsc.edu) 12 * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) 13 * William McGrath (wmcgrath@twilight.vtc.vsc.edu) 14 * |
15 * The basis for this code may be found at http://bigbang.vtc.vsc.edu/fmradio/ | 15 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
16 */ 17 18#include <stdarg.h> 19#include <linux/module.h> 20#include <linux/init.h> 21#include <linux/ioport.h> 22#include <asm/io.h> 23#include <asm/uaccess.h> | 16 */ 17 18#include <stdarg.h> 19#include <linux/module.h> 20#include <linux/init.h> 21#include <linux/ioport.h> 22#include <asm/io.h> 23#include <asm/uaccess.h> |
24#include <linux/videodev.h> | 24#include <linux/videodev2.h> |
25#include <media/v4l2-common.h> 26 | 25#include <media/v4l2-common.h> 26 |
27#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 28#define RADIO_VERSION KERNEL_VERSION(0,0,2) 29 30static struct v4l2_queryctrl radio_qctrl[] = { 31 { 32 .id = V4L2_CID_AUDIO_MUTE, 33 .name = "Mute", 34 .minimum = 0, 35 .maximum = 1, 36 .default_value = 1, 37 .type = V4L2_CTRL_TYPE_BOOLEAN, 38 },{ 39 .id = V4L2_CID_AUDIO_VOLUME, 40 .name = "Volume", 41 .minimum = 0, 42 .maximum = 65535, 43 .step = 2048, 44 .default_value = 65535, 45 .type = V4L2_CTRL_TYPE_INTEGER, 46 },{ 47 .id = V4L2_CID_AUDIO_BASS, 48 .name = "Bass", 49 .minimum = 0, 50 .maximum = 65535, 51 .step = 4370, 52 .default_value = 32768, 53 .type = V4L2_CTRL_TYPE_INTEGER, 54 },{ 55 .id = V4L2_CID_AUDIO_TREBLE, 56 .name = "Treble", 57 .minimum = 0, 58 .maximum = 65535, 59 .step = 4370, 60 .default_value = 32768, 61 .type = V4L2_CTRL_TYPE_INTEGER, 62 }, 63}; 64 |
|
27/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ 28 29#ifndef CONFIG_RADIO_TRUST_PORT 30#define CONFIG_RADIO_TRUST_PORT -1 31#endif 32 33static int io = CONFIG_RADIO_TRUST_PORT; 34static int radio_nr = -1; --- 119 unchanged lines hidden (view full) --- 154 write_i2c(5, TSA6060T_ADDR, (f << 1) | 1, f >> 7, 0x60 | ((f >> 15) & 1), 0); 155} 156 157static int tr_do_ioctl(struct inode *inode, struct file *file, 158 unsigned int cmd, void *arg) 159{ 160 switch(cmd) 161 { | 65/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ 66 67#ifndef CONFIG_RADIO_TRUST_PORT 68#define CONFIG_RADIO_TRUST_PORT -1 69#endif 70 71static int io = CONFIG_RADIO_TRUST_PORT; 72static int radio_nr = -1; --- 119 unchanged lines hidden (view full) --- 192 write_i2c(5, TSA6060T_ADDR, (f << 1) | 1, f >> 7, 0x60 | ((f >> 15) & 1), 0); 193} 194 195static int tr_do_ioctl(struct inode *inode, struct file *file, 196 unsigned int cmd, void *arg) 197{ 198 switch(cmd) 199 { |
162 case VIDIOCGCAP: | 200 case VIDIOC_QUERYCAP: |
163 { | 201 { |
164 struct video_capability *v = arg; 165 | 202 struct v4l2_capability *v = arg; |
166 memset(v,0,sizeof(*v)); | 203 memset(v,0,sizeof(*v)); |
167 v->type=VID_TYPE_TUNER; 168 v->channels=1; 169 v->audios=1; 170 strcpy(v->name, "Trust FM Radio"); | 204 strlcpy(v->driver, "radio-trust", sizeof (v->driver)); 205 strlcpy(v->card, "Trust FM Radio", sizeof (v->card)); 206 sprintf(v->bus_info,"ISA"); 207 v->version = RADIO_VERSION; 208 v->capabilities = V4L2_CAP_TUNER; |
171 172 return 0; 173 } | 209 210 return 0; 211 } |
174 case VIDIOCGTUNER: | 212 case VIDIOC_G_TUNER: |
175 { | 213 { |
176 struct video_tuner *v = arg; | 214 struct v4l2_tuner *v = arg; |
177 | 215 |
178 if(v->tuner) /* Only 1 tuner */ | 216 if (v->index > 0) |
179 return -EINVAL; 180 | 217 return -EINVAL; 218 |
181 v->rangelow = 87500 * 16; 182 v->rangehigh = 108000 * 16; 183 v->flags = VIDEO_TUNER_LOW; 184 v->mode = VIDEO_MODE_AUTO; | 219 memset(v,0,sizeof(*v)); 220 strcpy(v->name, "FM"); 221 v->type = V4L2_TUNER_RADIO; |
185 | 222 |
186 v->signal = tr_getsigstr(); | 223 v->rangelow=(87.5*16000); 224 v->rangehigh=(108*16000); 225 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; 226 v->capability=V4L2_TUNER_CAP_LOW; |
187 if(tr_getstereo()) | 227 if(tr_getstereo()) |
188 v->flags |= VIDEO_TUNER_STEREO_ON; | 228 v->audmode = V4L2_TUNER_MODE_STEREO; 229 else 230 v->audmode = V4L2_TUNER_MODE_MONO; 231 v->signal=tr_getsigstr(); |
189 | 232 |
190 strcpy(v->name, "FM"); 191 | |
192 return 0; 193 } | 233 return 0; 234 } |
194 case VIDIOCSTUNER: | 235 case VIDIOC_S_TUNER: |
195 { | 236 { |
196 struct video_tuner *v = arg; 197 if(v->tuner != 0) | 237 struct v4l2_tuner *v = arg; 238 239 if (v->index > 0) |
198 return -EINVAL; | 240 return -EINVAL; |
241 |
|
199 return 0; 200 } | 242 return 0; 243 } |
201 case VIDIOCGFREQ: | 244 case VIDIOC_S_FREQUENCY: |
202 { | 245 { |
203 unsigned long *freq = arg; 204 *freq = curfreq; | 246 struct v4l2_frequency *f = arg; 247 248 curfreq = f->frequency; 249 tr_setfreq(curfreq); |
205 return 0; 206 } | 250 return 0; 251 } |
207 case VIDIOCSFREQ: | 252 case VIDIOC_G_FREQUENCY: |
208 { | 253 { |
209 unsigned long *freq = arg; 210 tr_setfreq(*freq); | 254 struct v4l2_frequency *f = arg; 255 256 f->type = V4L2_TUNER_RADIO; 257 f->frequency = curfreq; 258 |
211 return 0; 212 } | 259 return 0; 260 } |
213 case VIDIOCGAUDIO: | 261 case VIDIOC_QUERYCTRL: |
214 { | 262 { |
215 struct video_audio *v = arg; | 263 struct v4l2_queryctrl *qc = arg; 264 int i; |
216 | 265 |
217 memset(v,0, sizeof(*v)); 218 v->flags = VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME | 219 VIDEO_AUDIO_BASS | VIDEO_AUDIO_TREBLE; 220 v->mode = curstereo? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO; 221 v->volume = curvol * 2048; 222 v->step = 2048; 223 v->bass = curbass * 4370; 224 v->treble = curtreble * 4370; | 266 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 267 if (qc->id && qc->id == radio_qctrl[i].id) { 268 memcpy(qc, &(radio_qctrl[i]), 269 sizeof(*qc)); 270 return (0); 271 } 272 } 273 return -EINVAL; 274 } 275 case VIDIOC_G_CTRL: 276 { 277 struct v4l2_control *ctrl= arg; |
225 | 278 |
226 strcpy(v->name, "Trust FM Radio"); 227 return 0; | 279 switch (ctrl->id) { 280 case V4L2_CID_AUDIO_MUTE: 281 ctrl->value=curmute; 282 return (0); 283 case V4L2_CID_AUDIO_VOLUME: 284 ctrl->value= curvol * 2048; 285 return (0); 286 case V4L2_CID_AUDIO_BASS: 287 ctrl->value= curbass * 4370; 288 return (0); 289 case V4L2_CID_AUDIO_TREBLE: 290 ctrl->value= curtreble * 4370; 291 return (0); 292 } 293 return -EINVAL; |
228 } | 294 } |
229 case VIDIOCSAUDIO: | 295 case VIDIOC_S_CTRL: |
230 { | 296 { |
231 struct video_audio *v = arg; | 297 struct v4l2_control *ctrl= arg; |
232 | 298 |
233 if(v->audio) 234 return -EINVAL; 235 tr_setvol(v->volume); 236 tr_setbass(v->bass); 237 tr_settreble(v->treble); 238 tr_setstereo(v->mode & VIDEO_SOUND_STEREO); 239 tr_setmute(v->flags & VIDEO_AUDIO_MUTE); 240 return 0; | 299 switch (ctrl->id) { 300 case V4L2_CID_AUDIO_MUTE: 301 tr_setmute(ctrl->value); 302 return 0; 303 case V4L2_CID_AUDIO_VOLUME: 304 tr_setvol(ctrl->value); 305 return 0; 306 case V4L2_CID_AUDIO_BASS: 307 tr_setbass(ctrl->value); 308 return 0; 309 case V4L2_CID_AUDIO_TREBLE: 310 tr_settreble(ctrl->value); 311 return (0); 312 } 313 return -EINVAL; |
241 } | 314 } |
315 |
|
242 default: | 316 default: |
243 return -ENOIOCTLCMD; | 317 return v4l_compat_translate_ioctl(inode,file,cmd,arg, 318 tr_do_ioctl); |
244 } 245} 246 247static int tr_ioctl(struct inode *inode, struct file *file, 248 unsigned int cmd, unsigned long arg) 249{ 250 return video_usercopy(inode, file, cmd, arg, tr_do_ioctl); 251} --- 7 unchanged lines hidden (view full) --- 259 .llseek = no_llseek, 260}; 261 262static struct video_device trust_radio= 263{ 264 .owner = THIS_MODULE, 265 .name = "Trust FM Radio", 266 .type = VID_TYPE_TUNER, | 319 } 320} 321 322static int tr_ioctl(struct inode *inode, struct file *file, 323 unsigned int cmd, unsigned long arg) 324{ 325 return video_usercopy(inode, file, cmd, arg, tr_do_ioctl); 326} --- 7 unchanged lines hidden (view full) --- 334 .llseek = no_llseek, 335}; 336 337static struct video_device trust_radio= 338{ 339 .owner = THIS_MODULE, 340 .name = "Trust FM Radio", 341 .type = VID_TYPE_TUNER, |
267 .hardware = VID_HARDWARE_TRUST, | 342 .hardware = 0, |
268 .fops = &trust_fops, 269}; 270 271static int __init trust_init(void) 272{ 273 if(io == -1) { 274 printk(KERN_ERR "You must set an I/O address with io=0x???\n"); 275 return -EINVAL; --- 46 unchanged lines hidden --- | 343 .fops = &trust_fops, 344}; 345 346static int __init trust_init(void) 347{ 348 if(io == -1) { 349 printk(KERN_ERR "You must set an I/O address with io=0x???\n"); 350 return -EINVAL; --- 46 unchanged lines hidden --- |