diff options
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/rtc-max8998.c | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/drivers/rtc/rtc-max8998.c b/drivers/rtc/rtc-max8998.c index f22dee35f330..3f7bc6b9fefa 100644 --- a/drivers/rtc/rtc-max8998.c +++ b/drivers/rtc/rtc-max8998.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
21 | #include <linux/mfd/max8998.h> | 21 | #include <linux/mfd/max8998.h> |
22 | #include <linux/mfd/max8998-private.h> | 22 | #include <linux/mfd/max8998-private.h> |
23 | #include <linux/delay.h> | ||
23 | 24 | ||
24 | #define MAX8998_RTC_SEC 0x00 | 25 | #define MAX8998_RTC_SEC 0x00 |
25 | #define MAX8998_RTC_MIN 0x01 | 26 | #define MAX8998_RTC_MIN 0x01 |
@@ -73,6 +74,7 @@ struct max8998_rtc_info { | |||
73 | struct i2c_client *rtc; | 74 | struct i2c_client *rtc; |
74 | struct rtc_device *rtc_dev; | 75 | struct rtc_device *rtc_dev; |
75 | int irq; | 76 | int irq; |
77 | bool lp3974_bug_workaround; | ||
76 | }; | 78 | }; |
77 | 79 | ||
78 | static void max8998_data_to_tm(u8 *data, struct rtc_time *tm) | 80 | static void max8998_data_to_tm(u8 *data, struct rtc_time *tm) |
@@ -124,10 +126,16 @@ static int max8998_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
124 | { | 126 | { |
125 | struct max8998_rtc_info *info = dev_get_drvdata(dev); | 127 | struct max8998_rtc_info *info = dev_get_drvdata(dev); |
126 | u8 data[8]; | 128 | u8 data[8]; |
129 | int ret; | ||
127 | 130 | ||
128 | max8998_tm_to_data(tm, data); | 131 | max8998_tm_to_data(tm, data); |
129 | 132 | ||
130 | return max8998_bulk_write(info->rtc, MAX8998_RTC_SEC, 8, data); | 133 | ret = max8998_bulk_write(info->rtc, MAX8998_RTC_SEC, 8, data); |
134 | |||
135 | if (info->lp3974_bug_workaround) | ||
136 | msleep(2000); | ||
137 | |||
138 | return ret; | ||
131 | } | 139 | } |
132 | 140 | ||
133 | static int max8998_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 141 | static int max8998_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
@@ -163,12 +171,29 @@ static int max8998_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
163 | 171 | ||
164 | static int max8998_rtc_stop_alarm(struct max8998_rtc_info *info) | 172 | static int max8998_rtc_stop_alarm(struct max8998_rtc_info *info) |
165 | { | 173 | { |
166 | return max8998_write_reg(info->rtc, MAX8998_ALARM0_CONF, 0); | 174 | int ret = max8998_write_reg(info->rtc, MAX8998_ALARM0_CONF, 0); |
175 | |||
176 | if (info->lp3974_bug_workaround) | ||
177 | msleep(2000); | ||
178 | |||
179 | return ret; | ||
167 | } | 180 | } |
168 | 181 | ||
169 | static int max8998_rtc_start_alarm(struct max8998_rtc_info *info) | 182 | static int max8998_rtc_start_alarm(struct max8998_rtc_info *info) |
170 | { | 183 | { |
171 | return max8998_write_reg(info->rtc, MAX8998_ALARM0_CONF, 0x77); | 184 | int ret; |
185 | u8 alarm0_conf = 0x77; | ||
186 | |||
187 | /* LP3974 with delay bug chips has rtc alarm bugs with "MONTH" field */ | ||
188 | if (info->lp3974_bug_workaround) | ||
189 | alarm0_conf = 0x57; | ||
190 | |||
191 | ret = max8998_write_reg(info->rtc, MAX8998_ALARM0_CONF, alarm0_conf); | ||
192 | |||
193 | if (info->lp3974_bug_workaround) | ||
194 | msleep(2000); | ||
195 | |||
196 | return ret; | ||
172 | } | 197 | } |
173 | 198 | ||
174 | static int max8998_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 199 | static int max8998_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
@@ -187,10 +212,13 @@ static int max8998_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
187 | if (ret < 0) | 212 | if (ret < 0) |
188 | return ret; | 213 | return ret; |
189 | 214 | ||
215 | if (info->lp3974_bug_workaround) | ||
216 | msleep(2000); | ||
217 | |||
190 | if (alrm->enabled) | 218 | if (alrm->enabled) |
191 | return max8998_rtc_start_alarm(info); | 219 | ret = max8998_rtc_start_alarm(info); |
192 | 220 | ||
193 | return 0; | 221 | return ret; |
194 | } | 222 | } |
195 | 223 | ||
196 | static int max8998_rtc_alarm_irq_enable(struct device *dev, | 224 | static int max8998_rtc_alarm_irq_enable(struct device *dev, |
@@ -224,6 +252,7 @@ static const struct rtc_class_ops max8998_rtc_ops = { | |||
224 | static int __devinit max8998_rtc_probe(struct platform_device *pdev) | 252 | static int __devinit max8998_rtc_probe(struct platform_device *pdev) |
225 | { | 253 | { |
226 | struct max8998_dev *max8998 = dev_get_drvdata(pdev->dev.parent); | 254 | struct max8998_dev *max8998 = dev_get_drvdata(pdev->dev.parent); |
255 | struct max8998_platform_data *pdata = dev_get_platdata(max8998->dev); | ||
227 | struct max8998_rtc_info *info; | 256 | struct max8998_rtc_info *info; |
228 | int ret; | 257 | int ret; |
229 | 258 | ||
@@ -249,10 +278,18 @@ static int __devinit max8998_rtc_probe(struct platform_device *pdev) | |||
249 | 278 | ||
250 | ret = request_threaded_irq(info->irq, NULL, max8998_rtc_alarm_irq, 0, | 279 | ret = request_threaded_irq(info->irq, NULL, max8998_rtc_alarm_irq, 0, |
251 | "rtc-alarm0", info); | 280 | "rtc-alarm0", info); |
281 | |||
252 | if (ret < 0) | 282 | if (ret < 0) |
253 | dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", | 283 | dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", |
254 | info->irq, ret); | 284 | info->irq, ret); |
255 | 285 | ||
286 | dev_info(&pdev->dev, "RTC CHIP NAME: %s\n", pdev->id_entry->name); | ||
287 | if (pdata->rtc_delay) { | ||
288 | info->lp3974_bug_workaround = true; | ||
289 | dev_warn(&pdev->dev, "LP3974 with RTC REGERR option." | ||
290 | " RTC updates will be extremely slow.\n"); | ||
291 | } | ||
292 | |||
256 | return 0; | 293 | return 0; |
257 | 294 | ||
258 | out_rtc: | 295 | out_rtc: |
@@ -273,6 +310,12 @@ static int __devexit max8998_rtc_remove(struct platform_device *pdev) | |||
273 | return 0; | 310 | return 0; |
274 | } | 311 | } |
275 | 312 | ||
313 | static const struct platform_device_id max8998_rtc_id[] = { | ||
314 | { "max8998-rtc", TYPE_MAX8998 }, | ||
315 | { "lp3974-rtc", TYPE_LP3974 }, | ||
316 | { } | ||
317 | }; | ||
318 | |||
276 | static struct platform_driver max8998_rtc_driver = { | 319 | static struct platform_driver max8998_rtc_driver = { |
277 | .driver = { | 320 | .driver = { |
278 | .name = "max8998-rtc", | 321 | .name = "max8998-rtc", |
@@ -280,6 +323,7 @@ static struct platform_driver max8998_rtc_driver = { | |||
280 | }, | 323 | }, |
281 | .probe = max8998_rtc_probe, | 324 | .probe = max8998_rtc_probe, |
282 | .remove = __devexit_p(max8998_rtc_remove), | 325 | .remove = __devexit_p(max8998_rtc_remove), |
326 | .id_table = max8998_rtc_id, | ||
283 | }; | 327 | }; |
284 | 328 | ||
285 | static int __init max8998_rtc_init(void) | 329 | static int __init max8998_rtc_init(void) |