void get_dilated_time(struct task_struct * task,struct timeval* tv)
{
	s64 temp_past_physical_time;

	do_gettimeofday(tv);

	if(task->virt_start_time != 0){
		if (task->group_leader != task) { //use virtual time of the leader thread
                       	task = task->group_leader;
        }
		s64 now = timeval_to_ns(tv);
		s32 rem;
		s64 real_running_time;
		s64 dilated_running_time;
		//spin_lock(&task->dialation_lock);
		if(task->freeze_time == 0){
			real_running_time = now - task->virt_start_time;
		}
		else{
			real_running_time = task->freeze_time - task->virt_start_time;
		}
		//real_running_time = now - task->virt_start_time;
		//if (task->freeze_time != 0)
		//	temp_past_physical_time = task->past_physical_time + (now - task->freeze_time);
		//else
		temp_past_physical_time = task->past_physical_time;

		if (task->dilation_factor > 0) {
			dilated_running_time = div_s64_rem( (real_running_time - temp_past_physical_time)*1000 ,task->dilation_factor,&rem) + task->past_virtual_time;
			now = dilated_running_time + task->virt_start_time;
		}
		else if (task->dilation_factor < 0) {
			dilated_running_time = div_s64_rem( (real_running_time - temp_past_physical_time)*(task->dilation_factor*-1),1000,&rem) + task->past_virtual_time;
			now =  dilated_running_time + task->virt_start_time;
		}
		else {
			dilated_running_time = (real_running_time - temp_past_physical_time) + task->past_virtual_time;
			now = dilated_running_time + task->virt_start_time;
		}
		
		if(task->freeze_time == 0){
			task->past_physical_time = real_running_time;
			task->past_virtual_time = dilated_running_time;
		}
		//spin_unlock(&task->dialation_lock);
		*tv = ns_to_timeval(now);
	}

	return;

}
Exemple #2
0
struct timespec ns_to_timespec(const s64 nsec)
{
	struct timespec ts;
	s32 rem;

	if (!nsec)
		return (struct timespec) {0, 0};

	ts.tv_sec = div_s64_rem(nsec, NSEC_PER_SEC, &rem);
	if (unlikely(rem < 0)) {
		ts.tv_sec--;
		rem += NSEC_PER_SEC;
	}
	ts.tv_nsec = rem;

	return ts;
}


struct timeval ns_to_timeval(const s64 nsec)
{
	struct timespec ts = ns_to_timespec(nsec);
	struct timeval  tv;

	tv.tv_sec = ts.tv_sec;
	tv.tv_usec =  ts.tv_nsec / 1000;

	return tv;
}
Exemple #3
0
inline s64 ConvertPCR(s64 a)
{
	s32 ext;
	s64 b;

	b = div_s64_rem(a, 300 << 22, &ext);

	return (b << 31) | ext;

}
Exemple #4
0
inline s64 NegConvertPCR(s64 a)
{
	s32 ext;
	s64 b;

	b = -div_s64_rem(a, 300 << 22, &ext);

	if (ext != 0) {
		ext = (300 << 22) - ext;
		b -= 1;
	}
	return (b << 31) | ext;
}
Exemple #5
0
/**
 * time64_to_tm - converts the calendar time to local broken-down time
 *
 * @totalsecs	the number of seconds elapsed since 00:00:00 on January 1, 1970,
 *		Coordinated Universal Time (UTC).
 * @offset	offset seconds adding to totalsecs.
 * @result	pointer to struct tm variable to receive broken-down time
 */
