Lines Matching +full:3 +full:base +full:- +full:x

1 // SPDX-License-Identifier: GPL-2.0
53 regmap_update_bits(info->map, PM800_RTC_CONTROL, mask | PM800_ALARM1_EN, in rtc_update_handler()
55 rtc_update_irq(info->rtc_dev, 1, RTC_AF); in rtc_update_handler()
64 regmap_update_bits(info->map, PM800_RTC_CONTROL, in pm80x_rtc_alarm_irq_enable()
67 regmap_update_bits(info->map, PM800_RTC_CONTROL, in pm80x_rtc_alarm_irq_enable()
82 next->tm_year = now->tm_year; in rtc_next_alarm_time()
83 next->tm_mon = now->tm_mon; in rtc_next_alarm_time()
84 next->tm_mday = now->tm_mday; in rtc_next_alarm_time()
85 next->tm_hour = alrm->tm_hour; in rtc_next_alarm_time()
86 next->tm_min = alrm->tm_min; in rtc_next_alarm_time()
87 next->tm_sec = alrm->tm_sec; in rtc_next_alarm_time()
103 unsigned long ticks, base, data; in pm80x_rtc_read_time() local
104 regmap_raw_read(info->map, PM800_RTC_EXPIRE2_1, buf, 4); in pm80x_rtc_read_time()
105 base = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | in pm80x_rtc_read_time()
107 dev_dbg(info->dev, "%x-%x-%x-%x\n", buf[0], buf[1], buf[2], buf[3]); in pm80x_rtc_read_time()
109 /* load 32-bit read-only counter */ in pm80x_rtc_read_time()
110 regmap_raw_read(info->map, PM800_RTC_COUNTER1, buf, 4); in pm80x_rtc_read_time()
111 data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | in pm80x_rtc_read_time()
113 ticks = base + data; in pm80x_rtc_read_time()
114 dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", in pm80x_rtc_read_time()
115 base, data, ticks); in pm80x_rtc_read_time()
124 unsigned long ticks, base, data; in pm80x_rtc_set_time() local
128 /* load 32-bit read-only counter */ in pm80x_rtc_set_time()
129 regmap_raw_read(info->map, PM800_RTC_COUNTER1, buf, 4); in pm80x_rtc_set_time()
130 data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | in pm80x_rtc_set_time()
132 base = ticks - data; in pm80x_rtc_set_time()
133 dev_dbg(info->dev, "set base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", in pm80x_rtc_set_time()
134 base, data, ticks); in pm80x_rtc_set_time()
135 buf[0] = base & 0xFF; in pm80x_rtc_set_time()
136 buf[1] = (base >> 8) & 0xFF; in pm80x_rtc_set_time()
137 buf[2] = (base >> 16) & 0xFF; in pm80x_rtc_set_time()
138 buf[3] = (base >> 24) & 0xFF; in pm80x_rtc_set_time()
139 regmap_raw_write(info->map, PM800_RTC_EXPIRE2_1, buf, 4); in pm80x_rtc_set_time()
148 unsigned long ticks, base, data; in pm80x_rtc_read_alarm() local
151 regmap_raw_read(info->map, PM800_RTC_EXPIRE2_1, buf, 4); in pm80x_rtc_read_alarm()
152 base = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | in pm80x_rtc_read_alarm()
154 dev_dbg(info->dev, "%x-%x-%x-%x\n", buf[0], buf[1], buf[2], buf[3]); in pm80x_rtc_read_alarm()
156 regmap_raw_read(info->map, PM800_RTC_EXPIRE1_1, buf, 4); in pm80x_rtc_read_alarm()
157 data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | in pm80x_rtc_read_alarm()
159 ticks = base + data; in pm80x_rtc_read_alarm()
160 dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", in pm80x_rtc_read_alarm()
161 base, data, ticks); in pm80x_rtc_read_alarm()
163 rtc_time64_to_tm(ticks, &alrm->time); in pm80x_rtc_read_alarm()
164 regmap_read(info->map, PM800_RTC_CONTROL, &ret); in pm80x_rtc_read_alarm()
165 alrm->enabled = (ret & PM800_ALARM1_EN) ? 1 : 0; in pm80x_rtc_read_alarm()
166 alrm->pending = (ret & (PM800_ALARM | PM800_ALARM_WAKEUP)) ? 1 : 0; in pm80x_rtc_read_alarm()
174 unsigned long ticks, base, data; in pm80x_rtc_set_alarm() local
178 regmap_update_bits(info->map, PM800_RTC_CONTROL, PM800_ALARM1_EN, 0); in pm80x_rtc_set_alarm()
180 regmap_raw_read(info->map, PM800_RTC_EXPIRE2_1, buf, 4); in pm80x_rtc_set_alarm()
181 base = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | in pm80x_rtc_set_alarm()
183 dev_dbg(info->dev, "%x-%x-%x-%x\n", buf[0], buf[1], buf[2], buf[3]); in pm80x_rtc_set_alarm()
185 /* load 32-bit read-only counter */ in pm80x_rtc_set_alarm()
186 regmap_raw_read(info->map, PM800_RTC_COUNTER1, buf, 4); in pm80x_rtc_set_alarm()
187 data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | in pm80x_rtc_set_alarm()
189 ticks = base + data; in pm80x_rtc_set_alarm()
190 dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", in pm80x_rtc_set_alarm()
191 base, data, ticks); in pm80x_rtc_set_alarm()
194 dev_dbg(info->dev, "%s, now time : %lu\n", __func__, ticks); in pm80x_rtc_set_alarm()
195 rtc_next_alarm_time(&alarm_tm, &now_tm, &alrm->time); in pm80x_rtc_set_alarm()
198 dev_dbg(info->dev, "%s, alarm time: %lu\n", __func__, ticks); in pm80x_rtc_set_alarm()
199 data = ticks - base; in pm80x_rtc_set_alarm()
204 buf[3] = (data >> 24) & 0xff; in pm80x_rtc_set_alarm()
205 regmap_raw_write(info->map, PM800_RTC_EXPIRE1_1, buf, 4); in pm80x_rtc_set_alarm()
206 if (alrm->enabled) { in pm80x_rtc_set_alarm()
208 regmap_update_bits(info->map, PM800_RTC_CONTROL, mask, mask); in pm80x_rtc_set_alarm()
211 regmap_update_bits(info->map, PM800_RTC_CONTROL, mask, in pm80x_rtc_set_alarm()
241 struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent); in pm80x_rtc_probe()
242 struct pm80x_rtc_pdata *pdata = dev_get_platdata(&pdev->dev); in pm80x_rtc_probe()
244 struct device_node *node = pdev->dev.of_node; in pm80x_rtc_probe()
248 dev_err(&pdev->dev, in pm80x_rtc_probe()
249 "pm80x-rtc requires platform data or of_node\n"); in pm80x_rtc_probe()
250 return -EINVAL; in pm80x_rtc_probe()
254 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in pm80x_rtc_probe()
256 dev_err(&pdev->dev, "failed to allocate memory\n"); in pm80x_rtc_probe()
257 return -ENOMEM; in pm80x_rtc_probe()
262 devm_kzalloc(&pdev->dev, sizeof(struct pm80x_rtc_info), GFP_KERNEL); in pm80x_rtc_probe()
264 return -ENOMEM; in pm80x_rtc_probe()
265 info->irq = platform_get_irq(pdev, 0); in pm80x_rtc_probe()
266 if (info->irq < 0) { in pm80x_rtc_probe()
267 ret = -EINVAL; in pm80x_rtc_probe()
271 info->chip = chip; in pm80x_rtc_probe()
272 info->map = chip->regmap; in pm80x_rtc_probe()
273 if (!info->map) { in pm80x_rtc_probe()
274 dev_err(&pdev->dev, "no regmap!\n"); in pm80x_rtc_probe()
275 ret = -EINVAL; in pm80x_rtc_probe()
279 info->dev = &pdev->dev; in pm80x_rtc_probe()
280 dev_set_drvdata(&pdev->dev, info); in pm80x_rtc_probe()
282 info->rtc_dev = devm_rtc_allocate_device(&pdev->dev); in pm80x_rtc_probe()
283 if (IS_ERR(info->rtc_dev)) in pm80x_rtc_probe()
284 return PTR_ERR(info->rtc_dev); in pm80x_rtc_probe()
286 ret = pm80x_request_irq(chip, info->irq, rtc_update_handler, in pm80x_rtc_probe()
289 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", in pm80x_rtc_probe()
290 info->irq, ret); in pm80x_rtc_probe()
294 info->rtc_dev->ops = &pm80x_rtc_ops; in pm80x_rtc_probe()
295 info->rtc_dev->range_max = U32_MAX; in pm80x_rtc_probe()
297 ret = devm_rtc_register_device(info->rtc_dev); in pm80x_rtc_probe()
303 * free running in PMIC power-down state. in pm80x_rtc_probe()
305 regmap_update_bits(info->map, PM800_RTC_CONTROL, PM800_RTC1_USE_XO, in pm80x_rtc_probe()
309 info->rtc_dev->dev.platform_data = &pdata->rtc_wakeup; in pm80x_rtc_probe()
311 device_init_wakeup(&pdev->dev, 1); in pm80x_rtc_probe()
315 pm80x_free_irq(chip, info->irq, info); in pm80x_rtc_probe()
323 pm80x_free_irq(info->chip, info->irq, info); in pm80x_rtc_remove()
328 .name = "88pm80x-rtc",
340 MODULE_ALIAS("platform:88pm80x-rtc");