summaryrefslogtreecommitdiff
path: root/include/linux/power/wmt_battery.h
blob: e721fa5e8d864d99acd21d8f63dafcdd6bed3fd6 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * 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.
 */

#ifndef __LINUX_POWER_WMT_BATTERY_H__
#define __LINUX_POWER_WMT_BATTERY_H__

static inline int prefixcmp(const char *str, const char *prefix)
{
	for (; ; str++, prefix++)
		if (!*prefix)
			return 0;
		else if (*str != *prefix)
			return (unsigned char)*prefix - (unsigned char)*str;
}

#include <linux/power_supply.h>
#include <mach/hardware.h>

enum cable_type {
	CABLE_TYPE_DC,
	CABLE_TYPE_USB,
	CABLE_TYPE_UNKNOWN,
};

enum {
	CURRENT_SWITCH_DYNAMIC,
	CURRENT_SWITCH_SLEEP,
};

enum {
	PC_CONNECTED_NOT_CHARGING,
	PC_CONNECTED_CHARGING,
};

#define USB_BASE_ADD	(0xD8007800+WMT_MMAP_OFFSET)

static inline int wmt_is_otg_plugin(void)
{
	return !(REG8_VAL(USB_BASE_ADD + 0x7F2) & BIT0);
}

static inline int wmt_is_dc_plugin(void)
{
	return (REG8_VAL(PM_CTRL_BASE_ADDR + 0x005d) & 0x01);
}

static inline void wmt_dcdet_irq_enable(void)
{
	uint32_t val;
	// dcdet wakeup interrupt
	PMTC_VAL |= BIT27;
	val = PMWTC_VAL;
	val &= ~(0xf << 12);
	val |= 0x04 << 12;
	PMWTC_VAL = val;
	PMWE_VAL |= BIT27;

	// dcdet interrupt
	/* Register dcdet interrupt, edge trigger */
	PMCIE_VAL |= BIT27;
	WK_TRG_EN_VAL |= BIT27;
	pmc_enable_wakeup_isr(WKS_DCDET, 4);
}

static inline void wmt_dcdet_irq_disable(void)
{
	pmc_disable_wakeup_isr(WKS_DCDET);
}

static inline int charger_get_status(void)
{
	struct power_supply *charger;
	union power_supply_propval val;
	
	charger = power_supply_get_by_name("ac");
	if (!charger) {
		pr_err("get ac power supply failed\n");
		return -ENODEV;
	}

	charger->get_property(charger, POWER_SUPPLY_PROP_STATUS, &val);
	return val.intval;
}

static inline int charger_is_full(void)
{
	return charger_get_status() == POWER_SUPPLY_STATUS_FULL;
}

static inline int wmt_charger_is_dc_plugin(void)
{
	return power_supply_is_system_supplied();
}

extern int  wmt_is_pc_connected(void);
extern void wmt_do_pc_connected(void);

extern int parse_charger_led(void);
extern void led_power_enable(int enable);

#endif