diff options
author | Vasily Khoruzhick <anarsoul@gmail.com> | 2011-01-06 14:52:49 -0500 |
---|---|---|
committer | Ben Dooks <ben-linux@fluff.org> | 2011-03-20 19:14:55 -0400 |
commit | a8e99850d39cac11d03100aa9c40ebaea16e48c5 (patch) | |
tree | cad70016dd193f959903886c85caaedd99570fe6 /arch/arm/mach-s3c2410 | |
parent | 50e2d10da82774e0733ab561c15c84cb92d9ab33 (diff) |
ARM: S3C2410: H1940: Add battery support
Add battery monitoring/charging support via pda_power and
s3c_adc_battery drivers
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
Diffstat (limited to 'arch/arm/mach-s3c2410')
-rw-r--r-- | arch/arm/mach-s3c2410/mach-h1940.c | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/arch/arm/mach-s3c2410/mach-h1940.c b/arch/arm/mach-s3c2410/mach-h1940.c index 36cdb7210879..a0116ef2eca7 100644 --- a/arch/arm/mach-s3c2410/mach-h1940.c +++ b/arch/arm/mach-s3c2410/mach-h1940.c | |||
@@ -28,6 +28,8 @@ | |||
28 | #include <linux/pwm_backlight.h> | 28 | #include <linux/pwm_backlight.h> |
29 | #include <linux/i2c.h> | 29 | #include <linux/i2c.h> |
30 | #include <linux/leds.h> | 30 | #include <linux/leds.h> |
31 | #include <linux/pda_power.h> | ||
32 | #include <linux/s3c_adc_battery.h> | ||
31 | 33 | ||
32 | #include <video/platform_lcd.h> | 34 | #include <video/platform_lcd.h> |
33 | 35 | ||
@@ -218,6 +220,146 @@ static struct s3c2410fb_mach_info h1940_fb_info __initdata = { | |||
218 | .gpdup_mask= 0xffffffff, | 220 | .gpdup_mask= 0xffffffff, |
219 | }; | 221 | }; |
220 | 222 | ||
223 | static int power_supply_init(struct device *dev) | ||
224 | { | ||
225 | return gpio_request(S3C2410_GPF(2), "cable plugged"); | ||
226 | } | ||
227 | |||
228 | static int h1940_is_ac_online(void) | ||
229 | { | ||
230 | return !gpio_get_value(S3C2410_GPF(2)); | ||
231 | } | ||
232 | |||
233 | static void power_supply_exit(struct device *dev) | ||
234 | { | ||
235 | gpio_free(S3C2410_GPF(2)); | ||
236 | } | ||
237 | |||
238 | static char *h1940_supplicants[] = { | ||
239 | "main-battery", | ||
240 | "backup-battery", | ||
241 | }; | ||
242 | |||
243 | static struct pda_power_pdata power_supply_info = { | ||
244 | .init = power_supply_init, | ||
245 | .is_ac_online = h1940_is_ac_online, | ||
246 | .exit = power_supply_exit, | ||
247 | .supplied_to = h1940_supplicants, | ||
248 | .num_supplicants = ARRAY_SIZE(h1940_supplicants), | ||
249 | }; | ||
250 | |||
251 | static struct resource power_supply_resources[] = { | ||
252 | [0] = { | ||
253 | .name = "ac", | ||
254 | .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE | | ||
255 | IORESOURCE_IRQ_HIGHEDGE, | ||
256 | .start = IRQ_EINT2, | ||
257 | .end = IRQ_EINT2, | ||
258 | }, | ||
259 | }; | ||
260 | |||
261 | static struct platform_device power_supply = { | ||
262 | .name = "pda-power", | ||
263 | .id = -1, | ||
264 | .dev = { | ||
265 | .platform_data = | ||
266 | &power_supply_info, | ||
267 | }, | ||
268 | .resource = power_supply_resources, | ||
269 | .num_resources = ARRAY_SIZE(power_supply_resources), | ||
270 | }; | ||
271 | |||
272 | static const struct s3c_adc_bat_thresh bat_lut_noac[] = { | ||
273 | { .volt = 4070, .cur = 162, .level = 100}, | ||
274 | { .volt = 4040, .cur = 165, .level = 95}, | ||
275 | { .volt = 4016, .cur = 164, .level = 90}, | ||
276 | { .volt = 3996, .cur = 166, .level = 85}, | ||
277 | { .volt = 3971, .cur = 168, .level = 80}, | ||
278 | { .volt = 3951, .cur = 168, .level = 75}, | ||
279 | { .volt = 3931, .cur = 170, .level = 70}, | ||
280 | { .volt = 3903, .cur = 172, .level = 65}, | ||
281 | { .volt = 3886, .cur = 172, .level = 60}, | ||
282 | { .volt = 3858, .cur = 176, .level = 55}, | ||
283 | { .volt = 3842, .cur = 176, .level = 50}, | ||
284 | { .volt = 3818, .cur = 176, .level = 45}, | ||
285 | { .volt = 3789, .cur = 180, .level = 40}, | ||
286 | { .volt = 3769, .cur = 180, .level = 35}, | ||
287 | { .volt = 3749, .cur = 184, .level = 30}, | ||
288 | { .volt = 3732, .cur = 184, .level = 25}, | ||
289 | { .volt = 3716, .cur = 184, .level = 20}, | ||
290 | { .volt = 3708, .cur = 184, .level = 15}, | ||
291 | { .volt = 3716, .cur = 96, .level = 10}, | ||
292 | { .volt = 3700, .cur = 96, .level = 5}, | ||
293 | { .volt = 3684, .cur = 96, .level = 0}, | ||
294 | }; | ||
295 | |||
296 | static const struct s3c_adc_bat_thresh bat_lut_acin[] = { | ||
297 | { .volt = 4130, .cur = 0, .level = 100}, | ||
298 | { .volt = 3982, .cur = 0, .level = 50}, | ||
299 | { .volt = 3854, .cur = 0, .level = 10}, | ||
300 | { .volt = 3841, .cur = 0, .level = 0}, | ||
301 | }; | ||
302 | |||
303 | int h1940_bat_init(void) | ||
304 | { | ||
305 | int ret; | ||
306 | |||
307 | ret = gpio_request(H1940_LATCH_SM803_ENABLE, "h1940-charger-enable"); | ||
308 | if (ret) | ||
309 | return ret; | ||
310 | gpio_direction_output(H1940_LATCH_SM803_ENABLE, 0); | ||
311 | |||
312 | return 0; | ||
313 | |||
314 | } | ||
315 | |||
316 | void h1940_bat_exit(void) | ||
317 | { | ||
318 | gpio_free(H1940_LATCH_SM803_ENABLE); | ||
319 | } | ||
320 | |||
321 | void h1940_enable_charger(void) | ||
322 | { | ||
323 | gpio_set_value(H1940_LATCH_SM803_ENABLE, 1); | ||
324 | } | ||
325 | |||
326 | void h1940_disable_charger(void) | ||
327 | { | ||
328 | gpio_set_value(H1940_LATCH_SM803_ENABLE, 0); | ||
329 | } | ||
330 | |||
331 | static struct s3c_adc_bat_pdata h1940_bat_cfg = { | ||
332 | .init = h1940_bat_init, | ||
333 | .exit = h1940_bat_exit, | ||
334 | .enable_charger = h1940_enable_charger, | ||
335 | .disable_charger = h1940_disable_charger, | ||
336 | .gpio_charge_finished = S3C2410_GPF(3), | ||
337 | .gpio_inverted = 1, | ||
338 | .lut_noac = bat_lut_noac, | ||
339 | .lut_noac_cnt = ARRAY_SIZE(bat_lut_noac), | ||
340 | .lut_acin = bat_lut_acin, | ||
341 | .lut_acin_cnt = ARRAY_SIZE(bat_lut_acin), | ||
342 | .volt_channel = 0, | ||
343 | .current_channel = 1, | ||
344 | .volt_mult = 4056, | ||
345 | .current_mult = 1893, | ||
346 | .internal_impedance = 200, | ||
347 | .backup_volt_channel = 3, | ||
348 | /* TODO Check backup volt multiplier */ | ||
349 | .backup_volt_mult = 4056, | ||
350 | .backup_volt_min = 0, | ||
351 | .backup_volt_max = 4149288 | ||
352 | }; | ||
353 | |||
354 | static struct platform_device h1940_battery = { | ||
355 | .name = "s3c-adc-battery", | ||
356 | .id = -1, | ||
357 | .dev = { | ||
358 | .parent = &s3c_device_adc.dev, | ||
359 | .platform_data = &h1940_bat_cfg, | ||
360 | }, | ||
361 | }; | ||
362 | |||
221 | DEFINE_SPINLOCK(h1940_blink_spin); | 363 | DEFINE_SPINLOCK(h1940_blink_spin); |
222 | 364 | ||
223 | int h1940_led_blink_set(unsigned gpio, int state, | 365 | int h1940_led_blink_set(unsigned gpio, int state, |
@@ -498,6 +640,8 @@ static struct platform_device *h1940_devices[] __initdata = { | |||
498 | &h1940_lcd_powerdev, | 640 | &h1940_lcd_powerdev, |
499 | &s3c_device_adc, | 641 | &s3c_device_adc, |
500 | &s3c_device_ts, | 642 | &s3c_device_ts, |
643 | &power_supply, | ||
644 | &h1940_battery, | ||
501 | }; | 645 | }; |
502 | 646 | ||
503 | static void __init h1940_map_io(void) | 647 | static void __init h1940_map_io(void) |