pty: avoid forcing 'low_latency' tty flag
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / i2c / other / tea575x-tuner.c
blobd31c373e076d543a619aa101917a3ef61689e0e8
1 /*
2 * ALSA driver for TEA5757/5759 Philips AM/FM radio tuner chips
4 * Copyright (c) 2004 Jaroslav Kysela <perex@perex.cz>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <asm/io.h>
24 #include <linux/delay.h>
25 #include <linux/interrupt.h>
26 #include <linux/init.h>
27 #include <linux/version.h>
28 #include <sound/core.h>
29 #include <sound/tea575x-tuner.h>
31 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
32 MODULE_DESCRIPTION("Routines for control of TEA5757/5759 Philips AM/FM radio tuner chips");
33 MODULE_LICENSE("GPL");
35 static int radio_nr = -1;
36 module_param(radio_nr, int, 0);
38 #define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
39 #define FREQ_LO (87 * 16000)
40 #define FREQ_HI (108 * 16000)
43 * definitions
46 #define TEA575X_BIT_SEARCH (1<<24) /* 1 = search action, 0 = tuned */
47 #define TEA575X_BIT_UPDOWN (1<<23) /* 0 = search down, 1 = search up */
48 #define TEA575X_BIT_MONO (1<<22) /* 0 = stereo, 1 = mono */
49 #define TEA575X_BIT_BAND_MASK (3<<20)
50 #define TEA575X_BIT_BAND_FM (0<<20)
51 #define TEA575X_BIT_BAND_MW (1<<20)
52 #define TEA575X_BIT_BAND_LW (1<<21)
53 #define TEA575X_BIT_BAND_SW (1<<22)
54 #define TEA575X_BIT_PORT_0 (1<<19) /* user bit */
55 #define TEA575X_BIT_PORT_1 (1<<18) /* user bit */
56 #define TEA575X_BIT_SEARCH_MASK (3<<16) /* search level */
57 #define TEA575X_BIT_SEARCH_5_28 (0<<16) /* FM >5uV, AM >28uV */
58 #define TEA575X_BIT_SEARCH_10_40 (1<<16) /* FM >10uV, AM > 40uV */
59 #define TEA575X_BIT_SEARCH_30_63 (2<<16) /* FM >30uV, AM > 63uV */
60 #define TEA575X_BIT_SEARCH_150_1000 (3<<16) /* FM > 150uV, AM > 1000uV */
61 #define TEA575X_BIT_DUMMY (1<<15) /* buffer */
62 #define TEA575X_BIT_FREQ_MASK 0x7fff
64 static struct v4l2_queryctrl radio_qctrl[] = {
66 .id = V4L2_CID_AUDIO_MUTE,
67 .name = "Mute",
68 .minimum = 0,
69 .maximum = 1,
70 .default_value = 1,
71 .type = V4L2_CTRL_TYPE_BOOLEAN,
76 * lowlevel part
79 static void snd_tea575x_set_freq(struct snd_tea575x *tea)
81 unsigned long freq;
83 freq = tea->freq / 16; /* to kHz */
84 if (freq > 108000)
85 freq = 108000;
86 if (freq < 87000)
87 freq = 87000;
88 /* crystal fixup */
89 if (tea->tea5759)
90 freq -= tea->freq_fixup;
91 else
92 freq += tea->freq_fixup;
93 /* freq /= 12.5 */
94 freq *= 10;
95 freq /= 125;
97 tea->val &= ~TEA575X_BIT_FREQ_MASK;
98 tea->val |= freq & TEA575X_BIT_FREQ_MASK;
99 tea->ops->write(tea, tea->val);
103 * Linux Video interface
106 static int vidioc_querycap(struct file *file, void *priv,
107 struct v4l2_capability *v)
109 struct snd_tea575x *tea = video_drvdata(file);
111 strcpy(v->card, tea->tea5759 ? "TEA5759" : "TEA5757");
112 strlcpy(v->driver, "tea575x-tuner", sizeof(v->driver));
113 strlcpy(v->card, "Maestro Radio", sizeof(v->card));
114 sprintf(v->bus_info, "PCI");
115 v->version = RADIO_VERSION;
116 v->capabilities = V4L2_CAP_TUNER;
117 return 0;
120 static int vidioc_g_tuner(struct file *file, void *priv,
121 struct v4l2_tuner *v)
123 if (v->index > 0)
124 return -EINVAL;
126 strcpy(v->name, "FM");
127 v->type = V4L2_TUNER_RADIO;
128 v->rangelow = FREQ_LO;
129 v->rangehigh = FREQ_HI;
130 v->rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
131 v->capability = V4L2_TUNER_CAP_LOW;
132 v->audmode = V4L2_TUNER_MODE_MONO;
133 v->signal = 0xffff;
134 return 0;
137 static int vidioc_s_tuner(struct file *file, void *priv,
138 struct v4l2_tuner *v)
140 if (v->index > 0)
141 return -EINVAL;
142 return 0;
145 static int vidioc_g_frequency(struct file *file, void *priv,
146 struct v4l2_frequency *f)
148 struct snd_tea575x *tea = video_drvdata(file);
150 f->type = V4L2_TUNER_RADIO;
151 f->frequency = tea->freq;
152 return 0;
155 static int vidioc_s_frequency(struct file *file, void *priv,
156 struct v4l2_frequency *f)
158 struct snd_tea575x *tea = video_drvdata(file);
160 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
161 return -EINVAL;
163 tea->freq = f->frequency;
165 snd_tea575x_set_freq(tea);
167 return 0;
170 static int vidioc_g_audio(struct file *file, void *priv,
171 struct v4l2_audio *a)
173 if (a->index > 1)
174 return -EINVAL;
176 strcpy(a->name, "Radio");
177 a->capability = V4L2_AUDCAP_STEREO;
178 return 0;
181 static int vidioc_s_audio(struct file *file, void *priv,
182 struct v4l2_audio *a)
184 if (a->index != 0)
185 return -EINVAL;
186 return 0;
189 static int vidioc_queryctrl(struct file *file, void *priv,
190 struct v4l2_queryctrl *qc)
192 int i;
194 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
195 if (qc->id && qc->id == radio_qctrl[i].id) {
196 memcpy(qc, &(radio_qctrl[i]),
197 sizeof(*qc));
198 return 0;
201 return -EINVAL;
204 static int vidioc_g_ctrl(struct file *file, void *priv,
205 struct v4l2_control *ctrl)
207 struct snd_tea575x *tea = video_drvdata(file);
209 switch (ctrl->id) {
210 case V4L2_CID_AUDIO_MUTE:
211 if (tea->ops->mute) {
212 ctrl->value = tea->mute;
213 return 0;
216 return -EINVAL;
219 static int vidioc_s_ctrl(struct file *file, void *priv,
220 struct v4l2_control *ctrl)
222 struct snd_tea575x *tea = video_drvdata(file);
224 switch (ctrl->id) {
225 case V4L2_CID_AUDIO_MUTE:
226 if (tea->ops->mute) {
227 tea->ops->mute(tea, ctrl->value);
228 tea->mute = 1;
229 return 0;
232 return -EINVAL;
235 static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
237 *i = 0;
238 return 0;
241 static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
243 if (i != 0)
244 return -EINVAL;
245 return 0;
248 static int snd_tea575x_exclusive_open(struct file *file)
250 struct snd_tea575x *tea = video_drvdata(file);
252 return test_and_set_bit(0, &tea->in_use) ? -EBUSY : 0;
255 static int snd_tea575x_exclusive_release(struct file *file)
257 struct snd_tea575x *tea = video_drvdata(file);
259 clear_bit(0, &tea->in_use);
260 return 0;
263 static const struct v4l2_file_operations tea575x_fops = {
264 .owner = THIS_MODULE,
265 .open = snd_tea575x_exclusive_open,
266 .release = snd_tea575x_exclusive_release,
267 .ioctl = video_ioctl2,
270 static const struct v4l2_ioctl_ops tea575x_ioctl_ops = {
271 .vidioc_querycap = vidioc_querycap,
272 .vidioc_g_tuner = vidioc_g_tuner,
273 .vidioc_s_tuner = vidioc_s_tuner,
274 .vidioc_g_audio = vidioc_g_audio,
275 .vidioc_s_audio = vidioc_s_audio,
276 .vidioc_g_input = vidioc_g_input,
277 .vidioc_s_input = vidioc_s_input,
278 .vidioc_g_frequency = vidioc_g_frequency,
279 .vidioc_s_frequency = vidioc_s_frequency,
280 .vidioc_queryctrl = vidioc_queryctrl,
281 .vidioc_g_ctrl = vidioc_g_ctrl,
282 .vidioc_s_ctrl = vidioc_s_ctrl,
285 static struct video_device tea575x_radio = {
286 .name = "tea575x-tuner",
287 .fops = &tea575x_fops,
288 .ioctl_ops = &tea575x_ioctl_ops,
289 .release = video_device_release,
293 * initialize all the tea575x chips
295 void snd_tea575x_init(struct snd_tea575x *tea)
297 int retval;
298 unsigned int val;
299 struct video_device *tea575x_radio_inst;
301 val = tea->ops->read(tea);
302 if (val == 0x1ffffff || val == 0) {
303 snd_printk(KERN_ERR
304 "tea575x-tuner: Cannot find TEA575x chip\n");
305 return;
308 tea->in_use = 0;
309 tea->val = TEA575X_BIT_BAND_FM | TEA575X_BIT_SEARCH_10_40;
310 tea->freq = 90500 * 16; /* 90.5Mhz default */
312 tea575x_radio_inst = video_device_alloc();
313 if (tea575x_radio_inst == NULL) {
314 printk(KERN_ERR "tea575x-tuner: not enough memory\n");
315 return;
318 memcpy(tea575x_radio_inst, &tea575x_radio, sizeof(tea575x_radio));
320 strcpy(tea575x_radio.name, tea->tea5759 ?
321 "TEA5759 radio" : "TEA5757 radio");
323 video_set_drvdata(tea575x_radio_inst, tea);
325 retval = video_register_device(tea575x_radio_inst,
326 VFL_TYPE_RADIO, radio_nr);
327 if (retval) {
328 printk(KERN_ERR "tea575x-tuner: can't register video device!\n");
329 kfree(tea575x_radio_inst);
330 return;
333 snd_tea575x_set_freq(tea);
335 /* mute on init */
336 if (tea->ops->mute) {
337 tea->ops->mute(tea, 1);
338 tea->mute = 1;
340 tea->vd = tea575x_radio_inst;
343 void snd_tea575x_exit(struct snd_tea575x *tea)
345 if (tea->vd) {
346 video_unregister_device(tea->vd);
347 tea->vd = NULL;
351 static int __init alsa_tea575x_module_init(void)
353 return 0;
356 static void __exit alsa_tea575x_module_exit(void)
360 module_init(alsa_tea575x_module_init)
361 module_exit(alsa_tea575x_module_exit)
363 EXPORT_SYMBOL(snd_tea575x_init);
364 EXPORT_SYMBOL(snd_tea575x_exit);