Alexandre Belloni | cdf7545 | 2019-03-13 23:02:48 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Alexandre Belloni | 697e5a4 | 2017-07-06 11:42:02 +0200 | [diff] [blame] | 2 | /* |
| 3 | * RTC subsystem, nvmem interface |
| 4 | * |
| 5 | * Copyright (C) 2017 Alexandre Belloni |
Alexandre Belloni | 697e5a4 | 2017-07-06 11:42:02 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/err.h> |
| 9 | #include <linux/types.h> |
| 10 | #include <linux/nvmem-consumer.h> |
| 11 | #include <linux/rtc.h> |
Alexandre Belloni | 697e5a4 | 2017-07-06 11:42:02 +0200 | [diff] [blame] | 12 | |
Bartosz Golaszewski | 3a905c2d | 2020-11-09 17:34:06 +0100 | [diff] [blame] | 13 | int devm_rtc_nvmem_register(struct rtc_device *rtc, |
Alexandre Belloni | 2cc8212 | 2018-02-12 23:47:17 +0100 | [diff] [blame] | 14 | struct nvmem_config *nvmem_config) |
Alexandre Belloni | 697e5a4 | 2017-07-06 11:42:02 +0200 | [diff] [blame] | 15 | { |
Bartosz Golaszewski | 6746bc0 | 2020-11-09 17:34:07 +0100 | [diff] [blame] | 16 | struct device *dev = rtc->dev.parent; |
Alexandre Belloni | 41c9e13 | 2018-11-10 21:29:03 +0100 | [diff] [blame] | 17 | struct nvmem_device *nvmem; |
Alexandre Belloni | ab3ea36 | 2018-02-12 23:47:18 +0100 | [diff] [blame] | 18 | |
Alexandre Belloni | 4cce9d3 | 2018-02-12 23:47:16 +0100 | [diff] [blame] | 19 | if (!nvmem_config) |
Alexandre Belloni | 2cc8212 | 2018-02-12 23:47:17 +0100 | [diff] [blame] | 20 | return -ENODEV; |
Alexandre Belloni | 697e5a4 | 2017-07-06 11:42:02 +0200 | [diff] [blame] | 21 | |
Bartosz Golaszewski | 6746bc0 | 2020-11-09 17:34:07 +0100 | [diff] [blame] | 22 | nvmem_config->dev = dev; |
Alexandre Belloni | 4cce9d3 | 2018-02-12 23:47:16 +0100 | [diff] [blame] | 23 | nvmem_config->owner = rtc->owner; |
Bartosz Golaszewski | 6746bc0 | 2020-11-09 17:34:07 +0100 | [diff] [blame] | 24 | nvmem = devm_nvmem_register(dev, nvmem_config); |
| 25 | if (IS_ERR(nvmem)) |
| 26 | dev_err(dev, "failed to register nvmem device for RTC\n"); |
Alexandre Belloni | 697e5a4 | 2017-07-06 11:42:02 +0200 | [diff] [blame] | 27 | |
Alexandre Belloni | 25ece30 | 2020-11-09 17:34:05 +0100 | [diff] [blame] | 28 | return PTR_ERR_OR_ZERO(nvmem); |
Alexandre Belloni | 697e5a4 | 2017-07-06 11:42:02 +0200 | [diff] [blame] | 29 | } |
Bartosz Golaszewski | 3a905c2d | 2020-11-09 17:34:06 +0100 | [diff] [blame] | 30 | EXPORT_SYMBOL_GPL(devm_rtc_nvmem_register); |