void time64_to_tm(time64_t totalsecs, int offset, struct tm *result)
{
	long days, rem, y;
	int remainder;
	const unsigned short *ip;

	days = div_s64_rem(totalsecs, SECS_PER_DAY, &remainder);
	rem = remainder;
	rem += offset;
	while (rem < 0) {
		rem += SECS_PER_DAY;
		--days;
	}
	while (rem >= SECS_PER_DAY) {
		rem -= SECS_PER_DAY;
		++days;
	}

	result->tm_hour = rem / SECS_PER_HOUR;
	rem %= SECS_PER_HOUR;
	result->tm_min = rem / 60;
	result->tm_sec = rem % 60;

	/* January 1, 1970 was a Thursday. */
	result->tm_wday = (4 + days) % 7;
	if (result->tm_wday < 0)
		result->tm_wday += 7;

	y = 1970;

	while (days < 0 || days >= (__isleap(y) ? 366 : 365)) {
		/* Guess a corrected year, assuming 365 days per year. */
		long yg = y + math_div(days, 365);

		/* Adjust DAYS and Y to match the guessed year. */
		days -= (yg - y) * 365 + leaps_between(y, yg);
		y = yg;
	}

	result->tm_year = y - 1900;

	result->tm_yday = days;

	ip = __mon_yday[__isleap(y)];
	for (y = 11; days < ip[y]; y--)
		continue;
	days -= ip[y];

	result->tm_mon = y;
	result->tm_mday = days + 1;
}
Exemple #6
0
static int zopt2201_read_raw(struct iio_dev *indio_dev,
				struct iio_chan_spec const *chan,
				int *val, int *val2, long mask)
{
	struct zopt2201_data *data = iio_priv(indio_dev);
	u64 tmp;
	int ret;

	switch (mask) {
	case IIO_CHAN_INFO_RAW:
		ret = zopt2201_read(data, chan->address);
		if (ret < 0)
			return ret;
		*val = ret;
		return IIO_VAL_INT;
	case IIO_CHAN_INFO_PROCESSED:
		ret = zopt2201_read(data, ZOPT2201_UVB_DATA);
		if (ret < 0)
			return ret;
		*val = ret * 18 *
			(1 << (20 - zopt2201_resolution[data->res].bits)) /
			zopt2201_gain_uvb[data->gain].gain;
		return IIO_VAL_INT;
	case IIO_CHAN_INFO_SCALE:
		switch (chan->address) {
		case ZOPT2201_ALS_DATA:
			*val = zopt2201_gain_als[data->gain].scale;
			break;
		case ZOPT2201_UVB_DATA:
			*val = zopt2201_gain_uvb[data->gain].scale;
			break;
		default:
			return -EINVAL;
		}

		*val2 = 1000000;
		*val2 *= (1 << (zopt2201_resolution[data->res].bits - 13));
		tmp = div_s64(*val * 1000000ULL, *val2);
		*val = div_s64_rem(tmp, 1000000, val2);

		return IIO_VAL_INT_PLUS_MICRO;
	case IIO_CHAN_INFO_INT_TIME:
		*val = 0;
		*val2 = zopt2201_resolution[data->res].us;
		return IIO_VAL_INT_PLUS_MICRO;
	default:
		return -EINVAL;
	}
}
Exemple #7
0
static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{
	struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
	time64_t s1970;
	u32 seconds, days;
	int ret;

	mc13xxx_lock(priv->mc13xxx);

	/* disable alarm to prevent false triggering */
	ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCTODA, 0x1ffff);
	if (unlikely(ret))
		goto out;

	ret = mc13xxx_irq_ack(priv->mc13xxx, MC13XXX_IRQ_TODA);
	if (unlikely(ret))
		goto out;

	s1970 = rtc_tm_to_time64(&alarm->time);

	dev_dbg(dev, "%s: %s %lld\n", __func__, alarm->enabled ? "on" : "off",
			(long long)s1970);

	ret = mc13xxx_rtc_irq_enable_unlocked(dev, alarm->enabled,
			MC13XXX_IRQ_TODA);
	if (unlikely(ret))
		goto out;

	days = div_s64_rem(s1970, SEC_PER_DAY, &seconds);

	ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCDAYA, days);
	if (unlikely(ret))
		goto out;

	ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCTODA, seconds);

out:
	mc13xxx_unlock(priv->mc13xxx);

	return ret;
}
Exemple #8
0
/*
 * rtc_time64_to_tm - Converts time64_t to rtc_time.
 * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
 */
