Lines Matching +full:imx93 +full:- +full:bbnsm +full:- +full:rtc

1 // SPDX-License-Identifier: GPL-2.0+
14 #include <linux/rtc.h>
36 struct rtc_device *rtc; member
42 static u32 bbnsm_read_counter(struct bbnsm_rtc *bbnsm) in bbnsm_read_counter() argument
52 regmap_read(bbnsm->regmap, BBNSM_RTC_MS, &rtc_msb); in bbnsm_read_counter()
54 regmap_read(bbnsm->regmap, BBNSM_RTC_LS, &rtc_lsb); in bbnsm_read_counter()
57 } while (tmp != time && --timeout); in bbnsm_read_counter()
64 struct bbnsm_rtc *bbnsm = dev_get_drvdata(dev); in bbnsm_rtc_read_time() local
68 regmap_read(bbnsm->regmap, BBNSM_CTRL, &val); in bbnsm_rtc_read_time()
70 return -EINVAL; in bbnsm_rtc_read_time()
72 time = bbnsm_read_counter(bbnsm); in bbnsm_rtc_read_time()
80 struct bbnsm_rtc *bbnsm = dev_get_drvdata(dev); in bbnsm_rtc_set_time() local
83 /* disable the RTC first */ in bbnsm_rtc_set_time()
84 regmap_update_bits(bbnsm->regmap, BBNSM_CTRL, RTC_EN_MSK, 0); in bbnsm_rtc_set_time()
87 regmap_write(bbnsm->regmap, BBNSM_RTC_LS, time << CNTR_TO_SECS_SH); in bbnsm_rtc_set_time()
88 regmap_write(bbnsm->regmap, BBNSM_RTC_MS, time >> (32 - CNTR_TO_SECS_SH)); in bbnsm_rtc_set_time()
90 /* Enable the RTC again */ in bbnsm_rtc_set_time()
91 regmap_update_bits(bbnsm->regmap, BBNSM_CTRL, RTC_EN_MSK, RTC_EN); in bbnsm_rtc_set_time()
98 struct bbnsm_rtc *bbnsm = dev_get_drvdata(dev); in bbnsm_rtc_read_alarm() local
101 regmap_read(bbnsm->regmap, BBNSM_TA, &bbnsm_ta); in bbnsm_rtc_read_alarm()
102 rtc_time64_to_tm(bbnsm_ta, &alrm->time); in bbnsm_rtc_read_alarm()
104 regmap_read(bbnsm->regmap, BBNSM_EVENTS, &bbnsm_events); in bbnsm_rtc_read_alarm()
105 alrm->pending = (bbnsm_events & BBNSM_EVENT_TA) ? 1 : 0; in bbnsm_rtc_read_alarm()
112 struct bbnsm_rtc *bbnsm = dev_get_drvdata(dev); in bbnsm_rtc_alarm_irq_enable() local
115 regmap_update_bits(bbnsm->regmap, BBNSM_CTRL, TA_EN_MSK, enable ? TA_EN : TA_DIS); in bbnsm_rtc_alarm_irq_enable()
117 regmap_update_bits(bbnsm->regmap, BBNSM_INT_EN, TA_EN_MSK, enable ? TA_EN : TA_DIS); in bbnsm_rtc_alarm_irq_enable()
124 struct bbnsm_rtc *bbnsm = dev_get_drvdata(dev); in bbnsm_rtc_set_alarm() local
125 unsigned long time = rtc_tm_to_time64(&alrm->time); in bbnsm_rtc_set_alarm()
128 regmap_update_bits(bbnsm->regmap, BBNSM_CTRL, TA_EN, TA_EN); in bbnsm_rtc_set_alarm()
131 regmap_write(bbnsm->regmap, BBNSM_TA, time); in bbnsm_rtc_set_alarm()
133 return bbnsm_rtc_alarm_irq_enable(dev, alrm->enabled); in bbnsm_rtc_set_alarm()
147 struct bbnsm_rtc *bbnsm = dev_get_drvdata(dev); in bbnsm_rtc_irq_handler() local
150 regmap_read(bbnsm->regmap, BBNSM_EVENTS, &val); in bbnsm_rtc_irq_handler()
154 regmap_write_bits(bbnsm->regmap, BBNSM_EVENTS, TA_EN_MSK, BBNSM_EVENT_TA); in bbnsm_rtc_irq_handler()
155 rtc_update_irq(bbnsm->rtc, 1, RTC_AF | RTC_IRQF); in bbnsm_rtc_irq_handler()
165 struct device_node *np = pdev->dev.of_node; in bbnsm_rtc_probe()
166 struct bbnsm_rtc *bbnsm; in bbnsm_rtc_probe() local
169 bbnsm = devm_kzalloc(&pdev->dev, sizeof(*bbnsm), GFP_KERNEL); in bbnsm_rtc_probe()
170 if (!bbnsm) in bbnsm_rtc_probe()
171 return -ENOMEM; in bbnsm_rtc_probe()
173 bbnsm->rtc = devm_rtc_allocate_device(&pdev->dev); in bbnsm_rtc_probe()
174 if (IS_ERR(bbnsm->rtc)) in bbnsm_rtc_probe()
175 return PTR_ERR(bbnsm->rtc); in bbnsm_rtc_probe()
177 bbnsm->regmap = syscon_node_to_regmap(np->parent); in bbnsm_rtc_probe()
178 if (IS_ERR(bbnsm->regmap)) { in bbnsm_rtc_probe()
179 dev_dbg(&pdev->dev, "bbnsm get regmap failed\n"); in bbnsm_rtc_probe()
180 return PTR_ERR(bbnsm->regmap); in bbnsm_rtc_probe()
183 bbnsm->irq = platform_get_irq(pdev, 0); in bbnsm_rtc_probe()
184 if (bbnsm->irq < 0) in bbnsm_rtc_probe()
185 return bbnsm->irq; in bbnsm_rtc_probe()
187 platform_set_drvdata(pdev, bbnsm); in bbnsm_rtc_probe()
190 regmap_write(bbnsm->regmap, BBNSM_EVENTS, 0x7A); in bbnsm_rtc_probe()
192 device_init_wakeup(&pdev->dev, true); in bbnsm_rtc_probe()
193 dev_pm_set_wake_irq(&pdev->dev, bbnsm->irq); in bbnsm_rtc_probe()
195 ret = devm_request_irq(&pdev->dev, bbnsm->irq, bbnsm_rtc_irq_handler, in bbnsm_rtc_probe()
196 IRQF_SHARED, "rtc alarm", &pdev->dev); in bbnsm_rtc_probe()
198 dev_err(&pdev->dev, "failed to request irq %d: %d\n", in bbnsm_rtc_probe()
199 bbnsm->irq, ret); in bbnsm_rtc_probe()
203 bbnsm->rtc->ops = &bbnsm_rtc_ops; in bbnsm_rtc_probe()
204 bbnsm->rtc->range_max = U32_MAX; in bbnsm_rtc_probe()
206 ret = devm_rtc_register_device(bbnsm->rtc); in bbnsm_rtc_probe()
213 dev_pm_clear_wake_irq(&pdev->dev); in bbnsm_rtc_probe()
214 device_init_wakeup(&pdev->dev, false); in bbnsm_rtc_probe()
220 dev_pm_clear_wake_irq(&pdev->dev); in bbnsm_rtc_remove()
221 device_init_wakeup(&pdev->dev, false); in bbnsm_rtc_remove()
225 { .compatible = "nxp,imx93-bbnsm-rtc" },
241 MODULE_DESCRIPTION("NXP BBNSM RTC Driver");