Lines Matching +full:int +full:- +full:map +full:- +full:mask

1 // SPDX-License-Identifier: GPL-2.0
40 struct regmap *map; member
44 int irq;
47 static irqreturn_t rtc_update_handler(int irq, void *data) in rtc_update_handler()
50 int mask; in rtc_update_handler() local
52 mask = PM800_ALARM | PM800_ALARM_WAKEUP; in rtc_update_handler()
53 regmap_update_bits(info->map, PM800_RTC_CONTROL, mask | PM800_ALARM1_EN, in rtc_update_handler()
54 mask); in rtc_update_handler()
55 rtc_update_irq(info->rtc_dev, 1, RTC_AF); in rtc_update_handler()
59 static int pm80x_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) in pm80x_rtc_alarm_irq_enable()
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()
73 * Calculate the next alarm time given the requested alarm time mask
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()
99 static int pm80x_rtc_read_time(struct device *dev, struct rtc_time *tm) in pm80x_rtc_read_time()
104 regmap_raw_read(info->map, PM800_RTC_EXPIRE2_1, buf, 4); 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()
114 dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", in pm80x_rtc_read_time()
120 static int pm80x_rtc_set_time(struct device *dev, struct rtc_time *tm) in pm80x_rtc_set_time()
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()
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()
139 regmap_raw_write(info->map, PM800_RTC_EXPIRE2_1, buf, 4); in pm80x_rtc_set_time()
144 static int pm80x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) in pm80x_rtc_read_alarm()
149 int ret; in pm80x_rtc_read_alarm()
151 regmap_raw_read(info->map, PM800_RTC_EXPIRE2_1, buf, 4); 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()
160 dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", 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()
170 static int pm80x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) in pm80x_rtc_set_alarm()
176 int mask; 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()
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()
190 dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", 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()
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()
207 mask = PM800_ALARM | PM800_ALARM_WAKEUP | PM800_ALARM1_EN; in pm80x_rtc_set_alarm()
208 regmap_update_bits(info->map, PM800_RTC_CONTROL, mask, mask); in pm80x_rtc_set_alarm()
210 mask = PM800_ALARM | PM800_ALARM_WAKEUP | PM800_ALARM1_EN; in pm80x_rtc_set_alarm()
211 regmap_update_bits(info->map, PM800_RTC_CONTROL, mask, in pm80x_rtc_set_alarm()
226 static int pm80x_rtc_suspend(struct device *dev) in pm80x_rtc_suspend()
231 static int pm80x_rtc_resume(struct device *dev) in pm80x_rtc_resume()
239 static int pm80x_rtc_probe(struct platform_device *pdev) in pm80x_rtc_probe()
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()
245 int ret; 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");