Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ALSA driver for TEA5757/5759 Philips AM/FM radio tuner chips |
| 3 | * |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 4 | * Copyright (c) 2004 Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 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. Liplianin | 4b29631 | 2008-11-09 15:25:31 -0300 | [diff] [blame] | 21 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/io.h> |
| 24 | #include <linux/delay.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 25 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 28 | #include <linux/version.h> |
Ondrej Zary | 4522e82 | 2011-05-23 09:17:19 -0300 | [diff] [blame] | 29 | #include <media/v4l2-dev.h> |
| 30 | #include <media/v4l2-ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <sound/tea575x-tuner.h> |
| 32 | |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 33 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | MODULE_DESCRIPTION("Routines for control of TEA5757/5759 Philips AM/FM radio tuner chips"); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 37 | static int radio_nr = -1; |
| 38 | module_param(radio_nr, int, 0); |
| 39 | |
| 40 | #define RADIO_VERSION KERNEL_VERSION(0, 0, 2) |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 41 | #define FREQ_LO (50UL * 16000) |
| 42 | #define FREQ_HI (150UL * 16000) |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | /* |
| 45 | * definitions |
| 46 | */ |
| 47 | |
| 48 | #define TEA575X_BIT_SEARCH (1<<24) /* 1 = search action, 0 = tuned */ |
| 49 | #define TEA575X_BIT_UPDOWN (1<<23) /* 0 = search down, 1 = search up */ |
| 50 | #define TEA575X_BIT_MONO (1<<22) /* 0 = stereo, 1 = mono */ |
| 51 | #define TEA575X_BIT_BAND_MASK (3<<20) |
| 52 | #define TEA575X_BIT_BAND_FM (0<<20) |
| 53 | #define TEA575X_BIT_BAND_MW (1<<20) |
| 54 | #define TEA575X_BIT_BAND_LW (1<<21) |
| 55 | #define TEA575X_BIT_BAND_SW (1<<22) |
| 56 | #define TEA575X_BIT_PORT_0 (1<<19) /* user bit */ |
| 57 | #define TEA575X_BIT_PORT_1 (1<<18) /* user bit */ |
| 58 | #define TEA575X_BIT_SEARCH_MASK (3<<16) /* search level */ |
| 59 | #define TEA575X_BIT_SEARCH_5_28 (0<<16) /* FM >5uV, AM >28uV */ |
| 60 | #define TEA575X_BIT_SEARCH_10_40 (1<<16) /* FM >10uV, AM > 40uV */ |
| 61 | #define TEA575X_BIT_SEARCH_30_63 (2<<16) /* FM >30uV, AM > 63uV */ |
| 62 | #define TEA575X_BIT_SEARCH_150_1000 (3<<16) /* FM > 150uV, AM > 1000uV */ |
| 63 | #define TEA575X_BIT_DUMMY (1<<15) /* buffer */ |
| 64 | #define TEA575X_BIT_FREQ_MASK 0x7fff |
| 65 | |
| 66 | /* |
| 67 | * lowlevel part |
| 68 | */ |
| 69 | |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 70 | static void snd_tea575x_write(struct snd_tea575x *tea, unsigned int val) |
| 71 | { |
| 72 | u16 l; |
| 73 | u8 data; |
| 74 | |
| 75 | tea->ops->set_direction(tea, 1); |
| 76 | udelay(16); |
| 77 | |
| 78 | for (l = 25; l > 0; l--) { |
| 79 | data = (val >> 24) & TEA575X_DATA; |
| 80 | val <<= 1; /* shift data */ |
| 81 | tea->ops->set_pins(tea, data | TEA575X_WREN); |
| 82 | udelay(2); |
| 83 | tea->ops->set_pins(tea, data | TEA575X_WREN | TEA575X_CLK); |
| 84 | udelay(2); |
| 85 | tea->ops->set_pins(tea, data | TEA575X_WREN); |
| 86 | udelay(2); |
| 87 | } |
| 88 | |
| 89 | if (!tea->mute) |
| 90 | tea->ops->set_pins(tea, 0); |
| 91 | } |
| 92 | |
| 93 | static unsigned int snd_tea575x_read(struct snd_tea575x *tea) |
| 94 | { |
| 95 | u16 l, rdata; |
| 96 | u32 data = 0; |
| 97 | |
| 98 | tea->ops->set_direction(tea, 0); |
| 99 | tea->ops->set_pins(tea, 0); |
| 100 | udelay(16); |
| 101 | |
| 102 | for (l = 24; l--;) { |
| 103 | tea->ops->set_pins(tea, TEA575X_CLK); |
| 104 | udelay(2); |
| 105 | if (!l) |
| 106 | tea->tuned = tea->ops->get_pins(tea) & TEA575X_MOST ? 0 : 1; |
| 107 | tea->ops->set_pins(tea, 0); |
| 108 | udelay(2); |
| 109 | data <<= 1; /* shift data */ |
| 110 | rdata = tea->ops->get_pins(tea); |
| 111 | if (!l) |
| 112 | tea->stereo = (rdata & TEA575X_MOST) ? 0 : 1; |
| 113 | if (rdata & TEA575X_DATA) |
| 114 | data++; |
| 115 | udelay(2); |
| 116 | } |
| 117 | |
| 118 | if (tea->mute) |
| 119 | tea->ops->set_pins(tea, TEA575X_WREN); |
| 120 | |
| 121 | return data; |
| 122 | } |
| 123 | |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 124 | static void snd_tea575x_get_freq(struct snd_tea575x *tea) |
| 125 | { |
| 126 | unsigned long freq; |
| 127 | |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 128 | freq = snd_tea575x_read(tea) & TEA575X_BIT_FREQ_MASK; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 129 | /* freq *= 12.5 */ |
| 130 | freq *= 125; |
| 131 | freq /= 10; |
| 132 | /* crystal fixup */ |
| 133 | if (tea->tea5759) |
Ondrej Zary | ea27316 | 2011-05-12 22:17:56 +0200 | [diff] [blame] | 134 | freq += TEA575X_FMIF; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 135 | else |
Ondrej Zary | ea27316 | 2011-05-12 22:17:56 +0200 | [diff] [blame] | 136 | freq -= TEA575X_FMIF; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 137 | |
| 138 | tea->freq = freq * 16; /* from kHz */ |
| 139 | } |
| 140 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 141 | static void snd_tea575x_set_freq(struct snd_tea575x *tea) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
| 143 | unsigned long freq; |
| 144 | |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 145 | freq = clamp(tea->freq, FREQ_LO, FREQ_HI); |
| 146 | freq /= 16; /* to kHz */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | /* crystal fixup */ |
| 148 | if (tea->tea5759) |
Ondrej Zary | ea27316 | 2011-05-12 22:17:56 +0200 | [diff] [blame] | 149 | freq -= TEA575X_FMIF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | else |
Ondrej Zary | ea27316 | 2011-05-12 22:17:56 +0200 | [diff] [blame] | 151 | freq += TEA575X_FMIF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* freq /= 12.5 */ |
| 153 | freq *= 10; |
| 154 | freq /= 125; |
| 155 | |
| 156 | tea->val &= ~TEA575X_BIT_FREQ_MASK; |
| 157 | tea->val |= freq & TEA575X_BIT_FREQ_MASK; |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 158 | snd_tea575x_write(tea, tea->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /* |
| 162 | * Linux Video interface |
| 163 | */ |
| 164 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 165 | static int vidioc_querycap(struct file *file, void *priv, |
| 166 | struct v4l2_capability *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 168 | struct snd_tea575x *tea = video_drvdata(file); |
Igor M. Liplianin | 4b29631 | 2008-11-09 15:25:31 -0300 | [diff] [blame] | 169 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 170 | strlcpy(v->driver, "tea575x-tuner", sizeof(v->driver)); |
Ondrej Zary | 10ca720 | 2011-05-12 22:18:22 +0200 | [diff] [blame] | 171 | strlcpy(v->card, tea->card, sizeof(v->card)); |
| 172 | strlcat(v->card, tea->tea5759 ? " TEA5759" : " TEA5757", sizeof(v->card)); |
| 173 | strlcpy(v->bus_info, tea->bus_info, sizeof(v->bus_info)); |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 174 | v->version = RADIO_VERSION; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 175 | v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 176 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 179 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 180 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 182 | struct snd_tea575x *tea = video_drvdata(file); |
| 183 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 184 | if (v->index > 0) |
| 185 | return -EINVAL; |
| 186 | |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 187 | snd_tea575x_read(tea); |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 188 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 189 | strcpy(v->name, "FM"); |
| 190 | v->type = V4L2_TUNER_RADIO; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 191 | v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 192 | v->rangelow = FREQ_LO; |
| 193 | v->rangehigh = FREQ_HI; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 194 | v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; |
| 195 | v->audmode = tea->stereo ? V4L2_TUNER_MODE_STEREO : V4L2_TUNER_MODE_MONO; |
| 196 | v->signal = tea->tuned ? 0xffff : 0; |
| 197 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 202 | struct v4l2_tuner *v) |
| 203 | { |
| 204 | if (v->index > 0) |
| 205 | return -EINVAL; |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 210 | struct v4l2_frequency *f) |
| 211 | { |
| 212 | struct snd_tea575x *tea = video_drvdata(file); |
| 213 | |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 214 | if (f->tuner != 0) |
| 215 | return -EINVAL; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 216 | f->type = V4L2_TUNER_RADIO; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 217 | snd_tea575x_get_freq(tea); |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 218 | f->frequency = tea->freq; |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 223 | struct v4l2_frequency *f) |
| 224 | { |
| 225 | struct snd_tea575x *tea = video_drvdata(file); |
| 226 | |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 227 | if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) |
| 228 | return -EINVAL; |
| 229 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 230 | if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) |
| 231 | return -EINVAL; |
| 232 | |
| 233 | tea->freq = f->frequency; |
| 234 | |
| 235 | snd_tea575x_set_freq(tea); |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | static int vidioc_g_audio(struct file *file, void *priv, |
| 241 | struct v4l2_audio *a) |
| 242 | { |
| 243 | if (a->index > 1) |
| 244 | return -EINVAL; |
| 245 | |
| 246 | strcpy(a->name, "Radio"); |
| 247 | a->capability = V4L2_AUDCAP_STEREO; |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | static int vidioc_s_audio(struct file *file, void *priv, |
| 252 | struct v4l2_audio *a) |
| 253 | { |
| 254 | if (a->index != 0) |
| 255 | return -EINVAL; |
| 256 | return 0; |
| 257 | } |
| 258 | |
Ondrej Zary | 4522e82 | 2011-05-23 09:17:19 -0300 | [diff] [blame] | 259 | static int tea575x_s_ctrl(struct v4l2_ctrl *ctrl) |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 260 | { |
Ondrej Zary | 4522e82 | 2011-05-23 09:17:19 -0300 | [diff] [blame] | 261 | struct snd_tea575x *tea = container_of(ctrl->handler, struct snd_tea575x, ctrl_handler); |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 262 | |
| 263 | switch (ctrl->id) { |
| 264 | case V4L2_CID_AUDIO_MUTE: |
Ondrej Zary | 4522e82 | 2011-05-23 09:17:19 -0300 | [diff] [blame] | 265 | tea->mute = ctrl->val; |
| 266 | snd_tea575x_set_freq(tea); |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 267 | return 0; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 268 | } |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 269 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 270 | return -EINVAL; |
| 271 | } |
| 272 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 273 | static const struct v4l2_file_operations tea575x_fops = { |
| 274 | .owner = THIS_MODULE, |
Ondrej Zary | 6a529c1 | 2011-06-11 10:28:59 -0300 | [diff] [blame] | 275 | .unlocked_ioctl = video_ioctl2, |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 276 | }; |
| 277 | |
| 278 | static const struct v4l2_ioctl_ops tea575x_ioctl_ops = { |
| 279 | .vidioc_querycap = vidioc_querycap, |
| 280 | .vidioc_g_tuner = vidioc_g_tuner, |
| 281 | .vidioc_s_tuner = vidioc_s_tuner, |
| 282 | .vidioc_g_audio = vidioc_g_audio, |
| 283 | .vidioc_s_audio = vidioc_s_audio, |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 284 | .vidioc_g_frequency = vidioc_g_frequency, |
| 285 | .vidioc_s_frequency = vidioc_s_frequency, |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 286 | }; |
| 287 | |
| 288 | static struct video_device tea575x_radio = { |
| 289 | .name = "tea575x-tuner", |
| 290 | .fops = &tea575x_fops, |
| 291 | .ioctl_ops = &tea575x_ioctl_ops, |
Ondrej Zary | 4522e82 | 2011-05-23 09:17:19 -0300 | [diff] [blame] | 292 | .release = video_device_release_empty, |
| 293 | }; |
| 294 | |
| 295 | static const struct v4l2_ctrl_ops tea575x_ctrl_ops = { |
| 296 | .s_ctrl = tea575x_s_ctrl, |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 297 | }; |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | /* |
| 300 | * initialize all the tea575x chips |
| 301 | */ |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 302 | int snd_tea575x_init(struct snd_tea575x *tea) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 304 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 306 | tea->mute = 1; |
| 307 | |
| 308 | snd_tea575x_write(tea, 0x55AA); |
| 309 | if (snd_tea575x_read(tea) != 0x55AA) |
| 310 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | tea->val = TEA575X_BIT_BAND_FM | TEA575X_BIT_SEARCH_10_40; |
| 313 | tea->freq = 90500 * 16; /* 90.5Mhz default */ |
Ondrej Zary | 4522e82 | 2011-05-23 09:17:19 -0300 | [diff] [blame] | 314 | snd_tea575x_set_freq(tea); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Ondrej Zary | 4522e82 | 2011-05-23 09:17:19 -0300 | [diff] [blame] | 316 | tea->vd = tea575x_radio; |
| 317 | video_set_drvdata(&tea->vd, tea); |
Ondrej Zary | 6a529c1 | 2011-06-11 10:28:59 -0300 | [diff] [blame] | 318 | mutex_init(&tea->mutex); |
| 319 | tea->vd.lock = &tea->mutex; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 320 | |
Ondrej Zary | 4522e82 | 2011-05-23 09:17:19 -0300 | [diff] [blame] | 321 | v4l2_ctrl_handler_init(&tea->ctrl_handler, 1); |
| 322 | tea->vd.ctrl_handler = &tea->ctrl_handler; |
| 323 | v4l2_ctrl_new_std(&tea->ctrl_handler, &tea575x_ctrl_ops, V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1); |
| 324 | retval = tea->ctrl_handler.error; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 325 | if (retval) { |
Ondrej Zary | 4522e82 | 2011-05-23 09:17:19 -0300 | [diff] [blame] | 326 | printk(KERN_ERR "tea575x-tuner: can't initialize controls\n"); |
| 327 | v4l2_ctrl_handler_free(&tea->ctrl_handler); |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 328 | return retval; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 329 | } |
| 330 | |
Ondrej Zary | 4522e82 | 2011-05-23 09:17:19 -0300 | [diff] [blame] | 331 | if (tea->ext_init) { |
| 332 | retval = tea->ext_init(tea); |
| 333 | if (retval) { |
| 334 | v4l2_ctrl_handler_free(&tea->ctrl_handler); |
| 335 | return retval; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | v4l2_ctrl_handler_setup(&tea->ctrl_handler); |
| 340 | |
| 341 | retval = video_register_device(&tea->vd, VFL_TYPE_RADIO, radio_nr); |
| 342 | if (retval) { |
| 343 | printk(KERN_ERR "tea575x-tuner: can't register video device!\n"); |
| 344 | v4l2_ctrl_handler_free(&tea->ctrl_handler); |
| 345 | return retval; |
| 346 | } |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 347 | |
| 348 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 351 | void snd_tea575x_exit(struct snd_tea575x *tea) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | { |
Ondrej Zary | 4522e82 | 2011-05-23 09:17:19 -0300 | [diff] [blame] | 353 | video_unregister_device(&tea->vd); |
| 354 | v4l2_ctrl_handler_free(&tea->ctrl_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static int __init alsa_tea575x_module_init(void) |
| 358 | { |
| 359 | return 0; |
| 360 | } |
Igor M. Liplianin | 4b29631 | 2008-11-09 15:25:31 -0300 | [diff] [blame] | 361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | static void __exit alsa_tea575x_module_exit(void) |
| 363 | { |
| 364 | } |
Igor M. Liplianin | 4b29631 | 2008-11-09 15:25:31 -0300 | [diff] [blame] | 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | module_init(alsa_tea575x_module_init) |
| 367 | module_exit(alsa_tea575x_module_exit) |
| 368 | |
| 369 | EXPORT_SYMBOL(snd_tea575x_init); |
| 370 | EXPORT_SYMBOL(snd_tea575x_exit); |