Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 1 | /* |
| 2 | Samsung S5H1409 VSB/QAM demodulator driver |
| 3 | |
Steven Toth | 6d89761 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 4 | Copyright (C) 2006 Steven Toth <stoth@linuxtv.org> |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 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 |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | |
| 20 | */ |
| 21 | |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/string.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include "dvb_frontend.h" |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 29 | #include "s5h1409.h" |
| 30 | |
| 31 | struct s5h1409_state { |
| 32 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 33 | struct i2c_adapter *i2c; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 34 | |
| 35 | /* configuration settings */ |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 36 | const struct s5h1409_config *config; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 37 | |
| 38 | struct dvb_frontend frontend; |
| 39 | |
| 40 | /* previous uncorrected block counter */ |
| 41 | fe_modulation_t current_modulation; |
| 42 | |
| 43 | u32 current_frequency; |
Michael Krufky | 2b03238 | 2007-12-13 10:04:10 -0300 | [diff] [blame] | 44 | int if_freq; |
Steven Toth | dd7d501 | 2007-10-24 21:05:51 -0300 | [diff] [blame] | 45 | |
| 46 | u32 is_qam_locked; |
| 47 | u32 qam_state; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 48 | }; |
| 49 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 50 | static int debug; |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 51 | module_param(debug, int, 0644); |
| 52 | MODULE_PARM_DESC(debug, "Enable verbose debug messages"); |
| 53 | |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 54 | #define dprintk if (debug) printk |
| 55 | |
| 56 | /* Register values to initialise the demod, this will set VSB by default */ |
| 57 | static struct init_tab { |
| 58 | u8 reg; |
| 59 | u16 data; |
| 60 | } init_tab[] = { |
| 61 | { 0x00, 0x0071, }, |
| 62 | { 0x01, 0x3213, }, |
| 63 | { 0x09, 0x0025, }, |
| 64 | { 0x1c, 0x001d, }, |
| 65 | { 0x1f, 0x002d, }, |
| 66 | { 0x20, 0x001d, }, |
| 67 | { 0x22, 0x0022, }, |
| 68 | { 0x23, 0x0020, }, |
| 69 | { 0x29, 0x110f, }, |
| 70 | { 0x2a, 0x10b4, }, |
| 71 | { 0x2b, 0x10ae, }, |
| 72 | { 0x2c, 0x0031, }, |
| 73 | { 0x31, 0x010d, }, |
| 74 | { 0x32, 0x0100, }, |
| 75 | { 0x44, 0x0510, }, |
| 76 | { 0x54, 0x0104, }, |
| 77 | { 0x58, 0x2222, }, |
| 78 | { 0x59, 0x1162, }, |
| 79 | { 0x5a, 0x3211, }, |
| 80 | { 0x5d, 0x0370, }, |
| 81 | { 0x5e, 0x0296, }, |
| 82 | { 0x61, 0x0010, }, |
| 83 | { 0x63, 0x4a00, }, |
| 84 | { 0x65, 0x0800, }, |
| 85 | { 0x71, 0x0003, }, |
| 86 | { 0x72, 0x0470, }, |
| 87 | { 0x81, 0x0002, }, |
| 88 | { 0x82, 0x0600, }, |
| 89 | { 0x86, 0x0002, }, |
| 90 | { 0x8a, 0x2c38, }, |
| 91 | { 0x8b, 0x2a37, }, |
| 92 | { 0x92, 0x302f, }, |
| 93 | { 0x93, 0x3332, }, |
| 94 | { 0x96, 0x000c, }, |
| 95 | { 0x99, 0x0101, }, |
| 96 | { 0x9c, 0x2e37, }, |
| 97 | { 0x9d, 0x2c37, }, |
| 98 | { 0x9e, 0x2c37, }, |
| 99 | { 0xab, 0x0100, }, |
| 100 | { 0xac, 0x1003, }, |
| 101 | { 0xad, 0x103f, }, |
| 102 | { 0xe2, 0x0100, }, |
Steven Toth | dfc1c08 | 2008-01-15 21:35:22 -0300 | [diff] [blame] | 103 | { 0xe3, 0x1000, }, |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 104 | { 0x28, 0x1010, }, |
| 105 | { 0xb1, 0x000e, }, |
| 106 | }; |
| 107 | |
| 108 | /* VSB SNR lookup table */ |
| 109 | static struct vsb_snr_tab { |
| 110 | u16 val; |
| 111 | u16 data; |
| 112 | } vsb_snr_tab[] = { |
Steven Toth | 2300317 | 2007-12-12 22:14:00 -0300 | [diff] [blame] | 113 | { 924, 300, }, |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 114 | { 923, 300, }, |
| 115 | { 918, 295, }, |
| 116 | { 915, 290, }, |
| 117 | { 911, 285, }, |
| 118 | { 906, 280, }, |
| 119 | { 901, 275, }, |
| 120 | { 896, 270, }, |
| 121 | { 891, 265, }, |
| 122 | { 885, 260, }, |
| 123 | { 879, 255, }, |
| 124 | { 873, 250, }, |
| 125 | { 864, 245, }, |
| 126 | { 858, 240, }, |
| 127 | { 850, 235, }, |
| 128 | { 841, 230, }, |
| 129 | { 832, 225, }, |
| 130 | { 823, 220, }, |
| 131 | { 812, 215, }, |
| 132 | { 802, 210, }, |
| 133 | { 788, 205, }, |
| 134 | { 778, 200, }, |
| 135 | { 767, 195, }, |
| 136 | { 753, 190, }, |
| 137 | { 740, 185, }, |
| 138 | { 725, 180, }, |
| 139 | { 707, 175, }, |
| 140 | { 689, 170, }, |
| 141 | { 671, 165, }, |
| 142 | { 656, 160, }, |
| 143 | { 637, 155, }, |
| 144 | { 616, 150, }, |
| 145 | { 542, 145, }, |
| 146 | { 519, 140, }, |
| 147 | { 507, 135, }, |
| 148 | { 497, 130, }, |
| 149 | { 492, 125, }, |
| 150 | { 474, 120, }, |
| 151 | { 300, 111, }, |
| 152 | { 0, 0, }, |
| 153 | }; |
| 154 | |
| 155 | /* QAM64 SNR lookup table */ |
| 156 | static struct qam64_snr_tab { |
| 157 | u16 val; |
| 158 | u16 data; |
| 159 | } qam64_snr_tab[] = { |
Steven Toth | 2300317 | 2007-12-12 22:14:00 -0300 | [diff] [blame] | 160 | { 1, 0, }, |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 161 | { 12, 300, }, |
| 162 | { 15, 290, }, |
| 163 | { 18, 280, }, |
| 164 | { 22, 270, }, |
| 165 | { 23, 268, }, |
| 166 | { 24, 266, }, |
| 167 | { 25, 264, }, |
| 168 | { 27, 262, }, |
| 169 | { 28, 260, }, |
| 170 | { 29, 258, }, |
| 171 | { 30, 256, }, |
| 172 | { 32, 254, }, |
| 173 | { 33, 252, }, |
| 174 | { 34, 250, }, |
| 175 | { 35, 249, }, |
| 176 | { 36, 248, }, |
| 177 | { 37, 247, }, |
| 178 | { 38, 246, }, |
| 179 | { 39, 245, }, |
| 180 | { 40, 244, }, |
| 181 | { 41, 243, }, |
| 182 | { 42, 241, }, |
| 183 | { 43, 240, }, |
| 184 | { 44, 239, }, |
| 185 | { 45, 238, }, |
| 186 | { 46, 237, }, |
| 187 | { 47, 236, }, |
| 188 | { 48, 235, }, |
| 189 | { 49, 234, }, |
| 190 | { 50, 233, }, |
| 191 | { 51, 232, }, |
| 192 | { 52, 231, }, |
| 193 | { 53, 230, }, |
| 194 | { 55, 229, }, |
| 195 | { 56, 228, }, |
| 196 | { 57, 227, }, |
| 197 | { 58, 226, }, |
| 198 | { 59, 225, }, |
| 199 | { 60, 224, }, |
| 200 | { 62, 223, }, |
| 201 | { 63, 222, }, |
| 202 | { 65, 221, }, |
| 203 | { 66, 220, }, |
| 204 | { 68, 219, }, |
| 205 | { 69, 218, }, |
| 206 | { 70, 217, }, |
| 207 | { 72, 216, }, |
| 208 | { 73, 215, }, |
| 209 | { 75, 214, }, |
| 210 | { 76, 213, }, |
| 211 | { 78, 212, }, |
| 212 | { 80, 211, }, |
| 213 | { 81, 210, }, |
| 214 | { 83, 209, }, |
| 215 | { 84, 208, }, |
| 216 | { 85, 207, }, |
| 217 | { 87, 206, }, |
| 218 | { 89, 205, }, |
| 219 | { 91, 204, }, |
| 220 | { 93, 203, }, |
| 221 | { 95, 202, }, |
| 222 | { 96, 201, }, |
| 223 | { 104, 200, }, |
Steven Toth | 2300317 | 2007-12-12 22:14:00 -0300 | [diff] [blame] | 224 | { 255, 0, }, |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | /* QAM256 SNR lookup table */ |
| 228 | static struct qam256_snr_tab { |
| 229 | u16 val; |
| 230 | u16 data; |
| 231 | } qam256_snr_tab[] = { |
Steven Toth | 2300317 | 2007-12-12 22:14:00 -0300 | [diff] [blame] | 232 | { 1, 0, }, |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 233 | { 12, 400, }, |
| 234 | { 13, 390, }, |
| 235 | { 15, 380, }, |
| 236 | { 17, 360, }, |
| 237 | { 19, 350, }, |
| 238 | { 22, 348, }, |
| 239 | { 23, 346, }, |
| 240 | { 24, 344, }, |
| 241 | { 25, 342, }, |
| 242 | { 26, 340, }, |
| 243 | { 27, 336, }, |
| 244 | { 28, 334, }, |
| 245 | { 29, 332, }, |
| 246 | { 30, 330, }, |
| 247 | { 31, 328, }, |
| 248 | { 32, 326, }, |
| 249 | { 33, 325, }, |
| 250 | { 34, 322, }, |
| 251 | { 35, 320, }, |
| 252 | { 37, 318, }, |
| 253 | { 39, 316, }, |
| 254 | { 40, 314, }, |
| 255 | { 41, 312, }, |
| 256 | { 42, 310, }, |
| 257 | { 43, 308, }, |
| 258 | { 46, 306, }, |
| 259 | { 47, 304, }, |
| 260 | { 49, 302, }, |
| 261 | { 51, 300, }, |
| 262 | { 53, 298, }, |
| 263 | { 54, 297, }, |
| 264 | { 55, 296, }, |
| 265 | { 56, 295, }, |
| 266 | { 57, 294, }, |
| 267 | { 59, 293, }, |
| 268 | { 60, 292, }, |
| 269 | { 61, 291, }, |
| 270 | { 63, 290, }, |
| 271 | { 64, 289, }, |
| 272 | { 65, 288, }, |
| 273 | { 66, 287, }, |
| 274 | { 68, 286, }, |
| 275 | { 69, 285, }, |
| 276 | { 71, 284, }, |
| 277 | { 72, 283, }, |
| 278 | { 74, 282, }, |
| 279 | { 75, 281, }, |
| 280 | { 76, 280, }, |
| 281 | { 77, 279, }, |
| 282 | { 78, 278, }, |
| 283 | { 81, 277, }, |
| 284 | { 83, 276, }, |
| 285 | { 84, 275, }, |
| 286 | { 86, 274, }, |
| 287 | { 87, 273, }, |
| 288 | { 89, 272, }, |
| 289 | { 90, 271, }, |
| 290 | { 92, 270, }, |
| 291 | { 93, 269, }, |
| 292 | { 95, 268, }, |
| 293 | { 96, 267, }, |
| 294 | { 98, 266, }, |
| 295 | { 100, 265, }, |
| 296 | { 102, 264, }, |
| 297 | { 104, 263, }, |
| 298 | { 105, 262, }, |
| 299 | { 106, 261, }, |
| 300 | { 110, 260, }, |
Steven Toth | 2300317 | 2007-12-12 22:14:00 -0300 | [diff] [blame] | 301 | { 255, 0, }, |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | /* 8 bit registers, 16 bit values */ |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 305 | static int s5h1409_writereg(struct s5h1409_state *state, u8 reg, u16 data) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 306 | { |
| 307 | int ret; |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 308 | u8 buf[] = { reg, data >> 8, data & 0xff }; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 309 | |
Michael Krufky | 3873dd0 | 2007-07-28 20:02:55 -0300 | [diff] [blame] | 310 | struct i2c_msg msg = { .addr = state->config->demod_address, |
| 311 | .flags = 0, .buf = buf, .len = 3 }; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 312 | |
| 313 | ret = i2c_transfer(state->i2c, &msg, 1); |
| 314 | |
| 315 | if (ret != 1) |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 316 | printk(KERN_ERR "%s: error (reg == 0x%02x, val == 0x%04x, " |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 317 | "ret == %i)\n", __func__, reg, data, ret); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 318 | |
| 319 | return (ret != 1) ? -1 : 0; |
| 320 | } |
| 321 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 322 | static u16 s5h1409_readreg(struct s5h1409_state *state, u8 reg) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 323 | { |
| 324 | int ret; |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 325 | u8 b0[] = { reg }; |
| 326 | u8 b1[] = { 0, 0 }; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 327 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 328 | struct i2c_msg msg[] = { |
Michael Krufky | 3873dd0 | 2007-07-28 20:02:55 -0300 | [diff] [blame] | 329 | { .addr = state->config->demod_address, .flags = 0, |
| 330 | .buf = b0, .len = 1 }, |
| 331 | { .addr = state->config->demod_address, .flags = I2C_M_RD, |
| 332 | .buf = b1, .len = 2 } }; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 333 | |
| 334 | ret = i2c_transfer(state->i2c, msg, 2); |
| 335 | |
| 336 | if (ret != 2) |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 337 | printk("%s: readreg error (ret == %i)\n", __func__, ret); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 338 | return (b1[0] << 8) | b1[1]; |
| 339 | } |
| 340 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 341 | static int s5h1409_softreset(struct dvb_frontend *fe) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 342 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 343 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 344 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 345 | dprintk("%s()\n", __func__); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 346 | |
| 347 | s5h1409_writereg(state, 0xf5, 0); |
| 348 | s5h1409_writereg(state, 0xf5, 1); |
Steven Toth | dd7d501 | 2007-10-24 21:05:51 -0300 | [diff] [blame] | 349 | state->is_qam_locked = 0; |
| 350 | state->qam_state = 0; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
Michael Krufky | 2b03238 | 2007-12-13 10:04:10 -0300 | [diff] [blame] | 354 | #define S5H1409_VSB_IF_FREQ 5380 |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 355 | #define S5H1409_QAM_IF_FREQ (state->config->qam_if) |
Michael Krufky | 2b03238 | 2007-12-13 10:04:10 -0300 | [diff] [blame] | 356 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 357 | static int s5h1409_set_if_freq(struct dvb_frontend *fe, int KHz) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 358 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 359 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 360 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 361 | dprintk("%s(%d KHz)\n", __func__, KHz); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 362 | |
Michael Krufky | 6b7daa8 | 2007-12-13 10:11:49 -0300 | [diff] [blame] | 363 | switch (KHz) { |
| 364 | case 4000: |
Steven Toth | dd7d501 | 2007-10-24 21:05:51 -0300 | [diff] [blame] | 365 | s5h1409_writereg(state, 0x87, 0x014b); |
| 366 | s5h1409_writereg(state, 0x88, 0x0cb5); |
| 367 | s5h1409_writereg(state, 0x89, 0x03e2); |
Michael Krufky | 6b7daa8 | 2007-12-13 10:11:49 -0300 | [diff] [blame] | 368 | break; |
| 369 | case 5380: |
| 370 | case 44000: |
| 371 | default: |
| 372 | s5h1409_writereg(state, 0x87, 0x01be); |
| 373 | s5h1409_writereg(state, 0x88, 0x0436); |
| 374 | s5h1409_writereg(state, 0x89, 0x054d); |
| 375 | break; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 376 | } |
Michael Krufky | 6b7daa8 | 2007-12-13 10:11:49 -0300 | [diff] [blame] | 377 | state->if_freq = KHz; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 378 | |
Michael Krufky | 6b7daa8 | 2007-12-13 10:11:49 -0300 | [diff] [blame] | 379 | return 0; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 380 | } |
| 381 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 382 | static int s5h1409_set_spectralinversion(struct dvb_frontend *fe, int inverted) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 383 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 384 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 385 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 386 | dprintk("%s(%d)\n", __func__, inverted); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 387 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 388 | if (inverted == 1) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 389 | return s5h1409_writereg(state, 0x1b, 0x1101); /* Inverted */ |
| 390 | else |
| 391 | return s5h1409_writereg(state, 0x1b, 0x0110); /* Normal */ |
| 392 | } |
| 393 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 394 | static int s5h1409_enable_modulation(struct dvb_frontend *fe, |
Michael Krufky | 3873dd0 | 2007-07-28 20:02:55 -0300 | [diff] [blame] | 395 | fe_modulation_t m) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 396 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 397 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 398 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 399 | dprintk("%s(0x%08x)\n", __func__, m); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 400 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 401 | switch (m) { |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 402 | case VSB_8: |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 403 | dprintk("%s() VSB_8\n", __func__); |
Michael Krufky | 2b03238 | 2007-12-13 10:04:10 -0300 | [diff] [blame] | 404 | if (state->if_freq != S5H1409_VSB_IF_FREQ) |
| 405 | s5h1409_set_if_freq(fe, S5H1409_VSB_IF_FREQ); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 406 | s5h1409_writereg(state, 0xf4, 0); |
| 407 | break; |
| 408 | case QAM_64: |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 409 | case QAM_256: |
Steven Toth | 4fc85c7 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 410 | case QAM_AUTO: |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 411 | dprintk("%s() QAM_AUTO (64/256)\n", __func__); |
Michael Krufky | 2b03238 | 2007-12-13 10:04:10 -0300 | [diff] [blame] | 412 | if (state->if_freq != S5H1409_QAM_IF_FREQ) |
| 413 | s5h1409_set_if_freq(fe, S5H1409_QAM_IF_FREQ); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 414 | s5h1409_writereg(state, 0xf4, 1); |
Steven Toth | dd7d501 | 2007-10-24 21:05:51 -0300 | [diff] [blame] | 415 | s5h1409_writereg(state, 0x85, 0x110); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 416 | break; |
| 417 | default: |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 418 | dprintk("%s() Invalid modulation\n", __func__); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 419 | return -EINVAL; |
| 420 | } |
| 421 | |
| 422 | state->current_modulation = m; |
| 423 | s5h1409_softreset(fe); |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 428 | static int s5h1409_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 429 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 430 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 431 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 432 | dprintk("%s(%d)\n", __func__, enable); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 433 | |
| 434 | if (enable) |
| 435 | return s5h1409_writereg(state, 0xf3, 1); |
| 436 | else |
| 437 | return s5h1409_writereg(state, 0xf3, 0); |
| 438 | } |
| 439 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 440 | static int s5h1409_set_gpio(struct dvb_frontend *fe, int enable) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 441 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 442 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 443 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 444 | dprintk("%s(%d)\n", __func__, enable); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 445 | |
| 446 | if (enable) |
Steven Toth | dfc1c08 | 2008-01-15 21:35:22 -0300 | [diff] [blame] | 447 | return s5h1409_writereg(state, 0xe3, |
| 448 | s5h1409_readreg(state, 0xe3) | 0x1100); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 449 | else |
Steven Toth | dfc1c08 | 2008-01-15 21:35:22 -0300 | [diff] [blame] | 450 | return s5h1409_writereg(state, 0xe3, |
Michael Krufky | 8e08af3 | 2008-04-02 22:14:41 -0300 | [diff] [blame] | 451 | s5h1409_readreg(state, 0xe3) & 0xfeff); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 452 | } |
| 453 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 454 | static int s5h1409_sleep(struct dvb_frontend *fe, int enable) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 455 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 456 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 457 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 458 | dprintk("%s(%d)\n", __func__, enable); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 459 | |
| 460 | return s5h1409_writereg(state, 0xf2, enable); |
| 461 | } |
| 462 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 463 | static int s5h1409_register_reset(struct dvb_frontend *fe) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 464 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 465 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 466 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 467 | dprintk("%s()\n", __func__); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 468 | |
| 469 | return s5h1409_writereg(state, 0xfa, 0); |
| 470 | } |
| 471 | |
Steven Toth | dd7d501 | 2007-10-24 21:05:51 -0300 | [diff] [blame] | 472 | static void s5h1409_set_qam_amhum_mode(struct dvb_frontend *fe) |
| 473 | { |
| 474 | struct s5h1409_state *state = fe->demodulator_priv; |
| 475 | u16 reg; |
| 476 | |
| 477 | if (state->is_qam_locked) |
| 478 | return; |
| 479 | |
| 480 | /* QAM EQ lock check */ |
| 481 | reg = s5h1409_readreg(state, 0xf0); |
| 482 | |
| 483 | if ((reg >> 13) & 0x1) { |
| 484 | |
| 485 | state->is_qam_locked = 1; |
| 486 | reg &= 0xff; |
| 487 | |
| 488 | s5h1409_writereg(state, 0x96, 0x00c); |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 489 | if ((reg < 0x38) || (reg > 0x68)) { |
Steven Toth | dd7d501 | 2007-10-24 21:05:51 -0300 | [diff] [blame] | 490 | s5h1409_writereg(state, 0x93, 0x3332); |
| 491 | s5h1409_writereg(state, 0x9e, 0x2c37); |
| 492 | } else { |
| 493 | s5h1409_writereg(state, 0x93, 0x3130); |
| 494 | s5h1409_writereg(state, 0x9e, 0x2836); |
| 495 | } |
| 496 | |
| 497 | } else { |
| 498 | s5h1409_writereg(state, 0x96, 0x0008); |
| 499 | s5h1409_writereg(state, 0x93, 0x3332); |
| 500 | s5h1409_writereg(state, 0x9e, 0x2c37); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | static void s5h1409_set_qam_interleave_mode(struct dvb_frontend *fe) |
| 505 | { |
| 506 | struct s5h1409_state *state = fe->demodulator_priv; |
| 507 | u16 reg, reg1, reg2; |
| 508 | |
| 509 | reg = s5h1409_readreg(state, 0xf1); |
| 510 | |
| 511 | /* Master lock */ |
| 512 | if ((reg >> 15) & 0x1) { |
| 513 | if (state->qam_state != 2) { |
| 514 | state->qam_state = 2; |
| 515 | reg1 = s5h1409_readreg(state, 0xb2); |
| 516 | reg2 = s5h1409_readreg(state, 0xad); |
| 517 | |
| 518 | s5h1409_writereg(state, 0x96, 0x20); |
| 519 | s5h1409_writereg(state, 0xad, |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 520 | (((reg1 & 0xf000) >> 4) | (reg2 & 0xf0ff))); |
Steven Toth | dfc1c08 | 2008-01-15 21:35:22 -0300 | [diff] [blame] | 521 | s5h1409_writereg(state, 0xab, |
| 522 | s5h1409_readreg(state, 0xab) & 0xeffe); |
Steven Toth | dd7d501 | 2007-10-24 21:05:51 -0300 | [diff] [blame] | 523 | } |
| 524 | } else { |
| 525 | if (state->qam_state != 1) { |
| 526 | state->qam_state = 1; |
| 527 | s5h1409_writereg(state, 0x96, 0x08); |
Steven Toth | dfc1c08 | 2008-01-15 21:35:22 -0300 | [diff] [blame] | 528 | s5h1409_writereg(state, 0xab, |
| 529 | s5h1409_readreg(state, 0xab) | 0x1001); |
Steven Toth | dd7d501 | 2007-10-24 21:05:51 -0300 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 534 | /* Talk to the demod, set the FEC, GUARD, QAM settings etc */ |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 535 | static int s5h1409_set_frontend(struct dvb_frontend *fe, |
Michael Krufky | 3873dd0 | 2007-07-28 20:02:55 -0300 | [diff] [blame] | 536 | struct dvb_frontend_parameters *p) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 537 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 538 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 539 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 540 | dprintk("%s(frequency=%d)\n", __func__, p->frequency); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 541 | |
| 542 | s5h1409_softreset(fe); |
| 543 | |
| 544 | state->current_frequency = p->frequency; |
| 545 | |
| 546 | s5h1409_enable_modulation(fe, p->u.vsb.modulation); |
| 547 | |
| 548 | if (fe->ops.tuner_ops.set_params) { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 549 | if (fe->ops.i2c_gate_ctrl) |
| 550 | fe->ops.i2c_gate_ctrl(fe, 1); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 551 | fe->ops.tuner_ops.set_params(fe, p); |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 552 | if (fe->ops.i2c_gate_ctrl) |
| 553 | fe->ops.i2c_gate_ctrl(fe, 0); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 554 | } |
| 555 | |
Steven Toth | dd7d501 | 2007-10-24 21:05:51 -0300 | [diff] [blame] | 556 | /* Optimize the demod for QAM */ |
| 557 | if (p->u.vsb.modulation != VSB_8) { |
| 558 | s5h1409_set_qam_amhum_mode(fe); |
| 559 | s5h1409_set_qam_interleave_mode(fe); |
| 560 | } |
| 561 | |
Devin Heitmueller | 67e70ba | 2009-01-26 03:07:59 -0300 | [diff] [blame] | 562 | /* Issue a reset to the demod so it knows to resync against the |
| 563 | newly tuned frequency */ |
| 564 | s5h1409_softreset(fe); |
| 565 | |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 566 | return 0; |
| 567 | } |
| 568 | |
Steven Toth | dfc1c08 | 2008-01-15 21:35:22 -0300 | [diff] [blame] | 569 | static int s5h1409_set_mpeg_timing(struct dvb_frontend *fe, int mode) |
| 570 | { |
| 571 | struct s5h1409_state *state = fe->demodulator_priv; |
| 572 | u16 val; |
| 573 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 574 | dprintk("%s(%d)\n", __func__, mode); |
Steven Toth | dfc1c08 | 2008-01-15 21:35:22 -0300 | [diff] [blame] | 575 | |
| 576 | val = s5h1409_readreg(state, 0xac) & 0xcfff; |
| 577 | switch (mode) { |
| 578 | case S5H1409_MPEGTIMING_CONTINOUS_INVERTING_CLOCK: |
| 579 | val |= 0x0000; |
| 580 | break; |
| 581 | case S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK: |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 582 | dprintk("%s(%d) Mode1 or Defaulting\n", __func__, mode); |
Steven Toth | dfc1c08 | 2008-01-15 21:35:22 -0300 | [diff] [blame] | 583 | val |= 0x1000; |
| 584 | break; |
| 585 | case S5H1409_MPEGTIMING_NONCONTINOUS_INVERTING_CLOCK: |
| 586 | val |= 0x2000; |
| 587 | break; |
| 588 | case S5H1409_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK: |
| 589 | val |= 0x3000; |
| 590 | break; |
| 591 | default: |
| 592 | return -EINVAL; |
| 593 | } |
| 594 | |
| 595 | /* Configure MPEG Signal Timing charactistics */ |
| 596 | return s5h1409_writereg(state, 0xac, val); |
| 597 | } |
| 598 | |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 599 | /* Reset the demod hardware and reset all of the configuration registers |
| 600 | to a default state. */ |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 601 | static int s5h1409_init(struct dvb_frontend *fe) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 602 | { |
| 603 | int i; |
| 604 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 605 | struct s5h1409_state *state = fe->demodulator_priv; |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 606 | dprintk("%s()\n", __func__); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 607 | |
| 608 | s5h1409_sleep(fe, 0); |
| 609 | s5h1409_register_reset(fe); |
| 610 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 611 | for (i = 0; i < ARRAY_SIZE(init_tab); i++) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 612 | s5h1409_writereg(state, init_tab[i].reg, init_tab[i].data); |
| 613 | |
| 614 | /* The datasheet says that after initialisation, VSB is default */ |
| 615 | state->current_modulation = VSB_8; |
| 616 | |
Devin Heitmueller | af5c8e1 | 2009-10-27 23:33:21 -0300 | [diff] [blame^] | 617 | /* Optimize for the HVR-1600 if appropriate. Note that some of these |
| 618 | may get folded into the generic case after testing with other |
| 619 | devices */ |
| 620 | if (state->config->hvr1600_opt == S5H1409_HVR1600_OPTIMIZE) { |
| 621 | /* VSB AGC REF */ |
| 622 | s5h1409_writereg(state, 0x09, 0x0050); |
| 623 | |
| 624 | /* Unknown but Windows driver does it... */ |
| 625 | s5h1409_writereg(state, 0x21, 0x0001); |
| 626 | s5h1409_writereg(state, 0x50, 0x030e); |
| 627 | |
| 628 | /* QAM AGC REF */ |
| 629 | s5h1409_writereg(state, 0x82, 0x0800); |
| 630 | } |
| 631 | |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 632 | if (state->config->output_mode == S5H1409_SERIAL_OUTPUT) |
Steven Toth | dfc1c08 | 2008-01-15 21:35:22 -0300 | [diff] [blame] | 633 | s5h1409_writereg(state, 0xab, |
| 634 | s5h1409_readreg(state, 0xab) | 0x100); /* Serial */ |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 635 | else |
Steven Toth | dfc1c08 | 2008-01-15 21:35:22 -0300 | [diff] [blame] | 636 | s5h1409_writereg(state, 0xab, |
| 637 | s5h1409_readreg(state, 0xab) & 0xfeff); /* Parallel */ |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 638 | |
| 639 | s5h1409_set_spectralinversion(fe, state->config->inversion); |
Michael Krufky | 2b03238 | 2007-12-13 10:04:10 -0300 | [diff] [blame] | 640 | s5h1409_set_if_freq(fe, state->if_freq); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 641 | s5h1409_set_gpio(fe, state->config->gpio); |
Steven Toth | dfc1c08 | 2008-01-15 21:35:22 -0300 | [diff] [blame] | 642 | s5h1409_set_mpeg_timing(fe, state->config->mpeg_timing); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 643 | s5h1409_softreset(fe); |
| 644 | |
Steven Toth | dd7d501 | 2007-10-24 21:05:51 -0300 | [diff] [blame] | 645 | /* Note: Leaving the I2C gate closed. */ |
| 646 | s5h1409_i2c_gate_ctrl(fe, 0); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 651 | static int s5h1409_read_status(struct dvb_frontend *fe, fe_status_t *status) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 652 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 653 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 654 | u16 reg; |
| 655 | u32 tuner_status = 0; |
| 656 | |
| 657 | *status = 0; |
| 658 | |
| 659 | /* Get the demodulator status */ |
| 660 | reg = s5h1409_readreg(state, 0xf1); |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 661 | if (reg & 0x1000) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 662 | *status |= FE_HAS_VITERBI; |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 663 | if (reg & 0x8000) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 664 | *status |= FE_HAS_LOCK | FE_HAS_SYNC; |
| 665 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 666 | switch (state->config->status_mode) { |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 667 | case S5H1409_DEMODLOCKING: |
| 668 | if (*status & FE_HAS_VITERBI) |
| 669 | *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL; |
| 670 | break; |
| 671 | case S5H1409_TUNERLOCKING: |
| 672 | /* Get the tuner status */ |
| 673 | if (fe->ops.tuner_ops.get_status) { |
Michael Krufky | 3873dd0 | 2007-07-28 20:02:55 -0300 | [diff] [blame] | 674 | if (fe->ops.i2c_gate_ctrl) |
| 675 | fe->ops.i2c_gate_ctrl(fe, 1); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 676 | |
| 677 | fe->ops.tuner_ops.get_status(fe, &tuner_status); |
| 678 | |
Michael Krufky | 3873dd0 | 2007-07-28 20:02:55 -0300 | [diff] [blame] | 679 | if (fe->ops.i2c_gate_ctrl) |
| 680 | fe->ops.i2c_gate_ctrl(fe, 0); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 681 | } |
| 682 | if (tuner_status) |
| 683 | *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL; |
| 684 | break; |
| 685 | } |
| 686 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 687 | dprintk("%s() status 0x%08x\n", __func__, *status); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 688 | |
| 689 | return 0; |
| 690 | } |
| 691 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 692 | static int s5h1409_qam256_lookup_snr(struct dvb_frontend *fe, u16 *snr, u16 v) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 693 | { |
| 694 | int i, ret = -EINVAL; |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 695 | dprintk("%s()\n", __func__); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 696 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 697 | for (i = 0; i < ARRAY_SIZE(qam256_snr_tab); i++) { |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 698 | if (v < qam256_snr_tab[i].val) { |
| 699 | *snr = qam256_snr_tab[i].data; |
| 700 | ret = 0; |
| 701 | break; |
| 702 | } |
| 703 | } |
| 704 | return ret; |
| 705 | } |
| 706 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 707 | static int s5h1409_qam64_lookup_snr(struct dvb_frontend *fe, u16 *snr, u16 v) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 708 | { |
| 709 | int i, ret = -EINVAL; |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 710 | dprintk("%s()\n", __func__); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 711 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 712 | for (i = 0; i < ARRAY_SIZE(qam64_snr_tab); i++) { |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 713 | if (v < qam64_snr_tab[i].val) { |
| 714 | *snr = qam64_snr_tab[i].data; |
| 715 | ret = 0; |
| 716 | break; |
| 717 | } |
| 718 | } |
| 719 | return ret; |
| 720 | } |
| 721 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 722 | static int s5h1409_vsb_lookup_snr(struct dvb_frontend *fe, u16 *snr, u16 v) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 723 | { |
| 724 | int i, ret = -EINVAL; |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 725 | dprintk("%s()\n", __func__); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 726 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 727 | for (i = 0; i < ARRAY_SIZE(vsb_snr_tab); i++) { |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 728 | if (v > vsb_snr_tab[i].val) { |
| 729 | *snr = vsb_snr_tab[i].data; |
| 730 | ret = 0; |
| 731 | break; |
| 732 | } |
| 733 | } |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 734 | dprintk("%s() snr=%d\n", __func__, *snr); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 735 | return ret; |
| 736 | } |
| 737 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 738 | static int s5h1409_read_snr(struct dvb_frontend *fe, u16 *snr) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 739 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 740 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 741 | u16 reg; |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 742 | dprintk("%s()\n", __func__); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 743 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 744 | switch (state->current_modulation) { |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 745 | case QAM_64: |
Steven Toth | 2300317 | 2007-12-12 22:14:00 -0300 | [diff] [blame] | 746 | reg = s5h1409_readreg(state, 0xf0) & 0xff; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 747 | return s5h1409_qam64_lookup_snr(fe, snr, reg); |
| 748 | case QAM_256: |
Steven Toth | 2300317 | 2007-12-12 22:14:00 -0300 | [diff] [blame] | 749 | reg = s5h1409_readreg(state, 0xf0) & 0xff; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 750 | return s5h1409_qam256_lookup_snr(fe, snr, reg); |
| 751 | case VSB_8: |
Steven Toth | 2300317 | 2007-12-12 22:14:00 -0300 | [diff] [blame] | 752 | reg = s5h1409_readreg(state, 0xf1) & 0x3ff; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 753 | return s5h1409_vsb_lookup_snr(fe, snr, reg); |
| 754 | default: |
| 755 | break; |
| 756 | } |
| 757 | |
| 758 | return -EINVAL; |
| 759 | } |
| 760 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 761 | static int s5h1409_read_signal_strength(struct dvb_frontend *fe, |
| 762 | u16 *signal_strength) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 763 | { |
| 764 | return s5h1409_read_snr(fe, signal_strength); |
| 765 | } |
| 766 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 767 | static int s5h1409_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 768 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 769 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 770 | |
| 771 | *ucblocks = s5h1409_readreg(state, 0xb5); |
| 772 | |
| 773 | return 0; |
| 774 | } |
| 775 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 776 | static int s5h1409_read_ber(struct dvb_frontend *fe, u32 *ber) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 777 | { |
| 778 | return s5h1409_read_ucblocks(fe, ber); |
| 779 | } |
| 780 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 781 | static int s5h1409_get_frontend(struct dvb_frontend *fe, |
Michael Krufky | 3873dd0 | 2007-07-28 20:02:55 -0300 | [diff] [blame] | 782 | struct dvb_frontend_parameters *p) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 783 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 784 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 785 | |
| 786 | p->frequency = state->current_frequency; |
| 787 | p->u.vsb.modulation = state->current_modulation; |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 792 | static int s5h1409_get_tune_settings(struct dvb_frontend *fe, |
Michael Krufky | 3873dd0 | 2007-07-28 20:02:55 -0300 | [diff] [blame] | 793 | struct dvb_frontend_tune_settings *tune) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 794 | { |
| 795 | tune->min_delay_ms = 1000; |
| 796 | return 0; |
| 797 | } |
| 798 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 799 | static void s5h1409_release(struct dvb_frontend *fe) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 800 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 801 | struct s5h1409_state *state = fe->demodulator_priv; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 802 | kfree(state); |
| 803 | } |
| 804 | |
| 805 | static struct dvb_frontend_ops s5h1409_ops; |
| 806 | |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 807 | struct dvb_frontend *s5h1409_attach(const struct s5h1409_config *config, |
| 808 | struct i2c_adapter *i2c) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 809 | { |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 810 | struct s5h1409_state *state = NULL; |
Steven Toth | a57ed8a | 2008-01-10 03:43:11 -0300 | [diff] [blame] | 811 | u16 reg; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 812 | |
| 813 | /* allocate memory for the internal state */ |
Matthias Schwarzott | 084e24a | 2009-08-10 22:51:01 -0300 | [diff] [blame] | 814 | state = kzalloc(sizeof(struct s5h1409_state), GFP_KERNEL); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 815 | if (state == NULL) |
| 816 | goto error; |
| 817 | |
| 818 | /* setup the state */ |
| 819 | state->config = config; |
| 820 | state->i2c = i2c; |
| 821 | state->current_modulation = 0; |
Michael Krufky | 2b03238 | 2007-12-13 10:04:10 -0300 | [diff] [blame] | 822 | state->if_freq = S5H1409_VSB_IF_FREQ; |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 823 | |
| 824 | /* check if the demod exists */ |
Steven Toth | a57ed8a | 2008-01-10 03:43:11 -0300 | [diff] [blame] | 825 | reg = s5h1409_readreg(state, 0x04); |
| 826 | if ((reg != 0x0066) && (reg != 0x007f)) |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 827 | goto error; |
| 828 | |
| 829 | /* create dvb_frontend */ |
Michael Krufky | 3873dd0 | 2007-07-28 20:02:55 -0300 | [diff] [blame] | 830 | memcpy(&state->frontend.ops, &s5h1409_ops, |
| 831 | sizeof(struct dvb_frontend_ops)); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 832 | state->frontend.demodulator_priv = state; |
| 833 | |
Steven Toth | a57ed8a | 2008-01-10 03:43:11 -0300 | [diff] [blame] | 834 | if (s5h1409_init(&state->frontend) != 0) { |
| 835 | printk(KERN_ERR "%s: Failed to initialize correctly\n", |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 836 | __func__); |
Steven Toth | a57ed8a | 2008-01-10 03:43:11 -0300 | [diff] [blame] | 837 | goto error; |
| 838 | } |
| 839 | |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 840 | /* Note: Leaving the I2C gate open here. */ |
Steven Toth | a57ed8a | 2008-01-10 03:43:11 -0300 | [diff] [blame] | 841 | s5h1409_i2c_gate_ctrl(&state->frontend, 1); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 842 | |
| 843 | return &state->frontend; |
| 844 | |
| 845 | error: |
| 846 | kfree(state); |
| 847 | return NULL; |
| 848 | } |
Steven Toth | b7709c0d | 2008-10-16 20:27:11 -0300 | [diff] [blame] | 849 | EXPORT_SYMBOL(s5h1409_attach); |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 850 | |
| 851 | static struct dvb_frontend_ops s5h1409_ops = { |
| 852 | |
| 853 | .info = { |
| 854 | .name = "Samsung S5H1409 QAM/8VSB Frontend", |
| 855 | .type = FE_ATSC, |
| 856 | .frequency_min = 54000000, |
| 857 | .frequency_max = 858000000, |
| 858 | .frequency_stepsize = 62500, |
| 859 | .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB |
| 860 | }, |
| 861 | |
| 862 | .init = s5h1409_init, |
| 863 | .i2c_gate_ctrl = s5h1409_i2c_gate_ctrl, |
| 864 | .set_frontend = s5h1409_set_frontend, |
| 865 | .get_frontend = s5h1409_get_frontend, |
| 866 | .get_tune_settings = s5h1409_get_tune_settings, |
| 867 | .read_status = s5h1409_read_status, |
| 868 | .read_ber = s5h1409_read_ber, |
| 869 | .read_signal_strength = s5h1409_read_signal_strength, |
| 870 | .read_snr = s5h1409_read_snr, |
| 871 | .read_ucblocks = s5h1409_read_ucblocks, |
| 872 | .release = s5h1409_release, |
| 873 | }; |
| 874 | |
Steven Toth | 8988555 | 2007-07-28 19:34:52 -0300 | [diff] [blame] | 875 | MODULE_DESCRIPTION("Samsung S5H1409 QAM-B/ATSC Demodulator driver"); |
| 876 | MODULE_AUTHOR("Steven Toth"); |
| 877 | MODULE_LICENSE("GPL"); |
| 878 | |
Michael Krufky | 3873dd0 | 2007-07-28 20:02:55 -0300 | [diff] [blame] | 879 | |
| 880 | /* |
| 881 | * Local variables: |
| 882 | * c-basic-offset: 8 |
| 883 | */ |