aboutsummaryrefslogtreecommitdiff
path: root/linux/3.1.6/0009-n30-Add-battery-status-for-Acer-n30-n35.patch
blob: e466b4714330d13ea509a13fdd7eeec7f674fdd0 (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
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
--- linux-3.1.6/arch/arm/mach-s3c2410/mach-n30.c.orig	2011-12-31 16:38:31.958217564 +0100
+++ linux-3.1.6/arch/arm/mach-s3c2410/mach-n30.c	2011-12-31 16:38:56.694337733 +0100
@@ -167,6 +167,11 @@
 	.cfg_gpio = s3c24xx_ts_cfg_gpio,
 };
 
+static struct platform_device n30_battery = {
+	.name		= "n30-battery",
+	.id		= -1,
+};
+
 static struct gpio_keys_button n30_buttons[] = {
 	{
 		.gpio		= S3C2410_GPF(0),
@@ -521,6 +526,7 @@
 	&s3c_device_sdi,
 	&s3c_device_adc,
 	&s3c_device_ts,
+	&n30_battery,
 	&n30_button_device,
 	&n30_blue_led,
 	&n30_warning_led,
@@ -539,6 +545,7 @@
 	&s3c_device_ts,
 	&s3c_device_timer[0],
 	&n35_backlight,
+	&n30_battery,
 	&n35_button_device,
 	&n35_blue_led,
 	&n35_warning_led,
--- linux-3.1.6/drivers/power/Kconfig.orig	2011-12-31 16:38:31.958217564 +0100
+++ linux-3.1.6/drivers/power/Kconfig	2011-12-31 16:38:56.695337657 +0100
@@ -82,6 +82,12 @@
 	  Say Y here to enable support for the DS2782/DS2786 standalone battery
 	  gas-gauge.
 
+config BATTERY_N30
+	tristate "Acer n30/n35 battery driver"
+	depends on (MACH_N30 || MACH_N35) && I2C
+	help
+	  Say Y here to enable support for batteries on the Acer n30 family.
+
 config BATTERY_PMU
 	tristate "Apple PMU battery"
 	depends on PPC32 && ADB_PMU
--- linux-3.1.6/drivers/power/Makefile.orig	2011-12-21 22:00:46.000000000 +0100
+++ linux-3.1.6/drivers/power/Makefile	2011-12-31 16:38:56.695337657 +0100
@@ -32,6 +32,7 @@
 obj-$(CONFIG_CHARGER_PCF50633)	+= pcf50633-charger.o
 obj-$(CONFIG_BATTERY_JZ4740)	+= jz4740-battery.o
 obj-$(CONFIG_BATTERY_INTEL_MID)	+= intel_mid_battery.o
+obj-$(CONFIG_BATTERY_N30)	+= n30_battery.o
 obj-$(CONFIG_CHARGER_ISP1704)	+= isp1704_charger.o
 obj-$(CONFIG_CHARGER_MAX8903)	+= max8903_charger.o
 obj-$(CONFIG_CHARGER_TWL4030)	+= twl4030_charger.o
--- linux-3.1.6/drivers/power/n30_battery.c.orig	2011-12-31 16:38:56.696337581 +0100
+++ linux-3.1.6/drivers/power/n30_battery.c	2011-12-31 16:38:56.696337581 +0100
@@ -0,0 +1,116 @@
+/* Acer n30 battery driver.
+ *
+ * The Acer n30 family has a battery controller which sits on the I2C
+ * bus and which can report the battery charge in percent.  Two GPIO
+ * pins tells if the PDA is being powered from a charger or via USB.
+ *
+ * Copyright (c) 2008 Christer Weinigel <christer@weinigel.se>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <linux/power_supply.h>
+
+#include <mach/hardware.h>
+#include <mach/regs-gpio.h>
+
+#include <asm/mach-types.h>
+
+static int n30_battery_get_capacity(struct device *dev)
+{
+	u8 value;
+	struct i2c_adapter *adap;
+	struct i2c_msg msg[] = {
+		{ .addr = 0x0b, .flags = I2C_M_RD, .buf = &value, .len = 1 }
+	};
+	int capacity = -EIO;
+
+	adap = i2c_get_adapter(0);
+	if (adap != NULL) {
+		if (i2c_transfer(adap, msg, 1) == 1)
+			capacity = value;
+		else
+			dev_err(dev, "failed to read capacity\n");
+		i2c_put_adapter(adap);
+	} else
+		dev_err(dev, "failed to get i2c adapter\n");
+
+	return capacity;
+}
+
+static int n30_battery_get_property(struct power_supply *psy,
+				    enum power_supply_property psp,
+				    union power_supply_propval *val)
+{
+	switch (psp) {
+	case POWER_SUPPLY_PROP_CAPACITY:
+		val->intval = n30_battery_get_capacity(psy->dev);
+		return 0;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static enum power_supply_property n30_battery_props[] = {
+	POWER_SUPPLY_PROP_CAPACITY,
+};
+
+static struct power_supply n30_battery = {
+	.name = "battery",
+	.type = POWER_SUPPLY_TYPE_BATTERY,
+	.properties = n30_battery_props,
+	.num_properties = ARRAY_SIZE(n30_battery_props),
+	.get_property = n30_battery_get_property,
+	.use_for_apm = 1,
+};
+
+static int __devinit n30_battery_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	dev_info(&pdev->dev, "Acer n30 battery driver\n");
+
+	ret = power_supply_register(&pdev->dev, &n30_battery);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int n30_battery_remove(struct platform_device *pdev)
+{
+	power_supply_unregister(&n30_battery);
+	return 0;
+}
+
+static struct platform_driver n30_battery_driver = {
+	.driver = {
+		.name = "n30-battery",
+	},
+	.probe = n30_battery_probe,
+	.remove = n30_battery_remove,
+};
+
+static int __init n30_battery_init(void)
+{
+	return platform_driver_register(&n30_battery_driver);
+}
+
+static void __exit n30_battery_exit(void)
+{
+	platform_driver_unregister(&n30_battery_driver);
+}
+
+module_init(n30_battery_init);
+module_exit(n30_battery_exit);
+
+MODULE_AUTHOR("Christer Weinigel <christer@weinigel.se>");
+MODULE_DESCRIPTION("Acer n30 battery driver");
+MODULE_LICENSE("GPL");