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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/*
* Android dummy test battery driver.
* Based on goldfish_battery.c
* Author: Nicu Pavel <npavel@mini-box.com>
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/module.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/types.h>
#include <linux/pci.h>
#include <linux/interrupt.h>
#include <asm/io.h>
static int adbattery_bat_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val);
static int adbattery_ac_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val);
static struct platform_device *adbattery_pdev;
static enum power_supply_property adbattery_battery_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_HEALTH,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_TECHNOLOGY,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_TEMP,
POWER_SUPPLY_PROP_CAPACITY,
};
static enum power_supply_property adbattery_ac_props[] = {
POWER_SUPPLY_PROP_ONLINE,
};
static struct power_supply adbattery_bat = {
.name = "battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = adbattery_battery_props,
.num_properties = ARRAY_SIZE(adbattery_battery_props),
.get_property = adbattery_bat_get_property,
.use_for_apm = 1,
};
static struct power_supply adbattery_ac = {
.name = "ac",
.type = POWER_SUPPLY_TYPE_MAINS,
.properties = adbattery_ac_props,
.num_properties = ARRAY_SIZE(adbattery_ac_props),
.get_property = adbattery_ac_get_property,
};
static struct power_supply adbattery_usb = {
.name = "usb",
.type = POWER_SUPPLY_TYPE_MAINS,
.properties = adbattery_ac_props,
.num_properties = ARRAY_SIZE(adbattery_ac_props),
.get_property = adbattery_ac_get_property,
};
static int adbattery_ac_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
int ret = 0;
switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
val->intval = 1;
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static int adbattery_bat_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
int ret = 0;
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
val->intval = POWER_SUPPLY_STATUS_CHARGING;
break;
case POWER_SUPPLY_PROP_HEALTH:
val->intval = POWER_SUPPLY_HEALTH_GOOD;
break;
case POWER_SUPPLY_PROP_PRESENT:
val->intval = 1;
break;
case POWER_SUPPLY_PROP_TECHNOLOGY:
val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
break;
case POWER_SUPPLY_PROP_CAPACITY:
val->intval = 100;
break;
case POWER_SUPPLY_PROP_TEMP:
val->intval = 20;
break;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
val->intval = 5;
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static int __init adbattery_init(void)
{
int ret = 0;
adbattery_pdev = platform_device_register_simple("battery", 0, NULL, 0);
if (IS_ERR(adbattery_pdev))
return PTR_ERR(adbattery_pdev);
ret = power_supply_register(&adbattery_pdev->dev, &adbattery_bat);
if (ret)
goto bat_failed;
ret = power_supply_register(&adbattery_pdev->dev, &adbattery_ac);
if (ret)
goto ac_failed;
ret = power_supply_register(&adbattery_pdev->dev, &adbattery_usb);
if (ret)
goto usb_failed;
printk(KERN_INFO "adbattery: android dummy battery driver loaded\n");
goto success;
bat_failed:
power_supply_unregister(&adbattery_bat);
ac_failed:
power_supply_unregister(&adbattery_ac);
usb_failed:
power_supply_unregister(&adbattery_usb);
platform_device_unregister(adbattery_pdev);
success:
return ret;
}
static void __exit adbattery_exit(void)
{
power_supply_unregister(&adbattery_bat);
power_supply_unregister(&adbattery_ac);
power_supply_unregister(&adbattery_usb);
platform_device_unregister(adbattery_pdev);
printk(KERN_INFO "adbattery: android dummy battery driver unloaded\n");
}
module_init(adbattery_init);
module_exit(adbattery_exit);
MODULE_AUTHOR("Nicu Pavel npavel@mini-box.com");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Dummy battery driver for Android battery service ");
|