Пример #1
0
int stmmac_open_ext_timer(struct net_device *dev, struct stmmac_timer *tm)
{
	stmmac_task.private_data = dev;
	stmmac_task.func = stmmac_timer_handler;

	stmmac_rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
	if (stmmac_rtc == NULL) {
		pr_error("open rtc device failed\n");
		return -ENODEV;
	}

	rtc_irq_register(stmmac_rtc, &stmmac_task);

	/* Periodic mode is not supported */
	if ((rtc_irq_set_freq(stmmac_rtc, &stmmac_task, tm->freq) < 0)) {
		pr_error("set periodic failed\n");
		rtc_irq_unregister(stmmac_rtc, &stmmac_task);
		rtc_class_close(stmmac_rtc);
		return -1;
	}

	STMMAC_TIMER_MSG(CONFIG_RTC_HCTOSYS_DEVICE, tm->freq);

	tm->timer_start = stmmac_rtc_start;
	tm->timer_stop = stmmac_rtc_stop;

	return 0;
}
Пример #2
0
int stmmac_close_ext_timer(void)
{
	rtc_irq_set_state(stmmac_rtc, &stmmac_task, 0);
	rtc_irq_unregister(stmmac_rtc, &stmmac_task);
	rtc_class_close(stmmac_rtc);
	return 0;
}
Пример #3
0
static int __init test_suspend(void)
{
	static char		warn_no_rtc[] __initdata =
		KERN_WARNING "PM: no wakealarm-capable RTC driver is ready\n";

	char			*pony = NULL;
	struct rtc_device	*rtc = NULL;

	/* PM is initialized by now; is that state testable? */
	if (test_state == PM_SUSPEND_ON)
		goto done;
	if (!valid_state(test_state)) {
		printk(warn_bad_state, pm_states[test_state]);
		goto done;
	}

	/* RTCs have initialized by now too ... can we use one? */
	class_find_device(rtc_class, NULL, &pony, has_wakealarm);
	if (pony)
		rtc = rtc_class_open(pony);
	if (!rtc) {
		printk(warn_no_rtc);
		goto done;
	}

	/* go for it */
	test_wakealarm(rtc, test_state);
	rtc_class_close(rtc);
done:
	return 0;
}
static int __init test_suspend(void)
{
	static char		warn_no_rtc[] __initdata =
		KERN_WARNING "PM: no wakealarm-capable RTC driver is ready\n";

	char			*pony = NULL;
	struct rtc_device	*rtc = NULL;

	
	if (test_state == PM_SUSPEND_ON)
		goto done;
	if (!valid_state(test_state)) {
		printk(warn_bad_state, pm_states[test_state]);
		goto done;
	}

	
	class_find_device(rtc_class, NULL, &pony, has_wakealarm);
	if (pony)
		rtc = rtc_class_open(pony);
	if (!rtc) {
		printk(warn_no_rtc);
		goto done;
	}

	
	test_wakealarm(rtc, test_state);
	rtc_class_close(rtc);
done:
	return 0;
}
Пример #5
0
static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
	struct rtc_time *tm = &alrm->time;
	void __iomem *base = s3c_rtc_base;
	unsigned int alrm_en;
#ifdef CONFIG_RTC_DRV_S5M
    struct rtc_device *rtc1;
