diff options
author | Richard Purdie <richard@openedhand.com> | 2008-01-20 17:03:32 +0000 |
---|---|---|
committer | Richard Purdie <richard@openedhand.com> | 2008-01-20 17:03:32 +0000 |
commit | 53d19e1c1ffda8e7724d9d6658e3bb9acde758a7 (patch) | |
tree | 11a7541bc58ef7c90c75984de24b2f6a518506a0 /meta/packages/linux/linux-rp-2.6.23 | |
parent | 388339b8f62705597453e5d627724c8dae90ced8 (diff) | |
download | poky-53d19e1c1ffda8e7724d9d6658e3bb9acde758a7.tar.gz |
linux-rp: Tidy up .bb file and clean up unused patches
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@3557 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'meta/packages/linux/linux-rp-2.6.23')
9 files changed, 3106 insertions, 3465 deletions
diff --git a/meta/packages/linux/linux-rp-2.6.23/mmcsd_no_scr_check-r2.patch b/meta/packages/linux/linux-rp-2.6.23/mmcsd_no_scr_check-r2.patch deleted file mode 100644 index ac2245f088..0000000000 --- a/meta/packages/linux/linux-rp-2.6.23/mmcsd_no_scr_check-r2.patch +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | --- | ||
2 | drivers/mmc/core/sd.c | 11 ++++++----- | ||
3 | 1 file changed, 6 insertions(+), 5 deletions(-) | ||
4 | |||
5 | Index: linux-2.6.23/drivers/mmc/core/sd.c | ||
6 | =================================================================== | ||
7 | --- linux-2.6.23.orig/drivers/mmc/core/sd.c 2007-10-17 11:33:26.000000000 +0200 | ||
8 | +++ linux-2.6.23/drivers/mmc/core/sd.c 2007-10-17 11:33:49.000000000 +0200 | ||
9 | @@ -173,14 +173,15 @@ | ||
10 | |||
11 | scr_struct = UNSTUFF_BITS(resp, 60, 4); | ||
12 | if (scr_struct != 0) { | ||
13 | - printk(KERN_ERR "%s: unrecognised SCR structure version %d\n", | ||
14 | + printk(KERN_WARNING "%s: unrecognised SCR structure version %d\n", | ||
15 | mmc_hostname(card->host), scr_struct); | ||
16 | - return -EINVAL; | ||
17 | + scr->sda_vsn = 0; | ||
18 | + scr->bus_widths = 0; | ||
19 | + } else { | ||
20 | + scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4); | ||
21 | + scr->bus_widths = UNSTUFF_BITS(resp, 48, 4); | ||
22 | } | ||
23 | |||
24 | - scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4); | ||
25 | - scr->bus_widths = UNSTUFF_BITS(resp, 48, 4); | ||
26 | - | ||
27 | return 0; | ||
28 | } | ||
29 | |||
diff --git a/meta/packages/linux/linux-rp-2.6.23/pda-power.patch b/meta/packages/linux/linux-rp-2.6.23/pda-power.patch deleted file mode 100644 index face2f4ef2..0000000000 --- a/meta/packages/linux/linux-rp-2.6.23/pda-power.patch +++ /dev/null | |||
@@ -1,3373 +0,0 @@ | |||
1 | --- | ||
2 | arch/arm/Kconfig | 2 | ||
3 | drivers/Kconfig | 2 | ||
4 | drivers/Makefile | 1 | ||
5 | drivers/power/Kconfig | 70 +++++ | ||
6 | drivers/power/Makefile | 28 ++ | ||
7 | drivers/power/adc_battery.c | 278 +++++++++++++++++++++ | ||
8 | drivers/power/apm_power.c | 247 +++++++++++++++++++ | ||
9 | drivers/power/ds2760_battery.c | 475 +++++++++++++++++++++++++++++++++++++ | ||
10 | drivers/power/micro_battery.c | 257 ++++++++++++++++++++ | ||
11 | drivers/power/olpc_battery.c | 302 +++++++++++++++++++++++ | ||
12 | drivers/power/pda_power.c | 263 ++++++++++++++++++++ | ||
13 | drivers/power/pmu_battery.c | 215 ++++++++++++++++ | ||
14 | drivers/power/power_supply.h | 42 +++ | ||
15 | drivers/power/power_supply_core.c | 168 +++++++++++++ | ||
16 | drivers/power/power_supply_leds.c | 188 ++++++++++++++ | ||
17 | drivers/power/power_supply_sysfs.c | 289 ++++++++++++++++++++++ | ||
18 | drivers/power/simpad-battery.c | 242 ++++++++++++++++++ | ||
19 | include/linux/power_supply.h | 175 +++++++++++++ | ||
20 | 18 files changed, 3244 insertions(+) | ||
21 | |||
22 | Index: linux-2.6.22/drivers/power/adc_battery.c | ||
23 | =================================================================== | ||
24 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
25 | +++ linux-2.6.22/drivers/power/adc_battery.c 2007-08-23 12:26:28.000000000 +0200 | ||
26 | @@ -0,0 +1,278 @@ | ||
27 | +/* | ||
28 | + * Copyright (c) 2007 Paul Sokolovsky | ||
29 | + * | ||
30 | + * This program is free software; you can redistribute it and/or modify | ||
31 | + * it under the terms of the GNU General Public License as published by | ||
32 | + * the Free Software Foundation; either version 2 of the License, or | ||
33 | + * (at your option) any later version. | ||
34 | + * | ||
35 | + */ | ||
36 | + | ||
37 | +//#define DEBUG | ||
38 | + | ||
39 | +#include <linux/module.h> | ||
40 | +#include <linux/interrupt.h> | ||
41 | +#include <linux/pm.h> | ||
42 | +#include <linux/delay.h> | ||
43 | +#include <linux/workqueue.h> | ||
44 | +#include <linux/platform_device.h> | ||
45 | +#include <linux/power_supply.h> | ||
46 | +#include <linux/adc.h> | ||
47 | +#include <linux/adc_battery.h> | ||
48 | + | ||
49 | +#include <asm/irq.h> | ||
50 | + | ||
51 | +#define PIN_NO_VOLT 0 | ||
52 | +#define PIN_NO_CURR 1 | ||
53 | +#define PIN_NO_TEMP 2 | ||
54 | + | ||
55 | +struct battery_adc_priv { | ||
56 | + struct power_supply batt_cdev; | ||
57 | + | ||
58 | + struct battery_adc_platform_data *pdata; | ||
59 | + | ||
60 | + struct adc_request req; | ||
61 | + struct adc_sense pins[3]; | ||
62 | + struct adc_sense last_good_pins[3]; | ||
63 | + | ||
64 | + struct workqueue_struct *wq; | ||
65 | + struct delayed_work work; | ||
66 | +}; | ||
67 | + | ||
68 | +/* | ||
69 | + * Battery properties | ||
70 | + */ | ||
71 | + | ||
72 | +static int adc_battery_get_property(struct power_supply *psy, | ||
73 | + enum power_supply_property psp, | ||
74 | + union power_supply_propval *val) | ||
75 | +{ | ||
76 | + struct battery_adc_priv* drvdata = (struct battery_adc_priv*)psy; | ||
77 | + int voltage; | ||
78 | + | ||
79 | + switch (psp) { | ||
80 | + case POWER_SUPPLY_PROP_STATUS: | ||
81 | + val->intval = drvdata->pdata->charge_status; | ||
82 | + break; | ||
83 | + case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: | ||
84 | + val->intval = drvdata->pdata->battery_info.voltage_max_design; | ||
85 | + break; | ||
86 | + case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: | ||
87 | + val->intval = drvdata->pdata->battery_info.voltage_min_design; | ||
88 | + break; | ||
89 | + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: | ||
90 | + val->intval = drvdata->pdata->battery_info.charge_full_design; | ||
91 | + break; | ||
92 | + case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN: | ||
93 | + val->intval = drvdata->pdata->battery_info.charge_empty_design; | ||
94 | + break; | ||
95 | + case POWER_SUPPLY_PROP_VOLTAGE_NOW: | ||
96 | + val->intval = drvdata->last_good_pins[PIN_NO_VOLT].value * drvdata->pdata->voltage_mult; | ||
97 | + break; | ||
98 | + case POWER_SUPPLY_PROP_CURRENT_NOW: | ||
99 | + val->intval = drvdata->last_good_pins[PIN_NO_CURR].value * drvdata->pdata->current_mult; | ||
100 | + break; | ||
101 | + case POWER_SUPPLY_PROP_CHARGE_NOW: | ||
102 | + /* We do calculations in mX, not uX, because todo it in uX we should use "long long"s, | ||
103 | + * which is a mess (need to use do_div) when you need divide operation). */ | ||
104 | + voltage = drvdata->last_good_pins[PIN_NO_VOLT].value * drvdata->pdata->voltage_mult; | ||
105 | + val->intval = ((voltage/1000 - drvdata->pdata->battery_info.voltage_min_design/1000) * | ||
106 | + (drvdata->pdata->battery_info.charge_full_design/1000 - | ||
107 | + drvdata->pdata->battery_info.charge_empty_design/1000)) / | ||
108 | + (drvdata->pdata->battery_info.voltage_max_design/1000 - | ||
109 | + drvdata->pdata->battery_info.voltage_min_design/1000); | ||
110 | + val->intval *= 1000; /* convert final result to uX */ | ||
111 | + break; | ||
112 | + case POWER_SUPPLY_PROP_TEMP: | ||
113 | + val->intval = drvdata->last_good_pins[PIN_NO_TEMP].value * drvdata->pdata->temperature_mult / 1000; | ||
114 | + break; | ||
115 | + default: | ||
116 | + return -EINVAL; | ||
117 | + }; | ||
118 | + return 0; | ||
119 | +} | ||
120 | + | ||
121 | +/* | ||
122 | + * Driver body | ||
123 | + */ | ||
124 | + | ||
125 | +static void adc_battery_query(struct battery_adc_priv *drvdata) | ||
126 | +{ | ||
127 | + struct battery_adc_platform_data *pdata = drvdata->pdata; | ||
128 | + int powered, charging; | ||
129 | + | ||
130 | + adc_request_sample(&drvdata->req); | ||
131 | + | ||
132 | + powered = power_supply_am_i_supplied(&drvdata->batt_cdev); | ||
133 | + charging = pdata->is_charging ? pdata->is_charging() : -1; | ||
134 | + | ||
135 | + if (powered && charging) | ||
136 | + pdata->charge_status = POWER_SUPPLY_STATUS_CHARGING; | ||
137 | + else if (powered && !charging && charging != -1) | ||
138 | + pdata->charge_status = POWER_SUPPLY_STATUS_FULL; | ||
139 | + else | ||
140 | + pdata->charge_status = POWER_SUPPLY_STATUS_DISCHARGING; | ||
141 | + | ||
142 | + /* Throw away invalid samples, this may happen soon after resume for example. */ | ||
143 | + if (drvdata->pins[PIN_NO_VOLT].value > 0) { | ||
144 | + memcpy(drvdata->last_good_pins, drvdata->pins, sizeof(drvdata->pins)); | ||
145 | +#ifdef DEBUG | ||
146 | + printk("%d %d %d\n", drvdata->pins[PIN_NO_VOLT].value, | ||
147 | + drvdata->pins[PIN_NO_CURR].value, | ||
148 | + drvdata->pins[PIN_NO_TEMP].value); | ||
149 | +#endif | ||
150 | + } | ||
151 | +} | ||
152 | + | ||
153 | +static void adc_battery_charge_power_changed(struct power_supply *bat) | ||
154 | +{ | ||
155 | + struct battery_adc_priv *drvdata = (struct battery_adc_priv*)bat; | ||
156 | + cancel_delayed_work(&drvdata->work); | ||
157 | + queue_delayed_work(drvdata->wq, &drvdata->work, 0); | ||
158 | +} | ||
159 | + | ||
160 | +static void adc_battery_work_func(struct work_struct *work) | ||
161 | +{ | ||
162 | + struct delayed_work *delayed_work = container_of(work, struct delayed_work, work); | ||
163 | + struct battery_adc_priv *drvdata = container_of(delayed_work, struct battery_adc_priv, work); | ||
164 | + | ||
165 | + adc_battery_query(drvdata); | ||
166 | + power_supply_changed(&drvdata->batt_cdev); | ||
167 | + | ||
168 | + queue_delayed_work(drvdata->wq, &drvdata->work, (5000 * HZ) / 1000); | ||
169 | +} | ||
170 | + | ||
171 | +static int adc_battery_probe(struct platform_device *pdev) | ||
172 | +{ | ||
173 | + int retval; | ||
174 | + struct battery_adc_platform_data *pdata = pdev->dev.platform_data; | ||
175 | + struct battery_adc_priv *drvdata; | ||
176 | + int i, j; | ||
177 | + enum power_supply_property props[] = { | ||
178 | + POWER_SUPPLY_PROP_STATUS, | ||
179 | + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, | ||
180 | + POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, | ||
181 | + POWER_SUPPLY_PROP_VOLTAGE_NOW, | ||
182 | + POWER_SUPPLY_PROP_CURRENT_NOW, | ||
183 | + POWER_SUPPLY_PROP_CHARGE_NOW, | ||
184 | + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, | ||
185 | + POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN, | ||
186 | + POWER_SUPPLY_PROP_TEMP, | ||
187 | + }; | ||
188 | + | ||
189 | + // Initialize ts data structure. | ||
190 | + drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); | ||
191 | + if (!drvdata) | ||
192 | + return -ENOMEM; | ||
193 | + | ||
194 | + drvdata->batt_cdev.name = pdata->battery_info.name; | ||
195 | + drvdata->batt_cdev.use_for_apm = pdata->battery_info.use_for_apm; | ||
196 | + drvdata->batt_cdev.num_properties = ARRAY_SIZE(props); | ||
197 | + drvdata->batt_cdev.get_property = adc_battery_get_property; | ||
198 | + drvdata->batt_cdev.external_power_changed = | ||
199 | + adc_battery_charge_power_changed; | ||
200 | + | ||
201 | + if (!pdata->voltage_pin) { | ||
202 | + drvdata->batt_cdev.num_properties--; | ||
203 | + props[3] = -1; | ||
204 | + } | ||
205 | + if (!pdata->current_pin) { | ||
206 | + drvdata->batt_cdev.num_properties--; | ||
207 | + props[4] = -1; | ||
208 | + } | ||
209 | + if (!pdata->temperature_pin) { | ||
210 | + drvdata->batt_cdev.num_properties--; | ||
211 | + props[8] = -1; | ||
212 | + } | ||
213 | + | ||
214 | + drvdata->batt_cdev.properties = kmalloc( | ||
215 | + sizeof(*drvdata->batt_cdev.properties) * | ||
216 | + drvdata->batt_cdev.num_properties, GFP_KERNEL); | ||
217 | + if (!drvdata->batt_cdev.properties) | ||
218 | + return -ENOMEM; | ||
219 | + | ||
220 | + j = 0; | ||
221 | + for (i = 0; i < ARRAY_SIZE(props); i++) { | ||
222 | + if (props[i] == -1) | ||
223 | + continue; | ||
224 | + drvdata->batt_cdev.properties[j++] = props[i]; | ||
225 | + } | ||
226 | + | ||
227 | + retval = power_supply_register(&pdev->dev, &drvdata->batt_cdev); | ||
228 | + if (retval) { | ||
229 | + printk("adc-battery: Error registering battery classdev"); | ||
230 | + return retval; | ||
231 | + } | ||
232 | + | ||
233 | + drvdata->req.senses = drvdata->pins; | ||
234 | + drvdata->req.num_senses = ARRAY_SIZE(drvdata->pins); | ||
235 | + drvdata->pins[PIN_NO_VOLT].name = pdata->voltage_pin; | ||
236 | + drvdata->pins[PIN_NO_CURR].name = pdata->current_pin; | ||
237 | + drvdata->pins[PIN_NO_TEMP].name = pdata->temperature_pin; | ||
238 | + | ||
239 | + adc_request_register(&drvdata->req); | ||
240 | + | ||
241 | + /* Here we assume raw values in mV */ | ||
242 | + if (!pdata->voltage_mult) | ||
243 | + pdata->voltage_mult = 1000; | ||
244 | + /* Here we assume raw values in mA */ | ||
245 | + if (!pdata->current_mult) | ||
246 | + pdata->current_mult = 1000; | ||
247 | + /* Here we assume raw values in 1/10 C */ | ||
248 | + if (!pdata->temperature_mult) | ||
249 | + pdata->temperature_mult = 1000; | ||
250 | + | ||
251 | + drvdata->pdata = pdata; | ||
252 | + pdata->drvdata = drvdata; /* Seems ugly, we need better solution */ | ||
253 | + | ||
254 | + platform_set_drvdata(pdev, drvdata); | ||
255 | + | ||
256 | + // Load initial values ASAP | ||
257 | + adc_battery_query(drvdata); | ||
258 | + | ||
259 | + // Still schedule next sampling soon | ||
260 | + INIT_DELAYED_WORK(&drvdata->work, adc_battery_work_func); | ||
261 | + drvdata->wq = create_workqueue(pdev->dev.bus_id); | ||
262 | + if (!drvdata->wq) | ||
263 | + return -ESRCH; | ||
264 | + | ||
265 | + queue_delayed_work(drvdata->wq, &drvdata->work, (5000 * HZ) / 1000); | ||
266 | + | ||
267 | + return retval; | ||
268 | +} | ||
269 | + | ||
270 | +static int adc_battery_remove(struct platform_device *pdev) | ||
271 | +{ | ||
272 | + struct battery_adc_priv *drvdata = platform_get_drvdata(pdev); | ||
273 | + cancel_delayed_work(&drvdata->work); | ||
274 | + destroy_workqueue(drvdata->wq); | ||
275 | + power_supply_unregister(&drvdata->batt_cdev); | ||
276 | + adc_request_unregister(&drvdata->req); | ||
277 | + kfree(drvdata->batt_cdev.properties); | ||
278 | + return 0; | ||
279 | +} | ||
280 | + | ||
281 | +static struct platform_driver adc_battery_driver = { | ||
282 | + .driver = { | ||
283 | + .name = "adc-battery", | ||
284 | + }, | ||
285 | + .probe = adc_battery_probe, | ||
286 | + .remove = adc_battery_remove, | ||
287 | +}; | ||
288 | + | ||
289 | +static int __init adc_battery_init(void) | ||
290 | +{ | ||
291 | + return platform_driver_register(&adc_battery_driver); | ||
292 | +} | ||
293 | + | ||
294 | +static void __exit adc_battery_exit(void) | ||
295 | +{ | ||
296 | + platform_driver_unregister(&adc_battery_driver); | ||
297 | +} | ||
298 | + | ||
299 | +module_init(adc_battery_init) | ||
300 | +module_exit(adc_battery_exit) | ||
301 | + | ||
302 | +MODULE_AUTHOR("Paul Sokolovsky"); | ||
303 | +MODULE_DESCRIPTION("Battery driver for ADC device"); | ||
304 | +MODULE_LICENSE("GPL"); | ||
305 | Index: linux-2.6.22/drivers/power/apm_power.c | ||
306 | =================================================================== | ||
307 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
308 | +++ linux-2.6.22/drivers/power/apm_power.c 2007-08-23 12:13:52.000000000 +0200 | ||
309 | @@ -0,0 +1,247 @@ | ||
310 | +/* | ||
311 | + * Copyright (c) 2007 Anton Vorontsov <cbou@mail.ru> | ||
312 | + * Copyright (c) 2007 Eugeny Boger <eugenyboger@dgap.mipt.ru> | ||
313 | + * | ||
314 | + * Author: Eugeny Boger <eugenyboger@dgap.mipt.ru> | ||
315 | + * | ||
316 | + * Use consistent with the GNU GPL is permitted, | ||
317 | + * provided that this copyright notice is | ||
318 | + * preserved in its entirety in all copies and derived works. | ||
319 | + */ | ||
320 | + | ||
321 | +#include <linux/module.h> | ||
322 | +#include <linux/power_supply.h> | ||
323 | +#include <linux/apm-emulation.h> | ||
324 | + | ||
325 | +#define PSY_PROP(psy, prop, val) psy->get_property(psy, \ | ||
326 | + POWER_SUPPLY_PROP_##prop, val) | ||
327 | + | ||
328 | +#define _MPSY_PROP(prop, val) main_battery->get_property(main_battery, \ | ||
329 | + prop, val) | ||
330 | + | ||
331 | +#define MPSY_PROP(prop, val) _MPSY_PROP(POWER_SUPPLY_PROP_##prop, val) | ||
332 | + | ||
333 | +static struct power_supply *main_battery; | ||
334 | + | ||
335 | +static void find_main_battery(void) | ||
336 | +{ | ||
337 | + struct device *dev; | ||
338 | + struct power_supply *bat, *batm; | ||
339 | + union power_supply_propval full; | ||
340 | + int max_charge = 0; | ||
341 | + | ||
342 | + main_battery = NULL; | ||
343 | + batm = NULL; | ||
344 | + list_for_each_entry(dev, &power_supply_class->devices, node) { | ||
345 | + bat = dev_get_drvdata(dev); | ||
346 | + /* If none of battery devices cantains 'use_for_apm' flag, | ||
347 | + choice one with maximum design charge */ | ||
348 | + if (!PSY_PROP(bat, CHARGE_FULL_DESIGN, &full)) { | ||
349 | + if (full.intval > max_charge) { | ||
350 | + batm = bat; | ||
351 | + max_charge = full.intval; | ||
352 | + } | ||
353 | + } | ||
354 | + | ||
355 | + if (bat->use_for_apm) | ||
356 | + main_battery = bat; | ||
357 | + } | ||
358 | + if (!main_battery) | ||
359 | + main_battery = batm; | ||
360 | + | ||
361 | + return; | ||
362 | +} | ||
363 | + | ||
364 | +static int calculate_time(int status) | ||
365 | +{ | ||
366 | + union power_supply_propval charge_full, charge_empty; | ||
367 | + union power_supply_propval charge, I; | ||
368 | + | ||
369 | + if (MPSY_PROP(CHARGE_FULL, &charge_full)) { | ||
370 | + /* if battery can't report this property, use design value */ | ||
371 | + if (MPSY_PROP(CHARGE_FULL_DESIGN, &charge_full)) | ||
372 | + return -1; | ||
373 | + } | ||
374 | + | ||
375 | + if (MPSY_PROP(CHARGE_EMPTY, &charge_empty)) { | ||
376 | + /* if battery can't report this property, use design value */ | ||
377 | + if (MPSY_PROP(CHARGE_EMPTY_DESIGN, &charge_empty)) | ||
378 | + charge_empty.intval = 0; | ||
379 | + } | ||
380 | + | ||
381 | + if (MPSY_PROP(CHARGE_AVG, &charge)) { | ||
382 | + /* if battery can't report average value, use momentary */ | ||
383 | + if (MPSY_PROP(CHARGE_NOW, &charge)) | ||
384 | + return -1; | ||
385 | + } | ||
386 | + | ||
387 | + if (MPSY_PROP(CURRENT_AVG, &I)) { | ||
388 | + /* if battery can't report average value, use momentary */ | ||
389 | + if (MPSY_PROP(CURRENT_NOW, &I)) | ||
390 | + return -1; | ||
391 | + } | ||
392 | + | ||
393 | + if (I.intval == 0) | ||
394 | + return 0; | ||
395 | + else if (status == POWER_SUPPLY_STATUS_CHARGING) | ||
396 | + return ((charge.intval - charge_full.intval) * 60L) / | ||
397 | + I.intval; | ||
398 | + else | ||
399 | + return -((charge.intval - charge_empty.intval) * 60L) / | ||
400 | + I.intval; | ||
401 | +} | ||
402 | + | ||
403 | +static int calculate_capacity(int using_charge) | ||
404 | +{ | ||
405 | + enum power_supply_property full_prop, empty_prop; | ||
406 | + enum power_supply_property full_design_prop, empty_design_prop; | ||
407 | + enum power_supply_property now_prop, avg_prop; | ||
408 | + union power_supply_propval empty, full, cur; | ||
409 | + int ret; | ||
410 | + | ||
411 | + if (using_charge) { | ||
412 | + full_prop = POWER_SUPPLY_PROP_CHARGE_FULL; | ||
413 | + empty_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY; | ||
414 | + full_design_prop = POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN; | ||
415 | + empty_design_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN; | ||
416 | + now_prop = POWER_SUPPLY_PROP_CHARGE_NOW; | ||
417 | + avg_prop = POWER_SUPPLY_PROP_CHARGE_AVG; | ||
418 | + } | ||
419 | + else { | ||
420 | + full_prop = POWER_SUPPLY_PROP_ENERGY_FULL; | ||
421 | + empty_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY; | ||
422 | + full_design_prop = POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN; | ||
423 | + empty_design_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN; | ||
424 | + now_prop = POWER_SUPPLY_PROP_ENERGY_NOW; | ||
425 | + avg_prop = POWER_SUPPLY_PROP_ENERGY_AVG; | ||
426 | + } | ||
427 | + | ||
428 | + if (_MPSY_PROP(full_prop, &full)) { | ||
429 | + /* if battery can't report this property, use design value */ | ||
430 | + if (_MPSY_PROP(full_design_prop, &full)) | ||
431 | + return -1; | ||
432 | + } | ||
433 | + | ||
434 | + if (_MPSY_PROP(avg_prop, &cur)) { | ||
435 | + /* if battery can't report average value, use momentary */ | ||
436 | + if (_MPSY_PROP(now_prop, &cur)) | ||
437 | + return -1; | ||
438 | + } | ||
439 | + | ||
440 | + if (_MPSY_PROP(empty_prop, &empty)) { | ||
441 | + /* if battery can't report this property, use design value */ | ||
442 | + if (_MPSY_PROP(empty_design_prop, &empty)) | ||
443 | + empty.intval = 0; | ||
444 | + } | ||
445 | + | ||
446 | + if (full.intval - empty.intval) | ||
447 | + ret = ((cur.intval - empty.intval) * 100L) / | ||
448 | + (full.intval - empty.intval); | ||
449 | + else | ||
450 | + return -1; | ||
451 | + | ||
452 | + if (ret > 100) | ||
453 | + return 100; | ||
454 | + else if (ret < 0) | ||
455 | + return 0; | ||
456 | + | ||
457 | + return ret; | ||
458 | +} | ||
459 | + | ||
460 | +static void apm_battery_apm_get_power_status(struct apm_power_info *info) | ||
461 | +{ | ||
462 | + union power_supply_propval status; | ||
463 | + union power_supply_propval capacity, time_to_full, time_to_empty; | ||
464 | + | ||
465 | + down(&power_supply_class->sem); | ||
466 | + find_main_battery(); | ||
467 | + if (!main_battery) { | ||
468 | + up(&power_supply_class->sem); | ||
469 | + return; | ||
470 | + } | ||
471 | + | ||
472 | + /* status */ | ||
473 | + | ||
474 | + if (MPSY_PROP(STATUS, &status)) | ||
475 | + status.intval = POWER_SUPPLY_STATUS_UNKNOWN; | ||
476 | + | ||
477 | + /* ac line status */ | ||
478 | + | ||
479 | + if ((status.intval == POWER_SUPPLY_STATUS_CHARGING) || | ||
480 | + (status.intval == POWER_SUPPLY_STATUS_NOT_CHARGING) || | ||
481 | + (status.intval == POWER_SUPPLY_STATUS_FULL)) | ||
482 | + info->ac_line_status = APM_AC_ONLINE; | ||
483 | + else | ||
484 | + info->ac_line_status = APM_AC_OFFLINE; | ||
485 | + | ||
486 | + /* battery life (i.e. capacity, in percents) */ | ||
487 | + | ||
488 | + if (MPSY_PROP(CAPACITY, &capacity) == 0) | ||
489 | + info->battery_life = capacity.intval; | ||
490 | + else { | ||
491 | + /* try calculate using energy */ | ||
492 | + info->battery_life = calculate_capacity(0); | ||
493 | + /* if failed try calculate using charge instead */ | ||
494 | + if (info->battery_life == -1) | ||
495 | + info->battery_life = calculate_capacity(1); | ||
496 | + } | ||
497 | + | ||
498 | + /* charging status */ | ||
499 | + | ||
500 | + if (status.intval == POWER_SUPPLY_STATUS_CHARGING) | ||
501 | + info->battery_status = APM_BATTERY_STATUS_CHARGING; | ||
502 | + else { | ||
503 | + if (info->battery_life > 50) | ||
504 | + info->battery_status = APM_BATTERY_STATUS_HIGH; | ||
505 | + else if (info->battery_life > 5) | ||
506 | + info->battery_status = APM_BATTERY_STATUS_LOW; | ||
507 | + else | ||
508 | + info->battery_status = APM_BATTERY_STATUS_CRITICAL; | ||
509 | + } | ||
510 | + info->battery_flag = info->battery_status; | ||
511 | + | ||
512 | + /* time */ | ||
513 | + | ||
514 | + info->units = APM_UNITS_MINS; | ||
515 | + | ||
516 | + if (status.intval == POWER_SUPPLY_STATUS_CHARGING) { | ||
517 | + if (MPSY_PROP(TIME_TO_FULL_AVG, &time_to_full)) { | ||
518 | + if (MPSY_PROP(TIME_TO_FULL_NOW, &time_to_full)) | ||
519 | + info->time = calculate_time(status.intval); | ||
520 | + else | ||
521 | + info->time = time_to_full.intval / 60; | ||
522 | + } | ||
523 | + } | ||
524 | + else { | ||
525 | + if (MPSY_PROP(TIME_TO_EMPTY_AVG, &time_to_empty)) { | ||
526 | + if (MPSY_PROP(TIME_TO_EMPTY_NOW, &time_to_empty)) | ||
527 | + info->time = calculate_time(status.intval); | ||
528 | + else | ||
529 | + info->time = time_to_empty.intval / 60; | ||
530 | + } | ||
531 | + } | ||
532 | + | ||
533 | + up(&power_supply_class->sem); | ||
534 | + return; | ||
535 | +} | ||
536 | + | ||
537 | +static int __init apm_battery_init(void) | ||
538 | +{ | ||
539 | + printk(KERN_INFO "APM Battery Driver\n"); | ||
540 | + | ||
541 | + apm_get_power_status = apm_battery_apm_get_power_status; | ||
542 | + return 0; | ||
543 | +} | ||
544 | + | ||
545 | +static void __exit apm_battery_exit(void) | ||
546 | +{ | ||
547 | + apm_get_power_status = NULL; | ||
548 | + return; | ||
549 | +} | ||
550 | + | ||
551 | +module_init(apm_battery_init); | ||
552 | +module_exit(apm_battery_exit); | ||
553 | + | ||
554 | +MODULE_AUTHOR("Eugeny Boger <eugenyboger@dgap.mipt.ru>"); | ||
555 | +MODULE_DESCRIPTION("APM emulation driver for battery monitoring class"); | ||
556 | +MODULE_LICENSE("GPL"); | ||
557 | Index: linux-2.6.22/drivers/power/ds2760_battery.c | ||
558 | =================================================================== | ||
559 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
560 | +++ linux-2.6.22/drivers/power/ds2760_battery.c 2007-08-23 12:13:52.000000000 +0200 | ||
561 | @@ -0,0 +1,475 @@ | ||
562 | +/* | ||
563 | + * Driver for batteries with DS2760 chips inside. | ||
564 | + * | ||
565 | + * Copyright (c) 2007 Anton Vorontsov | ||
566 | + * 2004-2007 Matt Reimer | ||
567 | + * 2004 Szabolcs Gyurko | ||
568 | + * | ||
569 | + * Use consistent with the GNU GPL is permitted, | ||
570 | + * provided that this copyright notice is | ||
571 | + * preserved in its entirety in all copies and derived works. | ||
572 | + * | ||
573 | + * Author: Anton Vorontsov <cbou@mail.ru> | ||
574 | + * February 2007 | ||
575 | + * | ||
576 | + * Matt Reimer <mreimer@vpop.net> | ||
577 | + * April 2004, 2005, 2007 | ||
578 | + * | ||
579 | + * Szabolcs Gyurko <szabolcs.gyurko@tlt.hu> | ||
580 | + * September 2004 | ||
581 | + */ | ||
582 | + | ||
583 | +#include <linux/module.h> | ||
584 | +#include <linux/param.h> | ||
585 | +#include <linux/jiffies.h> | ||
586 | +#include <linux/workqueue.h> | ||
587 | +#include <linux/pm.h> | ||
588 | +#include <linux/platform_device.h> | ||
589 | +#include <linux/power_supply.h> | ||
590 | + | ||
591 | +#include "../w1/w1.h" | ||
592 | +#include "../w1/slaves/w1_ds2760.h" | ||
593 | + | ||
594 | +struct ds2760_device_info { | ||
595 | + struct device *dev; | ||
596 | + | ||
597 | + /* DS2760 data, valid after calling ds2760_battery_read_status() */ | ||
598 | + unsigned long update_time; /* jiffies when data read */ | ||
599 | + char raw[DS2760_DATA_SIZE]; /* raw DS2760 data */ | ||
600 | + int voltage_raw; /* units of 4.88 mV */ | ||
601 | + int voltage_uV; /* units of uV */ | ||
602 | + int current_raw; /* units of 0.625 mA */ | ||
603 | + int current_uA; /* units of uA */ | ||
604 | + int accum_current_raw; /* units of 0.25 mAh */ | ||
605 | + int accum_current_uAh; /* units of uAh */ | ||
606 | + int temp_raw; /* units of 0.125 C */ | ||
607 | + int temp_C; /* units of 0.1 C */ | ||
608 | + int rated_capacity; /* units of uAh */ | ||
609 | + int rem_capacity; /* percentage */ | ||
610 | + int full_active_uAh; /* units of uAh */ | ||
611 | + int empty_uAh; /* units of uAh */ | ||
612 | + int life_sec; /* units of seconds */ | ||
613 | + int charge_status; /* POWER_SUPPLY_STATUS_* */ | ||
614 | + | ||
615 | + int full_counter; | ||
616 | + struct power_supply bat; | ||
617 | + struct device *w1_dev; | ||
618 | + struct workqueue_struct *monitor_wqueue; | ||
619 | + struct delayed_work monitor_work; | ||
620 | +}; | ||
621 | + | ||
622 | +static unsigned int cache_time = 1000; | ||
623 | +module_param(cache_time, uint, 0644); | ||
624 | +MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); | ||
625 | + | ||
626 | +/* Some batteries have their rated capacity stored a N * 10 mAh, while | ||
627 | + * others use an index into this table. */ | ||
628 | +static int rated_capacities[] = { | ||
629 | + 0, | ||
630 | + 920, /* Samsung */ | ||
631 | + 920, /* BYD */ | ||
632 | + 920, /* Lishen */ | ||
633 | + 920, /* NEC */ | ||
634 | + 1440, /* Samsung */ | ||
635 | + 1440, /* BYD */ | ||
636 | + 1440, /* Lishen */ | ||
637 | + 1440, /* NEC */ | ||
638 | + 2880, /* Samsung */ | ||
639 | + 2880, /* BYD */ | ||
640 | + 2880, /* Lishen */ | ||
641 | + 2880 /* NEC */ | ||
642 | +}; | ||
643 | + | ||
644 | +/* array is level at temps 0C, 10C, 20C, 30C, 40C | ||
645 | + * temp is in Celsius */ | ||
646 | +static int battery_interpolate(int array[], int temp) | ||
647 | +{ | ||
648 | + int index, dt; | ||
649 | + | ||
650 | + if (temp <= 0) | ||
651 | + return array[0]; | ||
652 | + if (temp >= 40) | ||
653 | + return array[4]; | ||
654 | + | ||
655 | + index = temp / 10; | ||
656 | + dt = temp % 10; | ||
657 | + | ||
658 | + return array[index] + (((array[index + 1] - array[index]) * dt) / 10); | ||
659 | +} | ||
660 | + | ||
661 | +static int ds2760_battery_read_status(struct ds2760_device_info *di) | ||
662 | +{ | ||
663 | + int ret, i, start, count, scale[5]; | ||
664 | + | ||
665 | + if (di->update_time && time_before(jiffies, di->update_time + | ||
666 | + msecs_to_jiffies(cache_time))) | ||
667 | + return 0; | ||
668 | + | ||
669 | + /* The first time we read the entire contents of SRAM/EEPROM, | ||
670 | + * but after that we just read the interesting bits that change. */ | ||
671 | + if (di->update_time == 0) { | ||
672 | + start = 0; | ||
673 | + count = DS2760_DATA_SIZE; | ||
674 | + } | ||
675 | + else { | ||
676 | + start = DS2760_VOLTAGE_MSB; | ||
677 | + count = DS2760_TEMP_LSB - start + 1; | ||
678 | + } | ||
679 | + | ||
680 | + ret = w1_ds2760_read(di->w1_dev, di->raw + start, start, count); | ||
681 | + if (ret != count) { | ||
682 | + dev_warn(di->dev, "call to w1_ds2760_read failed (0x%p)\n", | ||
683 | + di->w1_dev); | ||
684 | + return 1; | ||
685 | + } | ||
686 | + | ||
687 | + di->update_time = jiffies; | ||
688 | + | ||
689 | + /* DS2760 reports voltage in units of 4.88mV, but the battery class | ||
690 | + * reports in units of uV, so convert by multiplying by 4880. */ | ||
691 | + di->voltage_raw = (di->raw[DS2760_VOLTAGE_MSB] << 3) | | ||
692 | + (di->raw[DS2760_VOLTAGE_LSB] >> 5); | ||
693 | + di->voltage_uV = di->voltage_raw * 4880; | ||
694 | + | ||
695 | + /* DS2760 reports current in signed units of 0.625mA, but the battery | ||
696 | + * class reports in units of uA, so convert by multiplying by 625. */ | ||
697 | + di->current_raw = | ||
698 | + (((signed char)di->raw[DS2760_CURRENT_MSB]) << 5) | | ||
699 | + (di->raw[DS2760_CURRENT_LSB] >> 3); | ||
700 | + di->current_uA = di->current_raw * 625; | ||
701 | + | ||
702 | + /* DS2760 reports accumulated current in signed units of 0.25mAh. */ | ||
703 | + di->accum_current_raw = | ||
704 | + (((signed char)di->raw[DS2760_CURRENT_ACCUM_MSB]) << 8) | | ||
705 | + di->raw[DS2760_CURRENT_ACCUM_LSB]; | ||
706 | + di->accum_current_uAh = di->accum_current_raw * 250; | ||
707 | + | ||
708 | + /* DS2760 reports temperature in signed units of 0.125C, but the | ||
709 | + * battery class reports in units of 1/10 C, so we convert by | ||
710 | + * multiplying by .125 * 10 = 1.25. */ | ||
711 | + di->temp_raw = (((signed char)di->raw[DS2760_TEMP_MSB]) << 3) | | ||
712 | + (di->raw[DS2760_TEMP_LSB] >> 5); | ||
713 | + di->temp_C = di->temp_raw + (di->temp_raw / 4); | ||
714 | + | ||
715 | + /* At least some battery monitors (e.g. HP iPAQ) store the battery's | ||
716 | + * maximum rated capacity. */ | ||
717 | + if (di->raw[DS2760_RATED_CAPACITY] < ARRAY_SIZE(rated_capacities)) | ||
718 | + di->rated_capacity = rated_capacities[ | ||
719 | + (unsigned int)di->raw[DS2760_RATED_CAPACITY]]; | ||
720 | + else | ||
721 | + di->rated_capacity = di->raw[DS2760_RATED_CAPACITY] * 10; | ||
722 | + | ||
723 | + di->rated_capacity *= 1000; /* convert to uAh */ | ||
724 | + | ||
725 | + /* Calculate the full level at the present temperature. */ | ||
726 | + di->full_active_uAh = di->raw[DS2760_ACTIVE_FULL] << 8 | | ||
727 | + di->raw[DS2760_ACTIVE_FULL + 1]; | ||
728 | + | ||
729 | + scale[0] = di->raw[DS2760_ACTIVE_FULL] << 8 | | ||
730 | + di->raw[DS2760_ACTIVE_FULL + 1]; | ||
731 | + for (i = 1; i < 5; i++) | ||
732 | + scale[i] = scale[i - 1] + di->raw[DS2760_ACTIVE_FULL + 2 + i]; | ||
733 | + | ||
734 | + di->full_active_uAh = battery_interpolate(scale, di->temp_C / 10); | ||
735 | + di->full_active_uAh *= 1000; /* convert to uAh */ | ||
736 | + | ||
737 | + /* Calculate the empty level at the present temperature. */ | ||
738 | + scale[4] = di->raw[DS2760_ACTIVE_EMPTY + 4]; | ||
739 | + for (i = 3; i >= 0; i--) | ||
740 | + scale[i] = scale[i + 1] + di->raw[DS2760_ACTIVE_EMPTY + i]; | ||
741 | + | ||
742 | + di->empty_uAh = battery_interpolate(scale, di->temp_C / 10); | ||
743 | + di->empty_uAh *= 1000; /* convert to uAh */ | ||
744 | + | ||
745 | + /* From Maxim Application Note 131: remaining capacity = | ||
746 | + * ((ICA - Empty Value) / (Full Value - Empty Value)) x 100% */ | ||
747 | + di->rem_capacity = ((di->accum_current_uAh - di->empty_uAh) * 100L) / | ||
748 | + (di->full_active_uAh - di->empty_uAh); | ||
749 | + | ||
750 | + if (di->rem_capacity < 0) | ||
751 | + di->rem_capacity = 0; | ||
752 | + if (di->rem_capacity > 100) | ||
753 | + di->rem_capacity = 100; | ||
754 | + | ||
755 | + if (di->current_uA) | ||
756 | + di->life_sec = -((di->accum_current_uAh - di->empty_uAh) * | ||
757 | + 3600L) / di->current_uA; | ||
758 | + else | ||
759 | + di->life_sec = 0; | ||
760 | + | ||
761 | + return 0; | ||
762 | +} | ||
763 | + | ||
764 | +static void ds2760_battery_update_status(struct ds2760_device_info *di) | ||
765 | +{ | ||
766 | + int old_charge_status = di->charge_status; | ||
767 | + | ||
768 | + ds2760_battery_read_status(di); | ||
769 | + | ||
770 | + if (di->charge_status == POWER_SUPPLY_STATUS_UNKNOWN) | ||
771 | + di->full_counter = 0; | ||
772 | + | ||
773 | + if (power_supply_am_i_supplied(&di->bat)) { | ||
774 | + if (di->current_uA > 10000) { | ||
775 | + di->charge_status = POWER_SUPPLY_STATUS_CHARGING; | ||
776 | + di->full_counter = 0; | ||
777 | + } | ||
778 | + else if (di->current_uA < -5000) { | ||
779 | + if (di->charge_status != POWER_SUPPLY_STATUS_NOT_CHARGING) | ||
780 | + dev_notice(di->dev, "not enough power to " | ||
781 | + "charge\n"); | ||
782 | + di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING; | ||
783 | + di->full_counter = 0; | ||
784 | + } | ||
785 | + else if (di->current_uA < 10000 && | ||
786 | + di->charge_status != POWER_SUPPLY_STATUS_FULL) { | ||
787 | + | ||
788 | + /* Don't consider the battery to be full unless | ||
789 | + * we've seen the current < 10 mA at least two | ||
790 | + * consecutive times. */ | ||
791 | + | ||
792 | + di->full_counter++; | ||
793 | + | ||
794 | + if (di->full_counter < 2) | ||
795 | + di->charge_status = POWER_SUPPLY_STATUS_CHARGING; | ||
796 | + else { | ||
797 | + unsigned char acr[2]; | ||
798 | + int acr_val; | ||
799 | + | ||
800 | + /* acr is in units of 0.25 mAh */ | ||
801 | + acr_val = di->full_active_uAh * 4L / 1000; | ||
802 | + | ||
803 | + acr[0] = acr_val >> 8; | ||
804 | + acr[1] = acr_val & 0xff; | ||
805 | + | ||
806 | + if (w1_ds2760_write(di->w1_dev, acr, | ||
807 | + DS2760_CURRENT_ACCUM_MSB, 2) < 2) | ||
808 | + dev_warn(di->dev, | ||
809 | + "ACR reset failed\n"); | ||
810 | + | ||
811 | + di->charge_status = POWER_SUPPLY_STATUS_FULL; | ||
812 | + } | ||
813 | + } | ||
814 | + } | ||
815 | + else { | ||
816 | + di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING; | ||
817 | + di->full_counter = 0; | ||
818 | + } | ||
819 | + | ||
820 | + if (di->charge_status != old_charge_status) | ||
821 | + power_supply_changed(&di->bat); | ||
822 | + | ||
823 | + return; | ||
824 | +} | ||
825 | + | ||
826 | +static void ds2760_battery_work(struct work_struct *work) | ||
827 | +{ | ||
828 | + struct ds2760_device_info *di = container_of(work, | ||
829 | + struct ds2760_device_info, monitor_work.work); | ||
830 | + const int interval = HZ * 60; | ||
831 | + | ||
832 | + dev_dbg(di->dev, "%s\n", __FUNCTION__); | ||
833 | + | ||
834 | + ds2760_battery_update_status(di); | ||
835 | + queue_delayed_work(di->monitor_wqueue, &di->monitor_work, interval); | ||
836 | + | ||
837 | + return; | ||
838 | +} | ||
839 | + | ||
840 | +#define to_ds2760_device_info(x) container_of((x), struct ds2760_device_info, \ | ||
841 | + bat); | ||
842 | + | ||
843 | +static void ds2760_battery_external_power_changed(struct power_supply *psy) | ||
844 | +{ | ||
845 | + struct ds2760_device_info *di = to_ds2760_device_info(psy); | ||
846 | + | ||
847 | + dev_dbg(di->dev, "%s\n", __FUNCTION__); | ||
848 | + | ||
849 | + cancel_delayed_work(&di->monitor_work); | ||
850 | + queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ/10); | ||
851 | + | ||
852 | + return; | ||
853 | +} | ||
854 | + | ||
855 | +static int ds2760_battery_get_property(struct power_supply *psy, | ||
856 | + enum power_supply_property psp, | ||
857 | + union power_supply_propval *val) | ||
858 | +{ | ||
859 | + struct ds2760_device_info *di = to_ds2760_device_info(psy); | ||
860 | + | ||
861 | + switch (psp) { | ||
862 | + case POWER_SUPPLY_PROP_STATUS: | ||
863 | + val->intval = di->charge_status; | ||
864 | + return 0; | ||
865 | + default: | ||
866 | + break; | ||
867 | + } | ||
868 | + | ||
869 | + ds2760_battery_read_status(di); | ||
870 | + | ||
871 | + switch (psp) { | ||
872 | + case POWER_SUPPLY_PROP_VOLTAGE_NOW: | ||
873 | + val->intval = di->voltage_uV; | ||
874 | + break; | ||
875 | + case POWER_SUPPLY_PROP_CURRENT_NOW: | ||
876 | + val->intval = di->current_uA; | ||
877 | + break; | ||
878 | + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: | ||
879 | + val->intval = di->rated_capacity; | ||
880 | + break; | ||
881 | + case POWER_SUPPLY_PROP_CHARGE_FULL: | ||
882 | + val->intval = di->full_active_uAh; | ||
883 | + break; | ||
884 | + case POWER_SUPPLY_PROP_CHARGE_EMPTY: | ||
885 | + val->intval = di->empty_uAh; | ||
886 | + break; | ||
887 | + case POWER_SUPPLY_PROP_CHARGE_NOW: | ||
888 | + val->intval = di->accum_current_uAh; | ||
889 | + break; | ||
890 | + case POWER_SUPPLY_PROP_TEMP: | ||
891 | + val->intval = di->temp_C; | ||
892 | + break; | ||
893 | + default: | ||
894 | + return -EINVAL; | ||
895 | + } | ||
896 | + | ||
897 | + return 0; | ||
898 | +} | ||
899 | + | ||
900 | +static enum power_supply_property ds2760_battery_props[] = { | ||
901 | + POWER_SUPPLY_PROP_STATUS, | ||
902 | + POWER_SUPPLY_PROP_VOLTAGE_NOW, | ||
903 | + POWER_SUPPLY_PROP_CURRENT_NOW, | ||
904 | + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, | ||
905 | + POWER_SUPPLY_PROP_CHARGE_FULL, | ||
906 | + POWER_SUPPLY_PROP_CHARGE_EMPTY, | ||
907 | + POWER_SUPPLY_PROP_CHARGE_NOW, | ||
908 | + POWER_SUPPLY_PROP_TEMP, | ||
909 | +}; | ||
910 | + | ||
911 | +static int ds2760_battery_probe(struct platform_device *pdev) | ||
912 | +{ | ||
913 | + int retval = 0; | ||
914 | + struct ds2760_device_info *di; | ||
915 | + struct ds2760_platform_data *pdata; | ||
916 | + | ||
917 | + di = kzalloc(sizeof(*di), GFP_KERNEL); | ||
918 | + if (!di) { | ||
919 | + retval = -ENOMEM; | ||
920 | + goto di_alloc_failed; | ||
921 | + } | ||
922 | + | ||
923 | + platform_set_drvdata(pdev, di); | ||
924 | + | ||
925 | + pdata = pdev->dev.platform_data; | ||
926 | + di->dev = &pdev->dev; | ||
927 | + di->w1_dev = pdev->dev.parent; | ||
928 | + di->bat.name = pdev->dev.bus_id; | ||
929 | + di->bat.type = POWER_SUPPLY_TYPE_BATTERY; | ||
930 | + di->bat.properties = ds2760_battery_props; | ||
931 | + di->bat.num_properties = ARRAY_SIZE(ds2760_battery_props); | ||
932 | + di->bat.get_property = ds2760_battery_get_property; | ||
933 | + di->bat.external_power_changed = | ||
934 | + ds2760_battery_external_power_changed; | ||
935 | + di->bat.use_for_apm = 1; | ||
936 | + | ||
937 | + di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; | ||
938 | + | ||
939 | + retval = power_supply_register(&pdev->dev, &di->bat); | ||
940 | + if (retval) { | ||
941 | + dev_err(di->dev, "failed to register battery"); | ||
942 | + goto batt_failed; | ||
943 | + } | ||
944 | + | ||
945 | + INIT_DELAYED_WORK(&di->monitor_work, ds2760_battery_work); | ||
946 | + di->monitor_wqueue = create_singlethread_workqueue(pdev->dev.bus_id); | ||
947 | + if (!di->monitor_wqueue) { | ||
948 | + retval = -ESRCH; | ||
949 | + goto workqueue_failed; | ||
950 | + } | ||
951 | + queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ * 1); | ||
952 | + | ||
953 | + goto success; | ||
954 | + | ||
955 | +workqueue_failed: | ||
956 | + power_supply_unregister(&di->bat); | ||
957 | +batt_failed: | ||
958 | + kfree(di); | ||
959 | +di_alloc_failed: | ||
960 | +success: | ||
961 | + return retval; | ||
962 | +} | ||
963 | + | ||
964 | +static int ds2760_battery_remove(struct platform_device *pdev) | ||
965 | +{ | ||
966 | + struct ds2760_device_info *di = platform_get_drvdata(pdev); | ||
967 | + | ||
968 | + cancel_rearming_delayed_workqueue(di->monitor_wqueue, | ||
969 | + &di->monitor_work); | ||
970 | + destroy_workqueue(di->monitor_wqueue); | ||
971 | + power_supply_unregister(&di->bat); | ||
972 | + | ||
973 | + return 0; | ||
974 | +} | ||
975 | + | ||
976 | +#ifdef CONFIG_PM | ||
977 | + | ||
978 | +static int ds2760_battery_suspend(struct platform_device *pdev, | ||
979 | + pm_message_t state) | ||
980 | +{ | ||
981 | + struct ds2760_device_info *di = platform_get_drvdata(pdev); | ||
982 | + | ||
983 | + di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; | ||
984 | + | ||
985 | + return 0; | ||
986 | +} | ||
987 | + | ||
988 | +static int ds2760_battery_resume(struct platform_device *pdev) | ||
989 | +{ | ||
990 | + struct ds2760_device_info *di = platform_get_drvdata(pdev); | ||
991 | + | ||
992 | + di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; | ||
993 | + power_supply_changed(&di->bat); | ||
994 | + | ||
995 | + cancel_delayed_work(&di->monitor_work); | ||
996 | + queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ); | ||
997 | + | ||
998 | + return 0; | ||
999 | +} | ||
1000 | + | ||
1001 | +#else | ||
1002 | + | ||
1003 | +#define ds2760_battery_suspend NULL | ||
1004 | +#define ds2760_battery_resume NULL | ||
1005 | + | ||
1006 | +#endif /* CONFIG_PM */ | ||
1007 | + | ||
1008 | +static struct platform_driver ds2760_battery_driver = { | ||
1009 | + .driver = { | ||
1010 | + .name = "ds2760-battery", | ||
1011 | + }, | ||
1012 | + .probe = ds2760_battery_probe, | ||
1013 | + .remove = ds2760_battery_remove, | ||
1014 | + .suspend = ds2760_battery_suspend, | ||
1015 | + .resume = ds2760_battery_resume, | ||
1016 | +}; | ||
1017 | + | ||
1018 | +static int __init ds2760_battery_init(void) | ||
1019 | +{ | ||
1020 | + return platform_driver_register(&ds2760_battery_driver); | ||
1021 | +} | ||
1022 | + | ||
1023 | +static void __exit ds2760_battery_exit(void) | ||
1024 | +{ | ||
1025 | + platform_driver_unregister(&ds2760_battery_driver); | ||
1026 | + return; | ||
1027 | +} | ||
1028 | + | ||
1029 | +module_init(ds2760_battery_init); | ||
1030 | +module_exit(ds2760_battery_exit); | ||
1031 | + | ||
1032 | +MODULE_LICENSE("GPL"); | ||
1033 | +MODULE_AUTHOR("Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>, " | ||
1034 | + "Matt Reimer <mreimer@vpop.net>, " | ||
1035 | + "Anton Vorontsov <cbou@mail.ru>"); | ||
1036 | +MODULE_DESCRIPTION("ds2760 battery driver"); | ||
1037 | Index: linux-2.6.22/drivers/power/Kconfig | ||
1038 | =================================================================== | ||
1039 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
1040 | +++ linux-2.6.22/drivers/power/Kconfig 2007-08-23 12:13:52.000000000 +0200 | ||
1041 | @@ -0,0 +1,70 @@ | ||
1042 | +menuconfig POWER_SUPPLY | ||
1043 | + tristate "Power supply class support" | ||
1044 | + help | ||
1045 | + Say Y here to enable power supply class support. This allows | ||
1046 | + power supply (batteries, AC, USB) monitoring by userspace | ||
1047 | + via sysfs and uevent (if available) and/or APM kernel interface | ||
1048 | + (if selected below). | ||
1049 | + | ||
1050 | +if POWER_SUPPLY | ||
1051 | + | ||
1052 | +config POWER_SUPPLY_DEBUG | ||
1053 | + bool "Power supply debug" | ||
1054 | + help | ||
1055 | + Say Y here to enable debugging messages for power supply class | ||
1056 | + and drivers. | ||
1057 | + | ||
1058 | +config PDA_POWER | ||
1059 | + tristate "Generic PDA/phone power driver" | ||
1060 | + help | ||
1061 | + Say Y here to enable generic power driver for PDAs and phones with | ||
1062 | + one or two external power supplies (AC/USB) connected to main and | ||
1063 | + backup batteries, and optional builtin charger. | ||
1064 | + | ||
1065 | +config APM_POWER | ||
1066 | + tristate "APM emulation for class batteries" | ||
1067 | + depends on APM_EMULATION | ||
1068 | + help | ||
1069 | + Say Y here to enable support APM status emulation using | ||
1070 | + battery class devices. | ||
1071 | + | ||
1072 | +config BATTERY_DS2760 | ||
1073 | + tristate "DS2760 battery driver (HP iPAQ & others)" | ||
1074 | + select W1 | ||
1075 | + select W1_SLAVE_DS2760 | ||
1076 | + help | ||
1077 | + Say Y here to enable support for batteries with ds2760 chip. | ||
1078 | + | ||
1079 | +config BATTERY_PMU | ||
1080 | + tristate "Apple PMU battery" | ||
1081 | + depends on ADB_PMU | ||
1082 | + help | ||
1083 | + Say Y here to expose battery information on Apple machines | ||
1084 | + through the generic battery class. | ||
1085 | + | ||
1086 | +config BATTERY_OLPC | ||
1087 | + tristate "One Laptop Per Child battery" | ||
1088 | + depends on X86_32 | ||
1089 | + help | ||
1090 | + Say Y to enable support for the battery on the OLPC laptop. | ||
1091 | + | ||
1092 | +# drivers below are not in battery2-2.6 tree | ||
1093 | + | ||
1094 | +config ADC_BATTERY | ||
1095 | + tristate "Generic ADC battery driver" | ||
1096 | + depends on ADC && POWER_SUPPLY | ||
1097 | + help | ||
1098 | + Say Y here to enable support for battery monitoring using generic ADC device. | ||
1099 | + | ||
1100 | +config IPAQ_MICRO_BATTERY | ||
1101 | + tristate "HP iPAQ Micro ASIC battery driver" | ||
1102 | + depends on IPAQ_MICRO && POWER_SUPPLY | ||
1103 | + help | ||
1104 | + Choose this option if you want to monitor battery status on | ||
1105 | + Compaq/HP iPAQ h3100 h3600 | ||
1106 | + | ||
1107 | +config MCP_UCB1x00_SIMPAD_BATTERY | ||
1108 | + tristate "SIMpad Battery Reading Support" | ||
1109 | + depends on MCP_UCB1x00 && POWER_SUPPLY | ||
1110 | + | ||
1111 | +endif # POWER_SUPPLY | ||
1112 | Index: linux-2.6.22/drivers/power/Makefile | ||
1113 | =================================================================== | ||
1114 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
1115 | +++ linux-2.6.22/drivers/power/Makefile 2007-08-23 12:13:52.000000000 +0200 | ||
1116 | @@ -0,0 +1,28 @@ | ||
1117 | +power_supply-objs := power_supply_core.o | ||
1118 | + | ||
1119 | +ifeq ($(CONFIG_SYSFS),y) | ||
1120 | +power_supply-objs += power_supply_sysfs.o | ||
1121 | +endif | ||
1122 | + | ||
1123 | +ifeq ($(CONFIG_LEDS_TRIGGERS),y) | ||
1124 | +power_supply-objs += power_supply_leds.o | ||
1125 | +endif | ||
1126 | + | ||
1127 | +ifeq ($(CONFIG_POWER_SUPPLY_DEBUG),y) | ||
1128 | +EXTRA_CFLAGS += -DDEBUG | ||
1129 | +endif | ||
1130 | + | ||
1131 | +obj-$(CONFIG_POWER_SUPPLY) += power_supply.o | ||
1132 | + | ||
1133 | +obj-$(CONFIG_PDA_POWER) += pda_power.o | ||
1134 | +obj-$(CONFIG_APM_POWER) += apm_power.o | ||
1135 | + | ||
1136 | +obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o | ||
1137 | +obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o | ||
1138 | +obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o | ||
1139 | + | ||
1140 | +# drivers below are not in battery2-2.6 tree | ||
1141 | + | ||
1142 | +obj-$(CONFIG_ADC_BATTERY) += adc_battery.o | ||
1143 | +obj-$(CONFIG_IPAQ_MICRO_BATTERY) += micro_battery.o | ||
1144 | +obj-$(CONFIG_MCP_UCB1x00_SIMPAD_BATTERY) += simpad-battery.o | ||
1145 | Index: linux-2.6.22/drivers/power/micro_battery.c | ||
1146 | =================================================================== | ||
1147 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
1148 | +++ linux-2.6.22/drivers/power/micro_battery.c 2007-08-23 12:25:20.000000000 +0200 | ||
1149 | @@ -0,0 +1,257 @@ | ||
1150 | +/* | ||
1151 | + * This program is free software; you can redistribute it and/or modify | ||
1152 | + * it under the terms of the GNU General Public License version 2 as | ||
1153 | + * published by the Free Software Foundation. | ||
1154 | + * | ||
1155 | + * h3600 atmel micro companion support, battery subdevice | ||
1156 | + * based on previous kernel 2.4 version | ||
1157 | + * Author : Alessandro Gardich <gremlin@gremlin.it> | ||
1158 | + * | ||
1159 | + */ | ||
1160 | + | ||
1161 | + | ||
1162 | +#include <linux/module.h> | ||
1163 | +#include <linux/version.h> | ||
1164 | + | ||
1165 | +#include <linux/init.h> | ||
1166 | +#include <linux/fs.h> | ||
1167 | +#include <linux/interrupt.h> | ||
1168 | +#include <linux/sched.h> | ||
1169 | +#include <linux/pm.h> | ||
1170 | +#include <linux/sysctl.h> | ||
1171 | +#include <linux/proc_fs.h> | ||
1172 | +#include <linux/delay.h> | ||
1173 | +#include <linux/device.h> | ||
1174 | +#include <linux/power_supply.h> | ||
1175 | +#include <linux/platform_device.h> | ||
1176 | +#include <linux/timer.h> | ||
1177 | + | ||
1178 | +#include <asm/arch/hardware.h> | ||
1179 | + | ||
1180 | +#include <asm/arch/h3600.h> | ||
1181 | +#include <asm/arch/SA-1100.h> | ||
1182 | + | ||
1183 | +#include <asm/hardware/micro.h> | ||
1184 | + | ||
1185 | +#define BATT_PERIOD 10*HZ | ||
1186 | + | ||
1187 | +#define H3600_BATT_STATUS_HIGH 0x01 | ||
1188 | +#define H3600_BATT_STATUS_LOW 0x02 | ||
1189 | +#define H3600_BATT_STATUS_CRITICAL 0x04 | ||
1190 | +#define H3600_BATT_STATUS_CHARGING 0x08 | ||
1191 | +#define H3600_BATT_STATUS_CHARGEMAIN 0x10 | ||
1192 | +#define H3600_BATT_STATUS_DEAD 0x20 /* Battery will not charge */ | ||
1193 | +#define H3600_BATT_STATUS_NOTINSTALLED 0x20 /* For expansion pack batteries */ | ||
1194 | +#define H3600_BATT_STATUS_FULL 0x40 /* Battery fully charged (and connected to AC) */ | ||
1195 | +#define H3600_BATT_STATUS_NOBATTERY 0x80 | ||
1196 | +#define H3600_BATT_STATUS_UNKNOWN 0xff | ||
1197 | + | ||
1198 | + | ||
1199 | +//static struct power_supply_dev *micro_battery; | ||
1200 | + | ||
1201 | +static micro_private_t *p_micro; | ||
1202 | + | ||
1203 | +struct timer_list batt_timer; | ||
1204 | + | ||
1205 | +struct { | ||
1206 | + int ac; | ||
1207 | + int update_time; | ||
1208 | + int chemistry; | ||
1209 | + int voltage; | ||
1210 | + int temperature; | ||
1211 | + int flag; | ||
1212 | +} micro_battery; | ||
1213 | + | ||
1214 | +static void micro_battery_receive (int len, unsigned char *data) { | ||
1215 | + if (0) { | ||
1216 | + printk(KERN_ERR "h3600_battery - AC = %02x\n", data[0]); | ||
1217 | + printk(KERN_ERR "h3600_battery - BAT1 chemistry = %02x\n", data[1]); | ||
1218 | + printk(KERN_ERR "h3600_battery - BAT1 voltage = %d %02x%02x\n", (data[3]<<8)+data[2], data[2], data[3]); | ||
1219 | + printk(KERN_ERR "h3600_battery - BAT1 status = %02x\n", data[4]); | ||
1220 | + } | ||
1221 | + | ||
1222 | + micro_battery.ac = data[0]; | ||
1223 | + micro_battery.chemistry = data[1]; | ||
1224 | + micro_battery.voltage = ((((unsigned short)data[3]<<8)+data[2]) * 5000L ) * 1000 / 1024; | ||
1225 | + micro_battery.flag = data[4]; | ||
1226 | + | ||
1227 | + if (len == 9) { | ||
1228 | + if (0) { | ||
1229 | + printk(KERN_ERR "h3600_battery - BAT2 chemistry = %02x\n", data[5]); | ||
1230 | + printk(KERN_ERR "h3600_battery - BAT2 voltage = %d %02x%02x\n", (data[7]<<8)+data[6], data[6], data[7]); | ||
1231 | + printk(KERN_ERR "h3600_battery - BAT2 status = %02x\n", data[8]); | ||
1232 | + } | ||
1233 | + } | ||
1234 | +} | ||
1235 | + | ||
1236 | +static void micro_temperature_receive (int len, unsigned char *data) { | ||
1237 | + micro_battery.temperature = ((unsigned short)data[1]<<8)+data[0]; | ||
1238 | +} | ||
1239 | + | ||
1240 | +void h3600_battery_read_status(unsigned long data) { | ||
1241 | + | ||
1242 | + if (++data % 2) | ||
1243 | + h3600_micro_tx_msg(0x09,0,NULL); | ||
1244 | + else | ||
1245 | + h3600_micro_tx_msg(0x06,0,NULL); | ||
1246 | + | ||
1247 | + batt_timer.expires += BATT_PERIOD; | ||
1248 | + batt_timer.data = data; | ||
1249 | + | ||
1250 | + add_timer(&batt_timer); | ||
1251 | +} | ||
1252 | + | ||
1253 | +int get_capacity(struct power_supply *b) { | ||
1254 | + switch (micro_battery.flag) { | ||
1255 | + case H3600_BATT_STATUS_HIGH : return 100; break; | ||
1256 | + case H3600_BATT_STATUS_LOW : return 50; break; | ||
1257 | + case H3600_BATT_STATUS_CRITICAL : return 5; break; | ||
1258 | + default: break; | ||
1259 | + } | ||
1260 | + return 0; | ||
1261 | +} | ||
1262 | + | ||
1263 | +int get_status(struct power_supply *b) { | ||
1264 | + | ||
1265 | + if (micro_battery.flag == H3600_BATT_STATUS_UNKNOWN) | ||
1266 | + return POWER_SUPPLY_STATUS_UNKNOWN; | ||
1267 | + | ||
1268 | + if (micro_battery.flag & H3600_BATT_STATUS_FULL) | ||
1269 | + return POWER_SUPPLY_STATUS_FULL; | ||
1270 | + | ||
1271 | + if ((micro_battery.flag & H3600_BATT_STATUS_CHARGING) || | ||
1272 | + (micro_battery.flag & H3600_BATT_STATUS_CHARGEMAIN)) | ||
1273 | + return POWER_SUPPLY_STATUS_CHARGING; | ||
1274 | + | ||
1275 | + return POWER_SUPPLY_STATUS_DISCHARGING; | ||
1276 | +} | ||
1277 | + | ||
1278 | +static int micro_batt_get_property(struct power_supply *b, | ||
1279 | + enum power_supply_property psp, | ||
1280 | + union power_supply_propval *val) | ||
1281 | +{ | ||
1282 | + switch (psp) { | ||
1283 | + case POWER_SUPPLY_PROP_STATUS: | ||
1284 | + val->intval = get_status(b); | ||
1285 | + break; | ||
1286 | + case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: | ||
1287 | + val->intval = 4700000; | ||
1288 | + break; | ||
1289 | + case POWER_SUPPLY_PROP_CAPACITY: | ||
1290 | + val->intval = get_capacity(b); | ||
1291 | + break; | ||
1292 | + case POWER_SUPPLY_PROP_TEMP: | ||
1293 | + val->intval = micro_battery.temperature; | ||
1294 | + break; | ||
1295 | + case POWER_SUPPLY_PROP_VOLTAGE_NOW: | ||
1296 | + val->intval = micro_battery.voltage; | ||
1297 | + break; | ||
1298 | + default: | ||
1299 | + return -EINVAL; | ||
1300 | + }; | ||
1301 | + | ||
1302 | + return 0; | ||
1303 | +} | ||
1304 | + | ||
1305 | +static enum power_supply_property micro_batt_props[] = { | ||
1306 | + POWER_SUPPLY_PROP_STATUS, | ||
1307 | + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, | ||
1308 | + POWER_SUPPLY_PROP_CAPACITY, | ||
1309 | + POWER_SUPPLY_PROP_TEMP, | ||
1310 | + POWER_SUPPLY_PROP_VOLTAGE_NOW, | ||
1311 | +}; | ||
1312 | + | ||
1313 | +static struct power_supply h3600_battery = { | ||
1314 | + .name = "main-battery", | ||
1315 | + .properties = micro_batt_props, | ||
1316 | + .num_properties = ARRAY_SIZE(micro_batt_props), | ||
1317 | + .get_property = micro_batt_get_property, | ||
1318 | + .use_for_apm = 1, | ||
1319 | +}; | ||
1320 | + | ||
1321 | +static int micro_batt_probe (struct platform_device *pdev) | ||
1322 | +{ | ||
1323 | + if (1) printk(KERN_ERR "micro battery probe : begin\n"); | ||
1324 | + | ||
1325 | + power_supply_register(&pdev->dev, &h3600_battery); | ||
1326 | + | ||
1327 | + { /*--- callback ---*/ | ||
1328 | + p_micro = platform_get_drvdata(pdev); | ||
1329 | + spin_lock(p_micro->lock); | ||
1330 | + p_micro->h_batt = micro_battery_receive; | ||
1331 | + p_micro->h_temp = micro_temperature_receive; | ||
1332 | + spin_unlock(p_micro->lock); | ||
1333 | + } | ||
1334 | + | ||
1335 | + { /*--- timer ---*/ | ||
1336 | + init_timer(&batt_timer); | ||
1337 | + batt_timer.expires = jiffies + BATT_PERIOD; | ||
1338 | + batt_timer.data = 0; | ||
1339 | + batt_timer.function = h3600_battery_read_status; | ||
1340 | + | ||
1341 | + add_timer(&batt_timer); | ||
1342 | + } | ||
1343 | + | ||
1344 | + if (1) printk(KERN_ERR "micro battery probe : end\n"); | ||
1345 | + return 0; | ||
1346 | +} | ||
1347 | + | ||
1348 | +static int micro_batt_remove (struct platform_device *pdev) | ||
1349 | +{ | ||
1350 | + power_supply_unregister(&h3600_battery); | ||
1351 | + { /*--- callback ---*/ | ||
1352 | + init_timer(&batt_timer); | ||
1353 | + p_micro->h_batt = NULL; | ||
1354 | + p_micro->h_temp = NULL; | ||
1355 | + spin_unlock(p_micro->lock); | ||
1356 | + } | ||
1357 | + { /*--- timer ---*/ | ||
1358 | + del_timer_sync(&batt_timer); | ||
1359 | + } | ||
1360 | + return 0; | ||
1361 | +} | ||
1362 | + | ||
1363 | +static int micro_batt_suspend ( struct platform_device *pdev, pm_message_t state) | ||
1364 | +{ | ||
1365 | + { /*--- timer ---*/ | ||
1366 | + del_timer(&batt_timer); | ||
1367 | + } | ||
1368 | + return 0; | ||
1369 | +} | ||
1370 | + | ||
1371 | +static int micro_batt_resume ( struct platform_device *pdev) | ||
1372 | +{ | ||
1373 | + { /*--- timer ---*/ | ||
1374 | + add_timer(&batt_timer); | ||
1375 | + } | ||
1376 | + return 0; | ||
1377 | +} | ||
1378 | + | ||
1379 | +struct platform_driver micro_batt_device_driver = { | ||
1380 | + .driver = { | ||
1381 | + .name = "h3600-micro-battery", | ||
1382 | + }, | ||
1383 | + .probe = micro_batt_probe, | ||
1384 | + .remove = micro_batt_remove, | ||
1385 | + .suspend = micro_batt_suspend, | ||
1386 | + .resume = micro_batt_resume, | ||
1387 | +}; | ||
1388 | + | ||
1389 | +static int micro_batt_init (void) | ||
1390 | +{ | ||
1391 | + return platform_driver_register(µ_batt_device_driver); | ||
1392 | +} | ||
1393 | + | ||
1394 | +static void micro_batt_cleanup (void) | ||
1395 | +{ | ||
1396 | + platform_driver_unregister (µ_batt_device_driver); | ||
1397 | +} | ||
1398 | + | ||
1399 | +module_init (micro_batt_init); | ||
1400 | +module_exit (micro_batt_cleanup); | ||
1401 | + | ||
1402 | +MODULE_LICENSE("GPL"); | ||
1403 | +MODULE_AUTHOR("gremlin.it"); | ||
1404 | +MODULE_DESCRIPTION("driver for iPAQ Atmel micro battery"); | ||
1405 | + | ||
1406 | + | ||
1407 | Index: linux-2.6.22/drivers/power/olpc_battery.c | ||
1408 | =================================================================== | ||
1409 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
1410 | +++ linux-2.6.22/drivers/power/olpc_battery.c 2007-08-23 12:13:52.000000000 +0200 | ||
1411 | @@ -0,0 +1,302 @@ | ||
1412 | +/* | ||
1413 | + * Battery driver for One Laptop Per Child board. | ||
1414 | + * | ||
1415 | + * Copyright © 2006 David Woodhouse <dwmw2@infradead.org> | ||
1416 | + * | ||
1417 | + * This program is free software; you can redistribute it and/or modify | ||
1418 | + * it under the terms of the GNU General Public License version 2 as | ||
1419 | + * published by the Free Software Foundation. | ||
1420 | + */ | ||
1421 | + | ||
1422 | +#include <linux/module.h> | ||
1423 | +#include <linux/err.h> | ||
1424 | +#include <linux/platform_device.h> | ||
1425 | +#include <linux/power_supply.h> | ||
1426 | +#include <linux/jiffies.h> | ||
1427 | +#include <linux/sched.h> | ||
1428 | +#include <asm/io.h> | ||
1429 | + | ||
1430 | +#define wBAT_VOLTAGE 0xf900 /* *9.76/32, mV */ | ||
1431 | +#define wBAT_CURRENT 0xf902 /* *15.625/120, mA */ | ||
1432 | +#define wBAT_TEMP 0xf906 /* *256/1000, °C */ | ||
1433 | +#define wAMB_TEMP 0xf908 /* *256/1000, °C */ | ||
1434 | +#define SOC 0xf910 /* percentage */ | ||
1435 | +#define sMBAT_STATUS 0xfaa4 | ||
1436 | +#define sBAT_PRESENT 1 | ||
1437 | +#define sBAT_FULL 2 | ||
1438 | +#define sBAT_DESTROY 4 /* what is this exactly? */ | ||
1439 | +#define sBAT_LOW 32 | ||
1440 | +#define sBAT_DISCHG 64 | ||
1441 | +#define sMCHARGE_STATUS 0xfaa5 | ||
1442 | +#define sBAT_CHARGE 1 | ||
1443 | +#define sBAT_OVERTEMP 4 | ||
1444 | +#define sBAT_NiMH 8 | ||
1445 | +#define sPOWER_FLAG 0xfa40 | ||
1446 | +#define ADAPTER_IN 1 | ||
1447 | + | ||
1448 | +/********************************************************************* | ||
1449 | + * EC locking and access | ||
1450 | + *********************************************************************/ | ||
1451 | + | ||
1452 | +static int lock_ec(void) | ||
1453 | +{ | ||
1454 | + unsigned long timeo = jiffies + HZ / 20; | ||
1455 | + | ||
1456 | + while (1) { | ||
1457 | + unsigned char lock = inb(0x6c) & 0x80; | ||
1458 | + if (!lock) | ||
1459 | + return 0; | ||
1460 | + if (time_after(jiffies, timeo)) { | ||
1461 | + printk(KERN_ERR "olpc_battery: failed to lock EC for " | ||
1462 | + "battery access\n"); | ||
1463 | + return 1; | ||
1464 | + } | ||
1465 | + yield(); | ||
1466 | + } | ||
1467 | +} | ||
1468 | + | ||
1469 | +static void unlock_ec(void) | ||
1470 | +{ | ||
1471 | + outb(0xff, 0x6c); | ||
1472 | + return; | ||
1473 | +} | ||
1474 | + | ||
1475 | +static unsigned char read_ec_byte(unsigned short adr) | ||
1476 | +{ | ||
1477 | + outb(adr >> 8, 0x381); | ||
1478 | + outb(adr, 0x382); | ||
1479 | + return inb(0x383); | ||
1480 | +} | ||
1481 | + | ||
1482 | +static unsigned short read_ec_word(unsigned short adr) | ||
1483 | +{ | ||
1484 | + return (read_ec_byte(adr) << 8) | read_ec_byte(adr + 1); | ||
1485 | +} | ||
1486 | + | ||
1487 | +/********************************************************************* | ||
1488 | + * Power | ||
1489 | + *********************************************************************/ | ||
1490 | + | ||
1491 | +static int olpc_ac_get_prop(struct power_supply *psy, | ||
1492 | + enum power_supply_property psp, | ||
1493 | + union power_supply_propval *val) | ||
1494 | +{ | ||
1495 | + int ret = 0; | ||
1496 | + | ||
1497 | + if (lock_ec()) | ||
1498 | + return -EIO; | ||
1499 | + | ||
1500 | + switch (psp) { | ||
1501 | + case POWER_SUPPLY_PROP_ONLINE: | ||
1502 | + if (!(read_ec_byte(sMBAT_STATUS) & sBAT_PRESENT)) { | ||
1503 | + ret = -ENODEV; | ||
1504 | + goto out; | ||
1505 | + } | ||
1506 | + val->intval = !!(read_ec_byte(sPOWER_FLAG) & ADAPTER_IN); | ||
1507 | + break; | ||
1508 | + default: | ||
1509 | + ret = -EINVAL; | ||
1510 | + break; | ||
1511 | + } | ||
1512 | +out: | ||
1513 | + unlock_ec(); | ||
1514 | + return ret; | ||
1515 | +} | ||
1516 | + | ||
1517 | +static enum power_supply_property olpc_ac_props[] = { | ||
1518 | + POWER_SUPPLY_PROP_ONLINE, | ||
1519 | +}; | ||
1520 | + | ||
1521 | +static struct power_supply olpc_ac = { | ||
1522 | + .name = "olpc-ac", | ||
1523 | + .type = POWER_SUPPLY_TYPE_MAINS, | ||
1524 | + .properties = olpc_ac_props, | ||
1525 | + .num_properties = ARRAY_SIZE(olpc_ac_props), | ||
1526 | + .get_property = olpc_ac_get_prop, | ||
1527 | +}; | ||
1528 | + | ||
1529 | +/********************************************************************* | ||
1530 | + * Battery properties | ||
1531 | + *********************************************************************/ | ||
1532 | + | ||
1533 | +static int olpc_bat_get_property(struct power_supply *psy, | ||
1534 | + enum power_supply_property psp, | ||
1535 | + union power_supply_propval *val) | ||
1536 | +{ | ||
1537 | + int ret = 0; | ||
1538 | + | ||
1539 | + if (lock_ec()) | ||
1540 | + return -EIO; | ||
1541 | + | ||
1542 | + switch (psp) { | ||
1543 | + case POWER_SUPPLY_PROP_STATUS: | ||
1544 | + { | ||
1545 | + int status = POWER_SUPPLY_STATUS_UNKNOWN; | ||
1546 | + | ||
1547 | + val->intval = read_ec_byte(sMBAT_STATUS); | ||
1548 | + | ||
1549 | + if (!(val->intval & sBAT_PRESENT)) { | ||
1550 | + ret = -ENODEV; | ||
1551 | + goto out; | ||
1552 | + } | ||
1553 | + | ||
1554 | + if (val->intval & sBAT_DISCHG) | ||
1555 | + status = POWER_SUPPLY_STATUS_DISCHARGING; | ||
1556 | + else if (val->intval & sBAT_FULL) | ||
1557 | + status = POWER_SUPPLY_STATUS_FULL; | ||
1558 | + | ||
1559 | + val->intval = read_ec_byte(sMCHARGE_STATUS); | ||
1560 | + if (val->intval & sBAT_CHARGE) | ||
1561 | + status = POWER_SUPPLY_STATUS_CHARGING; | ||
1562 | + | ||
1563 | + val->intval = status; | ||
1564 | + break; | ||
1565 | + } | ||
1566 | + case POWER_SUPPLY_PROP_PRESENT: | ||
1567 | + val->intval = !!(read_ec_byte(sMBAT_STATUS) & sBAT_PRESENT); | ||
1568 | + break; | ||
1569 | + case POWER_SUPPLY_PROP_HEALTH: | ||
1570 | + val->intval = read_ec_byte(sMCHARGE_STATUS); | ||
1571 | + if (val->intval & sBAT_OVERTEMP) | ||
1572 | + val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; | ||
1573 | + else | ||
1574 | + val->intval = POWER_SUPPLY_HEALTH_GOOD; | ||
1575 | + break; | ||
1576 | + case POWER_SUPPLY_PROP_TECHNOLOGY: | ||
1577 | + val->intval = read_ec_byte(sMCHARGE_STATUS); | ||
1578 | + if (val->intval & sBAT_NiMH) | ||
1579 | + val->intval = POWER_SUPPLY_TECHNOLOGY_NIMH; | ||
1580 | + else | ||
1581 | + val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN; | ||
1582 | + break; | ||
1583 | + case POWER_SUPPLY_PROP_VOLTAGE_AVG: | ||
1584 | + val->intval = read_ec_byte(wBAT_VOLTAGE) * 9760L / 32; | ||
1585 | + break; | ||
1586 | + case POWER_SUPPLY_PROP_CURRENT_AVG: | ||
1587 | + val->intval = read_ec_byte(wBAT_CURRENT) * 15625L / 120; | ||
1588 | + break; | ||
1589 | + case POWER_SUPPLY_PROP_CAPACITY: | ||
1590 | + val->intval = read_ec_byte(SOC); | ||
1591 | + break; | ||
1592 | + case POWER_SUPPLY_PROP_CAPACITY_LEVEL: | ||
1593 | + val->intval = read_ec_byte(sMBAT_STATUS); | ||
1594 | + if (val->intval & sBAT_FULL) | ||
1595 | + val->intval = POWER_SUPPLY_CAPACITY_LEVEL_FULL; | ||
1596 | + else if (val->intval & sBAT_LOW) | ||
1597 | + val->intval = POWER_SUPPLY_CAPACITY_LEVEL_LOW; | ||
1598 | + else | ||
1599 | + val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; | ||
1600 | + break; | ||
1601 | + case POWER_SUPPLY_PROP_TEMP: | ||
1602 | + val->intval = read_ec_byte(wBAT_TEMP) * 256 / 100; | ||
1603 | + break; | ||
1604 | + case POWER_SUPPLY_PROP_TEMP_AMBIENT: | ||
1605 | + val->intval = read_ec_byte(wAMB_TEMP) * 256 / 100; | ||
1606 | + break; | ||
1607 | + default: | ||
1608 | + ret = -EINVAL; | ||
1609 | + break; | ||
1610 | + } | ||
1611 | + | ||
1612 | +out: | ||
1613 | + unlock_ec(); | ||
1614 | + return ret; | ||
1615 | +} | ||
1616 | + | ||
1617 | +static enum power_supply_property olpc_bat_props[] = { | ||
1618 | + POWER_SUPPLY_PROP_STATUS, | ||
1619 | + POWER_SUPPLY_PROP_PRESENT, | ||
1620 | + POWER_SUPPLY_PROP_HEALTH, | ||
1621 | + POWER_SUPPLY_PROP_TECHNOLOGY, | ||
1622 | + POWER_SUPPLY_PROP_VOLTAGE_AVG, | ||
1623 | + POWER_SUPPLY_PROP_CURRENT_AVG, | ||
1624 | + POWER_SUPPLY_PROP_CAPACITY, | ||
1625 | + POWER_SUPPLY_PROP_CAPACITY_LEVEL, | ||
1626 | + POWER_SUPPLY_PROP_TEMP, | ||
1627 | + POWER_SUPPLY_PROP_TEMP_AMBIENT, | ||
1628 | +}; | ||
1629 | + | ||
1630 | +/********************************************************************* | ||
1631 | + * Initialisation | ||
1632 | + *********************************************************************/ | ||
1633 | + | ||
1634 | +static struct platform_device *bat_pdev; | ||
1635 | + | ||
1636 | +static struct power_supply olpc_bat = { | ||
1637 | + .properties = olpc_bat_props, | ||
1638 | + .num_properties = ARRAY_SIZE(olpc_bat_props), | ||
1639 | + .get_property = olpc_bat_get_property, | ||
1640 | + .use_for_apm = 1, | ||
1641 | +}; | ||
1642 | + | ||
1643 | +static int __init olpc_bat_init(void) | ||
1644 | +{ | ||
1645 | + int ret = 0; | ||
1646 | + unsigned short tmp; | ||
1647 | + | ||
1648 | + if (!request_region(0x380, 4, "olpc-battery")) { | ||
1649 | + ret = -EIO; | ||
1650 | + goto region_failed; | ||
1651 | + } | ||
1652 | + | ||
1653 | + if (lock_ec()) { | ||
1654 | + ret = -EIO; | ||
1655 | + goto lock_failed; | ||
1656 | + } | ||
1657 | + | ||
1658 | + tmp = read_ec_word(0xfe92); | ||
1659 | + unlock_ec(); | ||
1660 | + | ||
1661 | + if (tmp != 0x380) { | ||
1662 | + /* Doesn't look like OLPC EC */ | ||
1663 | + ret = -ENODEV; | ||
1664 | + goto not_olpc_ec; | ||
1665 | + } | ||
1666 | + | ||
1667 | + bat_pdev = platform_device_register_simple("olpc-battery", 0, NULL, 0); | ||
1668 | + if (IS_ERR(bat_pdev)) { | ||
1669 | + ret = PTR_ERR(bat_pdev); | ||
1670 | + goto pdev_failed; | ||
1671 | + } | ||
1672 | + | ||
1673 | + ret = power_supply_register(&bat_pdev->dev, &olpc_ac); | ||
1674 | + if (ret) | ||
1675 | + goto ac_failed; | ||
1676 | + | ||
1677 | + olpc_bat.name = bat_pdev->name; | ||
1678 | + | ||
1679 | + ret = power_supply_register(&bat_pdev->dev, &olpc_bat); | ||
1680 | + if (ret) | ||
1681 | + goto battery_failed; | ||
1682 | + | ||
1683 | + goto success; | ||
1684 | + | ||
1685 | +battery_failed: | ||
1686 | + power_supply_unregister(&olpc_ac); | ||
1687 | +ac_failed: | ||
1688 | + platform_device_unregister(bat_pdev); | ||
1689 | +pdev_failed: | ||
1690 | +not_olpc_ec: | ||
1691 | +lock_failed: | ||
1692 | + release_region(0x380, 4); | ||
1693 | +region_failed: | ||
1694 | +success: | ||
1695 | + return ret; | ||
1696 | +} | ||
1697 | + | ||
1698 | +static void __exit olpc_bat_exit(void) | ||
1699 | +{ | ||
1700 | + power_supply_unregister(&olpc_bat); | ||
1701 | + power_supply_unregister(&olpc_ac); | ||
1702 | + platform_device_unregister(bat_pdev); | ||
1703 | + release_region(0x380, 4); | ||
1704 | + return; | ||
1705 | +} | ||
1706 | + | ||
1707 | +module_init(olpc_bat_init); | ||
1708 | +module_exit(olpc_bat_exit); | ||
1709 | + | ||
1710 | +MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); | ||
1711 | +MODULE_LICENSE("GPL"); | ||
1712 | +MODULE_DESCRIPTION("Battery driver for One Laptop Per Child " | ||
1713 | + "($100 laptop) board."); | ||
1714 | Index: linux-2.6.22/drivers/power/pda_power.c | ||
1715 | =================================================================== | ||
1716 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
1717 | +++ linux-2.6.22/drivers/power/pda_power.c 2007-08-23 12:13:52.000000000 +0200 | ||
1718 | @@ -0,0 +1,263 @@ | ||
1719 | +/* | ||
1720 | + * Common power driver for PDAs and phones with one or two external | ||
1721 | + * power supplies (AC/USB) connected to main and backup batteries, | ||
1722 | + * and optional builtin charger. | ||
1723 | + * | ||
1724 | + * Copyright 2007 Anton Vorontsov <cbou@mail.ru> | ||
1725 | + * | ||
1726 | + * This program is free software; you can redistribute it and/or modify | ||
1727 | + * it under the terms of the GNU General Public License version 2 as | ||
1728 | + * published by the Free Software Foundation. | ||
1729 | + */ | ||
1730 | + | ||
1731 | +#include <linux/module.h> | ||
1732 | +#include <linux/platform_device.h> | ||
1733 | +#include <linux/interrupt.h> | ||
1734 | +#include <linux/power_supply.h> | ||
1735 | +#include <linux/pda_power.h> | ||
1736 | +#include <linux/timer.h> | ||
1737 | +#include <linux/jiffies.h> | ||
1738 | + | ||
1739 | +static inline unsigned int get_irq_flags(struct resource *res) | ||
1740 | +{ | ||
1741 | + unsigned int flags = IRQF_DISABLED | IRQF_SHARED; | ||
1742 | + | ||
1743 | + flags |= res->flags & IRQF_TRIGGER_MASK; | ||
1744 | + | ||
1745 | + return flags; | ||
1746 | +} | ||
1747 | + | ||
1748 | +static struct device *dev; | ||
1749 | +static struct pda_power_pdata *pdata; | ||
1750 | +static struct resource *ac_irq, *usb_irq; | ||
1751 | +static struct timer_list charger_timer; | ||
1752 | +static struct timer_list supply_timer; | ||
1753 | + | ||
1754 | +static int pda_power_get_property(struct power_supply *psy, | ||
1755 | + enum power_supply_property psp, | ||
1756 | + union power_supply_propval *val) | ||
1757 | +{ | ||
1758 | + switch (psp) { | ||
1759 | + case POWER_SUPPLY_PROP_ONLINE: | ||
1760 | + if (psy->type == POWER_SUPPLY_TYPE_MAINS) | ||
1761 | + val->intval = pdata->is_ac_online ? | ||
1762 | + pdata->is_ac_online() : 0; | ||
1763 | + else | ||
1764 | + val->intval = pdata->is_usb_online ? | ||
1765 | + pdata->is_usb_online() : 0; | ||
1766 | + break; | ||
1767 | + default: | ||
1768 | + return -EINVAL; | ||
1769 | + } | ||
1770 | + return 0; | ||
1771 | +} | ||
1772 | + | ||
1773 | +static enum power_supply_property pda_power_props[] = { | ||
1774 | + POWER_SUPPLY_PROP_ONLINE, | ||
1775 | +}; | ||
1776 | + | ||
1777 | +static char *pda_power_supplied_to[] = { | ||
1778 | + "main-battery", | ||
1779 | + "backup-battery", | ||
1780 | +}; | ||
1781 | + | ||
1782 | +static struct power_supply pda_power_supplies[] = { | ||
1783 | + { | ||
1784 | + .name = "ac", | ||
1785 | + .type = POWER_SUPPLY_TYPE_MAINS, | ||
1786 | + .supplied_to = pda_power_supplied_to, | ||
1787 | + .num_supplicants = ARRAY_SIZE(pda_power_supplied_to), | ||
1788 | + .properties = pda_power_props, | ||
1789 | + .num_properties = ARRAY_SIZE(pda_power_props), | ||
1790 | + .get_property = pda_power_get_property, | ||
1791 | + }, | ||
1792 | + { | ||
1793 | + .name = "usb", | ||
1794 | + .type = POWER_SUPPLY_TYPE_USB, | ||
1795 | + .supplied_to = pda_power_supplied_to, | ||
1796 | + .num_supplicants = ARRAY_SIZE(pda_power_supplied_to), | ||
1797 | + .properties = pda_power_props, | ||
1798 | + .num_properties = ARRAY_SIZE(pda_power_props), | ||
1799 | + .get_property = pda_power_get_property, | ||
1800 | + }, | ||
1801 | +}; | ||
1802 | + | ||
1803 | +static void update_charger(void) | ||
1804 | +{ | ||
1805 | + if (!pdata->set_charge) | ||
1806 | + return; | ||
1807 | + | ||
1808 | + if (pdata->is_ac_online && pdata->is_ac_online()) { | ||
1809 | + dev_dbg(dev, "charger on (AC)\n"); | ||
1810 | + pdata->set_charge(PDA_POWER_CHARGE_AC); | ||
1811 | + } | ||
1812 | + else if (pdata->is_usb_online && pdata->is_usb_online()) { | ||
1813 | + dev_dbg(dev, "charger on (USB)\n"); | ||
1814 | + pdata->set_charge(PDA_POWER_CHARGE_USB); | ||
1815 | + } | ||
1816 | + else { | ||
1817 | + dev_dbg(dev, "charger off\n"); | ||
1818 | + pdata->set_charge(0); | ||
1819 | + } | ||
1820 | + | ||
1821 | + return; | ||
1822 | +} | ||
1823 | + | ||
1824 | +static void supply_timer_func(unsigned long irq) | ||
1825 | +{ | ||
1826 | + if (ac_irq && irq == ac_irq->start) | ||
1827 | + power_supply_changed(&pda_power_supplies[0]); | ||
1828 | + else if (usb_irq && irq == usb_irq->start) | ||
1829 | + power_supply_changed(&pda_power_supplies[1]); | ||
1830 | + return; | ||
1831 | +} | ||
1832 | + | ||
1833 | +static void charger_timer_func(unsigned long irq) | ||
1834 | +{ | ||
1835 | + update_charger(); | ||
1836 | + | ||
1837 | + /* Okay, charger set. Now wait a bit before notifying supplicants, | ||
1838 | + * charge power should stabilize. */ | ||
1839 | + supply_timer.data = irq; | ||
1840 | + mod_timer(&supply_timer, | ||
1841 | + jiffies + msecs_to_jiffies(pdata->wait_for_charger)); | ||
1842 | + return; | ||
1843 | +} | ||
1844 | + | ||
1845 | +static irqreturn_t power_changed_isr(int irq, void *unused) | ||
1846 | +{ | ||
1847 | + /* Wait a bit before reading ac/usb line status and setting charger, | ||
1848 | + * because ac/usb status readings may lag from irq. */ | ||
1849 | + charger_timer.data = irq; | ||
1850 | + mod_timer(&charger_timer, | ||
1851 | + jiffies + msecs_to_jiffies(pdata->wait_for_status)); | ||
1852 | + return IRQ_HANDLED; | ||
1853 | +} | ||
1854 | + | ||
1855 | +static int pda_power_probe(struct platform_device *pdev) | ||
1856 | +{ | ||
1857 | + int ret = 0; | ||
1858 | + | ||
1859 | + dev = &pdev->dev; | ||
1860 | + | ||
1861 | + if (pdev->id != -1) { | ||
1862 | + dev_err(dev, "it's meaningless to register several " | ||
1863 | + "pda_powers, use id = -1\n"); | ||
1864 | + ret = -EINVAL; | ||
1865 | + goto wrongid; | ||
1866 | + } | ||
1867 | + | ||
1868 | + pdata = pdev->dev.platform_data; | ||
1869 | + | ||
1870 | + update_charger(); | ||
1871 | + | ||
1872 | + if (!pdata->wait_for_status) | ||
1873 | + pdata->wait_for_status = 500; | ||
1874 | + | ||
1875 | + if (!pdata->wait_for_charger) | ||
1876 | + pdata->wait_for_charger = 500; | ||
1877 | + | ||
1878 | + setup_timer(&charger_timer, charger_timer_func, 0); | ||
1879 | + setup_timer(&supply_timer, supply_timer_func, 0); | ||
1880 | + | ||
1881 | + ac_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ac"); | ||
1882 | + usb_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "usb"); | ||
1883 | + if (!ac_irq && !usb_irq) { | ||
1884 | + dev_err(dev, "no ac/usb irq specified\n"); | ||
1885 | + ret = -ENODEV; | ||
1886 | + goto noirqs; | ||
1887 | + } | ||
1888 | + | ||
1889 | + if (pdata->supplied_to) { | ||
1890 | + pda_power_supplies[0].supplied_to = pdata->supplied_to; | ||
1891 | + pda_power_supplies[1].supplied_to = pdata->supplied_to; | ||
1892 | + pda_power_supplies[0].num_supplicants = pdata->num_supplicants; | ||
1893 | + pda_power_supplies[1].num_supplicants = pdata->num_supplicants; | ||
1894 | + } | ||
1895 | + | ||
1896 | + ret = power_supply_register(&pdev->dev, &pda_power_supplies[0]); | ||
1897 | + if (ret) { | ||
1898 | + dev_err(dev, "failed to register %s power supply\n", | ||
1899 | + pda_power_supplies[0].name); | ||
1900 | + goto supply0_failed; | ||
1901 | + } | ||
1902 | + | ||
1903 | + ret = power_supply_register(&pdev->dev, &pda_power_supplies[1]); | ||
1904 | + if (ret) { | ||
1905 | + dev_err(dev, "failed to register %s power supply\n", | ||
1906 | + pda_power_supplies[1].name); | ||
1907 | + goto supply1_failed; | ||
1908 | + } | ||
1909 | + | ||
1910 | + if (ac_irq) { | ||
1911 | + ret = request_irq(ac_irq->start, power_changed_isr, | ||
1912 | + get_irq_flags(ac_irq), ac_irq->name, | ||
1913 | + &pda_power_supplies[0]); | ||
1914 | + if (ret) { | ||
1915 | + dev_err(dev, "request ac irq failed\n"); | ||
1916 | + goto ac_irq_failed; | ||
1917 | + } | ||
1918 | + } | ||
1919 | + | ||
1920 | + if (usb_irq) { | ||
1921 | + ret = request_irq(usb_irq->start, power_changed_isr, | ||
1922 | + get_irq_flags(usb_irq), usb_irq->name, | ||
1923 | + &pda_power_supplies[1]); | ||
1924 | + if (ret) { | ||
1925 | + dev_err(dev, "request usb irq failed\n"); | ||
1926 | + goto usb_irq_failed; | ||
1927 | + } | ||
1928 | + } | ||
1929 | + | ||
1930 | + goto success; | ||
1931 | + | ||
1932 | +usb_irq_failed: | ||
1933 | + if (ac_irq) | ||
1934 | + free_irq(ac_irq->start, &pda_power_supplies[0]); | ||
1935 | +ac_irq_failed: | ||
1936 | + power_supply_unregister(&pda_power_supplies[1]); | ||
1937 | +supply1_failed: | ||
1938 | + power_supply_unregister(&pda_power_supplies[0]); | ||
1939 | +supply0_failed: | ||
1940 | +noirqs: | ||
1941 | +wrongid: | ||
1942 | +success: | ||
1943 | + return ret; | ||
1944 | +} | ||
1945 | + | ||
1946 | +static int pda_power_remove(struct platform_device *pdev) | ||
1947 | +{ | ||
1948 | + if (usb_irq) | ||
1949 | + free_irq(usb_irq->start, &pda_power_supplies[1]); | ||
1950 | + if (ac_irq) | ||
1951 | + free_irq(ac_irq->start, &pda_power_supplies[0]); | ||
1952 | + del_timer_sync(&charger_timer); | ||
1953 | + del_timer_sync(&supply_timer); | ||
1954 | + power_supply_unregister(&pda_power_supplies[1]); | ||
1955 | + power_supply_unregister(&pda_power_supplies[0]); | ||
1956 | + return 0; | ||
1957 | +} | ||
1958 | + | ||
1959 | +static struct platform_driver pda_power_pdrv = { | ||
1960 | + .driver = { | ||
1961 | + .name = "pda-power", | ||
1962 | + }, | ||
1963 | + .probe = pda_power_probe, | ||
1964 | + .remove = pda_power_remove, | ||
1965 | +}; | ||
1966 | + | ||
1967 | +static int __init pda_power_init(void) | ||
1968 | +{ | ||
1969 | + return platform_driver_register(&pda_power_pdrv); | ||
1970 | +} | ||
1971 | + | ||
1972 | +static void __exit pda_power_exit(void) | ||
1973 | +{ | ||
1974 | + platform_driver_unregister(&pda_power_pdrv); | ||
1975 | + return; | ||
1976 | +} | ||
1977 | + | ||
1978 | +module_init(pda_power_init); | ||
1979 | +module_exit(pda_power_exit); | ||
1980 | +MODULE_LICENSE("GPL"); | ||
1981 | +MODULE_AUTHOR("Anton Vorontsov <cbou@mail.ru>"); | ||
1982 | Index: linux-2.6.22/drivers/power/pmu_battery.c | ||
1983 | =================================================================== | ||
1984 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
1985 | +++ linux-2.6.22/drivers/power/pmu_battery.c 2007-08-23 12:13:52.000000000 +0200 | ||
1986 | @@ -0,0 +1,215 @@ | ||
1987 | +/* | ||
1988 | + * Battery class driver for Apple PMU | ||
1989 | + * | ||
1990 | + * Copyright © 2006 David Woodhouse <dwmw2@infradead.org> | ||
1991 | + * | ||
1992 | + * This program is free software; you can redistribute it and/or modify | ||
1993 | + * it under the terms of the GNU General Public License version 2 as | ||
1994 | + * published by the Free Software Foundation. | ||
1995 | + */ | ||
1996 | + | ||
1997 | +#include <linux/module.h> | ||
1998 | +#include <linux/platform_device.h> | ||
1999 | +#include <linux/err.h> | ||
2000 | +#include <linux/power_supply.h> | ||
2001 | +#include <linux/adb.h> | ||
2002 | +#include <linux/pmu.h> | ||
2003 | + | ||
2004 | +static struct pmu_battery_dev { | ||
2005 | + struct power_supply bat; | ||
2006 | + struct pmu_battery_info *pbi; | ||
2007 | + char name[16]; | ||
2008 | + int propval; | ||
2009 | +} *pbats[PMU_MAX_BATTERIES]; | ||
2010 | + | ||
2011 | +#define to_pmu_battery_dev(x) container_of(x, struct pmu_battery_dev, bat) | ||
2012 | + | ||
2013 | +/********************************************************************* | ||
2014 | + * Power | ||
2015 | + *********************************************************************/ | ||
2016 | + | ||
2017 | +static int pmu_get_ac_prop(struct power_supply *psy, | ||
2018 | + enum power_supply_property psp, | ||
2019 | + union power_supply_propval *val) | ||
2020 | +{ | ||
2021 | + switch (psp) { | ||
2022 | + case POWER_SUPPLY_PROP_ONLINE: | ||
2023 | + val->intval = (!!(pmu_power_flags & PMU_PWR_AC_PRESENT)) || | ||
2024 | + (pmu_battery_count == 0); | ||
2025 | + break; | ||
2026 | + default: | ||
2027 | + return -EINVAL; | ||
2028 | + } | ||
2029 | + | ||
2030 | + return 0; | ||
2031 | +} | ||
2032 | + | ||
2033 | +static enum power_supply_property pmu_ac_props[] = { | ||
2034 | + POWER_SUPPLY_PROP_ONLINE, | ||
2035 | +}; | ||
2036 | + | ||
2037 | +static struct power_supply pmu_ac = { | ||
2038 | + .name = "pmu-ac", | ||
2039 | + .type = POWER_SUPPLY_TYPE_MAINS, | ||
2040 | + .properties = pmu_ac_props, | ||
2041 | + .num_properties = ARRAY_SIZE(pmu_ac_props), | ||
2042 | + .get_property = pmu_get_ac_prop, | ||
2043 | +}; | ||
2044 | + | ||
2045 | +/********************************************************************* | ||
2046 | + * Battery properties | ||
2047 | + *********************************************************************/ | ||
2048 | + | ||
2049 | +static char *pmu_batt_types[] = { | ||
2050 | + "Smart", "Comet", "Hooper", "Unknown" | ||
2051 | +}; | ||
2052 | + | ||
2053 | +static char *pmu_bat_get_model_name(struct pmu_battery_info *pbi) | ||
2054 | +{ | ||
2055 | + switch (pbi->flags & PMU_BATT_TYPE_MASK) { | ||
2056 | + case PMU_BATT_TYPE_SMART: | ||
2057 | + return pmu_batt_types[0]; | ||
2058 | + case PMU_BATT_TYPE_COMET: | ||
2059 | + return pmu_batt_types[1]; | ||
2060 | + case PMU_BATT_TYPE_HOOPER: | ||
2061 | + return pmu_batt_types[2]; | ||
2062 | + default: break; | ||
2063 | + } | ||
2064 | + return pmu_batt_types[3]; | ||
2065 | +} | ||
2066 | + | ||
2067 | +static int pmu_bat_get_property(struct power_supply *psy, | ||
2068 | + enum power_supply_property psp, | ||
2069 | + union power_supply_propval *val) | ||
2070 | +{ | ||
2071 | + struct pmu_battery_dev *pbat = to_pmu_battery_dev(psy); | ||
2072 | + struct pmu_battery_info *pbi = pbat->pbi; | ||
2073 | + | ||
2074 | + switch (psp) { | ||
2075 | + case POWER_SUPPLY_PROP_STATUS: | ||
2076 | + if (pbi->flags & PMU_BATT_CHARGING) | ||
2077 | + val->intval = POWER_SUPPLY_STATUS_CHARGING; | ||
2078 | + else | ||
2079 | + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; | ||
2080 | + break; | ||
2081 | + case POWER_SUPPLY_PROP_PRESENT: | ||
2082 | + val->intval = !!(pbi->flags & PMU_BATT_PRESENT); | ||
2083 | + break; | ||
2084 | + case POWER_SUPPLY_PROP_MODEL_NAME: | ||
2085 | + val->strval = pmu_bat_get_model_name(pbi); | ||
2086 | + break; | ||
2087 | + case POWER_SUPPLY_PROP_ENERGY_AVG: | ||
2088 | + val->intval = pbi->charge * 1000; /* mWh -> µWh */ | ||
2089 | + break; | ||
2090 | + case POWER_SUPPLY_PROP_ENERGY_FULL: | ||
2091 | + val->intval = pbi->max_charge * 1000; /* mWh -> µWh */ | ||
2092 | + break; | ||
2093 | + case POWER_SUPPLY_PROP_CURRENT_AVG: | ||
2094 | + val->intval = pbi->amperage * 1000; /* mA -> µA */ | ||
2095 | + break; | ||
2096 | + case POWER_SUPPLY_PROP_VOLTAGE_AVG: | ||
2097 | + val->intval = pbi->voltage * 1000; /* mV -> µV */ | ||
2098 | + break; | ||
2099 | + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: | ||
2100 | + val->intval = pbi->time_remaining; | ||
2101 | + break; | ||
2102 | + default: | ||
2103 | + return -EINVAL; | ||
2104 | + } | ||
2105 | + | ||
2106 | + return 0; | ||
2107 | +} | ||
2108 | + | ||
2109 | +static enum power_supply_property pmu_bat_props[] = { | ||
2110 | + POWER_SUPPLY_PROP_STATUS, | ||
2111 | + POWER_SUPPLY_PROP_PRESENT, | ||
2112 | + POWER_SUPPLY_PROP_MODEL_NAME, | ||
2113 | + POWER_SUPPLY_PROP_ENERGY_AVG, | ||
2114 | + POWER_SUPPLY_PROP_ENERGY_FULL, | ||
2115 | + POWER_SUPPLY_PROP_CURRENT_AVG, | ||
2116 | + POWER_SUPPLY_PROP_VOLTAGE_AVG, | ||
2117 | + POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, | ||
2118 | +}; | ||
2119 | + | ||
2120 | +/********************************************************************* | ||
2121 | + * Initialisation | ||
2122 | + *********************************************************************/ | ||
2123 | + | ||
2124 | +static struct platform_device *bat_pdev; | ||
2125 | + | ||
2126 | +static int __init pmu_bat_init(void) | ||
2127 | +{ | ||
2128 | + int ret; | ||
2129 | + int i; | ||
2130 | + | ||
2131 | + bat_pdev = platform_device_register_simple("pmu-battery", | ||
2132 | + 0, NULL, 0); | ||
2133 | + if (IS_ERR(bat_pdev)) { | ||
2134 | + ret = PTR_ERR(bat_pdev); | ||
2135 | + goto pdev_register_failed; | ||
2136 | + } | ||
2137 | + | ||
2138 | + ret = power_supply_register(&bat_pdev->dev, &pmu_ac); | ||
2139 | + if (ret) | ||
2140 | + goto ac_register_failed; | ||
2141 | + | ||
2142 | + for (i = 0; i < pmu_battery_count; i++) { | ||
2143 | + struct pmu_battery_dev *pbat = kzalloc(sizeof(*pbat), | ||
2144 | + GFP_KERNEL); | ||
2145 | + if (!pbat) | ||
2146 | + break; | ||
2147 | + | ||
2148 | + sprintf(pbat->name, "PMU battery %d", i); | ||
2149 | + pbat->bat.name = pbat->name; | ||
2150 | + pbat->bat.properties = pmu_bat_props; | ||
2151 | + pbat->bat.num_properties = ARRAY_SIZE(pmu_bat_props); | ||
2152 | + pbat->bat.get_property = pmu_bat_get_property; | ||
2153 | + pbat->pbi = &pmu_batteries[i]; | ||
2154 | + | ||
2155 | + ret = power_supply_register(&bat_pdev->dev, &pbat->bat); | ||
2156 | + if (ret) { | ||
2157 | + kfree(pbat); | ||
2158 | + goto battery_register_failed; | ||
2159 | + } | ||
2160 | + pbats[i] = pbat; | ||
2161 | + } | ||
2162 | + | ||
2163 | + goto success; | ||
2164 | + | ||
2165 | +battery_register_failed: | ||
2166 | + while (i--) { | ||
2167 | + if (!pbats[i]) | ||
2168 | + continue; | ||
2169 | + power_supply_unregister(&pbats[i]->bat); | ||
2170 | + kfree(pbats[i]); | ||
2171 | + } | ||
2172 | + power_supply_unregister(&pmu_ac); | ||
2173 | +ac_register_failed: | ||
2174 | + platform_device_unregister(bat_pdev); | ||
2175 | +pdev_register_failed: | ||
2176 | +success: | ||
2177 | + return ret; | ||
2178 | +} | ||
2179 | + | ||
2180 | +static void __exit pmu_bat_exit(void) | ||
2181 | +{ | ||
2182 | + int i; | ||
2183 | + | ||
2184 | + for (i = 0; i < PMU_MAX_BATTERIES; i++) { | ||
2185 | + if (!pbats[i]) | ||
2186 | + continue; | ||
2187 | + power_supply_unregister(&pbats[i]->bat); | ||
2188 | + kfree(pbats[i]); | ||
2189 | + } | ||
2190 | + power_supply_unregister(&pmu_ac); | ||
2191 | + platform_device_unregister(bat_pdev); | ||
2192 | + | ||
2193 | + return; | ||
2194 | +} | ||
2195 | + | ||
2196 | +module_init(pmu_bat_init); | ||
2197 | +module_exit(pmu_bat_exit); | ||
2198 | + | ||
2199 | +MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); | ||
2200 | +MODULE_LICENSE("GPL"); | ||
2201 | +MODULE_DESCRIPTION("PMU battery driver"); | ||
2202 | Index: linux-2.6.22/drivers/power/power_supply_core.c | ||
2203 | =================================================================== | ||
2204 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
2205 | +++ linux-2.6.22/drivers/power/power_supply_core.c 2007-08-23 12:13:52.000000000 +0200 | ||
2206 | @@ -0,0 +1,168 @@ | ||
2207 | +/* | ||
2208 | + * Universal power supply monitor class | ||
2209 | + * | ||
2210 | + * Copyright (c) 2007 Anton Vorontsov <cbou@mail.ru> | ||
2211 | + * Copyright (c) 2004 Szabolcs Gyurko | ||
2212 | + * Copyright (c) 2003 Ian Molton <spyro@f2s.com> | ||
2213 | + * | ||
2214 | + * Modified: 2004, Oct Szabolcs Gyurko | ||
2215 | + * | ||
2216 | + * You may use this code as per GPL version 2 | ||
2217 | + */ | ||
2218 | + | ||
2219 | +#include <linux/module.h> | ||
2220 | +#include <linux/types.h> | ||
2221 | +#include <linux/init.h> | ||
2222 | +#include <linux/device.h> | ||
2223 | +#include <linux/err.h> | ||
2224 | +#include <linux/power_supply.h> | ||
2225 | +#include "power_supply.h" | ||
2226 | + | ||
2227 | +struct class *power_supply_class; | ||
2228 | + | ||
2229 | +static void power_supply_changed_work(struct work_struct *work) | ||
2230 | +{ | ||
2231 | + struct power_supply *psy = container_of(work, struct power_supply, | ||
2232 | + changed_work); | ||
2233 | + int i; | ||
2234 | + | ||
2235 | + dev_dbg(psy->dev, "%s\n", __FUNCTION__); | ||
2236 | + | ||
2237 | + for (i = 0; i < psy->num_supplicants; i++) { | ||
2238 | + struct device *dev; | ||
2239 | + | ||
2240 | + down(&power_supply_class->sem); | ||
2241 | + list_for_each_entry(dev, &power_supply_class->devices, node) { | ||
2242 | + struct power_supply *pst = dev_get_drvdata(dev); | ||
2243 | + | ||
2244 | + if (!strcmp(psy->supplied_to[i], pst->name)) { | ||
2245 | + if (pst->external_power_changed) | ||
2246 | + pst->external_power_changed(pst); | ||
2247 | + } | ||
2248 | + } | ||
2249 | + up(&power_supply_class->sem); | ||
2250 | + } | ||
2251 | + | ||
2252 | + power_supply_update_leds(psy); | ||
2253 | + | ||
2254 | + kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); | ||
2255 | + | ||
2256 | + return; | ||
2257 | +} | ||
2258 | + | ||
2259 | +void power_supply_changed(struct power_supply *psy) | ||
2260 | +{ | ||
2261 | + dev_dbg(psy->dev, "%s\n", __FUNCTION__); | ||
2262 | + | ||
2263 | + schedule_work(&psy->changed_work); | ||
2264 | + | ||
2265 | + return; | ||
2266 | +} | ||
2267 | + | ||
2268 | +int power_supply_am_i_supplied(struct power_supply *psy) | ||
2269 | +{ | ||
2270 | + union power_supply_propval ret = {0,}; | ||
2271 | + struct device *dev; | ||
2272 | + | ||
2273 | + down(&power_supply_class->sem); | ||
2274 | + list_for_each_entry(dev, &power_supply_class->devices, node) { | ||
2275 | + struct power_supply *epsy = dev_get_drvdata(dev); | ||
2276 | + int i; | ||
2277 | + | ||
2278 | + for (i = 0; i < epsy->num_supplicants; i++) { | ||
2279 | + if (!strcmp(epsy->supplied_to[i], psy->name)) { | ||
2280 | + if (epsy->get_property(epsy, | ||
2281 | + POWER_SUPPLY_PROP_ONLINE, &ret)) | ||
2282 | + continue; | ||
2283 | + if (ret.intval) | ||
2284 | + goto out; | ||
2285 | + } | ||
2286 | + } | ||
2287 | + } | ||
2288 | +out: | ||
2289 | + up(&power_supply_class->sem); | ||
2290 | + | ||
2291 | + dev_dbg(psy->dev, "%s %d\n", __FUNCTION__, ret.intval); | ||
2292 | + | ||
2293 | + return ret.intval; | ||
2294 | +} | ||
2295 | + | ||
2296 | +int power_supply_register(struct device *parent, struct power_supply *psy) | ||
2297 | +{ | ||
2298 | + int rc = 0; | ||
2299 | + | ||
2300 | + psy->dev = device_create(power_supply_class, parent, 0, | ||
2301 | + "%s", psy->name); | ||
2302 | + if (IS_ERR(psy->dev)) { | ||
2303 | + rc = PTR_ERR(psy->dev); | ||
2304 | + goto dev_create_failed; | ||
2305 | + } | ||
2306 | + | ||
2307 | + dev_set_drvdata(psy->dev, psy); | ||
2308 | + | ||
2309 | + INIT_WORK(&psy->changed_work, power_supply_changed_work); | ||
2310 | + | ||
2311 | + rc = power_supply_create_attrs(psy); | ||
2312 | + if (rc) | ||
2313 | + goto create_attrs_failed; | ||
2314 | + | ||
2315 | + rc = power_supply_create_triggers(psy); | ||
2316 | + if (rc) | ||
2317 | + goto create_triggers_failed; | ||
2318 | + | ||
2319 | + power_supply_changed(psy); | ||
2320 | + | ||
2321 | + goto success; | ||
2322 | + | ||
2323 | +create_triggers_failed: | ||
2324 | + power_supply_remove_attrs(psy); | ||
2325 | +create_attrs_failed: | ||
2326 | + device_unregister(psy->dev); | ||
2327 | +dev_create_failed: | ||
2328 | +success: | ||
2329 | + return rc; | ||
2330 | +} | ||
2331 | + | ||
2332 | +void power_supply_unregister(struct power_supply *psy) | ||
2333 | +{ | ||
2334 | + flush_scheduled_work(); | ||
2335 | + power_supply_remove_triggers(psy); | ||
2336 | + power_supply_remove_attrs(psy); | ||
2337 | + device_unregister(psy->dev); | ||
2338 | + return; | ||
2339 | +} | ||
2340 | + | ||
2341 | +static int __init power_supply_class_init(void) | ||
2342 | +{ | ||
2343 | + power_supply_class = class_create(THIS_MODULE, "power_supply"); | ||
2344 | + | ||
2345 | + if (IS_ERR(power_supply_class)) | ||
2346 | + return PTR_ERR(power_supply_class); | ||
2347 | + | ||
2348 | + power_supply_class->dev_uevent = power_supply_uevent; | ||
2349 | + | ||
2350 | + return 0; | ||
2351 | +} | ||
2352 | + | ||
2353 | +static void __exit power_supply_class_exit(void) | ||
2354 | +{ | ||
2355 | + class_destroy(power_supply_class); | ||
2356 | + return; | ||
2357 | +} | ||
2358 | + | ||
2359 | +EXPORT_SYMBOL_GPL(power_supply_changed); | ||
2360 | +EXPORT_SYMBOL_GPL(power_supply_am_i_supplied); | ||
2361 | +EXPORT_SYMBOL_GPL(power_supply_register); | ||
2362 | +EXPORT_SYMBOL_GPL(power_supply_unregister); | ||
2363 | + | ||
2364 | +/* exported for the APM Power driver, APM emulation */ | ||
2365 | +EXPORT_SYMBOL_GPL(power_supply_class); | ||
2366 | + | ||
2367 | +subsys_initcall(power_supply_class_init); | ||
2368 | +module_exit(power_supply_class_exit); | ||
2369 | + | ||
2370 | +MODULE_DESCRIPTION("Universal power supply monitor class"); | ||
2371 | +MODULE_AUTHOR("Ian Molton <spyro@f2s.com>, " | ||
2372 | + "Szabolcs Gyurko, " | ||
2373 | + "Anton Vorontsov <cbou@mail.ru>"); | ||
2374 | +MODULE_LICENSE("GPL"); | ||
2375 | Index: linux-2.6.22/drivers/power/power_supply.h | ||
2376 | =================================================================== | ||
2377 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
2378 | +++ linux-2.6.22/drivers/power/power_supply.h 2007-08-23 12:13:52.000000000 +0200 | ||
2379 | @@ -0,0 +1,42 @@ | ||
2380 | +/* | ||
2381 | + * Functions private to power supply class | ||
2382 | + * | ||
2383 | + * Copyright (c) 2007 Anton Vorontsov <cbou@mail.ru> | ||
2384 | + * Copyright (c) 2004 Szabolcs Gyurko | ||
2385 | + * Copyright (c) 2003 Ian Molton <spyro@f2s.com> | ||
2386 | + * | ||
2387 | + * Modified: 2004, Oct Szabolcs Gyurko | ||
2388 | + * | ||
2389 | + * You may use this code as per GPL version 2 | ||
2390 | + */ | ||
2391 | + | ||
2392 | +#ifdef CONFIG_SYSFS | ||
2393 | + | ||
2394 | +extern int power_supply_create_attrs(struct power_supply *psy); | ||
2395 | +extern void power_supply_remove_attrs(struct power_supply *psy); | ||
2396 | +extern int power_supply_uevent(struct device *dev, char **envp, int num_envp, | ||
2397 | + char *buffer, int buffer_size); | ||
2398 | + | ||
2399 | +#else | ||
2400 | + | ||
2401 | +static inline int power_supply_create_attrs(struct power_supply *psy) | ||
2402 | +{ return 0; } | ||
2403 | +static inline void power_supply_remove_attrs(struct power_supply *psy) {} | ||
2404 | +#define power_supply_uevent NULL | ||
2405 | + | ||
2406 | +#endif /* CONFIG_SYSFS */ | ||
2407 | + | ||
2408 | +#ifdef CONFIG_LEDS_TRIGGERS | ||
2409 | + | ||
2410 | +extern void power_supply_update_leds(struct power_supply *psy); | ||
2411 | +extern int power_supply_create_triggers(struct power_supply *psy); | ||
2412 | +extern void power_supply_remove_triggers(struct power_supply *psy); | ||
2413 | + | ||
2414 | +#else | ||
2415 | + | ||
2416 | +static inline void power_supply_update_leds(struct power_supply *psy) {} | ||
2417 | +static inline int power_supply_create_triggers(struct power_supply *psy) | ||
2418 | +{ return 0; } | ||
2419 | +static inline void power_supply_remove_triggers(struct power_supply *psy) {} | ||
2420 | + | ||
2421 | +#endif /* CONFIG_LEDS_TRIGGERS */ | ||
2422 | Index: linux-2.6.22/drivers/power/power_supply_leds.c | ||
2423 | =================================================================== | ||
2424 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
2425 | +++ linux-2.6.22/drivers/power/power_supply_leds.c 2007-08-23 12:13:52.000000000 +0200 | ||
2426 | @@ -0,0 +1,188 @@ | ||
2427 | +/* | ||
2428 | + * LEDs triggers for power supply class | ||
2429 | + * | ||
2430 | + * Copyright (c) 2007 Anton Vorontsov <cbou@mail.ru> | ||
2431 | + * Copyright (c) 2004 Szabolcs Gyurko | ||
2432 | + * Copyright (c) 2003 Ian Molton <spyro@f2s.com> | ||
2433 | + * | ||
2434 | + * Modified: 2004, Oct Szabolcs Gyurko | ||
2435 | + * | ||
2436 | + * You may use this code as per GPL version 2 | ||
2437 | + */ | ||
2438 | + | ||
2439 | +#include <linux/power_supply.h> | ||
2440 | + | ||
2441 | +/* If we have hwtimer trigger, then use it to blink charging LED */ | ||
2442 | + | ||
2443 | +#if defined(CONFIG_LEDS_TRIGGER_HWTIMER) || \ | ||
2444 | + (defined(CONFIG_BATTERY_MODULE) && \ | ||
2445 | + defined(CONFIG_LEDS_TRIGGER_HWTIMER_MODULE)) | ||
2446 | + #define led_trigger_register_charging led_trigger_register_hwtimer | ||
2447 | + #define led_trigger_unregister_charging led_trigger_unregister_hwtimer | ||
2448 | +#else | ||
2449 | + #define led_trigger_register_charging led_trigger_register_simple | ||
2450 | + #define led_trigger_unregister_charging led_trigger_unregister_simple | ||
2451 | +#endif | ||
2452 | + | ||
2453 | +/* Battery specific LEDs triggers. */ | ||
2454 | + | ||
2455 | +static void power_supply_update_bat_leds(struct power_supply *psy) | ||
2456 | +{ | ||
2457 | + union power_supply_propval status; | ||
2458 | + | ||
2459 | + if (psy->get_property(psy, POWER_SUPPLY_PROP_STATUS, &status)) | ||
2460 | + return; | ||
2461 | + | ||
2462 | + dev_dbg(psy->dev, "%s %d\n", __FUNCTION__, status.intval); | ||
2463 | + | ||
2464 | + switch(status.intval) { | ||
2465 | + case POWER_SUPPLY_STATUS_FULL: | ||
2466 | + led_trigger_event(psy->charging_full_trig, LED_FULL); | ||
2467 | + led_trigger_event(psy->charging_trig, LED_OFF); | ||
2468 | + led_trigger_event(psy->full_trig, LED_FULL); | ||
2469 | + break; | ||
2470 | + case POWER_SUPPLY_STATUS_CHARGING: | ||
2471 | + led_trigger_event(psy->charging_full_trig, LED_FULL); | ||
2472 | + led_trigger_event(psy->charging_trig, LED_FULL); | ||
2473 | + led_trigger_event(psy->full_trig, LED_OFF); | ||
2474 | + break; | ||
2475 | + default: | ||
2476 | + led_trigger_event(psy->charging_full_trig, LED_OFF); | ||
2477 | + led_trigger_event(psy->charging_trig, LED_OFF); | ||
2478 | + led_trigger_event(psy->full_trig, LED_OFF); | ||
2479 | + break; | ||
2480 | + } | ||
2481 | + | ||
2482 | + return; | ||
2483 | +} | ||
2484 | + | ||
2485 | +static int power_supply_create_bat_triggers(struct power_supply *psy) | ||
2486 | +{ | ||
2487 | + int rc = 0; | ||
2488 | + | ||
2489 | + psy->charging_full_trig_name = kmalloc(strlen(psy->name) + | ||
2490 | + sizeof("-charging-or-full"), GFP_KERNEL); | ||
2491 | + if (!psy->charging_full_trig_name) | ||
2492 | + goto charging_full_failed; | ||
2493 | + | ||
2494 | + psy->charging_trig_name = kmalloc(strlen(psy->name) + | ||
2495 | + sizeof("-charging"), GFP_KERNEL); | ||
2496 | + if (!psy->charging_trig_name) | ||
2497 | + goto charging_failed; | ||
2498 | + | ||
2499 | + psy->full_trig_name = kmalloc(strlen(psy->name) + | ||
2500 | + sizeof("-full"), GFP_KERNEL); | ||
2501 | + if (!psy->full_trig_name) | ||
2502 | + goto full_failed; | ||
2503 | + | ||
2504 | + strcpy(psy->charging_full_trig_name, psy->name); | ||
2505 | + strcat(psy->charging_full_trig_name, "-charging-or-full"); | ||
2506 | + strcpy(psy->charging_trig_name, psy->name); | ||
2507 | + strcat(psy->charging_trig_name, "-charging"); | ||
2508 | + strcpy(psy->full_trig_name, psy->name); | ||
2509 | + strcat(psy->full_trig_name, "-full"); | ||
2510 | + | ||
2511 | + led_trigger_register_simple(psy->charging_full_trig_name, | ||
2512 | + &psy->charging_full_trig); | ||
2513 | + led_trigger_register_charging(psy->charging_trig_name, | ||
2514 | + &psy->charging_trig); | ||
2515 | + led_trigger_register_simple(psy->full_trig_name, | ||
2516 | + &psy->full_trig); | ||
2517 | + | ||
2518 | + goto success; | ||
2519 | + | ||
2520 | +full_failed: | ||
2521 | + kfree(psy->charging_trig_name); | ||
2522 | +charging_failed: | ||
2523 | + kfree(psy->charging_full_trig_name); | ||
2524 | +charging_full_failed: | ||
2525 | + rc = -ENOMEM; | ||
2526 | +success: | ||
2527 | + return rc; | ||
2528 | +} | ||
2529 | + | ||
2530 | +static void power_supply_remove_bat_triggers(struct power_supply *psy) | ||
2531 | +{ | ||
2532 | + led_trigger_unregister_simple(psy->charging_full_trig); | ||
2533 | + led_trigger_unregister_charging(psy->charging_trig); | ||
2534 | + led_trigger_unregister_simple(psy->full_trig); | ||
2535 | + kfree(psy->full_trig_name); | ||
2536 | + kfree(psy->charging_trig_name); | ||
2537 | + kfree(psy->charging_full_trig_name); | ||
2538 | + return; | ||
2539 | +} | ||
2540 | + | ||
2541 | +/* Generated power specific LEDs triggers. */ | ||
2542 | + | ||
2543 | +static void power_supply_update_gen_leds(struct power_supply *psy) | ||
2544 | +{ | ||
2545 | + union power_supply_propval online; | ||
2546 | + | ||
2547 | + if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &online)) | ||
2548 | + return; | ||
2549 | + | ||
2550 | + dev_dbg(psy->dev, "%s %d\n", __FUNCTION__, online.intval); | ||
2551 | + | ||
2552 | + if (online.intval) | ||
2553 | + led_trigger_event(psy->online_trig, LED_FULL); | ||
2554 | + else | ||
2555 | + led_trigger_event(psy->online_trig, LED_OFF); | ||
2556 | + | ||
2557 | + return; | ||
2558 | +} | ||
2559 | + | ||
2560 | +static int power_supply_create_gen_triggers(struct power_supply *psy) | ||
2561 | +{ | ||
2562 | + int rc = 0; | ||
2563 | + | ||
2564 | + psy->online_trig_name = kmalloc(strlen(psy->name) + sizeof("-online"), | ||
2565 | + GFP_KERNEL); | ||
2566 | + if (!psy->online_trig_name) | ||
2567 | + goto online_failed; | ||
2568 | + | ||
2569 | + strcpy(psy->online_trig_name, psy->name); | ||
2570 | + strcat(psy->online_trig_name, "-online"); | ||
2571 | + | ||
2572 | + led_trigger_register_simple(psy->online_trig_name, &psy->online_trig); | ||
2573 | + | ||
2574 | + goto success; | ||
2575 | + | ||
2576 | +online_failed: | ||
2577 | + rc = -ENOMEM; | ||
2578 | +success: | ||
2579 | + return rc; | ||
2580 | +} | ||
2581 | + | ||
2582 | +static void power_supply_remove_gen_triggers(struct power_supply *psy) | ||
2583 | +{ | ||
2584 | + led_trigger_unregister_simple(psy->online_trig); | ||
2585 | + kfree(psy->online_trig_name); | ||
2586 | + return; | ||
2587 | +} | ||
2588 | + | ||
2589 | +/* Choice what triggers to create&update. */ | ||
2590 | + | ||
2591 | +void power_supply_update_leds(struct power_supply *psy) | ||
2592 | +{ | ||
2593 | + if (psy->type == POWER_SUPPLY_TYPE_BATTERY) | ||
2594 | + power_supply_update_bat_leds(psy); | ||
2595 | + else | ||
2596 | + power_supply_update_gen_leds(psy); | ||
2597 | + return; | ||
2598 | +} | ||
2599 | + | ||
2600 | +int power_supply_create_triggers(struct power_supply *psy) | ||
2601 | +{ | ||
2602 | + if (psy->type == POWER_SUPPLY_TYPE_BATTERY) | ||
2603 | + return power_supply_create_bat_triggers(psy); | ||
2604 | + return power_supply_create_gen_triggers(psy); | ||
2605 | +} | ||
2606 | + | ||
2607 | +void power_supply_remove_triggers(struct power_supply *psy) | ||
2608 | +{ | ||
2609 | + if (psy->type == POWER_SUPPLY_TYPE_BATTERY) | ||
2610 | + power_supply_remove_bat_triggers(psy); | ||
2611 | + else | ||
2612 | + power_supply_remove_gen_triggers(psy); | ||
2613 | + return; | ||
2614 | +} | ||
2615 | Index: linux-2.6.22/drivers/power/power_supply_sysfs.c | ||
2616 | =================================================================== | ||
2617 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
2618 | +++ linux-2.6.22/drivers/power/power_supply_sysfs.c 2007-08-23 12:13:52.000000000 +0200 | ||
2619 | @@ -0,0 +1,289 @@ | ||
2620 | +/* | ||
2621 | + * Sysfs interface for the universal power supply monitor class | ||
2622 | + * | ||
2623 | + * Copyright © 2007 David Woodhouse <dwmw2@infradead.org> | ||
2624 | + * Copyright (c) 2007 Anton Vorontsov <cbou@mail.ru> | ||
2625 | + * Copyright (c) 2004 Szabolcs Gyurko | ||
2626 | + * Copyright (c) 2003 Ian Molton <spyro@f2s.com> | ||
2627 | + * | ||
2628 | + * Modified: 2004, Oct Szabolcs Gyurko | ||
2629 | + * | ||
2630 | + * You may use this code as per GPL version 2 | ||
2631 | + */ | ||
2632 | + | ||
2633 | +#include <linux/ctype.h> | ||
2634 | +#include <linux/power_supply.h> | ||
2635 | + | ||
2636 | +/* | ||
2637 | + * This is because the name "current" breaks the device attr macro. | ||
2638 | + * The "current" word resolvs to "(get_current())" so instead of | ||
2639 | + * "current" "(get_current())" appears in the sysfs. | ||
2640 | + * | ||
2641 | + * The source of this definition is the device.h which calls __ATTR | ||
2642 | + * macro in sysfs.h which calls the __stringify macro. | ||
2643 | + * | ||
2644 | + * Only modification that the name is not tried to be resolved | ||
2645 | + * (as a macro let's say). | ||
2646 | + */ | ||
2647 | + | ||
2648 | +#define POWER_SUPPLY_ATTR(_name) \ | ||
2649 | +{ \ | ||
2650 | + .attr = { .name = #_name, .mode = 0444, .owner = THIS_MODULE }, \ | ||
2651 | + .show = power_supply_show_property, \ | ||
2652 | + .store = NULL, \ | ||
2653 | +} | ||
2654 | + | ||
2655 | +static struct device_attribute power_supply_attrs[]; | ||
2656 | + | ||
2657 | +static ssize_t power_supply_show_property(struct device *dev, | ||
2658 | + struct device_attribute *attr, | ||
2659 | + char *buf) { | ||
2660 | + static char *status_text[] = { | ||
2661 | + "Unknown", "Charging", "Discharging", "Not charging", "Full" | ||
2662 | + }; | ||
2663 | + static char *health_text[] = { | ||
2664 | + "Unknown", "Good", "Overheat", "Dead" | ||
2665 | + }; | ||
2666 | + static char *technology_text[] = { | ||
2667 | + "Unknown", "NiMH", "Li-ion", "Li-poly" | ||
2668 | + }; | ||
2669 | + static char *capacity_level_text[] = { | ||
2670 | + "Unknown", "Critical", "Low", "Normal", "High", "Full" | ||
2671 | + }; | ||
2672 | + ssize_t ret; | ||
2673 | + struct power_supply *psy = dev_get_drvdata(dev); | ||
2674 | + const ptrdiff_t off = attr - power_supply_attrs; | ||
2675 | + union power_supply_propval value; | ||
2676 | + | ||
2677 | + ret = psy->get_property(psy, off, &value); | ||
2678 | + | ||
2679 | + if (ret < 0) { | ||
2680 | + dev_err(dev, "driver failed to report `%s' property\n", | ||
2681 | + attr->attr.name); | ||
2682 | + return ret; | ||
2683 | + } | ||
2684 | + | ||
2685 | + if (off == POWER_SUPPLY_PROP_STATUS) | ||
2686 | + return sprintf(buf, "%s\n", status_text[value.intval]); | ||
2687 | + else if (off == POWER_SUPPLY_PROP_HEALTH) | ||
2688 | + return sprintf(buf, "%s\n", health_text[value.intval]); | ||
2689 | + else if (off == POWER_SUPPLY_PROP_TECHNOLOGY) | ||
2690 | + return sprintf(buf, "%s\n", technology_text[value.intval]); | ||
2691 | + else if (off == POWER_SUPPLY_PROP_CAPACITY_LEVEL) | ||
2692 | + return sprintf(buf, "%s\n", | ||
2693 | + capacity_level_text[value.intval]); | ||
2694 | + else if (off == POWER_SUPPLY_PROP_MODEL_NAME) | ||
2695 | + return sprintf(buf, "%s\n", value.strval); | ||
2696 | + | ||
2697 | + return sprintf(buf, "%d\n", value.intval); | ||
2698 | +} | ||
2699 | + | ||
2700 | +/* Must be in the same order as POWER_SUPPLY_PROP_* */ | ||
2701 | +static struct device_attribute power_supply_attrs[] = { | ||
2702 | + /* Properties of type `int' */ | ||
2703 | + POWER_SUPPLY_ATTR(status), | ||
2704 | + POWER_SUPPLY_ATTR(health), | ||
2705 | + POWER_SUPPLY_ATTR(present), | ||
2706 | + POWER_SUPPLY_ATTR(online), | ||
2707 | + POWER_SUPPLY_ATTR(technology), | ||
2708 | + POWER_SUPPLY_ATTR(voltage_max_design), | ||
2709 | + POWER_SUPPLY_ATTR(voltage_min_design), | ||
2710 | + POWER_SUPPLY_ATTR(voltage_now), | ||
2711 | + POWER_SUPPLY_ATTR(voltage_avg), | ||
2712 | + POWER_SUPPLY_ATTR(current_now), | ||
2713 | + POWER_SUPPLY_ATTR(current_avg), | ||
2714 | + POWER_SUPPLY_ATTR(charge_full_design), | ||
2715 | + POWER_SUPPLY_ATTR(charge_empty_design), | ||
2716 | + POWER_SUPPLY_ATTR(charge_full), | ||
2717 | + POWER_SUPPLY_ATTR(charge_empty), | ||
2718 | + POWER_SUPPLY_ATTR(charge_now), | ||
2719 | + POWER_SUPPLY_ATTR(charge_avg), | ||
2720 | + POWER_SUPPLY_ATTR(energy_full_design), | ||
2721 | + POWER_SUPPLY_ATTR(energy_empty_design), | ||
2722 | + POWER_SUPPLY_ATTR(energy_full), | ||
2723 | + POWER_SUPPLY_ATTR(energy_empty), | ||
2724 | + POWER_SUPPLY_ATTR(energy_now), | ||
2725 | + POWER_SUPPLY_ATTR(energy_avg), | ||
2726 | + POWER_SUPPLY_ATTR(capacity), | ||
2727 | + POWER_SUPPLY_ATTR(capacity_level), | ||
2728 | + POWER_SUPPLY_ATTR(temp), | ||
2729 | + POWER_SUPPLY_ATTR(temp_ambient), | ||
2730 | + POWER_SUPPLY_ATTR(time_to_empty_now), | ||
2731 | + POWER_SUPPLY_ATTR(time_to_empty_avg), | ||
2732 | + POWER_SUPPLY_ATTR(time_to_full_now), | ||
2733 | + POWER_SUPPLY_ATTR(time_to_full_avg), | ||
2734 | + /* Properties of type `const char *' */ | ||
2735 | + POWER_SUPPLY_ATTR(model_name), | ||
2736 | +}; | ||
2737 | + | ||
2738 | +static ssize_t power_supply_show_static_attrs(struct device *dev, | ||
2739 | + struct device_attribute *attr, | ||
2740 | + char *buf) { | ||
2741 | + static char *type_text[] = { "Battery", "UPS", "Mains", "USB" }; | ||
2742 | + struct power_supply *psy = dev_get_drvdata(dev); | ||
2743 | + | ||
2744 | + return sprintf(buf, "%s\n", type_text[psy->type]); | ||
2745 | +} | ||
2746 | + | ||
2747 | +static struct device_attribute power_supply_static_attrs[] = { | ||
2748 | + __ATTR(type, 0444, power_supply_show_static_attrs, NULL), | ||
2749 | +}; | ||
2750 | + | ||
2751 | +int power_supply_create_attrs(struct power_supply *psy) | ||
2752 | +{ | ||
2753 | + int rc = 0; | ||
2754 | + int i, j; | ||
2755 | + | ||
2756 | + for (i = 0; i < ARRAY_SIZE(power_supply_static_attrs); i++) { | ||
2757 | + rc = device_create_file(psy->dev, | ||
2758 | + &power_supply_static_attrs[i]); | ||
2759 | + if (rc) | ||
2760 | + goto statics_failed; | ||
2761 | + } | ||
2762 | + | ||
2763 | + for (j = 0; j < psy->num_properties; j++) { | ||
2764 | + rc = device_create_file(psy->dev, | ||
2765 | + &power_supply_attrs[psy->properties[j]]); | ||
2766 | + if (rc) | ||
2767 | + goto dynamics_failed; | ||
2768 | + } | ||
2769 | + | ||
2770 | + goto succeed; | ||
2771 | + | ||
2772 | +dynamics_failed: | ||
2773 | + while (j--) | ||
2774 | + device_remove_file(psy->dev, | ||
2775 | + &power_supply_attrs[psy->properties[j]]); | ||
2776 | +statics_failed: | ||
2777 | + while (i--) | ||
2778 | + device_remove_file(psy->dev, | ||
2779 | + &power_supply_static_attrs[psy->properties[i]]); | ||
2780 | +succeed: | ||
2781 | + return rc; | ||
2782 | +} | ||
2783 | + | ||
2784 | +void power_supply_remove_attrs(struct power_supply *psy) | ||
2785 | +{ | ||
2786 | + int i; | ||
2787 | + | ||
2788 | + for (i = 0; i < ARRAY_SIZE(power_supply_static_attrs); i++) | ||
2789 | + device_remove_file(psy->dev, | ||
2790 | + &power_supply_static_attrs[i]); | ||
2791 | + | ||
2792 | + for (i = 0; i < psy->num_properties; i++) | ||
2793 | + device_remove_file(psy->dev, | ||
2794 | + &power_supply_attrs[psy->properties[i]]); | ||
2795 | + | ||
2796 | + return; | ||
2797 | +} | ||
2798 | + | ||
2799 | +static char *kstruprdup(const char *str, gfp_t gfp) | ||
2800 | +{ | ||
2801 | + char *ret, *ustr; | ||
2802 | + | ||
2803 | + ustr = ret = kmalloc(strlen(str) + 1, gfp); | ||
2804 | + | ||
2805 | + if (!ret) | ||
2806 | + return NULL; | ||
2807 | + | ||
2808 | + while (*str) | ||
2809 | + *ustr++ = toupper(*str++); | ||
2810 | + | ||
2811 | + *ustr = 0; | ||
2812 | + | ||
2813 | + return ret; | ||
2814 | +} | ||
2815 | + | ||
2816 | +int power_supply_uevent(struct device *dev, char **envp, int num_envp, | ||
2817 | + char *buffer, int buffer_size) | ||
2818 | +{ | ||
2819 | + struct power_supply *psy = dev_get_drvdata(dev); | ||
2820 | + int i = 0, length = 0, ret = 0, j; | ||
2821 | + char *prop_buf; | ||
2822 | + char *attrname; | ||
2823 | + | ||
2824 | + dev_dbg(dev, "uevent\n"); | ||
2825 | + | ||
2826 | + if (!psy) { | ||
2827 | + dev_dbg(dev, "No power supply yet\n"); | ||
2828 | + return ret; | ||
2829 | + } | ||
2830 | + | ||
2831 | + dev_dbg(dev, "POWER_SUPPLY_NAME=%s\n", psy->name); | ||
2832 | + | ||
2833 | + ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, | ||
2834 | + &length, "POWER_SUPPLY_NAME=%s", psy->name); | ||
2835 | + if (ret) | ||
2836 | + return ret; | ||
2837 | + | ||
2838 | + prop_buf = (char *)get_zeroed_page(GFP_KERNEL); | ||
2839 | + if (!prop_buf) | ||
2840 | + return -ENOMEM; | ||
2841 | + | ||
2842 | + for (j = 0; j < ARRAY_SIZE(power_supply_static_attrs); j++) { | ||
2843 | + struct device_attribute *attr; | ||
2844 | + char *line; | ||
2845 | + | ||
2846 | + attr = &power_supply_static_attrs[j]; | ||
2847 | + | ||
2848 | + ret = power_supply_show_static_attrs(dev, attr, prop_buf); | ||
2849 | + if (ret < 0) | ||
2850 | + goto out; | ||
2851 | + | ||
2852 | + line = strchr(prop_buf, '\n'); | ||
2853 | + if (line) | ||
2854 | + *line = 0; | ||
2855 | + | ||
2856 | + attrname = kstruprdup(attr->attr.name, GFP_KERNEL); | ||
2857 | + if (!attrname) { | ||
2858 | + ret = -ENOMEM; | ||
2859 | + goto out; | ||
2860 | + } | ||
2861 | + | ||
2862 | + dev_dbg(dev, "Static prop %s=%s\n", attrname, prop_buf); | ||
2863 | + | ||
2864 | + ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, | ||
2865 | + &length, "POWER_SUPPLY_%s=%s", | ||
2866 | + attrname, prop_buf); | ||
2867 | + kfree(attrname); | ||
2868 | + if (ret) | ||
2869 | + goto out; | ||
2870 | + } | ||
2871 | + | ||
2872 | + dev_dbg(dev, "%zd dynamic props\n", psy->num_properties); | ||
2873 | + | ||
2874 | + for (j = 0; j < psy->num_properties; j++) { | ||
2875 | + struct device_attribute *attr; | ||
2876 | + char *line; | ||
2877 | + | ||
2878 | + attr = &power_supply_attrs[psy->properties[j]]; | ||
2879 | + | ||
2880 | + ret = power_supply_show_property(dev, attr, prop_buf); | ||
2881 | + if (ret < 0) | ||
2882 | + goto out; | ||
2883 | + | ||
2884 | + line = strchr(prop_buf, '\n'); | ||
2885 | + if (line) | ||
2886 | + *line = 0; | ||
2887 | + | ||
2888 | + attrname = kstruprdup(attr->attr.name, GFP_KERNEL); | ||
2889 | + if (!attrname) { | ||
2890 | + ret = -ENOMEM; | ||
2891 | + goto out; | ||
2892 | + } | ||
2893 | + | ||
2894 | + dev_dbg(dev, "prop %s=%s\n", attrname, prop_buf); | ||
2895 | + | ||
2896 | + ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, | ||
2897 | + &length, "POWER_SUPPLY_%s=%s", | ||
2898 | + attrname, prop_buf); | ||
2899 | + kfree(attrname); | ||
2900 | + if (ret) | ||
2901 | + goto out; | ||
2902 | + } | ||
2903 | + | ||
2904 | +out: | ||
2905 | + free_page((unsigned long)prop_buf); | ||
2906 | + | ||
2907 | + return ret; | ||
2908 | +} | ||
2909 | Index: linux-2.6.22/drivers/power/simpad-battery.c | ||
2910 | =================================================================== | ||
2911 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
2912 | +++ linux-2.6.22/drivers/power/simpad-battery.c 2007-08-23 12:13:52.000000000 +0200 | ||
2913 | @@ -0,0 +1,242 @@ | ||
2914 | +/* | ||
2915 | + * linux/drivers/misc/simpad-battery.c | ||
2916 | + * | ||
2917 | + * Copyright (C) 2005 Holger Hans Peter Freyther | ||
2918 | + * Copyright (C) 2001 Juergen Messerer | ||
2919 | + * | ||
2920 | + * This program is free software; you can redistribute it and/or modify | ||
2921 | + * it under the terms of the GNU General Public License as published by | ||
2922 | + * the Free Software Foundation; either version 2 of the License. | ||
2923 | + * | ||
2924 | + * Read the Battery Level through the UCB1x00 chip. T-Sinuspad is | ||
2925 | + * unsupported for now. | ||
2926 | + * | ||
2927 | + */ | ||
2928 | + | ||
2929 | +#include <linux/battery.h> | ||
2930 | +#include <asm/dma.h> | ||
2931 | +#include "ucb1x00.h" | ||
2932 | + | ||
2933 | + | ||
2934 | +/* | ||
2935 | + * Conversion from AD -> mV | ||
2936 | + * 7.5V = 1023 7.3313mV/Digit | ||
2937 | + * | ||
2938 | + * 400 Units == 9.7V | ||
2939 | + * a = ADC value | ||
2940 | + * 21 = ADC error | ||
2941 | + * 12600 = Divident to get 2*7.3242 | ||
2942 | + * 860 = Divider to get 2*7.3242 | ||
2943 | + * 170 = Voltagedrop over | ||
2944 | + */ | ||
2945 | +#define CALIBRATE_BATTERY(a) ((((a + 21)*12600)/860) + 170) | ||
2946 | + | ||
2947 | +/* | ||
2948 | + * We have two types of batteries a small and a large one | ||
2949 | + * To get the right value we to distinguish between those two | ||
2950 | + * 450 Units == 15 V | ||
2951 | + */ | ||
2952 | +#define CALIBRATE_SUPPLY(a) (((a) * 1500) / 45) | ||
2953 | +#define MIN_SUPPLY 12000 /* Less then 12V means no powersupply */ | ||
2954 | + | ||
2955 | +/* | ||
2956 | + * Charging Current | ||
2957 | + * if value is >= 50 then charging is on | ||
2958 | + */ | ||
2959 | +#define CALIBRATE_CHARGING(a) (((a)* 1000)/(152/4))) | ||
2960 | + | ||
2961 | +struct simpad_battery_t { | ||
2962 | + struct battery battery; | ||
2963 | + struct ucb1x00* ucb; | ||
2964 | + | ||
2965 | + /* | ||
2966 | + * Variables for the values to one time support | ||
2967 | + * T-Sinuspad as well | ||
2968 | + */ | ||
2969 | + int min_voltage; | ||
2970 | + int min_current; | ||
2971 | + int min_charge; | ||
2972 | + | ||
2973 | + int max_voltage; | ||
2974 | + int max_current; | ||
2975 | + int max_charge; | ||
2976 | + | ||
2977 | + int min_supply; | ||
2978 | + int charging_led_label; | ||
2979 | + int charging_max_label; | ||
2980 | + int batt_full; | ||
2981 | + int batt_low; | ||
2982 | + int batt_critical; | ||
2983 | + int batt_empty; | ||
2984 | +}; | ||
2985 | + | ||
2986 | +static int simpad_get_min_voltage(struct battery* _battery ) | ||
2987 | +{ | ||
2988 | + struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; | ||
2989 | + return battery->min_voltage; | ||
2990 | +} | ||
2991 | + | ||
2992 | +static int simpad_get_min_current(struct battery* _battery) | ||
2993 | +{ | ||
2994 | + struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; | ||
2995 | + return battery->min_current; | ||
2996 | +} | ||
2997 | + | ||
2998 | +static int simpad_get_min_charge(struct battery* _battery) | ||
2999 | +{ | ||
3000 | + struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; | ||
3001 | + return battery->min_charge; | ||
3002 | +} | ||
3003 | + | ||
3004 | +static int simpad_get_max_voltage(struct battery* _battery) | ||
3005 | +{ | ||
3006 | + struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; | ||
3007 | + return battery->max_voltage; | ||
3008 | +} | ||
3009 | + | ||
3010 | +static int simpad_get_max_current(struct battery* _battery) | ||
3011 | +{ | ||
3012 | + struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; | ||
3013 | + return battery->max_current; | ||
3014 | +} | ||
3015 | + | ||
3016 | +static int simpad_get_max_charge(struct battery* _battery) | ||
3017 | +{ | ||
3018 | + struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; | ||
3019 | + return battery->max_charge; | ||
3020 | +} | ||
3021 | + | ||
3022 | +static int simpad_get_temp(struct battery* _battery) | ||
3023 | +{ | ||
3024 | + return 0; | ||
3025 | +} | ||
3026 | + | ||
3027 | +static int simpad_get_voltage(struct battery* _battery) | ||
3028 | +{ | ||
3029 | + int val; | ||
3030 | + struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; | ||
3031 | + | ||
3032 | + | ||
3033 | + ucb1x00_adc_enable(battery->ucb); | ||
3034 | + val = ucb1x00_adc_read(battery->ucb, UCB_ADC_INP_AD1, UCB_NOSYNC); | ||
3035 | + ucb1x00_adc_disable(battery->ucb); | ||
3036 | + | ||
3037 | + return CALIBRATE_BATTERY(val); | ||
3038 | +} | ||
3039 | + | ||
3040 | +static int simpad_get_current(struct battery* _battery) | ||
3041 | +{ | ||
3042 | + int val; | ||
3043 | + struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; | ||
3044 | + | ||
3045 | + ucb1x00_adc_enable(battery->ucb); | ||
3046 | + val = ucb1x00_adc_read(battery->ucb, UCB_ADC_INP_AD3, UCB_NOSYNC); | ||
3047 | + ucb1x00_adc_disable(battery->ucb); | ||
3048 | + | ||
3049 | + return val; | ||
3050 | +} | ||
3051 | + | ||
3052 | +static int simpad_get_charge(struct battery* _battery) | ||
3053 | +{ | ||
3054 | + int val; | ||
3055 | + struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; | ||
3056 | + | ||
3057 | + ucb1x00_adc_enable(battery->ucb); | ||
3058 | + val = ucb1x00_adc_read(battery->ucb, UCB_ADC_INP_AD2, UCB_NOSYNC); | ||
3059 | + ucb1x00_adc_disable(battery->ucb); | ||
3060 | + | ||
3061 | + return CALIBRATE_SUPPLY(val); | ||
3062 | + | ||
3063 | +} | ||
3064 | + | ||
3065 | +static int simpad_get_status(struct battery* _battery) | ||
3066 | +{ | ||
3067 | + struct simpad_battery_t* battery = (struct simpad_battery_t*)(_battery); | ||
3068 | + int vcharger = simpad_get_voltage(_battery); | ||
3069 | + int icharger = simpad_get_current(_battery); | ||
3070 | + | ||
3071 | + int status = BATTERY_STATUS_UNKNOWN; | ||
3072 | + if(icharger > battery->charging_led_label) | ||
3073 | + status = BATTERY_STATUS_CHARGING; | ||
3074 | + else if(vcharger > battery->min_supply) | ||
3075 | + status = BATTERY_STATUS_NOT_CHARGING; | ||
3076 | + else | ||
3077 | + status = BATTERY_STATUS_DISCHARGING; | ||
3078 | + | ||
3079 | + return status; | ||
3080 | +} | ||
3081 | + | ||
3082 | +static struct simpad_battery_t simpad_battery = { | ||
3083 | + .battery = { | ||
3084 | + .get_min_voltage = simpad_get_min_voltage, | ||
3085 | + .get_min_current = simpad_get_min_current, | ||
3086 | + .get_min_charge = simpad_get_min_charge, | ||
3087 | + .get_max_voltage = simpad_get_max_voltage, | ||
3088 | + .get_max_current = simpad_get_max_current, | ||
3089 | + .get_max_charge = simpad_get_max_charge, | ||
3090 | + .get_temp = simpad_get_temp, | ||
3091 | + .get_voltage = simpad_get_voltage, | ||
3092 | + .get_current = simpad_get_current, | ||
3093 | + .get_charge = simpad_get_charge, | ||
3094 | + .get_status = simpad_get_status, | ||
3095 | + }, | ||
3096 | + .min_voltage = 0, | ||
3097 | + .min_current = 0, | ||
3098 | + .min_charge = 0, | ||
3099 | + .max_voltage = 0, | ||
3100 | + .max_current = 0, | ||
3101 | + .max_charge = 0, | ||
3102 | + | ||
3103 | + .min_supply = 1200, | ||
3104 | + .charging_led_label = 18, | ||
3105 | + .charging_max_label = 265, | ||
3106 | + .batt_full = 8300, | ||
3107 | + .batt_low = 7300, | ||
3108 | + .batt_critical = 6800, | ||
3109 | + .batt_empty = 6500, | ||
3110 | +}; | ||
3111 | + | ||
3112 | + | ||
3113 | + | ||
3114 | +/* | ||
3115 | + * UCB glue code | ||
3116 | + */ | ||
3117 | +static int ucb1x00_battery_add(struct class_device *dev) | ||
3118 | +{ | ||
3119 | + struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); | ||
3120 | + simpad_battery.ucb = ucb; | ||
3121 | + | ||
3122 | + battery_class_register(&simpad_battery.battery); | ||
3123 | + | ||
3124 | + return 0; | ||
3125 | +} | ||
3126 | + | ||
3127 | +static void ucb1x00_battery_remove(struct class_device *dev) | ||
3128 | +{ | ||
3129 | + return battery_class_unregister(&simpad_battery.battery); | ||
3130 | +} | ||
3131 | + | ||
3132 | + | ||
3133 | +static struct ucb1x00_class_interface ucb1x00_battery_interface = { | ||
3134 | + .interface = { | ||
3135 | + .add = ucb1x00_battery_add, | ||
3136 | + .remove = ucb1x00_battery_remove, | ||
3137 | + }, | ||
3138 | +}; | ||
3139 | + | ||
3140 | + | ||
3141 | +static int __init battery_register(void) | ||
3142 | +{ | ||
3143 | + return ucb1x00_register_interface(&ucb1x00_battery_interface); | ||
3144 | +} | ||
3145 | + | ||
3146 | +static void __exit battery_unregister(void) | ||
3147 | +{ | ||
3148 | + ucb1x00_unregister_interface(&ucb1x00_battery_interface); | ||
3149 | +} | ||
3150 | + | ||
3151 | +module_init(battery_register); | ||
3152 | +module_exit(battery_unregister); | ||
3153 | + | ||
3154 | +MODULE_AUTHOR("Holger Hans Peter Freyther"); | ||
3155 | +MODULE_LICENSE("GPL"); | ||
3156 | Index: linux-2.6.22/arch/arm/Kconfig | ||
3157 | =================================================================== | ||
3158 | --- linux-2.6.22.orig/arch/arm/Kconfig 2007-08-23 12:17:42.000000000 +0200 | ||
3159 | +++ linux-2.6.22/arch/arm/Kconfig 2007-08-23 12:22:28.000000000 +0200 | ||
3160 | @@ -1016,6 +1016,8 @@ | ||
3161 | |||
3162 | source "drivers/w1/Kconfig" | ||
3163 | |||
3164 | +source "drivers/power/Kconfig" | ||
3165 | + | ||
3166 | source "drivers/hwmon/Kconfig" | ||
3167 | |||
3168 | #source "drivers/l3/Kconfig" | ||
3169 | Index: linux-2.6.22/drivers/Kconfig | ||
3170 | =================================================================== | ||
3171 | --- linux-2.6.22.orig/drivers/Kconfig 2007-08-23 12:21:27.000000000 +0200 | ||
3172 | +++ linux-2.6.22/drivers/Kconfig 2007-08-23 12:22:03.000000000 +0200 | ||
3173 | @@ -54,6 +54,8 @@ | ||
3174 | |||
3175 | source "drivers/w1/Kconfig" | ||
3176 | |||
3177 | +source "drivers/power/Kconfig" | ||
3178 | + | ||
3179 | source "drivers/hwmon/Kconfig" | ||
3180 | |||
3181 | source "drivers/mfd/Kconfig" | ||
3182 | Index: linux-2.6.22/drivers/Makefile | ||
3183 | =================================================================== | ||
3184 | --- linux-2.6.22.orig/drivers/Makefile 2007-08-23 12:33:58.000000000 +0200 | ||
3185 | +++ linux-2.6.22/drivers/Makefile 2007-08-23 12:34:34.000000000 +0200 | ||
3186 | @@ -61,6 +61,7 @@ | ||
3187 | obj-$(CONFIG_RTC_LIB) += rtc/ | ||
3188 | obj-y += i2c/ | ||
3189 | obj-$(CONFIG_W1) += w1/ | ||
3190 | +obj-$(CONFIG_POWER_SUPPLY) += power/ | ||
3191 | obj-$(CONFIG_HWMON) += hwmon/ | ||
3192 | obj-$(CONFIG_PHONE) += telephony/ | ||
3193 | obj-$(CONFIG_MD) += md/ | ||
3194 | Index: linux-2.6.22/include/linux/power_supply.h | ||
3195 | =================================================================== | ||
3196 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
3197 | +++ linux-2.6.22/include/linux/power_supply.h 2007-08-23 12:37:10.000000000 +0200 | ||
3198 | @@ -0,0 +1,175 @@ | ||
3199 | +/* | ||
3200 | + * Universal power supply monitor class | ||
3201 | + * | ||
3202 | + * Copyright (c) 2007 Anton Vorontsov <cbou@mail.ru> | ||
3203 | + * Copyright (c) 2004 Szabolcs Gyurko | ||
3204 | + * Copyright (c) 2003 Ian Molton <spyro@f2s.com> | ||
3205 | + * | ||
3206 | + * Modified: 2004, Oct Szabolcs Gyurko | ||
3207 | + * | ||
3208 | + * You may use this code as per GPL version 2 | ||
3209 | + */ | ||
3210 | + | ||
3211 | +#ifndef __LINUX_POWER_SUPPLY_H__ | ||
3212 | +#define __LINUX_POWER_SUPPLY_H__ | ||
3213 | + | ||
3214 | +#include <linux/device.h> | ||
3215 | +#include <linux/workqueue.h> | ||
3216 | +#include <linux/leds.h> | ||
3217 | + | ||
3218 | +/* | ||
3219 | + * All voltages, currents, charges, energies, time and temperatures in uV, | ||
3220 | + * uA, uAh, uWh, seconds and tenths of degree Celsius unless otherwise | ||
3221 | + * stated. It's driver's job to convert its raw values to units in which | ||
3222 | + * this class operates. | ||
3223 | + */ | ||
3224 | + | ||
3225 | +/* | ||
3226 | + * For systems where the charger determines the maximum battery capacity | ||
3227 | + * the min and max fields should be used to present these values to user | ||
3228 | + * space. Unused/unknown fields will not appear in sysfs. | ||
3229 | + */ | ||
3230 | + | ||
3231 | +enum { | ||
3232 | + POWER_SUPPLY_STATUS_UNKNOWN = 0, | ||
3233 | + POWER_SUPPLY_STATUS_CHARGING, | ||
3234 | + POWER_SUPPLY_STATUS_DISCHARGING, | ||
3235 | + POWER_SUPPLY_STATUS_NOT_CHARGING, | ||
3236 | + POWER_SUPPLY_STATUS_FULL, | ||
3237 | +}; | ||
3238 | + | ||
3239 | +enum { | ||
3240 | + POWER_SUPPLY_HEALTH_UNKNOWN = 0, | ||
3241 | + POWER_SUPPLY_HEALTH_GOOD, | ||
3242 | + POWER_SUPPLY_HEALTH_OVERHEAT, | ||
3243 | + POWER_SUPPLY_HEALTH_DEAD, | ||
3244 | +}; | ||
3245 | + | ||
3246 | +enum { | ||
3247 | + POWER_SUPPLY_TECHNOLOGY_UNKNOWN = 0, | ||
3248 | + POWER_SUPPLY_TECHNOLOGY_NIMH, | ||
3249 | + POWER_SUPPLY_TECHNOLOGY_LION, | ||
3250 | + POWER_SUPPLY_TECHNOLOGY_LIPO, | ||
3251 | +}; | ||
3252 | + | ||
3253 | +enum { | ||
3254 | + POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0, | ||
3255 | + POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL, | ||
3256 | + POWER_SUPPLY_CAPACITY_LEVEL_LOW, | ||
3257 | + POWER_SUPPLY_CAPACITY_LEVEL_NORMAL, | ||
3258 | + POWER_SUPPLY_CAPACITY_LEVEL_HIGH, | ||
3259 | + POWER_SUPPLY_CAPACITY_LEVEL_FULL, | ||
3260 | +}; | ||
3261 | + | ||
3262 | +enum power_supply_property { | ||
3263 | + /* Properties of type `int' */ | ||
3264 | + POWER_SUPPLY_PROP_STATUS = 0, | ||
3265 | + POWER_SUPPLY_PROP_HEALTH, | ||
3266 | + POWER_SUPPLY_PROP_PRESENT, | ||
3267 | + POWER_SUPPLY_PROP_ONLINE, | ||
3268 | + POWER_SUPPLY_PROP_TECHNOLOGY, | ||
3269 | + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, | ||
3270 | + POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, | ||
3271 | + POWER_SUPPLY_PROP_VOLTAGE_NOW, | ||
3272 | + POWER_SUPPLY_PROP_VOLTAGE_AVG, | ||
3273 | + POWER_SUPPLY_PROP_CURRENT_NOW, | ||
3274 | + POWER_SUPPLY_PROP_CURRENT_AVG, | ||
3275 | + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, | ||
3276 | + POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN, | ||
3277 | + POWER_SUPPLY_PROP_CHARGE_FULL, | ||
3278 | + POWER_SUPPLY_PROP_CHARGE_EMPTY, | ||
3279 | + POWER_SUPPLY_PROP_CHARGE_NOW, | ||
3280 | + POWER_SUPPLY_PROP_CHARGE_AVG, | ||
3281 | + POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, | ||
3282 | + POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN, | ||
3283 | + POWER_SUPPLY_PROP_ENERGY_FULL, | ||
3284 | + POWER_SUPPLY_PROP_ENERGY_EMPTY, | ||
3285 | + POWER_SUPPLY_PROP_ENERGY_NOW, | ||
3286 | + POWER_SUPPLY_PROP_ENERGY_AVG, | ||
3287 | + POWER_SUPPLY_PROP_CAPACITY, /* in percents! */ | ||
3288 | + POWER_SUPPLY_PROP_CAPACITY_LEVEL, | ||
3289 | + POWER_SUPPLY_PROP_TEMP, | ||
3290 | + POWER_SUPPLY_PROP_TEMP_AMBIENT, | ||
3291 | + POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, | ||
3292 | + POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, | ||
3293 | + POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, | ||
3294 | + POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, | ||
3295 | + /* Properties of type `const char *' */ | ||
3296 | + POWER_SUPPLY_PROP_MODEL_NAME, | ||
3297 | +}; | ||
3298 | + | ||
3299 | +enum power_supply_type { | ||
3300 | + POWER_SUPPLY_TYPE_BATTERY = 0, | ||
3301 | + POWER_SUPPLY_TYPE_UPS, | ||
3302 | + POWER_SUPPLY_TYPE_MAINS, | ||
3303 | + POWER_SUPPLY_TYPE_USB, | ||
3304 | +}; | ||
3305 | + | ||
3306 | +union power_supply_propval { | ||
3307 | + int intval; | ||
3308 | + const char *strval; | ||
3309 | +}; | ||
3310 | + | ||
3311 | +struct power_supply { | ||
3312 | + const char *name; | ||
3313 | + enum power_supply_type type; | ||
3314 | + enum power_supply_property *properties; | ||
3315 | + size_t num_properties; | ||
3316 | + | ||
3317 | + char **supplied_to; | ||
3318 | + size_t num_supplicants; | ||
3319 | + | ||
3320 | + int (*get_property)(struct power_supply *psy, | ||
3321 | + enum power_supply_property psp, | ||
3322 | + union power_supply_propval *val); | ||
3323 | + void (*external_power_changed)(struct power_supply *psy); | ||
3324 | + | ||
3325 | + /* For APM emulation, think legacy userspace. */ | ||
3326 | + int use_for_apm; | ||
3327 | + | ||
3328 | + /* private */ | ||
3329 | + struct device *dev; | ||
3330 | + struct work_struct changed_work; | ||
3331 | + | ||
3332 | +#ifdef CONFIG_LEDS_TRIGGERS | ||
3333 | + struct led_trigger *charging_full_trig; | ||
3334 | + char *charging_full_trig_name; | ||
3335 | + struct led_trigger *charging_trig; | ||
3336 | + char *charging_trig_name; | ||
3337 | + struct led_trigger *full_trig; | ||
3338 | + char *full_trig_name; | ||
3339 | + struct led_trigger *online_trig; | ||
3340 | + char *online_trig_name; | ||
3341 | +#endif | ||
3342 | +}; | ||
3343 | + | ||
3344 | +/* | ||
3345 | + * This is recommended structure to specify static power supply parameters. | ||
3346 | + * Generic one, parametrizable for different power supplies. Power supply | ||
3347 | + * class itself does not use it, but that's what implementing most platform | ||
3348 | + * drivers, should try reuse for consistency. | ||
3349 | + */ | ||
3350 | + | ||
3351 | +struct power_supply_info { | ||
3352 | + const char *name; | ||
3353 | + int technology; | ||
3354 | + int voltage_max_design; | ||
3355 | + int voltage_min_design; | ||
3356 | + int charge_full_design; | ||
3357 | + int charge_empty_design; | ||
3358 | + int energy_full_design; | ||
3359 | + int energy_empty_design; | ||
3360 | + int use_for_apm; | ||
3361 | +}; | ||
3362 | + | ||
3363 | +extern void power_supply_changed(struct power_supply *psy); | ||
3364 | +extern int power_supply_am_i_supplied(struct power_supply *psy); | ||
3365 | + | ||
3366 | +extern int power_supply_register(struct device *parent, | ||
3367 | + struct power_supply *psy); | ||
3368 | +extern void power_supply_unregister(struct power_supply *psy); | ||
3369 | + | ||
3370 | +/* For APM emulation, think legacy userspace. */ | ||
3371 | +extern struct class *power_supply_class; | ||
3372 | + | ||
3373 | +#endif /* __LINUX_POWER_SUPPLY_H__ */ | ||
diff --git a/meta/packages/linux/linux-rp-2.6.23/versatile-armv6.patch b/meta/packages/linux/linux-rp-2.6.23/versatile-armv6.patch new file mode 100644 index 0000000000..e2d0060ac3 --- /dev/null +++ b/meta/packages/linux/linux-rp-2.6.23/versatile-armv6.patch | |||
@@ -0,0 +1,19 @@ | |||
1 | --- | ||
2 | arch/arm/mm/Kconfig | 2 +- | ||
3 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
4 | |||
5 | --- linux-2.6.23.orig/arch/arm/mm/Kconfig | ||
6 | +++ linux-2.6.23/arch/arm/mm/Kconfig | ||
7 | @@ -343,11 +343,11 @@ config CPU_XSC3 | ||
8 | select IO_36 | ||
9 | |||
10 | # ARMv6 | ||
11 | config CPU_V6 | ||
12 | bool "Support ARM V6 processor" | ||
13 | - depends on ARCH_INTEGRATOR || MACH_REALVIEW_EB || ARCH_OMAP2 || ARCH_MX3 | ||
14 | + depends on ARCH_INTEGRATOR || MACH_REALVIEW_EB || ARCH_OMAP2 || ARCH_MX3 || ARCH_VERSATILE_PB | ||
15 | default y if ARCH_MX3 | ||
16 | select CPU_32v6 | ||
17 | select CPU_ABRT_EV6 | ||
18 | select CPU_CACHE_V6 | ||
19 | select CPU_CACHE_VIPT | ||
diff --git a/meta/packages/linux/linux-rp-2.6.23/vt_ioctl_race.patch b/meta/packages/linux/linux-rp-2.6.23/vt_ioctl_race.patch deleted file mode 100644 index 5a51d1c3f5..0000000000 --- a/meta/packages/linux/linux-rp-2.6.23/vt_ioctl_race.patch +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | --- | ||
2 | drivers/char/vt_ioctl.c | 8 +++++--- | ||
3 | 1 file changed, 5 insertions(+), 3 deletions(-) | ||
4 | |||
5 | Index: linux-2.6.22/drivers/char/vt_ioctl.c | ||
6 | =================================================================== | ||
7 | --- linux-2.6.22.orig/drivers/char/vt_ioctl.c 2007-07-09 01:32:17.000000000 +0200 | ||
8 | +++ linux-2.6.22/drivers/char/vt_ioctl.c 2007-09-27 11:58:42.000000000 +0200 | ||
9 | @@ -770,6 +770,7 @@ | ||
10 | /* | ||
11 | * Switching-from response | ||
12 | */ | ||
13 | + acquire_console_sem(); | ||
14 | if (vc->vt_newvt >= 0) { | ||
15 | if (arg == 0) | ||
16 | /* | ||
17 | @@ -784,7 +785,6 @@ | ||
18 | * complete the switch. | ||
19 | */ | ||
20 | int newvt; | ||
21 | - acquire_console_sem(); | ||
22 | newvt = vc->vt_newvt; | ||
23 | vc->vt_newvt = -1; | ||
24 | i = vc_allocate(newvt); | ||
25 | @@ -798,7 +798,6 @@ | ||
26 | * other console switches.. | ||
27 | */ | ||
28 | complete_change_console(vc_cons[newvt].d); | ||
29 | - release_console_sem(); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | @@ -810,9 +809,12 @@ | ||
34 | /* | ||
35 | * If it's just an ACK, ignore it | ||
36 | */ | ||
37 | - if (arg != VT_ACKACQ) | ||
38 | + if (arg != VT_ACKACQ) { | ||
39 | + release_console_sem(); | ||
40 | return -EINVAL; | ||
41 | + } | ||
42 | } | ||
43 | + release_console_sem(); | ||
44 | |||
45 | return 0; | ||
46 | |||
diff --git a/meta/packages/linux/linux-rp-2.6.23/w100fb-unused-var.patch b/meta/packages/linux/linux-rp-2.6.23/w100fb-unused-var.patch deleted file mode 100644 index 8cbbb6bd01..0000000000 --- a/meta/packages/linux/linux-rp-2.6.23/w100fb-unused-var.patch +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | From: Marcin Juszkiewicz <openembedded@haerwu.biz> | ||
2 | |||
3 | drivers/video/w100fb.c: In function ‘w100fb_imageblit’: | ||
4 | drivers/video/w100fb.c:507: warning: unused variable ‘par’ | ||
5 | |||
6 | Signed-off-by: Marcin Juszkiewicz <openembedded@haerwu.biz> | ||
7 | |||
8 | --- linux-2.6.23/drivers/video/w100fb.c 2007-10-11 16:52:30.000000000 +0200 | ||
9 | +++ linux-2.6.23/drivers/video/w100fb.c 2007-10-15 12:56:01.000000000 +0200 | ||
10 | @@ -504,7 +504,6 @@ static void w100_hostdata(u32 width, u32 | ||
11 | static void w100fb_imageblit(struct fb_info *info, | ||
12 | const struct fb_image *image) | ||
13 | { | ||
14 | - struct w100fb_par *par = info->par; | ||
15 | union dp_gui_master_cntl_u gmc; | ||
16 | u32 fgcolor, bgcolor; | ||
17 | |||
diff --git a/meta/packages/linux/linux-rp-2.6.23/wm9712-reset-loop-r2.patch b/meta/packages/linux/linux-rp-2.6.23/wm9712-reset-loop-r2.patch new file mode 100644 index 0000000000..78e81ea83a --- /dev/null +++ b/meta/packages/linux/linux-rp-2.6.23/wm9712-reset-loop-r2.patch | |||
@@ -0,0 +1,44 @@ | |||
1 | sound/soc/codecs/wm9712.c | 28 ++++++++++++++++++---------- | ||
2 | 1 file changed, 18 insertions(+), 10 deletions(-) | ||
3 | |||
4 | Index: git/sound/soc/codecs/wm9712.c | ||
5 | =================================================================== | ||
6 | --- git.orig/sound/soc/codecs/wm9712.c 2006-11-07 22:10:01.000000000 +0000 | ||
7 | +++ git/sound/soc/codecs/wm9712.c 2006-11-07 22:11:50.000000000 +0000 | ||
8 | @@ -618,18 +618,26 @@ static int wm9712_dapm_event(struct snd_ | ||
9 | |||
10 | static int wm9712_reset(struct snd_soc_codec *codec, int try_warm) | ||
11 | { | ||
12 | - if (try_warm && soc_ac97_ops.warm_reset) { | ||
13 | - soc_ac97_ops.warm_reset(codec->ac97); | ||
14 | - if (!(ac97_read(codec, 0) & 0x8000)) | ||
15 | - return 1; | ||
16 | - } | ||
17 | + int retry = 3; | ||
18 | |||
19 | - soc_ac97_ops.reset(codec->ac97); | ||
20 | - if (ac97_read(codec, 0) & 0x8000) | ||
21 | - goto err; | ||
22 | - return 0; | ||
23 | + while (retry--) | ||
24 | + { | ||
25 | + if(try_warm && soc_ac97_ops.warm_reset) { | ||
26 | + soc_ac97_ops.warm_reset(codec->ac97); | ||
27 | + if(ac97_read(codec, 0) & 0x8000) | ||
28 | + continue; | ||
29 | + else | ||
30 | + return 1; | ||
31 | + } | ||
32 | + | ||
33 | + soc_ac97_ops.reset(codec->ac97); | ||
34 | + if(ac97_read(codec, 0) & 0x8000) | ||
35 | + continue; | ||
36 | + else | ||
37 | + return 0; | ||
38 | + | ||
39 | + } | ||
40 | |||
41 | -err: | ||
42 | printk(KERN_ERR "WM9712 AC97 reset failed\n"); | ||
43 | return -EIO; | ||
44 | } | ||
diff --git a/meta/packages/linux/linux-rp-2.6.23/wm9712-suspend-cold-res-r2.patch b/meta/packages/linux/linux-rp-2.6.23/wm9712-suspend-cold-res-r2.patch new file mode 100644 index 0000000000..5179b47cc4 --- /dev/null +++ b/meta/packages/linux/linux-rp-2.6.23/wm9712-suspend-cold-res-r2.patch | |||
@@ -0,0 +1,16 @@ | |||
1 | sound/soc/codecs/wm9712.c | 2 +- | ||
2 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
3 | |||
4 | Index: git/sound/soc/codecs/wm9712.c | ||
5 | =================================================================== | ||
6 | --- git.orig/sound/soc/codecs/wm9712.c 2006-11-07 21:57:34.000000000 +0000 | ||
7 | +++ git/sound/soc/codecs/wm9712.c 2006-11-07 21:59:30.000000000 +0000 | ||
8 | @@ -651,7 +651,7 @@ static int wm9712_soc_resume(struct plat | ||
9 | int i, ret; | ||
10 | u16 *cache = codec->reg_cache; | ||
11 | |||
12 | - ret = wm9712_reset(codec, 1); | ||
13 | + ret = wm9712_reset(codec, 0); | ||
14 | if (ret < 0){ | ||
15 | printk(KERN_ERR "could not reset AC97 codec\n"); | ||
16 | return ret; | ||
diff --git a/meta/packages/linux/linux-rp-2.6.23/wm97xx-lg13-r0-fix-r0.patch b/meta/packages/linux/linux-rp-2.6.23/wm97xx-lg13-r0-fix-r0.patch new file mode 100644 index 0000000000..5ad0d8703d --- /dev/null +++ b/meta/packages/linux/linux-rp-2.6.23/wm97xx-lg13-r0-fix-r0.patch | |||
@@ -0,0 +1,128 @@ | |||
1 | drivers/input/power.c | 2 +- | ||
2 | drivers/input/touchscreen/Kconfig | 2 +- | ||
3 | drivers/input/touchscreen/wm97xx-core.c | 35 ++++++++++++++++--------------- | ||
4 | include/linux/wm97xx.h | 2 +- | ||
5 | 4 files changed, 21 insertions(+), 20 deletions(-) | ||
6 | |||
7 | diff --git a/drivers/input/power.c b/drivers/input/power.c | ||
8 | index 4443e34..7aac875 100644 | ||
9 | --- a/drivers/input/power.c | ||
10 | +++ b/drivers/input/power.c | ||
11 | @@ -156,7 +156,7 @@ static void power_event(struct input_handle *handle, unsigned int type, | ||
12 | } | ||
13 | } | ||
14 | |||
15 | -static struct input_handle *power_connect(struct input_handler *handler, | ||
16 | +static int power_connect(struct input_handler *handler, | ||
17 | struct input_dev *dev, | ||
18 | const struct input_device_id *id) | ||
19 | { | ||
20 | diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig | ||
21 | index 6862e8f..9b532e9 100644 | ||
22 | --- a/drivers/input/touchscreen/Kconfig | ||
23 | +++ b/drivers/input/touchscreen/Kconfig | ||
24 | @@ -247,7 +247,7 @@ config TOUCHSCREEN_TSC2101 | ||
25 | |||
26 | config TOUCHSCREEN_WM97XX | ||
27 | tristate "Support for WM97xx AC97 touchscreen controllers" | ||
28 | - depends SND_AC97_BUS | ||
29 | + depends AC97_BUS | ||
30 | |||
31 | choice | ||
32 | prompt "WM97xx codec type" | ||
33 | diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c | ||
34 | index 9b2710e..d3ce3f3 100644 | ||
35 | --- a/drivers/input/touchscreen/wm97xx-core.c | ||
36 | +++ b/drivers/input/touchscreen/wm97xx-core.c | ||
37 | @@ -84,6 +84,7 @@ | ||
38 | #include <linux/bitops.h> | ||
39 | #include <linux/workqueue.h> | ||
40 | #include <linux/device.h> | ||
41 | +#include <linux/freezer.h> | ||
42 | #include <linux/wm97xx.h> | ||
43 | #include <asm/uaccess.h> | ||
44 | #include <asm/io.h> | ||
45 | @@ -241,14 +242,15 @@ WM97XX_STATUS_ATTR(gpio); | ||
46 | |||
47 | static int wm97xx_sys_add(struct device *dev) | ||
48 | { | ||
49 | + int err; | ||
50 | if (aux_sys) { | ||
51 | - device_create_file(dev, &dev_attr_aux1); | ||
52 | - device_create_file(dev, &dev_attr_aux2); | ||
53 | - device_create_file(dev, &dev_attr_aux3); | ||
54 | - device_create_file(dev, &dev_attr_aux4); | ||
55 | + err = device_create_file(dev, &dev_attr_aux1); | ||
56 | + err = device_create_file(dev, &dev_attr_aux2); | ||
57 | + err = device_create_file(dev, &dev_attr_aux3); | ||
58 | + err = device_create_file(dev, &dev_attr_aux4); | ||
59 | } | ||
60 | if (status_sys) | ||
61 | - device_create_file(dev, &dev_attr_gpio); | ||
62 | + err = device_create_file(dev, &dev_attr_gpio); | ||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | @@ -366,12 +368,12 @@ void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, wm97xx_gpio_dir_t dir, | ||
67 | |||
68 | /* | ||
69 | * Handle a pen down interrupt. | ||
70 | - */ | ||
71 | -static void wm97xx_pen_irq_worker(void *ptr) | ||
72 | -{ | ||
73 | - struct wm97xx *wm = (struct wm97xx *) ptr; | ||
74 | - | ||
75 | - /* do we need to enable the touch panel reader */ | ||
76 | + */ | ||
77 | +static void wm97xx_pen_irq_worker(struct work_struct *work) | ||
78 | +{ | ||
79 | + struct wm97xx *wm = container_of(work, struct wm97xx, pen_event_work); | ||
80 | + | ||
81 | + /* do we need to enable the touch panel reader */ | ||
82 | if (wm->id == WM9705_ID2) { | ||
83 | if (wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD) & WM97XX_PEN_DOWN) | ||
84 | wm->pen_is_down = 1; | ||
85 | @@ -411,9 +413,8 @@ static void wm97xx_pen_irq_worker(void *ptr) | ||
86 | * We have to disable the codec interrupt in the handler because it can | ||
87 | * take upto 1ms to clear the interrupt source. The interrupt is then enabled | ||
88 | * again in the slow handler when the source has been cleared. | ||
89 | - */ | ||
90 | -static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id, | ||
91 | - struct pt_regs *regs) | ||
92 | + */ | ||
93 | +static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id) | ||
94 | { | ||
95 | struct wm97xx *wm = (struct wm97xx *) dev_id; | ||
96 | disable_irq(wm->pen_irq); | ||
97 | @@ -428,15 +429,15 @@ static int wm97xx_init_pen_irq(struct wm97xx *wm) | ||
98 | { | ||
99 | u16 reg; | ||
100 | |||
101 | - INIT_WORK(&wm->pen_event_work, wm97xx_pen_irq_worker, wm); | ||
102 | - if ((wm->pen_irq_workq = | ||
103 | + INIT_WORK(&wm->pen_event_work, wm97xx_pen_irq_worker); | ||
104 | + if ((wm->pen_irq_workq = | ||
105 | create_singlethread_workqueue("kwm97pen")) == NULL) { | ||
106 | err("could not create pen irq work queue"); | ||
107 | wm->pen_irq = 0; | ||
108 | return -EINVAL; | ||
109 | } | ||
110 | |||
111 | - if (request_irq (wm->pen_irq, wm97xx_pen_interrupt, SA_SHIRQ, "wm97xx-pen", wm)) { | ||
112 | + if (request_irq (wm->pen_irq, wm97xx_pen_interrupt, IRQF_SHARED, "wm97xx-pen", wm)) { | ||
113 | err("could not register codec pen down interrupt, will poll for pen down"); | ||
114 | destroy_workqueue(wm->pen_irq_workq); | ||
115 | wm->pen_irq = 0; | ||
116 | diff --git a/include/linux/wm97xx.h b/include/linux/wm97xx.h | ||
117 | index b1c1740..a9bd57e 100644 | ||
118 | --- a/include/linux/wm97xx.h | ||
119 | +++ b/include/linux/wm97xx.h | ||
120 | @@ -243,7 +243,7 @@ struct wm97xx { | ||
121 | u16 dig_save[3]; /* saved during aux reading */ | ||
122 | struct wm97xx_codec_drv *codec; /* attached codec driver*/ | ||
123 | struct input_dev* input_dev; /* touchscreen input device */ | ||
124 | - ac97_t *ac97; /* ALSA codec access */ | ||
125 | + struct snd_ac97 *ac97; /* ALSA codec access */ | ||
126 | struct device *dev; /* ALSA device */ | ||
127 | struct device *battery_dev; | ||
128 | struct device *touch_dev; | ||
diff --git a/meta/packages/linux/linux-rp-2.6.23/wm97xx-lg13-r0.patch b/meta/packages/linux/linux-rp-2.6.23/wm97xx-lg13-r0.patch new file mode 100644 index 0000000000..c918c5daff --- /dev/null +++ b/meta/packages/linux/linux-rp-2.6.23/wm97xx-lg13-r0.patch | |||
@@ -0,0 +1,2899 @@ | |||
1 | Index: linux-2.6.17/drivers/input/touchscreen/Kconfig | ||
2 | =================================================================== | ||
3 | --- linux-2.6.17.orig/drivers/input/touchscreen/Kconfig 2006-09-19 20:35:35.060495500 +0200 | ||
4 | +++ linux-2.6.17/drivers/input/touchscreen/Kconfig 2006-09-19 20:36:47.965051750 +0200 | ||
5 | @@ -121,4 +121,57 @@ config TOUCHSCREEN_TSC2101 | ||
6 | To compile this driver as a module, choose M here: the | ||
7 | module will be called ads7846_ts. | ||
8 | |||
9 | +config TOUCHSCREEN_WM97XX | ||
10 | + tristate "Support for WM97xx AC97 touchscreen controllers" | ||
11 | + depends SND_AC97_BUS | ||
12 | + | ||
13 | +choice | ||
14 | + prompt "WM97xx codec type" | ||
15 | + | ||
16 | +config TOUCHSCREEN_WM9705 | ||
17 | + bool "WM9705 Touchscreen interface support" | ||
18 | + depends on TOUCHSCREEN_WM97XX | ||
19 | + help | ||
20 | + Say Y here if you have the wm9705 touchscreen. | ||
21 | + | ||
22 | + If unsure, say N. | ||
23 | + | ||
24 | + To compile this driver as a module, choose M here: the | ||
25 | + module will be called wm9705. | ||
26 | + | ||
27 | +config TOUCHSCREEN_WM9712 | ||
28 | + bool "WM9712 Touchscreen interface support" | ||
29 | + depends on TOUCHSCREEN_WM97XX | ||
30 | + help | ||
31 | + Say Y here if you have the wm9712 touchscreen. | ||
32 | + | ||
33 | + If unsure, say N. | ||
34 | + | ||
35 | + To compile this driver as a module, choose M here: the | ||
36 | + module will be called wm9712. | ||
37 | + | ||
38 | +config TOUCHSCREEN_WM9713 | ||
39 | + bool "WM9713 Touchscreen interface support" | ||
40 | + depends on TOUCHSCREEN_WM97XX | ||
41 | + help | ||
42 | + Say Y here if you have the wm9713 touchscreen. | ||
43 | + | ||
44 | + If unsure, say N. | ||
45 | + | ||
46 | + To compile this driver as a module, choose M here: the | ||
47 | + module will be called wm9713. | ||
48 | + | ||
49 | +endchoice | ||
50 | + | ||
51 | +config TOUCHSCREEN_WM97XX_PXA | ||
52 | + tristate "WM97xx PXA accelerated touch" | ||
53 | + depends on TOUCHSCREEN_WM97XX && ARCH_PXA | ||
54 | + help | ||
55 | + Say Y here for continuous mode touch on the PXA | ||
56 | + | ||
57 | + If unsure, say N | ||
58 | + | ||
59 | + To compile this driver as a module, choose M here: the | ||
60 | + module will be called pxa-wm97xx | ||
61 | + | ||
62 | endif | ||
63 | Index: linux-2.6.17/drivers/input/touchscreen/Makefile | ||
64 | =================================================================== | ||
65 | --- linux-2.6.17.orig/drivers/input/touchscreen/Makefile 2006-09-19 20:35:35.072496250 +0200 | ||
66 | +++ linux-2.6.17/drivers/input/touchscreen/Makefile 2006-09-19 20:37:40.540337500 +0200 | ||
67 | @@ -4,6 +4,8 @@ | ||
68 | |||
69 | # Each configuration option enables a list of files. | ||
70 | |||
71 | +wm97xx-ts-objs := wm97xx-core.o | ||
72 | + | ||
73 | obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o | ||
74 | obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o | ||
75 | obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o | ||
76 | @@ -13,3 +15,16 @@ obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtou | ||
77 | obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o | ||
78 | obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o | ||
79 | obj-$(CONFIG_TOUCHSCREEN_TSC2101) += tsc2101_ts.o | ||
80 | +obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o | ||
81 | +obj-$(CONFIG_TOUCHSCREEN_WM97XX_PXA) += pxa-wm97xx.o | ||
82 | + | ||
83 | +ifeq ($(CONFIG_TOUCHSCREEN_WM9713),y) | ||
84 | +wm97xx-ts-objs += wm9713.o | ||
85 | +endif | ||
86 | + | ||
87 | +ifeq ($(CONFIG_TOUCHSCREEN_WM9712),y) | ||
88 | +wm97xx-ts-objs += wm9712.o | ||
89 | +endif | ||
90 | +ifeq ($(CONFIG_TOUCHSCREEN_WM9705),y) | ||
91 | +wm97xx-ts-objs += wm9705.o | ||
92 | +endif | ||
93 | Index: linux-2.6.17/drivers/input/touchscreen/pxa-wm97xx.c | ||
94 | =================================================================== | ||
95 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
96 | +++ linux-2.6.17/drivers/input/touchscreen/pxa-wm97xx.c 2006-09-19 20:36:47.965051750 +0200 | ||
97 | @@ -0,0 +1,289 @@ | ||
98 | +/* | ||
99 | + * pxa-wm97xx.c -- pxa-wm97xx Continuous Touch screen driver for | ||
100 | + * Wolfson WM97xx AC97 Codecs. | ||
101 | + * | ||
102 | + * Copyright 2004 Wolfson Microelectronics PLC. | ||
103 | + * Author: Liam Girdwood | ||
104 | + * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com | ||
105 | + * Parts Copyright : Ian Molton <spyro@f2s.com> | ||
106 | + * Andrew Zabolotny <zap@homelink.ru> | ||
107 | + * | ||
108 | + * This program is free software; you can redistribute it and/or modify it | ||
109 | + * under the terms of the GNU General Public License as published by the | ||
110 | + * Free Software Foundation; either version 2 of the License, or (at your | ||
111 | + * option) any later version. | ||
112 | + * | ||
113 | + * Notes: | ||
114 | + * This is a wm97xx extended touch driver to capture touch | ||
115 | + * data in a continuous manner on the Intel XScale archictecture | ||
116 | + * | ||
117 | + * Features: | ||
118 | + * - codecs supported:- WM9705, WM9712, WM9713 | ||
119 | + * - processors supported:- Intel XScale PXA25x, PXA26x, PXA27x | ||
120 | + * | ||
121 | + * Revision history | ||
122 | + * 18th Aug 2004 Initial version. | ||
123 | + * 26th Jul 2005 Improved continous read back and added FIFO flushing. | ||
124 | + * 06th Sep 2005 Mike Arthur <linux@wolfsonmicro.com> | ||
125 | + * Moved to using the wm97xx bus | ||
126 | + * | ||
127 | + */ | ||
128 | + | ||
129 | +#include <linux/module.h> | ||
130 | +#include <linux/moduleparam.h> | ||
131 | +#include <linux/version.h> | ||
132 | +#include <linux/kernel.h> | ||
133 | +#include <linux/init.h> | ||
134 | +#include <linux/delay.h> | ||
135 | +#include <linux/irq.h> | ||
136 | +#include <linux/wm97xx.h> | ||
137 | +#include <asm/io.h> | ||
138 | +#include <asm/arch/pxa-regs.h> | ||
139 | + | ||
140 | +#define VERSION "0.13" | ||
141 | + | ||
142 | +struct continuous { | ||
143 | + u16 id; /* codec id */ | ||
144 | + u8 code; /* continuous code */ | ||
145 | + u8 reads; /* number of coord reads per read cycle */ | ||
146 | + u32 speed; /* number of coords per second */ | ||
147 | +}; | ||
148 | + | ||
149 | +#define WM_READS(sp) ((sp / HZ) + 1) | ||
150 | + | ||
151 | +static const struct continuous cinfo[] = { | ||
152 | + {WM9705_ID2, 0, WM_READS(94), 94}, | ||
153 | + {WM9705_ID2, 1, WM_READS(188), 188}, | ||
154 | + {WM9705_ID2, 2, WM_READS(375), 375}, | ||
155 | + {WM9705_ID2, 3, WM_READS(750), 750}, | ||
156 | + {WM9712_ID2, 0, WM_READS(94), 94}, | ||
157 | + {WM9712_ID2, 1, WM_READS(188), 188}, | ||
158 | + {WM9712_ID2, 2, WM_READS(375), 375}, | ||
159 | + {WM9712_ID2, 3, WM_READS(750), 750}, | ||
160 | + {WM9713_ID2, 0, WM_READS(94), 94}, | ||
161 | + {WM9713_ID2, 1, WM_READS(120), 120}, | ||
162 | + {WM9713_ID2, 2, WM_READS(154), 154}, | ||
163 | + {WM9713_ID2, 3, WM_READS(188), 188}, | ||
164 | +}; | ||
165 | + | ||
166 | +/* continuous speed index */ | ||
167 | +static int sp_idx = 0; | ||
168 | +static u16 last = 0, tries = 0; | ||
169 | + | ||
170 | +/* | ||
171 | + * Pen sampling frequency (Hz) in continuous mode. | ||
172 | + */ | ||
173 | +static int cont_rate = 200; | ||
174 | +module_param(cont_rate, int, 0); | ||
175 | +MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)"); | ||
176 | + | ||
177 | +/* | ||
178 | + * Pen down detection. | ||
179 | + * | ||
180 | + * This driver can either poll or use an interrupt to indicate a pen down | ||
181 | + * event. If the irq request fails then it will fall back to polling mode. | ||
182 | + */ | ||
183 | +static int pen_int = 1; | ||
184 | +module_param(pen_int, int, 0); | ||
185 | +MODULE_PARM_DESC(pen_int, "Pen down detection (1 = interrupt, 0 = polling)"); | ||
186 | + | ||
187 | +/* | ||
188 | + * Pressure readback. | ||
189 | + * | ||
190 | + * Set to 1 to read back pen down pressure | ||
191 | + */ | ||
192 | +static int pressure = 0; | ||
193 | +module_param(pressure, int, 0); | ||
194 | +MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no pressure)"); | ||
195 | + | ||
196 | +/* | ||
197 | + * AC97 touch data slot. | ||
198 | + * | ||
199 | + * Touch screen readback data ac97 slot | ||
200 | + */ | ||
201 | +static int ac97_touch_slot = 5; | ||
202 | +module_param(ac97_touch_slot, int, 0); | ||
203 | +MODULE_PARM_DESC(ac97_touch_slot, "Touch screen data slot AC97 number"); | ||
204 | + | ||
205 | + | ||
206 | +/* flush AC97 slot 5 FIFO on pxa machines */ | ||
207 | +#ifdef CONFIG_PXA27x | ||
208 | +void wm97xx_acc_pen_up (struct wm97xx* wm) | ||
209 | +{ | ||
210 | + set_current_state(TASK_INTERRUPTIBLE); | ||
211 | + schedule_timeout(1); | ||
212 | + | ||
213 | + while (MISR & (1 << 2)) | ||
214 | + MODR; | ||
215 | +} | ||
216 | +#else | ||
217 | +void wm97xx_acc_pen_up (struct wm97xx* wm) | ||
218 | +{ | ||
219 | + int count = 16; | ||
220 | + set_current_state(TASK_INTERRUPTIBLE); | ||
221 | + schedule_timeout(1); | ||
222 | + | ||
223 | + while (count < 16) { | ||
224 | + MODR; | ||
225 | + count--; | ||
226 | + } | ||
227 | +} | ||
228 | +#endif | ||
229 | + | ||
230 | +int wm97xx_acc_pen_down (struct wm97xx* wm) | ||
231 | +{ | ||
232 | + u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES; | ||
233 | + int reads = 0; | ||
234 | + | ||
235 | + /* data is never immediately available after pen down irq */ | ||
236 | + set_current_state(TASK_INTERRUPTIBLE); | ||
237 | + schedule_timeout(1); | ||
238 | + | ||
239 | + if (tries > 5){ | ||
240 | + tries = 0; | ||
241 | + return RC_PENUP; | ||
242 | + } | ||
243 | + | ||
244 | + x = MODR; | ||
245 | + if (x == last) { | ||
246 | + tries++; | ||
247 | + return RC_AGAIN; | ||
248 | + } | ||
249 | + last = x; | ||
250 | + do { | ||
251 | + if (reads) | ||
252 | + x= MODR; | ||
253 | + y= MODR; | ||
254 | + if (pressure) | ||
255 | + p = MODR; | ||
256 | + | ||
257 | + /* are samples valid */ | ||
258 | + if ((x & 0x7000) != WM97XX_ADCSEL_X || | ||
259 | + (y & 0x7000) != WM97XX_ADCSEL_Y || | ||
260 | + (p & 0x7000) != WM97XX_ADCSEL_PRES) | ||
261 | + goto up; | ||
262 | + | ||
263 | + /* coordinate is good */ | ||
264 | + tries = 0; | ||
265 | + //printk("x %x y %x p %x\n", x,y,p); | ||
266 | + input_report_abs (wm->input_dev, ABS_X, x & 0xfff); | ||
267 | + input_report_abs (wm->input_dev, ABS_Y, y & 0xfff); | ||
268 | + input_report_abs (wm->input_dev, ABS_PRESSURE, p & 0xfff); | ||
269 | + input_sync (wm->input_dev); | ||
270 | + reads++; | ||
271 | + } while (reads < cinfo[sp_idx].reads); | ||
272 | +up: | ||
273 | + return RC_PENDOWN | RC_AGAIN; | ||
274 | +} | ||
275 | + | ||
276 | +int wm97xx_acc_startup(struct wm97xx* wm) | ||
277 | +{ | ||
278 | + int idx = 0; | ||
279 | + | ||
280 | + /* check we have a codec */ | ||
281 | + if (wm->ac97 == NULL) | ||
282 | + return -ENODEV; | ||
283 | + | ||
284 | + /* Go you big red fire engine */ | ||
285 | + for (idx = 0; idx < ARRAY_SIZE(cinfo); idx++) { | ||
286 | + if (wm->id != cinfo[idx].id) | ||
287 | + continue; | ||
288 | + sp_idx = idx; | ||
289 | + if (cont_rate <= cinfo[idx].speed) | ||
290 | + break; | ||
291 | + } | ||
292 | + wm->acc_rate = cinfo[sp_idx].code; | ||
293 | + wm->acc_slot = ac97_touch_slot; | ||
294 | + printk(KERN_INFO "pxa2xx accelerated touchscreen driver, %d samples (sec)\n", | ||
295 | + cinfo[sp_idx].speed); | ||
296 | + | ||
297 | + /* codec specific irq config */ | ||
298 | + if (pen_int) { | ||
299 | + switch (wm->id) { | ||
300 | + case WM9705_ID2: | ||
301 | + wm->pen_irq = IRQ_GPIO(4); | ||
302 | + set_irq_type(IRQ_GPIO(4), IRQT_BOTHEDGE); | ||
303 | + break; | ||
304 | + case WM9712_ID2: | ||
305 | + case WM9713_ID2: | ||
306 | + /* enable pen down interrupt */ | ||
307 | + /* use PEN_DOWN GPIO 13 to assert IRQ on GPIO line 2 */ | ||
308 | + wm->pen_irq = MAINSTONE_AC97_IRQ; | ||
309 | + wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN, | ||
310 | + WM97XX_GPIO_POL_HIGH, WM97XX_GPIO_STICKY, WM97XX_GPIO_WAKE); | ||
311 | + wm97xx_config_gpio(wm, WM97XX_GPIO_2, WM97XX_GPIO_OUT, | ||
312 | + WM97XX_GPIO_POL_HIGH, WM97XX_GPIO_NOTSTICKY, WM97XX_GPIO_NOWAKE); | ||
313 | + break; | ||
314 | + default: | ||
315 | + printk(KERN_WARNING "pen down irq not supported on this device\n"); | ||
316 | + pen_int = 0; | ||
317 | + break; | ||
318 | + } | ||
319 | + } | ||
320 | + | ||
321 | + return 0; | ||
322 | +} | ||
323 | + | ||
324 | +void wm97xx_acc_shutdown(struct wm97xx* wm) | ||
325 | +{ | ||
326 | + /* codec specific deconfig */ | ||
327 | + if (pen_int) { | ||
328 | + switch (wm->id & 0xffff) { | ||
329 | + case WM9705_ID2: | ||
330 | + wm->pen_irq = 0; | ||
331 | + break; | ||
332 | + case WM9712_ID2: | ||
333 | + case WM9713_ID2: | ||
334 | + /* disable interrupt */ | ||
335 | + wm->pen_irq = 0; | ||
336 | + break; | ||
337 | + } | ||
338 | + } | ||
339 | +} | ||
340 | + | ||
341 | +static struct wm97xx_mach_ops pxa_mach_ops = { | ||
342 | + .acc_enabled = 1, | ||
343 | + .acc_pen_up = wm97xx_acc_pen_up, | ||
344 | + .acc_pen_down = wm97xx_acc_pen_down, | ||
345 | + .acc_startup = wm97xx_acc_startup, | ||
346 | + .acc_shutdown = wm97xx_acc_shutdown, | ||
347 | +}; | ||
348 | + | ||
349 | +int pxa_wm97xx_probe(struct device *dev) | ||
350 | +{ | ||
351 | + struct wm97xx *wm = dev->driver_data; | ||
352 | + return wm97xx_register_mach_ops (wm, &pxa_mach_ops); | ||
353 | +} | ||
354 | + | ||
355 | +int pxa_wm97xx_remove(struct device *dev) | ||
356 | +{ | ||
357 | + struct wm97xx *wm = dev->driver_data; | ||
358 | + wm97xx_unregister_mach_ops (wm); | ||
359 | + return 0; | ||
360 | +} | ||
361 | + | ||
362 | +static struct device_driver pxa_wm97xx_driver = { | ||
363 | + .name = "wm97xx-touchscreen", | ||
364 | + .bus = &wm97xx_bus_type, | ||
365 | + .owner = THIS_MODULE, | ||
366 | + .probe = pxa_wm97xx_probe, | ||
367 | + .remove = pxa_wm97xx_remove | ||
368 | +}; | ||
369 | + | ||
370 | +static int __init pxa_wm97xx_init(void) | ||
371 | +{ | ||
372 | + return driver_register(&pxa_wm97xx_driver); | ||
373 | +} | ||
374 | + | ||
375 | +static void __exit pxa_wm97xx_exit(void) | ||
376 | +{ | ||
377 | + driver_unregister(&pxa_wm97xx_driver); | ||
378 | +} | ||
379 | + | ||
380 | +module_init(pxa_wm97xx_init); | ||
381 | +module_exit(pxa_wm97xx_exit); | ||
382 | + | ||
383 | +/* Module information */ | ||
384 | +MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>"); | ||
385 | +MODULE_DESCRIPTION("wm97xx continuous touch driver for pxa2xx"); | ||
386 | +MODULE_LICENSE("GPL"); | ||
387 | Index: linux-2.6.17/drivers/input/touchscreen/wm9705.c | ||
388 | =================================================================== | ||
389 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
390 | +++ linux-2.6.17/drivers/input/touchscreen/wm9705.c 2006-09-19 20:36:47.969052000 +0200 | ||
391 | @@ -0,0 +1,360 @@ | ||
392 | +/* | ||
393 | + * wm9705.c -- Codec driver for Wolfson WM9705 AC97 Codec. | ||
394 | + * | ||
395 | + * Copyright 2003, 2004, 2005, 2006 Wolfson Microelectronics PLC. | ||
396 | + * Author: Liam Girdwood | ||
397 | + * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com | ||
398 | + * Parts Copyright : Ian Molton <spyro@f2s.com> | ||
399 | + * Andrew Zabolotny <zap@homelink.ru> | ||
400 | + * Russell King <rmk@arm.linux.org.uk> | ||
401 | + * | ||
402 | + * This program is free software; you can redistribute it and/or modify it | ||
403 | + * under the terms of the GNU General Public License as published by the | ||
404 | + * Free Software Foundation; either version 2 of the License, or (at your | ||
405 | + * option) any later version. | ||
406 | + * | ||
407 | + * Revision history | ||
408 | + * 6th Sep 2006 Mike Arthur <linux@wolfsonmicro.com> | ||
409 | + * Added pre and post sample calls. | ||
410 | + * | ||
411 | + */ | ||
412 | + | ||
413 | +#include <linux/module.h> | ||
414 | +#include <linux/moduleparam.h> | ||
415 | +#include <linux/version.h> | ||
416 | +#include <linux/kernel.h> | ||
417 | +#include <linux/input.h> | ||
418 | +#include <linux/delay.h> | ||
419 | +#include <linux/bitops.h> | ||
420 | +#include <linux/wm97xx.h> | ||
421 | + | ||
422 | +#define TS_NAME "wm97xx" | ||
423 | +#define WM9705_VERSION "0.62" | ||
424 | +#define DEFAULT_PRESSURE 0xb0c0 | ||
425 | + | ||
426 | +/* | ||
427 | + * Debug | ||
428 | + */ | ||
429 | +#if 0 | ||
430 | +#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg) | ||
431 | +#else | ||
432 | +#define dbg(format, arg...) | ||
433 | +#endif | ||
434 | +#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg) | ||
435 | +#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg) | ||
436 | +#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg) | ||
437 | + | ||
438 | +/* | ||
439 | + * Module parameters | ||
440 | + */ | ||
441 | + | ||
442 | +/* | ||
443 | + * Set current used for pressure measurement. | ||
444 | + * | ||
445 | + * Set pil = 2 to use 400uA | ||
446 | + * pil = 1 to use 200uA and | ||
447 | + * pil = 0 to disable pressure measurement. | ||
448 | + * | ||
449 | + * This is used to increase the range of values returned by the adc | ||
450 | + * when measureing touchpanel pressure. | ||
451 | + */ | ||
452 | +static int pil = 0; | ||
453 | +module_param(pil, int, 0); | ||
454 | +MODULE_PARM_DESC(pil, "Set current used for pressure measurement."); | ||
455 | + | ||
456 | +/* | ||
457 | + * Set threshold for pressure measurement. | ||
458 | + * | ||
459 | + * Pen down pressure below threshold is ignored. | ||
460 | + */ | ||
461 | +static int pressure = DEFAULT_PRESSURE & 0xfff; | ||
462 | +module_param(pressure, int, 0); | ||
463 | +MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement."); | ||
464 | + | ||
465 | +/* | ||
466 | + * Set adc sample delay. | ||
467 | + * | ||
468 | + * For accurate touchpanel measurements, some settling time may be | ||
469 | + * required between the switch matrix applying a voltage across the | ||
470 | + * touchpanel plate and the ADC sampling the signal. | ||
471 | + * | ||
472 | + * This delay can be set by setting delay = n, where n is the array | ||
473 | + * position of the delay in the array delay_table below. | ||
474 | + * Long delays > 1ms are supported for completeness, but are not | ||
475 | + * recommended. | ||
476 | + */ | ||
477 | +static int delay = 4; | ||
478 | +module_param(delay, int, 0); | ||
479 | +MODULE_PARM_DESC(delay, "Set adc sample delay."); | ||
480 | + | ||
481 | +/* | ||
482 | + * Pen detect comparator threshold. | ||
483 | + * | ||
484 | + * 0 to Vmid in 15 steps, 0 = use zero power comparator with Vmid threshold | ||
485 | + * i.e. 1 = Vmid/15 threshold | ||
486 | + * 15 = Vmid/1 threshold | ||
487 | + * | ||
488 | + * Adjust this value if you are having problems with pen detect not | ||
489 | + * detecting any down events. | ||
490 | + */ | ||
491 | +static int pdd = 8; | ||
492 | +module_param(pdd, int, 0); | ||
493 | +MODULE_PARM_DESC(pdd, "Set pen detect comparator threshold"); | ||
494 | + | ||
495 | +/* | ||
496 | + * Set adc mask function. | ||
497 | + * | ||
498 | + * Sources of glitch noise, such as signals driving an LCD display, may feed | ||
499 | + * through to the touch screen plates and affect measurement accuracy. In | ||
500 | + * order to minimise this, a signal may be applied to the MASK pin to delay or | ||
501 | + * synchronise the sampling. | ||
502 | + * | ||
503 | + * 0 = No delay or sync | ||
504 | + * 1 = High on pin stops conversions | ||
505 | + * 2 = Edge triggered, edge on pin delays conversion by delay param (above) | ||
506 | + * 3 = Edge triggered, edge on pin starts conversion after delay param | ||
507 | + */ | ||
508 | +static int mask = 0; | ||
509 | +module_param(mask, int, 0); | ||
510 | +MODULE_PARM_DESC(mask, "Set adc mask function."); | ||
511 | + | ||
512 | +/* | ||
513 | + * ADC sample delay times in uS | ||
514 | + */ | ||
515 | +static const int delay_table[] = { | ||
516 | + 21, // 1 AC97 Link frames | ||
517 | + 42, // 2 | ||
518 | + 84, // 4 | ||
519 | + 167, // 8 | ||
520 | + 333, // 16 | ||
521 | + 667, // 32 | ||
522 | + 1000, // 48 | ||
523 | + 1333, // 64 | ||
524 | + 2000, // 96 | ||
525 | + 2667, // 128 | ||
526 | + 3333, // 160 | ||
527 | + 4000, // 192 | ||
528 | + 4667, // 224 | ||
529 | + 5333, // 256 | ||
530 | + 6000, // 288 | ||
531 | + 0 // No delay, switch matrix always on | ||
532 | +}; | ||
533 | + | ||
534 | +/* | ||
535 | + * Delay after issuing a POLL command. | ||
536 | + * | ||
537 | + * The delay is 3 AC97 link frames + the touchpanel settling delay | ||
538 | + */ | ||
539 | +static inline void poll_delay(int d) | ||
540 | +{ | ||
541 | + udelay (3 * AC97_LINK_FRAME + delay_table [d]); | ||
542 | +} | ||
543 | + | ||
544 | +/* | ||
545 | + * set up the physical settings of the WM9705 | ||
546 | + */ | ||
547 | +static void init_wm9705_phy(struct wm97xx* wm) | ||
548 | +{ | ||
549 | + u16 dig1 = 0, dig2 = WM97XX_RPR; | ||
550 | + | ||
551 | + /* | ||
552 | + * mute VIDEO and AUX as they share X and Y touchscreen | ||
553 | + * inputs on the WM9705 | ||
554 | + */ | ||
555 | + wm97xx_reg_write(wm, AC97_AUX, 0x8000); | ||
556 | + wm97xx_reg_write(wm, AC97_VIDEO, 0x8000); | ||
557 | + | ||
558 | + /* touchpanel pressure current*/ | ||
559 | + if (pil == 2) { | ||
560 | + dig2 |= WM9705_PIL; | ||
561 | + dbg("setting pressure measurement current to 400uA."); | ||
562 | + } else if (pil) | ||
563 | + dbg("setting pressure measurement current to 200uA."); | ||
564 | + if(!pil) | ||
565 | + pressure = 0; | ||
566 | + | ||
567 | + /* polling mode sample settling delay */ | ||
568 | + if (delay!=4) { | ||
569 | + if (delay < 0 || delay > 15) { | ||
570 | + dbg("supplied delay out of range."); | ||
571 | + delay = 4; | ||
572 | + } | ||
573 | + } | ||
574 | + dig1 &= 0xff0f; | ||
575 | + dig1 |= WM97XX_DELAY(delay); | ||
576 | + dbg("setting adc sample delay to %d u Secs.", delay_table[delay]); | ||
577 | + | ||
578 | + /* WM9705 pdd */ | ||
579 | + dig2 |= (pdd & 0x000f); | ||
580 | + dbg("setting pdd to Vmid/%d", 1 - (pdd & 0x000f)); | ||
581 | + | ||
582 | + /* mask */ | ||
583 | + dig2 |= ((mask & 0x3) << 4); | ||
584 | + | ||
585 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1); | ||
586 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2); | ||
587 | +} | ||
588 | + | ||
589 | +static int wm9705_digitiser_ioctl(struct wm97xx* wm, int cmd) | ||
590 | +{ | ||
591 | + switch(cmd) { | ||
592 | + case WM97XX_DIG_START: | ||
593 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig[2] | WM97XX_PRP_DET_DIG); | ||
594 | + wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */ | ||
595 | + break; | ||
596 | + case WM97XX_DIG_STOP: | ||
597 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig[2] & ~WM97XX_PRP_DET_DIG); | ||
598 | + break; | ||
599 | + case WM97XX_AUX_PREPARE: | ||
600 | + memcpy(wm->dig_save, wm->dig, sizeof(wm->dig)); | ||
601 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, 0); | ||
602 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, WM97XX_PRP_DET_DIG); | ||
603 | + break; | ||
604 | + case WM97XX_DIG_RESTORE: | ||
605 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, wm->dig_save[1]); | ||
606 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig_save[2]); | ||
607 | + break; | ||
608 | + case WM97XX_PHY_INIT: | ||
609 | + init_wm9705_phy(wm); | ||
610 | + break; | ||
611 | + default: | ||
612 | + return -EINVAL; | ||
613 | + } | ||
614 | + return 0; | ||
615 | +} | ||
616 | + | ||
617 | +static inline int is_pden (struct wm97xx* wm) | ||
618 | +{ | ||
619 | + return wm->dig[2] & WM9705_PDEN; | ||
620 | +} | ||
621 | + | ||
622 | +/* | ||
623 | + * Read a sample from the WM9705 adc in polling mode. | ||
624 | + */ | ||
625 | +static int wm9705_poll_sample (struct wm97xx* wm, int adcsel, int *sample) | ||
626 | +{ | ||
627 | + int timeout = 5 * delay; | ||
628 | + | ||
629 | + if (!wm->pen_probably_down) { | ||
630 | + u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
631 | + if (!(data & WM97XX_PEN_DOWN)) | ||
632 | + return RC_PENUP; | ||
633 | + wm->pen_probably_down = 1; | ||
634 | + } | ||
635 | + | ||
636 | + /* set up digitiser */ | ||
637 | + if (adcsel & 0x8000) | ||
638 | + adcsel = ((adcsel & 0x7fff) + 3) << 12; | ||
639 | + | ||
640 | + if (wm->mach_ops && wm->mach_ops->pre_sample) | ||
641 | + wm->mach_ops->pre_sample(adcsel); | ||
642 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, adcsel | WM97XX_POLL | WM97XX_DELAY(delay)); | ||
643 | + | ||
644 | + /* wait 3 AC97 time slots + delay for conversion */ | ||
645 | + poll_delay (delay); | ||
646 | + | ||
647 | + /* wait for POLL to go low */ | ||
648 | + while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL) && timeout) { | ||
649 | + udelay(AC97_LINK_FRAME); | ||
650 | + timeout--; | ||
651 | + } | ||
652 | + | ||
653 | + if (timeout <= 0) { | ||
654 | + /* If PDEN is set, we can get a timeout when pen goes up */ | ||
655 | + if (is_pden(wm)) | ||
656 | + wm->pen_probably_down = 0; | ||
657 | + else | ||
658 | + dbg ("adc sample timeout"); | ||
659 | + return RC_PENUP; | ||
660 | + } | ||
661 | + | ||
662 | + *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
663 | + if (wm->mach_ops && wm->mach_ops->post_sample) | ||
664 | + wm->mach_ops->post_sample(adcsel); | ||
665 | + | ||
666 | + /* check we have correct sample */ | ||
667 | + if ((*sample & WM97XX_ADCSEL_MASK) != adcsel) { | ||
668 | + dbg ("adc wrong sample, read %x got %x", adcsel, | ||
669 | + *sample & WM97XX_ADCSEL_MASK); | ||
670 | + return RC_PENUP; | ||
671 | + } | ||
672 | + | ||
673 | + if (!(*sample & WM97XX_PEN_DOWN)) { | ||
674 | + wm->pen_probably_down = 0; | ||
675 | + return RC_PENUP; | ||
676 | + } | ||
677 | + | ||
678 | + return RC_VALID; | ||
679 | +} | ||
680 | + | ||
681 | +/* | ||
682 | + * Sample the WM9705 touchscreen in polling mode | ||
683 | + */ | ||
684 | +static int wm9705_poll_touch(struct wm97xx* wm, struct wm97xx_data *data) | ||
685 | +{ | ||
686 | + int rc; | ||
687 | + | ||
688 | + if ((rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_X, &data->x)) != RC_VALID) | ||
689 | + return rc; | ||
690 | + if ((rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_Y, &data->y)) != RC_VALID) | ||
691 | + return rc; | ||
692 | + if (pil) { | ||
693 | + if ((rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_PRES, &data->p)) != RC_VALID) | ||
694 | + return rc; | ||
695 | + } else | ||
696 | + data->p = DEFAULT_PRESSURE; | ||
697 | + | ||
698 | + return RC_VALID; | ||
699 | +} | ||
700 | + | ||
701 | +/* | ||
702 | + * Enable WM9705 continuous mode, i.e. touch data is streamed across an AC97 slot | ||
703 | + */ | ||
704 | +static int wm9705_acc_enable (struct wm97xx* wm, int enable) | ||
705 | +{ | ||
706 | + u16 dig1, dig2; | ||
707 | + int ret = 0; | ||
708 | + | ||
709 | + dig1 = wm->dig[1]; | ||
710 | + dig2 = wm->dig[2]; | ||
711 | + | ||
712 | + if (enable) { | ||
713 | + /* continous mode */ | ||
714 | + if (wm->mach_ops->acc_startup && (ret = wm->mach_ops->acc_startup(wm)) < 0) | ||
715 | + return ret; | ||
716 | + dig1 &= ~(WM97XX_CM_RATE_MASK | WM97XX_ADCSEL_MASK | | ||
717 | + WM97XX_DELAY_MASK | WM97XX_SLT_MASK); | ||
718 | + dig1 |= WM97XX_CTC | WM97XX_COO | WM97XX_SLEN | | ||
719 | + WM97XX_DELAY (delay) | | ||
720 | + WM97XX_SLT (wm->acc_slot) | | ||
721 | + WM97XX_RATE (wm->acc_rate); | ||
722 | + if (pil) | ||
723 | + dig1 |= WM97XX_ADCSEL_PRES; | ||
724 | + dig2 |= WM9705_PDEN; | ||
725 | + } else { | ||
726 | + dig1 &= ~(WM97XX_CTC | WM97XX_COO | WM97XX_SLEN); | ||
727 | + dig2 &= ~WM9705_PDEN; | ||
728 | + if (wm->mach_ops->acc_shutdown) | ||
729 | + wm->mach_ops->acc_shutdown(wm); | ||
730 | + } | ||
731 | + | ||
732 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1); | ||
733 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2); | ||
734 | + return ret; | ||
735 | +} | ||
736 | + | ||
737 | +struct wm97xx_codec_drv wm97xx_codec = { | ||
738 | + .id = WM9705_ID2, | ||
739 | + .name = "wm9705", | ||
740 | + .poll_sample = wm9705_poll_sample, | ||
741 | + .poll_touch = wm9705_poll_touch, | ||
742 | + .acc_enable = wm9705_acc_enable, | ||
743 | + .digitiser_ioctl = wm9705_digitiser_ioctl, | ||
744 | +}; | ||
745 | + | ||
746 | +EXPORT_SYMBOL_GPL(wm97xx_codec); | ||
747 | + | ||
748 | +/* Module information */ | ||
749 | +MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com"); | ||
750 | +MODULE_DESCRIPTION("WM9705 Touch Screen Driver"); | ||
751 | +MODULE_LICENSE("GPL"); | ||
752 | Index: linux-2.6.17/drivers/input/touchscreen/wm9712.c | ||
753 | =================================================================== | ||
754 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
755 | +++ linux-2.6.17/drivers/input/touchscreen/wm9712.c 2006-09-19 20:36:47.969052000 +0200 | ||
756 | @@ -0,0 +1,464 @@ | ||
757 | +/* | ||
758 | + * wm9712.c -- Codec driver for Wolfson WM9712 AC97 Codecs. | ||
759 | + * | ||
760 | + * Copyright 2003, 2004, 2005, 2006 Wolfson Microelectronics PLC. | ||
761 | + * Author: Liam Girdwood | ||
762 | + * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com | ||
763 | + * Parts Copyright : Ian Molton <spyro@f2s.com> | ||
764 | + * Andrew Zabolotny <zap@homelink.ru> | ||
765 | + * Russell King <rmk@arm.linux.org.uk> | ||
766 | + * | ||
767 | + * This program is free software; you can redistribute it and/or modify it | ||
768 | + * under the terms of the GNU General Public License as published by the | ||
769 | + * Free Software Foundation; either version 2 of the License, or (at your | ||
770 | + * option) any later version. | ||
771 | + * | ||
772 | + * Revision history | ||
773 | + * 4th Jul 2005 Initial version. | ||
774 | + * 6th Sep 2006 Mike Arthur <linux@wolfsonmicro.com> | ||
775 | + * Added pre and post sample calls. | ||
776 | + * | ||
777 | + */ | ||
778 | + | ||
779 | +#include <linux/module.h> | ||
780 | +#include <linux/moduleparam.h> | ||
781 | +#include <linux/version.h> | ||
782 | +#include <linux/kernel.h> | ||
783 | +#include <linux/input.h> | ||
784 | +#include <linux/delay.h> | ||
785 | +#include <linux/bitops.h> | ||
786 | +#include <linux/wm97xx.h> | ||
787 | + | ||
788 | +#define TS_NAME "wm97xx" | ||
789 | +#define WM9712_VERSION "0.61" | ||
790 | +#define DEFAULT_PRESSURE 0xb0c0 | ||
791 | + | ||
792 | +/* | ||
793 | + * Debug | ||
794 | + */ | ||
795 | +#if 0 | ||
796 | +#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg) | ||
797 | +#else | ||
798 | +#define dbg(format, arg...) | ||
799 | +#endif | ||
800 | +#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg) | ||
801 | +#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg) | ||
802 | +#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg) | ||
803 | + | ||
804 | +/* | ||
805 | + * Module parameters | ||
806 | + */ | ||
807 | + | ||
808 | +/* | ||
809 | + * Set internal pull up for pen detect. | ||
810 | + * | ||
811 | + * Pull up is in the range 1.02k (least sensitive) to 64k (most sensitive) | ||
812 | + * i.e. pull up resistance = 64k Ohms / rpu. | ||
813 | + * | ||
814 | + * Adjust this value if you are having problems with pen detect not | ||
815 | + * detecting any down event. | ||
816 | + */ | ||
817 | +static int rpu = 3; | ||
818 | +module_param(rpu, int, 0); | ||
819 | +MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect."); | ||
820 | + | ||
821 | +/* | ||
822 | + * Set current used for pressure measurement. | ||
823 | + * | ||
824 | + * Set pil = 2 to use 400uA | ||
825 | + * pil = 1 to use 200uA and | ||
826 | + * pil = 0 to disable pressure measurement. | ||
827 | + * | ||
828 | + * This is used to increase the range of values returned by the adc | ||
829 | + * when measureing touchpanel pressure. | ||
830 | + */ | ||
831 | +static int pil = 0; | ||
832 | +module_param(pil, int, 0); | ||
833 | +MODULE_PARM_DESC(pil, "Set current used for pressure measurement."); | ||
834 | + | ||
835 | +/* | ||
836 | + * Set threshold for pressure measurement. | ||
837 | + * | ||
838 | + * Pen down pressure below threshold is ignored. | ||
839 | + */ | ||
840 | +static int pressure = DEFAULT_PRESSURE & 0xfff; | ||
841 | +module_param(pressure, int, 0); | ||
842 | +MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement."); | ||
843 | + | ||
844 | +/* | ||
845 | + * Set adc sample delay. | ||
846 | + * | ||
847 | + * For accurate touchpanel measurements, some settling time may be | ||
848 | + * required between the switch matrix applying a voltage across the | ||
849 | + * touchpanel plate and the ADC sampling the signal. | ||
850 | + * | ||
851 | + * This delay can be set by setting delay = n, where n is the array | ||
852 | + * position of the delay in the array delay_table below. | ||
853 | + * Long delays > 1ms are supported for completeness, but are not | ||
854 | + * recommended. | ||
855 | + */ | ||
856 | +static int delay = 3; | ||
857 | +module_param(delay, int, 0); | ||
858 | +MODULE_PARM_DESC(delay, "Set adc sample delay."); | ||
859 | + | ||
860 | +/* | ||
861 | + * Set five_wire = 1 to use a 5 wire touchscreen. | ||
862 | + * | ||
863 | + * NOTE: Five wire mode does not allow for readback of pressure. | ||
864 | + */ | ||
865 | +static int five_wire; | ||
866 | +module_param(five_wire, int, 0); | ||
867 | +MODULE_PARM_DESC(five_wire, "Set to '1' to use 5-wire touchscreen."); | ||
868 | + | ||
869 | +/* | ||
870 | + * Set adc mask function. | ||
871 | + * | ||
872 | + * Sources of glitch noise, such as signals driving an LCD display, may feed | ||
873 | + * through to the touch screen plates and affect measurement accuracy. In | ||
874 | + * order to minimise this, a signal may be applied to the MASK pin to delay or | ||
875 | + * synchronise the sampling. | ||
876 | + * | ||
877 | + * 0 = No delay or sync | ||
878 | + * 1 = High on pin stops conversions | ||
879 | + * 2 = Edge triggered, edge on pin delays conversion by delay param (above) | ||
880 | + * 3 = Edge triggered, edge on pin starts conversion after delay param | ||
881 | + */ | ||
882 | +static int mask = 0; | ||
883 | +module_param(mask, int, 0); | ||
884 | +MODULE_PARM_DESC(mask, "Set adc mask function."); | ||
885 | + | ||
886 | +/* | ||
887 | + * Coordinate Polling Enable. | ||
888 | + * | ||
889 | + * Set to 1 to enable coordinate polling. e.g. x,y[,p] is sampled together | ||
890 | + * for every poll. | ||
891 | + */ | ||
892 | +static int coord = 0; | ||
893 | +module_param(coord, int, 0); | ||
894 | +MODULE_PARM_DESC(coord, "Polling coordinate mode"); | ||
895 | + | ||
896 | +/* | ||
897 | + * ADC sample delay times in uS | ||
898 | + */ | ||
899 | +static const int delay_table[] = { | ||
900 | + 21, // 1 AC97 Link frames | ||
901 | + 42, // 2 | ||
902 | + 84, // 4 | ||
903 | + 167, // 8 | ||
904 | + 333, // 16 | ||
905 | + 667, // 32 | ||
906 | + 1000, // 48 | ||
907 | + 1333, // 64 | ||
908 | + 2000, // 96 | ||
909 | + 2667, // 128 | ||
910 | + 3333, // 160 | ||
911 | + 4000, // 192 | ||
912 | + 4667, // 224 | ||
913 | + 5333, // 256 | ||
914 | + 6000, // 288 | ||
915 | + 0 // No delay, switch matrix always on | ||
916 | +}; | ||
917 | + | ||
918 | +/* | ||
919 | + * Delay after issuing a POLL command. | ||
920 | + * | ||
921 | + * The delay is 3 AC97 link frames + the touchpanel settling delay | ||
922 | + */ | ||
923 | +static inline void poll_delay(int d) | ||
924 | +{ | ||
925 | + udelay (3 * AC97_LINK_FRAME + delay_table [d]); | ||
926 | +} | ||
927 | + | ||
928 | +/* | ||
929 | + * set up the physical settings of the WM9712 | ||
930 | + */ | ||
931 | +static void init_wm9712_phy(struct wm97xx* wm) | ||
932 | +{ | ||
933 | + u16 dig1 = 0; | ||
934 | + u16 dig2 = WM97XX_RPR | WM9712_RPU(1); | ||
935 | + | ||
936 | + /* WM9712 rpu */ | ||
937 | + if (rpu) { | ||
938 | + dig2 &= 0xffc0; | ||
939 | + dig2 |= WM9712_RPU(rpu); | ||
940 | + dbg("setting pen detect pull-up to %d Ohms",64000 / rpu); | ||
941 | + } | ||
942 | + | ||
943 | + /* touchpanel pressure current*/ | ||
944 | + if (pil == 2) { | ||
945 | + dig2 |= WM9712_PIL; | ||
946 | + dbg("setting pressure measurement current to 400uA."); | ||
947 | + } else if (pil) | ||
948 | + dbg("setting pressure measurement current to 200uA."); | ||
949 | + if(!pil) | ||
950 | + pressure = 0; | ||
951 | + | ||
952 | + /* WM9712 five wire */ | ||
953 | + if (five_wire) { | ||
954 | + dig2 |= WM9712_45W; | ||
955 | + dbg("setting 5-wire touchscreen mode."); | ||
956 | + } | ||
957 | + | ||
958 | + /* polling mode sample settling delay */ | ||
959 | + if (delay < 0 || delay > 15) { | ||
960 | + dbg("supplied delay out of range."); | ||
961 | + delay = 4; | ||
962 | + } | ||
963 | + dig1 &= 0xff0f; | ||
964 | + dig1 |= WM97XX_DELAY(delay); | ||
965 | + dbg("setting adc sample delay to %d u Secs.", delay_table[delay]); | ||
966 | + | ||
967 | + /* mask */ | ||
968 | + dig2 |= ((mask & 0x3) << 6); | ||
969 | + if (mask) { | ||
970 | + u16 reg; | ||
971 | + /* Set GPIO4 as Mask Pin*/ | ||
972 | + reg = wm97xx_reg_read(wm, AC97_MISC_AFE); | ||
973 | + wm97xx_reg_write(wm, AC97_MISC_AFE, reg | WM97XX_GPIO_4); | ||
974 | + reg = wm97xx_reg_read(wm, AC97_GPIO_CFG); | ||
975 | + wm97xx_reg_write(wm, AC97_GPIO_CFG, reg | WM97XX_GPIO_4); | ||
976 | + } | ||
977 | + | ||
978 | + /* wait - coord mode */ | ||
979 | + if(coord) | ||
980 | + dig2 |= WM9712_WAIT; | ||
981 | + | ||
982 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1); | ||
983 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2); | ||
984 | +} | ||
985 | + | ||
986 | +static int wm9712_digitiser_ioctl(struct wm97xx* wm, int cmd) | ||
987 | +{ | ||
988 | + u16 dig2 = wm->dig[2]; | ||
989 | + | ||
990 | + switch(cmd) { | ||
991 | + case WM97XX_DIG_START: | ||
992 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2 | WM97XX_PRP_DET_DIG); | ||
993 | + wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */ | ||
994 | + break; | ||
995 | + case WM97XX_DIG_STOP: | ||
996 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2 & ~WM97XX_PRP_DET_DIG); | ||
997 | + break; | ||
998 | + case WM97XX_AUX_PREPARE: | ||
999 | + memcpy(wm->dig_save, wm->dig, sizeof(wm->dig)); | ||
1000 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, 0); | ||
1001 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, WM97XX_PRP_DET_DIG); | ||
1002 | + break; | ||
1003 | + case WM97XX_DIG_RESTORE: | ||
1004 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, wm->dig_save[1]); | ||
1005 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig_save[2]); | ||
1006 | + break; | ||
1007 | + case WM97XX_PHY_INIT: | ||
1008 | + init_wm9712_phy(wm); | ||
1009 | + break; | ||
1010 | + default: | ||
1011 | + return -EINVAL; | ||
1012 | + } | ||
1013 | + return 0; | ||
1014 | +} | ||
1015 | + | ||
1016 | +static inline int is_pden (struct wm97xx* wm) | ||
1017 | +{ | ||
1018 | + return wm->dig[2] & WM9712_PDEN; | ||
1019 | +} | ||
1020 | + | ||
1021 | +/* | ||
1022 | + * Read a sample from the WM9712 adc in polling mode. | ||
1023 | + */ | ||
1024 | +static int wm9712_poll_sample (struct wm97xx* wm, int adcsel, int *sample) | ||
1025 | +{ | ||
1026 | + int timeout = 5 * delay; | ||
1027 | + | ||
1028 | + if (!wm->pen_probably_down) { | ||
1029 | + u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
1030 | + if (!(data & WM97XX_PEN_DOWN)) | ||
1031 | + return RC_PENUP; | ||
1032 | + wm->pen_probably_down = 1; | ||
1033 | + } | ||
1034 | + | ||
1035 | + /* set up digitiser */ | ||
1036 | + if (adcsel & 0x8000) | ||
1037 | + adcsel = ((adcsel & 0x7fff) + 3) << 12; | ||
1038 | + | ||
1039 | + if (wm->mach_ops && wm->mach_ops->pre_sample) | ||
1040 | + wm->mach_ops->pre_sample(adcsel); | ||
1041 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, adcsel | WM97XX_POLL | WM97XX_DELAY(delay)); | ||
1042 | + | ||
1043 | + /* wait 3 AC97 time slots + delay for conversion */ | ||
1044 | + poll_delay (delay); | ||
1045 | + | ||
1046 | + /* wait for POLL to go low */ | ||
1047 | + while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL) && timeout) { | ||
1048 | + udelay(AC97_LINK_FRAME); | ||
1049 | + timeout--; | ||
1050 | + } | ||
1051 | + | ||
1052 | + if (timeout <= 0) { | ||
1053 | + /* If PDEN is set, we can get a timeout when pen goes up */ | ||
1054 | + if (is_pden(wm)) | ||
1055 | + wm->pen_probably_down = 0; | ||
1056 | + else | ||
1057 | + dbg ("adc sample timeout"); | ||
1058 | + return RC_PENUP; | ||
1059 | + } | ||
1060 | + | ||
1061 | + *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
1062 | + if (wm->mach_ops && wm->mach_ops->post_sample) | ||
1063 | + wm->mach_ops->post_sample(adcsel); | ||
1064 | + | ||
1065 | + /* check we have correct sample */ | ||
1066 | + if ((*sample & WM97XX_ADCSEL_MASK) != adcsel) { | ||
1067 | + dbg ("adc wrong sample, read %x got %x", adcsel, | ||
1068 | + *sample & WM97XX_ADCSEL_MASK); | ||
1069 | + return RC_PENUP; | ||
1070 | + } | ||
1071 | + | ||
1072 | + if (!(*sample & WM97XX_PEN_DOWN)) { | ||
1073 | + wm->pen_probably_down = 0; | ||
1074 | + return RC_PENUP; | ||
1075 | + } | ||
1076 | + | ||
1077 | + return RC_VALID; | ||
1078 | +} | ||
1079 | + | ||
1080 | +/* | ||
1081 | + * Read a coord from the WM9712 adc in polling mode. | ||
1082 | + */ | ||
1083 | +static int wm9712_poll_coord (struct wm97xx* wm, struct wm97xx_data *data) | ||
1084 | +{ | ||
1085 | + int timeout = 5 * delay; | ||
1086 | + | ||
1087 | + if (!wm->pen_probably_down) { | ||
1088 | + u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
1089 | + if (!(data & WM97XX_PEN_DOWN)) | ||
1090 | + return RC_PENUP; | ||
1091 | + wm->pen_probably_down = 1; | ||
1092 | + } | ||
1093 | + | ||
1094 | + /* set up digitiser */ | ||
1095 | + if (wm->mach_ops && wm->mach_ops->pre_sample) | ||
1096 | + wm->mach_ops->pre_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y); | ||
1097 | + | ||
1098 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, | ||
1099 | + WM97XX_COO | WM97XX_POLL | WM97XX_DELAY(delay)); | ||
1100 | + | ||
1101 | + /* wait 3 AC97 time slots + delay for conversion and read x */ | ||
1102 | + poll_delay(delay); | ||
1103 | + data->x = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
1104 | + /* wait for POLL to go low */ | ||
1105 | + while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL) && timeout) { | ||
1106 | + udelay(AC97_LINK_FRAME); | ||
1107 | + timeout--; | ||
1108 | + } | ||
1109 | + | ||
1110 | + if (timeout <= 0) { | ||
1111 | + /* If PDEN is set, we can get a timeout when pen goes up */ | ||
1112 | + if (is_pden(wm)) | ||
1113 | + wm->pen_probably_down = 0; | ||
1114 | + else | ||
1115 | + dbg ("adc sample timeout"); | ||
1116 | + return RC_PENUP; | ||
1117 | + } | ||
1118 | + | ||
1119 | + /* read back y data */ | ||
1120 | + data->y = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
1121 | + if (pil) | ||
1122 | + data->p = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
1123 | + else | ||
1124 | + data->p = DEFAULT_PRESSURE; | ||
1125 | + | ||
1126 | + if (wm->mach_ops && wm->mach_ops->post_sample) | ||
1127 | + wm->mach_ops->post_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y); | ||
1128 | + | ||
1129 | + /* check we have correct sample */ | ||
1130 | + if (!(data->x & WM97XX_ADCSEL_X) || !(data->y & WM97XX_ADCSEL_Y)) | ||
1131 | + goto err; | ||
1132 | + if(pil && !(data->p & WM97XX_ADCSEL_PRES)) | ||
1133 | + goto err; | ||
1134 | + | ||
1135 | + if (!(data->x & WM97XX_PEN_DOWN)) { | ||
1136 | + wm->pen_probably_down = 0; | ||
1137 | + return RC_PENUP; | ||
1138 | + } | ||
1139 | + return RC_VALID; | ||
1140 | +err: | ||
1141 | + return RC_PENUP; | ||
1142 | +} | ||
1143 | + | ||
1144 | +/* | ||
1145 | + * Sample the WM9712 touchscreen in polling mode | ||
1146 | + */ | ||
1147 | +static int wm9712_poll_touch(struct wm97xx* wm, struct wm97xx_data *data) | ||
1148 | +{ | ||
1149 | + int rc; | ||
1150 | + | ||
1151 | + if(coord) { | ||
1152 | + if((rc = wm9712_poll_coord(wm, data)) != RC_VALID) | ||
1153 | + return rc; | ||
1154 | + } else { | ||
1155 | + if ((rc = wm9712_poll_sample(wm, WM97XX_ADCSEL_X, &data->x)) != RC_VALID) | ||
1156 | + return rc; | ||
1157 | + | ||
1158 | + if ((rc = wm9712_poll_sample(wm, WM97XX_ADCSEL_Y, &data->y)) != RC_VALID) | ||
1159 | + return rc; | ||
1160 | + | ||
1161 | + if (pil && !five_wire) { | ||
1162 | + if ((rc = wm9712_poll_sample(wm, WM97XX_ADCSEL_PRES, &data->p)) != RC_VALID) | ||
1163 | + return rc; | ||
1164 | + } else | ||
1165 | + data->p = DEFAULT_PRESSURE; | ||
1166 | + } | ||
1167 | + return RC_VALID; | ||
1168 | +} | ||
1169 | + | ||
1170 | +/* | ||
1171 | + * Enable WM9712 continuous mode, i.e. touch data is streamed across an AC97 slot | ||
1172 | + */ | ||
1173 | +static int wm9712_acc_enable (struct wm97xx* wm, int enable) | ||
1174 | +{ | ||
1175 | + u16 dig1, dig2; | ||
1176 | + int ret = 0; | ||
1177 | + | ||
1178 | + dig1 = wm->dig[1]; | ||
1179 | + dig2 = wm->dig[2]; | ||
1180 | + | ||
1181 | + if (enable) { | ||
1182 | + /* continous mode */ | ||
1183 | + if (wm->mach_ops->acc_startup && (ret = wm->mach_ops->acc_startup(wm)) < 0) | ||
1184 | + return ret; | ||
1185 | + dig1 &= ~(WM97XX_CM_RATE_MASK | WM97XX_ADCSEL_MASK | | ||
1186 | + WM97XX_DELAY_MASK | WM97XX_SLT_MASK); | ||
1187 | + dig1 |= WM97XX_CTC | WM97XX_COO | WM97XX_SLEN | | ||
1188 | + WM97XX_DELAY (delay) | | ||
1189 | + WM97XX_SLT (wm->acc_slot) | | ||
1190 | + WM97XX_RATE (wm->acc_rate); | ||
1191 | + if (pil) | ||
1192 | + dig1 |= WM97XX_ADCSEL_PRES; | ||
1193 | + dig2 |= WM9712_PDEN; | ||
1194 | + } else { | ||
1195 | + dig1 &= ~(WM97XX_CTC | WM97XX_COO | WM97XX_SLEN); | ||
1196 | + dig2 &= ~WM9712_PDEN; | ||
1197 | + if (wm->mach_ops->acc_shutdown) | ||
1198 | + wm->mach_ops->acc_shutdown(wm); | ||
1199 | + } | ||
1200 | + | ||
1201 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1); | ||
1202 | + wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2); | ||
1203 | + return 0; | ||
1204 | +} | ||
1205 | + | ||
1206 | +struct wm97xx_codec_drv wm97xx_codec = { | ||
1207 | + .id = WM9712_ID2, | ||
1208 | + .name = "wm9712", | ||
1209 | + .poll_sample = wm9712_poll_sample, | ||
1210 | + .poll_touch = wm9712_poll_touch, | ||
1211 | + .acc_enable = wm9712_acc_enable, | ||
1212 | + .digitiser_ioctl = wm9712_digitiser_ioctl, | ||
1213 | +}; | ||
1214 | + | ||
1215 | +EXPORT_SYMBOL_GPL(wm97xx_codec); | ||
1216 | + | ||
1217 | +/* Module information */ | ||
1218 | +MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com"); | ||
1219 | +MODULE_DESCRIPTION("WM9712 Touch Screen Driver"); | ||
1220 | +MODULE_LICENSE("GPL"); | ||
1221 | Index: linux-2.6.17/drivers/input/touchscreen/wm9713.c | ||
1222 | =================================================================== | ||
1223 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
1224 | +++ linux-2.6.17/drivers/input/touchscreen/wm9713.c 2006-09-19 20:36:47.969052000 +0200 | ||
1225 | @@ -0,0 +1,461 @@ | ||
1226 | +/* | ||
1227 | + * wm9713.c -- Codec touch driver for Wolfson WM9713 AC97 Codec. | ||
1228 | + * | ||
1229 | + * Copyright 2003, 2004, 2005, 2006 Wolfson Microelectronics PLC. | ||
1230 | + * Author: Liam Girdwood | ||
1231 | + * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com | ||
1232 | + * Parts Copyright : Ian Molton <spyro@f2s.com> | ||
1233 | + * Andrew Zabolotny <zap@homelink.ru> | ||
1234 | + * Russell King <rmk@arm.linux.org.uk> | ||
1235 | + * | ||
1236 | + * This program is free software; you can redistribute it and/or modify it | ||
1237 | + * under the terms of the GNU General Public License as published by the | ||
1238 | + * Free Software Foundation; either version 2 of the License, or (at your | ||
1239 | + * option) any later version. | ||
1240 | + * | ||
1241 | + * Revision history | ||
1242 | + * 6th Sep 2006 Mike Arthur <linux@wolfsonmicro.com> | ||
1243 | + * Added pre and post sample calls. | ||
1244 | + * | ||
1245 | + */ | ||
1246 | + | ||
1247 | +#include <linux/module.h> | ||
1248 | +#include <linux/moduleparam.h> | ||
1249 | +#include <linux/version.h> | ||
1250 | +#include <linux/kernel.h> | ||
1251 | +#include <linux/input.h> | ||
1252 | +#include <linux/delay.h> | ||
1253 | +#include <linux/bitops.h> | ||
1254 | +#include <linux/wm97xx.h> | ||
1255 | + | ||
1256 | +#define TS_NAME "wm97xx" | ||
1257 | +#define WM9713_VERSION "0.53" | ||
1258 | +#define DEFAULT_PRESSURE 0xb0c0 | ||
1259 | + | ||
1260 | +/* | ||
1261 | + * Debug | ||
1262 | + */ | ||
1263 | +#if 0 | ||
1264 | +#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg) | ||
1265 | +#else | ||
1266 | +#define dbg(format, arg...) | ||
1267 | +#endif | ||
1268 | +#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg) | ||
1269 | +#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg) | ||
1270 | +#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg) | ||
1271 | + | ||
1272 | +/* | ||
1273 | + * Module parameters | ||
1274 | + */ | ||
1275 | + | ||
1276 | +/* | ||
1277 | + * Set internal pull up for pen detect. | ||
1278 | + * | ||
1279 | + * Pull up is in the range 1.02k (least sensitive) to 64k (most sensitive) | ||
1280 | + * i.e. pull up resistance = 64k Ohms / rpu. | ||
1281 | + * | ||
1282 | + * Adjust this value if you are having problems with pen detect not | ||
1283 | + * detecting any down event. | ||
1284 | + */ | ||
1285 | +static int rpu = 1; | ||
1286 | +module_param(rpu, int, 0); | ||
1287 | +MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect."); | ||
1288 | + | ||
1289 | +/* | ||
1290 | + * Set current used for pressure measurement. | ||
1291 | + * | ||
1292 | + * Set pil = 2 to use 400uA | ||
1293 | + * pil = 1 to use 200uA and | ||
1294 | + * pil = 0 to disable pressure measurement. | ||
1295 | + * | ||
1296 | + * This is used to increase the range of values returned by the adc | ||
1297 | + * when measureing touchpanel pressure. | ||
1298 | + */ | ||
1299 | +static int pil = 0; | ||
1300 | +module_param(pil, int, 0); | ||
1301 | +MODULE_PARM_DESC(pil, "Set current used for pressure measurement."); | ||
1302 | + | ||
1303 | +/* | ||
1304 | + * Set threshold for pressure measurement. | ||
1305 | + * | ||
1306 | + * Pen down pressure below threshold is ignored. | ||
1307 | + */ | ||
1308 | +static int pressure = DEFAULT_PRESSURE & 0xfff; | ||
1309 | +module_param(pressure, int, 0); | ||
1310 | +MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement."); | ||
1311 | + | ||
1312 | +/* | ||
1313 | + * Set adc sample delay. | ||
1314 | + * | ||
1315 | + * For accurate touchpanel measurements, some settling time may be | ||
1316 | + * required between the switch matrix applying a voltage across the | ||
1317 | + * touchpanel plate and the ADC sampling the signal. | ||
1318 | + * | ||
1319 | + * This delay can be set by setting delay = n, where n is the array | ||
1320 | + * position of the delay in the array delay_table below. | ||
1321 | + * Long delays > 1ms are supported for completeness, but are not | ||
1322 | + * recommended. | ||
1323 | + */ | ||
1324 | +static int delay = 4; | ||
1325 | +module_param(delay, int, 0); | ||
1326 | +MODULE_PARM_DESC(delay, "Set adc sample delay."); | ||
1327 | + | ||
1328 | +/* | ||
1329 | + * Set adc mask function. | ||
1330 | + * | ||
1331 | + * Sources of glitch noise, such as signals driving an LCD display, may feed | ||
1332 | + * through to the touch screen plates and affect measurement accuracy. In | ||
1333 | + * order to minimise this, a signal may be applied to the MASK pin to delay or | ||
1334 | + * synchronise the sampling. | ||
1335 | + * | ||
1336 | + * 0 = No delay or sync | ||
1337 | + * 1 = High on pin stops conversions | ||
1338 | + * 2 = Edge triggered, edge on pin delays conversion by delay param (above) | ||
1339 | + * 3 = Edge triggered, edge on pin starts conversion after delay param | ||
1340 | + */ | ||
1341 | +static int mask = 0; | ||
1342 | +module_param(mask, int, 0); | ||
1343 | +MODULE_PARM_DESC(mask, "Set adc mask function."); | ||
1344 | + | ||
1345 | +/* | ||
1346 | + * Coordinate Polling Enable. | ||
1347 | + * | ||
1348 | + * Set to 1 to enable coordinate polling. e.g. x,y[,p] is sampled together | ||
1349 | + * for every poll. | ||
1350 | + */ | ||
1351 | +static int coord = 1; | ||
1352 | +module_param(coord, int, 0); | ||
1353 | +MODULE_PARM_DESC(coord, "Polling coordinate mode"); | ||
1354 | + | ||
1355 | +/* | ||
1356 | + * ADC sample delay times in uS | ||
1357 | + */ | ||
1358 | +static const int delay_table[] = { | ||
1359 | + 21, // 1 AC97 Link frames | ||
1360 | + 42, // 2 | ||
1361 | + 84, // 4 | ||
1362 | + 167, // 8 | ||
1363 | + 333, // 16 | ||
1364 | + 667, // 32 | ||
1365 | + 1000, // 48 | ||
1366 | + 1333, // 64 | ||
1367 | + 2000, // 96 | ||
1368 | + 2667, // 128 | ||
1369 | + 3333, // 160 | ||
1370 | + 4000, // 192 | ||
1371 | + 4667, // 224 | ||
1372 | + 5333, // 256 | ||
1373 | + 6000, // 288 | ||
1374 | + 0 // No delay, switch matrix always on | ||
1375 | +}; | ||
1376 | + | ||
1377 | +/* | ||
1378 | + * Delay after issuing a POLL command. | ||
1379 | + * | ||
1380 | + * The delay is 3 AC97 link frames + the touchpanel settling delay | ||
1381 | + */ | ||
1382 | +static inline void poll_delay(int d) | ||
1383 | +{ | ||
1384 | + udelay (3 * AC97_LINK_FRAME + delay_table [d]); | ||
1385 | +} | ||
1386 | + | ||
1387 | +/* | ||
1388 | + * set up the physical settings of the WM9713 | ||
1389 | + */ | ||
1390 | +static void init_wm9713_phy(struct wm97xx* wm) | ||
1391 | +{ | ||
1392 | + u16 dig1 = 0, dig2, dig3; | ||
1393 | + | ||
1394 | + /* default values */ | ||
1395 | + dig2 = WM97XX_DELAY(4) | WM97XX_SLT(5); | ||
1396 | + dig3= WM9712_RPU(1); | ||
1397 | + | ||
1398 | + /* rpu */ | ||
1399 | + if (rpu) { | ||
1400 | + dig3 &= 0xffc0; | ||
1401 | + dig3 |= WM9712_RPU(rpu); | ||
1402 | + info("setting pen detect pull-up to %d Ohms",64000 / rpu); | ||
1403 | + } | ||
1404 | + | ||
1405 | + /* touchpanel pressure */ | ||
1406 | + if (pil == 2) { | ||
1407 | + dig3 |= WM9712_PIL; | ||
1408 | + info("setting pressure measurement current to 400uA."); | ||
1409 | + } else if (pil) | ||
1410 | + info ("setting pressure measurement current to 200uA."); | ||
1411 | + if(!pil) | ||
1412 | + pressure = 0; | ||
1413 | + | ||
1414 | + /* sample settling delay */ | ||
1415 | + if (delay < 0 || delay > 15) { | ||
1416 | + info ("supplied delay out of range."); | ||
1417 | + delay = 4; | ||
1418 | + info("setting adc sample delay to %d u Secs.", delay_table[delay]); | ||
1419 | + } | ||
1420 | + dig2 &= 0xff0f; | ||
1421 | + dig2 |= WM97XX_DELAY(delay); | ||
1422 | + | ||
1423 | + /* mask */ | ||
1424 | + dig3 |= ((mask & 0x3) << 4); | ||
1425 | + if(coord) | ||
1426 | + dig3 |= WM9713_WAIT; | ||
1427 | + | ||
1428 | + wm->misc = wm97xx_reg_read(wm, 0x5a); | ||
1429 | + | ||
1430 | + wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1); | ||
1431 | + wm97xx_reg_write(wm, AC97_WM9713_DIG2, dig2); | ||
1432 | + wm97xx_reg_write(wm, AC97_WM9713_DIG3, dig3); | ||
1433 | + wm97xx_reg_write(wm, AC97_GPIO_STICKY, 0x0); | ||
1434 | +} | ||
1435 | + | ||
1436 | +static int wm9713_digitiser_ioctl(struct wm97xx* wm, int cmd) | ||
1437 | +{ | ||
1438 | + u16 val = 0; | ||
1439 | + | ||
1440 | + switch(cmd){ | ||
1441 | + case WM97XX_DIG_START: | ||
1442 | + val = wm97xx_reg_read(wm, AC97_EXTENDED_MID); | ||
1443 | + wm97xx_reg_write(wm, AC97_EXTENDED_MID, val & 0x7fff); | ||
1444 | + wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2] | WM97XX_PRP_DET_DIG); | ||
1445 | + wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */ | ||
1446 | + break; | ||
1447 | + case WM97XX_DIG_STOP: | ||
1448 | + wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2] & ~WM97XX_PRP_DET_DIG); | ||
1449 | + val = wm97xx_reg_read(wm, AC97_EXTENDED_MID); | ||
1450 | + wm97xx_reg_write(wm, AC97_EXTENDED_MID, val | 0x8000); | ||
1451 | + break; | ||
1452 | + case WM97XX_AUX_PREPARE: | ||
1453 | + memcpy(wm->dig_save, wm->dig, sizeof(wm->dig)); | ||
1454 | + wm97xx_reg_write(wm, AC97_WM9713_DIG1, 0); | ||
1455 | + wm97xx_reg_write(wm, AC97_WM9713_DIG2, 0); | ||
1456 | + wm97xx_reg_write(wm, AC97_WM9713_DIG3, WM97XX_PRP_DET_DIG); | ||
1457 | + break; | ||
1458 | + case WM97XX_DIG_RESTORE: | ||
1459 | + wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig_save[0]); | ||
1460 | + wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig_save[1]); | ||
1461 | + wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig_save[2]); | ||
1462 | + break; | ||
1463 | + case WM97XX_PHY_INIT: | ||
1464 | + init_wm9713_phy(wm); | ||
1465 | + break; | ||
1466 | + default: | ||
1467 | + return -EINVAL; | ||
1468 | + } | ||
1469 | + return 0; | ||
1470 | +} | ||
1471 | + | ||
1472 | +static inline int is_pden (struct wm97xx* wm) | ||
1473 | +{ | ||
1474 | + return wm->dig[2] & WM9713_PDEN; | ||
1475 | +} | ||
1476 | + | ||
1477 | +/* | ||
1478 | + * Read a sample from the WM9713 adc in polling mode. | ||
1479 | + */ | ||
1480 | +static int wm9713_poll_sample (struct wm97xx* wm, int adcsel, int *sample) | ||
1481 | +{ | ||
1482 | + u16 dig1; | ||
1483 | + int timeout = 5 * delay; | ||
1484 | + | ||
1485 | + if (!wm->pen_probably_down) { | ||
1486 | + u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
1487 | + if (!(data & WM97XX_PEN_DOWN)) | ||
1488 | + return RC_PENUP; | ||
1489 | + wm->pen_probably_down = 1; | ||
1490 | + } | ||
1491 | + | ||
1492 | + /* set up digitiser */ | ||
1493 | + if (adcsel & 0x8000) | ||
1494 | + adcsel = 1 << ((adcsel & 0x7fff) + 3); | ||
1495 | + | ||
1496 | + dig1 = wm97xx_reg_read(wm, AC97_WM9713_DIG1); | ||
1497 | + dig1 &= ~WM9713_ADCSEL_MASK; | ||
1498 | + | ||
1499 | + if (wm->mach_ops && wm->mach_ops->pre_sample) | ||
1500 | + wm->mach_ops->pre_sample(adcsel); | ||
1501 | + wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1 | adcsel |WM9713_POLL); | ||
1502 | + | ||
1503 | + /* wait 3 AC97 time slots + delay for conversion */ | ||
1504 | + poll_delay(delay); | ||
1505 | + | ||
1506 | + /* wait for POLL to go low */ | ||
1507 | + while ((wm97xx_reg_read(wm, AC97_WM9713_DIG1) & WM9713_POLL) && timeout) { | ||
1508 | + udelay(AC97_LINK_FRAME); | ||
1509 | + timeout--; | ||
1510 | + } | ||
1511 | + | ||
1512 | + if (timeout <= 0) { | ||
1513 | + /* If PDEN is set, we can get a timeout when pen goes up */ | ||
1514 | + if (is_pden(wm)) | ||
1515 | + wm->pen_probably_down = 0; | ||
1516 | + else | ||
1517 | + dbg ("adc sample timeout"); | ||
1518 | + return RC_PENUP; | ||
1519 | + } | ||
1520 | + | ||
1521 | + *sample =wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
1522 | + if (wm->mach_ops && wm->mach_ops->post_sample) | ||
1523 | + wm->mach_ops->post_sample(adcsel); | ||
1524 | + | ||
1525 | + /* check we have correct sample */ | ||
1526 | + if ((*sample & WM97XX_ADCSRC_MASK) != ffs(adcsel >> 1) << 12) { | ||
1527 | + dbg ("adc wrong sample, read %x got %x", adcsel, | ||
1528 | + *sample & WM97XX_ADCSRC_MASK); | ||
1529 | + return RC_PENUP; | ||
1530 | + } | ||
1531 | + | ||
1532 | + if (!(*sample & WM97XX_PEN_DOWN)) { | ||
1533 | + wm->pen_probably_down = 0; | ||
1534 | + return RC_PENUP; | ||
1535 | + } | ||
1536 | + | ||
1537 | + return RC_VALID; | ||
1538 | +} | ||
1539 | + | ||
1540 | +/* | ||
1541 | + * Read a coordinate from the WM9713 adc in polling mode. | ||
1542 | + */ | ||
1543 | +static int wm9713_poll_coord (struct wm97xx* wm, struct wm97xx_data *data) | ||
1544 | +{ | ||
1545 | + u16 dig1; | ||
1546 | + int timeout = 5 * delay; | ||
1547 | + | ||
1548 | + if (!wm->pen_probably_down) { | ||
1549 | + u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
1550 | + if (!(data & WM97XX_PEN_DOWN)) | ||
1551 | + return RC_PENUP; | ||
1552 | + wm->pen_probably_down = 1; | ||
1553 | + } | ||
1554 | + | ||
1555 | + /* set up digitiser */ | ||
1556 | + dig1 = wm97xx_reg_read(wm, AC97_WM9713_DIG1); | ||
1557 | + dig1 &= ~WM9713_ADCSEL_MASK; | ||
1558 | + if(pil) | ||
1559 | + dig1 |= WM97XX_ADCSEL_PRES; | ||
1560 | + | ||
1561 | + if (wm->mach_ops && wm->mach_ops->pre_sample) | ||
1562 | + wm->mach_ops->pre_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y); | ||
1563 | + wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1 | WM9713_POLL | WM9713_COO); | ||
1564 | + | ||
1565 | + /* wait 3 AC97 time slots + delay for conversion */ | ||
1566 | + poll_delay(delay); | ||
1567 | + data->x = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
1568 | + /* wait for POLL to go low */ | ||
1569 | + while ((wm97xx_reg_read(wm, AC97_WM9713_DIG1) & WM9713_POLL) && timeout) { | ||
1570 | + udelay(AC97_LINK_FRAME); | ||
1571 | + timeout--; | ||
1572 | + } | ||
1573 | + | ||
1574 | + if (timeout <= 0) { | ||
1575 | + /* If PDEN is set, we can get a timeout when pen goes up */ | ||
1576 | + if (is_pden(wm)) | ||
1577 | + wm->pen_probably_down = 0; | ||
1578 | + else | ||
1579 | + dbg ("adc sample timeout"); | ||
1580 | + return RC_PENUP; | ||
1581 | + } | ||
1582 | + | ||
1583 | + /* read back data */ | ||
1584 | + data->y = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
1585 | + if (pil) | ||
1586 | + data->p = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); | ||
1587 | + else | ||
1588 | + data->p = DEFAULT_PRESSURE; | ||
1589 | + | ||
1590 | + if (wm->mach_ops && wm->mach_ops->post_sample) | ||
1591 | + wm->mach_ops->post_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y); | ||
1592 | + | ||
1593 | + /* check we have correct sample */ | ||
1594 | + if (!(data->x & WM97XX_ADCSEL_X) || !(data->y & WM97XX_ADCSEL_Y)) | ||
1595 | + goto err; | ||
1596 | + if(pil && !(data->p & WM97XX_ADCSEL_PRES)) | ||
1597 | + goto err; | ||
1598 | + | ||
1599 | + if (!(data->x & WM97XX_PEN_DOWN)) { | ||
1600 | + wm->pen_probably_down = 0; | ||
1601 | + return RC_PENUP; | ||
1602 | + } | ||
1603 | + return RC_VALID; | ||
1604 | +err: | ||
1605 | + return RC_PENUP; | ||
1606 | +} | ||
1607 | + | ||
1608 | +/* | ||
1609 | + * Sample the WM9713 touchscreen in polling mode | ||
1610 | + */ | ||
1611 | +static int wm9713_poll_touch(struct wm97xx* wm, struct wm97xx_data *data) | ||
1612 | +{ | ||
1613 | + int rc; | ||
1614 | + | ||
1615 | + if(coord) { | ||
1616 | + if((rc = wm9713_poll_coord(wm, data)) != RC_VALID) | ||
1617 | + return rc; | ||
1618 | + } else { | ||
1619 | + if ((rc = wm9713_poll_sample(wm, WM9713_ADCSEL_X, &data->x)) != RC_VALID) | ||
1620 | + return rc; | ||
1621 | + if ((rc = wm9713_poll_sample(wm, WM9713_ADCSEL_Y, &data->y)) != RC_VALID) | ||
1622 | + return rc; | ||
1623 | + if (pil) { | ||
1624 | + if ((rc = wm9713_poll_sample(wm, WM9713_ADCSEL_PRES, &data->p)) != RC_VALID) | ||
1625 | + return rc; | ||
1626 | + } else | ||
1627 | + data->p = DEFAULT_PRESSURE; | ||
1628 | + } | ||
1629 | + return RC_VALID; | ||
1630 | +} | ||
1631 | + | ||
1632 | +/* | ||
1633 | + * Enable WM9713 continuous mode, i.e. touch data is streamed across an AC97 slot | ||
1634 | + */ | ||
1635 | +static int wm9713_acc_enable (struct wm97xx* wm, int enable) | ||
1636 | +{ | ||
1637 | + u16 dig1, dig2, dig3; | ||
1638 | + int ret = 0; | ||
1639 | + | ||
1640 | + dig1 = wm->dig[0]; | ||
1641 | + dig2 = wm->dig[1]; | ||
1642 | + dig3 = wm->dig[2]; | ||
1643 | + | ||
1644 | + if (enable) { | ||
1645 | + /* continous mode */ | ||
1646 | + if (wm->mach_ops->acc_startup && | ||
1647 | + (ret = wm->mach_ops->acc_startup(wm)) < 0) | ||
1648 | + return ret; | ||
1649 | + | ||
1650 | + dig1 &= ~WM9713_ADCSEL_MASK; | ||
1651 | + dig1 |= WM9713_CTC | WM9713_COO | WM9713_ADCSEL_X | WM9713_ADCSEL_Y; | ||
1652 | + if (pil) | ||
1653 | + dig1 |= WM9713_ADCSEL_PRES; | ||
1654 | + dig2 &= ~(WM97XX_DELAY_MASK | WM97XX_SLT_MASK | WM97XX_CM_RATE_MASK); | ||
1655 | + dig2 |= WM97XX_SLEN | WM97XX_DELAY (delay) | | ||
1656 | + WM97XX_SLT (wm->acc_slot) | WM97XX_RATE (wm->acc_rate); | ||
1657 | + dig3 |= WM9713_PDEN; | ||
1658 | + } else { | ||
1659 | + dig1 &= ~(WM9713_CTC | WM9713_COO); | ||
1660 | + dig2 &= ~WM97XX_SLEN; | ||
1661 | + dig3 &= ~WM9713_PDEN; | ||
1662 | + if (wm->mach_ops->acc_shutdown) | ||
1663 | + wm->mach_ops->acc_shutdown(wm); | ||
1664 | + } | ||
1665 | + | ||
1666 | + wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1); | ||
1667 | + wm97xx_reg_write(wm, AC97_WM9713_DIG2, dig2); | ||
1668 | + wm97xx_reg_write(wm, AC97_WM9713_DIG3, dig3); | ||
1669 | + return ret; | ||
1670 | +} | ||
1671 | + | ||
1672 | +struct wm97xx_codec_drv wm97xx_codec = { | ||
1673 | + .id = WM9713_ID2, | ||
1674 | + .name = "wm9713", | ||
1675 | + .poll_sample = wm9713_poll_sample, | ||
1676 | + .poll_touch = wm9713_poll_touch, | ||
1677 | + .acc_enable = wm9713_acc_enable, | ||
1678 | + .digitiser_ioctl = wm9713_digitiser_ioctl, | ||
1679 | +}; | ||
1680 | + | ||
1681 | +EXPORT_SYMBOL_GPL(wm97xx_codec); | ||
1682 | + | ||
1683 | +/* Module information */ | ||
1684 | +MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com"); | ||
1685 | +MODULE_DESCRIPTION("WM9713 Touch Screen Driver"); | ||
1686 | +MODULE_LICENSE("GPL"); | ||
1687 | Index: linux-2.6.17/drivers/input/touchscreen/wm97xx-core.c | ||
1688 | =================================================================== | ||
1689 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
1690 | +++ linux-2.6.17/drivers/input/touchscreen/wm97xx-core.c 2006-09-19 20:36:47.969052000 +0200 | ||
1691 | @@ -0,0 +1,912 @@ | ||
1692 | +/* | ||
1693 | + * wm97xx-core.c -- Touch screen driver core for Wolfson WM9705, WM9712 | ||
1694 | + * and WM9713 AC97 Codecs. | ||
1695 | + * | ||
1696 | + * Copyright 2003, 2004, 2005, 2006 Wolfson Microelectronics PLC. | ||
1697 | + * Author: Liam Girdwood | ||
1698 | + * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com | ||
1699 | + * Parts Copyright : Ian Molton <spyro@f2s.com> | ||
1700 | + * Andrew Zabolotny <zap@homelink.ru> | ||
1701 | + * Russell King <rmk@arm.linux.org.uk> | ||
1702 | + * | ||
1703 | + * This program is free software; you can redistribute it and/or modify it | ||
1704 | + * under the terms of the GNU General Public License as published by the | ||
1705 | + * Free Software Foundation; either version 2 of the License, or (at your | ||
1706 | + * option) any later version. | ||
1707 | + * | ||
1708 | + * Notes: | ||
1709 | + * | ||
1710 | + * Features: | ||
1711 | + * - supports WM9705, WM9712, WM9713 | ||
1712 | + * - polling mode | ||
1713 | + * - continuous mode (arch-dependent) | ||
1714 | + * - adjustable rpu/dpp settings | ||
1715 | + * - adjustable pressure current | ||
1716 | + * - adjustable sample settle delay | ||
1717 | + * - 4 and 5 wire touchscreens (5 wire is WM9712 only) | ||
1718 | + * - pen down detection | ||
1719 | + * - battery monitor | ||
1720 | + * - sample AUX adc's | ||
1721 | + * - power management | ||
1722 | + * - codec GPIO | ||
1723 | + * - codec event notification | ||
1724 | + * Todo | ||
1725 | + * - Support for async sampling control for noisy LCD's. | ||
1726 | + * | ||
1727 | + * Revision history | ||
1728 | + * 7th May 2003 Initial version. | ||
1729 | + * 6th June 2003 Added non module support and AC97 registration. | ||
1730 | + * 18th June 2003 Added AUX adc sampling. | ||
1731 | + * 23rd June 2003 Did some minimal reformatting, fixed a couple of | ||
1732 | + * codec_mutexing bugs and noted a race to fix. | ||
1733 | + * 24th June 2003 Added power management and fixed race condition. | ||
1734 | + * 10th July 2003 Changed to a misc device. | ||
1735 | + * 31st July 2003 Moved TS_EVENT and TS_CAL to wm97xx.h | ||
1736 | + * 8th Aug 2003 Added option for read() calling wm97xx_sample_touch() | ||
1737 | + * because some ac97_read/ac_97_write call schedule() | ||
1738 | + * 7th Nov 2003 Added Input touch event interface, stanley.cai@intel.com | ||
1739 | + * 13th Nov 2003 Removed h3600 touch interface, added interrupt based | ||
1740 | + * pen down notification and implemented continous mode | ||
1741 | + * on XScale arch. | ||
1742 | + * 16th Nov 2003 Ian Molton <spyro@f2s.com> | ||
1743 | + * Modified so that it suits the new 2.6 driver model. | ||
1744 | + * 25th Jan 2004 Andrew Zabolotny <zap@homelink.ru> | ||
1745 | + * Implemented IRQ-driven pen down detection, implemented | ||
1746 | + * the private API meant to be exposed to platform-specific | ||
1747 | + * drivers, reorganized the driver so that it supports | ||
1748 | + * an arbitrary number of devices. | ||
1749 | + * 1st Feb 2004 Moved continuous mode handling to a separate | ||
1750 | + * architecture-dependent file. For now only PXA | ||
1751 | + * built-in AC97 controller is supported (pxa-ac97-wm97xx.c). | ||
1752 | + * 11th Feb 2004 Reduced CPU usage by keeping a cached copy of both | ||
1753 | + * digitizer registers instead of reading them every time. | ||
1754 | + * A reorganization of the whole code for better | ||
1755 | + * error handling. | ||
1756 | + * 17th Apr 2004 Added BMON support. | ||
1757 | + * 17th Nov 2004 Added codec GPIO, codec event handling (real and virtual | ||
1758 | + * GPIOs) and 2.6 power management. | ||
1759 | + * 29th Nov 2004 Added WM9713 support. | ||
1760 | + * 4th Jul 2005 Moved codec specific code out to seperate files. | ||
1761 | + * 6th Sep 2006 Mike Arthur <linux@wolfsonmicro.com> | ||
1762 | + * Added bus interface. | ||
1763 | + */ | ||
1764 | + | ||
1765 | +#include <linux/module.h> | ||
1766 | +#include <linux/moduleparam.h> | ||
1767 | +#include <linux/version.h> | ||
1768 | +#include <linux/kernel.h> | ||
1769 | +#include <linux/init.h> | ||
1770 | +#include <linux/delay.h> | ||
1771 | +#include <linux/string.h> | ||
1772 | +#include <linux/proc_fs.h> | ||
1773 | +#include <linux/pm.h> | ||
1774 | +#include <linux/interrupt.h> | ||
1775 | +#include <linux/bitops.h> | ||
1776 | +#include <linux/workqueue.h> | ||
1777 | +#include <linux/device.h> | ||
1778 | +#include <linux/wm97xx.h> | ||
1779 | +#include <asm/uaccess.h> | ||
1780 | +#include <asm/io.h> | ||
1781 | + | ||
1782 | +#define TS_NAME "wm97xx" | ||
1783 | +#define WM_CORE_VERSION "0.63" | ||
1784 | +#define DEFAULT_PRESSURE 0xb0c0 | ||
1785 | + | ||
1786 | +/* | ||
1787 | + * WM97xx - enable/disable AUX ADC sysfs | ||
1788 | + */ | ||
1789 | +static int aux_sys = 1; | ||
1790 | +module_param(aux_sys, int, 0); | ||
1791 | +MODULE_PARM_DESC(aux_sys, "enable AUX ADC sysfs entries"); | ||
1792 | + | ||
1793 | +/* | ||
1794 | + * WM97xx - enable/disable codec status sysfs | ||
1795 | + */ | ||
1796 | +static int status_sys = 1; | ||
1797 | +module_param(status_sys, int, 0); | ||
1798 | +MODULE_PARM_DESC(status_sys, "enable codec status sysfs entries"); | ||
1799 | + | ||
1800 | +/* | ||
1801 | + * Touchscreen absolute values | ||
1802 | + * | ||
1803 | + * These parameters are used to help the input layer discard out of | ||
1804 | + * range readings and reduce jitter etc. | ||
1805 | + * | ||
1806 | + * o min, max:- indicate the min and max values your touch screen returns | ||
1807 | + * o fuzz:- use a higher number to reduce jitter | ||
1808 | + * | ||
1809 | + * The default values correspond to Mainstone II in QVGA mode | ||
1810 | + * | ||
1811 | + * Please read | ||
1812 | + * Documentation/input/input-programming.txt for more details. | ||
1813 | + */ | ||
1814 | + | ||
1815 | +static int abs_x[3] = {350,3900,5}; | ||
1816 | +module_param_array(abs_x, int, NULL, 0); | ||
1817 | +MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz"); | ||
1818 | + | ||
1819 | +static int abs_y[3] = {320,3750,40}; | ||
1820 | +module_param_array(abs_y, int, NULL, 0); | ||
1821 | +MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz"); | ||
1822 | + | ||
1823 | +static int abs_p[3] = {0,150,4}; | ||
1824 | +module_param_array(abs_p, int, NULL, 0); | ||
1825 | +MODULE_PARM_DESC(abs_p, "Touchscreen absolute Pressure min, max, fuzz"); | ||
1826 | + | ||
1827 | +/* | ||
1828 | + * Debug | ||
1829 | + */ | ||
1830 | +#if 0 | ||
1831 | +#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg) | ||
1832 | +#else | ||
1833 | +#define dbg(format, arg...) | ||
1834 | +#endif | ||
1835 | +#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg) | ||
1836 | +#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg) | ||
1837 | +#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg) | ||
1838 | + | ||
1839 | +/* codec AC97 IO access */ | ||
1840 | +int wm97xx_reg_read(struct wm97xx *wm, u16 reg) | ||
1841 | +{ | ||
1842 | + if (wm->ac97) | ||
1843 | + return wm->ac97->bus->ops->read(wm->ac97, reg); | ||
1844 | + else | ||
1845 | + return -1; | ||
1846 | +} | ||
1847 | + | ||
1848 | +void wm97xx_reg_write(struct wm97xx *wm, u16 reg, u16 val) | ||
1849 | +{ | ||
1850 | + /* cache digitiser registers */ | ||
1851 | + if(reg >= AC97_WM9713_DIG1 && reg <= AC97_WM9713_DIG3) | ||
1852 | + wm->dig[(reg - AC97_WM9713_DIG1) >> 1] = val; | ||
1853 | + | ||
1854 | + /* cache gpio regs */ | ||
1855 | + if(reg >= AC97_GPIO_CFG && reg <= AC97_MISC_AFE) | ||
1856 | + wm->gpio[(reg - AC97_GPIO_CFG) >> 1] = val; | ||
1857 | + | ||
1858 | + /* wm9713 irq reg */ | ||
1859 | + if(reg == 0x5a) | ||
1860 | + wm->misc = val; | ||
1861 | + | ||
1862 | + if (wm->ac97) | ||
1863 | + wm->ac97->bus->ops->write(wm->ac97, reg, val); | ||
1864 | +} | ||
1865 | + | ||
1866 | + | ||
1867 | +/** | ||
1868 | + * wm97xx_read_aux_adc - Read the aux adc. | ||
1869 | + * @wm: wm97xx device. | ||
1870 | + * @adcsel: codec ADC to be read | ||
1871 | + * | ||
1872 | + * Reads the selected AUX ADC. | ||
1873 | + */ | ||
1874 | + | ||
1875 | +int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel) | ||
1876 | +{ | ||
1877 | + int power_adc = 0, auxval; | ||
1878 | + u16 power = 0; | ||
1879 | + | ||
1880 | + /* get codec */ | ||
1881 | + mutex_lock(&wm->codec_mutex); | ||
1882 | + | ||
1883 | + /* When the touchscreen is not in use, we may have to power up the AUX ADC | ||
1884 | + * before we can use sample the AUX inputs-> | ||
1885 | + */ | ||
1886 | + if (wm->id == WM9713_ID2 && | ||
1887 | + (power = wm97xx_reg_read(wm, AC97_EXTENDED_MID)) & 0x8000) { | ||
1888 | + power_adc = 1; | ||
1889 | + wm97xx_reg_write(wm, AC97_EXTENDED_MID, power & 0x7fff); | ||
1890 | + } | ||
1891 | + | ||
1892 | + /* Prepare the codec for AUX reading */ | ||
1893 | + wm->codec->digitiser_ioctl(wm, WM97XX_AUX_PREPARE); | ||
1894 | + | ||
1895 | + /* Turn polling mode on to read AUX ADC */ | ||
1896 | + wm->pen_probably_down = 1; | ||
1897 | + wm->codec->poll_sample(wm, adcsel, &auxval); | ||
1898 | + | ||
1899 | + if (power_adc) | ||
1900 | + wm97xx_reg_write(wm, AC97_EXTENDED_MID, power | 0x8000); | ||
1901 | + | ||
1902 | + wm->codec->digitiser_ioctl(wm, WM97XX_DIG_RESTORE); | ||
1903 | + | ||
1904 | + wm->pen_probably_down = 0; | ||
1905 | + | ||
1906 | + mutex_unlock(&wm->codec_mutex); | ||
1907 | + return auxval & 0xfff; | ||
1908 | +} | ||
1909 | + | ||
1910 | +#define WM97XX_AUX_ATTR(name,input) \ | ||
1911 | +static ssize_t name##_show(struct device *dev, struct device_attribute *attr, char *buf) \ | ||
1912 | +{ \ | ||
1913 | + struct wm97xx *wm = (struct wm97xx*)dev->driver_data; \ | ||
1914 | + return sprintf(buf, "%d\n", wm97xx_read_aux_adc(wm, input)); \ | ||
1915 | +} \ | ||
1916 | +static DEVICE_ATTR(name, 0444, name##_show, NULL) | ||
1917 | + | ||
1918 | +WM97XX_AUX_ATTR(aux1, WM97XX_AUX_ID1); | ||
1919 | +WM97XX_AUX_ATTR(aux2, WM97XX_AUX_ID2); | ||
1920 | +WM97XX_AUX_ATTR(aux3, WM97XX_AUX_ID3); | ||
1921 | +WM97XX_AUX_ATTR(aux4, WM97XX_AUX_ID4); | ||
1922 | + | ||
1923 | +#define WM97XX_STATUS_ATTR(name) \ | ||
1924 | +static ssize_t name##_show(struct device *dev, struct device_attribute *attr, char *buf) \ | ||
1925 | +{ \ | ||
1926 | + struct wm97xx *wm = (struct wm97xx*)dev->driver_data; \ | ||
1927 | + return sprintf(buf, "%d\n", wm97xx_reg_read(wm, AC97_GPIO_STATUS)); \ | ||
1928 | +} \ | ||
1929 | +static DEVICE_ATTR(name, 0444, name##_show, NULL) | ||
1930 | + | ||
1931 | +WM97XX_STATUS_ATTR(gpio); | ||
1932 | + | ||
1933 | +static int wm97xx_sys_add(struct device *dev) | ||
1934 | +{ | ||
1935 | + if (aux_sys) { | ||
1936 | + device_create_file(dev, &dev_attr_aux1); | ||
1937 | + device_create_file(dev, &dev_attr_aux2); | ||
1938 | + device_create_file(dev, &dev_attr_aux3); | ||
1939 | + device_create_file(dev, &dev_attr_aux4); | ||
1940 | + } | ||
1941 | + if (status_sys) | ||
1942 | + device_create_file(dev, &dev_attr_gpio); | ||
1943 | + return 0; | ||
1944 | +} | ||
1945 | + | ||
1946 | +static void wm97xx_sys_remove(struct device *dev) | ||
1947 | +{ | ||
1948 | + if (status_sys) | ||
1949 | + device_remove_file(dev, &dev_attr_gpio); | ||
1950 | + if (aux_sys) { | ||
1951 | + device_remove_file(dev, &dev_attr_aux1); | ||
1952 | + device_remove_file(dev, &dev_attr_aux2); | ||
1953 | + device_remove_file(dev, &dev_attr_aux3); | ||
1954 | + device_remove_file(dev, &dev_attr_aux4); | ||
1955 | + } | ||
1956 | +} | ||
1957 | + | ||
1958 | +/** | ||
1959 | + * wm97xx_get_gpio - Get the status of a codec GPIO. | ||
1960 | + * @wm: wm97xx device. | ||
1961 | + * @gpio: gpio | ||
1962 | + * | ||
1963 | + * Get the status of a codec GPIO pin | ||
1964 | + */ | ||
1965 | + | ||
1966 | +wm97xx_gpio_status_t wm97xx_get_gpio(struct wm97xx *wm, u32 gpio) | ||
1967 | +{ | ||
1968 | + u16 status; | ||
1969 | + wm97xx_gpio_status_t ret; | ||
1970 | + | ||
1971 | + mutex_lock(&wm->codec_mutex); | ||
1972 | + status = wm97xx_reg_read(wm, AC97_GPIO_STATUS); | ||
1973 | + | ||
1974 | + if (status & gpio) | ||
1975 | + ret = WM97XX_GPIO_HIGH; | ||
1976 | + else | ||
1977 | + ret = WM97XX_GPIO_LOW; | ||
1978 | + | ||
1979 | + mutex_unlock(&wm->codec_mutex); | ||
1980 | + return ret; | ||
1981 | +} | ||
1982 | + | ||
1983 | +/** | ||
1984 | + * wm97xx_set_gpio - Set the status of a codec GPIO. | ||
1985 | + * @wm: wm97xx device. | ||
1986 | + * @gpio: gpio | ||
1987 | + * | ||
1988 | + * | ||
1989 | + * Set the status of a codec GPIO pin | ||
1990 | + */ | ||
1991 | + | ||
1992 | +void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio, | ||
1993 | + wm97xx_gpio_status_t status) | ||
1994 | +{ | ||
1995 | + u16 reg; | ||
1996 | + | ||
1997 | + mutex_lock(&wm->codec_mutex); | ||
1998 | + reg = wm97xx_reg_read(wm, AC97_GPIO_STATUS); | ||
1999 | + | ||
2000 | + if (status & WM97XX_GPIO_HIGH) | ||
2001 | + reg |= gpio; | ||
2002 | + else | ||
2003 | + reg &= ~gpio; | ||
2004 | + | ||
2005 | + if (wm->id == WM9712_ID2) | ||
2006 | + wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg << 1); | ||
2007 | + else | ||
2008 | + wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg); | ||
2009 | + mutex_unlock(&wm->codec_mutex); | ||
2010 | +} | ||
2011 | + | ||
2012 | +/* | ||
2013 | + * Codec GPIO pin configuration, this set's pin direction, polarity, | ||
2014 | + * stickyness and wake up. | ||
2015 | + */ | ||
2016 | +void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, wm97xx_gpio_dir_t dir, | ||
2017 | + wm97xx_gpio_pol_t pol, wm97xx_gpio_sticky_t sticky, | ||
2018 | + wm97xx_gpio_wake_t wake) | ||
2019 | +{ | ||
2020 | + u16 reg; | ||
2021 | + | ||
2022 | + mutex_lock(&wm->codec_mutex); | ||
2023 | + reg = wm97xx_reg_read(wm, AC97_GPIO_POLARITY); | ||
2024 | + | ||
2025 | + if (pol == WM97XX_GPIO_POL_HIGH) | ||
2026 | + reg |= gpio; | ||
2027 | + else | ||
2028 | + reg &= ~gpio; | ||
2029 | + | ||
2030 | + wm97xx_reg_write(wm, AC97_GPIO_POLARITY, reg); | ||
2031 | + reg = wm97xx_reg_read(wm, AC97_GPIO_STICKY); | ||
2032 | + | ||
2033 | + if (sticky == WM97XX_GPIO_STICKY) | ||
2034 | + reg |= gpio; | ||
2035 | + else | ||
2036 | + reg &= ~gpio; | ||
2037 | + | ||
2038 | + wm97xx_reg_write(wm, AC97_GPIO_STICKY, reg); | ||
2039 | + reg = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP); | ||
2040 | + | ||
2041 | + if (wake == WM97XX_GPIO_WAKE) | ||
2042 | + reg |= gpio; | ||
2043 | + else | ||
2044 | + reg &= ~gpio; | ||
2045 | + | ||
2046 | + wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, reg); | ||
2047 | + reg = wm97xx_reg_read(wm, AC97_GPIO_CFG); | ||
2048 | + | ||
2049 | + if (dir == WM97XX_GPIO_IN) | ||
2050 | + reg |= gpio; | ||
2051 | + else | ||
2052 | + reg &= ~gpio; | ||
2053 | + | ||
2054 | + wm97xx_reg_write(wm, AC97_GPIO_CFG, reg); | ||
2055 | + mutex_unlock(&wm->codec_mutex); | ||
2056 | +} | ||
2057 | + | ||
2058 | +/* | ||
2059 | + * Handle a pen down interrupt. | ||
2060 | + */ | ||
2061 | +static void wm97xx_pen_irq_worker(void *ptr) | ||
2062 | +{ | ||
2063 | + struct wm97xx *wm = (struct wm97xx *) ptr; | ||
2064 | + | ||
2065 | + /* do we need to enable the touch panel reader */ | ||
2066 | + if (wm->id == WM9705_ID2) { | ||
2067 | + if (wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD) & WM97XX_PEN_DOWN) | ||
2068 | + wm->pen_is_down = 1; | ||
2069 | + else | ||
2070 | + wm->pen_is_down = 0; | ||
2071 | + wake_up_interruptible(&wm->pen_irq_wait); | ||
2072 | + } else { | ||
2073 | + u16 status, pol; | ||
2074 | + mutex_lock(&wm->codec_mutex); | ||
2075 | + status = wm97xx_reg_read(wm, AC97_GPIO_STATUS); | ||
2076 | + pol = wm97xx_reg_read(wm, AC97_GPIO_POLARITY); | ||
2077 | + | ||
2078 | + if (WM97XX_GPIO_13 & pol & status) { | ||
2079 | + wm->pen_is_down = 1; | ||
2080 | + wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol & ~WM97XX_GPIO_13); | ||
2081 | + } else { | ||
2082 | + wm->pen_is_down = 0; | ||
2083 | + wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol | WM97XX_GPIO_13); | ||
2084 | + } | ||
2085 | + | ||
2086 | + if (wm->id == WM9712_ID2) | ||
2087 | + wm97xx_reg_write(wm, AC97_GPIO_STATUS, (status & ~WM97XX_GPIO_13) << 1); | ||
2088 | + else | ||
2089 | + wm97xx_reg_write(wm, AC97_GPIO_STATUS, status & ~WM97XX_GPIO_13); | ||
2090 | + mutex_unlock(&wm->codec_mutex); | ||
2091 | + wake_up_interruptible(&wm->pen_irq_wait); | ||
2092 | + } | ||
2093 | + | ||
2094 | + if (!wm->pen_is_down && wm->mach_ops && wm->mach_ops->acc_enabled) | ||
2095 | + wm->mach_ops->acc_pen_up(wm); | ||
2096 | + enable_irq(wm->pen_irq); | ||
2097 | +} | ||
2098 | + | ||
2099 | +/* | ||
2100 | + * Codec PENDOWN irq handler | ||
2101 | + * | ||
2102 | + * We have to disable the codec interrupt in the handler because it can | ||
2103 | + * take upto 1ms to clear the interrupt source. The interrupt is then enabled | ||
2104 | + * again in the slow handler when the source has been cleared. | ||
2105 | + */ | ||
2106 | +static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id, | ||
2107 | + struct pt_regs *regs) | ||
2108 | +{ | ||
2109 | + struct wm97xx *wm = (struct wm97xx *) dev_id; | ||
2110 | + disable_irq(wm->pen_irq); | ||
2111 | + queue_work(wm->pen_irq_workq, &wm->pen_event_work); | ||
2112 | + return IRQ_HANDLED; | ||
2113 | +} | ||
2114 | + | ||
2115 | +/* | ||
2116 | + * initialise pen IRQ handler and workqueue | ||
2117 | + */ | ||
2118 | +static int wm97xx_init_pen_irq(struct wm97xx *wm) | ||
2119 | +{ | ||
2120 | + u16 reg; | ||
2121 | + | ||
2122 | + INIT_WORK(&wm->pen_event_work, wm97xx_pen_irq_worker, wm); | ||
2123 | + if ((wm->pen_irq_workq = | ||
2124 | + create_singlethread_workqueue("kwm97pen")) == NULL) { | ||
2125 | + err("could not create pen irq work queue"); | ||
2126 | + wm->pen_irq = 0; | ||
2127 | + return -EINVAL; | ||
2128 | + } | ||
2129 | + | ||
2130 | + if (request_irq (wm->pen_irq, wm97xx_pen_interrupt, SA_SHIRQ, "wm97xx-pen", wm)) { | ||
2131 | + err("could not register codec pen down interrupt, will poll for pen down"); | ||
2132 | + destroy_workqueue(wm->pen_irq_workq); | ||
2133 | + wm->pen_irq = 0; | ||
2134 | + return -EINVAL; | ||
2135 | + } | ||
2136 | + | ||
2137 | + /* enable PEN down on wm9712/13 */ | ||
2138 | + if (wm->id != WM9705_ID2) { | ||
2139 | + reg = wm97xx_reg_read(wm, AC97_MISC_AFE); | ||
2140 | + wm97xx_reg_write(wm, AC97_MISC_AFE, reg & 0xfffb); | ||
2141 | + reg = wm97xx_reg_read(wm, 0x5a); | ||
2142 | + wm97xx_reg_write(wm, 0x5a, reg & ~0x0001); | ||
2143 | + } | ||
2144 | + | ||
2145 | + return 0; | ||
2146 | +} | ||
2147 | + | ||
2148 | +/* Private struct for communication between struct wm97xx_tshread | ||
2149 | + * and wm97xx_read_samples */ | ||
2150 | +struct ts_state { | ||
2151 | + int sleep_time; | ||
2152 | + int min_sleep_time; | ||
2153 | +}; | ||
2154 | + | ||
2155 | +static int wm97xx_read_samples(struct wm97xx *wm, struct ts_state *state) | ||
2156 | +{ | ||
2157 | + struct wm97xx_data data; | ||
2158 | + int rc; | ||
2159 | + | ||
2160 | + mutex_lock(&wm->codec_mutex); | ||
2161 | + | ||
2162 | + if (wm->mach_ops && wm->mach_ops->acc_enabled) | ||
2163 | + rc = wm->mach_ops->acc_pen_down(wm); | ||
2164 | + else | ||
2165 | + rc = wm->codec->poll_touch(wm, &data); | ||
2166 | + | ||
2167 | + if (rc & RC_PENUP) { | ||
2168 | + if (wm->pen_is_down) { | ||
2169 | + wm->pen_is_down = 0; | ||
2170 | + dbg("pen up"); | ||
2171 | + input_report_abs(wm->input_dev, ABS_PRESSURE, 0); | ||
2172 | + input_sync(wm->input_dev); | ||
2173 | + } else if (!(rc & RC_AGAIN)) { | ||
2174 | + /* We need high frequency updates only while pen is down, | ||
2175 | + * the user never will be able to touch screen faster than | ||
2176 | + * a few times per second... On the other hand, when the | ||
2177 | + * user is actively working with the touchscreen we don't | ||
2178 | + * want to lose the quick response. So we will slowly | ||
2179 | + * increase sleep time after the pen is up and quicky | ||
2180 | + * restore it to ~one task switch when pen is down again. | ||
2181 | + */ | ||
2182 | + if (state->sleep_time < HZ / 10) | ||
2183 | + state->sleep_time++; | ||
2184 | + } | ||
2185 | + | ||
2186 | + } else if (rc & RC_VALID) { | ||
2187 | + dbg("pen down: x=%x:%d, y=%x:%d, pressure=%x:%d\n", | ||
2188 | + data.x >> 12, data.x & 0xfff, data.y >> 12, | ||
2189 | + data.y & 0xfff, data.p >> 12, data.p & 0xfff); | ||
2190 | + input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff); | ||
2191 | + input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff); | ||
2192 | + input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff); | ||
2193 | + input_sync(wm->input_dev); | ||
2194 | + wm->pen_is_down = 1; | ||
2195 | + state->sleep_time = state->min_sleep_time; | ||
2196 | + } else if (rc & RC_PENDOWN) { | ||
2197 | + dbg("pen down"); | ||
2198 | + wm->pen_is_down = 1; | ||
2199 | + state->sleep_time = state->min_sleep_time; | ||
2200 | + } | ||
2201 | + | ||
2202 | + mutex_unlock(&wm->codec_mutex); | ||
2203 | + return rc; | ||
2204 | +} | ||
2205 | + | ||
2206 | +/* | ||
2207 | +* The touchscreen sample reader thread. | ||
2208 | +*/ | ||
2209 | +static int wm97xx_ts_read(void *data) | ||
2210 | +{ | ||
2211 | + int rc; | ||
2212 | + struct ts_state state; | ||
2213 | + struct wm97xx *wm = (struct wm97xx *) data; | ||
2214 | + | ||
2215 | + /* set up thread context */ | ||
2216 | + wm->ts_task = current; | ||
2217 | + daemonize("kwm97xxts"); | ||
2218 | + | ||
2219 | + if (wm->codec == NULL) { | ||
2220 | + wm->ts_task = NULL; | ||
2221 | + printk(KERN_ERR "codec is NULL, bailing\n"); | ||
2222 | + } | ||
2223 | + | ||
2224 | + complete(&wm->ts_init); | ||
2225 | + wm->pen_is_down = 0; | ||
2226 | + state.min_sleep_time = HZ >= 100 ? HZ / 100 : 1; | ||
2227 | + if (state.min_sleep_time < 1) | ||
2228 | + state.min_sleep_time = 1; | ||
2229 | + state.sleep_time = state.min_sleep_time; | ||
2230 | + | ||
2231 | + /* touch reader loop */ | ||
2232 | + while (wm->ts_task) { | ||
2233 | + do { | ||
2234 | + try_to_freeze(); | ||
2235 | + rc = wm97xx_read_samples(wm, &state); | ||
2236 | + } while (rc & RC_AGAIN); | ||
2237 | + if (!wm->pen_is_down && wm->pen_irq) { | ||
2238 | + /* Nice, we don't have to poll for pen down event */ | ||
2239 | + wait_event_interruptible(wm->pen_irq_wait, wm->pen_is_down); | ||
2240 | + } else { | ||
2241 | + set_task_state(current, TASK_INTERRUPTIBLE); | ||
2242 | + schedule_timeout(state.sleep_time); | ||
2243 | + } | ||
2244 | + } | ||
2245 | + complete_and_exit(&wm->ts_exit, 0); | ||
2246 | +} | ||
2247 | + | ||
2248 | +/** | ||
2249 | + * wm97xx_ts_input_open - Open the touch screen input device. | ||
2250 | + * @idev: Input device to be opened. | ||
2251 | + * | ||
2252 | + * Called by the input sub system to open a wm97xx touchscreen device. | ||
2253 | + * Starts the touchscreen thread and touch digitiser. | ||
2254 | + */ | ||
2255 | +static int wm97xx_ts_input_open(struct input_dev *idev) | ||
2256 | +{ | ||
2257 | + int ret = 0; | ||
2258 | + struct wm97xx *wm = (struct wm97xx *) idev->private; | ||
2259 | + | ||
2260 | + mutex_lock(&wm->codec_mutex); | ||
2261 | + /* first time opened ? */ | ||
2262 | + if (wm->ts_use_count++ == 0) { | ||
2263 | + /* start touchscreen thread */ | ||
2264 | + init_completion(&wm->ts_init); | ||
2265 | + init_completion(&wm->ts_exit); | ||
2266 | + ret = kernel_thread(wm97xx_ts_read, wm, CLONE_KERNEL); | ||
2267 | + | ||
2268 | + if (ret >= 0) { | ||
2269 | + wait_for_completion(&wm->ts_init); | ||
2270 | + if (wm->ts_task == NULL) | ||
2271 | + ret = -EINVAL; | ||
2272 | + } else { | ||
2273 | + mutex_unlock(&wm->codec_mutex); | ||
2274 | + return ret; | ||
2275 | + } | ||
2276 | + | ||
2277 | + /* start digitiser */ | ||
2278 | + if (wm->mach_ops && wm->mach_ops->acc_enabled) | ||
2279 | + wm->codec->acc_enable(wm, 1); | ||
2280 | + wm->codec->digitiser_ioctl(wm, WM97XX_DIG_START); | ||
2281 | + | ||
2282 | + /* init pen down/up irq handling */ | ||
2283 | + if (wm->pen_irq) { | ||
2284 | + wm97xx_init_pen_irq(wm); | ||
2285 | + | ||
2286 | + if (wm->pen_irq == 0) { | ||
2287 | + /* we failed to get an irq for pen down events, | ||
2288 | + * so we resort to polling. kickstart the reader */ | ||
2289 | + wm->pen_is_down = 1; | ||
2290 | + wake_up_interruptible(&wm->pen_irq_wait); | ||
2291 | + } | ||
2292 | + } | ||
2293 | + } | ||
2294 | + | ||
2295 | + mutex_unlock(&wm->codec_mutex); | ||
2296 | + return 0; | ||
2297 | +} | ||
2298 | + | ||
2299 | +/** | ||
2300 | + * wm97xx_ts_input_close - Close the touch screen input device. | ||
2301 | + * @idev: Input device to be closed. | ||
2302 | + * | ||
2303 | + * Called by the input sub system to close a wm97xx touchscreen device. | ||
2304 | + * Kills the touchscreen thread and stops the touch digitiser. | ||
2305 | + */ | ||
2306 | + | ||
2307 | +static void wm97xx_ts_input_close(struct input_dev *idev) | ||
2308 | +{ | ||
2309 | + struct wm97xx *wm = (struct wm97xx *) idev->private; | ||
2310 | + | ||
2311 | + mutex_lock(&wm->codec_mutex); | ||
2312 | + if (--wm->ts_use_count == 0) { | ||
2313 | + /* destroy workqueues and free irqs */ | ||
2314 | + if (wm->pen_irq) { | ||
2315 | + free_irq(wm->pen_irq, wm); | ||
2316 | + destroy_workqueue(wm->pen_irq_workq); | ||
2317 | + } | ||
2318 | + | ||
2319 | + /* kill thread */ | ||
2320 | + if (wm->ts_task) { | ||
2321 | + wm->ts_task = NULL; | ||
2322 | + wm->pen_is_down = 1; | ||
2323 | + wake_up_interruptible(&wm->pen_irq_wait); | ||
2324 | + wait_for_completion(&wm->ts_exit); | ||
2325 | + wm->pen_is_down = 0; | ||
2326 | + } | ||
2327 | + | ||
2328 | + /* stop digitiser */ | ||
2329 | + wm->codec->digitiser_ioctl(wm, WM97XX_DIG_STOP); | ||
2330 | + if (wm->mach_ops && wm->mach_ops->acc_enabled) | ||
2331 | + wm->codec->acc_enable(wm, 0); | ||
2332 | + } | ||
2333 | + mutex_unlock(&wm->codec_mutex); | ||
2334 | +} | ||
2335 | + | ||
2336 | +static int wm97xx_bus_match(struct device *dev, struct device_driver *drv) | ||
2337 | +{ | ||
2338 | + return !(strcmp(dev->bus_id,drv->name)); | ||
2339 | +} | ||
2340 | + | ||
2341 | +/* | ||
2342 | + * The AC97 audio driver will do all the Codec suspend and resume | ||
2343 | + * tasks. This is just for anything machine specific or extra. | ||
2344 | + */ | ||
2345 | +static int wm97xx_bus_suspend(struct device *dev, pm_message_t state) | ||
2346 | +{ | ||
2347 | + int ret = 0; | ||
2348 | + | ||
2349 | + if (dev->driver && dev->driver->suspend) | ||
2350 | + ret = dev->driver->suspend(dev, state); | ||
2351 | + | ||
2352 | + return ret; | ||
2353 | +} | ||
2354 | + | ||
2355 | +static int wm97xx_bus_resume(struct device *dev) | ||
2356 | +{ | ||
2357 | + int ret = 0; | ||
2358 | + | ||
2359 | + if (dev->driver && dev->driver->resume) | ||
2360 | + ret = dev->driver->resume(dev); | ||
2361 | + | ||
2362 | + return ret; | ||
2363 | +} | ||
2364 | + | ||
2365 | +struct bus_type wm97xx_bus_type = { | ||
2366 | + .name = "wm97xx", | ||
2367 | + .match = wm97xx_bus_match, | ||
2368 | + .suspend = wm97xx_bus_suspend, | ||
2369 | + .resume = wm97xx_bus_resume, | ||
2370 | +}; | ||
2371 | + | ||
2372 | +static void wm97xx_release(struct device *dev) | ||
2373 | +{ | ||
2374 | + kfree(dev); | ||
2375 | +} | ||
2376 | + | ||
2377 | +static int wm97xx_probe(struct device *dev) | ||
2378 | +{ | ||
2379 | + struct wm97xx* wm; | ||
2380 | + int ret = 0, id = 0; | ||
2381 | + | ||
2382 | + if (!(wm = kzalloc(sizeof(struct wm97xx), GFP_KERNEL))) | ||
2383 | + return -ENOMEM; | ||
2384 | + mutex_init(&wm->codec_mutex); | ||
2385 | + | ||
2386 | + init_waitqueue_head(&wm->pen_irq_wait); | ||
2387 | + wm->dev = dev; | ||
2388 | + dev->driver_data = wm; | ||
2389 | + wm->ac97 = to_ac97_t(dev); | ||
2390 | + | ||
2391 | + /* check that we have a supported codec */ | ||
2392 | + if ((id = wm97xx_reg_read(wm, AC97_VENDOR_ID1)) != WM97XX_ID1) { | ||
2393 | + err("could not find a wm97xx, found a %x instead\n", id); | ||
2394 | + kfree(wm); | ||
2395 | + return -ENODEV; | ||
2396 | + } | ||
2397 | + | ||
2398 | + wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2); | ||
2399 | + if(wm->id != wm97xx_codec.id) { | ||
2400 | + err("could not find a the selected codec, please build for wm97%2x", wm->id & 0xff); | ||
2401 | + kfree(wm); | ||
2402 | + return -ENODEV; | ||
2403 | + } | ||
2404 | + | ||
2405 | + if((wm->input_dev = input_allocate_device()) == NULL) { | ||
2406 | + kfree(wm); | ||
2407 | + return -ENOMEM; | ||
2408 | + } | ||
2409 | + | ||
2410 | + /* set up touch configuration */ | ||
2411 | + info("detected a wm97%2x codec", wm->id & 0xff); | ||
2412 | + wm->input_dev->name = "wm97xx touchscreen"; | ||
2413 | + wm->input_dev->open = wm97xx_ts_input_open; | ||
2414 | + wm->input_dev->close = wm97xx_ts_input_close; | ||
2415 | + set_bit(EV_ABS, wm->input_dev->evbit); | ||
2416 | + set_bit(ABS_X, wm->input_dev->absbit); | ||
2417 | + set_bit(ABS_Y, wm->input_dev->absbit); | ||
2418 | + set_bit(ABS_PRESSURE, wm->input_dev->absbit); | ||
2419 | + wm->input_dev->absmax[ABS_X] = abs_x[1]; | ||
2420 | + wm->input_dev->absmax[ABS_Y] = abs_y[1]; | ||
2421 | + wm->input_dev->absmax[ABS_PRESSURE] = abs_p[1]; | ||
2422 | + wm->input_dev->absmin[ABS_X] = abs_x[0]; | ||
2423 | + wm->input_dev->absmin[ABS_Y] = abs_y[0]; | ||
2424 | + wm->input_dev->absmin[ABS_PRESSURE] = abs_p[0]; | ||
2425 | + wm->input_dev->absfuzz[ABS_X] = abs_x[2]; | ||
2426 | + wm->input_dev->absfuzz[ABS_Y] = abs_y[2]; | ||
2427 | + wm->input_dev->absfuzz[ABS_PRESSURE] = abs_p[2]; | ||
2428 | + wm->input_dev->private = wm; | ||
2429 | + wm->codec = &wm97xx_codec; | ||
2430 | + if((ret = input_register_device(wm->input_dev)) < 0) { | ||
2431 | + kfree(wm); | ||
2432 | + return -ENOMEM; | ||
2433 | + } | ||
2434 | + | ||
2435 | + if(aux_sys) | ||
2436 | + wm97xx_sys_add(dev); | ||
2437 | + | ||
2438 | + /* set up physical characteristics */ | ||
2439 | + wm->codec->digitiser_ioctl(wm, WM97XX_PHY_INIT); | ||
2440 | + | ||
2441 | + /* load gpio cache */ | ||
2442 | + wm->gpio[0] = wm97xx_reg_read(wm, AC97_GPIO_CFG); | ||
2443 | + wm->gpio[1] = wm97xx_reg_read(wm, AC97_GPIO_POLARITY); | ||
2444 | + wm->gpio[2] = wm97xx_reg_read(wm, AC97_GPIO_STICKY); | ||
2445 | + wm->gpio[3] = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP); | ||
2446 | + wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS); | ||
2447 | + wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE); | ||
2448 | + | ||
2449 | + /* register our battery device */ | ||
2450 | + if (!(wm->battery_dev = kzalloc(sizeof(struct device), GFP_KERNEL))) { | ||
2451 | + ret = -ENOMEM; | ||
2452 | + goto batt_err; | ||
2453 | + } | ||
2454 | + wm->battery_dev->bus = &wm97xx_bus_type; | ||
2455 | + strcpy(wm->battery_dev->bus_id,"wm97xx-battery"); | ||
2456 | + wm->battery_dev->driver_data = wm; | ||
2457 | + wm->battery_dev->parent = dev; | ||
2458 | + wm->battery_dev->release = wm97xx_release; | ||
2459 | + if((ret = device_register(wm->battery_dev)) < 0) | ||
2460 | + goto batt_reg_err; | ||
2461 | + | ||
2462 | + /* register our extended touch device (for machine specific extensions) */ | ||
2463 | + if (!(wm->touch_dev = kzalloc(sizeof(struct device), GFP_KERNEL))) { | ||
2464 | + ret = -ENOMEM; | ||
2465 | + goto touch_err; | ||
2466 | + } | ||
2467 | + wm->touch_dev->bus = &wm97xx_bus_type; | ||
2468 | + strcpy(wm->touch_dev->bus_id,"wm97xx-touchscreen"); | ||
2469 | + wm->touch_dev->driver_data = wm; | ||
2470 | + wm->touch_dev->parent = dev; | ||
2471 | + wm->touch_dev->release = wm97xx_release; | ||
2472 | + if((ret = device_register(wm->touch_dev)) < 0) | ||
2473 | + goto touch_reg_err; | ||
2474 | + | ||
2475 | + return ret; | ||
2476 | + | ||
2477 | +touch_reg_err: | ||
2478 | + kfree(wm->touch_dev); | ||
2479 | +touch_err: | ||
2480 | + device_unregister(wm->battery_dev); | ||
2481 | +batt_reg_err: | ||
2482 | + kfree(wm->battery_dev); | ||
2483 | +batt_err: | ||
2484 | + input_unregister_device(wm->input_dev); | ||
2485 | + kfree(wm); | ||
2486 | + return ret; | ||
2487 | +} | ||
2488 | + | ||
2489 | +static int wm97xx_remove(struct device *dev) | ||
2490 | +{ | ||
2491 | + struct wm97xx *wm = dev_get_drvdata(dev); | ||
2492 | + | ||
2493 | + /* Stop touch reader thread */ | ||
2494 | + if (wm->ts_task) { | ||
2495 | + wm->ts_task = NULL; | ||
2496 | + wm->pen_is_down = 1; | ||
2497 | + wake_up_interruptible(&wm->pen_irq_wait); | ||
2498 | + wait_for_completion(&wm->ts_exit); | ||
2499 | + } | ||
2500 | + device_unregister(wm->battery_dev); | ||
2501 | + device_unregister(wm->touch_dev); | ||
2502 | + input_unregister_device(wm->input_dev); | ||
2503 | + | ||
2504 | + if(aux_sys) | ||
2505 | + wm97xx_sys_remove(dev); | ||
2506 | + | ||
2507 | + kfree(wm); | ||
2508 | + return 0; | ||
2509 | +} | ||
2510 | + | ||
2511 | +#ifdef CONFIG_PM | ||
2512 | +int wm97xx_resume(struct device* dev) | ||
2513 | +{ | ||
2514 | + struct wm97xx *wm = dev_get_drvdata(dev); | ||
2515 | + | ||
2516 | + /* restore digitiser and gpio's */ | ||
2517 | + if(wm->id == WM9713_ID2) { | ||
2518 | + wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig[0]); | ||
2519 | + wm97xx_reg_write(wm, 0x5a, wm->misc); | ||
2520 | + if(wm->ts_use_count) { | ||
2521 | + u16 reg = wm97xx_reg_read(wm, AC97_EXTENDED_MID) & 0x7fff; | ||
2522 | + wm97xx_reg_write(wm, AC97_EXTENDED_MID, reg); | ||
2523 | + } | ||
2524 | + } | ||
2525 | + | ||
2526 | + wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig[1]); | ||
2527 | + wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2]); | ||
2528 | + | ||
2529 | + wm97xx_reg_write(wm, AC97_GPIO_CFG, wm->gpio[0]); | ||
2530 | + wm97xx_reg_write(wm, AC97_GPIO_POLARITY, wm->gpio[1]); | ||
2531 | + wm97xx_reg_write(wm, AC97_GPIO_STICKY, wm->gpio[2]); | ||
2532 | + wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, wm->gpio[3]); | ||
2533 | + wm97xx_reg_write(wm, AC97_GPIO_STATUS, wm->gpio[4]); | ||
2534 | + wm97xx_reg_write(wm, AC97_MISC_AFE, wm->gpio[5]); | ||
2535 | + | ||
2536 | + return 0; | ||
2537 | +} | ||
2538 | + | ||
2539 | +#else | ||
2540 | +#define wm97xx_resume NULL | ||
2541 | +#endif | ||
2542 | + | ||
2543 | +int wm97xx_register_mach_ops(struct wm97xx *wm, struct wm97xx_mach_ops *mach_ops) | ||
2544 | +{ | ||
2545 | + mutex_lock(&wm->codec_mutex); | ||
2546 | + if(wm->mach_ops) { | ||
2547 | + mutex_unlock(&wm->codec_mutex); | ||
2548 | + return -EINVAL; | ||
2549 | + } | ||
2550 | + wm->mach_ops = mach_ops; | ||
2551 | + mutex_unlock(&wm->codec_mutex); | ||
2552 | + return 0; | ||
2553 | +} | ||
2554 | + | ||
2555 | +void wm97xx_unregister_mach_ops(struct wm97xx *wm) | ||
2556 | +{ | ||
2557 | + mutex_lock(&wm->codec_mutex); | ||
2558 | + wm->mach_ops = NULL; | ||
2559 | + mutex_unlock(&wm->codec_mutex); | ||
2560 | +} | ||
2561 | + | ||
2562 | +static struct device_driver wm97xx_driver = { | ||
2563 | + .name = "ac97", | ||
2564 | + .bus = &ac97_bus_type, | ||
2565 | + .owner = THIS_MODULE, | ||
2566 | + .probe = wm97xx_probe, | ||
2567 | + .remove = wm97xx_remove, | ||
2568 | + .resume = wm97xx_resume, | ||
2569 | +}; | ||
2570 | + | ||
2571 | +static int __init wm97xx_init(void) | ||
2572 | +{ | ||
2573 | + int ret; | ||
2574 | + | ||
2575 | + info("version %s liam.girdwood@wolfsonmicro.com", WM_CORE_VERSION); | ||
2576 | + if((ret = bus_register(&wm97xx_bus_type)) < 0) | ||
2577 | + return ret; | ||
2578 | + return driver_register(&wm97xx_driver); | ||
2579 | +} | ||
2580 | + | ||
2581 | +static void __exit wm97xx_exit(void) | ||
2582 | +{ | ||
2583 | + driver_unregister(&wm97xx_driver); | ||
2584 | + bus_unregister(&wm97xx_bus_type); | ||
2585 | +} | ||
2586 | + | ||
2587 | +EXPORT_SYMBOL_GPL(wm97xx_get_gpio); | ||
2588 | +EXPORT_SYMBOL_GPL(wm97xx_set_gpio); | ||
2589 | +EXPORT_SYMBOL_GPL(wm97xx_config_gpio); | ||
2590 | +EXPORT_SYMBOL_GPL(wm97xx_read_aux_adc); | ||
2591 | +EXPORT_SYMBOL_GPL(wm97xx_reg_read); | ||
2592 | +EXPORT_SYMBOL_GPL(wm97xx_reg_write); | ||
2593 | +EXPORT_SYMBOL_GPL(wm97xx_bus_type); | ||
2594 | +EXPORT_SYMBOL_GPL(wm97xx_register_mach_ops); | ||
2595 | +EXPORT_SYMBOL_GPL(wm97xx_unregister_mach_ops); | ||
2596 | + | ||
2597 | +module_init(wm97xx_init); | ||
2598 | +module_exit(wm97xx_exit); | ||
2599 | + | ||
2600 | +/* Module information */ | ||
2601 | +MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com"); | ||
2602 | +MODULE_DESCRIPTION("WM97xx Core - Touch Screen / AUX ADC / GPIO Driver"); | ||
2603 | +MODULE_LICENSE("GPL"); | ||
2604 | Index: linux-2.6.17/include/linux/wm97xx.h | ||
2605 | =================================================================== | ||
2606 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
2607 | +++ linux-2.6.17/include/linux/wm97xx.h 2006-09-19 20:36:47.973052250 +0200 | ||
2608 | @@ -0,0 +1,291 @@ | ||
2609 | + | ||
2610 | +/* | ||
2611 | + * Register bits and API for Wolfson WM97xx series of codecs | ||
2612 | + */ | ||
2613 | + | ||
2614 | +#ifndef _LINUX_WM97XX_H | ||
2615 | +#define _LINUX_WM97XX_H | ||
2616 | + | ||
2617 | +#include <sound/driver.h> | ||
2618 | +#include <sound/core.h> | ||
2619 | +#include <sound/pcm.h> | ||
2620 | +#include <sound/ac97_codec.h> | ||
2621 | +#include <sound/initval.h> | ||
2622 | +#include <linux/types.h> | ||
2623 | +#include <linux/list.h> | ||
2624 | +#include <linux/input.h> /* Input device layer */ | ||
2625 | + | ||
2626 | +/* | ||
2627 | + * WM97xx AC97 Touchscreen registers | ||
2628 | + */ | ||
2629 | +#define AC97_WM97XX_DIGITISER1 0x76 | ||
2630 | +#define AC97_WM97XX_DIGITISER2 0x78 | ||
2631 | +#define AC97_WM97XX_DIGITISER_RD 0x7a | ||
2632 | +#define AC97_WM9713_DIG1 0x74 | ||
2633 | +#define AC97_WM9713_DIG2 AC97_WM97XX_DIGITISER1 | ||
2634 | +#define AC97_WM9713_DIG3 AC97_WM97XX_DIGITISER2 | ||
2635 | + | ||
2636 | +/* | ||
2637 | + * WM97xx register bits | ||
2638 | + */ | ||
2639 | +#define WM97XX_POLL 0x8000 /* initiate a polling measurement */ | ||
2640 | +#define WM97XX_ADCSEL_X 0x1000 /* x coord measurement */ | ||
2641 | +#define WM97XX_ADCSEL_Y 0x2000 /* y coord measurement */ | ||
2642 | +#define WM97XX_ADCSEL_PRES 0x3000 /* pressure measurement */ | ||
2643 | +#define WM97XX_ADCSEL_MASK 0x7000 | ||
2644 | +#define WM97XX_COO 0x0800 /* enable coordinate mode */ | ||
2645 | +#define WM97XX_CTC 0x0400 /* enable continuous mode */ | ||
2646 | +#define WM97XX_CM_RATE_93 0x0000 /* 93.75Hz continuous rate */ | ||
2647 | +#define WM97XX_CM_RATE_187 0x0100 /* 187.5Hz continuous rate */ | ||
2648 | +#define WM97XX_CM_RATE_375 0x0200 /* 375Hz continuous rate */ | ||
2649 | +#define WM97XX_CM_RATE_750 0x0300 /* 750Hz continuous rate */ | ||
2650 | +#define WM97XX_CM_RATE_8K 0x00f0 /* 8kHz continuous rate */ | ||
2651 | +#define WM97XX_CM_RATE_12K 0x01f0 /* 12kHz continuous rate */ | ||
2652 | +#define WM97XX_CM_RATE_24K 0x02f0 /* 24kHz continuous rate */ | ||
2653 | +#define WM97XX_CM_RATE_48K 0x03f0 /* 48kHz continuous rate */ | ||
2654 | +#define WM97XX_CM_RATE_MASK 0x03f0 | ||
2655 | +#define WM97XX_RATE(i) (((i & 3) << 8) | ((i & 4) ? 0xf0 : 0)) | ||
2656 | +#define WM97XX_DELAY(i) ((i << 4) & 0x00f0) /* sample delay times */ | ||
2657 | +#define WM97XX_DELAY_MASK 0x00f0 | ||
2658 | +#define WM97XX_SLEN 0x0008 /* slot read back enable */ | ||
2659 | +#define WM97XX_SLT(i) ((i - 5) & 0x7) /* touchpanel slot selection (5-11) */ | ||
2660 | +#define WM97XX_SLT_MASK 0x0007 | ||
2661 | +#define WM97XX_PRP_DETW 0x4000 /* pen detect on, digitiser off, wake up */ | ||
2662 | +#define WM97XX_PRP_DET 0x8000 /* pen detect on, digitiser off, no wake up */ | ||
2663 | +#define WM97XX_PRP_DET_DIG 0xc000 /* pen detect on, digitiser on */ | ||
2664 | +#define WM97XX_RPR 0x2000 /* wake up on pen down */ | ||
2665 | +#define WM97XX_PEN_DOWN 0x8000 /* pen is down */ | ||
2666 | +#define WM97XX_ADCSRC_MASK 0x7000 /* ADC source mask */ | ||
2667 | + | ||
2668 | +#define WM97XX_AUX_ID1 0x8001 | ||
2669 | +#define WM97XX_AUX_ID2 0x8002 | ||
2670 | +#define WM97XX_AUX_ID3 0x8003 | ||
2671 | +#define WM97XX_AUX_ID4 0x8004 | ||
2672 | + | ||
2673 | + | ||
2674 | +/* WM9712 Bits */ | ||
2675 | +#define WM9712_45W 0x1000 /* set for 5-wire touchscreen */ | ||
2676 | +#define WM9712_PDEN 0x0800 /* measure only when pen down */ | ||
2677 | +#define WM9712_WAIT 0x0200 /* wait until adc is read before next sample */ | ||
2678 | +#define WM9712_PIL 0x0100 /* current used for pressure measurement. set 400uA else 200uA */ | ||
2679 | +#define WM9712_MASK_HI 0x0040 /* hi on mask pin (47) stops conversions */ | ||
2680 | +#define WM9712_MASK_EDGE 0x0080 /* rising/falling edge on pin delays sample */ | ||
2681 | +#define WM9712_MASK_SYNC 0x00c0 /* rising/falling edge on mask initiates sample */ | ||
2682 | +#define WM9712_RPU(i) (i&0x3f) /* internal pull up on pen detect (64k / rpu) */ | ||
2683 | +#define WM9712_PD(i) (0x1 << i) /* power management */ | ||
2684 | + | ||
2685 | +/* WM9712 Registers */ | ||
2686 | +#define AC97_WM9712_POWER 0x24 | ||
2687 | +#define AC97_WM9712_REV 0x58 | ||
2688 | + | ||
2689 | +/* WM9705 Bits */ | ||
2690 | +#define WM9705_PDEN 0x1000 /* measure only when pen is down */ | ||
2691 | +#define WM9705_PINV 0x0800 /* inverts sense of pen down output */ | ||
2692 | +#define WM9705_BSEN 0x0400 /* BUSY flag enable, pin47 is 1 when busy */ | ||
2693 | +#define WM9705_BINV 0x0200 /* invert BUSY (pin47) output */ | ||
2694 | +#define WM9705_WAIT 0x0100 /* wait until adc is read before next sample */ | ||
2695 | +#define WM9705_PIL 0x0080 /* current used for pressure measurement. set 400uA else 200uA */ | ||
2696 | +#define WM9705_PHIZ 0x0040 /* set PHONE and PCBEEP inputs to high impedance */ | ||
2697 | +#define WM9705_MASK_HI 0x0010 /* hi on mask stops conversions */ | ||
2698 | +#define WM9705_MASK_EDGE 0x0020 /* rising/falling edge on pin delays sample */ | ||
2699 | +#define WM9705_MASK_SYNC 0x0030 /* rising/falling edge on mask initiates sample */ | ||
2700 | +#define WM9705_PDD(i) (i & 0x000f) /* pen detect comparator threshold */ | ||
2701 | + | ||
2702 | + | ||
2703 | +/* WM9713 Bits */ | ||
2704 | +#define WM9713_PDPOL 0x0400 /* Pen down polarity */ | ||
2705 | +#define WM9713_POLL 0x0200 /* initiate a polling measurement */ | ||
2706 | +#define WM9713_CTC 0x0100 /* enable continuous mode */ | ||
2707 | +#define WM9713_ADCSEL_X 0x0002 /* X measurement */ | ||
2708 | +#define WM9713_ADCSEL_Y 0x0004 /* Y measurement */ | ||
2709 | +#define WM9713_ADCSEL_PRES 0x0008 /* Pressure measurement */ | ||
2710 | +#define WM9713_COO 0x0001 /* enable coordinate mode */ | ||
2711 | +#define WM9713_PDEN 0x0800 /* measure only when pen down */ | ||
2712 | +#define WM9713_ADCSEL_MASK 0x00fe /* ADC selection mask */ | ||
2713 | +#define WM9713_WAIT 0x0200 /* coordinate wait */ | ||
2714 | + | ||
2715 | +/* AUX ADC ID's */ | ||
2716 | +#define TS_COMP1 0x0 | ||
2717 | +#define TS_COMP2 0x1 | ||
2718 | +#define TS_BMON 0x2 | ||
2719 | +#define TS_WIPER 0x3 | ||
2720 | + | ||
2721 | +/* ID numbers */ | ||
2722 | +#define WM97XX_ID1 0x574d | ||
2723 | +#define WM9712_ID2 0x4c12 | ||
2724 | +#define WM9705_ID2 0x4c05 | ||
2725 | +#define WM9713_ID2 0x4c13 | ||
2726 | + | ||
2727 | +/* Codec GPIO's */ | ||
2728 | +#define WM97XX_MAX_GPIO 16 | ||
2729 | +#define WM97XX_GPIO_1 (1 << 1) | ||
2730 | +#define WM97XX_GPIO_2 (1 << 2) | ||
2731 | +#define WM97XX_GPIO_3 (1 << 3) | ||
2732 | +#define WM97XX_GPIO_4 (1 << 4) | ||
2733 | +#define WM97XX_GPIO_5 (1 << 5) | ||
2734 | +#define WM97XX_GPIO_6 (1 << 6) | ||
2735 | +#define WM97XX_GPIO_7 (1 << 7) | ||
2736 | +#define WM97XX_GPIO_8 (1 << 8) | ||
2737 | +#define WM97XX_GPIO_9 (1 << 9) | ||
2738 | +#define WM97XX_GPIO_10 (1 << 10) | ||
2739 | +#define WM97XX_GPIO_11 (1 << 11) | ||
2740 | +#define WM97XX_GPIO_12 (1 << 12) | ||
2741 | +#define WM97XX_GPIO_13 (1 << 13) | ||
2742 | +#define WM97XX_GPIO_14 (1 << 14) | ||
2743 | +#define WM97XX_GPIO_15 (1 << 15) | ||
2744 | + | ||
2745 | + | ||
2746 | +#define AC97_LINK_FRAME 21 /* time in uS for AC97 link frame */ | ||
2747 | + | ||
2748 | + | ||
2749 | +/*---------------- Return codes from sample reading functions ---------------*/ | ||
2750 | + | ||
2751 | +/* More data is available; call the sample gathering function again */ | ||
2752 | +#define RC_AGAIN 0x00000001 | ||
2753 | +/* The returned sample is valid */ | ||
2754 | +#define RC_VALID 0x00000002 | ||
2755 | +/* The pen is up (the first RC_VALID without RC_PENUP means pen is down) */ | ||
2756 | +#define RC_PENUP 0x00000004 | ||
2757 | +/* The pen is down (RC_VALID implies RC_PENDOWN, but sometimes it is helpful | ||
2758 | + to tell the handler that the pen is down but we don't know yet his coords, | ||
2759 | + so the handler should not sleep or wait for pendown irq) */ | ||
2760 | +#define RC_PENDOWN 0x00000008 | ||
2761 | + | ||
2762 | +/* The wm97xx driver provides a private API for writing platform-specific | ||
2763 | + * drivers. | ||
2764 | + */ | ||
2765 | + | ||
2766 | +/* The structure used to return arch specific sampled data into */ | ||
2767 | +struct wm97xx_data { | ||
2768 | + int x; | ||
2769 | + int y; | ||
2770 | + int p; | ||
2771 | +}; | ||
2772 | + | ||
2773 | +/* Codec GPIO status | ||
2774 | + */ | ||
2775 | +typedef enum { | ||
2776 | + WM97XX_GPIO_HIGH, | ||
2777 | + WM97XX_GPIO_LOW | ||
2778 | +} wm97xx_gpio_status_t; | ||
2779 | + | ||
2780 | +/* Codec GPIO direction | ||
2781 | + */ | ||
2782 | +typedef enum { | ||
2783 | + WM97XX_GPIO_IN, | ||
2784 | + WM97XX_GPIO_OUT | ||
2785 | +} wm97xx_gpio_dir_t; | ||
2786 | + | ||
2787 | +/* Codec GPIO polarity | ||
2788 | + */ | ||
2789 | +typedef enum { | ||
2790 | + WM97XX_GPIO_POL_HIGH, | ||
2791 | + WM97XX_GPIO_POL_LOW | ||
2792 | +} wm97xx_gpio_pol_t; | ||
2793 | + | ||
2794 | +/* Codec GPIO sticky | ||
2795 | + */ | ||
2796 | +typedef enum { | ||
2797 | + WM97XX_GPIO_STICKY, | ||
2798 | + WM97XX_GPIO_NOTSTICKY | ||
2799 | +} wm97xx_gpio_sticky_t; | ||
2800 | + | ||
2801 | +/* Codec GPIO wake | ||
2802 | + */ | ||
2803 | +typedef enum { | ||
2804 | + WM97XX_GPIO_WAKE, | ||
2805 | + WM97XX_GPIO_NOWAKE | ||
2806 | +} wm97xx_gpio_wake_t; | ||
2807 | + | ||
2808 | + | ||
2809 | +/* | ||
2810 | + * Digitiser ioctl commands | ||
2811 | + */ | ||
2812 | +#define WM97XX_DIG_START 0x1 | ||
2813 | +#define WM97XX_DIG_STOP 0x2 | ||
2814 | +#define WM97XX_PHY_INIT 0x3 | ||
2815 | +#define WM97XX_AUX_PREPARE 0x4 | ||
2816 | +#define WM97XX_DIG_RESTORE 0x5 | ||
2817 | + | ||
2818 | +struct wm97xx; | ||
2819 | +extern struct wm97xx_codec_drv wm97xx_codec; | ||
2820 | + | ||
2821 | +/* | ||
2822 | + * Codec driver interface - allows mapping to WM9705/12/13 and newer codecs | ||
2823 | + */ | ||
2824 | +struct wm97xx_codec_drv { | ||
2825 | + u16 id; | ||
2826 | + char *name; | ||
2827 | + int (*poll_sample) (struct wm97xx *, int adcsel, int *sample); /* read 1 sample */ | ||
2828 | + int (*poll_touch) (struct wm97xx *, struct wm97xx_data *); /* read X,Y,[P] in poll */ | ||
2829 | + int (*digitiser_ioctl) (struct wm97xx *, int cmd); | ||
2830 | + int (*acc_enable) (struct wm97xx *, int enable); | ||
2831 | +}; | ||
2832 | + | ||
2833 | + | ||
2834 | +/* Machine specific and accelerated touch operations */ | ||
2835 | +struct wm97xx_mach_ops { | ||
2836 | + | ||
2837 | + /* accelerated touch readback - coords are transmited on AC97 link */ | ||
2838 | + int acc_enabled; | ||
2839 | + void (*acc_pen_up) (struct wm97xx *); | ||
2840 | + int (*acc_pen_down) (struct wm97xx *); | ||
2841 | + int (*acc_startup) (struct wm97xx *); | ||
2842 | + void (*acc_shutdown) (struct wm97xx *); | ||
2843 | + | ||
2844 | + /* pre and post sample - can be used to minimise any analog noise */ | ||
2845 | + void (*pre_sample) (int); /* function to run before sampling */ | ||
2846 | + void (*post_sample) (int); /* function to run after sampling */ | ||
2847 | +}; | ||
2848 | + | ||
2849 | +struct wm97xx { | ||
2850 | + u16 dig[3], id, gpio[6], misc; /* Cached codec registers */ | ||
2851 | + u16 dig_save[3]; /* saved during aux reading */ | ||
2852 | + struct wm97xx_codec_drv *codec; /* attached codec driver*/ | ||
2853 | + struct input_dev* input_dev; /* touchscreen input device */ | ||
2854 | + ac97_t *ac97; /* ALSA codec access */ | ||
2855 | + struct device *dev; /* ALSA device */ | ||
2856 | + struct device *battery_dev; | ||
2857 | + struct device *touch_dev; | ||
2858 | + struct wm97xx_mach_ops *mach_ops; | ||
2859 | + struct mutex codec_mutex; | ||
2860 | + struct completion ts_init; | ||
2861 | + struct completion ts_exit; | ||
2862 | + struct task_struct *ts_task; | ||
2863 | + unsigned int pen_irq; /* Pen IRQ number in use */ | ||
2864 | + wait_queue_head_t pen_irq_wait; /* Pen IRQ wait queue */ | ||
2865 | + struct workqueue_struct *pen_irq_workq; | ||
2866 | + struct work_struct pen_event_work; | ||
2867 | + u16 acc_slot; /* AC97 slot used for acc touch data */ | ||
2868 | + u16 acc_rate; /* acc touch data rate */ | ||
2869 | + unsigned int ts_use_count; | ||
2870 | + unsigned pen_is_down:1; /* Pen is down */ | ||
2871 | + unsigned aux_waiting:1; /* aux measurement waiting */ | ||
2872 | + unsigned pen_probably_down:1; /* used in polling mode */ | ||
2873 | +}; | ||
2874 | + | ||
2875 | +/* Codec GPIO access (not supported on WM9705) | ||
2876 | + * This can be used to set/get codec GPIO and Virtual GPIO status. | ||
2877 | + */ | ||
2878 | +wm97xx_gpio_status_t wm97xx_get_gpio(struct wm97xx *wm, u32 gpio); | ||
2879 | +void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio, | ||
2880 | + wm97xx_gpio_status_t status); | ||
2881 | +void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, | ||
2882 | + wm97xx_gpio_dir_t dir, | ||
2883 | + wm97xx_gpio_pol_t pol, | ||
2884 | + wm97xx_gpio_sticky_t sticky, | ||
2885 | + wm97xx_gpio_wake_t wake); | ||
2886 | + | ||
2887 | +/* codec AC97 IO access */ | ||
2888 | +int wm97xx_reg_read(struct wm97xx *wm, u16 reg); | ||
2889 | +void wm97xx_reg_write(struct wm97xx *wm, u16 reg, u16 val); | ||
2890 | + | ||
2891 | +/* aux adc readback */ | ||
2892 | +int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel); | ||
2893 | + | ||
2894 | +/* machine ops */ | ||
2895 | +int wm97xx_register_mach_ops(struct wm97xx *, struct wm97xx_mach_ops *); | ||
2896 | +void wm97xx_unregister_mach_ops(struct wm97xx *); | ||
2897 | + | ||
2898 | +extern struct bus_type wm97xx_bus_type; | ||
2899 | +#endif | ||