|
@@ -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>
|
|
@@ -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
|
|
@@ -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),
|
|
@@ -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,
|
|
|
}
|
|
|
};
|
|
|
|