void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
{
	unsigned int month, year, secs;
	int days;

	/* time must be positive */
	days = div_s64_rem(time, 86400, &secs);

	/* day of the week, 1970-01-01 was a Thursday */
	tm->tm_wday = (days + 4) % 7;

	year = 1970 + days / 365;
	days -= (year - 1970) * 365
		+ LEAPS_THRU_END_OF(year - 1)
		- LEAPS_THRU_END_OF(1970 - 1);
	while (days < 0) {
		year -= 1;
		days += 365 + is_leap_year(year);
	}
	tm->tm_year = year - 1900;
	tm->tm_yday = days + 1;

	for (month = 0; month < 11; month++) {
		int newdays;

		newdays = days - rtc_month_days(month, year);
		if (newdays < 0)
			break;
		days = newdays;
	}
	tm->tm_mon = month;
	tm->tm_mday = days + 1;

	tm->tm_hour = secs / 3600;
	secs -= tm->tm_hour * 3600;
	tm->tm_min = secs / 60;
	tm->tm_sec = secs - tm->tm_min * 60;

	tm->tm_isdst = 0;
}
static int vco_set_rate(struct clk *c, unsigned long rate)
{
	s64 vco_clk_rate = rate;
	s32 rem;
	s64 refclk_cfg, frac_n_mode, ref_doubler_en_b;
	s64 ref_clk_to_pll, div_fbx1000, frac_n_value;
	s64 sdm_cfg0, sdm_cfg1, sdm_cfg2, sdm_cfg3;
	s64 gen_vco_clk, cal_cfg10, cal_cfg11;
	u32 res;
	int i, rc = 0;
	struct dsi_pll_vco_clk *vco = to_vco_clk(c);

	clk_prepare_enable(mdss_dsi_ahb_clk);

	/* Configure the Loop filter resistance */
	for (i = 0; i < vco->lpfr_lut_size; i++)
		if (vco_clk_rate <= vco->lpfr_lut[i].vco_rate)
			break;
	if (i == vco->lpfr_lut_size) {
		pr_err("%s: unable to get loop filter resistance. vco=%ld\n",
			__func__, rate);
		rc = -EINVAL;
		goto error;
	}
	res = vco->lpfr_lut[i].r;
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LPFR_CFG, res);

	/* Loop filter capacitance values : c1 and c2 */
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LPFC1_CFG, 0x70);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LPFC2_CFG, 0x15);

	div_s64_rem(vco_clk_rate, vco->ref_clk_rate, &rem);
	if (rem) {
		refclk_cfg = 0x1;
		frac_n_mode = 1;
		ref_doubler_en_b = 0;
	} else {
		refclk_cfg = 0x0;
		frac_n_mode = 0;
		ref_doubler_en_b = 1;
	}

	pr_debug("%s:refclk_cfg = %lld\n", __func__, refclk_cfg);

	ref_clk_to_pll = ((vco->ref_clk_rate * 2 * (refclk_cfg))
			  + (ref_doubler_en_b * vco->ref_clk_rate));
	div_fbx1000 = div_s64((vco_clk_rate * 1000), ref_clk_to_pll);

	div_s64_rem(div_fbx1000, 1000, &rem);
	frac_n_value = div_s64((rem * (1 << 16)), 1000);
	gen_vco_clk = div_s64(div_fbx1000 * ref_clk_to_pll, 1000);

	pr_debug("%s:ref_clk_to_pll = %lld\n", __func__, ref_clk_to_pll);
	pr_debug("%s:div_fb = %lld\n", __func__, div_fbx1000);
	pr_debug("%s:frac_n_value = %lld\n", __func__, frac_n_value);

	pr_debug("%s:Generated VCO Clock: %lld\n", __func__, gen_vco_clk);
	rem = 0;
	if (frac_n_mode) {
		sdm_cfg0 = (0x0 << 5);
		sdm_cfg0 |= (0x0 & 0x3f);
		sdm_cfg1 = (div_s64(div_fbx1000, 1000) & 0x3f) - 1;
		sdm_cfg3 = div_s64_rem(frac_n_value, 256, &rem);
		sdm_cfg2 = rem;
	} else {
		sdm_cfg0 = (0x1 << 5);
		sdm_cfg0 |= (div_s64(div_fbx1000, 1000) & 0x3f) - 1;
		sdm_cfg1 = (0x0 & 0x3f);
		sdm_cfg2 = 0;
		sdm_cfg3 = 0;
	}

	pr_debug("%s: sdm_cfg0=%lld\n", __func__, sdm_cfg0);
	pr_debug("%s: sdm_cfg1=%lld\n", __func__, sdm_cfg1);
	pr_debug("%s: sdm_cfg2=%lld\n", __func__, sdm_cfg2);
	pr_debug("%s: sdm_cfg3=%lld\n", __func__, sdm_cfg3);

	cal_cfg11 = div_s64_rem(gen_vco_clk, 256 * 1000000, &rem);
	cal_cfg10 = rem / 1000000;
	pr_debug("%s: cal_cfg10=%lld, cal_cfg11=%lld\n", __func__,
		cal_cfg10, cal_cfg11);

	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CHGPUMP_CFG, 0x02);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG3, 0x2b);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG4, 0x66);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG2, 0x05);

	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG1,
		(u32)(sdm_cfg1 & 0xff));
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG2,
		(u32)(sdm_cfg2 & 0xff));
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG3,
		(u32)(sdm_cfg3 & 0xff));
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG4, 0x00);

	/* Add hardware recommended delay for correct PLL configuration */
	udelay(1000);

	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_REFCLK_CFG,
		(u32)refclk_cfg);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_PWRGEN_CFG, 0x00);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_VCOLPF_CFG, 0x71);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG0,
		(u32)sdm_cfg0);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG0, 0x0a);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG6, 0x30);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG7, 0x00);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG8, 0x60);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG9, 0x00);
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG10,
		(u32)(cal_cfg10 & 0xff));
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG11,
		(u32)(cal_cfg11 & 0xff));
	DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_EFUSE_CFG, 0x20);

