コード例 #1
0
static int tps80031_battery_charge_counter(struct tps80031_device_info *di,
			union power_supply_propval *val)
{
	int retval, ret;
	uint32_t cnt_byte;
	uint32_t acc_byte;

	/* check if calibrated */
	if (di->fg_calib_intr == 0)
		return 0;

	/* get current accumlator */
	ret = tps80031_reads(di->dev->parent, TPS80031_SLAVE_ID2, FG_REG_04, 4,
							(uint8_t *) &acc_byte);
	if (ret < 0)
		return ret;
	/* counter value is mAs, need report uAh */
	retval = (int32_t) acc_byte / 18 * 5;

	/* get counter */
	ret = tps80031_reads(di->dev->parent, TPS80031_SLAVE_ID2, FG_REG_01, 3,
							(uint8_t *) &cnt_byte);
	if (ret < 0)
		return ret;
	/* we need calibrate the offset current in uAh*/
	retval = retval - (di->fg_offset / 4 * cnt_byte);

	/* @todo, counter value will overflow if battery get continuously
	 * charged discharged for more than 108Ah using 250mS integration
	 * period althrough it is hightly impossible.
	 */

	return retval;
}
コード例 #2
0
static int tps80031_read_regs(struct device *dev, int reg, int len,
	uint8_t *val)
{
	int ret;

	/* dummy read of STATUS_REG as per data sheet */
	ret = tps80031_reads(dev->parent, 1, RTC_STATUS, 1, val);
	if (ret < 0) {
		dev_err(dev->parent, "failed reading RTC_STATUS\n");
		WARN_ON(1);
		return ret;
	}

	ret = tps80031_reads(dev->parent, 1, reg, len, val);
	if (ret < 0) {
		dev_err(dev->parent, "failed reading from reg %d\n", reg);
		WARN_ON(1);
		return ret;
	}
	return 0;
}
コード例 #3
0
ファイル: rtc-tps80031.c プロジェクト: AiWinters/linux
static int tps80031_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
	u8 buff[TPS80031_RTC_TIME_NUM_REGS];
	int ret;

	ret = tps80031_reads(dev->parent, TPS80031_SLAVE_ID1,
			TPS80031_SECONDS_REG, TPS80031_RTC_TIME_NUM_REGS, buff);
	if (ret < 0) {
		dev_err(dev, "reading RTC_SECONDS_REG failed, err = %d\n", ret);
		return ret;
	}

	tm->tm_sec = bcd2bin(buff[0]);
	tm->tm_min = bcd2bin(buff[1]);
	tm->tm_hour = bcd2bin(buff[2]);
	tm->tm_mday = bcd2bin(buff[3]);
	tm->tm_mon = bcd2bin(buff[4]) - 1;
	tm->tm_year = bcd2bin(buff[5]) + RTC_YEAR_OFFSET;
	tm->tm_wday = bcd2bin(buff[6]);
	return 0;
}
コード例 #4
0
ファイル: rtc-tps80031.c プロジェクト: AiWinters/linux
static int tps80031_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
	u8 buff[6];
	int ret;

	ret = tps80031_reads(dev->parent, TPS80031_SLAVE_ID1,
			TPS80031_ALARM_SECONDS_REG,
			TPS80031_RTC_ALARM_NUM_REGS, buff);
	if (ret < 0) {
		dev_err(dev->parent,
			"reading RTC_ALARM failed, err = %d\n", ret);
		return ret;
	}

	alrm->time.tm_sec = bcd2bin(buff[0]);
	alrm->time.tm_min = bcd2bin(buff[1]);
	alrm->time.tm_hour = bcd2bin(buff[2]);
	alrm->time.tm_mday = bcd2bin(buff[3]);
	alrm->time.tm_mon = bcd2bin(buff[4]) - 1;
	alrm->time.tm_year = bcd2bin(buff[5]) + RTC_YEAR_OFFSET;
	return 0;
}