diff options
Diffstat (limited to 'drivers/rtc')
| -rw-r--r-- | drivers/rtc/Kconfig | 19 | ||||
| -rw-r--r-- | drivers/rtc/Makefile | 3 | ||||
| -rw-r--r-- | drivers/rtc/rtc-ab8500.c | 103 | ||||
| -rw-r--r-- | drivers/rtc/rtc-max8998.c | 300 | ||||
| -rw-r--r-- | drivers/rtc/rtc-mc13783.c | 428 | ||||
| -rw-r--r-- | drivers/rtc/rtc-mc13xxx.c | 437 |
6 files changed, 807 insertions, 483 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 6a77437d4f5a..2883428d5ac8 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
| @@ -196,6 +196,16 @@ config RTC_DRV_MAX8925 | |||
| 196 | This driver can also be built as a module. If so, the module | 196 | This driver can also be built as a module. If so, the module |
| 197 | will be called rtc-max8925. | 197 | will be called rtc-max8925. |
| 198 | 198 | ||
| 199 | config RTC_DRV_MAX8998 | ||
| 200 | tristate "Maxim MAX8998" | ||
| 201 | depends on MFD_MAX8998 | ||
| 202 | help | ||
| 203 | If you say yes here you will get support for the | ||
| 204 | RTC of Maxim MAX8998 PMIC. | ||
| 205 | |||
| 206 | This driver can also be built as a module. If so, the module | ||
| 207 | will be called rtc-max8998. | ||
| 208 | |||
| 199 | config RTC_DRV_RS5C372 | 209 | config RTC_DRV_RS5C372 |
| 200 | tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A" | 210 | tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A" |
| 201 | help | 211 | help |
| @@ -926,11 +936,12 @@ config RTC_DRV_PCAP | |||
| 926 | If you say Y here you will get support for the RTC found on | 936 | If you say Y here you will get support for the RTC found on |
| 927 | the PCAP2 ASIC used on some Motorola phones. | 937 | the PCAP2 ASIC used on some Motorola phones. |
| 928 | 938 | ||
| 929 | config RTC_DRV_MC13783 | 939 | config RTC_DRV_MC13XXX |
| 930 | depends on MFD_MC13783 | 940 | depends on MFD_MC13XXX |
| 931 | tristate "Freescale MC13783 RTC" | 941 | tristate "Freescale MC13xxx RTC" |
| 932 | help | 942 | help |
| 933 | This enables support for the Freescale MC13783 PMIC RTC | 943 | This enables support for the RTCs found on Freescale's PMICs |
| 944 | MC13783 and MC13892. | ||
| 934 | 945 | ||
| 935 | config RTC_DRV_MPC5121 | 946 | config RTC_DRV_MPC5121 |
| 936 | tristate "Freescale MPC5121 built-in RTC" | 947 | tristate "Freescale MPC5121 built-in RTC" |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 7a7cb3228a1d..4c2832df4697 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
| @@ -60,8 +60,9 @@ obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o | |||
| 60 | obj-$(CONFIG_RTC_MXC) += rtc-mxc.o | 60 | obj-$(CONFIG_RTC_MXC) += rtc-mxc.o |
| 61 | obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o | 61 | obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o |
| 62 | obj-$(CONFIG_RTC_DRV_MAX8925) += rtc-max8925.o | 62 | obj-$(CONFIG_RTC_DRV_MAX8925) += rtc-max8925.o |
| 63 | obj-$(CONFIG_RTC_DRV_MAX8998) += rtc-max8998.o | ||
| 63 | obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o | 64 | obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o |
| 64 | obj-$(CONFIG_RTC_DRV_MC13783) += rtc-mc13783.o | 65 | obj-$(CONFIG_RTC_DRV_MC13XXX) += rtc-mc13xxx.o |
| 65 | obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o | 66 | obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o |
| 66 | obj-$(CONFIG_RTC_DRV_MPC5121) += rtc-mpc5121.o | 67 | obj-$(CONFIG_RTC_DRV_MPC5121) += rtc-mpc5121.o |
| 67 | obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o | 68 | obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o |
diff --git a/drivers/rtc/rtc-ab8500.c b/drivers/rtc/rtc-ab8500.c index 2fda03125e55..e346705aae92 100644 --- a/drivers/rtc/rtc-ab8500.c +++ b/drivers/rtc/rtc-ab8500.c | |||
| @@ -14,26 +14,26 @@ | |||
| 14 | #include <linux/init.h> | 14 | #include <linux/init.h> |
| 15 | #include <linux/platform_device.h> | 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/rtc.h> | 16 | #include <linux/rtc.h> |
| 17 | #include <linux/mfd/abx500.h> | ||
| 17 | #include <linux/mfd/ab8500.h> | 18 | #include <linux/mfd/ab8500.h> |
| 18 | #include <linux/delay.h> | 19 | #include <linux/delay.h> |
| 19 | 20 | ||
| 20 | #define AB8500_RTC_SOFF_STAT_REG 0x0F00 | 21 | #define AB8500_RTC_SOFF_STAT_REG 0x00 |
| 21 | #define AB8500_RTC_CC_CONF_REG 0x0F01 | 22 | #define AB8500_RTC_CC_CONF_REG 0x01 |
| 22 | #define AB8500_RTC_READ_REQ_REG 0x0F02 | 23 | #define AB8500_RTC_READ_REQ_REG 0x02 |
| 23 | #define AB8500_RTC_WATCH_TSECMID_REG 0x0F03 | 24 | #define AB8500_RTC_WATCH_TSECMID_REG 0x03 |
| 24 | #define AB8500_RTC_WATCH_TSECHI_REG 0x0F04 | 25 | #define AB8500_RTC_WATCH_TSECHI_REG 0x04 |
| 25 | #define AB8500_RTC_WATCH_TMIN_LOW_REG 0x0F05 | 26 | #define AB8500_RTC_WATCH_TMIN_LOW_REG 0x05 |
| 26 | #define AB8500_RTC_WATCH_TMIN_MID_REG 0x0F06 | 27 | #define AB8500_RTC_WATCH_TMIN_MID_REG 0x06 |
| 27 | #define AB8500_RTC_WATCH_TMIN_HI_REG 0x0F07 | 28 | #define AB8500_RTC_WATCH_TMIN_HI_REG 0x07 |
| 28 | #define AB8500_RTC_ALRM_MIN_LOW_REG 0x0F08 | 29 | #define AB8500_RTC_ALRM_MIN_LOW_REG 0x08 |
| 29 | #define AB8500_RTC_ALRM_MIN_MID_REG 0x0F09 | 30 | #define AB8500_RTC_ALRM_MIN_MID_REG 0x09 |
| 30 | #define AB8500_RTC_ALRM_MIN_HI_REG 0x0F0A | 31 | #define AB8500_RTC_ALRM_MIN_HI_REG 0x0A |
| 31 | #define AB8500_RTC_STAT_REG 0x0F0B | 32 | #define AB8500_RTC_STAT_REG 0x0B |
| 32 | #define AB8500_RTC_BKUP_CHG_REG 0x0F0C | 33 | #define AB8500_RTC_BKUP_CHG_REG 0x0C |
| 33 | #define AB8500_RTC_FORCE_BKUP_REG 0x0F0D | 34 | #define AB8500_RTC_FORCE_BKUP_REG 0x0D |
| 34 | #define AB8500_RTC_CALIB_REG 0x0F0E | 35 | #define AB8500_RTC_CALIB_REG 0x0E |
| 35 | #define AB8500_RTC_SWITCH_STAT_REG 0x0F0F | 36 | #define AB8500_RTC_SWITCH_STAT_REG 0x0F |
| 36 | #define AB8500_REV_REG 0x1080 | ||
| 37 | 37 | ||
| 38 | /* RtcReadRequest bits */ | 38 | /* RtcReadRequest bits */ |
| 39 | #define RTC_READ_REQUEST 0x01 | 39 | #define RTC_READ_REQUEST 0x01 |
| @@ -46,13 +46,13 @@ | |||
| 46 | #define COUNTS_PER_SEC (0xF000 / 60) | 46 | #define COUNTS_PER_SEC (0xF000 / 60) |
| 47 | #define AB8500_RTC_EPOCH 2000 | 47 | #define AB8500_RTC_EPOCH 2000 |
| 48 | 48 | ||
| 49 | static const unsigned long ab8500_rtc_time_regs[] = { | 49 | static const u8 ab8500_rtc_time_regs[] = { |
| 50 | AB8500_RTC_WATCH_TMIN_HI_REG, AB8500_RTC_WATCH_TMIN_MID_REG, | 50 | AB8500_RTC_WATCH_TMIN_HI_REG, AB8500_RTC_WATCH_TMIN_MID_REG, |
| 51 | AB8500_RTC_WATCH_TMIN_LOW_REG, AB8500_RTC_WATCH_TSECHI_REG, | 51 | AB8500_RTC_WATCH_TMIN_LOW_REG, AB8500_RTC_WATCH_TSECHI_REG, |
| 52 | AB8500_RTC_WATCH_TSECMID_REG | 52 | AB8500_RTC_WATCH_TSECMID_REG |
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| 55 | static const unsigned long ab8500_rtc_alarm_regs[] = { | 55 | static const u8 ab8500_rtc_alarm_regs[] = { |
| 56 | AB8500_RTC_ALRM_MIN_HI_REG, AB8500_RTC_ALRM_MIN_MID_REG, | 56 | AB8500_RTC_ALRM_MIN_HI_REG, AB8500_RTC_ALRM_MIN_MID_REG, |
| 57 | AB8500_RTC_ALRM_MIN_LOW_REG | 57 | AB8500_RTC_ALRM_MIN_LOW_REG |
| 58 | }; | 58 | }; |
| @@ -76,29 +76,30 @@ static unsigned long get_elapsed_seconds(int year) | |||
| 76 | 76 | ||
| 77 | static int ab8500_rtc_read_time(struct device *dev, struct rtc_time *tm) | 77 | static int ab8500_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| 78 | { | 78 | { |
| 79 | struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); | ||
| 80 | unsigned long timeout = jiffies + HZ; | 79 | unsigned long timeout = jiffies + HZ; |
| 81 | int retval, i; | 80 | int retval, i; |
| 82 | unsigned long mins, secs; | 81 | unsigned long mins, secs; |
| 83 | unsigned char buf[ARRAY_SIZE(ab8500_rtc_time_regs)]; | 82 | unsigned char buf[ARRAY_SIZE(ab8500_rtc_time_regs)]; |
| 83 | u8 value; | ||
| 84 | 84 | ||
| 85 | /* Request a data read */ | 85 | /* Request a data read */ |
| 86 | retval = ab8500_write(ab8500, AB8500_RTC_READ_REQ_REG, | 86 | retval = abx500_set_register_interruptible(dev, |
| 87 | RTC_READ_REQUEST); | 87 | AB8500_RTC, AB8500_RTC_READ_REQ_REG, RTC_READ_REQUEST); |
| 88 | if (retval < 0) | 88 | if (retval < 0) |
| 89 | return retval; | 89 | return retval; |
| 90 | 90 | ||
| 91 | /* Early AB8500 chips will not clear the rtc read request bit */ | 91 | /* Early AB8500 chips will not clear the rtc read request bit */ |
| 92 | if (ab8500->revision == 0) { | 92 | if (abx500_get_chip_id(dev) == 0) { |
| 93 | msleep(1); | 93 | msleep(1); |
| 94 | } else { | 94 | } else { |
| 95 | /* Wait for some cycles after enabling the rtc read in ab8500 */ | 95 | /* Wait for some cycles after enabling the rtc read in ab8500 */ |
| 96 | while (time_before(jiffies, timeout)) { | 96 | while (time_before(jiffies, timeout)) { |
| 97 | retval = ab8500_read(ab8500, AB8500_RTC_READ_REQ_REG); | 97 | retval = abx500_get_register_interruptible(dev, |
| 98 | AB8500_RTC, AB8500_RTC_READ_REQ_REG, &value); | ||
| 98 | if (retval < 0) | 99 | if (retval < 0) |
| 99 | return retval; | 100 | return retval; |
| 100 | 101 | ||
| 101 | if (!(retval & RTC_READ_REQUEST)) | 102 | if (!(value & RTC_READ_REQUEST)) |
| 102 | break; | 103 | break; |
| 103 | 104 | ||
| 104 | msleep(1); | 105 | msleep(1); |
| @@ -107,10 +108,11 @@ static int ab8500_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 107 | 108 | ||
| 108 | /* Read the Watchtime registers */ | 109 | /* Read the Watchtime registers */ |
| 109 | for (i = 0; i < ARRAY_SIZE(ab8500_rtc_time_regs); i++) { | 110 | for (i = 0; i < ARRAY_SIZE(ab8500_rtc_time_regs); i++) { |
| 110 | retval = ab8500_read(ab8500, ab8500_rtc_time_regs[i]); | 111 | retval = abx500_get_register_interruptible(dev, |
| 112 | AB8500_RTC, ab8500_rtc_time_regs[i], &value); | ||
| 111 | if (retval < 0) | 113 | if (retval < 0) |
| 112 | return retval; | 114 | return retval; |
| 113 | buf[i] = retval; | 115 | buf[i] = value; |
| 114 | } | 116 | } |
| 115 | 117 | ||
| 116 | mins = (buf[0] << 16) | (buf[1] << 8) | buf[2]; | 118 | mins = (buf[0] << 16) | (buf[1] << 8) | buf[2]; |
| @@ -128,7 +130,6 @@ static int ab8500_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 128 | 130 | ||
| 129 | static int ab8500_rtc_set_time(struct device *dev, struct rtc_time *tm) | 131 | static int ab8500_rtc_set_time(struct device *dev, struct rtc_time *tm) |
| 130 | { | 132 | { |
| 131 | struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); | ||
| 132 | int retval, i; | 133 | int retval, i; |
| 133 | unsigned char buf[ARRAY_SIZE(ab8500_rtc_time_regs)]; | 134 | unsigned char buf[ARRAY_SIZE(ab8500_rtc_time_regs)]; |
| 134 | unsigned long no_secs, no_mins, secs = 0; | 135 | unsigned long no_secs, no_mins, secs = 0; |
| @@ -162,27 +163,29 @@ static int ab8500_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
| 162 | buf[0] = (no_mins >> 16) & 0xFF; | 163 | buf[0] = (no_mins >> 16) & 0xFF; |
| 163 | 164 | ||
| 164 | for (i = 0; i < ARRAY_SIZE(ab8500_rtc_time_regs); i++) { | 165 | for (i = 0; i < ARRAY_SIZE(ab8500_rtc_time_regs); i++) { |
| 165 | retval = ab8500_write(ab8500, ab8500_rtc_time_regs[i], buf[i]); | 166 | retval = abx500_set_register_interruptible(dev, AB8500_RTC, |
| 167 | ab8500_rtc_time_regs[i], buf[i]); | ||
| 166 | if (retval < 0) | 168 | if (retval < 0) |
| 167 | return retval; | 169 | return retval; |
| 168 | } | 170 | } |
| 169 | 171 | ||
| 170 | /* Request a data write */ | 172 | /* Request a data write */ |
| 171 | return ab8500_write(ab8500, AB8500_RTC_READ_REQ_REG, RTC_WRITE_REQUEST); | 173 | return abx500_set_register_interruptible(dev, AB8500_RTC, |
| 174 | AB8500_RTC_READ_REQ_REG, RTC_WRITE_REQUEST); | ||
| 172 | } | 175 | } |
| 173 | 176 | ||
| 174 | static int ab8500_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | 177 | static int ab8500_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
| 175 | { | 178 | { |
| 176 | struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); | ||
| 177 | int retval, i; | 179 | int retval, i; |
| 178 | int rtc_ctrl; | 180 | u8 rtc_ctrl, value; |
| 179 | unsigned char buf[ARRAY_SIZE(ab8500_rtc_alarm_regs)]; | 181 | unsigned char buf[ARRAY_SIZE(ab8500_rtc_alarm_regs)]; |
| 180 | unsigned long secs, mins; | 182 | unsigned long secs, mins; |
| 181 | 183 | ||
| 182 | /* Check if the alarm is enabled or not */ | 184 | /* Check if the alarm is enabled or not */ |
| 183 | rtc_ctrl = ab8500_read(ab8500, AB8500_RTC_STAT_REG); | 185 | retval = abx500_get_register_interruptible(dev, AB8500_RTC, |
| 184 | if (rtc_ctrl < 0) | 186 | AB8500_RTC_STAT_REG, &rtc_ctrl); |
| 185 | return rtc_ctrl; | 187 | if (retval < 0) |
| 188 | return retval; | ||
| 186 | 189 | ||
| 187 | if (rtc_ctrl & RTC_ALARM_ENA) | 190 | if (rtc_ctrl & RTC_ALARM_ENA) |
| 188 | alarm->enabled = 1; | 191 | alarm->enabled = 1; |
| @@ -192,10 +195,11 @@ static int ab8500_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | |||
| 192 | alarm->pending = 0; | 195 | alarm->pending = 0; |
| 193 | 196 | ||
| 194 | for (i = 0; i < ARRAY_SIZE(ab8500_rtc_alarm_regs); i++) { | 197 | for (i = 0; i < ARRAY_SIZE(ab8500_rtc_alarm_regs); i++) { |
| 195 | retval = ab8500_read(ab8500, ab8500_rtc_alarm_regs[i]); | 198 | retval = abx500_get_register_interruptible(dev, AB8500_RTC, |
| 199 | ab8500_rtc_alarm_regs[i], &value); | ||
| 196 | if (retval < 0) | 200 | if (retval < 0) |
| 197 | return retval; | 201 | return retval; |
| 198 | buf[i] = retval; | 202 | buf[i] = value; |
| 199 | } | 203 | } |
| 200 | 204 | ||
| 201 | mins = (buf[0] << 16) | (buf[1] << 8) | (buf[2]); | 205 | mins = (buf[0] << 16) | (buf[1] << 8) | (buf[2]); |
| @@ -211,15 +215,13 @@ static int ab8500_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | |||
| 211 | 215 | ||
| 212 | static int ab8500_rtc_irq_enable(struct device *dev, unsigned int enabled) | 216 | static int ab8500_rtc_irq_enable(struct device *dev, unsigned int enabled) |
| 213 | { | 217 | { |
| 214 | struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); | 218 | return abx500_mask_and_set_register_interruptible(dev, AB8500_RTC, |
| 215 | 219 | AB8500_RTC_STAT_REG, RTC_ALARM_ENA, | |
| 216 | return ab8500_set_bits(ab8500, AB8500_RTC_STAT_REG, RTC_ALARM_ENA, | 220 | enabled ? RTC_ALARM_ENA : 0); |
| 217 | enabled ? RTC_ALARM_ENA : 0); | ||
| 218 | } | 221 | } |
| 219 | 222 | ||
| 220 | static int ab8500_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | 223 | static int ab8500_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
| 221 | { | 224 | { |
| 222 | struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); | ||
| 223 | int retval, i; | 225 | int retval, i; |
| 224 | unsigned char buf[ARRAY_SIZE(ab8500_rtc_alarm_regs)]; | 226 | unsigned char buf[ARRAY_SIZE(ab8500_rtc_alarm_regs)]; |
| 225 | unsigned long mins, secs = 0; | 227 | unsigned long mins, secs = 0; |
| @@ -247,7 +249,8 @@ static int ab8500_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | |||
| 247 | 249 | ||
| 248 | /* Set the alarm time */ | 250 | /* Set the alarm time */ |
| 249 | for (i = 0; i < ARRAY_SIZE(ab8500_rtc_alarm_regs); i++) { | 251 | for (i = 0; i < ARRAY_SIZE(ab8500_rtc_alarm_regs); i++) { |
| 250 | retval = ab8500_write(ab8500, ab8500_rtc_alarm_regs[i], buf[i]); | 252 | retval = abx500_set_register_interruptible(dev, AB8500_RTC, |
| 253 | ab8500_rtc_alarm_regs[i], buf[i]); | ||
| 251 | if (retval < 0) | 254 | if (retval < 0) |
| 252 | return retval; | 255 | return retval; |
| 253 | } | 256 | } |
| @@ -276,10 +279,9 @@ static const struct rtc_class_ops ab8500_rtc_ops = { | |||
| 276 | 279 | ||
| 277 | static int __devinit ab8500_rtc_probe(struct platform_device *pdev) | 280 | static int __devinit ab8500_rtc_probe(struct platform_device *pdev) |
| 278 | { | 281 | { |
| 279 | struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); | ||
| 280 | int err; | 282 | int err; |
| 281 | struct rtc_device *rtc; | 283 | struct rtc_device *rtc; |
| 282 | int rtc_ctrl; | 284 | u8 rtc_ctrl; |
| 283 | int irq; | 285 | int irq; |
| 284 | 286 | ||
| 285 | irq = platform_get_irq_byname(pdev, "ALARM"); | 287 | irq = platform_get_irq_byname(pdev, "ALARM"); |
| @@ -287,17 +289,18 @@ static int __devinit ab8500_rtc_probe(struct platform_device *pdev) | |||
| 287 | return irq; | 289 | return irq; |
| 288 | 290 | ||
| 289 | /* For RTC supply test */ | 291 | /* For RTC supply test */ |
| 290 | err = ab8500_set_bits(ab8500, AB8500_RTC_STAT_REG, RTC_STATUS_DATA, | 292 | err = abx500_mask_and_set_register_interruptible(&pdev->dev, AB8500_RTC, |
| 291 | RTC_STATUS_DATA); | 293 | AB8500_RTC_STAT_REG, RTC_STATUS_DATA, RTC_STATUS_DATA); |
| 292 | if (err < 0) | 294 | if (err < 0) |
| 293 | return err; | 295 | return err; |
| 294 | 296 | ||
| 295 | /* Wait for reset by the PorRtc */ | 297 | /* Wait for reset by the PorRtc */ |
| 296 | msleep(1); | 298 | msleep(1); |
| 297 | 299 | ||
| 298 | rtc_ctrl = ab8500_read(ab8500, AB8500_RTC_STAT_REG); | 300 | err = abx500_get_register_interruptible(&pdev->dev, AB8500_RTC, |
| 299 | if (rtc_ctrl < 0) | 301 | AB8500_RTC_STAT_REG, &rtc_ctrl); |
| 300 | return rtc_ctrl; | 302 | if (err < 0) |
| 303 | return err; | ||
| 301 | 304 | ||
| 302 | /* Check if the RTC Supply fails */ | 305 | /* Check if the RTC Supply fails */ |
| 303 | if (!(rtc_ctrl & RTC_STATUS_DATA)) { | 306 | if (!(rtc_ctrl & RTC_STATUS_DATA)) { |
diff --git a/drivers/rtc/rtc-max8998.c b/drivers/rtc/rtc-max8998.c new file mode 100644 index 000000000000..f22dee35f330 --- /dev/null +++ b/drivers/rtc/rtc-max8998.c | |||
| @@ -0,0 +1,300 @@ | |||
| 1 | /* | ||
| 2 | * RTC driver for Maxim MAX8998 | ||
| 3 | * | ||
| 4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd | ||
| 5 | * Author: Minkyu Kang <mk7.kang@samsung.com> | ||
| 6 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> | ||
| 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 | |||
| 15 | #include <linux/module.h> | ||
| 16 | #include <linux/i2c.h> | ||
| 17 | #include <linux/slab.h> | ||
| 18 | #include <linux/bcd.h> | ||
| 19 | #include <linux/rtc.h> | ||
| 20 | #include <linux/platform_device.h> | ||
| 21 | #include <linux/mfd/max8998.h> | ||
| 22 | #include <linux/mfd/max8998-private.h> | ||
| 23 | |||
| 24 | #define MAX8998_RTC_SEC 0x00 | ||
| 25 | #define MAX8998_RTC_MIN 0x01 | ||
| 26 | #define MAX8998_RTC_HOUR 0x02 | ||
| 27 | #define MAX8998_RTC_WEEKDAY 0x03 | ||
| 28 | #define MAX8998_RTC_DATE 0x04 | ||
| 29 | #define MAX8998_RTC_MONTH 0x05 | ||
| 30 | #define MAX8998_RTC_YEAR1 0x06 | ||
| 31 | #define MAX8998_RTC_YEAR2 0x07 | ||
| 32 | #define MAX8998_ALARM0_SEC 0x08 | ||
| 33 | #define MAX8998_ALARM0_MIN 0x09 | ||
| 34 | #define MAX8998_ALARM0_HOUR 0x0a | ||
| 35 | #define MAX8998_ALARM0_WEEKDAY 0x0b | ||
| 36 | #define MAX8998_ALARM0_DATE 0x0c | ||
| 37 | #define MAX8998_ALARM0_MONTH 0x0d | ||
| 38 | #define MAX8998_ALARM0_YEAR1 0x0e | ||
| 39 | #define MAX8998_ALARM0_YEAR2 0x0f | ||
| 40 | #define MAX8998_ALARM1_SEC 0x10 | ||
| 41 | #define MAX8998_ALARM1_MIN 0x11 | ||
| 42 | #define MAX8998_ALARM1_HOUR 0x12 | ||
| 43 | #define MAX8998_ALARM1_WEEKDAY 0x13 | ||
| 44 | #define MAX8998_ALARM1_DATE 0x14 | ||
| 45 | #define MAX8998_ALARM1_MONTH 0x15 | ||
| 46 | #define MAX8998_ALARM1_YEAR1 0x16 | ||
| 47 | #define MAX8998_ALARM1_YEAR2 0x17 | ||
| 48 | #define MAX8998_ALARM0_CONF 0x18 | ||
| 49 | #define MAX8998_ALARM1_CONF 0x19 | ||
| 50 | #define MAX8998_RTC_STATUS 0x1a | ||
| 51 | #define MAX8998_WTSR_SMPL_CNTL 0x1b | ||
| 52 | #define MAX8998_TEST 0x1f | ||
| 53 | |||
| 54 | #define HOUR_12 (1 << 7) | ||
| 55 | #define HOUR_PM (1 << 5) | ||
| 56 | #define ALARM0_STATUS (1 << 1) | ||
| 57 | #define ALARM1_STATUS (1 << 2) | ||
| 58 | |||
| 59 | enum { | ||
| 60 | RTC_SEC = 0, | ||
| 61 | RTC_MIN, | ||
| 62 | RTC_HOUR, | ||
| 63 | RTC_WEEKDAY, | ||
| 64 | RTC_DATE, | ||
| 65 | RTC_MONTH, | ||
| 66 | RTC_YEAR1, | ||
| 67 | RTC_YEAR2, | ||
| 68 | }; | ||
| 69 | |||
| 70 | struct max8998_rtc_info { | ||
| 71 | struct device *dev; | ||
| 72 | struct max8998_dev *max8998; | ||
| 73 | struct i2c_client *rtc; | ||
| 74 | struct rtc_device *rtc_dev; | ||
| 75 | int irq; | ||
| 76 | }; | ||
| 77 | |||
| 78 | static void max8998_data_to_tm(u8 *data, struct rtc_time *tm) | ||
| 79 | { | ||
| 80 | tm->tm_sec = bcd2bin(data[RTC_SEC]); | ||
| 81 | tm->tm_min = bcd2bin(data[RTC_MIN]); | ||
| 82 | if (data[RTC_HOUR] & HOUR_12) { | ||
| 83 | tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x1f); | ||
| 84 | if (data[RTC_HOUR] & HOUR_PM) | ||
| 85 | tm->tm_hour += 12; | ||
| 86 | } else | ||
| 87 | tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x3f); | ||
| 88 | |||
| 89 | tm->tm_wday = data[RTC_WEEKDAY] & 0x07; | ||
| 90 | tm->tm_mday = bcd2bin(data[RTC_DATE]); | ||
| 91 | tm->tm_mon = bcd2bin(data[RTC_MONTH]); | ||
| 92 | tm->tm_year = bcd2bin(data[RTC_YEAR1]) + bcd2bin(data[RTC_YEAR2]) * 100; | ||
| 93 | tm->tm_year -= 1900; | ||
| 94 | } | ||
| 95 | |||
| 96 | static void max8998_tm_to_data(struct rtc_time *tm, u8 *data) | ||
| 97 | { | ||
| 98 | data[RTC_SEC] = bin2bcd(tm->tm_sec); | ||
| 99 | data[RTC_MIN] = bin2bcd(tm->tm_min); | ||
| 100 | data[RTC_HOUR] = bin2bcd(tm->tm_hour); | ||
| 101 | data[RTC_WEEKDAY] = tm->tm_wday; | ||
| 102 | data[RTC_DATE] = bin2bcd(tm->tm_mday); | ||
| 103 | data[RTC_MONTH] = bin2bcd(tm->tm_mon); | ||
| 104 | data[RTC_YEAR1] = bin2bcd(tm->tm_year % 100); | ||
| 105 | data[RTC_YEAR2] = bin2bcd((tm->tm_year + 1900) / 100); | ||
| 106 | } | ||
| 107 | |||
| 108 | static int max8998_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
| 109 | { | ||
| 110 | struct max8998_rtc_info *info = dev_get_drvdata(dev); | ||
| 111 | u8 data[8]; | ||
| 112 | int ret; | ||
| 113 | |||
| 114 | ret = max8998_bulk_read(info->rtc, MAX8998_RTC_SEC, 8, data); | ||
| 115 | if (ret < 0) | ||
| 116 | return ret; | ||
| 117 | |||
| 118 | max8998_data_to_tm(data, tm); | ||
| 119 | |||
| 120 | return rtc_valid_tm(tm); | ||
| 121 | } | ||
| 122 | |||
| 123 | static int max8998_rtc_set_time(struct device *dev, struct rtc_time *tm) | ||
| 124 | { | ||
| 125 | struct max8998_rtc_info *info = dev_get_drvdata(dev); | ||
| 126 | u8 data[8]; | ||
| 127 | |||
| 128 | max8998_tm_to_data(tm, data); | ||
| 129 | |||
| 130 | return max8998_bulk_write(info->rtc, MAX8998_RTC_SEC, 8, data); | ||
| 131 | } | ||
| 132 | |||
| 133 | static int max8998_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | ||
| 134 | { | ||
| 135 | struct max8998_rtc_info *info = dev_get_drvdata(dev); | ||
| 136 | u8 data[8]; | ||
| 137 | u8 val; | ||
| 138 | int ret; | ||
| 139 | |||
| 140 | ret = max8998_bulk_read(info->rtc, MAX8998_ALARM0_SEC, 8, data); | ||
| 141 | if (ret < 0) | ||
| 142 | return ret; | ||
| 143 | |||
| 144 | max8998_data_to_tm(data, &alrm->time); | ||
| 145 | |||
| 146 | ret = max8998_read_reg(info->rtc, MAX8998_ALARM0_CONF, &val); | ||
| 147 | if (ret < 0) | ||
| 148 | return ret; | ||
| 149 | |||
| 150 | alrm->enabled = !!val; | ||
| 151 | |||
| 152 | ret = max8998_read_reg(info->rtc, MAX8998_RTC_STATUS, &val); | ||
| 153 | if (ret < 0) | ||
| 154 | return ret; | ||
| 155 | |||
| 156 | if (val & ALARM0_STATUS) | ||
| 157 | alrm->pending = 1; | ||
| 158 | else | ||
| 159 | alrm->pending = 0; | ||
| 160 | |||
| 161 | return 0; | ||
| 162 | } | ||
| 163 | |||
| 164 | static int max8998_rtc_stop_alarm(struct max8998_rtc_info *info) | ||
| 165 | { | ||
| 166 | return max8998_write_reg(info->rtc, MAX8998_ALARM0_CONF, 0); | ||
| 167 | } | ||
| 168 | |||
| 169 | static int max8998_rtc_start_alarm(struct max8998_rtc_info *info) | ||
| 170 | { | ||
| 171 | return max8998_write_reg(info->rtc, MAX8998_ALARM0_CONF, 0x77); | ||
| 172 | } | ||
| 173 | |||
| 174 | static int max8998_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | ||
| 175 | { | ||
| 176 | struct max8998_rtc_info *info = dev_get_drvdata(dev); | ||
| 177 | u8 data[8]; | ||
| 178 | int ret; | ||
| 179 | |||
| 180 | max8998_tm_to_data(&alrm->time, data); | ||
| 181 | |||
| 182 | ret = max8998_rtc_stop_alarm(info); | ||
| 183 | if (ret < 0) | ||
| 184 | return ret; | ||
| 185 | |||
| 186 | ret = max8998_bulk_write(info->rtc, MAX8998_ALARM0_SEC, 8, data); | ||
| 187 | if (ret < 0) | ||
| 188 | return ret; | ||
| 189 | |||
| 190 | if (alrm->enabled) | ||
| 191 | return max8998_rtc_start_alarm(info); | ||
| 192 | |||
| 193 | return 0; | ||
| 194 | } | ||
| 195 | |||
| 196 | static int max8998_rtc_alarm_irq_enable(struct device *dev, | ||
| 197 | unsigned int enabled) | ||
| 198 | { | ||
| 199 | struct max8998_rtc_info *info = dev_get_drvdata(dev); | ||
| 200 | |||
| 201 | if (enabled) | ||
| 202 | return max8998_rtc_start_alarm(info); | ||
| 203 | else | ||
| 204 | return max8998_rtc_stop_alarm(info); | ||
| 205 | } | ||
| 206 | |||
| 207 | static irqreturn_t max8998_rtc_alarm_irq(int irq, void *data) | ||
| 208 | { | ||
| 209 | struct max8998_rtc_info *info = data; | ||
| 210 | |||
| 211 | rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF); | ||
| 212 | |||
| 213 | return IRQ_HANDLED; | ||
| 214 | } | ||
| 215 | |||
| 216 | static const struct rtc_class_ops max8998_rtc_ops = { | ||
| 217 | .read_time = max8998_rtc_read_time, | ||
| 218 | .set_time = max8998_rtc_set_time, | ||
| 219 | .read_alarm = max8998_rtc_read_alarm, | ||
| 220 | .set_alarm = max8998_rtc_set_alarm, | ||
| 221 | .alarm_irq_enable = max8998_rtc_alarm_irq_enable, | ||
| 222 | }; | ||
| 223 | |||
| 224 | static int __devinit max8998_rtc_probe(struct platform_device *pdev) | ||
| 225 | { | ||
| 226 | struct max8998_dev *max8998 = dev_get_drvdata(pdev->dev.parent); | ||
| 227 | struct max8998_rtc_info *info; | ||
| 228 | int ret; | ||
| 229 | |||
| 230 | info = kzalloc(sizeof(struct max8998_rtc_info), GFP_KERNEL); | ||
| 231 | if (!info) | ||
| 232 | return -ENOMEM; | ||
| 233 | |||
| 234 | info->dev = &pdev->dev; | ||
| 235 | info->max8998 = max8998; | ||
| 236 | info->rtc = max8998->rtc; | ||
| 237 | info->irq = max8998->irq_base + MAX8998_IRQ_ALARM0; | ||
| 238 | |||
| 239 | info->rtc_dev = rtc_device_register("max8998-rtc", &pdev->dev, | ||
| 240 | &max8998_rtc_ops, THIS_MODULE); | ||
| 241 | |||
| 242 | if (IS_ERR(info->rtc_dev)) { | ||
| 243 | ret = PTR_ERR(info->rtc_dev); | ||
| 244 | dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); | ||
| 245 | goto out_rtc; | ||
| 246 | } | ||
| 247 | |||
| 248 | platform_set_drvdata(pdev, info); | ||
| 249 | |||
| 250 | ret = request_threaded_irq(info->irq, NULL, max8998_rtc_alarm_irq, 0, | ||
| 251 | "rtc-alarm0", info); | ||
| 252 | if (ret < 0) | ||
| 253 | dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", | ||
| 254 | info->irq, ret); | ||
| 255 | |||
| 256 | return 0; | ||
| 257 | |||
| 258 | out_rtc: | ||
| 259 | kfree(info); | ||
| 260 | return ret; | ||
| 261 | } | ||
| 262 | |||
| 263 | static int __devexit max8998_rtc_remove(struct platform_device *pdev) | ||
| 264 | { | ||
| 265 | struct max8998_rtc_info *info = platform_get_drvdata(pdev); | ||
| 266 | |||
| 267 | if (info) { | ||
| 268 | free_irq(info->irq, info); | ||
| 269 | rtc_device_unregister(info->rtc_dev); | ||
| 270 | kfree(info); | ||
| 271 | } | ||
| 272 | |||
| 273 | return 0; | ||
| 274 | } | ||
| 275 | |||
| 276 | static struct platform_driver max8998_rtc_driver = { | ||
| 277 | .driver = { | ||
| 278 | .name = "max8998-rtc", | ||
| 279 | .owner = THIS_MODULE, | ||
| 280 | }, | ||
| 281 | .probe = max8998_rtc_probe, | ||
| 282 | .remove = __devexit_p(max8998_rtc_remove), | ||
| 283 | }; | ||
| 284 | |||
| 285 | static int __init max8998_rtc_init(void) | ||
| 286 | { | ||
| 287 | return platform_driver_register(&max8998_rtc_driver); | ||
| 288 | } | ||
| 289 | module_init(max8998_rtc_init); | ||
| 290 | |||
| 291 | static void __exit max8998_rtc_exit(void) | ||
| 292 | { | ||
| 293 | platform_driver_unregister(&max8998_rtc_driver); | ||
| 294 | } | ||
| 295 | module_exit(max8998_rtc_exit); | ||
| 296 | |||
| 297 | MODULE_AUTHOR("Minkyu Kang <mk7.kang@samsung.com>"); | ||
| 298 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); | ||
| 299 | MODULE_DESCRIPTION("Maxim MAX8998 RTC driver"); | ||
| 300 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/rtc/rtc-mc13783.c b/drivers/rtc/rtc-mc13783.c deleted file mode 100644 index 675bfb515367..000000000000 --- a/drivers/rtc/rtc-mc13783.c +++ /dev/null | |||
| @@ -1,428 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Real Time Clock driver for Freescale MC13783 PMIC | ||
| 3 | * | ||
| 4 | * (C) 2009 Sascha Hauer, Pengutronix | ||
| 5 | * (C) 2009 Uwe Kleine-Koenig, Pengutronix | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License version 2 as | ||
| 9 | * published by the Free Software Foundation. | ||
| 10 | */ | ||
| 11 | |||
| 12 | #include <linux/mfd/mc13783.h> | ||
| 13 | #include <linux/platform_device.h> | ||
| 14 | #include <linux/kernel.h> | ||
| 15 | #include <linux/module.h> | ||
| 16 | #include <linux/slab.h> | ||
| 17 | #include <linux/rtc.h> | ||
| 18 | |||
| 19 | #define DRIVER_NAME "mc13783-rtc" | ||
| 20 | |||
| 21 | #define MC13783_RTCTOD 20 | ||
| 22 | #define MC13783_RTCTODA 21 | ||
| 23 | #define MC13783_RTCDAY 22 | ||
| 24 | #define MC13783_RTCDAYA 23 | ||
| 25 | |||
| 26 | struct mc13783_rtc { | ||
| 27 | struct rtc_device *rtc; | ||
| 28 | struct mc13783 *mc13783; | ||
| 29 | int valid; | ||
| 30 | }; | ||
| 31 | |||
| 32 | static int mc13783_rtc_irq_enable_unlocked(struct device *dev, | ||
| 33 | unsigned int enabled, int irq) | ||
| 34 | { | ||
| 35 | struct mc13783_rtc *priv = dev_get_drvdata(dev); | ||
| 36 | int (*func)(struct mc13783 *mc13783, int irq); | ||
| 37 | |||
| 38 | if (!priv->valid) | ||
| 39 | return -ENODATA; | ||
| 40 | |||
| 41 | func = enabled ? mc13783_irq_unmask : mc13783_irq_mask; | ||
| 42 | return func(priv->mc13783, irq); | ||
| 43 | } | ||
| 44 | |||
| 45 | static int mc13783_rtc_irq_enable(struct device *dev, | ||
| 46 | unsigned int enabled, int irq) | ||
| 47 | { | ||
| 48 | struct mc13783_rtc *priv = dev_get_drvdata(dev); | ||
| 49 | int ret; | ||
| 50 | |||
| 51 | mc13783_lock(priv->mc13783); | ||
| 52 | |||
| 53 | ret = mc13783_rtc_irq_enable_unlocked(dev, enabled, irq); | ||
| 54 | |||
| 55 | mc13783_unlock(priv->mc13783); | ||
| 56 | |||
| 57 | return ret; | ||
| 58 | } | ||
| 59 | |||
| 60 | static int mc13783_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
| 61 | { | ||
| 62 | struct mc13783_rtc *priv = dev_get_drvdata(dev); | ||
| 63 | unsigned int seconds, days1, days2; | ||
| 64 | unsigned long s1970; | ||
| 65 | int ret; | ||
| 66 | |||
| 67 | mc13783_lock(priv->mc13783); | ||
| 68 | |||
| 69 | if (!priv->valid) { | ||
| 70 | ret = -ENODATA; | ||
| 71 | goto out; | ||
| 72 | } | ||
| 73 | |||
| 74 | ret = mc13783_reg_read(priv->mc13783, MC13783_RTCDAY, &days1); | ||
| 75 | if (unlikely(ret)) | ||
| 76 | goto out; | ||
| 77 | |||
| 78 | ret = mc13783_reg_read(priv->mc13783, MC13783_RTCTOD, &seconds); | ||
| 79 | if (unlikely(ret)) | ||
| 80 | goto out; | ||
| 81 | |||
| 82 | ret = mc13783_reg_read(priv->mc13783, MC13783_RTCDAY, &days2); | ||
| 83 | out: | ||
| 84 | mc13783_unlock(priv->mc13783); | ||
| 85 | |||
| 86 | if (ret) | ||
| 87 | return ret; | ||
| 88 | |||
| 89 | if (days2 == days1 + 1) { | ||
| 90 | if (seconds >= 86400 / 2) | ||
| 91 | days2 = days1; | ||
| 92 | else | ||
| 93 | days1 = days2; | ||
| 94 | } | ||
| 95 | |||
| 96 | if (days1 != days2) | ||
| 97 | return -EIO; | ||
| 98 | |||
| 99 | s1970 = days1 * 86400 + seconds; | ||
| 100 | |||
| 101 | rtc_time_to_tm(s1970, tm); | ||
| 102 | |||
| 103 | return rtc_valid_tm(tm); | ||
| 104 | } | ||
| 105 | |||
| 106 | static int mc13783_rtc_set_mmss(struct device *dev, unsigned long secs) | ||
| 107 | { | ||
| 108 | struct mc13783_rtc *priv = dev_get_drvdata(dev); | ||
| 109 | unsigned int seconds, days; | ||
| 110 | unsigned int alarmseconds; | ||
| 111 | int ret; | ||
| 112 | |||
| 113 | seconds = secs % 86400; | ||
| 114 | days = secs / 86400; | ||
| 115 | |||
| 116 | mc13783_lock(priv->mc13783); | ||
| 117 | |||
| 118 | /* | ||
| 119 | * temporarily invalidate alarm to prevent triggering it when the day is | ||
| 120 | * already updated while the time isn't yet. | ||
| 121 | */ | ||
| 122 | ret = mc13783_reg_read(priv->mc13783, MC13783_RTCTODA, &alarmseconds); | ||
| 123 | if (unlikely(ret)) | ||
| 124 | goto out; | ||
| 125 | |||
| 126 | if (alarmseconds < 86400) { | ||
| 127 | ret = mc13783_reg_write(priv->mc13783, | ||
| 128 | MC13783_RTCTODA, 0x1ffff); | ||
| 129 | if (unlikely(ret)) | ||
| 130 | goto out; | ||
| 131 | } | ||
| 132 | |||
| 133 | /* | ||
| 134 | * write seconds=0 to prevent a day switch between writing days | ||
| 135 | * and seconds below | ||
| 136 | */ | ||
| 137 | ret = mc13783_reg_write(priv->mc13783, MC13783_RTCTOD, 0); | ||
| 138 | if (unlikely(ret)) | ||
| 139 | goto out; | ||
| 140 | |||
| 141 | ret = mc13783_reg_write(priv->mc13783, MC13783_RTCDAY, days); | ||
| 142 | if (unlikely(ret)) | ||
| 143 | goto out; | ||
| 144 | |||
| 145 | ret = mc13783_reg_write(priv->mc13783, MC13783_RTCTOD, seconds); | ||
| 146 | if (unlikely(ret)) | ||
| 147 | goto out; | ||
| 148 | |||
| 149 | /* restore alarm */ | ||
| 150 | if (alarmseconds < 86400) { | ||
| 151 | ret = mc13783_reg_write(priv->mc13783, | ||
| 152 | MC13783_RTCTODA, alarmseconds); | ||
| 153 | if (unlikely(ret)) | ||
| 154 | goto out; | ||
| 155 | } | ||
| 156 | |||
| 157 | ret = mc13783_irq_ack(priv->mc13783, MC13783_IRQ_RTCRST); | ||
| 158 | if (unlikely(ret)) | ||
| 159 | goto out; | ||
| 160 | |||
| 161 | ret = mc13783_irq_unmask(priv->mc13783, MC13783_IRQ_RTCRST); | ||
| 162 | out: | ||
| 163 | priv->valid = !ret; | ||
| 164 | |||
| 165 | mc13783_unlock(priv->mc13783); | ||
| 166 | |||
| 167 | return ret; | ||
| 168 | } | ||
| 169 | |||
| 170 | static int mc13783_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 171 | { | ||
| 172 | struct mc13783_rtc *priv = dev_get_drvdata(dev); | ||
| 173 | unsigned seconds, days; | ||
| 174 | unsigned long s1970; | ||
| 175 | int enabled, pending; | ||
| 176 | int ret; | ||
| 177 | |||
| 178 | mc13783_lock(priv->mc13783); | ||
| 179 | |||
| 180 | ret = mc13783_reg_read(priv->mc13783, MC13783_RTCTODA, &seconds); | ||
| 181 | if (unlikely(ret)) | ||
| 182 | goto out; | ||
| 183 | if (seconds >= 86400) { | ||
| 184 | ret = -ENODATA; | ||
| 185 | goto out; | ||
| 186 | } | ||
| 187 | |||
| 188 | ret = mc13783_reg_read(priv->mc13783, MC13783_RTCDAY, &days); | ||
| 189 | if (unlikely(ret)) | ||
| 190 | goto out; | ||
| 191 | |||
| 192 | ret = mc13783_irq_status(priv->mc13783, MC13783_IRQ_TODA, | ||
| 193 | &enabled, &pending); | ||
| 194 | |||
| 195 | out: | ||
| 196 | mc13783_unlock(priv->mc13783); | ||
| 197 | |||
| 198 | if (ret) | ||
| 199 | return ret; | ||
| 200 | |||
| 201 | alarm->enabled = enabled; | ||
| 202 | alarm->pending = pending; | ||
| 203 | |||
| 204 | s1970 = days * 86400 + seconds; | ||
| 205 | |||
| 206 | rtc_time_to_tm(s1970, &alarm->time); | ||
| 207 | dev_dbg(dev, "%s: %lu\n", __func__, s1970); | ||
| 208 | |||
| 209 | return 0; | ||
| 210 | } | ||
| 211 | |||
| 212 | static int mc13783_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 213 | { | ||
| 214 | struct mc13783_rtc *priv = dev_get_drvdata(dev); | ||
| 215 | unsigned long s1970; | ||
| 216 | unsigned seconds, days; | ||
| 217 | int ret; | ||
| 218 | |||
| 219 | mc13783_lock(priv->mc13783); | ||
| 220 | |||
| 221 | /* disable alarm to prevent false triggering */ | ||
| 222 | ret = mc13783_reg_write(priv->mc13783, MC13783_RTCTODA, 0x1ffff); | ||
| 223 | if (unlikely(ret)) | ||
| 224 | goto out; | ||
| 225 | |||
| 226 | ret = mc13783_irq_ack(priv->mc13783, MC13783_IRQ_TODA); | ||
| 227 | if (unlikely(ret)) | ||
| 228 | goto out; | ||
| 229 | |||
| 230 | ret = rtc_tm_to_time(&alarm->time, &s1970); | ||
| 231 | if (unlikely(ret)) | ||
| 232 | goto out; | ||
| 233 | |||
| 234 | dev_dbg(dev, "%s: o%2.s %lu\n", __func__, alarm->enabled ? "n" : "ff", | ||
| 235 | s1970); | ||
| 236 | |||
| 237 | ret = mc13783_rtc_irq_enable_unlocked(dev, alarm->enabled, | ||
| 238 | MC13783_IRQ_TODA); | ||
| 239 | if (unlikely(ret)) | ||
| 240 | goto out; | ||
| 241 | |||
| 242 | seconds = s1970 % 86400; | ||
| 243 | days = s1970 / 86400; | ||
| 244 | |||
| 245 | ret = mc13783_reg_write(priv->mc13783, MC13783_RTCDAYA, days); | ||
| 246 | if (unlikely(ret)) | ||
| 247 | goto out; | ||
| 248 | |||
| 249 | ret = mc13783_reg_write(priv->mc13783, MC13783_RTCTODA, seconds); | ||
| 250 | |||
| 251 | out: | ||
| 252 | mc13783_unlock(priv->mc13783); | ||
| 253 | |||
| 254 | return ret; | ||
| 255 | } | ||
| 256 | |||
| 257 | static irqreturn_t mc13783_rtc_alarm_handler(int irq, void *dev) | ||
| 258 | { | ||
| 259 | struct mc13783_rtc *priv = dev; | ||
| 260 | struct mc13783 *mc13783 = priv->mc13783; | ||
| 261 | |||
| 262 | dev_dbg(&priv->rtc->dev, "Alarm\n"); | ||
| 263 | |||
| 264 | rtc_update_irq(priv->rtc, 1, RTC_IRQF | RTC_AF); | ||
| 265 | |||
| 266 | mc13783_irq_ack(mc13783, irq); | ||
| 267 | |||
| 268 | return IRQ_HANDLED; | ||
| 269 | } | ||
| 270 | |||
| 271 | static irqreturn_t mc13783_rtc_update_handler(int irq, void *dev) | ||
| 272 | { | ||
| 273 | struct mc13783_rtc *priv = dev; | ||
| 274 | struct mc13783 *mc13783 = priv->mc13783; | ||
| 275 | |||
| 276 | dev_dbg(&priv->rtc->dev, "1HZ\n"); | ||
| 277 | |||
| 278 | rtc_update_irq(priv->rtc, 1, RTC_IRQF | RTC_UF); | ||
| 279 | |||
| 280 | mc13783_irq_ack(mc13783, irq); | ||
| 281 | |||
| 282 | return IRQ_HANDLED; | ||
| 283 | } | ||
| 284 | |||
| 285 | static int mc13783_rtc_update_irq_enable(struct device *dev, | ||
| 286 | unsigned int enabled) | ||
| 287 | { | ||
| 288 | return mc13783_rtc_irq_enable(dev, enabled, MC13783_IRQ_1HZ); | ||
| 289 | } | ||
| 290 | |||
| 291 | static int mc13783_rtc_alarm_irq_enable(struct device *dev, | ||
| 292 | unsigned int enabled) | ||
| 293 | { | ||
| 294 | return mc13783_rtc_irq_enable(dev, enabled, MC13783_IRQ_TODA); | ||
| 295 | } | ||
| 296 | |||
| 297 | static const struct rtc_class_ops mc13783_rtc_ops = { | ||
| 298 | .read_time = mc13783_rtc_read_time, | ||
| 299 | .set_mmss = mc13783_rtc_set_mmss, | ||
| 300 | .read_alarm = mc13783_rtc_read_alarm, | ||
| 301 | .set_alarm = mc13783_rtc_set_alarm, | ||
| 302 | .alarm_irq_enable = mc13783_rtc_alarm_irq_enable, | ||
| 303 | .update_irq_enable = mc13783_rtc_update_irq_enable, | ||
| 304 | }; | ||
| 305 | |||
| 306 | static irqreturn_t mc13783_rtc_reset_handler(int irq, void *dev) | ||
| 307 | { | ||
| 308 | struct mc13783_rtc *priv = dev; | ||
| 309 | struct mc13783 *mc13783 = priv->mc13783; | ||
| 310 | |||
| 311 | dev_dbg(&priv->rtc->dev, "RTCRST\n"); | ||
| 312 | priv->valid = 0; | ||
| 313 | |||
| 314 | mc13783_irq_mask(mc13783, irq); | ||
| 315 | |||
| 316 | return IRQ_HANDLED; | ||
| 317 | } | ||
| 318 | |||
| 319 | static int __devinit mc13783_rtc_probe(struct platform_device *pdev) | ||
| 320 | { | ||
| 321 | int ret; | ||
| 322 | struct mc13783_rtc *priv; | ||
| 323 | struct mc13783 *mc13783; | ||
| 324 | int rtcrst_pending; | ||
| 325 | |||
| 326 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | ||
| 327 | if (!priv) | ||
| 328 | return -ENOMEM; | ||
| 329 | |||
| 330 | mc13783 = dev_get_drvdata(pdev->dev.parent); | ||
| 331 | priv->mc13783 = mc13783; | ||
| 332 | |||
| 333 | platform_set_drvdata(pdev, priv); | ||
| 334 | |||
| 335 | mc13783_lock(mc13783); | ||
| 336 | |||
| 337 | ret = mc13783_irq_request(mc13783, MC13783_IRQ_RTCRST, | ||
| 338 | mc13783_rtc_reset_handler, DRIVER_NAME, priv); | ||
| 339 | if (ret) | ||
| 340 | goto err_reset_irq_request; | ||
| 341 | |||
| 342 | ret = mc13783_irq_status(mc13783, MC13783_IRQ_RTCRST, | ||
| 343 | NULL, &rtcrst_pending); | ||
| 344 | if (ret) | ||
| 345 | goto err_reset_irq_status; | ||
| 346 | |||
| 347 | priv->valid = !rtcrst_pending; | ||
| 348 | |||
| 349 | ret = mc13783_irq_request_nounmask(mc13783, MC13783_IRQ_1HZ, | ||
| 350 | mc13783_rtc_update_handler, DRIVER_NAME, priv); | ||
| 351 | if (ret) | ||
| 352 | goto err_update_irq_request; | ||
| 353 | |||
| 354 | ret = mc13783_irq_request_nounmask(mc13783, MC13783_IRQ_TODA, | ||
| 355 | mc13783_rtc_alarm_handler, DRIVER_NAME, priv); | ||
| 356 | if (ret) | ||
| 357 | goto err_alarm_irq_request; | ||
| 358 | |||
| 359 | priv->rtc = rtc_device_register(pdev->name, | ||
| 360 | &pdev->dev, &mc13783_rtc_ops, THIS_MODULE); | ||
| 361 | if (IS_ERR(priv->rtc)) { | ||
| 362 | ret = PTR_ERR(priv->rtc); | ||
| 363 | |||
| 364 | mc13783_irq_free(mc13783, MC13783_IRQ_TODA, priv); | ||
| 365 | err_alarm_irq_request: | ||
| 366 | |||
| 367 | mc13783_irq_free(mc13783, MC13783_IRQ_1HZ, priv); | ||
| 368 | err_update_irq_request: | ||
| 369 | |||
| 370 | err_reset_irq_status: | ||
| 371 | |||
| 372 | mc13783_irq_free(mc13783, MC13783_IRQ_RTCRST, priv); | ||
| 373 | err_reset_irq_request: | ||
| 374 | |||
| 375 | platform_set_drvdata(pdev, NULL); | ||
| 376 | kfree(priv); | ||
| 377 | } | ||
| 378 | |||
| 379 | mc13783_unlock(mc13783); | ||
| 380 | |||
| 381 | return ret; | ||
| 382 | } | ||
| 383 | |||
| 384 | static int __devexit mc13783_rtc_remove(struct platform_device *pdev) | ||
| 385 | { | ||
| 386 | struct mc13783_rtc *priv = platform_get_drvdata(pdev); | ||
| 387 | |||
| 388 | mc13783_lock(priv->mc13783); | ||
| 389 | |||
| 390 | rtc_device_unregister(priv->rtc); | ||
| 391 | |||
| 392 | mc13783_irq_free(priv->mc13783, MC13783_IRQ_TODA, priv); | ||
| 393 | mc13783_irq_free(priv->mc13783, MC13783_IRQ_1HZ, priv); | ||
| 394 | mc13783_irq_free(priv->mc13783, MC13783_IRQ_RTCRST, priv); | ||
| 395 | |||
| 396 | mc13783_unlock(priv->mc13783); | ||
| 397 | |||
| 398 | platform_set_drvdata(pdev, NULL); | ||
| 399 | |||
| 400 | kfree(priv); | ||
| 401 | |||
| 402 | return 0; | ||
| 403 | } | ||
| 404 | |||
| 405 | static struct platform_driver mc13783_rtc_driver = { | ||
| 406 | .remove = __devexit_p(mc13783_rtc_remove), | ||
| 407 | .driver = { | ||
| 408 | .name = DRIVER_NAME, | ||
| 409 | .owner = THIS_MODULE, | ||
| 410 | }, | ||
| 411 | }; | ||
| 412 | |||
| 413 | static int __init mc13783_rtc_init(void) | ||
| 414 | { | ||
| 415 | return platform_driver_probe(&mc13783_rtc_driver, &mc13783_rtc_probe); | ||
| 416 | } | ||
| 417 | module_init(mc13783_rtc_init); | ||
| 418 | |||
| 419 | static void __exit mc13783_rtc_exit(void) | ||
| 420 | { | ||
| 421 | platform_driver_unregister(&mc13783_rtc_driver); | ||
| 422 | } | ||
| 423 | module_exit(mc13783_rtc_exit); | ||
| 424 | |||
| 425 | MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); | ||
| 426 | MODULE_DESCRIPTION("RTC driver for Freescale MC13783 PMIC"); | ||
| 427 | MODULE_LICENSE("GPL v2"); | ||
| 428 | MODULE_ALIAS("platform:" DRIVER_NAME); | ||
diff --git a/drivers/rtc/rtc-mc13xxx.c b/drivers/rtc/rtc-mc13xxx.c new file mode 100644 index 000000000000..5314b153bfba --- /dev/null +++ b/drivers/rtc/rtc-mc13xxx.c | |||
| @@ -0,0 +1,437 @@ | |||
| 1 | /* | ||
| 2 | * Real Time Clock driver for Freescale MC13XXX PMIC | ||
| 3 | * | ||
| 4 | * (C) 2009 Sascha Hauer, Pengutronix | ||
| 5 | * (C) 2009 Uwe Kleine-Koenig, Pengutronix | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License version 2 as | ||
| 9 | * published by the Free Software Foundation. | ||
| 10 | */ | ||
| 11 | |||
| 12 | #include <linux/mfd/mc13xxx.h> | ||
| 13 | #include <linux/platform_device.h> | ||
| 14 | #include <linux/kernel.h> | ||
| 15 | #include <linux/module.h> | ||
| 16 | #include <linux/slab.h> | ||
| 17 | #include <linux/rtc.h> | ||
| 18 | |||
| 19 | #define DRIVER_NAME "mc13xxx-rtc" | ||
| 20 | |||
| 21 | #define MC13XXX_RTCTOD 20 | ||
| 22 | #define MC13XXX_RTCTODA 21 | ||
| 23 | #define MC13XXX_RTCDAY 22 | ||
| 24 | #define MC13XXX_RTCDAYA 23 | ||
| 25 | |||
| 26 | struct mc13xxx_rtc { | ||
| 27 | struct rtc_device *rtc; | ||
| 28 | struct mc13xxx *mc13xxx; | ||
| 29 | int valid; | ||
| 30 | }; | ||
| 31 | |||
| 32 | static int mc13xxx_rtc_irq_enable_unlocked(struct device *dev, | ||
| 33 | unsigned int enabled, int irq) | ||
| 34 | { | ||
| 35 | struct mc13xxx_rtc *priv = dev_get_drvdata(dev); | ||
| 36 | int (*func)(struct mc13xxx *mc13xxx, int irq); | ||
| 37 | |||
| 38 | if (!priv->valid) | ||
| 39 | return -ENODATA; | ||
| 40 | |||
| 41 | func = enabled ? mc13xxx_irq_unmask : mc13xxx_irq_mask; | ||
| 42 | return func(priv->mc13xxx, irq); | ||
| 43 | } | ||
| 44 | |||
| 45 | static int mc13xxx_rtc_irq_enable(struct device *dev, | ||
| 46 | unsigned int enabled, int irq) | ||
| 47 | { | ||
| 48 | struct mc13xxx_rtc *priv = dev_get_drvdata(dev); | ||
| 49 | int ret; | ||
| 50 | |||
| 51 | mc13xxx_lock(priv->mc13xxx); | ||
| 52 | |||
| 53 | ret = mc13xxx_rtc_irq_enable_unlocked(dev, enabled, irq); | ||
| 54 | |||
| 55 | mc13xxx_unlock(priv->mc13xxx); | ||
| 56 | |||
| 57 | return ret; | ||
| 58 | } | ||
| 59 | |||
| 60 | static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
| 61 | { | ||
| 62 | struct mc13xxx_rtc *priv = dev_get_drvdata(dev); | ||
| 63 | unsigned int seconds, days1, days2; | ||
| 64 | unsigned long s1970; | ||
| 65 | int ret; | ||
| 66 | |||
| 67 | mc13xxx_lock(priv->mc13xxx); | ||
| 68 | |||
| 69 | if (!priv->valid) { | ||
| 70 | ret = -ENODATA; | ||
| 71 | goto out; | ||
| 72 | } | ||
| 73 | |||
| 74 | ret = mc13xxx_reg_read(priv->mc13xxx, MC13XXX_RTCDAY, &days1); | ||
| 75 | if (unlikely(ret)) | ||
| 76 | goto out; | ||
| 77 | |||
| 78 | ret = mc13xxx_reg_read(priv->mc13xxx, MC13XXX_RTCTOD, &seconds); | ||
| 79 | if (unlikely(ret)) | ||
| 80 | goto out; | ||
| 81 | |||
| 82 | ret = mc13xxx_reg_read(priv->mc13xxx, MC13XXX_RTCDAY, &days2); | ||
| 83 | out: | ||
| 84 | mc13xxx_unlock(priv->mc13xxx); | ||
| 85 | |||
| 86 | if (ret) | ||
| 87 | return ret; | ||
| 88 | |||
| 89 | if (days2 == days1 + 1) { | ||
| 90 | if (seconds >= 86400 / 2) | ||
| 91 | days2 = days1; | ||
| 92 | else | ||
| 93 | days1 = days2; | ||
| 94 | } | ||
| 95 | |||
| 96 | if (days1 != days2) | ||
| 97 | return -EIO; | ||
| 98 | |||
| 99 | s1970 = days1 * 86400 + seconds; | ||
| 100 | |||
| 101 | rtc_time_to_tm(s1970, tm); | ||
| 102 | |||
| 103 | return rtc_valid_tm(tm); | ||
| 104 | } | ||
| 105 | |||
| 106 | static int mc13xxx_rtc_set_mmss(struct device *dev, unsigned long secs) | ||
| 107 | { | ||
| 108 | struct mc13xxx_rtc *priv = dev_get_drvdata(dev); | ||
| 109 | unsigned int seconds, days; | ||
| 110 | unsigned int alarmseconds; | ||
| 111 | int ret; | ||
| 112 | |||
| 113 | seconds = secs % 86400; | ||
| 114 | days = secs / 86400; | ||
| 115 | |||
| 116 | mc13xxx_lock(priv->mc13xxx); | ||
| 117 | |||
| 118 | /* | ||
| 119 | * temporarily invalidate alarm to prevent triggering it when the day is | ||
| 120 | * already updated while the time isn't yet. | ||
| 121 | */ | ||
| 122 | ret = mc13xxx_reg_read(priv->mc13xxx, MC13XXX_RTCTODA, &alarmseconds); | ||
| 123 | if (unlikely(ret)) | ||
| 124 | goto out; | ||
| 125 | |||
| 126 | if (alarmseconds < 86400) { | ||
| 127 | ret = mc13xxx_reg_write(priv->mc13xxx, | ||
| 128 | MC13XXX_RTCTODA, 0x1ffff); | ||
| 129 | if (unlikely(ret)) | ||
| 130 | goto out; | ||
| 131 | } | ||
| 132 | |||
| 133 | /* | ||
| 134 | * write seconds=0 to prevent a day switch between writing days | ||
| 135 | * and seconds below | ||
| 136 | */ | ||
| 137 | ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCTOD, 0); | ||
| 138 | if (unlikely(ret)) | ||
| 139 | goto out; | ||
| 140 | |||
| 141 | ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCDAY, days); | ||
| 142 | if (unlikely(ret)) | ||
| 143 | goto out; | ||
| 144 | |||
| 145 | ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCTOD, seconds); | ||
| 146 | if (unlikely(ret)) | ||
| 147 | goto out; | ||
| 148 | |||
| 149 | /* restore alarm */ | ||
| 150 | if (alarmseconds < 86400) { | ||
| 151 | ret = mc13xxx_reg_write(priv->mc13xxx, | ||
| 152 | MC13XXX_RTCTODA, alarmseconds); | ||
| 153 | if (unlikely(ret)) | ||
| 154 | goto out; | ||
| 155 | } | ||
| 156 | |||
| 157 | ret = mc13xxx_irq_ack(priv->mc13xxx, MC13XXX_IRQ_RTCRST); | ||
| 158 | if (unlikely(ret)) | ||
| 159 | goto out; | ||
| 160 | |||
| 161 | ret = mc13xxx_irq_unmask(priv->mc13xxx, MC13XXX_IRQ_RTCRST); | ||
| 162 | out: | ||
| 163 | priv->valid = !ret; | ||
| 164 | |||
| 165 | mc13xxx_unlock(priv->mc13xxx); | ||
| 166 | |||
| 167 | return ret; | ||
| 168 | } | ||
| 169 | |||
| 170 | static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 171 | { | ||
| 172 | struct mc13xxx_rtc *priv = dev_get_drvdata(dev); | ||
| 173 | unsigned seconds, days; | ||
| 174 | unsigned long s1970; | ||
| 175 | int enabled, pending; | ||
| 176 | int ret; | ||
| 177 | |||
| 178 | mc13xxx_lock(priv->mc13xxx); | ||
| 179 | |||
| 180 | ret = mc13xxx_reg_read(priv->mc13xxx, MC13XXX_RTCTODA, &seconds); | ||
| 181 | if (unlikely(ret)) | ||
| 182 | goto out; | ||
| 183 | if (seconds >= 86400) { | ||
| 184 | ret = -ENODATA; | ||
| 185 | goto out; | ||
| 186 | } | ||
| 187 | |||
| 188 | ret = mc13xxx_reg_read(priv->mc13xxx, MC13XXX_RTCDAY, &days); | ||
| 189 | if (unlikely(ret)) | ||
| 190 | goto out; | ||
| 191 | |||
| 192 | ret = mc13xxx_irq_status(priv->mc13xxx, MC13XXX_IRQ_TODA, | ||
| 193 | &enabled, &pending); | ||
| 194 | |||
| 195 | out: | ||
| 196 | mc13xxx_unlock(priv->mc13xxx); | ||
| 197 | |||
| 198 | if (ret) | ||
| 199 | return ret; | ||
| 200 | |||
| 201 | alarm->enabled = enabled; | ||
| 202 | alarm->pending = pending; | ||
| 203 | |||
| 204 | s1970 = days * 86400 + seconds; | ||
| 205 | |||
| 206 | rtc_time_to_tm(s1970, &alarm->time); | ||
| 207 | dev_dbg(dev, "%s: %lu\n", __func__, s1970); | ||
| 208 | |||
| 209 | return 0; | ||
| 210 | } | ||
| 211 | |||
| 212 | static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 213 | { | ||
| 214 | struct mc13xxx_rtc *priv = dev_get_drvdata(dev); | ||
| 215 | unsigned long s1970; | ||
| 216 | unsigned seconds, days; | ||
| 217 | int ret; | ||
| 218 | |||
| 219 | mc13xxx_lock(priv->mc13xxx); | ||
| 220 | |||
| 221 | /* disable alarm to prevent false triggering */ | ||
| 222 | ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCTODA, 0x1ffff); | ||
| 223 | if (unlikely(ret)) | ||
| 224 | goto out; | ||
| 225 | |||
| 226 | ret = mc13xxx_irq_ack(priv->mc13xxx, MC13XXX_IRQ_TODA); | ||
| 227 | if (unlikely(ret)) | ||
| 228 | goto out; | ||
| 229 | |||
| 230 | ret = rtc_tm_to_time(&alarm->time, &s1970); | ||
| 231 | if (unlikely(ret)) | ||
| 232 | goto out; | ||
| 233 | |||
| 234 | dev_dbg(dev, "%s: o%2.s %lu\n", __func__, alarm->enabled ? "n" : "ff", | ||
| 235 | s1970); | ||
| 236 | |||
| 237 | ret = mc13xxx_rtc_irq_enable_unlocked(dev, alarm->enabled, | ||
| 238 | MC13XXX_IRQ_TODA); | ||
| 239 | if (unlikely(ret)) | ||
| 240 | goto out; | ||
| 241 | |||
| 242 | seconds = s1970 % 86400; | ||
| 243 | days = s1970 / 86400; | ||
| 244 | |||
| 245 | ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCDAYA, days); | ||
| 246 | if (unlikely(ret)) | ||
| 247 | goto out; | ||
| 248 | |||
| 249 | ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCTODA, seconds); | ||
| 250 | |||
| 251 | out: | ||
| 252 | mc13xxx_unlock(priv->mc13xxx); | ||
| 253 | |||
| 254 | return ret; | ||
| 255 | } | ||
| 256 | |||
| 257 | static irqreturn_t mc13xxx_rtc_alarm_handler(int irq, void *dev) | ||
| 258 | { | ||
| 259 | struct mc13xxx_rtc *priv = dev; | ||
| 260 | struct mc13xxx *mc13xxx = priv->mc13xxx; | ||
| 261 | |||
| 262 | dev_dbg(&priv->rtc->dev, "Alarm\n"); | ||
| 263 | |||
| 264 | rtc_update_irq(priv->rtc, 1, RTC_IRQF | RTC_AF); | ||
| 265 | |||
| 266 | mc13xxx_irq_ack(mc13xxx, irq); | ||
| 267 | |||
| 268 | return IRQ_HANDLED; | ||
| 269 | } | ||
| 270 | |||
| 271 | static irqreturn_t mc13xxx_rtc_update_handler(int irq, void *dev) | ||
| 272 | { | ||
| 273 | struct mc13xxx_rtc *priv = dev; | ||
| 274 | struct mc13xxx *mc13xxx = priv->mc13xxx; | ||
| 275 | |||
| 276 | dev_dbg(&priv->rtc->dev, "1HZ\n"); | ||
| 277 | |||
| 278 | rtc_update_irq(priv->rtc, 1, RTC_IRQF | RTC_UF); | ||
| 279 | |||
| 280 | mc13xxx_irq_ack(mc13xxx, irq); | ||
| 281 | |||
| 282 | return IRQ_HANDLED; | ||
| 283 | } | ||
| 284 | |||
| 285 | static int mc13xxx_rtc_update_irq_enable(struct device *dev, | ||
| 286 | unsigned int enabled) | ||
| 287 | { | ||
| 288 | return mc13xxx_rtc_irq_enable(dev, enabled, MC13XXX_IRQ_1HZ); | ||
| 289 | } | ||
| 290 | |||
| 291 | static int mc13xxx_rtc_alarm_irq_enable(struct device *dev, | ||
| 292 | unsigned int enabled) | ||
| 293 | { | ||
| 294 | return mc13xxx_rtc_irq_enable(dev, enabled, MC13XXX_IRQ_TODA); | ||
| 295 | } | ||
| 296 | |||
| 297 | static const struct rtc_class_ops mc13xxx_rtc_ops = { | ||
| 298 | .read_time = mc13xxx_rtc_read_time, | ||
| 299 | .set_mmss = mc13xxx_rtc_set_mmss, | ||
| 300 | .read_alarm = mc13xxx_rtc_read_alarm, | ||
| 301 | .set_alarm = mc13xxx_rtc_set_alarm, | ||
| 302 | .alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable, | ||
| 303 | .update_irq_enable = mc13xxx_rtc_update_irq_enable, | ||
| 304 | }; | ||
| 305 | |||
| 306 | static irqreturn_t mc13xxx_rtc_reset_handler(int irq, void *dev) | ||
| 307 | { | ||
| 308 | struct mc13xxx_rtc *priv = dev; | ||
| 309 | struct mc13xxx *mc13xxx = priv->mc13xxx; | ||
| 310 | |||
| 311 | dev_dbg(&priv->rtc->dev, "RTCRST\n"); | ||
| 312 | priv->valid = 0; | ||
| 313 | |||
| 314 | mc13xxx_irq_mask(mc13xxx, irq); | ||
| 315 | |||
| 316 | return IRQ_HANDLED; | ||
| 317 | } | ||
| 318 | |||
| 319 | static int __devinit mc13xxx_rtc_probe(struct platform_device *pdev) | ||
| 320 | { | ||
| 321 | int ret; | ||
| 322 | struct mc13xxx_rtc *priv; | ||
| 323 | struct mc13xxx *mc13xxx; | ||
| 324 | int rtcrst_pending; | ||
| 325 | |||
| 326 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | ||
| 327 | if (!priv) | ||
| 328 | return -ENOMEM; | ||
| 329 | |||
| 330 | mc13xxx = dev_get_drvdata(pdev->dev.parent); | ||
| 331 | priv->mc13xxx = mc13xxx; | ||
| 332 | |||
| 333 | platform_set_drvdata(pdev, priv); | ||
| 334 | |||
| 335 | mc13xxx_lock(mc13xxx); | ||
| 336 | |||
| 337 | ret = mc13xxx_irq_request(mc13xxx, MC13XXX_IRQ_RTCRST, | ||
| 338 | mc13xxx_rtc_reset_handler, DRIVER_NAME, priv); | ||
| 339 | if (ret) | ||
| 340 | goto err_reset_irq_request; | ||
| 341 | |||
| 342 | ret = mc13xxx_irq_status(mc13xxx, MC13XXX_IRQ_RTCRST, | ||
| 343 | NULL, &rtcrst_pending); | ||
| 344 | if (ret) | ||
| 345 | goto err_reset_irq_status; | ||
| 346 | |||
| 347 | priv->valid = !rtcrst_pending; | ||
| 348 | |||
| 349 | ret = mc13xxx_irq_request_nounmask(mc13xxx, MC13XXX_IRQ_1HZ, | ||
| 350 | mc13xxx_rtc_update_handler, DRIVER_NAME, priv); | ||
| 351 | if (ret) | ||
| 352 | goto err_update_irq_request; | ||
| 353 | |||
| 354 | ret = mc13xxx_irq_request_nounmask(mc13xxx, MC13XXX_IRQ_TODA, | ||
| 355 | mc13xxx_rtc_alarm_handler, DRIVER_NAME, priv); | ||
| 356 | if (ret) | ||
| 357 | goto err_alarm_irq_request; | ||
| 358 | |||
| 359 | priv->rtc = rtc_device_register(pdev->name, | ||
| 360 | &pdev->dev, &mc13xxx_rtc_ops, THIS_MODULE); | ||
| 361 | if (IS_ERR(priv->rtc)) { | ||
| 362 | ret = PTR_ERR(priv->rtc); | ||
| 363 | |||
| 364 | mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_TODA, priv); | ||
| 365 | err_alarm_irq_request: | ||
| 366 | |||
| 367 | mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_1HZ, priv); | ||
| 368 | err_update_irq_request: | ||
| 369 | |||
| 370 | err_reset_irq_status: | ||
| 371 | |||
| 372 | mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_RTCRST, priv); | ||
| 373 | err_reset_irq_request: | ||
| 374 | |||
| 375 | platform_set_drvdata(pdev, NULL); | ||
| 376 | kfree(priv); | ||
| 377 | } | ||
| 378 | |||
| 379 | mc13xxx_unlock(mc13xxx); | ||
| 380 | |||
| 381 | return ret; | ||
| 382 | } | ||
| 383 | |||
| 384 | static int __devexit mc13xxx_rtc_remove(struct platform_device *pdev) | ||
| 385 | { | ||
| 386 | struct mc13xxx_rtc *priv = platform_get_drvdata(pdev); | ||
| 387 | |||
| 388 | mc13xxx_lock(priv->mc13xxx); | ||
| 389 | |||
| 390 | rtc_device_unregister(priv->rtc); | ||
| 391 | |||
| 392 | mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_TODA, priv); | ||
| 393 | mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_1HZ, priv); | ||
| 394 | mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_RTCRST, priv); | ||
| 395 | |||
| 396 | mc13xxx_unlock(priv->mc13xxx); | ||
| 397 | |||
| 398 | platform_set_drvdata(pdev, NULL); | ||
| 399 | |||
| 400 | kfree(priv); | ||
| 401 | |||
| 402 | return 0; | ||
| 403 | } | ||
| 404 | |||
| 405 | const struct platform_device_id mc13xxx_rtc_idtable[] = { | ||
| 406 | { | ||
| 407 | .name = "mc13783-rtc", | ||
| 408 | }, { | ||
| 409 | .name = "mc13892-rtc", | ||
| 410 | }, | ||
| 411 | }; | ||
| 412 | |||
| 413 | static struct platform_driver mc13xxx_rtc_driver = { | ||
| 414 | .id_table = mc13xxx_rtc_idtable, | ||
| 415 | .remove = __devexit_p(mc13xxx_rtc_remove), | ||
| 416 | .driver = { | ||
| 417 | .name = DRIVER_NAME, | ||
| 418 | .owner = THIS_MODULE, | ||
| 419 | }, | ||
| 420 | }; | ||
| 421 | |||
| 422 | static int __init mc13xxx_rtc_init(void) | ||
| 423 | { | ||
| 424 | return platform_driver_probe(&mc13xxx_rtc_driver, &mc13xxx_rtc_probe); | ||
| 425 | } | ||
| 426 | module_init(mc13xxx_rtc_init); | ||
| 427 | |||
| 428 | static void __exit mc13xxx_rtc_exit(void) | ||
| 429 | { | ||
| 430 | platform_driver_unregister(&mc13xxx_rtc_driver); | ||
| 431 | } | ||
| 432 | module_exit(mc13xxx_rtc_exit); | ||
| 433 | |||
| 434 | MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); | ||
| 435 | MODULE_DESCRIPTION("RTC driver for Freescale MC13XXX PMIC"); | ||
| 436 | MODULE_LICENSE("GPL v2"); | ||
| 437 | MODULE_ALIAS("platform:" DRIVER_NAME); | ||