error:
	clk_disable_unprepare(mdss_dsi_ahb_clk);
	return rc;
}
static int mdss_dsi_phy_calc_param_phy_rev_2(struct dsi_phy_t_clk_param *t_clk,
		struct dsi_phy_timing *t_param)
{
	/* recommended fraction for PHY REV 2.0 */
	u32 const min_prepare_frac = 50;
	u32 const hs_exit_min_frac = 10;
	u32 const phy_timing_frac = 30;
	u32 const hs_zero_min_frac = 10;
	u32 const clk_zero_min_frac = 2;
	int tmp;
	int t_hs_prep_actual;
	int teot_clk_lane, teot_data_lane;
	u64 dividend;
	u64 temp, rc = 0;
	u64 multiplier = BIT(20);
	u64 temp_multiple;
	s64 mipi_min, mipi_max, mipi_max_tr, rec_min, rec_prog;
	s64 clk_prep_actual;
	s64 actual_intermediate;
	s32 actual_frac;
	s64 rec_temp1, rec_temp2, rec_temp3;

	/* clk_prepare calculations */
	dividend = ((t_param->clk_prepare.rec_max
			- t_param->clk_prepare.rec_min)
			* min_prepare_frac * multiplier);
	temp = roundup(div_s64(dividend, 100), multiplier);
	temp += (t_param->clk_prepare.rec_min * multiplier);
	t_param->clk_prepare.rec = div_s64(temp, multiplier);

	rc = mdss_dsi_phy_common_validate_and_set(&t_param->clk_prepare,
			"clk prepare");
	if (rc)
		goto error;

	/* clk_ prepare theoretical value*/
	temp_multiple = (8 * t_param->clk_prepare.program_value
			* t_clk->tlpx_numer_ns * multiplier);
	actual_intermediate = div_s64(temp_multiple, t_clk->bitclk_mbps);
	div_s64_rem(temp_multiple, t_clk->bitclk_mbps, &actual_frac);
	clk_prep_actual =
		div_s64((actual_intermediate + actual_frac), multiplier);

	pr_debug("CLK PREPARE: mipi_min=%d, max=%d, rec_min=%d, rec_max=%d",
			t_param->clk_prepare.mipi_min,
			t_param->clk_prepare.mipi_max,
			t_param->clk_prepare.rec_min,
			t_param->clk_prepare.rec_max);
	pr_debug("prog value = %d, actual=%lld\n",
			t_param->clk_prepare.rec, clk_prep_actual);

	/* clk zero calculations */
	/* Mipi spec min*/
	mipi_min = (300 * multiplier) - (actual_intermediate + actual_frac);
	t_param->clk_zero.mipi_min = div_s64(mipi_min, multiplier);

	/* recommended min */
	rec_temp1 = div_s64(mipi_min * t_clk->bitclk_mbps,
			t_clk->tlpx_numer_ns);
	rec_temp2 = rec_temp1 - (11 * multiplier);
	rec_temp3 = roundup(div_s64(rec_temp2, 8),  multiplier);
	rec_min = div_s64(rec_temp3, multiplier) - 3;
	t_param->clk_zero.rec_min = rec_min;

	/* recommended max */
	t_param->clk_zero.rec_max =
			((t_param->clk_zero.rec_min > 255) ? 511 : 255);

	/* Programmed value */
	t_param->clk_zero.rec = DIV_ROUND_UP(
			(t_param->clk_zero.rec_max - t_param->clk_zero.rec_min)
				* clk_zero_min_frac
				+ (t_param->clk_zero.rec_min * 100), 100);

	rc = mdss_dsi_phy_common_validate_and_set(&t_param->clk_zero,
			"clk zero");
	if (rc)
		goto error;

	pr_debug("CLK ZERO: mipi_min=%d, max=%d, rec_min=%d, rec_max=%d, prog value = %d\n",
			t_param->clk_zero.mipi_min, t_param->clk_zero.mipi_max,
			t_param->clk_zero.rec_min, t_param->clk_zero.rec_max,
			t_param->clk_zero.rec);

	/* clk trail calculations */
	temp_multiple = div_s64(12 * multiplier * t_clk->tlpx_numer_ns,
						t_clk->bitclk_mbps);
	div_s64_rem(temp_multiple, multiplier, &actual_frac);

	mipi_max_tr = 105 * multiplier + (temp_multiple + actual_frac);
	teot_clk_lane = div_s64(mipi_max_tr, multiplier);

	mipi_max = mipi_max_tr - (t_clk->treot_ns * multiplier);

	t_param->clk_trail.mipi_max =  div_s64(mipi_max, multiplier);

