blob: 19fbb91fe83ae6f43aa2927cd74389817c1e37f7 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* arch/arm/mach-msm/fish_battery.c
2 *
3 * Copyright (C) 2008 Google, Inc.
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * based on: arch/arm/mach-msm/htc_battery.c
15 */
16
17#include <linux/init.h>
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/err.h>
21#include <linux/power_supply.h>
22#include <linux/platform_device.h>
23
24static enum power_supply_property fish_battery_properties[] = {
25 POWER_SUPPLY_PROP_STATUS,
26 POWER_SUPPLY_PROP_HEALTH,
27 POWER_SUPPLY_PROP_PRESENT,
28 POWER_SUPPLY_PROP_TECHNOLOGY,
29 POWER_SUPPLY_PROP_CAPACITY,
30};
31
32static enum power_supply_property fish_power_properties[] = {
33 POWER_SUPPLY_PROP_ONLINE,
34};
35
36static char *supply_list[] = {
37 "battery",
38};
39
40static int fish_power_get_property(struct power_supply *psy,
41 enum power_supply_property psp,
42 union power_supply_propval *val);
43
44static int fish_battery_get_property(struct power_supply *psy,
45 enum power_supply_property psp,
46 union power_supply_propval *val);
47
48static struct power_supply fish_power_supplies[] = {
49 {
50 .name = "battery",
51 .type = POWER_SUPPLY_TYPE_BATTERY,
52 .properties = fish_battery_properties,
53 .num_properties = ARRAY_SIZE(fish_battery_properties),
54 .get_property = fish_battery_get_property,
55 },
56 {
57 .name = "ac",
58 .type = POWER_SUPPLY_TYPE_MAINS,
59 .supplied_to = supply_list,
60 .num_supplicants = ARRAY_SIZE(supply_list),
61 .properties = fish_power_properties,
62 .num_properties = ARRAY_SIZE(fish_power_properties),
63 .get_property = fish_power_get_property,
64 },
65};
66
67static int fish_power_get_property(struct power_supply *psy,
68 enum power_supply_property psp,
69 union power_supply_propval *val)
70{
71 switch (psp) {
72 case POWER_SUPPLY_PROP_ONLINE:
73 if (psy->type == POWER_SUPPLY_TYPE_MAINS)
74 val->intval = 1;
75 else
76 val->intval = 0;
77 break;
78 default:
79 return -EINVAL;
80 }
81
82 return 0;
83}
84
85static int fish_battery_get_property(struct power_supply *psy,
86 enum power_supply_property psp,
87 union power_supply_propval *val)
88{
89 switch (psp) {
90 case POWER_SUPPLY_PROP_STATUS:
91 val->intval = POWER_SUPPLY_STATUS_FULL;
92 break;
93 case POWER_SUPPLY_PROP_HEALTH:
94 val->intval = POWER_SUPPLY_HEALTH_GOOD;
95 break;
96 case POWER_SUPPLY_PROP_PRESENT:
97 val->intval = 1;
98 break;
99 case POWER_SUPPLY_PROP_TECHNOLOGY:
100 val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
101 break;
102 case POWER_SUPPLY_PROP_CAPACITY:
103 val->intval = 100;
104 break;
105 default:
106 return -EINVAL;
107 }
108
109 return 0;
110}
111
112static int fish_battery_probe(struct platform_device *pdev)
113{
114 int i;
115 int rc;
116
117 /* init power supplier framework */
118 for (i = 0; i < ARRAY_SIZE(fish_power_supplies); i++) {
119 rc = power_supply_register(&pdev->dev, &fish_power_supplies[i]);
120 if (rc)
121 pr_err("%s: Failed to register power supply (%d)\n",
122 __func__, rc);
123 }
124
125 return 0;
126}
127
128static struct platform_driver fish_battery_driver = {
129 .probe = fish_battery_probe,
130 .driver = {
131 .name = "fish_battery",
132 .owner = THIS_MODULE,
133 },
134};
135
136static int __init fish_battery_init(void)
137{
138 platform_driver_register(&fish_battery_driver);
139 return 0;
140}
141
142module_init(fish_battery_init);
143MODULE_DESCRIPTION("Qualcomm fish battery driver");
144MODULE_LICENSE("GPL");
145