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> |
| 25 | #include <linux/interrupt.h> |
| 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <sound/core.h> |
| 30 | #include <sound/tea575x-tuner.h> |
| 31 | |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 32 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | MODULE_DESCRIPTION("Routines for control of TEA5757/5759 Philips AM/FM radio tuner chips"); |
| 34 | MODULE_LICENSE("GPL"); |
| 35 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 36 | static int radio_nr = -1; |
| 37 | module_param(radio_nr, int, 0); |
| 38 | |
| 39 | #define RADIO_VERSION KERNEL_VERSION(0, 0, 2) |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 40 | #define FREQ_LO (50UL * 16000) |
| 41 | #define FREQ_HI (150UL * 16000) |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /* |
| 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 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 65 | static struct v4l2_queryctrl radio_qctrl[] = { |
| 66 | { |
| 67 | .id = V4L2_CID_AUDIO_MUTE, |
| 68 | .name = "Mute", |
| 69 | .minimum = 0, |
| 70 | .maximum = 1, |
| 71 | .default_value = 1, |
| 72 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 73 | } |
| 74 | }; |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* |
| 77 | * lowlevel part |
| 78 | */ |
| 79 | |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 80 | static void snd_tea575x_write(struct snd_tea575x *tea, unsigned int val) |
| 81 | { |
| 82 | u16 l; |
| 83 | u8 data; |
| 84 | |
| 85 | tea->ops->set_direction(tea, 1); |
| 86 | udelay(16); |
| 87 | |
| 88 | for (l = 25; l > 0; l--) { |
| 89 | data = (val >> 24) & TEA575X_DATA; |
| 90 | val <<= 1; /* shift data */ |
| 91 | tea->ops->set_pins(tea, data | TEA575X_WREN); |
| 92 | udelay(2); |
| 93 | tea->ops->set_pins(tea, data | TEA575X_WREN | TEA575X_CLK); |
| 94 | udelay(2); |
| 95 | tea->ops->set_pins(tea, data | TEA575X_WREN); |
| 96 | udelay(2); |
| 97 | } |
| 98 | |
| 99 | if (!tea->mute) |
| 100 | tea->ops->set_pins(tea, 0); |
| 101 | } |
| 102 | |
| 103 | static unsigned int snd_tea575x_read(struct snd_tea575x *tea) |
| 104 | { |
| 105 | u16 l, rdata; |
| 106 | u32 data = 0; |
| 107 | |
| 108 | tea->ops->set_direction(tea, 0); |
| 109 | tea->ops->set_pins(tea, 0); |
| 110 | udelay(16); |
| 111 | |
| 112 | for (l = 24; l--;) { |
| 113 | tea->ops->set_pins(tea, TEA575X_CLK); |
| 114 | udelay(2); |
| 115 | if (!l) |
| 116 | tea->tuned = tea->ops->get_pins(tea) & TEA575X_MOST ? 0 : 1; |
| 117 | tea->ops->set_pins(tea, 0); |
| 118 | udelay(2); |
| 119 | data <<= 1; /* shift data */ |
| 120 | rdata = tea->ops->get_pins(tea); |
| 121 | if (!l) |
| 122 | tea->stereo = (rdata & TEA575X_MOST) ? 0 : 1; |
| 123 | if (rdata & TEA575X_DATA) |
| 124 | data++; |
| 125 | udelay(2); |
| 126 | } |
| 127 | |
| 128 | if (tea->mute) |
| 129 | tea->ops->set_pins(tea, TEA575X_WREN); |
| 130 | |
| 131 | return data; |
| 132 | } |
| 133 | |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 134 | static void snd_tea575x_get_freq(struct snd_tea575x *tea) |
| 135 | { |
| 136 | unsigned long freq; |
| 137 | |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 138 | freq = snd_tea575x_read(tea) & TEA575X_BIT_FREQ_MASK; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 139 | /* freq *= 12.5 */ |
| 140 | freq *= 125; |
| 141 | freq /= 10; |
| 142 | /* crystal fixup */ |
| 143 | if (tea->tea5759) |
Ondrej Zary | ea27316 | 2011-05-12 22:17:56 +0200 | [diff] [blame^] | 144 | freq += TEA575X_FMIF; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 145 | else |
Ondrej Zary | ea27316 | 2011-05-12 22:17:56 +0200 | [diff] [blame^] | 146 | freq -= TEA575X_FMIF; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 147 | |
| 148 | tea->freq = freq * 16; /* from kHz */ |
| 149 | } |
| 150 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 151 | static void snd_tea575x_set_freq(struct snd_tea575x *tea) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
| 153 | unsigned long freq; |
| 154 | |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 155 | freq = clamp(tea->freq, FREQ_LO, FREQ_HI); |
| 156 | freq /= 16; /* to kHz */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* crystal fixup */ |
| 158 | if (tea->tea5759) |
Ondrej Zary | ea27316 | 2011-05-12 22:17:56 +0200 | [diff] [blame^] | 159 | freq -= TEA575X_FMIF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | else |
Ondrej Zary | ea27316 | 2011-05-12 22:17:56 +0200 | [diff] [blame^] | 161 | freq += TEA575X_FMIF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | /* freq /= 12.5 */ |
| 163 | freq *= 10; |
| 164 | freq /= 125; |
| 165 | |
| 166 | tea->val &= ~TEA575X_BIT_FREQ_MASK; |
| 167 | tea->val |= freq & TEA575X_BIT_FREQ_MASK; |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 168 | snd_tea575x_write(tea, tea->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /* |
| 172 | * Linux Video interface |
| 173 | */ |
| 174 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 175 | static int vidioc_querycap(struct file *file, void *priv, |
| 176 | struct v4l2_capability *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 178 | struct snd_tea575x *tea = video_drvdata(file); |
Igor M. Liplianin | 4b29631 | 2008-11-09 15:25:31 -0300 | [diff] [blame] | 179 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 180 | strlcpy(v->driver, "tea575x-tuner", sizeof(v->driver)); |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 181 | strlcpy(v->card, tea->tea5759 ? "TEA5759" : "TEA5757", sizeof(v->card)); |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 182 | sprintf(v->bus_info, "PCI"); |
| 183 | v->version = RADIO_VERSION; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 184 | v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 185 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 188 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 189 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 191 | struct snd_tea575x *tea = video_drvdata(file); |
| 192 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 193 | if (v->index > 0) |
| 194 | return -EINVAL; |
| 195 | |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 196 | snd_tea575x_read(tea); |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 197 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 198 | strcpy(v->name, "FM"); |
| 199 | v->type = V4L2_TUNER_RADIO; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 200 | v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 201 | v->rangelow = FREQ_LO; |
| 202 | v->rangehigh = FREQ_HI; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 203 | v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; |
| 204 | v->audmode = tea->stereo ? V4L2_TUNER_MODE_STEREO : V4L2_TUNER_MODE_MONO; |
| 205 | v->signal = tea->tuned ? 0xffff : 0; |
| 206 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 211 | struct v4l2_tuner *v) |
| 212 | { |
| 213 | if (v->index > 0) |
| 214 | return -EINVAL; |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 219 | struct v4l2_frequency *f) |
| 220 | { |
| 221 | struct snd_tea575x *tea = video_drvdata(file); |
| 222 | |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 223 | if (f->tuner != 0) |
| 224 | return -EINVAL; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 225 | f->type = V4L2_TUNER_RADIO; |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 226 | snd_tea575x_get_freq(tea); |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 227 | f->frequency = tea->freq; |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 232 | struct v4l2_frequency *f) |
| 233 | { |
| 234 | struct snd_tea575x *tea = video_drvdata(file); |
| 235 | |
Ondrej Zary | 375d135 | 2011-03-19 16:32:53 +0100 | [diff] [blame] | 236 | if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) |
| 237 | return -EINVAL; |
| 238 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 239 | if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) |
| 240 | return -EINVAL; |
| 241 | |
| 242 | tea->freq = f->frequency; |
| 243 | |
| 244 | snd_tea575x_set_freq(tea); |
| 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | static int vidioc_g_audio(struct file *file, void *priv, |
| 250 | struct v4l2_audio *a) |
| 251 | { |
| 252 | if (a->index > 1) |
| 253 | return -EINVAL; |
| 254 | |
| 255 | strcpy(a->name, "Radio"); |
| 256 | a->capability = V4L2_AUDCAP_STEREO; |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static int vidioc_s_audio(struct file *file, void *priv, |
| 261 | struct v4l2_audio *a) |
| 262 | { |
| 263 | if (a->index != 0) |
| 264 | return -EINVAL; |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 269 | struct v4l2_queryctrl *qc) |
| 270 | { |
| 271 | int i; |
| 272 | |
| 273 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { |
| 274 | if (qc->id && qc->id == radio_qctrl[i].id) { |
| 275 | memcpy(qc, &(radio_qctrl[i]), |
| 276 | sizeof(*qc)); |
| 277 | return 0; |
| 278 | } |
| 279 | } |
| 280 | return -EINVAL; |
| 281 | } |
| 282 | |
| 283 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 284 | struct v4l2_control *ctrl) |
| 285 | { |
| 286 | struct snd_tea575x *tea = video_drvdata(file); |
| 287 | |
| 288 | switch (ctrl->id) { |
| 289 | case V4L2_CID_AUDIO_MUTE: |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 290 | ctrl->value = tea->mute; |
| 291 | return 0; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 292 | } |
| 293 | return -EINVAL; |
| 294 | } |
| 295 | |
| 296 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 297 | struct v4l2_control *ctrl) |
| 298 | { |
| 299 | struct snd_tea575x *tea = video_drvdata(file); |
| 300 | |
| 301 | switch (ctrl->id) { |
| 302 | case V4L2_CID_AUDIO_MUTE: |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 303 | if (tea->mute != ctrl->value) { |
Ondrej Zary | 1233faa | 2009-11-27 18:19:28 +0100 | [diff] [blame] | 304 | tea->mute = ctrl->value; |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 305 | snd_tea575x_set_freq(tea); |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 306 | } |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 307 | return 0; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 308 | } |
| 309 | return -EINVAL; |
| 310 | } |
| 311 | |
| 312 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 313 | { |
| 314 | *i = 0; |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 319 | { |
| 320 | if (i != 0) |
| 321 | return -EINVAL; |
| 322 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 325 | static int snd_tea575x_exclusive_open(struct file *file) |
Hans Verkuil | 2f3d002 | 2008-08-23 04:52:00 -0300 | [diff] [blame] | 326 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 327 | struct snd_tea575x *tea = video_drvdata(file); |
Hans Verkuil | 2f3d002 | 2008-08-23 04:52:00 -0300 | [diff] [blame] | 328 | |
| 329 | return test_and_set_bit(0, &tea->in_use) ? -EBUSY : 0; |
| 330 | } |
| 331 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 332 | static int snd_tea575x_exclusive_release(struct file *file) |
Hans Verkuil | 2f3d002 | 2008-08-23 04:52:00 -0300 | [diff] [blame] | 333 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 334 | struct snd_tea575x *tea = video_drvdata(file); |
Hans Verkuil | 2f3d002 | 2008-08-23 04:52:00 -0300 | [diff] [blame] | 335 | |
| 336 | clear_bit(0, &tea->in_use); |
| 337 | return 0; |
| 338 | } |
| 339 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 340 | static const struct v4l2_file_operations tea575x_fops = { |
| 341 | .owner = THIS_MODULE, |
| 342 | .open = snd_tea575x_exclusive_open, |
| 343 | .release = snd_tea575x_exclusive_release, |
| 344 | .ioctl = video_ioctl2, |
| 345 | }; |
| 346 | |
| 347 | static const struct v4l2_ioctl_ops tea575x_ioctl_ops = { |
| 348 | .vidioc_querycap = vidioc_querycap, |
| 349 | .vidioc_g_tuner = vidioc_g_tuner, |
| 350 | .vidioc_s_tuner = vidioc_s_tuner, |
| 351 | .vidioc_g_audio = vidioc_g_audio, |
| 352 | .vidioc_s_audio = vidioc_s_audio, |
| 353 | .vidioc_g_input = vidioc_g_input, |
| 354 | .vidioc_s_input = vidioc_s_input, |
| 355 | .vidioc_g_frequency = vidioc_g_frequency, |
| 356 | .vidioc_s_frequency = vidioc_s_frequency, |
| 357 | .vidioc_queryctrl = vidioc_queryctrl, |
| 358 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 359 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 360 | }; |
| 361 | |
| 362 | static struct video_device tea575x_radio = { |
| 363 | .name = "tea575x-tuner", |
| 364 | .fops = &tea575x_fops, |
| 365 | .ioctl_ops = &tea575x_ioctl_ops, |
| 366 | .release = video_device_release, |
| 367 | }; |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | /* |
| 370 | * initialize all the tea575x chips |
| 371 | */ |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 372 | int snd_tea575x_init(struct snd_tea575x *tea) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | { |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 374 | int retval; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 375 | struct video_device *tea575x_radio_inst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 377 | tea->mute = 1; |
| 378 | |
| 379 | snd_tea575x_write(tea, 0x55AA); |
| 380 | if (snd_tea575x_read(tea) != 0x55AA) |
| 381 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Hans Verkuil | 2f3d002 | 2008-08-23 04:52:00 -0300 | [diff] [blame] | 383 | tea->in_use = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | tea->val = TEA575X_BIT_BAND_FM | TEA575X_BIT_SEARCH_10_40; |
| 385 | tea->freq = 90500 * 16; /* 90.5Mhz default */ |
| 386 | |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 387 | tea575x_radio_inst = video_device_alloc(); |
| 388 | if (tea575x_radio_inst == NULL) { |
| 389 | printk(KERN_ERR "tea575x-tuner: not enough memory\n"); |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 390 | return -ENOMEM; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | memcpy(tea575x_radio_inst, &tea575x_radio, sizeof(tea575x_radio)); |
| 394 | |
| 395 | strcpy(tea575x_radio.name, tea->tea5759 ? |
| 396 | "TEA5759 radio" : "TEA5757 radio"); |
| 397 | |
| 398 | video_set_drvdata(tea575x_radio_inst, tea); |
| 399 | |
| 400 | retval = video_register_device(tea575x_radio_inst, |
| 401 | VFL_TYPE_RADIO, radio_nr); |
| 402 | if (retval) { |
| 403 | printk(KERN_ERR "tea575x-tuner: can't register video device!\n"); |
| 404 | kfree(tea575x_radio_inst); |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 405 | return retval; |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 406 | } |
| 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | snd_tea575x_set_freq(tea); |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 409 | tea->vd = tea575x_radio_inst; |
Ondrej Zary | 14219d0 | 2011-05-09 23:39:26 +0200 | [diff] [blame] | 410 | |
| 411 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 414 | void snd_tea575x_exit(struct snd_tea575x *tea) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
Mauro Carvalho Chehab | 9b76ede | 2009-02-27 11:51:24 -0300 | [diff] [blame] | 416 | if (tea->vd) { |
| 417 | video_unregister_device(tea->vd); |
| 418 | tea->vd = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | |
| 422 | static int __init alsa_tea575x_module_init(void) |
| 423 | { |
| 424 | return 0; |
| 425 | } |
Igor M. Liplianin | 4b29631 | 2008-11-09 15:25:31 -0300 | [diff] [blame] | 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | static void __exit alsa_tea575x_module_exit(void) |
| 428 | { |
| 429 | } |
Igor M. Liplianin | 4b29631 | 2008-11-09 15:25:31 -0300 | [diff] [blame] | 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | module_init(alsa_tea575x_module_init) |
| 432 | module_exit(alsa_tea575x_module_exit) |
| 433 | |
| 434 | EXPORT_SYMBOL(snd_tea575x_init); |
| 435 | EXPORT_SYMBOL(snd_tea575x_exit); |