18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * An rtc driver for the Dallas DS1553 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2006 Atsushi Nemoto <anemo@mba.ocn.ne.jp> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/bcd.h> 98c2ecf20Sopenharmony_ci#include <linux/init.h> 108c2ecf20Sopenharmony_ci#include <linux/kernel.h> 118c2ecf20Sopenharmony_ci#include <linux/gfp.h> 128c2ecf20Sopenharmony_ci#include <linux/delay.h> 138c2ecf20Sopenharmony_ci#include <linux/jiffies.h> 148c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 158c2ecf20Sopenharmony_ci#include <linux/rtc.h> 168c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 178c2ecf20Sopenharmony_ci#include <linux/io.h> 188c2ecf20Sopenharmony_ci#include <linux/module.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define RTC_REG_SIZE 0x2000 218c2ecf20Sopenharmony_ci#define RTC_OFFSET 0x1ff0 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define RTC_FLAGS (RTC_OFFSET + 0) 248c2ecf20Sopenharmony_ci#define RTC_SECONDS_ALARM (RTC_OFFSET + 2) 258c2ecf20Sopenharmony_ci#define RTC_MINUTES_ALARM (RTC_OFFSET + 3) 268c2ecf20Sopenharmony_ci#define RTC_HOURS_ALARM (RTC_OFFSET + 4) 278c2ecf20Sopenharmony_ci#define RTC_DATE_ALARM (RTC_OFFSET + 5) 288c2ecf20Sopenharmony_ci#define RTC_INTERRUPTS (RTC_OFFSET + 6) 298c2ecf20Sopenharmony_ci#define RTC_WATCHDOG (RTC_OFFSET + 7) 308c2ecf20Sopenharmony_ci#define RTC_CONTROL (RTC_OFFSET + 8) 318c2ecf20Sopenharmony_ci#define RTC_CENTURY (RTC_OFFSET + 8) 328c2ecf20Sopenharmony_ci#define RTC_SECONDS (RTC_OFFSET + 9) 338c2ecf20Sopenharmony_ci#define RTC_MINUTES (RTC_OFFSET + 10) 348c2ecf20Sopenharmony_ci#define RTC_HOURS (RTC_OFFSET + 11) 358c2ecf20Sopenharmony_ci#define RTC_DAY (RTC_OFFSET + 12) 368c2ecf20Sopenharmony_ci#define RTC_DATE (RTC_OFFSET + 13) 378c2ecf20Sopenharmony_ci#define RTC_MONTH (RTC_OFFSET + 14) 388c2ecf20Sopenharmony_ci#define RTC_YEAR (RTC_OFFSET + 15) 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#define RTC_CENTURY_MASK 0x3f 418c2ecf20Sopenharmony_ci#define RTC_SECONDS_MASK 0x7f 428c2ecf20Sopenharmony_ci#define RTC_DAY_MASK 0x07 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* Bits in the Control/Century register */ 458c2ecf20Sopenharmony_ci#define RTC_WRITE 0x80 468c2ecf20Sopenharmony_ci#define RTC_READ 0x40 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* Bits in the Seconds register */ 498c2ecf20Sopenharmony_ci#define RTC_STOP 0x80 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/* Bits in the Flags register */ 528c2ecf20Sopenharmony_ci#define RTC_FLAGS_AF 0x40 538c2ecf20Sopenharmony_ci#define RTC_FLAGS_BLF 0x10 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/* Bits in the Interrupts register */ 568c2ecf20Sopenharmony_ci#define RTC_INTS_AE 0x80 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistruct rtc_plat_data { 598c2ecf20Sopenharmony_ci struct rtc_device *rtc; 608c2ecf20Sopenharmony_ci void __iomem *ioaddr; 618c2ecf20Sopenharmony_ci unsigned long last_jiffies; 628c2ecf20Sopenharmony_ci int irq; 638c2ecf20Sopenharmony_ci unsigned int irqen; 648c2ecf20Sopenharmony_ci int alrm_sec; 658c2ecf20Sopenharmony_ci int alrm_min; 668c2ecf20Sopenharmony_ci int alrm_hour; 678c2ecf20Sopenharmony_ci int alrm_mday; 688c2ecf20Sopenharmony_ci spinlock_t lock; 698c2ecf20Sopenharmony_ci}; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistatic int ds1553_rtc_set_time(struct device *dev, struct rtc_time *tm) 728c2ecf20Sopenharmony_ci{ 738c2ecf20Sopenharmony_ci struct rtc_plat_data *pdata = dev_get_drvdata(dev); 748c2ecf20Sopenharmony_ci void __iomem *ioaddr = pdata->ioaddr; 758c2ecf20Sopenharmony_ci u8 century; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci century = bin2bcd((tm->tm_year + 1900) / 100); 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci writeb(RTC_WRITE, pdata->ioaddr + RTC_CONTROL); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci writeb(bin2bcd(tm->tm_year % 100), ioaddr + RTC_YEAR); 828c2ecf20Sopenharmony_ci writeb(bin2bcd(tm->tm_mon + 1), ioaddr + RTC_MONTH); 838c2ecf20Sopenharmony_ci writeb(bin2bcd(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY); 848c2ecf20Sopenharmony_ci writeb(bin2bcd(tm->tm_mday), ioaddr + RTC_DATE); 858c2ecf20Sopenharmony_ci writeb(bin2bcd(tm->tm_hour), ioaddr + RTC_HOURS); 868c2ecf20Sopenharmony_ci writeb(bin2bcd(tm->tm_min), ioaddr + RTC_MINUTES); 878c2ecf20Sopenharmony_ci writeb(bin2bcd(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS); 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci /* RTC_CENTURY and RTC_CONTROL share same register */ 908c2ecf20Sopenharmony_ci writeb(RTC_WRITE | (century & RTC_CENTURY_MASK), ioaddr + RTC_CENTURY); 918c2ecf20Sopenharmony_ci writeb(century & RTC_CENTURY_MASK, ioaddr + RTC_CONTROL); 928c2ecf20Sopenharmony_ci return 0; 938c2ecf20Sopenharmony_ci} 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_cistatic int ds1553_rtc_read_time(struct device *dev, struct rtc_time *tm) 968c2ecf20Sopenharmony_ci{ 978c2ecf20Sopenharmony_ci struct rtc_plat_data *pdata = dev_get_drvdata(dev); 988c2ecf20Sopenharmony_ci void __iomem *ioaddr = pdata->ioaddr; 998c2ecf20Sopenharmony_ci unsigned int year, month, day, hour, minute, second, week; 1008c2ecf20Sopenharmony_ci unsigned int century; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci /* give enough time to update RTC in case of continuous read */ 1038c2ecf20Sopenharmony_ci if (pdata->last_jiffies == jiffies) 1048c2ecf20Sopenharmony_ci msleep(1); 1058c2ecf20Sopenharmony_ci pdata->last_jiffies = jiffies; 1068c2ecf20Sopenharmony_ci writeb(RTC_READ, ioaddr + RTC_CONTROL); 1078c2ecf20Sopenharmony_ci second = readb(ioaddr + RTC_SECONDS) & RTC_SECONDS_MASK; 1088c2ecf20Sopenharmony_ci minute = readb(ioaddr + RTC_MINUTES); 1098c2ecf20Sopenharmony_ci hour = readb(ioaddr + RTC_HOURS); 1108c2ecf20Sopenharmony_ci day = readb(ioaddr + RTC_DATE); 1118c2ecf20Sopenharmony_ci week = readb(ioaddr + RTC_DAY) & RTC_DAY_MASK; 1128c2ecf20Sopenharmony_ci month = readb(ioaddr + RTC_MONTH); 1138c2ecf20Sopenharmony_ci year = readb(ioaddr + RTC_YEAR); 1148c2ecf20Sopenharmony_ci century = readb(ioaddr + RTC_CENTURY) & RTC_CENTURY_MASK; 1158c2ecf20Sopenharmony_ci writeb(0, ioaddr + RTC_CONTROL); 1168c2ecf20Sopenharmony_ci tm->tm_sec = bcd2bin(second); 1178c2ecf20Sopenharmony_ci tm->tm_min = bcd2bin(minute); 1188c2ecf20Sopenharmony_ci tm->tm_hour = bcd2bin(hour); 1198c2ecf20Sopenharmony_ci tm->tm_mday = bcd2bin(day); 1208c2ecf20Sopenharmony_ci tm->tm_wday = bcd2bin(week); 1218c2ecf20Sopenharmony_ci tm->tm_mon = bcd2bin(month) - 1; 1228c2ecf20Sopenharmony_ci /* year is 1900 + tm->tm_year */ 1238c2ecf20Sopenharmony_ci tm->tm_year = bcd2bin(year) + bcd2bin(century) * 100 - 1900; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci return 0; 1268c2ecf20Sopenharmony_ci} 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistatic void ds1553_rtc_update_alarm(struct rtc_plat_data *pdata) 1298c2ecf20Sopenharmony_ci{ 1308c2ecf20Sopenharmony_ci void __iomem *ioaddr = pdata->ioaddr; 1318c2ecf20Sopenharmony_ci unsigned long flags; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci spin_lock_irqsave(&pdata->lock, flags); 1348c2ecf20Sopenharmony_ci writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? 1358c2ecf20Sopenharmony_ci 0x80 : bin2bcd(pdata->alrm_mday), 1368c2ecf20Sopenharmony_ci ioaddr + RTC_DATE_ALARM); 1378c2ecf20Sopenharmony_ci writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ? 1388c2ecf20Sopenharmony_ci 0x80 : bin2bcd(pdata->alrm_hour), 1398c2ecf20Sopenharmony_ci ioaddr + RTC_HOURS_ALARM); 1408c2ecf20Sopenharmony_ci writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ? 1418c2ecf20Sopenharmony_ci 0x80 : bin2bcd(pdata->alrm_min), 1428c2ecf20Sopenharmony_ci ioaddr + RTC_MINUTES_ALARM); 1438c2ecf20Sopenharmony_ci writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ? 1448c2ecf20Sopenharmony_ci 0x80 : bin2bcd(pdata->alrm_sec), 1458c2ecf20Sopenharmony_ci ioaddr + RTC_SECONDS_ALARM); 1468c2ecf20Sopenharmony_ci writeb(pdata->irqen ? RTC_INTS_AE : 0, ioaddr + RTC_INTERRUPTS); 1478c2ecf20Sopenharmony_ci readb(ioaddr + RTC_FLAGS); /* clear interrupts */ 1488c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pdata->lock, flags); 1498c2ecf20Sopenharmony_ci} 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistatic int ds1553_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 1528c2ecf20Sopenharmony_ci{ 1538c2ecf20Sopenharmony_ci struct rtc_plat_data *pdata = dev_get_drvdata(dev); 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci if (pdata->irq <= 0) 1568c2ecf20Sopenharmony_ci return -EINVAL; 1578c2ecf20Sopenharmony_ci pdata->alrm_mday = alrm->time.tm_mday; 1588c2ecf20Sopenharmony_ci pdata->alrm_hour = alrm->time.tm_hour; 1598c2ecf20Sopenharmony_ci pdata->alrm_min = alrm->time.tm_min; 1608c2ecf20Sopenharmony_ci pdata->alrm_sec = alrm->time.tm_sec; 1618c2ecf20Sopenharmony_ci if (alrm->enabled) 1628c2ecf20Sopenharmony_ci pdata->irqen |= RTC_AF; 1638c2ecf20Sopenharmony_ci ds1553_rtc_update_alarm(pdata); 1648c2ecf20Sopenharmony_ci return 0; 1658c2ecf20Sopenharmony_ci} 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistatic int ds1553_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 1688c2ecf20Sopenharmony_ci{ 1698c2ecf20Sopenharmony_ci struct rtc_plat_data *pdata = dev_get_drvdata(dev); 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci if (pdata->irq <= 0) 1728c2ecf20Sopenharmony_ci return -EINVAL; 1738c2ecf20Sopenharmony_ci alrm->time.tm_mday = pdata->alrm_mday < 0 ? 0 : pdata->alrm_mday; 1748c2ecf20Sopenharmony_ci alrm->time.tm_hour = pdata->alrm_hour < 0 ? 0 : pdata->alrm_hour; 1758c2ecf20Sopenharmony_ci alrm->time.tm_min = pdata->alrm_min < 0 ? 0 : pdata->alrm_min; 1768c2ecf20Sopenharmony_ci alrm->time.tm_sec = pdata->alrm_sec < 0 ? 0 : pdata->alrm_sec; 1778c2ecf20Sopenharmony_ci alrm->enabled = (pdata->irqen & RTC_AF) ? 1 : 0; 1788c2ecf20Sopenharmony_ci return 0; 1798c2ecf20Sopenharmony_ci} 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_cistatic irqreturn_t ds1553_rtc_interrupt(int irq, void *dev_id) 1828c2ecf20Sopenharmony_ci{ 1838c2ecf20Sopenharmony_ci struct platform_device *pdev = dev_id; 1848c2ecf20Sopenharmony_ci struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 1858c2ecf20Sopenharmony_ci void __iomem *ioaddr = pdata->ioaddr; 1868c2ecf20Sopenharmony_ci unsigned long events = 0; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci spin_lock(&pdata->lock); 1898c2ecf20Sopenharmony_ci /* read and clear interrupt */ 1908c2ecf20Sopenharmony_ci if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_AF) { 1918c2ecf20Sopenharmony_ci events = RTC_IRQF; 1928c2ecf20Sopenharmony_ci if (readb(ioaddr + RTC_SECONDS_ALARM) & 0x80) 1938c2ecf20Sopenharmony_ci events |= RTC_UF; 1948c2ecf20Sopenharmony_ci else 1958c2ecf20Sopenharmony_ci events |= RTC_AF; 1968c2ecf20Sopenharmony_ci rtc_update_irq(pdata->rtc, 1, events); 1978c2ecf20Sopenharmony_ci } 1988c2ecf20Sopenharmony_ci spin_unlock(&pdata->lock); 1998c2ecf20Sopenharmony_ci return events ? IRQ_HANDLED : IRQ_NONE; 2008c2ecf20Sopenharmony_ci} 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_cistatic int ds1553_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 2038c2ecf20Sopenharmony_ci{ 2048c2ecf20Sopenharmony_ci struct rtc_plat_data *pdata = dev_get_drvdata(dev); 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci if (pdata->irq <= 0) 2078c2ecf20Sopenharmony_ci return -EINVAL; 2088c2ecf20Sopenharmony_ci if (enabled) 2098c2ecf20Sopenharmony_ci pdata->irqen |= RTC_AF; 2108c2ecf20Sopenharmony_ci else 2118c2ecf20Sopenharmony_ci pdata->irqen &= ~RTC_AF; 2128c2ecf20Sopenharmony_ci ds1553_rtc_update_alarm(pdata); 2138c2ecf20Sopenharmony_ci return 0; 2148c2ecf20Sopenharmony_ci} 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_cistatic const struct rtc_class_ops ds1553_rtc_ops = { 2178c2ecf20Sopenharmony_ci .read_time = ds1553_rtc_read_time, 2188c2ecf20Sopenharmony_ci .set_time = ds1553_rtc_set_time, 2198c2ecf20Sopenharmony_ci .read_alarm = ds1553_rtc_read_alarm, 2208c2ecf20Sopenharmony_ci .set_alarm = ds1553_rtc_set_alarm, 2218c2ecf20Sopenharmony_ci .alarm_irq_enable = ds1553_rtc_alarm_irq_enable, 2228c2ecf20Sopenharmony_ci}; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_cistatic int ds1553_nvram_read(void *priv, unsigned int pos, void *val, 2258c2ecf20Sopenharmony_ci size_t bytes) 2268c2ecf20Sopenharmony_ci{ 2278c2ecf20Sopenharmony_ci struct platform_device *pdev = priv; 2288c2ecf20Sopenharmony_ci struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 2298c2ecf20Sopenharmony_ci void __iomem *ioaddr = pdata->ioaddr; 2308c2ecf20Sopenharmony_ci u8 *buf = val; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci for (; bytes; bytes--) 2338c2ecf20Sopenharmony_ci *buf++ = readb(ioaddr + pos++); 2348c2ecf20Sopenharmony_ci return 0; 2358c2ecf20Sopenharmony_ci} 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_cistatic int ds1553_nvram_write(void *priv, unsigned int pos, void *val, 2388c2ecf20Sopenharmony_ci size_t bytes) 2398c2ecf20Sopenharmony_ci{ 2408c2ecf20Sopenharmony_ci struct platform_device *pdev = priv; 2418c2ecf20Sopenharmony_ci struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 2428c2ecf20Sopenharmony_ci void __iomem *ioaddr = pdata->ioaddr; 2438c2ecf20Sopenharmony_ci u8 *buf = val; 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci for (; bytes; bytes--) 2468c2ecf20Sopenharmony_ci writeb(*buf++, ioaddr + pos++); 2478c2ecf20Sopenharmony_ci return 0; 2488c2ecf20Sopenharmony_ci} 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_cistatic int ds1553_rtc_probe(struct platform_device *pdev) 2518c2ecf20Sopenharmony_ci{ 2528c2ecf20Sopenharmony_ci unsigned int cen, sec; 2538c2ecf20Sopenharmony_ci struct rtc_plat_data *pdata; 2548c2ecf20Sopenharmony_ci void __iomem *ioaddr; 2558c2ecf20Sopenharmony_ci int ret = 0; 2568c2ecf20Sopenharmony_ci struct nvmem_config nvmem_cfg = { 2578c2ecf20Sopenharmony_ci .name = "ds1553_nvram", 2588c2ecf20Sopenharmony_ci .word_size = 1, 2598c2ecf20Sopenharmony_ci .stride = 1, 2608c2ecf20Sopenharmony_ci .size = RTC_OFFSET, 2618c2ecf20Sopenharmony_ci .reg_read = ds1553_nvram_read, 2628c2ecf20Sopenharmony_ci .reg_write = ds1553_nvram_write, 2638c2ecf20Sopenharmony_ci .priv = pdev, 2648c2ecf20Sopenharmony_ci }; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 2678c2ecf20Sopenharmony_ci if (!pdata) 2688c2ecf20Sopenharmony_ci return -ENOMEM; 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci ioaddr = devm_platform_ioremap_resource(pdev, 0); 2718c2ecf20Sopenharmony_ci if (IS_ERR(ioaddr)) 2728c2ecf20Sopenharmony_ci return PTR_ERR(ioaddr); 2738c2ecf20Sopenharmony_ci pdata->ioaddr = ioaddr; 2748c2ecf20Sopenharmony_ci pdata->irq = platform_get_irq(pdev, 0); 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci /* turn RTC on if it was not on */ 2778c2ecf20Sopenharmony_ci sec = readb(ioaddr + RTC_SECONDS); 2788c2ecf20Sopenharmony_ci if (sec & RTC_STOP) { 2798c2ecf20Sopenharmony_ci sec &= RTC_SECONDS_MASK; 2808c2ecf20Sopenharmony_ci cen = readb(ioaddr + RTC_CENTURY) & RTC_CENTURY_MASK; 2818c2ecf20Sopenharmony_ci writeb(RTC_WRITE, ioaddr + RTC_CONTROL); 2828c2ecf20Sopenharmony_ci writeb(sec, ioaddr + RTC_SECONDS); 2838c2ecf20Sopenharmony_ci writeb(cen & RTC_CENTURY_MASK, ioaddr + RTC_CONTROL); 2848c2ecf20Sopenharmony_ci } 2858c2ecf20Sopenharmony_ci if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_BLF) 2868c2ecf20Sopenharmony_ci dev_warn(&pdev->dev, "voltage-low detected.\n"); 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci spin_lock_init(&pdata->lock); 2898c2ecf20Sopenharmony_ci pdata->last_jiffies = jiffies; 2908c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, pdata); 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci pdata->rtc = devm_rtc_allocate_device(&pdev->dev); 2938c2ecf20Sopenharmony_ci if (IS_ERR(pdata->rtc)) 2948c2ecf20Sopenharmony_ci return PTR_ERR(pdata->rtc); 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci pdata->rtc->ops = &ds1553_rtc_ops; 2978c2ecf20Sopenharmony_ci pdata->rtc->nvram_old_abi = true; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci ret = rtc_register_device(pdata->rtc); 3008c2ecf20Sopenharmony_ci if (ret) 3018c2ecf20Sopenharmony_ci return ret; 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci if (pdata->irq > 0) { 3048c2ecf20Sopenharmony_ci writeb(0, ioaddr + RTC_INTERRUPTS); 3058c2ecf20Sopenharmony_ci if (devm_request_irq(&pdev->dev, pdata->irq, 3068c2ecf20Sopenharmony_ci ds1553_rtc_interrupt, 3078c2ecf20Sopenharmony_ci 0, pdev->name, pdev) < 0) { 3088c2ecf20Sopenharmony_ci dev_warn(&pdev->dev, "interrupt not available.\n"); 3098c2ecf20Sopenharmony_ci pdata->irq = 0; 3108c2ecf20Sopenharmony_ci } 3118c2ecf20Sopenharmony_ci } 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci if (rtc_nvmem_register(pdata->rtc, &nvmem_cfg)) 3148c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "unable to register nvmem\n"); 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci return 0; 3178c2ecf20Sopenharmony_ci} 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci/* work with hotplug and coldplug */ 3208c2ecf20Sopenharmony_ciMODULE_ALIAS("platform:rtc-ds1553"); 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_cistatic struct platform_driver ds1553_rtc_driver = { 3238c2ecf20Sopenharmony_ci .probe = ds1553_rtc_probe, 3248c2ecf20Sopenharmony_ci .driver = { 3258c2ecf20Sopenharmony_ci .name = "rtc-ds1553", 3268c2ecf20Sopenharmony_ci }, 3278c2ecf20Sopenharmony_ci}; 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_cimodule_platform_driver(ds1553_rtc_driver); 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ciMODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>"); 3328c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Dallas DS1553 RTC driver"); 3338c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 334