1 From 20fb4fd1e317dadaaaaeb9c153098b57d0fc86fe Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Tue, 21 Jul 2009 12:47:03 +0200
4 Subject: [PATCH] 056-pcf50633.patch
7 drivers/mfd/pcf50633-core.c | 16 +++--
8 drivers/power/pcf50633-charger.c | 121 ++++++++++++++++++++++++++++---
9 drivers/regulator/pcf50633-regulator.c | 60 +++++++++++++---
10 drivers/rtc/rtc-pcf50633.c | 12 +++-
11 include/linux/mfd/pcf50633/core.h | 5 +-
12 5 files changed, 180 insertions(+), 34 deletions(-)
14 diff --git a/drivers/mfd/pcf50633-core.c b/drivers/mfd/pcf50633-core.c
15 index 8d3c38b..e81c967 100644
16 --- a/drivers/mfd/pcf50633-core.c
17 +++ b/drivers/mfd/pcf50633-core.c
19 #include <linux/kernel.h>
20 #include <linux/device.h>
21 #include <linux/sysfs.h>
22 +#include <linux/device.h>
23 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/interrupt.h>
26 @@ -345,6 +346,8 @@ static void pcf50633_irq_worker(struct work_struct *work)
30 + pcf50633_reg_write(pcf, PCF50633_REG_OOCSHDWN, 0x04 ); /* defeat 8s death from lowsys on A5 */
32 /* We immediately read the usb and adapter status. We thus make sure
33 * only of USBINS/USBREM IRQ handlers are called */
34 if (pcf_int[0] & (PCF50633_INT1_USBINS | PCF50633_INT1_USBREM)) {
35 @@ -482,13 +485,13 @@ pcf50633_client_dev_register(struct pcf50633 *pcf, const char *name,
39 -static int pcf50633_suspend(struct device *dev, pm_message_t state)
40 +static int pcf50633_suspend(struct i2c_client *client, pm_message_t state)
46 - pcf = dev_get_drvdata(dev);
47 + pcf = i2c_get_clientdata(client);
49 /* Make sure our interrupt handlers are not called
51 @@ -523,12 +526,12 @@ out:
55 -static int pcf50633_resume(struct device *dev)
56 +static int pcf50633_resume(struct i2c_client *client)
61 - pcf = dev_get_drvdata(dev);
62 + pcf = i2c_get_clientdata(client);
64 /* Write the saved mask registers */
65 ret = pcf50633_write_block(pcf, PCF50633_REG_INT1M,
66 @@ -625,6 +628,7 @@ static int __devinit pcf50633_probe(struct i2c_client *client,
70 + set_irq_handler(client->irq, handle_level_irq);
71 ret = request_irq(client->irq, pcf50633_irq,
72 IRQF_TRIGGER_LOW, "pcf50633", pcf);
74 @@ -683,12 +687,12 @@ static struct i2c_device_id pcf50633_id_table[] = {
75 static struct i2c_driver pcf50633_driver = {
78 - .suspend = pcf50633_suspend,
79 - .resume = pcf50633_resume,
81 .id_table = pcf50633_id_table,
82 .probe = pcf50633_probe,
83 .remove = __devexit_p(pcf50633_remove),
84 + .suspend = pcf50633_suspend,
85 + .resume = pcf50633_resume,
88 static int __init pcf50633_init(void)
89 diff --git a/drivers/power/pcf50633-charger.c b/drivers/power/pcf50633-charger.c
90 index e8b278f..41fa421 100644
91 --- a/drivers/power/pcf50633-charger.c
92 +++ b/drivers/power/pcf50633-charger.c
93 @@ -36,6 +36,7 @@ struct pcf50633_mbc {
95 struct power_supply usb;
96 struct power_supply adapter;
97 + struct power_supply ac;
99 struct delayed_work charging_restart_work;
101 @@ -47,16 +48,21 @@ int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
103 int charging_start = 1;
105 + unsigned int mbcc5;
109 bits = PCF50633_MBCC7_USB_1000mA;
110 - else if (ma >= 500)
112 + } else if (ma >= 500) {
113 bits = PCF50633_MBCC7_USB_500mA;
114 - else if (ma >= 100)
116 + } else if (ma >= 100) {
117 bits = PCF50633_MBCC7_USB_100mA;
121 bits = PCF50633_MBCC7_USB_SUSPEND;
126 ret = pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_MBCC7,
127 @@ -66,7 +72,22 @@ int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
129 dev_info(pcf->dev, "usb curlim to %d mA\n", ma);
131 - /* Manual charging start */
133 + * We limit the charging current to be the USB current limit.
134 + * The reason is that on pcf50633, when it enters PMU Standby mode,
135 + * which it does when the device goes "off", the USB current limit
136 + * reverts to the variant default. In at least one common case, that
137 + * default is 500mA. By setting the charging current to be the same
138 + * as the USB limit we set here before PMU standby, we enforce it only
139 + * using the correct amount of current even when the USB current limit
140 + * gets reset to the wrong thing
143 + mbcc5 = (ma << 8) / mbc->pcf->pdata->chg_ref_current_ma;
146 + pcf50633_reg_write(mbc->pcf, PCF50633_REG_MBCC5, mbcc5);
148 mbcs2 = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2);
149 chgmod = (mbcs2 & PCF50633_MBCS2_MBC_MASK);
151 @@ -81,7 +102,7 @@ int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
152 PCF50633_MBCC1_RESUME, PCF50633_MBCC1_RESUME);
154 mbc->usb_active = charging_start;
157 power_supply_changed(&mbc->usb);
160 @@ -156,9 +177,44 @@ static ssize_t set_usblim(struct device *dev,
162 static DEVICE_ATTR(usb_curlim, S_IRUGO | S_IWUSR, show_usblim, set_usblim);
165 +show_chglim(struct device *dev, struct device_attribute *attr, char *buf)
167 + struct pcf50633_mbc *mbc = dev_get_drvdata(dev);
168 + u8 mbcc5 = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC5);
171 + ma = (mbc->pcf->pdata->chg_ref_current_ma * mbcc5) >> 8;
173 + return sprintf(buf, "%u\n", ma);
176 +static ssize_t set_chglim(struct device *dev,
177 + struct device_attribute *attr, const char *buf, size_t count)
179 + struct pcf50633_mbc *mbc = dev_get_drvdata(dev);
181 + unsigned int mbcc5;
184 + ret = strict_strtoul(buf, 10, &ma);
188 + mbcc5 = (ma << 8) / mbc->pcf->pdata->chg_ref_current_ma;
191 + pcf50633_reg_write(mbc->pcf, PCF50633_REG_MBCC5, mbcc5);
196 +static DEVICE_ATTR(chg_curlim, S_IRUGO | S_IWUSR, show_chglim, set_chglim);
198 static struct attribute *pcf50633_mbc_sysfs_entries[] = {
199 &dev_attr_chgmode.attr,
200 &dev_attr_usb_curlim.attr,
201 + &dev_attr_chg_curlim.attr,
205 @@ -239,6 +295,7 @@ pcf50633_mbc_irq_handler(int irq, void *data)
207 power_supply_changed(&mbc->usb);
208 power_supply_changed(&mbc->adapter);
209 + power_supply_changed(&mbc->ac);
211 if (mbc->pcf->pdata->mbc_event_callback)
212 mbc->pcf->pdata->mbc_event_callback(mbc->pcf, irq);
213 @@ -248,8 +305,7 @@ static int adapter_get_property(struct power_supply *psy,
214 enum power_supply_property psp,
215 union power_supply_propval *val)
217 - struct pcf50633_mbc *mbc = container_of(psy,
218 - struct pcf50633_mbc, adapter);
219 + struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, adapter);
223 @@ -269,10 +325,34 @@ static int usb_get_property(struct power_supply *psy,
225 struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, usb);
227 + u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) &
228 + PCF50633_MBCC7_USB_MASK;
231 case POWER_SUPPLY_PROP_ONLINE:
232 - val->intval = mbc->usb_online;
233 + val->intval = mbc->usb_online &&
234 + (usblim <= PCF50633_MBCC7_USB_500mA);
243 +static int ac_get_property(struct power_supply *psy,
244 + enum power_supply_property psp,
245 + union power_supply_propval *val)
247 + struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, ac);
249 + u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) &
250 + PCF50633_MBCC7_USB_MASK;
253 + case POWER_SUPPLY_PROP_ONLINE:
254 + val->intval = mbc->usb_online &&
255 + (usblim == PCF50633_MBCC7_USB_1000mA);
259 @@ -337,6 +417,17 @@ static int __devinit pcf50633_mbc_probe(struct platform_device *pdev)
260 mbc->usb.supplied_to = mbc->pcf->pdata->batteries;
261 mbc->usb.num_supplicants = mbc->pcf->pdata->num_batteries;
263 + mbc->ac.name = "ac";
264 + mbc->ac.type = POWER_SUPPLY_TYPE_MAINS;
265 + mbc->ac.properties = power_props;
266 + mbc->ac.num_properties = ARRAY_SIZE(power_props);
267 + mbc->ac.get_property = ac_get_property;
268 + mbc->ac.supplied_to = mbc->pcf->pdata->batteries;
269 + mbc->ac.num_supplicants = mbc->pcf->pdata->num_batteries;
271 + INIT_DELAYED_WORK(&mbc->charging_restart_work,
272 + pcf50633_mbc_charging_restart);
274 ret = power_supply_register(&pdev->dev, &mbc->adapter);
276 dev_err(mbc->pcf->dev, "failed to register adapter\n");
277 @@ -352,9 +443,15 @@ static int __devinit pcf50633_mbc_probe(struct platform_device *pdev)
281 - INIT_DELAYED_WORK(&mbc->charging_restart_work,
282 - pcf50633_mbc_charging_restart);
284 + ret = power_supply_register(&pdev->dev, &mbc->ac);
286 + dev_err(mbc->pcf->dev, "failed to register ac\n");
287 + power_supply_unregister(&mbc->adapter);
288 + power_supply_unregister(&mbc->usb);
293 ret = sysfs_create_group(&pdev->dev.kobj, &mbc_attr_group);
295 dev_err(mbc->pcf->dev, "failed to create sysfs entries\n");
296 diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c
297 index 8e14900..4809789 100644
298 --- a/drivers/regulator/pcf50633-regulator.c
299 +++ b/drivers/regulator/pcf50633-regulator.c
301 #include <linux/mfd/pcf50633/core.h>
302 #include <linux/mfd/pcf50633/pmic.h>
304 -#define PCF50633_REGULATOR(_name, _id) \
305 +#define PCF50633_REGULATOR(_name, _id, _n) \
309 .ops = &pcf50633_regulator_ops, \
310 + .n_voltages = _n, \
311 .type = REGULATOR_VOLTAGE, \
312 .owner = THIS_MODULE, \
314 @@ -193,6 +194,40 @@ static int pcf50633_regulator_get_voltage(struct regulator_dev *rdev)
315 return millivolts * 1000;
318 +static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev,
319 + unsigned int index)
321 + struct pcf50633 *pcf;
322 + int regulator_id, millivolts;
324 + pcf = rdev_get_drvdata(rdev);;
326 + regulator_id = rdev_get_id(rdev);
328 + switch (regulator_id) {
329 + case PCF50633_REGULATOR_AUTO:
330 + millivolts = auto_voltage_value(index + 0x2f);
332 + case PCF50633_REGULATOR_DOWN1:
333 + case PCF50633_REGULATOR_DOWN2:
334 + millivolts = down_voltage_value(index);
336 + case PCF50633_REGULATOR_LDO1:
337 + case PCF50633_REGULATOR_LDO2:
338 + case PCF50633_REGULATOR_LDO3:
339 + case PCF50633_REGULATOR_LDO4:
340 + case PCF50633_REGULATOR_LDO5:
341 + case PCF50633_REGULATOR_LDO6:
342 + case PCF50633_REGULATOR_HCLDO:
343 + millivolts = ldo_voltage_value(index);
349 + return millivolts * 1000;
352 static int pcf50633_regulator_enable(struct regulator_dev *rdev)
354 struct pcf50633 *pcf = rdev_get_drvdata(rdev);
355 @@ -246,6 +281,7 @@ static int pcf50633_regulator_is_enabled(struct regulator_dev *rdev)
356 static struct regulator_ops pcf50633_regulator_ops = {
357 .set_voltage = pcf50633_regulator_set_voltage,
358 .get_voltage = pcf50633_regulator_get_voltage,
359 + .list_voltage = pcf50633_regulator_list_voltage,
360 .enable = pcf50633_regulator_enable,
361 .disable = pcf50633_regulator_disable,
362 .is_enabled = pcf50633_regulator_is_enabled,
363 @@ -253,27 +289,27 @@ static struct regulator_ops pcf50633_regulator_ops = {
365 static struct regulator_desc regulators[] = {
366 [PCF50633_REGULATOR_AUTO] =
367 - PCF50633_REGULATOR("auto", PCF50633_REGULATOR_AUTO),
368 + PCF50633_REGULATOR("auto", PCF50633_REGULATOR_AUTO, 80),
369 [PCF50633_REGULATOR_DOWN1] =
370 - PCF50633_REGULATOR("down1", PCF50633_REGULATOR_DOWN1),
371 + PCF50633_REGULATOR("down1", PCF50633_REGULATOR_DOWN1, 95),
372 [PCF50633_REGULATOR_DOWN2] =
373 - PCF50633_REGULATOR("down2", PCF50633_REGULATOR_DOWN2),
374 + PCF50633_REGULATOR("down2", PCF50633_REGULATOR_DOWN2, 95),
375 [PCF50633_REGULATOR_LDO1] =
376 - PCF50633_REGULATOR("ldo1", PCF50633_REGULATOR_LDO1),
377 + PCF50633_REGULATOR("ldo1", PCF50633_REGULATOR_LDO1, 27),
378 [PCF50633_REGULATOR_LDO2] =
379 - PCF50633_REGULATOR("ldo2", PCF50633_REGULATOR_LDO2),
380 + PCF50633_REGULATOR("ldo2", PCF50633_REGULATOR_LDO2, 27),
381 [PCF50633_REGULATOR_LDO3] =
382 - PCF50633_REGULATOR("ldo3", PCF50633_REGULATOR_LDO3),
383 + PCF50633_REGULATOR("ldo3", PCF50633_REGULATOR_LDO3, 27),
384 [PCF50633_REGULATOR_LDO4] =
385 - PCF50633_REGULATOR("ldo4", PCF50633_REGULATOR_LDO4),
386 + PCF50633_REGULATOR("ldo4", PCF50633_REGULATOR_LDO4, 27),
387 [PCF50633_REGULATOR_LDO5] =
388 - PCF50633_REGULATOR("ldo5", PCF50633_REGULATOR_LDO5),
389 + PCF50633_REGULATOR("ldo5", PCF50633_REGULATOR_LDO5, 27),
390 [PCF50633_REGULATOR_LDO6] =
391 - PCF50633_REGULATOR("ldo6", PCF50633_REGULATOR_LDO6),
392 + PCF50633_REGULATOR("ldo6", PCF50633_REGULATOR_LDO6, 27),
393 [PCF50633_REGULATOR_HCLDO] =
394 - PCF50633_REGULATOR("hcldo", PCF50633_REGULATOR_HCLDO),
395 + PCF50633_REGULATOR("hcldo", PCF50633_REGULATOR_HCLDO, 26),
396 [PCF50633_REGULATOR_MEMLDO] =
397 - PCF50633_REGULATOR("memldo", PCF50633_REGULATOR_MEMLDO),
398 + PCF50633_REGULATOR("memldo", PCF50633_REGULATOR_MEMLDO, 27),
401 static int __devinit pcf50633_regulator_probe(struct platform_device *pdev)
402 diff --git a/drivers/rtc/rtc-pcf50633.c b/drivers/rtc/rtc-pcf50633.c
403 index f4dd87e..8669815 100644
404 --- a/drivers/rtc/rtc-pcf50633.c
405 +++ b/drivers/rtc/rtc-pcf50633.c
406 @@ -58,6 +58,7 @@ struct pcf50633_time {
407 struct pcf50633_rtc {
412 struct pcf50633 *pcf;
413 struct rtc_device *rtc_dev;
414 @@ -70,7 +71,7 @@ static void pcf2rtc_time(struct rtc_time *rtc, struct pcf50633_time *pcf)
415 rtc->tm_hour = bcd2bin(pcf->time[PCF50633_TI_HOUR]);
416 rtc->tm_wday = bcd2bin(pcf->time[PCF50633_TI_WKDAY]);
417 rtc->tm_mday = bcd2bin(pcf->time[PCF50633_TI_DAY]);
418 - rtc->tm_mon = bcd2bin(pcf->time[PCF50633_TI_MONTH]);
419 + rtc->tm_mon = bcd2bin(pcf->time[PCF50633_TI_MONTH]) - 1;
420 rtc->tm_year = bcd2bin(pcf->time[PCF50633_TI_YEAR]) + 100;
423 @@ -81,7 +82,7 @@ static void rtc2pcf_time(struct pcf50633_time *pcf, struct rtc_time *rtc)
424 pcf->time[PCF50633_TI_HOUR] = bin2bcd(rtc->tm_hour);
425 pcf->time[PCF50633_TI_WKDAY] = bin2bcd(rtc->tm_wday);
426 pcf->time[PCF50633_TI_DAY] = bin2bcd(rtc->tm_mday);
427 - pcf->time[PCF50633_TI_MONTH] = bin2bcd(rtc->tm_mon);
428 + pcf->time[PCF50633_TI_MONTH] = bin2bcd(rtc->tm_mon + 1);
429 pcf->time[PCF50633_TI_YEAR] = bin2bcd(rtc->tm_year % 100);
432 @@ -209,6 +210,7 @@ static int pcf50633_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
433 rtc = dev_get_drvdata(dev);
435 alrm->enabled = rtc->alarm_enabled;
436 + alrm->pending = rtc->alarm_pending;
438 ret = pcf50633_read_block(rtc->pcf, PCF50633_REG_RTCSCA,
439 PCF50633_TI_EXTENT, &pcf_tm.time[0]);
440 @@ -244,9 +246,12 @@ static int pcf50633_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
441 /* Returns 0 on success */
442 ret = pcf50633_write_block(rtc->pcf, PCF50633_REG_RTCSCA,
443 PCF50633_TI_EXTENT, &pcf_tm.time[0]);
444 + if (!alrm->enabled)
445 + rtc->alarm_pending = 0;
448 + if (!alarm_masked || alrm->enabled)
449 pcf50633_irq_unmask(rtc->pcf, PCF50633_IRQ_ALARM);
450 + rtc->alarm_enabled = alrm->enabled;
454 @@ -267,6 +272,7 @@ static void pcf50633_rtc_irq(int irq, void *data)
456 case PCF50633_IRQ_ALARM:
457 rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
458 + rtc->alarm_pending = 1;
460 case PCF50633_IRQ_SECOND:
461 rtc_update_irq(rtc->rtc_dev, 1, RTC_UF | RTC_IRQF);
462 diff --git a/include/linux/mfd/pcf50633/core.h b/include/linux/mfd/pcf50633/core.h
463 index c8f51c3..af67b4e 100644
464 --- a/include/linux/mfd/pcf50633/core.h
465 +++ b/include/linux/mfd/pcf50633/core.h
466 @@ -31,6 +31,8 @@ struct pcf50633_platform_data {
468 int charging_restart_interval;
470 + int chg_ref_current_ma;
473 void (*probe_done)(struct pcf50633 *);
474 void (*mbc_event_callback)(struct pcf50633 *, int);
475 @@ -208,7 +210,8 @@ enum pcf50633_reg_int5 {
478 /* misc. registers */
479 -#define PCF50633_REG_OOCSHDWN 0x0c
480 +#define PCF50633_REG_OOCSHDWN 0x0c
481 +#define PCF50633_OOCSHDWN_GOSTDBY 0x01
484 #define PCF50633_REG_LEDOUT 0x28