	/* recommended min*/
	temp_multiple = div_s64(t_param->clk_trail.mipi_min * multiplier *
			t_clk->bitclk_mbps, t_clk->tlpx_numer_ns);
	div_s64_rem(temp_multiple, multiplier, &actual_frac);
	rec_temp1 = temp_multiple + actual_frac + 3 * multiplier;
	rec_temp2 = div_s64(rec_temp1, 8);
	rec_temp3 = roundup(rec_temp2, multiplier);

	t_param->clk_trail.rec_min = div_s64(rec_temp3, multiplier);

	/* recommended max */
	rec_temp1 = div_s64(mipi_max * t_clk->bitclk_mbps,
						t_clk->tlpx_numer_ns);
	rec_temp2 = rec_temp1 + 3 * multiplier;
	rec_temp3 = rec_temp2 / 8;
	t_param->clk_trail.rec_max = div_s64(rec_temp3, multiplier);

	/* Programmed value */
	t_param->clk_trail.rec = DIV_ROUND_UP(
		(t_param->clk_trail.rec_max - t_param->clk_trail.rec_min)
			* phy_timing_frac
			+ (t_param->clk_trail.rec_min * 100), 100);

	rc = mdss_dsi_phy_common_validate_and_set(&t_param->clk_trail,
			"clk trail");
	if (rc)
		goto error;

	pr_debug("CLK TRAIL: mipi_min=%d, max=%d, rec_min=%d, rec_max=%d, prog value = %d\n",
			t_param->clk_trail.mipi_min,
			t_param->clk_trail.mipi_max,
			t_param->clk_trail.rec_min,
			t_param->clk_trail.rec_max,
			t_param->clk_trail.rec);

	/* hs prepare calculations */
	/* mipi min */
	temp_multiple = div_s64(4 * t_clk->tlpx_numer_ns * multiplier,
			t_clk->bitclk_mbps);
	div_s64_rem(temp_multiple, multiplier, &actual_frac);
	mipi_min = 40 * multiplier + (temp_multiple + actual_frac);
	t_param->hs_prepare.mipi_min = div_s64(mipi_min, multiplier);

	/* mipi max */
	temp_multiple = div_s64(6 * t_clk->tlpx_numer_ns * multiplier,
			t_clk->bitclk_mbps);
	div_s64_rem(temp_multiple, multiplier, &actual_frac);
	mipi_max = 85 * multiplier + temp_multiple;
	t_param->hs_prepare.mipi_max = div_s64(mipi_max, multiplier);

	/* recommended min */
	temp_multiple = div_s64(mipi_min * t_clk->bitclk_mbps,
			t_clk->tlpx_numer_ns);
	div_s64_rem(temp_multiple, multiplier, &actual_frac);
	rec_temp1 = roundup((temp_multiple + actual_frac)/8, multiplier);
	t_param->hs_prepare.rec_min = div_s64(rec_temp1, multiplier);

	/* recommended max*/
	temp_multiple = div_s64(mipi_max * t_clk->bitclk_mbps,
			t_clk->tlpx_numer_ns);
	div_s64_rem(temp_multiple, multiplier, &actual_frac);
	rec_temp2 = rounddown((temp_multiple + actual_frac)/8, multiplier);
	t_param->hs_prepare.rec_max = div_s64(rec_temp2, multiplier);

	/* prog value*/
	dividend = (rec_temp2 - rec_temp1) * min_prepare_frac;
	temp = roundup(div_u64(dividend, 100), multiplier);
	rec_prog = temp + rec_temp1;
	t_param->hs_prepare.rec = div_s64(rec_prog, multiplier);

	rc = mdss_dsi_phy_common_validate_and_set(&t_param->hs_prepare,
			"HS prepare");
	if (rc)
		goto error;

	/* theoretical Value */
	temp_multiple = div_s64(8 * rec_prog * t_clk->tlpx_numer_ns,
			t_clk->bitclk_mbps);
	div_s64_rem(temp_multiple, multiplier, &actual_frac);
	t_hs_prep_actual = div_s64(temp_multiple, multiplier);
	pr_debug("HS PREPARE: mipi_min=%d, max=%d, rec_min=%d, rec_max=%d, prog value = %d, actual=%d\n",
			t_param->hs_prepare.mipi_min,
			t_param->hs_prepare.mipi_max,
			t_param->hs_prepare.rec_min,
			t_param->hs_prepare.rec_max,
			t_param->hs_prepare.rec, t_hs_prep_actual);

	/* hs zero calculations */
	/* mipi min*/
	mipi_min = div_s64(10 * t_clk->tlpx_numer_ns * multiplier,
			t_clk->bitclk_mbps);
	rec_temp1 = (145 * multiplier) + mipi_min - temp_multiple;
	t_param->hs_zero.mipi_min = div_s64(rec_temp1, multiplier);

