diff options
Diffstat (limited to 'drivers/media/radio/radio-trust.c')
-rw-r--r-- | drivers/media/radio/radio-trust.c | 188 |
1 files changed, 131 insertions, 57 deletions
diff --git a/drivers/media/radio/radio-trust.c b/drivers/media/radio/radio-trust.c index 8da4badc22b4..bb03ad5a2033 100644 --- a/drivers/media/radio/radio-trust.c +++ b/drivers/media/radio/radio-trust.c | |||
@@ -12,7 +12,7 @@ | |||
12 | * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) | 12 | * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) |
13 | * William McGrath (wmcgrath@twilight.vtc.vsc.edu) | 13 | * William McGrath (wmcgrath@twilight.vtc.vsc.edu) |
14 | * | 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 | */ | 16 | */ |
17 | 17 | ||
18 | #include <stdarg.h> | 18 | #include <stdarg.h> |
@@ -21,9 +21,46 @@ | |||
21 | #include <linux/ioport.h> | 21 | #include <linux/ioport.h> |
22 | #include <asm/io.h> | 22 | #include <asm/io.h> |
23 | #include <asm/uaccess.h> | 23 | #include <asm/uaccess.h> |
24 | #include <linux/videodev.h> | 24 | #include <linux/videodev2.h> |
25 | #include <media/v4l2-common.h> | 25 | #include <media/v4l2-common.h> |
26 | #include <linux/config.h> /* CONFIG_RADIO_TRUST_PORT */ | 26 | |
27 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ | ||
28 | #define RADIO_VERSION KERNEL_VERSION(0,0,2) | ||
29 | |||
30 | static 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 | }; | ||
27 | 64 | ||
28 | /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ | 65 | /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ |
29 | 66 | ||
@@ -160,88 +197,125 @@ static int tr_do_ioctl(struct inode *inode, struct file *file, | |||
160 | { | 197 | { |
161 | switch(cmd) | 198 | switch(cmd) |
162 | { | 199 | { |
163 | case VIDIOCGCAP: | 200 | case VIDIOC_QUERYCAP: |
164 | { | 201 | { |
165 | struct video_capability *v = arg; | 202 | struct v4l2_capability *v = arg; |
166 | |||
167 | memset(v,0,sizeof(*v)); | 203 | memset(v,0,sizeof(*v)); |
168 | v->type=VID_TYPE_TUNER; | 204 | strlcpy(v->driver, "radio-trust", sizeof (v->driver)); |
169 | v->channels=1; | 205 | strlcpy(v->card, "Trust FM Radio", sizeof (v->card)); |
170 | v->audios=1; | 206 | sprintf(v->bus_info,"ISA"); |
171 | strcpy(v->name, "Trust FM Radio"); | 207 | v->version = RADIO_VERSION; |
208 | v->capabilities = V4L2_CAP_TUNER; | ||
172 | 209 | ||
173 | return 0; | 210 | return 0; |
174 | } | 211 | } |
175 | case VIDIOCGTUNER: | 212 | case VIDIOC_G_TUNER: |
176 | { | 213 | { |
177 | struct video_tuner *v = arg; | 214 | struct v4l2_tuner *v = arg; |
178 | 215 | ||
179 | if(v->tuner) /* Only 1 tuner */ | 216 | if (v->index > 0) |
180 | return -EINVAL; | 217 | return -EINVAL; |
181 | 218 | ||
182 | v->rangelow = 87500 * 16; | 219 | memset(v,0,sizeof(*v)); |
183 | v->rangehigh = 108000 * 16; | 220 | strcpy(v->name, "FM"); |
184 | v->flags = VIDEO_TUNER_LOW; | 221 | v->type = V4L2_TUNER_RADIO; |
185 | v->mode = VIDEO_MODE_AUTO; | ||
186 | 222 | ||
187 | 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; | ||
188 | if(tr_getstereo()) | 227 | if(tr_getstereo()) |
189 | v->flags |= VIDEO_TUNER_STEREO_ON; | 228 | v->audmode = V4L2_TUNER_MODE_STEREO; |
190 | 229 | else | |
191 | strcpy(v->name, "FM"); | 230 | v->audmode = V4L2_TUNER_MODE_MONO; |
231 | v->signal=tr_getsigstr(); | ||
192 | 232 | ||
193 | return 0; | 233 | return 0; |
194 | } | 234 | } |
195 | case VIDIOCSTUNER: | 235 | case VIDIOC_S_TUNER: |
196 | { | 236 | { |
197 | struct video_tuner *v = arg; | 237 | struct v4l2_tuner *v = arg; |
198 | if(v->tuner != 0) | 238 | |
239 | if (v->index > 0) | ||
199 | return -EINVAL; | 240 | return -EINVAL; |
241 | |||
200 | return 0; | 242 | return 0; |
201 | } | 243 | } |
202 | case VIDIOCGFREQ: | 244 | case VIDIOC_S_FREQUENCY: |
203 | { | 245 | { |
204 | unsigned long *freq = arg; | 246 | struct v4l2_frequency *f = arg; |
205 | *freq = curfreq; | 247 | |
248 | curfreq = f->frequency; | ||
249 | tr_setfreq(curfreq); | ||
206 | return 0; | 250 | return 0; |
207 | } | 251 | } |
208 | case VIDIOCSFREQ: | 252 | case VIDIOC_G_FREQUENCY: |
209 | { | 253 | { |
210 | unsigned long *freq = arg; | 254 | struct v4l2_frequency *f = arg; |
211 | tr_setfreq(*freq); | 255 | |
256 | f->type = V4L2_TUNER_RADIO; | ||
257 | f->frequency = curfreq; | ||
258 | |||
212 | return 0; | 259 | return 0; |
213 | } | 260 | } |
214 | case VIDIOCGAUDIO: | 261 | case VIDIOC_QUERYCTRL: |
215 | { | 262 | { |
216 | struct video_audio *v = arg; | 263 | struct v4l2_queryctrl *qc = arg; |
217 | 264 | int i; | |
218 | memset(v,0, sizeof(*v)); | 265 | |
219 | v->flags = VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME | | 266 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { |
220 | VIDEO_AUDIO_BASS | VIDEO_AUDIO_TREBLE; | 267 | if (qc->id && qc->id == radio_qctrl[i].id) { |
221 | v->mode = curstereo? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO; | 268 | memcpy(qc, &(radio_qctrl[i]), |
222 | v->volume = curvol * 2048; | 269 | sizeof(*qc)); |
223 | v->step = 2048; | 270 | return (0); |
224 | v->bass = curbass * 4370; | 271 | } |
225 | v->treble = curtreble * 4370; | 272 | } |
226 | 273 | return -EINVAL; | |
227 | strcpy(v->name, "Trust FM Radio"); | ||
228 | return 0; | ||
229 | } | 274 | } |
230 | case VIDIOCSAUDIO: | 275 | case VIDIOC_G_CTRL: |
231 | { | 276 | { |
232 | struct video_audio *v = arg; | 277 | struct v4l2_control *ctrl= arg; |
233 | 278 | ||
234 | if(v->audio) | 279 | switch (ctrl->id) { |
235 | return -EINVAL; | 280 | case V4L2_CID_AUDIO_MUTE: |
236 | tr_setvol(v->volume); | 281 | ctrl->value=curmute; |
237 | tr_setbass(v->bass); | 282 | return (0); |
238 | tr_settreble(v->treble); | 283 | case V4L2_CID_AUDIO_VOLUME: |
239 | tr_setstereo(v->mode & VIDEO_SOUND_STEREO); | 284 | ctrl->value= curvol * 2048; |
240 | tr_setmute(v->flags & VIDEO_AUDIO_MUTE); | 285 | return (0); |
241 | 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; | ||
242 | } | 294 | } |
295 | case VIDIOC_S_CTRL: | ||
296 | { | ||
297 | struct v4l2_control *ctrl= arg; | ||
298 | |||
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; | ||
314 | } | ||
315 | |||
243 | default: | 316 | default: |
244 | return -ENOIOCTLCMD; | 317 | return v4l_compat_translate_ioctl(inode,file,cmd,arg, |
318 | tr_do_ioctl); | ||
245 | } | 319 | } |
246 | } | 320 | } |
247 | 321 | ||
@@ -265,7 +339,7 @@ static struct video_device trust_radio= | |||
265 | .owner = THIS_MODULE, | 339 | .owner = THIS_MODULE, |
266 | .name = "Trust FM Radio", | 340 | .name = "Trust FM Radio", |
267 | .type = VID_TYPE_TUNER, | 341 | .type = VID_TYPE_TUNER, |
268 | .hardware = VID_HARDWARE_TRUST, | 342 | .hardware = 0, |
269 | .fops = &trust_fops, | 343 | .fops = &trust_fops, |
270 | }; | 344 | }; |
271 | 345 | ||