Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 234930
b: refs/heads/master
c: 3bcbaf6
h: refs/heads/master
v: v3
  • Loading branch information
Sebastian Andrzej Siewior authored and Thomas Gleixner committed Feb 23, 2011
1 parent 1d95682 commit 0e68659
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1fa4163bdc199a0b80f9e333d718b3f65e901593
refs/heads/master: 3bcbaf6e08d8d82cde781997bd2c56dda87049b5
28 changes: 28 additions & 0 deletions trunk/Documentation/devicetree/bindings/rtc/rtc-cmos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Motorola mc146818 compatible RTC
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Required properties:
- compatible : "motorola,mc146818"
- reg : should contain registers location and length.

Optional properties:
- interrupts : should contain interrupt.
- interrupt-parent : interrupt source phandle.
- ctrl-reg : Contains the initial value of the control register also
called "Register B".
- freq-reg : Contains the initial value of the frequency register also
called "Regsiter A".

"Register A" and "B" are usually initialized by the firmware (BIOS for
instance). If this is not done, it can be performed by the driver.

ISA Example:

rtc@70 {
compatible = "motorola,mc146818";
interrupts = <8 3>;
interrupt-parent = <&ioapic1>;
ctrl-reg = <2>;
freq-reg = <0x26>;
reg = <1 0x70 2>;
};
3 changes: 3 additions & 0 deletions trunk/arch/x86/kernel/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <linux/acpi.h>
#include <linux/bcd.h>
#include <linux/pnp.h>
#include <linux/of.h>

#include <asm/vsyscall.h>
#include <asm/x86_init.h>
Expand Down Expand Up @@ -236,6 +237,8 @@ static __init int add_rtc_cmos(void)
}
}
#endif
if (of_have_populated_dt())
return 0;

platform_device_register(&rtc_device);
dev_info(&rtc_device.dev,
Expand Down
45 changes: 45 additions & 0 deletions trunk/drivers/rtc/rtc-cmos.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <linux/mod_devicetable.h>
#include <linux/log2.h>
#include <linux/pm.h>
#include <linux/of.h>
#include <linux/of_platform.h>

/* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */
#include <asm-generic/rtc.h>
Expand Down Expand Up @@ -1123,6 +1125,47 @@ static struct pnp_driver cmos_pnp_driver = {

#endif /* CONFIG_PNP */

#ifdef CONFIG_OF
static const struct of_device_id of_cmos_match[] = {
{
.compatible = "motorola,mc146818",
},
{ },
};
MODULE_DEVICE_TABLE(of, of_cmos_match);

static __init void cmos_of_init(struct platform_device *pdev)
{
struct device_node *node = pdev->dev.of_node;
struct rtc_time time;
int ret;
const __be32 *val;

if (!node)
return;

val = of_get_property(node, "ctrl-reg", NULL);
if (val)
CMOS_WRITE(be32_to_cpup(val), RTC_CONTROL);

val = of_get_property(node, "freq-reg", NULL);
if (val)
CMOS_WRITE(be32_to_cpup(val), RTC_FREQ_SELECT);

get_rtc_time(&time);
ret = rtc_valid_tm(&time);
if (ret) {
struct rtc_time def_time = {
.tm_year = 1,
.tm_mday = 1,
};
set_rtc_time(&def_time);
}
}
#else
static inline void cmos_of_init(struct platform_device *pdev) {}
#define of_cmos_match NULL
#endif
/*----------------------------------------------------------------*/

/* Platform setup should have set up an RTC device, when PNP is
Expand All @@ -1131,6 +1174,7 @@ static struct pnp_driver cmos_pnp_driver = {

static int __init cmos_platform_probe(struct platform_device *pdev)
{
cmos_of_init(pdev);
cmos_wake_setup(&pdev->dev);
return cmos_do_probe(&pdev->dev,
platform_get_resource(pdev, IORESOURCE_IO, 0),
Expand Down Expand Up @@ -1162,6 +1206,7 @@ static struct platform_driver cmos_platform_driver = {
#ifdef CONFIG_PM
.pm = &cmos_pm_ops,
#endif
.of_match_table = of_cmos_match,
}
};

Expand Down
12 changes: 12 additions & 0 deletions trunk/include/linux/of.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ extern struct device_node *allnodes;
extern struct device_node *of_chosen;
extern rwlock_t devtree_lock;

static inline bool of_have_populated_dt(void)
{
return allnodes != NULL;
}

static inline bool of_node_is_root(const struct device_node *node)
{
return node && (node->parent == NULL);
Expand Down Expand Up @@ -222,5 +227,12 @@ extern void of_attach_node(struct device_node *);
extern void of_detach_node(struct device_node *);
#endif

#else

static inline bool of_have_populated_dt(void)
{
return false;
}

#endif /* CONFIG_OF */
#endif /* _LINUX_OF_H */

0 comments on commit 0e68659

Please sign in to comment.