	/* recommended min */
	rec_temp1 = div_s64(rec_temp1 * t_clk->bitclk_mbps,
			t_clk->tlpx_numer_ns);
	rec_temp2 = rec_temp1 - (11 * multiplier);
	rec_temp3 = roundup((rec_temp2/8), multiplier);
	rec_min = rec_temp3 - (3 * multiplier);
	t_param->hs_zero.rec_min = div_s64(rec_min, multiplier);

	t_param->hs_zero.rec_max =
			((t_param->hs_zero.rec_min > 255) ? 511 : 255);

	/* prog value */
	t_param->hs_zero.rec = DIV_ROUND_UP(
		(t_param->hs_zero.rec_max - t_param->hs_zero.rec_min)
		* hs_zero_min_frac + (t_param->hs_zero.rec_min * 100),
		100);

	rc = mdss_dsi_phy_common_validate_and_set(&t_param->hs_zero, "HS zero");
	if (rc)
		goto error;

	pr_debug("HS ZERO: mipi_min=%d, max=%d, rec_min=%d, rec_max=%d, prog value = %d\n",
			t_param->hs_zero.mipi_min, t_param->hs_zero.mipi_max,
			t_param->hs_zero.rec_min, t_param->hs_zero.rec_max,
			t_param->hs_zero.rec);

	/* hs_trail calculations */
	teot_data_lane  = teot_clk_lane;
	t_param->hs_trail.mipi_min =  60 +
		mult_frac(t_clk->tlpx_numer_ns, 4, t_clk->bitclk_mbps);
	t_param->hs_trail.mipi_max =  teot_clk_lane - t_clk->treot_ns;
	t_param->hs_trail.rec_min = DIV_ROUND_UP(
		((t_param->hs_trail.mipi_min * t_clk->bitclk_mbps)
		 + 3 * t_clk->tlpx_numer_ns), (8 * t_clk->tlpx_numer_ns));
	tmp = ((t_param->hs_trail.mipi_max * t_clk->bitclk_mbps)
		 + (3 * t_clk->tlpx_numer_ns));
	t_param->hs_trail.rec_max = tmp/(8 * t_clk->tlpx_numer_ns);
	tmp = DIV_ROUND_UP((t_param->hs_trail.rec_max
			- t_param->hs_trail.rec_min) * phy_timing_frac,
			100);
	t_param->hs_trail.rec = tmp + t_param->hs_trail.rec_min;


	rc = mdss_dsi_phy_common_validate_and_set(&t_param->hs_trail,
			"HS trail");
	if (rc)
		goto error;

	pr_debug("HS TRAIL: mipi_min=%d, max=%d, rec_min=%d, rec_max=%d, prog value = %d\n",
			t_param->hs_trail.mipi_min, t_param->hs_trail.mipi_max,
			t_param->hs_trail.rec_min, t_param->hs_trail.rec_max,
			t_param->hs_trail.rec);

	/* hs rqst calculations for Data lane */
	t_param->hs_rqst.rec = DIV_ROUND_UP(
		(t_param->hs_rqst.mipi_min * t_clk->bitclk_mbps)
		- (8 * t_clk->tlpx_numer_ns), (8 * t_clk->tlpx_numer_ns));

	rc = mdss_dsi_phy_common_validate_and_set(&t_param->hs_rqst, "HS rqst");
	if (rc)
		goto error;

	pr_debug("HS RQST-DATA: mipi_min=%d, max=%d, rec_min=%d, rec_max=%d, prog value = %d\n",
			t_param->hs_rqst.mipi_min, t_param->hs_rqst.mipi_max,
			t_param->hs_rqst.rec_min, t_param->hs_rqst.rec_max,
			t_param->hs_rqst.rec);

	/* hs exit calculations */
	t_param->hs_exit.rec_min = DIV_ROUND_UP(
		(t_param->hs_exit.mipi_min * t_clk->bitclk_mbps),
		(8 * t_clk->tlpx_numer_ns)) - 1;
	t_param->hs_exit.rec = DIV_ROUND_UP(
		(t_param->hs_exit.rec_max - t_param->hs_exit.rec_min)
			* hs_exit_min_frac
			+ (t_param->hs_exit.rec_min * 100), 100);

	rc = mdss_dsi_phy_common_validate_and_set(&t_param->hs_exit, "HS exit");
	if (rc)
		goto error;

	pr_debug("HS EXIT: mipi_min=%d, max=%d, rec_min=%d, rec_max=%d, prog value = %d\n",
			t_param->hs_exit.mipi_min, t_param->hs_exit.mipi_max,
			t_param->hs_exit.rec_min, t_param->hs_exit.rec_max,
			t_param->hs_exit.rec);

