Lines Matching full:rtc

15 #include <linux/rtc.h>
16 #include <linux/mfd/mt6397/rtc.h>
19 static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc) in mtk_rtc_write_trigger() argument
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()
42 struct mt6397_rtc *rtc = data; in mtk_rtc_irq_handler_thread() local
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()
53 mtk_rtc_write_trigger(rtc); in mtk_rtc_irq_handler_thread()
54 mutex_unlock(&rtc->lock); in mtk_rtc_irq_handler_thread()
62 static int __mtk_rtc_read_time(struct mt6397_rtc *rtc, in __mtk_rtc_read_time() argument
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()
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()
90 struct mt6397_rtc *rtc = dev_get_drvdata(dev); in mtk_rtc_read_time() local
94 ret = __mtk_rtc_read_time(rtc, tm, &sec); in mtk_rtc_read_time()
121 struct mt6397_rtc *rtc = dev_get_drvdata(dev); in mtk_rtc_set_time() local
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()
142 ret = mtk_rtc_write_trigger(rtc); in mtk_rtc_set_time()
145 mutex_unlock(&rtc->lock); in mtk_rtc_set_time()
152 struct mt6397_rtc *rtc = dev_get_drvdata(dev); in mtk_rtc_read_alarm() local
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()
172 mutex_unlock(&rtc->lock); in mtk_rtc_read_alarm()
186 mutex_unlock(&rtc->lock); in mtk_rtc_read_alarm()
193 struct mt6397_rtc *rtc = dev_get_drvdata(dev); in mtk_rtc_set_alarm() local
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()
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()
247 ret = mtk_rtc_write_trigger(rtc); in mtk_rtc_set_alarm()
249 mutex_unlock(&rtc->lock); in mtk_rtc_set_alarm()
264 struct mt6397_rtc *rtc; in mtk_rtc_probe() local
267 rtc = devm_kzalloc(&pdev->dev, sizeof(struct mt6397_rtc), GFP_KERNEL); in mtk_rtc_probe()
268 if (!rtc) in mtk_rtc_probe()
274 rtc->addr_base = res->start; in mtk_rtc_probe()
276 rtc->data = of_device_get_match_data(&pdev->dev); in mtk_rtc_probe()
278 rtc->irq = platform_get_irq(pdev, 0); in mtk_rtc_probe()
279 if (rtc->irq < 0) in mtk_rtc_probe()
280 return rtc->irq; in mtk_rtc_probe()
282 rtc->regmap = mt6397_chip->regmap; in mtk_rtc_probe()
283 mutex_init(&rtc->lock); in mtk_rtc_probe()
285 platform_set_drvdata(pdev, rtc); in mtk_rtc_probe()
287 rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev); in mtk_rtc_probe()
288 if (IS_ERR(rtc->rtc_dev)) in mtk_rtc_probe()
289 return PTR_ERR(rtc->rtc_dev); in mtk_rtc_probe()
291 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, in mtk_rtc_probe()
294 "mt6397-rtc", rtc); in mtk_rtc_probe()
298 rtc->irq, ret); in mtk_rtc_probe()
304 rtc->rtc_dev->ops = &mtk_rtc_ops; in mtk_rtc_probe()
306 return devm_rtc_register_device(rtc->rtc_dev); in mtk_rtc_probe()
312 struct mt6397_rtc *rtc = dev_get_drvdata(dev); in mt6397_rtc_suspend() local
315 enable_irq_wake(rtc->irq); in mt6397_rtc_suspend()
322 struct mt6397_rtc *rtc = dev_get_drvdata(dev); in mt6397_rtc_resume() local
325 disable_irq_wake(rtc->irq); in mt6397_rtc_resume()
343 { .compatible = "mediatek,mt6323-rtc", .data = &mt6397_rtc_data },
344 { .compatible = "mediatek,mt6358-rtc", .data = &mt6358_rtc_data },
345 { .compatible = "mediatek,mt6397-rtc", .data = &mt6397_rtc_data },
352 .name = "mt6397-rtc",
363 MODULE_DESCRIPTION("RTC Driver for MediaTek MT6397 PMIC");