/* The @minsec conversion range argument controls the time frame in seconds which must be covered by the runtime conversion with the calculated mult and shift factors. This guarantees that no 64bit overflow happens when the input value of the conversion is multiplied with the calculated mult factor. Larger ranges may reduce the conversion accuracy by chosing smaller mult and shift factors.  */
void clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 minsec)
/* The @minsec conversion range argument controls the time frame in seconds which must be covered by the runtime conversion with the calculated mult and shift factors. This guarantees that no 64bit overflow happens when the input value of the conversion is multiplied with the calculated mult factor. Larger ranges may reduce the conversion accuracy by chosing smaller mult and shift factors.  */
void clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 minsec)
{
	u64 tmp;
	u32 sft, sftacc= 32;
	tmp = ((u64)minsec * from) >> 32;
	while (tmp) {
		tmp >>=1;
		sftacc--;
	}
	for (sft = 32; sft > 0; sft--) {
		tmp = (u64) to << sft;
		do_div(tmp, from);
		if ((tmp >> sftacc) == 0)
			break;
	}
	*mult = tmp;
	*shift = sft;
}