Commit 337ce5d1c5759644cea6c47220ce7e84f0398362

Authored by MyungJoo Ham
Committed by Samuel Ortiz
1 parent de8255ccd2

mfd: Support LP3974 RTC

The first releases of LP3974 have a large delay in RTC registers,
which requires 2 seconds of delay after writing to a rtc register
(recommended by National Semiconductor's engineers)
before reading it.

If "rtc_delay" field of the platform data is true, the rtc driver
assumes that such delays are required. Although we have not seen
LP3974s without requiring such delays, we assume that such LP3974s
will be released soon (or they have done so already) and they are
supported by "lp3974" without setting "rtc_delay" at the platform
data.

This patch adds delays with msleep when writing values to RTC registers
if the platform data has rtc_delay set.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

Showing 4 changed files with 83 additions and 8 deletions Side-by-side Diff

drivers/mfd/max8998.c
... ... @@ -42,6 +42,14 @@
42 42 },
43 43 };
44 44  
  45 +static struct mfd_cell lp3974_devs[] = {
  46 + {
  47 + .name = "lp3974-pmic",
  48 + }, {
  49 + .name = "lp3974-rtc",
  50 + },
  51 +};
  52 +
45 53 int max8998_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest)
46 54 {
47 55 struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
48 56  
... ... @@ -146,10 +154,22 @@
146 154  
147 155 max8998_irq_init(max8998);
148 156  
149   - ret = mfd_add_devices(max8998->dev, -1,
150   - max8998_devs, ARRAY_SIZE(max8998_devs),
151   - NULL, 0);
152 157 pm_runtime_set_active(max8998->dev);
  158 +
  159 + switch (id->driver_data) {
  160 + case TYPE_LP3974:
  161 + ret = mfd_add_devices(max8998->dev, -1,
  162 + lp3974_devs, ARRAY_SIZE(lp3974_devs),
  163 + NULL, 0);
  164 + break;
  165 + case TYPE_MAX8998:
  166 + ret = mfd_add_devices(max8998->dev, -1,
  167 + max8998_devs, ARRAY_SIZE(max8998_devs),
  168 + NULL, 0);
  169 + break;
  170 + default:
  171 + ret = -EINVAL;
  172 + }
153 173  
154 174 if (ret < 0)
155 175 goto err;
drivers/regulator/max8998.c
... ... @@ -835,6 +835,12 @@
835 835 return 0;
836 836 }
837 837  
  838 +static const struct platform_device_id max8998_pmic_id[] = {
  839 + { "max8998-pmic", TYPE_MAX8998 },
  840 + { "lp3974-pmic", TYPE_LP3974 },
  841 + { }
  842 +};
  843 +
838 844 static struct platform_driver max8998_pmic_driver = {
839 845 .driver = {
840 846 .name = "max8998-pmic",
... ... @@ -842,6 +848,7 @@
842 848 },
843 849 .probe = max8998_pmic_probe,
844 850 .remove = __devexit_p(max8998_pmic_remove),
  851 + .id_table = max8998_pmic_id,
845 852 };
846 853  
847 854 static int __init max8998_pmic_init(void)
drivers/rtc/rtc-max8998.c
... ... @@ -20,6 +20,7 @@
20 20 #include <linux/platform_device.h>
21 21 #include <linux/mfd/max8998.h>
22 22 #include <linux/mfd/max8998-private.h>
  23 +#include <linux/delay.h>
23 24  
24 25 #define MAX8998_RTC_SEC 0x00
25 26 #define MAX8998_RTC_MIN 0x01
... ... @@ -73,6 +74,7 @@
73 74 struct i2c_client *rtc;
74 75 struct rtc_device *rtc_dev;
75 76 int irq;
  77 + bool lp3974_bug_workaround;
76 78 };
77 79  
78 80 static void max8998_data_to_tm(u8 *data, struct rtc_time *tm)
79 81  
... ... @@ -124,10 +126,16 @@
124 126 {
125 127 struct max8998_rtc_info *info = dev_get_drvdata(dev);
126 128 u8 data[8];
  129 + int ret;
127 130  
128 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 141 static int max8998_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
134 142  
... ... @@ -163,12 +171,29 @@
163 171  
164 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 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 199 static int max8998_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
175 200  
176 201  
... ... @@ -187,10 +212,13 @@
187 212 if (ret < 0)
188 213 return ret;
189 214  
  215 + if (info->lp3974_bug_workaround)
  216 + msleep(2000);
  217 +
190 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 224 static int max8998_rtc_alarm_irq_enable(struct device *dev,
... ... @@ -224,6 +252,7 @@
224 252 static int __devinit max8998_rtc_probe(struct platform_device *pdev)
225 253 {
226 254 struct max8998_dev *max8998 = dev_get_drvdata(pdev->dev.parent);
  255 + struct max8998_platform_data *pdata = dev_get_platdata(max8998->dev);
227 256 struct max8998_rtc_info *info;
228 257 int ret;
229 258  
230 259  
... ... @@ -249,10 +278,18 @@
249 278  
250 279 ret = request_threaded_irq(info->irq, NULL, max8998_rtc_alarm_irq, 0,
251 280 "rtc-alarm0", info);
  281 +
252 282 if (ret < 0)
253 283 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
254 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 293 return 0;
257 294  
258 295 out_rtc:
... ... @@ -273,6 +310,12 @@
273 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 319 static struct platform_driver max8998_rtc_driver = {
277 320 .driver = {
278 321 .name = "max8998-rtc",
... ... @@ -280,6 +323,7 @@
280 323 },
281 324 .probe = max8998_rtc_probe,
282 325 .remove = __devexit_p(max8998_rtc_remove),
  326 + .id_table = max8998_rtc_id,
283 327 };
284 328  
285 329 static int __init max8998_rtc_init(void)
include/linux/mfd/max8998.h
... ... @@ -76,6 +76,9 @@
76 76 * @buck1_set1: BUCK1 gpio pin 1 to set output voltage
77 77 * @buck1_set2: BUCK1 gpio pin 2 to set output voltage
78 78 * @buck2_set3: BUCK2 gpio pin to set output voltage
  79 + * @wakeup: Allow to wake up from suspend
  80 + * @rtc_delay: LP3974 RTC chip bug that requires delay after a register
  81 + * write before reading it.
79 82 */
80 83 struct max8998_platform_data {
81 84 struct max8998_regulator_data *regulators;
... ... @@ -89,6 +92,7 @@
89 92 int buck1_set2;
90 93 int buck2_set3;
91 94 bool wakeup;
  95 + bool rtc_delay;
92 96 };
93 97  
94 98 #endif /* __LINUX_MFD_MAX8998_H */