#endif
	//pr_debug
	printk("s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
		 alrm->enabled,
		 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
		 tm->tm_hour, tm->tm_min, tm->tm_sec);

	alrm_en = readb(base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;
	writeb(0x00, base + S3C2410_RTCALM);

	if (tm->tm_sec < 60 && tm->tm_sec >= 0) {
		alrm_en |= S3C2410_RTCALM_SECEN;
		writeb(bin2bcd(tm->tm_sec), base + S3C2410_ALMSEC);
	}

	if (tm->tm_min < 60 && tm->tm_min >= 0) {
		alrm_en |= S3C2410_RTCALM_MINEN;
		writeb(bin2bcd(tm->tm_min), base + S3C2410_ALMMIN);
	}

	if (tm->tm_hour < 24 && tm->tm_hour >= 0) {
		alrm_en |= S3C2410_RTCALM_HOUREN;
		writeb(bin2bcd(tm->tm_hour), base + S3C2410_ALMHOUR);
	}

	pr_debug("setting S3C2410_RTCALM to %08x\n", alrm_en);

	writeb(alrm_en, base + S3C2410_RTCALM);

	s3c_rtc_setaie(dev, alrm->enabled);
	
    /*Cellon add start, Devin Yuan, 2012/10/11, for off-mode alarm*/ 
#ifdef S5M8767_OFF_ALARM
#ifdef CONFIG_RTC_DRV_S5M
	rtc1 = rtc_class_open("rtc1");
	if(rtc1 == NULL)
	{
	    printk("!!!!!! %s: unable to open rtc1 device!!!!!\n",
	            __FILE__);
	}
	else
	{
	    rtc_set_alarm(rtc1, alrm);
	    rtc_class_close(rtc1);
	}
#endif
#endif
     /*Cellon add end, Devin Yuan, 2012/10/11, for off-mode alarm*/

	return 0;
}
int rtc_hctosys(void)
{
	int err = -ENODEV;
	struct rtc_time tm;
	struct timespec tv = {
		.tv_nsec = NSEC_PER_SEC >> 1,
	};
	struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);

	if (rtc == NULL) {
		pr_err("%s: unable to open rtc device (%s)\n",
			__FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
		goto err_open;
	}

	err = rtc_read_time(rtc, &tm);
	if (err) {
		dev_err(rtc->dev.parent,
			"hctosys: unable to read the hardware clock\n");
		goto err_read;

	}

	/*
	 * Force update rtc year time to 2014
	 * (The release year of device)
	 */
	tm.tm_year = 114;

	err = rtc_valid_tm(&tm);
	if (err) {
		dev_err(rtc->dev.parent,
			"hctosys: invalid date/time\n");
		goto err_invalid;
	}

	rtc_tm_to_time(&tm, &tv.tv_sec);

	err = do_settimeofday(&tv);

	dev_info(rtc->dev.parent,
		"setting system clock to "
		"%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n",
		tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
		tm.tm_hour, tm.tm_min, tm.tm_sec,
		(unsigned int) tv.tv_sec);

err_invalid:
err_read:
	rtc_class_close(rtc);

err_open:
	rtc_hctosys_ret = err;

	return err;
}