	/* hs rqst calculations for Clock lane */
	t_param->hs_rqst_clk.rec = DIV_ROUND_UP(
		(t_param->hs_rqst_clk.mipi_min * t_clk->bitclk_mbps)
		- (8 * t_clk->tlpx_numer_ns), (8 * t_clk->tlpx_numer_ns));

	rc = mdss_dsi_phy_common_validate_and_set(&t_param->hs_rqst_clk,
			"HS rqst clk");
	if (rc)
		goto error;

	pr_debug("HS RQST-CLK: mipi_min=%d, max=%d, rec_min=%d, rec_max=%d, prog value = %d\n",
			t_param->hs_rqst_clk.mipi_min,
			t_param->hs_rqst_clk.mipi_max,
			t_param->hs_rqst_clk.rec_min,
			t_param->hs_rqst_clk.rec_max,
			t_param->hs_rqst_clk.rec);
	pr_debug("teot_clk=%d, data=%d\n", teot_clk_lane, teot_data_lane);
	return 0;

error:
	return -EINVAL;
}
Exemple #11
0
static int mc13xxx_rtc_set_mmss(struct device *dev, time64_t secs)
{
	struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
	unsigned int seconds, days;
	unsigned int alarmseconds;
	int ret;

	days = div_s64_rem(secs, SEC_PER_DAY, &seconds);

	mc13xxx_lock(priv->mc13xxx);

	/*
	 * temporarily invalidate alarm to prevent triggering it when the day is
	 * already updated while the time isn't yet.
	 */
	ret = mc13xxx_reg_read(priv->mc13xxx, MC13XXX_RTCTODA, &alarmseconds);
	if (unlikely(ret))
		goto out;

	if (alarmseconds < SEC_PER_DAY) {
		ret = mc13xxx_reg_write(priv->mc13xxx,
				MC13XXX_RTCTODA, 0x1ffff);
		if (unlikely(ret))
			goto out;
	}

	/*
	 * write seconds=0 to prevent a day switch between writing days
	 * and seconds below
	 */
	ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCTOD, 0);
	if (unlikely(ret))
		goto out;

	ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCDAY, days);
	if (unlikely(ret))
		goto out;

	ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCTOD, seconds);
	if (unlikely(ret))
		goto out;

	/* restore alarm */
	if (alarmseconds < SEC_PER_DAY) {
		ret = mc13xxx_reg_write(priv->mc13xxx,
				MC13XXX_RTCTODA, alarmseconds);
		if (unlikely(ret))
			goto out;
	}

	if (!priv->valid) {
		ret = mc13xxx_irq_ack(priv->mc13xxx, MC13XXX_IRQ_RTCRST);
		if (unlikely(ret))
			goto out;

		ret = mc13xxx_irq_unmask(priv->mc13xxx, MC13XXX_IRQ_RTCRST);
	}

