/* * NOTE: M48T59 only uses BCD mode */ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm) { struct platform_device *pdev = to_platform_device(dev); struct m48t59_plat_data *pdata = pdev->dev.platform_data; struct m48t59_private *m48t59 = platform_get_drvdata(pdev); unsigned long flags; u8 val; spin_lock_irqsave(&m48t59->lock, flags); /* Issue the READ command */ M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)); /* tm_mon is 0-11 */ tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1; tm->tm_mday = bcd2bin(M48T59_READ(M48T59_MDAY)); val = M48T59_READ(M48T59_WDAY); if ((pdata->type == M48T59RTC_TYPE_M48T59) && (val & M48T59_WDAY_CEB) && (val & M48T59_WDAY_CB)) { dev_dbg(dev, "Century bit is enabled\n"); tm->tm_year += 100; /* one century */ } #ifdef CONFIG_SPARC /* Sun SPARC machines count years since 1968 */ tm->tm_year += 68; #endif tm->tm_wday = bcd2bin(val & 0x07); tm->tm_hour = bcd2bin(M48T59_READ(M48T59_HOUR) & 0x3F); tm->tm_min = bcd2bin(M48T59_READ(M48T59_MIN) & 0x7F); tm->tm_sec = bcd2bin(M48T59_READ(M48T59_SEC) & 0x7F); /* Clear the READ bit */ M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL); spin_unlock_irqrestore(&m48t59->lock, flags); dev_dbg(dev, "RTC read time %04d-%02d-%02d %02d/%02d/%02d\n", tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); return rtc_valid_tm(tm); }
static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) { unsigned int have_retried = 0; void __iomem *base = s3c_rtc_base; clk_enable(rtc_clk); retry_get_time: rtc_tm->tm_min = readb(base + S3C2410_RTCMIN); rtc_tm->tm_hour = readb(base + S3C2410_RTCHOUR); rtc_tm->tm_mday = readb(base + S3C2410_RTCDATE); rtc_tm->tm_mon = readb(base + S3C2410_RTCMON); rtc_tm->tm_year = readb(base + S3C2410_RTCYEAR); rtc_tm->tm_sec = readb(base + S3C2410_RTCSEC); /* the only way to work out whether the system was mid-update * when we read it is to check the second counter, and if it * is zero, then we re-try the entire read */ if (rtc_tm->tm_sec == 0 && !have_retried) { have_retried = 1; goto retry_get_time; } rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min); rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour); rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday); rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); rtc_tm->tm_year += 100; dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); rtc_tm->tm_mon -= 1; clk_disable(rtc_clk); return rtc_valid_tm(rtc_tm); }
/* * In order to set the CMOS clock precisely, set_rtc_mmss has to be * called 500 ms after the second nowtime has started, because when * nowtime is written into the registers of the CMOS clock, it will * jump to the next second precisely 500 ms later. Check the Motorola * MC146818A or Dallas DS12887 data sheet for details. */ int mach_set_rtc_mmss(const struct timespec *now) { unsigned long nowtime = now->tv_sec; struct rtc_time tm; int retval = 0; rtc_time_to_tm(nowtime, &tm); if (!rtc_valid_tm(&tm)) { retval = set_rtc_time(&tm); if (retval) printk(KERN_ERR "%s: RTC write failed with error %d\n", __func__, retval); } else { printk(KERN_ERR "%s: Invalid RTC value: write of %lx to RTC failed\n", __func__, nowtime); retval = -EINVAL; } return retval; }
static int da9052_read_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) { int ret; uint8_t v[5]; ret = da9052_group_read(rtc->da9052, DA9052_ALARM_MI_REG, 5, v); if (ret != 0) { rtc_err(rtc, "Failed to group read ALM: %d\n", ret); return ret; } rtc_tm->tm_year = (v[4] & DA9052_RTC_YEAR) + 100; rtc_tm->tm_mon = (v[3] & DA9052_RTC_MONTH) - 1; rtc_tm->tm_mday = v[2] & DA9052_RTC_DAY; rtc_tm->tm_hour = v[1] & DA9052_RTC_HOUR; rtc_tm->tm_min = v[0] & DA9052_RTC_MIN; ret = rtc_valid_tm(rtc_tm); return ret; }
static int isl12057_rtc_read_time(struct device *dev, struct rtc_time *tm) { struct isl12057_rtc_data *data = dev_get_drvdata(dev); u8 regs[ISL12057_RTC_SEC_LEN]; int ret; mutex_lock(&data->lock); ret = regmap_bulk_read(data->regmap, ISL12057_REG_RTC_SC, regs, ISL12057_RTC_SEC_LEN); mutex_unlock(&data->lock); if (ret) { dev_err(dev, "%s: RTC read failed\n", __func__); return ret; } isl12057_rtc_regs_to_tm(tm, regs); return rtc_valid_tm(tm); }
static int da9055_read_alarm(struct da9055 *da9055, struct rtc_time *rtc_tm) { int ret; uint8_t v[5]; ret = da9055_group_read(da9055, DA9055_REG_ALARM_MI, 5, v); if (ret != 0) { dev_err(da9055->dev, "Failed to group read ALM: %d\n", ret); return ret; } rtc_tm->tm_year = (v[4] & DA9055_RTC_ALM_YEAR) + 100; rtc_tm->tm_mon = (v[3] & DA9055_RTC_ALM_MONTH) - 1; rtc_tm->tm_mday = v[2] & DA9055_RTC_ALM_DAY; rtc_tm->tm_hour = v[1] & DA9055_RTC_ALM_HOUR; rtc_tm->tm_min = v[0] & DA9055_RTC_ALM_MIN; rtc_tm->tm_sec = 0; return rtc_valid_tm(rtc_tm); }
static int ds1343_read_time(struct device *dev, struct rtc_time *dt) { struct ds1343_priv *priv = dev_get_drvdata(dev); unsigned char buf[7]; int res; res = regmap_bulk_read(priv->map, DS1343_SECONDS_REG, buf, 7); if (res) return res; dt->tm_sec = bcd2bin(buf[0]); dt->tm_min = bcd2bin(buf[1]); dt->tm_hour = bcd2bin(buf[2] & 0x3F); dt->tm_wday = bcd2bin(buf[3]) - 1; dt->tm_mday = bcd2bin(buf[4]); dt->tm_mon = bcd2bin(buf[5] & 0x1F) - 1; dt->tm_year = bcd2bin(buf[6]) + 100; /* year offset from 1900 */ return rtc_valid_tm(dt); }
static int max8997_rtc_read_time(struct device *dev, struct rtc_time *tm) { struct max8997_rtc_info *info = dev_get_drvdata(dev); u8 data[RTC_NR_TIME]; int ret; mutex_lock(&info->lock); ret = max8997_bulk_read(info->rtc, MAX8997_RTC_SEC, RTC_NR_TIME, data); mutex_unlock(&info->lock); if (ret < 0) { dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__, ret); return ret; } max8997_rtc_data_to_tm(data, tm, info->rtc_24hr_mode); return rtc_valid_tm(tm); }
static int m41st85w_read_time(struct device *dev, struct rtc_time *dt) { struct i2c_client *client = to_i2c_client(dev); u8 buf[7]; int ret; unsigned int year, month, day, week, hour, minute, second; ret = i2c_smbus_read_i2c_block_data(client, 0x01, 7, buf); if (ret < 0) return ret; if (ret < 7) return -EIO; second = buf[0]; minute = buf[1]; hour = buf[2]; week = buf[3]; day = buf[4]; month = buf[5]; year = buf[6]; dt->tm_sec = bcd2bin(second & 0x7f); dt->tm_min = bcd2bin(minute & 0x7f); dt->tm_hour = bcd2bin(hour & 0x3f); dt->tm_wday = bcd2bin(week & 0x07); dt->tm_mday = bcd2bin(day & 0x7f); dt->tm_mon = bcd2bin(month & 0x3f); dt->tm_year = bcd2bin(year); /* fix up values */ /* dt->tm_mon is zero-based */ dt->tm_mon--; /* year is 1900 + dt->tm_year */ if (dt->tm_year < 95) dt->tm_year += 100; dt->tm_isdst = 0; return rtc_valid_tm(dt); }
static int m48t35_read_time(struct device *dev, struct rtc_time *tm) { struct m48t35_priv *priv = dev_get_drvdata(dev); u8 control; /* * Only the values that we read from the RTC are set. We leave * tm_wday, tm_yday and tm_isdst untouched. Even though the * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated * by the RTC when initially set to a non-zero value. */ spin_lock_irq(&priv->lock); control = readb(&priv->reg->control); writeb(control | M48T35_RTC_READ, &priv->reg->control); tm->tm_sec = readb(&priv->reg->sec); tm->tm_min = readb(&priv->reg->min); tm->tm_hour = readb(&priv->reg->hour); tm->tm_mday = readb(&priv->reg->date); tm->tm_mon = readb(&priv->reg->month); tm->tm_year = readb(&priv->reg->year); writeb(control, &priv->reg->control); spin_unlock_irq(&priv->lock); tm->tm_sec = bcd2bin(tm->tm_sec); tm->tm_min = bcd2bin(tm->tm_min); tm->tm_hour = bcd2bin(tm->tm_hour); tm->tm_mday = bcd2bin(tm->tm_mday); tm->tm_mon = bcd2bin(tm->tm_mon); tm->tm_year = bcd2bin(tm->tm_year); /* * Account for differences between how the RTC uses the values * and how they are defined in a struct rtc_time; */ tm->tm_year += 70; if (tm->tm_year <= 69) tm->tm_year += 100; tm->tm_mon--; return rtc_valid_tm(tm); }
static int asm9260_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) { struct asm9260_rtc_priv *priv = dev_get_drvdata(dev); unsigned long irq_flags; spin_lock_irqsave(&priv->lock, irq_flags); alrm->time.tm_year = ioread32(priv->iobase + HW_ALYEAR); alrm->time.tm_mon = ioread32(priv->iobase + HW_ALMON); alrm->time.tm_mday = ioread32(priv->iobase + HW_ALDOM); alrm->time.tm_wday = ioread32(priv->iobase + HW_ALDOW); alrm->time.tm_yday = ioread32(priv->iobase + HW_ALDOY); alrm->time.tm_hour = ioread32(priv->iobase + HW_ALHOUR); alrm->time.tm_min = ioread32(priv->iobase + HW_ALMIN); alrm->time.tm_sec = ioread32(priv->iobase + HW_ALSEC); alrm->enabled = ioread32(priv->iobase + HW_AMR) ? 1 : 0; alrm->pending = ioread32(priv->iobase + HW_CIIR) ? 1 : 0; spin_unlock_irqrestore(&priv->lock, irq_flags); return rtc_valid_tm(&alrm->time); }
static int mpc5121_rtc_read_time(struct device *dev, struct rtc_time *tm) { struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev); struct mpc5121_rtc_regs __iomem *regs = rtc->regs; unsigned long now; /* * linux time is actual_time plus the offset saved in target_time */ now = in_be32(®s->actual_time) + in_be32(®s->target_time); rtc_time_to_tm(now, tm); /* * update second minute hour registers * so alarms will work */ mpc5121_rtc_update_smh(regs, tm); return rtc_valid_tm(tm); }
static int mpc5121_rtc_read_time(struct device *dev, struct rtc_time *tm) { struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev); struct mpc5121_rtc_regs __iomem *regs = rtc->regs; unsigned long now; /* */ now = in_be32(®s->actual_time) + in_be32(®s->target_time); rtc_time_to_tm(now, tm); /* */ mpc5121_rtc_update_smh(regs, tm); return rtc_valid_tm(tm); }
static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm) { tm->tm_sec = bcd2bin(ds1302_readbyte(RTC_ADDR_SEC)); tm->tm_min = bcd2bin(ds1302_readbyte(RTC_ADDR_MIN)); tm->tm_hour = bcd2bin(ds1302_readbyte(RTC_ADDR_HOUR)); tm->tm_wday = bcd2bin(ds1302_readbyte(RTC_ADDR_DAY)); tm->tm_mday = bcd2bin(ds1302_readbyte(RTC_ADDR_DATE)); tm->tm_mon = bcd2bin(ds1302_readbyte(RTC_ADDR_MON)) - 1; tm->tm_year = bcd2bin(ds1302_readbyte(RTC_ADDR_YEAR)); if (tm->tm_year < 70) tm->tm_year += 100; dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, " "mday=%d, mon=%d, year=%d, wday=%d\n", __func__, tm->tm_sec, tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday); return rtc_valid_tm(tm); }
/* * rtc_time's year contains the increment over 1900, but vRTC's YEAR * register can't be programmed to value larger than 0x64, so vRTC * driver chose to use 1972 (1970 is UNIX time start point) as the base, * and does the translation at read/write time. * * Why not just use 1970 as the offset? it's because using 1972 will * make it consistent in leap year setting for both vrtc and low-level * physical rtc devices. Then why not use 1960 as the offset? If we use * 1960, for a device's first use, its YEAR register is 0 and the system * year will be parsed as 1960 which is not a valid UNIX time and will * cause many applications to fail mysteriously. */ static int mrst_read_time(struct device *dev, struct rtc_time *time) { unsigned long flags; if (vrtc_is_updating()) mdelay(20); spin_lock_irqsave(&rtc_lock, flags); time->tm_sec = vrtc_cmos_read(RTC_SECONDS); time->tm_min = vrtc_cmos_read(RTC_MINUTES); time->tm_hour = vrtc_cmos_read(RTC_HOURS); time->tm_mday = vrtc_cmos_read(RTC_DAY_OF_MONTH); time->tm_mon = vrtc_cmos_read(RTC_MONTH); time->tm_year = vrtc_cmos_read(RTC_YEAR); spin_unlock_irqrestore(&rtc_lock, flags); /* Adjust for the 1972/1900 */ time->tm_year += 72; time->tm_mon--; return rtc_valid_tm(time); }
static int pcf50633_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) { struct pcf50633_rtc *rtc; struct pcf50633_time pcf_tm; int ret = 0; rtc = dev_get_drvdata(dev); alrm->enabled = rtc->alarm_enabled; ret = pcf50633_read_block(rtc->pcf, PCF50633_REG_RTCSCA, PCF50633_TI_EXTENT, &pcf_tm.time[0]); if (ret != PCF50633_TI_EXTENT) { dev_err(dev, "Failed to read time\n"); return -EIO; } pcf2rtc_time(&alrm->time, &pcf_tm); return rtc_valid_tm(&alrm->time); }
/** * balong_rtc_setalarm-set rtc alarm */ s32 balong_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alarm) { s32 ret = 0; u32 alarmtime = 0; u32 currenttime = 0; u32 ccr_value = 0; balong_alarm_irq_enable(dev, ALARM_DISABLED); ret = rtc_valid_tm(&alarm->time); if (0 != ret) { rtc_print_error("balong rtc_valid_tm Fail!\n"); return BSP_ERROR; } ret = rtc_tm_to_time(&alarm->time, (unsigned long *)&alarmtime); if (0 != ret) { rtc_print_error("balong rtc_tm_to_time Fail!\n"); return BSP_ERROR; } currenttime = readl(g_rtc_ctrl.rtc_base_addr + HI_RTC_CCVR_OFFSET); if(currenttime <= alarmtime) { writel( alarmtime, g_rtc_ctrl.rtc_base_addr + HI_RTC_CMR_OFFSET); } else { rtc_print_error("the alarm time to be set is error.\r\n"); } ccr_value = readl(g_rtc_ctrl.rtc_base_addr + HI_RTC_CCR_OFFSET); writel( ccr_value|RTC_BIT_AI, g_rtc_ctrl.rtc_base_addr + HI_RTC_CCR_OFFSET); balong_alarm_irq_enable(dev, alarm->enabled); return BSP_OK; }
int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) { int err; err = rtc_valid_tm(tm); if (err != 0) return err; err = rtc_valid_range(rtc, tm); if (err) return err; rtc_subtract_offset(rtc, tm); err = mutex_lock_interruptible(&rtc->ops_lock); if (err) return err; if (!rtc->ops) err = -ENODEV; else if (rtc->ops->set_time) err = rtc->ops->set_time(rtc->dev.parent, tm); else if (rtc->ops->set_mmss64) { time64_t secs64 = rtc_tm_to_time64(tm); err = rtc->ops->set_mmss64(rtc->dev.parent, secs64); } else if (rtc->ops->set_mmss) { time64_t secs64 = rtc_tm_to_time64(tm); err = rtc->ops->set_mmss(rtc->dev.parent, secs64); } else err = -EINVAL; pm_stay_awake(rtc->dev.parent); mutex_unlock(&rtc->ops_lock); /* A timer might have just expired */ schedule_work(&rtc->irqwork); trace_rtc_set_time(rtc_tm_to_time64(tm), err); return err; }
static int stk17ta8_rtc_read_time(struct device *dev, struct rtc_time *tm) { struct platform_device *pdev = to_platform_device(dev); struct rtc_plat_data *pdata = platform_get_drvdata(pdev); void __iomem *ioaddr = pdata->ioaddr; unsigned int year, month, day, hour, minute, second, week; unsigned int century; u8 flags; /* give enough time to update RTC in case of continuous read */ if (pdata->last_jiffies == jiffies) msleep(1); pdata->last_jiffies = jiffies; flags = readb(pdata->ioaddr + RTC_FLAGS); writeb(flags | RTC_READ, ioaddr + RTC_FLAGS); second = readb(ioaddr + RTC_SECONDS) & RTC_SECONDS_MASK; minute = readb(ioaddr + RTC_MINUTES); hour = readb(ioaddr + RTC_HOURS); day = readb(ioaddr + RTC_DATE); week = readb(ioaddr + RTC_DAY) & RTC_DAY_MASK; month = readb(ioaddr + RTC_MONTH); year = readb(ioaddr + RTC_YEAR); century = readb(ioaddr + RTC_CENTURY); writeb(flags & ~RTC_READ, ioaddr + RTC_FLAGS); tm->tm_sec = BCD2BIN(second); tm->tm_min = BCD2BIN(minute); tm->tm_hour = BCD2BIN(hour); tm->tm_mday = BCD2BIN(day); tm->tm_wday = BCD2BIN(week); tm->tm_mon = BCD2BIN(month) - 1; /* year is 1900 + tm->tm_year */ tm->tm_year = BCD2BIN(year) + BCD2BIN(century) * 100 - 1900; if (rtc_valid_tm(tm) < 0) { dev_err(dev, "retrieved date/time is not valid.\n"); rtc_time_to_tm(0, tm); } return 0; }
static int cpcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) { struct cpcap_rtc *rtc; struct cpcap_time cpcap_tm; int ret; rtc = dev_get_drvdata(dev); alrm->enabled = rtc->alarm_enabled; ret = regmap_read(rtc->regmap, CPCAP_REG_DAYA, &cpcap_tm.day); ret |= regmap_read(rtc->regmap, CPCAP_REG_TODA2, &cpcap_tm.tod2); ret |= regmap_read(rtc->regmap, CPCAP_REG_TODA1, &cpcap_tm.tod1); if (ret) { dev_err(dev, "Failed to read time\n"); return -EIO; } cpcap2rtc_time(&alrm->time, &cpcap_tm); return rtc_valid_tm(&alrm->time); }
static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) { int err; if (!rtc->ops) err = -ENODEV; else if (!rtc->ops->read_time) err = -EINVAL; else { memset(tm, 0, sizeof(struct rtc_time)); err = rtc->ops->read_time(rtc->dev.parent, tm); if (err < 0) { dev_dbg(&rtc->dev, "read_time: fail to read: %d\n", err); return err; } err = rtc_valid_tm(tm); if (err < 0) dev_dbg(&rtc->dev, "read_time: rtc_time isn't valid\n"); } return err; }
int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) { int err; err = rtc_valid_tm(&alarm->time); if (err != 0) return err; err = mutex_lock_interruptible(&rtc->ops_lock); if (err) return err; if (rtc->aie_timer.enabled) rtc_timer_remove(rtc, &rtc->aie_timer); rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time); rtc->aie_timer.period = 0; if (alarm->enabled) err = rtc_timer_enqueue(rtc, &rtc->aie_timer); mutex_unlock(&rtc->ops_lock); return err; }
static int imap_rtc_resume(struct platform_device *pdev) { struct rtc_time tm = {.tm_sec = 0,}; struct timespec time; time.tv_nsec = 0; while(!tm.tm_sec) imap_rtc_gettime(&pdev->dev, &tm); rtc_tm_to_time(&tm, &time.tv_sec); if(!rtc_valid_tm(&tm)) do_settimeofday(&time); restore_time_delta(&imap_rtc_delta, &time); writeb(ticnt_save, imap_rtc_base + IMAPX200_TICNT); return 0; } #endif static struct platform_driver imap_rtc_driver = { .probe = imap_rtc_probe, .remove = imap_rtc_remove, #ifdef CONFIG_PM .suspend = imap_rtc_suspend, .resume = imap_rtc_resume, #endif .driver = { .name = "imapx200_rtc", .owner = THIS_MODULE, }, }; static int __init imap_rtc_init(void) { printk(KERN_INFO "iMAPx200 RTC, (c) 2009, 2014 InfoTM Microelctronics Co., Ltd\n"); return platform_driver_register(&imap_rtc_driver); }
static int s2mps11_rtc_read_time(struct device *dev, struct rtc_time *tm) { struct s2mps11_rtc_info *info = dev_get_drvdata(dev); u8 data[7]; int ret; ret = s2mps11_rtc_read_time_reg(info); if (ret < 0) return ret; ret = sec_rtc_bulk_read(info->iodev, S2MPS11_RTC_SEC, 7, data); if (ret < 0) return ret; s2mps11_data_to_tm(data, tm, info->rtc_24hr_mode); pr_debug("%s: %d/%d/%d %d:%d:%d(%d)\n", __func__, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_wday); return rtc_valid_tm(tm); }
static int da9052_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm) { struct da9052_rtc *rtc = dev_get_drvdata(dev); uint8_t v[6]; int ret; ret = da9052_group_read(rtc->da9052, DA9052_COUNT_S_REG, 6, v); if (ret < 0) { rtc_err(rtc, "Failed to read RTC time : %d\n", ret); return ret; } rtc_tm->tm_year = (v[5] & DA9052_RTC_YEAR) + 100; rtc_tm->tm_mon = (v[4] & DA9052_RTC_MONTH) - 1; rtc_tm->tm_mday = v[3] & DA9052_RTC_DAY; rtc_tm->tm_hour = v[2] & DA9052_RTC_HOUR; rtc_tm->tm_min = v[1] & DA9052_RTC_MIN; rtc_tm->tm_sec = v[0] & DA9052_RTC_SEC; ret = rtc_valid_tm(rtc_tm); return ret; }
static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) { struct rtc_time tm; time64_t now, scheduled; int err; err = rtc_valid_tm(&alarm->time); if (err) return err; scheduled = rtc_tm_to_time64(&alarm->time); /* Make sure we're not setting alarms in the past */ err = __rtc_read_time(rtc, &tm); if (err) return err; now = rtc_tm_to_time64(&tm); if (scheduled <= now) return -ETIME; /* * XXX - We just checked to make sure the alarm time is not * in the past, but there is still a race window where if * the is alarm set for the next second and the second ticks * over right here, before we set the alarm. */ rtc_subtract_offset(rtc, &alarm->time); if (!rtc->ops) err = -ENODEV; else if (!rtc->ops->set_alarm) err = -EINVAL; else err = rtc->ops->set_alarm(rtc->dev.parent, alarm); trace_rtc_set_alarm(rtc_tm_to_time64(&alarm->time), err); return err; }
static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) { unsigned int have_retried = 0; void __iomem *base = s3c_rtc_base; clk_enable(rtc_clk); retry_get_time: rtc_tm->tm_min = readb(base + S3C2410_RTCMIN); rtc_tm->tm_hour = readb(base + S3C2410_RTCHOUR); rtc_tm->tm_mday = readb(base + S3C2410_RTCDATE); rtc_tm->tm_mon = readb(base + S3C2410_RTCMON); rtc_tm->tm_year = readb(base + S3C2410_RTCYEAR); rtc_tm->tm_sec = readb(base + S3C2410_RTCSEC); if (rtc_tm->tm_sec == 0 && !have_retried) { have_retried = 1; goto retry_get_time; } rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min); rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour); rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday); rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); rtc_tm->tm_year += 100; pr_debug("read time %04d.%02d.%02d %02d:%02d:%02d\n", 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); rtc_tm->tm_mon -= 1; clk_disable(rtc_clk); return rtc_valid_tm(rtc_tm); }
static int mcp795_read_time(struct device *dev, struct rtc_time *tim) { int ret; u8 data[7]; ret = mcp795_rtcc_read(dev, 0x01, data, sizeof(data)); if (ret) return ret; tim->tm_sec = ((data[0] & 0x70) >> 4) * 10 + (data[0] & 0x0f); tim->tm_min = ((data[1] & 0x70) >> 4) * 10 + (data[1] & 0x0f); tim->tm_hour = ((data[2] & 0x30) >> 4) * 10 + (data[2] & 0x0f); tim->tm_mday = ((data[4] & 0x30) >> 4) * 10 + (data[4] & 0x0f); tim->tm_mon = ((data[5] & 0x10) >> 4) * 10 + (data[5] & 0x0f); tim->tm_year = ((data[6] & 0xf0) >> 4) * 10 + (data[6] & 0x0f) + 100; /* Assume we are in 20xx */ dev_dbg(dev, "Read from mcp795: %04d-%02d-%02d %02d:%02d:%02d\n", tim->tm_year + 1900, tim->tm_mon, tim->tm_mday, tim->tm_hour, tim->tm_min, tim->tm_sec); return rtc_valid_tm(tim); }
static int ds3234_read_time(struct device *dev, struct rtc_time *dt) { int err; unsigned char buf[8]; struct spi_device *spi = to_spi_device(dev); buf[0] = 0x00; /* Start address */ err = spi_write_then_read(spi, buf, 1, buf, 8); if (err != 0) return err; /* Seconds, Minutes, Hours, Day, Date, Month, Year */ dt->tm_sec = bcd2bin(buf[0]); dt->tm_min = bcd2bin(buf[1]); dt->tm_hour = bcd2bin(buf[2] & 0x3f); dt->tm_wday = bcd2bin(buf[3]) - 1; /* 0 = Sun */ dt->tm_mday = bcd2bin(buf[4]); dt->tm_mon = bcd2bin(buf[5] & 0x1f) - 1; /* 0 = Jan */ dt->tm_year = bcd2bin(buf[6] & 0xff) + 100; /* Assume 20YY */ return rtc_valid_tm(dt); }
static int ds1305_get_time(struct device *dev, struct rtc_time *time) { struct ds1305 *ds1305 = dev_get_drvdata(dev); u8 addr = DS1305_SEC; u8 buf[DS1305_RTC_LEN]; int status; /* Use write-then-read to get all the date/time registers * since dma from stack is nonportable */ status = spi_write_then_read(ds1305->spi, &addr, sizeof addr, buf, sizeof buf); if (status < 0) return status; dev_vdbg(dev, "%s: %02x %02x %02x, %02x %02x %02x %02x\n", "read", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); /* Decode the registers */ time->tm_sec = bcd2bin(buf[DS1305_SEC]); time->tm_min = bcd2bin(buf[DS1305_MIN]); time->tm_hour = bcd2hour(buf[DS1305_HOUR]); time->tm_wday = buf[DS1305_WDAY] - 1; time->tm_mday = bcd2bin(buf[DS1305_MDAY]); time->tm_mon = bcd2bin(buf[DS1305_MON]) - 1; time->tm_year = bcd2bin(buf[DS1305_YEAR]) + 100; dev_vdbg(dev, "%s secs=%d, mins=%d, " "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", "read", time->tm_sec, time->tm_min, time->tm_hour, time->tm_mday, time->tm_mon, time->tm_year, time->tm_wday); /* Time may not be set */ return rtc_valid_tm(time); }