Lines Matching refs:mt2712_rtc
77 struct mt2712_rtc { struct
85 static inline u32 mt2712_readl(struct mt2712_rtc *mt2712_rtc, u32 reg) in mt2712_readl() argument
87 return readl(mt2712_rtc->base + reg); in mt2712_readl()
90 static inline void mt2712_writel(struct mt2712_rtc *mt2712_rtc, in mt2712_writel() argument
93 writel(val, mt2712_rtc->base + reg); in mt2712_writel()
96 static void mt2712_rtc_write_trigger(struct mt2712_rtc *mt2712_rtc) in mt2712_rtc_write_trigger() argument
100 mt2712_writel(mt2712_rtc, MT2712_WRTGR, 1); in mt2712_rtc_write_trigger()
102 if (!(mt2712_readl(mt2712_rtc, MT2712_BBPU) in mt2712_rtc_write_trigger()
107 dev_err(&mt2712_rtc->rtc->dev, in mt2712_rtc_write_trigger()
115 static void mt2712_rtc_writeif_unlock(struct mt2712_rtc *mt2712_rtc) in mt2712_rtc_writeif_unlock() argument
117 mt2712_writel(mt2712_rtc, MT2712_PROT, MT2712_PROT_UNLOCK1); in mt2712_rtc_writeif_unlock()
118 mt2712_rtc_write_trigger(mt2712_rtc); in mt2712_rtc_writeif_unlock()
119 mt2712_writel(mt2712_rtc, MT2712_PROT, MT2712_PROT_UNLOCK2); in mt2712_rtc_writeif_unlock()
120 mt2712_rtc_write_trigger(mt2712_rtc); in mt2712_rtc_writeif_unlock()
125 struct mt2712_rtc *mt2712_rtc = data; in rtc_irq_handler_thread() local
129 irqsta = mt2712_readl(mt2712_rtc, MT2712_IRQ_STA); in rtc_irq_handler_thread()
131 rtc_update_irq(mt2712_rtc->rtc, 1, RTC_IRQF | RTC_AF); in rtc_irq_handler_thread()
138 static void __mt2712_rtc_read_time(struct mt2712_rtc *mt2712_rtc, in __mt2712_rtc_read_time() argument
141 tm->tm_sec = mt2712_readl(mt2712_rtc, MT2712_TC_SEC) in __mt2712_rtc_read_time()
143 tm->tm_min = mt2712_readl(mt2712_rtc, MT2712_TC_MIN) in __mt2712_rtc_read_time()
145 tm->tm_hour = mt2712_readl(mt2712_rtc, MT2712_TC_HOU) in __mt2712_rtc_read_time()
147 tm->tm_mday = mt2712_readl(mt2712_rtc, MT2712_TC_DOM) in __mt2712_rtc_read_time()
149 tm->tm_mon = (mt2712_readl(mt2712_rtc, MT2712_TC_MTH) - 1) in __mt2712_rtc_read_time()
151 tm->tm_year = (mt2712_readl(mt2712_rtc, MT2712_TC_YEA) + 100) in __mt2712_rtc_read_time()
154 *sec = mt2712_readl(mt2712_rtc, MT2712_TC_SEC) & MT2712_SEC_MASK; in __mt2712_rtc_read_time()
159 struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); in mt2712_rtc_read_time() local
162 if (mt2712_rtc->powerlost) in mt2712_rtc_read_time()
166 __mt2712_rtc_read_time(mt2712_rtc, tm, &sec); in mt2712_rtc_read_time()
174 struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); in mt2712_rtc_set_time() local
176 mt2712_writel(mt2712_rtc, MT2712_TC_SEC, tm->tm_sec & MT2712_SEC_MASK); in mt2712_rtc_set_time()
177 mt2712_writel(mt2712_rtc, MT2712_TC_MIN, tm->tm_min & MT2712_MIN_MASK); in mt2712_rtc_set_time()
178 mt2712_writel(mt2712_rtc, MT2712_TC_HOU, tm->tm_hour & MT2712_HOU_MASK); in mt2712_rtc_set_time()
179 mt2712_writel(mt2712_rtc, MT2712_TC_DOM, tm->tm_mday & MT2712_DOM_MASK); in mt2712_rtc_set_time()
180 mt2712_writel(mt2712_rtc, MT2712_TC_MTH, in mt2712_rtc_set_time()
182 mt2712_writel(mt2712_rtc, MT2712_TC_YEA, in mt2712_rtc_set_time()
185 mt2712_rtc_write_trigger(mt2712_rtc); in mt2712_rtc_set_time()
187 if (mt2712_rtc->powerlost) in mt2712_rtc_set_time()
188 mt2712_rtc->powerlost = false; in mt2712_rtc_set_time()
195 struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); in mt2712_rtc_read_alarm() local
199 irqen = mt2712_readl(mt2712_rtc, MT2712_IRQ_EN); in mt2712_rtc_read_alarm()
202 tm->tm_sec = mt2712_readl(mt2712_rtc, MT2712_AL_SEC) & MT2712_SEC_MASK; in mt2712_rtc_read_alarm()
203 tm->tm_min = mt2712_readl(mt2712_rtc, MT2712_AL_MIN) & MT2712_MIN_MASK; in mt2712_rtc_read_alarm()
204 tm->tm_hour = mt2712_readl(mt2712_rtc, MT2712_AL_HOU) & MT2712_HOU_MASK; in mt2712_rtc_read_alarm()
205 tm->tm_mday = mt2712_readl(mt2712_rtc, MT2712_AL_DOM) & MT2712_DOM_MASK; in mt2712_rtc_read_alarm()
206 tm->tm_mon = (mt2712_readl(mt2712_rtc, MT2712_AL_MTH) - 1) in mt2712_rtc_read_alarm()
208 tm->tm_year = (mt2712_readl(mt2712_rtc, MT2712_AL_YEA) + 100) in mt2712_rtc_read_alarm()
217 struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); in mt2712_rtc_alarm_irq_enable() local
220 irqen = mt2712_readl(mt2712_rtc, MT2712_IRQ_EN); in mt2712_rtc_alarm_irq_enable()
225 mt2712_writel(mt2712_rtc, MT2712_IRQ_EN, irqen); in mt2712_rtc_alarm_irq_enable()
226 mt2712_rtc_write_trigger(mt2712_rtc); in mt2712_rtc_alarm_irq_enable()
233 struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); in mt2712_rtc_set_alarm() local
236 dev_dbg(&mt2712_rtc->rtc->dev, "set al time: %ptR, alm en: %d\n", in mt2712_rtc_set_alarm()
239 mt2712_writel(mt2712_rtc, MT2712_AL_SEC, in mt2712_rtc_set_alarm()
240 (mt2712_readl(mt2712_rtc, MT2712_AL_SEC) in mt2712_rtc_set_alarm()
242 mt2712_writel(mt2712_rtc, MT2712_AL_MIN, in mt2712_rtc_set_alarm()
243 (mt2712_readl(mt2712_rtc, MT2712_AL_MIN) in mt2712_rtc_set_alarm()
245 mt2712_writel(mt2712_rtc, MT2712_AL_HOU, in mt2712_rtc_set_alarm()
246 (mt2712_readl(mt2712_rtc, MT2712_AL_HOU) in mt2712_rtc_set_alarm()
248 mt2712_writel(mt2712_rtc, MT2712_AL_DOM, in mt2712_rtc_set_alarm()
249 (mt2712_readl(mt2712_rtc, MT2712_AL_DOM) in mt2712_rtc_set_alarm()
251 mt2712_writel(mt2712_rtc, MT2712_AL_MTH, in mt2712_rtc_set_alarm()
252 (mt2712_readl(mt2712_rtc, MT2712_AL_MTH) in mt2712_rtc_set_alarm()
255 mt2712_writel(mt2712_rtc, MT2712_AL_YEA, in mt2712_rtc_set_alarm()
256 (mt2712_readl(mt2712_rtc, MT2712_AL_YEA) in mt2712_rtc_set_alarm()
261 mt2712_writel(mt2712_rtc, MT2712_AL_MASK, MT2712_AL_MASK_DOW); in mt2712_rtc_set_alarm()
262 mt2712_rtc_write_trigger(mt2712_rtc); in mt2712_rtc_set_alarm()
270 static void mt2712_rtc_hw_init(struct mt2712_rtc *mt2712_rtc) in mt2712_rtc_hw_init() argument
274 mt2712_writel(mt2712_rtc, MT2712_BBPU, in mt2712_rtc_hw_init()
277 mt2712_writel(mt2712_rtc, MT2712_CII_EN, 0); in mt2712_rtc_hw_init()
278 mt2712_writel(mt2712_rtc, MT2712_AL_MASK, 0); in mt2712_rtc_hw_init()
280 mt2712_writel(mt2712_rtc, MT2712_CON0, 0x4848); in mt2712_rtc_hw_init()
281 mt2712_writel(mt2712_rtc, MT2712_CON1, 0x0048); in mt2712_rtc_hw_init()
283 mt2712_rtc_write_trigger(mt2712_rtc); in mt2712_rtc_hw_init()
285 p1 = mt2712_readl(mt2712_rtc, MT2712_POWERKEY1); in mt2712_rtc_hw_init()
286 p2 = mt2712_readl(mt2712_rtc, MT2712_POWERKEY2); in mt2712_rtc_hw_init()
288 mt2712_rtc->powerlost = true; in mt2712_rtc_hw_init()
289 dev_dbg(&mt2712_rtc->rtc->dev, in mt2712_rtc_hw_init()
292 mt2712_rtc->powerlost = false; in mt2712_rtc_hw_init()
296 mt2712_writel(mt2712_rtc, MT2712_POWERKEY1, MT2712_POWERKEY1_KEY); in mt2712_rtc_hw_init()
297 mt2712_writel(mt2712_rtc, MT2712_POWERKEY2, MT2712_POWERKEY2_KEY); in mt2712_rtc_hw_init()
298 mt2712_rtc_write_trigger(mt2712_rtc); in mt2712_rtc_hw_init()
300 mt2712_rtc_writeif_unlock(mt2712_rtc); in mt2712_rtc_hw_init()
313 struct mt2712_rtc *mt2712_rtc; in mt2712_rtc_probe() local
316 mt2712_rtc = devm_kzalloc(&pdev->dev, in mt2712_rtc_probe()
317 sizeof(struct mt2712_rtc), GFP_KERNEL); in mt2712_rtc_probe()
318 if (!mt2712_rtc) in mt2712_rtc_probe()
321 mt2712_rtc->base = devm_platform_ioremap_resource(pdev, 0); in mt2712_rtc_probe()
322 if (IS_ERR(mt2712_rtc->base)) in mt2712_rtc_probe()
323 return PTR_ERR(mt2712_rtc->base); in mt2712_rtc_probe()
326 mt2712_rtc_hw_init(mt2712_rtc); in mt2712_rtc_probe()
328 mt2712_rtc->irq = platform_get_irq(pdev, 0); in mt2712_rtc_probe()
329 if (mt2712_rtc->irq < 0) in mt2712_rtc_probe()
330 return mt2712_rtc->irq; in mt2712_rtc_probe()
332 platform_set_drvdata(pdev, mt2712_rtc); in mt2712_rtc_probe()
334 mt2712_rtc->rtc = devm_rtc_allocate_device(&pdev->dev); in mt2712_rtc_probe()
335 if (IS_ERR(mt2712_rtc->rtc)) in mt2712_rtc_probe()
336 return PTR_ERR(mt2712_rtc->rtc); in mt2712_rtc_probe()
338 ret = devm_request_threaded_irq(&pdev->dev, mt2712_rtc->irq, NULL, in mt2712_rtc_probe()
341 dev_name(&mt2712_rtc->rtc->dev), in mt2712_rtc_probe()
342 mt2712_rtc); in mt2712_rtc_probe()
345 mt2712_rtc->irq, ret); in mt2712_rtc_probe()
351 mt2712_rtc->rtc->ops = &mt2712_rtc_ops; in mt2712_rtc_probe()
352 mt2712_rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in mt2712_rtc_probe()
353 mt2712_rtc->rtc->range_max = MT2712_RTC_TIMESTAMP_END_2127; in mt2712_rtc_probe()
355 return devm_rtc_register_device(mt2712_rtc->rtc); in mt2712_rtc_probe()
362 struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); in mt2712_rtc_suspend() local
365 wake_status = enable_irq_wake(mt2712_rtc->irq); in mt2712_rtc_suspend()
367 mt2712_rtc->irq_wake_enabled = true; in mt2712_rtc_suspend()
376 struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); in mt2712_rtc_resume() local
378 if (device_may_wakeup(dev) && mt2712_rtc->irq_wake_enabled) { in mt2712_rtc_resume()
379 wake_status = disable_irq_wake(mt2712_rtc->irq); in mt2712_rtc_resume()
381 mt2712_rtc->irq_wake_enabled = false; in mt2712_rtc_resume()