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