blob: 07ede21cee347ce08be451293f8f8d9c4f696341 [file] [log] [blame]
Alexandre Bellonicdf75452019-03-13 23:02:48 +01001// SPDX-License-Identifier: GPL-2.0
Alexandre Belloni697e5a42017-07-06 11:42:02 +02002/*
3 * RTC subsystem, nvmem interface
4 *
5 * Copyright (C) 2017 Alexandre Belloni
Alexandre Belloni697e5a42017-07-06 11:42:02 +02006 */
7
8#include <linux/err.h>
9#include <linux/types.h>
10#include <linux/nvmem-consumer.h>
11#include <linux/rtc.h>
Alexandre Belloni697e5a42017-07-06 11:42:02 +020012
Bartosz Golaszewski3a905c2d2020-11-09 17:34:06 +010013int devm_rtc_nvmem_register(struct rtc_device *rtc,
Alexandre Belloni2cc82122018-02-12 23:47:17 +010014 struct nvmem_config *nvmem_config)
Alexandre Belloni697e5a42017-07-06 11:42:02 +020015{
Bartosz Golaszewski6746bc02020-11-09 17:34:07 +010016 struct device *dev = rtc->dev.parent;
Alexandre Belloni41c9e132018-11-10 21:29:03 +010017 struct nvmem_device *nvmem;
Alexandre Belloniab3ea362018-02-12 23:47:18 +010018
Alexandre Belloni4cce9d32018-02-12 23:47:16 +010019 if (!nvmem_config)
Alexandre Belloni2cc82122018-02-12 23:47:17 +010020 return -ENODEV;
Alexandre Belloni697e5a42017-07-06 11:42:02 +020021
Bartosz Golaszewski6746bc02020-11-09 17:34:07 +010022 nvmem_config->dev = dev;
Alexandre Belloni4cce9d32018-02-12 23:47:16 +010023 nvmem_config->owner = rtc->owner;
Bartosz Golaszewski6746bc02020-11-09 17:34:07 +010024 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 Belloni697e5a42017-07-06 11:42:02 +020027
Alexandre Belloni25ece302020-11-09 17:34:05 +010028 return PTR_ERR_OR_ZERO(nvmem);
Alexandre Belloni697e5a42017-07-06 11:42:02 +020029}
Bartosz Golaszewski3a905c2d2020-11-09 17:34:06 +010030EXPORT_SYMBOL_GPL(devm_rtc_nvmem_register);