18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Elonics E4000 silicon tuner driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2012 Antti Palosaari <crope@iki.fi> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef E4000_PRIV_H 98c2ecf20Sopenharmony_ci#define E4000_PRIV_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include "e4000.h" 128c2ecf20Sopenharmony_ci#include <linux/math64.h> 138c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h> 148c2ecf20Sopenharmony_ci#include <media/v4l2-subdev.h> 158c2ecf20Sopenharmony_ci#include <linux/regmap.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cistruct e4000_dev { 188c2ecf20Sopenharmony_ci struct i2c_client *client; 198c2ecf20Sopenharmony_ci struct regmap *regmap; 208c2ecf20Sopenharmony_ci u32 clk; 218c2ecf20Sopenharmony_ci struct dvb_frontend *fe; 228c2ecf20Sopenharmony_ci struct v4l2_subdev sd; 238c2ecf20Sopenharmony_ci bool active; 248c2ecf20Sopenharmony_ci unsigned int f_frequency; 258c2ecf20Sopenharmony_ci unsigned int f_bandwidth; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci /* Controls */ 288c2ecf20Sopenharmony_ci struct v4l2_ctrl_handler hdl; 298c2ecf20Sopenharmony_ci struct v4l2_ctrl *bandwidth_auto; 308c2ecf20Sopenharmony_ci struct v4l2_ctrl *bandwidth; 318c2ecf20Sopenharmony_ci struct v4l2_ctrl *lna_gain_auto; 328c2ecf20Sopenharmony_ci struct v4l2_ctrl *lna_gain; 338c2ecf20Sopenharmony_ci struct v4l2_ctrl *mixer_gain_auto; 348c2ecf20Sopenharmony_ci struct v4l2_ctrl *mixer_gain; 358c2ecf20Sopenharmony_ci struct v4l2_ctrl *if_gain_auto; 368c2ecf20Sopenharmony_ci struct v4l2_ctrl *if_gain; 378c2ecf20Sopenharmony_ci struct v4l2_ctrl *pll_lock; 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct e4000_pll { 418c2ecf20Sopenharmony_ci u32 freq; 428c2ecf20Sopenharmony_ci u8 div_out_reg; 438c2ecf20Sopenharmony_ci u8 div_out; 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic const struct e4000_pll e4000_pll_lut[] = { 478c2ecf20Sopenharmony_ci/* VCO min VCO max */ 488c2ecf20Sopenharmony_ci { 72400000, 0x0f, 48 }, /* .......... 3475200000 */ 498c2ecf20Sopenharmony_ci { 81200000, 0x0e, 40 }, /* 2896000000 3248000000 */ 508c2ecf20Sopenharmony_ci { 108300000, 0x0d, 32 }, /* 2598400000 3465600000 */ 518c2ecf20Sopenharmony_ci { 162500000, 0x0c, 24 }, /* 2599200000 3900000000 */ 528c2ecf20Sopenharmony_ci { 216600000, 0x0b, 16 }, /* 2600000000 3465600000 */ 538c2ecf20Sopenharmony_ci { 325000000, 0x0a, 12 }, /* 2599200000 3900000000 */ 548c2ecf20Sopenharmony_ci { 350000000, 0x09, 8 }, /* 2600000000 2800000000 */ 558c2ecf20Sopenharmony_ci { 432000000, 0x03, 8 }, /* 2800000000 3456000000 */ 568c2ecf20Sopenharmony_ci { 667000000, 0x02, 6 }, /* 2592000000 4002000000 */ 578c2ecf20Sopenharmony_ci { 1200000000, 0x01, 4 }, /* 2668000000 4800000000 */ 588c2ecf20Sopenharmony_ci { 0xffffffff, 0x00, 2 }, /* 2400000000 .......... */ 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistruct e4000_lna_filter { 628c2ecf20Sopenharmony_ci u32 freq; 638c2ecf20Sopenharmony_ci u8 val; 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic const struct e4000_lna_filter e400_lna_filter_lut[] = { 678c2ecf20Sopenharmony_ci { 370000000, 0 }, 688c2ecf20Sopenharmony_ci { 392500000, 1 }, 698c2ecf20Sopenharmony_ci { 415000000, 2 }, 708c2ecf20Sopenharmony_ci { 437500000, 3 }, 718c2ecf20Sopenharmony_ci { 462500000, 4 }, 728c2ecf20Sopenharmony_ci { 490000000, 5 }, 738c2ecf20Sopenharmony_ci { 522500000, 6 }, 748c2ecf20Sopenharmony_ci { 557500000, 7 }, 758c2ecf20Sopenharmony_ci { 595000000, 8 }, 768c2ecf20Sopenharmony_ci { 642500000, 9 }, 778c2ecf20Sopenharmony_ci { 695000000, 10 }, 788c2ecf20Sopenharmony_ci { 740000000, 11 }, 798c2ecf20Sopenharmony_ci { 800000000, 12 }, 808c2ecf20Sopenharmony_ci { 865000000, 13 }, 818c2ecf20Sopenharmony_ci { 930000000, 14 }, 828c2ecf20Sopenharmony_ci { 1000000000, 15 }, 838c2ecf20Sopenharmony_ci { 1310000000, 0 }, 848c2ecf20Sopenharmony_ci { 1340000000, 1 }, 858c2ecf20Sopenharmony_ci { 1385000000, 2 }, 868c2ecf20Sopenharmony_ci { 1427500000, 3 }, 878c2ecf20Sopenharmony_ci { 1452500000, 4 }, 888c2ecf20Sopenharmony_ci { 1475000000, 5 }, 898c2ecf20Sopenharmony_ci { 1510000000, 6 }, 908c2ecf20Sopenharmony_ci { 1545000000, 7 }, 918c2ecf20Sopenharmony_ci { 1575000000, 8 }, 928c2ecf20Sopenharmony_ci { 1615000000, 9 }, 938c2ecf20Sopenharmony_ci { 1650000000, 10 }, 948c2ecf20Sopenharmony_ci { 1670000000, 11 }, 958c2ecf20Sopenharmony_ci { 1690000000, 12 }, 968c2ecf20Sopenharmony_ci { 1710000000, 13 }, 978c2ecf20Sopenharmony_ci { 1735000000, 14 }, 988c2ecf20Sopenharmony_ci { 0xffffffff, 15 }, 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistruct e4000_band { 1028c2ecf20Sopenharmony_ci u32 freq; 1038c2ecf20Sopenharmony_ci u8 reg07_val; 1048c2ecf20Sopenharmony_ci u8 reg78_val; 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic const struct e4000_band e4000_band_lut[] = { 1088c2ecf20Sopenharmony_ci { 140000000, 0x01, 0x03 }, 1098c2ecf20Sopenharmony_ci { 350000000, 0x03, 0x03 }, 1108c2ecf20Sopenharmony_ci { 1000000000, 0x05, 0x03 }, 1118c2ecf20Sopenharmony_ci { 0xffffffff, 0x07, 0x00 }, 1128c2ecf20Sopenharmony_ci}; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistruct e4000_if_filter { 1158c2ecf20Sopenharmony_ci u32 freq; 1168c2ecf20Sopenharmony_ci u8 reg11_val; 1178c2ecf20Sopenharmony_ci u8 reg12_val; 1188c2ecf20Sopenharmony_ci}; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cistatic const struct e4000_if_filter e4000_if_filter_lut[] = { 1218c2ecf20Sopenharmony_ci { 4300000, 0xfd, 0x1f }, 1228c2ecf20Sopenharmony_ci { 4400000, 0xfd, 0x1e }, 1238c2ecf20Sopenharmony_ci { 4480000, 0xfc, 0x1d }, 1248c2ecf20Sopenharmony_ci { 4560000, 0xfc, 0x1c }, 1258c2ecf20Sopenharmony_ci { 4600000, 0xfc, 0x1b }, 1268c2ecf20Sopenharmony_ci { 4800000, 0xfc, 0x1a }, 1278c2ecf20Sopenharmony_ci { 4900000, 0xfc, 0x19 }, 1288c2ecf20Sopenharmony_ci { 5000000, 0xfc, 0x18 }, 1298c2ecf20Sopenharmony_ci { 5100000, 0xfc, 0x17 }, 1308c2ecf20Sopenharmony_ci { 5200000, 0xfc, 0x16 }, 1318c2ecf20Sopenharmony_ci { 5400000, 0xfc, 0x15 }, 1328c2ecf20Sopenharmony_ci { 5500000, 0xfc, 0x14 }, 1338c2ecf20Sopenharmony_ci { 5600000, 0xfc, 0x13 }, 1348c2ecf20Sopenharmony_ci { 5800000, 0xfb, 0x12 }, 1358c2ecf20Sopenharmony_ci { 5900000, 0xfb, 0x11 }, 1368c2ecf20Sopenharmony_ci { 6000000, 0xfb, 0x10 }, 1378c2ecf20Sopenharmony_ci { 6200000, 0xfb, 0x0f }, 1388c2ecf20Sopenharmony_ci { 6400000, 0xfa, 0x0e }, 1398c2ecf20Sopenharmony_ci { 6600000, 0xfa, 0x0d }, 1408c2ecf20Sopenharmony_ci { 6800000, 0xf9, 0x0c }, 1418c2ecf20Sopenharmony_ci { 7200000, 0xf9, 0x0b }, 1428c2ecf20Sopenharmony_ci { 7400000, 0xf9, 0x0a }, 1438c2ecf20Sopenharmony_ci { 7600000, 0xf8, 0x09 }, 1448c2ecf20Sopenharmony_ci { 7800000, 0xf8, 0x08 }, 1458c2ecf20Sopenharmony_ci { 8200000, 0xf8, 0x07 }, 1468c2ecf20Sopenharmony_ci { 8600000, 0xf7, 0x06 }, 1478c2ecf20Sopenharmony_ci { 8800000, 0xf7, 0x05 }, 1488c2ecf20Sopenharmony_ci { 9200000, 0xf7, 0x04 }, 1498c2ecf20Sopenharmony_ci { 9600000, 0xf6, 0x03 }, 1508c2ecf20Sopenharmony_ci { 10000000, 0xf6, 0x02 }, 1518c2ecf20Sopenharmony_ci { 10600000, 0xf5, 0x01 }, 1528c2ecf20Sopenharmony_ci { 11000000, 0xf5, 0x00 }, 1538c2ecf20Sopenharmony_ci { 0xffffffff, 0x00, 0x20 }, 1548c2ecf20Sopenharmony_ci}; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_cistruct e4000_if_gain { 1578c2ecf20Sopenharmony_ci u8 reg16_val; 1588c2ecf20Sopenharmony_ci u8 reg17_val; 1598c2ecf20Sopenharmony_ci}; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_cistatic const struct e4000_if_gain e4000_if_gain_lut[] = { 1628c2ecf20Sopenharmony_ci {0x00, 0x00}, 1638c2ecf20Sopenharmony_ci {0x20, 0x00}, 1648c2ecf20Sopenharmony_ci {0x40, 0x00}, 1658c2ecf20Sopenharmony_ci {0x02, 0x00}, 1668c2ecf20Sopenharmony_ci {0x22, 0x00}, 1678c2ecf20Sopenharmony_ci {0x42, 0x00}, 1688c2ecf20Sopenharmony_ci {0x04, 0x00}, 1698c2ecf20Sopenharmony_ci {0x24, 0x00}, 1708c2ecf20Sopenharmony_ci {0x44, 0x00}, 1718c2ecf20Sopenharmony_ci {0x01, 0x00}, 1728c2ecf20Sopenharmony_ci {0x21, 0x00}, 1738c2ecf20Sopenharmony_ci {0x41, 0x00}, 1748c2ecf20Sopenharmony_ci {0x03, 0x00}, 1758c2ecf20Sopenharmony_ci {0x23, 0x00}, 1768c2ecf20Sopenharmony_ci {0x43, 0x00}, 1778c2ecf20Sopenharmony_ci {0x05, 0x00}, 1788c2ecf20Sopenharmony_ci {0x25, 0x00}, 1798c2ecf20Sopenharmony_ci {0x45, 0x00}, 1808c2ecf20Sopenharmony_ci {0x07, 0x00}, 1818c2ecf20Sopenharmony_ci {0x27, 0x00}, 1828c2ecf20Sopenharmony_ci {0x47, 0x00}, 1838c2ecf20Sopenharmony_ci {0x0f, 0x00}, 1848c2ecf20Sopenharmony_ci {0x2f, 0x00}, 1858c2ecf20Sopenharmony_ci {0x4f, 0x00}, 1868c2ecf20Sopenharmony_ci {0x17, 0x00}, 1878c2ecf20Sopenharmony_ci {0x37, 0x00}, 1888c2ecf20Sopenharmony_ci {0x57, 0x00}, 1898c2ecf20Sopenharmony_ci {0x1f, 0x00}, 1908c2ecf20Sopenharmony_ci {0x3f, 0x00}, 1918c2ecf20Sopenharmony_ci {0x5f, 0x00}, 1928c2ecf20Sopenharmony_ci {0x1f, 0x01}, 1938c2ecf20Sopenharmony_ci {0x3f, 0x01}, 1948c2ecf20Sopenharmony_ci {0x5f, 0x01}, 1958c2ecf20Sopenharmony_ci {0x1f, 0x02}, 1968c2ecf20Sopenharmony_ci {0x3f, 0x02}, 1978c2ecf20Sopenharmony_ci {0x5f, 0x02}, 1988c2ecf20Sopenharmony_ci {0x1f, 0x03}, 1998c2ecf20Sopenharmony_ci {0x3f, 0x03}, 2008c2ecf20Sopenharmony_ci {0x5f, 0x03}, 2018c2ecf20Sopenharmony_ci {0x1f, 0x04}, 2028c2ecf20Sopenharmony_ci {0x3f, 0x04}, 2038c2ecf20Sopenharmony_ci {0x5f, 0x04}, 2048c2ecf20Sopenharmony_ci {0x1f, 0x0c}, 2058c2ecf20Sopenharmony_ci {0x3f, 0x0c}, 2068c2ecf20Sopenharmony_ci {0x5f, 0x0c}, 2078c2ecf20Sopenharmony_ci {0x1f, 0x14}, 2088c2ecf20Sopenharmony_ci {0x3f, 0x14}, 2098c2ecf20Sopenharmony_ci {0x5f, 0x14}, 2108c2ecf20Sopenharmony_ci {0x1f, 0x1c}, 2118c2ecf20Sopenharmony_ci {0x3f, 0x1c}, 2128c2ecf20Sopenharmony_ci {0x5f, 0x1c}, 2138c2ecf20Sopenharmony_ci {0x1f, 0x24}, 2148c2ecf20Sopenharmony_ci {0x3f, 0x24}, 2158c2ecf20Sopenharmony_ci {0x5f, 0x24}, 2168c2ecf20Sopenharmony_ci {0x7f, 0x24}, 2178c2ecf20Sopenharmony_ci}; 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci#endif 220