Lines Matching +full:start +full:- +full:year
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014-2015 MediaTek Inc.
24 ret = regmap_write(rtc->regmap, rtc->addr_base + rtc->data->wrtgr, 1); in mtk_rtc_write_trigger()
28 ret = regmap_read_poll_timeout(rtc->regmap, in mtk_rtc_write_trigger()
29 rtc->addr_base + RTC_BBPU, data, in mtk_rtc_write_trigger()
34 dev_err(rtc->rtc_dev->dev.parent, in mtk_rtc_write_trigger()
46 ret = regmap_read(rtc->regmap, rtc->addr_base + RTC_IRQ_STA, &irqsta); in mtk_rtc_irq_handler_thread()
48 rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF); in mtk_rtc_irq_handler_thread()
50 mutex_lock(&rtc->lock); in mtk_rtc_irq_handler_thread()
51 if (regmap_write(rtc->regmap, rtc->addr_base + RTC_IRQ_EN, in mtk_rtc_irq_handler_thread()
54 mutex_unlock(&rtc->lock); in mtk_rtc_irq_handler_thread()
68 mutex_lock(&rtc->lock); in __mtk_rtc_read_time()
69 ret = regmap_bulk_read(rtc->regmap, rtc->addr_base + RTC_TC_SEC, in __mtk_rtc_read_time()
74 tm->tm_sec = data[RTC_OFFSET_SEC]; in __mtk_rtc_read_time()
75 tm->tm_min = data[RTC_OFFSET_MIN]; in __mtk_rtc_read_time()
76 tm->tm_hour = data[RTC_OFFSET_HOUR]; in __mtk_rtc_read_time()
77 tm->tm_mday = data[RTC_OFFSET_DOM]; in __mtk_rtc_read_time()
78 tm->tm_mon = data[RTC_OFFSET_MTH]; in __mtk_rtc_read_time()
79 tm->tm_year = data[RTC_OFFSET_YEAR]; in __mtk_rtc_read_time()
81 ret = regmap_read(rtc->regmap, rtc->addr_base + RTC_TC_SEC, sec); in __mtk_rtc_read_time()
83 mutex_unlock(&rtc->lock); in __mtk_rtc_read_time()
97 } while (sec < tm->tm_sec); in mtk_rtc_read_time()
99 /* HW register use 7 bits to store year data, minus in mtk_rtc_read_time()
100 * RTC_MIN_YEAR_OFFSET before write year data to register, and plus in mtk_rtc_read_time()
101 * RTC_MIN_YEAR_OFFSET back after read year from register in mtk_rtc_read_time()
103 tm->tm_year += RTC_MIN_YEAR_OFFSET; in mtk_rtc_read_time()
105 /* HW register start mon from one, but tm_mon start from zero. */ in mtk_rtc_read_time()
106 tm->tm_mon--; in mtk_rtc_read_time()
110 * 01-01-1970 00:00:00, and this date is Thursday. in mtk_rtc_read_time()
113 tm->tm_wday = (days + 4) % 7; in mtk_rtc_read_time()
125 tm->tm_year -= RTC_MIN_YEAR_OFFSET; in mtk_rtc_set_time()
126 tm->tm_mon++; in mtk_rtc_set_time()
128 data[RTC_OFFSET_SEC] = tm->tm_sec; in mtk_rtc_set_time()
129 data[RTC_OFFSET_MIN] = tm->tm_min; in mtk_rtc_set_time()
130 data[RTC_OFFSET_HOUR] = tm->tm_hour; in mtk_rtc_set_time()
131 data[RTC_OFFSET_DOM] = tm->tm_mday; in mtk_rtc_set_time()
132 data[RTC_OFFSET_MTH] = tm->tm_mon; in mtk_rtc_set_time()
133 data[RTC_OFFSET_YEAR] = tm->tm_year; in mtk_rtc_set_time()
135 mutex_lock(&rtc->lock); in mtk_rtc_set_time()
136 ret = regmap_bulk_write(rtc->regmap, rtc->addr_base + RTC_TC_SEC, in mtk_rtc_set_time()
145 mutex_unlock(&rtc->lock); in mtk_rtc_set_time()
151 struct rtc_time *tm = &alm->time; in mtk_rtc_read_alarm()
157 mutex_lock(&rtc->lock); in mtk_rtc_read_alarm()
158 ret = regmap_read(rtc->regmap, rtc->addr_base + RTC_IRQ_EN, &irqen); in mtk_rtc_read_alarm()
161 ret = regmap_read(rtc->regmap, rtc->addr_base + RTC_PDN2, &pdn2); in mtk_rtc_read_alarm()
165 ret = regmap_bulk_read(rtc->regmap, rtc->addr_base + RTC_AL_SEC, in mtk_rtc_read_alarm()
170 alm->enabled = !!(irqen & RTC_IRQ_EN_AL); in mtk_rtc_read_alarm()
171 alm->pending = !!(pdn2 & RTC_PDN2_PWRON_ALARM); in mtk_rtc_read_alarm()
172 mutex_unlock(&rtc->lock); in mtk_rtc_read_alarm()
174 tm->tm_sec = data[RTC_OFFSET_SEC] & RTC_AL_SEC_MASK; in mtk_rtc_read_alarm()
175 tm->tm_min = data[RTC_OFFSET_MIN] & RTC_AL_MIN_MASK; in mtk_rtc_read_alarm()
176 tm->tm_hour = data[RTC_OFFSET_HOUR] & RTC_AL_HOU_MASK; in mtk_rtc_read_alarm()
177 tm->tm_mday = data[RTC_OFFSET_DOM] & RTC_AL_DOM_MASK; in mtk_rtc_read_alarm()
178 tm->tm_mon = data[RTC_OFFSET_MTH] & RTC_AL_MTH_MASK; in mtk_rtc_read_alarm()
179 tm->tm_year = data[RTC_OFFSET_YEAR] & RTC_AL_YEA_MASK; in mtk_rtc_read_alarm()
181 tm->tm_year += RTC_MIN_YEAR_OFFSET; in mtk_rtc_read_alarm()
182 tm->tm_mon--; in mtk_rtc_read_alarm()
186 mutex_unlock(&rtc->lock); in mtk_rtc_read_alarm()
192 struct rtc_time *tm = &alm->time; in mtk_rtc_set_alarm()
197 tm->tm_year -= RTC_MIN_YEAR_OFFSET; in mtk_rtc_set_alarm()
198 tm->tm_mon++; in mtk_rtc_set_alarm()
200 mutex_lock(&rtc->lock); in mtk_rtc_set_alarm()
201 ret = regmap_bulk_read(rtc->regmap, rtc->addr_base + RTC_AL_SEC, in mtk_rtc_set_alarm()
207 (tm->tm_sec & RTC_AL_SEC_MASK)); in mtk_rtc_set_alarm()
209 (tm->tm_min & RTC_AL_MIN_MASK)); in mtk_rtc_set_alarm()
211 (tm->tm_hour & RTC_AL_HOU_MASK)); in mtk_rtc_set_alarm()
213 (tm->tm_mday & RTC_AL_DOM_MASK)); in mtk_rtc_set_alarm()
215 (tm->tm_mon & RTC_AL_MTH_MASK)); in mtk_rtc_set_alarm()
217 (tm->tm_year & RTC_AL_YEA_MASK)); in mtk_rtc_set_alarm()
219 if (alm->enabled) { in mtk_rtc_set_alarm()
220 ret = regmap_bulk_write(rtc->regmap, in mtk_rtc_set_alarm()
221 rtc->addr_base + RTC_AL_SEC, in mtk_rtc_set_alarm()
225 ret = regmap_write(rtc->regmap, rtc->addr_base + RTC_AL_MASK, in mtk_rtc_set_alarm()
229 ret = regmap_update_bits(rtc->regmap, in mtk_rtc_set_alarm()
230 rtc->addr_base + RTC_IRQ_EN, in mtk_rtc_set_alarm()
236 ret = regmap_update_bits(rtc->regmap, in mtk_rtc_set_alarm()
237 rtc->addr_base + RTC_IRQ_EN, in mtk_rtc_set_alarm()
249 mutex_unlock(&rtc->lock); in mtk_rtc_set_alarm()
263 struct mt6397_chip *mt6397_chip = dev_get_drvdata(pdev->dev.parent); in mtk_rtc_probe()
267 rtc = devm_kzalloc(&pdev->dev, sizeof(struct mt6397_rtc), GFP_KERNEL); in mtk_rtc_probe()
269 return -ENOMEM; in mtk_rtc_probe()
272 rtc->addr_base = res->start; in mtk_rtc_probe()
274 rtc->data = of_device_get_match_data(&pdev->dev); in mtk_rtc_probe()
276 rtc->irq = platform_get_irq(pdev, 0); in mtk_rtc_probe()
277 if (rtc->irq < 0) in mtk_rtc_probe()
278 return rtc->irq; in mtk_rtc_probe()
280 rtc->regmap = mt6397_chip->regmap; in mtk_rtc_probe()
281 mutex_init(&rtc->lock); in mtk_rtc_probe()
285 rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev); in mtk_rtc_probe()
286 if (IS_ERR(rtc->rtc_dev)) in mtk_rtc_probe()
287 return PTR_ERR(rtc->rtc_dev); in mtk_rtc_probe()
289 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, in mtk_rtc_probe()
292 "mt6397-rtc", rtc); in mtk_rtc_probe()
295 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", in mtk_rtc_probe()
296 rtc->irq, ret); in mtk_rtc_probe()
300 device_init_wakeup(&pdev->dev, 1); in mtk_rtc_probe()
302 rtc->rtc_dev->ops = &mtk_rtc_ops; in mtk_rtc_probe()
304 return rtc_register_device(rtc->rtc_dev); in mtk_rtc_probe()
313 enable_irq_wake(rtc->irq); in mt6397_rtc_suspend()
323 disable_irq_wake(rtc->irq); in mt6397_rtc_resume()
341 { .compatible = "mediatek,mt6323-rtc", .data = &mt6397_rtc_data },
342 { .compatible = "mediatek,mt6358-rtc", .data = &mt6358_rtc_data },
343 { .compatible = "mediatek,mt6397-rtc", .data = &mt6397_rtc_data },
350 .name = "mt6397-rtc",