Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1 | /* |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 2 | * Conexant cx24123/cx24109 - DVB QPSK Satellite demod/tuner driver |
| 3 | * |
Steven Toth | 6d89761 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 4 | * Copyright (C) 2005 Steven Toth <stoth@linuxtv.org> |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 5 | * |
| 6 | * Support for KWorld DVB-S 100 by Vadim Catana <skystar@moldova.cc> |
| 7 | * |
| 8 | * Support for CX24123/CX24113-NIM by Patrick Boettcher <pb@linuxtv.org> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | */ |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 24 | |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 28 | #include <linux/init.h> |
Mauro Carvalho Chehab | 752a62b | 2013-04-07 21:11:53 -0300 | [diff] [blame] | 29 | #include <asm/div64.h> |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 30 | |
| 31 | #include "dvb_frontend.h" |
| 32 | #include "cx24123.h" |
| 33 | |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 34 | #define XTAL 10111000 |
| 35 | |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 36 | static int force_band; |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 37 | module_param(force_band, int, 0644); |
| 38 | MODULE_PARM_DESC(force_band, "Force a specific band select "\ |
| 39 | "(1-9, default:off)."); |
| 40 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 41 | static int debug; |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 42 | module_param(debug, int, 0644); |
| 43 | MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)"); |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 44 | |
| 45 | #define info(args...) do { printk(KERN_INFO "CX24123: " args); } while (0) |
| 46 | #define err(args...) do { printk(KERN_ERR "CX24123: " args); } while (0) |
| 47 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 48 | #define dprintk(args...) \ |
| 49 | do { \ |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 50 | if (debug) { \ |
| 51 | printk(KERN_DEBUG "CX24123: %s: ", __func__); \ |
| 52 | printk(args); \ |
| 53 | } \ |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 54 | } while (0) |
| 55 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 56 | struct cx24123_state { |
| 57 | struct i2c_adapter *i2c; |
| 58 | const struct cx24123_config *config; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 59 | |
| 60 | struct dvb_frontend frontend; |
| 61 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 62 | /* Some PLL specifics for tuning */ |
| 63 | u32 VCAarg; |
| 64 | u32 VGAarg; |
| 65 | u32 bandselectarg; |
| 66 | u32 pllarg; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 67 | u32 FILTune; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 68 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 69 | struct i2c_adapter tuner_i2c_adapter; |
| 70 | |
| 71 | u8 demod_rev; |
| 72 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 73 | /* The Demod/Tuner can't easily provide these, we cache them */ |
| 74 | u32 currentfreq; |
| 75 | u32 currentsymbolrate; |
| 76 | }; |
| 77 | |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 78 | /* Various tuner defaults need to be established for a given symbol rate Sps */ |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 79 | static struct cx24123_AGC_val { |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 80 | u32 symbolrate_low; |
| 81 | u32 symbolrate_high; |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 82 | u32 VCAprogdata; |
| 83 | u32 VGAprogdata; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 84 | u32 FILTune; |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 85 | } cx24123_AGC_vals[] = |
| 86 | { |
| 87 | { |
| 88 | .symbolrate_low = 1000000, |
| 89 | .symbolrate_high = 4999999, |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 90 | /* the specs recommend other values for VGA offsets, |
| 91 | but tests show they are wrong */ |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 92 | .VGAprogdata = (1 << 19) | (0x180 << 9) | 0x1e0, |
| 93 | .VCAprogdata = (2 << 19) | (0x07 << 9) | 0x07, |
| 94 | .FILTune = 0x27f /* 0.41 V */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 95 | }, |
| 96 | { |
| 97 | .symbolrate_low = 5000000, |
| 98 | .symbolrate_high = 14999999, |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 99 | .VGAprogdata = (1 << 19) | (0x180 << 9) | 0x1e0, |
| 100 | .VCAprogdata = (2 << 19) | (0x07 << 9) | 0x1f, |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 101 | .FILTune = 0x317 /* 0.90 V */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 102 | }, |
| 103 | { |
| 104 | .symbolrate_low = 15000000, |
| 105 | .symbolrate_high = 45000000, |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 106 | .VGAprogdata = (1 << 19) | (0x100 << 9) | 0x180, |
| 107 | .VCAprogdata = (2 << 19) | (0x07 << 9) | 0x3f, |
| 108 | .FILTune = 0x145 /* 2.70 V */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 109 | }, |
| 110 | }; |
| 111 | |
| 112 | /* |
| 113 | * Various tuner defaults need to be established for a given frequency kHz. |
| 114 | * fixme: The bounds on the bands do not match the doc in real life. |
| 115 | * fixme: Some of them have been moved, other might need adjustment. |
| 116 | */ |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 117 | static struct cx24123_bandselect_val { |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 118 | u32 freq_low; |
| 119 | u32 freq_high; |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 120 | u32 VCOdivider; |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 121 | u32 progdata; |
| 122 | } cx24123_bandselect_vals[] = |
| 123 | { |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 124 | /* band 1 */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 125 | { |
| 126 | .freq_low = 950000, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 127 | .freq_high = 1074999, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 128 | .VCOdivider = 4, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 129 | .progdata = (0 << 19) | (0 << 9) | 0x40, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 130 | }, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 131 | |
| 132 | /* band 2 */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 133 | { |
| 134 | .freq_low = 1075000, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 135 | .freq_high = 1177999, |
| 136 | .VCOdivider = 4, |
| 137 | .progdata = (0 << 19) | (0 << 9) | 0x80, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 138 | }, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 139 | |
| 140 | /* band 3 */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 141 | { |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 142 | .freq_low = 1178000, |
| 143 | .freq_high = 1295999, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 144 | .VCOdivider = 2, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 145 | .progdata = (0 << 19) | (1 << 9) | 0x01, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 146 | }, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 147 | |
| 148 | /* band 4 */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 149 | { |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 150 | .freq_low = 1296000, |
| 151 | .freq_high = 1431999, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 152 | .VCOdivider = 2, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 153 | .progdata = (0 << 19) | (1 << 9) | 0x02, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 154 | }, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 155 | |
| 156 | /* band 5 */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 157 | { |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 158 | .freq_low = 1432000, |
| 159 | .freq_high = 1575999, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 160 | .VCOdivider = 2, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 161 | .progdata = (0 << 19) | (1 << 9) | 0x04, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 162 | }, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 163 | |
| 164 | /* band 6 */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 165 | { |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 166 | .freq_low = 1576000, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 167 | .freq_high = 1717999, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 168 | .VCOdivider = 2, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 169 | .progdata = (0 << 19) | (1 << 9) | 0x08, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 170 | }, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 171 | |
| 172 | /* band 7 */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 173 | { |
| 174 | .freq_low = 1718000, |
| 175 | .freq_high = 1855999, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 176 | .VCOdivider = 2, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 177 | .progdata = (0 << 19) | (1 << 9) | 0x10, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 178 | }, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 179 | |
| 180 | /* band 8 */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 181 | { |
| 182 | .freq_low = 1856000, |
| 183 | .freq_high = 2035999, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 184 | .VCOdivider = 2, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 185 | .progdata = (0 << 19) | (1 << 9) | 0x20, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 186 | }, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 187 | |
| 188 | /* band 9 */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 189 | { |
| 190 | .freq_low = 2036000, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 191 | .freq_high = 2150000, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 192 | .VCOdivider = 2, |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 193 | .progdata = (0 << 19) | (1 << 9) | 0x40, |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 194 | }, |
| 195 | }; |
| 196 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 197 | static struct { |
| 198 | u8 reg; |
| 199 | u8 data; |
| 200 | } cx24123_regdata[] = |
| 201 | { |
| 202 | {0x00, 0x03}, /* Reset system */ |
| 203 | {0x00, 0x00}, /* Clear reset */ |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 204 | {0x03, 0x07}, /* QPSK, DVB, Auto Acquisition (default) */ |
| 205 | {0x04, 0x10}, /* MPEG */ |
| 206 | {0x05, 0x04}, /* MPEG */ |
| 207 | {0x06, 0x31}, /* MPEG (default) */ |
| 208 | {0x0b, 0x00}, /* Freq search start point (default) */ |
| 209 | {0x0c, 0x00}, /* Demodulator sample gain (default) */ |
Mauro Carvalho Chehab | d93f886 | 2006-08-06 17:03:50 -0300 | [diff] [blame] | 210 | {0x0d, 0x7f}, /* Force driver to shift until the maximum (+-10 MHz) */ |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 211 | {0x0e, 0x03}, /* Default non-inverted, FEC 3/4 (default) */ |
| 212 | {0x0f, 0xfe}, /* FEC search mask (all supported codes) */ |
| 213 | {0x10, 0x01}, /* Default search inversion, no repeat (default) */ |
| 214 | {0x16, 0x00}, /* Enable reading of frequency */ |
| 215 | {0x17, 0x01}, /* Enable EsNO Ready Counter */ |
| 216 | {0x1c, 0x80}, /* Enable error counter */ |
| 217 | {0x20, 0x00}, /* Tuner burst clock rate = 500KHz */ |
| 218 | {0x21, 0x15}, /* Tuner burst mode, word length = 0x15 */ |
| 219 | {0x28, 0x00}, /* Enable FILTERV with positive pol., DiSEqC 2.x off */ |
| 220 | {0x29, 0x00}, /* DiSEqC LNB_DC off */ |
| 221 | {0x2a, 0xb0}, /* DiSEqC Parameters (default) */ |
| 222 | {0x2b, 0x73}, /* DiSEqC Tone Frequency (default) */ |
| 223 | {0x2c, 0x00}, /* DiSEqC Message (0x2c - 0x31) */ |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 224 | {0x2d, 0x00}, |
| 225 | {0x2e, 0x00}, |
| 226 | {0x2f, 0x00}, |
| 227 | {0x30, 0x00}, |
| 228 | {0x31, 0x00}, |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 229 | {0x32, 0x8c}, /* DiSEqC Parameters (default) */ |
| 230 | {0x33, 0x00}, /* Interrupts off (0x33 - 0x34) */ |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 231 | {0x34, 0x00}, |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 232 | {0x35, 0x03}, /* DiSEqC Tone Amplitude (default) */ |
| 233 | {0x36, 0x02}, /* DiSEqC Parameters (default) */ |
| 234 | {0x37, 0x3a}, /* DiSEqC Parameters (default) */ |
| 235 | {0x3a, 0x00}, /* Enable AGC accumulator (for signal strength) */ |
| 236 | {0x44, 0x00}, /* Constellation (default) */ |
| 237 | {0x45, 0x00}, /* Symbol count (default) */ |
| 238 | {0x46, 0x0d}, /* Symbol rate estimator on (default) */ |
Yeasah Pell | 18c053b | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 239 | {0x56, 0xc1}, /* Error Counter = Viterbi BER */ |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 240 | {0x57, 0xff}, /* Error Counter Window (default) */ |
Mauro Carvalho Chehab | d93f886 | 2006-08-06 17:03:50 -0300 | [diff] [blame] | 241 | {0x5c, 0x20}, /* Acquisition AFC Expiration window (default is 0x10) */ |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 242 | {0x67, 0x83}, /* Non-DCII symbol clock */ |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 243 | }; |
| 244 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 245 | static int cx24123_i2c_writereg(struct cx24123_state *state, |
| 246 | u8 i2c_addr, int reg, int data) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 247 | { |
| 248 | u8 buf[] = { reg, data }; |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 249 | struct i2c_msg msg = { |
| 250 | .addr = i2c_addr, .flags = 0, .buf = buf, .len = 2 |
| 251 | }; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 252 | int err; |
| 253 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 254 | /* printk(KERN_DEBUG "wr(%02x): %02x %02x\n", i2c_addr, reg, data); */ |
Mauro Carvalho Chehab | caf970e | 2006-04-13 11:29:13 -0300 | [diff] [blame] | 255 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 256 | err = i2c_transfer(state->i2c, &msg, 1); |
| 257 | if (err != 1) { |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 258 | printk("%s: writereg error(err == %i, reg == 0x%02x," |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 259 | " data == 0x%02x)\n", __func__, err, reg, data); |
| 260 | return err; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 266 | static int cx24123_i2c_readreg(struct cx24123_state *state, u8 i2c_addr, u8 reg) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 267 | { |
| 268 | int ret; |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 269 | u8 b = 0; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 270 | struct i2c_msg msg[] = { |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 271 | { .addr = i2c_addr, .flags = 0, .buf = ®, .len = 1 }, |
| 272 | { .addr = i2c_addr, .flags = I2C_M_RD, .buf = &b, .len = 1 } |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | ret = i2c_transfer(state->i2c, msg, 2); |
| 276 | |
| 277 | if (ret != 2) { |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 278 | err("%s: reg=0x%x (error=%d)\n", __func__, reg, ret); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 279 | return ret; |
| 280 | } |
| 281 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 282 | /* printk(KERN_DEBUG "rd(%02x): %02x %02x\n", i2c_addr, reg, b); */ |
Mauro Carvalho Chehab | caf970e | 2006-04-13 11:29:13 -0300 | [diff] [blame] | 283 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 284 | return b; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 285 | } |
| 286 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 287 | #define cx24123_readreg(state, reg) \ |
| 288 | cx24123_i2c_readreg(state, state->config->demod_address, reg) |
| 289 | #define cx24123_writereg(state, reg, val) \ |
| 290 | cx24123_i2c_writereg(state, state->config->demod_address, reg, val) |
| 291 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 292 | static int cx24123_set_inversion(struct cx24123_state *state, |
| 293 | fe_spectral_inversion_t inversion) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 294 | { |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 295 | u8 nom_reg = cx24123_readreg(state, 0x0e); |
| 296 | u8 auto_reg = cx24123_readreg(state, 0x10); |
| 297 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 298 | switch (inversion) { |
| 299 | case INVERSION_OFF: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 300 | dprintk("inversion off\n"); |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 301 | cx24123_writereg(state, 0x0e, nom_reg & ~0x80); |
| 302 | cx24123_writereg(state, 0x10, auto_reg | 0x80); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 303 | break; |
| 304 | case INVERSION_ON: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 305 | dprintk("inversion on\n"); |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 306 | cx24123_writereg(state, 0x0e, nom_reg | 0x80); |
| 307 | cx24123_writereg(state, 0x10, auto_reg | 0x80); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 308 | break; |
| 309 | case INVERSION_AUTO: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 310 | dprintk("inversion auto\n"); |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 311 | cx24123_writereg(state, 0x10, auto_reg & ~0x80); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 312 | break; |
| 313 | default: |
| 314 | return -EINVAL; |
| 315 | } |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 320 | static int cx24123_get_inversion(struct cx24123_state *state, |
| 321 | fe_spectral_inversion_t *inversion) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 322 | { |
| 323 | u8 val; |
| 324 | |
| 325 | val = cx24123_readreg(state, 0x1b) >> 7; |
| 326 | |
Mauro Carvalho Chehab | caf970e | 2006-04-13 11:29:13 -0300 | [diff] [blame] | 327 | if (val == 0) { |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 328 | dprintk("read inversion off\n"); |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 329 | *inversion = INVERSION_OFF; |
Mauro Carvalho Chehab | caf970e | 2006-04-13 11:29:13 -0300 | [diff] [blame] | 330 | } else { |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 331 | dprintk("read inversion on\n"); |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 332 | *inversion = INVERSION_ON; |
Mauro Carvalho Chehab | caf970e | 2006-04-13 11:29:13 -0300 | [diff] [blame] | 333 | } |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 338 | static int cx24123_set_fec(struct cx24123_state *state, fe_code_rate_t fec) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 339 | { |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 340 | u8 nom_reg = cx24123_readreg(state, 0x0e) & ~0x07; |
| 341 | |
Mauro Carvalho Chehab | 830e4b5 | 2012-10-27 16:14:01 -0300 | [diff] [blame] | 342 | if (((int)fec < FEC_NONE) || (fec > FEC_AUTO)) |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 343 | fec = FEC_AUTO; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 344 | |
Yeasah Pell | d12a9b9 | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 345 | /* Set the soft decision threshold */ |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 346 | if (fec == FEC_1_2) |
| 347 | cx24123_writereg(state, 0x43, |
| 348 | cx24123_readreg(state, 0x43) | 0x01); |
Yeasah Pell | d12a9b9 | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 349 | else |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 350 | cx24123_writereg(state, 0x43, |
| 351 | cx24123_readreg(state, 0x43) & ~0x01); |
Yeasah Pell | d12a9b9 | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 352 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 353 | switch (fec) { |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 354 | case FEC_1_2: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 355 | dprintk("set FEC to 1/2\n"); |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 356 | cx24123_writereg(state, 0x0e, nom_reg | 0x01); |
| 357 | cx24123_writereg(state, 0x0f, 0x02); |
| 358 | break; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 359 | case FEC_2_3: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 360 | dprintk("set FEC to 2/3\n"); |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 361 | cx24123_writereg(state, 0x0e, nom_reg | 0x02); |
| 362 | cx24123_writereg(state, 0x0f, 0x04); |
| 363 | break; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 364 | case FEC_3_4: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 365 | dprintk("set FEC to 3/4\n"); |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 366 | cx24123_writereg(state, 0x0e, nom_reg | 0x03); |
| 367 | cx24123_writereg(state, 0x0f, 0x08); |
| 368 | break; |
| 369 | case FEC_4_5: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 370 | dprintk("set FEC to 4/5\n"); |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 371 | cx24123_writereg(state, 0x0e, nom_reg | 0x04); |
| 372 | cx24123_writereg(state, 0x0f, 0x10); |
| 373 | break; |
| 374 | case FEC_5_6: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 375 | dprintk("set FEC to 5/6\n"); |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 376 | cx24123_writereg(state, 0x0e, nom_reg | 0x05); |
| 377 | cx24123_writereg(state, 0x0f, 0x20); |
| 378 | break; |
| 379 | case FEC_6_7: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 380 | dprintk("set FEC to 6/7\n"); |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 381 | cx24123_writereg(state, 0x0e, nom_reg | 0x06); |
| 382 | cx24123_writereg(state, 0x0f, 0x40); |
| 383 | break; |
| 384 | case FEC_7_8: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 385 | dprintk("set FEC to 7/8\n"); |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 386 | cx24123_writereg(state, 0x0e, nom_reg | 0x07); |
| 387 | cx24123_writereg(state, 0x0f, 0x80); |
| 388 | break; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 389 | case FEC_AUTO: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 390 | dprintk("set FEC to auto\n"); |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 391 | cx24123_writereg(state, 0x0f, 0xfe); |
| 392 | break; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 393 | default: |
| 394 | return -EOPNOTSUPP; |
| 395 | } |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 396 | |
| 397 | return 0; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 398 | } |
| 399 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 400 | static int cx24123_get_fec(struct cx24123_state *state, fe_code_rate_t *fec) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 401 | { |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 402 | int ret; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 403 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 404 | ret = cx24123_readreg(state, 0x1b); |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 405 | if (ret < 0) |
| 406 | return ret; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 407 | ret = ret & 0x07; |
| 408 | |
| 409 | switch (ret) { |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 410 | case 1: |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 411 | *fec = FEC_1_2; |
| 412 | break; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 413 | case 2: |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 414 | *fec = FEC_2_3; |
| 415 | break; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 416 | case 3: |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 417 | *fec = FEC_3_4; |
| 418 | break; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 419 | case 4: |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 420 | *fec = FEC_4_5; |
| 421 | break; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 422 | case 5: |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 423 | *fec = FEC_5_6; |
| 424 | break; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 425 | case 6: |
| 426 | *fec = FEC_6_7; |
| 427 | break; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 428 | case 7: |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 429 | *fec = FEC_7_8; |
| 430 | break; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 431 | default: |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 432 | /* this can happen when there's no lock */ |
| 433 | *fec = FEC_NONE; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 434 | } |
| 435 | |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 436 | return 0; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 437 | } |
| 438 | |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 439 | /* Approximation of closest integer of log2(a/b). It actually gives the |
| 440 | lowest integer i such that 2^i >= round(a/b) */ |
| 441 | static u32 cx24123_int_log2(u32 a, u32 b) |
| 442 | { |
| 443 | u32 exp, nearest = 0; |
| 444 | u32 div = a / b; |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 445 | if (a % b >= b / 2) |
| 446 | ++div; |
| 447 | if (div < (1 << 31)) { |
| 448 | for (exp = 1; div > exp; nearest++) |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 449 | exp += exp; |
| 450 | } |
| 451 | return nearest; |
| 452 | } |
| 453 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 454 | static int cx24123_set_symbolrate(struct cx24123_state *state, u32 srate) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 455 | { |
Mauro Carvalho Chehab | 752a62b | 2013-04-07 21:11:53 -0300 | [diff] [blame] | 456 | u64 tmp; |
| 457 | u32 sample_rate, ratio, sample_gain; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 458 | u8 pll_mult; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 459 | |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 460 | /* check if symbol rate is within limits */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 461 | if ((srate > state->frontend.ops.info.symbol_rate_max) || |
| 462 | (srate < state->frontend.ops.info.symbol_rate_min)) |
Joe Perches | 1ebcad7 | 2009-07-02 15:57:09 -0300 | [diff] [blame] | 463 | return -EOPNOTSUPP; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 464 | |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 465 | /* choose the sampling rate high enough for the required operation, |
| 466 | while optimizing the power consumed by the demodulator */ |
| 467 | if (srate < (XTAL*2)/2) |
| 468 | pll_mult = 2; |
| 469 | else if (srate < (XTAL*3)/2) |
| 470 | pll_mult = 3; |
| 471 | else if (srate < (XTAL*4)/2) |
| 472 | pll_mult = 4; |
| 473 | else if (srate < (XTAL*5)/2) |
| 474 | pll_mult = 5; |
| 475 | else if (srate < (XTAL*6)/2) |
| 476 | pll_mult = 6; |
| 477 | else if (srate < (XTAL*7)/2) |
| 478 | pll_mult = 7; |
| 479 | else if (srate < (XTAL*8)/2) |
| 480 | pll_mult = 8; |
| 481 | else |
| 482 | pll_mult = 9; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 483 | |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 484 | |
| 485 | sample_rate = pll_mult * XTAL; |
| 486 | |
Mauro Carvalho Chehab | 752a62b | 2013-04-07 21:11:53 -0300 | [diff] [blame] | 487 | /* SYSSymbolRate[21:0] = (srate << 23) / sample_rate */ |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 488 | |
Mauro Carvalho Chehab | 752a62b | 2013-04-07 21:11:53 -0300 | [diff] [blame] | 489 | tmp = ((u64)srate) << 23; |
| 490 | do_div(tmp, sample_rate); |
| 491 | ratio = (u32) tmp; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 492 | |
| 493 | cx24123_writereg(state, 0x01, pll_mult * 6); |
| 494 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 495 | cx24123_writereg(state, 0x08, (ratio >> 16) & 0x3f); |
| 496 | cx24123_writereg(state, 0x09, (ratio >> 8) & 0xff); |
| 497 | cx24123_writereg(state, 0x0a, ratio & 0xff); |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 498 | |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 499 | /* also set the demodulator sample gain */ |
| 500 | sample_gain = cx24123_int_log2(sample_rate, srate); |
| 501 | tmp = cx24123_readreg(state, 0x0c) & ~0xe0; |
| 502 | cx24123_writereg(state, 0x0c, tmp | sample_gain << 5); |
| 503 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 504 | dprintk("srate=%d, ratio=0x%08x, sample_rate=%i sample_gain=%d\n", |
| 505 | srate, ratio, sample_rate, sample_gain); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | /* |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 511 | * Based on the required frequency and symbolrate, the tuner AGC has |
| 512 | * to be configured and the correct band selected. |
| 513 | * Calculate those values. |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 514 | */ |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 515 | static int cx24123_pll_calculate(struct dvb_frontend *fe) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 516 | { |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 517 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 518 | struct cx24123_state *state = fe->demodulator_priv; |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 519 | u32 ndiv = 0, adiv = 0, vco_div = 0; |
| 520 | int i = 0; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 521 | int pump = 2; |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 522 | int band = 0; |
Ahmed S. Darwish | 0496daa7 | 2007-02-14 22:57:42 -0200 | [diff] [blame] | 523 | int num_bands = ARRAY_SIZE(cx24123_bandselect_vals); |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 524 | struct cx24123_bandselect_val *bsv = NULL; |
| 525 | struct cx24123_AGC_val *agcv = NULL; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 526 | |
| 527 | /* Defaults for low freq, low rate */ |
| 528 | state->VCAarg = cx24123_AGC_vals[0].VCAprogdata; |
| 529 | state->VGAarg = cx24123_AGC_vals[0].VGAprogdata; |
| 530 | state->bandselectarg = cx24123_bandselect_vals[0].progdata; |
| 531 | vco_div = cx24123_bandselect_vals[0].VCOdivider; |
| 532 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 533 | /* For the given symbol rate, determine the VCA, VGA and |
| 534 | * FILTUNE programming bits */ |
| 535 | for (i = 0; i < ARRAY_SIZE(cx24123_AGC_vals); i++) { |
| 536 | agcv = &cx24123_AGC_vals[i]; |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 537 | if ((agcv->symbolrate_low <= p->symbol_rate) && |
| 538 | (agcv->symbolrate_high >= p->symbol_rate)) { |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 539 | state->VCAarg = agcv->VCAprogdata; |
| 540 | state->VGAarg = agcv->VGAprogdata; |
| 541 | state->FILTune = agcv->FILTune; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 545 | /* determine the band to use */ |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 546 | if (force_band < 1 || force_band > num_bands) { |
| 547 | for (i = 0; i < num_bands; i++) { |
| 548 | bsv = &cx24123_bandselect_vals[i]; |
| 549 | if ((bsv->freq_low <= p->frequency) && |
| 550 | (bsv->freq_high >= p->frequency)) |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 551 | band = i; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 552 | } |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 553 | } else |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 554 | band = force_band - 1; |
| 555 | |
| 556 | state->bandselectarg = cx24123_bandselect_vals[band].progdata; |
| 557 | vco_div = cx24123_bandselect_vals[band].VCOdivider; |
| 558 | |
| 559 | /* determine the charge pump current */ |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 560 | if (p->frequency < (cx24123_bandselect_vals[band].freq_low + |
| 561 | cx24123_bandselect_vals[band].freq_high) / 2) |
Yeasah Pell | 70047f9 | 2006-04-13 17:26:22 -0300 | [diff] [blame] | 562 | pump = 0x01; |
| 563 | else |
| 564 | pump = 0x02; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 565 | |
| 566 | /* Determine the N/A dividers for the requested lband freq (in kHz). */ |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 567 | /* Note: the reference divider R=10, frequency is in KHz, |
| 568 | * XTAL is in Hz */ |
| 569 | ndiv = (((p->frequency * vco_div * 10) / |
| 570 | (2 * XTAL / 1000)) / 32) & 0x1ff; |
| 571 | adiv = (((p->frequency * vco_div * 10) / |
| 572 | (2 * XTAL / 1000)) % 32) & 0x1f; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 573 | |
Steven Toth | 9b5a4a6 | 2006-10-02 21:35:40 -0300 | [diff] [blame] | 574 | if (adiv == 0 && ndiv > 0) |
| 575 | ndiv--; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 576 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 577 | /* control bits 11, refdiv 11, charge pump polarity 1, |
| 578 | * charge pump current, ndiv, adiv */ |
| 579 | state->pllarg = (3 << 19) | (3 << 17) | (1 << 16) | |
| 580 | (pump << 14) | (ndiv << 5) | adiv; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | /* |
| 586 | * Tuner data is 21 bits long, must be left-aligned in data. |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 587 | * Tuner cx24109 is written through a dedicated 3wire interface |
| 588 | * on the demod chip. |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 589 | */ |
Mauro Carvalho Chehab | 31b4f32 | 2011-12-22 17:44:43 -0300 | [diff] [blame] | 590 | static int cx24123_pll_writereg(struct dvb_frontend *fe, u32 data) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 591 | { |
| 592 | struct cx24123_state *state = fe->demodulator_priv; |
Steven Toth | 0144f314 | 2006-01-09 15:25:22 -0200 | [diff] [blame] | 593 | unsigned long timeout; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 594 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 595 | dprintk("pll writereg called, data=0x%08x\n", data); |
Mauro Carvalho Chehab | caf970e | 2006-04-13 11:29:13 -0300 | [diff] [blame] | 596 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 597 | /* align the 21 bytes into to bit23 boundary */ |
| 598 | data = data << 3; |
| 599 | |
| 600 | /* Reset the demod pll word length to 0x15 bits */ |
| 601 | cx24123_writereg(state, 0x21, 0x15); |
| 602 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 603 | /* write the msb 8 bits, wait for the send to be completed */ |
Steven Toth | 0144f314 | 2006-01-09 15:25:22 -0200 | [diff] [blame] | 604 | timeout = jiffies + msecs_to_jiffies(40); |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 605 | cx24123_writereg(state, 0x22, (data >> 16) & 0xff); |
Steven Toth | 0144f314 | 2006-01-09 15:25:22 -0200 | [diff] [blame] | 606 | while ((cx24123_readreg(state, 0x20) & 0x40) == 0) { |
| 607 | if (time_after(jiffies, timeout)) { |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 608 | err("%s: demodulator is not responding, "\ |
| 609 | "possibly hung, aborting.\n", __func__); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 610 | return -EREMOTEIO; |
| 611 | } |
Steven Toth | 0144f314 | 2006-01-09 15:25:22 -0200 | [diff] [blame] | 612 | msleep(10); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 613 | } |
| 614 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 615 | /* send another 8 bytes, wait for the send to be completed */ |
Steven Toth | 0144f314 | 2006-01-09 15:25:22 -0200 | [diff] [blame] | 616 | timeout = jiffies + msecs_to_jiffies(40); |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 617 | cx24123_writereg(state, 0x22, (data >> 8) & 0xff); |
Steven Toth | 0144f314 | 2006-01-09 15:25:22 -0200 | [diff] [blame] | 618 | while ((cx24123_readreg(state, 0x20) & 0x40) == 0) { |
| 619 | if (time_after(jiffies, timeout)) { |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 620 | err("%s: demodulator is not responding, "\ |
| 621 | "possibly hung, aborting.\n", __func__); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 622 | return -EREMOTEIO; |
| 623 | } |
Steven Toth | 0144f314 | 2006-01-09 15:25:22 -0200 | [diff] [blame] | 624 | msleep(10); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 625 | } |
| 626 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 627 | /* send the lower 5 bits of this byte, padded with 3 LBB, |
| 628 | * wait for the send to be completed */ |
Steven Toth | 0144f314 | 2006-01-09 15:25:22 -0200 | [diff] [blame] | 629 | timeout = jiffies + msecs_to_jiffies(40); |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 630 | cx24123_writereg(state, 0x22, (data) & 0xff); |
Steven Toth | 0144f314 | 2006-01-09 15:25:22 -0200 | [diff] [blame] | 631 | while ((cx24123_readreg(state, 0x20) & 0x80)) { |
| 632 | if (time_after(jiffies, timeout)) { |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 633 | err("%s: demodulator is not responding," \ |
| 634 | "possibly hung, aborting.\n", __func__); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 635 | return -EREMOTEIO; |
| 636 | } |
Steven Toth | 0144f314 | 2006-01-09 15:25:22 -0200 | [diff] [blame] | 637 | msleep(10); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /* Trigger the demod to configure the tuner */ |
| 641 | cx24123_writereg(state, 0x20, cx24123_readreg(state, 0x20) | 2); |
| 642 | cx24123_writereg(state, 0x20, cx24123_readreg(state, 0x20) & 0xfd); |
| 643 | |
| 644 | return 0; |
| 645 | } |
| 646 | |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 647 | static int cx24123_pll_tune(struct dvb_frontend *fe) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 648 | { |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 649 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 650 | struct cx24123_state *state = fe->demodulator_priv; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 651 | u8 val; |
| 652 | |
| 653 | dprintk("frequency=%i\n", p->frequency); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 654 | |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 655 | if (cx24123_pll_calculate(fe) != 0) { |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 656 | err("%s: cx24123_pll_calcutate failed\n", __func__); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 657 | return -EINVAL; |
| 658 | } |
| 659 | |
| 660 | /* Write the new VCO/VGA */ |
Mauro Carvalho Chehab | 31b4f32 | 2011-12-22 17:44:43 -0300 | [diff] [blame] | 661 | cx24123_pll_writereg(fe, state->VCAarg); |
| 662 | cx24123_pll_writereg(fe, state->VGAarg); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 663 | |
| 664 | /* Write the new bandselect and pll args */ |
Mauro Carvalho Chehab | 31b4f32 | 2011-12-22 17:44:43 -0300 | [diff] [blame] | 665 | cx24123_pll_writereg(fe, state->bandselectarg); |
| 666 | cx24123_pll_writereg(fe, state->pllarg); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 667 | |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 668 | /* set the FILTUNE voltage */ |
| 669 | val = cx24123_readreg(state, 0x28) & ~0x3; |
| 670 | cx24123_writereg(state, 0x27, state->FILTune >> 2); |
| 671 | cx24123_writereg(state, 0x28, val | (state->FILTune & 0x3)); |
| 672 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 673 | dprintk("pll tune VCA=%d, band=%d, pll=%d\n", state->VCAarg, |
| 674 | state->bandselectarg, state->pllarg); |
Mauro Carvalho Chehab | caf970e | 2006-04-13 11:29:13 -0300 | [diff] [blame] | 675 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 676 | return 0; |
| 677 | } |
| 678 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 679 | |
| 680 | /* |
| 681 | * 0x23: |
| 682 | * [7:7] = BTI enabled |
| 683 | * [6:6] = I2C repeater enabled |
| 684 | * [5:5] = I2C repeater start |
| 685 | * [0:0] = BTI start |
| 686 | */ |
| 687 | |
| 688 | /* mode == 1 -> i2c-repeater, 0 -> bti */ |
| 689 | static int cx24123_repeater_mode(struct cx24123_state *state, u8 mode, u8 start) |
| 690 | { |
| 691 | u8 r = cx24123_readreg(state, 0x23) & 0x1e; |
| 692 | if (mode) |
| 693 | r |= (1 << 6) | (start << 5); |
| 694 | else |
| 695 | r |= (1 << 7) | (start); |
| 696 | return cx24123_writereg(state, 0x23, r); |
| 697 | } |
| 698 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 699 | static int cx24123_initfe(struct dvb_frontend *fe) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 700 | { |
| 701 | struct cx24123_state *state = fe->demodulator_priv; |
| 702 | int i; |
| 703 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 704 | dprintk("init frontend\n"); |
Mauro Carvalho Chehab | caf970e | 2006-04-13 11:29:13 -0300 | [diff] [blame] | 705 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 706 | /* Configure the demod to a good set of defaults */ |
Ahmed S. Darwish | 0496daa7 | 2007-02-14 22:57:42 -0200 | [diff] [blame] | 707 | for (i = 0; i < ARRAY_SIZE(cx24123_regdata); i++) |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 708 | cx24123_writereg(state, cx24123_regdata[i].reg, |
| 709 | cx24123_regdata[i].data); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 710 | |
Yeasah Pell | ef76856 | 2006-09-26 12:30:14 -0300 | [diff] [blame] | 711 | /* Set the LNB polarity */ |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 712 | if (state->config->lnb_polarity) |
| 713 | cx24123_writereg(state, 0x32, |
| 714 | cx24123_readreg(state, 0x32) | 0x02); |
Yeasah Pell | ef76856 | 2006-09-26 12:30:14 -0300 | [diff] [blame] | 715 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 716 | if (state->config->dont_use_pll) |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 717 | cx24123_repeater_mode(state, 1, 0); |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 718 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 719 | return 0; |
| 720 | } |
| 721 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 722 | static int cx24123_set_voltage(struct dvb_frontend *fe, |
| 723 | fe_sec_voltage_t voltage) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 724 | { |
| 725 | struct cx24123_state *state = fe->demodulator_priv; |
| 726 | u8 val; |
| 727 | |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 728 | val = cx24123_readreg(state, 0x29) & ~0x40; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 729 | |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 730 | switch (voltage) { |
| 731 | case SEC_VOLTAGE_13: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 732 | dprintk("setting voltage 13V\n"); |
Saqeb Akhter | ccd214b | 2006-06-29 20:29:29 -0300 | [diff] [blame] | 733 | return cx24123_writereg(state, 0x29, val & 0x7f); |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 734 | case SEC_VOLTAGE_18: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 735 | dprintk("setting voltage 18V\n"); |
Saqeb Akhter | ccd214b | 2006-06-29 20:29:29 -0300 | [diff] [blame] | 736 | return cx24123_writereg(state, 0x29, val | 0x80); |
Yeasah Pell | ef76856 | 2006-09-26 12:30:14 -0300 | [diff] [blame] | 737 | case SEC_VOLTAGE_OFF: |
| 738 | /* already handled in cx88-dvb */ |
| 739 | return 0; |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 740 | default: |
| 741 | return -EINVAL; |
Joe Perches | 2028c71 | 2013-10-08 20:29:08 -0300 | [diff] [blame] | 742 | } |
Vadim Catana | 1c956a3 | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 743 | |
| 744 | return 0; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 745 | } |
| 746 | |
Yeasah Pell | dce1dfc | 2006-04-13 11:40:59 -0300 | [diff] [blame] | 747 | /* wait for diseqc queue to become ready (or timeout) */ |
| 748 | static void cx24123_wait_for_diseqc(struct cx24123_state *state) |
| 749 | { |
| 750 | unsigned long timeout = jiffies + msecs_to_jiffies(200); |
| 751 | while (!(cx24123_readreg(state, 0x29) & 0x40)) { |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 752 | if (time_after(jiffies, timeout)) { |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 753 | err("%s: diseqc queue not ready, " \ |
| 754 | "command may be lost.\n", __func__); |
Yeasah Pell | dce1dfc | 2006-04-13 11:40:59 -0300 | [diff] [blame] | 755 | break; |
| 756 | } |
| 757 | msleep(10); |
| 758 | } |
| 759 | } |
| 760 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 761 | static int cx24123_send_diseqc_msg(struct dvb_frontend *fe, |
| 762 | struct dvb_diseqc_master_cmd *cmd) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 763 | { |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 764 | struct cx24123_state *state = fe->demodulator_priv; |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 765 | int i, val, tone; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 766 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 767 | dprintk("\n"); |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 768 | |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 769 | /* stop continuous tone if enabled */ |
| 770 | tone = cx24123_readreg(state, 0x29); |
| 771 | if (tone & 0x10) |
| 772 | cx24123_writereg(state, 0x29, tone & ~0x50); |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 773 | |
Yeasah Pell | dce1dfc | 2006-04-13 11:40:59 -0300 | [diff] [blame] | 774 | /* wait for diseqc queue ready */ |
| 775 | cx24123_wait_for_diseqc(state); |
| 776 | |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 777 | /* select tone mode */ |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 778 | cx24123_writereg(state, 0x2a, cx24123_readreg(state, 0x2a) & 0xfb); |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 779 | |
| 780 | for (i = 0; i < cmd->msg_len; i++) |
| 781 | cx24123_writereg(state, 0x2C + i, cmd->msg[i]); |
| 782 | |
| 783 | val = cx24123_readreg(state, 0x29); |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 784 | cx24123_writereg(state, 0x29, ((val & 0x90) | 0x40) | |
| 785 | ((cmd->msg_len-3) & 3)); |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 786 | |
Yeasah Pell | dce1dfc | 2006-04-13 11:40:59 -0300 | [diff] [blame] | 787 | /* wait for diseqc message to finish sending */ |
| 788 | cx24123_wait_for_diseqc(state); |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 789 | |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 790 | /* restart continuous tone if enabled */ |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 791 | if (tone & 0x10) |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 792 | cx24123_writereg(state, 0x29, tone & ~0x40); |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 793 | |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 794 | return 0; |
| 795 | } |
| 796 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 797 | static int cx24123_diseqc_send_burst(struct dvb_frontend *fe, |
| 798 | fe_sec_mini_cmd_t burst) |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 799 | { |
| 800 | struct cx24123_state *state = fe->demodulator_priv; |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 801 | int val, tone; |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 802 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 803 | dprintk("\n"); |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 804 | |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 805 | /* stop continuous tone if enabled */ |
| 806 | tone = cx24123_readreg(state, 0x29); |
| 807 | if (tone & 0x10) |
| 808 | cx24123_writereg(state, 0x29, tone & ~0x50); |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 809 | |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 810 | /* wait for diseqc queue ready */ |
Yeasah Pell | dce1dfc | 2006-04-13 11:40:59 -0300 | [diff] [blame] | 811 | cx24123_wait_for_diseqc(state); |
| 812 | |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 813 | /* select tone mode */ |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 814 | cx24123_writereg(state, 0x2a, cx24123_readreg(state, 0x2a) | 0x4); |
| 815 | msleep(30); |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 816 | val = cx24123_readreg(state, 0x29); |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 817 | if (burst == SEC_MINI_A) |
| 818 | cx24123_writereg(state, 0x29, ((val & 0x90) | 0x40 | 0x00)); |
| 819 | else if (burst == SEC_MINI_B) |
| 820 | cx24123_writereg(state, 0x29, ((val & 0x90) | 0x40 | 0x08)); |
| 821 | else |
| 822 | return -EINVAL; |
| 823 | |
Yeasah Pell | dce1dfc | 2006-04-13 11:40:59 -0300 | [diff] [blame] | 824 | cx24123_wait_for_diseqc(state); |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 825 | cx24123_writereg(state, 0x2a, cx24123_readreg(state, 0x2a) & 0xfb); |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 826 | |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 827 | /* restart continuous tone if enabled */ |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 828 | if (tone & 0x10) |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 829 | cx24123_writereg(state, 0x29, tone & ~0x40); |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 830 | |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 831 | return 0; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 832 | } |
| 833 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 834 | static int cx24123_read_status(struct dvb_frontend *fe, fe_status_t *status) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 835 | { |
| 836 | struct cx24123_state *state = fe->demodulator_priv; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 837 | int sync = cx24123_readreg(state, 0x14); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 838 | |
| 839 | *status = 0; |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 840 | if (state->config->dont_use_pll) { |
| 841 | u32 tun_status = 0; |
| 842 | if (fe->ops.tuner_ops.get_status) |
| 843 | fe->ops.tuner_ops.get_status(fe, &tun_status); |
| 844 | if (tun_status & TUNER_STATUS_LOCKED) |
| 845 | *status |= FE_HAS_SIGNAL; |
| 846 | } else { |
| 847 | int lock = cx24123_readreg(state, 0x20); |
| 848 | if (lock & 0x01) |
| 849 | *status |= FE_HAS_SIGNAL; |
| 850 | } |
| 851 | |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 852 | if (sync & 0x02) |
Mauro Carvalho Chehab | d93f886 | 2006-08-06 17:03:50 -0300 | [diff] [blame] | 853 | *status |= FE_HAS_CARRIER; /* Phase locked */ |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 854 | if (sync & 0x04) |
| 855 | *status |= FE_HAS_VITERBI; |
Mauro Carvalho Chehab | d93f886 | 2006-08-06 17:03:50 -0300 | [diff] [blame] | 856 | |
| 857 | /* Reed-Solomon Status */ |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 858 | if (sync & 0x08) |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 859 | *status |= FE_HAS_SYNC; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 860 | if (sync & 0x80) |
Mauro Carvalho Chehab | d93f886 | 2006-08-06 17:03:50 -0300 | [diff] [blame] | 861 | *status |= FE_HAS_LOCK; /*Full Sync */ |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | /* |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 867 | * Configured to return the measurement of errors in blocks, |
| 868 | * because no UCBLOCKS value is available, so this value doubles up |
| 869 | * to satisfy both measurements. |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 870 | */ |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 871 | static int cx24123_read_ber(struct dvb_frontend *fe, u32 *ber) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 872 | { |
| 873 | struct cx24123_state *state = fe->demodulator_priv; |
| 874 | |
Yeasah Pell | 18c053b | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 875 | /* The true bit error rate is this value divided by |
| 876 | the window size (set as 256 * 255) */ |
| 877 | *ber = ((cx24123_readreg(state, 0x1c) & 0x3f) << 16) | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 878 | (cx24123_readreg(state, 0x1d) << 8 | |
Yeasah Pell | 18c053b | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 879 | cx24123_readreg(state, 0x1e)); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 880 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 881 | dprintk("BER = %d\n", *ber); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 882 | |
| 883 | return 0; |
| 884 | } |
| 885 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 886 | static int cx24123_read_signal_strength(struct dvb_frontend *fe, |
| 887 | u16 *signal_strength) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 888 | { |
| 889 | struct cx24123_state *state = fe->demodulator_priv; |
Mauro Carvalho Chehab | d93f886 | 2006-08-06 17:03:50 -0300 | [diff] [blame] | 890 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 891 | /* larger = better */ |
| 892 | *signal_strength = cx24123_readreg(state, 0x3b) << 8; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 893 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 894 | dprintk("Signal strength = %d\n", *signal_strength); |
Mauro Carvalho Chehab | caf970e | 2006-04-13 11:29:13 -0300 | [diff] [blame] | 895 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 896 | return 0; |
| 897 | } |
| 898 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 899 | static int cx24123_read_snr(struct dvb_frontend *fe, u16 *snr) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 900 | { |
| 901 | struct cx24123_state *state = fe->demodulator_priv; |
Yeasah Pell | 18c053b | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 902 | |
| 903 | /* Inverted raw Es/N0 count, totally bogus but better than the |
| 904 | BER threshold. */ |
| 905 | *snr = 65535 - (((u16)cx24123_readreg(state, 0x18) << 8) | |
| 906 | (u16)cx24123_readreg(state, 0x19)); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 907 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 908 | dprintk("read S/N index = %d\n", *snr); |
Mauro Carvalho Chehab | caf970e | 2006-04-13 11:29:13 -0300 | [diff] [blame] | 909 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 910 | return 0; |
| 911 | } |
| 912 | |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 913 | static int cx24123_set_frontend(struct dvb_frontend *fe) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 914 | { |
| 915 | struct cx24123_state *state = fe->demodulator_priv; |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 916 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 917 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 918 | dprintk("\n"); |
Mauro Carvalho Chehab | caf970e | 2006-04-13 11:29:13 -0300 | [diff] [blame] | 919 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 920 | if (state->config->set_ts_params) |
| 921 | state->config->set_ts_params(fe, 0); |
| 922 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 923 | state->currentfreq = p->frequency; |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 924 | state->currentsymbolrate = p->symbol_rate; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 925 | |
| 926 | cx24123_set_inversion(state, p->inversion); |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 927 | cx24123_set_fec(state, p->fec_inner); |
| 928 | cx24123_set_symbolrate(state, p->symbol_rate); |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 929 | |
| 930 | if (!state->config->dont_use_pll) |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 931 | cx24123_pll_tune(fe); |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 932 | else if (fe->ops.tuner_ops.set_params) |
Mauro Carvalho Chehab | 14d24d1 | 2011-12-24 12:24:33 -0300 | [diff] [blame] | 933 | fe->ops.tuner_ops.set_params(fe); |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 934 | else |
| 935 | err("it seems I don't have a tuner..."); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 936 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 937 | /* Enable automatic acquisition and reset cycle */ |
Johannes Stezenbach | e3b152b | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 938 | cx24123_writereg(state, 0x03, (cx24123_readreg(state, 0x03) | 0x07)); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 939 | cx24123_writereg(state, 0x00, 0x10); |
| 940 | cx24123_writereg(state, 0x00, 0); |
| 941 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 942 | if (state->config->agc_callback) |
| 943 | state->config->agc_callback(fe); |
| 944 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 945 | return 0; |
| 946 | } |
| 947 | |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 948 | static int cx24123_get_frontend(struct dvb_frontend *fe) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 949 | { |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 950 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 951 | struct cx24123_state *state = fe->demodulator_priv; |
| 952 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 953 | dprintk("\n"); |
Mauro Carvalho Chehab | caf970e | 2006-04-13 11:29:13 -0300 | [diff] [blame] | 954 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 955 | if (cx24123_get_inversion(state, &p->inversion) != 0) { |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 956 | err("%s: Failed to get inversion status\n", __func__); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 957 | return -EREMOTEIO; |
| 958 | } |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 959 | if (cx24123_get_fec(state, &p->fec_inner) != 0) { |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 960 | err("%s: Failed to get fec status\n", __func__); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 961 | return -EREMOTEIO; |
| 962 | } |
| 963 | p->frequency = state->currentfreq; |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 964 | p->symbol_rate = state->currentsymbolrate; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 965 | |
| 966 | return 0; |
| 967 | } |
| 968 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 969 | static int cx24123_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 970 | { |
| 971 | struct cx24123_state *state = fe->demodulator_priv; |
| 972 | u8 val; |
| 973 | |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 974 | /* wait for diseqc queue ready */ |
| 975 | cx24123_wait_for_diseqc(state); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 976 | |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 977 | val = cx24123_readreg(state, 0x29) & ~0x40; |
Vadim Catana | 1c956a3 | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 978 | |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 979 | switch (tone) { |
| 980 | case SEC_TONE_ON: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 981 | dprintk("setting tone on\n"); |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 982 | return cx24123_writereg(state, 0x29, val | 0x10); |
| 983 | case SEC_TONE_OFF: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 984 | dprintk("setting tone off\n"); |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 985 | return cx24123_writereg(state, 0x29, val & 0xef); |
| 986 | default: |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 987 | err("CASE reached default with tone=%d\n", tone); |
Andrew de Quincey | cd20ca9 | 2006-05-12 20:31:51 -0300 | [diff] [blame] | 988 | return -EINVAL; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 989 | } |
Vadim Catana | 1c956a3 | 2006-01-09 15:25:08 -0200 | [diff] [blame] | 990 | |
| 991 | return 0; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 992 | } |
| 993 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 994 | static int cx24123_tune(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | 7e07222 | 2011-12-26 17:48:33 -0300 | [diff] [blame] | 995 | bool re_tune, |
Yeasah Pell | 174ff21 | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 996 | unsigned int mode_flags, |
Mauro Carvalho Chehab | 3ea9661 | 2007-07-16 09:27:20 -0300 | [diff] [blame] | 997 | unsigned int *delay, |
Yeasah Pell | 174ff21 | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 998 | fe_status_t *status) |
| 999 | { |
| 1000 | int retval = 0; |
| 1001 | |
Mauro Carvalho Chehab | 7e07222 | 2011-12-26 17:48:33 -0300 | [diff] [blame] | 1002 | if (re_tune) |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 1003 | retval = cx24123_set_frontend(fe); |
Yeasah Pell | 174ff21 | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 1004 | |
| 1005 | if (!(mode_flags & FE_TUNE_MODE_ONESHOT)) |
| 1006 | cx24123_read_status(fe, status); |
| 1007 | *delay = HZ/10; |
| 1008 | |
| 1009 | return retval; |
| 1010 | } |
| 1011 | |
| 1012 | static int cx24123_get_algo(struct dvb_frontend *fe) |
| 1013 | { |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 1014 | return 1; /* FE_ALGO_HW */ |
Yeasah Pell | 174ff21 | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 1015 | } |
| 1016 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 1017 | static void cx24123_release(struct dvb_frontend *fe) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1018 | { |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 1019 | struct cx24123_state *state = fe->demodulator_priv; |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 1020 | dprintk("\n"); |
| 1021 | i2c_del_adapter(&state->tuner_i2c_adapter); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1022 | kfree(state); |
| 1023 | } |
| 1024 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 1025 | static int cx24123_tuner_i2c_tuner_xfer(struct i2c_adapter *i2c_adap, |
| 1026 | struct i2c_msg msg[], int num) |
| 1027 | { |
| 1028 | struct cx24123_state *state = i2c_get_adapdata(i2c_adap); |
| 1029 | /* this repeater closes after the first stop */ |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 1030 | cx24123_repeater_mode(state, 1, 1); |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 1031 | return i2c_transfer(state->i2c, msg, num); |
| 1032 | } |
| 1033 | |
| 1034 | static u32 cx24123_tuner_i2c_func(struct i2c_adapter *adapter) |
| 1035 | { |
| 1036 | return I2C_FUNC_I2C; |
| 1037 | } |
| 1038 | |
| 1039 | static struct i2c_algorithm cx24123_tuner_i2c_algo = { |
| 1040 | .master_xfer = cx24123_tuner_i2c_tuner_xfer, |
| 1041 | .functionality = cx24123_tuner_i2c_func, |
| 1042 | }; |
| 1043 | |
| 1044 | struct i2c_adapter * |
| 1045 | cx24123_get_tuner_i2c_adapter(struct dvb_frontend *fe) |
| 1046 | { |
| 1047 | struct cx24123_state *state = fe->demodulator_priv; |
| 1048 | return &state->tuner_i2c_adapter; |
| 1049 | } |
| 1050 | EXPORT_SYMBOL(cx24123_get_tuner_i2c_adapter); |
| 1051 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1052 | static struct dvb_frontend_ops cx24123_ops; |
| 1053 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 1054 | struct dvb_frontend *cx24123_attach(const struct cx24123_config *config, |
| 1055 | struct i2c_adapter *i2c) |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1056 | { |
Matthias Schwarzott | 8420fa7 | 2009-02-23 12:26:38 -0300 | [diff] [blame] | 1057 | /* allocate memory for the internal state */ |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 1058 | struct cx24123_state *state = |
| 1059 | kzalloc(sizeof(struct cx24123_state), GFP_KERNEL); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1060 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 1061 | dprintk("\n"); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1062 | if (state == NULL) { |
Matthias Schwarzott | 8420fa7 | 2009-02-23 12:26:38 -0300 | [diff] [blame] | 1063 | err("Unable to kzalloc\n"); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1064 | goto error; |
| 1065 | } |
| 1066 | |
| 1067 | /* setup the state */ |
| 1068 | state->config = config; |
| 1069 | state->i2c = i2c; |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1070 | |
| 1071 | /* check if the demod is there */ |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 1072 | state->demod_rev = cx24123_readreg(state, 0x00); |
| 1073 | switch (state->demod_rev) { |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 1074 | case 0xe1: |
| 1075 | info("detected CX24123C\n"); |
| 1076 | break; |
| 1077 | case 0xd1: |
| 1078 | info("detected CX24123\n"); |
| 1079 | break; |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 1080 | default: |
| 1081 | err("wrong demod revision: %x\n", state->demod_rev); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1082 | goto error; |
| 1083 | } |
| 1084 | |
| 1085 | /* create dvb_frontend */ |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 1086 | memcpy(&state->frontend.ops, &cx24123_ops, |
| 1087 | sizeof(struct dvb_frontend_ops)); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1088 | state->frontend.demodulator_priv = state; |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 1089 | |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 1090 | /* create tuner i2c adapter */ |
| 1091 | if (config->dont_use_pll) |
| 1092 | cx24123_repeater_mode(state, 1, 0); |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 1093 | |
Jean Delvare | 1d43401 | 2008-09-03 17:12:23 -0300 | [diff] [blame] | 1094 | strlcpy(state->tuner_i2c_adapter.name, "CX24123 tuner I2C bus", |
| 1095 | sizeof(state->tuner_i2c_adapter.name)); |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 1096 | state->tuner_i2c_adapter.algo = &cx24123_tuner_i2c_algo; |
| 1097 | state->tuner_i2c_adapter.algo_data = NULL; |
| 1098 | i2c_set_adapdata(&state->tuner_i2c_adapter, state); |
| 1099 | if (i2c_add_adapter(&state->tuner_i2c_adapter) < 0) { |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 1100 | err("tuner i2c bus could not be initialized\n"); |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 1101 | goto error; |
| 1102 | } |
| 1103 | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1104 | return &state->frontend; |
| 1105 | |
| 1106 | error: |
| 1107 | kfree(state); |
| 1108 | |
| 1109 | return NULL; |
| 1110 | } |
Steven Toth | 93504ab | 2008-10-16 20:28:32 -0300 | [diff] [blame] | 1111 | EXPORT_SYMBOL(cx24123_attach); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1112 | |
| 1113 | static struct dvb_frontend_ops cx24123_ops = { |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 1114 | .delsys = { SYS_DVBS }, |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1115 | .info = { |
| 1116 | .name = "Conexant CX24123/CX24109", |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1117 | .frequency_min = 950000, |
| 1118 | .frequency_max = 2150000, |
| 1119 | .frequency_stepsize = 1011, /* kHz for QPSK frontends */ |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 1120 | .frequency_tolerance = 5000, |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1121 | .symbol_rate_min = 1000000, |
| 1122 | .symbol_rate_max = 45000000, |
| 1123 | .caps = FE_CAN_INVERSION_AUTO | |
| 1124 | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | |
Yeasah Pell | 0e4558a | 2006-04-13 17:24:13 -0300 | [diff] [blame] | 1125 | FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 | |
| 1126 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1127 | FE_CAN_QPSK | FE_CAN_RECOVER |
| 1128 | }, |
| 1129 | |
| 1130 | .release = cx24123_release, |
| 1131 | |
| 1132 | .init = cx24123_initfe, |
Mauro Carvalho Chehab | a73efc0 | 2011-12-22 17:54:00 -0300 | [diff] [blame] | 1133 | .set_frontend = cx24123_set_frontend, |
| 1134 | .get_frontend = cx24123_get_frontend, |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1135 | .read_status = cx24123_read_status, |
| 1136 | .read_ber = cx24123_read_ber, |
| 1137 | .read_signal_strength = cx24123_read_signal_strength, |
| 1138 | .read_snr = cx24123_read_snr, |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1139 | .diseqc_send_master_cmd = cx24123_send_diseqc_msg, |
Vadim Catana | a74b51f | 2006-04-13 10:19:52 -0300 | [diff] [blame] | 1140 | .diseqc_send_burst = cx24123_diseqc_send_burst, |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1141 | .set_tone = cx24123_set_tone, |
| 1142 | .set_voltage = cx24123_set_voltage, |
Yeasah Pell | 174ff21 | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 1143 | .tune = cx24123_tune, |
| 1144 | .get_frontend_algo = cx24123_get_algo, |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1145 | }; |
| 1146 | |
Patrick Boettcher | ca06fa7 | 2008-03-29 21:01:12 -0300 | [diff] [blame] | 1147 | MODULE_DESCRIPTION("DVB Frontend module for Conexant " \ |
| 1148 | "CX24123/CX24109/CX24113 hardware"); |
Steve Toth | b79cb65 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1149 | MODULE_AUTHOR("Steven Toth"); |
| 1150 | MODULE_LICENSE("GPL"); |
| 1151 | |