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