Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 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" |
Antti Palosaari | f8b9b87 | 2015-04-21 17:13:39 -0300 | [diff] [blame] | 25 | #include <linux/math64.h> |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 26 | #include <media/v4l2-ctrls.h> |
| 27 | #include <media/v4l2-subdev.h> |
Antti Palosaari | bd428bb | 2014-02-08 06:20:35 -0300 | [diff] [blame] | 28 | #include <linux/regmap.h> |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 29 | |
Antti Palosaari | f8b9b87 | 2015-04-21 17:13:39 -0300 | [diff] [blame] | 30 | struct e4000_dev { |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 31 | struct i2c_client *client; |
Antti Palosaari | bd428bb | 2014-02-08 06:20:35 -0300 | [diff] [blame] | 32 | struct regmap *regmap; |
Antti Palosaari | f8b9b87 | 2015-04-21 17:13:39 -0300 | [diff] [blame] | 33 | u32 clk; |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 34 | struct dvb_frontend *fe; |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 35 | struct v4l2_subdev sd; |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 36 | bool active; |
Antti Palosaari | c7861bb | 2015-05-12 14:26:07 -0300 | [diff] [blame] | 37 | unsigned int f_frequency; |
| 38 | unsigned int f_bandwidth; |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 39 | |
| 40 | /* Controls */ |
| 41 | struct v4l2_ctrl_handler hdl; |
| 42 | struct v4l2_ctrl *bandwidth_auto; |
| 43 | struct v4l2_ctrl *bandwidth; |
| 44 | struct v4l2_ctrl *lna_gain_auto; |
| 45 | struct v4l2_ctrl *lna_gain; |
| 46 | struct v4l2_ctrl *mixer_gain_auto; |
| 47 | struct v4l2_ctrl *mixer_gain; |
| 48 | struct v4l2_ctrl *if_gain_auto; |
| 49 | struct v4l2_ctrl *if_gain; |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 50 | struct v4l2_ctrl *pll_lock; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | struct e4000_pll { |
| 54 | u32 freq; |
Antti Palosaari | 0e3a71c | 2015-04-21 21:18:45 -0300 | [diff] [blame] | 55 | u8 div_out_reg; |
| 56 | u8 div_out; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | static const struct e4000_pll e4000_pll_lut[] = { |
| 60 | /* VCO min VCO max */ |
| 61 | { 72400000, 0x0f, 48 }, /* .......... 3475200000 */ |
| 62 | { 81200000, 0x0e, 40 }, /* 2896000000 3248000000 */ |
| 63 | { 108300000, 0x0d, 32 }, /* 2598400000 3465600000 */ |
| 64 | { 162500000, 0x0c, 24 }, /* 2599200000 3900000000 */ |
| 65 | { 216600000, 0x0b, 16 }, /* 2600000000 3465600000 */ |
| 66 | { 325000000, 0x0a, 12 }, /* 2599200000 3900000000 */ |
| 67 | { 350000000, 0x09, 8 }, /* 2600000000 2800000000 */ |
| 68 | { 432000000, 0x03, 8 }, /* 2800000000 3456000000 */ |
| 69 | { 667000000, 0x02, 6 }, /* 2592000000 4002000000 */ |
| 70 | { 1200000000, 0x01, 4 }, /* 2668000000 4800000000 */ |
| 71 | { 0xffffffff, 0x00, 2 }, /* 2400000000 .......... */ |
| 72 | }; |
| 73 | |
| 74 | struct e4000_lna_filter { |
| 75 | u32 freq; |
| 76 | u8 val; |
| 77 | }; |
| 78 | |
| 79 | static const struct e4000_lna_filter e400_lna_filter_lut[] = { |
| 80 | { 370000000, 0 }, |
| 81 | { 392500000, 1 }, |
| 82 | { 415000000, 2 }, |
| 83 | { 437500000, 3 }, |
| 84 | { 462500000, 4 }, |
| 85 | { 490000000, 5 }, |
| 86 | { 522500000, 6 }, |
| 87 | { 557500000, 7 }, |
| 88 | { 595000000, 8 }, |
| 89 | { 642500000, 9 }, |
| 90 | { 695000000, 10 }, |
| 91 | { 740000000, 11 }, |
| 92 | { 800000000, 12 }, |
| 93 | { 865000000, 13 }, |
| 94 | { 930000000, 14 }, |
| 95 | { 1000000000, 15 }, |
| 96 | { 1310000000, 0 }, |
| 97 | { 1340000000, 1 }, |
| 98 | { 1385000000, 2 }, |
| 99 | { 1427500000, 3 }, |
| 100 | { 1452500000, 4 }, |
| 101 | { 1475000000, 5 }, |
| 102 | { 1510000000, 6 }, |
| 103 | { 1545000000, 7 }, |
| 104 | { 1575000000, 8 }, |
| 105 | { 1615000000, 9 }, |
| 106 | { 1650000000, 10 }, |
| 107 | { 1670000000, 11 }, |
| 108 | { 1690000000, 12 }, |
| 109 | { 1710000000, 13 }, |
| 110 | { 1735000000, 14 }, |
| 111 | { 0xffffffff, 15 }, |
| 112 | }; |
| 113 | |
| 114 | struct e4000_band { |
| 115 | u32 freq; |
| 116 | u8 reg07_val; |
| 117 | u8 reg78_val; |
| 118 | }; |
| 119 | |
| 120 | static const struct e4000_band e4000_band_lut[] = { |
| 121 | { 140000000, 0x01, 0x03 }, |
| 122 | { 350000000, 0x03, 0x03 }, |
| 123 | { 1000000000, 0x05, 0x03 }, |
| 124 | { 0xffffffff, 0x07, 0x00 }, |
| 125 | }; |
| 126 | |
| 127 | struct e4000_if_filter { |
| 128 | u32 freq; |
| 129 | u8 reg11_val; |
| 130 | u8 reg12_val; |
| 131 | }; |
| 132 | |
| 133 | static const struct e4000_if_filter e4000_if_filter_lut[] = { |
| 134 | { 4300000, 0xfd, 0x1f }, |
| 135 | { 4400000, 0xfd, 0x1e }, |
| 136 | { 4480000, 0xfc, 0x1d }, |
| 137 | { 4560000, 0xfc, 0x1c }, |
| 138 | { 4600000, 0xfc, 0x1b }, |
| 139 | { 4800000, 0xfc, 0x1a }, |
| 140 | { 4900000, 0xfc, 0x19 }, |
| 141 | { 5000000, 0xfc, 0x18 }, |
| 142 | { 5100000, 0xfc, 0x17 }, |
| 143 | { 5200000, 0xfc, 0x16 }, |
| 144 | { 5400000, 0xfc, 0x15 }, |
| 145 | { 5500000, 0xfc, 0x14 }, |
| 146 | { 5600000, 0xfc, 0x13 }, |
| 147 | { 5800000, 0xfb, 0x12 }, |
| 148 | { 5900000, 0xfb, 0x11 }, |
| 149 | { 6000000, 0xfb, 0x10 }, |
| 150 | { 6200000, 0xfb, 0x0f }, |
| 151 | { 6400000, 0xfa, 0x0e }, |
| 152 | { 6600000, 0xfa, 0x0d }, |
| 153 | { 6800000, 0xf9, 0x0c }, |
| 154 | { 7200000, 0xf9, 0x0b }, |
| 155 | { 7400000, 0xf9, 0x0a }, |
| 156 | { 7600000, 0xf8, 0x09 }, |
| 157 | { 7800000, 0xf8, 0x08 }, |
| 158 | { 8200000, 0xf8, 0x07 }, |
| 159 | { 8600000, 0xf7, 0x06 }, |
| 160 | { 8800000, 0xf7, 0x05 }, |
| 161 | { 9200000, 0xf7, 0x04 }, |
| 162 | { 9600000, 0xf6, 0x03 }, |
| 163 | { 10000000, 0xf6, 0x02 }, |
| 164 | { 10600000, 0xf5, 0x01 }, |
| 165 | { 11000000, 0xf5, 0x00 }, |
| 166 | { 0xffffffff, 0x00, 0x20 }, |
| 167 | }; |
| 168 | |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 169 | struct e4000_if_gain { |
| 170 | u8 reg16_val; |
| 171 | u8 reg17_val; |
| 172 | }; |
| 173 | |
| 174 | static const struct e4000_if_gain e4000_if_gain_lut[] = { |
| 175 | {0x00, 0x00}, |
| 176 | {0x20, 0x00}, |
| 177 | {0x40, 0x00}, |
| 178 | {0x02, 0x00}, |
| 179 | {0x22, 0x00}, |
| 180 | {0x42, 0x00}, |
| 181 | {0x04, 0x00}, |
| 182 | {0x24, 0x00}, |
| 183 | {0x44, 0x00}, |
| 184 | {0x01, 0x00}, |
| 185 | {0x21, 0x00}, |
| 186 | {0x41, 0x00}, |
| 187 | {0x03, 0x00}, |
| 188 | {0x23, 0x00}, |
| 189 | {0x43, 0x00}, |
| 190 | {0x05, 0x00}, |
| 191 | {0x25, 0x00}, |
| 192 | {0x45, 0x00}, |
| 193 | {0x07, 0x00}, |
| 194 | {0x27, 0x00}, |
| 195 | {0x47, 0x00}, |
| 196 | {0x0f, 0x00}, |
| 197 | {0x2f, 0x00}, |
| 198 | {0x4f, 0x00}, |
| 199 | {0x17, 0x00}, |
| 200 | {0x37, 0x00}, |
| 201 | {0x57, 0x00}, |
| 202 | {0x1f, 0x00}, |
| 203 | {0x3f, 0x00}, |
| 204 | {0x5f, 0x00}, |
| 205 | {0x1f, 0x01}, |
| 206 | {0x3f, 0x01}, |
| 207 | {0x5f, 0x01}, |
| 208 | {0x1f, 0x02}, |
| 209 | {0x3f, 0x02}, |
| 210 | {0x5f, 0x02}, |
| 211 | {0x1f, 0x03}, |
| 212 | {0x3f, 0x03}, |
| 213 | {0x5f, 0x03}, |
| 214 | {0x1f, 0x04}, |
| 215 | {0x3f, 0x04}, |
| 216 | {0x5f, 0x04}, |
| 217 | {0x1f, 0x0c}, |
| 218 | {0x3f, 0x0c}, |
| 219 | {0x5f, 0x0c}, |
| 220 | {0x1f, 0x14}, |
| 221 | {0x3f, 0x14}, |
| 222 | {0x5f, 0x14}, |
| 223 | {0x1f, 0x1c}, |
| 224 | {0x3f, 0x1c}, |
| 225 | {0x5f, 0x1c}, |
| 226 | {0x1f, 0x24}, |
| 227 | {0x3f, 0x24}, |
| 228 | {0x5f, 0x24}, |
| 229 | {0x7f, 0x24}, |
| 230 | }; |
| 231 | |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 232 | #endif |