Lines Matching +full:bd71828 +full:- +full:pmic

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 // RTC driver for ROHM BD71828 and BD71815 PMIC
8 #include <linux/mfd/rohm-bd71815.h>
9 #include <linux/mfd/rohm-bd71828.h>
17 * On BD71828 and BD71815 the ALM0 MASK is 14 bytes after the ALM0
58 d->sec &= ~BD70528_MASK_RTC_SEC; in tmday2rtc()
59 d->min &= ~BD70528_MASK_RTC_MINUTE; in tmday2rtc()
60 d->hour &= ~BD70528_MASK_RTC_HOUR; in tmday2rtc()
61 d->sec |= bin2bcd(t->tm_sec); in tmday2rtc()
62 d->min |= bin2bcd(t->tm_min); in tmday2rtc()
63 d->hour |= bin2bcd(t->tm_hour); in tmday2rtc()
68 r->day &= ~BD70528_MASK_RTC_DAY; in tm2rtc()
69 r->week &= ~BD70528_MASK_RTC_WEEK; in tm2rtc()
70 r->month &= ~BD70528_MASK_RTC_MONTH; in tm2rtc()
72 * PM and 24H bits are not used by Wake - thus we clear them in tm2rtc()
75 r->time.hour &= ~(BD70528_MASK_RTC_HOUR_PM | BD70528_MASK_RTC_HOUR_24H); in tm2rtc()
77 tmday2rtc(t, &r->time); in tm2rtc()
81 r->time.hour |= BD70528_MASK_RTC_HOUR_24H; in tm2rtc()
82 r->day |= bin2bcd(t->tm_mday); in tm2rtc()
83 r->week |= bin2bcd(t->tm_wday); in tm2rtc()
84 r->month |= bin2bcd(t->tm_mon + 1); in tm2rtc()
85 r->year = bin2bcd(t->tm_year - 100); in tm2rtc()
90 t->tm_sec = bcd2bin(r->time.sec & BD70528_MASK_RTC_SEC); in rtc2tm()
91 t->tm_min = bcd2bin(r->time.min & BD70528_MASK_RTC_MINUTE); in rtc2tm()
92 t->tm_hour = bcd2bin(r->time.hour & BD70528_MASK_RTC_HOUR); in rtc2tm()
97 if (!(r->time.hour & BD70528_MASK_RTC_HOUR_24H)) { in rtc2tm()
98 t->tm_hour %= 12; in rtc2tm()
99 if (r->time.hour & BD70528_MASK_RTC_HOUR_PM) in rtc2tm()
100 t->tm_hour += 12; in rtc2tm()
102 t->tm_mday = bcd2bin(r->day & BD70528_MASK_RTC_DAY); in rtc2tm()
103 t->tm_mon = bcd2bin(r->month & BD70528_MASK_RTC_MONTH) - 1; in rtc2tm()
104 t->tm_year = 100 + bcd2bin(r->year & BD70528_MASK_RTC_YEAR); in rtc2tm()
105 t->tm_wday = bcd2bin(r->week & BD70528_MASK_RTC_WEEK); in rtc2tm()
114 ret = regmap_bulk_read(r->regmap, r->bd718xx_alm_block_start, &alm, in bd71828_set_alarm()
121 tm2rtc(&a->time, &alm.alm0); in bd71828_set_alarm()
123 if (!a->enabled) in bd71828_set_alarm()
128 ret = regmap_bulk_write(r->regmap, r->bd718xx_alm_block_start, &alm, in bd71828_set_alarm()
143 ret = regmap_bulk_read(r->regmap, r->bd718xx_alm_block_start, &alm, in bd71828_read_alarm()
150 rtc2tm(&alm.alm0, &a->time); in bd71828_read_alarm()
151 a->time.tm_mday = -1; in bd71828_read_alarm()
152 a->time.tm_mon = -1; in bd71828_read_alarm()
153 a->time.tm_year = -1; in bd71828_read_alarm()
154 a->enabled = !!(alm.alm_mask & BD70528_MASK_ALM_EN); in bd71828_read_alarm()
155 a->pending = 0; in bd71828_read_alarm()
166 ret = regmap_bulk_read(r->regmap, r->reg_time_start, &rtc_data, in bd71828_set_time()
174 ret = regmap_bulk_write(r->regmap, r->reg_time_start, &rtc_data, in bd71828_set_time()
189 ret = regmap_bulk_read(r->regmap, r->reg_time_start, &rtc_data, in bd70528_get_time()
210 ret = regmap_update_bits(r->regmap, r->bd718xx_alm_block_start + in bd71828_alm_enable()
244 enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data; in bd70528_probe()
246 bd_rtc = devm_kzalloc(&pdev->dev, sizeof(*bd_rtc), GFP_KERNEL); in bd70528_probe()
248 return -ENOMEM; in bd70528_probe()
250 bd_rtc->regmap = dev_get_regmap(pdev->dev.parent, NULL); in bd70528_probe()
251 if (!bd_rtc->regmap) { in bd70528_probe()
252 dev_err(&pdev->dev, "No regmap\n"); in bd70528_probe()
253 return -EINVAL; in bd70528_probe()
256 bd_rtc->dev = &pdev->dev; in bd70528_probe()
261 bd_rtc->reg_time_start = BD71815_REG_RTC_START; in bd70528_probe()
265 * This works for BD71828 and BD71815 as they have same offset in bd70528_probe()
268 * at the end of ALM0 block - but after all ALM blocks so if in bd70528_probe()
273 bd_rtc->bd718xx_alm_block_start = BD71815_REG_RTC_ALM_START; in bd70528_probe()
277 bd_rtc->reg_time_start = BD71828_REG_RTC_START; in bd70528_probe()
278 bd_rtc->bd718xx_alm_block_start = BD71828_REG_RTC_ALM_START; in bd70528_probe()
282 dev_err(&pdev->dev, "Unknown chip\n"); in bd70528_probe()
283 return -ENOENT; in bd70528_probe()
286 irq = platform_get_irq_byname(pdev, "bd70528-rtc-alm-0"); in bd70528_probe()
293 ret = regmap_read(bd_rtc->regmap, hour_reg, &hr); in bd70528_probe()
296 dev_err(&pdev->dev, "Failed to reag RTC clock\n"); in bd70528_probe()
303 ret = rtc_ops->read_time(&pdev->dev, &t); in bd70528_probe()
306 ret = rtc_ops->set_time(&pdev->dev, &t); in bd70528_probe()
309 dev_err(&pdev->dev, in bd70528_probe()
315 device_set_wakeup_capable(&pdev->dev, true); in bd70528_probe()
316 device_wakeup_enable(&pdev->dev); in bd70528_probe()
318 rtc = devm_rtc_allocate_device(&pdev->dev); in bd70528_probe()
320 dev_err(&pdev->dev, "RTC device creation failed\n"); in bd70528_probe()
324 rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in bd70528_probe()
325 rtc->range_max = RTC_TIMESTAMP_END_2099; in bd70528_probe()
326 rtc->ops = rtc_ops; in bd70528_probe()
329 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, &alm_hndlr, in bd70528_probe()
330 IRQF_ONESHOT, "bd70528-rtc", rtc); in bd70528_probe()
338 { "bd71828-rtc", ROHM_CHIP_TYPE_BD71828 },
339 { "bd71815-rtc", ROHM_CHIP_TYPE_BD71815 },
346 .name = "bd70528-rtc"
355 MODULE_DESCRIPTION("ROHM BD71828 and BD71815 PMIC RTC driver");
357 MODULE_ALIAS("platform:bd70528-rtc");