static int dump_thread(void *data) { struct rtc_device *rtc; struct rtc_time tm; int err = 0; char log_file_name[100]; char backup_log_file_name[100]; pr_at_info("%s: Enter into dump_thread\n", __func__); /* Dump the last kernel log */ /* MX have two rtc devices */ rtc = rtc_class_open("rtc0"); if (rtc == NULL) { rtc = rtc_class_open("rtc1"); if (rtc == NULL) { pr_err(ATP "%s: can not open rtc devices\n", __func__); err = -ENODEV; } } if (!err) { err = rtc_read_time(rtc, &tm); if (err) pr_err(ATP "%s: unable to read the hardware clock\n", __func__); } sprintf(log_file_name, "%s-%d%02d%02d_%02d%02d%02d", CONFIG_LAST_KMSG_LOG_FILE, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour + 8, tm.tm_min, tm.tm_sec); pr_at_info("%s: Get log file name: %s\n", __func__, log_file_name); err = dump_last_kmsg(log_file_name); if (err) { pr_err(ATP "%s: Failed dump kernel log to %s\n", __func__, log_file_name); sprintf(backup_log_file_name, "%s-%d%02d%02d_%02d%02d%02d", CONFIG_BACKUP_LAST_KMSG_LOG_FILE, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour + 8, tm.tm_min, tm.tm_sec); pr_at_info("%s: Get backup log file name: %s\n", __func__, backup_log_file_name); err = dump_last_kmsg(backup_log_file_name); if (err) { pr_err(ATP "%s: Failed dump kernel log to %s\n", __func__, backup_log_file_name); goto out; } else { pr_at_info("%s: kernel log file dumped to %s\n", __func__, backup_log_file_name); } } else { pr_at_info("%s: kernel log file dumped to %s\n", __func__, log_file_name); } out: complete_and_exit(&dump, 0); return err; }
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; }
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; }
static int __init rtc_hctosys(void) { int err; struct rtc_time tm; struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); if (rtc == NULL) { printk("%s: unable to open rtc device (%s)\n", __FILE__, CONFIG_RTC_HCTOSYS_DEVICE); return -ENODEV; } err = rtc_read_time(rtc, &tm); if (err == 0) { err = rtc_valid_tm(&tm); if (err == 0) { struct timespec tv; tv.tv_nsec = NSEC_PER_SEC >> 1; rtc_tm_to_time(&tm, &tv.tv_sec); // 110 = 2010 - 1900 if( tm.tm_year < 110 && tm.tm_year > 0 ) { tm.tm_year = 110; tm.tm_mon = 11; rtc_set_time(rtc,&tm); tv.tv_nsec = NSEC_PER_SEC >> 1; rtc_tm_to_time(&tm, &tv.tv_sec); } else if( tm.tm_year == 110 && tm.tm_mon < 11 ){
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 am33xx_pm_rtc_setup(void) { struct device_node *np; np = of_find_node_by_name(NULL, "rtc"); if (of_device_is_available(np)) { omap_rtc = rtc_class_open("rtc0"); if (!omap_rtc) { pr_warn("PM: rtc0 not available"); return -EPROBE_DEFER; } rtc_read_scratch(omap_rtc, RTC_SCRATCH_MAGIC_REG, &rtc_magic_val); if ((rtc_magic_val & 0xffff) != RTC_REG_BOOT_MAGIC) pr_warn("PM: bootloader does not support rtc-only!\n"); pm_sram->rtc_base_virt = pm_ops->get_rtc_base_addr(); rtc_write_scratch(omap_rtc, RTC_SCRATCH_MAGIC_REG, 0); rtc_write_scratch(omap_rtc, RTC_SCRATCH_RESUME_REG, pm_sram->rtc_resume_phys_addr); } else { pr_warn("PM: no-rtc available, rtc-only mode disabled.\n"); } return 0; }
/** * alarmtimer_get_rtcdev - Return selected rtcdevice * * This function returns the rtc device to use for wakealarms. * If one has not already been chosen, it checks to see if a * functional rtc device is available. */ static struct rtc_device *alarmtimer_get_rtcdev(void) { struct device *dev; char *str; unsigned long flags; struct rtc_device *ret; spin_lock_irqsave(&rtcdev_lock, flags); if (!rtcdev) { /* Find an rtc device and init the rtc_timer */ dev = class_find_device(rtc_class, NULL, &str, has_wakealarm); /* If we have a device then str is valid. See has_wakealarm() */ if (dev) { rtcdev = rtc_class_open(str); /* * Drop the reference we got in class_find_device, * rtc_open takes its own. */ put_device(dev); rtc_timer_init(&rtctimer, NULL, NULL); } } ret = rtcdev; spin_unlock_irqrestore(&rtcdev_lock, flags); return ret; }
/* * this function syncs system time with RTC when startup * if there is valid time store in RTC static int rtc_hctosys(void) */ static int rtc_hctosys(void) { int err; struct rtc_time tm; struct rtc_device *rtc = rtc_class_open("rtc1"); if (rtc == NULL) { printk("%s: unable to open rtc device (rtc1) for rtc_hctosys\n", __FILE__); return -ENODEV; } err = rtc_read_time(rtc, &tm); if (err == 0) { err = rtc_valid_tm(&tm); if (err == 0) { struct timespec tv; tv.tv_nsec = NSEC_PER_SEC >> 1; 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); } else {
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);
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; }
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; }
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);
/** * 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; }
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; }
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; }
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);
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; }
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; }
int rtc_hctosys(void) { int err; struct rtc_time tm; struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); if (rtc == NULL) { printk("%s: unable to open rtc device (%s)\n", __FILE__, CONFIG_RTC_HCTOSYS_DEVICE); return -ENODEV; } err = rtc_read_time(rtc, &tm); if (err == 0) { err = rtc_valid_tm(&tm); if (err == 0) { struct timespec tv; #ifdef CONFIG_RTC_DRV_MSM struct timeval curtv; #endif tv.tv_nsec = NSEC_PER_SEC >> 1; rtc_tm_to_time(&tm, &tv.tv_sec); #ifdef CONFIG_RTC_DRV_MSM /* Only update kernel time if seconds changed.. otherwise this causes confusion with A2DP. RTC time is in seconds.. so every invocation of do_settimeofday() will cause cur ms to skip.. */ do_gettimeofday(&curtv); if ((tv.tv_sec > (curtv.tv_sec + 1)) || ((tv.tv_sec + 1) < curtv.tv_sec)) { #endif 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); #ifdef CONFIG_RTC_DRV_MSM } #endif } else
static int __devinit suspend_autotest_probe(struct platform_device *pdev) { int err; char *pony = NULL; pwr_dev = input_allocate_device(); if (!pwr_dev) { pr_err("Can't allocate suspend autotest power button\n"); err = -ENOMEM; goto err_alloc_dev; } input_set_capability(pwr_dev, EV_KEY, KEY_POWER); pwr_dev->name = "suspend_autotest_pwrkey"; pwr_dev->phys = "suspend_autotest_pwrkey/input0"; err = input_register_device(pwr_dev); if (err) { pr_err("%s: input_register_device err=%d\n", __func__, err); goto err_input_dev; } /* 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) { pr_info("%s: rtc class fail\n",__func__); goto err_input_dev; } wake_lock_init(&test_wake_lock, WAKE_LOCK_SUSPEND, "suspend_autotest"); register_early_suspend(&suspend_autotest_earlysuspend); test_mode = NONE; return 0; err_input_dev: input_free_device(pwr_dev); err_alloc_dev: return err; }
static int rtc_work_check() { struct device *dev; struct rtc_device *rtc = NULL; struct timespec ktime, adjust_ktime; struct timespec check_delta; struct rtc_time tm; struct timespec rtime; printk(KERN_ERR "%s\n", __func__); rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); if (rtc!=NULL){ getnstimeofday(&ktime); // kernel_time rtc_read_time(rtc, &tm); rtc_tm_to_time(&tm, &rtime.tv_sec); // rtc_time rtc_tm_to_time(&tm, &adjust_ktime.tv_sec); /* RTC precision is 1 second; adjust delta for avg 1/2 sec err */ set_normalized_timespec(&check_delta, ktime.tv_sec - rtime.tv_sec, ktime.tv_nsec - (NSEC_PER_SEC >> 1)); if(abs(check_delta.tv_sec) >= 3) { printk(KERN_ERR "%s: 1 k_t: %10d\n", __func__, ktime.tv_sec); printk(KERN_ERR "%s: 2 r_t: %10d\n", __func__, rtime.tv_sec); printk(KERN_ERR "%s: 3 check_delta s: %3d, s: %10d \n", __func__, check_delta.tv_sec, check_delta.tv_nsec); printk(KERN_ERR "%s: 4 old_delta s: %3d, s: %10d \n", __func__, old_delta.tv_sec, old_delta.tv_nsec); adjust_ktime.tv_nsec = 0; do_settimeofday(&adjust_ktime); rtc_read_time(rtc, &tm); //request by QC getnstimeofday(&adjust_ktime); printk(KERN_ERR "%s: 5 adjust k time is set as: %10d\n", __func__, adjust_ktime.tv_sec); set_normalized_timespec(&old_delta, adjust_ktime.tv_sec - rtime.tv_sec, adjust_ktime.tv_nsec - (NSEC_PER_SEC >> 1)); printk(KERN_ERR "%s: 5 re-set delta, s:%3d, n:%10d\n", __func__, old_delta.tv_sec,old_delta.tv_nsec); }
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; }
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);
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);
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(¤t_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);
static int __init rtc_hctosys(void) { int err, rtc_init = 0; struct rtc_time tm; struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); if (rtc == NULL) { printk("%s: unable to open rtc device (%s)\n", __FILE__, CONFIG_RTC_HCTOSYS_DEVICE); return -ENODEV; } err = rtc_read_time(rtc, &tm); #if 1 // charles debug printk("============== RTC Debug Param =================\n"); printk("tm_year = %d\n", tm.tm_year); printk("tm_mon = %d\n", tm.tm_mon); printk("tm_mday = %d\n", tm.tm_mday); printk("tm_hour = %d\n", tm.tm_hour); printk("tm_min = %d\n", tm.tm_min); printk("tm_sec = %d\n", tm.tm_sec); printk("================================================\n"); #endif // android system time valid check, // rtc read time is invalid, set to default system time 2010, jan, 1, 00:00:00 if((tm.tm_year+1900)<=1970 || (tm.tm_year+1900)>2037) { printk("%s[%d]: invalid system time -> set to default system time.. \n", __FILE__,__LINE__); rtc_init = 1; } if (err == 0) { err = rtc_valid_tm(&tm); if(err || rtc_init) { // RTC default value setting (2010-01-01, 0:0:0) tm.tm_year = 110; tm.tm_mon = 0; tm.tm_mday = 1; tm.tm_hour = 0; tm.tm_min = 0; tm.tm_sec = 0; err = rtc_valid_tm(&tm); if(err == 0) { printk("============== RTC set to default system time =================\n"); printk("tm_year = %d\n", tm.tm_year); printk("tm_mon = %d\n", tm.tm_mon); printk("tm_mday = %d\n", tm.tm_mday); printk("tm_hour = %d\n", tm.tm_hour); printk("tm_min = %d\n", tm.tm_min); printk("tm_sec = %d\n", tm.tm_sec); printk("===============================================================\n"); rtc_set_time(rtc, &tm); } } if (err == 0) { struct timespec tv; tv.tv_nsec = NSEC_PER_SEC >> 1; 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); } else