Linux Audio

Check our new training course

Buildroot integration, development and maintenance

Need a Buildroot system for your embedded project?
Loading...
v3.1
 1/* rtc-starfire.c: Starfire platform RTC driver.
 2 *
 
 
 
 3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
 4 */
 5
 6#include <linux/kernel.h>
 7#include <linux/module.h>
 8#include <linux/init.h>
 9#include <linux/rtc.h>
10#include <linux/platform_device.h>
11
12#include <asm/oplib.h>
13
14MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
15MODULE_DESCRIPTION("Starfire RTC driver");
16MODULE_LICENSE("GPL");
17
18static u32 starfire_get_time(void)
19{
20	static char obp_gettod[32];
21	static u32 unix_tod;
22
23	sprintf(obp_gettod, "h# %08x unix-gettod",
24		(unsigned int) (long) &unix_tod);
25	prom_feval(obp_gettod);
26
27	return unix_tod;
28}
29
30static int starfire_read_time(struct device *dev, struct rtc_time *tm)
31{
32	rtc_time_to_tm(starfire_get_time(), tm);
33	return rtc_valid_tm(tm);
34}
35
36static const struct rtc_class_ops starfire_rtc_ops = {
37	.read_time	= starfire_read_time,
38};
39
40static int __init starfire_rtc_probe(struct platform_device *pdev)
41{
42	struct rtc_device *rtc = rtc_device_register("starfire", &pdev->dev,
43				     &starfire_rtc_ops, THIS_MODULE);
 
44	if (IS_ERR(rtc))
45		return PTR_ERR(rtc);
46
47	platform_set_drvdata(pdev, rtc);
48
49	return 0;
50}
51
52static int __exit starfire_rtc_remove(struct platform_device *pdev)
53{
54	struct rtc_device *rtc = platform_get_drvdata(pdev);
55
56	rtc_device_unregister(rtc);
57
58	return 0;
59}
60
61static struct platform_driver starfire_rtc_driver = {
62	.driver		= {
63		.name	= "rtc-starfire",
64		.owner	= THIS_MODULE,
65	},
66	.remove		= __exit_p(starfire_rtc_remove),
67};
68
69static int __init starfire_rtc_init(void)
70{
71	return platform_driver_probe(&starfire_rtc_driver, starfire_rtc_probe);
72}
73
74static void __exit starfire_rtc_exit(void)
75{
76	platform_driver_unregister(&starfire_rtc_driver);
77}
78
79module_init(starfire_rtc_init);
80module_exit(starfire_rtc_exit);
v6.2
 1/* rtc-starfire.c: Starfire platform RTC driver.
 2 *
 3 * Author: David S. Miller
 4 * License: GPL
 5 *
 6 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
 7 */
 8
 9#include <linux/kernel.h>
 
10#include <linux/init.h>
11#include <linux/rtc.h>
12#include <linux/platform_device.h>
13
14#include <asm/oplib.h>
15
 
 
 
 
16static u32 starfire_get_time(void)
17{
18	static char obp_gettod[32];
19	static u32 unix_tod;
20
21	sprintf(obp_gettod, "h# %08x unix-gettod",
22		(unsigned int) (long) &unix_tod);
23	prom_feval(obp_gettod);
24
25	return unix_tod;
26}
27
28static int starfire_read_time(struct device *dev, struct rtc_time *tm)
29{
30	rtc_time64_to_tm(starfire_get_time(), tm);
31	return 0;
32}
33
34static const struct rtc_class_ops starfire_rtc_ops = {
35	.read_time	= starfire_read_time,
36};
37
38static int __init starfire_rtc_probe(struct platform_device *pdev)
39{
40	struct rtc_device *rtc;
41
42	rtc = devm_rtc_allocate_device(&pdev->dev);
43	if (IS_ERR(rtc))
44		return PTR_ERR(rtc);
45
46	rtc->ops = &starfire_rtc_ops;
47	rtc->range_max = U32_MAX;
 
 
 
 
 
 
48
49	platform_set_drvdata(pdev, rtc);
50
51	return devm_rtc_register_device(rtc);
52}
53
54static struct platform_driver starfire_rtc_driver = {
55	.driver		= {
56		.name	= "rtc-starfire",
 
57	},
 
58};
59
60builtin_platform_driver_probe(starfire_rtc_driver, starfire_rtc_probe);