1 /* 2 * Montage Technology M88DS3103/M88RS6000 demodulator driver 3 * 4 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi> 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 17 #ifndef M88DS3103_PRIV_H 18 #define M88DS3103_PRIV_H 19 20 #include "dvb_frontend.h" 21 #include "m88ds3103.h" 22 #include "dvb_math.h" 23 #include <linux/firmware.h> 24 #include <linux/i2c-mux.h> 25 #include <linux/regmap.h> 26 #include <linux/math64.h> 27 28 #define M88DS3103_FIRMWARE "dvb-demod-m88ds3103.fw" 29 #define M88RS6000_FIRMWARE "dvb-demod-m88rs6000.fw" 30 #define M88DS3103_MCLK_KHZ 96000 31 #define M88RS6000_CHIP_ID 0x74 32 #define M88DS3103_CHIP_ID 0x70 33 34 struct m88ds3103_dev { 35 struct i2c_client *client; 36 struct regmap_config regmap_config; 37 struct regmap *regmap; 38 struct m88ds3103_config config; 39 const struct m88ds3103_config *cfg; 40 struct dvb_frontend fe; 41 enum fe_delivery_system delivery_system; 42 enum fe_status fe_status; 43 u32 dvbv3_ber; /* for old DVBv3 API read_ber */ 44 bool warm; /* FW running */ 45 struct i2c_adapter *i2c_adapter; 46 /* auto detect chip id to do different config */ 47 u8 chip_id; 48 /* main mclk is calculated for M88RS6000 dynamically */ 49 u32 mclk_khz; 50 u64 post_bit_error; 51 u64 post_bit_count; 52 }; 53 54 struct m88ds3103_reg_val { 55 u8 reg; 56 u8 val; 57 }; 58 59 static const struct m88ds3103_reg_val m88ds3103_dvbs_init_reg_vals[] = { 60 {0x23, 0x07}, 61 {0x08, 0x03}, 62 {0x0c, 0x02}, 63 {0x21, 0x54}, 64 {0x25, 0x8a}, 65 {0x27, 0x31}, 66 {0x30, 0x08}, 67 {0x31, 0x40}, 68 {0x32, 0x32}, 69 {0x35, 0xff}, 70 {0x3a, 0x00}, 71 {0x37, 0x10}, 72 {0x38, 0x10}, 73 {0x39, 0x02}, 74 {0x42, 0x60}, 75 {0x4a, 0x80}, 76 {0x4b, 0x04}, 77 {0x4d, 0x91}, 78 {0x5d, 0xc8}, 79 {0x50, 0x36}, 80 {0x51, 0x36}, 81 {0x52, 0x36}, 82 {0x53, 0x36}, 83 {0x56, 0x01}, 84 {0x63, 0x0f}, 85 {0x64, 0x30}, 86 {0x65, 0x40}, 87 {0x68, 0x26}, 88 {0x69, 0x4c}, 89 {0x70, 0x20}, 90 {0x71, 0x70}, 91 {0x72, 0x04}, 92 {0x73, 0x00}, 93 {0x70, 0x40}, 94 {0x71, 0x70}, 95 {0x72, 0x04}, 96 {0x73, 0x00}, 97 {0x70, 0x60}, 98 {0x71, 0x70}, 99 {0x72, 0x04}, 100 {0x73, 0x00}, 101 {0x70, 0x80}, 102 {0x71, 0x70}, 103 {0x72, 0x04}, 104 {0x73, 0x00}, 105 {0x70, 0xa0}, 106 {0x71, 0x70}, 107 {0x72, 0x04}, 108 {0x73, 0x00}, 109 {0x70, 0x1f}, 110 {0x76, 0x38}, 111 {0x77, 0xa6}, 112 {0x78, 0x0c}, 113 {0x79, 0x80}, 114 {0x7f, 0x14}, 115 {0x7c, 0x00}, 116 {0xae, 0x82}, 117 {0x80, 0x64}, 118 {0x81, 0x66}, 119 {0x82, 0x44}, 120 {0x85, 0x04}, 121 {0xcd, 0xf4}, 122 {0x90, 0x33}, 123 {0xa0, 0x44}, 124 {0xc0, 0x08}, 125 {0xc3, 0x10}, 126 {0xc4, 0x08}, 127 {0xc5, 0xf0}, 128 {0xc6, 0xff}, 129 {0xc7, 0x00}, 130 {0xc8, 0x1a}, 131 {0xc9, 0x80}, 132 {0xe0, 0xf8}, 133 {0xe6, 0x8b}, 134 {0xd0, 0x40}, 135 {0xf8, 0x20}, 136 {0xfa, 0x0f}, 137 {0x00, 0x00}, 138 {0xbd, 0x01}, 139 {0xb8, 0x00}, 140 }; 141 142 static const struct m88ds3103_reg_val m88ds3103_dvbs2_init_reg_vals[] = { 143 {0x23, 0x07}, 144 {0x08, 0x07}, 145 {0x0c, 0x02}, 146 {0x21, 0x54}, 147 {0x25, 0x8a}, 148 {0x27, 0x31}, 149 {0x30, 0x08}, 150 {0x32, 0x32}, 151 {0x35, 0xff}, 152 {0x3a, 0x00}, 153 {0x37, 0x10}, 154 {0x38, 0x10}, 155 {0x39, 0x02}, 156 {0x42, 0x60}, 157 {0x4a, 0x80}, 158 {0x4b, 0x04}, 159 {0x4d, 0x91}, 160 {0x5d, 0xc8}, 161 {0x50, 0x36}, 162 {0x51, 0x36}, 163 {0x52, 0x36}, 164 {0x53, 0x36}, 165 {0x56, 0x01}, 166 {0x63, 0x0f}, 167 {0x64, 0x10}, 168 {0x65, 0x20}, 169 {0x68, 0x46}, 170 {0x69, 0xcd}, 171 {0x70, 0x20}, 172 {0x71, 0x70}, 173 {0x72, 0x04}, 174 {0x73, 0x00}, 175 {0x70, 0x40}, 176 {0x71, 0x70}, 177 {0x72, 0x04}, 178 {0x73, 0x00}, 179 {0x70, 0x60}, 180 {0x71, 0x70}, 181 {0x72, 0x04}, 182 {0x73, 0x00}, 183 {0x70, 0x80}, 184 {0x71, 0x70}, 185 {0x72, 0x04}, 186 {0x73, 0x00}, 187 {0x70, 0xa0}, 188 {0x71, 0x70}, 189 {0x72, 0x04}, 190 {0x73, 0x00}, 191 {0x70, 0x1f}, 192 {0x76, 0x38}, 193 {0x77, 0xa6}, 194 {0x78, 0x0c}, 195 {0x79, 0x80}, 196 {0x7f, 0x14}, 197 {0x85, 0x08}, 198 {0xcd, 0xf4}, 199 {0x90, 0x33}, 200 {0x86, 0x00}, 201 {0x87, 0x0f}, 202 {0x89, 0x00}, 203 {0x8b, 0x44}, 204 {0x8c, 0x66}, 205 {0x9d, 0xc1}, 206 {0x8a, 0x10}, 207 {0xad, 0x40}, 208 {0xa0, 0x44}, 209 {0xc0, 0x08}, 210 {0xc1, 0x10}, 211 {0xc2, 0x08}, 212 {0xc3, 0x10}, 213 {0xc4, 0x08}, 214 {0xc5, 0xf0}, 215 {0xc6, 0xff}, 216 {0xc7, 0x00}, 217 {0xc8, 0x1a}, 218 {0xc9, 0x80}, 219 {0xca, 0x23}, 220 {0xcb, 0x24}, 221 {0xcc, 0xf4}, 222 {0xce, 0x74}, 223 {0x00, 0x00}, 224 {0xbd, 0x01}, 225 {0xb8, 0x00}, 226 }; 227 228 static const struct m88ds3103_reg_val m88rs6000_dvbs_init_reg_vals[] = { 229 {0x23, 0x07}, 230 {0x08, 0x03}, 231 {0x0c, 0x02}, 232 {0x20, 0x00}, 233 {0x21, 0x54}, 234 {0x25, 0x82}, 235 {0x27, 0x31}, 236 {0x30, 0x08}, 237 {0x31, 0x40}, 238 {0x32, 0x32}, 239 {0x33, 0x35}, 240 {0x35, 0xff}, 241 {0x3a, 0x00}, 242 {0x37, 0x10}, 243 {0x38, 0x10}, 244 {0x39, 0x02}, 245 {0x42, 0x60}, 246 {0x4a, 0x80}, 247 {0x4b, 0x04}, 248 {0x4d, 0x91}, 249 {0x5d, 0xc8}, 250 {0x50, 0x36}, 251 {0x51, 0x36}, 252 {0x52, 0x36}, 253 {0x53, 0x36}, 254 {0x63, 0x0f}, 255 {0x64, 0x30}, 256 {0x65, 0x40}, 257 {0x68, 0x26}, 258 {0x69, 0x4c}, 259 {0x70, 0x20}, 260 {0x71, 0x70}, 261 {0x72, 0x04}, 262 {0x73, 0x00}, 263 {0x70, 0x40}, 264 {0x71, 0x70}, 265 {0x72, 0x04}, 266 {0x73, 0x00}, 267 {0x70, 0x60}, 268 {0x71, 0x70}, 269 {0x72, 0x04}, 270 {0x73, 0x00}, 271 {0x70, 0x80}, 272 {0x71, 0x70}, 273 {0x72, 0x04}, 274 {0x73, 0x00}, 275 {0x70, 0xa0}, 276 {0x71, 0x70}, 277 {0x72, 0x04}, 278 {0x73, 0x00}, 279 {0x70, 0x1f}, 280 {0x76, 0x38}, 281 {0x77, 0xa6}, 282 {0x78, 0x0c}, 283 {0x79, 0x80}, 284 {0x7f, 0x14}, 285 {0x7c, 0x00}, 286 {0xae, 0x82}, 287 {0x80, 0x64}, 288 {0x81, 0x66}, 289 {0x82, 0x44}, 290 {0x85, 0x04}, 291 {0xcd, 0xf4}, 292 {0x90, 0x33}, 293 {0xa0, 0x44}, 294 {0xbe, 0x00}, 295 {0xc0, 0x08}, 296 {0xc3, 0x10}, 297 {0xc4, 0x08}, 298 {0xc5, 0xf0}, 299 {0xc6, 0xff}, 300 {0xc7, 0x00}, 301 {0xc8, 0x1a}, 302 {0xc9, 0x80}, 303 {0xe0, 0xf8}, 304 {0xe6, 0x8b}, 305 {0xd0, 0x40}, 306 {0xf8, 0x20}, 307 {0xfa, 0x0f}, 308 {0x00, 0x00}, 309 {0xbd, 0x01}, 310 {0xb8, 0x00}, 311 {0x29, 0x11}, 312 }; 313 314 static const struct m88ds3103_reg_val m88rs6000_dvbs2_init_reg_vals[] = { 315 {0x23, 0x07}, 316 {0x08, 0x07}, 317 {0x0c, 0x02}, 318 {0x20, 0x00}, 319 {0x21, 0x54}, 320 {0x25, 0x82}, 321 {0x27, 0x31}, 322 {0x30, 0x08}, 323 {0x32, 0x32}, 324 {0x33, 0x35}, 325 {0x35, 0xff}, 326 {0x3a, 0x00}, 327 {0x37, 0x10}, 328 {0x38, 0x10}, 329 {0x39, 0x02}, 330 {0x42, 0x60}, 331 {0x4a, 0x80}, 332 {0x4b, 0x04}, 333 {0x4d, 0x91}, 334 {0x5d, 0xc8}, 335 {0x50, 0x36}, 336 {0x51, 0x36}, 337 {0x52, 0x36}, 338 {0x53, 0x36}, 339 {0x63, 0x0f}, 340 {0x64, 0x10}, 341 {0x65, 0x20}, 342 {0x68, 0x46}, 343 {0x69, 0xcd}, 344 {0x70, 0x20}, 345 {0x71, 0x70}, 346 {0x72, 0x04}, 347 {0x73, 0x00}, 348 {0x70, 0x40}, 349 {0x71, 0x70}, 350 {0x72, 0x04}, 351 {0x73, 0x00}, 352 {0x70, 0x60}, 353 {0x71, 0x70}, 354 {0x72, 0x04}, 355 {0x73, 0x00}, 356 {0x70, 0x80}, 357 {0x71, 0x70}, 358 {0x72, 0x04}, 359 {0x73, 0x00}, 360 {0x70, 0xa0}, 361 {0x71, 0x70}, 362 {0x72, 0x04}, 363 {0x73, 0x00}, 364 {0x70, 0x1f}, 365 {0x76, 0x38}, 366 {0x77, 0xa6}, 367 {0x78, 0x0c}, 368 {0x79, 0x80}, 369 {0x7f, 0x14}, 370 {0x85, 0x08}, 371 {0xcd, 0xf4}, 372 {0x90, 0x33}, 373 {0x86, 0x00}, 374 {0x87, 0x0f}, 375 {0x89, 0x00}, 376 {0x8b, 0x44}, 377 {0x8c, 0x66}, 378 {0x9d, 0xc1}, 379 {0x8a, 0x10}, 380 {0xad, 0x40}, 381 {0xa0, 0x44}, 382 {0xbe, 0x00}, 383 {0xc0, 0x08}, 384 {0xc1, 0x10}, 385 {0xc2, 0x08}, 386 {0xc3, 0x10}, 387 {0xc4, 0x08}, 388 {0xc5, 0xf0}, 389 {0xc6, 0xff}, 390 {0xc7, 0x00}, 391 {0xc8, 0x1a}, 392 {0xc9, 0x80}, 393 {0xca, 0x23}, 394 {0xcb, 0x24}, 395 {0xcc, 0xf4}, 396 {0xce, 0x74}, 397 {0x00, 0x00}, 398 {0xbd, 0x01}, 399 {0xb8, 0x00}, 400 {0x29, 0x01}, 401 }; 402 #endif 403