make uclibc 0.9.30.1 the default
[openwrt.git] / target / linux / s3c24xx / patches-2.6.30 / 056-pcf50633.patch
1 Index: linux-2.6.30-rc6/drivers/mfd/pcf50633-core.c
2 ===================================================================
3 --- linux-2.6.30-rc6.orig/drivers/mfd/pcf50633-core.c   2009-05-16 06:12:57.000000000 +0200
4 +++ linux-2.6.30-rc6/drivers/mfd/pcf50633-core.c        2009-05-18 19:08:33.000000000 +0200
5 @@ -15,6 +15,7 @@
6  #include <linux/kernel.h>
7  #include <linux/device.h>
8  #include <linux/sysfs.h>
9 +#include <linux/device.h>
10  #include <linux/module.h>
11  #include <linux/types.h>
12  #include <linux/interrupt.h>
13 @@ -345,6 +346,8 @@
14                 goto out;
15         }
16  
17 +       pcf50633_reg_write(pcf, PCF50633_REG_OOCSHDWN,  0x04 );  /* defeat 8s death from lowsys on A5 */
18 +
19         /* We immediately read the usb and adapter status. We thus make sure
20          * only of USBINS/USBREM IRQ handlers are called */
21         if (pcf_int[0] & (PCF50633_INT1_USBINS | PCF50633_INT1_USBREM)) {
22 @@ -443,7 +446,8 @@
23         dev_dbg(pcf->dev, "pcf50633_irq\n");
24  
25         get_device(pcf->dev);
26 -       disable_irq(pcf->irq);
27 +       disable_irq_nosync(pcf->irq);
28 +
29         schedule_work(&pcf->irq_work);
30  
31         return IRQ_HANDLED;
32 @@ -482,13 +486,13 @@
33  }
34  
35  #ifdef CONFIG_PM
36 -static int pcf50633_suspend(struct device *dev, pm_message_t state)
37 +static int pcf50633_suspend(struct i2c_client *client, pm_message_t state)
38  {
39         struct pcf50633 *pcf;
40         int ret = 0, i;
41         u8 res[5];
42  
43 -       pcf = dev_get_drvdata(dev);
44 +       pcf = i2c_get_clientdata(client);
45  
46         /* Make sure our interrupt handlers are not called
47          * henceforth */
48 @@ -523,12 +527,12 @@
49         return ret;
50  }
51  
52 -static int pcf50633_resume(struct device *dev)
53 +static int pcf50633_resume(struct i2c_client *client)
54  {
55         struct pcf50633 *pcf;
56         int ret;
57  
58 -       pcf = dev_get_drvdata(dev);
59 +       pcf = i2c_get_clientdata(client);
60  
61         /* Write the saved mask registers */
62         ret = pcf50633_write_block(pcf, PCF50633_REG_INT1M,
63 @@ -625,6 +629,7 @@
64         }
65  
66         if (client->irq) {
67 +               set_irq_handler(client->irq, handle_level_irq);
68                 ret = request_irq(client->irq, pcf50633_irq,
69                                 IRQF_TRIGGER_LOW, "pcf50633", pcf);
70  
71 @@ -683,12 +688,12 @@
72  static struct i2c_driver pcf50633_driver = {
73         .driver = {
74                 .name   = "pcf50633",
75 -               .suspend = pcf50633_suspend,
76 -               .resume = pcf50633_resume,
77         },
78         .id_table = pcf50633_id_table,
79         .probe = pcf50633_probe,
80         .remove = __devexit_p(pcf50633_remove),
81 +       .suspend = pcf50633_suspend,
82 +       .resume = pcf50633_resume,
83  };
84  
85  static int __init pcf50633_init(void)
86 Index: linux-2.6.30-rc6/drivers/power/pcf50633-charger.c
87 ===================================================================
88 --- linux-2.6.30-rc6.orig/drivers/power/pcf50633-charger.c      2009-05-16 06:12:57.000000000 +0200
89 +++ linux-2.6.30-rc6/drivers/power/pcf50633-charger.c   2009-05-18 19:08:33.000000000 +0200
90 @@ -36,6 +36,7 @@
91  
92         struct power_supply usb;
93         struct power_supply adapter;
94 +       struct power_supply ac;
95  
96         struct delayed_work charging_restart_work;
97  };
98 @@ -47,16 +48,21 @@
99         u8 bits;
100         int charging_start = 1;
101         u8 mbcs2, chgmod;
102 +       unsigned int mbcc5;
103  
104 -       if (ma >= 1000)
105 +       if (ma >= 1000) {
106                 bits = PCF50633_MBCC7_USB_1000mA;
107 -       else if (ma >= 500)
108 +               ma = 1000;
109 +       } else if (ma >= 500) {
110                 bits = PCF50633_MBCC7_USB_500mA;
111 -       else if (ma >= 100)
112 +               ma = 500;
113 +       } else if (ma >= 100) {
114                 bits = PCF50633_MBCC7_USB_100mA;
115 -       else {
116 +               ma = 100;
117 +       } else {
118                 bits = PCF50633_MBCC7_USB_SUSPEND;
119                 charging_start = 0;
120 +               ma = 0;
121         }
122  
123         ret = pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_MBCC7,
124 @@ -66,7 +72,22 @@
125         else
126                 dev_info(pcf->dev, "usb curlim to %d mA\n", ma);
127  
128 -       /* Manual charging start */
129 +       /*
130 +        * We limit the charging current to be the USB current limit.
131 +        * The reason is that on pcf50633, when it enters PMU Standby mode,
132 +        * which it does when the device goes "off", the USB current limit
133 +        * reverts to the variant default.  In at least one common case, that
134 +        * default is 500mA.  By setting the charging current to be the same
135 +        * as the USB limit we set here before PMU standby, we enforce it only
136 +        * using the correct amount of current even when the USB current limit
137 +        * gets reset to the wrong thing
138 +        */
139 +
140 +       mbcc5 = (ma << 8) / mbc->pcf->pdata->chg_ref_current_ma;
141 +       if (mbcc5 > 255)
142 +               mbcc5 = 255;
143 +       pcf50633_reg_write(mbc->pcf, PCF50633_REG_MBCC5, mbcc5);
144 +
145         mbcs2 = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2);
146         chgmod = (mbcs2 & PCF50633_MBCS2_MBC_MASK);
147  
148 @@ -81,7 +102,7 @@
149                                 PCF50633_MBCC1_RESUME, PCF50633_MBCC1_RESUME);
150  
151         mbc->usb_active = charging_start;
152 -
153 +       
154         power_supply_changed(&mbc->usb);
155  
156         return ret;
157 @@ -156,9 +177,44 @@
158  
159  static DEVICE_ATTR(usb_curlim, S_IRUGO | S_IWUSR, show_usblim, set_usblim);
160  
161 +static ssize_t
162 +show_chglim(struct device *dev, struct device_attribute *attr, char *buf)
163 +{
164 +       struct pcf50633_mbc *mbc = dev_get_drvdata(dev);
165 +       u8 mbcc5 = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC5);
166 +       unsigned int ma;
167 +
168 +       ma = (mbc->pcf->pdata->chg_ref_current_ma *  mbcc5) >> 8;
169 +
170 +       return sprintf(buf, "%u\n", ma);
171 +}
172 +
173 +static ssize_t set_chglim(struct device *dev,
174 +               struct device_attribute *attr, const char *buf, size_t count)
175 +{
176 +       struct pcf50633_mbc *mbc = dev_get_drvdata(dev);
177 +       unsigned long ma;
178 +       unsigned int mbcc5;
179 +       int ret;
180 +
181 +       ret = strict_strtoul(buf, 10, &ma);
182 +       if (ret)
183 +               return -EINVAL;
184 +
185 +       mbcc5 = (ma << 8) / mbc->pcf->pdata->chg_ref_current_ma;
186 +       if (mbcc5 > 255)
187 +               mbcc5 = 255;
188 +       pcf50633_reg_write(mbc->pcf, PCF50633_REG_MBCC5, mbcc5);
189 +
190 +       return count;
191 +}
192 +
193 +static DEVICE_ATTR(chg_curlim, S_IRUGO | S_IWUSR, show_chglim, set_chglim);
194 +
195  static struct attribute *pcf50633_mbc_sysfs_entries[] = {
196         &dev_attr_chgmode.attr,
197         &dev_attr_usb_curlim.attr,
198 +       &dev_attr_chg_curlim.attr,
199         NULL,
200  };
201  
202 @@ -239,6 +295,7 @@
203  
204         power_supply_changed(&mbc->usb);
205         power_supply_changed(&mbc->adapter);
206 +       power_supply_changed(&mbc->ac);
207  
208         if (mbc->pcf->pdata->mbc_event_callback)
209                 mbc->pcf->pdata->mbc_event_callback(mbc->pcf, irq);
210 @@ -248,8 +305,7 @@
211                         enum power_supply_property psp,
212                         union power_supply_propval *val)
213  {
214 -       struct pcf50633_mbc *mbc = container_of(psy,
215 -                               struct pcf50633_mbc, adapter);
216 +       struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, adapter);
217         int ret = 0;
218  
219         switch (psp) {
220 @@ -269,10 +325,34 @@
221  {
222         struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, usb);
223         int ret = 0;
224 +       u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) &
225 +                                               PCF50633_MBCC7_USB_MASK;
226  
227         switch (psp) {
228         case POWER_SUPPLY_PROP_ONLINE:
229 -               val->intval = mbc->usb_online;
230 +               val->intval = mbc->usb_online &&
231 +                               (usblim <= PCF50633_MBCC7_USB_500mA);
232 +               break;
233 +       default:
234 +               ret = -EINVAL;
235 +               break;
236 +       }
237 +       return ret;
238 +}
239 +
240 +static int ac_get_property(struct power_supply *psy,
241 +                       enum power_supply_property psp,
242 +                       union power_supply_propval *val)
243 +{
244 +       struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, ac);
245 +       int ret = 0;
246 +       u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) &
247 +                                               PCF50633_MBCC7_USB_MASK;
248 +
249 +       switch (psp) {
250 +       case POWER_SUPPLY_PROP_ONLINE:
251 +               val->intval = mbc->usb_online &&
252 +                               (usblim == PCF50633_MBCC7_USB_1000mA);
253                 break;
254         default:
255                 ret = -EINVAL;
256 @@ -337,6 +417,17 @@
257         mbc->usb.supplied_to            = mbc->pcf->pdata->batteries;
258         mbc->usb.num_supplicants        = mbc->pcf->pdata->num_batteries;
259  
260 +       mbc->ac.name                    = "ac";
261 +       mbc->ac.type                    = POWER_SUPPLY_TYPE_MAINS;
262 +       mbc->ac.properties              = power_props;
263 +       mbc->ac.num_properties          = ARRAY_SIZE(power_props);
264 +       mbc->ac.get_property            = ac_get_property;
265 +       mbc->ac.supplied_to             = mbc->pcf->pdata->batteries;
266 +       mbc->ac.num_supplicants         = mbc->pcf->pdata->num_batteries;
267 +
268 +       INIT_DELAYED_WORK(&mbc->charging_restart_work,
269 +                               pcf50633_mbc_charging_restart);
270 +
271         ret = power_supply_register(&pdev->dev, &mbc->adapter);
272         if (ret) {
273                 dev_err(mbc->pcf->dev, "failed to register adapter\n");
274 @@ -352,9 +443,15 @@
275                 return ret;
276         }
277  
278 -       INIT_DELAYED_WORK(&mbc->charging_restart_work,
279 -                               pcf50633_mbc_charging_restart);
280 -
281 +       ret = power_supply_register(&pdev->dev, &mbc->ac);
282 +       if (ret) {
283 +               dev_err(mbc->pcf->dev, "failed to register ac\n");
284 +               power_supply_unregister(&mbc->adapter);
285 +               power_supply_unregister(&mbc->usb);
286 +               kfree(mbc);
287 +               return ret;
288 +       }
289 +       
290         ret = sysfs_create_group(&pdev->dev.kobj, &mbc_attr_group);
291         if (ret)
292                 dev_err(mbc->pcf->dev, "failed to create sysfs entries\n");
293 Index: linux-2.6.30-rc6/drivers/rtc/rtc-pcf50633.c
294 ===================================================================
295 --- linux-2.6.30-rc6.orig/drivers/rtc/rtc-pcf50633.c    2009-05-16 06:12:57.000000000 +0200
296 +++ linux-2.6.30-rc6/drivers/rtc/rtc-pcf50633.c 2009-05-18 19:08:33.000000000 +0200
297 @@ -58,6 +58,7 @@
298  struct pcf50633_rtc {
299         int alarm_enabled;
300         int second_enabled;
301 +       int alarm_pending;
302  
303         struct pcf50633 *pcf;
304         struct rtc_device *rtc_dev;
305 @@ -70,7 +71,7 @@
306         rtc->tm_hour = bcd2bin(pcf->time[PCF50633_TI_HOUR]);
307         rtc->tm_wday = bcd2bin(pcf->time[PCF50633_TI_WKDAY]);
308         rtc->tm_mday = bcd2bin(pcf->time[PCF50633_TI_DAY]);
309 -       rtc->tm_mon = bcd2bin(pcf->time[PCF50633_TI_MONTH]);
310 +       rtc->tm_mon = bcd2bin(pcf->time[PCF50633_TI_MONTH]) - 1;
311         rtc->tm_year = bcd2bin(pcf->time[PCF50633_TI_YEAR]) + 100;
312  }
313  
314 @@ -81,7 +82,7 @@
315         pcf->time[PCF50633_TI_HOUR] = bin2bcd(rtc->tm_hour);
316         pcf->time[PCF50633_TI_WKDAY] = bin2bcd(rtc->tm_wday);
317         pcf->time[PCF50633_TI_DAY] = bin2bcd(rtc->tm_mday);
318 -       pcf->time[PCF50633_TI_MONTH] = bin2bcd(rtc->tm_mon);
319 +       pcf->time[PCF50633_TI_MONTH] = bin2bcd(rtc->tm_mon + 1);
320         pcf->time[PCF50633_TI_YEAR] = bin2bcd(rtc->tm_year % 100);
321  }
322  
323 @@ -209,6 +210,7 @@
324         rtc = dev_get_drvdata(dev);
325  
326         alrm->enabled = rtc->alarm_enabled;
327 +       alrm->pending = rtc->alarm_pending;
328  
329         ret = pcf50633_read_block(rtc->pcf, PCF50633_REG_RTCSCA,
330                                 PCF50633_TI_EXTENT, &pcf_tm.time[0]);
331 @@ -244,9 +246,12 @@
332         /* Returns 0 on success */
333         ret = pcf50633_write_block(rtc->pcf, PCF50633_REG_RTCSCA,
334                                 PCF50633_TI_EXTENT, &pcf_tm.time[0]);
335 +       if (!alrm->enabled)
336 +               rtc->alarm_pending = 0;
337  
338 -       if (!alarm_masked)
339 +       if (!alarm_masked || alrm->enabled)
340                 pcf50633_irq_unmask(rtc->pcf, PCF50633_IRQ_ALARM);
341 +       rtc->alarm_enabled = alrm->enabled;
342  
343         return ret;
344  }
345 @@ -267,6 +272,7 @@
346         switch (irq) {
347         case PCF50633_IRQ_ALARM:
348                 rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
349 +               rtc->alarm_pending = 1;
350                 break;
351         case PCF50633_IRQ_SECOND:
352                 rtc_update_irq(rtc->rtc_dev, 1, RTC_UF | RTC_IRQF);
353 Index: linux-2.6.30-rc6/include/linux/mfd/pcf50633/core.h
354 ===================================================================
355 --- linux-2.6.30-rc6.orig/include/linux/mfd/pcf50633/core.h     2009-05-16 06:12:57.000000000 +0200
356 +++ linux-2.6.30-rc6/include/linux/mfd/pcf50633/core.h  2009-05-18 19:08:33.000000000 +0200
357 @@ -31,6 +31,8 @@
358  
359         int charging_restart_interval;
360  
361 +       int chg_ref_current_ma;
362 +
363         /* Callbacks */
364         void (*probe_done)(struct pcf50633 *);
365         void (*mbc_event_callback)(struct pcf50633 *, int);
366 @@ -208,7 +210,8 @@
367  };
368  
369  /* misc. registers */
370 -#define PCF50633_REG_OOCSHDWN  0x0c
371 +#define PCF50633_REG_OOCSHDWN          0x0c
372 +#define PCF50633_OOCSHDWN_GOSTDBY      0x01
373  
374  /* LED registers */
375  #define PCF50633_REG_LEDOUT 0x28