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