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> |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 26 | #include <linux/delay.h> |
| 27 | #include "dvb_frontend.h" |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 28 | #include "au8522.h" |
Devin Heitmueller | 0c44bf3 | 2009-03-11 02:59:56 -0300 | [diff] [blame] | 29 | #include "au8522_priv.h" |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 30 | |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 31 | static int debug; |
| 32 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 33 | #define dprintk(arg...)\ |
| 34 | do { if (debug)\ |
| 35 | printk(arg);\ |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 36 | } while (0) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 37 | |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 38 | struct mse2snr_tab { |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 39 | u16 val; |
| 40 | u16 data; |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | /* VSB SNR lookup table */ |
| 44 | static struct mse2snr_tab vsb_mse2snr_tab[] = { |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 45 | { 0, 270 }, |
| 46 | { 2, 250 }, |
| 47 | { 3, 240 }, |
| 48 | { 5, 230 }, |
| 49 | { 7, 220 }, |
| 50 | { 9, 210 }, |
| 51 | { 12, 200 }, |
| 52 | { 13, 195 }, |
| 53 | { 15, 190 }, |
| 54 | { 17, 185 }, |
| 55 | { 19, 180 }, |
| 56 | { 21, 175 }, |
| 57 | { 24, 170 }, |
| 58 | { 27, 165 }, |
| 59 | { 31, 160 }, |
| 60 | { 32, 158 }, |
| 61 | { 33, 156 }, |
| 62 | { 36, 152 }, |
| 63 | { 37, 150 }, |
| 64 | { 39, 148 }, |
| 65 | { 40, 146 }, |
| 66 | { 41, 144 }, |
| 67 | { 43, 142 }, |
| 68 | { 44, 140 }, |
| 69 | { 48, 135 }, |
| 70 | { 50, 130 }, |
| 71 | { 43, 142 }, |
| 72 | { 53, 125 }, |
| 73 | { 56, 120 }, |
| 74 | { 256, 115 }, |
| 75 | }; |
| 76 | |
| 77 | /* QAM64 SNR lookup table */ |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 78 | static struct mse2snr_tab qam64_mse2snr_tab[] = { |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 79 | { 15, 0 }, |
| 80 | { 16, 290 }, |
| 81 | { 17, 288 }, |
| 82 | { 18, 286 }, |
| 83 | { 19, 284 }, |
| 84 | { 20, 282 }, |
| 85 | { 21, 281 }, |
| 86 | { 22, 279 }, |
| 87 | { 23, 277 }, |
| 88 | { 24, 275 }, |
| 89 | { 25, 273 }, |
| 90 | { 26, 271 }, |
| 91 | { 27, 269 }, |
| 92 | { 28, 268 }, |
| 93 | { 29, 266 }, |
| 94 | { 30, 264 }, |
| 95 | { 31, 262 }, |
| 96 | { 32, 260 }, |
| 97 | { 33, 259 }, |
| 98 | { 34, 258 }, |
| 99 | { 35, 256 }, |
| 100 | { 36, 255 }, |
| 101 | { 37, 254 }, |
| 102 | { 38, 252 }, |
| 103 | { 39, 251 }, |
| 104 | { 40, 250 }, |
| 105 | { 41, 249 }, |
| 106 | { 42, 248 }, |
| 107 | { 43, 246 }, |
| 108 | { 44, 245 }, |
| 109 | { 45, 244 }, |
| 110 | { 46, 242 }, |
| 111 | { 47, 241 }, |
| 112 | { 48, 240 }, |
| 113 | { 50, 239 }, |
| 114 | { 51, 238 }, |
| 115 | { 53, 237 }, |
| 116 | { 54, 236 }, |
| 117 | { 56, 235 }, |
| 118 | { 57, 234 }, |
| 119 | { 59, 233 }, |
| 120 | { 60, 232 }, |
| 121 | { 62, 231 }, |
| 122 | { 63, 230 }, |
| 123 | { 65, 229 }, |
| 124 | { 67, 228 }, |
| 125 | { 68, 227 }, |
| 126 | { 70, 226 }, |
| 127 | { 71, 225 }, |
| 128 | { 73, 224 }, |
| 129 | { 74, 223 }, |
| 130 | { 76, 222 }, |
| 131 | { 78, 221 }, |
| 132 | { 80, 220 }, |
| 133 | { 82, 219 }, |
| 134 | { 85, 218 }, |
| 135 | { 88, 217 }, |
| 136 | { 90, 216 }, |
| 137 | { 92, 215 }, |
| 138 | { 93, 214 }, |
| 139 | { 94, 212 }, |
| 140 | { 95, 211 }, |
| 141 | { 97, 210 }, |
| 142 | { 99, 209 }, |
| 143 | { 101, 208 }, |
| 144 | { 102, 207 }, |
| 145 | { 104, 206 }, |
| 146 | { 107, 205 }, |
| 147 | { 111, 204 }, |
| 148 | { 114, 203 }, |
| 149 | { 118, 202 }, |
| 150 | { 122, 201 }, |
| 151 | { 125, 200 }, |
| 152 | { 128, 199 }, |
| 153 | { 130, 198 }, |
| 154 | { 132, 197 }, |
| 155 | { 256, 190 }, |
| 156 | }; |
| 157 | |
| 158 | /* QAM256 SNR lookup table */ |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 159 | static struct mse2snr_tab qam256_mse2snr_tab[] = { |
Devin Heitmueller | b0c4878 | 2012-08-06 22:46:52 -0300 | [diff] [blame^] | 160 | { 15, 0 }, |
| 161 | { 16, 400 }, |
| 162 | { 17, 398 }, |
| 163 | { 18, 396 }, |
| 164 | { 19, 394 }, |
| 165 | { 20, 392 }, |
| 166 | { 21, 390 }, |
| 167 | { 22, 388 }, |
| 168 | { 23, 386 }, |
| 169 | { 24, 384 }, |
| 170 | { 25, 382 }, |
| 171 | { 26, 380 }, |
| 172 | { 27, 379 }, |
| 173 | { 28, 378 }, |
| 174 | { 29, 377 }, |
| 175 | { 30, 376 }, |
| 176 | { 31, 375 }, |
| 177 | { 32, 374 }, |
| 178 | { 33, 373 }, |
| 179 | { 34, 372 }, |
| 180 | { 35, 371 }, |
| 181 | { 36, 370 }, |
| 182 | { 37, 362 }, |
| 183 | { 38, 354 }, |
| 184 | { 39, 346 }, |
| 185 | { 40, 338 }, |
| 186 | { 41, 330 }, |
| 187 | { 42, 328 }, |
| 188 | { 43, 326 }, |
| 189 | { 44, 324 }, |
| 190 | { 45, 322 }, |
| 191 | { 46, 320 }, |
| 192 | { 47, 319 }, |
| 193 | { 48, 318 }, |
| 194 | { 49, 317 }, |
| 195 | { 50, 316 }, |
| 196 | { 51, 315 }, |
| 197 | { 52, 314 }, |
| 198 | { 53, 313 }, |
| 199 | { 54, 312 }, |
| 200 | { 55, 311 }, |
| 201 | { 56, 310 }, |
| 202 | { 57, 308 }, |
| 203 | { 58, 306 }, |
| 204 | { 59, 304 }, |
| 205 | { 60, 302 }, |
| 206 | { 61, 300 }, |
| 207 | { 62, 298 }, |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 208 | { 65, 295 }, |
| 209 | { 68, 294 }, |
| 210 | { 70, 293 }, |
| 211 | { 73, 292 }, |
| 212 | { 76, 291 }, |
| 213 | { 78, 290 }, |
| 214 | { 79, 289 }, |
| 215 | { 81, 288 }, |
| 216 | { 82, 287 }, |
| 217 | { 83, 286 }, |
| 218 | { 84, 285 }, |
| 219 | { 85, 284 }, |
| 220 | { 86, 283 }, |
| 221 | { 88, 282 }, |
| 222 | { 89, 281 }, |
| 223 | { 256, 280 }, |
| 224 | }; |
| 225 | |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 226 | static int au8522_mse2snr_lookup(struct mse2snr_tab *tab, int sz, int mse, |
| 227 | u16 *snr) |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 228 | { |
| 229 | int i, ret = -EINVAL; |
| 230 | dprintk("%s()\n", __func__); |
| 231 | |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 232 | for (i = 0; i < sz; i++) { |
| 233 | if (mse < tab[i].val) { |
| 234 | *snr = tab[i].data; |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 235 | ret = 0; |
| 236 | break; |
| 237 | } |
| 238 | } |
| 239 | dprintk("%s() snr=%d\n", __func__, *snr); |
| 240 | return ret; |
| 241 | } |
| 242 | |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 243 | static int au8522_set_if(struct dvb_frontend *fe, enum au8522_if_freq if_freq) |
| 244 | { |
| 245 | struct au8522_state *state = fe->demodulator_priv; |
Michael Krufky | df76de0 | 2008-09-03 16:46:40 -0300 | [diff] [blame] | 246 | u8 r0b5, r0b6, r0b7; |
| 247 | char *ifmhz; |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 248 | |
| 249 | switch (if_freq) { |
| 250 | case AU8522_IF_3_25MHZ: |
Michael Krufky | df76de0 | 2008-09-03 16:46:40 -0300 | [diff] [blame] | 251 | ifmhz = "3.25"; |
| 252 | r0b5 = 0x00; |
| 253 | r0b6 = 0x3d; |
| 254 | r0b7 = 0xa0; |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 255 | break; |
| 256 | case AU8522_IF_4MHZ: |
Michael Krufky | df76de0 | 2008-09-03 16:46:40 -0300 | [diff] [blame] | 257 | ifmhz = "4.00"; |
| 258 | r0b5 = 0x00; |
| 259 | r0b6 = 0x4b; |
| 260 | r0b7 = 0xd9; |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 261 | break; |
| 262 | case AU8522_IF_6MHZ: |
Michael Krufky | df76de0 | 2008-09-03 16:46:40 -0300 | [diff] [blame] | 263 | ifmhz = "6.00"; |
| 264 | r0b5 = 0xfb; |
| 265 | r0b6 = 0x8e; |
| 266 | r0b7 = 0x39; |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 267 | break; |
| 268 | default: |
| 269 | dprintk("%s() IF Frequency not supported\n", __func__); |
| 270 | return -EINVAL; |
| 271 | } |
Michael Krufky | df76de0 | 2008-09-03 16:46:40 -0300 | [diff] [blame] | 272 | dprintk("%s() %s MHz\n", __func__, ifmhz); |
| 273 | au8522_writereg(state, 0x80b5, r0b5); |
| 274 | au8522_writereg(state, 0x80b6, r0b6); |
| 275 | au8522_writereg(state, 0x80b7, r0b7); |
| 276 | |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 277 | return 0; |
| 278 | } |
| 279 | |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 280 | /* VSB Modulation table */ |
| 281 | static struct { |
| 282 | u16 reg; |
| 283 | u16 data; |
| 284 | } VSB_mod_tab[] = { |
| 285 | { 0x8090, 0x84 }, |
| 286 | { 0x4092, 0x11 }, |
| 287 | { 0x2005, 0x00 }, |
| 288 | { 0x8091, 0x80 }, |
| 289 | { 0x80a3, 0x0c }, |
| 290 | { 0x80a4, 0xe8 }, |
| 291 | { 0x8081, 0xc4 }, |
| 292 | { 0x80a5, 0x40 }, |
| 293 | { 0x80a7, 0x40 }, |
| 294 | { 0x80a6, 0x67 }, |
| 295 | { 0x8262, 0x20 }, |
| 296 | { 0x821c, 0x30 }, |
| 297 | { 0x80d8, 0x1a }, |
| 298 | { 0x8227, 0xa0 }, |
| 299 | { 0x8121, 0xff }, |
| 300 | { 0x80a8, 0xf0 }, |
| 301 | { 0x80a9, 0x05 }, |
| 302 | { 0x80aa, 0x77 }, |
| 303 | { 0x80ab, 0xf0 }, |
| 304 | { 0x80ac, 0x05 }, |
| 305 | { 0x80ad, 0x77 }, |
| 306 | { 0x80ae, 0x41 }, |
| 307 | { 0x80af, 0x66 }, |
| 308 | { 0x821b, 0xcc }, |
| 309 | { 0x821d, 0x80 }, |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 310 | { 0x80a4, 0xe8 }, |
| 311 | { 0x8231, 0x13 }, |
| 312 | }; |
| 313 | |
Frank Dischner | 040d4cb | 2009-06-14 23:05:20 -0300 | [diff] [blame] | 314 | /* QAM64 Modulation table */ |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 315 | static struct { |
| 316 | u16 reg; |
| 317 | u16 data; |
Frank Dischner | 040d4cb | 2009-06-14 23:05:20 -0300 | [diff] [blame] | 318 | } QAM64_mod_tab[] = { |
| 319 | { 0x00a3, 0x09 }, |
| 320 | { 0x00a4, 0x00 }, |
| 321 | { 0x0081, 0xc4 }, |
| 322 | { 0x00a5, 0x40 }, |
| 323 | { 0x00aa, 0x77 }, |
| 324 | { 0x00ad, 0x77 }, |
| 325 | { 0x00a6, 0x67 }, |
| 326 | { 0x0262, 0x20 }, |
| 327 | { 0x021c, 0x30 }, |
| 328 | { 0x00b8, 0x3e }, |
| 329 | { 0x00b9, 0xf0 }, |
| 330 | { 0x00ba, 0x01 }, |
| 331 | { 0x00bb, 0x18 }, |
| 332 | { 0x00bc, 0x50 }, |
| 333 | { 0x00bd, 0x00 }, |
| 334 | { 0x00be, 0xea }, |
| 335 | { 0x00bf, 0xef }, |
| 336 | { 0x00c0, 0xfc }, |
| 337 | { 0x00c1, 0xbd }, |
| 338 | { 0x00c2, 0x1f }, |
| 339 | { 0x00c3, 0xfc }, |
| 340 | { 0x00c4, 0xdd }, |
| 341 | { 0x00c5, 0xaf }, |
| 342 | { 0x00c6, 0x00 }, |
| 343 | { 0x00c7, 0x38 }, |
| 344 | { 0x00c8, 0x30 }, |
| 345 | { 0x00c9, 0x05 }, |
| 346 | { 0x00ca, 0x4a }, |
| 347 | { 0x00cb, 0xd0 }, |
| 348 | { 0x00cc, 0x01 }, |
| 349 | { 0x00cd, 0xd9 }, |
| 350 | { 0x00ce, 0x6f }, |
| 351 | { 0x00cf, 0xf9 }, |
| 352 | { 0x00d0, 0x70 }, |
| 353 | { 0x00d1, 0xdf }, |
| 354 | { 0x00d2, 0xf7 }, |
| 355 | { 0x00d3, 0xc2 }, |
| 356 | { 0x00d4, 0xdf }, |
| 357 | { 0x00d5, 0x02 }, |
| 358 | { 0x00d6, 0x9a }, |
| 359 | { 0x00d7, 0xd0 }, |
| 360 | { 0x0250, 0x0d }, |
| 361 | { 0x0251, 0xcd }, |
| 362 | { 0x0252, 0xe0 }, |
| 363 | { 0x0253, 0x05 }, |
| 364 | { 0x0254, 0xa7 }, |
| 365 | { 0x0255, 0xff }, |
| 366 | { 0x0256, 0xed }, |
| 367 | { 0x0257, 0x5b }, |
| 368 | { 0x0258, 0xae }, |
| 369 | { 0x0259, 0xe6 }, |
| 370 | { 0x025a, 0x3d }, |
| 371 | { 0x025b, 0x0f }, |
| 372 | { 0x025c, 0x0d }, |
| 373 | { 0x025d, 0xea }, |
| 374 | { 0x025e, 0xf2 }, |
| 375 | { 0x025f, 0x51 }, |
| 376 | { 0x0260, 0xf5 }, |
| 377 | { 0x0261, 0x06 }, |
| 378 | { 0x021a, 0x00 }, |
| 379 | { 0x0546, 0x40 }, |
| 380 | { 0x0210, 0xc7 }, |
| 381 | { 0x0211, 0xaa }, |
| 382 | { 0x0212, 0xab }, |
| 383 | { 0x0213, 0x02 }, |
| 384 | { 0x0502, 0x00 }, |
| 385 | { 0x0121, 0x04 }, |
| 386 | { 0x0122, 0x04 }, |
| 387 | { 0x052e, 0x10 }, |
| 388 | { 0x00a4, 0xca }, |
| 389 | { 0x00a7, 0x40 }, |
| 390 | { 0x0526, 0x01 }, |
| 391 | }; |
| 392 | |
| 393 | /* QAM256 Modulation table */ |
| 394 | static struct { |
| 395 | u16 reg; |
| 396 | u16 data; |
| 397 | } QAM256_mod_tab[] = { |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 398 | { 0x80a3, 0x09 }, |
| 399 | { 0x80a4, 0x00 }, |
| 400 | { 0x8081, 0xc4 }, |
| 401 | { 0x80a5, 0x40 }, |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 402 | { 0x80aa, 0x77 }, |
| 403 | { 0x80ad, 0x77 }, |
| 404 | { 0x80a6, 0x67 }, |
| 405 | { 0x8262, 0x20 }, |
| 406 | { 0x821c, 0x30 }, |
| 407 | { 0x80b8, 0x3e }, |
| 408 | { 0x80b9, 0xf0 }, |
| 409 | { 0x80ba, 0x01 }, |
| 410 | { 0x80bb, 0x18 }, |
| 411 | { 0x80bc, 0x50 }, |
| 412 | { 0x80bd, 0x00 }, |
| 413 | { 0x80be, 0xea }, |
| 414 | { 0x80bf, 0xef }, |
| 415 | { 0x80c0, 0xfc }, |
| 416 | { 0x80c1, 0xbd }, |
| 417 | { 0x80c2, 0x1f }, |
| 418 | { 0x80c3, 0xfc }, |
| 419 | { 0x80c4, 0xdd }, |
| 420 | { 0x80c5, 0xaf }, |
| 421 | { 0x80c6, 0x00 }, |
| 422 | { 0x80c7, 0x38 }, |
| 423 | { 0x80c8, 0x30 }, |
| 424 | { 0x80c9, 0x05 }, |
| 425 | { 0x80ca, 0x4a }, |
| 426 | { 0x80cb, 0xd0 }, |
| 427 | { 0x80cc, 0x01 }, |
| 428 | { 0x80cd, 0xd9 }, |
| 429 | { 0x80ce, 0x6f }, |
| 430 | { 0x80cf, 0xf9 }, |
| 431 | { 0x80d0, 0x70 }, |
| 432 | { 0x80d1, 0xdf }, |
| 433 | { 0x80d2, 0xf7 }, |
| 434 | { 0x80d3, 0xc2 }, |
| 435 | { 0x80d4, 0xdf }, |
| 436 | { 0x80d5, 0x02 }, |
| 437 | { 0x80d6, 0x9a }, |
| 438 | { 0x80d7, 0xd0 }, |
| 439 | { 0x8250, 0x0d }, |
| 440 | { 0x8251, 0xcd }, |
| 441 | { 0x8252, 0xe0 }, |
| 442 | { 0x8253, 0x05 }, |
| 443 | { 0x8254, 0xa7 }, |
| 444 | { 0x8255, 0xff }, |
| 445 | { 0x8256, 0xed }, |
| 446 | { 0x8257, 0x5b }, |
| 447 | { 0x8258, 0xae }, |
| 448 | { 0x8259, 0xe6 }, |
| 449 | { 0x825a, 0x3d }, |
| 450 | { 0x825b, 0x0f }, |
| 451 | { 0x825c, 0x0d }, |
| 452 | { 0x825d, 0xea }, |
| 453 | { 0x825e, 0xf2 }, |
| 454 | { 0x825f, 0x51 }, |
| 455 | { 0x8260, 0xf5 }, |
| 456 | { 0x8261, 0x06 }, |
| 457 | { 0x821a, 0x00 }, |
| 458 | { 0x8546, 0x40 }, |
| 459 | { 0x8210, 0x26 }, |
| 460 | { 0x8211, 0xf6 }, |
| 461 | { 0x8212, 0x84 }, |
| 462 | { 0x8213, 0x02 }, |
| 463 | { 0x8502, 0x01 }, |
| 464 | { 0x8121, 0x04 }, |
| 465 | { 0x8122, 0x04 }, |
| 466 | { 0x852e, 0x10 }, |
| 467 | { 0x80a4, 0xca }, |
| 468 | { 0x80a7, 0x40 }, |
| 469 | { 0x8526, 0x01 }, |
| 470 | }; |
| 471 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 472 | static int au8522_enable_modulation(struct dvb_frontend *fe, |
| 473 | fe_modulation_t m) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 474 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 475 | struct au8522_state *state = fe->demodulator_priv; |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 476 | int i; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 477 | |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 478 | dprintk("%s(0x%08x)\n", __func__, m); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 479 | |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 480 | switch (m) { |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 481 | case VSB_8: |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 482 | dprintk("%s() VSB_8\n", __func__); |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 483 | for (i = 0; i < ARRAY_SIZE(VSB_mod_tab); i++) |
| 484 | au8522_writereg(state, |
| 485 | VSB_mod_tab[i].reg, |
| 486 | VSB_mod_tab[i].data); |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 487 | au8522_set_if(fe, state->config->vsb_if); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 488 | break; |
| 489 | case QAM_64: |
Frank Dischner | 040d4cb | 2009-06-14 23:05:20 -0300 | [diff] [blame] | 490 | dprintk("%s() QAM 64\n", __func__); |
| 491 | for (i = 0; i < ARRAY_SIZE(QAM64_mod_tab); i++) |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 492 | au8522_writereg(state, |
Frank Dischner | 040d4cb | 2009-06-14 23:05:20 -0300 | [diff] [blame] | 493 | QAM64_mod_tab[i].reg, |
| 494 | QAM64_mod_tab[i].data); |
| 495 | au8522_set_if(fe, state->config->qam_if); |
| 496 | break; |
| 497 | case QAM_256: |
| 498 | dprintk("%s() QAM 256\n", __func__); |
| 499 | for (i = 0; i < ARRAY_SIZE(QAM256_mod_tab); i++) |
| 500 | au8522_writereg(state, |
| 501 | QAM256_mod_tab[i].reg, |
| 502 | QAM256_mod_tab[i].data); |
Michael Krufky | 2e7acd7 | 2008-09-03 16:46:35 -0300 | [diff] [blame] | 503 | au8522_set_if(fe, state->config->qam_if); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 504 | break; |
| 505 | default: |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 506 | dprintk("%s() Invalid modulation\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 507 | return -EINVAL; |
| 508 | } |
| 509 | |
| 510 | state->current_modulation = m; |
| 511 | |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | /* Talk to the demod, set the FEC, GUARD, QAM settings etc */ |
Mauro Carvalho Chehab | 9b6a132 | 2011-12-22 09:53:20 -0300 | [diff] [blame] | 516 | static int au8522_set_frontend(struct dvb_frontend *fe) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 517 | { |
Mauro Carvalho Chehab | 9b6a132 | 2011-12-22 09:53:20 -0300 | [diff] [blame] | 518 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 519 | struct au8522_state *state = fe->demodulator_priv; |
Michael Krufky | 74d5072 | 2008-06-13 20:33:23 -0300 | [diff] [blame] | 520 | int ret = -EINVAL; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 521 | |
Mauro Carvalho Chehab | 9b6a132 | 2011-12-22 09:53:20 -0300 | [diff] [blame] | 522 | dprintk("%s(frequency=%d)\n", __func__, c->frequency); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 523 | |
Mauro Carvalho Chehab | 9b6a132 | 2011-12-22 09:53:20 -0300 | [diff] [blame] | 524 | if ((state->current_frequency == c->frequency) && |
| 525 | (state->current_modulation == c->modulation)) |
Michael Krufky | 74d5072 | 2008-06-13 20:33:23 -0300 | [diff] [blame] | 526 | return 0; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 527 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 528 | if (fe->ops.tuner_ops.set_params) { |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 529 | if (fe->ops.i2c_gate_ctrl) |
| 530 | fe->ops.i2c_gate_ctrl(fe, 1); |
Mauro Carvalho Chehab | 14d24d1 | 2011-12-24 12:24:33 -0300 | [diff] [blame] | 531 | ret = fe->ops.tuner_ops.set_params(fe); |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 532 | if (fe->ops.i2c_gate_ctrl) |
| 533 | fe->ops.i2c_gate_ctrl(fe, 0); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 534 | } |
| 535 | |
Michael Krufky | 74d5072 | 2008-06-13 20:33:23 -0300 | [diff] [blame] | 536 | if (ret < 0) |
| 537 | return ret; |
| 538 | |
Michael Krufky | ef3d2dc | 2012-03-12 17:07:22 -0300 | [diff] [blame] | 539 | /* Allow the tuner to settle */ |
| 540 | msleep(100); |
| 541 | |
| 542 | au8522_enable_modulation(fe, c->modulation); |
| 543 | |
Mauro Carvalho Chehab | 9b6a132 | 2011-12-22 09:53:20 -0300 | [diff] [blame] | 544 | state->current_frequency = c->frequency; |
Michael Krufky | 74d5072 | 2008-06-13 20:33:23 -0300 | [diff] [blame] | 545 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 546 | return 0; |
| 547 | } |
| 548 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 549 | 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] | 550 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 551 | struct au8522_state *state = fe->demodulator_priv; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 552 | u8 reg; |
| 553 | u32 tuner_status = 0; |
| 554 | |
| 555 | *status = 0; |
| 556 | |
| 557 | if (state->current_modulation == VSB_8) { |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 558 | dprintk("%s() Checking VSB_8\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 559 | reg = au8522_readreg(state, 0x4088); |
Steven Toth | 836c285 | 2008-06-21 19:32:41 -0300 | [diff] [blame] | 560 | if ((reg & 0x03) == 0x03) |
| 561 | *status |= FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 562 | } else { |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 563 | dprintk("%s() Checking QAM\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 564 | reg = au8522_readreg(state, 0x4541); |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 565 | if (reg & 0x80) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 566 | *status |= FE_HAS_VITERBI; |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 567 | if (reg & 0x20) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 568 | *status |= FE_HAS_LOCK | FE_HAS_SYNC; |
| 569 | } |
| 570 | |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 571 | switch (state->config->status_mode) { |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 572 | case AU8522_DEMODLOCKING: |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 573 | dprintk("%s() DEMODLOCKING\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 574 | if (*status & FE_HAS_VITERBI) |
| 575 | *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL; |
| 576 | break; |
| 577 | case AU8522_TUNERLOCKING: |
| 578 | /* Get the tuner status */ |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 579 | dprintk("%s() TUNERLOCKING\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 580 | if (fe->ops.tuner_ops.get_status) { |
| 581 | if (fe->ops.i2c_gate_ctrl) |
| 582 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 583 | |
| 584 | fe->ops.tuner_ops.get_status(fe, &tuner_status); |
| 585 | |
| 586 | if (fe->ops.i2c_gate_ctrl) |
| 587 | fe->ops.i2c_gate_ctrl(fe, 0); |
| 588 | } |
| 589 | if (tuner_status) |
| 590 | *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL; |
| 591 | break; |
| 592 | } |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 593 | state->fe_status = *status; |
| 594 | |
| 595 | if (*status & FE_HAS_LOCK) |
| 596 | /* turn on LED, if it isn't on already */ |
| 597 | au8522_led_ctrl(state, -1); |
| 598 | else |
| 599 | /* turn off LED */ |
| 600 | au8522_led_ctrl(state, 0); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 601 | |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 602 | dprintk("%s() status 0x%08x\n", __func__, *status); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 603 | |
| 604 | return 0; |
| 605 | } |
| 606 | |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 607 | static int au8522_led_status(struct au8522_state *state, const u16 *snr) |
| 608 | { |
| 609 | struct au8522_led_config *led_config = state->config->led_cfg; |
| 610 | int led; |
| 611 | u16 strong; |
| 612 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 613 | /* bail out if we can't control an LED */ |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 614 | if (!led_config) |
| 615 | return 0; |
| 616 | |
| 617 | if (0 == (state->fe_status & FE_HAS_LOCK)) |
| 618 | return au8522_led_ctrl(state, 0); |
| 619 | else if (state->current_modulation == QAM_256) |
| 620 | strong = led_config->qam256_strong; |
| 621 | else if (state->current_modulation == QAM_64) |
| 622 | strong = led_config->qam64_strong; |
| 623 | else /* (state->current_modulation == VSB_8) */ |
| 624 | strong = led_config->vsb8_strong; |
| 625 | |
| 626 | if (*snr >= strong) |
| 627 | led = 2; |
| 628 | else |
| 629 | led = 1; |
| 630 | |
| 631 | if ((state->led_state) && |
| 632 | (((strong < *snr) ? (*snr - strong) : (strong - *snr)) <= 10)) |
| 633 | /* snr didn't change enough to bother |
| 634 | * changing the color of the led */ |
| 635 | return 0; |
| 636 | |
| 637 | return au8522_led_ctrl(state, led); |
| 638 | } |
| 639 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 640 | static int au8522_read_snr(struct dvb_frontend *fe, u16 *snr) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 641 | { |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 642 | struct au8522_state *state = fe->demodulator_priv; |
| 643 | int ret = -EINVAL; |
| 644 | |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 645 | dprintk("%s()\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 646 | |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 647 | if (state->current_modulation == QAM_256) |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 648 | ret = au8522_mse2snr_lookup(qam256_mse2snr_tab, |
| 649 | ARRAY_SIZE(qam256_mse2snr_tab), |
| 650 | au8522_readreg(state, 0x4522), |
| 651 | snr); |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 652 | else if (state->current_modulation == QAM_64) |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 653 | ret = au8522_mse2snr_lookup(qam64_mse2snr_tab, |
| 654 | ARRAY_SIZE(qam64_mse2snr_tab), |
| 655 | au8522_readreg(state, 0x4522), |
| 656 | snr); |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 657 | else /* VSB_8 */ |
Michael Krufky | 0daa5de | 2008-04-10 04:24:56 -0300 | [diff] [blame] | 658 | ret = au8522_mse2snr_lookup(vsb_mse2snr_tab, |
| 659 | ARRAY_SIZE(vsb_mse2snr_tab), |
| 660 | au8522_readreg(state, 0x4311), |
| 661 | snr); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 662 | |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 663 | if (state->config->led_cfg) |
| 664 | au8522_led_status(state, snr); |
| 665 | |
Steven Toth | f01699b | 2008-04-10 02:01:48 -0300 | [diff] [blame] | 666 | return ret; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 667 | } |
| 668 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 669 | static int au8522_read_signal_strength(struct dvb_frontend *fe, |
| 670 | u16 *signal_strength) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 671 | { |
Michael Krufky | 5279b1f | 2011-10-31 08:11:00 -0300 | [diff] [blame] | 672 | /* borrowed from lgdt330x.c |
| 673 | * |
| 674 | * Calculate strength from SNR up to 35dB |
| 675 | * Even though the SNR can go higher than 35dB, |
| 676 | * there is some comfort factor in having a range of |
| 677 | * strong signals that can show at 100% |
| 678 | */ |
| 679 | u16 snr; |
| 680 | u32 tmp; |
| 681 | int ret = au8522_read_snr(fe, &snr); |
| 682 | |
| 683 | *signal_strength = 0; |
| 684 | |
| 685 | if (0 == ret) { |
| 686 | /* The following calculation method was chosen |
| 687 | * purely for the sake of code re-use from the |
| 688 | * other demod drivers that use this method */ |
| 689 | |
| 690 | /* Convert from SNR in dB * 10 to 8.24 fixed-point */ |
| 691 | tmp = (snr * ((1 << 24) / 10)); |
| 692 | |
| 693 | /* Convert from 8.24 fixed-point to |
| 694 | * scale the range 0 - 35*2^24 into 0 - 65535*/ |
| 695 | if (tmp >= 8960 * 0x10000) |
| 696 | *signal_strength = 0xffff; |
| 697 | else |
| 698 | *signal_strength = tmp / 8960; |
| 699 | } |
| 700 | |
| 701 | return ret; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 702 | } |
| 703 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 704 | static int au8522_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 705 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 706 | struct au8522_state *state = fe->demodulator_priv; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 707 | |
Michael Krufky | 8973dc4 | 2008-04-05 23:08:08 -0300 | [diff] [blame] | 708 | if (state->current_modulation == VSB_8) |
| 709 | *ucblocks = au8522_readreg(state, 0x4087); |
| 710 | else |
| 711 | *ucblocks = au8522_readreg(state, 0x4543); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 712 | |
| 713 | return 0; |
| 714 | } |
| 715 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 716 | static int au8522_read_ber(struct dvb_frontend *fe, u32 *ber) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 717 | { |
| 718 | return au8522_read_ucblocks(fe, ber); |
| 719 | } |
| 720 | |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 721 | static int au8522_get_frontend(struct dvb_frontend *fe) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 722 | { |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 723 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 724 | struct au8522_state *state = fe->demodulator_priv; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 725 | |
Mauro Carvalho Chehab | 9b6a132 | 2011-12-22 09:53:20 -0300 | [diff] [blame] | 726 | c->frequency = state->current_frequency; |
| 727 | c->modulation = state->current_modulation; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 728 | |
| 729 | return 0; |
| 730 | } |
| 731 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 732 | static int au8522_get_tune_settings(struct dvb_frontend *fe, |
| 733 | struct dvb_frontend_tune_settings *tune) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 734 | { |
| 735 | tune->min_delay_ms = 1000; |
| 736 | return 0; |
| 737 | } |
| 738 | |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 739 | static struct dvb_frontend_ops au8522_ops; |
| 740 | |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 741 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 742 | static void au8522_release(struct dvb_frontend *fe) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 743 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 744 | struct au8522_state *state = fe->demodulator_priv; |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 745 | au8522_release_state(state); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 746 | } |
| 747 | |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 748 | struct dvb_frontend *au8522_attach(const struct au8522_config *config, |
| 749 | struct i2c_adapter *i2c) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 750 | { |
Michael Krufky | e059b0f | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 751 | struct au8522_state *state = NULL; |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 752 | int instance; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 753 | |
| 754 | /* allocate memory for the internal state */ |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 755 | instance = au8522_get_state(&state, i2c, config->demod_address); |
| 756 | switch (instance) { |
| 757 | case 0: |
| 758 | dprintk("%s state allocation failed\n", __func__); |
| 759 | break; |
| 760 | case 1: |
| 761 | /* new demod instance */ |
| 762 | dprintk("%s using new instance\n", __func__); |
| 763 | break; |
| 764 | default: |
| 765 | /* existing demod instance */ |
| 766 | dprintk("%s using existing instance\n", __func__); |
| 767 | break; |
| 768 | } |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 769 | |
| 770 | /* setup the state */ |
| 771 | state->config = config; |
| 772 | state->i2c = i2c; |
Devin Heitmueller | 7f2c983 | 2010-02-17 22:47:55 -0300 | [diff] [blame] | 773 | state->operational_mode = AU8522_DIGITAL_MODE; |
| 774 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 775 | /* create dvb_frontend */ |
| 776 | memcpy(&state->frontend.ops, &au8522_ops, |
| 777 | sizeof(struct dvb_frontend_ops)); |
| 778 | state->frontend.demodulator_priv = state; |
| 779 | |
| 780 | if (au8522_init(&state->frontend) != 0) { |
| 781 | printk(KERN_ERR "%s: Failed to initialize correctly\n", |
Michael Krufky | ce1719a | 2008-04-02 18:59:48 -0300 | [diff] [blame] | 782 | __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 783 | goto error; |
| 784 | } |
| 785 | |
| 786 | /* Note: Leaving the I2C gate open here. */ |
| 787 | au8522_i2c_gate_ctrl(&state->frontend, 1); |
| 788 | |
| 789 | return &state->frontend; |
| 790 | |
| 791 | error: |
Devin Heitmueller | 209fdf6 | 2009-03-11 03:00:36 -0300 | [diff] [blame] | 792 | au8522_release_state(state); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 793 | return NULL; |
| 794 | } |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 795 | EXPORT_SYMBOL(au8522_attach); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 796 | |
| 797 | static struct dvb_frontend_ops au8522_ops = { |
Mauro Carvalho Chehab | 9b6a132 | 2011-12-22 09:53:20 -0300 | [diff] [blame] | 798 | .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B }, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 799 | .info = { |
| 800 | .name = "Auvitek AU8522 QAM/8VSB Frontend", |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 801 | .frequency_min = 54000000, |
| 802 | .frequency_max = 858000000, |
| 803 | .frequency_stepsize = 62500, |
| 804 | .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB |
| 805 | }, |
| 806 | |
| 807 | .init = au8522_init, |
Michael Krufky | 74d5072 | 2008-06-13 20:33:23 -0300 | [diff] [blame] | 808 | .sleep = au8522_sleep, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 809 | .i2c_gate_ctrl = au8522_i2c_gate_ctrl, |
Mauro Carvalho Chehab | 9b6a132 | 2011-12-22 09:53:20 -0300 | [diff] [blame] | 810 | .set_frontend = au8522_set_frontend, |
| 811 | .get_frontend = au8522_get_frontend, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 812 | .get_tune_settings = au8522_get_tune_settings, |
| 813 | .read_status = au8522_read_status, |
| 814 | .read_ber = au8522_read_ber, |
| 815 | .read_signal_strength = au8522_read_signal_strength, |
| 816 | .read_snr = au8522_read_snr, |
| 817 | .read_ucblocks = au8522_read_ucblocks, |
| 818 | .release = au8522_release, |
| 819 | }; |
| 820 | |
| 821 | module_param(debug, int, 0644); |
| 822 | MODULE_PARM_DESC(debug, "Enable verbose debug messages"); |
| 823 | |
| 824 | MODULE_DESCRIPTION("Auvitek AU8522 QAM-B/ATSC Demodulator driver"); |
| 825 | MODULE_AUTHOR("Steven Toth"); |
| 826 | MODULE_LICENSE("GPL"); |