Linux Audio

Check our new training course

Loading...
v5.9
 1// SPDX-License-Identifier: GPL-2.0-only
 2/* rtc-generic: RTC driver using the generic RTC abstraction
 3 *
 4 * Copyright (C) 2008 Kyle McMartin <kyle@mcmartin.ca>
 5 */
 6
 7#include <linux/kernel.h>
 8#include <linux/module.h>
 9#include <linux/time.h>
10#include <linux/platform_device.h>
11#include <linux/rtc.h>
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13static int __init generic_rtc_probe(struct platform_device *dev)
14{
15	struct rtc_device *rtc;
16	const struct rtc_class_ops *ops = dev_get_platdata(&dev->dev);
17
18	rtc = devm_rtc_device_register(&dev->dev, "rtc-generic",
19					ops, THIS_MODULE);
20	if (IS_ERR(rtc))
21		return PTR_ERR(rtc);
22
23	platform_set_drvdata(dev, rtc);
24
25	return 0;
26}
27
28static struct platform_driver generic_rtc_driver = {
29	.driver = {
30		.name = "rtc-generic",
 
31	},
32};
33
34module_platform_driver_probe(generic_rtc_driver, generic_rtc_probe);
35
36MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>");
37MODULE_LICENSE("GPL");
38MODULE_DESCRIPTION("Generic RTC driver");
39MODULE_ALIAS("platform:rtc-generic");
v3.15
 
 1/* rtc-generic: RTC driver using the generic RTC abstraction
 2 *
 3 * Copyright (C) 2008 Kyle McMartin <kyle@mcmartin.ca>
 4 */
 5
 6#include <linux/kernel.h>
 7#include <linux/module.h>
 8#include <linux/time.h>
 9#include <linux/platform_device.h>
10#include <linux/rtc.h>
11
12#include <asm/rtc.h>
13
14static int generic_get_time(struct device *dev, struct rtc_time *tm)
15{
16	unsigned int ret = get_rtc_time(tm);
17
18	if (ret & RTC_BATT_BAD)
19		return -EOPNOTSUPP;
20
21	return rtc_valid_tm(tm);
22}
23
24static int generic_set_time(struct device *dev, struct rtc_time *tm)
25{
26	if (set_rtc_time(tm) < 0)
27		return -EOPNOTSUPP;
28
29	return 0;
30}
31
32static const struct rtc_class_ops generic_rtc_ops = {
33	.read_time = generic_get_time,
34	.set_time = generic_set_time,
35};
36
37static int __init generic_rtc_probe(struct platform_device *dev)
38{
39	struct rtc_device *rtc;
 
40
41	rtc = devm_rtc_device_register(&dev->dev, "rtc-generic",
42					&generic_rtc_ops, THIS_MODULE);
43	if (IS_ERR(rtc))
44		return PTR_ERR(rtc);
45
46	platform_set_drvdata(dev, rtc);
47
48	return 0;
49}
50
51static struct platform_driver generic_rtc_driver = {
52	.driver = {
53		.name = "rtc-generic",
54		.owner = THIS_MODULE,
55	},
56};
57
58module_platform_driver_probe(generic_rtc_driver, generic_rtc_probe);
59
60MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>");
61MODULE_LICENSE("GPL");
62MODULE_DESCRIPTION("Generic RTC driver");
63MODULE_ALIAS("platform:rtc-generic");