Ejemplo n.º 1
0
static ssize_t max8997_muic_set_status(struct device *dev,
					struct device_attribute *attr,
					const char *buf, size_t count)
{
	struct max8997_muic_info *info = dev_get_drvdata(dev);
	u8  reg_value[3];
	char reg_name[5];

	if (sscanf(buf, "%4s:%02x,%02x,%02x" , reg_name, (u32 *)&reg_value[0],
		(u32 *)&reg_value[1], (u32 *)&reg_value[2])) {
		if (!strncmp(reg_name, "INTM", 4)) {
			dev_info(dev, "Manual Set INTMASK to 0x%02x, 0x%02x, 0x%02x\n",
				reg_value[0], reg_value[1], reg_value[2]);
			max8997_bulk_write(info->muic,
				MAX8997_MUIC_REG_INTMASK1, 3, reg_value);
		} else if (!strncmp(reg_name, "CONT", 4)) {
			dev_info(dev, "Manual Set CONTROL to 0x%02x, 0x%02x, 0x%02x\n",
				reg_value[0], reg_value[1], reg_value[2]);
			max8997_bulk_write(info->muic,
				MAX8997_MUIC_REG_CTRL1, 3, reg_value);
		} else if (!strncmp(reg_name, "CDET", 4)) {
			dev_info(dev, "Manual Set CDETCTRL to 0x%02x\n",
				reg_value[0]);
			max8997_write_reg(info->muic,
				MAX8997_MUIC_REG_CDETCTRL, reg_value[0]);
		} else {
			dev_info(dev, "Unsupported CMD format\n");
		}
	} else {
		dev_info(dev, "Read CMD fail\n");
	}

	return count;
}
Ejemplo n.º 2
0
static int max8997_rtc_stop_alarm(struct max8997_rtc_info *info)
{
	u8 data[RTC_NR_TIME];
	int ret, i;

	if (!mutex_is_locked(&info->lock))
		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);

	ret = max8997_bulk_read(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
				data);
	if (ret < 0) {
		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
				__func__, ret);
		goto out;
	}

	for (i = 0; i < RTC_NR_TIME; i++)
		data[i] &= ~ALARM_ENABLE_MASK;

	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
				 data);
	if (ret < 0) {
		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
				__func__, ret);
		goto out;
	}

	ret = max8997_rtc_set_update_reg(info);
out:
	return ret;
}
Ejemplo n.º 3
0
static int max8997_rtc_init_reg(struct max8997_rtc_info *info)
{
	u8 data[2];
	int ret;

	/* Set RTC control register : Binary mode, 24hour mdoe */
	data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
	data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);

	info->rtc_24hr_mode = 1;

	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_CTRLMASK, 2, data);
	if (ret < 0) {
		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
				__func__, ret);
		return ret;
	}

	ret = max8997_rtc_set_update_reg(info);
	return ret;
}
Ejemplo n.º 4
0
static int max8997_rtc_start_alarm(struct max8997_rtc_info *info)
{
	u8 data[RTC_NR_TIME];
	int ret;

	if (!mutex_is_locked(&info->lock))
		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);

	ret = max8997_bulk_read(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
				data);
	if (ret < 0) {
		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
				__func__, ret);
		goto out;
	}

	data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT);
	data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT);
	data[RTC_HOUR] |= (1 << ALARM_ENABLE_SHIFT);
	data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
	if (data[RTC_MONTH] & 0xf)
		data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT);
	if (data[RTC_YEAR] & 0x7f)
		data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT);
	if (data[RTC_DATE] & 0x1f)
		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);

	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
				 data);
	if (ret < 0) {
		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
				__func__, ret);
		goto out;
	}

	ret = max8997_rtc_set_update_reg(info);
out:
	return ret;
}
Ejemplo n.º 5
0
static int max8997_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
	struct max8997_rtc_info *info = dev_get_drvdata(dev);
	u8 data[RTC_NR_TIME];
	int ret;

	ret = max8997_rtc_tm_to_data(&alrm->time, data);
	if (ret < 0)
		return ret;

	dev_info(info->dev, "%s: %d-%02d-%02d %02d:%02d:%02d\n", __func__,
			data[RTC_YEAR] + 2000, data[RTC_MONTH], data[RTC_DATE],
			data[RTC_HOUR], data[RTC_MIN], data[RTC_SEC]);

	mutex_lock(&info->lock);

	ret = max8997_rtc_stop_alarm(info);
	if (ret < 0)
		goto out;

	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
				data);
	if (ret < 0) {
		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
				__func__, ret);
		goto out;
	}

	ret = max8997_rtc_set_update_reg(info);
	if (ret < 0)
		goto out;

	if (alrm->enabled)
		ret = max8997_rtc_start_alarm(info);
out:
	mutex_unlock(&info->lock);
	return ret;
}
Ejemplo n.º 6
0
static int max8997_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
	struct max8997_rtc_info *info = dev_get_drvdata(dev);
	u8 data[RTC_NR_TIME];
	int ret;

	ret = max8997_rtc_tm_to_data(tm, data);
	if (ret < 0)
		return ret;

	mutex_lock(&info->lock);

	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_SEC, RTC_NR_TIME, data);
	if (ret < 0) {
		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
				ret);
		goto out;
	}

	ret = max8997_rtc_set_update_reg(info);
out:
	mutex_unlock(&info->lock);
	return ret;
}