/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Afatech AF9013 demodulator driver
*
* Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
* Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
*
* Thanks to Afatech who kindly provided information.
*/
#ifndef AF9013_PRIV_H
#define AF9013_PRIV_H
#include <media/dvb_frontend.h>
#include <media/dvb_math.h>
#include "af9013.h"
#include <linux/firmware.h>
#include <linux/i2c-mux.h>
#include <linux/math64.h>
#include <linux/regmap.h>
#define AF9013_FIRMWARE "dvb-fe-af9013.fw"
struct af9013_reg_mask_val {
u16 reg;
u8 mask;
u8 val;
};
struct af9013_coeff {
u32 clock;
u32 bandwidth_hz;
u8 val[24];
};
/* pre-calculated coeff lookup table */
static const struct af9013_coeff coeff_lut[] = {
/* 28.800 MHz */
{ 28800000, 8000000, { 0x02, 0x8a, 0x28, 0xa3, 0x05, 0x14,
0x51, 0x11, 0x00, 0xa2, 0x8f, 0x3d, 0x00, 0xa2, 0x8a,
0x29, 0x00, 0xa2, 0x85, 0x14, 0x01, 0x45, 0x14, 0x14 } },
{ 28800000, 7000000, { 0x02, 0x38, 0xe3, 0x8e, 0x04, 0x71,
0xc7, 0x07, 0x00, 0x8e, 0x3d, 0x55, 0x00, 0x8e, 0x38,
0xe4, 0x00, 0x8e, 0x34, 0x72, 0x01, 0x1c, 0x71, 0x32 } },
{ 28800000, 6000000, { 0x01, 0xe7, 0x9e, 0x7a, 0x03, 0xcf,
0x3c, 0x3d, 0x00, 0x79, 0xeb, 0x6e, 0x00, 0x79, 0xe7,
0x9e, 0x00, 0x79, 0xe3, 0xcf, 0x00, 0xf3, 0xcf, 0x0f } },
/* 20.480 MHz */
{ 20480000, 8000000, { 0x03, 0x92, 0x49, 0x26, 0x07, 0x24,
0x92, 0x13, 0x00, 0xe4, 0x99, 0x6e, 0x00, 0xe4, 0x92,
0x49, 0x00, 0xe4, 0x8b, 0x25, 0x01, 0xc9, 0x24, 0x25 } },
{ 20480000, 7000000, { 0x03, 0x20, 0x00, 0x01, 0x06, 0x40,
0x00, 0x00, 0x00, 0xc8, 0x06, 0x40, 0x00, 0xc8, 0x00,
0x00, 0x00, 0xc7, 0xf9, 0xc0, 0x01, 0x90, 0x00, 0x00 } },
{ 20480000, 6000000, { 0x02, 0xad, 0xb6, 0xdc, 0x05, 0x5b,
0x6d, 0x2e, 0x00, 0xab, 0x73, 0x13, 0x00, 0xab, 0x6d,
0xb7, 0x00, 0xab, 0x68, 0x5c, 0x01, 0x56, 0xdb, 0x1c } },
/* 28.000 MHz */
{ 28000000, 8000000, { 0x02, 0x9c, 0xbc, 0x15, 0x05, 0x39,
0x78, 0x0a, 0x00, 0xa7, 0x34, 0x3f, 0x00, 0xa7, 0x2f,
0x05, 0x00, 0xa7, 0x29, 0xcc, 0x01, 0x4e, 0x5e, 0x03 } },
{ 28000000, 7000000, { 0x02, 0x49, 0x24, 0x92, 0x04, 0x92,
0x49, 0x09, 0x00, 0x92, 0x4d, 0xb7, 0x00, 0x92, 0x49,
0x25, 0x00, 0x92, 0x44, 0x92, 0x01, 0x24, 0x92, 0x12 } },
{ 28000000, 6000000, { 0x01, 0xf5, 0x8d, 0x10, 0x03, 0xeb,
0x1a, 0x08, 0x00, 0x7d, 0x67, 0x2f, 0x00, 0x7d, 0x63,
0x44, 0x00, 0x7d, 0x5f, 0x59, 0x00, 0xfa, 0xc6, 0x22 } },
/* 25.000 MHz */
{ 25000000, 8000000, { 0x02, 0xec, 0xfb, 0x9d, 0x05, 0xd9,
0xf7, 0x0e, 0x00, 0xbb, 0x44, 0xc1, 0x00, 0xbb, 0x3e,
0xe7, 0x00, 0xbb, 0x39, 0x0d, 0x01, 0x76, 0x7d, 0x34 } },
{ 25000000, 7000000, { 0x02, 0x8f, 0x5c, 0x29, 0x05, 0x1e,
0xb8, 0x14, 0x00, 0xa3, 0xdc, 0x29, 0x00, 0xa3, 0xd7,
0x0a, 0x00, 0xa3, 0xd1, 0xec, 0x01, 0x47, 0xae, 0x05 } },
{ 25000000, 6000000, { 0x02, 0x31, 0xbc, 0xb5, 0x04, 0x63,
0x79, 0x1b, 0x00, 0x8c, 0x73, 0x91, 0x00, 0x8c, 0x6f,
0x2d, 0x00, 0x8c, 0x6a, 0xca, 0x01, 0x18, 0xde, 0x17 } },
};
/*
* Afatech AF9013 demod init
*/
static const struct af9013_reg_mask_val demod_init_tab[] = {
{0xd73a, 0xff, 0xa1},
{0xd73b, 0xff, 0x1f},
{0xd73c, 0xf0, 0xa0},
{0xd732, 0x08, 0x00},
{0xd731, 0x30, 0x30},
{0xd73d, 0x80, 0x80},
{0xd740, 0x01, 0x00},
{0xd740, 0x02, 0x00},
{0xd740, 0x04, 0x00},
{0xd740, 0x08, 0x08},
{0xd3c1, 0x10, 0x10},
{0x9124, 0xff, 0x58},
{0x9125, 0x03, 0x02},
{0xd3a2, 0xff, 0x00},
{0xd3a3, 0xff, 0x04},
{0xd305, 0xff, 0x32},
{0xd306, 0xff, 0x10},
{0xd304, 0xff, 0x04},
{0x9112, 0x01, 0x01},
{0x911d, 0x01, 0x01},
{0x911a, 0x01, 0x01},
{0x911b, 0x01, 0x01},
{0x9bce, 0x0f, 0x02},
{0x9116, 0x01, 0x01},
{0x9122, 0xff, 0xd0},
{0xd2e0, 0xff, 0xd0},
{0xd2e9, 0x0f, 0x0d},
{0xd38c, 0xff, 0xfc},
{0xd38d, 0xff, 0x00},
{0xd38e, 0xff, 0x7e},
{0xd38f, 0xff, 0x00},
{0xd390, 0xff, 0x2f},
{0xd145, 0x10, 0x10},
{0xd1a9, 0x10, 0x10},
{0xd158, 0xe0, 0x20},
{0xd159, 0x3f, 0x06},
{0xd167, 0xff, 0x00},
{0xd168