Lines Matching +full:ma35d1 +full:- +full:clk
1 // SPDX-License-Identifier: GPL-2.0
3 * RTC driver for Nuvoton MA35D1
9 #include <linux/clk.h>
18 /* MA35D1 RTC Control Registers */
62 return __raw_readl(p->rtc_reg + offset); in rtc_reg_read()
67 __raw_writel(value, p->rtc_reg + offset); in rtc_reg_write()
82 rtc_update_irq(rtc->rtcdev, 1, events); in ma35d1_rtc_interrupt()
101 return -ETIMEDOUT; in ma35d1_rtc_init()
131 tm->tm_mday = bcd2bin(cal >> 0); in ma35d1_rtc_read_time()
132 tm->tm_wday = wday; in ma35d1_rtc_read_time()
133 tm->tm_mon = bcd2bin(cal >> 8); in ma35d1_rtc_read_time()
134 tm->tm_mon = tm->tm_mon - 1; in ma35d1_rtc_read_time()
135 tm->tm_year = bcd2bin(cal >> 16) + 100; in ma35d1_rtc_read_time()
137 tm->tm_sec = bcd2bin(time >> 0); in ma35d1_rtc_read_time()
138 tm->tm_min = bcd2bin(time >> 8); in ma35d1_rtc_read_time()
139 tm->tm_hour = bcd2bin(time >> 16); in ma35d1_rtc_read_time()
149 val = bin2bcd(tm->tm_mday) << 0 | bin2bcd(tm->tm_mon + 1) << 8 | in ma35d1_rtc_set_time()
150 bin2bcd(tm->tm_year - 100) << 16; in ma35d1_rtc_set_time()
153 val = bin2bcd(tm->tm_sec) << 0 | bin2bcd(tm->tm_min) << 8 | in ma35d1_rtc_set_time()
154 bin2bcd(tm->tm_hour) << 16; in ma35d1_rtc_set_time()
157 val = tm->tm_wday; in ma35d1_rtc_set_time()
171 alrm->time.tm_mday = bcd2bin(calm >> 0); in ma35d1_rtc_read_alarm()
172 alrm->time.tm_mon = bcd2bin(calm >> 8); in ma35d1_rtc_read_alarm()
173 alrm->time.tm_mon = alrm->time.tm_mon - 1; in ma35d1_rtc_read_alarm()
175 alrm->time.tm_year = bcd2bin(calm >> 16) + 100; in ma35d1_rtc_read_alarm()
177 alrm->time.tm_sec = bcd2bin(talm >> 0); in ma35d1_rtc_read_alarm()
178 alrm->time.tm_min = bcd2bin(talm >> 8); in ma35d1_rtc_read_alarm()
179 alrm->time.tm_hour = bcd2bin(talm >> 16); in ma35d1_rtc_read_alarm()
181 return rtc_valid_tm(&alrm->time); in ma35d1_rtc_read_alarm()
189 val = bin2bcd(alrm->time.tm_mday) << 0 | bin2bcd(alrm->time.tm_mon + 1) << 8 | in ma35d1_rtc_set_alarm()
190 bin2bcd(alrm->time.tm_year - 100) << 16; in ma35d1_rtc_set_alarm()
193 val = bin2bcd(alrm->time.tm_sec) << 0 | bin2bcd(alrm->time.tm_min) << 8 | in ma35d1_rtc_set_alarm()
194 bin2bcd(alrm->time.tm_hour) << 16; in ma35d1_rtc_set_alarm()
197 ma35d1_alarm_irq_enable(dev, alrm->enabled); in ma35d1_rtc_set_alarm()
213 struct clk *clk; in ma35d1_rtc_probe() local
216 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); in ma35d1_rtc_probe()
218 return -ENOMEM; in ma35d1_rtc_probe()
220 rtc->rtc_reg = devm_platform_ioremap_resource(pdev, 0); in ma35d1_rtc_probe()
221 if (IS_ERR(rtc->rtc_reg)) in ma35d1_rtc_probe()
222 return PTR_ERR(rtc->rtc_reg); in ma35d1_rtc_probe()
224 clk = of_clk_get(pdev->dev.of_node, 0); in ma35d1_rtc_probe()
225 if (IS_ERR(clk)) in ma35d1_rtc_probe()
226 return dev_err_probe(&pdev->dev, PTR_ERR(clk), "failed to find rtc clock\n"); in ma35d1_rtc_probe()
228 ret = clk_prepare_enable(clk); in ma35d1_rtc_probe()
235 return dev_err_probe(&pdev->dev, ret, "rtc init failed\n"); in ma35d1_rtc_probe()
238 rtc->irq_num = platform_get_irq(pdev, 0); in ma35d1_rtc_probe()
240 ret = devm_request_irq(&pdev->dev, rtc->irq_num, ma35d1_rtc_interrupt, in ma35d1_rtc_probe()
243 return dev_err_probe(&pdev->dev, ret, "Failed to request rtc irq\n"); in ma35d1_rtc_probe()
247 device_init_wakeup(&pdev->dev, true); in ma35d1_rtc_probe()
249 rtc->rtcdev = devm_rtc_allocate_device(&pdev->dev); in ma35d1_rtc_probe()
250 if (IS_ERR(rtc->rtcdev)) in ma35d1_rtc_probe()
251 return PTR_ERR(rtc->rtcdev); in ma35d1_rtc_probe()
253 rtc->rtcdev->ops = &ma35d1_rtc_ops; in ma35d1_rtc_probe()
254 rtc->rtcdev->range_min = RTC_TIMESTAMP_BEGIN_2000; in ma35d1_rtc_probe()
255 rtc->rtcdev->range_max = RTC_TIMESTAMP_END_2099; in ma35d1_rtc_probe()
257 ret = devm_rtc_register_device(rtc->rtcdev); in ma35d1_rtc_probe()
259 return dev_err_probe(&pdev->dev, ret, "Failed to register rtc device\n"); in ma35d1_rtc_probe()
268 if (device_may_wakeup(&pdev->dev)) in ma35d1_rtc_suspend()
269 enable_irq_wake(rtc->irq_num); in ma35d1_rtc_suspend()
278 if (device_may_wakeup(&pdev->dev)) in ma35d1_rtc_resume()
279 disable_irq_wake(rtc->irq_num); in ma35d1_rtc_resume()
285 { .compatible = "nuvoton,ma35d1-rtc", },
295 .name = "rtc-ma35d1",
302 MODULE_AUTHOR("Ming-Jen Chen <mjchen@nuvoton.com>");
303 MODULE_DESCRIPTION("MA35D1 RTC driver");