diff options
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/rtc-cmos.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index c7ff8df347e7..159b95e4b420 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c | |||
@@ -37,6 +37,8 @@ | |||
37 | #include <linux/mod_devicetable.h> | 37 | #include <linux/mod_devicetable.h> |
38 | #include <linux/log2.h> | 38 | #include <linux/log2.h> |
39 | #include <linux/pm.h> | 39 | #include <linux/pm.h> |
40 | #include <linux/of.h> | ||
41 | #include <linux/of_platform.h> | ||
40 | 42 | ||
41 | /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ | 43 | /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ |
42 | #include <asm-generic/rtc.h> | 44 | #include <asm-generic/rtc.h> |
@@ -1123,6 +1125,47 @@ static struct pnp_driver cmos_pnp_driver = { | |||
1123 | 1125 | ||
1124 | #endif /* CONFIG_PNP */ | 1126 | #endif /* CONFIG_PNP */ |
1125 | 1127 | ||
1128 | #ifdef CONFIG_OF | ||
1129 | static const struct of_device_id of_cmos_match[] = { | ||
1130 | { | ||
1131 | .compatible = "motorola,mc146818", | ||
1132 | }, | ||
1133 | { }, | ||
1134 | }; | ||
1135 | MODULE_DEVICE_TABLE(of, of_cmos_match); | ||
1136 | |||
1137 | static __init void cmos_of_init(struct platform_device *pdev) | ||
1138 | { | ||
1139 | struct device_node *node = pdev->dev.of_node; | ||
1140 | struct rtc_time time; | ||
1141 | int ret; | ||
1142 | const __be32 *val; | ||
1143 | |||
1144 | if (!node) | ||
1145 | return; | ||
1146 | |||
1147 | val = of_get_property(node, "ctrl-reg", NULL); | ||
1148 | if (val) | ||
1149 | CMOS_WRITE(be32_to_cpup(val), RTC_CONTROL); | ||
1150 | |||
1151 | val = of_get_property(node, "freq-reg", NULL); | ||
1152 | if (val) | ||
1153 | CMOS_WRITE(be32_to_cpup(val), RTC_FREQ_SELECT); | ||
1154 | |||
1155 | get_rtc_time(&time); | ||
1156 | ret = rtc_valid_tm(&time); | ||
1157 | if (ret) { | ||
1158 | struct rtc_time def_time = { | ||
1159 | .tm_year = 1, | ||
1160 | .tm_mday = 1, | ||
1161 | }; | ||
1162 | set_rtc_time(&def_time); | ||
1163 | } | ||
1164 | } | ||
1165 | #else | ||
1166 | static inline void cmos_of_init(struct platform_device *pdev) {} | ||
1167 | #define of_cmos_match NULL | ||
1168 | #endif | ||
1126 | /*----------------------------------------------------------------*/ | 1169 | /*----------------------------------------------------------------*/ |
1127 | 1170 | ||
1128 | /* Platform setup should have set up an RTC device, when PNP is | 1171 | /* Platform setup should have set up an RTC device, when PNP is |
@@ -1131,6 +1174,7 @@ static struct pnp_driver cmos_pnp_driver = { | |||
1131 | 1174 | ||
1132 | static int __init cmos_platform_probe(struct platform_device *pdev) | 1175 | static int __init cmos_platform_probe(struct platform_device *pdev) |
1133 | { | 1176 | { |
1177 | cmos_of_init(pdev); | ||
1134 | cmos_wake_setup(&pdev->dev); | 1178 | cmos_wake_setup(&pdev->dev); |
1135 | return cmos_do_probe(&pdev->dev, | 1179 | return cmos_do_probe(&pdev->dev, |
1136 | platform_get_resource(pdev, IORESOURCE_IO, 0), | 1180 | platform_get_resource(pdev, IORESOURCE_IO, 0), |
@@ -1162,6 +1206,7 @@ static struct platform_driver cmos_platform_driver = { | |||
1162 | #ifdef CONFIG_PM | 1206 | #ifdef CONFIG_PM |
1163 | .pm = &cmos_pm_ops, | 1207 | .pm = &cmos_pm_ops, |
1164 | #endif | 1208 | #endif |
1209 | .of_match_table = of_cmos_match, | ||
1165 | } | 1210 | } |
1166 | }; | 1211 | }; |
1167 | 1212 | ||