diff options
Diffstat (limited to 'drivers/rtc')
38 files changed, 836 insertions, 452 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index b5b5c3d485d6..6149ae01e11f 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
| @@ -1111,6 +1111,16 @@ config RTC_DRV_DAVINCI | |||
| 1111 | This driver can also be built as a module. If so, the module | 1111 | This driver can also be built as a module. If so, the module |
| 1112 | will be called rtc-davinci. | 1112 | will be called rtc-davinci. |
| 1113 | 1113 | ||
| 1114 | config RTC_DRV_DIGICOLOR | ||
| 1115 | tristate "Conexant Digicolor RTC" | ||
| 1116 | depends on ARCH_DIGICOLOR | ||
| 1117 | help | ||
| 1118 | If you say yes here you get support for the RTC on Conexant | ||
| 1119 | Digicolor platforms. This currently includes the CX92755 SoC. | ||
| 1120 | |||
| 1121 | This driver can also be built as a module. If so, the module | ||
| 1122 | will be called rtc-digicolor. | ||
| 1123 | |||
| 1114 | config RTC_DRV_IMXDI | 1124 | config RTC_DRV_IMXDI |
| 1115 | tristate "Freescale IMX DryIce Real Time Clock" | 1125 | tristate "Freescale IMX DryIce Real Time Clock" |
| 1116 | depends on ARCH_MXC | 1126 | depends on ARCH_MXC |
| @@ -1121,11 +1131,11 @@ config RTC_DRV_IMXDI | |||
| 1121 | will be called "rtc-imxdi". | 1131 | will be called "rtc-imxdi". |
| 1122 | 1132 | ||
| 1123 | config RTC_DRV_OMAP | 1133 | config RTC_DRV_OMAP |
| 1124 | tristate "TI OMAP1" | 1134 | tristate "TI OMAP Real Time Clock" |
| 1125 | depends on ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 || ARCH_DAVINCI_DA8XX || SOC_AM33XX | 1135 | depends on ARCH_OMAP || ARCH_DAVINCI |
| 1126 | help | 1136 | help |
| 1127 | Say "yes" here to support the on chip real time clock | 1137 | Say "yes" here to support the on chip real time clock |
| 1128 | present on TI OMAP1, AM33xx and DA8xx/OMAP-L13x. | 1138 | present on TI OMAP1, AM33xx, DA8xx/OMAP-L13x, AM43xx and DRA7xx. |
| 1129 | 1139 | ||
| 1130 | This driver can also be built as a module, if so, module | 1140 | This driver can also be built as a module, if so, module |
| 1131 | will be called rtc-omap. | 1141 | will be called rtc-omap. |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 69c87062b098..c31731c29762 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
| @@ -40,6 +40,7 @@ obj-$(CONFIG_RTC_DRV_DA9052) += rtc-da9052.o | |||
| 40 | obj-$(CONFIG_RTC_DRV_DA9055) += rtc-da9055.o | 40 | obj-$(CONFIG_RTC_DRV_DA9055) += rtc-da9055.o |
| 41 | obj-$(CONFIG_RTC_DRV_DA9063) += rtc-da9063.o | 41 | obj-$(CONFIG_RTC_DRV_DA9063) += rtc-da9063.o |
| 42 | obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o | 42 | obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o |
| 43 | obj-$(CONFIG_RTC_DRV_DIGICOLOR) += rtc-digicolor.o | ||
| 43 | obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o | 44 | obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o |
| 44 | obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o | 45 | obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o |
| 45 | obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o | 46 | obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o |
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index 472a5adc4642..ea2a315df6b7 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c | |||
| @@ -55,7 +55,7 @@ static int rtc_suspend(struct device *dev) | |||
| 55 | struct timespec64 delta, delta_delta; | 55 | struct timespec64 delta, delta_delta; |
| 56 | int err; | 56 | int err; |
| 57 | 57 | ||
| 58 | if (has_persistent_clock()) | 58 | if (timekeeping_rtc_skipsuspend()) |
| 59 | return 0; | 59 | return 0; |
| 60 | 60 | ||
| 61 | if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) | 61 | if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) |
| @@ -102,7 +102,7 @@ static int rtc_resume(struct device *dev) | |||
| 102 | struct timespec64 sleep_time; | 102 | struct timespec64 sleep_time; |
| 103 | int err; | 103 | int err; |
| 104 | 104 | ||
| 105 | if (has_persistent_clock()) | 105 | if (timekeeping_rtc_skipresume()) |
| 106 | return 0; | 106 | return 0; |
| 107 | 107 | ||
| 108 | rtc_hctosys_ret = -ENODEV; | 108 | rtc_hctosys_ret = -ENODEV; |
| @@ -117,10 +117,6 @@ static int rtc_resume(struct device *dev) | |||
| 117 | return 0; | 117 | return 0; |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | if (rtc_valid_tm(&tm) != 0) { | ||
| 121 | pr_debug("%s: bogus resume time\n", dev_name(&rtc->dev)); | ||
| 122 | return 0; | ||
| 123 | } | ||
| 124 | new_rtc.tv_sec = rtc_tm_to_time64(&tm); | 120 | new_rtc.tv_sec = rtc_tm_to_time64(&tm); |
| 125 | new_rtc.tv_nsec = 0; | 121 | new_rtc.tv_nsec = 0; |
| 126 | 122 | ||
| @@ -225,15 +221,15 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, | |||
| 225 | rtc->pie_timer.function = rtc_pie_update_irq; | 221 | rtc->pie_timer.function = rtc_pie_update_irq; |
| 226 | rtc->pie_enabled = 0; | 222 | rtc->pie_enabled = 0; |
| 227 | 223 | ||
| 224 | strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE); | ||
| 225 | dev_set_name(&rtc->dev, "rtc%d", id); | ||
| 226 | |||
| 228 | /* Check to see if there is an ALARM already set in hw */ | 227 | /* Check to see if there is an ALARM already set in hw */ |
| 229 | err = __rtc_read_alarm(rtc, &alrm); | 228 | err = __rtc_read_alarm(rtc, &alrm); |
| 230 | 229 | ||
| 231 | if (!err && !rtc_valid_tm(&alrm.time)) | 230 | if (!err && !rtc_valid_tm(&alrm.time)) |
| 232 | rtc_initialize_alarm(rtc, &alrm); | 231 | rtc_initialize_alarm(rtc, &alrm); |
| 233 | 232 | ||
| 234 | strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE); | ||
| 235 | dev_set_name(&rtc->dev, "rtc%d", id); | ||
| 236 | |||
| 237 | rtc_dev_prepare(rtc); | 233 | rtc_dev_prepare(rtc); |
| 238 | 234 | ||
| 239 | err = device_register(&rtc->dev); | 235 | err = device_register(&rtc->dev); |
diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c index 6c719f23520a..e1cfa06810ef 100644 --- a/drivers/rtc/hctosys.c +++ b/drivers/rtc/hctosys.c | |||
| @@ -9,6 +9,8 @@ | |||
| 9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
| 10 | */ | 10 | */ |
| 11 | 11 | ||
| 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 13 | |||
| 12 | #include <linux/rtc.h> | 14 | #include <linux/rtc.h> |
| 13 | 15 | ||
| 14 | /* IMPORTANT: the RTC only stores whole seconds. It is arbitrary | 16 | /* IMPORTANT: the RTC only stores whole seconds. It is arbitrary |
| @@ -32,8 +34,8 @@ static int __init rtc_hctosys(void) | |||
| 32 | struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); | 34 | struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); |
| 33 | 35 | ||
| 34 | if (rtc == NULL) { | 36 | if (rtc == NULL) { |
| 35 | pr_err("%s: unable to open rtc device (%s)\n", | 37 | pr_info("unable to open rtc device (%s)\n", |
| 36 | __FILE__, CONFIG_RTC_HCTOSYS_DEVICE); | 38 | CONFIG_RTC_HCTOSYS_DEVICE); |
| 37 | goto err_open; | 39 | goto err_open; |
| 38 | } | 40 | } |
| 39 | 41 | ||
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 37215cf983e9..166fc60d8b55 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c | |||
| @@ -31,13 +31,14 @@ static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) | |||
| 31 | memset(tm, 0, sizeof(struct rtc_time)); | 31 | memset(tm, 0, sizeof(struct rtc_time)); |
| 32 | err = rtc->ops->read_time(rtc->dev.parent, tm); | 32 | err = rtc->ops->read_time(rtc->dev.parent, tm); |
| 33 | if (err < 0) { | 33 | if (err < 0) { |
| 34 | dev_err(&rtc->dev, "read_time: fail to read\n"); | 34 | dev_dbg(&rtc->dev, "read_time: fail to read: %d\n", |
| 35 | err); | ||
| 35 | return err; | 36 | return err; |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | err = rtc_valid_tm(tm); | 39 | err = rtc_valid_tm(tm); |
| 39 | if (err < 0) | 40 | if (err < 0) |
| 40 | dev_err(&rtc->dev, "read_time: rtc_time isn't valid\n"); | 41 | dev_dbg(&rtc->dev, "read_time: rtc_time isn't valid\n"); |
| 41 | } | 42 | } |
| 42 | return err; | 43 | return err; |
| 43 | } | 44 | } |
| @@ -72,7 +73,11 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) | |||
| 72 | err = -ENODEV; | 73 | err = -ENODEV; |
| 73 | else if (rtc->ops->set_time) | 74 | else if (rtc->ops->set_time) |
| 74 | err = rtc->ops->set_time(rtc->dev.parent, tm); | 75 | err = rtc->ops->set_time(rtc->dev.parent, tm); |
| 75 | else if (rtc->ops->set_mmss) { | 76 | else if (rtc->ops->set_mmss64) { |
| 77 | time64_t secs64 = rtc_tm_to_time64(tm); | ||
| 78 | |||
| 79 | err = rtc->ops->set_mmss64(rtc->dev.parent, secs64); | ||
| 80 | } else if (rtc->ops->set_mmss) { | ||
| 76 | time64_t secs64 = rtc_tm_to_time64(tm); | 81 | time64_t secs64 = rtc_tm_to_time64(tm); |
| 77 | err = rtc->ops->set_mmss(rtc->dev.parent, secs64); | 82 | err = rtc->ops->set_mmss(rtc->dev.parent, secs64); |
| 78 | } else | 83 | } else |
| @@ -96,6 +101,8 @@ int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs) | |||
| 96 | 101 | ||
| 97 | if (!rtc->ops) | 102 | if (!rtc->ops) |
| 98 | err = -ENODEV; | 103 | err = -ENODEV; |
| 104 | else if (rtc->ops->set_mmss64) | ||
| 105 | err = rtc->ops->set_mmss64(rtc->dev.parent, secs); | ||
| 99 | else if (rtc->ops->set_mmss) | 106 | else if (rtc->ops->set_mmss) |
| 100 | err = rtc->ops->set_mmss(rtc->dev.parent, secs); | 107 | err = rtc->ops->set_mmss(rtc->dev.parent, secs); |
| 101 | else if (rtc->ops->read_time && rtc->ops->set_time) { | 108 | else if (rtc->ops->read_time && rtc->ops->set_time) { |
diff --git a/drivers/rtc/rtc-ab-b5ze-s3.c b/drivers/rtc/rtc-ab-b5ze-s3.c index cfc2ef98d393..b5cbc1bf5a3e 100644 --- a/drivers/rtc/rtc-ab-b5ze-s3.c +++ b/drivers/rtc/rtc-ab-b5ze-s3.c | |||
| @@ -881,7 +881,7 @@ static const struct rtc_class_ops rtc_ops = { | |||
| 881 | .alarm_irq_enable = abb5zes3_rtc_alarm_irq_enable, | 881 | .alarm_irq_enable = abb5zes3_rtc_alarm_irq_enable, |
| 882 | }; | 882 | }; |
| 883 | 883 | ||
| 884 | static struct regmap_config abb5zes3_rtc_regmap_config = { | 884 | static const struct regmap_config abb5zes3_rtc_regmap_config = { |
| 885 | .reg_bits = 8, | 885 | .reg_bits = 8, |
| 886 | .val_bits = 8, | 886 | .val_bits = 8, |
| 887 | }; | 887 | }; |
diff --git a/drivers/rtc/rtc-ab3100.c b/drivers/rtc/rtc-ab3100.c index 1d0340fdb820..9b725c553058 100644 --- a/drivers/rtc/rtc-ab3100.c +++ b/drivers/rtc/rtc-ab3100.c | |||
| @@ -43,21 +43,21 @@ | |||
| 43 | /* | 43 | /* |
| 44 | * RTC clock functions and device struct declaration | 44 | * RTC clock functions and device struct declaration |
| 45 | */ | 45 | */ |
| 46 | static int ab3100_rtc_set_mmss(struct device *dev, unsigned long secs) | 46 | static int ab3100_rtc_set_mmss(struct device *dev, time64_t secs) |
| 47 | { | 47 | { |
| 48 | u8 regs[] = {AB3100_TI0, AB3100_TI1, AB3100_TI2, | 48 | u8 regs[] = {AB3100_TI0, AB3100_TI1, AB3100_TI2, |
| 49 | AB3100_TI3, AB3100_TI4, AB3100_TI5}; | 49 | AB3100_TI3, AB3100_TI4, AB3100_TI5}; |
| 50 | unsigned char buf[6]; | 50 | unsigned char buf[6]; |
| 51 | u64 fat_time = (u64) secs * AB3100_RTC_CLOCK_RATE * 2; | 51 | u64 hw_counter = secs * AB3100_RTC_CLOCK_RATE * 2; |
| 52 | int err = 0; | 52 | int err = 0; |
| 53 | int i; | 53 | int i; |
| 54 | 54 | ||
| 55 | buf[0] = (fat_time) & 0xFF; | 55 | buf[0] = (hw_counter) & 0xFF; |
| 56 | buf[1] = (fat_time >> 8) & 0xFF; | 56 | buf[1] = (hw_counter >> 8) & 0xFF; |
| 57 | buf[2] = (fat_time >> 16) & 0xFF; | 57 | buf[2] = (hw_counter >> 16) & 0xFF; |
| 58 | buf[3] = (fat_time >> 24) & 0xFF; | 58 | buf[3] = (hw_counter >> 24) & 0xFF; |
| 59 | buf[4] = (fat_time >> 32) & 0xFF; | 59 | buf[4] = (hw_counter >> 32) & 0xFF; |
| 60 | buf[5] = (fat_time >> 40) & 0xFF; | 60 | buf[5] = (hw_counter >> 40) & 0xFF; |
| 61 | 61 | ||
| 62 | for (i = 0; i < 6; i++) { | 62 | for (i = 0; i < 6; i++) { |
| 63 | err = abx500_set_register_interruptible(dev, 0, | 63 | err = abx500_set_register_interruptible(dev, 0, |
| @@ -75,7 +75,7 @@ static int ab3100_rtc_set_mmss(struct device *dev, unsigned long secs) | |||
| 75 | 75 | ||
| 76 | static int ab3100_rtc_read_time(struct device *dev, struct rtc_time *tm) | 76 | static int ab3100_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| 77 | { | 77 | { |
| 78 | unsigned long time; | 78 | time64_t time; |
| 79 | u8 rtcval; | 79 | u8 rtcval; |
| 80 | int err; | 80 | int err; |
| 81 | 81 | ||
| @@ -88,7 +88,7 @@ static int ab3100_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 88 | dev_info(dev, "clock not set (lost power)"); | 88 | dev_info(dev, "clock not set (lost power)"); |
| 89 | return -EINVAL; | 89 | return -EINVAL; |
| 90 | } else { | 90 | } else { |
| 91 | u64 fat_time; | 91 | u64 hw_counter; |
| 92 | u8 buf[6]; | 92 | u8 buf[6]; |
| 93 | 93 | ||
| 94 | /* Read out time registers */ | 94 | /* Read out time registers */ |
| @@ -98,22 +98,21 @@ static int ab3100_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 98 | if (err != 0) | 98 | if (err != 0) |
| 99 | return err; | 99 | return err; |
| 100 | 100 | ||
| 101 | fat_time = ((u64) buf[5] << 40) | ((u64) buf[4] << 32) | | 101 | hw_counter = ((u64) buf[5] << 40) | ((u64) buf[4] << 32) | |
| 102 | ((u64) buf[3] << 24) | ((u64) buf[2] << 16) | | 102 | ((u64) buf[3] << 24) | ((u64) buf[2] << 16) | |
| 103 | ((u64) buf[1] << 8) | (u64) buf[0]; | 103 | ((u64) buf[1] << 8) | (u64) buf[0]; |
| 104 | time = (unsigned long) (fat_time / | 104 | time = hw_counter / (u64) (AB3100_RTC_CLOCK_RATE * 2); |
| 105 | (u64) (AB3100_RTC_CLOCK_RATE * 2)); | ||
| 106 | } | 105 | } |
| 107 | 106 | ||
| 108 | rtc_time_to_tm(time, tm); | 107 | rtc_time64_to_tm(time, tm); |
| 109 | 108 | ||
| 110 | return rtc_valid_tm(tm); | 109 | return rtc_valid_tm(tm); |
| 111 | } | 110 | } |
| 112 | 111 | ||
| 113 | static int ab3100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | 112 | static int ab3100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
| 114 | { | 113 | { |
| 115 | unsigned long time; | 114 | time64_t time; |
| 116 | u64 fat_time; | 115 | u64 hw_counter; |
| 117 | u8 buf[6]; | 116 | u8 buf[6]; |
| 118 | u8 rtcval; | 117 | u8 rtcval; |
| 119 | int err; | 118 | int err; |
| @@ -134,11 +133,11 @@ static int ab3100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | |||
| 134 | AB3100_AL0, buf, 4); | 133 | AB3100_AL0, buf, 4); |
| 135 | if (err) | 134 | if (err) |
| 136 | return err; | 135 | return err; |
| 137 | fat_time = ((u64) buf[3] << 40) | ((u64) buf[2] << 32) | | 136 | hw_counter = ((u64) buf[3] << 40) | ((u64) buf[2] << 32) | |
| 138 | ((u64) buf[1] << 24) | ((u64) buf[0] << 16); | 137 | ((u64) buf[1] << 24) | ((u64) buf[0] << 16); |
| 139 | time = (unsigned long) (fat_time / (u64) (AB3100_RTC_CLOCK_RATE * 2)); | 138 | time = hw_counter / (u64) (AB3100_RTC_CLOCK_RATE * 2); |
| 140 | 139 | ||
| 141 | rtc_time_to_tm(time, &alarm->time); | 140 | rtc_time64_to_tm(time, &alarm->time); |
| 142 | 141 | ||
| 143 | return rtc_valid_tm(&alarm->time); | 142 | return rtc_valid_tm(&alarm->time); |
| 144 | } | 143 | } |
| @@ -147,17 +146,17 @@ static int ab3100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | |||
| 147 | { | 146 | { |
| 148 | u8 regs[] = {AB3100_AL0, AB3100_AL1, AB3100_AL2, AB3100_AL3}; | 147 | u8 regs[] = {AB3100_AL0, AB3100_AL1, AB3100_AL2, AB3100_AL3}; |
| 149 | unsigned char buf[4]; | 148 | unsigned char buf[4]; |
| 150 | unsigned long secs; | 149 | time64_t secs; |
| 151 | u64 fat_time; | 150 | u64 hw_counter; |
| 152 | int err; | 151 | int err; |
| 153 | int i; | 152 | int i; |
| 154 | 153 | ||
| 155 | rtc_tm_to_time(&alarm->time, &secs); | 154 | secs = rtc_tm_to_time64(&alarm->time); |
| 156 | fat_time = (u64) secs * AB3100_RTC_CLOCK_RATE * 2; | 155 | hw_counter = secs * AB3100_RTC_CLOCK_RATE * 2; |
| 157 | buf[0] = (fat_time >> 16) & 0xFF; | 156 | buf[0] = (hw_counter >> 16) & 0xFF; |
| 158 | buf[1] = (fat_time >> 24) & 0xFF; | 157 | buf[1] = (hw_counter >> 24) & 0xFF; |
| 159 | buf[2] = (fat_time >> 32) & 0xFF; | 158 | buf[2] = (hw_counter >> 32) & 0xFF; |
| 160 | buf[3] = (fat_time >> 40) & 0xFF; | 159 | buf[3] = (hw_counter >> 40) & 0xFF; |
| 161 | 160 | ||
| 162 | /* Set the alarm */ | 161 | /* Set the alarm */ |
| 163 | for (i = 0; i < 4; i++) { | 162 | for (i = 0; i < 4; i++) { |
| @@ -193,7 +192,7 @@ static int ab3100_rtc_irq_enable(struct device *dev, unsigned int enabled) | |||
| 193 | 192 | ||
| 194 | static const struct rtc_class_ops ab3100_rtc_ops = { | 193 | static const struct rtc_class_ops ab3100_rtc_ops = { |
| 195 | .read_time = ab3100_rtc_read_time, | 194 | .read_time = ab3100_rtc_read_time, |
| 196 | .set_mmss = ab3100_rtc_set_mmss, | 195 | .set_mmss64 = ab3100_rtc_set_mmss, |
| 197 | .read_alarm = ab3100_rtc_read_alarm, | 196 | .read_alarm = ab3100_rtc_read_alarm, |
| 198 | .set_alarm = ab3100_rtc_set_alarm, | 197 | .set_alarm = ab3100_rtc_set_alarm, |
| 199 | .alarm_irq_enable = ab3100_rtc_irq_enable, | 198 | .alarm_irq_enable = ab3100_rtc_irq_enable, |
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c index 70a5d94cc766..35efd3f75b18 100644 --- a/drivers/rtc/rtc-at91rm9200.c +++ b/drivers/rtc/rtc-at91rm9200.c | |||
| @@ -31,14 +31,15 @@ | |||
| 31 | #include <linux/io.h> | 31 | #include <linux/io.h> |
| 32 | #include <linux/of.h> | 32 | #include <linux/of.h> |
| 33 | #include <linux/of_device.h> | 33 | #include <linux/of_device.h> |
| 34 | #include <linux/suspend.h> | ||
| 34 | #include <linux/uaccess.h> | 35 | #include <linux/uaccess.h> |
| 35 | 36 | ||
| 36 | #include "rtc-at91rm9200.h" | 37 | #include "rtc-at91rm9200.h" |
| 37 | 38 | ||
| 38 | #define at91_rtc_read(field) \ | 39 | #define at91_rtc_read(field) \ |
| 39 | __raw_readl(at91_rtc_regs + field) | 40 | readl_relaxed(at91_rtc_regs + field) |
| 40 | #define at91_rtc_write(field, val) \ | 41 | #define at91_rtc_write(field, val) \ |
| 41 | __raw_writel((val), at91_rtc_regs + field) | 42 | writel_relaxed((val), at91_rtc_regs + field) |
| 42 | 43 | ||
| 43 | #define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */ | 44 | #define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */ |
| 44 | 45 | ||
| @@ -54,6 +55,10 @@ static void __iomem *at91_rtc_regs; | |||
| 54 | static int irq; | 55 | static int irq; |
| 55 | static DEFINE_SPINLOCK(at91_rtc_lock); | 56 | static DEFINE_SPINLOCK(at91_rtc_lock); |
| 56 | static u32 at91_rtc_shadow_imr; | 57 | static u32 at91_rtc_shadow_imr; |
| 58 | static bool suspended; | ||
| 59 | static DEFINE_SPINLOCK(suspended_lock); | ||
| 60 | static unsigned long cached_events; | ||
| 61 | static u32 at91_rtc_imr; | ||
| 57 | 62 | ||
| 58 | static void at91_rtc_write_ier(u32 mask) | 63 | static void at91_rtc_write_ier(u32 mask) |
| 59 | { | 64 | { |
| @@ -290,7 +295,9 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id) | |||
| 290 | struct rtc_device *rtc = platform_get_drvdata(pdev); | 295 | struct rtc_device *rtc = platform_get_drvdata(pdev); |
| 291 | unsigned int rtsr; | 296 | unsigned int rtsr; |
| 292 | unsigned long events = 0; | 297 | unsigned long events = 0; |
| 298 | int ret = IRQ_NONE; | ||
| 293 | 299 | ||
| 300 | spin_lock(&suspended_lock); | ||
| 294 | rtsr = at91_rtc_read(AT91_RTC_SR) & at91_rtc_read_imr(); | 301 | rtsr = at91_rtc_read(AT91_RTC_SR) & at91_rtc_read_imr(); |
| 295 | if (rtsr) { /* this interrupt is shared! Is it ours? */ | 302 | if (rtsr) { /* this interrupt is shared! Is it ours? */ |
| 296 | if (rtsr & AT91_RTC_ALARM) | 303 | if (rtsr & AT91_RTC_ALARM) |
| @@ -304,14 +311,22 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id) | |||
| 304 | 311 | ||
| 305 | at91_rtc_write(AT91_RTC_SCCR, rtsr); /* clear status reg */ | 312 | at91_rtc_write(AT91_RTC_SCCR, rtsr); /* clear status reg */ |
| 306 | 313 | ||
| 307 | rtc_update_irq(rtc, 1, events); | 314 | if (!suspended) { |
| 315 | rtc_update_irq(rtc, 1, events); | ||
| 308 | 316 | ||
| 309 | dev_dbg(&pdev->dev, "%s(): num=%ld, events=0x%02lx\n", __func__, | 317 | dev_dbg(&pdev->dev, "%s(): num=%ld, events=0x%02lx\n", |
| 310 | events >> 8, events & 0x000000FF); | 318 | __func__, events >> 8, events & 0x000000FF); |
| 319 | } else { | ||
| 320 | cached_events |= events; | ||
| 321 | at91_rtc_write_idr(at91_rtc_imr); | ||
| 322 | pm_system_wakeup(); | ||
| 323 | } | ||
| 311 | 324 | ||
| 312 | return IRQ_HANDLED; | 325 | ret = IRQ_HANDLED; |
| 313 | } | 326 | } |
| 314 | return IRQ_NONE; /* not handled */ | 327 | spin_unlock(&suspended_lock); |
| 328 | |||
| 329 | return ret; | ||
| 315 | } | 330 | } |
| 316 | 331 | ||
| 317 | static const struct at91_rtc_config at91rm9200_config = { | 332 | static const struct at91_rtc_config at91rm9200_config = { |
| @@ -401,8 +416,8 @@ static int __init at91_rtc_probe(struct platform_device *pdev) | |||
| 401 | AT91_RTC_CALEV); | 416 | AT91_RTC_CALEV); |
| 402 | 417 | ||
| 403 | ret = devm_request_irq(&pdev->dev, irq, at91_rtc_interrupt, | 418 | ret = devm_request_irq(&pdev->dev, irq, at91_rtc_interrupt, |
| 404 | IRQF_SHARED, | 419 | IRQF_SHARED | IRQF_COND_SUSPEND, |
| 405 | "at91_rtc", pdev); | 420 | "at91_rtc", pdev); |
| 406 | if (ret) { | 421 | if (ret) { |
| 407 | dev_err(&pdev->dev, "IRQ %d already in use.\n", irq); | 422 | dev_err(&pdev->dev, "IRQ %d already in use.\n", irq); |
| 408 | return ret; | 423 | return ret; |
| @@ -454,8 +469,6 @@ static void at91_rtc_shutdown(struct platform_device *pdev) | |||
| 454 | 469 | ||
| 455 | /* AT91RM9200 RTC Power management control */ | 470 | /* AT91RM9200 RTC Power management control */ |
| 456 | 471 | ||
| 457 | static u32 at91_rtc_imr; | ||
| 458 | |||
| 459 | static int at91_rtc_suspend(struct device *dev) | 472 | static int at91_rtc_suspend(struct device *dev) |
| 460 | { | 473 | { |
| 461 | /* this IRQ is shared with DBGU and other hardware which isn't | 474 | /* this IRQ is shared with DBGU and other hardware which isn't |
| @@ -464,21 +477,42 @@ static int at91_rtc_suspend(struct device *dev) | |||
| 464 | at91_rtc_imr = at91_rtc_read_imr() | 477 | at91_rtc_imr = at91_rtc_read_imr() |
| 465 | & (AT91_RTC_ALARM|AT91_RTC_SECEV); | 478 | & (AT91_RTC_ALARM|AT91_RTC_SECEV); |
| 466 | if (at91_rtc_imr) { | 479 | if (at91_rtc_imr) { |
| 467 | if (device_may_wakeup(dev)) | 480 | if (device_may_wakeup(dev)) { |
| 481 | unsigned long flags; | ||
| 482 | |||
| 468 | enable_irq_wake(irq); | 483 | enable_irq_wake(irq); |
| 469 | else | 484 | |
| 485 | spin_lock_irqsave(&suspended_lock, flags); | ||
| 486 | suspended = true; | ||
| 487 | spin_unlock_irqrestore(&suspended_lock, flags); | ||
| 488 | } else { | ||
| 470 | at91_rtc_write_idr(at91_rtc_imr); | 489 | at91_rtc_write_idr(at91_rtc_imr); |
| 490 | } | ||
| 471 | } | 491 | } |
| 472 | return 0; | 492 | return 0; |
| 473 | } | 493 | } |
| 474 | 494 | ||
| 475 | static int at91_rtc_resume(struct device *dev) | 495 | static int at91_rtc_resume(struct device *dev) |
| 476 | { | 496 | { |
| 497 | struct rtc_device *rtc = dev_get_drvdata(dev); | ||
| 498 | |||
| 477 | if (at91_rtc_imr) { | 499 | if (at91_rtc_imr) { |
| 478 | if (device_may_wakeup(dev)) | 500 | if (device_may_wakeup(dev)) { |
| 501 | unsigned long flags; | ||
| 502 | |||
| 503 | spin_lock_irqsave(&suspended_lock, flags); | ||
| 504 | |||
| 505 | if (cached_events) { | ||
| 506 | rtc_update_irq(rtc, 1, cached_events); | ||
| 507 | cached_events = 0; | ||
| 508 | } | ||
| 509 | |||
| 510 | suspended = false; | ||
| 511 | spin_unlock_irqrestore(&suspended_lock, flags); | ||
| 512 | |||
| 479 | disable_irq_wake(irq); | 513 | disable_irq_wake(irq); |
| 480 | else | 514 | } |
| 481 | at91_rtc_write_ier(at91_rtc_imr); | 515 | at91_rtc_write_ier(at91_rtc_imr); |
| 482 | } | 516 | } |
| 483 | return 0; | 517 | return 0; |
| 484 | } | 518 | } |
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c index 2183fd2750ab..5ccaee32df72 100644 --- a/drivers/rtc/rtc-at91sam9.c +++ b/drivers/rtc/rtc-at91sam9.c | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include <linux/io.h> | 23 | #include <linux/io.h> |
| 24 | #include <linux/mfd/syscon.h> | 24 | #include <linux/mfd/syscon.h> |
| 25 | #include <linux/regmap.h> | 25 | #include <linux/regmap.h> |
| 26 | #include <linux/suspend.h> | ||
| 26 | #include <linux/clk.h> | 27 | #include <linux/clk.h> |
| 27 | 28 | ||
| 28 | /* | 29 | /* |
| @@ -77,6 +78,9 @@ struct sam9_rtc { | |||
| 77 | unsigned int gpbr_offset; | 78 | unsigned int gpbr_offset; |
| 78 | int irq; | 79 | int irq; |
| 79 | struct clk *sclk; | 80 | struct clk *sclk; |
| 81 | bool suspended; | ||
| 82 | unsigned long events; | ||
| 83 | spinlock_t lock; | ||
| 80 | }; | 84 | }; |
| 81 | 85 | ||
| 82 | #define rtt_readl(rtc, field) \ | 86 | #define rtt_readl(rtc, field) \ |
| @@ -271,14 +275,9 @@ static int at91_rtc_proc(struct device *dev, struct seq_file *seq) | |||
| 271 | return 0; | 275 | return 0; |
| 272 | } | 276 | } |
| 273 | 277 | ||
| 274 | /* | 278 | static irqreturn_t at91_rtc_cache_events(struct sam9_rtc *rtc) |
| 275 | * IRQ handler for the RTC | ||
| 276 | */ | ||
| 277 | static irqreturn_t at91_rtc_interrupt(int irq, void *_rtc) | ||
| 278 | { | 279 | { |
| 279 | struct sam9_rtc *rtc = _rtc; | ||
| 280 | u32 sr, mr; | 280 | u32 sr, mr; |
| 281 | unsigned long events = 0; | ||
| 282 | 281 | ||
| 283 | /* Shared interrupt may be for another device. Note: reading | 282 | /* Shared interrupt may be for another device. Note: reading |
| 284 | * SR clears it, so we must only read it in this irq handler! | 283 | * SR clears it, so we must only read it in this irq handler! |
| @@ -290,18 +289,54 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *_rtc) | |||
| 290 | 289 | ||
| 291 | /* alarm status */ | 290 | /* alarm status */ |
| 292 | if (sr & AT91_RTT_ALMS) | 291 | if (sr & AT91_RTT_ALMS) |
| 293 | events |= (RTC_AF | RTC_IRQF); | 292 | rtc->events |= (RTC_AF | RTC_IRQF); |
| 294 | 293 | ||
| 295 | /* timer update/increment */ | 294 | /* timer update/increment */ |
| 296 | if (sr & AT91_RTT_RTTINC) | 295 | if (sr & AT91_RTT_RTTINC) |
| 297 | events |= (RTC_UF | RTC_IRQF); | 296 | rtc->events |= (RTC_UF | RTC_IRQF); |
| 297 | |||
| 298 | return IRQ_HANDLED; | ||
| 299 | } | ||
| 300 | |||
| 301 | static void at91_rtc_flush_events(struct sam9_rtc *rtc) | ||
| 302 | { | ||
| 303 | if (!rtc->events) | ||
| 304 | return; | ||
| 298 | 305 | ||
| 299 | rtc_update_irq(rtc->rtcdev, 1, events); | 306 | rtc_update_irq(rtc->rtcdev, 1, rtc->events); |
| 307 | rtc->events = 0; | ||
| 300 | 308 | ||
| 301 | pr_debug("%s: num=%ld, events=0x%02lx\n", __func__, | 309 | pr_debug("%s: num=%ld, events=0x%02lx\n", __func__, |
| 302 | events >> 8, events & 0x000000FF); | 310 | rtc->events >> 8, rtc->events & 0x000000FF); |
| 311 | } | ||
| 303 | 312 | ||
| 304 | return IRQ_HANDLED; | 313 | /* |
| 314 | * IRQ handler for the RTC | ||
| 315 | */ | ||
| 316 | static irqreturn_t at91_rtc_interrupt(int irq, void *_rtc) | ||
| 317 | { | ||
| 318 | struct sam9_rtc *rtc = _rtc; | ||
| 319 | int ret; | ||
| 320 | |||
| 321 | spin_lock(&rtc->lock); | ||
| 322 | |||
| 323 | ret = at91_rtc_cache_events(rtc); | ||
| 324 | |||
| 325 | /* We're called in suspended state */ | ||
| 326 | if (rtc->suspended) { | ||
| 327 | /* Mask irqs coming from this peripheral */ | ||
| 328 | rtt_writel(rtc, MR, | ||
| 329 | rtt_readl(rtc, MR) & | ||
| 330 | ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)); | ||
| 331 | /* Trigger a system wakeup */ | ||
| 332 | pm_system_wakeup(); | ||
| 333 | } else { | ||
| 334 | at91_rtc_flush_events(rtc); | ||
| 335 | } | ||
| 336 | |||
| 337 | spin_unlock(&rtc->lock); | ||
| 338 | |||
| 339 | return ret; | ||
| 305 | } | 340 | } |
| 306 | 341 | ||
| 307 | static const struct rtc_class_ops at91_rtc_ops = { | 342 | static const struct rtc_class_ops at91_rtc_ops = { |
| @@ -421,7 +456,8 @@ static int at91_rtc_probe(struct platform_device *pdev) | |||
| 421 | 456 | ||
| 422 | /* register irq handler after we know what name we'll use */ | 457 | /* register irq handler after we know what name we'll use */ |
| 423 | ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt, | 458 | ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt, |
| 424 | IRQF_SHARED, dev_name(&rtc->rtcdev->dev), rtc); | 459 | IRQF_SHARED | IRQF_COND_SUSPEND, |
| 460 | dev_name(&rtc->rtcdev->dev), rtc); | ||
| 425 | if (ret) { | 461 | if (ret) { |
| 426 | dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq); | 462 | dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq); |
| 427 | return ret; | 463 | return ret; |
| @@ -482,7 +518,12 @@ static int at91_rtc_suspend(struct device *dev) | |||
| 482 | rtc->imr = mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); | 518 | rtc->imr = mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); |
| 483 | if (rtc->imr) { | 519 | if (rtc->imr) { |
| 484 | if (device_may_wakeup(dev) && (mr & AT91_RTT_ALMIEN)) { | 520 | if (device_may_wakeup(dev) && (mr & AT91_RTT_ALMIEN)) { |
| 521 | unsigned long flags; | ||
| 522 | |||
| 485 | enable_irq_wake(rtc->irq); | 523 | enable_irq_wake(rtc->irq); |
| 524 | spin_lock_irqsave(&rtc->lock, flags); | ||
| 525 | rtc->suspended = true; | ||
| 526 | spin_unlock_irqrestore(&rtc->lock, flags); | ||
| 486 | /* don't let RTTINC cause wakeups */ | 527 | /* don't let RTTINC cause wakeups */ |
| 487 | if (mr & AT91_RTT_RTTINCIEN) | 528 | if (mr & AT91_RTT_RTTINCIEN) |
| 488 | rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN); | 529 | rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN); |
| @@ -499,10 +540,18 @@ static int at91_rtc_resume(struct device *dev) | |||
| 499 | u32 mr; | 540 | u32 mr; |
| 500 | 541 | ||
| 501 | if (rtc->imr) { | 542 | if (rtc->imr) { |
| 543 | unsigned long flags; | ||
| 544 | |||
| 502 | if (device_may_wakeup(dev)) | 545 | if (device_may_wakeup(dev)) |
| 503 | disable_irq_wake(rtc->irq); | 546 | disable_irq_wake(rtc->irq); |
| 504 | mr = rtt_readl(rtc, MR); | 547 | mr = rtt_readl(rtc, MR); |
| 505 | rtt_writel(rtc, MR, mr | rtc->imr); | 548 | rtt_writel(rtc, MR, mr | rtc->imr); |
| 549 | |||
| 550 | spin_lock_irqsave(&rtc->lock, flags); | ||
| 551 | rtc->suspended = false; | ||
| 552 | at91_rtc_cache_events(rtc); | ||
| 553 | at91_rtc_flush_events(rtc); | ||
| 554 | spin_unlock_irqrestore(&rtc->lock, flags); | ||
| 506 | } | 555 | } |
| 507 | 556 | ||
| 508 | return 0; | 557 | return 0; |
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index 5b2e76159b41..a82556a0757a 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c | |||
| @@ -28,6 +28,9 @@ | |||
| 28 | * interrupts disabled, holding the global rtc_lock, to exclude those | 28 | * interrupts disabled, holding the global rtc_lock, to exclude those |
| 29 | * other drivers and utilities on correctly configured systems. | 29 | * other drivers and utilities on correctly configured systems. |
| 30 | */ | 30 | */ |
| 31 | |||
| 32 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 33 | |||
| 31 | #include <linux/kernel.h> | 34 | #include <linux/kernel.h> |
| 32 | #include <linux/module.h> | 35 | #include <linux/module.h> |
| 33 | #include <linux/init.h> | 36 | #include <linux/init.h> |
| @@ -385,8 +388,7 @@ static bool alarm_disable_quirk; | |||
| 385 | static int __init set_alarm_disable_quirk(const struct dmi_system_id *id) | 388 | static int __init set_alarm_disable_quirk(const struct dmi_system_id *id) |
| 386 | { | 389 | { |
| 387 | alarm_disable_quirk = true; | 390 | alarm_disable_quirk = true; |
| 388 | pr_info("rtc-cmos: BIOS has alarm-disable quirk. "); | 391 | pr_info("BIOS has alarm-disable quirk - RTC alarms disabled\n"); |
| 389 | pr_info("RTC alarms disabled\n"); | ||
| 390 | return 0; | 392 | return 0; |
| 391 | } | 393 | } |
| 392 | 394 | ||
| @@ -459,23 +461,25 @@ static int cmos_procfs(struct device *dev, struct seq_file *seq) | |||
| 459 | /* NOTE: at least ICH6 reports battery status using a different | 461 | /* NOTE: at least ICH6 reports battery status using a different |
| 460 | * (non-RTC) bit; and SQWE is ignored on many current systems. | 462 | * (non-RTC) bit; and SQWE is ignored on many current systems. |
| 461 | */ | 463 | */ |
| 462 | return seq_printf(seq, | 464 | seq_printf(seq, |
| 463 | "periodic_IRQ\t: %s\n" | 465 | "periodic_IRQ\t: %s\n" |
| 464 | "update_IRQ\t: %s\n" | 466 | "update_IRQ\t: %s\n" |
| 465 | "HPET_emulated\t: %s\n" | 467 | "HPET_emulated\t: %s\n" |
| 466 | // "square_wave\t: %s\n" | 468 | // "square_wave\t: %s\n" |
| 467 | "BCD\t\t: %s\n" | 469 | "BCD\t\t: %s\n" |
| 468 | "DST_enable\t: %s\n" | 470 | "DST_enable\t: %s\n" |
| 469 | "periodic_freq\t: %d\n" | 471 | "periodic_freq\t: %d\n" |
| 470 | "batt_status\t: %s\n", | 472 | "batt_status\t: %s\n", |
| 471 | (rtc_control & RTC_PIE) ? "yes" : "no", | 473 | (rtc_control & RTC_PIE) ? "yes" : "no", |
| 472 | (rtc_control & RTC_UIE) ? "yes" : "no", | 474 | (rtc_control & RTC_UIE) ? "yes" : "no", |
| 473 | is_hpet_enabled() ? "yes" : "no", | 475 | is_hpet_enabled() ? "yes" : "no", |
| 474 | // (rtc_control & RTC_SQWE) ? "yes" : "no", | 476 | // (rtc_control & RTC_SQWE) ? "yes" : "no", |
| 475 | (rtc_control & RTC_DM_BINARY) ? "no" : "yes", | 477 | (rtc_control & RTC_DM_BINARY) ? "no" : "yes", |
| 476 | (rtc_control & RTC_DST_EN) ? "yes" : "no", | 478 | (rtc_control & RTC_DST_EN) ? "yes" : "no", |
| 477 | cmos->rtc->irq_freq, | 479 | cmos->rtc->irq_freq, |
| 478 | (valid & RTC_VRT) ? "okay" : "dead"); | 480 | (valid & RTC_VRT) ? "okay" : "dead"); |
| 481 | |||
| 482 | return 0; | ||
| 479 | } | 483 | } |
| 480 | 484 | ||
| 481 | #else | 485 | #else |
diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c index 613c43b7e9ae..1ba4371cbc2d 100644 --- a/drivers/rtc/rtc-da9052.c +++ b/drivers/rtc/rtc-da9052.c | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/rtc.h> | 17 | #include <linux/rtc.h> |
| 18 | #include <linux/err.h> | 18 | #include <linux/err.h> |
| 19 | #include <linux/delay.h> | ||
| 19 | 20 | ||
| 20 | #include <linux/mfd/da9052/da9052.h> | 21 | #include <linux/mfd/da9052/da9052.h> |
| 21 | #include <linux/mfd/da9052/reg.h> | 22 | #include <linux/mfd/da9052/reg.h> |
| @@ -23,6 +24,8 @@ | |||
| 23 | #define rtc_err(rtc, fmt, ...) \ | 24 | #define rtc_err(rtc, fmt, ...) \ |
| 24 | dev_err(rtc->da9052->dev, "%s: " fmt, __func__, ##__VA_ARGS__) | 25 | dev_err(rtc->da9052->dev, "%s: " fmt, __func__, ##__VA_ARGS__) |
| 25 | 26 | ||
| 27 | #define DA9052_GET_TIME_RETRIES 5 | ||
| 28 | |||
| 26 | struct da9052_rtc { | 29 | struct da9052_rtc { |
| 27 | struct rtc_device *rtc; | 30 | struct rtc_device *rtc; |
| 28 | struct da9052 *da9052; | 31 | struct da9052 *da9052; |
| @@ -58,22 +61,43 @@ static irqreturn_t da9052_rtc_irq(int irq, void *data) | |||
| 58 | static int da9052_read_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) | 61 | static int da9052_read_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) |
| 59 | { | 62 | { |
| 60 | int ret; | 63 | int ret; |
| 61 | uint8_t v[5]; | 64 | uint8_t v[2][5]; |
| 65 | int idx = 1; | ||
| 66 | int timeout = DA9052_GET_TIME_RETRIES; | ||
| 62 | 67 | ||
| 63 | ret = da9052_group_read(rtc->da9052, DA9052_ALARM_MI_REG, 5, v); | 68 | ret = da9052_group_read(rtc->da9052, DA9052_ALARM_MI_REG, 5, &v[0][0]); |
| 64 | if (ret != 0) { | 69 | if (ret) { |
| 65 | rtc_err(rtc, "Failed to group read ALM: %d\n", ret); | 70 | rtc_err(rtc, "Failed to group read ALM: %d\n", ret); |
| 66 | return ret; | 71 | return ret; |
| 67 | } | 72 | } |
| 68 | 73 | ||
| 69 | rtc_tm->tm_year = (v[4] & DA9052_RTC_YEAR) + 100; | 74 | do { |
| 70 | rtc_tm->tm_mon = (v[3] & DA9052_RTC_MONTH) - 1; | 75 | ret = da9052_group_read(rtc->da9052, |
| 71 | rtc_tm->tm_mday = v[2] & DA9052_RTC_DAY; | 76 | DA9052_ALARM_MI_REG, 5, &v[idx][0]); |
| 72 | rtc_tm->tm_hour = v[1] & DA9052_RTC_HOUR; | 77 | if (ret) { |
| 73 | rtc_tm->tm_min = v[0] & DA9052_RTC_MIN; | 78 | rtc_err(rtc, "Failed to group read ALM: %d\n", ret); |
| 79 | return ret; | ||
| 80 | } | ||
| 74 | 81 | ||
| 75 | ret = rtc_valid_tm(rtc_tm); | 82 | if (memcmp(&v[0][0], &v[1][0], 5) == 0) { |
| 76 | return ret; | 83 | rtc_tm->tm_year = (v[0][4] & DA9052_RTC_YEAR) + 100; |
| 84 | rtc_tm->tm_mon = (v[0][3] & DA9052_RTC_MONTH) - 1; | ||
| 85 | rtc_tm->tm_mday = v[0][2] & DA9052_RTC_DAY; | ||
| 86 | rtc_tm->tm_hour = v[0][1] & DA9052_RTC_HOUR; | ||
| 87 | rtc_tm->tm_min = v[0][0] & DA9052_RTC_MIN; | ||
| 88 | |||
| 89 | ret = rtc_valid_tm(rtc_tm); | ||
| 90 | return ret; | ||
| 91 | } | ||
| 92 | |||
| 93 | idx = (1-idx); | ||
| 94 | msleep(20); | ||
| 95 | |||
| 96 | } while (timeout--); | ||
| 97 | |||
| 98 | rtc_err(rtc, "Timed out reading alarm time\n"); | ||
| 99 | |||
| 100 | return -EIO; | ||
| 77 | } | 101 | } |
| 78 | 102 | ||
| 79 | static int da9052_set_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) | 103 | static int da9052_set_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) |
| @@ -135,24 +159,45 @@ static int da9052_rtc_get_alarm_status(struct da9052_rtc *rtc) | |||
| 135 | static int da9052_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm) | 159 | static int da9052_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm) |
| 136 | { | 160 | { |
| 137 | struct da9052_rtc *rtc = dev_get_drvdata(dev); | 161 | struct da9052_rtc *rtc = dev_get_drvdata(dev); |
| 138 | uint8_t v[6]; | ||
| 139 | int ret; | 162 | int ret; |
| 163 | uint8_t v[2][6]; | ||
| 164 | int idx = 1; | ||
| 165 | int timeout = DA9052_GET_TIME_RETRIES; | ||
| 140 | 166 | ||
| 141 | ret = da9052_group_read(rtc->da9052, DA9052_COUNT_S_REG, 6, v); | 167 | ret = da9052_group_read(rtc->da9052, DA9052_COUNT_S_REG, 6, &v[0][0]); |
| 142 | if (ret < 0) { | 168 | if (ret) { |
| 143 | rtc_err(rtc, "Failed to read RTC time : %d\n", ret); | 169 | rtc_err(rtc, "Failed to read RTC time : %d\n", ret); |
| 144 | return ret; | 170 | return ret; |
| 145 | } | 171 | } |
| 146 | 172 | ||
| 147 | rtc_tm->tm_year = (v[5] & DA9052_RTC_YEAR) + 100; | 173 | do { |
| 148 | rtc_tm->tm_mon = (v[4] & DA9052_RTC_MONTH) - 1; | 174 | ret = da9052_group_read(rtc->da9052, |
| 149 | rtc_tm->tm_mday = v[3] & DA9052_RTC_DAY; | 175 | DA9052_COUNT_S_REG, 6, &v[idx][0]); |
| 150 | rtc_tm->tm_hour = v[2] & DA9052_RTC_HOUR; | 176 | if (ret) { |
| 151 | rtc_tm->tm_min = v[1] & DA9052_RTC_MIN; | 177 | rtc_err(rtc, "Failed to read RTC time : %d\n", ret); |
| 152 | rtc_tm->tm_sec = v[0] & DA9052_RTC_SEC; | 178 | return ret; |
| 179 | } | ||
| 153 | 180 | ||
| 154 | ret = rtc_valid_tm(rtc_tm); | 181 | if (memcmp(&v[0][0], &v[1][0], 6) == 0) { |
| 155 | return ret; | 182 | rtc_tm->tm_year = (v[0][5] & DA9052_RTC_YEAR) + 100; |
| 183 | rtc_tm->tm_mon = (v[0][4] & DA9052_RTC_MONTH) - 1; | ||
| 184 | rtc_tm->tm_mday = v[0][3] & DA9052_RTC_DAY; | ||
| 185 | rtc_tm->tm_hour = v[0][2] & DA9052_RTC_HOUR; | ||
| 186 | rtc_tm->tm_min = v[0][1] & DA9052_RTC_MIN; | ||
| 187 | rtc_tm->tm_sec = v[0][0] & DA9052_RTC_SEC; | ||
| 188 | |||
| 189 | ret = rtc_valid_tm(rtc_tm); | ||
| 190 | return ret; | ||
| 191 | } | ||
| 192 | |||
| 193 | idx = (1-idx); | ||
| 194 | msleep(20); | ||
| 195 | |||
| 196 | } while (timeout--); | ||
| 197 | |||
| 198 | rtc_err(rtc, "Timed out reading time\n"); | ||
| 199 | |||
| 200 | return -EIO; | ||
| 156 | } | 201 | } |
| 157 | 202 | ||
| 158 | static int da9052_rtc_set_time(struct device *dev, struct rtc_time *tm) | 203 | static int da9052_rtc_set_time(struct device *dev, struct rtc_time *tm) |
| @@ -161,6 +206,10 @@ static int da9052_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
| 161 | uint8_t v[6]; | 206 | uint8_t v[6]; |
| 162 | int ret; | 207 | int ret; |
| 163 | 208 | ||
| 209 | /* DA9052 only has 6 bits for year - to represent 2000-2063 */ | ||
| 210 | if ((tm->tm_year < 100) || (tm->tm_year > 163)) | ||
| 211 | return -EINVAL; | ||
| 212 | |||
| 164 | rtc = dev_get_drvdata(dev); | 213 | rtc = dev_get_drvdata(dev); |
| 165 | 214 | ||
| 166 | v[0] = tm->tm_sec; | 215 | v[0] = tm->tm_sec; |
| @@ -198,6 +247,10 @@ static int da9052_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 198 | struct rtc_time *tm = &alrm->time; | 247 | struct rtc_time *tm = &alrm->time; |
| 199 | struct da9052_rtc *rtc = dev_get_drvdata(dev); | 248 | struct da9052_rtc *rtc = dev_get_drvdata(dev); |
| 200 | 249 | ||
| 250 | /* DA9052 only has 6 bits for year - to represent 2000-2063 */ | ||
| 251 | if ((tm->tm_year < 100) || (tm->tm_year > 163)) | ||
| 252 | return -EINVAL; | ||
| 253 | |||
| 201 | ret = da9052_rtc_enable_alarm(rtc, 0); | 254 | ret = da9052_rtc_enable_alarm(rtc, 0); |
| 202 | if (ret < 0) | 255 | if (ret < 0) |
| 203 | return ret; | 256 | return ret; |
| @@ -256,6 +309,8 @@ static int da9052_rtc_probe(struct platform_device *pdev) | |||
| 256 | return ret; | 309 | return ret; |
| 257 | } | 310 | } |
| 258 | 311 | ||
| 312 | device_init_wakeup(&pdev->dev, true); | ||
| 313 | |||
| 259 | rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, | 314 | rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, |
| 260 | &da9052_rtc_ops, THIS_MODULE); | 315 | &da9052_rtc_ops, THIS_MODULE); |
| 261 | return PTR_ERR_OR_ZERO(rtc->rtc); | 316 | return PTR_ERR_OR_ZERO(rtc->rtc); |
diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c new file mode 100644 index 000000000000..8d05596a6765 --- /dev/null +++ b/drivers/rtc/rtc-digicolor.c | |||
| @@ -0,0 +1,227 @@ | |||
| 1 | /* | ||
| 2 | * Real Time Clock driver for Conexant Digicolor | ||
| 3 | * | ||
| 4 | * Copyright (C) 2015 Paradox Innovation Ltd. | ||
| 5 | * | ||
| 6 | * Author: Baruch Siach <baruch@tkos.co.il> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify it | ||
| 9 | * under the terms of the GNU General Public License as published by the | ||
| 10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
| 11 | * option) any later version. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/io.h> | ||
| 15 | #include <linux/iopoll.h> | ||
| 16 | #include <linux/delay.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/platform_device.h> | ||
| 19 | #include <linux/rtc.h> | ||
| 20 | #include <linux/of.h> | ||
| 21 | |||
| 22 | #define DC_RTC_CONTROL 0x0 | ||
| 23 | #define DC_RTC_TIME 0x8 | ||
| 24 | #define DC_RTC_REFERENCE 0xc | ||
| 25 | #define DC_RTC_ALARM 0x10 | ||
| 26 | #define DC_RTC_INTFLAG_CLEAR 0x14 | ||
| 27 | #define DC_RTC_INTENABLE 0x16 | ||
| 28 | |||
| 29 | #define DC_RTC_CMD_MASK 0xf | ||
| 30 | #define DC_RTC_GO_BUSY BIT(7) | ||
| 31 | |||
| 32 | #define CMD_NOP 0 | ||
| 33 | #define CMD_RESET 1 | ||
| 34 | #define CMD_WRITE 3 | ||
| 35 | #define CMD_READ 4 | ||
| 36 | |||
| 37 | #define CMD_DELAY_US (10*1000) | ||
| 38 | #define CMD_TIMEOUT_US (500*CMD_DELAY_US) | ||
| 39 | |||
| 40 | struct dc_rtc { | ||
| 41 | struct rtc_device *rtc_dev; | ||
| 42 | void __iomem *regs; | ||
| 43 | }; | ||
| 44 | |||
| 45 | static int dc_rtc_cmds(struct dc_rtc *rtc, const u8 *cmds, int len) | ||
| 46 | { | ||
| 47 | u8 val; | ||
| 48 | int i, ret; | ||
| 49 | |||
| 50 | for (i = 0; i < len; i++) { | ||
| 51 | writeb_relaxed((cmds[i] & DC_RTC_CMD_MASK) | DC_RTC_GO_BUSY, | ||
| 52 | rtc->regs + DC_RTC_CONTROL); | ||
| 53 | ret = readb_relaxed_poll_timeout( | ||
| 54 | rtc->regs + DC_RTC_CONTROL, val, | ||
| 55 | !(val & DC_RTC_GO_BUSY), CMD_DELAY_US, CMD_TIMEOUT_US); | ||
| 56 | if (ret < 0) | ||
| 57 | return ret; | ||
| 58 | } | ||
| 59 | |||
| 60 | return 0; | ||
| 61 | } | ||
| 62 | |||
| 63 | static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val) | ||
| 64 | { | ||
| 65 | static const u8 read_cmds[] = {CMD_READ, CMD_NOP}; | ||
| 66 | u32 reference, time1, time2; | ||
| 67 | int ret; | ||
| 68 | |||
| 69 | ret = dc_rtc_cmds(rtc, read_cmds, ARRAY_SIZE(read_cmds)); | ||
| 70 | if (ret < 0) | ||
| 71 | return ret; | ||
| 72 | |||
| 73 | reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE); | ||
| 74 | time1 = readl_relaxed(rtc->regs + DC_RTC_TIME); | ||
| 75 | /* Read twice to ensure consistency */ | ||
| 76 | while (1) { | ||
| 77 | time2 = readl_relaxed(rtc->regs + DC_RTC_TIME); | ||
| 78 | if (time1 == time2) | ||
| 79 | break; | ||
| 80 | time1 = time2; | ||
| 81 | } | ||
| 82 | |||
| 83 | *val = reference + time1; | ||
| 84 | return 0; | ||
| 85 | } | ||
| 86 | |||
| 87 | static int dc_rtc_write(struct dc_rtc *rtc, u32 val) | ||
| 88 | { | ||
| 89 | static const u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP}; | ||
| 90 | |||
| 91 | writel_relaxed(val, rtc->regs + DC_RTC_REFERENCE); | ||
| 92 | return dc_rtc_cmds(rtc, write_cmds, ARRAY_SIZE(write_cmds)); | ||
| 93 | } | ||
| 94 | |||
| 95 | static int dc_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
| 96 | { | ||
| 97 | struct dc_rtc *rtc = dev_get_drvdata(dev); | ||
| 98 | unsigned long now; | ||
| 99 | int ret; | ||
| 100 | |||
| 101 | ret = dc_rtc_read(rtc, &now); | ||
| 102 | if (ret < 0) | ||
| 103 | return ret; | ||
| 104 | rtc_time64_to_tm(now, tm); | ||
| 105 | |||
| 106 | return 0; | ||
| 107 | } | ||
| 108 | |||
| 109 | static int dc_rtc_set_mmss(struct device *dev, unsigned long secs) | ||
| 110 | { | ||
| 111 | struct dc_rtc *rtc = dev_get_drvdata(dev); | ||
| 112 | |||
| 113 | return dc_rtc_write(rtc, secs); | ||
| 114 | } | ||
| 115 | |||
| 116 | static int dc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 117 | { | ||
| 118 | struct dc_rtc *rtc = dev_get_drvdata(dev); | ||
| 119 | u32 alarm_reg, reference; | ||
| 120 | unsigned long now; | ||
| 121 | int ret; | ||
| 122 | |||
| 123 | alarm_reg = readl_relaxed(rtc->regs + DC_RTC_ALARM); | ||
| 124 | reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE); | ||
| 125 | rtc_time64_to_tm(reference + alarm_reg, &alarm->time); | ||
| 126 | |||
| 127 | ret = dc_rtc_read(rtc, &now); | ||
| 128 | if (ret < 0) | ||
| 129 | return ret; | ||
| 130 | |||
| 131 | alarm->pending = alarm_reg + reference > now; | ||
| 132 | alarm->enabled = readl_relaxed(rtc->regs + DC_RTC_INTENABLE); | ||
| 133 | |||
| 134 | return 0; | ||
| 135 | } | ||
| 136 | |||
| 137 | static int dc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 138 | { | ||
| 139 | struct dc_rtc *rtc = dev_get_drvdata(dev); | ||
| 140 | time64_t alarm_time; | ||
| 141 | u32 reference; | ||
| 142 | |||
| 143 | alarm_time = rtc_tm_to_time64(&alarm->time); | ||
| 144 | |||
| 145 | reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE); | ||
| 146 | writel_relaxed(alarm_time - reference, rtc->regs + DC_RTC_ALARM); | ||
| 147 | |||
| 148 | writeb_relaxed(!!alarm->enabled, rtc->regs + DC_RTC_INTENABLE); | ||
| 149 | |||
| 150 | return 0; | ||
| 151 | } | ||
| 152 | |||
| 153 | static int dc_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | ||
| 154 | { | ||
| 155 | struct dc_rtc *rtc = dev_get_drvdata(dev); | ||
| 156 | |||
| 157 | writeb_relaxed(!!enabled, rtc->regs + DC_RTC_INTENABLE); | ||
| 158 | |||
| 159 | return 0; | ||
| 160 | } | ||
| 161 | |||
| 162 | static struct rtc_class_ops dc_rtc_ops = { | ||
| 163 | .read_time = dc_rtc_read_time, | ||
| 164 | .set_mmss = dc_rtc_set_mmss, | ||
| 165 | .read_alarm = dc_rtc_read_alarm, | ||
| 166 | .set_alarm = dc_rtc_set_alarm, | ||
| 167 | .alarm_irq_enable = dc_rtc_alarm_irq_enable, | ||
| 168 | }; | ||
| 169 | |||
| 170 | static irqreturn_t dc_rtc_irq(int irq, void *dev_id) | ||
| 171 | { | ||
| 172 | struct dc_rtc *rtc = dev_id; | ||
| 173 | |||
| 174 | writeb_relaxed(1, rtc->regs + DC_RTC_INTFLAG_CLEAR); | ||
| 175 | rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF); | ||
| 176 | |||
| 177 | return IRQ_HANDLED; | ||
| 178 | } | ||
| 179 | |||
| 180 | static int __init dc_rtc_probe(struct platform_device *pdev) | ||
| 181 | { | ||
| 182 | struct resource *res; | ||
| 183 | struct dc_rtc *rtc; | ||
| 184 | int irq, ret; | ||
| 185 | |||
| 186 | rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); | ||
| 187 | if (!rtc) | ||
| 188 | return -ENOMEM; | ||
| 189 | |||
| 190 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 191 | rtc->regs = devm_ioremap_resource(&pdev->dev, res); | ||
| 192 | if (IS_ERR(rtc->regs)) | ||
| 193 | return PTR_ERR(rtc->regs); | ||
| 194 | |||
| 195 | irq = platform_get_irq(pdev, 0); | ||
| 196 | if (irq < 0) | ||
| 197 | return irq; | ||
| 198 | ret = devm_request_irq(&pdev->dev, irq, dc_rtc_irq, 0, pdev->name, rtc); | ||
| 199 | if (ret < 0) | ||
| 200 | return ret; | ||
| 201 | |||
| 202 | platform_set_drvdata(pdev, rtc); | ||
| 203 | rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name, | ||
| 204 | &dc_rtc_ops, THIS_MODULE); | ||
| 205 | if (IS_ERR(rtc->rtc_dev)) | ||
| 206 | return PTR_ERR(rtc->rtc_dev); | ||
| 207 | |||
| 208 | return 0; | ||
| 209 | } | ||
| 210 | |||
| 211 | static const struct of_device_id dc_dt_ids[] = { | ||
| 212 | { .compatible = "cnxt,cx92755-rtc" }, | ||
| 213 | { /* sentinel */ } | ||
| 214 | }; | ||
| 215 | MODULE_DEVICE_TABLE(of, dc_dt_ids); | ||
| 216 | |||
| 217 | static struct platform_driver dc_rtc_driver = { | ||
| 218 | .driver = { | ||
| 219 | .name = "digicolor_rtc", | ||
| 220 | .of_match_table = of_match_ptr(dc_dt_ids), | ||
| 221 | }, | ||
| 222 | }; | ||
| 223 | module_platform_driver_probe(dc_rtc_driver, dc_rtc_probe); | ||
| 224 | |||
| 225 | MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); | ||
| 226 | MODULE_DESCRIPTION("Conexant Digicolor Realtime Clock Driver (RTC)"); | ||
| 227 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c index 129add77065d..12b07158a366 100644 --- a/drivers/rtc/rtc-ds1305.c +++ b/drivers/rtc/rtc-ds1305.c | |||
| @@ -434,9 +434,9 @@ static int ds1305_proc(struct device *dev, struct seq_file *seq) | |||
| 434 | } | 434 | } |
| 435 | 435 | ||
| 436 | done: | 436 | done: |
| 437 | return seq_printf(seq, | 437 | seq_printf(seq, "trickle_charge\t: %s%s\n", diodes, resistors); |
| 438 | "trickle_charge\t: %s%s\n", | 438 | |
| 439 | diodes, resistors); | 439 | return 0; |
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | #else | 442 | #else |
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c index 8605fde394b2..167783fa7ac1 100644 --- a/drivers/rtc/rtc-ds1374.c +++ b/drivers/rtc/rtc-ds1374.c | |||
| @@ -18,6 +18,8 @@ | |||
| 18 | * "Sending and receiving", using SMBus level communication is preferred. | 18 | * "Sending and receiving", using SMBus level communication is preferred. |
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| 21 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 22 | |||
| 21 | #include <linux/kernel.h> | 23 | #include <linux/kernel.h> |
| 22 | #include <linux/module.h> | 24 | #include <linux/module.h> |
| 23 | #include <linux/interrupt.h> | 25 | #include <linux/interrupt.h> |
| @@ -406,7 +408,7 @@ static int ds1374_wdt_settimeout(unsigned int timeout) | |||
| 406 | /* Set new watchdog time */ | 408 | /* Set new watchdog time */ |
| 407 | ret = ds1374_write_rtc(save_client, timeout, DS1374_REG_WDALM0, 3); | 409 | ret = ds1374_write_rtc(save_client, timeout, DS1374_REG_WDALM0, 3); |
| 408 | if (ret) { | 410 | if (ret) { |
| 409 | pr_info("rtc-ds1374 - couldn't set new watchdog time\n"); | 411 | pr_info("couldn't set new watchdog time\n"); |
| 410 | goto out; | 412 | goto out; |
| 411 | } | 413 | } |
| 412 | 414 | ||
| @@ -539,12 +541,12 @@ static long ds1374_wdt_ioctl(struct file *file, unsigned int cmd, | |||
| 539 | return -EFAULT; | 541 | return -EFAULT; |
| 540 | 542 | ||
| 541 | if (options & WDIOS_DISABLECARD) { | 543 | if (options & WDIOS_DISABLECARD) { |
| 542 | pr_info("rtc-ds1374: disable watchdog\n"); | 544 | pr_info("disable watchdog\n"); |
| 543 | ds1374_wdt_disable(); | 545 | ds1374_wdt_disable(); |
| 544 | } | 546 | } |
| 545 | 547 | ||
| 546 | if (options & WDIOS_ENABLECARD) { | 548 | if (options & WDIOS_ENABLECARD) { |
| 547 | pr_info("rtc-ds1374: enable watchdog\n"); | 549 | pr_info("enable watchdog\n"); |
| 548 | ds1374_wdt_settimeout(wdt_margin); | 550 | ds1374_wdt_settimeout(wdt_margin); |
| 549 | ds1374_wdt_ping(); | 551 | ds1374_wdt_ping(); |
| 550 | } | 552 | } |
diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c index 803869c7d7c2..818a3635a8c8 100644 --- a/drivers/rtc/rtc-ds1685.c +++ b/drivers/rtc/rtc-ds1685.c | |||
| @@ -16,6 +16,8 @@ | |||
| 16 | * published by the Free Software Foundation. | 16 | * published by the Free Software Foundation. |
| 17 | */ | 17 | */ |
| 18 | 18 | ||
| 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 20 | |||
| 19 | #include <linux/bcd.h> | 21 | #include <linux/bcd.h> |
| 20 | #include <linux/delay.h> | 22 | #include <linux/delay.h> |
| 21 | #include <linux/io.h> | 23 | #include <linux/io.h> |
| @@ -799,7 +801,7 @@ ds1685_rtc_proc(struct device *dev, struct seq_file *seq) | |||
| 799 | struct platform_device *pdev = to_platform_device(dev); | 801 | struct platform_device *pdev = to_platform_device(dev); |
| 800 | struct ds1685_priv *rtc = platform_get_drvdata(pdev); | 802 | struct ds1685_priv *rtc = platform_get_drvdata(pdev); |
| 801 | u8 ctrla, ctrlb, ctrlc, ctrld, ctrl4a, ctrl4b, ssn[8]; | 803 | u8 ctrla, ctrlb, ctrlc, ctrld, ctrl4a, ctrl4b, ssn[8]; |
| 802 | char *model = '\0'; | 804 | char *model; |
| 803 | #ifdef CONFIG_RTC_DS1685_PROC_REGS | 805 | #ifdef CONFIG_RTC_DS1685_PROC_REGS |
| 804 | char bits[NUM_REGS][(NUM_BITS * NUM_SPACES) + NUM_BITS + 1]; | 806 | char bits[NUM_REGS][(NUM_BITS * NUM_SPACES) + NUM_BITS + 1]; |
| 805 | #endif | 807 | #endif |
| @@ -2139,7 +2141,6 @@ ds1685_rtc_remove(struct platform_device *pdev) | |||
| 2139 | static struct platform_driver ds1685_rtc_driver = { | 2141 | static struct platform_driver ds1685_rtc_driver = { |
| 2140 | .driver = { | 2142 | .driver = { |
| 2141 | .name = "rtc-ds1685", | 2143 | .name = "rtc-ds1685", |
| 2142 | .owner = THIS_MODULE, | ||
| 2143 | }, | 2144 | }, |
| 2144 | .probe = ds1685_rtc_probe, | 2145 | .probe = ds1685_rtc_probe, |
| 2145 | .remove = ds1685_rtc_remove, | 2146 | .remove = ds1685_rtc_remove, |
| @@ -2175,7 +2176,7 @@ module_exit(ds1685_rtc_exit); | |||
| 2175 | * ds1685_rtc_poweroff - uses the RTC chip to power the system off. | 2176 | * ds1685_rtc_poweroff - uses the RTC chip to power the system off. |
| 2176 | * @pdev: pointer to platform_device structure. | 2177 | * @pdev: pointer to platform_device structure. |
| 2177 | */ | 2178 | */ |
| 2178 | extern void __noreturn | 2179 | void __noreturn |
| 2179 | ds1685_rtc_poweroff(struct platform_device *pdev) | 2180 | ds1685_rtc_poweroff(struct platform_device *pdev) |
| 2180 | { | 2181 | { |
| 2181 | u8 ctrla, ctrl4a, ctrl4b; | 2182 | u8 ctrla, ctrl4a, ctrl4b; |
| @@ -2183,7 +2184,7 @@ ds1685_rtc_poweroff(struct platform_device *pdev) | |||
| 2183 | 2184 | ||
| 2184 | /* Check for valid RTC data, else, spin forever. */ | 2185 | /* Check for valid RTC data, else, spin forever. */ |
| 2185 | if (unlikely(!pdev)) { | 2186 | if (unlikely(!pdev)) { |
| 2186 | pr_emerg("rtc-ds1685: platform device data not available, spinning forever ...\n"); | 2187 | pr_emerg("platform device data not available, spinning forever ...\n"); |
| 2187 | unreachable(); | 2188 | unreachable(); |
| 2188 | } else { | 2189 | } else { |
| 2189 | /* Get the rtc data. */ | 2190 | /* Get the rtc data. */ |
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c index adaf06c41479..7e48e532214f 100644 --- a/drivers/rtc/rtc-ds3232.c +++ b/drivers/rtc/rtc-ds3232.c | |||
| @@ -15,6 +15,8 @@ | |||
| 15 | * "Sending and receiving", using SMBus level communication is preferred. | 15 | * "Sending and receiving", using SMBus level communication is preferred. |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 19 | |||
| 18 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
| 19 | #include <linux/module.h> | 21 | #include <linux/module.h> |
| 20 | #include <linux/interrupt.h> | 22 | #include <linux/interrupt.h> |
| @@ -373,8 +375,8 @@ static void ds3232_work(struct work_struct *work) | |||
| 373 | if (stat & DS3232_REG_SR_A1F) { | 375 | if (stat & DS3232_REG_SR_A1F) { |
| 374 | control = i2c_smbus_read_byte_data(client, DS3232_REG_CR); | 376 | control = i2c_smbus_read_byte_data(client, DS3232_REG_CR); |
| 375 | if (control < 0) { | 377 | if (control < 0) { |
| 376 | pr_warn("Read DS3232 Control Register error." | 378 | pr_warn("Read Control Register error - Disable IRQ%d\n", |
| 377 | "Disable IRQ%d.\n", client->irq); | 379 | client->irq); |
| 378 | } else { | 380 | } else { |
| 379 | /* disable alarm1 interrupt */ | 381 | /* disable alarm1 interrupt */ |
| 380 | control &= ~(DS3232_REG_CR_A1IE); | 382 | control &= ~(DS3232_REG_CR_A1IE); |
diff --git a/drivers/rtc/rtc-efi-platform.c b/drivers/rtc/rtc-efi-platform.c index b40fbe332af4..1a7f1d1bc174 100644 --- a/drivers/rtc/rtc-efi-platform.c +++ b/drivers/rtc/rtc-efi-platform.c | |||
| @@ -8,6 +8,9 @@ | |||
| 8 | * Copyright (C) 1999-2000 VA Linux Systems | 8 | * Copyright (C) 1999-2000 VA Linux Systems |
| 9 | * Copyright (C) 1999-2000 Walt Drummond <drummond@valinux.com> | 9 | * Copyright (C) 1999-2000 Walt Drummond <drummond@valinux.com> |
| 10 | */ | 10 | */ |
| 11 | |||
| 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 13 | |||
| 11 | #include <linux/init.h> | 14 | #include <linux/init.h> |
| 12 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
| 13 | #include <linux/module.h> | 16 | #include <linux/module.h> |
diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c index fccf36699245..4f4930a2004c 100644 --- a/drivers/rtc/rtc-em3027.c +++ b/drivers/rtc/rtc-em3027.c | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #include <linux/rtc.h> | 15 | #include <linux/rtc.h> |
| 16 | #include <linux/bcd.h> | 16 | #include <linux/bcd.h> |
| 17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
| 18 | #include <linux/of.h> | ||
| 18 | 19 | ||
| 19 | /* Registers */ | 20 | /* Registers */ |
| 20 | #define EM3027_REG_ON_OFF_CTRL 0x00 | 21 | #define EM3027_REG_ON_OFF_CTRL 0x00 |
| @@ -135,10 +136,20 @@ static struct i2c_device_id em3027_id[] = { | |||
| 135 | { "em3027", 0 }, | 136 | { "em3027", 0 }, |
| 136 | { } | 137 | { } |
| 137 | }; | 138 | }; |
| 139 | MODULE_DEVICE_TABLE(i2c, em3027_id); | ||
| 140 | |||
| 141 | #ifdef CONFIG_OF | ||
| 142 | static const struct of_device_id em3027_of_match[] = { | ||
| 143 | { .compatible = "emmicro,em3027", }, | ||
| 144 | {} | ||
| 145 | }; | ||
| 146 | MODULE_DEVICE_TABLE(of, em3027_of_match); | ||
| 147 | #endif | ||
| 138 | 148 | ||
| 139 | static struct i2c_driver em3027_driver = { | 149 | static struct i2c_driver em3027_driver = { |
| 140 | .driver = { | 150 | .driver = { |
| 141 | .name = "rtc-em3027", | 151 | .name = "rtc-em3027", |
| 152 | .of_match_table = of_match_ptr(em3027_of_match), | ||
| 142 | }, | 153 | }, |
| 143 | .probe = &em3027_probe, | 154 | .probe = &em3027_probe, |
| 144 | .id_table = em3027_id, | 155 | .id_table = em3027_id, |
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c index ae7c2ba440cf..af4f85a66b39 100644 --- a/drivers/rtc/rtc-hid-sensor-time.c +++ b/drivers/rtc/rtc-hid-sensor-time.c | |||
| @@ -213,7 +213,7 @@ static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 213 | /* get a report with all values through requesting one value */ | 213 | /* get a report with all values through requesting one value */ |
| 214 | sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev, | 214 | sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev, |
| 215 | HID_USAGE_SENSOR_TIME, hid_time_addresses[0], | 215 | HID_USAGE_SENSOR_TIME, hid_time_addresses[0], |
| 216 | time_state->info[0].report_id); | 216 | time_state->info[0].report_id, SENSOR_HUB_SYNC); |
| 217 | /* wait for all values (event) */ | 217 | /* wait for all values (event) */ |
| 218 | ret = wait_for_completion_killable_timeout( | 218 | ret = wait_for_completion_killable_timeout( |
| 219 | &time_state->comp_last_time, HZ*6); | 219 | &time_state->comp_last_time, HZ*6); |
diff --git a/drivers/rtc/rtc-hym8563.c b/drivers/rtc/rtc-hym8563.c index b936bb4096b5..0f710e98538f 100644 --- a/drivers/rtc/rtc-hym8563.c +++ b/drivers/rtc/rtc-hym8563.c | |||
| @@ -66,7 +66,7 @@ | |||
| 66 | #define HYM8563_ALM_BIT_DISABLE BIT(7) | 66 | #define HYM8563_ALM_BIT_DISABLE BIT(7) |
| 67 | 67 | ||
| 68 | #define HYM8563_CLKOUT 0x0d | 68 | #define HYM8563_CLKOUT 0x0d |
| 69 | #define HYM8563_CLKOUT_DISABLE BIT(7) | 69 | #define HYM8563_CLKOUT_ENABLE BIT(7) |
| 70 | #define HYM8563_CLKOUT_32768 0 | 70 | #define HYM8563_CLKOUT_32768 0 |
| 71 | #define HYM8563_CLKOUT_1024 1 | 71 | #define HYM8563_CLKOUT_1024 1 |
| 72 | #define HYM8563_CLKOUT_32 2 | 72 | #define HYM8563_CLKOUT_32 2 |
| @@ -309,7 +309,7 @@ static unsigned long hym8563_clkout_recalc_rate(struct clk_hw *hw, | |||
| 309 | struct i2c_client *client = hym8563->client; | 309 | struct i2c_client *client = hym8563->client; |
| 310 | int ret = i2c_smbus_read_byte_data(client, HYM8563_CLKOUT); | 310 | int ret = i2c_smbus_read_byte_data(client, HYM8563_CLKOUT); |
| 311 | 311 | ||
| 312 | if (ret < 0 || ret & HYM8563_CLKOUT_DISABLE) | 312 | if (ret < 0) |
| 313 | return 0; | 313 | return 0; |
| 314 | 314 | ||
| 315 | ret &= HYM8563_CLKOUT_MASK; | 315 | ret &= HYM8563_CLKOUT_MASK; |
| @@ -360,9 +360,9 @@ static int hym8563_clkout_control(struct clk_hw *hw, bool enable) | |||
| 360 | return ret; | 360 | return ret; |
| 361 | 361 | ||
| 362 | if (enable) | 362 | if (enable) |
| 363 | ret &= ~HYM8563_CLKOUT_DISABLE; | 363 | ret |= HYM8563_CLKOUT_ENABLE; |
| 364 | else | 364 | else |
| 365 | ret |= HYM8563_CLKOUT_DISABLE; | 365 | ret &= ~HYM8563_CLKOUT_ENABLE; |
| 366 | 366 | ||
| 367 | return i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, ret); | 367 | return i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, ret); |
| 368 | } | 368 | } |
| @@ -386,7 +386,7 @@ static int hym8563_clkout_is_prepared(struct clk_hw *hw) | |||
| 386 | if (ret < 0) | 386 | if (ret < 0) |
| 387 | return ret; | 387 | return ret; |
| 388 | 388 | ||
| 389 | return !(ret & HYM8563_CLKOUT_DISABLE); | 389 | return !!(ret & HYM8563_CLKOUT_ENABLE); |
| 390 | } | 390 | } |
| 391 | 391 | ||
| 392 | static const struct clk_ops hym8563_clkout_ops = { | 392 | static const struct clk_ops hym8563_clkout_ops = { |
| @@ -407,7 +407,7 @@ static struct clk *hym8563_clkout_register_clk(struct hym8563 *hym8563) | |||
| 407 | int ret; | 407 | int ret; |
| 408 | 408 | ||
| 409 | ret = i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, | 409 | ret = i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, |
| 410 | HYM8563_CLKOUT_DISABLE); | 410 | 0); |
| 411 | if (ret < 0) | 411 | if (ret < 0) |
| 412 | return ERR_PTR(ret); | 412 | return ERR_PTR(ret); |
| 413 | 413 | ||
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c index 7ff7427c2e6a..a82937e2f824 100644 --- a/drivers/rtc/rtc-m41t80.c +++ b/drivers/rtc/rtc-m41t80.c | |||
| @@ -13,6 +13,8 @@ | |||
| 13 | * | 13 | * |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 17 | |||
| 16 | #include <linux/bcd.h> | 18 | #include <linux/bcd.h> |
| 17 | #include <linux/i2c.h> | 19 | #include <linux/i2c.h> |
| 18 | #include <linux/init.h> | 20 | #include <linux/init.h> |
| @@ -513,12 +515,12 @@ static int wdt_ioctl(struct file *file, unsigned int cmd, | |||
| 513 | return -EFAULT; | 515 | return -EFAULT; |
| 514 | 516 | ||
| 515 | if (rv & WDIOS_DISABLECARD) { | 517 | if (rv & WDIOS_DISABLECARD) { |
| 516 | pr_info("rtc-m41t80: disable watchdog\n"); | 518 | pr_info("disable watchdog\n"); |
| 517 | wdt_disable(); | 519 | wdt_disable(); |
| 518 | } | 520 | } |
| 519 | 521 | ||
| 520 | if (rv & WDIOS_ENABLECARD) { | 522 | if (rv & WDIOS_ENABLECARD) { |
| 521 | pr_info("rtc-m41t80: enable watchdog\n"); | 523 | pr_info("enable watchdog\n"); |
| 522 | wdt_ping(); | 524 | wdt_ping(); |
| 523 | } | 525 | } |
| 524 | 526 | ||
diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c index 9d71328e59b9..7632a87784c3 100644 --- a/drivers/rtc/rtc-max77686.c +++ b/drivers/rtc/rtc-max77686.c | |||
| @@ -12,6 +12,8 @@ | |||
| 12 | * | 12 | * |
| 13 | */ | 13 | */ |
| 14 | 14 | ||
| 15 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 16 | |||
| 15 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
| 16 | #include <linux/rtc.h> | 18 | #include <linux/rtc.h> |
| 17 | #include <linux/delay.h> | 19 | #include <linux/delay.h> |
| @@ -103,8 +105,8 @@ static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data) | |||
| 103 | data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; | 105 | data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; |
| 104 | 106 | ||
| 105 | if (tm->tm_year < 100) { | 107 | if (tm->tm_year < 100) { |
| 106 | pr_warn("%s: MAX77686 RTC cannot handle the year %d." | 108 | pr_warn("RTC cannot handle the year %d. Assume it's 2000.\n", |
| 107 | "Assume it's 2000.\n", __func__, 1900 + tm->tm_year); | 109 | 1900 + tm->tm_year); |
| 108 | return -EINVAL; | 110 | return -EINVAL; |
| 109 | } | 111 | } |
| 110 | return 0; | 112 | return 0; |
diff --git a/drivers/rtc/rtc-max8997.c b/drivers/rtc/rtc-max8997.c index 67fbe559d535..9e02bcda0c09 100644 --- a/drivers/rtc/rtc-max8997.c +++ b/drivers/rtc/rtc-max8997.c | |||
| @@ -12,6 +12,8 @@ | |||
| 12 | * | 12 | * |
| 13 | */ | 13 | */ |
| 14 | 14 | ||
| 15 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 16 | |||
| 15 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
| 16 | #include <linux/rtc.h> | 18 | #include <linux/rtc.h> |
| 17 | #include <linux/delay.h> | 19 | #include <linux/delay.h> |
| @@ -107,8 +109,8 @@ static int max8997_rtc_tm_to_data(struct rtc_time *tm, u8 *data) | |||
| 107 | data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; | 109 | data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; |
| 108 | 110 | ||
| 109 | if (tm->tm_year < 100) { | 111 | if (tm->tm_year < 100) { |
| 110 | pr_warn("%s: MAX8997 RTC cannot handle the year %d." | 112 | pr_warn("RTC cannot handle the year %d. Assume it's 2000.\n", |
| 111 | "Assume it's 2000.\n", __func__, 1900 + tm->tm_year); | 113 | 1900 + tm->tm_year); |
| 112 | return -EINVAL; | 114 | return -EINVAL; |
| 113 | } | 115 | } |
| 114 | return 0; | 116 | return 0; |
| @@ -424,7 +426,7 @@ static void max8997_rtc_enable_smpl(struct max8997_rtc_info *info, bool enable) | |||
| 424 | 426 | ||
| 425 | val = 0; | 427 | val = 0; |
| 426 | max8997_read_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, &val); | 428 | max8997_read_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, &val); |
| 427 | pr_info("%s: WTSR_SMPL(0x%02x)\n", __func__, val); | 429 | pr_info("WTSR_SMPL(0x%02x)\n", val); |
| 428 | } | 430 | } |
| 429 | 431 | ||
| 430 | static int max8997_rtc_init_reg(struct max8997_rtc_info *info) | 432 | static int max8997_rtc_init_reg(struct max8997_rtc_info *info) |
diff --git a/drivers/rtc/rtc-mc13xxx.c b/drivers/rtc/rtc-mc13xxx.c index 5bce904b7ee6..32df1d812367 100644 --- a/drivers/rtc/rtc-mc13xxx.c +++ b/drivers/rtc/rtc-mc13xxx.c | |||
| @@ -83,20 +83,19 @@ static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 83 | return ret; | 83 | return ret; |
| 84 | } while (days1 != days2); | 84 | } while (days1 != days2); |
| 85 | 85 | ||
| 86 | rtc_time_to_tm(days1 * SEC_PER_DAY + seconds, tm); | 86 | rtc_time64_to_tm((time64_t)days1 * SEC_PER_DAY + seconds, tm); |
| 87 | 87 | ||
| 88 | return rtc_valid_tm(tm); | 88 | return rtc_valid_tm(tm); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | static int mc13xxx_rtc_set_mmss(struct device *dev, unsigned long secs) | 91 | static int mc13xxx_rtc_set_mmss(struct device *dev, time64_t secs) |
| 92 | { | 92 | { |
| 93 | struct mc13xxx_rtc *priv = dev_get_drvdata(dev); | 93 | struct mc13xxx_rtc *priv = dev_get_drvdata(dev); |
| 94 | unsigned int seconds, days; | 94 | unsigned int seconds, days; |
| 95 | unsigned int alarmseconds; | 95 | unsigned int alarmseconds; |
| 96 | int ret; | 96 | int ret; |
| 97 | 97 | ||
| 98 | seconds = secs % SEC_PER_DAY; | 98 | days = div_s64_rem(secs, SEC_PER_DAY, &seconds); |
| 99 | days = secs / SEC_PER_DAY; | ||
| 100 | 99 | ||
| 101 | mc13xxx_lock(priv->mc13xxx); | 100 | mc13xxx_lock(priv->mc13xxx); |
| 102 | 101 | ||
| @@ -159,7 +158,7 @@ static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | |||
| 159 | { | 158 | { |
| 160 | struct mc13xxx_rtc *priv = dev_get_drvdata(dev); | 159 | struct mc13xxx_rtc *priv = dev_get_drvdata(dev); |
| 161 | unsigned seconds, days; | 160 | unsigned seconds, days; |
| 162 | unsigned long s1970; | 161 | time64_t s1970; |
| 163 | int enabled, pending; | 162 | int enabled, pending; |
| 164 | int ret; | 163 | int ret; |
| 165 | 164 | ||
| @@ -189,10 +188,10 @@ out: | |||
| 189 | alarm->enabled = enabled; | 188 | alarm->enabled = enabled; |
| 190 | alarm->pending = pending; | 189 | alarm->pending = pending; |
| 191 | 190 | ||
| 192 | s1970 = days * SEC_PER_DAY + seconds; | 191 | s1970 = (time64_t)days * SEC_PER_DAY + seconds; |
| 193 | 192 | ||
| 194 | rtc_time_to_tm(s1970, &alarm->time); | 193 | rtc_time64_to_tm(s1970, &alarm->time); |
| 195 | dev_dbg(dev, "%s: %lu\n", __func__, s1970); | 194 | dev_dbg(dev, "%s: %lld\n", __func__, (long long)s1970); |
| 196 | 195 | ||
| 197 | return 0; | 196 | return 0; |
| 198 | } | 197 | } |
| @@ -200,8 +199,8 @@ out: | |||
| 200 | static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | 199 | static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
| 201 | { | 200 | { |
| 202 | struct mc13xxx_rtc *priv = dev_get_drvdata(dev); | 201 | struct mc13xxx_rtc *priv = dev_get_drvdata(dev); |
| 203 | unsigned long s1970; | 202 | time64_t s1970; |
| 204 | unsigned seconds, days; | 203 | u32 seconds, days; |
| 205 | int ret; | 204 | int ret; |
| 206 | 205 | ||
| 207 | mc13xxx_lock(priv->mc13xxx); | 206 | mc13xxx_lock(priv->mc13xxx); |
| @@ -215,20 +214,17 @@ static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | |||
| 215 | if (unlikely(ret)) | 214 | if (unlikely(ret)) |
| 216 | goto out; | 215 | goto out; |
| 217 | 216 | ||
| 218 | ret = rtc_tm_to_time(&alarm->time, &s1970); | 217 | s1970 = rtc_tm_to_time64(&alarm->time); |
| 219 | if (unlikely(ret)) | ||
| 220 | goto out; | ||
| 221 | 218 | ||
| 222 | dev_dbg(dev, "%s: o%2.s %lu\n", __func__, alarm->enabled ? "n" : "ff", | 219 | dev_dbg(dev, "%s: o%2.s %lld\n", __func__, alarm->enabled ? "n" : "ff", |
| 223 | s1970); | 220 | (long long)s1970); |
| 224 | 221 | ||
| 225 | ret = mc13xxx_rtc_irq_enable_unlocked(dev, alarm->enabled, | 222 | ret = mc13xxx_rtc_irq_enable_unlocked(dev, alarm->enabled, |
| 226 | MC13XXX_IRQ_TODA); | 223 | MC13XXX_IRQ_TODA); |
| 227 | if (unlikely(ret)) | 224 | if (unlikely(ret)) |
| 228 | goto out; | 225 | goto out; |
| 229 | 226 | ||
| 230 | seconds = s1970 % SEC_PER_DAY; | 227 | days = div_s64_rem(s1970, SEC_PER_DAY, &seconds); |
| 231 | days = s1970 / SEC_PER_DAY; | ||
| 232 | 228 | ||
| 233 | ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCDAYA, days); | 229 | ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCDAYA, days); |
| 234 | if (unlikely(ret)) | 230 | if (unlikely(ret)) |
| @@ -268,7 +264,7 @@ static irqreturn_t mc13xxx_rtc_update_handler(int irq, void *dev) | |||
| 268 | 264 | ||
| 269 | static const struct rtc_class_ops mc13xxx_rtc_ops = { | 265 | static const struct rtc_class_ops mc13xxx_rtc_ops = { |
| 270 | .read_time = mc13xxx_rtc_read_time, | 266 | .read_time = mc13xxx_rtc_read_time, |
| 271 | .set_mmss = mc13xxx_rtc_set_mmss, | 267 | .set_mmss64 = mc13xxx_rtc_set_mmss, |
| 272 | .read_alarm = mc13xxx_rtc_read_alarm, | 268 | .read_alarm = mc13xxx_rtc_read_alarm, |
| 273 | .set_alarm = mc13xxx_rtc_set_alarm, | 269 | .set_alarm = mc13xxx_rtc_set_alarm, |
| 274 | .alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable, | 270 | .alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable, |
diff --git a/drivers/rtc/rtc-mrst.c b/drivers/rtc/rtc-mrst.c index e2436d140175..548ea6f6f384 100644 --- a/drivers/rtc/rtc-mrst.c +++ b/drivers/rtc/rtc-mrst.c | |||
| @@ -277,13 +277,15 @@ static int mrst_procfs(struct device *dev, struct seq_file *seq) | |||
| 277 | valid = vrtc_cmos_read(RTC_VALID); | 277 | valid = vrtc_cmos_read(RTC_VALID); |
| 278 | spin_unlock_irq(&rtc_lock); | 278 | spin_unlock_irq(&rtc_lock); |
| 279 | 279 | ||
| 280 | return seq_printf(seq, | 280 | seq_printf(seq, |
| 281 | "periodic_IRQ\t: %s\n" | 281 | "periodic_IRQ\t: %s\n" |
| 282 | "alarm\t\t: %s\n" | 282 | "alarm\t\t: %s\n" |
| 283 | "BCD\t\t: no\n" | 283 | "BCD\t\t: no\n" |
| 284 | "periodic_freq\t: daily (not adjustable)\n", | 284 | "periodic_freq\t: daily (not adjustable)\n", |
| 285 | (rtc_control & RTC_PIE) ? "on" : "off", | 285 | (rtc_control & RTC_PIE) ? "on" : "off", |
| 286 | (rtc_control & RTC_AIE) ? "on" : "off"); | 286 | (rtc_control & RTC_AIE) ? "on" : "off"); |
| 287 | |||
| 288 | return 0; | ||
| 287 | } | 289 | } |
| 288 | 290 | ||
| 289 | #else | 291 | #else |
| @@ -413,8 +415,8 @@ static void rtc_mrst_do_remove(struct device *dev) | |||
| 413 | mrst->dev = NULL; | 415 | mrst->dev = NULL; |
| 414 | } | 416 | } |
| 415 | 417 | ||
| 416 | #ifdef CONFIG_PM | 418 | #ifdef CONFIG_PM_SLEEP |
| 417 | static int mrst_suspend(struct device *dev, pm_message_t mesg) | 419 | static int mrst_suspend(struct device *dev) |
| 418 | { | 420 | { |
| 419 | struct mrst_rtc *mrst = dev_get_drvdata(dev); | 421 | struct mrst_rtc *mrst = dev_get_drvdata(dev); |
| 420 | unsigned char tmp; | 422 | unsigned char tmp; |
| @@ -453,7 +455,7 @@ static int mrst_suspend(struct device *dev, pm_message_t mesg) | |||
| 453 | */ | 455 | */ |
| 454 | static inline int mrst_poweroff(struct device *dev) | 456 | static inline int mrst_poweroff(struct device *dev) |
| 455 | { | 457 | { |
| 456 | return mrst_suspend(dev, PMSG_HIBERNATE); | 458 | return mrst_suspend(dev); |
| 457 | } | 459 | } |
| 458 | 460 | ||
| 459 | static int mrst_resume(struct device *dev) | 461 | static int mrst_resume(struct device *dev) |
| @@ -490,9 +492,11 @@ static int mrst_resume(struct device *dev) | |||
| 490 | return 0; | 492 | return 0; |
| 491 | } | 493 | } |
| 492 | 494 | ||
| 495 | static SIMPLE_DEV_PM_OPS(mrst_pm_ops, mrst_suspend, mrst_resume); | ||
| 496 | #define MRST_PM_OPS (&mrst_pm_ops) | ||
| 497 | |||
| 493 | #else | 498 | #else |
| 494 | #define mrst_suspend NULL | 499 | #define MRST_PM_OPS NULL |
| 495 | #define mrst_resume NULL | ||
| 496 | 500 | ||
| 497 | static inline int mrst_poweroff(struct device *dev) | 501 | static inline int mrst_poweroff(struct device *dev) |
| 498 | { | 502 | { |
| @@ -529,9 +533,8 @@ static struct platform_driver vrtc_mrst_platform_driver = { | |||
| 529 | .remove = vrtc_mrst_platform_remove, | 533 | .remove = vrtc_mrst_platform_remove, |
| 530 | .shutdown = vrtc_mrst_platform_shutdown, | 534 | .shutdown = vrtc_mrst_platform_shutdown, |
| 531 | .driver = { | 535 | .driver = { |
| 532 | .name = (char *) driver_name, | 536 | .name = driver_name, |
| 533 | .suspend = mrst_suspend, | 537 | .pm = MRST_PM_OPS, |
| 534 | .resume = mrst_resume, | ||
| 535 | } | 538 | } |
| 536 | }; | 539 | }; |
| 537 | 540 | ||
diff --git a/drivers/rtc/rtc-msm6242.c b/drivers/rtc/rtc-msm6242.c index 9bf877bdf836..c1c5c4e3b3b4 100644 --- a/drivers/rtc/rtc-msm6242.c +++ b/drivers/rtc/rtc-msm6242.c | |||
| @@ -7,6 +7,8 @@ | |||
| 7 | * Copyright (C) 1993 Hamish Macdonald | 7 | * Copyright (C) 1993 Hamish Macdonald |
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 11 | |||
| 10 | #include <linux/delay.h> | 12 | #include <linux/delay.h> |
| 11 | #include <linux/io.h> | 13 | #include <linux/io.h> |
| 12 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
| @@ -111,7 +113,7 @@ static void msm6242_lock(struct msm6242_priv *priv) | |||
| 111 | } | 113 | } |
| 112 | 114 | ||
| 113 | if (!cnt) | 115 | if (!cnt) |
| 114 | pr_warn("msm6242: timed out waiting for RTC (0x%x)\n", | 116 | pr_warn("timed out waiting for RTC (0x%x)\n", |
| 115 | msm6242_read(priv, MSM6242_CD)); | 117 | msm6242_read(priv, MSM6242_CD)); |
| 116 | } | 118 | } |
| 117 | 119 | ||
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c index 3c3f8d10ab43..09d422b9f7f7 100644 --- a/drivers/rtc/rtc-mxc.c +++ b/drivers/rtc/rtc-mxc.c | |||
| @@ -106,7 +106,7 @@ static inline int is_imx1_rtc(struct rtc_plat_data *data) | |||
| 106 | * This function is used to obtain the RTC time or the alarm value in | 106 | * This function is used to obtain the RTC time or the alarm value in |
| 107 | * second. | 107 | * second. |
| 108 | */ | 108 | */ |
| 109 | static u32 get_alarm_or_time(struct device *dev, int time_alarm) | 109 | static time64_t get_alarm_or_time(struct device *dev, int time_alarm) |
| 110 | { | 110 | { |
| 111 | struct platform_device *pdev = to_platform_device(dev); | 111 | struct platform_device *pdev = to_platform_device(dev); |
| 112 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 112 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| @@ -129,29 +129,28 @@ static u32 get_alarm_or_time(struct device *dev, int time_alarm) | |||
| 129 | hr = hr_min >> 8; | 129 | hr = hr_min >> 8; |
| 130 | min = hr_min & 0xff; | 130 | min = hr_min & 0xff; |
| 131 | 131 | ||
| 132 | return (((day * 24 + hr) * 60) + min) * 60 + sec; | 132 | return ((((time64_t)day * 24 + hr) * 60) + min) * 60 + sec; |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | /* | 135 | /* |
| 136 | * This function sets the RTC alarm value or the time value. | 136 | * This function sets the RTC alarm value or the time value. |
| 137 | */ | 137 | */ |
| 138 | static void set_alarm_or_time(struct device *dev, int time_alarm, u32 time) | 138 | static void set_alarm_or_time(struct device *dev, int time_alarm, time64_t time) |
| 139 | { | 139 | { |
| 140 | u32 day, hr, min, sec, temp; | 140 | u32 tod, day, hr, min, sec, temp; |
| 141 | struct platform_device *pdev = to_platform_device(dev); | 141 | struct platform_device *pdev = to_platform_device(dev); |
| 142 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 142 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 143 | void __iomem *ioaddr = pdata->ioaddr; | 143 | void __iomem *ioaddr = pdata->ioaddr; |
| 144 | 144 | ||
| 145 | day = time / 86400; | 145 | day = div_s64_rem(time, 86400, &tod); |
| 146 | time -= day * 86400; | ||
| 147 | 146 | ||
| 148 | /* time is within a day now */ | 147 | /* time is within a day now */ |
| 149 | hr = time / 3600; | 148 | hr = tod / 3600; |
| 150 | time -= hr * 3600; | 149 | tod -= hr * 3600; |
| 151 | 150 | ||
| 152 | /* time is within an hour now */ | 151 | /* time is within an hour now */ |
| 153 | min = time / 60; | 152 | min = tod / 60; |
| 154 | sec = time - min * 60; | 153 | sec = tod - min * 60; |
| 155 | 154 | ||
| 156 | temp = (hr << 8) + min; | 155 | temp = (hr << 8) + min; |
| 157 | 156 | ||
| @@ -173,29 +172,18 @@ static void set_alarm_or_time(struct device *dev, int time_alarm, u32 time) | |||
| 173 | * This function updates the RTC alarm registers and then clears all the | 172 | * This function updates the RTC alarm registers and then clears all the |
| 174 | * interrupt status bits. | 173 | * interrupt status bits. |
| 175 | */ | 174 | */ |
| 176 | static int rtc_update_alarm(struct device *dev, struct rtc_time *alrm) | 175 | static void rtc_update_alarm(struct device *dev, struct rtc_time *alrm) |
| 177 | { | 176 | { |
| 178 | struct rtc_time alarm_tm, now_tm; | 177 | time64_t time; |
| 179 | unsigned long now, time; | ||
| 180 | struct platform_device *pdev = to_platform_device(dev); | 178 | struct platform_device *pdev = to_platform_device(dev); |
| 181 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 179 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 182 | void __iomem *ioaddr = pdata->ioaddr; | 180 | void __iomem *ioaddr = pdata->ioaddr; |
| 183 | 181 | ||
| 184 | now = get_alarm_or_time(dev, MXC_RTC_TIME); | 182 | time = rtc_tm_to_time64(alrm); |
| 185 | rtc_time_to_tm(now, &now_tm); | ||
| 186 | alarm_tm.tm_year = now_tm.tm_year; | ||
| 187 | alarm_tm.tm_mon = now_tm.tm_mon; | ||
| 188 | alarm_tm.tm_mday = now_tm.tm_mday; | ||
| 189 | alarm_tm.tm_hour = alrm->tm_hour; | ||
| 190 | alarm_tm.tm_min = alrm->tm_min; | ||
| 191 | alarm_tm.tm_sec = alrm->tm_sec; | ||
| 192 | rtc_tm_to_time(&alarm_tm, &time); | ||
| 193 | 183 | ||
| 194 | /* clear all the interrupt status bits */ | 184 | /* clear all the interrupt status bits */ |
| 195 | writew(readw(ioaddr + RTC_RTCISR), ioaddr + RTC_RTCISR); | 185 | writew(readw(ioaddr + RTC_RTCISR), ioaddr + RTC_RTCISR); |
| 196 | set_alarm_or_time(dev, MXC_RTC_ALARM, time); | 186 | set_alarm_or_time(dev, MXC_RTC_ALARM, time); |
| 197 | |||
| 198 | return 0; | ||
| 199 | } | 187 | } |
| 200 | 188 | ||
| 201 | static void mxc_rtc_irq_enable(struct device *dev, unsigned int bit, | 189 | static void mxc_rtc_irq_enable(struct device *dev, unsigned int bit, |
| @@ -283,14 +271,14 @@ static int mxc_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | |||
| 283 | */ | 271 | */ |
| 284 | static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm) | 272 | static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| 285 | { | 273 | { |
| 286 | u32 val; | 274 | time64_t val; |
| 287 | 275 | ||
| 288 | /* Avoid roll-over from reading the different registers */ | 276 | /* Avoid roll-over from reading the different registers */ |
| 289 | do { | 277 | do { |
| 290 | val = get_alarm_or_time(dev, MXC_RTC_TIME); | 278 | val = get_alarm_or_time(dev, MXC_RTC_TIME); |
| 291 | } while (val != get_alarm_or_time(dev, MXC_RTC_TIME)); | 279 | } while (val != get_alarm_or_time(dev, MXC_RTC_TIME)); |
| 292 | 280 | ||
| 293 | rtc_time_to_tm(val, tm); | 281 | rtc_time64_to_tm(val, tm); |
| 294 | 282 | ||
| 295 | return 0; | 283 | return 0; |
| 296 | } | 284 | } |
| @@ -298,7 +286,7 @@ static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 298 | /* | 286 | /* |
| 299 | * This function sets the internal RTC time based on tm in Gregorian date. | 287 | * This function sets the internal RTC time based on tm in Gregorian date. |
| 300 | */ | 288 | */ |
| 301 | static int mxc_rtc_set_mmss(struct device *dev, unsigned long time) | 289 | static int mxc_rtc_set_mmss(struct device *dev, time64_t time) |
| 302 | { | 290 | { |
| 303 | struct platform_device *pdev = to_platform_device(dev); | 291 | struct platform_device *pdev = to_platform_device(dev); |
| 304 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 292 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| @@ -309,9 +297,9 @@ static int mxc_rtc_set_mmss(struct device *dev, unsigned long time) | |||
| 309 | if (is_imx1_rtc(pdata)) { | 297 | if (is_imx1_rtc(pdata)) { |
| 310 | struct rtc_time tm; | 298 | struct rtc_time tm; |
| 311 | 299 | ||
| 312 | rtc_time_to_tm(time, &tm); | 300 | rtc_time64_to_tm(time, &tm); |
| 313 | tm.tm_year = 70; | 301 | tm.tm_year = 70; |
| 314 | rtc_tm_to_time(&tm, &time); | 302 | time = rtc_tm_to_time64(&tm); |
| 315 | } | 303 | } |
| 316 | 304 | ||
| 317 | /* Avoid roll-over from reading the different registers */ | 305 | /* Avoid roll-over from reading the different registers */ |
| @@ -333,7 +321,7 @@ static int mxc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 333 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 321 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 334 | void __iomem *ioaddr = pdata->ioaddr; | 322 | void __iomem *ioaddr = pdata->ioaddr; |
| 335 | 323 | ||
| 336 | rtc_time_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time); | 324 | rtc_time64_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time); |
| 337 | alrm->pending = ((readw(ioaddr + RTC_RTCISR) & RTC_ALM_BIT)) ? 1 : 0; | 325 | alrm->pending = ((readw(ioaddr + RTC_RTCISR) & RTC_ALM_BIT)) ? 1 : 0; |
| 338 | 326 | ||
| 339 | return 0; | 327 | return 0; |
| @@ -346,11 +334,8 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 346 | { | 334 | { |
| 347 | struct platform_device *pdev = to_platform_device(dev); | 335 | struct platform_device *pdev = to_platform_device(dev); |
| 348 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 336 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 349 | int ret; | ||
| 350 | 337 | ||
| 351 | ret = rtc_update_alarm(dev, &alrm->time); | 338 | rtc_update_alarm(dev, &alrm->time); |
| 352 | if (ret) | ||
| 353 | return ret; | ||
| 354 | 339 | ||
| 355 | memcpy(&pdata->g_rtc_alarm, &alrm->time, sizeof(struct rtc_time)); | 340 | memcpy(&pdata->g_rtc_alarm, &alrm->time, sizeof(struct rtc_time)); |
| 356 | mxc_rtc_irq_enable(dev, RTC_ALM_BIT, alrm->enabled); | 341 | mxc_rtc_irq_enable(dev, RTC_ALM_BIT, alrm->enabled); |
| @@ -362,7 +347,7 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 362 | static struct rtc_class_ops mxc_rtc_ops = { | 347 | static struct rtc_class_ops mxc_rtc_ops = { |
| 363 | .release = mxc_rtc_release, | 348 | .release = mxc_rtc_release, |
| 364 | .read_time = mxc_rtc_read_time, | 349 | .read_time = mxc_rtc_read_time, |
| 365 | .set_mmss = mxc_rtc_set_mmss, | 350 | .set_mmss64 = mxc_rtc_set_mmss, |
| 366 | .read_alarm = mxc_rtc_read_alarm, | 351 | .read_alarm = mxc_rtc_read_alarm, |
| 367 | .set_alarm = mxc_rtc_set_alarm, | 352 | .set_alarm = mxc_rtc_set_alarm, |
| 368 | .alarm_irq_enable = mxc_rtc_alarm_irq_enable, | 353 | .alarm_irq_enable = mxc_rtc_alarm_irq_enable, |
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c index 8e5851aa4369..8b6355ffaff9 100644 --- a/drivers/rtc/rtc-omap.c +++ b/drivers/rtc/rtc-omap.c | |||
| @@ -118,12 +118,15 @@ | |||
| 118 | #define KICK0_VALUE 0x83e70b13 | 118 | #define KICK0_VALUE 0x83e70b13 |
| 119 | #define KICK1_VALUE 0x95a4f1e0 | 119 | #define KICK1_VALUE 0x95a4f1e0 |
| 120 | 120 | ||
| 121 | struct omap_rtc; | ||
| 122 | |||
| 121 | struct omap_rtc_device_type { | 123 | struct omap_rtc_device_type { |
| 122 | bool has_32kclk_en; | 124 | bool has_32kclk_en; |
| 123 | bool has_kicker; | ||
| 124 | bool has_irqwakeen; | 125 | bool has_irqwakeen; |
| 125 | bool has_pmic_mode; | 126 | bool has_pmic_mode; |
| 126 | bool has_power_up_reset; | 127 | bool has_power_up_reset; |
| 128 | void (*lock)(struct omap_rtc *rtc); | ||
| 129 | void (*unlock)(struct omap_rtc *rtc); | ||
| 127 | }; | 130 | }; |
| 128 | 131 | ||
| 129 | struct omap_rtc { | 132 | struct omap_rtc { |
| @@ -156,6 +159,26 @@ static inline void rtc_writel(struct omap_rtc *rtc, unsigned int reg, u32 val) | |||
| 156 | writel(val, rtc->base + reg); | 159 | writel(val, rtc->base + reg); |
| 157 | } | 160 | } |
| 158 | 161 | ||
| 162 | static void am3352_rtc_unlock(struct omap_rtc *rtc) | ||
| 163 | { | ||
| 164 | rtc_writel(rtc, OMAP_RTC_KICK0_REG, KICK0_VALUE); | ||
| 165 | rtc_writel(rtc, OMAP_RTC_KICK1_REG, KICK1_VALUE); | ||
| 166 | } | ||
| 167 | |||
| 168 | static void am3352_rtc_lock(struct omap_rtc *rtc) | ||
| 169 | { | ||
| 170 | rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0); | ||
| 171 | rtc_writel(rtc, OMAP_RTC_KICK1_REG, 0); | ||
| 172 | } | ||
| 173 | |||
| 174 | static void default_rtc_unlock(struct omap_rtc *rtc) | ||
| 175 | { | ||
| 176 | } | ||
| 177 | |||
| 178 | static void default_rtc_lock(struct omap_rtc *rtc) | ||
| 179 | { | ||
| 180 | } | ||
| 181 | |||
| 159 | /* | 182 | /* |
| 160 | * We rely on the rtc framework to handle locking (rtc->ops_lock), | 183 | * We rely on the rtc framework to handle locking (rtc->ops_lock), |
| 161 | * so the only other requirement is that register accesses which | 184 | * so the only other requirement is that register accesses which |
| @@ -186,7 +209,9 @@ static irqreturn_t rtc_irq(int irq, void *dev_id) | |||
| 186 | 209 | ||
| 187 | /* alarm irq? */ | 210 | /* alarm irq? */ |
| 188 | if (irq_data & OMAP_RTC_STATUS_ALARM) { | 211 | if (irq_data & OMAP_RTC_STATUS_ALARM) { |
| 212 | rtc->type->unlock(rtc); | ||
| 189 | rtc_write(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM); | 213 | rtc_write(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM); |
| 214 | rtc->type->lock(rtc); | ||
| 190 | events |= RTC_IRQF | RTC_AF; | 215 | events |= RTC_IRQF | RTC_AF; |
| 191 | } | 216 | } |
| 192 | 217 | ||
| @@ -218,9 +243,11 @@ static int omap_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | |||
| 218 | irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN; | 243 | irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN; |
| 219 | } | 244 | } |
| 220 | rtc_wait_not_busy(rtc); | 245 | rtc_wait_not_busy(rtc); |
| 246 | rtc->type->unlock(rtc); | ||
| 221 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); | 247 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); |
| 222 | if (rtc->type->has_irqwakeen) | 248 | if (rtc->type->has_irqwakeen) |
| 223 | rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); | 249 | rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); |
| 250 | rtc->type->lock(rtc); | ||
| 224 | local_irq_enable(); | 251 | local_irq_enable(); |
| 225 | 252 | ||
| 226 | return 0; | 253 | return 0; |
| @@ -293,12 +320,14 @@ static int omap_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
| 293 | local_irq_disable(); | 320 | local_irq_disable(); |
| 294 | rtc_wait_not_busy(rtc); | 321 | rtc_wait_not_busy(rtc); |
| 295 | 322 | ||
| 323 | rtc->type->unlock(rtc); | ||
| 296 | rtc_write(rtc, OMAP_RTC_YEARS_REG, tm->tm_year); | 324 | rtc_write(rtc, OMAP_RTC_YEARS_REG, tm->tm_year); |
| 297 | rtc_write(rtc, OMAP_RTC_MONTHS_REG, tm->tm_mon); | 325 | rtc_write(rtc, OMAP_RTC_MONTHS_REG, tm->tm_mon); |
| 298 | rtc_write(rtc, OMAP_RTC_DAYS_REG, tm->tm_mday); | 326 | rtc_write(rtc, OMAP_RTC_DAYS_REG, tm->tm_mday); |
| 299 | rtc_write(rtc, OMAP_RTC_HOURS_REG, tm->tm_hour); | 327 | rtc_write(rtc, OMAP_RTC_HOURS_REG, tm->tm_hour); |
| 300 | rtc_write(rtc, OMAP_RTC_MINUTES_REG, tm->tm_min); | 328 | rtc_write(rtc, OMAP_RTC_MINUTES_REG, tm->tm_min); |
| 301 | rtc_write(rtc, OMAP_RTC_SECONDS_REG, tm->tm_sec); | 329 | rtc_write(rtc, OMAP_RTC_SECONDS_REG, tm->tm_sec); |
| 330 | rtc->type->lock(rtc); | ||
| 302 | 331 | ||
| 303 | local_irq_enable(); | 332 | local_irq_enable(); |
| 304 | 333 | ||
| @@ -341,6 +370,7 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) | |||
| 341 | local_irq_disable(); | 370 | local_irq_disable(); |
| 342 | rtc_wait_not_busy(rtc); | 371 | rtc_wait_not_busy(rtc); |
| 343 | 372 | ||
| 373 | rtc->type->unlock(rtc); | ||
| 344 | rtc_write(rtc, OMAP_RTC_ALARM_YEARS_REG, alm->time.tm_year); | 374 | rtc_write(rtc, OMAP_RTC_ALARM_YEARS_REG, alm->time.tm_year); |
| 345 | rtc_write(rtc, OMAP_RTC_ALARM_MONTHS_REG, alm->time.tm_mon); | 375 | rtc_write(rtc, OMAP_RTC_ALARM_MONTHS_REG, alm->time.tm_mon); |
| 346 | rtc_write(rtc, OMAP_RTC_ALARM_DAYS_REG, alm->time.tm_mday); | 376 | rtc_write(rtc, OMAP_RTC_ALARM_DAYS_REG, alm->time.tm_mday); |
| @@ -362,6 +392,7 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) | |||
| 362 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); | 392 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); |
| 363 | if (rtc->type->has_irqwakeen) | 393 | if (rtc->type->has_irqwakeen) |
| 364 | rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); | 394 | rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); |
| 395 | rtc->type->lock(rtc); | ||
| 365 | 396 | ||
| 366 | local_irq_enable(); | 397 | local_irq_enable(); |
| 367 | 398 | ||
| @@ -391,6 +422,7 @@ static void omap_rtc_power_off(void) | |||
| 391 | unsigned long now; | 422 | unsigned long now; |
| 392 | u32 val; | 423 | u32 val; |
| 393 | 424 | ||
| 425 | rtc->type->unlock(rtc); | ||
| 394 | /* enable pmic_power_en control */ | 426 | /* enable pmic_power_en control */ |
| 395 | val = rtc_readl(rtc, OMAP_RTC_PMIC_REG); | 427 | val = rtc_readl(rtc, OMAP_RTC_PMIC_REG); |
| 396 | rtc_writel(rtc, OMAP_RTC_PMIC_REG, val | OMAP_RTC_PMIC_POWER_EN_EN); | 428 | rtc_writel(rtc, OMAP_RTC_PMIC_REG, val | OMAP_RTC_PMIC_POWER_EN_EN); |
| @@ -423,6 +455,7 @@ static void omap_rtc_power_off(void) | |||
| 423 | val = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); | 455 | val = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); |
| 424 | rtc_writel(rtc, OMAP_RTC_INTERRUPTS_REG, | 456 | rtc_writel(rtc, OMAP_RTC_INTERRUPTS_REG, |
| 425 | val | OMAP_RTC_INTERRUPTS_IT_ALARM2); | 457 | val | OMAP_RTC_INTERRUPTS_IT_ALARM2); |
| 458 | rtc->type->lock(rtc); | ||
| 426 | 459 | ||
| 427 | /* | 460 | /* |
| 428 | * Wait for alarm to trigger (within two seconds) and external PMIC to | 461 | * Wait for alarm to trigger (within two seconds) and external PMIC to |
| @@ -442,17 +475,21 @@ static struct rtc_class_ops omap_rtc_ops = { | |||
| 442 | 475 | ||
| 443 | static const struct omap_rtc_device_type omap_rtc_default_type = { | 476 | static const struct omap_rtc_device_type omap_rtc_default_type = { |
| 444 | .has_power_up_reset = true, | 477 | .has_power_up_reset = true, |
| 478 | .lock = default_rtc_lock, | ||
| 479 | .unlock = default_rtc_unlock, | ||
| 445 | }; | 480 | }; |
| 446 | 481 | ||
| 447 | static const struct omap_rtc_device_type omap_rtc_am3352_type = { | 482 | static const struct omap_rtc_device_type omap_rtc_am3352_type = { |
| 448 | .has_32kclk_en = true, | 483 | .has_32kclk_en = true, |
| 449 | .has_kicker = true, | ||
| 450 | .has_irqwakeen = true, | 484 | .has_irqwakeen = true, |
| 451 | .has_pmic_mode = true, | 485 | .has_pmic_mode = true, |
| 486 | .lock = am3352_rtc_lock, | ||
| 487 | .unlock = am3352_rtc_unlock, | ||
| 452 | }; | 488 | }; |
| 453 | 489 | ||
| 454 | static const struct omap_rtc_device_type omap_rtc_da830_type = { | 490 | static const struct omap_rtc_device_type omap_rtc_da830_type = { |
| 455 | .has_kicker = true, | 491 | .lock = am3352_rtc_lock, |
| 492 | .unlock = am3352_rtc_unlock, | ||
| 456 | }; | 493 | }; |
| 457 | 494 | ||
| 458 | static const struct platform_device_id omap_rtc_id_table[] = { | 495 | static const struct platform_device_id omap_rtc_id_table[] = { |
| @@ -484,7 +521,7 @@ static const struct of_device_id omap_rtc_of_match[] = { | |||
| 484 | }; | 521 | }; |
| 485 | MODULE_DEVICE_TABLE(of, omap_rtc_of_match); | 522 | MODULE_DEVICE_TABLE(of, omap_rtc_of_match); |
| 486 | 523 | ||
| 487 | static int __init omap_rtc_probe(struct platform_device *pdev) | 524 | static int omap_rtc_probe(struct platform_device *pdev) |
| 488 | { | 525 | { |
| 489 | struct omap_rtc *rtc; | 526 | struct omap_rtc *rtc; |
| 490 | struct resource *res; | 527 | struct resource *res; |
| @@ -527,10 +564,7 @@ static int __init omap_rtc_probe(struct platform_device *pdev) | |||
| 527 | pm_runtime_enable(&pdev->dev); | 564 | pm_runtime_enable(&pdev->dev); |
| 528 | pm_runtime_get_sync(&pdev->dev); | 565 | pm_runtime_get_sync(&pdev->dev); |
| 529 | 566 | ||
| 530 | if (rtc->type->has_kicker) { | 567 | rtc->type->unlock(rtc); |
| 531 | rtc_writel(rtc, OMAP_RTC_KICK0_REG, KICK0_VALUE); | ||
| 532 | rtc_writel(rtc, OMAP_RTC_KICK1_REG, KICK1_VALUE); | ||
| 533 | } | ||
| 534 | 568 | ||
| 535 | /* | 569 | /* |
| 536 | * disable interrupts | 570 | * disable interrupts |
| @@ -593,6 +627,8 @@ static int __init omap_rtc_probe(struct platform_device *pdev) | |||
| 593 | if (reg != new_ctrl) | 627 | if (reg != new_ctrl) |
| 594 | rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl); | 628 | rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl); |
| 595 | 629 | ||
| 630 | rtc->type->lock(rtc); | ||
| 631 | |||
| 596 | device_init_wakeup(&pdev->dev, true); | 632 | device_init_wakeup(&pdev->dev, true); |
| 597 | 633 | ||
| 598 | rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, | 634 | rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, |
| @@ -626,8 +662,7 @@ static int __init omap_rtc_probe(struct platform_device *pdev) | |||
| 626 | 662 | ||
| 627 | err: | 663 | err: |
| 628 | device_init_wakeup(&pdev->dev, false); | 664 | device_init_wakeup(&pdev->dev, false); |
| 629 | if (rtc->type->has_kicker) | 665 | rtc->type->lock(rtc); |
| 630 | rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0); | ||
| 631 | pm_runtime_put_sync(&pdev->dev); | 666 | pm_runtime_put_sync(&pdev->dev); |
| 632 | pm_runtime_disable(&pdev->dev); | 667 | pm_runtime_disable(&pdev->dev); |
| 633 | 668 | ||
| @@ -646,11 +681,11 @@ static int __exit omap_rtc_remove(struct platform_device *pdev) | |||
| 646 | 681 | ||
| 647 | device_init_wakeup(&pdev->dev, 0); | 682 | device_init_wakeup(&pdev->dev, 0); |
| 648 | 683 | ||
| 684 | rtc->type->unlock(rtc); | ||
| 649 | /* leave rtc running, but disable irqs */ | 685 | /* leave rtc running, but disable irqs */ |
| 650 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); | 686 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); |
| 651 | 687 | ||
| 652 | if (rtc->type->has_kicker) | 688 | rtc->type->lock(rtc); |
| 653 | rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0); | ||
| 654 | 689 | ||
| 655 | /* Disable the clock/module */ | 690 | /* Disable the clock/module */ |
| 656 | pm_runtime_put_sync(&pdev->dev); | 691 | pm_runtime_put_sync(&pdev->dev); |
| @@ -666,6 +701,7 @@ static int omap_rtc_suspend(struct device *dev) | |||
| 666 | 701 | ||
| 667 | rtc->interrupts_reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); | 702 | rtc->interrupts_reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); |
| 668 | 703 | ||
| 704 | rtc->type->unlock(rtc); | ||
| 669 | /* | 705 | /* |
| 670 | * FIXME: the RTC alarm is not currently acting as a wakeup event | 706 | * FIXME: the RTC alarm is not currently acting as a wakeup event |
| 671 | * source on some platforms, and in fact this enable() call is just | 707 | * source on some platforms, and in fact this enable() call is just |
| @@ -675,6 +711,7 @@ static int omap_rtc_suspend(struct device *dev) | |||
| 675 | enable_irq_wake(rtc->irq_alarm); | 711 | enable_irq_wake(rtc->irq_alarm); |
| 676 | else | 712 | else |
| 677 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); | 713 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); |
| 714 | rtc->type->lock(rtc); | ||
| 678 | 715 | ||
| 679 | /* Disable the clock/module */ | 716 | /* Disable the clock/module */ |
| 680 | pm_runtime_put_sync(dev); | 717 | pm_runtime_put_sync(dev); |
| @@ -689,10 +726,12 @@ static int omap_rtc_resume(struct device *dev) | |||
| 689 | /* Enable the clock/module so that we can access the registers */ | 726 | /* Enable the clock/module so that we can access the registers */ |
| 690 | pm_runtime_get_sync(dev); | 727 | pm_runtime_get_sync(dev); |
| 691 | 728 | ||
| 729 | rtc->type->unlock(rtc); | ||
| 692 | if (device_may_wakeup(dev)) | 730 | if (device_may_wakeup(dev)) |
| 693 | disable_irq_wake(rtc->irq_alarm); | 731 | disable_irq_wake(rtc->irq_alarm); |
| 694 | else | 732 | else |
| 695 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg); | 733 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg); |
| 734 | rtc->type->lock(rtc); | ||
| 696 | 735 | ||
| 697 | return 0; | 736 | return 0; |
| 698 | } | 737 | } |
| @@ -709,12 +748,15 @@ static void omap_rtc_shutdown(struct platform_device *pdev) | |||
| 709 | * Keep the ALARM interrupt enabled to allow the system to power up on | 748 | * Keep the ALARM interrupt enabled to allow the system to power up on |
| 710 | * alarm events. | 749 | * alarm events. |
| 711 | */ | 750 | */ |
| 751 | rtc->type->unlock(rtc); | ||
| 712 | mask = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); | 752 | mask = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); |
| 713 | mask &= OMAP_RTC_INTERRUPTS_IT_ALARM; | 753 | mask &= OMAP_RTC_INTERRUPTS_IT_ALARM; |
| 714 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, mask); | 754 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, mask); |
| 755 | rtc->type->lock(rtc); | ||
| 715 | } | 756 | } |
| 716 | 757 | ||
| 717 | static struct platform_driver omap_rtc_driver = { | 758 | static struct platform_driver omap_rtc_driver = { |
| 759 | .probe = omap_rtc_probe, | ||
| 718 | .remove = __exit_p(omap_rtc_remove), | 760 | .remove = __exit_p(omap_rtc_remove), |
| 719 | .shutdown = omap_rtc_shutdown, | 761 | .shutdown = omap_rtc_shutdown, |
| 720 | .driver = { | 762 | .driver = { |
| @@ -725,7 +767,7 @@ static struct platform_driver omap_rtc_driver = { | |||
| 725 | .id_table = omap_rtc_id_table, | 767 | .id_table = omap_rtc_id_table, |
| 726 | }; | 768 | }; |
| 727 | 769 | ||
| 728 | module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe); | 770 | module_platform_driver(omap_rtc_driver); |
| 729 | 771 | ||
| 730 | MODULE_ALIAS("platform:omap_rtc"); | 772 | MODULE_ALIAS("platform:omap_rtc"); |
| 731 | MODULE_AUTHOR("George G. Davis (and others)"); | 773 | MODULE_AUTHOR("George G. Davis (and others)"); |
diff --git a/drivers/rtc/rtc-opal.c b/drivers/rtc/rtc-opal.c index 95f652165fe9..7061dcae2b09 100644 --- a/drivers/rtc/rtc-opal.c +++ b/drivers/rtc/rtc-opal.c | |||
| @@ -16,8 +16,9 @@ | |||
| 16 | * along with this program. | 16 | * along with this program. |
| 17 | */ | 17 | */ |
| 18 | 18 | ||
| 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 20 | |||
| 19 | #define DRVNAME "rtc-opal" | 21 | #define DRVNAME "rtc-opal" |
| 20 | #define pr_fmt(fmt) DRVNAME ": " fmt | ||
| 21 | 22 | ||
| 22 | #include <linux/module.h> | 23 | #include <linux/module.h> |
| 23 | #include <linux/err.h> | 24 | #include <linux/err.h> |
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c index 96fb32e7d6f8..0ba7e59929be 100644 --- a/drivers/rtc/rtc-pcf8563.c +++ b/drivers/rtc/rtc-pcf8563.c | |||
| @@ -246,7 +246,6 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
| 246 | static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm) | 246 | static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm) |
| 247 | { | 247 | { |
| 248 | struct pcf8563 *pcf8563 = i2c_get_clientdata(client); | 248 | struct pcf8563 *pcf8563 = i2c_get_clientdata(client); |
| 249 | int err; | ||
| 250 | unsigned char buf[9]; | 249 | unsigned char buf[9]; |
| 251 | 250 | ||
| 252 | dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, " | 251 | dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, " |
| @@ -272,12 +271,8 @@ static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
| 272 | 271 | ||
| 273 | buf[PCF8563_REG_DW] = tm->tm_wday & 0x07; | 272 | buf[PCF8563_REG_DW] = tm->tm_wday & 0x07; |
| 274 | 273 | ||
| 275 | err = pcf8563_write_block_data(client, PCF8563_REG_SC, | 274 | return pcf8563_write_block_data(client, PCF8563_REG_SC, |
| 276 | 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC); | 275 | 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC); |
| 277 | if (err) | ||
| 278 | return err; | ||
| 279 | |||
| 280 | return 0; | ||
| 281 | } | 276 | } |
| 282 | 277 | ||
| 283 | #ifdef CONFIG_RTC_INTF_DEV | 278 | #ifdef CONFIG_RTC_INTF_DEV |
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c index 4241eeab3386..76cbad7a99d3 100644 --- a/drivers/rtc/rtc-s3c.c +++ b/drivers/rtc/rtc-s3c.c | |||
| @@ -39,7 +39,6 @@ struct s3c_rtc { | |||
| 39 | void __iomem *base; | 39 | void __iomem *base; |
| 40 | struct clk *rtc_clk; | 40 | struct clk *rtc_clk; |
| 41 | struct clk *rtc_src_clk; | 41 | struct clk *rtc_src_clk; |
| 42 | bool enabled; | ||
| 43 | 42 | ||
| 44 | struct s3c_rtc_data *data; | 43 | struct s3c_rtc_data *data; |
| 45 | 44 | ||
| @@ -67,26 +66,25 @@ struct s3c_rtc_data { | |||
| 67 | void (*disable) (struct s3c_rtc *info); | 66 | void (*disable) (struct s3c_rtc *info); |
| 68 | }; | 67 | }; |
| 69 | 68 | ||
| 70 | static void s3c_rtc_alarm_clk_enable(struct s3c_rtc *info, bool enable) | 69 | static void s3c_rtc_enable_clk(struct s3c_rtc *info) |
| 71 | { | 70 | { |
| 72 | unsigned long irq_flags; | 71 | unsigned long irq_flags; |
| 73 | 72 | ||
| 74 | spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); | 73 | spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); |
| 75 | if (enable) { | 74 | clk_enable(info->rtc_clk); |
| 76 | if (!info->enabled) { | 75 | if (info->data->needs_src_clk) |
| 77 | clk_enable(info->rtc_clk); | 76 | clk_enable(info->rtc_src_clk); |
| 78 | if (info->data->needs_src_clk) | 77 | spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); |
| 79 | clk_enable(info->rtc_src_clk); | 78 | } |
| 80 | info->enabled = true; | 79 | |
| 81 | } | 80 | static void s3c_rtc_disable_clk(struct s3c_rtc *info) |
| 82 | } else { | 81 | { |
| 83 | if (info->enabled) { | 82 | unsigned long irq_flags; |
| 84 | if (info->data->needs_src_clk) | 83 | |
| 85 | clk_disable(info->rtc_src_clk); | 84 | spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); |
| 86 | clk_disable(info->rtc_clk); | 85 | if (info->data->needs_src_clk) |
| 87 | info->enabled = false; | 86 | clk_disable(info->rtc_src_clk); |
| 88 | } | 87 | clk_disable(info->rtc_clk); |
| 89 | } | ||
| 90 | spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); | 88 | spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); |
| 91 | } | 89 | } |
| 92 | 90 | ||
| @@ -119,20 +117,16 @@ static int s3c_rtc_setaie(struct device *dev, unsigned int enabled) | |||
| 119 | 117 | ||
| 120 | dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled); | 118 | dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled); |
| 121 | 119 | ||
| 122 | clk_enable(info->rtc_clk); | 120 | s3c_rtc_enable_clk(info); |
| 123 | if (info->data->needs_src_clk) | 121 | |
| 124 | clk_enable(info->rtc_src_clk); | ||
| 125 | tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; | 122 | tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; |
| 126 | 123 | ||
| 127 | if (enabled) | 124 | if (enabled) |
| 128 | tmp |= S3C2410_RTCALM_ALMEN; | 125 | tmp |= S3C2410_RTCALM_ALMEN; |
| 129 | 126 | ||
| 130 | writeb(tmp, info->base + S3C2410_RTCALM); | 127 | writeb(tmp, info->base + S3C2410_RTCALM); |
| 131 | if (info->data->needs_src_clk) | ||
| 132 | clk_disable(info->rtc_src_clk); | ||
| 133 | clk_disable(info->rtc_clk); | ||
| 134 | 128 | ||
| 135 | s3c_rtc_alarm_clk_enable(info, enabled); | 129 | s3c_rtc_disable_clk(info); |
| 136 | 130 | ||
| 137 | return 0; | 131 | return 0; |
| 138 | } | 132 | } |
| @@ -143,18 +137,12 @@ static int s3c_rtc_setfreq(struct s3c_rtc *info, int freq) | |||
| 143 | if (!is_power_of_2(freq)) | 137 | if (!is_power_of_2(freq)) |
| 144 | return -EINVAL; | 138 | return -EINVAL; |
| 145 | 139 | ||
| 146 | clk_enable(info->rtc_clk); | ||
| 147 | if (info->data->needs_src_clk) | ||
| 148 | clk_enable(info->rtc_src_clk); | ||
| 149 | spin_lock_irq(&info->pie_lock); | 140 | spin_lock_irq(&info->pie_lock); |
| 150 | 141 | ||
| 151 | if (info->data->set_freq) | 142 | if (info->data->set_freq) |
| 152 | info->data->set_freq(info, freq); | 143 | info->data->set_freq(info, freq); |
| 153 | 144 | ||
| 154 | spin_unlock_irq(&info->pie_lock); | 145 | spin_unlock_irq(&info->pie_lock); |
| 155 | if (info->data->needs_src_clk) | ||
| 156 | clk_disable(info->rtc_src_clk); | ||
| 157 | clk_disable(info->rtc_clk); | ||
| 158 | 146 | ||
| 159 | return 0; | 147 | return 0; |
| 160 | } | 148 | } |
| @@ -165,9 +153,7 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) | |||
| 165 | struct s3c_rtc *info = dev_get_drvdata(dev); | 153 | struct s3c_rtc *info = dev_get_drvdata(dev); |
| 166 | unsigned int have_retried = 0; | 154 | unsigned int have_retried = 0; |
| 167 | 155 | ||
| 168 | clk_enable(info->rtc_clk); | 156 | s3c_rtc_enable_clk(info); |
| 169 | if (info->data->needs_src_clk) | ||
| 170 | clk_enable(info->rtc_src_clk); | ||
| 171 | 157 | ||
| 172 | retry_get_time: | 158 | retry_get_time: |
| 173 | rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN); | 159 | rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN); |
| @@ -194,6 +180,8 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) | |||
| 194 | rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); | 180 | rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); |
| 195 | rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); | 181 | rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); |
| 196 | 182 | ||
| 183 | s3c_rtc_disable_clk(info); | ||
| 184 | |||
| 197 | rtc_tm->tm_year += 100; | 185 | rtc_tm->tm_year += 100; |
| 198 | 186 | ||
| 199 | dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", | 187 | dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", |
| @@ -202,10 +190,6 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) | |||
| 202 | 190 | ||
| 203 | rtc_tm->tm_mon -= 1; | 191 | rtc_tm->tm_mon -= 1; |
| 204 | 192 | ||
| 205 | if (info->data->needs_src_clk) | ||
| 206 | clk_disable(info->rtc_src_clk); | ||
| 207 | clk_disable(info->rtc_clk); | ||
| 208 | |||
| 209 | return rtc_valid_tm(rtc_tm); | 193 | return rtc_valid_tm(rtc_tm); |
| 210 | } | 194 | } |
| 211 | 195 | ||
| @@ -225,9 +209,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm) | |||
| 225 | return -EINVAL; | 209 | return -EINVAL; |
| 226 | } | 210 | } |
| 227 | 211 | ||
| 228 | clk_enable(info->rtc_clk); | 212 | s3c_rtc_enable_clk(info); |
| 229 | if (info->data->needs_src_clk) | ||
| 230 | clk_enable(info->rtc_src_clk); | ||
| 231 | 213 | ||
| 232 | writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC); | 214 | writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC); |
| 233 | writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN); | 215 | writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN); |
| @@ -236,9 +218,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm) | |||
| 236 | writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON); | 218 | writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON); |
| 237 | writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR); | 219 | writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR); |
| 238 | 220 | ||
| 239 | if (info->data->needs_src_clk) | 221 | s3c_rtc_disable_clk(info); |
| 240 | clk_disable(info->rtc_src_clk); | ||
| 241 | clk_disable(info->rtc_clk); | ||
| 242 | 222 | ||
| 243 | return 0; | 223 | return 0; |
| 244 | } | 224 | } |
| @@ -249,9 +229,7 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 249 | struct rtc_time *alm_tm = &alrm->time; | 229 | struct rtc_time *alm_tm = &alrm->time; |
| 250 | unsigned int alm_en; | 230 | unsigned int alm_en; |
| 251 | 231 | ||
| 252 | clk_enable(info->rtc_clk); | 232 | s3c_rtc_enable_clk(info); |
| 253 | if (info->data->needs_src_clk) | ||
| 254 | clk_enable(info->rtc_src_clk); | ||
| 255 | 233 | ||
| 256 | alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC); | 234 | alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC); |
| 257 | alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN); | 235 | alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN); |
| @@ -262,6 +240,8 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 262 | 240 | ||
| 263 | alm_en = readb(info->base + S3C2410_RTCALM); | 241 | alm_en = readb(info->base + S3C2410_RTCALM); |
| 264 | 242 | ||
| 243 | s3c_rtc_disable_clk(info); | ||
| 244 | |||
| 265 | alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; | 245 | alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; |
| 266 | 246 | ||
| 267 | dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n", | 247 | dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n", |
| @@ -269,9 +249,7 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 269 | 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, | 249 | 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, |
| 270 | alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); | 250 | alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); |
| 271 | 251 | ||
| 272 | |||
| 273 | /* decode the alarm enable field */ | 252 | /* decode the alarm enable field */ |
| 274 | |||
| 275 | if (alm_en & S3C2410_RTCALM_SECEN) | 253 | if (alm_en & S3C2410_RTCALM_SECEN) |
| 276 | alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); | 254 | alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); |
| 277 | else | 255 | else |
| @@ -304,10 +282,6 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 304 | else | 282 | else |
| 305 | alm_tm->tm_year = -1; | 283 | alm_tm->tm_year = -1; |
| 306 | 284 | ||
| 307 | if (info->data->needs_src_clk) | ||
| 308 | clk_disable(info->rtc_src_clk); | ||
| 309 | clk_disable(info->rtc_clk); | ||
| 310 | |||
| 311 | return 0; | 285 | return 0; |
| 312 | } | 286 | } |
| 313 | 287 | ||
| @@ -317,15 +291,13 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 317 | struct rtc_time *tm = &alrm->time; | 291 | struct rtc_time *tm = &alrm->time; |
| 318 | unsigned int alrm_en; | 292 | unsigned int alrm_en; |
| 319 | 293 | ||
| 320 | clk_enable(info->rtc_clk); | ||
| 321 | if (info->data->needs_src_clk) | ||
| 322 | clk_enable(info->rtc_src_clk); | ||
| 323 | |||
| 324 | dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", | 294 | dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", |
| 325 | alrm->enabled, | 295 | alrm->enabled, |
| 326 | 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, | 296 | 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, |
| 327 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 297 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 328 | 298 | ||
| 299 | s3c_rtc_enable_clk(info); | ||
| 300 | |||
| 329 | alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; | 301 | alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; |
| 330 | writeb(0x00, info->base + S3C2410_RTCALM); | 302 | writeb(0x00, info->base + S3C2410_RTCALM); |
| 331 | 303 | ||
| @@ -348,11 +320,9 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 348 | 320 | ||
| 349 | writeb(alrm_en, info->base + S3C2410_RTCALM); | 321 | writeb(alrm_en, info->base + S3C2410_RTCALM); |
| 350 | 322 | ||
| 351 | s3c_rtc_setaie(dev, alrm->enabled); | 323 | s3c_rtc_disable_clk(info); |
| 352 | 324 | ||
| 353 | if (info->data->needs_src_clk) | 325 | s3c_rtc_setaie(dev, alrm->enabled); |
| 354 | clk_disable(info->rtc_src_clk); | ||
| 355 | clk_disable(info->rtc_clk); | ||
| 356 | 326 | ||
| 357 | return 0; | 327 | return 0; |
| 358 | } | 328 | } |
| @@ -361,16 +331,12 @@ static int s3c_rtc_proc(struct device *dev, struct seq_file *seq) | |||
| 361 | { | 331 | { |
| 362 | struct s3c_rtc *info = dev_get_drvdata(dev); | 332 | struct s3c_rtc *info = dev_get_drvdata(dev); |
| 363 | 333 | ||
| 364 | clk_enable(info->rtc_clk); | 334 | s3c_rtc_enable_clk(info); |
| 365 | if (info->data->needs_src_clk) | ||
| 366 | clk_enable(info->rtc_src_clk); | ||
| 367 | 335 | ||
| 368 | if (info->data->enable_tick) | 336 | if (info->data->enable_tick) |
| 369 | info->data->enable_tick(info, seq); | 337 | info->data->enable_tick(info, seq); |
| 370 | 338 | ||
| 371 | if (info->data->needs_src_clk) | 339 | s3c_rtc_disable_clk(info); |
| 372 | clk_disable(info->rtc_src_clk); | ||
| 373 | clk_disable(info->rtc_clk); | ||
| 374 | 340 | ||
| 375 | return 0; | 341 | return 0; |
| 376 | } | 342 | } |
| @@ -388,10 +354,6 @@ static void s3c24xx_rtc_enable(struct s3c_rtc *info) | |||
| 388 | { | 354 | { |
| 389 | unsigned int con, tmp; | 355 | unsigned int con, tmp; |
| 390 | 356 | ||
| 391 | clk_enable(info->rtc_clk); | ||
| 392 | if (info->data->needs_src_clk) | ||
| 393 | clk_enable(info->rtc_src_clk); | ||
| 394 | |||
| 395 | con = readw(info->base + S3C2410_RTCCON); | 357 | con = readw(info->base + S3C2410_RTCCON); |
| 396 | /* re-enable the device, and check it is ok */ | 358 | /* re-enable the device, and check it is ok */ |
| 397 | if ((con & S3C2410_RTCCON_RTCEN) == 0) { | 359 | if ((con & S3C2410_RTCCON_RTCEN) == 0) { |
| @@ -417,20 +379,12 @@ static void s3c24xx_rtc_enable(struct s3c_rtc *info) | |||
| 417 | writew(tmp & ~S3C2410_RTCCON_CLKRST, | 379 | writew(tmp & ~S3C2410_RTCCON_CLKRST, |
| 418 | info->base + S3C2410_RTCCON); | 380 | info->base + S3C2410_RTCCON); |
| 419 | } | 381 | } |
| 420 | |||
| 421 | if (info->data->needs_src_clk) | ||
| 422 | clk_disable(info->rtc_src_clk); | ||
| 423 | clk_disable(info->rtc_clk); | ||
| 424 | } | 382 | } |
| 425 | 383 | ||
| 426 | static void s3c24xx_rtc_disable(struct s3c_rtc *info) | 384 | static void s3c24xx_rtc_disable(struct s3c_rtc *info) |
| 427 | { | 385 | { |
| 428 | unsigned int con; | 386 | unsigned int con; |
| 429 | 387 | ||
| 430 | clk_enable(info->rtc_clk); | ||
| 431 | if (info->data->needs_src_clk) | ||
| 432 | clk_enable(info->rtc_src_clk); | ||
| 433 | |||
| 434 | con = readw(info->base + S3C2410_RTCCON); | 388 | con = readw(info->base + S3C2410_RTCCON); |
| 435 | con &= ~S3C2410_RTCCON_RTCEN; | 389 | con &= ~S3C2410_RTCCON_RTCEN; |
| 436 | writew(con, info->base + S3C2410_RTCCON); | 390 | writew(con, info->base + S3C2410_RTCCON); |
| @@ -438,28 +392,16 @@ static void s3c24xx_rtc_disable(struct s3c_rtc *info) | |||
| 438 | con = readb(info->base + S3C2410_TICNT); | 392 | con = readb(info->base + S3C2410_TICNT); |
| 439 | con &= ~S3C2410_TICNT_ENABLE; | 393 | con &= ~S3C2410_TICNT_ENABLE; |
| 440 | writeb(con, info->base + S3C2410_TICNT); | 394 | writeb(con, info->base + S3C2410_TICNT); |
| 441 | |||
| 442 | if (info->data->needs_src_clk) | ||
| 443 | clk_disable(info->rtc_src_clk); | ||
| 444 | clk_disable(info->rtc_clk); | ||
| 445 | } | 395 | } |
| 446 | 396 | ||
| 447 | static void s3c6410_rtc_disable(struct s3c_rtc *info) | 397 | static void s3c6410_rtc_disable(struct s3c_rtc *info) |
| 448 | { | 398 | { |
| 449 | unsigned int con; | 399 | unsigned int con; |
| 450 | 400 | ||
| 451 | clk_enable(info->rtc_clk); | ||
| 452 | if (info->data->needs_src_clk) | ||
| 453 | clk_enable(info->rtc_src_clk); | ||
| 454 | |||
| 455 | con = readw(info->base + S3C2410_RTCCON); | 401 | con = readw(info->base + S3C2410_RTCCON); |
| 456 | con &= ~S3C64XX_RTCCON_TICEN; | 402 | con &= ~S3C64XX_RTCCON_TICEN; |
| 457 | con &= ~S3C2410_RTCCON_RTCEN; | 403 | con &= ~S3C2410_RTCCON_RTCEN; |
| 458 | writew(con, info->base + S3C2410_RTCCON); | 404 | writew(con, info->base + S3C2410_RTCCON); |
| 459 | |||
| 460 | if (info->data->needs_src_clk) | ||
| 461 | clk_disable(info->rtc_src_clk); | ||
| 462 | clk_disable(info->rtc_clk); | ||
| 463 | } | 405 | } |
| 464 | 406 | ||
| 465 | static int s3c_rtc_remove(struct platform_device *pdev) | 407 | static int s3c_rtc_remove(struct platform_device *pdev) |
| @@ -554,6 +496,20 @@ static int s3c_rtc_probe(struct platform_device *pdev) | |||
| 554 | 496 | ||
| 555 | device_init_wakeup(&pdev->dev, 1); | 497 | device_init_wakeup(&pdev->dev, 1); |
| 556 | 498 | ||
| 499 | /* Check RTC Time */ | ||
| 500 | if (s3c_rtc_gettime(&pdev->dev, &rtc_tm)) { | ||
| 501 | rtc_tm.tm_year = 100; | ||
| 502 | rtc_tm.tm_mon = 0; | ||
| 503 | rtc_tm.tm_mday = 1; | ||
| 504 | rtc_tm.tm_hour = 0; | ||
| 505 | rtc_tm.tm_min = 0; | ||
| 506 | rtc_tm.tm_sec = 0; | ||
| 507 | |||
| 508 | s3c_rtc_settime(&pdev->dev, &rtc_tm); | ||
| 509 | |||
| 510 | dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n"); | ||
| 511 | } | ||
| 512 | |||
| 557 | /* register RTC and exit */ | 513 | /* register RTC and exit */ |
| 558 | info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops, | 514 | info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops, |
| 559 | THIS_MODULE); | 515 | THIS_MODULE); |
| @@ -577,36 +533,21 @@ static int s3c_rtc_probe(struct platform_device *pdev) | |||
| 577 | goto err_nortc; | 533 | goto err_nortc; |
| 578 | } | 534 | } |
| 579 | 535 | ||
| 580 | /* Check RTC Time */ | ||
| 581 | s3c_rtc_gettime(&pdev->dev, &rtc_tm); | ||
| 582 | |||
| 583 | if (rtc_valid_tm(&rtc_tm)) { | ||
| 584 | rtc_tm.tm_year = 100; | ||
| 585 | rtc_tm.tm_mon = 0; | ||
| 586 | rtc_tm.tm_mday = 1; | ||
| 587 | rtc_tm.tm_hour = 0; | ||
| 588 | rtc_tm.tm_min = 0; | ||
| 589 | rtc_tm.tm_sec = 0; | ||
| 590 | |||
| 591 | s3c_rtc_settime(&pdev->dev, &rtc_tm); | ||
| 592 | |||
| 593 | dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n"); | ||
| 594 | } | ||
| 595 | |||
| 596 | if (info->data->select_tick_clk) | 536 | if (info->data->select_tick_clk) |
| 597 | info->data->select_tick_clk(info); | 537 | info->data->select_tick_clk(info); |
| 598 | 538 | ||
| 599 | s3c_rtc_setfreq(info, 1); | 539 | s3c_rtc_setfreq(info, 1); |
| 600 | 540 | ||
| 601 | if (info->data->needs_src_clk) | 541 | s3c_rtc_disable_clk(info); |
| 602 | clk_disable(info->rtc_src_clk); | ||
| 603 | clk_disable(info->rtc_clk); | ||
| 604 | 542 | ||
| 605 | return 0; | 543 | return 0; |
| 606 | 544 | ||
| 607 | err_nortc: | 545 | err_nortc: |
| 608 | if (info->data->disable) | 546 | if (info->data->disable) |
| 609 | info->data->disable(info); | 547 | info->data->disable(info); |
| 548 | |||
| 549 | if (info->data->needs_src_clk) | ||
| 550 | clk_disable_unprepare(info->rtc_src_clk); | ||
| 610 | clk_disable_unprepare(info->rtc_clk); | 551 | clk_disable_unprepare(info->rtc_clk); |
| 611 | 552 | ||
| 612 | return ret; | 553 | return ret; |
| @@ -618,9 +559,7 @@ static int s3c_rtc_suspend(struct device *dev) | |||
| 618 | { | 559 | { |
| 619 | struct s3c_rtc *info = dev_get_drvdata(dev); | 560 | struct s3c_rtc *info = dev_get_drvdata(dev); |
| 620 | 561 | ||
| 621 | clk_enable(info->rtc_clk); | 562 | s3c_rtc_enable_clk(info); |
| 622 | if (info->data->needs_src_clk) | ||
| 623 | clk_enable(info->rtc_src_clk); | ||
| 624 | 563 | ||
| 625 | /* save TICNT for anyone using periodic interrupts */ | 564 | /* save TICNT for anyone using periodic interrupts */ |
| 626 | if (info->data->save_tick_cnt) | 565 | if (info->data->save_tick_cnt) |
| @@ -636,10 +575,6 @@ static int s3c_rtc_suspend(struct device *dev) | |||
| 636 | dev_err(dev, "enable_irq_wake failed\n"); | 575 | dev_err(dev, "enable_irq_wake failed\n"); |
| 637 | } | 576 | } |
| 638 | 577 | ||
| 639 | if (info->data->needs_src_clk) | ||
| 640 | clk_disable(info->rtc_src_clk); | ||
| 641 | clk_disable(info->rtc_clk); | ||
| 642 | |||
| 643 | return 0; | 578 | return 0; |
| 644 | } | 579 | } |
| 645 | 580 | ||
| @@ -647,25 +582,19 @@ static int s3c_rtc_resume(struct device *dev) | |||
| 647 | { | 582 | { |
| 648 | struct s3c_rtc *info = dev_get_drvdata(dev); | 583 | struct s3c_rtc *info = dev_get_drvdata(dev); |
| 649 | 584 | ||
| 650 | clk_enable(info->rtc_clk); | ||
| 651 | if (info->data->needs_src_clk) | ||
| 652 | clk_enable(info->rtc_src_clk); | ||
| 653 | |||
| 654 | if (info->data->enable) | 585 | if (info->data->enable) |
| 655 | info->data->enable(info); | 586 | info->data->enable(info); |
| 656 | 587 | ||
| 657 | if (info->data->restore_tick_cnt) | 588 | if (info->data->restore_tick_cnt) |
| 658 | info->data->restore_tick_cnt(info); | 589 | info->data->restore_tick_cnt(info); |
| 659 | 590 | ||
| 591 | s3c_rtc_disable_clk(info); | ||
| 592 | |||
| 660 | if (device_may_wakeup(dev) && info->wake_en) { | 593 | if (device_may_wakeup(dev) && info->wake_en) { |
| 661 | disable_irq_wake(info->irq_alarm); | 594 | disable_irq_wake(info->irq_alarm); |
| 662 | info->wake_en = false; | 595 | info->wake_en = false; |
| 663 | } | 596 | } |
| 664 | 597 | ||
| 665 | if (info->data->needs_src_clk) | ||
| 666 | clk_disable(info->rtc_src_clk); | ||
| 667 | clk_disable(info->rtc_clk); | ||
| 668 | |||
| 669 | return 0; | 598 | return 0; |
| 670 | } | 599 | } |
| 671 | #endif | 600 | #endif |
| @@ -673,29 +602,13 @@ static SIMPLE_DEV_PM_OPS(s3c_rtc_pm_ops, s3c_rtc_suspend, s3c_rtc_resume); | |||
| 673 | 602 | ||
| 674 | static void s3c24xx_rtc_irq(struct s3c_rtc *info, int mask) | 603 | static void s3c24xx_rtc_irq(struct s3c_rtc *info, int mask) |
| 675 | { | 604 | { |
| 676 | clk_enable(info->rtc_clk); | ||
| 677 | if (info->data->needs_src_clk) | ||
| 678 | clk_enable(info->rtc_src_clk); | ||
| 679 | rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); | 605 | rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); |
| 680 | if (info->data->needs_src_clk) | ||
| 681 | clk_disable(info->rtc_src_clk); | ||
| 682 | clk_disable(info->rtc_clk); | ||
| 683 | |||
| 684 | s3c_rtc_alarm_clk_enable(info, false); | ||
| 685 | } | 606 | } |
| 686 | 607 | ||
| 687 | static void s3c6410_rtc_irq(struct s3c_rtc *info, int mask) | 608 | static void s3c6410_rtc_irq(struct s3c_rtc *info, int mask) |
| 688 | { | 609 | { |
| 689 | clk_enable(info->rtc_clk); | ||
| 690 | if (info->data->needs_src_clk) | ||
| 691 | clk_enable(info->rtc_src_clk); | ||
| 692 | rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); | 610 | rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); |
| 693 | writeb(mask, info->base + S3C2410_INTP); | 611 | writeb(mask, info->base + S3C2410_INTP); |
| 694 | if (info->data->needs_src_clk) | ||
| 695 | clk_disable(info->rtc_src_clk); | ||
| 696 | clk_disable(info->rtc_clk); | ||
| 697 | |||
| 698 | s3c_rtc_alarm_clk_enable(info, false); | ||
| 699 | } | 612 | } |
| 700 | 613 | ||
| 701 | static void s3c2410_rtc_setfreq(struct s3c_rtc *info, int freq) | 614 | static void s3c2410_rtc_setfreq(struct s3c_rtc *info, int freq) |
| @@ -849,6 +762,7 @@ static struct s3c_rtc_data const s3c2443_rtc_data = { | |||
| 849 | 762 | ||
| 850 | static struct s3c_rtc_data const s3c6410_rtc_data = { | 763 | static struct s3c_rtc_data const s3c6410_rtc_data = { |
| 851 | .max_user_freq = 32768, | 764 | .max_user_freq = 32768, |
| 765 | .needs_src_clk = true, | ||
| 852 | .irq_handler = s3c6410_rtc_irq, | 766 | .irq_handler = s3c6410_rtc_irq, |
| 853 | .set_freq = s3c6410_rtc_setfreq, | 767 | .set_freq = s3c6410_rtc_setfreq, |
| 854 | .enable_tick = s3c6410_rtc_enable_tick, | 768 | .enable_tick = s3c6410_rtc_enable_tick, |
diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c index 89ac1d5083c6..8c70d785ba73 100644 --- a/drivers/rtc/rtc-s5m.c +++ b/drivers/rtc/rtc-s5m.c | |||
| @@ -15,6 +15,8 @@ | |||
| 15 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 19 | |||
| 18 | #include <linux/module.h> | 20 | #include <linux/module.h> |
| 19 | #include <linux/i2c.h> | 21 | #include <linux/i2c.h> |
| 20 | #include <linux/bcd.h> | 22 | #include <linux/bcd.h> |
| @@ -48,8 +50,6 @@ struct s5m_rtc_reg_config { | |||
| 48 | unsigned int alarm0; | 50 | unsigned int alarm0; |
| 49 | /* First register for alarm 1, seconds */ | 51 | /* First register for alarm 1, seconds */ |
| 50 | unsigned int alarm1; | 52 | unsigned int alarm1; |
| 51 | /* SMPL/WTSR register */ | ||
| 52 | unsigned int smpl_wtsr; | ||
| 53 | /* | 53 | /* |
| 54 | * Register for update flag (UDR). Typically setting UDR field to 1 | 54 | * Register for update flag (UDR). Typically setting UDR field to 1 |
| 55 | * will enable update of time or alarm register. Then it will be | 55 | * will enable update of time or alarm register. Then it will be |
| @@ -67,7 +67,6 @@ static const struct s5m_rtc_reg_config s5m_rtc_regs = { | |||
| 67 | .ctrl = S5M_ALARM1_CONF, | 67 | .ctrl = S5M_ALARM1_CONF, |
| 68 | .alarm0 = S5M_ALARM0_SEC, | 68 | .alarm0 = S5M_ALARM0_SEC, |
| 69 | .alarm1 = S5M_ALARM1_SEC, | 69 | .alarm1 = S5M_ALARM1_SEC, |
| 70 | .smpl_wtsr = S5M_WTSR_SMPL_CNTL, | ||
| 71 | .rtc_udr_update = S5M_RTC_UDR_CON, | 70 | .rtc_udr_update = S5M_RTC_UDR_CON, |
| 72 | .rtc_udr_mask = S5M_RTC_UDR_MASK, | 71 | .rtc_udr_mask = S5M_RTC_UDR_MASK, |
| 73 | }; | 72 | }; |
| @@ -82,7 +81,6 @@ static const struct s5m_rtc_reg_config s2mps_rtc_regs = { | |||
| 82 | .ctrl = S2MPS_RTC_CTRL, | 81 | .ctrl = S2MPS_RTC_CTRL, |
| 83 | .alarm0 = S2MPS_ALARM0_SEC, | 82 | .alarm0 = S2MPS_ALARM0_SEC, |
| 84 | .alarm1 = S2MPS_ALARM1_SEC, | 83 | .alarm1 = S2MPS_ALARM1_SEC, |
| 85 | .smpl_wtsr = S2MPS_WTSR_SMPL_CNTL, | ||
| 86 | .rtc_udr_update = S2MPS_RTC_UDR_CON, | 84 | .rtc_udr_update = S2MPS_RTC_UDR_CON, |
| 87 | .rtc_udr_mask = S2MPS_RTC_WUDR_MASK, | 85 | .rtc_udr_mask = S2MPS_RTC_WUDR_MASK, |
| 88 | }; | 86 | }; |
| @@ -94,9 +92,8 @@ struct s5m_rtc_info { | |||
| 94 | struct regmap *regmap; | 92 | struct regmap *regmap; |
| 95 | struct rtc_device *rtc_dev; | 93 | struct rtc_device *rtc_dev; |
| 96 | int irq; | 94 | int irq; |
| 97 | int device_type; | 95 | enum sec_device_type device_type; |
| 98 | int rtc_24hr_mode; | 96 | int rtc_24hr_mode; |
| 99 | bool wtsr_smpl; | ||
| 100 | const struct s5m_rtc_reg_config *regs; | 97 | const struct s5m_rtc_reg_config *regs; |
| 101 | }; | 98 | }; |
| 102 | 99 | ||
| @@ -151,7 +148,7 @@ static int s5m8767_tm_to_data(struct rtc_time *tm, u8 *data) | |||
| 151 | data[RTC_YEAR1] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; | 148 | data[RTC_YEAR1] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; |
| 152 | 149 | ||
| 153 | if (tm->tm_year < 100) { | 150 | if (tm->tm_year < 100) { |
| 154 | pr_err("s5m8767 RTC cannot handle the year %d.\n", | 151 | pr_err("RTC cannot handle the year %d\n", |
| 155 | 1900 + tm->tm_year); | 152 | 1900 + tm->tm_year); |
| 156 | return -EINVAL; | 153 | return -EINVAL; |
| 157 | } else { | 154 | } else { |
| @@ -192,6 +189,7 @@ static inline int s5m_check_peding_alarm_interrupt(struct s5m_rtc_info *info, | |||
| 192 | val &= S5M_ALARM0_STATUS; | 189 | val &= S5M_ALARM0_STATUS; |
| 193 | break; | 190 | break; |
| 194 | case S2MPS14X: | 191 | case S2MPS14X: |
| 192 | case S2MPS13X: | ||
| 195 | ret = regmap_read(info->s5m87xx->regmap_pmic, S2MPS14_REG_ST2, | 193 | ret = regmap_read(info->s5m87xx->regmap_pmic, S2MPS14_REG_ST2, |
| 196 | &val); | 194 | &val); |
| 197 | val &= S2MPS_ALARM0_STATUS; | 195 | val &= S2MPS_ALARM0_STATUS; |
| @@ -257,6 +255,9 @@ static inline int s5m8767_rtc_set_alarm_reg(struct s5m_rtc_info *info) | |||
| 257 | case S2MPS14X: | 255 | case S2MPS14X: |
| 258 | data |= S2MPS_RTC_RUDR_MASK; | 256 | data |= S2MPS_RTC_RUDR_MASK; |
| 259 | break; | 257 | break; |
| 258 | case S2MPS13X: | ||
| 259 | data |= S2MPS13_RTC_AUDR_MASK; | ||
| 260 | break; | ||
| 260 | default: | 261 | default: |
| 261 | return -EINVAL; | 262 | return -EINVAL; |
| 262 | } | 263 | } |
| @@ -270,6 +271,11 @@ static inline int s5m8767_rtc_set_alarm_reg(struct s5m_rtc_info *info) | |||
| 270 | 271 | ||
| 271 | ret = s5m8767_wait_for_udr_update(info); | 272 | ret = s5m8767_wait_for_udr_update(info); |
| 272 | 273 | ||
| 274 | /* On S2MPS13 the AUDR is not auto-cleared */ | ||
| 275 | if (info->device_type == S2MPS13X) | ||
| 276 | regmap_update_bits(info->regmap, info->regs->rtc_udr_update, | ||
| 277 | S2MPS13_RTC_AUDR_MASK, 0); | ||
| 278 | |||
| 273 | return ret; | 279 | return ret; |
| 274 | } | 280 | } |
| 275 | 281 | ||
| @@ -311,7 +317,7 @@ static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 311 | u8 data[info->regs->regs_count]; | 317 | u8 data[info->regs->regs_count]; |
| 312 | int ret; | 318 | int ret; |
| 313 | 319 | ||
| 314 | if (info->device_type == S2MPS14X) { | 320 | if (info->device_type == S2MPS14X || info->device_type == S2MPS13X) { |
| 315 | ret = regmap_update_bits(info->regmap, | 321 | ret = regmap_update_bits(info->regmap, |
| 316 | info->regs->rtc_udr_update, | 322 | info->regs->rtc_udr_update, |
| 317 | S2MPS_RTC_RUDR_MASK, S2MPS_RTC_RUDR_MASK); | 323 | S2MPS_RTC_RUDR_MASK, S2MPS_RTC_RUDR_MASK); |
| @@ -334,6 +340,7 @@ static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 334 | 340 | ||
| 335 | case S5M8767X: | 341 | case S5M8767X: |
| 336 | case S2MPS14X: | 342 | case S2MPS14X: |
| 343 | case S2MPS13X: | ||
| 337 | s5m8767_data_to_tm(data, tm, info->rtc_24hr_mode); | 344 | s5m8767_data_to_tm(data, tm, info->rtc_24hr_mode); |
| 338 | break; | 345 | break; |
| 339 | 346 | ||
| @@ -360,6 +367,7 @@ static int s5m_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
| 360 | break; | 367 | break; |
| 361 | case S5M8767X: | 368 | case S5M8767X: |
| 362 | case S2MPS14X: | 369 | case S2MPS14X: |
| 370 | case S2MPS13X: | ||
| 363 | ret = s5m8767_tm_to_data(tm, data); | 371 | ret = s5m8767_tm_to_data(tm, data); |
| 364 | break; | 372 | break; |
| 365 | default: | 373 | default: |
| @@ -407,6 +415,7 @@ static int s5m_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 407 | 415 | ||
| 408 | case S5M8767X: | 416 | case S5M8767X: |
| 409 | case S2MPS14X: | 417 | case S2MPS14X: |
| 418 | case S2MPS13X: | ||
| 410 | s5m8767_data_to_tm(data, &alrm->time, info->rtc_24hr_mode); | 419 | s5m8767_data_to_tm(data, &alrm->time, info->rtc_24hr_mode); |
| 411 | alrm->enabled = 0; | 420 | alrm->enabled = 0; |
| 412 | for (i = 0; i < info->regs->regs_count; i++) { | 421 | for (i = 0; i < info->regs->regs_count; i++) { |
| @@ -455,6 +464,7 @@ static int s5m_rtc_stop_alarm(struct s5m_rtc_info *info) | |||
| 455 | 464 | ||
| 456 | case S5M8767X: | 465 | case S5M8767X: |
| 457 | case S2MPS14X: | 466 | case S2MPS14X: |
| 467 | case S2MPS13X: | ||
| 458 | for (i = 0; i < info->regs->regs_count; i++) | 468 | for (i = 0; i < info->regs->regs_count; i++) |
| 459 | data[i] &= ~ALARM_ENABLE_MASK; | 469 | data[i] &= ~ALARM_ENABLE_MASK; |
| 460 | 470 | ||
| @@ -499,6 +509,7 @@ static int s5m_rtc_start_alarm(struct s5m_rtc_info *info) | |||
| 499 | 509 | ||
| 500 | case S5M8767X: | 510 | case S5M8767X: |
| 501 | case S2MPS14X: | 511 | case S2MPS14X: |
| 512 | case S2MPS13X: | ||
| 502 | data[RTC_SEC] |= ALARM_ENABLE_MASK; | 513 | data[RTC_SEC] |= ALARM_ENABLE_MASK; |
| 503 | data[RTC_MIN] |= ALARM_ENABLE_MASK; | 514 | data[RTC_MIN] |= ALARM_ENABLE_MASK; |
| 504 | data[RTC_HOUR] |= ALARM_ENABLE_MASK; | 515 | data[RTC_HOUR] |= ALARM_ENABLE_MASK; |
| @@ -538,6 +549,7 @@ static int s5m_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 538 | 549 | ||
| 539 | case S5M8767X: | 550 | case S5M8767X: |
| 540 | case S2MPS14X: | 551 | case S2MPS14X: |
| 552 | case S2MPS13X: | ||
| 541 | s5m8767_tm_to_data(&alrm->time, data); | 553 | s5m8767_tm_to_data(&alrm->time, data); |
| 542 | break; | 554 | break; |
| 543 | 555 | ||
| @@ -597,28 +609,6 @@ static const struct rtc_class_ops s5m_rtc_ops = { | |||
| 597 | .alarm_irq_enable = s5m_rtc_alarm_irq_enable, | 609 | .alarm_irq_enable = s5m_rtc_alarm_irq_enable, |
| 598 | }; | 610 | }; |
| 599 | 611 | ||
| 600 | static void s5m_rtc_enable_wtsr(struct s5m_rtc_info *info, bool enable) | ||
| 601 | { | ||
| 602 | int ret; | ||
| 603 | ret = regmap_update_bits(info->regmap, info->regs->smpl_wtsr, | ||
| 604 | WTSR_ENABLE_MASK, | ||
| 605 | enable ? WTSR_ENABLE_MASK : 0); | ||
| 606 | if (ret < 0) | ||
| 607 | dev_err(info->dev, "%s: fail to update WTSR reg(%d)\n", | ||
| 608 | __func__, ret); | ||
| 609 | } | ||
| 610 | |||
| 611 | static void s5m_rtc_enable_smpl(struct s5m_rtc_info *info, bool enable) | ||
| 612 | { | ||
| 613 | int ret; | ||
| 614 | ret = regmap_update_bits(info->regmap, info->regs->smpl_wtsr, | ||
| 615 | SMPL_ENABLE_MASK, | ||
| 616 | enable ? SMPL_ENABLE_MASK : 0); | ||
| 617 | if (ret < 0) | ||
| 618 | dev_err(info->dev, "%s: fail to update SMPL reg(%d)\n", | ||
| 619 | __func__, ret); | ||
| 620 | } | ||
| 621 | |||
| 622 | static int s5m8767_rtc_init_reg(struct s5m_rtc_info *info) | 612 | static int s5m8767_rtc_init_reg(struct s5m_rtc_info *info) |
| 623 | { | 613 | { |
| 624 | u8 data[2]; | 614 | u8 data[2]; |
| @@ -642,6 +632,7 @@ static int s5m8767_rtc_init_reg(struct s5m_rtc_info *info) | |||
| 642 | break; | 632 | break; |
| 643 | 633 | ||
| 644 | case S2MPS14X: | 634 | case S2MPS14X: |
| 635 | case S2MPS13X: | ||
| 645 | data[0] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT); | 636 | data[0] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT); |
| 646 | ret = regmap_write(info->regmap, info->regs->ctrl, data[0]); | 637 | ret = regmap_write(info->regmap, info->regs->ctrl, data[0]); |
| 647 | break; | 638 | break; |
| @@ -677,8 +668,9 @@ static int s5m_rtc_probe(struct platform_device *pdev) | |||
| 677 | if (!info) | 668 | if (!info) |
| 678 | return -ENOMEM; | 669 | return -ENOMEM; |
| 679 | 670 | ||
| 680 | switch (pdata->device_type) { | 671 | switch (platform_get_device_id(pdev)->driver_data) { |
| 681 | case S2MPS14X: | 672 | case S2MPS14X: |
| 673 | case S2MPS13X: | ||
| 682 | regmap_cfg = &s2mps14_rtc_regmap_config; | 674 | regmap_cfg = &s2mps14_rtc_regmap_config; |
| 683 | info->regs = &s2mps_rtc_regs; | 675 | info->regs = &s2mps_rtc_regs; |
| 684 | alarm_irq = S2MPS14_IRQ_RTCA0; | 676 | alarm_irq = S2MPS14_IRQ_RTCA0; |
| @@ -694,7 +686,9 @@ static int s5m_rtc_probe(struct platform_device *pdev) | |||
| 694 | alarm_irq = S5M8767_IRQ_RTCA1; | 686 | alarm_irq = S5M8767_IRQ_RTCA1; |
| 695 | break; | 687 | break; |
| 696 | default: | 688 | default: |
| 697 | dev_err(&pdev->dev, "Device type is not supported by RTC driver\n"); | 689 | dev_err(&pdev->dev, |
| 690 | "Device type %lu is not supported by RTC driver\n", | ||
| 691 | platform_get_device_id(pdev)->driver_data); | ||
| 698 | return -ENODEV; | 692 | return -ENODEV; |
| 699 | } | 693 | } |
| 700 | 694 | ||
| @@ -714,8 +708,7 @@ static int s5m_rtc_probe(struct platform_device *pdev) | |||
| 714 | 708 | ||
| 715 | info->dev = &pdev->dev; | 709 | info->dev = &pdev->dev; |
| 716 | info->s5m87xx = s5m87xx; | 710 | info->s5m87xx = s5m87xx; |
| 717 | info->device_type = s5m87xx->device_type; | 711 | info->device_type = platform_get_device_id(pdev)->driver_data; |
| 718 | info->wtsr_smpl = s5m87xx->wtsr_smpl; | ||
| 719 | 712 | ||
| 720 | if (s5m87xx->irq_data) { | 713 | if (s5m87xx->irq_data) { |
| 721 | info->irq = regmap_irq_get_virq(s5m87xx->irq_data, alarm_irq); | 714 | info->irq = regmap_irq_get_virq(s5m87xx->irq_data, alarm_irq); |
| @@ -731,11 +724,6 @@ static int s5m_rtc_probe(struct platform_device *pdev) | |||
| 731 | 724 | ||
| 732 | ret = s5m8767_rtc_init_reg(info); | 725 | ret = s5m8767_rtc_init_reg(info); |
| 733 | 726 | ||
| 734 | if (info->wtsr_smpl) { | ||
| 735 | s5m_rtc_enable_wtsr(info, true); | ||
| 736 | s5m_rtc_enable_smpl(info, true); | ||
| 737 | } | ||
| 738 | |||
| 739 | device_init_wakeup(&pdev->dev, 1); | 727 | device_init_wakeup(&pdev->dev, 1); |
| 740 | 728 | ||
| 741 | info->rtc_dev = devm_rtc_device_register(&pdev->dev, "s5m-rtc", | 729 | info->rtc_dev = devm_rtc_device_register(&pdev->dev, "s5m-rtc", |
| @@ -768,36 +756,10 @@ err: | |||
| 768 | return ret; | 756 | return ret; |
| 769 | } | 757 | } |
| 770 | 758 | ||
| 771 | static void s5m_rtc_shutdown(struct platform_device *pdev) | ||
| 772 | { | ||
| 773 | struct s5m_rtc_info *info = platform_get_drvdata(pdev); | ||
| 774 | int i; | ||
| 775 | unsigned int val = 0; | ||
| 776 | if (info->wtsr_smpl) { | ||
| 777 | for (i = 0; i < 3; i++) { | ||
| 778 | s5m_rtc_enable_wtsr(info, false); | ||
| 779 | regmap_read(info->regmap, info->regs->smpl_wtsr, &val); | ||
| 780 | pr_debug("%s: WTSR_SMPL reg(0x%02x)\n", __func__, val); | ||
| 781 | if (val & WTSR_ENABLE_MASK) | ||
| 782 | pr_emerg("%s: fail to disable WTSR\n", | ||
| 783 | __func__); | ||
| 784 | else { | ||
| 785 | pr_info("%s: success to disable WTSR\n", | ||
| 786 | __func__); | ||
| 787 | break; | ||
| 788 | } | ||
| 789 | } | ||
| 790 | } | ||
| 791 | /* Disable SMPL when power off */ | ||
| 792 | s5m_rtc_enable_smpl(info, false); | ||
| 793 | } | ||
| 794 | |||
| 795 | static int s5m_rtc_remove(struct platform_device *pdev) | 759 | static int s5m_rtc_remove(struct platform_device *pdev) |
| 796 | { | 760 | { |
| 797 | struct s5m_rtc_info *info = platform_get_drvdata(pdev); | 761 | struct s5m_rtc_info *info = platform_get_drvdata(pdev); |
| 798 | 762 | ||
| 799 | /* Perform also all shutdown steps when removing */ | ||
| 800 | s5m_rtc_shutdown(pdev); | ||
| 801 | i2c_unregister_device(info->i2c); | 763 | i2c_unregister_device(info->i2c); |
| 802 | 764 | ||
| 803 | return 0; | 765 | return 0; |
| @@ -831,6 +793,7 @@ static SIMPLE_DEV_PM_OPS(s5m_rtc_pm_ops, s5m_rtc_suspend, s5m_rtc_resume); | |||
| 831 | 793 | ||
| 832 | static const struct platform_device_id s5m_rtc_id[] = { | 794 | static const struct platform_device_id s5m_rtc_id[] = { |
| 833 | { "s5m-rtc", S5M8767X }, | 795 | { "s5m-rtc", S5M8767X }, |
| 796 | { "s2mps13-rtc", S2MPS13X }, | ||
| 834 | { "s2mps14-rtc", S2MPS14X }, | 797 | { "s2mps14-rtc", S2MPS14X }, |
| 835 | { }, | 798 | { }, |
| 836 | }; | 799 | }; |
| @@ -842,7 +805,6 @@ static struct platform_driver s5m_rtc_driver = { | |||
| 842 | }, | 805 | }, |
| 843 | .probe = s5m_rtc_probe, | 806 | .probe = s5m_rtc_probe, |
| 844 | .remove = s5m_rtc_remove, | 807 | .remove = s5m_rtc_remove, |
| 845 | .shutdown = s5m_rtc_shutdown, | ||
| 846 | .id_table = s5m_rtc_id, | 808 | .id_table = s5m_rtc_id, |
| 847 | }; | 809 | }; |
| 848 | 810 | ||
diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c index 2939cdcb2688..eb09eddf39b8 100644 --- a/drivers/rtc/rtc-stmp3xxx.c +++ b/drivers/rtc/rtc-stmp3xxx.c | |||
| @@ -42,6 +42,8 @@ | |||
| 42 | #define STMP3XXX_RTC_STAT 0x10 | 42 | #define STMP3XXX_RTC_STAT 0x10 |
| 43 | #define STMP3XXX_RTC_STAT_STALE_SHIFT 16 | 43 | #define STMP3XXX_RTC_STAT_STALE_SHIFT 16 |
| 44 | #define STMP3XXX_RTC_STAT_RTC_PRESENT 0x80000000 | 44 | #define STMP3XXX_RTC_STAT_RTC_PRESENT 0x80000000 |
| 45 | #define STMP3XXX_RTC_STAT_XTAL32000_PRESENT 0x10000000 | ||
| 46 | #define STMP3XXX_RTC_STAT_XTAL32768_PRESENT 0x08000000 | ||
| 45 | 47 | ||
| 46 | #define STMP3XXX_RTC_SECONDS 0x30 | 48 | #define STMP3XXX_RTC_SECONDS 0x30 |
| 47 | 49 | ||
| @@ -52,9 +54,13 @@ | |||
| 52 | #define STMP3XXX_RTC_PERSISTENT0 0x60 | 54 | #define STMP3XXX_RTC_PERSISTENT0 0x60 |
| 53 | #define STMP3XXX_RTC_PERSISTENT0_SET 0x64 | 55 | #define STMP3XXX_RTC_PERSISTENT0_SET 0x64 |
| 54 | #define STMP3XXX_RTC_PERSISTENT0_CLR 0x68 | 56 | #define STMP3XXX_RTC_PERSISTENT0_CLR 0x68 |
| 55 | #define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN 0x00000002 | 57 | #define STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE (1 << 0) |
| 56 | #define STMP3XXX_RTC_PERSISTENT0_ALARM_EN 0x00000004 | 58 | #define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN (1 << 1) |
| 57 | #define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE 0x00000080 | 59 | #define STMP3XXX_RTC_PERSISTENT0_ALARM_EN (1 << 2) |
| 60 | #define STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP (1 << 4) | ||
| 61 | #define STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP (1 << 5) | ||
| 62 | #define STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ (1 << 6) | ||
| 63 | #define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE (1 << 7) | ||
| 58 | 64 | ||
| 59 | #define STMP3XXX_RTC_PERSISTENT1 0x70 | 65 | #define STMP3XXX_RTC_PERSISTENT1 0x70 |
| 60 | /* missing bitmask in headers */ | 66 | /* missing bitmask in headers */ |
| @@ -248,6 +254,9 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev) | |||
| 248 | { | 254 | { |
| 249 | struct stmp3xxx_rtc_data *rtc_data; | 255 | struct stmp3xxx_rtc_data *rtc_data; |
| 250 | struct resource *r; | 256 | struct resource *r; |
| 257 | u32 rtc_stat; | ||
| 258 | u32 pers0_set, pers0_clr; | ||
| 259 | u32 crystalfreq = 0; | ||
| 251 | int err; | 260 | int err; |
| 252 | 261 | ||
| 253 | rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL); | 262 | rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL); |
| @@ -268,8 +277,8 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev) | |||
| 268 | 277 | ||
| 269 | rtc_data->irq_alarm = platform_get_irq(pdev, 0); | 278 | rtc_data->irq_alarm = platform_get_irq(pdev, 0); |
| 270 | 279 | ||
| 271 | if (!(readl(STMP3XXX_RTC_STAT + rtc_data->io) & | 280 | rtc_stat = readl(rtc_data->io + STMP3XXX_RTC_STAT); |
| 272 | STMP3XXX_RTC_STAT_RTC_PRESENT)) { | 281 | if (!(rtc_stat & STMP3XXX_RTC_STAT_RTC_PRESENT)) { |
| 273 | dev_err(&pdev->dev, "no device onboard\n"); | 282 | dev_err(&pdev->dev, "no device onboard\n"); |
| 274 | return -ENODEV; | 283 | return -ENODEV; |
| 275 | } | 284 | } |
| @@ -282,9 +291,54 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev) | |||
| 282 | return err; | 291 | return err; |
| 283 | } | 292 | } |
| 284 | 293 | ||
| 294 | /* | ||
| 295 | * Obviously the rtc needs a clock input to be able to run. | ||
| 296 | * This clock can be provided by an external 32k crystal. If that one is | ||
| 297 | * missing XTAL must not be disabled in suspend which consumes a | ||
| 298 | * lot of power. Normally the presence and exact frequency (supported | ||
| 299 | * are 32000 Hz and 32768 Hz) is detectable from fuses, but as reality | ||
| 300 | * proves these fuses are not blown correctly on all machines, so the | ||
| 301 | * frequency can be overridden in the device tree. | ||
| 302 | */ | ||
| 303 | if (rtc_stat & STMP3XXX_RTC_STAT_XTAL32000_PRESENT) | ||
| 304 | crystalfreq = 32000; | ||
| 305 | else if (rtc_stat & STMP3XXX_RTC_STAT_XTAL32768_PRESENT) | ||
| 306 | crystalfreq = 32768; | ||
| 307 | |||
| 308 | of_property_read_u32(pdev->dev.of_node, "stmp,crystal-freq", | ||
| 309 | &crystalfreq); | ||
| 310 | |||
| 311 | switch (crystalfreq) { | ||
| 312 | case 32000: | ||
| 313 | /* keep 32kHz crystal running in low-power mode */ | ||
| 314 | pers0_set = STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ | | ||
| 315 | STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP | | ||
| 316 | STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE; | ||
| 317 | pers0_clr = STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP; | ||
| 318 | break; | ||
| 319 | case 32768: | ||
| 320 | /* keep 32.768kHz crystal running in low-power mode */ | ||
| 321 | pers0_set = STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP | | ||
| 322 | STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE; | ||
| 323 | pers0_clr = STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP | | ||
| 324 | STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ; | ||
| 325 | break; | ||
| 326 | default: | ||
| 327 | dev_warn(&pdev->dev, | ||
| 328 | "invalid crystal-freq specified in device-tree. Assuming no crystal\n"); | ||
| 329 | /* fall-through */ | ||
| 330 | case 0: | ||
| 331 | /* keep XTAL on in low-power mode */ | ||
| 332 | pers0_set = STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP; | ||
| 333 | pers0_clr = STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP | | ||
| 334 | STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE; | ||
| 335 | } | ||
| 336 | |||
| 337 | writel(pers0_set, rtc_data->io + STMP3XXX_RTC_PERSISTENT0_SET); | ||
| 338 | |||
| 285 | writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | | 339 | writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | |
| 286 | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | | 340 | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | |
| 287 | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE, | 341 | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE | pers0_clr, |
| 288 | rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); | 342 | rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); |
| 289 | 343 | ||
| 290 | writel(STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN | | 344 | writel(STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN | |
diff --git a/drivers/rtc/rtc-tegra.c b/drivers/rtc/rtc-tegra.c index d948277057d8..60232bd366ef 100644 --- a/drivers/rtc/rtc-tegra.c +++ b/drivers/rtc/rtc-tegra.c | |||
| @@ -261,7 +261,9 @@ static int tegra_rtc_proc(struct device *dev, struct seq_file *seq) | |||
| 261 | if (!dev || !dev->driver) | 261 | if (!dev || !dev->driver) |
| 262 | return 0; | 262 | return 0; |
| 263 | 263 | ||
| 264 | return seq_printf(seq, "name\t\t: %s\n", dev_name(dev)); | 264 | seq_printf(seq, "name\t\t: %s\n", dev_name(dev)); |
| 265 | |||
| 266 | return 0; | ||
| 265 | } | 267 | } |
| 266 | 268 | ||
| 267 | static irqreturn_t tegra_rtc_irq_handler(int irq, void *data) | 269 | static irqreturn_t tegra_rtc_irq_handler(int irq, void *data) |
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c index 8f86fa91de1a..3a2da4c892d6 100644 --- a/drivers/rtc/rtc-test.c +++ b/drivers/rtc/rtc-test.c | |||
| @@ -13,6 +13,10 @@ | |||
| 13 | #include <linux/rtc.h> | 13 | #include <linux/rtc.h> |
| 14 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
| 15 | 15 | ||
| 16 | static int test_mmss64; | ||
| 17 | module_param(test_mmss64, int, 0644); | ||
| 18 | MODULE_PARM_DESC(test_mmss64, "Test struct rtc_class_ops.set_mmss64()."); | ||
| 19 | |||
| 16 | static struct platform_device *test0 = NULL, *test1 = NULL; | 20 | static struct platform_device *test0 = NULL, *test1 = NULL; |
| 17 | 21 | ||
| 18 | static int test_rtc_read_alarm(struct device *dev, | 22 | static int test_rtc_read_alarm(struct device *dev, |
| @@ -30,7 +34,13 @@ static int test_rtc_set_alarm(struct device *dev, | |||
| 30 | static int test_rtc_read_time(struct device *dev, | 34 | static int test_rtc_read_time(struct device *dev, |
| 31 | struct rtc_time *tm) | 35 | struct rtc_time *tm) |
| 32 | { | 36 | { |
| 33 | rtc_time_to_tm(get_seconds(), tm); | 37 | rtc_time64_to_tm(ktime_get_real_seconds(), tm); |
| 38 | return 0; | ||
| 39 | } | ||
| 40 | |||
| 41 | static int test_rtc_set_mmss64(struct device *dev, time64_t secs) | ||
| 42 | { | ||
| 43 | dev_info(dev, "%s, secs = %lld\n", __func__, (long long)secs); | ||
| 34 | return 0; | 44 | return 0; |
| 35 | } | 45 | } |
| 36 | 46 | ||
| @@ -55,7 +65,7 @@ static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) | |||
| 55 | return 0; | 65 | return 0; |
| 56 | } | 66 | } |
| 57 | 67 | ||
| 58 | static const struct rtc_class_ops test_rtc_ops = { | 68 | static struct rtc_class_ops test_rtc_ops = { |
| 59 | .proc = test_rtc_proc, | 69 | .proc = test_rtc_proc, |
| 60 | .read_time = test_rtc_read_time, | 70 | .read_time = test_rtc_read_time, |
| 61 | .read_alarm = test_rtc_read_alarm, | 71 | .read_alarm = test_rtc_read_alarm, |
| @@ -101,6 +111,11 @@ static int test_probe(struct platform_device *plat_dev) | |||
| 101 | int err; | 111 | int err; |
| 102 | struct rtc_device *rtc; | 112 | struct rtc_device *rtc; |
| 103 | 113 | ||
| 114 | if (test_mmss64) { | ||
| 115 | test_rtc_ops.set_mmss64 = test_rtc_set_mmss64; | ||
| 116 | test_rtc_ops.set_mmss = NULL; | ||
| 117 | } | ||
| 118 | |||
| 104 | rtc = devm_rtc_device_register(&plat_dev->dev, "test", | 119 | rtc = devm_rtc_device_register(&plat_dev->dev, "test", |
| 105 | &test_rtc_ops, THIS_MODULE); | 120 | &test_rtc_ops, THIS_MODULE); |
| 106 | if (IS_ERR(rtc)) { | 121 | if (IS_ERR(rtc)) { |
diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c index 5baea3f54926..2dc787dc06c1 100644 --- a/drivers/rtc/rtc-twl.c +++ b/drivers/rtc/rtc-twl.c | |||
| @@ -18,6 +18,8 @@ | |||
| 18 | * 2 of the License, or (at your option) any later version. | 18 | * 2 of the License, or (at your option) any later version. |
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| 21 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 22 | |||
| 21 | #include <linux/kernel.h> | 23 | #include <linux/kernel.h> |
| 22 | #include <linux/errno.h> | 24 | #include <linux/errno.h> |
| 23 | #include <linux/init.h> | 25 | #include <linux/init.h> |
| @@ -145,8 +147,7 @@ static int twl_rtc_read_u8(u8 *data, u8 reg) | |||
| 145 | 147 | ||
| 146 | ret = twl_i2c_read_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); | 148 | ret = twl_i2c_read_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); |
| 147 | if (ret < 0) | 149 | if (ret < 0) |
| 148 | pr_err("twl_rtc: Could not read TWL" | 150 | pr_err("Could not read TWL register %X - error %d\n", reg, ret); |
| 149 | "register %X - error %d\n", reg, ret); | ||
| 150 | return ret; | 151 | return ret; |
| 151 | } | 152 | } |
| 152 | 153 | ||
| @@ -159,8 +160,8 @@ static int twl_rtc_write_u8(u8 data, u8 reg) | |||
| 159 | 160 | ||
| 160 | ret = twl_i2c_write_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); | 161 | ret = twl_i2c_write_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); |
| 161 | if (ret < 0) | 162 | if (ret < 0) |
| 162 | pr_err("twl_rtc: Could not write TWL" | 163 | pr_err("Could not write TWL register %X - error %d\n", |
| 163 | "register %X - error %d\n", reg, ret); | 164 | reg, ret); |
| 164 | return ret; | 165 | return ret; |
| 165 | } | 166 | } |
| 166 | 167 | ||
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c index b1de58e0b3d0..5638b7ba8b06 100644 --- a/drivers/rtc/rtc-x1205.c +++ b/drivers/rtc/rtc-x1205.c | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | #include <linux/rtc.h> | 22 | #include <linux/rtc.h> |
| 23 | #include <linux/delay.h> | 23 | #include <linux/delay.h> |
| 24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
| 25 | #include <linux/bitops.h> | ||
| 25 | 26 | ||
| 26 | #define DRV_VERSION "1.0.8" | 27 | #define DRV_VERSION "1.0.8" |
| 27 | 28 | ||
| @@ -366,8 +367,7 @@ static int x1205_get_atrim(struct i2c_client *client, int *trim) | |||
| 366 | * perform sign extension. The formula is | 367 | * perform sign extension. The formula is |
| 367 | * Catr = (atr * 0.25pF) + 11.00pF. | 368 | * Catr = (atr * 0.25pF) + 11.00pF. |
| 368 | */ | 369 | */ |
| 369 | if (atr & 0x20) | 370 | atr = sign_extend32(atr, 5); |
| 370 | atr |= 0xC0; | ||
| 371 | 371 | ||
| 372 | dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __func__, atr, atr); | 372 | dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __func__, atr, atr); |
| 373 | 373 | ||
diff --git a/drivers/rtc/systohc.c b/drivers/rtc/systohc.c index eb71872d0361..7728d5e32bf4 100644 --- a/drivers/rtc/systohc.c +++ b/drivers/rtc/systohc.c | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | * rtc_set_ntp_time - Save NTP synchronized time to the RTC | 11 | * rtc_set_ntp_time - Save NTP synchronized time to the RTC |
| 12 | * @now: Current time of day | 12 | * @now: Current time of day |
| 13 | * | 13 | * |
| 14 | * Replacement for the NTP platform function update_persistent_clock | 14 | * Replacement for the NTP platform function update_persistent_clock64 |
| 15 | * that stores time for later retrieval by rtc_hctosys. | 15 | * that stores time for later retrieval by rtc_hctosys. |
| 16 | * | 16 | * |
| 17 | * Returns 0 on successful RTC update, -ENODEV if a RTC update is not | 17 | * Returns 0 on successful RTC update, -ENODEV if a RTC update is not |
| @@ -35,7 +35,10 @@ int rtc_set_ntp_time(struct timespec64 now) | |||
| 35 | if (rtc) { | 35 | if (rtc) { |
| 36 | /* rtc_hctosys exclusively uses UTC, so we call set_time here, | 36 | /* rtc_hctosys exclusively uses UTC, so we call set_time here, |
| 37 | * not set_mmss. */ | 37 | * not set_mmss. */ |
| 38 | if (rtc->ops && (rtc->ops->set_time || rtc->ops->set_mmss)) | 38 | if (rtc->ops && |
| 39 | (rtc->ops->set_time || | ||
| 40 | rtc->ops->set_mmss64 || | ||
| 41 | rtc->ops->set_mmss)) | ||
| 39 | err = rtc_set_time(rtc, &tm); | 42 | err = rtc_set_time(rtc, &tm); |
| 40 | rtc_class_close(rtc); | 43 | rtc_class_close(rtc); |
| 41 | } | 44 | } |