late_initcall(rtc_hctosys);
Пример #7
0
static int read_rtc0_time(struct msm_rpc_server *server,
		   struct rpc_request_hdr *req,
		   unsigned len)
{
	int err;
	unsigned long tm_sec;
	uint32_t size = 0;
	void *reply;
	uint32_t output_valid;
	uint32_t rpc_status = RPC_ACCEPTSTAT_SYSTEM_ERR;
	struct rtc_time tm;
	struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);

	if (rtc == NULL) {
		pr_err("%s: unable to open rtc device (%s)\n",
			__FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
		goto send_reply;
	}

	err = rtc_read_time(rtc, &tm);
	if (err) {
		pr_err("%s: Error reading rtc device (%s) : %d\n",
			__FILE__, CONFIG_RTC_HCTOSYS_DEVICE, err);
		goto close_dev;
	}

	err = rtc_valid_tm(&tm);
	if (err) {
		pr_err("%s: Invalid RTC time (%s)\n",
			__FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
		goto close_dev;
	}

	rtc_tm_to_time(&tm, &tm_sec);
	rpc_status = RPC_ACCEPTSTAT_SUCCESS;

close_dev:
	rtc_class_close(rtc);

send_reply:
	reply = msm_rpc_server_start_accepted_reply(server, req->xid,
						    rpc_status);
	if (rpc_status == RPC_ACCEPTSTAT_SUCCESS) {
		output_valid = *((uint32_t *)(req + 1));
		*(uint32_t *)reply = output_valid;
		size = sizeof(uint32_t);
		if (be32_to_cpu(output_valid)) {
			reply += sizeof(uint32_t);
			*(uint32_t *)reply = cpu_to_be32(tm_sec);
			size += sizeof(uint32_t);
		}
	}
	err = msm_rpc_server_send_accepted_reply(server, size);
	if (err)
		pr_err("%s: send accepted reply failed: %d\n", __func__, err);

	return 1;
}
Пример #8
0
int rtc_hctosys(void)
{
	int err = -ENODEV;
	struct rtc_time tm;
	struct timespec tv = {
		.tv_nsec = NSEC_PER_SEC >> 1,
	};
	struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);

	if (rtc == NULL) {
		pr_err("%s: unable to open rtc device (%s)\n",
			__FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
		goto err_open;
	}

	err = rtc_read_time(rtc, &tm);
	if (err) {
		dev_err(rtc->dev.parent,
			"hctosys: unable to read the hardware clock\n");
		goto err_read;

	}

	err = rtc_valid_tm(&tm);
	if (err) {
		dev_err(rtc->dev.parent,
			"hctosys: invalid date/time\n");
		goto err_invalid;
	}

	rtc_tm_to_time(&tm, &tv.tv_sec);

	if (tv.tv_sec < 86400) {
		tv.tv_sec = 86400;
		pr_info("%s: Make sure the boot time starts from 86400 or more to avoid system server crash due to alarm trigger immediately\n", __FILE__);
	}
	do_settimeofday(&tv);

	dev_info(rtc->dev.parent,
		"setting system clock to "
		"%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n",
		tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
		tm.tm_hour, tm.tm_min, tm.tm_sec,
		(unsigned int) tv.tv_sec);

err_invalid:
err_read:
	rtc_class_close(rtc);

err_open:
	rtc_hctosys_ret = err;

	return err;
}

late_initcall(rtc_hctosys);
Пример #9
0
/**
 * tegra_get_linear_age - helper function to return linear age
 * from Jan 2012.
 *
 * @return
 * 1 - Jan 2012,
 * 2 - Feb 2012,
 * .....
 * 13 - Jan 2013
 */
int tegra_get_linear_age(void)
{
	struct rtc_time tm;
	int year, month, linear_age;
	struct rtc_device *rtc_dev = NULL;
	const char *name = NULL;
	int ret;
	struct device *dev = NULL;

	linear_age = -1;
	year = month = 0;
	dev = class_find_device(rtc_class, NULL, &name, has_readtime);

	if (!dev) {
		pr_err("DVFS: No device with readtime capability\n");
		goto done;
	}

	name = dev_name(dev);

	pr_info("DVFS: Got RTC device name:%s\n", name);

	if (name)
		rtc_dev = rtc_class_open((char *)name);

	if (!rtc_dev) {
		pr_err("DVFS: No RTC device\n");
		goto error_dev;
	}

	ret = rtc_read_time(rtc_dev, &tm);

	if (ret < 0) {
		pr_err("DVFS: Can't read RTC time\n");
		goto error_rtc;
	}

	year = tm.tm_year;
	/*Normalize it to 2012*/
	year -= 112;
	month = tm.tm_mon + 1;

	if (year >= 0)
		linear_age = year * 12 + month;

error_rtc:
	rtc_class_close(rtc_dev);
error_dev:
	put_device(dev);
done:
	return linear_age;

}
Пример #10
0
static int set_rtc_mmss(unsigned long secs)
{
	struct rtc_device *rtc = rtc_class_open("rtc0");
	int err = -1;

	if (rtc) {
		err = rtc_set_mmss(rtc, secs);
		rtc_class_close(rtc);
	}

	return err;
}
Пример #11
0
static int __devexit suspend_autotest_remove(struct platform_device *pdev)
{
	if (wake_lock_active(&test_wake_lock))
		wake_unlock(&test_wake_lock);
	wake_lock_destroy(&test_wake_lock);

	rtc_class_close(rtc);
	input_unregister_device(pwr_dev);
	input_free_device(pwr_dev);

	return 0;
}
Пример #12
0
static int restore_wakealarm(void)
{
	struct rtc_wkalrm	alm;
	struct rtc_device	*rtc = NULL;

	rtc = rtc_class_open(CONFIG_WAKEALARM_RTC);
	if (!rtc) {
		return -1;
	}
	alm.enabled = false;
	rtc_set_alarm(rtc, &alm);
	rtc_class_close(rtc);
	return 0;
}
Пример #13
0
static int __init rtc_hctosys(void)
{
	int err = -ENODEV;
	struct rtc_time tm;
	struct timespec64 tv64 = {
		.tv_nsec = NSEC_PER_SEC >> 1,
	};
	struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);

	if (rtc == NULL) {
		pr_info("unable to open rtc device (%s)\n",
			CONFIG_RTC_HCTOSYS_DEVICE);
		goto err_open;
	}

	err = rtc_read_time(rtc, &tm);
	if (err) {
		dev_err(rtc->dev.parent,
			"hctosys: unable to read the hardware clock\n");
		goto err_read;

	}

	tv64.tv_sec = rtc_tm_to_time64(&tm);

#if BITS_PER_LONG == 32
	if (tv64.tv_sec > INT_MAX)
		goto err_read;
#endif

	err = do_settimeofday64(&tv64);

	dev_info(rtc->dev.parent,
		"setting system clock to "
		"%d-%02d-%02d %02d:%02d:%02d UTC (%lld)\n",
		tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
		tm.tm_hour, tm.tm_min, tm.tm_sec,
		(long long) tv64.tv_sec);

err_read:
	rtc_class_close(rtc);

err_open:
	rtc_hctosys_ret = err;

	return err;
}

