Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75b697f7 authored by Julia Lawall's avatar Julia Lawall Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (12483): Use DIV_ROUND_CLOSEST

The kernel.h macro DIV_ROUND_CLOSEST performs the computation (x + d/2)/d
but is perhaps more readable.

The semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/

)

// <smpl>
@haskernel@
@@

@depends on haskernel@
expression x,__divisor;
@@

- (((x) + ((__divisor) / 2)) / (__divisor))
+ DIV_ROUND_CLOSEST(x,__divisor)
// </smpl>

Signed-off-by: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 166987c6
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -883,7 +883,7 @@ static void dib7000p_spur_protect(struct dib7000p_state *state, u32 rf_khz, u32
	255, 255, 255, 255, 255, 255};
	255, 255, 255, 255, 255, 255};


	u32 xtal = state->cfg.bw->xtal_hz / 1000;
	u32 xtal = state->cfg.bw->xtal_hz / 1000;
	int f_rel = ( (rf_khz + xtal/2) / xtal) * xtal - rf_khz;
	int f_rel = DIV_ROUND_CLOSEST(rf_khz, xtal) * xtal - rf_khz;
	int k;
	int k;
	int coef_re[8],coef_im[8];
	int coef_re[8],coef_im[8];
	int bw_khz = bw;
	int bw_khz = bw;
+3 −1
Original line number Original line Diff line number Diff line
@@ -367,7 +367,9 @@ static int stb6100_set_frequency(struct dvb_frontend *fe, u32 frequency)
	/* N(I) = floor(f(VCO) / (f(XTAL) * (PSD2 ? 2 : 1)))	*/
	/* N(I) = floor(f(VCO) / (f(XTAL) * (PSD2 ? 2 : 1)))	*/
	nint = fvco / (state->reference << psd2);
	nint = fvco / (state->reference << psd2);
	/* N(F) = round(f(VCO) / f(XTAL) * (PSD2 ? 2 : 1) - N(I)) * 2 ^ 9	*/
	/* N(F) = round(f(VCO) / f(XTAL) * (PSD2 ? 2 : 1) - N(I)) * 2 ^ 9	*/
	nfrac = (((fvco - (nint * state->reference << psd2)) << (9 - psd2)) + state->reference / 2) / state->reference;
	nfrac = DIV_ROUND_CLOSEST((fvco - (nint * state->reference << psd2))
					 << (9 - psd2),
				  state->reference);
	dprintk(verbose, FE_DEBUG, 1,
	dprintk(verbose, FE_DEBUG, 1,
		"frequency = %u, srate = %u, g = %u, odiv = %u, psd2 = %u, fxtal = %u, osm = %u, fvco = %u, N(I) = %u, N(F) = %u",
		"frequency = %u, srate = %u, g = %u, odiv = %u, psd2 = %u, fxtal = %u, osm = %u, fvco = %u, N(I) = %u, N(F) = %u",
		frequency, srate, (unsigned int)g, (unsigned int)odiv,
		frequency, srate, (unsigned int)g, (unsigned int)odiv,
+1 −1
Original line number Original line Diff line number Diff line
@@ -176,7 +176,7 @@ static int tda10021_set_symbolrate (struct tda10021_state* state, u32 symbolrate
	tmp =  ((symbolrate << 4) % FIN) << 8;
	tmp =  ((symbolrate << 4) % FIN) << 8;
	ratio = (ratio << 8) + tmp / FIN;
	ratio = (ratio << 8) + tmp / FIN;
	tmp = (tmp % FIN) << 8;
	tmp = (tmp % FIN) << 8;
	ratio = (ratio << 8) + (tmp + FIN/2) / FIN;
	ratio = (ratio << 8) + DIV_ROUND_CLOSEST(tmp, FIN);


	BDR = ratio;
	BDR = ratio;
	BDRI = (((XIN << 5) / symbolrate) + 1) / 2;
	BDRI = (((XIN << 5) / symbolrate) + 1) / 2;
+1 −1
Original line number Original line Diff line number Diff line
@@ -165,7 +165,7 @@ static int ves1820_set_symbolrate(struct ves1820_state *state, u32 symbolrate)
	tmp = ((symbolrate << 4) % fin) << 8;
	tmp = ((symbolrate << 4) % fin) << 8;
	ratio = (ratio << 8) + tmp / fin;
	ratio = (ratio << 8) + tmp / fin;
	tmp = (tmp % fin) << 8;
	tmp = (tmp % fin) << 8;
	ratio = (ratio << 8) + (tmp + fin / 2) / fin;
	ratio = (ratio << 8) + DIV_ROUND_CLOSEST(tmp, fin);


	BDR = ratio;
	BDR = ratio;
	BDRI = (((state->config->xin << 5) / symbolrate) + 1) / 2;
	BDRI = (((state->config->xin << 5) / symbolrate) + 1) / 2;
+1 −1
Original line number Original line Diff line number Diff line
@@ -439,7 +439,7 @@ static inline u32 divide(u32 numerator, u32 denominator)
	if (denominator == 0)
	if (denominator == 0)
		return ~0;
		return ~0;


	return (numerator + denominator / 2) / denominator;
	return DIV_ROUND_CLOSEST(numerator, denominator);
}
}


/* LG Innotek TDTE-E001P (Infineon TUA6034) */
/* LG Innotek TDTE-E001P (Infineon TUA6034) */
Loading