[media] v4l2: add const to argument of write-only s_frequency ioctl
[deliverable/linux.git] / drivers / media / radio / radio-miropcm20.c
CommitLineData
8366fc39
KH
1/* Miro PCM20 radio driver for Linux radio support
2 * (c) 1998 Ruurd Reitsma <R.A.Reitsma@wbmt.tudelft.nl>
3 * Thanks to Norberto Pellici for the ACI device interface specification
4 * The API part is based on the radiotrack driver by M. Kirkwood
5 * This driver relies on the aci mixer provided by the snd-miro
6 * ALSA driver.
7 * Look there for further info...
8 */
9
10/* What ever you think about the ACI, version 0x07 is not very well!
11 * I can't get frequency, 'tuner status', 'tuner flags' or mute/mono
12 * conditions... Robert
13 */
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/videodev2.h>
18#include <media/v4l2-device.h>
19#include <media/v4l2-ioctl.h>
7f51a610 20#include <media/v4l2-ctrls.h>
f7c096f7
HV
21#include <media/v4l2-fh.h>
22#include <media/v4l2-event.h>
8366fc39
KH
23#include <sound/aci.h>
24
25static int radio_nr = -1;
26module_param(radio_nr, int, 0);
27MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)");
28
8366fc39
KH
29struct pcm20 {
30 struct v4l2_device v4l2_dev;
31 struct video_device vdev;
7f51a610 32 struct v4l2_ctrl_handler ctrl_handler;
8366fc39 33 unsigned long freq;
f5e7cc4a 34 u32 audmode;
8366fc39 35 struct snd_miro_aci *aci;
32958fdd 36 struct mutex lock;
8366fc39
KH
37};
38
39static struct pcm20 pcm20_card = {
f5e7cc4a
HV
40 .freq = 87 * 16000,
41 .audmode = V4L2_TUNER_MODE_STEREO,
8366fc39
KH
42};
43
8366fc39
KH
44static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq)
45{
46 unsigned char freql;
47 unsigned char freqh;
48 struct snd_miro_aci *aci = dev->aci;
49
8366fc39
KH
50 freq /= 160;
51 if (!(aci->aci_version == 0x07 || aci->aci_version >= 0xb0))
52 freq /= 10; /* I don't know exactly which version
53 * needs this hack */
54 freql = freq & 0xff;
55 freqh = freq >> 8;
56
8366fc39
KH
57 return snd_aci_cmd(aci, ACI_WRITE_TUNE, freql, freqh);
58}
59
60static const struct v4l2_file_operations pcm20_fops = {
61 .owner = THIS_MODULE,
f7c096f7
HV
62 .open = v4l2_fh_open,
63 .poll = v4l2_ctrl_poll,
64 .release = v4l2_fh_release,
32958fdd 65 .unlocked_ioctl = video_ioctl2,
8366fc39
KH
66};
67
68static int vidioc_querycap(struct file *file, void *priv,
69 struct v4l2_capability *v)
70{
f122d9a8
HV
71 struct pcm20 *dev = video_drvdata(file);
72
8366fc39
KH
73 strlcpy(v->driver, "Miro PCM20", sizeof(v->driver));
74 strlcpy(v->card, "Miro PCM20", sizeof(v->card));
f122d9a8
HV
75 snprintf(v->bus_info, sizeof(v->bus_info), "ISA:%s", dev->v4l2_dev.name);
76 v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
77 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
8366fc39
KH
78 return 0;
79}
80
81static int vidioc_g_tuner(struct file *file, void *priv,
82 struct v4l2_tuner *v)
83{
f5e7cc4a 84 struct pcm20 *dev = video_drvdata(file);
9bbc5820 85 int res;
f5e7cc4a
HV
86
87 if (v->index)
8366fc39
KH
88 return -EINVAL;
89 strlcpy(v->name, "FM", sizeof(v->name));
90 v->type = V4L2_TUNER_RADIO;
91 v->rangelow = 87*16000;
92 v->rangehigh = 108*16000;
9bbc5820
HV
93 res = snd_aci_cmd(dev->aci, ACI_READ_TUNERSTATION, -1, -1);
94 v->signal = (res & 0x80) ? 0 : 0xffff;
95 /* Note: stereo detection does not work if the audio is muted,
96 it will default to mono in that case. */
97 res = snd_aci_cmd(dev->aci, ACI_READ_TUNERSTEREO, -1, -1);
98 v->rxsubchans = (res & 0x40) ? V4L2_TUNER_SUB_MONO :
99 V4L2_TUNER_SUB_STEREO;
f5e7cc4a
HV
100 v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
101 v->audmode = dev->audmode;
8366fc39
KH
102 return 0;
103}
104
105static int vidioc_s_tuner(struct file *file, void *priv,
106 struct v4l2_tuner *v)
107{
f5e7cc4a
HV
108 struct pcm20 *dev = video_drvdata(file);
109
110 if (v->index)
111 return -EINVAL;
112 if (v->audmode > V4L2_TUNER_MODE_STEREO)
113 v->audmode = V4L2_TUNER_MODE_STEREO;
114 snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO,
115 v->audmode == V4L2_TUNER_MODE_MONO, -1);
116 return 0;
8366fc39
KH
117}
118
119static int vidioc_g_frequency(struct file *file, void *priv,
120 struct v4l2_frequency *f)
121{
122 struct pcm20 *dev = video_drvdata(file);
123
124 if (f->tuner != 0)
125 return -EINVAL;
126
127 f->type = V4L2_TUNER_RADIO;
128 f->frequency = dev->freq;
129 return 0;
130}
131
132
133static int vidioc_s_frequency(struct file *file, void *priv,
b530a447 134 const struct v4l2_frequency *f)
8366fc39
KH
135{
136 struct pcm20 *dev = video_drvdata(file);
137
138 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
139 return -EINVAL;
140
b530a447 141 dev->freq = clamp_t(u32, f->frequency, 87 * 16000U, 108 * 16000U);
f5e7cc4a 142 pcm20_setfreq(dev, dev->freq);
8366fc39
KH
143 return 0;
144}
145
7f51a610 146static int pcm20_s_ctrl(struct v4l2_ctrl *ctrl)
8366fc39 147{
7f51a610 148 struct pcm20 *dev = container_of(ctrl->handler, struct pcm20, ctrl_handler);
8366fc39
KH
149
150 switch (ctrl->id) {
151 case V4L2_CID_AUDIO_MUTE:
f5e7cc4a 152 snd_aci_cmd(dev->aci, ACI_SET_TUNERMUTE, ctrl->val, -1);
7f51a610 153 return 0;
8366fc39 154 }
7f51a610 155 return -EINVAL;
8366fc39
KH
156}
157
8366fc39
KH
158static const struct v4l2_ioctl_ops pcm20_ioctl_ops = {
159 .vidioc_querycap = vidioc_querycap,
160 .vidioc_g_tuner = vidioc_g_tuner,
161 .vidioc_s_tuner = vidioc_s_tuner,
162 .vidioc_g_frequency = vidioc_g_frequency,
163 .vidioc_s_frequency = vidioc_s_frequency,
f7c096f7
HV
164 .vidioc_log_status = v4l2_ctrl_log_status,
165 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
166 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
7f51a610
HV
167};
168
169static const struct v4l2_ctrl_ops pcm20_ctrl_ops = {
170 .s_ctrl = pcm20_s_ctrl,
8366fc39
KH
171};
172
173static int __init pcm20_init(void)
174{
175 struct pcm20 *dev = &pcm20_card;
176 struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
7f51a610 177 struct v4l2_ctrl_handler *hdl;
8366fc39
KH
178 int res;
179
180 dev->aci = snd_aci_get_aci();
181 if (dev->aci == NULL) {
182 v4l2_err(v4l2_dev,
183 "you must load the snd-miro driver first!\n");
184 return -ENODEV;
185 }
f122d9a8 186 strlcpy(v4l2_dev->name, "radio-miropcm20", sizeof(v4l2_dev->name));
32958fdd 187 mutex_init(&dev->lock);
8366fc39
KH
188
189 res = v4l2_device_register(NULL, v4l2_dev);
190 if (res < 0) {
191 v4l2_err(v4l2_dev, "could not register v4l2_device\n");
192 return -EINVAL;
193 }
194
7f51a610
HV
195 hdl = &dev->ctrl_handler;
196 v4l2_ctrl_handler_init(hdl, 1);
197 v4l2_ctrl_new_std(hdl, &pcm20_ctrl_ops,
198 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
199 v4l2_dev->ctrl_handler = hdl;
200 if (hdl->error) {
201 res = hdl->error;
202 v4l2_err(v4l2_dev, "Could not register control\n");
203 goto err_hdl;
204 }
8366fc39
KH
205 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
206 dev->vdev.v4l2_dev = v4l2_dev;
207 dev->vdev.fops = &pcm20_fops;
208 dev->vdev.ioctl_ops = &pcm20_ioctl_ops;
209 dev->vdev.release = video_device_release_empty;
32958fdd 210 dev->vdev.lock = &dev->lock;
f7c096f7 211 set_bit(V4L2_FL_USE_FH_PRIO, &dev->vdev.flags);
8366fc39 212 video_set_drvdata(&dev->vdev, dev);
f5e7cc4a
HV
213 snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO,
214 dev->audmode == V4L2_TUNER_MODE_MONO, -1);
215 pcm20_setfreq(dev, dev->freq);
8366fc39
KH
216
217 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0)
7f51a610 218 goto err_hdl;
8366fc39
KH
219
220 v4l2_info(v4l2_dev, "Mirosound PCM20 Radio tuner\n");
221 return 0;
7f51a610
HV
222err_hdl:
223 v4l2_ctrl_handler_free(hdl);
8366fc39
KH
224 v4l2_device_unregister(v4l2_dev);
225 return -EINVAL;
226}
227
228MODULE_AUTHOR("Ruurd Reitsma, Krzysztof Helt");
229MODULE_DESCRIPTION("A driver for the Miro PCM20 radio card.");
230MODULE_LICENSE("GPL");
231
232static void __exit pcm20_cleanup(void)
233{
234 struct pcm20 *dev = &pcm20_card;
235
236 video_unregister_device(&dev->vdev);
f5e7cc4a 237 snd_aci_cmd(dev->aci, ACI_SET_TUNERMUTE, 1, -1);
7f51a610 238 v4l2_ctrl_handler_free(&dev->ctrl_handler);
8366fc39
KH
239 v4l2_device_unregister(&dev->v4l2_dev);
240}
241
242module_init(pcm20_init);
243module_exit(pcm20_cleanup);
This page took 0.310688 seconds and 5 git commands to generate.