late_initcall(rtc_hctosys);
Пример #14
0
static int set_wakealarm(void)
{
	int retval = 0;
	unsigned long now, alarm;
	struct rtc_wkalrm alm;
	struct rtc_device *rtc;

	rtc = rtc_class_open(CONFIG_WAKEALARM_RTC);
	if (!rtc) {
		return -1;
	}

	/* Only request alarms that trigger in the future.  Disable them
	 * by writing another time, e.g. 0 meaning Jan 1 1970 UTC.
	 */
	retval = rtc_read_time(rtc, &alm.time);
	if (retval < 0)
		goto close_rtc;
	rtc_tm_to_time(&alm.time, &now);

	alarm = now + sleep_time;
	
	if (alarm > now) {
		/* Avoid accidentally clobbering active alarms; we can't
		 * entirely prevent that here, without even the minimal
		 * locking from the /dev/rtcN api.
		 */
		retval = rtc_read_alarm(rtc, &alm);
		if (retval < 0)
			goto close_rtc;

		alm.enabled = 1;
	} else {
		alm.enabled = 0;

		/* Provide a valid future alarm time.  Linux isn't EFI,
		 * this time won't be ignored when disabling the alarm.
		 */
		alarm = now + 300;
	}

	rtc_time_to_tm(alarm, &alm.time);
	retval = rtc_set_alarm(rtc, &alm);

close_rtc:
	rtc_class_close(rtc);
	return retval;
}
Пример #15
0
static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
{
	void __iomem *base = s3c_rtc_base;
//	int year = tm->tm_year;//- 100;
	int year = tm->tm_year-100;
#ifdef CONFIG_RTC_DRV_S5M
	struct rtc_device *rtc1 ;
#endif

	printk("%s() %d-%d-%d %d:%d:%d\n", __FUNCTION__,
			tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
			tm->tm_hour, tm->tm_min, tm->tm_sec);
	pr_debug("set time %04d.%02d.%02d %02d:%02d:%02d\n",
		 1900 + tm->tm_year, tm->tm_mon+1, tm->tm_mday,
		 tm->tm_hour, tm->tm_min, tm->tm_sec);

	/* we get around y2k by simply not supporting it */
	
//	printk("year %d\n",year);
//	if (year < 70) {
//		dev_err(dev, "rtc only supports from year 1970\n");
//		return -EINVAL;
//	}


	writeb(bin2bcd(tm->tm_sec),  base + S3C2410_RTCSEC);
	writeb(bin2bcd(tm->tm_min),  base + S3C2410_RTCMIN);
	writeb(bin2bcd(tm->tm_hour), base + S3C2410_RTCHOUR);
	writeb(bin2bcd(tm->tm_mday), base + S3C2410_RTCDATE);
	writeb(bin2bcd(tm->tm_mon + 1), base + S3C2410_RTCMON);
	writeb(bin2bcd(year), base + S3C2410_RTCYEAR);

#ifdef CONFIG_RTC_DRV_S5M
	rtc1 = rtc_class_open("rtc1");
	if(rtc1 == NULL)
	{
		pr_err("!!!!!! %s: unable to open rtc1 device!!!!!\n",
				__FILE__);
	}
	else
	{
		rtc_set_time(rtc1,tm);
		rtc_class_close(rtc1);
	}
#endif
	return 0;
}
Пример #16
0
static int __init test_suspend(void)
{
	static char		warn_no_rtc[] __initdata =
		KERN_WARNING "PM: no wakealarm-capable RTC driver is ready\n";

	struct rtc_device	*rtc = NULL;
	struct device		*dev;
	suspend_state_t test_state;

	/* PM is initialized by now; is that state testable? */
	if (!test_state_label)
		return 0;

	for (test_state = PM_SUSPEND_MIN; test_state < PM_SUSPEND_MAX; test_state++) {
		const char *state_label = pm_states[test_state];

		if (state_label && !strcmp(test_state_label, state_label))
			break;
	}
	if (test_state == PM_SUSPEND_MAX) {
		printk(warn_bad_state, test_state_label);
		return 0;
	}

	/* RTCs have initialized by now too ... can we use one? */
	dev = class_find_device(rtc_class, NULL, NULL, has_wakealarm);
	if (dev) {
		rtc = rtc_class_open(dev_name(dev));
		put_device(dev);
	}
	if (!rtc) {
		printk(warn_no_rtc);
		return 0;
	}

	/* go for it */
	test_wakealarm(rtc, test_state);
	rtc_class_close(rtc);
	return 0;
}
Пример #17
0
static int __init rtc_hctosys(void)
{
	int err = -ENODEV;
	struct rtc_time tm;
	struct timespec tv = {
	        .tv_nsec = NSEC_PER_SEC >> 1,
	    };
	    struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);

	    if (rtc == NULL) {
	            pr_err("%s: unable to open rtc device (%s)\n",
	                    __FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
	            goto err_open;
	    }

	    {
	            if(!strcmp("rtc1",CONFIG_RTC_HCTOSYS_DEVICE))
	            {
	                    struct rtc_device *rtc0 = rtc_class_open("rtc0");
	                    if(rtc0 == NULL)
	                    {
	                            pr_err("!!!!!!Robin: %s: unable to open rtc0 device!!!!!\n",
	                      __FILE__);
	                    }
				printk("read rtc1 time\n");	
	                    err = rtc_read_time(rtc, &tm);
				printk("set  rtc1 time 2 rtc0\n");	
	                    rtc_set_time(rtc0,&tm);
	                    rtc_class_close(rtc0);
	            }
	    }
	    if (err)
	    {
	            err = rtc_read_time(rtc, &tm);
			printk("rtc_read_time error\n");	
	
	            if (err) {
	                    dev_err(rtc->dev.parent,
	                                    "hctosys: unable to read the hardware clock\n");
	                    goto err_read;

	            }
	    }

	    err = rtc_valid_tm(&tm);
	    if (err) {
	            dev_err(rtc->dev.parent,
	                    "hctosys: invalid date/time\n");
	            goto err_invalid;
	    }

	    rtc_tm_to_time(&tm, &tv.tv_sec);

	    do_settimeofday(&tv);

	    dev_info(rtc->dev.parent,
	            "setting system clock to "
	            "%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n",
	            tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,

	            tm.tm_hour, tm.tm_min, tm.tm_sec,
	            (unsigned int) tv.tv_sec);

	err_invalid:
	err_read:
	    rtc_class_close(rtc);

	err_open:
	    rtc_hctosys_ret = err;

	    return err;
}



