summaryrefslogtreecommitdiff
path: root/ANDROID_3.4.5/drivers/power/wmt_battery/wmt_battery.c
blob: 23692ee9e433350d858a0d01e0ed88a318242f8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * mp2625_charger.c - WonderMedia Charger Driver.
 *
 * Copyright (C) 2013  WonderMedia Technologies, Inc.  
 *
 * This program is free software; you can redistribute it and/or modify it
 * under  the terms of the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the License, or (at your
 * option) any later version.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <linux/gpio.h>
#include <mach/wmt_iomux.h>
#include <mach/wmt_env.h>
#include <linux/power/wmt_battery.h>

extern void mp2625_pc_connected(void);
extern void g2214_pc_connected(void);

void wmt_do_pc_connected(void)
{
	mp2625_pc_connected();
	g2214_pc_connected();
}

static struct {
	int led_power;
	int led_gpio_level;
} charger_led;

void led_power_enable(int enable)
{
	if (gpio_is_valid(charger_led.led_power)) {
		if (enable)
			gpio_direction_output(charger_led.led_power,
					      charger_led.led_gpio_level);
		else
			gpio_direction_output(charger_led.led_power,
					      !charger_led.led_gpio_level);
	}
}

int parse_charger_led(void)
{
	static const char uboot_env[] = "wmt.charger.led";
	char buf[64];
	size_t l = sizeof(buf);
	int id;

	if (wmt_getsyspara((char *)uboot_env, buf, &l) ||
	    (sscanf(buf, "%d:%d:%d", &id,
		    &charger_led.led_power, &charger_led.led_gpio_level) != 3) ||
	    id != 0 || !gpio_is_valid(charger_led.led_power) ||
	    gpio_request(charger_led.led_power, "led power")) {
		charger_led.led_power = -1;
		return -EINVAL;
	}

	led_power_enable(0);
	return 0;
}