Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * b2c2-common.c - common methods for the B2C2/Technisat SkyStar2 PCI DVB card and |
| 3 | * for the B2C2/Technisat Sky/Cable/AirStar USB devices |
| 4 | * based on the FlexCopII/FlexCopIII by B2C2, Inc. |
| 5 | * |
| 6 | * Copyright (C) 2003 Vadim Catana, skystar@moldova.cc |
| 7 | * |
| 8 | * FIX: DISEQC Tone Burst in flexcop_diseqc_ioctl() |
| 9 | * FIX: FULL soft DiSEqC for skystar2 (FlexCopII rev 130) VP310 equipped |
| 10 | * Vincenzo Di Massa, hawk.it at tiscalinet.it |
| 11 | * |
| 12 | * Converted to Linux coding style |
| 13 | * Misc reorganization, polishing, restyling |
| 14 | * Roberto Ragusa, r.ragusa at libero.it |
| 15 | * |
| 16 | * Added hardware filtering support, |
| 17 | * Niklas Peinecke, peinecke at gdv.uni-hannover.de |
| 18 | * |
| 19 | * This program is free software; you can redistribute it and/or |
| 20 | * modify it under the terms of the GNU Lesser General Public License |
| 21 | * as published by the Free Software Foundation; either version 2.1 |
| 22 | * of the License, or (at your option) any later version. |
| 23 | * |
| 24 | * This program is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | * GNU General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU Lesser General Public License |
| 30 | * along with this program; if not, write to the Free Software |
| 31 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 32 | * |
| 33 | */ |
| 34 | #include "stv0299.h" |
| 35 | #include "mt352.h" |
| 36 | #include "mt312.h" |
| 37 | |
| 38 | static int samsung_tbmu24112_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio) |
| 39 | { |
| 40 | u8 aclk = 0; |
| 41 | u8 bclk = 0; |
| 42 | |
| 43 | if (srate < 1500000) { aclk = 0xb7; bclk = 0x47; } |
| 44 | else if (srate < 3000000) { aclk = 0xb7; bclk = 0x4b; } |
| 45 | else if (srate < 7000000) { aclk = 0xb7; bclk = 0x4f; } |
| 46 | else if (srate < 14000000) { aclk = 0xb7; bclk = 0x53; } |
| 47 | else if (srate < 30000000) { aclk = 0xb6; bclk = 0x53; } |
| 48 | else if (srate < 45000000) { aclk = 0xb4; bclk = 0x51; } |
| 49 | |
| 50 | stv0299_writereg (fe, 0x13, aclk); |
| 51 | stv0299_writereg (fe, 0x14, bclk); |
| 52 | stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff); |
| 53 | stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff); |
| 54 | stv0299_writereg (fe, 0x21, (ratio ) & 0xf0); |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static int samsung_tbmu24112_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) |
| 60 | { |
| 61 | u8 buf[4]; |
| 62 | u32 div; |
| 63 | struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) }; |
| 64 | // struct adapter* adapter = (struct adapter*) fe->dvb->priv; |
| 65 | |
| 66 | div = params->frequency / 125; |
| 67 | |
| 68 | buf[0] = (div >> 8) & 0x7f; |
| 69 | buf[1] = div & 0xff; |
| 70 | buf[2] = 0x84; // 0xC4 |
| 71 | buf[3] = 0x08; |
| 72 | |
| 73 | if (params->frequency < 1500000) buf[3] |= 0x10; |
| 74 | |
| 75 | // if (i2c_transfer (&adapter->i2c_adap, &msg, 1) != 1) return -EIO; |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | static u8 samsung_tbmu24112_inittab[] = { |
| 80 | 0x01, 0x15, |
| 81 | 0x02, 0x30, |
| 82 | 0x03, 0x00, |
| 83 | 0x04, 0x7D, |
| 84 | 0x05, 0x35, |
| 85 | 0x06, 0x02, |
| 86 | 0x07, 0x00, |
| 87 | 0x08, 0xC3, |
| 88 | 0x0C, 0x00, |
| 89 | 0x0D, 0x81, |
| 90 | 0x0E, 0x23, |
| 91 | 0x0F, 0x12, |
| 92 | 0x10, 0x7E, |
| 93 | 0x11, 0x84, |
| 94 | 0x12, 0xB9, |
| 95 | 0x13, 0x88, |
| 96 | 0x14, 0x89, |
| 97 | 0x15, 0xC9, |
| 98 | 0x16, 0x00, |
| 99 | 0x17, 0x5C, |
| 100 | 0x18, 0x00, |
| 101 | 0x19, 0x00, |
| 102 | 0x1A, 0x00, |
| 103 | 0x1C, 0x00, |
| 104 | 0x1D, 0x00, |
| 105 | 0x1E, 0x00, |
| 106 | 0x1F, 0x3A, |
| 107 | 0x20, 0x2E, |
| 108 | 0x21, 0x80, |
| 109 | 0x22, 0xFF, |
| 110 | 0x23, 0xC1, |
| 111 | 0x28, 0x00, |
| 112 | 0x29, 0x1E, |
| 113 | 0x2A, 0x14, |
| 114 | 0x2B, 0x0F, |
| 115 | 0x2C, 0x09, |
| 116 | 0x2D, 0x05, |
| 117 | 0x31, 0x1F, |
| 118 | 0x32, 0x19, |
| 119 | 0x33, 0xFE, |
| 120 | 0x34, 0x93, |
| 121 | 0xff, 0xff, |
| 122 | }; |
| 123 | |
| 124 | static struct stv0299_config samsung_tbmu24112_config = { |
| 125 | .demod_address = 0x68, |
| 126 | .inittab = samsung_tbmu24112_inittab, |
| 127 | .mclk = 88000000UL, |
| 128 | .invert = 0, |
| 129 | .enhanced_tuning = 0, |
| 130 | .skip_reinit = 0, |
| 131 | .lock_output = STV0229_LOCKOUTPUT_LK, |
| 132 | .volt13_op0_op1 = STV0299_VOLT13_OP1, |
| 133 | .min_delay_ms = 100, |
| 134 | .set_symbol_rate = samsung_tbmu24112_set_symbol_rate, |
| 135 | .pll_set = samsung_tbmu24112_pll_set, |
| 136 | }; |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | static int samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe) |
| 143 | { |
| 144 | static u8 mt352_clock_config [] = { 0x89, 0x10, 0x2d }; |
| 145 | static u8 mt352_reset [] = { 0x50, 0x80 }; |
| 146 | static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 }; |
| 147 | static u8 mt352_agc_cfg [] = { 0x67, 0x28, 0xa1 }; |
| 148 | static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 }; |
| 149 | |
| 150 | mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config)); |
| 151 | udelay(2000); |
| 152 | mt352_write(fe, mt352_reset, sizeof(mt352_reset)); |
| 153 | mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg)); |
| 154 | |
| 155 | mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg)); |
| 156 | mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg)); |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | static int samsung_tdtc9251dh0_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf) |
| 162 | { |
| 163 | u32 div; |
| 164 | unsigned char bs = 0; |
| 165 | |
| 166 | #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */ |
| 167 | div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6; |
| 168 | |
| 169 | if (params->frequency >= 48000000 && params->frequency <= 154000000) bs = 0x09; |
| 170 | if (params->frequency >= 161000000 && params->frequency <= 439000000) bs = 0x0a; |
| 171 | if (params->frequency >= 447000000 && params->frequency <= 863000000) bs = 0x08; |
| 172 | |
| 173 | pllbuf[0] = 0xc2; // Note: non-linux standard PLL i2c address |
| 174 | pllbuf[1] = div >> 8; |
| 175 | pllbuf[2] = div & 0xff; |
| 176 | pllbuf[3] = 0xcc; |
| 177 | pllbuf[4] = bs; |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | static struct mt352_config samsung_tdtc9251dh0_config = { |
| 183 | |
| 184 | .demod_address = 0x0f, |
| 185 | .demod_init = samsung_tdtc9251dh0_demod_init, |
| 186 | .pll_set = samsung_tdtc9251dh0_pll_set, |
| 187 | }; |
| 188 | |
| 189 | static int skystar23_samsung_tbdu18132_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) |
| 190 | { |
| 191 | u8 buf[4]; |
| 192 | u32 div; |
| 193 | struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) }; |
| 194 | // struct adapter* adapter = (struct adapter*) fe->dvb->priv; |
| 195 | |
| 196 | div = (params->frequency + (125/2)) / 125; |
| 197 | |
| 198 | buf[0] = (div >> 8) & 0x7f; |
| 199 | buf[1] = (div >> 0) & 0xff; |
| 200 | buf[2] = 0x84 | ((div >> 10) & 0x60); |
| 201 | buf[3] = 0x80; |
| 202 | |
| 203 | if (params->frequency < 1550000) |
| 204 | buf[3] |= 0x02; |
| 205 | |
| 206 | //if (i2c_transfer (&adapter->i2c_adap, &msg, 1) != 1) return -EIO; |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | static struct mt312_config skystar23_samsung_tbdu18132_config = { |
| 211 | |
| 212 | .demod_address = 0x0e, |
| 213 | .pll_set = skystar23_samsung_tbdu18132_pll_set, |
| 214 | }; |