#else
static int __init rtc_hctosys(void)
{
	int err = -ENODEV;
	struct rtc_time tm;
	struct timespec tv = {
		.tv_nsec = NSEC_PER_SEC >> 1,
	};
	struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);

	if (rtc == NULL) {
		pr_err("%s: unable to open rtc device (%s)\n",
			__FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
		goto err_open;
	}

	{
		if(strcmp("rtc0",CONFIG_RTC_HCTOSYS_DEVICE))
		{
			struct rtc_device *rtc0 = rtc_class_open("rtc0");
			if(rtc0 == NULL)
			{
				pr_err("!!!!!!Robin: %s: unable to open rtc0 device!!!!!\n",
			  __FILE__);
			}
			err = rtc_read_time(rtc, &tm);
			rtc_set_time(rtc0,&tm);
			rtc_class_close(rtc0);
		}	
	}
	if (err)
	{
		err = rtc_read_time(rtc, &tm);
		if (err) {
			dev_err(rtc->dev.parent,
					"hctosys: unable to read the hardware clock\n");
			goto err_read;

		}
	}

	err = rtc_valid_tm(&tm);
	if (err) {
		dev_err(rtc->dev.parent,
			"hctosys: invalid date/time\n");
		goto err_invalid;
	}

	rtc_tm_to_time(&tm, &tv.tv_sec);

	do_settimeofday(&tv);

	dev_info(rtc->dev.parent,
		"setting system clock to "
		"%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n",
		tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
		tm.tm_hour, tm.tm_min, tm.tm_sec,
		(unsigned int) tv.tv_sec);

err_invalid:
err_read:
	rtc_class_close(rtc);

err_open:
	rtc_hctosys_ret = err;

	return err;
}
#endif
late_initcall(rtc_hctosys);
Пример #18
0
static int __init rtc_hctosys(void)
{
	int err = -ENODEV;
	struct rtc_time tm;
	struct timespec tv = {
		.tv_nsec = NSEC_PER_SEC >> 1,
	};
	struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);

	if (rtc == NULL) {
		pr_err("%s: unable to open rtc device (%s)\n",
			__FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
		goto err_open;
	}

	err = rtc_read_time(rtc, &tm);
	if (err) {
		dev_err(rtc->dev.parent,
			"hctosys: unable to read the hardware clock\n");
		goto err_read;

	}

	err = rtc_valid_tm(&tm);
	if (err) {
		dev_err(rtc->dev.parent,
			"hctosys: invalid date/time\n");
		goto err_invalid;
	}

	rtc_tm_to_time(&tm, &tv.tv_sec);

	do_settimeofday(&tv);

	//                                                              
	#if 1
	{
		struct timespec ts;
		getnstimeofday(&ts);
		printk(KERN_UTC_BOOT "%d-%02d-%02d %02d:%02d:%02d.%06lu\n",
			tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
			tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec/1000);
	}
	#else
	//                                                            
	dev_info(rtc->dev.parent,
		"setting system clock to "
		"%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n",
		tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
		tm.tm_hour, tm.tm_min, tm.tm_sec,
		(unsigned int) tv.tv_sec);
	#endif

err_invalid:
err_read:
	rtc_class_close(rtc);

err_open:
	rtc_hctosys_ret = err;

	return err;
}

