Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] e4000: revise synthesizer calculation

Update synthesizer calculation to model I prefer nowadays. It is
mostly just renaming some variables to ones I think are most standard.
Also add 'schematic' of synthesizer following my current understanding.

Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Antti Palosaari and committed by
Mauro Carvalho Chehab
0e3a71c3 e4d131d3

+34 -16
+32 -14
drivers/media/tuners/e4000.c
··· 115 115 { 116 116 struct e4000 *s = fe->tuner_priv; 117 117 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 118 - int ret, i, sigma_delta; 119 - unsigned int pll_n, pll_f; 118 + int ret, i; 119 + unsigned int div_n, k, k_cw, div_out; 120 120 u64 f_vco; 121 121 u8 buf[5], i_data[4], q_data[4]; 122 122 ··· 129 129 if (ret) 130 130 goto err; 131 131 132 - /* PLL */ 132 + /* 133 + * Fractional-N synthesizer 134 + * 135 + * +----------------------------+ 136 + * v | 137 + * Fref +----+ +-------+ +------+ +---+ 138 + * ------> | PD | --> | VCO | ------> | /N.F | <-- | K | 139 + * +----+ +-------+ +------+ +---+ 140 + * | 141 + * | 142 + * v 143 + * +-------+ Fout 144 + * | /Rout | ------> 145 + * +-------+ 146 + */ 133 147 for (i = 0; i < ARRAY_SIZE(e4000_pll_lut); i++) { 134 148 if (c->frequency <= e4000_pll_lut[i].freq) 135 149 break; ··· 154 140 goto err; 155 141 } 156 142 157 - f_vco = 1ull * c->frequency * e4000_pll_lut[i].mul; 158 - pll_n = div_u64_rem(f_vco, s->clock, &pll_f); 159 - sigma_delta = div_u64(0x10000ULL * pll_f, s->clock); 160 - buf[0] = pll_n; 161 - buf[1] = (sigma_delta >> 0) & 0xff; 162 - buf[2] = (sigma_delta >> 8) & 0xff; 143 + #define F_REF s->clock 144 + div_out = e4000_pll_lut[i].div_out; 145 + f_vco = (u64) c->frequency * div_out; 146 + /* calculate PLL integer and fractional control word */ 147 + div_n = div_u64_rem(f_vco, F_REF, &k); 148 + k_cw = div_u64((u64) k * 0x10000, F_REF); 149 + 150 + dev_dbg(&s->client->dev, 151 + "frequency=%u f_vco=%llu F_REF=%u div_n=%u k=%u k_cw=%04x div_out=%u\n", 152 + c->frequency, f_vco, F_REF, div_n, k, k_cw, div_out); 153 + 154 + buf[0] = div_n; 155 + buf[1] = (k_cw >> 0) & 0xff; 156 + buf[2] = (k_cw >> 8) & 0xff; 163 157 buf[3] = 0x00; 164 - buf[4] = e4000_pll_lut[i].div; 165 - 166 - dev_dbg(&s->client->dev, "f_vco=%llu pll div=%d sigma_delta=%04x\n", 167 - f_vco, buf[0], sigma_delta); 168 - 158 + buf[4] = e4000_pll_lut[i].div_out_reg; 169 159 ret = regmap_bulk_write(s->regmap, 0x09, buf, 5); 170 160 if (ret) 171 161 goto err;
+2 -2
drivers/media/tuners/e4000_priv.h
··· 49 49 50 50 struct e4000_pll { 51 51 u32 freq; 52 - u8 div; 53 - u8 mul; 52 + u8 div_out_reg; 53 + u8 div_out; 54 54 }; 55 55 56 56 static const struct e4000_pll e4000_pll_lut[] = {