out:
	priv->valid = !ret;

	mc13xxx_unlock(priv->mc13xxx);

	return ret;
}
Exemple #12
0
static inline s64 div_s64(s64 dividend, s32 divisor)
{
        s32 remainder;
        return div_s64_rem(dividend, divisor, &remainder);
}
Exemple #13
0
static int adxl345_read_raw(struct iio_dev *indio_dev,
			    struct iio_chan_spec const *chan,
			    int *val, int *val2, long mask)
{
	struct adxl345_data *data = iio_priv(indio_dev);
	__le16 accel;
	long long samp_freq_nhz;
	unsigned int regval;
	int ret;

	switch (mask) {
	case IIO_CHAN_INFO_RAW:
		/*
		 * Data is stored in adjacent registers:
		 * ADXL345_REG_DATA(X0/Y0/Z0) contain the least significant byte
		 * and ADXL345_REG_DATA(X0/Y0/Z0) + 1 the most significant byte
		 */
		ret = regmap_bulk_read(data->regmap,
				       ADXL345_REG_DATA_AXIS(chan->address),
				       &accel, sizeof(accel));
		if (ret < 0)
			return ret;

		*val = sign_extend32(le16_to_cpu(accel), 12);
		return IIO_VAL_INT;
	case IIO_CHAN_INFO_SCALE:
		*val = 0;
		switch (data->type) {
		case ADXL345:
			*val2 = adxl345_uscale;
			break;
		case ADXL375:
			*val2 = adxl375_uscale;
			break;
		}

		return IIO_VAL_INT_PLUS_MICRO;
	case IIO_CHAN_INFO_CALIBBIAS:
		ret = regmap_read(data->regmap,
				  ADXL345_REG_OFS_AXIS(chan->address), &regval);
		if (ret < 0)
			return ret;
		/*
		 * 8-bit resolution at +/- 2g, that is 4x accel data scale
		 * factor
		 */
		*val = sign_extend32(regval, 7) * 4;

		return IIO_VAL_INT;
	case IIO_CHAN_INFO_SAMP_FREQ:
		ret = regmap_read(data->regmap, ADXL345_REG_BW_RATE, &regval);
		if (ret < 0)
			return ret;

		samp_freq_nhz = ADXL345_BASE_RATE_NANO_HZ <<
				(regval & ADXL345_BW_RATE);
		*val = div_s64_rem(samp_freq_nhz, NHZ_PER_HZ, val2);

		return IIO_VAL_INT_PLUS_NANO;
	}

	return -EINVAL;
}
Exemple #14
0
static void cros_usbpd_print_log_entry(struct ec_response_pd_log *r,
				       ktime_t tstamp)
{
	const char *fault, *role, *chg_type;
	struct usb_chg_measures *meas;
	struct mcdp_info *minfo;
	int role_idx, type_idx;
	char buf[BUF_SIZE + 1];
	struct rtc_time rt;
	int len = 0;
	s32 rem;
	int i;

	/* The timestamp is the number of 1024th of seconds in the past */
	tstamp = ktime_sub_us(tstamp, r->timestamp << PD_LOG_TIMESTAMP_SHIFT);
	rt = rtc_ktime_to_tm(tstamp);

	switch (r->type) {
	case PD_EVENT_MCU_CHARGE:
		if (r->data & CHARGE_FLAGS_OVERRIDE)
			len += append_str(buf, len, "override ");

		if (r->data & CHARGE_FLAGS_DELAYED_OVERRIDE)
			len += append_str(buf, len, "pending_override ");

		role_idx = r->data & CHARGE_FLAGS_ROLE_MASK;
		role = role_idx < ARRAY_SIZE(role_names) ?
			role_names[role_idx] : "Unknown";

		type_idx = (r->data & CHARGE_FLAGS_TYPE_MASK)
			 >> CHARGE_FLAGS_TYPE_SHIFT;

		chg_type = type_idx < ARRAY_SIZE(chg_type_names) ?
			chg_type_names[type_idx] : "???";

		if (role_idx == USB_PD_PORT_POWER_DISCONNECTED ||
		    role_idx == USB_PD_PORT_POWER_SOURCE) {
			len += append_str(buf, len, "%s", role);
			break;
		}

		meas = (struct usb_chg_measures *)r->payload;
		len += append_str(buf, len, "%s %s %s %dmV max %dmV / %dmA",
				  role,	r->data & CHARGE_FLAGS_DUAL_ROLE ?
				  "DRP" : "Charger",
				  chg_type, meas->voltage_now,
				  meas->voltage_max, meas->current_max);
		break;
	case PD_EVENT_ACC_RW_FAIL:
		len += append_str(buf, len, "RW signature check failed");
		break;
	case PD_EVENT_PS_FAULT:
		fault = r->data < ARRAY_SIZE(fault_names) ? fault_names[r->data]
							  : "???";
		len += append_str(buf, len, "Power supply fault: %s", fault);
		break;
	case PD_EVENT_VIDEO_DP_MODE:
		len += append_str(buf, len, "DP mode %sabled", r->data == 1 ?
				  "en" : "dis");
		break;
	case PD_EVENT_VIDEO_CODEC:
		minfo = (struct mcdp_info *)r->payload;
		len += append_str(buf, len, "HDMI info: family:%04x chipid:%04x ",
				  MCDP_FAMILY(minfo->family),
				  MCDP_CHIPID(minfo->chipid));
		len += append_str(buf, len, "irom:%d.%d.%d fw:%d.%d.%d",
				  minfo->irom.major, minfo->irom.minor,
				  minfo->irom.build, minfo->fw.major,
				  minfo->fw.minor, minfo->fw.build);
		break;
	default:
		len += append_str(buf, len, "Event %02x (%04x) [", r->type,
				  r->data);

		for (i = 0; i < PD_LOG_SIZE(r->size_port); i++)
			len += append_str(buf, len, "%02x ", r->payload[i]);

		len += append_str(buf, len, "]");
		break;
	}

	div_s64_rem(ktime_to_ms(tstamp), MSEC_PER_SEC, &rem);
	pr_info("PDLOG %d/%02d/%02d %02d:%02d:%02d.%03d P%d %s\n",
		rt.tm_year + 1900, rt.tm_mon + 1, rt.tm_mday,
		rt.tm_hour, rt.tm_min, rt.tm_sec, rem,
		PD_LOG_PORT(r->size_port), buf);
}