late_initcall(rtc_hctosys);
Пример #19
0
void  modem_time_sync(struct work_struct *work)
{
	int err = -ENODEV;
	struct rtc_time tm;
	struct timespec tv = {
		.tv_nsec = NSEC_PER_SEC >> 1,
	};
	struct timeval current_time;
	struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);

	if (rtc == NULL) {
		pr_err("%s: unable to open rtc device (%s)\n",
			__FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
		goto err_open;
	}

	do_gettimeofday(&current_time);

	err = rtc_read_time(rtc, &tm);
	if (err) {
		dev_err(rtc->dev.parent,
			"hctosys: unable to read the hardware clock\n");
		goto err_read;

	}

	err = rtc_valid_tm(&tm);
	if (err) {
		dev_err(rtc->dev.parent,
			"hctosys: invalid date/time\n");
		goto err_invalid;
	}

	rtc_tm_to_time(&tm, &tv.tv_sec);

	if((current_time.tv_sec - tv.tv_sec > 30) || (current_time.tv_sec - tv.tv_sec < -30) ) {
		do_settimeofday(&tv);
	}


err_invalid:
err_read:
	rtc_class_close(rtc);

err_open:
	rtc_hctosys_ret = err;

	schedule_delayed_work(&time_sync_work, HZ*30);
}

