Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 1 | /* |
| 2 | Auvitek AU8522 QAM/8VSB demodulator driver |
| 3 | |
Steven Toth | 6d89761 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 4 | Copyright (C) 2008 Steven Toth <stoth@linuxtv.org> |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | |
| 20 | */ |
| 21 | |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/string.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include "dvb_frontend.h" |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 29 | #include "au8522.h" |
Devin Heitmueller | 0c44bf3 | 2009-03-11 02:59:56 -0300 | [diff] [blame] | 30 | #include "au8522_priv.h" |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 31 | |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 32 | static int debug; |
| 33 | |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 34 | /* Despite the name "hybrid_tuner", the framework works just as well for |
| 35 | hybrid demodulators as well... */ |
| 36 | static LIST_HEAD(hybrid_tuner_instance_list); |
Devin Heitmueller | 4ff5ed4 | 2009-03-11 03:00:45 -0300 | [diff] [blame] | 37 | static DEFINE_MUTEX(au8522_list_mutex); |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 38 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame^] | 39 | #define dprintk(arg...)\ |
| 40 | do { if (debug)\ |
| 41 | printk(arg);\ |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 42 | } while (0) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 43 | |
| 44 | /* 16 bit registers, 8 bit values */ |
Devin Heitmueller | 0c44bf3 | 2009-03-11 02:59:56 -0300 | [diff] [blame] | 45 | int au8522_writereg(struct au8522_state *state, u16 reg, u8 data) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 46 | { |
| 47 | int ret; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame^] | 48 | u8 buf[] = { (reg >> 8) | 0x80, reg & 0xff, data }; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 49 | |
| 50 | struct i2c_msg msg = { .addr = state->config->demod_address, |
| 51 | .flags = 0, .buf = buf, .len = 3 }; |
| 52 | |
| 53 | ret = i2c_transfer(state->i2c, &msg, 1); |
| 54 | |
| 55 | if (ret != 1) |
| 56 | printk("%s: writereg error (reg == 0x%02x, val == 0x%04x, " |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 57 | "ret == %i)\n", __func__, reg, data, ret); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 58 | |
| 59 | return (ret != 1) ? -1 : 0; |
| 60 | } |
| 61 | |
Devin Heitmueller | 0c44bf3 | 2009-03-11 02:59:56 -0300 | [diff] [blame] | 62 | u8 au8522_readreg(struct au8522_state *state, u16 reg) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 63 | { |
| 64 | int ret; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame^] | 65 | u8 b0[] = { (reg >> 8) | 0x40, reg & 0xff }; |
| 66 | u8 b1[] = { 0 }; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 67 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame^] | 68 | struct i2c_msg msg[] = { |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 69 | { .addr = state->config->demod_address, .flags = 0, |
| 70 | .buf = b0, .len = 2 }, |
| 71 | { .addr = state->config->demod_address, .flags = I2C_M_RD, |
| 72 | .buf = b1, .len = 1 } }; |
| 73 | |
| 74 | ret = i2c_transfer(state->i2c, msg, 2); |
| 75 | |
| 76 | if (ret != 2) |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 77 | printk(KERN_ERR "%s: readreg error (ret == %i)\n", |
| 78 | __func__, ret); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 79 | return b1[0]; |
| 80 | } |
| 81 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 82 | static int au8522_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 83 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 84 | struct au8522_state *state = fe->demodulator_priv; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 85 | |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 86 | dprintk("%s(%d)\n", __func__, enable); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 87 | |
| 88 | if (enable) |
| 89 | return au8522_writereg(state, 0x106, 1); |
| 90 | else |
| 91 | return au8522_writereg(state, 0x106, 0); |
| 92 | } |
| 93 | |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 94 | struct mse2snr_tab { |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 95 | u16 val; |
| 96 | u16 data; |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | /* VSB SNR lookup table */ |
| 100 | static struct mse2snr_tab vsb_mse2snr_tab[] = { |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 101 | { 0, 270 }, |
| 102 | { 2, 250 }, |
| 103 | { 3, 240 }, |
| 104 | { 5, 230 }, |
| 105 | { 7, 220 }, |
| 106 | { 9, 210 }, |
| 107 | { 12, 200 }, |
| 108 | { 13, 195 }, |
| 109 | { 15, 190 }, |
| 110 | { 17, 185 }, |
| 111 | { 19, 180 }, |
| 112 | { 21, 175 }, |
| 113 | { 24, 170 }, |
| 114 | { 27, 165 }, |
| 115 | { 31, 160 }, |
| 116 | { 32, 158 }, |
| 117 | { 33, 156 }, |
| 118 | { 36, 152 }, |
| 119 | { 37, 150 }, |
| 120 | { 39, 148 }, |
| 121 | { 40, 146 }, |
| 122 | { 41, 144 }, |
| 123 | { 43, 142 }, |
| 124 | { 44, 140 }, |
| 125 | { 48, 135 }, |
| 126 | { 50, 130 }, |
| 127 | { 43, 142 }, |
| 128 | { 53, 125 }, |
| 129 | { 56, 120 }, |
| 130 | { 256, 115 }, |
| 131 | }; |
| 132 | |
| 133 | /* QAM64 SNR lookup table */ |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 134 | static struct mse2snr_tab qam64_mse2snr_tab[] = { |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 135 | { 15, 0 }, |
| 136 | { 16, 290 }, |
| 137 | { 17, 288 }, |
| 138 | { 18, 286 }, |
| 139 | { 19, 284 }, |
| 140 | { 20, 282 }, |
| 141 | { 21, 281 }, |
| 142 | { 22, 279 }, |
| 143 | { 23, 277 }, |
| 144 | { 24, 275 }, |
| 145 | { 25, 273 }, |
| 146 | { 26, 271 }, |
| 147 | { 27, 269 }, |
| 148 | { 28, 268 }, |
| 149 | { 29, 266 }, |
| 150 | { 30, 264 }, |
| 151 | { 31, 262 }, |
| 152 | { 32, 260 }, |
| 153 | { 33, 259 }, |
| 154 | { 34, 258 }, |
| 155 | { 35, 256 }, |
| 156 | { 36, 255 }, |
| 157 | { 37, 254 }, |
| 158 | { 38, 252 }, |
| 159 | { 39, 251 }, |
| 160 | { 40, 250 }, |
| 161 | { 41, 249 }, |
| 162 | { 42, 248 }, |
| 163 | { 43, 246 }, |
| 164 | { 44, 245 }, |
| 165 | { 45, 244 }, |
| 166 | { 46, 242 }, |
| 167 | { 47, 241 }, |
| 168 | { 48, 240 }, |
| 169 | { 50, 239 }, |
| 170 | { 51, 238 }, |
| 171 | { 53, 237 }, |
| 172 | { 54, 236 }, |
| 173 | { 56, 235 }, |
| 174 | { 57, 234 }, |
| 175 | { 59, 233 }, |
| 176 | { 60, 232 }, |
| 177 | { 62, 231 }, |
| 178 | { 63, 230 }, |
| 179 | { 65, 229 }, |
| 180 | { 67, 228 }, |
| 181 | { 68, 227 }, |
| 182 | { 70, 226 }, |
| 183 | { 71, 225 }, |
| 184 | { 73, 224 }, |
| 185 | { 74, 223 }, |
| 186 | { 76, 222 }, |
| 187 | { 78, 221 }, |
| 188 | { 80, 220 }, |
| 189 | { 82, 219 }, |
| 190 | { 85, 218 }, |
| 191 | { 88, 217 }, |
| 192 | { 90, 216 }, |
| 193 | { 92, 215 }, |
| 194 | { 93, 214 }, |
| 195 | { 94, 212 }, |
| 196 | { 95, 211 }, |
| 197 | { 97, 210 }, |
| 198 | { 99, 209 }, |
| 199 | { 101, 208 }, |
| 200 | { 102, 207 }, |
| 201 | { 104, 206 }, |
| 202 | { 107, 205 }, |
| 203 | { 111, 204 }, |
| 204 | { 114, 203 }, |
| 205 | { 118, 202 }, |
| 206 | { 122, 201 }, |
| 207 | { 125, 200 }, |
| 208 | { 128, 199 }, |
| 209 | { 130, 198 }, |
| 210 | { 132, 197 }, |
| 211 | { 256, 190 }, |
| 212 | }; |
| 213 | |
| 214 | /* QAM256 SNR lookup table */ |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 215 | static struct mse2snr_tab qam256_mse2snr_tab[] = { |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 216 | { 16, 0 }, |
| 217 | { 17, 400 }, |
| 218 | { 18, 398 }, |
| 219 | { 19, 396 }, |
| 220 | { 20, 394 }, |
| 221 | { 21, 392 }, |
| 222 | { 22, 390 }, |
| 223 | { 23, 388 }, |
| 224 | { 24, 386 }, |
| 225 | { 25, 384 }, |
| 226 | { 26, 382 }, |
| 227 | { 27, 380 }, |
| 228 | { 28, 379 }, |
| 229 | { 29, 378 }, |
| 230 | { 30, 377 }, |
| 231 | { 31, 376 }, |
| 232 | { 32, 375 }, |
| 233 | { 33, 374 }, |
| 234 | { 34, 373 }, |
| 235 | { 35, 372 }, |
| 236 | { 36, 371 }, |
| 237 | { 37, 370 }, |
| 238 | { 38, 362 }, |
| 239 | { 39, 354 }, |
| 240 | { 40, 346 }, |
| 241 | { 41, 338 }, |
| 242 | { 42, 330 }, |
| 243 | { 43, 328 }, |
| 244 | { 44, 326 }, |
| 245 | { 45, 324 }, |
| 246 | { 46, 322 }, |
| 247 | { 47, 320 }, |
| 248 | { 48, 319 }, |
| 249 | { 49, 318 }, |
| 250 | { 50, 317 }, |
| 251 | { 51, 316 }, |
| 252 | { 52, 315 }, |
| 253 | { 53, 314 }, |
| 254 | { 54, 313 }, |
| 255 | { 55, 312 }, |
| 256 | { 56, 311 }, |
| 257 | { 57, 310 }, |
| 258 | { 58, 308 }, |
| 259 | { 59, 306 }, |
| 260 | { 60, 304 }, |
| 261 | { 61, 302 }, |
| 262 | { 62, 300 }, |
| 263 | { 63, 298 }, |
| 264 | { 65, 295 }, |
| 265 | { 68, 294 }, |
| 266 | { 70, 293 }, |
| 267 | { 73, 292 }, |
| 268 | { 76, 291 }, |
| 269 | { 78, 290 }, |
| 270 | { 79, 289 }, |
| 271 | { 81, 288 }, |
| 272 | { 82, 287 }, |
| 273 | { 83, 286 }, |
| 274 | { 84, 285 }, |
| 275 | { 85, 284 }, |
| 276 | { 86, 283 }, |
| 277 | { 88, 282 }, |
| 278 | { 89, 281 }, |
| 279 | { 256, 280 }, |
| 280 | }; |
| 281 | |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 282 | static int au8522_mse2snr_lookup(struct mse2snr_tab *tab, int sz, int mse, |
| 283 | u16 *snr) |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 284 | { |
| 285 | int i, ret = -EINVAL; |
| 286 | dprintk("%s()\n", __func__); |
| 287 | |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 288 | for (i = 0; i < sz; i++) { |
| 289 | if (mse < tab[i].val) { |
| 290 | *snr = tab[i].data; |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 291 | ret = 0; |
| 292 | break; |
| 293 | } |
| 294 | } |
| 295 | dprintk("%s() snr=%d\n", __func__, *snr); |
| 296 | return ret; |
| 297 | } |
| 298 | |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 299 | static int au8522_set_if(struct dvb_frontend *fe, enum au8522_if_freq if_freq) |
| 300 | { |
| 301 | struct au8522_state *state = fe->demodulator_priv; |
Michael Krufky | df76de0 | 2008-09-03 16:46:40 -0300 | [diff] [blame] | 302 | u8 r0b5, r0b6, r0b7; |
| 303 | char *ifmhz; |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 304 | |
| 305 | switch (if_freq) { |
| 306 | case AU8522_IF_3_25MHZ: |
Michael Krufky | df76de0 | 2008-09-03 16:46:40 -0300 | [diff] [blame] | 307 | ifmhz = "3.25"; |
| 308 | r0b5 = 0x00; |
| 309 | r0b6 = 0x3d; |
| 310 | r0b7 = 0xa0; |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 311 | break; |
| 312 | case AU8522_IF_4MHZ: |
Michael Krufky | df76de0 | 2008-09-03 16:46:40 -0300 | [diff] [blame] | 313 | ifmhz = "4.00"; |
| 314 | r0b5 = 0x00; |
| 315 | r0b6 = 0x4b; |
| 316 | r0b7 = 0xd9; |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 317 | break; |
| 318 | case AU8522_IF_6MHZ: |
Michael Krufky | df76de0 | 2008-09-03 16:46:40 -0300 | [diff] [blame] | 319 | ifmhz = "6.00"; |
| 320 | r0b5 = 0xfb; |
| 321 | r0b6 = 0x8e; |
| 322 | r0b7 = 0x39; |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 323 | break; |
| 324 | default: |
| 325 | dprintk("%s() IF Frequency not supported\n", __func__); |
| 326 | return -EINVAL; |
| 327 | } |
Michael Krufky | df76de0 | 2008-09-03 16:46:40 -0300 | [diff] [blame] | 328 | dprintk("%s() %s MHz\n", __func__, ifmhz); |
| 329 | au8522_writereg(state, 0x80b5, r0b5); |
| 330 | au8522_writereg(state, 0x80b6, r0b6); |
| 331 | au8522_writereg(state, 0x80b7, r0b7); |
| 332 | |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 333 | return 0; |
| 334 | } |
| 335 | |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 336 | /* VSB Modulation table */ |
| 337 | static struct { |
| 338 | u16 reg; |
| 339 | u16 data; |
| 340 | } VSB_mod_tab[] = { |
| 341 | { 0x8090, 0x84 }, |
| 342 | { 0x4092, 0x11 }, |
| 343 | { 0x2005, 0x00 }, |
| 344 | { 0x8091, 0x80 }, |
| 345 | { 0x80a3, 0x0c }, |
| 346 | { 0x80a4, 0xe8 }, |
| 347 | { 0x8081, 0xc4 }, |
| 348 | { 0x80a5, 0x40 }, |
| 349 | { 0x80a7, 0x40 }, |
| 350 | { 0x80a6, 0x67 }, |
| 351 | { 0x8262, 0x20 }, |
| 352 | { 0x821c, 0x30 }, |
| 353 | { 0x80d8, 0x1a }, |
| 354 | { 0x8227, 0xa0 }, |
| 355 | { 0x8121, 0xff }, |
| 356 | { 0x80a8, 0xf0 }, |
| 357 | { 0x80a9, 0x05 }, |
| 358 | { 0x80aa, 0x77 }, |
| 359 | { 0x80ab, 0xf0 }, |
| 360 | { 0x80ac, 0x05 }, |
| 361 | { 0x80ad, 0x77 }, |
| 362 | { 0x80ae, 0x41 }, |
| 363 | { 0x80af, 0x66 }, |
| 364 | { 0x821b, 0xcc }, |
| 365 | { 0x821d, 0x80 }, |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 366 | { 0x80a4, 0xe8 }, |
| 367 | { 0x8231, 0x13 }, |
| 368 | }; |
| 369 | |
| 370 | /* QAM Modulation table */ |
| 371 | static struct { |
| 372 | u16 reg; |
| 373 | u16 data; |
| 374 | } QAM_mod_tab[] = { |
| 375 | { 0x80a3, 0x09 }, |
| 376 | { 0x80a4, 0x00 }, |
| 377 | { 0x8081, 0xc4 }, |
| 378 | { 0x80a5, 0x40 }, |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 379 | { 0x80aa, 0x77 }, |
| 380 | { 0x80ad, 0x77 }, |
| 381 | { 0x80a6, 0x67 }, |
| 382 | { 0x8262, 0x20 }, |
| 383 | { 0x821c, 0x30 }, |
| 384 | { 0x80b8, 0x3e }, |
| 385 | { 0x80b9, 0xf0 }, |
| 386 | { 0x80ba, 0x01 }, |
| 387 | { 0x80bb, 0x18 }, |
| 388 | { 0x80bc, 0x50 }, |
| 389 | { 0x80bd, 0x00 }, |
| 390 | { 0x80be, 0xea }, |
| 391 | { 0x80bf, 0xef }, |
| 392 | { 0x80c0, 0xfc }, |
| 393 | { 0x80c1, 0xbd }, |
| 394 | { 0x80c2, 0x1f }, |
| 395 | { 0x80c3, 0xfc }, |
| 396 | { 0x80c4, 0xdd }, |
| 397 | { 0x80c5, 0xaf }, |
| 398 | { 0x80c6, 0x00 }, |
| 399 | { 0x80c7, 0x38 }, |
| 400 | { 0x80c8, 0x30 }, |
| 401 | { 0x80c9, 0x05 }, |
| 402 | { 0x80ca, 0x4a }, |
| 403 | { 0x80cb, 0xd0 }, |
| 404 | { 0x80cc, 0x01 }, |
| 405 | { 0x80cd, 0xd9 }, |
| 406 | { 0x80ce, 0x6f }, |
| 407 | { 0x80cf, 0xf9 }, |
| 408 | { 0x80d0, 0x70 }, |
| 409 | { 0x80d1, 0xdf }, |
| 410 | { 0x80d2, 0xf7 }, |
| 411 | { 0x80d3, 0xc2 }, |
| 412 | { 0x80d4, 0xdf }, |
| 413 | { 0x80d5, 0x02 }, |
| 414 | { 0x80d6, 0x9a }, |
| 415 | { 0x80d7, 0xd0 }, |
| 416 | { 0x8250, 0x0d }, |
| 417 | { 0x8251, 0xcd }, |
| 418 | { 0x8252, 0xe0 }, |
| 419 | { 0x8253, 0x05 }, |
| 420 | { 0x8254, 0xa7 }, |
| 421 | { 0x8255, 0xff }, |
| 422 | { 0x8256, 0xed }, |
| 423 | { 0x8257, 0x5b }, |
| 424 | { 0x8258, 0xae }, |
| 425 | { 0x8259, 0xe6 }, |
| 426 | { 0x825a, 0x3d }, |
| 427 | { 0x825b, 0x0f }, |
| 428 | { 0x825c, 0x0d }, |
| 429 | { 0x825d, 0xea }, |
| 430 | { 0x825e, 0xf2 }, |
| 431 | { 0x825f, 0x51 }, |
| 432 | { 0x8260, 0xf5 }, |
| 433 | { 0x8261, 0x06 }, |
| 434 | { 0x821a, 0x00 }, |
| 435 | { 0x8546, 0x40 }, |
| 436 | { 0x8210, 0x26 }, |
| 437 | { 0x8211, 0xf6 }, |
| 438 | { 0x8212, 0x84 }, |
| 439 | { 0x8213, 0x02 }, |
| 440 | { 0x8502, 0x01 }, |
| 441 | { 0x8121, 0x04 }, |
| 442 | { 0x8122, 0x04 }, |
| 443 | { 0x852e, 0x10 }, |
| 444 | { 0x80a4, 0xca }, |
| 445 | { 0x80a7, 0x40 }, |
| 446 | { 0x8526, 0x01 }, |
| 447 | }; |
| 448 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 449 | static int au8522_enable_modulation(struct dvb_frontend *fe, |
| 450 | fe_modulation_t m) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 451 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 452 | struct au8522_state *state = fe->demodulator_priv; |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 453 | int i; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 454 | |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 455 | dprintk("%s(0x%08x)\n", __func__, m); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 456 | |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 457 | switch (m) { |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 458 | case VSB_8: |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 459 | dprintk("%s() VSB_8\n", __func__); |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 460 | for (i = 0; i < ARRAY_SIZE(VSB_mod_tab); i++) |
| 461 | au8522_writereg(state, |
| 462 | VSB_mod_tab[i].reg, |
| 463 | VSB_mod_tab[i].data); |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 464 | au8522_set_if(fe, state->config->vsb_if); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 465 | break; |
| 466 | case QAM_64: |
| 467 | case QAM_256: |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 468 | dprintk("%s() QAM 64/256\n", __func__); |
| 469 | for (i = 0; i < ARRAY_SIZE(QAM_mod_tab); i++) |
| 470 | au8522_writereg(state, |
| 471 | QAM_mod_tab[i].reg, |
| 472 | QAM_mod_tab[i].data); |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 473 | au8522_set_if(fe, state->config->qam_if); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 474 | break; |
| 475 | default: |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 476 | dprintk("%s() Invalid modulation\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 477 | return -EINVAL; |
| 478 | } |
| 479 | |
| 480 | state->current_modulation = m; |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | /* Talk to the demod, set the FEC, GUARD, QAM settings etc */ |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 486 | static int au8522_set_frontend(struct dvb_frontend *fe, |
| 487 | struct dvb_frontend_parameters *p) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 488 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 489 | struct au8522_state *state = fe->demodulator_priv; |
Michael Krufky | 74d5072 | 2008-06-13 20:33:23 -0300 | [diff] [blame] | 490 | int ret = -EINVAL; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 491 | |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 492 | dprintk("%s(frequency=%d)\n", __func__, p->frequency); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 493 | |
Michael Krufky | 74d5072 | 2008-06-13 20:33:23 -0300 | [diff] [blame] | 494 | if ((state->current_frequency == p->frequency) && |
| 495 | (state->current_modulation == p->u.vsb.modulation)) |
| 496 | return 0; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 497 | |
| 498 | au8522_enable_modulation(fe, p->u.vsb.modulation); |
| 499 | |
| 500 | /* Allow the demod to settle */ |
| 501 | msleep(100); |
| 502 | |
| 503 | if (fe->ops.tuner_ops.set_params) { |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 504 | if (fe->ops.i2c_gate_ctrl) |
| 505 | fe->ops.i2c_gate_ctrl(fe, 1); |
Michael Krufky | 74d5072 | 2008-06-13 20:33:23 -0300 | [diff] [blame] | 506 | ret = fe->ops.tuner_ops.set_params(fe, p); |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 507 | if (fe->ops.i2c_gate_ctrl) |
| 508 | fe->ops.i2c_gate_ctrl(fe, 0); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 509 | } |
| 510 | |
Michael Krufky | 74d5072 | 2008-06-13 20:33:23 -0300 | [diff] [blame] | 511 | if (ret < 0) |
| 512 | return ret; |
| 513 | |
| 514 | state->current_frequency = p->frequency; |
| 515 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | /* Reset the demod hardware and reset all of the configuration registers |
| 520 | to a default state. */ |
Devin Heitmueller | 0c44bf3 | 2009-03-11 02:59:56 -0300 | [diff] [blame] | 521 | int au8522_init(struct dvb_frontend *fe) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 522 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 523 | struct au8522_state *state = fe->demodulator_priv; |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 524 | dprintk("%s()\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 525 | |
| 526 | au8522_writereg(state, 0xa4, 1 << 5); |
| 527 | |
| 528 | au8522_i2c_gate_ctrl(fe, 1); |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 533 | static int au8522_led_gpio_enable(struct au8522_state *state, int onoff) |
| 534 | { |
| 535 | struct au8522_led_config *led_config = state->config->led_cfg; |
| 536 | u8 val; |
| 537 | |
| 538 | /* bail out if we cant control an LED */ |
| 539 | if (!led_config || !led_config->gpio_output || |
| 540 | !led_config->gpio_output_enable || !led_config->gpio_output_disable) |
| 541 | return 0; |
| 542 | |
| 543 | val = au8522_readreg(state, 0x4000 | |
| 544 | (led_config->gpio_output & ~0xc000)); |
| 545 | if (onoff) { |
| 546 | /* enable GPIO output */ |
| 547 | val &= ~((led_config->gpio_output_enable >> 8) & 0xff); |
| 548 | val |= (led_config->gpio_output_enable & 0xff); |
| 549 | } else { |
| 550 | /* disable GPIO output */ |
| 551 | val &= ~((led_config->gpio_output_disable >> 8) & 0xff); |
| 552 | val |= (led_config->gpio_output_disable & 0xff); |
| 553 | } |
| 554 | return au8522_writereg(state, 0x8000 | |
| 555 | (led_config->gpio_output & ~0xc000), val); |
| 556 | } |
| 557 | |
| 558 | /* led = 0 | off |
| 559 | * led = 1 | signal ok |
| 560 | * led = 2 | signal strong |
| 561 | * led < 0 | only light led if leds are currently off |
| 562 | */ |
| 563 | static int au8522_led_ctrl(struct au8522_state *state, int led) |
| 564 | { |
| 565 | struct au8522_led_config *led_config = state->config->led_cfg; |
| 566 | int i, ret = 0; |
| 567 | |
| 568 | /* bail out if we cant control an LED */ |
| 569 | if (!led_config || !led_config->gpio_leds || |
| 570 | !led_config->num_led_states || !led_config->led_states) |
| 571 | return 0; |
| 572 | |
| 573 | if (led < 0) { |
| 574 | /* if LED is already lit, then leave it as-is */ |
| 575 | if (state->led_state) |
| 576 | return 0; |
| 577 | else |
| 578 | led *= -1; |
| 579 | } |
| 580 | |
| 581 | /* toggle LED if changing state */ |
| 582 | if (state->led_state != led) { |
| 583 | u8 val; |
| 584 | |
| 585 | dprintk("%s: %d\n", __func__, led); |
| 586 | |
| 587 | au8522_led_gpio_enable(state, 1); |
| 588 | |
| 589 | val = au8522_readreg(state, 0x4000 | |
| 590 | (led_config->gpio_leds & ~0xc000)); |
| 591 | |
| 592 | /* start with all leds off */ |
| 593 | for (i = 0; i < led_config->num_led_states; i++) |
| 594 | val &= ~led_config->led_states[i]; |
| 595 | |
| 596 | /* set selected LED state */ |
| 597 | if (led < led_config->num_led_states) |
| 598 | val |= led_config->led_states[led]; |
| 599 | else if (led_config->num_led_states) |
| 600 | val |= |
| 601 | led_config->led_states[led_config->num_led_states - 1]; |
| 602 | |
| 603 | ret = au8522_writereg(state, 0x8000 | |
| 604 | (led_config->gpio_leds & ~0xc000), val); |
| 605 | if (ret < 0) |
| 606 | return ret; |
| 607 | |
| 608 | state->led_state = led; |
| 609 | |
| 610 | if (led == 0) |
| 611 | au8522_led_gpio_enable(state, 0); |
| 612 | } |
| 613 | |
| 614 | return 0; |
| 615 | } |
| 616 | |
Devin Heitmueller | 0c44bf3 | 2009-03-11 02:59:56 -0300 | [diff] [blame] | 617 | int au8522_sleep(struct dvb_frontend *fe) |
Michael Krufky | 74d5072 | 2008-06-13 20:33:23 -0300 | [diff] [blame] | 618 | { |
| 619 | struct au8522_state *state = fe->demodulator_priv; |
| 620 | dprintk("%s()\n", __func__); |
| 621 | |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 622 | /* turn off led */ |
| 623 | au8522_led_ctrl(state, 0); |
| 624 | |
Devin Heitmueller | 7bf63ed | 2009-03-11 03:00:34 -0300 | [diff] [blame] | 625 | /* Power down the chip */ |
| 626 | au8522_writereg(state, 0xa4, 1 << 5); |
| 627 | |
Michael Krufky | 74d5072 | 2008-06-13 20:33:23 -0300 | [diff] [blame] | 628 | state->current_frequency = 0; |
| 629 | |
| 630 | return 0; |
| 631 | } |
| 632 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 633 | static int au8522_read_status(struct dvb_frontend *fe, fe_status_t *status) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 634 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 635 | struct au8522_state *state = fe->demodulator_priv; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 636 | u8 reg; |
| 637 | u32 tuner_status = 0; |
| 638 | |
| 639 | *status = 0; |
| 640 | |
| 641 | if (state->current_modulation == VSB_8) { |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 642 | dprintk("%s() Checking VSB_8\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 643 | reg = au8522_readreg(state, 0x4088); |
Steven Toth | 836c285 | 2008-06-21 19:32:41 -0300 | [diff] [blame] | 644 | if ((reg & 0x03) == 0x03) |
| 645 | *status |= FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 646 | } else { |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 647 | dprintk("%s() Checking QAM\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 648 | reg = au8522_readreg(state, 0x4541); |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 649 | if (reg & 0x80) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 650 | *status |= FE_HAS_VITERBI; |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 651 | if (reg & 0x20) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 652 | *status |= FE_HAS_LOCK | FE_HAS_SYNC; |
| 653 | } |
| 654 | |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 655 | switch (state->config->status_mode) { |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 656 | case AU8522_DEMODLOCKING: |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 657 | dprintk("%s() DEMODLOCKING\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 658 | if (*status & FE_HAS_VITERBI) |
| 659 | *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL; |
| 660 | break; |
| 661 | case AU8522_TUNERLOCKING: |
| 662 | /* Get the tuner status */ |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 663 | dprintk("%s() TUNERLOCKING\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 664 | if (fe->ops.tuner_ops.get_status) { |
| 665 | if (fe->ops.i2c_gate_ctrl) |
| 666 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 667 | |
| 668 | fe->ops.tuner_ops.get_status(fe, &tuner_status); |
| 669 | |
| 670 | if (fe->ops.i2c_gate_ctrl) |
| 671 | fe->ops.i2c_gate_ctrl(fe, 0); |
| 672 | } |
| 673 | if (tuner_status) |
| 674 | *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL; |
| 675 | break; |
| 676 | } |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 677 | state->fe_status = *status; |
| 678 | |
| 679 | if (*status & FE_HAS_LOCK) |
| 680 | /* turn on LED, if it isn't on already */ |
| 681 | au8522_led_ctrl(state, -1); |
| 682 | else |
| 683 | /* turn off LED */ |
| 684 | au8522_led_ctrl(state, 0); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 685 | |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 686 | dprintk("%s() status 0x%08x\n", __func__, *status); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 687 | |
| 688 | return 0; |
| 689 | } |
| 690 | |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 691 | static int au8522_led_status(struct au8522_state *state, const u16 *snr) |
| 692 | { |
| 693 | struct au8522_led_config *led_config = state->config->led_cfg; |
| 694 | int led; |
| 695 | u16 strong; |
| 696 | |
| 697 | /* bail out if we cant control an LED */ |
| 698 | if (!led_config) |
| 699 | return 0; |
| 700 | |
| 701 | if (0 == (state->fe_status & FE_HAS_LOCK)) |
| 702 | return au8522_led_ctrl(state, 0); |
| 703 | else if (state->current_modulation == QAM_256) |
| 704 | strong = led_config->qam256_strong; |
| 705 | else if (state->current_modulation == QAM_64) |
| 706 | strong = led_config->qam64_strong; |
| 707 | else /* (state->current_modulation == VSB_8) */ |
| 708 | strong = led_config->vsb8_strong; |
| 709 | |
| 710 | if (*snr >= strong) |
| 711 | led = 2; |
| 712 | else |
| 713 | led = 1; |
| 714 | |
| 715 | if ((state->led_state) && |
| 716 | (((strong < *snr) ? (*snr - strong) : (strong - *snr)) <= 10)) |
| 717 | /* snr didn't change enough to bother |
| 718 | * changing the color of the led */ |
| 719 | return 0; |
| 720 | |
| 721 | return au8522_led_ctrl(state, led); |
| 722 | } |
| 723 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 724 | static int au8522_read_snr(struct dvb_frontend *fe, u16 *snr) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 725 | { |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 726 | struct au8522_state *state = fe->demodulator_priv; |
| 727 | int ret = -EINVAL; |
| 728 | |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 729 | dprintk("%s()\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 730 | |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 731 | if (state->current_modulation == QAM_256) |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 732 | ret = au8522_mse2snr_lookup(qam256_mse2snr_tab, |
| 733 | ARRAY_SIZE(qam256_mse2snr_tab), |
| 734 | au8522_readreg(state, 0x4522), |
| 735 | snr); |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 736 | else if (state->current_modulation == QAM_64) |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 737 | ret = au8522_mse2snr_lookup(qam64_mse2snr_tab, |
| 738 | ARRAY_SIZE(qam64_mse2snr_tab), |
| 739 | au8522_readreg(state, 0x4522), |
| 740 | snr); |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 741 | else /* VSB_8 */ |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 742 | ret = au8522_mse2snr_lookup(vsb_mse2snr_tab, |
| 743 | ARRAY_SIZE(vsb_mse2snr_tab), |
| 744 | au8522_readreg(state, 0x4311), |
| 745 | snr); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 746 | |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 747 | if (state->config->led_cfg) |
| 748 | au8522_led_status(state, snr); |
| 749 | |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 750 | return ret; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 751 | } |
| 752 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 753 | static int au8522_read_signal_strength(struct dvb_frontend *fe, |
| 754 | u16 *signal_strength) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 755 | { |
| 756 | return au8522_read_snr(fe, signal_strength); |
| 757 | } |
| 758 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 759 | static int au8522_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 760 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 761 | struct au8522_state *state = fe->demodulator_priv; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 762 | |
Michael Krufky | 8973dc4 | 2008-04-05 23:08:08 -0300 | [diff] [blame] | 763 | if (state->current_modulation == VSB_8) |
| 764 | *ucblocks = au8522_readreg(state, 0x4087); |
| 765 | else |
| 766 | *ucblocks = au8522_readreg(state, 0x4543); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 767 | |
| 768 | return 0; |
| 769 | } |
| 770 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 771 | static int au8522_read_ber(struct dvb_frontend *fe, u32 *ber) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 772 | { |
| 773 | return au8522_read_ucblocks(fe, ber); |
| 774 | } |
| 775 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 776 | static int au8522_get_frontend(struct dvb_frontend *fe, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 777 | struct dvb_frontend_parameters *p) |
| 778 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 779 | struct au8522_state *state = fe->demodulator_priv; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 780 | |
| 781 | p->frequency = state->current_frequency; |
| 782 | p->u.vsb.modulation = state->current_modulation; |
| 783 | |
| 784 | return 0; |
| 785 | } |
| 786 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 787 | static int au8522_get_tune_settings(struct dvb_frontend *fe, |
| 788 | struct dvb_frontend_tune_settings *tune) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 789 | { |
| 790 | tune->min_delay_ms = 1000; |
| 791 | return 0; |
| 792 | } |
| 793 | |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 794 | static struct dvb_frontend_ops au8522_ops; |
| 795 | |
| 796 | int au8522_get_state(struct au8522_state **state, struct i2c_adapter *i2c, |
| 797 | u8 client_address) |
| 798 | { |
Devin Heitmueller | 4ff5ed4 | 2009-03-11 03:00:45 -0300 | [diff] [blame] | 799 | int ret; |
| 800 | |
| 801 | mutex_lock(&au8522_list_mutex); |
| 802 | ret = hybrid_tuner_request_state(struct au8522_state, (*state), |
| 803 | hybrid_tuner_instance_list, |
| 804 | i2c, client_address, "au8522"); |
| 805 | mutex_unlock(&au8522_list_mutex); |
| 806 | |
| 807 | return ret; |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | void au8522_release_state(struct au8522_state *state) |
| 811 | { |
Devin Heitmueller | 4ff5ed4 | 2009-03-11 03:00:45 -0300 | [diff] [blame] | 812 | mutex_lock(&au8522_list_mutex); |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 813 | if (state != NULL) |
| 814 | hybrid_tuner_release_state(state); |
Devin Heitmueller | 4ff5ed4 | 2009-03-11 03:00:45 -0300 | [diff] [blame] | 815 | mutex_unlock(&au8522_list_mutex); |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 819 | static void au8522_release(struct dvb_frontend *fe) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 820 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 821 | struct au8522_state *state = fe->demodulator_priv; |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 822 | au8522_release_state(state); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 823 | } |
| 824 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 825 | struct dvb_frontend *au8522_attach(const struct au8522_config *config, |
| 826 | struct i2c_adapter *i2c) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 827 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 828 | struct au8522_state *state = NULL; |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 829 | int instance; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 830 | |
| 831 | /* allocate memory for the internal state */ |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 832 | instance = au8522_get_state(&state, i2c, config->demod_address); |
| 833 | switch (instance) { |
| 834 | case 0: |
| 835 | dprintk("%s state allocation failed\n", __func__); |
| 836 | break; |
| 837 | case 1: |
| 838 | /* new demod instance */ |
| 839 | dprintk("%s using new instance\n", __func__); |
| 840 | break; |
| 841 | default: |
| 842 | /* existing demod instance */ |
| 843 | dprintk("%s using existing instance\n", __func__); |
| 844 | break; |
| 845 | } |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 846 | |
| 847 | /* setup the state */ |
| 848 | state->config = config; |
| 849 | state->i2c = i2c; |
| 850 | /* create dvb_frontend */ |
| 851 | memcpy(&state->frontend.ops, &au8522_ops, |
| 852 | sizeof(struct dvb_frontend_ops)); |
| 853 | state->frontend.demodulator_priv = state; |
| 854 | |
| 855 | if (au8522_init(&state->frontend) != 0) { |
| 856 | printk(KERN_ERR "%s: Failed to initialize correctly\n", |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 857 | __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 858 | goto error; |
| 859 | } |
| 860 | |
| 861 | /* Note: Leaving the I2C gate open here. */ |
| 862 | au8522_i2c_gate_ctrl(&state->frontend, 1); |
| 863 | |
| 864 | return &state->frontend; |
| 865 | |
| 866 | error: |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 867 | au8522_release_state(state); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 868 | return NULL; |
| 869 | } |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 870 | EXPORT_SYMBOL(au8522_attach); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 871 | |
| 872 | static struct dvb_frontend_ops au8522_ops = { |
| 873 | |
| 874 | .info = { |
| 875 | .name = "Auvitek AU8522 QAM/8VSB Frontend", |
| 876 | .type = FE_ATSC, |
| 877 | .frequency_min = 54000000, |
| 878 | .frequency_max = 858000000, |
| 879 | .frequency_stepsize = 62500, |
| 880 | .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB |
| 881 | }, |
| 882 | |
| 883 | .init = au8522_init, |
Michael Krufky | 74d5072 | 2008-06-13 20:33:23 -0300 | [diff] [blame] | 884 | .sleep = au8522_sleep, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 885 | .i2c_gate_ctrl = au8522_i2c_gate_ctrl, |
| 886 | .set_frontend = au8522_set_frontend, |
| 887 | .get_frontend = au8522_get_frontend, |
| 888 | .get_tune_settings = au8522_get_tune_settings, |
| 889 | .read_status = au8522_read_status, |
| 890 | .read_ber = au8522_read_ber, |
| 891 | .read_signal_strength = au8522_read_signal_strength, |
| 892 | .read_snr = au8522_read_snr, |
| 893 | .read_ucblocks = au8522_read_ucblocks, |
| 894 | .release = au8522_release, |
| 895 | }; |
| 896 | |
| 897 | module_param(debug, int, 0644); |
| 898 | MODULE_PARM_DESC(debug, "Enable verbose debug messages"); |
| 899 | |
| 900 | MODULE_DESCRIPTION("Auvitek AU8522 QAM-B/ATSC Demodulator driver"); |
| 901 | MODULE_AUTHOR("Steven Toth"); |
| 902 | MODULE_LICENSE("GPL"); |