1 /*
2  * Elonics E4000 silicon tuner driver
3  *
4  * Copyright (C) 2012 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  *    You should have received a copy of the GNU General Public License along
17  *    with this program; if not, write to the Free Software Foundation, Inc.,
18  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef E4000_PRIV_H
22 #define E4000_PRIV_H
23 
24 #include "e4000.h"
25 
26 struct e4000_priv {
27 	const struct e4000_config *cfg;
28 	struct i2c_adapter *i2c;
29 };
30 
31 struct e4000_pll {
32 	u32 freq;
33 	u8 div;
34 	u8 mul;
35 };
36 
37 static const struct e4000_pll e4000_pll_lut[] = {
38 /*                                      VCO min    VCO max */
39 	{   72400000, 0x0f, 48 }, /* .......... 3475200000 */
40 	{   81200000, 0x0e, 40 }, /* 2896000000 3248000000 */
41 	{  108300000, 0x0d, 32 }, /* 2598400000 3465600000 */
42 	{  162500000, 0x0c, 24 }, /* 2599200000 3900000000 */
43 	{  216600000, 0x0b, 16 }, /* 2600000000 3465600000 */
44 	{  325000000, 0x0a, 12 }, /* 2599200000 3900000000 */
45 	{  350000000, 0x09,  8 }, /* 2600000000 2800000000 */
46 	{  432000000, 0x03,  8 }, /* 2800000000 3456000000 */
47 	{  667000000, 0x02,  6 }, /* 2592000000 4002000000 */
48 	{ 1200000000, 0x01,  4 }, /* 2668000000 4800000000 */
49 	{ 0xffffffff, 0x00,  2 }, /* 2400000000 .......... */
50 };
51 
52 struct e4000_lna_filter {
53 	u32 freq;
54 	u8 val;
55 };
56 
57 static const struct e4000_lna_filter e400_lna_filter_lut[] = {
58 	{  370000000,  0 },
59 	{  392500000,  1 },
60 	{  415000000,  2 },
61 	{  437500000,  3 },
62 	{  462500000,  4 },
63 	{  490000000,  5 },
64 	{  522500000,  6 },
65 	{  557500000,  7 },
66 	{  595000000,  8 },
67 	{  642500000,  9 },
68 	{  695000000, 10 },
69 	{  740000000, 11 },
70 	{  800000000, 12 },
71 	{  865000000, 13 },
72 	{  930000000, 14 },
73 	{ 1000000000, 15 },
74 	{ 1310000000,  0 },
75 	{ 1340000000,  1 },
76 	{ 1385000000,  2 },
77 	{ 1427500000,  3 },
78 	{ 1452500000,  4 },
79 	{ 1475000000,  5 },
80 	{ 1510000000,  6 },
81 	{ 1545000000,  7 },
82 	{ 1575000000,  8 },
83 	{ 1615000000,  9 },
84 	{ 1650000000, 10 },
85 	{ 1670000000, 11 },
86 	{ 1690000000, 12 },
87 	{ 1710000000, 13 },
88 	{ 1735000000, 14 },
89 	{ 0xffffffff, 15 },
90 };
91 
92 struct e4000_band {
93 	u32 freq;
94 	u8 reg07_val;
95 	u8 reg78_val;
96 };
97 
98 static const struct e4000_band e4000_band_lut[] = {
99 	{  140000000, 0x01, 0x03 },
100 	{  350000000, 0x03, 0x03 },
101 	{ 1000000000, 0x05, 0x03 },
102 	{ 0xffffffff, 0x07, 0x00 },
103 };
104 
105 struct e4000_if_filter {
106 	u32 freq;
107 	u8 reg11_val;
108 	u8 reg12_val;
109 };
110 
111 static const struct e4000_if_filter e4000_if_filter_lut[] = {
112 	{    4300000, 0xfd, 0x1f },
113 	{    4400000, 0xfd, 0x1e },
114 	{    4480000, 0xfc, 0x1d },
115 	{    4560000, 0xfc, 0x1c },
116 	{    4600000, 0xfc, 0x1b },
117 	{    4800000, 0xfc, 0x1a },
118 	{    4900000, 0xfc, 0x19 },
119 	{    5000000, 0xfc, 0x18 },
120 	{    5100000, 0xfc, 0x17 },
121 	{    5200000, 0xfc, 0x16 },
122 	{    5400000, 0xfc, 0x15 },
123 	{    5500000, 0xfc, 0x14 },
124 	{    5600000, 0xfc, 0x13 },
125 	{    5800000, 0xfb, 0x12 },
126 	{    5900000, 0xfb, 0x11 },
127 	{    6000000, 0xfb, 0x10 },
128 	{    6200000, 0xfb, 0x0f },
129 	{    6400000, 0xfa, 0x0e },
130 	{    6600000, 0xfa, 0x0d },
131 	{    6800000, 0xf9, 0x0c },
132 	{    7200000, 0xf9, 0x0b },
133 	{    7400000, 0xf9, 0x0a },
134 	{    7600000, 0xf8, 0x09 },
135 	{    7800000, 0xf8, 0x08 },
136 	{    8200000, 0xf8, 0x07 },
137 	{    8600000, 0xf7, 0x06 },
138 	{    8800000, 0xf7, 0x05 },
139 	{    9200000, 0xf7, 0x04 },
140 	{    9600000, 0xf6, 0x03 },
141 	{   10000000, 0xf6, 0x02 },
142 	{   10600000, 0xf5, 0x01 },
143 	{   11000000, 0xf5, 0x00 },
144 	{ 0xffffffff, 0x00, 0x20 },
145 };
146 
147 #endif
148