int modem_time_sync_init(void)
{
	static bool first = true;
	if(first) {
		INIT_DELAYED_WORK(&time_sync_work, modem_time_sync);
		schedule_delayed_work(&time_sync_work, HZ*30);
		first = false;
	}
	return 0;
}
#endif
/*[ECID:000000] ZTEBSP zhangbo, sync time with modem, end*/


int rtc_hctosys(void)
{
	int err = -ENODEV;
	struct rtc_time tm;
	struct timespec tv = {
		.tv_nsec = NSEC_PER_SEC >> 1,
	};
	struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);

	/*[ECID:000000] ZTEBSP zhangbo, sync time with modem, start*/
	#ifdef CONFIG_ZTE_TIME_SYNC_WITH_MODEM
	modem_time_sync_init();
	#endif
	/*[ECID:000000] ZTEBSP zhangbo, sync time with modem, end*/
	
	if (rtc == NULL) {
		pr_err("%s: unable to open rtc device (%s)\n",
			__FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
		goto err_open;
	}

	err = rtc_read_time(rtc, &tm);
	if (err) {
		dev_err(rtc->dev.parent,
			"hctosys: unable to read the hardware clock\n");
		goto err_read;

	}

	err = rtc_valid_tm(&tm);
	if (err) {
		dev_err(rtc->dev.parent,
			"hctosys: invalid date/time\n");
		goto err_invalid;
	}

	rtc_tm_to_time(&tm, &tv.tv_sec);

	do_settimeofday(&tv);
	//[ECID:0000]ZTE_BSP maxiaoping 20121030 modify PLATFORM 8064 RTC alarm driver for power_off alarm,start.
	#ifdef CONFIG_ZTE_FIX_ALARM_SYNC
		fix_sync_alarm();
	#endif
	//[ECID:0000]ZTE_BSP maxiaoping 20121030 modify PLATFORM 8064 RTC alarm driver for power_off alarm,end.
	
	dev_info(rtc->dev.parent,
		"setting system clock to "
		"%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n",
		tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
		tm.tm_hour, tm.tm_min, tm.tm_sec,
		(unsigned int) tv.tv_sec);

err_invalid:
err_read:
	rtc_class_close(rtc);

err_open:
	rtc_hctosys_ret = err;

	return err;
}

late_initcall(rtc_hctosys);