bq2415x_charger: Add support for offline and 100mA mode
[kernel-power] / kernel-power-2.6.28 / debian / patches / bq2415x_rx51.patch
1 --- kernel-power/drivers/usb/otg/twl4030-usb.c.orig     2012-04-29 17:15:00.195894587 +0200
2 +++ kernel-power/drivers/usb/otg/twl4030-usb.c  2012-04-29 17:18:06.815889128 +0200
3 @@ -37,6 +37,8 @@
4  #include <linux/regulator/consumer.h>
5  #include <linux/err.h>
6  
7 +#include <asm/mach-types.h>
8 +#include <mach/board-rx51.h>
9  
10  /* Register defines */
11  
12 @@ -265,6 +265,9 @@ struct twl4030_usb {
13         u8                      linkstat;
14         u8                      asleep;
15         bool                    irq_enabled;
16 +
17 +       struct delayed_work     work;
18 +       int                     work_inited;
19  };
20  
21  /* internal define on top of container_of */
22 @@ -365,6 +367,13 @@ static enum linkstat twl4030_usb_linksta
23         dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",
24                         status, status, linkstat);
25  
26 +       if (machine_is_nokia_rx51() && rx51_with_charger_detection()) {
27 +               rx51_set_charger(linkstat == USB_LINK_VBUS);
28 +               if (twl->work_inited && linkstat == USB_LINK_VBUS) {
29 +                       schedule_delayed_work(&twl->work, 2 * HZ); /* 2 seconds should be enought */
30 +               }
31 +       }
32 +
33         /* REVISIT this assumes host and peripheral controllers
34          * are registered, and that both are active...
35          */
36 @@ -771,6 +773,11 @@ static int __init twl4030_usb_probe(stru
37          */
38         twl4030_usb_irq(twl->irq, twl);
39  
40 +       if (machine_is_nokia_rx51()) {
41 +               INIT_DELAYED_WORK(&twl->work, rx51_detect_wallcharger);
42 +               twl->work_inited = 1;
43 +       }
44 +
45         dev_info(&pdev->dev, "Initialized TWL4030 USB module\n");
46         return 0;
47  }
48 --- kernel-power/drivers/usb/musb/omap2430.c.orig       2012-04-29 16:34:10.123966221 +0200
49 +++ kernel-power/drivers/usb/musb/omap2430.c    2012-04-29 16:50:48.611937027 +0200
50 @@ -38,6 +38,8 @@
51  #include <mach/hardware.h>
52  #include <mach/mux.h>
53  
54 +#include <mach/board-rx51.h>
55 +
56  #include <linux/i2c/twl4030.h>
57  
58  #include "musb_core.h"
59 @@ -230,6 +232,7 @@ int musb_platform_set_mode(struct musb *
60   
61                  if (machine_is_nokia_rx51()) {
62                          u8 testmode;
63 +                        rx51_enable_charger_detection(0);
64   
65                          musb_platform_resume(musb);
66   
67 @@ -255,6 +259,7 @@ int musb_platform_set_mode(struct musb *
68   
69                          musb_writeb(musb->mregs, MUSB_TESTMODE, 0);
70                         musb_platform_suspend(musb);
71 +                        rx51_enable_charger_detection(1);
72                  }
73   
74                 otg_set_peripheral(musb->xceiv, &musb->g);
75 @@ -434,6 +438,9 @@ void musb_save_ctx_and_suspend(struct us
76  
77         musb->is_charger = 0;
78  
79 +       if (machine_is_nokia_rx51() && rx51_with_charger_detection())
80 +               rx51_set_wallcharger(0);
81 +
82         /* clear constraints */
83         if (musb->board && musb->board->set_pm_limits)
84                 musb->board->set_pm_limits(musb->controller, 0);
85 --- kernel-power/drivers/usb/musb/musb_core.c.orig      2012-04-29 16:57:27.407925369 +0200
86 +++ kernel-power/drivers/usb/musb/musb_core.c   2012-04-29 17:13:39.083896956 +0200
87 @@ -105,6 +105,8 @@
88  #include <asm/mach-types.h>
89  #endif
90  
91 +#include <mach/board-rx51.h>
92 +
93  #include "musb_core.h"
94  
95  
96 @@ -223,6 +224,9 @@ static int musb_charger_detect(struct mu
97         u8              vdat = 0;
98         u8              r;
99  
100 +       if (machine_is_nokia_rx51() && !rx51_with_charger_detection())
101 +               return 0;
102 +
103         msleep(5);
104  
105         /* Using ulpi with musb is quite tricky. The following code
106 @@ -308,6 +315,8 @@ static int musb_charger_detect(struct mu
107                 /* Regulators off */
108                 otg_set_suspend(musb->xceiv, 1);
109                 musb->is_charger = 1;
110 +               if (machine_is_nokia_rx51() && rx51_with_charger_detection())
111 +                       rx51_set_wallcharger(1);
112         } else {
113                 /* enable interrupts */
114                 musb_writeb(musb->mregs, MUSB_INTRUSBE, ctx.intrusbe);
115 @@ -330,6 +330,13 @@ static int musb_charger_detect(struct mu
116         return vdat;
117  }
118  
119 +void rx51_detect_wallcharger(void *work)
120 +{
121 +       if (the_musb)
122 +               musb_charger_detect(the_musb);
123 +}
124 +EXPORT_SYMBOL(rx51_detect_wallcharger);
125 +
126  /*-------------------------------------------------------------------------*/
127  
128  static inline struct musb *dev_to_musb(struct device *dev)
129 --- kernel-power/arch/arm/plat-omap/include/mach/board-rx51.h.orig      2012-04-29 16:39:03.927957628 +0200
130 +++ kernel-power/arch/arm/plat-omap/include/mach/board-rx51.h   2012-04-29 17:14:50.923894858 +0200
131 @@ -39,6 +39,12 @@ extern void rx51_usb_init(void);
132  static inline void rx51_usb_init(void) { }
133  #endif
134  
135 +extern void rx51_set_charger(int connected);
136 +extern void rx51_set_wallcharger(int connected);
137 +extern void rx51_enable_charger_detection(int enable);
138 +extern void rx51_detect_wallcharger(void *work);
139 +extern int rx51_with_charger_detection(void);
140 +
141  extern void omap_bt_init(struct omap_bluetooth_config *bt_config);
142  
143  struct omap_sdrc_params *rx51_get_sdram_timings(void);
144 --- kernel-power/arch/arm/mach-omap2/board-rx51-peripherals.c.orig      2012-04-29 17:18:56.995887664 +0200
145 +++ kernel-power/arch/arm/mach-omap2/board-rx51-peripherals.c   2012-04-29 17:46:57.487838528 +0200
146 @@ -38,6 +38,8 @@
147  #include <mach/omap-pm.h>
148  
149  #include "../../../drivers/input/lirc/lirc_rx51.h"
150 +#include <mach/board-rx51.h>
151 +#include <linux/power/bq2415x_charger.h>
152  
153  #define RX51_DEBUG_BASE                        0x08000000  /* debug board */
154  #define RX51_ETHR_START                        RX51_DEBUG_BASE
155 @@ -563,6 +565,79 @@ static struct i2c_board_info __initdata
156         },
157  };
158  
159 +static int rx51_charger_mode;
160 +static int rx51_charger_connected;
161 +static int rx51_wallcharger_connected;
162 +static int rx51_charger_detection = 1;
163 +
164 +static void *rx51_charger_hook_data;
165 +static void (*rx51_charger_hook)(enum bq2415x_mode mode, void *data);
166 +
167 +static int rx51_charger_set_hook(void (*hook)(enum bq2415x_mode mode, void *data), void *data)
168 +{
169 +       rx51_charger_hook = hook;
170 +       rx51_charger_hook_data = data;
171 +       if (rx51_charger_hook)
172 +               rx51_charger_hook(rx51_charger_mode, rx51_charger_hook_data);
173 +       return 1;
174 +}
175 +
176 +static void rx51_update_charger_mode(void)
177 +{
178 +       enum bq2415x_mode mode;
179 +       if (rx51_charger_connected && rx51_wallcharger_connected)
180 +               mode = BQ2415X_MODE_DEDICATED_CHARGER; /* wallcharger */
181 +       else if (rx51_charger_connected)
182 +               mode = BQ2415X_MODE_HOST_CHARGER; /* usb charger */
183 +       else
184 +               mode = BQ2415X_MODE_OFF; /* no charger */
185 +
186 +       if (rx51_charger_mode == mode)
187 +               return;
188 +
189 +       printk("rx51_update_charger_mode (mode = %d)\n", mode);
190 +       rx51_charger_mode = mode;
191 +
192 +       if (rx51_charger_hook)
193 +               rx51_charger_hook(rx51_charger_mode, rx51_charger_hook_data);
194 +}
195 +
196 +void rx51_set_charger(int connected)
197 +{
198 +       rx51_charger_connected = connected;
199 +       rx51_update_charger_mode();
200 +}
201 +EXPORT_SYMBOL(rx51_set_charger);
202 +
203 +void rx51_set_wallcharger(int connected)
204 +{
205 +       rx51_wallcharger_connected = connected;
206 +       rx51_update_charger_mode();
207 +}
208 +EXPORT_SYMBOL(rx51_set_wallcharger);
209 +
210 +void rx51_enable_charger_detection(int enable)
211 +{
212 +       rx51_charger_detection = enable;
213 +}
214 +EXPORT_SYMBOL(rx51_enable_charger_detection);
215 +
216 +int rx51_with_charger_detection(void)
217 +{
218 +       return rx51_charger_detection;
219 +}
220 +EXPORT_SYMBOL(rx51_with_charger_detection);
221 +
222 +static struct bq2415x_platform_data rx51_bq24150_platform_data = {
223 +       .current_limit = 100,                   /* mA */
224 +       .weak_battery_voltage = 3400,           /* mV */
225 +       .battery_regulation_voltage = 4200,     /* mV */
226 +       .charge_current = 950, /*1200*/         /* mA */
227 +       .termination_current = 100, /*400*/     /* mA */
228 +       .resistor_sense = 68,                   /* m ohm */
229 +       .set_mode_hook = &rx51_charger_set_hook,
230 +};
231 +
232  static struct i2c_board_info __initdata rx51_peripherals_i2c_board_info_2[] = {
233         {
234                 I2C_BOARD_INFO("lp5523", 0x32),
235 @@ -575,6 +638,10 @@ static struct i2c_board_info __initdata
236         {
237                 I2C_BOARD_INFO("bq27200", 0x55),
238         },
239 +       {
240 +               I2C_BOARD_INFO("bq24150a", 0x6b),
241 +               .platform_data = &rx51_bq24150_platform_data,
242 +       },
243  };
244  
245  static struct i2c_board_info __initdata rx51_peripherals_i2c_board_info_3[] = {