Lines Matching full:data

44 static u64 rtc_read_lpsrt(struct snvs_rtc_data *data)  in rtc_read_lpsrt()  argument
48 regmap_read(data->regmap, data->offset + SNVS_LPSRTCMR, &msb); in rtc_read_lpsrt()
49 regmap_read(data->regmap, data->offset + SNVS_LPSRTCLR, &lsb); in rtc_read_lpsrt()
56 static u32 rtc_read_lp_counter(struct snvs_rtc_data *data) in rtc_read_lp_counter() argument
65 read1 = rtc_read_lpsrt(data); in rtc_read_lp_counter()
68 read1 = rtc_read_lpsrt(data); in rtc_read_lp_counter()
71 dev_err(&data->rtc->dev, "Timeout trying to get valid LPSRT Counter read\n"); in rtc_read_lp_counter()
78 static int rtc_read_lp_counter_lsb(struct snvs_rtc_data *data, u32 *lsb) in rtc_read_lp_counter_lsb() argument
83 regmap_read(data->regmap, data->offset + SNVS_LPSRTCLR, &count1); in rtc_read_lp_counter_lsb()
86 regmap_read(data->regmap, data->offset + SNVS_LPSRTCLR, &count1); in rtc_read_lp_counter_lsb()
89 dev_err(&data->rtc->dev, "Timeout trying to get valid LPSRT Counter read\n"); in rtc_read_lp_counter_lsb()
97 static int rtc_write_sync_lp(struct snvs_rtc_data *data) in rtc_write_sync_lp() argument
104 ret = rtc_read_lp_counter_lsb(data, &count1); in rtc_write_sync_lp()
110 ret = rtc_read_lp_counter_lsb(data, &count2); in rtc_write_sync_lp()
116 dev_err(&data->rtc->dev, "Timeout waiting for LPSRT Counter to change\n"); in rtc_write_sync_lp()
122 static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable) in snvs_rtc_enable() argument
127 regmap_update_bits(data->regmap, data->offset + SNVS_LPCR, SNVS_LPCR_SRTC_ENV, in snvs_rtc_enable()
131 regmap_read(data->regmap, data->offset + SNVS_LPCR, &lpcr); in snvs_rtc_enable()
150 struct snvs_rtc_data *data = dev_get_drvdata(dev); in snvs_rtc_read_time() local
154 ret = clk_enable(data->clk); in snvs_rtc_read_time()
158 time = rtc_read_lp_counter(data); in snvs_rtc_read_time()
161 clk_disable(data->clk); in snvs_rtc_read_time()
168 struct snvs_rtc_data *data = dev_get_drvdata(dev); in snvs_rtc_set_time() local
172 ret = clk_enable(data->clk); in snvs_rtc_set_time()
177 ret = snvs_rtc_enable(data, false); in snvs_rtc_set_time()
182 regmap_write(data->regmap, data->offset + SNVS_LPSRTCLR, time << CNTR_TO_SECS_SH); in snvs_rtc_set_time()
183 regmap_write(data->regmap, data->offset + SNVS_LPSRTCMR, time >> (32 - CNTR_TO_SECS_SH)); in snvs_rtc_set_time()
186 ret = snvs_rtc_enable(data, true); in snvs_rtc_set_time()
188 clk_disable(data->clk); in snvs_rtc_set_time()
195 struct snvs_rtc_data *data = dev_get_drvdata(dev); in snvs_rtc_read_alarm() local
199 ret = clk_enable(data->clk); in snvs_rtc_read_alarm()
203 regmap_read(data->regmap, data->offset + SNVS_LPTAR, &lptar); in snvs_rtc_read_alarm()
206 regmap_read(data->regmap, data->offset + SNVS_LPSR, &lpsr); in snvs_rtc_read_alarm()
209 clk_disable(data->clk); in snvs_rtc_read_alarm()
216 struct snvs_rtc_data *data = dev_get_drvdata(dev); in snvs_rtc_alarm_irq_enable() local
219 ret = clk_enable(data->clk); in snvs_rtc_alarm_irq_enable()
223 regmap_update_bits(data->regmap, data->offset + SNVS_LPCR, in snvs_rtc_alarm_irq_enable()
227 ret = rtc_write_sync_lp(data); in snvs_rtc_alarm_irq_enable()
229 clk_disable(data->clk); in snvs_rtc_alarm_irq_enable()
236 struct snvs_rtc_data *data = dev_get_drvdata(dev); in snvs_rtc_set_alarm() local
240 ret = clk_enable(data->clk); in snvs_rtc_set_alarm()
244 regmap_update_bits(data->regmap, data->offset + SNVS_LPCR, SNVS_LPCR_LPTA_EN, 0); in snvs_rtc_set_alarm()
245 ret = rtc_write_sync_lp(data); in snvs_rtc_set_alarm()
248 regmap_write(data->regmap, data->offset + SNVS_LPTAR, time); in snvs_rtc_set_alarm()
251 regmap_write(data->regmap, data->offset + SNVS_LPSR, SNVS_LPSR_LPTA); in snvs_rtc_set_alarm()
253 clk_disable(data->clk); in snvs_rtc_set_alarm()
269 struct snvs_rtc_data *data = dev_get_drvdata(dev); in snvs_rtc_irq_handler() local
273 clk_enable(data->clk); in snvs_rtc_irq_handler()
275 regmap_read(data->regmap, data->offset + SNVS_LPSR, &lpsr); in snvs_rtc_irq_handler()
283 rtc_update_irq(data->rtc, 1, events); in snvs_rtc_irq_handler()
287 regmap_write(data->regmap, data->offset + SNVS_LPSR, lpsr); in snvs_rtc_irq_handler()
289 clk_disable(data->clk); in snvs_rtc_irq_handler()
300 static void snvs_rtc_action(void *data) in snvs_rtc_action() argument
302 clk_disable_unprepare(data); in snvs_rtc_action()
307 struct snvs_rtc_data *data; in snvs_rtc_probe() local
311 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); in snvs_rtc_probe()
312 if (!data) in snvs_rtc_probe()
315 data->rtc = devm_rtc_allocate_device(&pdev->dev); in snvs_rtc_probe()
316 if (IS_ERR(data->rtc)) in snvs_rtc_probe()
317 return PTR_ERR(data->rtc); in snvs_rtc_probe()
319 data->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "regmap"); in snvs_rtc_probe()
321 if (IS_ERR(data->regmap)) { in snvs_rtc_probe()
328 data->regmap = devm_regmap_init_mmio(&pdev->dev, mmio, &snvs_rtc_config); in snvs_rtc_probe()
330 data->offset = SNVS_LPREGISTER_OFFSET; in snvs_rtc_probe()
331 of_property_read_u32(pdev->dev.of_node, "offset", &data->offset); in snvs_rtc_probe()
334 if (IS_ERR(data->regmap)) { in snvs_rtc_probe()
339 data->irq = platform_get_irq(pdev, 0); in snvs_rtc_probe()
340 if (data->irq < 0) in snvs_rtc_probe()
341 return data->irq; in snvs_rtc_probe()
343 data->clk = devm_clk_get(&pdev->dev, "snvs-rtc"); in snvs_rtc_probe()
344 if (IS_ERR(data->clk)) { in snvs_rtc_probe()
345 data->clk = NULL; in snvs_rtc_probe()
347 ret = clk_prepare_enable(data->clk); in snvs_rtc_probe()
355 ret = devm_add_action_or_reset(&pdev->dev, snvs_rtc_action, data->clk); in snvs_rtc_probe()
359 platform_set_drvdata(pdev, data); in snvs_rtc_probe()
362 regmap_write(data->regmap, data->offset + SNVS_LPPGDR, SNVS_LPPGDR_INIT); in snvs_rtc_probe()
365 regmap_write(data->regmap, data->offset + SNVS_LPSR, 0xffffffff); in snvs_rtc_probe()
368 ret = snvs_rtc_enable(data, true); in snvs_rtc_probe()
375 ret = dev_pm_set_wake_irq(&pdev->dev, data->irq); in snvs_rtc_probe()
379 ret = devm_request_irq(&pdev->dev, data->irq, snvs_rtc_irq_handler, in snvs_rtc_probe()
383 data->irq, ret); in snvs_rtc_probe()
387 data->rtc->ops = &snvs_rtc_ops; in snvs_rtc_probe()
388 data->rtc->range_max = U32_MAX; in snvs_rtc_probe()
390 return devm_rtc_register_device(data->rtc); in snvs_rtc_probe()
395 struct snvs_rtc_data *data = dev_get_drvdata(dev); in snvs_rtc_suspend_noirq() local
397 clk_disable(data->clk); in snvs_rtc_suspend_noirq()
404 struct snvs_rtc_data *data = dev_get_drvdata(dev); in snvs_rtc_resume_noirq() local
406 if (data->clk) in snvs_rtc_resume_noirq()
407 return clk_enable(data->clk); in snvs_rtc_resume_noirq()