blob: d14edb7d6484a1963cd9ae0c4b61750a349bfbf0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ALSA driver for TEA5757/5759 Philips AM/FM radio tuner chips
3 *
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02004 * Copyright (c) 2004 Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 *
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.
11 *
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.
16 *
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
20 *
Igor M. Liplianin4b296312008-11-09 15:25:31 -030021 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/io.h>
24#include <linux/delay.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040025#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
Hans Verkuild4ecc832012-02-27 05:30:13 -030028#include <linux/sched.h>
29#include <media/v4l2-device.h>
Ondrej Zary4522e822011-05-23 09:17:19 -030030#include <media/v4l2-dev.h>
Hans Verkuild4ecc832012-02-27 05:30:13 -030031#include <media/v4l2-fh.h>
Ondrej Zary4522e822011-05-23 09:17:19 -030032#include <media/v4l2-ioctl.h>
Hans Verkuild4ecc832012-02-27 05:30:13 -030033#include <media/v4l2-event.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <sound/tea575x-tuner.h>
35
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020036MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070037MODULE_DESCRIPTION("Routines for control of TEA5757/5759 Philips AM/FM radio tuner chips");
38MODULE_LICENSE("GPL");
39
Hans de Goede0875eb72012-05-18 15:01:36 -030040#define FREQ_LO ((tea->tea5759 ? 760 : 875) * 1600U)
41#define FREQ_HI ((tea->tea5759 ? 910 : 1080) * 1600U)
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -030042
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/*
44 * definitions
45 */
46
47#define TEA575X_BIT_SEARCH (1<<24) /* 1 = search action, 0 = tuned */
48#define TEA575X_BIT_UPDOWN (1<<23) /* 0 = search down, 1 = search up */
49#define TEA575X_BIT_MONO (1<<22) /* 0 = stereo, 1 = mono */
50#define TEA575X_BIT_BAND_MASK (3<<20)
51#define TEA575X_BIT_BAND_FM (0<<20)
52#define TEA575X_BIT_BAND_MW (1<<20)
53#define TEA575X_BIT_BAND_LW (1<<21)
54#define TEA575X_BIT_BAND_SW (1<<22)
55#define TEA575X_BIT_PORT_0 (1<<19) /* user bit */
56#define TEA575X_BIT_PORT_1 (1<<18) /* user bit */
57#define TEA575X_BIT_SEARCH_MASK (3<<16) /* search level */
58#define TEA575X_BIT_SEARCH_5_28 (0<<16) /* FM >5uV, AM >28uV */
59#define TEA575X_BIT_SEARCH_10_40 (1<<16) /* FM >10uV, AM > 40uV */
60#define TEA575X_BIT_SEARCH_30_63 (2<<16) /* FM >30uV, AM > 63uV */
61#define TEA575X_BIT_SEARCH_150_1000 (3<<16) /* FM > 150uV, AM > 1000uV */
62#define TEA575X_BIT_DUMMY (1<<15) /* buffer */
63#define TEA575X_BIT_FREQ_MASK 0x7fff
64
65/*
66 * lowlevel part
67 */
68
Ondrej Zary14219d02011-05-09 23:39:26 +020069static void snd_tea575x_write(struct snd_tea575x *tea, unsigned int val)
70{
71 u16 l;
72 u8 data;
73
Hans de Goede31a62d42012-05-18 09:36:17 -030074 if (tea->ops->write_val)
75 return tea->ops->write_val(tea, val);
76
Ondrej Zary14219d02011-05-09 23:39:26 +020077 tea->ops->set_direction(tea, 1);
78 udelay(16);
79
80 for (l = 25; l > 0; l--) {
81 data = (val >> 24) & TEA575X_DATA;
82 val <<= 1; /* shift data */
83 tea->ops->set_pins(tea, data | TEA575X_WREN);
84 udelay(2);
85 tea->ops->set_pins(tea, data | TEA575X_WREN | TEA575X_CLK);
86 udelay(2);
87 tea->ops->set_pins(tea, data | TEA575X_WREN);
88 udelay(2);
89 }
90
91 if (!tea->mute)
92 tea->ops->set_pins(tea, 0);
93}
94
Hans Verkuilbc2b3952012-02-27 05:31:58 -030095static u32 snd_tea575x_read(struct snd_tea575x *tea)
Ondrej Zary14219d02011-05-09 23:39:26 +020096{
97 u16 l, rdata;
98 u32 data = 0;
99
Hans de Goede31a62d42012-05-18 09:36:17 -0300100 if (tea->ops->read_val)
101 return tea->ops->read_val(tea);
102
Ondrej Zary14219d02011-05-09 23:39:26 +0200103 tea->ops->set_direction(tea, 0);
104 tea->ops->set_pins(tea, 0);
105 udelay(16);
106
107 for (l = 24; l--;) {
108 tea->ops->set_pins(tea, TEA575X_CLK);
109 udelay(2);
110 if (!l)
111 tea->tuned = tea->ops->get_pins(tea) & TEA575X_MOST ? 0 : 1;
112 tea->ops->set_pins(tea, 0);
113 udelay(2);
114 data <<= 1; /* shift data */
115 rdata = tea->ops->get_pins(tea);
116 if (!l)
117 tea->stereo = (rdata & TEA575X_MOST) ? 0 : 1;
118 if (rdata & TEA575X_DATA)
119 data++;
120 udelay(2);
121 }
122
123 if (tea->mute)
124 tea->ops->set_pins(tea, TEA575X_WREN);
125
126 return data;
127}
128
Hans de Goede40e006a2012-05-19 11:19:06 -0300129static u32 snd_tea575x_val_to_freq(struct snd_tea575x *tea, u32 val)
Hans Verkuilbc2b3952012-02-27 05:31:58 -0300130{
Hans de Goede40e006a2012-05-19 11:19:06 -0300131 u32 freq = val & TEA575X_BIT_FREQ_MASK;
Hans Verkuilbc2b3952012-02-27 05:31:58 -0300132
133 if (freq == 0)
134 return freq;
135
136 /* freq *= 12.5 */
137 freq *= 125;
138 freq /= 10;
139 /* crystal fixup */
140 if (tea->tea5759)
141 freq += TEA575X_FMIF;
142 else
143 freq -= TEA575X_FMIF;
144
145 return clamp(freq * 16, FREQ_LO, FREQ_HI); /* from kHz */
146}
147
Hans de Goede40e006a2012-05-19 11:19:06 -0300148static u32 snd_tea575x_get_freq(struct snd_tea575x *tea)
149{
150 return snd_tea575x_val_to_freq(tea, snd_tea575x_read(tea));
151}
152
Takashi Iwai97f02e02005-11-17 14:17:19 +0100153static void snd_tea575x_set_freq(struct snd_tea575x *tea)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Hans Verkuild4ecc832012-02-27 05:30:13 -0300155 u32 freq = tea->freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Ondrej Zary375d1352011-03-19 16:32:53 +0100157 freq /= 16; /* to kHz */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 /* crystal fixup */
159 if (tea->tea5759)
Ondrej Zaryea273162011-05-12 22:17:56 +0200160 freq -= TEA575X_FMIF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 else
Ondrej Zaryea273162011-05-12 22:17:56 +0200162 freq += TEA575X_FMIF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /* freq /= 12.5 */
164 freq *= 10;
165 freq /= 125;
166
167 tea->val &= ~TEA575X_BIT_FREQ_MASK;
168 tea->val |= freq & TEA575X_BIT_FREQ_MASK;
Ondrej Zary14219d02011-05-09 23:39:26 +0200169 snd_tea575x_write(tea, tea->val);
Hans de Goede40e006a2012-05-19 11:19:06 -0300170 tea->freq = snd_tea575x_val_to_freq(tea, tea->val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
173/*
174 * Linux Video interface
175 */
176
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300177static int vidioc_querycap(struct file *file, void *priv,
178 struct v4l2_capability *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300180 struct snd_tea575x *tea = video_drvdata(file);
Igor M. Liplianin4b296312008-11-09 15:25:31 -0300181
Hans Verkuild4ecc832012-02-27 05:30:13 -0300182 strlcpy(v->driver, tea->v4l2_dev->name, sizeof(v->driver));
Ondrej Zary10ca7202011-05-12 22:18:22 +0200183 strlcpy(v->card, tea->card, sizeof(v->card));
184 strlcat(v->card, tea->tea5759 ? " TEA5759" : " TEA5757", sizeof(v->card));
185 strlcpy(v->bus_info, tea->bus_info, sizeof(v->bus_info));
Hans Verkuild4ecc832012-02-27 05:30:13 -0300186 v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
187 if (!tea->cannot_read_data)
188 v->device_caps |= V4L2_CAP_HW_FREQ_SEEK;
189 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300190 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
192
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300193static int vidioc_g_tuner(struct file *file, void *priv,
194 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Ondrej Zary375d1352011-03-19 16:32:53 +0100196 struct snd_tea575x *tea = video_drvdata(file);
197
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300198 if (v->index > 0)
199 return -EINVAL;
200
Ondrej Zary14219d02011-05-09 23:39:26 +0200201 snd_tea575x_read(tea);
Ondrej Zary375d1352011-03-19 16:32:53 +0100202
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300203 strcpy(v->name, "FM");
204 v->type = V4L2_TUNER_RADIO;
Ondrej Zary375d1352011-03-19 16:32:53 +0100205 v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
Hans Verkuil54f60192012-05-27 07:25:06 -0300206 if (!tea->cannot_read_data)
207 v->capability |= V4L2_TUNER_CAP_HWSEEK_BOUNDED;
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300208 v->rangelow = FREQ_LO;
209 v->rangehigh = FREQ_HI;
Hans Verkuild4ecc832012-02-27 05:30:13 -0300210 v->rxsubchans = tea->stereo ? V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
211 v->audmode = (tea->val & TEA575X_BIT_MONO) ?
212 V4L2_TUNER_MODE_MONO : V4L2_TUNER_MODE_STEREO;
Ondrej Zary375d1352011-03-19 16:32:53 +0100213 v->signal = tea->tuned ? 0xffff : 0;
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300214 return 0;
215}
216
217static int vidioc_s_tuner(struct file *file, void *priv,
218 struct v4l2_tuner *v)
219{
Hans Verkuild4ecc832012-02-27 05:30:13 -0300220 struct snd_tea575x *tea = video_drvdata(file);
221
222 if (v->index)
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300223 return -EINVAL;
Hans Verkuild4ecc832012-02-27 05:30:13 -0300224 tea->val &= ~TEA575X_BIT_MONO;
225 if (v->audmode == V4L2_TUNER_MODE_MONO)
226 tea->val |= TEA575X_BIT_MONO;
227 snd_tea575x_write(tea, tea->val);
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300228 return 0;
229}
230
231static int vidioc_g_frequency(struct file *file, void *priv,
232 struct v4l2_frequency *f)
233{
234 struct snd_tea575x *tea = video_drvdata(file);
235
Ondrej Zary375d1352011-03-19 16:32:53 +0100236 if (f->tuner != 0)
237 return -EINVAL;
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300238 f->type = V4L2_TUNER_RADIO;
239 f->frequency = tea->freq;
240 return 0;
241}
242
243static int vidioc_s_frequency(struct file *file, void *priv,
244 struct v4l2_frequency *f)
245{
246 struct snd_tea575x *tea = video_drvdata(file);
247
Ondrej Zary375d1352011-03-19 16:32:53 +0100248 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
249 return -EINVAL;
250
Hans Verkuild4ecc832012-02-27 05:30:13 -0300251 tea->val &= ~TEA575X_BIT_SEARCH;
252 tea->freq = clamp(f->frequency, FREQ_LO, FREQ_HI);
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300253 snd_tea575x_set_freq(tea);
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300254 return 0;
255}
256
Hans Verkuild4ecc832012-02-27 05:30:13 -0300257static int vidioc_s_hw_freq_seek(struct file *file, void *fh,
258 struct v4l2_hw_freq_seek *a)
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300259{
Hans Verkuild4ecc832012-02-27 05:30:13 -0300260 struct snd_tea575x *tea = video_drvdata(file);
Hans Verkuilbc2b3952012-02-27 05:31:58 -0300261 unsigned long timeout;
262 int i;
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300263
Hans Verkuild4ecc832012-02-27 05:30:13 -0300264 if (tea->cannot_read_data)
265 return -ENOTTY;
266 if (a->tuner || a->wrap_around)
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300267 return -EINVAL;
Hans Verkuilbc2b3952012-02-27 05:31:58 -0300268
269 /* clear the frequency, HW will fill it in */
270 tea->val &= ~TEA575X_BIT_FREQ_MASK;
Hans Verkuild4ecc832012-02-27 05:30:13 -0300271 tea->val |= TEA575X_BIT_SEARCH;
Hans Verkuild4ecc832012-02-27 05:30:13 -0300272 if (a->seek_upward)
273 tea->val |= TEA575X_BIT_UPDOWN;
Hans Verkuilbc2b3952012-02-27 05:31:58 -0300274 else
275 tea->val &= ~TEA575X_BIT_UPDOWN;
Hans Verkuild4ecc832012-02-27 05:30:13 -0300276 snd_tea575x_write(tea, tea->val);
Hans Verkuilbc2b3952012-02-27 05:31:58 -0300277 timeout = jiffies + msecs_to_jiffies(10000);
Hans Verkuild4ecc832012-02-27 05:30:13 -0300278 for (;;) {
Hans Verkuilbc2b3952012-02-27 05:31:58 -0300279 if (time_after(jiffies, timeout))
280 break;
Hans Verkuild4ecc832012-02-27 05:30:13 -0300281 if (schedule_timeout_interruptible(msecs_to_jiffies(10))) {
282 /* some signal arrived, stop search */
283 tea->val &= ~TEA575X_BIT_SEARCH;
Hans Verkuilbc2b3952012-02-27 05:31:58 -0300284 snd_tea575x_set_freq(tea);
Hans Verkuild4ecc832012-02-27 05:30:13 -0300285 return -ERESTARTSYS;
286 }
Hans Verkuilbc2b3952012-02-27 05:31:58 -0300287 if (!(snd_tea575x_read(tea) & TEA575X_BIT_SEARCH)) {
288 u32 freq;
289
290 /* Found a frequency, wait until it can be read */
291 for (i = 0; i < 100; i++) {
292 msleep(10);
293 freq = snd_tea575x_get_freq(tea);
294 if (freq) /* available */
295 break;
296 }
297 if (freq == 0) /* shouldn't happen */
298 break;
299 /*
300 * if we moved by less than 50 kHz, or in the wrong
301 * direction, continue seeking
302 */
303 if (abs(tea->freq - freq) < 16 * 50 ||
304 (a->seek_upward && freq < tea->freq) ||
305 (!a->seek_upward && freq > tea->freq)) {
306 snd_tea575x_write(tea, tea->val);
307 continue;
308 }
309 tea->freq = freq;
310 tea->val &= ~TEA575X_BIT_SEARCH;
311 return 0;
312 }
Hans Verkuild4ecc832012-02-27 05:30:13 -0300313 }
Hans Verkuilbc2b3952012-02-27 05:31:58 -0300314 tea->val &= ~TEA575X_BIT_SEARCH;
315 snd_tea575x_set_freq(tea);
Hans Verkuil54f60192012-05-27 07:25:06 -0300316 return -ENODATA;
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300317}
318
Ondrej Zary4522e822011-05-23 09:17:19 -0300319static int tea575x_s_ctrl(struct v4l2_ctrl *ctrl)
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300320{
Ondrej Zary4522e822011-05-23 09:17:19 -0300321 struct snd_tea575x *tea = container_of(ctrl->handler, struct snd_tea575x, ctrl_handler);
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300322
323 switch (ctrl->id) {
324 case V4L2_CID_AUDIO_MUTE:
Ondrej Zary4522e822011-05-23 09:17:19 -0300325 tea->mute = ctrl->val;
326 snd_tea575x_set_freq(tea);
Ondrej Zary14219d02011-05-09 23:39:26 +0200327 return 0;
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300328 }
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300329
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300330 return -EINVAL;
331}
332
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300333static const struct v4l2_file_operations tea575x_fops = {
Ondrej Zary6a529c12011-06-11 10:28:59 -0300334 .unlocked_ioctl = video_ioctl2,
Hans Verkuild4ecc832012-02-27 05:30:13 -0300335 .open = v4l2_fh_open,
336 .release = v4l2_fh_release,
337 .poll = v4l2_ctrl_poll,
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300338};
339
340static const struct v4l2_ioctl_ops tea575x_ioctl_ops = {
341 .vidioc_querycap = vidioc_querycap,
342 .vidioc_g_tuner = vidioc_g_tuner,
343 .vidioc_s_tuner = vidioc_s_tuner,
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300344 .vidioc_g_frequency = vidioc_g_frequency,
345 .vidioc_s_frequency = vidioc_s_frequency,
Hans Verkuild4ecc832012-02-27 05:30:13 -0300346 .vidioc_s_hw_freq_seek = vidioc_s_hw_freq_seek,
347 .vidioc_log_status = v4l2_ctrl_log_status,
348 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
349 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300350};
351
Hans Verkuild4ecc832012-02-27 05:30:13 -0300352static const struct video_device tea575x_radio = {
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300353 .ioctl_ops = &tea575x_ioctl_ops,
Hans Verkuild4ecc832012-02-27 05:30:13 -0300354 .release = video_device_release_empty,
Ondrej Zary4522e822011-05-23 09:17:19 -0300355};
356
357static const struct v4l2_ctrl_ops tea575x_ctrl_ops = {
358 .s_ctrl = tea575x_s_ctrl,
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300359};
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361/*
362 * initialize all the tea575x chips
363 */
Hans de Goede5daf53a2012-05-19 07:57:03 -0300364int snd_tea575x_init(struct snd_tea575x *tea, struct module *owner)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300366 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Hans Verkuild4ecc832012-02-27 05:30:13 -0300368 tea->mute = true;
Ondrej Zary14219d02011-05-09 23:39:26 +0200369
Hans Verkuild4ecc832012-02-27 05:30:13 -0300370 /* Not all devices can or know how to read the data back.
371 Such devices can set cannot_read_data to true. */
372 if (!tea->cannot_read_data) {
373 snd_tea575x_write(tea, 0x55AA);
374 if (snd_tea575x_read(tea) != 0x55AA)
375 return -ENODEV;
376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Hans Verkuilbc2b3952012-02-27 05:31:58 -0300378 tea->val = TEA575X_BIT_BAND_FM | TEA575X_BIT_SEARCH_5_28;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 tea->freq = 90500 * 16; /* 90.5Mhz default */
Ondrej Zary4522e822011-05-23 09:17:19 -0300380 snd_tea575x_set_freq(tea);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Ondrej Zary4522e822011-05-23 09:17:19 -0300382 tea->vd = tea575x_radio;
383 video_set_drvdata(&tea->vd, tea);
Ondrej Zary6a529c12011-06-11 10:28:59 -0300384 mutex_init(&tea->mutex);
Hans Verkuild4ecc832012-02-27 05:30:13 -0300385 strlcpy(tea->vd.name, tea->v4l2_dev->name, sizeof(tea->vd.name));
Ondrej Zary6a529c12011-06-11 10:28:59 -0300386 tea->vd.lock = &tea->mutex;
Hans Verkuild4ecc832012-02-27 05:30:13 -0300387 tea->vd.v4l2_dev = tea->v4l2_dev;
Hans de Goede5daf53a2012-05-19 07:57:03 -0300388 tea->fops = tea575x_fops;
389 tea->fops.owner = owner;
390 tea->vd.fops = &tea->fops;
Hans Verkuild4ecc832012-02-27 05:30:13 -0300391 set_bit(V4L2_FL_USE_FH_PRIO, &tea->vd.flags);
Hans Verkuil65397992012-05-10 03:16:14 -0300392 /* disable hw_freq_seek if we can't use it */
393 if (tea->cannot_read_data)
Hans Verkuil152a3a72012-05-14 11:32:48 -0300394 v4l2_disable_ioctl(&tea->vd, VIDIOC_S_HW_FREQ_SEEK);
Mauro Carvalho Chehab9b76ede2009-02-27 11:51:24 -0300395
Hans de Goede3d0fe512012-05-18 12:21:57 -0300396 if (!tea->cannot_mute) {
397 tea->vd.ctrl_handler = &tea->ctrl_handler;
398 v4l2_ctrl_handler_init(&tea->ctrl_handler, 1);
399 v4l2_ctrl_new_std(&tea->ctrl_handler, &tea575x_ctrl_ops,
400 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
401 retval = tea->ctrl_handler.error;
Ondrej Zary4522e822011-05-23 09:17:19 -0300402 if (retval) {
Hans de Goede3d0fe512012-05-18 12:21:57 -0300403 v4l2_err(tea->v4l2_dev, "can't initialize controls\n");
Ondrej Zary4522e822011-05-23 09:17:19 -0300404 v4l2_ctrl_handler_free(&tea->ctrl_handler);
405 return retval;
406 }
Ondrej Zary4522e822011-05-23 09:17:19 -0300407
Hans de Goede3d0fe512012-05-18 12:21:57 -0300408 if (tea->ext_init) {
409 retval = tea->ext_init(tea);
410 if (retval) {
411 v4l2_ctrl_handler_free(&tea->ctrl_handler);
412 return retval;
413 }
414 }
415
416 v4l2_ctrl_handler_setup(&tea->ctrl_handler);
417 }
Ondrej Zary4522e822011-05-23 09:17:19 -0300418
Hans Verkuild4ecc832012-02-27 05:30:13 -0300419 retval = video_register_device(&tea->vd, VFL_TYPE_RADIO, tea->radio_nr);
Ondrej Zary4522e822011-05-23 09:17:19 -0300420 if (retval) {
Hans Verkuild4ecc832012-02-27 05:30:13 -0300421 v4l2_err(tea->v4l2_dev, "can't register video device!\n");
Hans de Goede3d0fe512012-05-18 12:21:57 -0300422 v4l2_ctrl_handler_free(tea->vd.ctrl_handler);
Ondrej Zary4522e822011-05-23 09:17:19 -0300423 return retval;
424 }
Ondrej Zary14219d02011-05-09 23:39:26 +0200425
426 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
Takashi Iwai97f02e02005-11-17 14:17:19 +0100429void snd_tea575x_exit(struct snd_tea575x *tea)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Ondrej Zary4522e822011-05-23 09:17:19 -0300431 video_unregister_device(&tea->vd);
Hans de Goede3d0fe512012-05-18 12:21:57 -0300432 v4l2_ctrl_handler_free(tea->vd.ctrl_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433}
434
435static int __init alsa_tea575x_module_init(void)
436{
437 return 0;
438}
Igor M. Liplianin4b296312008-11-09 15:25:31 -0300439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440static void __exit alsa_tea575x_module_exit(void)
441{
442}
Igor M. Liplianin4b296312008-11-09 15:25:31 -0300443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444module_init(alsa_tea575x_module_init)
445module_exit(alsa_tea575x_module_exit)
446
447EXPORT_SYMBOL(snd_tea575x_init);
448EXPORT_SYMBOL(snd_tea575x_exit);