Beispiel #1
0
static int wm8350_rtc_alarm_irq_enable(struct device *dev,
				       unsigned int enabled)
{
	struct wm8350 *wm8350 = dev_get_drvdata(dev);

	if (enabled)
		return wm8350_rtc_start_alarm(wm8350);
	else
		return wm8350_rtc_stop_alarm(wm8350);
}
Beispiel #2
0
static int wm8350_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
	struct wm8350 *wm8350 = dev_get_drvdata(dev);
	struct rtc_time *tm = &alrm->time;
	u16 time[3];
	int ret;

	memset(time, 0, sizeof(time));

	if (tm->tm_sec != -1)
		time[0] |= tm->tm_sec;
	else
		time[0] |= WM8350_RTC_ALMSECS_MASK;

	if (tm->tm_min != -1)
		time[0] |= tm->tm_min << WM8350_RTC_ALMMINS_SHIFT;
	else
		time[0] |= WM8350_RTC_ALMMINS_MASK;

	if (tm->tm_hour != -1)
		time[1] |= tm->tm_hour;
	else
		time[1] |= WM8350_RTC_ALMHRS_MASK;

	if (tm->tm_wday != -1)
		time[1] |= (tm->tm_wday + 1) << WM8350_RTC_ALMDAY_SHIFT;
	else
		time[1] |= WM8350_RTC_ALMDAY_MASK;

	if (tm->tm_mday != -1)
		time[2] |= tm->tm_mday;
	else
		time[2] |= WM8350_RTC_ALMDATE_MASK;

	if (tm->tm_mon != -1)
		time[2] |= (tm->tm_mon + 1) << WM8350_RTC_ALMMTH_SHIFT;
	else
		time[2] |= WM8350_RTC_ALMMTH_MASK;

	ret = wm8350_rtc_stop_alarm(wm8350);
	if (ret < 0)
		return ret;

	/* Write time to RTC */
	ret = wm8350_block_write(wm8350, WM8350_ALARM_SECONDS_MINUTES,
				 3, time);
	if (ret < 0)
		return ret;

	if (alrm->enabled)
		ret = wm8350_rtc_start_alarm(wm8350);

	return ret;
}
Beispiel #3
0
static int wm8350_rtc_suspend(struct platform_device *pdev, pm_message_t state)
{
	struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
	int ret = 0;
	u16 reg;

	reg = wm8350_reg_read(wm8350, WM8350_RTC_TIME_CONTROL);

	if (device_may_wakeup(&wm8350->rtc.pdev->dev) &&
	    reg & WM8350_RTC_ALMSTS) {
		ret = wm8350_rtc_stop_alarm(wm8350);
		if (ret != 0)
			dev_err(&pdev->dev, "Failed to stop RTC alarm: %d\n",
				ret);
	}

	return ret;
}
Beispiel #4
0
/*
 * Handle commands from user-space
 */
static int wm8350_rtc_ioctl(struct device *dev, unsigned int cmd,
			    unsigned long arg)
{
	struct wm8350 *wm8350 = dev_get_drvdata(dev);

	switch (cmd) {
	case RTC_AIE_OFF:
		return wm8350_rtc_stop_alarm(wm8350);
	case RTC_AIE_ON:
		return wm8350_rtc_start_alarm(wm8350);

	case RTC_UIE_OFF:
		wm8350_mask_irq(wm8350, WM8350_IRQ_RTC_SEC);
		break;
	case RTC_UIE_ON:
		wm8350_unmask_irq(wm8350, WM8350_IRQ_RTC_SEC);
		break;

	default:
		return -ENOIOCTLCMD;
	}

	return 0;
}