From 53d19e1c1ffda8e7724d9d6658e3bb9acde758a7 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Sun, 20 Jan 2008 17:03:32 +0000 Subject: 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 --- .../linux-rp-2.6.23/mmcsd_no_scr_check-r2.patch | 29 - .../packages/linux/linux-rp-2.6.23/pda-power.patch | 3373 -------------------- .../linux/linux-rp-2.6.23/versatile-armv6.patch | 19 + .../linux/linux-rp-2.6.23/vt_ioctl_race.patch | 46 - .../linux/linux-rp-2.6.23/w100fb-unused-var.patch | 17 - .../linux-rp-2.6.23/wm9712-reset-loop-r2.patch | 44 + .../wm9712-suspend-cold-res-r2.patch | 16 + .../linux-rp-2.6.23/wm97xx-lg13-r0-fix-r0.patch | 128 + .../linux/linux-rp-2.6.23/wm97xx-lg13-r0.patch | 2899 +++++++++++++++++ 9 files changed, 3106 insertions(+), 3465 deletions(-) delete mode 100644 meta/packages/linux/linux-rp-2.6.23/mmcsd_no_scr_check-r2.patch delete mode 100644 meta/packages/linux/linux-rp-2.6.23/pda-power.patch create mode 100644 meta/packages/linux/linux-rp-2.6.23/versatile-armv6.patch delete mode 100644 meta/packages/linux/linux-rp-2.6.23/vt_ioctl_race.patch delete mode 100644 meta/packages/linux/linux-rp-2.6.23/w100fb-unused-var.patch create mode 100644 meta/packages/linux/linux-rp-2.6.23/wm9712-reset-loop-r2.patch create mode 100644 meta/packages/linux/linux-rp-2.6.23/wm9712-suspend-cold-res-r2.patch create mode 100644 meta/packages/linux/linux-rp-2.6.23/wm97xx-lg13-r0-fix-r0.patch create mode 100644 meta/packages/linux/linux-rp-2.6.23/wm97xx-lg13-r0.patch (limited to 'meta/packages/linux/linux-rp-2.6.23') 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 ac2245f08..000000000 --- a/meta/packages/linux/linux-rp-2.6.23/mmcsd_no_scr_check-r2.patch +++ /dev/null @@ -1,29 +0,0 @@ ---- - drivers/mmc/core/sd.c | 11 ++++++----- - 1 file changed, 6 insertions(+), 5 deletions(-) - -Index: linux-2.6.23/drivers/mmc/core/sd.c -=================================================================== ---- linux-2.6.23.orig/drivers/mmc/core/sd.c 2007-10-17 11:33:26.000000000 +0200 -+++ linux-2.6.23/drivers/mmc/core/sd.c 2007-10-17 11:33:49.000000000 +0200 -@@ -173,14 +173,15 @@ - - scr_struct = UNSTUFF_BITS(resp, 60, 4); - if (scr_struct != 0) { -- printk(KERN_ERR "%s: unrecognised SCR structure version %d\n", -+ printk(KERN_WARNING "%s: unrecognised SCR structure version %d\n", - mmc_hostname(card->host), scr_struct); -- return -EINVAL; -+ scr->sda_vsn = 0; -+ scr->bus_widths = 0; -+ } else { -+ scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4); -+ scr->bus_widths = UNSTUFF_BITS(resp, 48, 4); - } - -- scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4); -- scr->bus_widths = UNSTUFF_BITS(resp, 48, 4); -- - return 0; - } - 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 face2f4ef..000000000 --- a/meta/packages/linux/linux-rp-2.6.23/pda-power.patch +++ /dev/null @@ -1,3373 +0,0 @@ ---- - arch/arm/Kconfig | 2 - drivers/Kconfig | 2 - drivers/Makefile | 1 - drivers/power/Kconfig | 70 +++++ - drivers/power/Makefile | 28 ++ - drivers/power/adc_battery.c | 278 +++++++++++++++++++++ - drivers/power/apm_power.c | 247 +++++++++++++++++++ - drivers/power/ds2760_battery.c | 475 +++++++++++++++++++++++++++++++++++++ - drivers/power/micro_battery.c | 257 ++++++++++++++++++++ - drivers/power/olpc_battery.c | 302 +++++++++++++++++++++++ - drivers/power/pda_power.c | 263 ++++++++++++++++++++ - drivers/power/pmu_battery.c | 215 ++++++++++++++++ - drivers/power/power_supply.h | 42 +++ - drivers/power/power_supply_core.c | 168 +++++++++++++ - drivers/power/power_supply_leds.c | 188 ++++++++++++++ - drivers/power/power_supply_sysfs.c | 289 ++++++++++++++++++++++ - drivers/power/simpad-battery.c | 242 ++++++++++++++++++ - include/linux/power_supply.h | 175 +++++++++++++ - 18 files changed, 3244 insertions(+) - -Index: linux-2.6.22/drivers/power/adc_battery.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/adc_battery.c 2007-08-23 12:26:28.000000000 +0200 -@@ -0,0 +1,278 @@ -+/* -+ * Copyright (c) 2007 Paul Sokolovsky -+ * -+ * This program is free software; you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation; either version 2 of the License, or -+ * (at your option) any later version. -+ * -+ */ -+ -+//#define DEBUG -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#include -+ -+#define PIN_NO_VOLT 0 -+#define PIN_NO_CURR 1 -+#define PIN_NO_TEMP 2 -+ -+struct battery_adc_priv { -+ struct power_supply batt_cdev; -+ -+ struct battery_adc_platform_data *pdata; -+ -+ struct adc_request req; -+ struct adc_sense pins[3]; -+ struct adc_sense last_good_pins[3]; -+ -+ struct workqueue_struct *wq; -+ struct delayed_work work; -+}; -+ -+/* -+ * Battery properties -+ */ -+ -+static int adc_battery_get_property(struct power_supply *psy, -+ enum power_supply_property psp, -+ union power_supply_propval *val) -+{ -+ struct battery_adc_priv* drvdata = (struct battery_adc_priv*)psy; -+ int voltage; -+ -+ switch (psp) { -+ case POWER_SUPPLY_PROP_STATUS: -+ val->intval = drvdata->pdata->charge_status; -+ break; -+ case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: -+ val->intval = drvdata->pdata->battery_info.voltage_max_design; -+ break; -+ case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: -+ val->intval = drvdata->pdata->battery_info.voltage_min_design; -+ break; -+ case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: -+ val->intval = drvdata->pdata->battery_info.charge_full_design; -+ break; -+ case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN: -+ val->intval = drvdata->pdata->battery_info.charge_empty_design; -+ break; -+ case POWER_SUPPLY_PROP_VOLTAGE_NOW: -+ val->intval = drvdata->last_good_pins[PIN_NO_VOLT].value * drvdata->pdata->voltage_mult; -+ break; -+ case POWER_SUPPLY_PROP_CURRENT_NOW: -+ val->intval = drvdata->last_good_pins[PIN_NO_CURR].value * drvdata->pdata->current_mult; -+ break; -+ case POWER_SUPPLY_PROP_CHARGE_NOW: -+ /* We do calculations in mX, not uX, because todo it in uX we should use "long long"s, -+ * which is a mess (need to use do_div) when you need divide operation). */ -+ voltage = drvdata->last_good_pins[PIN_NO_VOLT].value * drvdata->pdata->voltage_mult; -+ val->intval = ((voltage/1000 - drvdata->pdata->battery_info.voltage_min_design/1000) * -+ (drvdata->pdata->battery_info.charge_full_design/1000 - -+ drvdata->pdata->battery_info.charge_empty_design/1000)) / -+ (drvdata->pdata->battery_info.voltage_max_design/1000 - -+ drvdata->pdata->battery_info.voltage_min_design/1000); -+ val->intval *= 1000; /* convert final result to uX */ -+ break; -+ case POWER_SUPPLY_PROP_TEMP: -+ val->intval = drvdata->last_good_pins[PIN_NO_TEMP].value * drvdata->pdata->temperature_mult / 1000; -+ break; -+ default: -+ return -EINVAL; -+ }; -+ return 0; -+} -+ -+/* -+ * Driver body -+ */ -+ -+static void adc_battery_query(struct battery_adc_priv *drvdata) -+{ -+ struct battery_adc_platform_data *pdata = drvdata->pdata; -+ int powered, charging; -+ -+ adc_request_sample(&drvdata->req); -+ -+ powered = power_supply_am_i_supplied(&drvdata->batt_cdev); -+ charging = pdata->is_charging ? pdata->is_charging() : -1; -+ -+ if (powered && charging) -+ pdata->charge_status = POWER_SUPPLY_STATUS_CHARGING; -+ else if (powered && !charging && charging != -1) -+ pdata->charge_status = POWER_SUPPLY_STATUS_FULL; -+ else -+ pdata->charge_status = POWER_SUPPLY_STATUS_DISCHARGING; -+ -+ /* Throw away invalid samples, this may happen soon after resume for example. */ -+ if (drvdata->pins[PIN_NO_VOLT].value > 0) { -+ memcpy(drvdata->last_good_pins, drvdata->pins, sizeof(drvdata->pins)); -+#ifdef DEBUG -+ printk("%d %d %d\n", drvdata->pins[PIN_NO_VOLT].value, -+ drvdata->pins[PIN_NO_CURR].value, -+ drvdata->pins[PIN_NO_TEMP].value); -+#endif -+ } -+} -+ -+static void adc_battery_charge_power_changed(struct power_supply *bat) -+{ -+ struct battery_adc_priv *drvdata = (struct battery_adc_priv*)bat; -+ cancel_delayed_work(&drvdata->work); -+ queue_delayed_work(drvdata->wq, &drvdata->work, 0); -+} -+ -+static void adc_battery_work_func(struct work_struct *work) -+{ -+ struct delayed_work *delayed_work = container_of(work, struct delayed_work, work); -+ struct battery_adc_priv *drvdata = container_of(delayed_work, struct battery_adc_priv, work); -+ -+ adc_battery_query(drvdata); -+ power_supply_changed(&drvdata->batt_cdev); -+ -+ queue_delayed_work(drvdata->wq, &drvdata->work, (5000 * HZ) / 1000); -+} -+ -+static int adc_battery_probe(struct platform_device *pdev) -+{ -+ int retval; -+ struct battery_adc_platform_data *pdata = pdev->dev.platform_data; -+ struct battery_adc_priv *drvdata; -+ int i, j; -+ enum power_supply_property props[] = { -+ POWER_SUPPLY_PROP_STATUS, -+ POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, -+ POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, -+ POWER_SUPPLY_PROP_VOLTAGE_NOW, -+ POWER_SUPPLY_PROP_CURRENT_NOW, -+ POWER_SUPPLY_PROP_CHARGE_NOW, -+ POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, -+ POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN, -+ POWER_SUPPLY_PROP_TEMP, -+ }; -+ -+ // Initialize ts data structure. -+ drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); -+ if (!drvdata) -+ return -ENOMEM; -+ -+ drvdata->batt_cdev.name = pdata->battery_info.name; -+ drvdata->batt_cdev.use_for_apm = pdata->battery_info.use_for_apm; -+ drvdata->batt_cdev.num_properties = ARRAY_SIZE(props); -+ drvdata->batt_cdev.get_property = adc_battery_get_property; -+ drvdata->batt_cdev.external_power_changed = -+ adc_battery_charge_power_changed; -+ -+ if (!pdata->voltage_pin) { -+ drvdata->batt_cdev.num_properties--; -+ props[3] = -1; -+ } -+ if (!pdata->current_pin) { -+ drvdata->batt_cdev.num_properties--; -+ props[4] = -1; -+ } -+ if (!pdata->temperature_pin) { -+ drvdata->batt_cdev.num_properties--; -+ props[8] = -1; -+ } -+ -+ drvdata->batt_cdev.properties = kmalloc( -+ sizeof(*drvdata->batt_cdev.properties) * -+ drvdata->batt_cdev.num_properties, GFP_KERNEL); -+ if (!drvdata->batt_cdev.properties) -+ return -ENOMEM; -+ -+ j = 0; -+ for (i = 0; i < ARRAY_SIZE(props); i++) { -+ if (props[i] == -1) -+ continue; -+ drvdata->batt_cdev.properties[j++] = props[i]; -+ } -+ -+ retval = power_supply_register(&pdev->dev, &drvdata->batt_cdev); -+ if (retval) { -+ printk("adc-battery: Error registering battery classdev"); -+ return retval; -+ } -+ -+ drvdata->req.senses = drvdata->pins; -+ drvdata->req.num_senses = ARRAY_SIZE(drvdata->pins); -+ drvdata->pins[PIN_NO_VOLT].name = pdata->voltage_pin; -+ drvdata->pins[PIN_NO_CURR].name = pdata->current_pin; -+ drvdata->pins[PIN_NO_TEMP].name = pdata->temperature_pin; -+ -+ adc_request_register(&drvdata->req); -+ -+ /* Here we assume raw values in mV */ -+ if (!pdata->voltage_mult) -+ pdata->voltage_mult = 1000; -+ /* Here we assume raw values in mA */ -+ if (!pdata->current_mult) -+ pdata->current_mult = 1000; -+ /* Here we assume raw values in 1/10 C */ -+ if (!pdata->temperature_mult) -+ pdata->temperature_mult = 1000; -+ -+ drvdata->pdata = pdata; -+ pdata->drvdata = drvdata; /* Seems ugly, we need better solution */ -+ -+ platform_set_drvdata(pdev, drvdata); -+ -+ // Load initial values ASAP -+ adc_battery_query(drvdata); -+ -+ // Still schedule next sampling soon -+ INIT_DELAYED_WORK(&drvdata->work, adc_battery_work_func); -+ drvdata->wq = create_workqueue(pdev->dev.bus_id); -+ if (!drvdata->wq) -+ return -ESRCH; -+ -+ queue_delayed_work(drvdata->wq, &drvdata->work, (5000 * HZ) / 1000); -+ -+ return retval; -+} -+ -+static int adc_battery_remove(struct platform_device *pdev) -+{ -+ struct battery_adc_priv *drvdata = platform_get_drvdata(pdev); -+ cancel_delayed_work(&drvdata->work); -+ destroy_workqueue(drvdata->wq); -+ power_supply_unregister(&drvdata->batt_cdev); -+ adc_request_unregister(&drvdata->req); -+ kfree(drvdata->batt_cdev.properties); -+ return 0; -+} -+ -+static struct platform_driver adc_battery_driver = { -+ .driver = { -+ .name = "adc-battery", -+ }, -+ .probe = adc_battery_probe, -+ .remove = adc_battery_remove, -+}; -+ -+static int __init adc_battery_init(void) -+{ -+ return platform_driver_register(&adc_battery_driver); -+} -+ -+static void __exit adc_battery_exit(void) -+{ -+ platform_driver_unregister(&adc_battery_driver); -+} -+ -+module_init(adc_battery_init) -+module_exit(adc_battery_exit) -+ -+MODULE_AUTHOR("Paul Sokolovsky"); -+MODULE_DESCRIPTION("Battery driver for ADC device"); -+MODULE_LICENSE("GPL"); -Index: linux-2.6.22/drivers/power/apm_power.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/apm_power.c 2007-08-23 12:13:52.000000000 +0200 -@@ -0,0 +1,247 @@ -+/* -+ * Copyright (c) 2007 Anton Vorontsov -+ * Copyright (c) 2007 Eugeny Boger -+ * -+ * Author: Eugeny Boger -+ * -+ * Use consistent with the GNU GPL is permitted, -+ * provided that this copyright notice is -+ * preserved in its entirety in all copies and derived works. -+ */ -+ -+#include -+#include -+#include -+ -+#define PSY_PROP(psy, prop, val) psy->get_property(psy, \ -+ POWER_SUPPLY_PROP_##prop, val) -+ -+#define _MPSY_PROP(prop, val) main_battery->get_property(main_battery, \ -+ prop, val) -+ -+#define MPSY_PROP(prop, val) _MPSY_PROP(POWER_SUPPLY_PROP_##prop, val) -+ -+static struct power_supply *main_battery; -+ -+static void find_main_battery(void) -+{ -+ struct device *dev; -+ struct power_supply *bat, *batm; -+ union power_supply_propval full; -+ int max_charge = 0; -+ -+ main_battery = NULL; -+ batm = NULL; -+ list_for_each_entry(dev, &power_supply_class->devices, node) { -+ bat = dev_get_drvdata(dev); -+ /* If none of battery devices cantains 'use_for_apm' flag, -+ choice one with maximum design charge */ -+ if (!PSY_PROP(bat, CHARGE_FULL_DESIGN, &full)) { -+ if (full.intval > max_charge) { -+ batm = bat; -+ max_charge = full.intval; -+ } -+ } -+ -+ if (bat->use_for_apm) -+ main_battery = bat; -+ } -+ if (!main_battery) -+ main_battery = batm; -+ -+ return; -+} -+ -+static int calculate_time(int status) -+{ -+ union power_supply_propval charge_full, charge_empty; -+ union power_supply_propval charge, I; -+ -+ if (MPSY_PROP(CHARGE_FULL, &charge_full)) { -+ /* if battery can't report this property, use design value */ -+ if (MPSY_PROP(CHARGE_FULL_DESIGN, &charge_full)) -+ return -1; -+ } -+ -+ if (MPSY_PROP(CHARGE_EMPTY, &charge_empty)) { -+ /* if battery can't report this property, use design value */ -+ if (MPSY_PROP(CHARGE_EMPTY_DESIGN, &charge_empty)) -+ charge_empty.intval = 0; -+ } -+ -+ if (MPSY_PROP(CHARGE_AVG, &charge)) { -+ /* if battery can't report average value, use momentary */ -+ if (MPSY_PROP(CHARGE_NOW, &charge)) -+ return -1; -+ } -+ -+ if (MPSY_PROP(CURRENT_AVG, &I)) { -+ /* if battery can't report average value, use momentary */ -+ if (MPSY_PROP(CURRENT_NOW, &I)) -+ return -1; -+ } -+ -+ if (I.intval == 0) -+ return 0; -+ else if (status == POWER_SUPPLY_STATUS_CHARGING) -+ return ((charge.intval - charge_full.intval) * 60L) / -+ I.intval; -+ else -+ return -((charge.intval - charge_empty.intval) * 60L) / -+ I.intval; -+} -+ -+static int calculate_capacity(int using_charge) -+{ -+ enum power_supply_property full_prop, empty_prop; -+ enum power_supply_property full_design_prop, empty_design_prop; -+ enum power_supply_property now_prop, avg_prop; -+ union power_supply_propval empty, full, cur; -+ int ret; -+ -+ if (using_charge) { -+ full_prop = POWER_SUPPLY_PROP_CHARGE_FULL; -+ empty_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY; -+ full_design_prop = POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN; -+ empty_design_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN; -+ now_prop = POWER_SUPPLY_PROP_CHARGE_NOW; -+ avg_prop = POWER_SUPPLY_PROP_CHARGE_AVG; -+ } -+ else { -+ full_prop = POWER_SUPPLY_PROP_ENERGY_FULL; -+ empty_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY; -+ full_design_prop = POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN; -+ empty_design_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN; -+ now_prop = POWER_SUPPLY_PROP_ENERGY_NOW; -+ avg_prop = POWER_SUPPLY_PROP_ENERGY_AVG; -+ } -+ -+ if (_MPSY_PROP(full_prop, &full)) { -+ /* if battery can't report this property, use design value */ -+ if (_MPSY_PROP(full_design_prop, &full)) -+ return -1; -+ } -+ -+ if (_MPSY_PROP(avg_prop, &cur)) { -+ /* if battery can't report average value, use momentary */ -+ if (_MPSY_PROP(now_prop, &cur)) -+ return -1; -+ } -+ -+ if (_MPSY_PROP(empty_prop, &empty)) { -+ /* if battery can't report this property, use design value */ -+ if (_MPSY_PROP(empty_design_prop, &empty)) -+ empty.intval = 0; -+ } -+ -+ if (full.intval - empty.intval) -+ ret = ((cur.intval - empty.intval) * 100L) / -+ (full.intval - empty.intval); -+ else -+ return -1; -+ -+ if (ret > 100) -+ return 100; -+ else if (ret < 0) -+ return 0; -+ -+ return ret; -+} -+ -+static void apm_battery_apm_get_power_status(struct apm_power_info *info) -+{ -+ union power_supply_propval status; -+ union power_supply_propval capacity, time_to_full, time_to_empty; -+ -+ down(&power_supply_class->sem); -+ find_main_battery(); -+ if (!main_battery) { -+ up(&power_supply_class->sem); -+ return; -+ } -+ -+ /* status */ -+ -+ if (MPSY_PROP(STATUS, &status)) -+ status.intval = POWER_SUPPLY_STATUS_UNKNOWN; -+ -+ /* ac line status */ -+ -+ if ((status.intval == POWER_SUPPLY_STATUS_CHARGING) || -+ (status.intval == POWER_SUPPLY_STATUS_NOT_CHARGING) || -+ (status.intval == POWER_SUPPLY_STATUS_FULL)) -+ info->ac_line_status = APM_AC_ONLINE; -+ else -+ info->ac_line_status = APM_AC_OFFLINE; -+ -+ /* battery life (i.e. capacity, in percents) */ -+ -+ if (MPSY_PROP(CAPACITY, &capacity) == 0) -+ info->battery_life = capacity.intval; -+ else { -+ /* try calculate using energy */ -+ info->battery_life = calculate_capacity(0); -+ /* if failed try calculate using charge instead */ -+ if (info->battery_life == -1) -+ info->battery_life = calculate_capacity(1); -+ } -+ -+ /* charging status */ -+ -+ if (status.intval == POWER_SUPPLY_STATUS_CHARGING) -+ info->battery_status = APM_BATTERY_STATUS_CHARGING; -+ else { -+ if (info->battery_life > 50) -+ info->battery_status = APM_BATTERY_STATUS_HIGH; -+ else if (info->battery_life > 5) -+ info->battery_status = APM_BATTERY_STATUS_LOW; -+ else -+ info->battery_status = APM_BATTERY_STATUS_CRITICAL; -+ } -+ info->battery_flag = info->battery_status; -+ -+ /* time */ -+ -+ info->units = APM_UNITS_MINS; -+ -+ if (status.intval == POWER_SUPPLY_STATUS_CHARGING) { -+ if (MPSY_PROP(TIME_TO_FULL_AVG, &time_to_full)) { -+ if (MPSY_PROP(TIME_TO_FULL_NOW, &time_to_full)) -+ info->time = calculate_time(status.intval); -+ else -+ info->time = time_to_full.intval / 60; -+ } -+ } -+ else { -+ if (MPSY_PROP(TIME_TO_EMPTY_AVG, &time_to_empty)) { -+ if (MPSY_PROP(TIME_TO_EMPTY_NOW, &time_to_empty)) -+ info->time = calculate_time(status.intval); -+ else -+ info->time = time_to_empty.intval / 60; -+ } -+ } -+ -+ up(&power_supply_class->sem); -+ return; -+} -+ -+static int __init apm_battery_init(void) -+{ -+ printk(KERN_INFO "APM Battery Driver\n"); -+ -+ apm_get_power_status = apm_battery_apm_get_power_status; -+ return 0; -+} -+ -+static void __exit apm_battery_exit(void) -+{ -+ apm_get_power_status = NULL; -+ return; -+} -+ -+module_init(apm_battery_init); -+module_exit(apm_battery_exit); -+ -+MODULE_AUTHOR("Eugeny Boger "); -+MODULE_DESCRIPTION("APM emulation driver for battery monitoring class"); -+MODULE_LICENSE("GPL"); -Index: linux-2.6.22/drivers/power/ds2760_battery.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/ds2760_battery.c 2007-08-23 12:13:52.000000000 +0200 -@@ -0,0 +1,475 @@ -+/* -+ * Driver for batteries with DS2760 chips inside. -+ * -+ * Copyright (c) 2007 Anton Vorontsov -+ * 2004-2007 Matt Reimer -+ * 2004 Szabolcs Gyurko -+ * -+ * Use consistent with the GNU GPL is permitted, -+ * provided that this copyright notice is -+ * preserved in its entirety in all copies and derived works. -+ * -+ * Author: Anton Vorontsov -+ * February 2007 -+ * -+ * Matt Reimer -+ * April 2004, 2005, 2007 -+ * -+ * Szabolcs Gyurko -+ * September 2004 -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#include "../w1/w1.h" -+#include "../w1/slaves/w1_ds2760.h" -+ -+struct ds2760_device_info { -+ struct device *dev; -+ -+ /* DS2760 data, valid after calling ds2760_battery_read_status() */ -+ unsigned long update_time; /* jiffies when data read */ -+ char raw[DS2760_DATA_SIZE]; /* raw DS2760 data */ -+ int voltage_raw; /* units of 4.88 mV */ -+ int voltage_uV; /* units of uV */ -+ int current_raw; /* units of 0.625 mA */ -+ int current_uA; /* units of uA */ -+ int accum_current_raw; /* units of 0.25 mAh */ -+ int accum_current_uAh; /* units of uAh */ -+ int temp_raw; /* units of 0.125 C */ -+ int temp_C; /* units of 0.1 C */ -+ int rated_capacity; /* units of uAh */ -+ int rem_capacity; /* percentage */ -+ int full_active_uAh; /* units of uAh */ -+ int empty_uAh; /* units of uAh */ -+ int life_sec; /* units of seconds */ -+ int charge_status; /* POWER_SUPPLY_STATUS_* */ -+ -+ int full_counter; -+ struct power_supply bat; -+ struct device *w1_dev; -+ struct workqueue_struct *monitor_wqueue; -+ struct delayed_work monitor_work; -+}; -+ -+static unsigned int cache_time = 1000; -+module_param(cache_time, uint, 0644); -+MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); -+ -+/* Some batteries have their rated capacity stored a N * 10 mAh, while -+ * others use an index into this table. */ -+static int rated_capacities[] = { -+ 0, -+ 920, /* Samsung */ -+ 920, /* BYD */ -+ 920, /* Lishen */ -+ 920, /* NEC */ -+ 1440, /* Samsung */ -+ 1440, /* BYD */ -+ 1440, /* Lishen */ -+ 1440, /* NEC */ -+ 2880, /* Samsung */ -+ 2880, /* BYD */ -+ 2880, /* Lishen */ -+ 2880 /* NEC */ -+}; -+ -+/* array is level at temps 0C, 10C, 20C, 30C, 40C -+ * temp is in Celsius */ -+static int battery_interpolate(int array[], int temp) -+{ -+ int index, dt; -+ -+ if (temp <= 0) -+ return array[0]; -+ if (temp >= 40) -+ return array[4]; -+ -+ index = temp / 10; -+ dt = temp % 10; -+ -+ return array[index] + (((array[index + 1] - array[index]) * dt) / 10); -+} -+ -+static int ds2760_battery_read_status(struct ds2760_device_info *di) -+{ -+ int ret, i, start, count, scale[5]; -+ -+ if (di->update_time && time_before(jiffies, di->update_time + -+ msecs_to_jiffies(cache_time))) -+ return 0; -+ -+ /* The first time we read the entire contents of SRAM/EEPROM, -+ * but after that we just read the interesting bits that change. */ -+ if (di->update_time == 0) { -+ start = 0; -+ count = DS2760_DATA_SIZE; -+ } -+ else { -+ start = DS2760_VOLTAGE_MSB; -+ count = DS2760_TEMP_LSB - start + 1; -+ } -+ -+ ret = w1_ds2760_read(di->w1_dev, di->raw + start, start, count); -+ if (ret != count) { -+ dev_warn(di->dev, "call to w1_ds2760_read failed (0x%p)\n", -+ di->w1_dev); -+ return 1; -+ } -+ -+ di->update_time = jiffies; -+ -+ /* DS2760 reports voltage in units of 4.88mV, but the battery class -+ * reports in units of uV, so convert by multiplying by 4880. */ -+ di->voltage_raw = (di->raw[DS2760_VOLTAGE_MSB] << 3) | -+ (di->raw[DS2760_VOLTAGE_LSB] >> 5); -+ di->voltage_uV = di->voltage_raw * 4880; -+ -+ /* DS2760 reports current in signed units of 0.625mA, but the battery -+ * class reports in units of uA, so convert by multiplying by 625. */ -+ di->current_raw = -+ (((signed char)di->raw[DS2760_CURRENT_MSB]) << 5) | -+ (di->raw[DS2760_CURRENT_LSB] >> 3); -+ di->current_uA = di->current_raw * 625; -+ -+ /* DS2760 reports accumulated current in signed units of 0.25mAh. */ -+ di->accum_current_raw = -+ (((signed char)di->raw[DS2760_CURRENT_ACCUM_MSB]) << 8) | -+ di->raw[DS2760_CURRENT_ACCUM_LSB]; -+ di->accum_current_uAh = di->accum_current_raw * 250; -+ -+ /* DS2760 reports temperature in signed units of 0.125C, but the -+ * battery class reports in units of 1/10 C, so we convert by -+ * multiplying by .125 * 10 = 1.25. */ -+ di->temp_raw = (((signed char)di->raw[DS2760_TEMP_MSB]) << 3) | -+ (di->raw[DS2760_TEMP_LSB] >> 5); -+ di->temp_C = di->temp_raw + (di->temp_raw / 4); -+ -+ /* At least some battery monitors (e.g. HP iPAQ) store the battery's -+ * maximum rated capacity. */ -+ if (di->raw[DS2760_RATED_CAPACITY] < ARRAY_SIZE(rated_capacities)) -+ di->rated_capacity = rated_capacities[ -+ (unsigned int)di->raw[DS2760_RATED_CAPACITY]]; -+ else -+ di->rated_capacity = di->raw[DS2760_RATED_CAPACITY] * 10; -+ -+ di->rated_capacity *= 1000; /* convert to uAh */ -+ -+ /* Calculate the full level at the present temperature. */ -+ di->full_active_uAh = di->raw[DS2760_ACTIVE_FULL] << 8 | -+ di->raw[DS2760_ACTIVE_FULL + 1]; -+ -+ scale[0] = di->raw[DS2760_ACTIVE_FULL] << 8 | -+ di->raw[DS2760_ACTIVE_FULL + 1]; -+ for (i = 1; i < 5; i++) -+ scale[i] = scale[i - 1] + di->raw[DS2760_ACTIVE_FULL + 2 + i]; -+ -+ di->full_active_uAh = battery_interpolate(scale, di->temp_C / 10); -+ di->full_active_uAh *= 1000; /* convert to uAh */ -+ -+ /* Calculate the empty level at the present temperature. */ -+ scale[4] = di->raw[DS2760_ACTIVE_EMPTY + 4]; -+ for (i = 3; i >= 0; i--) -+ scale[i] = scale[i + 1] + di->raw[DS2760_ACTIVE_EMPTY + i]; -+ -+ di->empty_uAh = battery_interpolate(scale, di->temp_C / 10); -+ di->empty_uAh *= 1000; /* convert to uAh */ -+ -+ /* From Maxim Application Note 131: remaining capacity = -+ * ((ICA - Empty Value) / (Full Value - Empty Value)) x 100% */ -+ di->rem_capacity = ((di->accum_current_uAh - di->empty_uAh) * 100L) / -+ (di->full_active_uAh - di->empty_uAh); -+ -+ if (di->rem_capacity < 0) -+ di->rem_capacity = 0; -+ if (di->rem_capacity > 100) -+ di->rem_capacity = 100; -+ -+ if (di->current_uA) -+ di->life_sec = -((di->accum_current_uAh - di->empty_uAh) * -+ 3600L) / di->current_uA; -+ else -+ di->life_sec = 0; -+ -+ return 0; -+} -+ -+static void ds2760_battery_update_status(struct ds2760_device_info *di) -+{ -+ int old_charge_status = di->charge_status; -+ -+ ds2760_battery_read_status(di); -+ -+ if (di->charge_status == POWER_SUPPLY_STATUS_UNKNOWN) -+ di->full_counter = 0; -+ -+ if (power_supply_am_i_supplied(&di->bat)) { -+ if (di->current_uA > 10000) { -+ di->charge_status = POWER_SUPPLY_STATUS_CHARGING; -+ di->full_counter = 0; -+ } -+ else if (di->current_uA < -5000) { -+ if (di->charge_status != POWER_SUPPLY_STATUS_NOT_CHARGING) -+ dev_notice(di->dev, "not enough power to " -+ "charge\n"); -+ di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING; -+ di->full_counter = 0; -+ } -+ else if (di->current_uA < 10000 && -+ di->charge_status != POWER_SUPPLY_STATUS_FULL) { -+ -+ /* Don't consider the battery to be full unless -+ * we've seen the current < 10 mA at least two -+ * consecutive times. */ -+ -+ di->full_counter++; -+ -+ if (di->full_counter < 2) -+ di->charge_status = POWER_SUPPLY_STATUS_CHARGING; -+ else { -+ unsigned char acr[2]; -+ int acr_val; -+ -+ /* acr is in units of 0.25 mAh */ -+ acr_val = di->full_active_uAh * 4L / 1000; -+ -+ acr[0] = acr_val >> 8; -+ acr[1] = acr_val & 0xff; -+ -+ if (w1_ds2760_write(di->w1_dev, acr, -+ DS2760_CURRENT_ACCUM_MSB, 2) < 2) -+ dev_warn(di->dev, -+ "ACR reset failed\n"); -+ -+ di->charge_status = POWER_SUPPLY_STATUS_FULL; -+ } -+ } -+ } -+ else { -+ di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING; -+ di->full_counter = 0; -+ } -+ -+ if (di->charge_status != old_charge_status) -+ power_supply_changed(&di->bat); -+ -+ return; -+} -+ -+static void ds2760_battery_work(struct work_struct *work) -+{ -+ struct ds2760_device_info *di = container_of(work, -+ struct ds2760_device_info, monitor_work.work); -+ const int interval = HZ * 60; -+ -+ dev_dbg(di->dev, "%s\n", __FUNCTION__); -+ -+ ds2760_battery_update_status(di); -+ queue_delayed_work(di->monitor_wqueue, &di->monitor_work, interval); -+ -+ return; -+} -+ -+#define to_ds2760_device_info(x) container_of((x), struct ds2760_device_info, \ -+ bat); -+ -+static void ds2760_battery_external_power_changed(struct power_supply *psy) -+{ -+ struct ds2760_device_info *di = to_ds2760_device_info(psy); -+ -+ dev_dbg(di->dev, "%s\n", __FUNCTION__); -+ -+ cancel_delayed_work(&di->monitor_work); -+ queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ/10); -+ -+ return; -+} -+ -+static int ds2760_battery_get_property(struct power_supply *psy, -+ enum power_supply_property psp, -+ union power_supply_propval *val) -+{ -+ struct ds2760_device_info *di = to_ds2760_device_info(psy); -+ -+ switch (psp) { -+ case POWER_SUPPLY_PROP_STATUS: -+ val->intval = di->charge_status; -+ return 0; -+ default: -+ break; -+ } -+ -+ ds2760_battery_read_status(di); -+ -+ switch (psp) { -+ case POWER_SUPPLY_PROP_VOLTAGE_NOW: -+ val->intval = di->voltage_uV; -+ break; -+ case POWER_SUPPLY_PROP_CURRENT_NOW: -+ val->intval = di->current_uA; -+ break; -+ case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: -+ val->intval = di->rated_capacity; -+ break; -+ case POWER_SUPPLY_PROP_CHARGE_FULL: -+ val->intval = di->full_active_uAh; -+ break; -+ case POWER_SUPPLY_PROP_CHARGE_EMPTY: -+ val->intval = di->empty_uAh; -+ break; -+ case POWER_SUPPLY_PROP_CHARGE_NOW: -+ val->intval = di->accum_current_uAh; -+ break; -+ case POWER_SUPPLY_PROP_TEMP: -+ val->intval = di->temp_C; -+ break; -+ default: -+ return -EINVAL; -+ } -+ -+ return 0; -+} -+ -+static enum power_supply_property ds2760_battery_props[] = { -+ POWER_SUPPLY_PROP_STATUS, -+ POWER_SUPPLY_PROP_VOLTAGE_NOW, -+ POWER_SUPPLY_PROP_CURRENT_NOW, -+ POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, -+ POWER_SUPPLY_PROP_CHARGE_FULL, -+ POWER_SUPPLY_PROP_CHARGE_EMPTY, -+ POWER_SUPPLY_PROP_CHARGE_NOW, -+ POWER_SUPPLY_PROP_TEMP, -+}; -+ -+static int ds2760_battery_probe(struct platform_device *pdev) -+{ -+ int retval = 0; -+ struct ds2760_device_info *di; -+ struct ds2760_platform_data *pdata; -+ -+ di = kzalloc(sizeof(*di), GFP_KERNEL); -+ if (!di) { -+ retval = -ENOMEM; -+ goto di_alloc_failed; -+ } -+ -+ platform_set_drvdata(pdev, di); -+ -+ pdata = pdev->dev.platform_data; -+ di->dev = &pdev->dev; -+ di->w1_dev = pdev->dev.parent; -+ di->bat.name = pdev->dev.bus_id; -+ di->bat.type = POWER_SUPPLY_TYPE_BATTERY; -+ di->bat.properties = ds2760_battery_props; -+ di->bat.num_properties = ARRAY_SIZE(ds2760_battery_props); -+ di->bat.get_property = ds2760_battery_get_property; -+ di->bat.external_power_changed = -+ ds2760_battery_external_power_changed; -+ di->bat.use_for_apm = 1; -+ -+ di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; -+ -+ retval = power_supply_register(&pdev->dev, &di->bat); -+ if (retval) { -+ dev_err(di->dev, "failed to register battery"); -+ goto batt_failed; -+ } -+ -+ INIT_DELAYED_WORK(&di->monitor_work, ds2760_battery_work); -+ di->monitor_wqueue = create_singlethread_workqueue(pdev->dev.bus_id); -+ if (!di->monitor_wqueue) { -+ retval = -ESRCH; -+ goto workqueue_failed; -+ } -+ queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ * 1); -+ -+ goto success; -+ -+workqueue_failed: -+ power_supply_unregister(&di->bat); -+batt_failed: -+ kfree(di); -+di_alloc_failed: -+success: -+ return retval; -+} -+ -+static int ds2760_battery_remove(struct platform_device *pdev) -+{ -+ struct ds2760_device_info *di = platform_get_drvdata(pdev); -+ -+ cancel_rearming_delayed_workqueue(di->monitor_wqueue, -+ &di->monitor_work); -+ destroy_workqueue(di->monitor_wqueue); -+ power_supply_unregister(&di->bat); -+ -+ return 0; -+} -+ -+#ifdef CONFIG_PM -+ -+static int ds2760_battery_suspend(struct platform_device *pdev, -+ pm_message_t state) -+{ -+ struct ds2760_device_info *di = platform_get_drvdata(pdev); -+ -+ di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; -+ -+ return 0; -+} -+ -+static int ds2760_battery_resume(struct platform_device *pdev) -+{ -+ struct ds2760_device_info *di = platform_get_drvdata(pdev); -+ -+ di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; -+ power_supply_changed(&di->bat); -+ -+ cancel_delayed_work(&di->monitor_work); -+ queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ); -+ -+ return 0; -+} -+ -+#else -+ -+#define ds2760_battery_suspend NULL -+#define ds2760_battery_resume NULL -+ -+#endif /* CONFIG_PM */ -+ -+static struct platform_driver ds2760_battery_driver = { -+ .driver = { -+ .name = "ds2760-battery", -+ }, -+ .probe = ds2760_battery_probe, -+ .remove = ds2760_battery_remove, -+ .suspend = ds2760_battery_suspend, -+ .resume = ds2760_battery_resume, -+}; -+ -+static int __init ds2760_battery_init(void) -+{ -+ return platform_driver_register(&ds2760_battery_driver); -+} -+ -+static void __exit ds2760_battery_exit(void) -+{ -+ platform_driver_unregister(&ds2760_battery_driver); -+ return; -+} -+ -+module_init(ds2760_battery_init); -+module_exit(ds2760_battery_exit); -+ -+MODULE_LICENSE("GPL"); -+MODULE_AUTHOR("Szabolcs Gyurko , " -+ "Matt Reimer , " -+ "Anton Vorontsov "); -+MODULE_DESCRIPTION("ds2760 battery driver"); -Index: linux-2.6.22/drivers/power/Kconfig -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/Kconfig 2007-08-23 12:13:52.000000000 +0200 -@@ -0,0 +1,70 @@ -+menuconfig POWER_SUPPLY -+ tristate "Power supply class support" -+ help -+ Say Y here to enable power supply class support. This allows -+ power supply (batteries, AC, USB) monitoring by userspace -+ via sysfs and uevent (if available) and/or APM kernel interface -+ (if selected below). -+ -+if POWER_SUPPLY -+ -+config POWER_SUPPLY_DEBUG -+ bool "Power supply debug" -+ help -+ Say Y here to enable debugging messages for power supply class -+ and drivers. -+ -+config PDA_POWER -+ tristate "Generic PDA/phone power driver" -+ help -+ Say Y here to enable generic power driver for PDAs and phones with -+ one or two external power supplies (AC/USB) connected to main and -+ backup batteries, and optional builtin charger. -+ -+config APM_POWER -+ tristate "APM emulation for class batteries" -+ depends on APM_EMULATION -+ help -+ Say Y here to enable support APM status emulation using -+ battery class devices. -+ -+config BATTERY_DS2760 -+ tristate "DS2760 battery driver (HP iPAQ & others)" -+ select W1 -+ select W1_SLAVE_DS2760 -+ help -+ Say Y here to enable support for batteries with ds2760 chip. -+ -+config BATTERY_PMU -+ tristate "Apple PMU battery" -+ depends on ADB_PMU -+ help -+ Say Y here to expose battery information on Apple machines -+ through the generic battery class. -+ -+config BATTERY_OLPC -+ tristate "One Laptop Per Child battery" -+ depends on X86_32 -+ help -+ Say Y to enable support for the battery on the OLPC laptop. -+ -+# drivers below are not in battery2-2.6 tree -+ -+config ADC_BATTERY -+ tristate "Generic ADC battery driver" -+ depends on ADC && POWER_SUPPLY -+ help -+ Say Y here to enable support for battery monitoring using generic ADC device. -+ -+config IPAQ_MICRO_BATTERY -+ tristate "HP iPAQ Micro ASIC battery driver" -+ depends on IPAQ_MICRO && POWER_SUPPLY -+ help -+ Choose this option if you want to monitor battery status on -+ Compaq/HP iPAQ h3100 h3600 -+ -+config MCP_UCB1x00_SIMPAD_BATTERY -+ tristate "SIMpad Battery Reading Support" -+ depends on MCP_UCB1x00 && POWER_SUPPLY -+ -+endif # POWER_SUPPLY -Index: linux-2.6.22/drivers/power/Makefile -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/Makefile 2007-08-23 12:13:52.000000000 +0200 -@@ -0,0 +1,28 @@ -+power_supply-objs := power_supply_core.o -+ -+ifeq ($(CONFIG_SYSFS),y) -+power_supply-objs += power_supply_sysfs.o -+endif -+ -+ifeq ($(CONFIG_LEDS_TRIGGERS),y) -+power_supply-objs += power_supply_leds.o -+endif -+ -+ifeq ($(CONFIG_POWER_SUPPLY_DEBUG),y) -+EXTRA_CFLAGS += -DDEBUG -+endif -+ -+obj-$(CONFIG_POWER_SUPPLY) += power_supply.o -+ -+obj-$(CONFIG_PDA_POWER) += pda_power.o -+obj-$(CONFIG_APM_POWER) += apm_power.o -+ -+obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o -+obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o -+obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o -+ -+# drivers below are not in battery2-2.6 tree -+ -+obj-$(CONFIG_ADC_BATTERY) += adc_battery.o -+obj-$(CONFIG_IPAQ_MICRO_BATTERY) += micro_battery.o -+obj-$(CONFIG_MCP_UCB1x00_SIMPAD_BATTERY) += simpad-battery.o -Index: linux-2.6.22/drivers/power/micro_battery.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/micro_battery.c 2007-08-23 12:25:20.000000000 +0200 -@@ -0,0 +1,257 @@ -+/* -+ * This program is free software; you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License version 2 as -+ * published by the Free Software Foundation. -+ * -+ * h3600 atmel micro companion support, battery subdevice -+ * based on previous kernel 2.4 version -+ * Author : Alessandro Gardich -+ * -+ */ -+ -+ -+#include -+#include -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#include -+ -+#include -+#include -+ -+#include -+ -+#define BATT_PERIOD 10*HZ -+ -+#define H3600_BATT_STATUS_HIGH 0x01 -+#define H3600_BATT_STATUS_LOW 0x02 -+#define H3600_BATT_STATUS_CRITICAL 0x04 -+#define H3600_BATT_STATUS_CHARGING 0x08 -+#define H3600_BATT_STATUS_CHARGEMAIN 0x10 -+#define H3600_BATT_STATUS_DEAD 0x20 /* Battery will not charge */ -+#define H3600_BATT_STATUS_NOTINSTALLED 0x20 /* For expansion pack batteries */ -+#define H3600_BATT_STATUS_FULL 0x40 /* Battery fully charged (and connected to AC) */ -+#define H3600_BATT_STATUS_NOBATTERY 0x80 -+#define H3600_BATT_STATUS_UNKNOWN 0xff -+ -+ -+//static struct power_supply_dev *micro_battery; -+ -+static micro_private_t *p_micro; -+ -+struct timer_list batt_timer; -+ -+struct { -+ int ac; -+ int update_time; -+ int chemistry; -+ int voltage; -+ int temperature; -+ int flag; -+} micro_battery; -+ -+static void micro_battery_receive (int len, unsigned char *data) { -+ if (0) { -+ printk(KERN_ERR "h3600_battery - AC = %02x\n", data[0]); -+ printk(KERN_ERR "h3600_battery - BAT1 chemistry = %02x\n", data[1]); -+ printk(KERN_ERR "h3600_battery - BAT1 voltage = %d %02x%02x\n", (data[3]<<8)+data[2], data[2], data[3]); -+ printk(KERN_ERR "h3600_battery - BAT1 status = %02x\n", data[4]); -+ } -+ -+ micro_battery.ac = data[0]; -+ micro_battery.chemistry = data[1]; -+ micro_battery.voltage = ((((unsigned short)data[3]<<8)+data[2]) * 5000L ) * 1000 / 1024; -+ micro_battery.flag = data[4]; -+ -+ if (len == 9) { -+ if (0) { -+ printk(KERN_ERR "h3600_battery - BAT2 chemistry = %02x\n", data[5]); -+ printk(KERN_ERR "h3600_battery - BAT2 voltage = %d %02x%02x\n", (data[7]<<8)+data[6], data[6], data[7]); -+ printk(KERN_ERR "h3600_battery - BAT2 status = %02x\n", data[8]); -+ } -+ } -+} -+ -+static void micro_temperature_receive (int len, unsigned char *data) { -+ micro_battery.temperature = ((unsigned short)data[1]<<8)+data[0]; -+} -+ -+void h3600_battery_read_status(unsigned long data) { -+ -+ if (++data % 2) -+ h3600_micro_tx_msg(0x09,0,NULL); -+ else -+ h3600_micro_tx_msg(0x06,0,NULL); -+ -+ batt_timer.expires += BATT_PERIOD; -+ batt_timer.data = data; -+ -+ add_timer(&batt_timer); -+} -+ -+int get_capacity(struct power_supply *b) { -+ switch (micro_battery.flag) { -+ case H3600_BATT_STATUS_HIGH : return 100; break; -+ case H3600_BATT_STATUS_LOW : return 50; break; -+ case H3600_BATT_STATUS_CRITICAL : return 5; break; -+ default: break; -+ } -+ return 0; -+} -+ -+int get_status(struct power_supply *b) { -+ -+ if (micro_battery.flag == H3600_BATT_STATUS_UNKNOWN) -+ return POWER_SUPPLY_STATUS_UNKNOWN; -+ -+ if (micro_battery.flag & H3600_BATT_STATUS_FULL) -+ return POWER_SUPPLY_STATUS_FULL; -+ -+ if ((micro_battery.flag & H3600_BATT_STATUS_CHARGING) || -+ (micro_battery.flag & H3600_BATT_STATUS_CHARGEMAIN)) -+ return POWER_SUPPLY_STATUS_CHARGING; -+ -+ return POWER_SUPPLY_STATUS_DISCHARGING; -+} -+ -+static int micro_batt_get_property(struct power_supply *b, -+ enum power_supply_property psp, -+ union power_supply_propval *val) -+{ -+ switch (psp) { -+ case POWER_SUPPLY_PROP_STATUS: -+ val->intval = get_status(b); -+ break; -+ case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: -+ val->intval = 4700000; -+ break; -+ case POWER_SUPPLY_PROP_CAPACITY: -+ val->intval = get_capacity(b); -+ break; -+ case POWER_SUPPLY_PROP_TEMP: -+ val->intval = micro_battery.temperature; -+ break; -+ case POWER_SUPPLY_PROP_VOLTAGE_NOW: -+ val->intval = micro_battery.voltage; -+ break; -+ default: -+ return -EINVAL; -+ }; -+ -+ return 0; -+} -+ -+static enum power_supply_property micro_batt_props[] = { -+ POWER_SUPPLY_PROP_STATUS, -+ POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, -+ POWER_SUPPLY_PROP_CAPACITY, -+ POWER_SUPPLY_PROP_TEMP, -+ POWER_SUPPLY_PROP_VOLTAGE_NOW, -+}; -+ -+static struct power_supply h3600_battery = { -+ .name = "main-battery", -+ .properties = micro_batt_props, -+ .num_properties = ARRAY_SIZE(micro_batt_props), -+ .get_property = micro_batt_get_property, -+ .use_for_apm = 1, -+}; -+ -+static int micro_batt_probe (struct platform_device *pdev) -+{ -+ if (1) printk(KERN_ERR "micro battery probe : begin\n"); -+ -+ power_supply_register(&pdev->dev, &h3600_battery); -+ -+ { /*--- callback ---*/ -+ p_micro = platform_get_drvdata(pdev); -+ spin_lock(p_micro->lock); -+ p_micro->h_batt = micro_battery_receive; -+ p_micro->h_temp = micro_temperature_receive; -+ spin_unlock(p_micro->lock); -+ } -+ -+ { /*--- timer ---*/ -+ init_timer(&batt_timer); -+ batt_timer.expires = jiffies + BATT_PERIOD; -+ batt_timer.data = 0; -+ batt_timer.function = h3600_battery_read_status; -+ -+ add_timer(&batt_timer); -+ } -+ -+ if (1) printk(KERN_ERR "micro battery probe : end\n"); -+ return 0; -+} -+ -+static int micro_batt_remove (struct platform_device *pdev) -+{ -+ power_supply_unregister(&h3600_battery); -+ { /*--- callback ---*/ -+ init_timer(&batt_timer); -+ p_micro->h_batt = NULL; -+ p_micro->h_temp = NULL; -+ spin_unlock(p_micro->lock); -+ } -+ { /*--- timer ---*/ -+ del_timer_sync(&batt_timer); -+ } -+ return 0; -+} -+ -+static int micro_batt_suspend ( struct platform_device *pdev, pm_message_t state) -+{ -+ { /*--- timer ---*/ -+ del_timer(&batt_timer); -+ } -+ return 0; -+} -+ -+static int micro_batt_resume ( struct platform_device *pdev) -+{ -+ { /*--- timer ---*/ -+ add_timer(&batt_timer); -+ } -+ return 0; -+} -+ -+struct platform_driver micro_batt_device_driver = { -+ .driver = { -+ .name = "h3600-micro-battery", -+ }, -+ .probe = micro_batt_probe, -+ .remove = micro_batt_remove, -+ .suspend = micro_batt_suspend, -+ .resume = micro_batt_resume, -+}; -+ -+static int micro_batt_init (void) -+{ -+ return platform_driver_register(µ_batt_device_driver); -+} -+ -+static void micro_batt_cleanup (void) -+{ -+ platform_driver_unregister (µ_batt_device_driver); -+} -+ -+module_init (micro_batt_init); -+module_exit (micro_batt_cleanup); -+ -+MODULE_LICENSE("GPL"); -+MODULE_AUTHOR("gremlin.it"); -+MODULE_DESCRIPTION("driver for iPAQ Atmel micro battery"); -+ -+ -Index: linux-2.6.22/drivers/power/olpc_battery.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/olpc_battery.c 2007-08-23 12:13:52.000000000 +0200 -@@ -0,0 +1,302 @@ -+/* -+ * Battery driver for One Laptop Per Child board. -+ * -+ * Copyright © 2006 David Woodhouse -+ * -+ * This program is free software; you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License version 2 as -+ * published by the Free Software Foundation. -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#define wBAT_VOLTAGE 0xf900 /* *9.76/32, mV */ -+#define wBAT_CURRENT 0xf902 /* *15.625/120, mA */ -+#define wBAT_TEMP 0xf906 /* *256/1000, °C */ -+#define wAMB_TEMP 0xf908 /* *256/1000, °C */ -+#define SOC 0xf910 /* percentage */ -+#define sMBAT_STATUS 0xfaa4 -+#define sBAT_PRESENT 1 -+#define sBAT_FULL 2 -+#define sBAT_DESTROY 4 /* what is this exactly? */ -+#define sBAT_LOW 32 -+#define sBAT_DISCHG 64 -+#define sMCHARGE_STATUS 0xfaa5 -+#define sBAT_CHARGE 1 -+#define sBAT_OVERTEMP 4 -+#define sBAT_NiMH 8 -+#define sPOWER_FLAG 0xfa40 -+#define ADAPTER_IN 1 -+ -+/********************************************************************* -+ * EC locking and access -+ *********************************************************************/ -+ -+static int lock_ec(void) -+{ -+ unsigned long timeo = jiffies + HZ / 20; -+ -+ while (1) { -+ unsigned char lock = inb(0x6c) & 0x80; -+ if (!lock) -+ return 0; -+ if (time_after(jiffies, timeo)) { -+ printk(KERN_ERR "olpc_battery: failed to lock EC for " -+ "battery access\n"); -+ return 1; -+ } -+ yield(); -+ } -+} -+ -+static void unlock_ec(void) -+{ -+ outb(0xff, 0x6c); -+ return; -+} -+ -+static unsigned char read_ec_byte(unsigned short adr) -+{ -+ outb(adr >> 8, 0x381); -+ outb(adr, 0x382); -+ return inb(0x383); -+} -+ -+static unsigned short read_ec_word(unsigned short adr) -+{ -+ return (read_ec_byte(adr) << 8) | read_ec_byte(adr + 1); -+} -+ -+/********************************************************************* -+ * Power -+ *********************************************************************/ -+ -+static int olpc_ac_get_prop(struct power_supply *psy, -+ enum power_supply_property psp, -+ union power_supply_propval *val) -+{ -+ int ret = 0; -+ -+ if (lock_ec()) -+ return -EIO; -+ -+ switch (psp) { -+ case POWER_SUPPLY_PROP_ONLINE: -+ if (!(read_ec_byte(sMBAT_STATUS) & sBAT_PRESENT)) { -+ ret = -ENODEV; -+ goto out; -+ } -+ val->intval = !!(read_ec_byte(sPOWER_FLAG) & ADAPTER_IN); -+ break; -+ default: -+ ret = -EINVAL; -+ break; -+ } -+out: -+ unlock_ec(); -+ return ret; -+} -+ -+static enum power_supply_property olpc_ac_props[] = { -+ POWER_SUPPLY_PROP_ONLINE, -+}; -+ -+static struct power_supply olpc_ac = { -+ .name = "olpc-ac", -+ .type = POWER_SUPPLY_TYPE_MAINS, -+ .properties = olpc_ac_props, -+ .num_properties = ARRAY_SIZE(olpc_ac_props), -+ .get_property = olpc_ac_get_prop, -+}; -+ -+/********************************************************************* -+ * Battery properties -+ *********************************************************************/ -+ -+static int olpc_bat_get_property(struct power_supply *psy, -+ enum power_supply_property psp, -+ union power_supply_propval *val) -+{ -+ int ret = 0; -+ -+ if (lock_ec()) -+ return -EIO; -+ -+ switch (psp) { -+ case POWER_SUPPLY_PROP_STATUS: -+ { -+ int status = POWER_SUPPLY_STATUS_UNKNOWN; -+ -+ val->intval = read_ec_byte(sMBAT_STATUS); -+ -+ if (!(val->intval & sBAT_PRESENT)) { -+ ret = -ENODEV; -+ goto out; -+ } -+ -+ if (val->intval & sBAT_DISCHG) -+ status = POWER_SUPPLY_STATUS_DISCHARGING; -+ else if (val->intval & sBAT_FULL) -+ status = POWER_SUPPLY_STATUS_FULL; -+ -+ val->intval = read_ec_byte(sMCHARGE_STATUS); -+ if (val->intval & sBAT_CHARGE) -+ status = POWER_SUPPLY_STATUS_CHARGING; -+ -+ val->intval = status; -+ break; -+ } -+ case POWER_SUPPLY_PROP_PRESENT: -+ val->intval = !!(read_ec_byte(sMBAT_STATUS) & sBAT_PRESENT); -+ break; -+ case POWER_SUPPLY_PROP_HEALTH: -+ val->intval = read_ec_byte(sMCHARGE_STATUS); -+ if (val->intval & sBAT_OVERTEMP) -+ val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; -+ else -+ val->intval = POWER_SUPPLY_HEALTH_GOOD; -+ break; -+ case POWER_SUPPLY_PROP_TECHNOLOGY: -+ val->intval = read_ec_byte(sMCHARGE_STATUS); -+ if (val->intval & sBAT_NiMH) -+ val->intval = POWER_SUPPLY_TECHNOLOGY_NIMH; -+ else -+ val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN; -+ break; -+ case POWER_SUPPLY_PROP_VOLTAGE_AVG: -+ val->intval = read_ec_byte(wBAT_VOLTAGE) * 9760L / 32; -+ break; -+ case POWER_SUPPLY_PROP_CURRENT_AVG: -+ val->intval = read_ec_byte(wBAT_CURRENT) * 15625L / 120; -+ break; -+ case POWER_SUPPLY_PROP_CAPACITY: -+ val->intval = read_ec_byte(SOC); -+ break; -+ case POWER_SUPPLY_PROP_CAPACITY_LEVEL: -+ val->intval = read_ec_byte(sMBAT_STATUS); -+ if (val->intval & sBAT_FULL) -+ val->intval = POWER_SUPPLY_CAPACITY_LEVEL_FULL; -+ else if (val->intval & sBAT_LOW) -+ val->intval = POWER_SUPPLY_CAPACITY_LEVEL_LOW; -+ else -+ val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; -+ break; -+ case POWER_SUPPLY_PROP_TEMP: -+ val->intval = read_ec_byte(wBAT_TEMP) * 256 / 100; -+ break; -+ case POWER_SUPPLY_PROP_TEMP_AMBIENT: -+ val->intval = read_ec_byte(wAMB_TEMP) * 256 / 100; -+ break; -+ default: -+ ret = -EINVAL; -+ break; -+ } -+ -+out: -+ unlock_ec(); -+ return ret; -+} -+ -+static enum power_supply_property olpc_bat_props[] = { -+ POWER_SUPPLY_PROP_STATUS, -+ POWER_SUPPLY_PROP_PRESENT, -+ POWER_SUPPLY_PROP_HEALTH, -+ POWER_SUPPLY_PROP_TECHNOLOGY, -+ POWER_SUPPLY_PROP_VOLTAGE_AVG, -+ POWER_SUPPLY_PROP_CURRENT_AVG, -+ POWER_SUPPLY_PROP_CAPACITY, -+ POWER_SUPPLY_PROP_CAPACITY_LEVEL, -+ POWER_SUPPLY_PROP_TEMP, -+ POWER_SUPPLY_PROP_TEMP_AMBIENT, -+}; -+ -+/********************************************************************* -+ * Initialisation -+ *********************************************************************/ -+ -+static struct platform_device *bat_pdev; -+ -+static struct power_supply olpc_bat = { -+ .properties = olpc_bat_props, -+ .num_properties = ARRAY_SIZE(olpc_bat_props), -+ .get_property = olpc_bat_get_property, -+ .use_for_apm = 1, -+}; -+ -+static int __init olpc_bat_init(void) -+{ -+ int ret = 0; -+ unsigned short tmp; -+ -+ if (!request_region(0x380, 4, "olpc-battery")) { -+ ret = -EIO; -+ goto region_failed; -+ } -+ -+ if (lock_ec()) { -+ ret = -EIO; -+ goto lock_failed; -+ } -+ -+ tmp = read_ec_word(0xfe92); -+ unlock_ec(); -+ -+ if (tmp != 0x380) { -+ /* Doesn't look like OLPC EC */ -+ ret = -ENODEV; -+ goto not_olpc_ec; -+ } -+ -+ bat_pdev = platform_device_register_simple("olpc-battery", 0, NULL, 0); -+ if (IS_ERR(bat_pdev)) { -+ ret = PTR_ERR(bat_pdev); -+ goto pdev_failed; -+ } -+ -+ ret = power_supply_register(&bat_pdev->dev, &olpc_ac); -+ if (ret) -+ goto ac_failed; -+ -+ olpc_bat.name = bat_pdev->name; -+ -+ ret = power_supply_register(&bat_pdev->dev, &olpc_bat); -+ if (ret) -+ goto battery_failed; -+ -+ goto success; -+ -+battery_failed: -+ power_supply_unregister(&olpc_ac); -+ac_failed: -+ platform_device_unregister(bat_pdev); -+pdev_failed: -+not_olpc_ec: -+lock_failed: -+ release_region(0x380, 4); -+region_failed: -+success: -+ return ret; -+} -+ -+static void __exit olpc_bat_exit(void) -+{ -+ power_supply_unregister(&olpc_bat); -+ power_supply_unregister(&olpc_ac); -+ platform_device_unregister(bat_pdev); -+ release_region(0x380, 4); -+ return; -+} -+ -+module_init(olpc_bat_init); -+module_exit(olpc_bat_exit); -+ -+MODULE_AUTHOR("David Woodhouse "); -+MODULE_LICENSE("GPL"); -+MODULE_DESCRIPTION("Battery driver for One Laptop Per Child " -+ "($100 laptop) board."); -Index: linux-2.6.22/drivers/power/pda_power.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/pda_power.c 2007-08-23 12:13:52.000000000 +0200 -@@ -0,0 +1,263 @@ -+/* -+ * Common power driver for PDAs and phones with one or two external -+ * power supplies (AC/USB) connected to main and backup batteries, -+ * and optional builtin charger. -+ * -+ * Copyright 2007 Anton Vorontsov -+ * -+ * This program is free software; you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License version 2 as -+ * published by the Free Software Foundation. -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+static inline unsigned int get_irq_flags(struct resource *res) -+{ -+ unsigned int flags = IRQF_DISABLED | IRQF_SHARED; -+ -+ flags |= res->flags & IRQF_TRIGGER_MASK; -+ -+ return flags; -+} -+ -+static struct device *dev; -+static struct pda_power_pdata *pdata; -+static struct resource *ac_irq, *usb_irq; -+static struct timer_list charger_timer; -+static struct timer_list supply_timer; -+ -+static int pda_power_get_property(struct power_supply *psy, -+ enum power_supply_property psp, -+ union power_supply_propval *val) -+{ -+ switch (psp) { -+ case POWER_SUPPLY_PROP_ONLINE: -+ if (psy->type == POWER_SUPPLY_TYPE_MAINS) -+ val->intval = pdata->is_ac_online ? -+ pdata->is_ac_online() : 0; -+ else -+ val->intval = pdata->is_usb_online ? -+ pdata->is_usb_online() : 0; -+ break; -+ default: -+ return -EINVAL; -+ } -+ return 0; -+} -+ -+static enum power_supply_property pda_power_props[] = { -+ POWER_SUPPLY_PROP_ONLINE, -+}; -+ -+static char *pda_power_supplied_to[] = { -+ "main-battery", -+ "backup-battery", -+}; -+ -+static struct power_supply pda_power_supplies[] = { -+ { -+ .name = "ac", -+ .type = POWER_SUPPLY_TYPE_MAINS, -+ .supplied_to = pda_power_supplied_to, -+ .num_supplicants = ARRAY_SIZE(pda_power_supplied_to), -+ .properties = pda_power_props, -+ .num_properties = ARRAY_SIZE(pda_power_props), -+ .get_property = pda_power_get_property, -+ }, -+ { -+ .name = "usb", -+ .type = POWER_SUPPLY_TYPE_USB, -+ .supplied_to = pda_power_supplied_to, -+ .num_supplicants = ARRAY_SIZE(pda_power_supplied_to), -+ .properties = pda_power_props, -+ .num_properties = ARRAY_SIZE(pda_power_props), -+ .get_property = pda_power_get_property, -+ }, -+}; -+ -+static void update_charger(void) -+{ -+ if (!pdata->set_charge) -+ return; -+ -+ if (pdata->is_ac_online && pdata->is_ac_online()) { -+ dev_dbg(dev, "charger on (AC)\n"); -+ pdata->set_charge(PDA_POWER_CHARGE_AC); -+ } -+ else if (pdata->is_usb_online && pdata->is_usb_online()) { -+ dev_dbg(dev, "charger on (USB)\n"); -+ pdata->set_charge(PDA_POWER_CHARGE_USB); -+ } -+ else { -+ dev_dbg(dev, "charger off\n"); -+ pdata->set_charge(0); -+ } -+ -+ return; -+} -+ -+static void supply_timer_func(unsigned long irq) -+{ -+ if (ac_irq && irq == ac_irq->start) -+ power_supply_changed(&pda_power_supplies[0]); -+ else if (usb_irq && irq == usb_irq->start) -+ power_supply_changed(&pda_power_supplies[1]); -+ return; -+} -+ -+static void charger_timer_func(unsigned long irq) -+{ -+ update_charger(); -+ -+ /* Okay, charger set. Now wait a bit before notifying supplicants, -+ * charge power should stabilize. */ -+ supply_timer.data = irq; -+ mod_timer(&supply_timer, -+ jiffies + msecs_to_jiffies(pdata->wait_for_charger)); -+ return; -+} -+ -+static irqreturn_t power_changed_isr(int irq, void *unused) -+{ -+ /* Wait a bit before reading ac/usb line status and setting charger, -+ * because ac/usb status readings may lag from irq. */ -+ charger_timer.data = irq; -+ mod_timer(&charger_timer, -+ jiffies + msecs_to_jiffies(pdata->wait_for_status)); -+ return IRQ_HANDLED; -+} -+ -+static int pda_power_probe(struct platform_device *pdev) -+{ -+ int ret = 0; -+ -+ dev = &pdev->dev; -+ -+ if (pdev->id != -1) { -+ dev_err(dev, "it's meaningless to register several " -+ "pda_powers, use id = -1\n"); -+ ret = -EINVAL; -+ goto wrongid; -+ } -+ -+ pdata = pdev->dev.platform_data; -+ -+ update_charger(); -+ -+ if (!pdata->wait_for_status) -+ pdata->wait_for_status = 500; -+ -+ if (!pdata->wait_for_charger) -+ pdata->wait_for_charger = 500; -+ -+ setup_timer(&charger_timer, charger_timer_func, 0); -+ setup_timer(&supply_timer, supply_timer_func, 0); -+ -+ ac_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ac"); -+ usb_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "usb"); -+ if (!ac_irq && !usb_irq) { -+ dev_err(dev, "no ac/usb irq specified\n"); -+ ret = -ENODEV; -+ goto noirqs; -+ } -+ -+ if (pdata->supplied_to) { -+ pda_power_supplies[0].supplied_to = pdata->supplied_to; -+ pda_power_supplies[1].supplied_to = pdata->supplied_to; -+ pda_power_supplies[0].num_supplicants = pdata->num_supplicants; -+ pda_power_supplies[1].num_supplicants = pdata->num_supplicants; -+ } -+ -+ ret = power_supply_register(&pdev->dev, &pda_power_supplies[0]); -+ if (ret) { -+ dev_err(dev, "failed to register %s power supply\n", -+ pda_power_supplies[0].name); -+ goto supply0_failed; -+ } -+ -+ ret = power_supply_register(&pdev->dev, &pda_power_supplies[1]); -+ if (ret) { -+ dev_err(dev, "failed to register %s power supply\n", -+ pda_power_supplies[1].name); -+ goto supply1_failed; -+ } -+ -+ if (ac_irq) { -+ ret = request_irq(ac_irq->start, power_changed_isr, -+ get_irq_flags(ac_irq), ac_irq->name, -+ &pda_power_supplies[0]); -+ if (ret) { -+ dev_err(dev, "request ac irq failed\n"); -+ goto ac_irq_failed; -+ } -+ } -+ -+ if (usb_irq) { -+ ret = request_irq(usb_irq->start, power_changed_isr, -+ get_irq_flags(usb_irq), usb_irq->name, -+ &pda_power_supplies[1]); -+ if (ret) { -+ dev_err(dev, "request usb irq failed\n"); -+ goto usb_irq_failed; -+ } -+ } -+ -+ goto success; -+ -+usb_irq_failed: -+ if (ac_irq) -+ free_irq(ac_irq->start, &pda_power_supplies[0]); -+ac_irq_failed: -+ power_supply_unregister(&pda_power_supplies[1]); -+supply1_failed: -+ power_supply_unregister(&pda_power_supplies[0]); -+supply0_failed: -+noirqs: -+wrongid: -+success: -+ return ret; -+} -+ -+static int pda_power_remove(struct platform_device *pdev) -+{ -+ if (usb_irq) -+ free_irq(usb_irq->start, &pda_power_supplies[1]); -+ if (ac_irq) -+ free_irq(ac_irq->start, &pda_power_supplies[0]); -+ del_timer_sync(&charger_timer); -+ del_timer_sync(&supply_timer); -+ power_supply_unregister(&pda_power_supplies[1]); -+ power_supply_unregister(&pda_power_supplies[0]); -+ return 0; -+} -+ -+static struct platform_driver pda_power_pdrv = { -+ .driver = { -+ .name = "pda-power", -+ }, -+ .probe = pda_power_probe, -+ .remove = pda_power_remove, -+}; -+ -+static int __init pda_power_init(void) -+{ -+ return platform_driver_register(&pda_power_pdrv); -+} -+ -+static void __exit pda_power_exit(void) -+{ -+ platform_driver_unregister(&pda_power_pdrv); -+ return; -+} -+ -+module_init(pda_power_init); -+module_exit(pda_power_exit); -+MODULE_LICENSE("GPL"); -+MODULE_AUTHOR("Anton Vorontsov "); -Index: linux-2.6.22/drivers/power/pmu_battery.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/pmu_battery.c 2007-08-23 12:13:52.000000000 +0200 -@@ -0,0 +1,215 @@ -+/* -+ * Battery class driver for Apple PMU -+ * -+ * Copyright © 2006 David Woodhouse -+ * -+ * This program is free software; you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License version 2 as -+ * published by the Free Software Foundation. -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+ -+static struct pmu_battery_dev { -+ struct power_supply bat; -+ struct pmu_battery_info *pbi; -+ char name[16]; -+ int propval; -+} *pbats[PMU_MAX_BATTERIES]; -+ -+#define to_pmu_battery_dev(x) container_of(x, struct pmu_battery_dev, bat) -+ -+/********************************************************************* -+ * Power -+ *********************************************************************/ -+ -+static int pmu_get_ac_prop(struct power_supply *psy, -+ enum power_supply_property psp, -+ union power_supply_propval *val) -+{ -+ switch (psp) { -+ case POWER_SUPPLY_PROP_ONLINE: -+ val->intval = (!!(pmu_power_flags & PMU_PWR_AC_PRESENT)) || -+ (pmu_battery_count == 0); -+ break; -+ default: -+ return -EINVAL; -+ } -+ -+ return 0; -+} -+ -+static enum power_supply_property pmu_ac_props[] = { -+ POWER_SUPPLY_PROP_ONLINE, -+}; -+ -+static struct power_supply pmu_ac = { -+ .name = "pmu-ac", -+ .type = POWER_SUPPLY_TYPE_MAINS, -+ .properties = pmu_ac_props, -+ .num_properties = ARRAY_SIZE(pmu_ac_props), -+ .get_property = pmu_get_ac_prop, -+}; -+ -+/********************************************************************* -+ * Battery properties -+ *********************************************************************/ -+ -+static char *pmu_batt_types[] = { -+ "Smart", "Comet", "Hooper", "Unknown" -+}; -+ -+static char *pmu_bat_get_model_name(struct pmu_battery_info *pbi) -+{ -+ switch (pbi->flags & PMU_BATT_TYPE_MASK) { -+ case PMU_BATT_TYPE_SMART: -+ return pmu_batt_types[0]; -+ case PMU_BATT_TYPE_COMET: -+ return pmu_batt_types[1]; -+ case PMU_BATT_TYPE_HOOPER: -+ return pmu_batt_types[2]; -+ default: break; -+ } -+ return pmu_batt_types[3]; -+} -+ -+static int pmu_bat_get_property(struct power_supply *psy, -+ enum power_supply_property psp, -+ union power_supply_propval *val) -+{ -+ struct pmu_battery_dev *pbat = to_pmu_battery_dev(psy); -+ struct pmu_battery_info *pbi = pbat->pbi; -+ -+ switch (psp) { -+ case POWER_SUPPLY_PROP_STATUS: -+ if (pbi->flags & PMU_BATT_CHARGING) -+ val->intval = POWER_SUPPLY_STATUS_CHARGING; -+ else -+ val->intval = POWER_SUPPLY_STATUS_DISCHARGING; -+ break; -+ case POWER_SUPPLY_PROP_PRESENT: -+ val->intval = !!(pbi->flags & PMU_BATT_PRESENT); -+ break; -+ case POWER_SUPPLY_PROP_MODEL_NAME: -+ val->strval = pmu_bat_get_model_name(pbi); -+ break; -+ case POWER_SUPPLY_PROP_ENERGY_AVG: -+ val->intval = pbi->charge * 1000; /* mWh -> µWh */ -+ break; -+ case POWER_SUPPLY_PROP_ENERGY_FULL: -+ val->intval = pbi->max_charge * 1000; /* mWh -> µWh */ -+ break; -+ case POWER_SUPPLY_PROP_CURRENT_AVG: -+ val->intval = pbi->amperage * 1000; /* mA -> µA */ -+ break; -+ case POWER_SUPPLY_PROP_VOLTAGE_AVG: -+ val->intval = pbi->voltage * 1000; /* mV -> µV */ -+ break; -+ case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: -+ val->intval = pbi->time_remaining; -+ break; -+ default: -+ return -EINVAL; -+ } -+ -+ return 0; -+} -+ -+static enum power_supply_property pmu_bat_props[] = { -+ POWER_SUPPLY_PROP_STATUS, -+ POWER_SUPPLY_PROP_PRESENT, -+ POWER_SUPPLY_PROP_MODEL_NAME, -+ POWER_SUPPLY_PROP_ENERGY_AVG, -+ POWER_SUPPLY_PROP_ENERGY_FULL, -+ POWER_SUPPLY_PROP_CURRENT_AVG, -+ POWER_SUPPLY_PROP_VOLTAGE_AVG, -+ POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, -+}; -+ -+/********************************************************************* -+ * Initialisation -+ *********************************************************************/ -+ -+static struct platform_device *bat_pdev; -+ -+static int __init pmu_bat_init(void) -+{ -+ int ret; -+ int i; -+ -+ bat_pdev = platform_device_register_simple("pmu-battery", -+ 0, NULL, 0); -+ if (IS_ERR(bat_pdev)) { -+ ret = PTR_ERR(bat_pdev); -+ goto pdev_register_failed; -+ } -+ -+ ret = power_supply_register(&bat_pdev->dev, &pmu_ac); -+ if (ret) -+ goto ac_register_failed; -+ -+ for (i = 0; i < pmu_battery_count; i++) { -+ struct pmu_battery_dev *pbat = kzalloc(sizeof(*pbat), -+ GFP_KERNEL); -+ if (!pbat) -+ break; -+ -+ sprintf(pbat->name, "PMU battery %d", i); -+ pbat->bat.name = pbat->name; -+ pbat->bat.properties = pmu_bat_props; -+ pbat->bat.num_properties = ARRAY_SIZE(pmu_bat_props); -+ pbat->bat.get_property = pmu_bat_get_property; -+ pbat->pbi = &pmu_batteries[i]; -+ -+ ret = power_supply_register(&bat_pdev->dev, &pbat->bat); -+ if (ret) { -+ kfree(pbat); -+ goto battery_register_failed; -+ } -+ pbats[i] = pbat; -+ } -+ -+ goto success; -+ -+battery_register_failed: -+ while (i--) { -+ if (!pbats[i]) -+ continue; -+ power_supply_unregister(&pbats[i]->bat); -+ kfree(pbats[i]); -+ } -+ power_supply_unregister(&pmu_ac); -+ac_register_failed: -+ platform_device_unregister(bat_pdev); -+pdev_register_failed: -+success: -+ return ret; -+} -+ -+static void __exit pmu_bat_exit(void) -+{ -+ int i; -+ -+ for (i = 0; i < PMU_MAX_BATTERIES; i++) { -+ if (!pbats[i]) -+ continue; -+ power_supply_unregister(&pbats[i]->bat); -+ kfree(pbats[i]); -+ } -+ power_supply_unregister(&pmu_ac); -+ platform_device_unregister(bat_pdev); -+ -+ return; -+} -+ -+module_init(pmu_bat_init); -+module_exit(pmu_bat_exit); -+ -+MODULE_AUTHOR("David Woodhouse "); -+MODULE_LICENSE("GPL"); -+MODULE_DESCRIPTION("PMU battery driver"); -Index: linux-2.6.22/drivers/power/power_supply_core.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/power_supply_core.c 2007-08-23 12:13:52.000000000 +0200 -@@ -0,0 +1,168 @@ -+/* -+ * Universal power supply monitor class -+ * -+ * Copyright (c) 2007 Anton Vorontsov -+ * Copyright (c) 2004 Szabolcs Gyurko -+ * Copyright (c) 2003 Ian Molton -+ * -+ * Modified: 2004, Oct Szabolcs Gyurko -+ * -+ * You may use this code as per GPL version 2 -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include "power_supply.h" -+ -+struct class *power_supply_class; -+ -+static void power_supply_changed_work(struct work_struct *work) -+{ -+ struct power_supply *psy = container_of(work, struct power_supply, -+ changed_work); -+ int i; -+ -+ dev_dbg(psy->dev, "%s\n", __FUNCTION__); -+ -+ for (i = 0; i < psy->num_supplicants; i++) { -+ struct device *dev; -+ -+ down(&power_supply_class->sem); -+ list_for_each_entry(dev, &power_supply_class->devices, node) { -+ struct power_supply *pst = dev_get_drvdata(dev); -+ -+ if (!strcmp(psy->supplied_to[i], pst->name)) { -+ if (pst->external_power_changed) -+ pst->external_power_changed(pst); -+ } -+ } -+ up(&power_supply_class->sem); -+ } -+ -+ power_supply_update_leds(psy); -+ -+ kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); -+ -+ return; -+} -+ -+void power_supply_changed(struct power_supply *psy) -+{ -+ dev_dbg(psy->dev, "%s\n", __FUNCTION__); -+ -+ schedule_work(&psy->changed_work); -+ -+ return; -+} -+ -+int power_supply_am_i_supplied(struct power_supply *psy) -+{ -+ union power_supply_propval ret = {0,}; -+ struct device *dev; -+ -+ down(&power_supply_class->sem); -+ list_for_each_entry(dev, &power_supply_class->devices, node) { -+ struct power_supply *epsy = dev_get_drvdata(dev); -+ int i; -+ -+ for (i = 0; i < epsy->num_supplicants; i++) { -+ if (!strcmp(epsy->supplied_to[i], psy->name)) { -+ if (epsy->get_property(epsy, -+ POWER_SUPPLY_PROP_ONLINE, &ret)) -+ continue; -+ if (ret.intval) -+ goto out; -+ } -+ } -+ } -+out: -+ up(&power_supply_class->sem); -+ -+ dev_dbg(psy->dev, "%s %d\n", __FUNCTION__, ret.intval); -+ -+ return ret.intval; -+} -+ -+int power_supply_register(struct device *parent, struct power_supply *psy) -+{ -+ int rc = 0; -+ -+ psy->dev = device_create(power_supply_class, parent, 0, -+ "%s", psy->name); -+ if (IS_ERR(psy->dev)) { -+ rc = PTR_ERR(psy->dev); -+ goto dev_create_failed; -+ } -+ -+ dev_set_drvdata(psy->dev, psy); -+ -+ INIT_WORK(&psy->changed_work, power_supply_changed_work); -+ -+ rc = power_supply_create_attrs(psy); -+ if (rc) -+ goto create_attrs_failed; -+ -+ rc = power_supply_create_triggers(psy); -+ if (rc) -+ goto create_triggers_failed; -+ -+ power_supply_changed(psy); -+ -+ goto success; -+ -+create_triggers_failed: -+ power_supply_remove_attrs(psy); -+create_attrs_failed: -+ device_unregister(psy->dev); -+dev_create_failed: -+success: -+ return rc; -+} -+ -+void power_supply_unregister(struct power_supply *psy) -+{ -+ flush_scheduled_work(); -+ power_supply_remove_triggers(psy); -+ power_supply_remove_attrs(psy); -+ device_unregister(psy->dev); -+ return; -+} -+ -+static int __init power_supply_class_init(void) -+{ -+ power_supply_class = class_create(THIS_MODULE, "power_supply"); -+ -+ if (IS_ERR(power_supply_class)) -+ return PTR_ERR(power_supply_class); -+ -+ power_supply_class->dev_uevent = power_supply_uevent; -+ -+ return 0; -+} -+ -+static void __exit power_supply_class_exit(void) -+{ -+ class_destroy(power_supply_class); -+ return; -+} -+ -+EXPORT_SYMBOL_GPL(power_supply_changed); -+EXPORT_SYMBOL_GPL(power_supply_am_i_supplied); -+EXPORT_SYMBOL_GPL(power_supply_register); -+EXPORT_SYMBOL_GPL(power_supply_unregister); -+ -+/* exported for the APM Power driver, APM emulation */ -+EXPORT_SYMBOL_GPL(power_supply_class); -+ -+subsys_initcall(power_supply_class_init); -+module_exit(power_supply_class_exit); -+ -+MODULE_DESCRIPTION("Universal power supply monitor class"); -+MODULE_AUTHOR("Ian Molton , " -+ "Szabolcs Gyurko, " -+ "Anton Vorontsov "); -+MODULE_LICENSE("GPL"); -Index: linux-2.6.22/drivers/power/power_supply.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/power_supply.h 2007-08-23 12:13:52.000000000 +0200 -@@ -0,0 +1,42 @@ -+/* -+ * Functions private to power supply class -+ * -+ * Copyright (c) 2007 Anton Vorontsov -+ * Copyright (c) 2004 Szabolcs Gyurko -+ * Copyright (c) 2003 Ian Molton -+ * -+ * Modified: 2004, Oct Szabolcs Gyurko -+ * -+ * You may use this code as per GPL version 2 -+ */ -+ -+#ifdef CONFIG_SYSFS -+ -+extern int power_supply_create_attrs(struct power_supply *psy); -+extern void power_supply_remove_attrs(struct power_supply *psy); -+extern int power_supply_uevent(struct device *dev, char **envp, int num_envp, -+ char *buffer, int buffer_size); -+ -+#else -+ -+static inline int power_supply_create_attrs(struct power_supply *psy) -+{ return 0; } -+static inline void power_supply_remove_attrs(struct power_supply *psy) {} -+#define power_supply_uevent NULL -+ -+#endif /* CONFIG_SYSFS */ -+ -+#ifdef CONFIG_LEDS_TRIGGERS -+ -+extern void power_supply_update_leds(struct power_supply *psy); -+extern int power_supply_create_triggers(struct power_supply *psy); -+extern void power_supply_remove_triggers(struct power_supply *psy); -+ -+#else -+ -+static inline void power_supply_update_leds(struct power_supply *psy) {} -+static inline int power_supply_create_triggers(struct power_supply *psy) -+{ return 0; } -+static inline void power_supply_remove_triggers(struct power_supply *psy) {} -+ -+#endif /* CONFIG_LEDS_TRIGGERS */ -Index: linux-2.6.22/drivers/power/power_supply_leds.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/power_supply_leds.c 2007-08-23 12:13:52.000000000 +0200 -@@ -0,0 +1,188 @@ -+/* -+ * LEDs triggers for power supply class -+ * -+ * Copyright (c) 2007 Anton Vorontsov -+ * Copyright (c) 2004 Szabolcs Gyurko -+ * Copyright (c) 2003 Ian Molton -+ * -+ * Modified: 2004, Oct Szabolcs Gyurko -+ * -+ * You may use this code as per GPL version 2 -+ */ -+ -+#include -+ -+/* If we have hwtimer trigger, then use it to blink charging LED */ -+ -+#if defined(CONFIG_LEDS_TRIGGER_HWTIMER) || \ -+ (defined(CONFIG_BATTERY_MODULE) && \ -+ defined(CONFIG_LEDS_TRIGGER_HWTIMER_MODULE)) -+ #define led_trigger_register_charging led_trigger_register_hwtimer -+ #define led_trigger_unregister_charging led_trigger_unregister_hwtimer -+#else -+ #define led_trigger_register_charging led_trigger_register_simple -+ #define led_trigger_unregister_charging led_trigger_unregister_simple -+#endif -+ -+/* Battery specific LEDs triggers. */ -+ -+static void power_supply_update_bat_leds(struct power_supply *psy) -+{ -+ union power_supply_propval status; -+ -+ if (psy->get_property(psy, POWER_SUPPLY_PROP_STATUS, &status)) -+ return; -+ -+ dev_dbg(psy->dev, "%s %d\n", __FUNCTION__, status.intval); -+ -+ switch(status.intval) { -+ case POWER_SUPPLY_STATUS_FULL: -+ led_trigger_event(psy->charging_full_trig, LED_FULL); -+ led_trigger_event(psy->charging_trig, LED_OFF); -+ led_trigger_event(psy->full_trig, LED_FULL); -+ break; -+ case POWER_SUPPLY_STATUS_CHARGING: -+ led_trigger_event(psy->charging_full_trig, LED_FULL); -+ led_trigger_event(psy->charging_trig, LED_FULL); -+ led_trigger_event(psy->full_trig, LED_OFF); -+ break; -+ default: -+ led_trigger_event(psy->charging_full_trig, LED_OFF); -+ led_trigger_event(psy->charging_trig, LED_OFF); -+ led_trigger_event(psy->full_trig, LED_OFF); -+ break; -+ } -+ -+ return; -+} -+ -+static int power_supply_create_bat_triggers(struct power_supply *psy) -+{ -+ int rc = 0; -+ -+ psy->charging_full_trig_name = kmalloc(strlen(psy->name) + -+ sizeof("-charging-or-full"), GFP_KERNEL); -+ if (!psy->charging_full_trig_name) -+ goto charging_full_failed; -+ -+ psy->charging_trig_name = kmalloc(strlen(psy->name) + -+ sizeof("-charging"), GFP_KERNEL); -+ if (!psy->charging_trig_name) -+ goto charging_failed; -+ -+ psy->full_trig_name = kmalloc(strlen(psy->name) + -+ sizeof("-full"), GFP_KERNEL); -+ if (!psy->full_trig_name) -+ goto full_failed; -+ -+ strcpy(psy->charging_full_trig_name, psy->name); -+ strcat(psy->charging_full_trig_name, "-charging-or-full"); -+ strcpy(psy->charging_trig_name, psy->name); -+ strcat(psy->charging_trig_name, "-charging"); -+ strcpy(psy->full_trig_name, psy->name); -+ strcat(psy->full_trig_name, "-full"); -+ -+ led_trigger_register_simple(psy->charging_full_trig_name, -+ &psy->charging_full_trig); -+ led_trigger_register_charging(psy->charging_trig_name, -+ &psy->charging_trig); -+ led_trigger_register_simple(psy->full_trig_name, -+ &psy->full_trig); -+ -+ goto success; -+ -+full_failed: -+ kfree(psy->charging_trig_name); -+charging_failed: -+ kfree(psy->charging_full_trig_name); -+charging_full_failed: -+ rc = -ENOMEM; -+success: -+ return rc; -+} -+ -+static void power_supply_remove_bat_triggers(struct power_supply *psy) -+{ -+ led_trigger_unregister_simple(psy->charging_full_trig); -+ led_trigger_unregister_charging(psy->charging_trig); -+ led_trigger_unregister_simple(psy->full_trig); -+ kfree(psy->full_trig_name); -+ kfree(psy->charging_trig_name); -+ kfree(psy->charging_full_trig_name); -+ return; -+} -+ -+/* Generated power specific LEDs triggers. */ -+ -+static void power_supply_update_gen_leds(struct power_supply *psy) -+{ -+ union power_supply_propval online; -+ -+ if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &online)) -+ return; -+ -+ dev_dbg(psy->dev, "%s %d\n", __FUNCTION__, online.intval); -+ -+ if (online.intval) -+ led_trigger_event(psy->online_trig, LED_FULL); -+ else -+ led_trigger_event(psy->online_trig, LED_OFF); -+ -+ return; -+} -+ -+static int power_supply_create_gen_triggers(struct power_supply *psy) -+{ -+ int rc = 0; -+ -+ psy->online_trig_name = kmalloc(strlen(psy->name) + sizeof("-online"), -+ GFP_KERNEL); -+ if (!psy->online_trig_name) -+ goto online_failed; -+ -+ strcpy(psy->online_trig_name, psy->name); -+ strcat(psy->online_trig_name, "-online"); -+ -+ led_trigger_register_simple(psy->online_trig_name, &psy->online_trig); -+ -+ goto success; -+ -+online_failed: -+ rc = -ENOMEM; -+success: -+ return rc; -+} -+ -+static void power_supply_remove_gen_triggers(struct power_supply *psy) -+{ -+ led_trigger_unregister_simple(psy->online_trig); -+ kfree(psy->online_trig_name); -+ return; -+} -+ -+/* Choice what triggers to create&update. */ -+ -+void power_supply_update_leds(struct power_supply *psy) -+{ -+ if (psy->type == POWER_SUPPLY_TYPE_BATTERY) -+ power_supply_update_bat_leds(psy); -+ else -+ power_supply_update_gen_leds(psy); -+ return; -+} -+ -+int power_supply_create_triggers(struct power_supply *psy) -+{ -+ if (psy->type == POWER_SUPPLY_TYPE_BATTERY) -+ return power_supply_create_bat_triggers(psy); -+ return power_supply_create_gen_triggers(psy); -+} -+ -+void power_supply_remove_triggers(struct power_supply *psy) -+{ -+ if (psy->type == POWER_SUPPLY_TYPE_BATTERY) -+ power_supply_remove_bat_triggers(psy); -+ else -+ power_supply_remove_gen_triggers(psy); -+ return; -+} -Index: linux-2.6.22/drivers/power/power_supply_sysfs.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/power_supply_sysfs.c 2007-08-23 12:13:52.000000000 +0200 -@@ -0,0 +1,289 @@ -+/* -+ * Sysfs interface for the universal power supply monitor class -+ * -+ * Copyright © 2007 David Woodhouse -+ * Copyright (c) 2007 Anton Vorontsov -+ * Copyright (c) 2004 Szabolcs Gyurko -+ * Copyright (c) 2003 Ian Molton -+ * -+ * Modified: 2004, Oct Szabolcs Gyurko -+ * -+ * You may use this code as per GPL version 2 -+ */ -+ -+#include -+#include -+ -+/* -+ * This is because the name "current" breaks the device attr macro. -+ * The "current" word resolvs to "(get_current())" so instead of -+ * "current" "(get_current())" appears in the sysfs. -+ * -+ * The source of this definition is the device.h which calls __ATTR -+ * macro in sysfs.h which calls the __stringify macro. -+ * -+ * Only modification that the name is not tried to be resolved -+ * (as a macro let's say). -+ */ -+ -+#define POWER_SUPPLY_ATTR(_name) \ -+{ \ -+ .attr = { .name = #_name, .mode = 0444, .owner = THIS_MODULE }, \ -+ .show = power_supply_show_property, \ -+ .store = NULL, \ -+} -+ -+static struct device_attribute power_supply_attrs[]; -+ -+static ssize_t power_supply_show_property(struct device *dev, -+ struct device_attribute *attr, -+ char *buf) { -+ static char *status_text[] = { -+ "Unknown", "Charging", "Discharging", "Not charging", "Full" -+ }; -+ static char *health_text[] = { -+ "Unknown", "Good", "Overheat", "Dead" -+ }; -+ static char *technology_text[] = { -+ "Unknown", "NiMH", "Li-ion", "Li-poly" -+ }; -+ static char *capacity_level_text[] = { -+ "Unknown", "Critical", "Low", "Normal", "High", "Full" -+ }; -+ ssize_t ret; -+ struct power_supply *psy = dev_get_drvdata(dev); -+ const ptrdiff_t off = attr - power_supply_attrs; -+ union power_supply_propval value; -+ -+ ret = psy->get_property(psy, off, &value); -+ -+ if (ret < 0) { -+ dev_err(dev, "driver failed to report `%s' property\n", -+ attr->attr.name); -+ return ret; -+ } -+ -+ if (off == POWER_SUPPLY_PROP_STATUS) -+ return sprintf(buf, "%s\n", status_text[value.intval]); -+ else if (off == POWER_SUPPLY_PROP_HEALTH) -+ return sprintf(buf, "%s\n", health_text[value.intval]); -+ else if (off == POWER_SUPPLY_PROP_TECHNOLOGY) -+ return sprintf(buf, "%s\n", technology_text[value.intval]); -+ else if (off == POWER_SUPPLY_PROP_CAPACITY_LEVEL) -+ return sprintf(buf, "%s\n", -+ capacity_level_text[value.intval]); -+ else if (off == POWER_SUPPLY_PROP_MODEL_NAME) -+ return sprintf(buf, "%s\n", value.strval); -+ -+ return sprintf(buf, "%d\n", value.intval); -+} -+ -+/* Must be in the same order as POWER_SUPPLY_PROP_* */ -+static struct device_attribute power_supply_attrs[] = { -+ /* Properties of type `int' */ -+ POWER_SUPPLY_ATTR(status), -+ POWER_SUPPLY_ATTR(health), -+ POWER_SUPPLY_ATTR(present), -+ POWER_SUPPLY_ATTR(online), -+ POWER_SUPPLY_ATTR(technology), -+ POWER_SUPPLY_ATTR(voltage_max_design), -+ POWER_SUPPLY_ATTR(voltage_min_design), -+ POWER_SUPPLY_ATTR(voltage_now), -+ POWER_SUPPLY_ATTR(voltage_avg), -+ POWER_SUPPLY_ATTR(current_now), -+ POWER_SUPPLY_ATTR(current_avg), -+ POWER_SUPPLY_ATTR(charge_full_design), -+ POWER_SUPPLY_ATTR(charge_empty_design), -+ POWER_SUPPLY_ATTR(charge_full), -+ POWER_SUPPLY_ATTR(charge_empty), -+ POWER_SUPPLY_ATTR(charge_now), -+ POWER_SUPPLY_ATTR(charge_avg), -+ POWER_SUPPLY_ATTR(energy_full_design), -+ POWER_SUPPLY_ATTR(energy_empty_design), -+ POWER_SUPPLY_ATTR(energy_full), -+ POWER_SUPPLY_ATTR(energy_empty), -+ POWER_SUPPLY_ATTR(energy_now), -+ POWER_SUPPLY_ATTR(energy_avg), -+ POWER_SUPPLY_ATTR(capacity), -+ POWER_SUPPLY_ATTR(capacity_level), -+ POWER_SUPPLY_ATTR(temp), -+ POWER_SUPPLY_ATTR(temp_ambient), -+ POWER_SUPPLY_ATTR(time_to_empty_now), -+ POWER_SUPPLY_ATTR(time_to_empty_avg), -+ POWER_SUPPLY_ATTR(time_to_full_now), -+ POWER_SUPPLY_ATTR(time_to_full_avg), -+ /* Properties of type `const char *' */ -+ POWER_SUPPLY_ATTR(model_name), -+}; -+ -+static ssize_t power_supply_show_static_attrs(struct device *dev, -+ struct device_attribute *attr, -+ char *buf) { -+ static char *type_text[] = { "Battery", "UPS", "Mains", "USB" }; -+ struct power_supply *psy = dev_get_drvdata(dev); -+ -+ return sprintf(buf, "%s\n", type_text[psy->type]); -+} -+ -+static struct device_attribute power_supply_static_attrs[] = { -+ __ATTR(type, 0444, power_supply_show_static_attrs, NULL), -+}; -+ -+int power_supply_create_attrs(struct power_supply *psy) -+{ -+ int rc = 0; -+ int i, j; -+ -+ for (i = 0; i < ARRAY_SIZE(power_supply_static_attrs); i++) { -+ rc = device_create_file(psy->dev, -+ &power_supply_static_attrs[i]); -+ if (rc) -+ goto statics_failed; -+ } -+ -+ for (j = 0; j < psy->num_properties; j++) { -+ rc = device_create_file(psy->dev, -+ &power_supply_attrs[psy->properties[j]]); -+ if (rc) -+ goto dynamics_failed; -+ } -+ -+ goto succeed; -+ -+dynamics_failed: -+ while (j--) -+ device_remove_file(psy->dev, -+ &power_supply_attrs[psy->properties[j]]); -+statics_failed: -+ while (i--) -+ device_remove_file(psy->dev, -+ &power_supply_static_attrs[psy->properties[i]]); -+succeed: -+ return rc; -+} -+ -+void power_supply_remove_attrs(struct power_supply *psy) -+{ -+ int i; -+ -+ for (i = 0; i < ARRAY_SIZE(power_supply_static_attrs); i++) -+ device_remove_file(psy->dev, -+ &power_supply_static_attrs[i]); -+ -+ for (i = 0; i < psy->num_properties; i++) -+ device_remove_file(psy->dev, -+ &power_supply_attrs[psy->properties[i]]); -+ -+ return; -+} -+ -+static char *kstruprdup(const char *str, gfp_t gfp) -+{ -+ char *ret, *ustr; -+ -+ ustr = ret = kmalloc(strlen(str) + 1, gfp); -+ -+ if (!ret) -+ return NULL; -+ -+ while (*str) -+ *ustr++ = toupper(*str++); -+ -+ *ustr = 0; -+ -+ return ret; -+} -+ -+int power_supply_uevent(struct device *dev, char **envp, int num_envp, -+ char *buffer, int buffer_size) -+{ -+ struct power_supply *psy = dev_get_drvdata(dev); -+ int i = 0, length = 0, ret = 0, j; -+ char *prop_buf; -+ char *attrname; -+ -+ dev_dbg(dev, "uevent\n"); -+ -+ if (!psy) { -+ dev_dbg(dev, "No power supply yet\n"); -+ return ret; -+ } -+ -+ dev_dbg(dev, "POWER_SUPPLY_NAME=%s\n", psy->name); -+ -+ ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, -+ &length, "POWER_SUPPLY_NAME=%s", psy->name); -+ if (ret) -+ return ret; -+ -+ prop_buf = (char *)get_zeroed_page(GFP_KERNEL); -+ if (!prop_buf) -+ return -ENOMEM; -+ -+ for (j = 0; j < ARRAY_SIZE(power_supply_static_attrs); j++) { -+ struct device_attribute *attr; -+ char *line; -+ -+ attr = &power_supply_static_attrs[j]; -+ -+ ret = power_supply_show_static_attrs(dev, attr, prop_buf); -+ if (ret < 0) -+ goto out; -+ -+ line = strchr(prop_buf, '\n'); -+ if (line) -+ *line = 0; -+ -+ attrname = kstruprdup(attr->attr.name, GFP_KERNEL); -+ if (!attrname) { -+ ret = -ENOMEM; -+ goto out; -+ } -+ -+ dev_dbg(dev, "Static prop %s=%s\n", attrname, prop_buf); -+ -+ ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, -+ &length, "POWER_SUPPLY_%s=%s", -+ attrname, prop_buf); -+ kfree(attrname); -+ if (ret) -+ goto out; -+ } -+ -+ dev_dbg(dev, "%zd dynamic props\n", psy->num_properties); -+ -+ for (j = 0; j < psy->num_properties; j++) { -+ struct device_attribute *attr; -+ char *line; -+ -+ attr = &power_supply_attrs[psy->properties[j]]; -+ -+ ret = power_supply_show_property(dev, attr, prop_buf); -+ if (ret < 0) -+ goto out; -+ -+ line = strchr(prop_buf, '\n'); -+ if (line) -+ *line = 0; -+ -+ attrname = kstruprdup(attr->attr.name, GFP_KERNEL); -+ if (!attrname) { -+ ret = -ENOMEM; -+ goto out; -+ } -+ -+ dev_dbg(dev, "prop %s=%s\n", attrname, prop_buf); -+ -+ ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, -+ &length, "POWER_SUPPLY_%s=%s", -+ attrname, prop_buf); -+ kfree(attrname); -+ if (ret) -+ goto out; -+ } -+ -+out: -+ free_page((unsigned long)prop_buf); -+ -+ return ret; -+} -Index: linux-2.6.22/drivers/power/simpad-battery.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/drivers/power/simpad-battery.c 2007-08-23 12:13:52.000000000 +0200 -@@ -0,0 +1,242 @@ -+/* -+ * linux/drivers/misc/simpad-battery.c -+ * -+ * Copyright (C) 2005 Holger Hans Peter Freyther -+ * Copyright (C) 2001 Juergen Messerer -+ * -+ * This program is free software; you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation; either version 2 of the License. -+ * -+ * Read the Battery Level through the UCB1x00 chip. T-Sinuspad is -+ * unsupported for now. -+ * -+ */ -+ -+#include -+#include -+#include "ucb1x00.h" -+ -+ -+/* -+ * Conversion from AD -> mV -+ * 7.5V = 1023 7.3313mV/Digit -+ * -+ * 400 Units == 9.7V -+ * a = ADC value -+ * 21 = ADC error -+ * 12600 = Divident to get 2*7.3242 -+ * 860 = Divider to get 2*7.3242 -+ * 170 = Voltagedrop over -+ */ -+#define CALIBRATE_BATTERY(a) ((((a + 21)*12600)/860) + 170) -+ -+/* -+ * We have two types of batteries a small and a large one -+ * To get the right value we to distinguish between those two -+ * 450 Units == 15 V -+ */ -+#define CALIBRATE_SUPPLY(a) (((a) * 1500) / 45) -+#define MIN_SUPPLY 12000 /* Less then 12V means no powersupply */ -+ -+/* -+ * Charging Current -+ * if value is >= 50 then charging is on -+ */ -+#define CALIBRATE_CHARGING(a) (((a)* 1000)/(152/4))) -+ -+struct simpad_battery_t { -+ struct battery battery; -+ struct ucb1x00* ucb; -+ -+ /* -+ * Variables for the values to one time support -+ * T-Sinuspad as well -+ */ -+ int min_voltage; -+ int min_current; -+ int min_charge; -+ -+ int max_voltage; -+ int max_current; -+ int max_charge; -+ -+ int min_supply; -+ int charging_led_label; -+ int charging_max_label; -+ int batt_full; -+ int batt_low; -+ int batt_critical; -+ int batt_empty; -+}; -+ -+static int simpad_get_min_voltage(struct battery* _battery ) -+{ -+ struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; -+ return battery->min_voltage; -+} -+ -+static int simpad_get_min_current(struct battery* _battery) -+{ -+ struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; -+ return battery->min_current; -+} -+ -+static int simpad_get_min_charge(struct battery* _battery) -+{ -+ struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; -+ return battery->min_charge; -+} -+ -+static int simpad_get_max_voltage(struct battery* _battery) -+{ -+ struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; -+ return battery->max_voltage; -+} -+ -+static int simpad_get_max_current(struct battery* _battery) -+{ -+ struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; -+ return battery->max_current; -+} -+ -+static int simpad_get_max_charge(struct battery* _battery) -+{ -+ struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; -+ return battery->max_charge; -+} -+ -+static int simpad_get_temp(struct battery* _battery) -+{ -+ return 0; -+} -+ -+static int simpad_get_voltage(struct battery* _battery) -+{ -+ int val; -+ struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; -+ -+ -+ ucb1x00_adc_enable(battery->ucb); -+ val = ucb1x00_adc_read(battery->ucb, UCB_ADC_INP_AD1, UCB_NOSYNC); -+ ucb1x00_adc_disable(battery->ucb); -+ -+ return CALIBRATE_BATTERY(val); -+} -+ -+static int simpad_get_current(struct battery* _battery) -+{ -+ int val; -+ struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; -+ -+ ucb1x00_adc_enable(battery->ucb); -+ val = ucb1x00_adc_read(battery->ucb, UCB_ADC_INP_AD3, UCB_NOSYNC); -+ ucb1x00_adc_disable(battery->ucb); -+ -+ return val; -+} -+ -+static int simpad_get_charge(struct battery* _battery) -+{ -+ int val; -+ struct simpad_battery_t* battery = (struct simpad_battery_t*)_battery; -+ -+ ucb1x00_adc_enable(battery->ucb); -+ val = ucb1x00_adc_read(battery->ucb, UCB_ADC_INP_AD2, UCB_NOSYNC); -+ ucb1x00_adc_disable(battery->ucb); -+ -+ return CALIBRATE_SUPPLY(val); -+ -+} -+ -+static int simpad_get_status(struct battery* _battery) -+{ -+ struct simpad_battery_t* battery = (struct simpad_battery_t*)(_battery); -+ int vcharger = simpad_get_voltage(_battery); -+ int icharger = simpad_get_current(_battery); -+ -+ int status = BATTERY_STATUS_UNKNOWN; -+ if(icharger > battery->charging_led_label) -+ status = BATTERY_STATUS_CHARGING; -+ else if(vcharger > battery->min_supply) -+ status = BATTERY_STATUS_NOT_CHARGING; -+ else -+ status = BATTERY_STATUS_DISCHARGING; -+ -+ return status; -+} -+ -+static struct simpad_battery_t simpad_battery = { -+ .battery = { -+ .get_min_voltage = simpad_get_min_voltage, -+ .get_min_current = simpad_get_min_current, -+ .get_min_charge = simpad_get_min_charge, -+ .get_max_voltage = simpad_get_max_voltage, -+ .get_max_current = simpad_get_max_current, -+ .get_max_charge = simpad_get_max_charge, -+ .get_temp = simpad_get_temp, -+ .get_voltage = simpad_get_voltage, -+ .get_current = simpad_get_current, -+ .get_charge = simpad_get_charge, -+ .get_status = simpad_get_status, -+ }, -+ .min_voltage = 0, -+ .min_current = 0, -+ .min_charge = 0, -+ .max_voltage = 0, -+ .max_current = 0, -+ .max_charge = 0, -+ -+ .min_supply = 1200, -+ .charging_led_label = 18, -+ .charging_max_label = 265, -+ .batt_full = 8300, -+ .batt_low = 7300, -+ .batt_critical = 6800, -+ .batt_empty = 6500, -+}; -+ -+ -+ -+/* -+ * UCB glue code -+ */ -+static int ucb1x00_battery_add(struct class_device *dev) -+{ -+ struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); -+ simpad_battery.ucb = ucb; -+ -+ battery_class_register(&simpad_battery.battery); -+ -+ return 0; -+} -+ -+static void ucb1x00_battery_remove(struct class_device *dev) -+{ -+ return battery_class_unregister(&simpad_battery.battery); -+} -+ -+ -+static struct ucb1x00_class_interface ucb1x00_battery_interface = { -+ .interface = { -+ .add = ucb1x00_battery_add, -+ .remove = ucb1x00_battery_remove, -+ }, -+}; -+ -+ -+static int __init battery_register(void) -+{ -+ return ucb1x00_register_interface(&ucb1x00_battery_interface); -+} -+ -+static void __exit battery_unregister(void) -+{ -+ ucb1x00_unregister_interface(&ucb1x00_battery_interface); -+} -+ -+module_init(battery_register); -+module_exit(battery_unregister); -+ -+MODULE_AUTHOR("Holger Hans Peter Freyther"); -+MODULE_LICENSE("GPL"); -Index: linux-2.6.22/arch/arm/Kconfig -=================================================================== ---- linux-2.6.22.orig/arch/arm/Kconfig 2007-08-23 12:17:42.000000000 +0200 -+++ linux-2.6.22/arch/arm/Kconfig 2007-08-23 12:22:28.000000000 +0200 -@@ -1016,6 +1016,8 @@ - - source "drivers/w1/Kconfig" - -+source "drivers/power/Kconfig" -+ - source "drivers/hwmon/Kconfig" - - #source "drivers/l3/Kconfig" -Index: linux-2.6.22/drivers/Kconfig -=================================================================== ---- linux-2.6.22.orig/drivers/Kconfig 2007-08-23 12:21:27.000000000 +0200 -+++ linux-2.6.22/drivers/Kconfig 2007-08-23 12:22:03.000000000 +0200 -@@ -54,6 +54,8 @@ - - source "drivers/w1/Kconfig" - -+source "drivers/power/Kconfig" -+ - source "drivers/hwmon/Kconfig" - - source "drivers/mfd/Kconfig" -Index: linux-2.6.22/drivers/Makefile -=================================================================== ---- linux-2.6.22.orig/drivers/Makefile 2007-08-23 12:33:58.000000000 +0200 -+++ linux-2.6.22/drivers/Makefile 2007-08-23 12:34:34.000000000 +0200 -@@ -61,6 +61,7 @@ - obj-$(CONFIG_RTC_LIB) += rtc/ - obj-y += i2c/ - obj-$(CONFIG_W1) += w1/ -+obj-$(CONFIG_POWER_SUPPLY) += power/ - obj-$(CONFIG_HWMON) += hwmon/ - obj-$(CONFIG_PHONE) += telephony/ - obj-$(CONFIG_MD) += md/ -Index: linux-2.6.22/include/linux/power_supply.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.22/include/linux/power_supply.h 2007-08-23 12:37:10.000000000 +0200 -@@ -0,0 +1,175 @@ -+/* -+ * Universal power supply monitor class -+ * -+ * Copyright (c) 2007 Anton Vorontsov -+ * Copyright (c) 2004 Szabolcs Gyurko -+ * Copyright (c) 2003 Ian Molton -+ * -+ * Modified: 2004, Oct Szabolcs Gyurko -+ * -+ * You may use this code as per GPL version 2 -+ */ -+ -+#ifndef __LINUX_POWER_SUPPLY_H__ -+#define __LINUX_POWER_SUPPLY_H__ -+ -+#include -+#include -+#include -+ -+/* -+ * All voltages, currents, charges, energies, time and temperatures in uV, -+ * uA, uAh, uWh, seconds and tenths of degree Celsius unless otherwise -+ * stated. It's driver's job to convert its raw values to units in which -+ * this class operates. -+ */ -+ -+/* -+ * For systems where the charger determines the maximum battery capacity -+ * the min and max fields should be used to present these values to user -+ * space. Unused/unknown fields will not appear in sysfs. -+ */ -+ -+enum { -+ POWER_SUPPLY_STATUS_UNKNOWN = 0, -+ POWER_SUPPLY_STATUS_CHARGING, -+ POWER_SUPPLY_STATUS_DISCHARGING, -+ POWER_SUPPLY_STATUS_NOT_CHARGING, -+ POWER_SUPPLY_STATUS_FULL, -+}; -+ -+enum { -+ POWER_SUPPLY_HEALTH_UNKNOWN = 0, -+ POWER_SUPPLY_HEALTH_GOOD, -+ POWER_SUPPLY_HEALTH_OVERHEAT, -+ POWER_SUPPLY_HEALTH_DEAD, -+}; -+ -+enum { -+ POWER_SUPPLY_TECHNOLOGY_UNKNOWN = 0, -+ POWER_SUPPLY_TECHNOLOGY_NIMH, -+ POWER_SUPPLY_TECHNOLOGY_LION, -+ POWER_SUPPLY_TECHNOLOGY_LIPO, -+}; -+ -+enum { -+ POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0, -+ POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL, -+ POWER_SUPPLY_CAPACITY_LEVEL_LOW, -+ POWER_SUPPLY_CAPACITY_LEVEL_NORMAL, -+ POWER_SUPPLY_CAPACITY_LEVEL_HIGH, -+ POWER_SUPPLY_CAPACITY_LEVEL_FULL, -+}; -+ -+enum power_supply_property { -+ /* Properties of type `int' */ -+ POWER_SUPPLY_PROP_STATUS = 0, -+ POWER_SUPPLY_PROP_HEALTH, -+ POWER_SUPPLY_PROP_PRESENT, -+ POWER_SUPPLY_PROP_ONLINE, -+ POWER_SUPPLY_PROP_TECHNOLOGY, -+ POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, -+ POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, -+ POWER_SUPPLY_PROP_VOLTAGE_NOW, -+ POWER_SUPPLY_PROP_VOLTAGE_AVG, -+ POWER_SUPPLY_PROP_CURRENT_NOW, -+ POWER_SUPPLY_PROP_CURRENT_AVG, -+ POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, -+ POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN, -+ POWER_SUPPLY_PROP_CHARGE_FULL, -+ POWER_SUPPLY_PROP_CHARGE_EMPTY, -+ POWER_SUPPLY_PROP_CHARGE_NOW, -+ POWER_SUPPLY_PROP_CHARGE_AVG, -+ POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, -+ POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN, -+ POWER_SUPPLY_PROP_ENERGY_FULL, -+ POWER_SUPPLY_PROP_ENERGY_EMPTY, -+ POWER_SUPPLY_PROP_ENERGY_NOW, -+ POWER_SUPPLY_PROP_ENERGY_AVG, -+ POWER_SUPPLY_PROP_CAPACITY, /* in percents! */ -+ POWER_SUPPLY_PROP_CAPACITY_LEVEL, -+ POWER_SUPPLY_PROP_TEMP, -+ POWER_SUPPLY_PROP_TEMP_AMBIENT, -+ POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, -+ POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, -+ POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, -+ POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, -+ /* Properties of type `const char *' */ -+ POWER_SUPPLY_PROP_MODEL_NAME, -+}; -+ -+enum power_supply_type { -+ POWER_SUPPLY_TYPE_BATTERY = 0, -+ POWER_SUPPLY_TYPE_UPS, -+ POWER_SUPPLY_TYPE_MAINS, -+ POWER_SUPPLY_TYPE_USB, -+}; -+ -+union power_supply_propval { -+ int intval; -+ const char *strval; -+}; -+ -+struct power_supply { -+ const char *name; -+ enum power_supply_type type; -+ enum power_supply_property *properties; -+ size_t num_properties; -+ -+ char **supplied_to; -+ size_t num_supplicants; -+ -+ int (*get_property)(struct power_supply *psy, -+ enum power_supply_property psp, -+ union power_supply_propval *val); -+ void (*external_power_changed)(struct power_supply *psy); -+ -+ /* For APM emulation, think legacy userspace. */ -+ int use_for_apm; -+ -+ /* private */ -+ struct device *dev; -+ struct work_struct changed_work; -+ -+#ifdef CONFIG_LEDS_TRIGGERS -+ struct led_trigger *charging_full_trig; -+ char *charging_full_trig_name; -+ struct led_trigger *charging_trig; -+ char *charging_trig_name; -+ struct led_trigger *full_trig; -+ char *full_trig_name; -+ struct led_trigger *online_trig; -+ char *online_trig_name; -+#endif -+}; -+ -+/* -+ * This is recommended structure to specify static power supply parameters. -+ * Generic one, parametrizable for different power supplies. Power supply -+ * class itself does not use it, but that's what implementing most platform -+ * drivers, should try reuse for consistency. -+ */ -+ -+struct power_supply_info { -+ const char *name; -+ int technology; -+ int voltage_max_design; -+ int voltage_min_design; -+ int charge_full_design; -+ int charge_empty_design; -+ int energy_full_design; -+ int energy_empty_design; -+ int use_for_apm; -+}; -+ -+extern void power_supply_changed(struct power_supply *psy); -+extern int power_supply_am_i_supplied(struct power_supply *psy); -+ -+extern int power_supply_register(struct device *parent, -+ struct power_supply *psy); -+extern void power_supply_unregister(struct power_supply *psy); -+ -+/* For APM emulation, think legacy userspace. */ -+extern struct class *power_supply_class; -+ -+#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 000000000..e2d0060ac --- /dev/null +++ b/meta/packages/linux/linux-rp-2.6.23/versatile-armv6.patch @@ -0,0 +1,19 @@ +--- + arch/arm/mm/Kconfig | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- linux-2.6.23.orig/arch/arm/mm/Kconfig ++++ linux-2.6.23/arch/arm/mm/Kconfig +@@ -343,11 +343,11 @@ config CPU_XSC3 + select IO_36 + + # ARMv6 + config CPU_V6 + bool "Support ARM V6 processor" +- depends on ARCH_INTEGRATOR || MACH_REALVIEW_EB || ARCH_OMAP2 || ARCH_MX3 ++ depends on ARCH_INTEGRATOR || MACH_REALVIEW_EB || ARCH_OMAP2 || ARCH_MX3 || ARCH_VERSATILE_PB + default y if ARCH_MX3 + select CPU_32v6 + select CPU_ABRT_EV6 + select CPU_CACHE_V6 + 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 5a51d1c3f..000000000 --- a/meta/packages/linux/linux-rp-2.6.23/vt_ioctl_race.patch +++ /dev/null @@ -1,46 +0,0 @@ ---- - drivers/char/vt_ioctl.c | 8 +++++--- - 1 file changed, 5 insertions(+), 3 deletions(-) - -Index: linux-2.6.22/drivers/char/vt_ioctl.c -=================================================================== ---- linux-2.6.22.orig/drivers/char/vt_ioctl.c 2007-07-09 01:32:17.000000000 +0200 -+++ linux-2.6.22/drivers/char/vt_ioctl.c 2007-09-27 11:58:42.000000000 +0200 -@@ -770,6 +770,7 @@ - /* - * Switching-from response - */ -+ acquire_console_sem(); - if (vc->vt_newvt >= 0) { - if (arg == 0) - /* -@@ -784,7 +785,6 @@ - * complete the switch. - */ - int newvt; -- acquire_console_sem(); - newvt = vc->vt_newvt; - vc->vt_newvt = -1; - i = vc_allocate(newvt); -@@ -798,7 +798,6 @@ - * other console switches.. - */ - complete_change_console(vc_cons[newvt].d); -- release_console_sem(); - } - } - -@@ -810,9 +809,12 @@ - /* - * If it's just an ACK, ignore it - */ -- if (arg != VT_ACKACQ) -+ if (arg != VT_ACKACQ) { -+ release_console_sem(); - return -EINVAL; -+ } - } -+ release_console_sem(); - - return 0; - 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 8cbbb6bd0..000000000 --- a/meta/packages/linux/linux-rp-2.6.23/w100fb-unused-var.patch +++ /dev/null @@ -1,17 +0,0 @@ -From: Marcin Juszkiewicz - -drivers/video/w100fb.c: In function ‘w100fb_imageblit’: -drivers/video/w100fb.c:507: warning: unused variable ‘par’ - -Signed-off-by: Marcin Juszkiewicz - ---- linux-2.6.23/drivers/video/w100fb.c 2007-10-11 16:52:30.000000000 +0200 -+++ linux-2.6.23/drivers/video/w100fb.c 2007-10-15 12:56:01.000000000 +0200 -@@ -504,7 +504,6 @@ static void w100_hostdata(u32 width, u32 - static void w100fb_imageblit(struct fb_info *info, - const struct fb_image *image) - { -- struct w100fb_par *par = info->par; - union dp_gui_master_cntl_u gmc; - u32 fgcolor, bgcolor; - 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 000000000..78e81ea83 --- /dev/null +++ b/meta/packages/linux/linux-rp-2.6.23/wm9712-reset-loop-r2.patch @@ -0,0 +1,44 @@ + sound/soc/codecs/wm9712.c | 28 ++++++++++++++++++---------- + 1 file changed, 18 insertions(+), 10 deletions(-) + +Index: git/sound/soc/codecs/wm9712.c +=================================================================== +--- git.orig/sound/soc/codecs/wm9712.c 2006-11-07 22:10:01.000000000 +0000 ++++ git/sound/soc/codecs/wm9712.c 2006-11-07 22:11:50.000000000 +0000 +@@ -618,18 +618,26 @@ static int wm9712_dapm_event(struct snd_ + + static int wm9712_reset(struct snd_soc_codec *codec, int try_warm) + { +- if (try_warm && soc_ac97_ops.warm_reset) { +- soc_ac97_ops.warm_reset(codec->ac97); +- if (!(ac97_read(codec, 0) & 0x8000)) +- return 1; +- } ++ int retry = 3; + +- soc_ac97_ops.reset(codec->ac97); +- if (ac97_read(codec, 0) & 0x8000) +- goto err; +- return 0; ++ while (retry--) ++ { ++ if(try_warm && soc_ac97_ops.warm_reset) { ++ soc_ac97_ops.warm_reset(codec->ac97); ++ if(ac97_read(codec, 0) & 0x8000) ++ continue; ++ else ++ return 1; ++ } ++ ++ soc_ac97_ops.reset(codec->ac97); ++ if(ac97_read(codec, 0) & 0x8000) ++ continue; ++ else ++ return 0; ++ ++ } + +-err: + printk(KERN_ERR "WM9712 AC97 reset failed\n"); + return -EIO; + } 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 000000000..5179b47cc --- /dev/null +++ b/meta/packages/linux/linux-rp-2.6.23/wm9712-suspend-cold-res-r2.patch @@ -0,0 +1,16 @@ + sound/soc/codecs/wm9712.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +Index: git/sound/soc/codecs/wm9712.c +=================================================================== +--- git.orig/sound/soc/codecs/wm9712.c 2006-11-07 21:57:34.000000000 +0000 ++++ git/sound/soc/codecs/wm9712.c 2006-11-07 21:59:30.000000000 +0000 +@@ -651,7 +651,7 @@ static int wm9712_soc_resume(struct plat + int i, ret; + u16 *cache = codec->reg_cache; + +- ret = wm9712_reset(codec, 1); ++ ret = wm9712_reset(codec, 0); + if (ret < 0){ + printk(KERN_ERR "could not reset AC97 codec\n"); + 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 000000000..5ad0d8703 --- /dev/null +++ b/meta/packages/linux/linux-rp-2.6.23/wm97xx-lg13-r0-fix-r0.patch @@ -0,0 +1,128 @@ + drivers/input/power.c | 2 +- + drivers/input/touchscreen/Kconfig | 2 +- + drivers/input/touchscreen/wm97xx-core.c | 35 ++++++++++++++++--------------- + include/linux/wm97xx.h | 2 +- + 4 files changed, 21 insertions(+), 20 deletions(-) + +diff --git a/drivers/input/power.c b/drivers/input/power.c +index 4443e34..7aac875 100644 +--- a/drivers/input/power.c ++++ b/drivers/input/power.c +@@ -156,7 +156,7 @@ static void power_event(struct input_handle *handle, unsigned int type, + } + } + +-static struct input_handle *power_connect(struct input_handler *handler, ++static int power_connect(struct input_handler *handler, + struct input_dev *dev, + const struct input_device_id *id) + { +diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig +index 6862e8f..9b532e9 100644 +--- a/drivers/input/touchscreen/Kconfig ++++ b/drivers/input/touchscreen/Kconfig +@@ -247,7 +247,7 @@ config TOUCHSCREEN_TSC2101 + + config TOUCHSCREEN_WM97XX + tristate "Support for WM97xx AC97 touchscreen controllers" +- depends SND_AC97_BUS ++ depends AC97_BUS + + choice + prompt "WM97xx codec type" +diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c +index 9b2710e..d3ce3f3 100644 +--- a/drivers/input/touchscreen/wm97xx-core.c ++++ b/drivers/input/touchscreen/wm97xx-core.c +@@ -84,6 +84,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -241,14 +242,15 @@ WM97XX_STATUS_ATTR(gpio); + + static int wm97xx_sys_add(struct device *dev) + { ++ int err; + if (aux_sys) { +- device_create_file(dev, &dev_attr_aux1); +- device_create_file(dev, &dev_attr_aux2); +- device_create_file(dev, &dev_attr_aux3); +- device_create_file(dev, &dev_attr_aux4); ++ err = device_create_file(dev, &dev_attr_aux1); ++ err = device_create_file(dev, &dev_attr_aux2); ++ err = device_create_file(dev, &dev_attr_aux3); ++ err = device_create_file(dev, &dev_attr_aux4); + } + if (status_sys) +- device_create_file(dev, &dev_attr_gpio); ++ err = device_create_file(dev, &dev_attr_gpio); + return 0; + } + +@@ -366,12 +368,12 @@ void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, wm97xx_gpio_dir_t dir, + + /* + * Handle a pen down interrupt. +- */ +-static void wm97xx_pen_irq_worker(void *ptr) +-{ +- struct wm97xx *wm = (struct wm97xx *) ptr; +- +- /* do we need to enable the touch panel reader */ ++ */ ++static void wm97xx_pen_irq_worker(struct work_struct *work) ++{ ++ struct wm97xx *wm = container_of(work, struct wm97xx, pen_event_work); ++ ++ /* do we need to enable the touch panel reader */ + if (wm->id == WM9705_ID2) { + if (wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD) & WM97XX_PEN_DOWN) + wm->pen_is_down = 1; +@@ -411,9 +413,8 @@ static void wm97xx_pen_irq_worker(void *ptr) + * We have to disable the codec interrupt in the handler because it can + * take upto 1ms to clear the interrupt source. The interrupt is then enabled + * again in the slow handler when the source has been cleared. +- */ +-static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id, +- struct pt_regs *regs) ++ */ ++static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id) + { + struct wm97xx *wm = (struct wm97xx *) dev_id; + disable_irq(wm->pen_irq); +@@ -428,15 +429,15 @@ static int wm97xx_init_pen_irq(struct wm97xx *wm) + { + u16 reg; + +- INIT_WORK(&wm->pen_event_work, wm97xx_pen_irq_worker, wm); +- if ((wm->pen_irq_workq = ++ INIT_WORK(&wm->pen_event_work, wm97xx_pen_irq_worker); ++ if ((wm->pen_irq_workq = + create_singlethread_workqueue("kwm97pen")) == NULL) { + err("could not create pen irq work queue"); + wm->pen_irq = 0; + return -EINVAL; + } + +- if (request_irq (wm->pen_irq, wm97xx_pen_interrupt, SA_SHIRQ, "wm97xx-pen", wm)) { ++ if (request_irq (wm->pen_irq, wm97xx_pen_interrupt, IRQF_SHARED, "wm97xx-pen", wm)) { + err("could not register codec pen down interrupt, will poll for pen down"); + destroy_workqueue(wm->pen_irq_workq); + wm->pen_irq = 0; +diff --git a/include/linux/wm97xx.h b/include/linux/wm97xx.h +index b1c1740..a9bd57e 100644 +--- a/include/linux/wm97xx.h ++++ b/include/linux/wm97xx.h +@@ -243,7 +243,7 @@ struct wm97xx { + u16 dig_save[3]; /* saved during aux reading */ + struct wm97xx_codec_drv *codec; /* attached codec driver*/ + struct input_dev* input_dev; /* touchscreen input device */ +- ac97_t *ac97; /* ALSA codec access */ ++ struct snd_ac97 *ac97; /* ALSA codec access */ + struct device *dev; /* ALSA device */ + struct device *battery_dev; + 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 000000000..c918c5daf --- /dev/null +++ b/meta/packages/linux/linux-rp-2.6.23/wm97xx-lg13-r0.patch @@ -0,0 +1,2899 @@ +Index: linux-2.6.17/drivers/input/touchscreen/Kconfig +=================================================================== +--- linux-2.6.17.orig/drivers/input/touchscreen/Kconfig 2006-09-19 20:35:35.060495500 +0200 ++++ linux-2.6.17/drivers/input/touchscreen/Kconfig 2006-09-19 20:36:47.965051750 +0200 +@@ -121,4 +121,57 @@ config TOUCHSCREEN_TSC2101 + To compile this driver as a module, choose M here: the + module will be called ads7846_ts. + ++config TOUCHSCREEN_WM97XX ++ tristate "Support for WM97xx AC97 touchscreen controllers" ++ depends SND_AC97_BUS ++ ++choice ++ prompt "WM97xx codec type" ++ ++config TOUCHSCREEN_WM9705 ++ bool "WM9705 Touchscreen interface support" ++ depends on TOUCHSCREEN_WM97XX ++ help ++ Say Y here if you have the wm9705 touchscreen. ++ ++ If unsure, say N. ++ ++ To compile this driver as a module, choose M here: the ++ module will be called wm9705. ++ ++config TOUCHSCREEN_WM9712 ++ bool "WM9712 Touchscreen interface support" ++ depends on TOUCHSCREEN_WM97XX ++ help ++ Say Y here if you have the wm9712 touchscreen. ++ ++ If unsure, say N. ++ ++ To compile this driver as a module, choose M here: the ++ module will be called wm9712. ++ ++config TOUCHSCREEN_WM9713 ++ bool "WM9713 Touchscreen interface support" ++ depends on TOUCHSCREEN_WM97XX ++ help ++ Say Y here if you have the wm9713 touchscreen. ++ ++ If unsure, say N. ++ ++ To compile this driver as a module, choose M here: the ++ module will be called wm9713. ++ ++endchoice ++ ++config TOUCHSCREEN_WM97XX_PXA ++ tristate "WM97xx PXA accelerated touch" ++ depends on TOUCHSCREEN_WM97XX && ARCH_PXA ++ help ++ Say Y here for continuous mode touch on the PXA ++ ++ If unsure, say N ++ ++ To compile this driver as a module, choose M here: the ++ module will be called pxa-wm97xx ++ + endif +Index: linux-2.6.17/drivers/input/touchscreen/Makefile +=================================================================== +--- linux-2.6.17.orig/drivers/input/touchscreen/Makefile 2006-09-19 20:35:35.072496250 +0200 ++++ linux-2.6.17/drivers/input/touchscreen/Makefile 2006-09-19 20:37:40.540337500 +0200 +@@ -4,6 +4,8 @@ + + # Each configuration option enables a list of files. + ++wm97xx-ts-objs := wm97xx-core.o ++ + obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o + obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o + obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o +@@ -13,3 +15,16 @@ obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtou + obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o + obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o + obj-$(CONFIG_TOUCHSCREEN_TSC2101) += tsc2101_ts.o ++obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o ++obj-$(CONFIG_TOUCHSCREEN_WM97XX_PXA) += pxa-wm97xx.o ++ ++ifeq ($(CONFIG_TOUCHSCREEN_WM9713),y) ++wm97xx-ts-objs += wm9713.o ++endif ++ ++ifeq ($(CONFIG_TOUCHSCREEN_WM9712),y) ++wm97xx-ts-objs += wm9712.o ++endif ++ifeq ($(CONFIG_TOUCHSCREEN_WM9705),y) ++wm97xx-ts-objs += wm9705.o ++endif +Index: linux-2.6.17/drivers/input/touchscreen/pxa-wm97xx.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-2.6.17/drivers/input/touchscreen/pxa-wm97xx.c 2006-09-19 20:36:47.965051750 +0200 +@@ -0,0 +1,289 @@ ++/* ++ * pxa-wm97xx.c -- pxa-wm97xx Continuous Touch screen driver for ++ * Wolfson WM97xx AC97 Codecs. ++ * ++ * Copyright 2004 Wolfson Microelectronics PLC. ++ * Author: Liam Girdwood ++ * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com ++ * Parts Copyright : Ian Molton ++ * Andrew Zabolotny ++ * ++ * This program is free software; you can redistribute it and/or modify it ++ * under the terms of the GNU General Public License as published by the ++ * Free Software Foundation; either version 2 of the License, or (at your ++ * option) any later version. ++ * ++ * Notes: ++ * This is a wm97xx extended touch driver to capture touch ++ * data in a continuous manner on the Intel XScale archictecture ++ * ++ * Features: ++ * - codecs supported:- WM9705, WM9712, WM9713 ++ * - processors supported:- Intel XScale PXA25x, PXA26x, PXA27x ++ * ++ * Revision history ++ * 18th Aug 2004 Initial version. ++ * 26th Jul 2005 Improved continous read back and added FIFO flushing. ++ * 06th Sep 2005 Mike Arthur ++ * Moved to using the wm97xx bus ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define VERSION "0.13" ++ ++struct continuous { ++ u16 id; /* codec id */ ++ u8 code; /* continuous code */ ++ u8 reads; /* number of coord reads per read cycle */ ++ u32 speed; /* number of coords per second */ ++}; ++ ++#define WM_READS(sp) ((sp / HZ) + 1) ++ ++static const struct continuous cinfo[] = { ++ {WM9705_ID2, 0, WM_READS(94), 94}, ++ {WM9705_ID2, 1, WM_READS(188), 188}, ++ {WM9705_ID2, 2, WM_READS(375), 375}, ++ {WM9705_ID2, 3, WM_READS(750), 750}, ++ {WM9712_ID2, 0, WM_READS(94), 94}, ++ {WM9712_ID2, 1, WM_READS(188), 188}, ++ {WM9712_ID2, 2, WM_READS(375), 375}, ++ {WM9712_ID2, 3, WM_READS(750), 750}, ++ {WM9713_ID2, 0, WM_READS(94), 94}, ++ {WM9713_ID2, 1, WM_READS(120), 120}, ++ {WM9713_ID2, 2, WM_READS(154), 154}, ++ {WM9713_ID2, 3, WM_READS(188), 188}, ++}; ++ ++/* continuous speed index */ ++static int sp_idx = 0; ++static u16 last = 0, tries = 0; ++ ++/* ++ * Pen sampling frequency (Hz) in continuous mode. ++ */ ++static int cont_rate = 200; ++module_param(cont_rate, int, 0); ++MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)"); ++ ++/* ++ * Pen down detection. ++ * ++ * This driver can either poll or use an interrupt to indicate a pen down ++ * event. If the irq request fails then it will fall back to polling mode. ++ */ ++static int pen_int = 1; ++module_param(pen_int, int, 0); ++MODULE_PARM_DESC(pen_int, "Pen down detection (1 = interrupt, 0 = polling)"); ++ ++/* ++ * Pressure readback. ++ * ++ * Set to 1 to read back pen down pressure ++ */ ++static int pressure = 0; ++module_param(pressure, int, 0); ++MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no pressure)"); ++ ++/* ++ * AC97 touch data slot. ++ * ++ * Touch screen readback data ac97 slot ++ */ ++static int ac97_touch_slot = 5; ++module_param(ac97_touch_slot, int, 0); ++MODULE_PARM_DESC(ac97_touch_slot, "Touch screen data slot AC97 number"); ++ ++ ++/* flush AC97 slot 5 FIFO on pxa machines */ ++#ifdef CONFIG_PXA27x ++void wm97xx_acc_pen_up (struct wm97xx* wm) ++{ ++ set_current_state(TASK_INTERRUPTIBLE); ++ schedule_timeout(1); ++ ++ while (MISR & (1 << 2)) ++ MODR; ++} ++#else ++void wm97xx_acc_pen_up (struct wm97xx* wm) ++{ ++ int count = 16; ++ set_current_state(TASK_INTERRUPTIBLE); ++ schedule_timeout(1); ++ ++ while (count < 16) { ++ MODR; ++ count--; ++ } ++} ++#endif ++ ++int wm97xx_acc_pen_down (struct wm97xx* wm) ++{ ++ u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES; ++ int reads = 0; ++ ++ /* data is never immediately available after pen down irq */ ++ set_current_state(TASK_INTERRUPTIBLE); ++ schedule_timeout(1); ++ ++ if (tries > 5){ ++ tries = 0; ++ return RC_PENUP; ++ } ++ ++ x = MODR; ++ if (x == last) { ++ tries++; ++ return RC_AGAIN; ++ } ++ last = x; ++ do { ++ if (reads) ++ x= MODR; ++ y= MODR; ++ if (pressure) ++ p = MODR; ++ ++ /* are samples valid */ ++ if ((x & 0x7000) != WM97XX_ADCSEL_X || ++ (y & 0x7000) != WM97XX_ADCSEL_Y || ++ (p & 0x7000) != WM97XX_ADCSEL_PRES) ++ goto up; ++ ++ /* coordinate is good */ ++ tries = 0; ++ //printk("x %x y %x p %x\n", x,y,p); ++ input_report_abs (wm->input_dev, ABS_X, x & 0xfff); ++ input_report_abs (wm->input_dev, ABS_Y, y & 0xfff); ++ input_report_abs (wm->input_dev, ABS_PRESSURE, p & 0xfff); ++ input_sync (wm->input_dev); ++ reads++; ++ } while (reads < cinfo[sp_idx].reads); ++up: ++ return RC_PENDOWN | RC_AGAIN; ++} ++ ++int wm97xx_acc_startup(struct wm97xx* wm) ++{ ++ int idx = 0; ++ ++ /* check we have a codec */ ++ if (wm->ac97 == NULL) ++ return -ENODEV; ++ ++ /* Go you big red fire engine */ ++ for (idx = 0; idx < ARRAY_SIZE(cinfo); idx++) { ++ if (wm->id != cinfo[idx].id) ++ continue; ++ sp_idx = idx; ++ if (cont_rate <= cinfo[idx].speed) ++ break; ++ } ++ wm->acc_rate = cinfo[sp_idx].code; ++ wm->acc_slot = ac97_touch_slot; ++ printk(KERN_INFO "pxa2xx accelerated touchscreen driver, %d samples (sec)\n", ++ cinfo[sp_idx].speed); ++ ++ /* codec specific irq config */ ++ if (pen_int) { ++ switch (wm->id) { ++ case WM9705_ID2: ++ wm->pen_irq = IRQ_GPIO(4); ++ set_irq_type(IRQ_GPIO(4), IRQT_BOTHEDGE); ++ break; ++ case WM9712_ID2: ++ case WM9713_ID2: ++ /* enable pen down interrupt */ ++ /* use PEN_DOWN GPIO 13 to assert IRQ on GPIO line 2 */ ++ wm->pen_irq = MAINSTONE_AC97_IRQ; ++ wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN, ++ WM97XX_GPIO_POL_HIGH, WM97XX_GPIO_STICKY, WM97XX_GPIO_WAKE); ++ wm97xx_config_gpio(wm, WM97XX_GPIO_2, WM97XX_GPIO_OUT, ++ WM97XX_GPIO_POL_HIGH, WM97XX_GPIO_NOTSTICKY, WM97XX_GPIO_NOWAKE); ++ break; ++ default: ++ printk(KERN_WARNING "pen down irq not supported on this device\n"); ++ pen_int = 0; ++ break; ++ } ++ } ++ ++ return 0; ++} ++ ++void wm97xx_acc_shutdown(struct wm97xx* wm) ++{ ++ /* codec specific deconfig */ ++ if (pen_int) { ++ switch (wm->id & 0xffff) { ++ case WM9705_ID2: ++ wm->pen_irq = 0; ++ break; ++ case WM9712_ID2: ++ case WM9713_ID2: ++ /* disable interrupt */ ++ wm->pen_irq = 0; ++ break; ++ } ++ } ++} ++ ++static struct wm97xx_mach_ops pxa_mach_ops = { ++ .acc_enabled = 1, ++ .acc_pen_up = wm97xx_acc_pen_up, ++ .acc_pen_down = wm97xx_acc_pen_down, ++ .acc_startup = wm97xx_acc_startup, ++ .acc_shutdown = wm97xx_acc_shutdown, ++}; ++ ++int pxa_wm97xx_probe(struct device *dev) ++{ ++ struct wm97xx *wm = dev->driver_data; ++ return wm97xx_register_mach_ops (wm, &pxa_mach_ops); ++} ++ ++int pxa_wm97xx_remove(struct device *dev) ++{ ++ struct wm97xx *wm = dev->driver_data; ++ wm97xx_unregister_mach_ops (wm); ++ return 0; ++} ++ ++static struct device_driver pxa_wm97xx_driver = { ++ .name = "wm97xx-touchscreen", ++ .bus = &wm97xx_bus_type, ++ .owner = THIS_MODULE, ++ .probe = pxa_wm97xx_probe, ++ .remove = pxa_wm97xx_remove ++}; ++ ++static int __init pxa_wm97xx_init(void) ++{ ++ return driver_register(&pxa_wm97xx_driver); ++} ++ ++static void __exit pxa_wm97xx_exit(void) ++{ ++ driver_unregister(&pxa_wm97xx_driver); ++} ++ ++module_init(pxa_wm97xx_init); ++module_exit(pxa_wm97xx_exit); ++ ++/* Module information */ ++MODULE_AUTHOR("Liam Girdwood "); ++MODULE_DESCRIPTION("wm97xx continuous touch driver for pxa2xx"); ++MODULE_LICENSE("GPL"); +Index: linux-2.6.17/drivers/input/touchscreen/wm9705.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-2.6.17/drivers/input/touchscreen/wm9705.c 2006-09-19 20:36:47.969052000 +0200 +@@ -0,0 +1,360 @@ ++/* ++ * wm9705.c -- Codec driver for Wolfson WM9705 AC97 Codec. ++ * ++ * Copyright 2003, 2004, 2005, 2006 Wolfson Microelectronics PLC. ++ * Author: Liam Girdwood ++ * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com ++ * Parts Copyright : Ian Molton ++ * Andrew Zabolotny ++ * Russell King ++ * ++ * This program is free software; you can redistribute it and/or modify it ++ * under the terms of the GNU General Public License as published by the ++ * Free Software Foundation; either version 2 of the License, or (at your ++ * option) any later version. ++ * ++ * Revision history ++ * 6th Sep 2006 Mike Arthur ++ * Added pre and post sample calls. ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define TS_NAME "wm97xx" ++#define WM9705_VERSION "0.62" ++#define DEFAULT_PRESSURE 0xb0c0 ++ ++/* ++ * Debug ++ */ ++#if 0 ++#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg) ++#else ++#define dbg(format, arg...) ++#endif ++#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg) ++#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg) ++#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg) ++ ++/* ++ * Module parameters ++ */ ++ ++/* ++ * Set current used for pressure measurement. ++ * ++ * Set pil = 2 to use 400uA ++ * pil = 1 to use 200uA and ++ * pil = 0 to disable pressure measurement. ++ * ++ * This is used to increase the range of values returned by the adc ++ * when measureing touchpanel pressure. ++ */ ++static int pil = 0; ++module_param(pil, int, 0); ++MODULE_PARM_DESC(pil, "Set current used for pressure measurement."); ++ ++/* ++ * Set threshold for pressure measurement. ++ * ++ * Pen down pressure below threshold is ignored. ++ */ ++static int pressure = DEFAULT_PRESSURE & 0xfff; ++module_param(pressure, int, 0); ++MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement."); ++ ++/* ++ * Set adc sample delay. ++ * ++ * For accurate touchpanel measurements, some settling time may be ++ * required between the switch matrix applying a voltage across the ++ * touchpanel plate and the ADC sampling the signal. ++ * ++ * This delay can be set by setting delay = n, where n is the array ++ * position of the delay in the array delay_table below. ++ * Long delays > 1ms are supported for completeness, but are not ++ * recommended. ++ */ ++static int delay = 4; ++module_param(delay, int, 0); ++MODULE_PARM_DESC(delay, "Set adc sample delay."); ++ ++/* ++ * Pen detect comparator threshold. ++ * ++ * 0 to Vmid in 15 steps, 0 = use zero power comparator with Vmid threshold ++ * i.e. 1 = Vmid/15 threshold ++ * 15 = Vmid/1 threshold ++ * ++ * Adjust this value if you are having problems with pen detect not ++ * detecting any down events. ++ */ ++static int pdd = 8; ++module_param(pdd, int, 0); ++MODULE_PARM_DESC(pdd, "Set pen detect comparator threshold"); ++ ++/* ++ * Set adc mask function. ++ * ++ * Sources of glitch noise, such as signals driving an LCD display, may feed ++ * through to the touch screen plates and affect measurement accuracy. In ++ * order to minimise this, a signal may be applied to the MASK pin to delay or ++ * synchronise the sampling. ++ * ++ * 0 = No delay or sync ++ * 1 = High on pin stops conversions ++ * 2 = Edge triggered, edge on pin delays conversion by delay param (above) ++ * 3 = Edge triggered, edge on pin starts conversion after delay param ++ */ ++static int mask = 0; ++module_param(mask, int, 0); ++MODULE_PARM_DESC(mask, "Set adc mask function."); ++ ++/* ++ * ADC sample delay times in uS ++ */ ++static const int delay_table[] = { ++ 21, // 1 AC97 Link frames ++ 42, // 2 ++ 84, // 4 ++ 167, // 8 ++ 333, // 16 ++ 667, // 32 ++ 1000, // 48 ++ 1333, // 64 ++ 2000, // 96 ++ 2667, // 128 ++ 3333, // 160 ++ 4000, // 192 ++ 4667, // 224 ++ 5333, // 256 ++ 6000, // 288 ++ 0 // No delay, switch matrix always on ++}; ++ ++/* ++ * Delay after issuing a POLL command. ++ * ++ * The delay is 3 AC97 link frames + the touchpanel settling delay ++ */ ++static inline void poll_delay(int d) ++{ ++ udelay (3 * AC97_LINK_FRAME + delay_table [d]); ++} ++ ++/* ++ * set up the physical settings of the WM9705 ++ */ ++static void init_wm9705_phy(struct wm97xx* wm) ++{ ++ u16 dig1 = 0, dig2 = WM97XX_RPR; ++ ++ /* ++ * mute VIDEO and AUX as they share X and Y touchscreen ++ * inputs on the WM9705 ++ */ ++ wm97xx_reg_write(wm, AC97_AUX, 0x8000); ++ wm97xx_reg_write(wm, AC97_VIDEO, 0x8000); ++ ++ /* touchpanel pressure current*/ ++ if (pil == 2) { ++ dig2 |= WM9705_PIL; ++ dbg("setting pressure measurement current to 400uA."); ++ } else if (pil) ++ dbg("setting pressure measurement current to 200uA."); ++ if(!pil) ++ pressure = 0; ++ ++ /* polling mode sample settling delay */ ++ if (delay!=4) { ++ if (delay < 0 || delay > 15) { ++ dbg("supplied delay out of range."); ++ delay = 4; ++ } ++ } ++ dig1 &= 0xff0f; ++ dig1 |= WM97XX_DELAY(delay); ++ dbg("setting adc sample delay to %d u Secs.", delay_table[delay]); ++ ++ /* WM9705 pdd */ ++ dig2 |= (pdd & 0x000f); ++ dbg("setting pdd to Vmid/%d", 1 - (pdd & 0x000f)); ++ ++ /* mask */ ++ dig2 |= ((mask & 0x3) << 4); ++ ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1); ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2); ++} ++ ++static int wm9705_digitiser_ioctl(struct wm97xx* wm, int cmd) ++{ ++ switch(cmd) { ++ case WM97XX_DIG_START: ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig[2] | WM97XX_PRP_DET_DIG); ++ wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */ ++ break; ++ case WM97XX_DIG_STOP: ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig[2] & ~WM97XX_PRP_DET_DIG); ++ break; ++ case WM97XX_AUX_PREPARE: ++ memcpy(wm->dig_save, wm->dig, sizeof(wm->dig)); ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, 0); ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, WM97XX_PRP_DET_DIG); ++ break; ++ case WM97XX_DIG_RESTORE: ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, wm->dig_save[1]); ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig_save[2]); ++ break; ++ case WM97XX_PHY_INIT: ++ init_wm9705_phy(wm); ++ break; ++ default: ++ return -EINVAL; ++ } ++ return 0; ++} ++ ++static inline int is_pden (struct wm97xx* wm) ++{ ++ return wm->dig[2] & WM9705_PDEN; ++} ++ ++/* ++ * Read a sample from the WM9705 adc in polling mode. ++ */ ++static int wm9705_poll_sample (struct wm97xx* wm, int adcsel, int *sample) ++{ ++ int timeout = 5 * delay; ++ ++ if (!wm->pen_probably_down) { ++ u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ if (!(data & WM97XX_PEN_DOWN)) ++ return RC_PENUP; ++ wm->pen_probably_down = 1; ++ } ++ ++ /* set up digitiser */ ++ if (adcsel & 0x8000) ++ adcsel = ((adcsel & 0x7fff) + 3) << 12; ++ ++ if (wm->mach_ops && wm->mach_ops->pre_sample) ++ wm->mach_ops->pre_sample(adcsel); ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, adcsel | WM97XX_POLL | WM97XX_DELAY(delay)); ++ ++ /* wait 3 AC97 time slots + delay for conversion */ ++ poll_delay (delay); ++ ++ /* wait for POLL to go low */ ++ while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL) && timeout) { ++ udelay(AC97_LINK_FRAME); ++ timeout--; ++ } ++ ++ if (timeout <= 0) { ++ /* If PDEN is set, we can get a timeout when pen goes up */ ++ if (is_pden(wm)) ++ wm->pen_probably_down = 0; ++ else ++ dbg ("adc sample timeout"); ++ return RC_PENUP; ++ } ++ ++ *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ if (wm->mach_ops && wm->mach_ops->post_sample) ++ wm->mach_ops->post_sample(adcsel); ++ ++ /* check we have correct sample */ ++ if ((*sample & WM97XX_ADCSEL_MASK) != adcsel) { ++ dbg ("adc wrong sample, read %x got %x", adcsel, ++ *sample & WM97XX_ADCSEL_MASK); ++ return RC_PENUP; ++ } ++ ++ if (!(*sample & WM97XX_PEN_DOWN)) { ++ wm->pen_probably_down = 0; ++ return RC_PENUP; ++ } ++ ++ return RC_VALID; ++} ++ ++/* ++ * Sample the WM9705 touchscreen in polling mode ++ */ ++static int wm9705_poll_touch(struct wm97xx* wm, struct wm97xx_data *data) ++{ ++ int rc; ++ ++ if ((rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_X, &data->x)) != RC_VALID) ++ return rc; ++ if ((rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_Y, &data->y)) != RC_VALID) ++ return rc; ++ if (pil) { ++ if ((rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_PRES, &data->p)) != RC_VALID) ++ return rc; ++ } else ++ data->p = DEFAULT_PRESSURE; ++ ++ return RC_VALID; ++} ++ ++/* ++ * Enable WM9705 continuous mode, i.e. touch data is streamed across an AC97 slot ++ */ ++static int wm9705_acc_enable (struct wm97xx* wm, int enable) ++{ ++ u16 dig1, dig2; ++ int ret = 0; ++ ++ dig1 = wm->dig[1]; ++ dig2 = wm->dig[2]; ++ ++ if (enable) { ++ /* continous mode */ ++ if (wm->mach_ops->acc_startup && (ret = wm->mach_ops->acc_startup(wm)) < 0) ++ return ret; ++ dig1 &= ~(WM97XX_CM_RATE_MASK | WM97XX_ADCSEL_MASK | ++ WM97XX_DELAY_MASK | WM97XX_SLT_MASK); ++ dig1 |= WM97XX_CTC | WM97XX_COO | WM97XX_SLEN | ++ WM97XX_DELAY (delay) | ++ WM97XX_SLT (wm->acc_slot) | ++ WM97XX_RATE (wm->acc_rate); ++ if (pil) ++ dig1 |= WM97XX_ADCSEL_PRES; ++ dig2 |= WM9705_PDEN; ++ } else { ++ dig1 &= ~(WM97XX_CTC | WM97XX_COO | WM97XX_SLEN); ++ dig2 &= ~WM9705_PDEN; ++ if (wm->mach_ops->acc_shutdown) ++ wm->mach_ops->acc_shutdown(wm); ++ } ++ ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1); ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2); ++ return ret; ++} ++ ++struct wm97xx_codec_drv wm97xx_codec = { ++ .id = WM9705_ID2, ++ .name = "wm9705", ++ .poll_sample = wm9705_poll_sample, ++ .poll_touch = wm9705_poll_touch, ++ .acc_enable = wm9705_acc_enable, ++ .digitiser_ioctl = wm9705_digitiser_ioctl, ++}; ++ ++EXPORT_SYMBOL_GPL(wm97xx_codec); ++ ++/* Module information */ ++MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com"); ++MODULE_DESCRIPTION("WM9705 Touch Screen Driver"); ++MODULE_LICENSE("GPL"); +Index: linux-2.6.17/drivers/input/touchscreen/wm9712.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-2.6.17/drivers/input/touchscreen/wm9712.c 2006-09-19 20:36:47.969052000 +0200 +@@ -0,0 +1,464 @@ ++/* ++ * wm9712.c -- Codec driver for Wolfson WM9712 AC97 Codecs. ++ * ++ * Copyright 2003, 2004, 2005, 2006 Wolfson Microelectronics PLC. ++ * Author: Liam Girdwood ++ * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com ++ * Parts Copyright : Ian Molton ++ * Andrew Zabolotny ++ * Russell King ++ * ++ * This program is free software; you can redistribute it and/or modify it ++ * under the terms of the GNU General Public License as published by the ++ * Free Software Foundation; either version 2 of the License, or (at your ++ * option) any later version. ++ * ++ * Revision history ++ * 4th Jul 2005 Initial version. ++ * 6th Sep 2006 Mike Arthur ++ * Added pre and post sample calls. ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define TS_NAME "wm97xx" ++#define WM9712_VERSION "0.61" ++#define DEFAULT_PRESSURE 0xb0c0 ++ ++/* ++ * Debug ++ */ ++#if 0 ++#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg) ++#else ++#define dbg(format, arg...) ++#endif ++#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg) ++#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg) ++#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg) ++ ++/* ++ * Module parameters ++ */ ++ ++/* ++ * Set internal pull up for pen detect. ++ * ++ * Pull up is in the range 1.02k (least sensitive) to 64k (most sensitive) ++ * i.e. pull up resistance = 64k Ohms / rpu. ++ * ++ * Adjust this value if you are having problems with pen detect not ++ * detecting any down event. ++ */ ++static int rpu = 3; ++module_param(rpu, int, 0); ++MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect."); ++ ++/* ++ * Set current used for pressure measurement. ++ * ++ * Set pil = 2 to use 400uA ++ * pil = 1 to use 200uA and ++ * pil = 0 to disable pressure measurement. ++ * ++ * This is used to increase the range of values returned by the adc ++ * when measureing touchpanel pressure. ++ */ ++static int pil = 0; ++module_param(pil, int, 0); ++MODULE_PARM_DESC(pil, "Set current used for pressure measurement."); ++ ++/* ++ * Set threshold for pressure measurement. ++ * ++ * Pen down pressure below threshold is ignored. ++ */ ++static int pressure = DEFAULT_PRESSURE & 0xfff; ++module_param(pressure, int, 0); ++MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement."); ++ ++/* ++ * Set adc sample delay. ++ * ++ * For accurate touchpanel measurements, some settling time may be ++ * required between the switch matrix applying a voltage across the ++ * touchpanel plate and the ADC sampling the signal. ++ * ++ * This delay can be set by setting delay = n, where n is the array ++ * position of the delay in the array delay_table below. ++ * Long delays > 1ms are supported for completeness, but are not ++ * recommended. ++ */ ++static int delay = 3; ++module_param(delay, int, 0); ++MODULE_PARM_DESC(delay, "Set adc sample delay."); ++ ++/* ++ * Set five_wire = 1 to use a 5 wire touchscreen. ++ * ++ * NOTE: Five wire mode does not allow for readback of pressure. ++ */ ++static int five_wire; ++module_param(five_wire, int, 0); ++MODULE_PARM_DESC(five_wire, "Set to '1' to use 5-wire touchscreen."); ++ ++/* ++ * Set adc mask function. ++ * ++ * Sources of glitch noise, such as signals driving an LCD display, may feed ++ * through to the touch screen plates and affect measurement accuracy. In ++ * order to minimise this, a signal may be applied to the MASK pin to delay or ++ * synchronise the sampling. ++ * ++ * 0 = No delay or sync ++ * 1 = High on pin stops conversions ++ * 2 = Edge triggered, edge on pin delays conversion by delay param (above) ++ * 3 = Edge triggered, edge on pin starts conversion after delay param ++ */ ++static int mask = 0; ++module_param(mask, int, 0); ++MODULE_PARM_DESC(mask, "Set adc mask function."); ++ ++/* ++ * Coordinate Polling Enable. ++ * ++ * Set to 1 to enable coordinate polling. e.g. x,y[,p] is sampled together ++ * for every poll. ++ */ ++static int coord = 0; ++module_param(coord, int, 0); ++MODULE_PARM_DESC(coord, "Polling coordinate mode"); ++ ++/* ++ * ADC sample delay times in uS ++ */ ++static const int delay_table[] = { ++ 21, // 1 AC97 Link frames ++ 42, // 2 ++ 84, // 4 ++ 167, // 8 ++ 333, // 16 ++ 667, // 32 ++ 1000, // 48 ++ 1333, // 64 ++ 2000, // 96 ++ 2667, // 128 ++ 3333, // 160 ++ 4000, // 192 ++ 4667, // 224 ++ 5333, // 256 ++ 6000, // 288 ++ 0 // No delay, switch matrix always on ++}; ++ ++/* ++ * Delay after issuing a POLL command. ++ * ++ * The delay is 3 AC97 link frames + the touchpanel settling delay ++ */ ++static inline void poll_delay(int d) ++{ ++ udelay (3 * AC97_LINK_FRAME + delay_table [d]); ++} ++ ++/* ++ * set up the physical settings of the WM9712 ++ */ ++static void init_wm9712_phy(struct wm97xx* wm) ++{ ++ u16 dig1 = 0; ++ u16 dig2 = WM97XX_RPR | WM9712_RPU(1); ++ ++ /* WM9712 rpu */ ++ if (rpu) { ++ dig2 &= 0xffc0; ++ dig2 |= WM9712_RPU(rpu); ++ dbg("setting pen detect pull-up to %d Ohms",64000 / rpu); ++ } ++ ++ /* touchpanel pressure current*/ ++ if (pil == 2) { ++ dig2 |= WM9712_PIL; ++ dbg("setting pressure measurement current to 400uA."); ++ } else if (pil) ++ dbg("setting pressure measurement current to 200uA."); ++ if(!pil) ++ pressure = 0; ++ ++ /* WM9712 five wire */ ++ if (five_wire) { ++ dig2 |= WM9712_45W; ++ dbg("setting 5-wire touchscreen mode."); ++ } ++ ++ /* polling mode sample settling delay */ ++ if (delay < 0 || delay > 15) { ++ dbg("supplied delay out of range."); ++ delay = 4; ++ } ++ dig1 &= 0xff0f; ++ dig1 |= WM97XX_DELAY(delay); ++ dbg("setting adc sample delay to %d u Secs.", delay_table[delay]); ++ ++ /* mask */ ++ dig2 |= ((mask & 0x3) << 6); ++ if (mask) { ++ u16 reg; ++ /* Set GPIO4 as Mask Pin*/ ++ reg = wm97xx_reg_read(wm, AC97_MISC_AFE); ++ wm97xx_reg_write(wm, AC97_MISC_AFE, reg | WM97XX_GPIO_4); ++ reg = wm97xx_reg_read(wm, AC97_GPIO_CFG); ++ wm97xx_reg_write(wm, AC97_GPIO_CFG, reg | WM97XX_GPIO_4); ++ } ++ ++ /* wait - coord mode */ ++ if(coord) ++ dig2 |= WM9712_WAIT; ++ ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1); ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2); ++} ++ ++static int wm9712_digitiser_ioctl(struct wm97xx* wm, int cmd) ++{ ++ u16 dig2 = wm->dig[2]; ++ ++ switch(cmd) { ++ case WM97XX_DIG_START: ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2 | WM97XX_PRP_DET_DIG); ++ wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */ ++ break; ++ case WM97XX_DIG_STOP: ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2 & ~WM97XX_PRP_DET_DIG); ++ break; ++ case WM97XX_AUX_PREPARE: ++ memcpy(wm->dig_save, wm->dig, sizeof(wm->dig)); ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, 0); ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, WM97XX_PRP_DET_DIG); ++ break; ++ case WM97XX_DIG_RESTORE: ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, wm->dig_save[1]); ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig_save[2]); ++ break; ++ case WM97XX_PHY_INIT: ++ init_wm9712_phy(wm); ++ break; ++ default: ++ return -EINVAL; ++ } ++ return 0; ++} ++ ++static inline int is_pden (struct wm97xx* wm) ++{ ++ return wm->dig[2] & WM9712_PDEN; ++} ++ ++/* ++ * Read a sample from the WM9712 adc in polling mode. ++ */ ++static int wm9712_poll_sample (struct wm97xx* wm, int adcsel, int *sample) ++{ ++ int timeout = 5 * delay; ++ ++ if (!wm->pen_probably_down) { ++ u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ if (!(data & WM97XX_PEN_DOWN)) ++ return RC_PENUP; ++ wm->pen_probably_down = 1; ++ } ++ ++ /* set up digitiser */ ++ if (adcsel & 0x8000) ++ adcsel = ((adcsel & 0x7fff) + 3) << 12; ++ ++ if (wm->mach_ops && wm->mach_ops->pre_sample) ++ wm->mach_ops->pre_sample(adcsel); ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, adcsel | WM97XX_POLL | WM97XX_DELAY(delay)); ++ ++ /* wait 3 AC97 time slots + delay for conversion */ ++ poll_delay (delay); ++ ++ /* wait for POLL to go low */ ++ while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL) && timeout) { ++ udelay(AC97_LINK_FRAME); ++ timeout--; ++ } ++ ++ if (timeout <= 0) { ++ /* If PDEN is set, we can get a timeout when pen goes up */ ++ if (is_pden(wm)) ++ wm->pen_probably_down = 0; ++ else ++ dbg ("adc sample timeout"); ++ return RC_PENUP; ++ } ++ ++ *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ if (wm->mach_ops && wm->mach_ops->post_sample) ++ wm->mach_ops->post_sample(adcsel); ++ ++ /* check we have correct sample */ ++ if ((*sample & WM97XX_ADCSEL_MASK) != adcsel) { ++ dbg ("adc wrong sample, read %x got %x", adcsel, ++ *sample & WM97XX_ADCSEL_MASK); ++ return RC_PENUP; ++ } ++ ++ if (!(*sample & WM97XX_PEN_DOWN)) { ++ wm->pen_probably_down = 0; ++ return RC_PENUP; ++ } ++ ++ return RC_VALID; ++} ++ ++/* ++ * Read a coord from the WM9712 adc in polling mode. ++ */ ++static int wm9712_poll_coord (struct wm97xx* wm, struct wm97xx_data *data) ++{ ++ int timeout = 5 * delay; ++ ++ if (!wm->pen_probably_down) { ++ u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ if (!(data & WM97XX_PEN_DOWN)) ++ return RC_PENUP; ++ wm->pen_probably_down = 1; ++ } ++ ++ /* set up digitiser */ ++ if (wm->mach_ops && wm->mach_ops->pre_sample) ++ wm->mach_ops->pre_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y); ++ ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, ++ WM97XX_COO | WM97XX_POLL | WM97XX_DELAY(delay)); ++ ++ /* wait 3 AC97 time slots + delay for conversion and read x */ ++ poll_delay(delay); ++ data->x = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ /* wait for POLL to go low */ ++ while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL) && timeout) { ++ udelay(AC97_LINK_FRAME); ++ timeout--; ++ } ++ ++ if (timeout <= 0) { ++ /* If PDEN is set, we can get a timeout when pen goes up */ ++ if (is_pden(wm)) ++ wm->pen_probably_down = 0; ++ else ++ dbg ("adc sample timeout"); ++ return RC_PENUP; ++ } ++ ++ /* read back y data */ ++ data->y = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ if (pil) ++ data->p = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ else ++ data->p = DEFAULT_PRESSURE; ++ ++ if (wm->mach_ops && wm->mach_ops->post_sample) ++ wm->mach_ops->post_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y); ++ ++ /* check we have correct sample */ ++ if (!(data->x & WM97XX_ADCSEL_X) || !(data->y & WM97XX_ADCSEL_Y)) ++ goto err; ++ if(pil && !(data->p & WM97XX_ADCSEL_PRES)) ++ goto err; ++ ++ if (!(data->x & WM97XX_PEN_DOWN)) { ++ wm->pen_probably_down = 0; ++ return RC_PENUP; ++ } ++ return RC_VALID; ++err: ++ return RC_PENUP; ++} ++ ++/* ++ * Sample the WM9712 touchscreen in polling mode ++ */ ++static int wm9712_poll_touch(struct wm97xx* wm, struct wm97xx_data *data) ++{ ++ int rc; ++ ++ if(coord) { ++ if((rc = wm9712_poll_coord(wm, data)) != RC_VALID) ++ return rc; ++ } else { ++ if ((rc = wm9712_poll_sample(wm, WM97XX_ADCSEL_X, &data->x)) != RC_VALID) ++ return rc; ++ ++ if ((rc = wm9712_poll_sample(wm, WM97XX_ADCSEL_Y, &data->y)) != RC_VALID) ++ return rc; ++ ++ if (pil && !five_wire) { ++ if ((rc = wm9712_poll_sample(wm, WM97XX_ADCSEL_PRES, &data->p)) != RC_VALID) ++ return rc; ++ } else ++ data->p = DEFAULT_PRESSURE; ++ } ++ return RC_VALID; ++} ++ ++/* ++ * Enable WM9712 continuous mode, i.e. touch data is streamed across an AC97 slot ++ */ ++static int wm9712_acc_enable (struct wm97xx* wm, int enable) ++{ ++ u16 dig1, dig2; ++ int ret = 0; ++ ++ dig1 = wm->dig[1]; ++ dig2 = wm->dig[2]; ++ ++ if (enable) { ++ /* continous mode */ ++ if (wm->mach_ops->acc_startup && (ret = wm->mach_ops->acc_startup(wm)) < 0) ++ return ret; ++ dig1 &= ~(WM97XX_CM_RATE_MASK | WM97XX_ADCSEL_MASK | ++ WM97XX_DELAY_MASK | WM97XX_SLT_MASK); ++ dig1 |= WM97XX_CTC | WM97XX_COO | WM97XX_SLEN | ++ WM97XX_DELAY (delay) | ++ WM97XX_SLT (wm->acc_slot) | ++ WM97XX_RATE (wm->acc_rate); ++ if (pil) ++ dig1 |= WM97XX_ADCSEL_PRES; ++ dig2 |= WM9712_PDEN; ++ } else { ++ dig1 &= ~(WM97XX_CTC | WM97XX_COO | WM97XX_SLEN); ++ dig2 &= ~WM9712_PDEN; ++ if (wm->mach_ops->acc_shutdown) ++ wm->mach_ops->acc_shutdown(wm); ++ } ++ ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1); ++ wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2); ++ return 0; ++} ++ ++struct wm97xx_codec_drv wm97xx_codec = { ++ .id = WM9712_ID2, ++ .name = "wm9712", ++ .poll_sample = wm9712_poll_sample, ++ .poll_touch = wm9712_poll_touch, ++ .acc_enable = wm9712_acc_enable, ++ .digitiser_ioctl = wm9712_digitiser_ioctl, ++}; ++ ++EXPORT_SYMBOL_GPL(wm97xx_codec); ++ ++/* Module information */ ++MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com"); ++MODULE_DESCRIPTION("WM9712 Touch Screen Driver"); ++MODULE_LICENSE("GPL"); +Index: linux-2.6.17/drivers/input/touchscreen/wm9713.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-2.6.17/drivers/input/touchscreen/wm9713.c 2006-09-19 20:36:47.969052000 +0200 +@@ -0,0 +1,461 @@ ++/* ++ * wm9713.c -- Codec touch driver for Wolfson WM9713 AC97 Codec. ++ * ++ * Copyright 2003, 2004, 2005, 2006 Wolfson Microelectronics PLC. ++ * Author: Liam Girdwood ++ * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com ++ * Parts Copyright : Ian Molton ++ * Andrew Zabolotny ++ * Russell King ++ * ++ * This program is free software; you can redistribute it and/or modify it ++ * under the terms of the GNU General Public License as published by the ++ * Free Software Foundation; either version 2 of the License, or (at your ++ * option) any later version. ++ * ++ * Revision history ++ * 6th Sep 2006 Mike Arthur ++ * Added pre and post sample calls. ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define TS_NAME "wm97xx" ++#define WM9713_VERSION "0.53" ++#define DEFAULT_PRESSURE 0xb0c0 ++ ++/* ++ * Debug ++ */ ++#if 0 ++#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg) ++#else ++#define dbg(format, arg...) ++#endif ++#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg) ++#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg) ++#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg) ++ ++/* ++ * Module parameters ++ */ ++ ++/* ++ * Set internal pull up for pen detect. ++ * ++ * Pull up is in the range 1.02k (least sensitive) to 64k (most sensitive) ++ * i.e. pull up resistance = 64k Ohms / rpu. ++ * ++ * Adjust this value if you are having problems with pen detect not ++ * detecting any down event. ++ */ ++static int rpu = 1; ++module_param(rpu, int, 0); ++MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect."); ++ ++/* ++ * Set current used for pressure measurement. ++ * ++ * Set pil = 2 to use 400uA ++ * pil = 1 to use 200uA and ++ * pil = 0 to disable pressure measurement. ++ * ++ * This is used to increase the range of values returned by the adc ++ * when measureing touchpanel pressure. ++ */ ++static int pil = 0; ++module_param(pil, int, 0); ++MODULE_PARM_DESC(pil, "Set current used for pressure measurement."); ++ ++/* ++ * Set threshold for pressure measurement. ++ * ++ * Pen down pressure below threshold is ignored. ++ */ ++static int pressure = DEFAULT_PRESSURE & 0xfff; ++module_param(pressure, int, 0); ++MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement."); ++ ++/* ++ * Set adc sample delay. ++ * ++ * For accurate touchpanel measurements, some settling time may be ++ * required between the switch matrix applying a voltage across the ++ * touchpanel plate and the ADC sampling the signal. ++ * ++ * This delay can be set by setting delay = n, where n is the array ++ * position of the delay in the array delay_table below. ++ * Long delays > 1ms are supported for completeness, but are not ++ * recommended. ++ */ ++static int delay = 4; ++module_param(delay, int, 0); ++MODULE_PARM_DESC(delay, "Set adc sample delay."); ++ ++/* ++ * Set adc mask function. ++ * ++ * Sources of glitch noise, such as signals driving an LCD display, may feed ++ * through to the touch screen plates and affect measurement accuracy. In ++ * order to minimise this, a signal may be applied to the MASK pin to delay or ++ * synchronise the sampling. ++ * ++ * 0 = No delay or sync ++ * 1 = High on pin stops conversions ++ * 2 = Edge triggered, edge on pin delays conversion by delay param (above) ++ * 3 = Edge triggered, edge on pin starts conversion after delay param ++ */ ++static int mask = 0; ++module_param(mask, int, 0); ++MODULE_PARM_DESC(mask, "Set adc mask function."); ++ ++/* ++ * Coordinate Polling Enable. ++ * ++ * Set to 1 to enable coordinate polling. e.g. x,y[,p] is sampled together ++ * for every poll. ++ */ ++static int coord = 1; ++module_param(coord, int, 0); ++MODULE_PARM_DESC(coord, "Polling coordinate mode"); ++ ++/* ++ * ADC sample delay times in uS ++ */ ++static const int delay_table[] = { ++ 21, // 1 AC97 Link frames ++ 42, // 2 ++ 84, // 4 ++ 167, // 8 ++ 333, // 16 ++ 667, // 32 ++ 1000, // 48 ++ 1333, // 64 ++ 2000, // 96 ++ 2667, // 128 ++ 3333, // 160 ++ 4000, // 192 ++ 4667, // 224 ++ 5333, // 256 ++ 6000, // 288 ++ 0 // No delay, switch matrix always on ++}; ++ ++/* ++ * Delay after issuing a POLL command. ++ * ++ * The delay is 3 AC97 link frames + the touchpanel settling delay ++ */ ++static inline void poll_delay(int d) ++{ ++ udelay (3 * AC97_LINK_FRAME + delay_table [d]); ++} ++ ++/* ++ * set up the physical settings of the WM9713 ++ */ ++static void init_wm9713_phy(struct wm97xx* wm) ++{ ++ u16 dig1 = 0, dig2, dig3; ++ ++ /* default values */ ++ dig2 = WM97XX_DELAY(4) | WM97XX_SLT(5); ++ dig3= WM9712_RPU(1); ++ ++ /* rpu */ ++ if (rpu) { ++ dig3 &= 0xffc0; ++ dig3 |= WM9712_RPU(rpu); ++ info("setting pen detect pull-up to %d Ohms",64000 / rpu); ++ } ++ ++ /* touchpanel pressure */ ++ if (pil == 2) { ++ dig3 |= WM9712_PIL; ++ info("setting pressure measurement current to 400uA."); ++ } else if (pil) ++ info ("setting pressure measurement current to 200uA."); ++ if(!pil) ++ pressure = 0; ++ ++ /* sample settling delay */ ++ if (delay < 0 || delay > 15) { ++ info ("supplied delay out of range."); ++ delay = 4; ++ info("setting adc sample delay to %d u Secs.", delay_table[delay]); ++ } ++ dig2 &= 0xff0f; ++ dig2 |= WM97XX_DELAY(delay); ++ ++ /* mask */ ++ dig3 |= ((mask & 0x3) << 4); ++ if(coord) ++ dig3 |= WM9713_WAIT; ++ ++ wm->misc = wm97xx_reg_read(wm, 0x5a); ++ ++ wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG2, dig2); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG3, dig3); ++ wm97xx_reg_write(wm, AC97_GPIO_STICKY, 0x0); ++} ++ ++static int wm9713_digitiser_ioctl(struct wm97xx* wm, int cmd) ++{ ++ u16 val = 0; ++ ++ switch(cmd){ ++ case WM97XX_DIG_START: ++ val = wm97xx_reg_read(wm, AC97_EXTENDED_MID); ++ wm97xx_reg_write(wm, AC97_EXTENDED_MID, val & 0x7fff); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2] | WM97XX_PRP_DET_DIG); ++ wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */ ++ break; ++ case WM97XX_DIG_STOP: ++ wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2] & ~WM97XX_PRP_DET_DIG); ++ val = wm97xx_reg_read(wm, AC97_EXTENDED_MID); ++ wm97xx_reg_write(wm, AC97_EXTENDED_MID, val | 0x8000); ++ break; ++ case WM97XX_AUX_PREPARE: ++ memcpy(wm->dig_save, wm->dig, sizeof(wm->dig)); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG1, 0); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG2, 0); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG3, WM97XX_PRP_DET_DIG); ++ break; ++ case WM97XX_DIG_RESTORE: ++ wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig_save[0]); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig_save[1]); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig_save[2]); ++ break; ++ case WM97XX_PHY_INIT: ++ init_wm9713_phy(wm); ++ break; ++ default: ++ return -EINVAL; ++ } ++ return 0; ++} ++ ++static inline int is_pden (struct wm97xx* wm) ++{ ++ return wm->dig[2] & WM9713_PDEN; ++} ++ ++/* ++ * Read a sample from the WM9713 adc in polling mode. ++ */ ++static int wm9713_poll_sample (struct wm97xx* wm, int adcsel, int *sample) ++{ ++ u16 dig1; ++ int timeout = 5 * delay; ++ ++ if (!wm->pen_probably_down) { ++ u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ if (!(data & WM97XX_PEN_DOWN)) ++ return RC_PENUP; ++ wm->pen_probably_down = 1; ++ } ++ ++ /* set up digitiser */ ++ if (adcsel & 0x8000) ++ adcsel = 1 << ((adcsel & 0x7fff) + 3); ++ ++ dig1 = wm97xx_reg_read(wm, AC97_WM9713_DIG1); ++ dig1 &= ~WM9713_ADCSEL_MASK; ++ ++ if (wm->mach_ops && wm->mach_ops->pre_sample) ++ wm->mach_ops->pre_sample(adcsel); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1 | adcsel |WM9713_POLL); ++ ++ /* wait 3 AC97 time slots + delay for conversion */ ++ poll_delay(delay); ++ ++ /* wait for POLL to go low */ ++ while ((wm97xx_reg_read(wm, AC97_WM9713_DIG1) & WM9713_POLL) && timeout) { ++ udelay(AC97_LINK_FRAME); ++ timeout--; ++ } ++ ++ if (timeout <= 0) { ++ /* If PDEN is set, we can get a timeout when pen goes up */ ++ if (is_pden(wm)) ++ wm->pen_probably_down = 0; ++ else ++ dbg ("adc sample timeout"); ++ return RC_PENUP; ++ } ++ ++ *sample =wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ if (wm->mach_ops && wm->mach_ops->post_sample) ++ wm->mach_ops->post_sample(adcsel); ++ ++ /* check we have correct sample */ ++ if ((*sample & WM97XX_ADCSRC_MASK) != ffs(adcsel >> 1) << 12) { ++ dbg ("adc wrong sample, read %x got %x", adcsel, ++ *sample & WM97XX_ADCSRC_MASK); ++ return RC_PENUP; ++ } ++ ++ if (!(*sample & WM97XX_PEN_DOWN)) { ++ wm->pen_probably_down = 0; ++ return RC_PENUP; ++ } ++ ++ return RC_VALID; ++} ++ ++/* ++ * Read a coordinate from the WM9713 adc in polling mode. ++ */ ++static int wm9713_poll_coord (struct wm97xx* wm, struct wm97xx_data *data) ++{ ++ u16 dig1; ++ int timeout = 5 * delay; ++ ++ if (!wm->pen_probably_down) { ++ u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ if (!(data & WM97XX_PEN_DOWN)) ++ return RC_PENUP; ++ wm->pen_probably_down = 1; ++ } ++ ++ /* set up digitiser */ ++ dig1 = wm97xx_reg_read(wm, AC97_WM9713_DIG1); ++ dig1 &= ~WM9713_ADCSEL_MASK; ++ if(pil) ++ dig1 |= WM97XX_ADCSEL_PRES; ++ ++ if (wm->mach_ops && wm->mach_ops->pre_sample) ++ wm->mach_ops->pre_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1 | WM9713_POLL | WM9713_COO); ++ ++ /* wait 3 AC97 time slots + delay for conversion */ ++ poll_delay(delay); ++ data->x = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ /* wait for POLL to go low */ ++ while ((wm97xx_reg_read(wm, AC97_WM9713_DIG1) & WM9713_POLL) && timeout) { ++ udelay(AC97_LINK_FRAME); ++ timeout--; ++ } ++ ++ if (timeout <= 0) { ++ /* If PDEN is set, we can get a timeout when pen goes up */ ++ if (is_pden(wm)) ++ wm->pen_probably_down = 0; ++ else ++ dbg ("adc sample timeout"); ++ return RC_PENUP; ++ } ++ ++ /* read back data */ ++ data->y = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ if (pil) ++ data->p = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); ++ else ++ data->p = DEFAULT_PRESSURE; ++ ++ if (wm->mach_ops && wm->mach_ops->post_sample) ++ wm->mach_ops->post_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y); ++ ++ /* check we have correct sample */ ++ if (!(data->x & WM97XX_ADCSEL_X) || !(data->y & WM97XX_ADCSEL_Y)) ++ goto err; ++ if(pil && !(data->p & WM97XX_ADCSEL_PRES)) ++ goto err; ++ ++ if (!(data->x & WM97XX_PEN_DOWN)) { ++ wm->pen_probably_down = 0; ++ return RC_PENUP; ++ } ++ return RC_VALID; ++err: ++ return RC_PENUP; ++} ++ ++/* ++ * Sample the WM9713 touchscreen in polling mode ++ */ ++static int wm9713_poll_touch(struct wm97xx* wm, struct wm97xx_data *data) ++{ ++ int rc; ++ ++ if(coord) { ++ if((rc = wm9713_poll_coord(wm, data)) != RC_VALID) ++ return rc; ++ } else { ++ if ((rc = wm9713_poll_sample(wm, WM9713_ADCSEL_X, &data->x)) != RC_VALID) ++ return rc; ++ if ((rc = wm9713_poll_sample(wm, WM9713_ADCSEL_Y, &data->y)) != RC_VALID) ++ return rc; ++ if (pil) { ++ if ((rc = wm9713_poll_sample(wm, WM9713_ADCSEL_PRES, &data->p)) != RC_VALID) ++ return rc; ++ } else ++ data->p = DEFAULT_PRESSURE; ++ } ++ return RC_VALID; ++} ++ ++/* ++ * Enable WM9713 continuous mode, i.e. touch data is streamed across an AC97 slot ++ */ ++static int wm9713_acc_enable (struct wm97xx* wm, int enable) ++{ ++ u16 dig1, dig2, dig3; ++ int ret = 0; ++ ++ dig1 = wm->dig[0]; ++ dig2 = wm->dig[1]; ++ dig3 = wm->dig[2]; ++ ++ if (enable) { ++ /* continous mode */ ++ if (wm->mach_ops->acc_startup && ++ (ret = wm->mach_ops->acc_startup(wm)) < 0) ++ return ret; ++ ++ dig1 &= ~WM9713_ADCSEL_MASK; ++ dig1 |= WM9713_CTC | WM9713_COO | WM9713_ADCSEL_X | WM9713_ADCSEL_Y; ++ if (pil) ++ dig1 |= WM9713_ADCSEL_PRES; ++ dig2 &= ~(WM97XX_DELAY_MASK | WM97XX_SLT_MASK | WM97XX_CM_RATE_MASK); ++ dig2 |= WM97XX_SLEN | WM97XX_DELAY (delay) | ++ WM97XX_SLT (wm->acc_slot) | WM97XX_RATE (wm->acc_rate); ++ dig3 |= WM9713_PDEN; ++ } else { ++ dig1 &= ~(WM9713_CTC | WM9713_COO); ++ dig2 &= ~WM97XX_SLEN; ++ dig3 &= ~WM9713_PDEN; ++ if (wm->mach_ops->acc_shutdown) ++ wm->mach_ops->acc_shutdown(wm); ++ } ++ ++ wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG2, dig2); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG3, dig3); ++ return ret; ++} ++ ++struct wm97xx_codec_drv wm97xx_codec = { ++ .id = WM9713_ID2, ++ .name = "wm9713", ++ .poll_sample = wm9713_poll_sample, ++ .poll_touch = wm9713_poll_touch, ++ .acc_enable = wm9713_acc_enable, ++ .digitiser_ioctl = wm9713_digitiser_ioctl, ++}; ++ ++EXPORT_SYMBOL_GPL(wm97xx_codec); ++ ++/* Module information */ ++MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com"); ++MODULE_DESCRIPTION("WM9713 Touch Screen Driver"); ++MODULE_LICENSE("GPL"); +Index: linux-2.6.17/drivers/input/touchscreen/wm97xx-core.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-2.6.17/drivers/input/touchscreen/wm97xx-core.c 2006-09-19 20:36:47.969052000 +0200 +@@ -0,0 +1,912 @@ ++/* ++ * wm97xx-core.c -- Touch screen driver core for Wolfson WM9705, WM9712 ++ * and WM9713 AC97 Codecs. ++ * ++ * Copyright 2003, 2004, 2005, 2006 Wolfson Microelectronics PLC. ++ * Author: Liam Girdwood ++ * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com ++ * Parts Copyright : Ian Molton ++ * Andrew Zabolotny ++ * Russell King ++ * ++ * This program is free software; you can redistribute it and/or modify it ++ * under the terms of the GNU General Public License as published by the ++ * Free Software Foundation; either version 2 of the License, or (at your ++ * option) any later version. ++ * ++ * Notes: ++ * ++ * Features: ++ * - supports WM9705, WM9712, WM9713 ++ * - polling mode ++ * - continuous mode (arch-dependent) ++ * - adjustable rpu/dpp settings ++ * - adjustable pressure current ++ * - adjustable sample settle delay ++ * - 4 and 5 wire touchscreens (5 wire is WM9712 only) ++ * - pen down detection ++ * - battery monitor ++ * - sample AUX adc's ++ * - power management ++ * - codec GPIO ++ * - codec event notification ++ * Todo ++ * - Support for async sampling control for noisy LCD's. ++ * ++ * Revision history ++ * 7th May 2003 Initial version. ++ * 6th June 2003 Added non module support and AC97 registration. ++ * 18th June 2003 Added AUX adc sampling. ++ * 23rd June 2003 Did some minimal reformatting, fixed a couple of ++ * codec_mutexing bugs and noted a race to fix. ++ * 24th June 2003 Added power management and fixed race condition. ++ * 10th July 2003 Changed to a misc device. ++ * 31st July 2003 Moved TS_EVENT and TS_CAL to wm97xx.h ++ * 8th Aug 2003 Added option for read() calling wm97xx_sample_touch() ++ * because some ac97_read/ac_97_write call schedule() ++ * 7th Nov 2003 Added Input touch event interface, stanley.cai@intel.com ++ * 13th Nov 2003 Removed h3600 touch interface, added interrupt based ++ * pen down notification and implemented continous mode ++ * on XScale arch. ++ * 16th Nov 2003 Ian Molton ++ * Modified so that it suits the new 2.6 driver model. ++ * 25th Jan 2004 Andrew Zabolotny ++ * Implemented IRQ-driven pen down detection, implemented ++ * the private API meant to be exposed to platform-specific ++ * drivers, reorganized the driver so that it supports ++ * an arbitrary number of devices. ++ * 1st Feb 2004 Moved continuous mode handling to a separate ++ * architecture-dependent file. For now only PXA ++ * built-in AC97 controller is supported (pxa-ac97-wm97xx.c). ++ * 11th Feb 2004 Reduced CPU usage by keeping a cached copy of both ++ * digitizer registers instead of reading them every time. ++ * A reorganization of the whole code for better ++ * error handling. ++ * 17th Apr 2004 Added BMON support. ++ * 17th Nov 2004 Added codec GPIO, codec event handling (real and virtual ++ * GPIOs) and 2.6 power management. ++ * 29th Nov 2004 Added WM9713 support. ++ * 4th Jul 2005 Moved codec specific code out to seperate files. ++ * 6th Sep 2006 Mike Arthur ++ * Added bus interface. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define TS_NAME "wm97xx" ++#define WM_CORE_VERSION "0.63" ++#define DEFAULT_PRESSURE 0xb0c0 ++ ++/* ++ * WM97xx - enable/disable AUX ADC sysfs ++ */ ++static int aux_sys = 1; ++module_param(aux_sys, int, 0); ++MODULE_PARM_DESC(aux_sys, "enable AUX ADC sysfs entries"); ++ ++/* ++ * WM97xx - enable/disable codec status sysfs ++ */ ++static int status_sys = 1; ++module_param(status_sys, int, 0); ++MODULE_PARM_DESC(status_sys, "enable codec status sysfs entries"); ++ ++/* ++ * Touchscreen absolute values ++ * ++ * These parameters are used to help the input layer discard out of ++ * range readings and reduce jitter etc. ++ * ++ * o min, max:- indicate the min and max values your touch screen returns ++ * o fuzz:- use a higher number to reduce jitter ++ * ++ * The default values correspond to Mainstone II in QVGA mode ++ * ++ * Please read ++ * Documentation/input/input-programming.txt for more details. ++ */ ++ ++static int abs_x[3] = {350,3900,5}; ++module_param_array(abs_x, int, NULL, 0); ++MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz"); ++ ++static int abs_y[3] = {320,3750,40}; ++module_param_array(abs_y, int, NULL, 0); ++MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz"); ++ ++static int abs_p[3] = {0,150,4}; ++module_param_array(abs_p, int, NULL, 0); ++MODULE_PARM_DESC(abs_p, "Touchscreen absolute Pressure min, max, fuzz"); ++ ++/* ++ * Debug ++ */ ++#if 0 ++#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg) ++#else ++#define dbg(format, arg...) ++#endif ++#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg) ++#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg) ++#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg) ++ ++/* codec AC97 IO access */ ++int wm97xx_reg_read(struct wm97xx *wm, u16 reg) ++{ ++ if (wm->ac97) ++ return wm->ac97->bus->ops->read(wm->ac97, reg); ++ else ++ return -1; ++} ++ ++void wm97xx_reg_write(struct wm97xx *wm, u16 reg, u16 val) ++{ ++ /* cache digitiser registers */ ++ if(reg >= AC97_WM9713_DIG1 && reg <= AC97_WM9713_DIG3) ++ wm->dig[(reg - AC97_WM9713_DIG1) >> 1] = val; ++ ++ /* cache gpio regs */ ++ if(reg >= AC97_GPIO_CFG && reg <= AC97_MISC_AFE) ++ wm->gpio[(reg - AC97_GPIO_CFG) >> 1] = val; ++ ++ /* wm9713 irq reg */ ++ if(reg == 0x5a) ++ wm->misc = val; ++ ++ if (wm->ac97) ++ wm->ac97->bus->ops->write(wm->ac97, reg, val); ++} ++ ++ ++/** ++ * wm97xx_read_aux_adc - Read the aux adc. ++ * @wm: wm97xx device. ++ * @adcsel: codec ADC to be read ++ * ++ * Reads the selected AUX ADC. ++ */ ++ ++int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel) ++{ ++ int power_adc = 0, auxval; ++ u16 power = 0; ++ ++ /* get codec */ ++ mutex_lock(&wm->codec_mutex); ++ ++ /* When the touchscreen is not in use, we may have to power up the AUX ADC ++ * before we can use sample the AUX inputs-> ++ */ ++ if (wm->id == WM9713_ID2 && ++ (power = wm97xx_reg_read(wm, AC97_EXTENDED_MID)) & 0x8000) { ++ power_adc = 1; ++ wm97xx_reg_write(wm, AC97_EXTENDED_MID, power & 0x7fff); ++ } ++ ++ /* Prepare the codec for AUX reading */ ++ wm->codec->digitiser_ioctl(wm, WM97XX_AUX_PREPARE); ++ ++ /* Turn polling mode on to read AUX ADC */ ++ wm->pen_probably_down = 1; ++ wm->codec->poll_sample(wm, adcsel, &auxval); ++ ++ if (power_adc) ++ wm97xx_reg_write(wm, AC97_EXTENDED_MID, power | 0x8000); ++ ++ wm->codec->digitiser_ioctl(wm, WM97XX_DIG_RESTORE); ++ ++ wm->pen_probably_down = 0; ++ ++ mutex_unlock(&wm->codec_mutex); ++ return auxval & 0xfff; ++} ++ ++#define WM97XX_AUX_ATTR(name,input) \ ++static ssize_t name##_show(struct device *dev, struct device_attribute *attr, char *buf) \ ++{ \ ++ struct wm97xx *wm = (struct wm97xx*)dev->driver_data; \ ++ return sprintf(buf, "%d\n", wm97xx_read_aux_adc(wm, input)); \ ++} \ ++static DEVICE_ATTR(name, 0444, name##_show, NULL) ++ ++WM97XX_AUX_ATTR(aux1, WM97XX_AUX_ID1); ++WM97XX_AUX_ATTR(aux2, WM97XX_AUX_ID2); ++WM97XX_AUX_ATTR(aux3, WM97XX_AUX_ID3); ++WM97XX_AUX_ATTR(aux4, WM97XX_AUX_ID4); ++ ++#define WM97XX_STATUS_ATTR(name) \ ++static ssize_t name##_show(struct device *dev, struct device_attribute *attr, char *buf) \ ++{ \ ++ struct wm97xx *wm = (struct wm97xx*)dev->driver_data; \ ++ return sprintf(buf, "%d\n", wm97xx_reg_read(wm, AC97_GPIO_STATUS)); \ ++} \ ++static DEVICE_ATTR(name, 0444, name##_show, NULL) ++ ++WM97XX_STATUS_ATTR(gpio); ++ ++static int wm97xx_sys_add(struct device *dev) ++{ ++ if (aux_sys) { ++ device_create_file(dev, &dev_attr_aux1); ++ device_create_file(dev, &dev_attr_aux2); ++ device_create_file(dev, &dev_attr_aux3); ++ device_create_file(dev, &dev_attr_aux4); ++ } ++ if (status_sys) ++ device_create_file(dev, &dev_attr_gpio); ++ return 0; ++} ++ ++static void wm97xx_sys_remove(struct device *dev) ++{ ++ if (status_sys) ++ device_remove_file(dev, &dev_attr_gpio); ++ if (aux_sys) { ++ device_remove_file(dev, &dev_attr_aux1); ++ device_remove_file(dev, &dev_attr_aux2); ++ device_remove_file(dev, &dev_attr_aux3); ++ device_remove_file(dev, &dev_attr_aux4); ++ } ++} ++ ++/** ++ * wm97xx_get_gpio - Get the status of a codec GPIO. ++ * @wm: wm97xx device. ++ * @gpio: gpio ++ * ++ * Get the status of a codec GPIO pin ++ */ ++ ++wm97xx_gpio_status_t wm97xx_get_gpio(struct wm97xx *wm, u32 gpio) ++{ ++ u16 status; ++ wm97xx_gpio_status_t ret; ++ ++ mutex_lock(&wm->codec_mutex); ++ status = wm97xx_reg_read(wm, AC97_GPIO_STATUS); ++ ++ if (status & gpio) ++ ret = WM97XX_GPIO_HIGH; ++ else ++ ret = WM97XX_GPIO_LOW; ++ ++ mutex_unlock(&wm->codec_mutex); ++ return ret; ++} ++ ++/** ++ * wm97xx_set_gpio - Set the status of a codec GPIO. ++ * @wm: wm97xx device. ++ * @gpio: gpio ++ * ++ * ++ * Set the status of a codec GPIO pin ++ */ ++ ++void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio, ++ wm97xx_gpio_status_t status) ++{ ++ u16 reg; ++ ++ mutex_lock(&wm->codec_mutex); ++ reg = wm97xx_reg_read(wm, AC97_GPIO_STATUS); ++ ++ if (status & WM97XX_GPIO_HIGH) ++ reg |= gpio; ++ else ++ reg &= ~gpio; ++ ++ if (wm->id == WM9712_ID2) ++ wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg << 1); ++ else ++ wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg); ++ mutex_unlock(&wm->codec_mutex); ++} ++ ++/* ++ * Codec GPIO pin configuration, this set's pin direction, polarity, ++ * stickyness and wake up. ++ */ ++void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, wm97xx_gpio_dir_t dir, ++ wm97xx_gpio_pol_t pol, wm97xx_gpio_sticky_t sticky, ++ wm97xx_gpio_wake_t wake) ++{ ++ u16 reg; ++ ++ mutex_lock(&wm->codec_mutex); ++ reg = wm97xx_reg_read(wm, AC97_GPIO_POLARITY); ++ ++ if (pol == WM97XX_GPIO_POL_HIGH) ++ reg |= gpio; ++ else ++ reg &= ~gpio; ++ ++ wm97xx_reg_write(wm, AC97_GPIO_POLARITY, reg); ++ reg = wm97xx_reg_read(wm, AC97_GPIO_STICKY); ++ ++ if (sticky == WM97XX_GPIO_STICKY) ++ reg |= gpio; ++ else ++ reg &= ~gpio; ++ ++ wm97xx_reg_write(wm, AC97_GPIO_STICKY, reg); ++ reg = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP); ++ ++ if (wake == WM97XX_GPIO_WAKE) ++ reg |= gpio; ++ else ++ reg &= ~gpio; ++ ++ wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, reg); ++ reg = wm97xx_reg_read(wm, AC97_GPIO_CFG); ++ ++ if (dir == WM97XX_GPIO_IN) ++ reg |= gpio; ++ else ++ reg &= ~gpio; ++ ++ wm97xx_reg_write(wm, AC97_GPIO_CFG, reg); ++ mutex_unlock(&wm->codec_mutex); ++} ++ ++/* ++ * Handle a pen down interrupt. ++ */ ++static void wm97xx_pen_irq_worker(void *ptr) ++{ ++ struct wm97xx *wm = (struct wm97xx *) ptr; ++ ++ /* do we need to enable the touch panel reader */ ++ if (wm->id == WM9705_ID2) { ++ if (wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD) & WM97XX_PEN_DOWN) ++ wm->pen_is_down = 1; ++ else ++ wm->pen_is_down = 0; ++ wake_up_interruptible(&wm->pen_irq_wait); ++ } else { ++ u16 status, pol; ++ mutex_lock(&wm->codec_mutex); ++ status = wm97xx_reg_read(wm, AC97_GPIO_STATUS); ++ pol = wm97xx_reg_read(wm, AC97_GPIO_POLARITY); ++ ++ if (WM97XX_GPIO_13 & pol & status) { ++ wm->pen_is_down = 1; ++ wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol & ~WM97XX_GPIO_13); ++ } else { ++ wm->pen_is_down = 0; ++ wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol | WM97XX_GPIO_13); ++ } ++ ++ if (wm->id == WM9712_ID2) ++ wm97xx_reg_write(wm, AC97_GPIO_STATUS, (status & ~WM97XX_GPIO_13) << 1); ++ else ++ wm97xx_reg_write(wm, AC97_GPIO_STATUS, status & ~WM97XX_GPIO_13); ++ mutex_unlock(&wm->codec_mutex); ++ wake_up_interruptible(&wm->pen_irq_wait); ++ } ++ ++ if (!wm->pen_is_down && wm->mach_ops && wm->mach_ops->acc_enabled) ++ wm->mach_ops->acc_pen_up(wm); ++ enable_irq(wm->pen_irq); ++} ++ ++/* ++ * Codec PENDOWN irq handler ++ * ++ * We have to disable the codec interrupt in the handler because it can ++ * take upto 1ms to clear the interrupt source. The interrupt is then enabled ++ * again in the slow handler when the source has been cleared. ++ */ ++static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id, ++ struct pt_regs *regs) ++{ ++ struct wm97xx *wm = (struct wm97xx *) dev_id; ++ disable_irq(wm->pen_irq); ++ queue_work(wm->pen_irq_workq, &wm->pen_event_work); ++ return IRQ_HANDLED; ++} ++ ++/* ++ * initialise pen IRQ handler and workqueue ++ */ ++static int wm97xx_init_pen_irq(struct wm97xx *wm) ++{ ++ u16 reg; ++ ++ INIT_WORK(&wm->pen_event_work, wm97xx_pen_irq_worker, wm); ++ if ((wm->pen_irq_workq = ++ create_singlethread_workqueue("kwm97pen")) == NULL) { ++ err("could not create pen irq work queue"); ++ wm->pen_irq = 0; ++ return -EINVAL; ++ } ++ ++ if (request_irq (wm->pen_irq, wm97xx_pen_interrupt, SA_SHIRQ, "wm97xx-pen", wm)) { ++ err("could not register codec pen down interrupt, will poll for pen down"); ++ destroy_workqueue(wm->pen_irq_workq); ++ wm->pen_irq = 0; ++ return -EINVAL; ++ } ++ ++ /* enable PEN down on wm9712/13 */ ++ if (wm->id != WM9705_ID2) { ++ reg = wm97xx_reg_read(wm, AC97_MISC_AFE); ++ wm97xx_reg_write(wm, AC97_MISC_AFE, reg & 0xfffb); ++ reg = wm97xx_reg_read(wm, 0x5a); ++ wm97xx_reg_write(wm, 0x5a, reg & ~0x0001); ++ } ++ ++ return 0; ++} ++ ++/* Private struct for communication between struct wm97xx_tshread ++ * and wm97xx_read_samples */ ++struct ts_state { ++ int sleep_time; ++ int min_sleep_time; ++}; ++ ++static int wm97xx_read_samples(struct wm97xx *wm, struct ts_state *state) ++{ ++ struct wm97xx_data data; ++ int rc; ++ ++ mutex_lock(&wm->codec_mutex); ++ ++ if (wm->mach_ops && wm->mach_ops->acc_enabled) ++ rc = wm->mach_ops->acc_pen_down(wm); ++ else ++ rc = wm->codec->poll_touch(wm, &data); ++ ++ if (rc & RC_PENUP) { ++ if (wm->pen_is_down) { ++ wm->pen_is_down = 0; ++ dbg("pen up"); ++ input_report_abs(wm->input_dev, ABS_PRESSURE, 0); ++ input_sync(wm->input_dev); ++ } else if (!(rc & RC_AGAIN)) { ++ /* We need high frequency updates only while pen is down, ++ * the user never will be able to touch screen faster than ++ * a few times per second... On the other hand, when the ++ * user is actively working with the touchscreen we don't ++ * want to lose the quick response. So we will slowly ++ * increase sleep time after the pen is up and quicky ++ * restore it to ~one task switch when pen is down again. ++ */ ++ if (state->sleep_time < HZ / 10) ++ state->sleep_time++; ++ } ++ ++ } else if (rc & RC_VALID) { ++ dbg("pen down: x=%x:%d, y=%x:%d, pressure=%x:%d\n", ++ data.x >> 12, data.x & 0xfff, data.y >> 12, ++ data.y & 0xfff, data.p >> 12, data.p & 0xfff); ++ input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff); ++ input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff); ++ input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff); ++ input_sync(wm->input_dev); ++ wm->pen_is_down = 1; ++ state->sleep_time = state->min_sleep_time; ++ } else if (rc & RC_PENDOWN) { ++ dbg("pen down"); ++ wm->pen_is_down = 1; ++ state->sleep_time = state->min_sleep_time; ++ } ++ ++ mutex_unlock(&wm->codec_mutex); ++ return rc; ++} ++ ++/* ++* The touchscreen sample reader thread. ++*/ ++static int wm97xx_ts_read(void *data) ++{ ++ int rc; ++ struct ts_state state; ++ struct wm97xx *wm = (struct wm97xx *) data; ++ ++ /* set up thread context */ ++ wm->ts_task = current; ++ daemonize("kwm97xxts"); ++ ++ if (wm->codec == NULL) { ++ wm->ts_task = NULL; ++ printk(KERN_ERR "codec is NULL, bailing\n"); ++ } ++ ++ complete(&wm->ts_init); ++ wm->pen_is_down = 0; ++ state.min_sleep_time = HZ >= 100 ? HZ / 100 : 1; ++ if (state.min_sleep_time < 1) ++ state.min_sleep_time = 1; ++ state.sleep_time = state.min_sleep_time; ++ ++ /* touch reader loop */ ++ while (wm->ts_task) { ++ do { ++ try_to_freeze(); ++ rc = wm97xx_read_samples(wm, &state); ++ } while (rc & RC_AGAIN); ++ if (!wm->pen_is_down && wm->pen_irq) { ++ /* Nice, we don't have to poll for pen down event */ ++ wait_event_interruptible(wm->pen_irq_wait, wm->pen_is_down); ++ } else { ++ set_task_state(current, TASK_INTERRUPTIBLE); ++ schedule_timeout(state.sleep_time); ++ } ++ } ++ complete_and_exit(&wm->ts_exit, 0); ++} ++ ++/** ++ * wm97xx_ts_input_open - Open the touch screen input device. ++ * @idev: Input device to be opened. ++ * ++ * Called by the input sub system to open a wm97xx touchscreen device. ++ * Starts the touchscreen thread and touch digitiser. ++ */ ++static int wm97xx_ts_input_open(struct input_dev *idev) ++{ ++ int ret = 0; ++ struct wm97xx *wm = (struct wm97xx *) idev->private; ++ ++ mutex_lock(&wm->codec_mutex); ++ /* first time opened ? */ ++ if (wm->ts_use_count++ == 0) { ++ /* start touchscreen thread */ ++ init_completion(&wm->ts_init); ++ init_completion(&wm->ts_exit); ++ ret = kernel_thread(wm97xx_ts_read, wm, CLONE_KERNEL); ++ ++ if (ret >= 0) { ++ wait_for_completion(&wm->ts_init); ++ if (wm->ts_task == NULL) ++ ret = -EINVAL; ++ } else { ++ mutex_unlock(&wm->codec_mutex); ++ return ret; ++ } ++ ++ /* start digitiser */ ++ if (wm->mach_ops && wm->mach_ops->acc_enabled) ++ wm->codec->acc_enable(wm, 1); ++ wm->codec->digitiser_ioctl(wm, WM97XX_DIG_START); ++ ++ /* init pen down/up irq handling */ ++ if (wm->pen_irq) { ++ wm97xx_init_pen_irq(wm); ++ ++ if (wm->pen_irq == 0) { ++ /* we failed to get an irq for pen down events, ++ * so we resort to polling. kickstart the reader */ ++ wm->pen_is_down = 1; ++ wake_up_interruptible(&wm->pen_irq_wait); ++ } ++ } ++ } ++ ++ mutex_unlock(&wm->codec_mutex); ++ return 0; ++} ++ ++/** ++ * wm97xx_ts_input_close - Close the touch screen input device. ++ * @idev: Input device to be closed. ++ * ++ * Called by the input sub system to close a wm97xx touchscreen device. ++ * Kills the touchscreen thread and stops the touch digitiser. ++ */ ++ ++static void wm97xx_ts_input_close(struct input_dev *idev) ++{ ++ struct wm97xx *wm = (struct wm97xx *) idev->private; ++ ++ mutex_lock(&wm->codec_mutex); ++ if (--wm->ts_use_count == 0) { ++ /* destroy workqueues and free irqs */ ++ if (wm->pen_irq) { ++ free_irq(wm->pen_irq, wm); ++ destroy_workqueue(wm->pen_irq_workq); ++ } ++ ++ /* kill thread */ ++ if (wm->ts_task) { ++ wm->ts_task = NULL; ++ wm->pen_is_down = 1; ++ wake_up_interruptible(&wm->pen_irq_wait); ++ wait_for_completion(&wm->ts_exit); ++ wm->pen_is_down = 0; ++ } ++ ++ /* stop digitiser */ ++ wm->codec->digitiser_ioctl(wm, WM97XX_DIG_STOP); ++ if (wm->mach_ops && wm->mach_ops->acc_enabled) ++ wm->codec->acc_enable(wm, 0); ++ } ++ mutex_unlock(&wm->codec_mutex); ++} ++ ++static int wm97xx_bus_match(struct device *dev, struct device_driver *drv) ++{ ++ return !(strcmp(dev->bus_id,drv->name)); ++} ++ ++/* ++ * The AC97 audio driver will do all the Codec suspend and resume ++ * tasks. This is just for anything machine specific or extra. ++ */ ++static int wm97xx_bus_suspend(struct device *dev, pm_message_t state) ++{ ++ int ret = 0; ++ ++ if (dev->driver && dev->driver->suspend) ++ ret = dev->driver->suspend(dev, state); ++ ++ return ret; ++} ++ ++static int wm97xx_bus_resume(struct device *dev) ++{ ++ int ret = 0; ++ ++ if (dev->driver && dev->driver->resume) ++ ret = dev->driver->resume(dev); ++ ++ return ret; ++} ++ ++struct bus_type wm97xx_bus_type = { ++ .name = "wm97xx", ++ .match = wm97xx_bus_match, ++ .suspend = wm97xx_bus_suspend, ++ .resume = wm97xx_bus_resume, ++}; ++ ++static void wm97xx_release(struct device *dev) ++{ ++ kfree(dev); ++} ++ ++static int wm97xx_probe(struct device *dev) ++{ ++ struct wm97xx* wm; ++ int ret = 0, id = 0; ++ ++ if (!(wm = kzalloc(sizeof(struct wm97xx), GFP_KERNEL))) ++ return -ENOMEM; ++ mutex_init(&wm->codec_mutex); ++ ++ init_waitqueue_head(&wm->pen_irq_wait); ++ wm->dev = dev; ++ dev->driver_data = wm; ++ wm->ac97 = to_ac97_t(dev); ++ ++ /* check that we have a supported codec */ ++ if ((id = wm97xx_reg_read(wm, AC97_VENDOR_ID1)) != WM97XX_ID1) { ++ err("could not find a wm97xx, found a %x instead\n", id); ++ kfree(wm); ++ return -ENODEV; ++ } ++ ++ wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2); ++ if(wm->id != wm97xx_codec.id) { ++ err("could not find a the selected codec, please build for wm97%2x", wm->id & 0xff); ++ kfree(wm); ++ return -ENODEV; ++ } ++ ++ if((wm->input_dev = input_allocate_device()) == NULL) { ++ kfree(wm); ++ return -ENOMEM; ++ } ++ ++ /* set up touch configuration */ ++ info("detected a wm97%2x codec", wm->id & 0xff); ++ wm->input_dev->name = "wm97xx touchscreen"; ++ wm->input_dev->open = wm97xx_ts_input_open; ++ wm->input_dev->close = wm97xx_ts_input_close; ++ set_bit(EV_ABS, wm->input_dev->evbit); ++ set_bit(ABS_X, wm->input_dev->absbit); ++ set_bit(ABS_Y, wm->input_dev->absbit); ++ set_bit(ABS_PRESSURE, wm->input_dev->absbit); ++ wm->input_dev->absmax[ABS_X] = abs_x[1]; ++ wm->input_dev->absmax[ABS_Y] = abs_y[1]; ++ wm->input_dev->absmax[ABS_PRESSURE] = abs_p[1]; ++ wm->input_dev->absmin[ABS_X] = abs_x[0]; ++ wm->input_dev->absmin[ABS_Y] = abs_y[0]; ++ wm->input_dev->absmin[ABS_PRESSURE] = abs_p[0]; ++ wm->input_dev->absfuzz[ABS_X] = abs_x[2]; ++ wm->input_dev->absfuzz[ABS_Y] = abs_y[2]; ++ wm->input_dev->absfuzz[ABS_PRESSURE] = abs_p[2]; ++ wm->input_dev->private = wm; ++ wm->codec = &wm97xx_codec; ++ if((ret = input_register_device(wm->input_dev)) < 0) { ++ kfree(wm); ++ return -ENOMEM; ++ } ++ ++ if(aux_sys) ++ wm97xx_sys_add(dev); ++ ++ /* set up physical characteristics */ ++ wm->codec->digitiser_ioctl(wm, WM97XX_PHY_INIT); ++ ++ /* load gpio cache */ ++ wm->gpio[0] = wm97xx_reg_read(wm, AC97_GPIO_CFG); ++ wm->gpio[1] = wm97xx_reg_read(wm, AC97_GPIO_POLARITY); ++ wm->gpio[2] = wm97xx_reg_read(wm, AC97_GPIO_STICKY); ++ wm->gpio[3] = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP); ++ wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS); ++ wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE); ++ ++ /* register our battery device */ ++ if (!(wm->battery_dev = kzalloc(sizeof(struct device), GFP_KERNEL))) { ++ ret = -ENOMEM; ++ goto batt_err; ++ } ++ wm->battery_dev->bus = &wm97xx_bus_type; ++ strcpy(wm->battery_dev->bus_id,"wm97xx-battery"); ++ wm->battery_dev->driver_data = wm; ++ wm->battery_dev->parent = dev; ++ wm->battery_dev->release = wm97xx_release; ++ if((ret = device_register(wm->battery_dev)) < 0) ++ goto batt_reg_err; ++ ++ /* register our extended touch device (for machine specific extensions) */ ++ if (!(wm->touch_dev = kzalloc(sizeof(struct device), GFP_KERNEL))) { ++ ret = -ENOMEM; ++ goto touch_err; ++ } ++ wm->touch_dev->bus = &wm97xx_bus_type; ++ strcpy(wm->touch_dev->bus_id,"wm97xx-touchscreen"); ++ wm->touch_dev->driver_data = wm; ++ wm->touch_dev->parent = dev; ++ wm->touch_dev->release = wm97xx_release; ++ if((ret = device_register(wm->touch_dev)) < 0) ++ goto touch_reg_err; ++ ++ return ret; ++ ++touch_reg_err: ++ kfree(wm->touch_dev); ++touch_err: ++ device_unregister(wm->battery_dev); ++batt_reg_err: ++ kfree(wm->battery_dev); ++batt_err: ++ input_unregister_device(wm->input_dev); ++ kfree(wm); ++ return ret; ++} ++ ++static int wm97xx_remove(struct device *dev) ++{ ++ struct wm97xx *wm = dev_get_drvdata(dev); ++ ++ /* Stop touch reader thread */ ++ if (wm->ts_task) { ++ wm->ts_task = NULL; ++ wm->pen_is_down = 1; ++ wake_up_interruptible(&wm->pen_irq_wait); ++ wait_for_completion(&wm->ts_exit); ++ } ++ device_unregister(wm->battery_dev); ++ device_unregister(wm->touch_dev); ++ input_unregister_device(wm->input_dev); ++ ++ if(aux_sys) ++ wm97xx_sys_remove(dev); ++ ++ kfree(wm); ++ return 0; ++} ++ ++#ifdef CONFIG_PM ++int wm97xx_resume(struct device* dev) ++{ ++ struct wm97xx *wm = dev_get_drvdata(dev); ++ ++ /* restore digitiser and gpio's */ ++ if(wm->id == WM9713_ID2) { ++ wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig[0]); ++ wm97xx_reg_write(wm, 0x5a, wm->misc); ++ if(wm->ts_use_count) { ++ u16 reg = wm97xx_reg_read(wm, AC97_EXTENDED_MID) & 0x7fff; ++ wm97xx_reg_write(wm, AC97_EXTENDED_MID, reg); ++ } ++ } ++ ++ wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig[1]); ++ wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2]); ++ ++ wm97xx_reg_write(wm, AC97_GPIO_CFG, wm->gpio[0]); ++ wm97xx_reg_write(wm, AC97_GPIO_POLARITY, wm->gpio[1]); ++ wm97xx_reg_write(wm, AC97_GPIO_STICKY, wm->gpio[2]); ++ wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, wm->gpio[3]); ++ wm97xx_reg_write(wm, AC97_GPIO_STATUS, wm->gpio[4]); ++ wm97xx_reg_write(wm, AC97_MISC_AFE, wm->gpio[5]); ++ ++ return 0; ++} ++ ++#else ++#define wm97xx_resume NULL ++#endif ++ ++int wm97xx_register_mach_ops(struct wm97xx *wm, struct wm97xx_mach_ops *mach_ops) ++{ ++ mutex_lock(&wm->codec_mutex); ++ if(wm->mach_ops) { ++ mutex_unlock(&wm->codec_mutex); ++ return -EINVAL; ++ } ++ wm->mach_ops = mach_ops; ++ mutex_unlock(&wm->codec_mutex); ++ return 0; ++} ++ ++void wm97xx_unregister_mach_ops(struct wm97xx *wm) ++{ ++ mutex_lock(&wm->codec_mutex); ++ wm->mach_ops = NULL; ++ mutex_unlock(&wm->codec_mutex); ++} ++ ++static struct device_driver wm97xx_driver = { ++ .name = "ac97", ++ .bus = &ac97_bus_type, ++ .owner = THIS_MODULE, ++ .probe = wm97xx_probe, ++ .remove = wm97xx_remove, ++ .resume = wm97xx_resume, ++}; ++ ++static int __init wm97xx_init(void) ++{ ++ int ret; ++ ++ info("version %s liam.girdwood@wolfsonmicro.com", WM_CORE_VERSION); ++ if((ret = bus_register(&wm97xx_bus_type)) < 0) ++ return ret; ++ return driver_register(&wm97xx_driver); ++} ++ ++static void __exit wm97xx_exit(void) ++{ ++ driver_unregister(&wm97xx_driver); ++ bus_unregister(&wm97xx_bus_type); ++} ++ ++EXPORT_SYMBOL_GPL(wm97xx_get_gpio); ++EXPORT_SYMBOL_GPL(wm97xx_set_gpio); ++EXPORT_SYMBOL_GPL(wm97xx_config_gpio); ++EXPORT_SYMBOL_GPL(wm97xx_read_aux_adc); ++EXPORT_SYMBOL_GPL(wm97xx_reg_read); ++EXPORT_SYMBOL_GPL(wm97xx_reg_write); ++EXPORT_SYMBOL_GPL(wm97xx_bus_type); ++EXPORT_SYMBOL_GPL(wm97xx_register_mach_ops); ++EXPORT_SYMBOL_GPL(wm97xx_unregister_mach_ops); ++ ++module_init(wm97xx_init); ++module_exit(wm97xx_exit); ++ ++/* Module information */ ++MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com"); ++MODULE_DESCRIPTION("WM97xx Core - Touch Screen / AUX ADC / GPIO Driver"); ++MODULE_LICENSE("GPL"); +Index: linux-2.6.17/include/linux/wm97xx.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-2.6.17/include/linux/wm97xx.h 2006-09-19 20:36:47.973052250 +0200 +@@ -0,0 +1,291 @@ ++ ++/* ++ * Register bits and API for Wolfson WM97xx series of codecs ++ */ ++ ++#ifndef _LINUX_WM97XX_H ++#define _LINUX_WM97XX_H ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include /* Input device layer */ ++ ++/* ++ * WM97xx AC97 Touchscreen registers ++ */ ++#define AC97_WM97XX_DIGITISER1 0x76 ++#define AC97_WM97XX_DIGITISER2 0x78 ++#define AC97_WM97XX_DIGITISER_RD 0x7a ++#define AC97_WM9713_DIG1 0x74 ++#define AC97_WM9713_DIG2 AC97_WM97XX_DIGITISER1 ++#define AC97_WM9713_DIG3 AC97_WM97XX_DIGITISER2 ++ ++/* ++ * WM97xx register bits ++ */ ++#define WM97XX_POLL 0x8000 /* initiate a polling measurement */ ++#define WM97XX_ADCSEL_X 0x1000 /* x coord measurement */ ++#define WM97XX_ADCSEL_Y 0x2000 /* y coord measurement */ ++#define WM97XX_ADCSEL_PRES 0x3000 /* pressure measurement */ ++#define WM97XX_ADCSEL_MASK 0x7000 ++#define WM97XX_COO 0x0800 /* enable coordinate mode */ ++#define WM97XX_CTC 0x0400 /* enable continuous mode */ ++#define WM97XX_CM_RATE_93 0x0000 /* 93.75Hz continuous rate */ ++#define WM97XX_CM_RATE_187 0x0100 /* 187.5Hz continuous rate */ ++#define WM97XX_CM_RATE_375 0x0200 /* 375Hz continuous rate */ ++#define WM97XX_CM_RATE_750 0x0300 /* 750Hz continuous rate */ ++#define WM97XX_CM_RATE_8K 0x00f0 /* 8kHz continuous rate */ ++#define WM97XX_CM_RATE_12K 0x01f0 /* 12kHz continuous rate */ ++#define WM97XX_CM_RATE_24K 0x02f0 /* 24kHz continuous rate */ ++#define WM97XX_CM_RATE_48K 0x03f0 /* 48kHz continuous rate */ ++#define WM97XX_CM_RATE_MASK 0x03f0 ++#define WM97XX_RATE(i) (((i & 3) << 8) | ((i & 4) ? 0xf0 : 0)) ++#define WM97XX_DELAY(i) ((i << 4) & 0x00f0) /* sample delay times */ ++#define WM97XX_DELAY_MASK 0x00f0 ++#define WM97XX_SLEN 0x0008 /* slot read back enable */ ++#define WM97XX_SLT(i) ((i - 5) & 0x7) /* touchpanel slot selection (5-11) */ ++#define WM97XX_SLT_MASK 0x0007 ++#define WM97XX_PRP_DETW 0x4000 /* pen detect on, digitiser off, wake up */ ++#define WM97XX_PRP_DET 0x8000 /* pen detect on, digitiser off, no wake up */ ++#define WM97XX_PRP_DET_DIG 0xc000 /* pen detect on, digitiser on */ ++#define WM97XX_RPR 0x2000 /* wake up on pen down */ ++#define WM97XX_PEN_DOWN 0x8000 /* pen is down */ ++#define WM97XX_ADCSRC_MASK 0x7000 /* ADC source mask */ ++ ++#define WM97XX_AUX_ID1 0x8001 ++#define WM97XX_AUX_ID2 0x8002 ++#define WM97XX_AUX_ID3 0x8003 ++#define WM97XX_AUX_ID4 0x8004 ++ ++ ++/* WM9712 Bits */ ++#define WM9712_45W 0x1000 /* set for 5-wire touchscreen */ ++#define WM9712_PDEN 0x0800 /* measure only when pen down */ ++#define WM9712_WAIT 0x0200 /* wait until adc is read before next sample */ ++#define WM9712_PIL 0x0100 /* current used for pressure measurement. set 400uA else 200uA */ ++#define WM9712_MASK_HI 0x0040 /* hi on mask pin (47) stops conversions */ ++#define WM9712_MASK_EDGE 0x0080 /* rising/falling edge on pin delays sample */ ++#define WM9712_MASK_SYNC 0x00c0 /* rising/falling edge on mask initiates sample */ ++#define WM9712_RPU(i) (i&0x3f) /* internal pull up on pen detect (64k / rpu) */ ++#define WM9712_PD(i) (0x1 << i) /* power management */ ++ ++/* WM9712 Registers */ ++#define AC97_WM9712_POWER 0x24 ++#define AC97_WM9712_REV 0x58 ++ ++/* WM9705 Bits */ ++#define WM9705_PDEN 0x1000 /* measure only when pen is down */ ++#define WM9705_PINV 0x0800 /* inverts sense of pen down output */ ++#define WM9705_BSEN 0x0400 /* BUSY flag enable, pin47 is 1 when busy */ ++#define WM9705_BINV 0x0200 /* invert BUSY (pin47) output */ ++#define WM9705_WAIT 0x0100 /* wait until adc is read before next sample */ ++#define WM9705_PIL 0x0080 /* current used for pressure measurement. set 400uA else 200uA */ ++#define WM9705_PHIZ 0x0040 /* set PHONE and PCBEEP inputs to high impedance */ ++#define WM9705_MASK_HI 0x0010 /* hi on mask stops conversions */ ++#define WM9705_MASK_EDGE 0x0020 /* rising/falling edge on pin delays sample */ ++#define WM9705_MASK_SYNC 0x0030 /* rising/falling edge on mask initiates sample */ ++#define WM9705_PDD(i) (i & 0x000f) /* pen detect comparator threshold */ ++ ++ ++/* WM9713 Bits */ ++#define WM9713_PDPOL 0x0400 /* Pen down polarity */ ++#define WM9713_POLL 0x0200 /* initiate a polling measurement */ ++#define WM9713_CTC 0x0100 /* enable continuous mode */ ++#define WM9713_ADCSEL_X 0x0002 /* X measurement */ ++#define WM9713_ADCSEL_Y 0x0004 /* Y measurement */ ++#define WM9713_ADCSEL_PRES 0x0008 /* Pressure measurement */ ++#define WM9713_COO 0x0001 /* enable coordinate mode */ ++#define WM9713_PDEN 0x0800 /* measure only when pen down */ ++#define WM9713_ADCSEL_MASK 0x00fe /* ADC selection mask */ ++#define WM9713_WAIT 0x0200 /* coordinate wait */ ++ ++/* AUX ADC ID's */ ++#define TS_COMP1 0x0 ++#define TS_COMP2 0x1 ++#define TS_BMON 0x2 ++#define TS_WIPER 0x3 ++ ++/* ID numbers */ ++#define WM97XX_ID1 0x574d ++#define WM9712_ID2 0x4c12 ++#define WM9705_ID2 0x4c05 ++#define WM9713_ID2 0x4c13 ++ ++/* Codec GPIO's */ ++#define WM97XX_MAX_GPIO 16 ++#define WM97XX_GPIO_1 (1 << 1) ++#define WM97XX_GPIO_2 (1 << 2) ++#define WM97XX_GPIO_3 (1 << 3) ++#define WM97XX_GPIO_4 (1 << 4) ++#define WM97XX_GPIO_5 (1 << 5) ++#define WM97XX_GPIO_6 (1 << 6) ++#define WM97XX_GPIO_7 (1 << 7) ++#define WM97XX_GPIO_8 (1 << 8) ++#define WM97XX_GPIO_9 (1 << 9) ++#define WM97XX_GPIO_10 (1 << 10) ++#define WM97XX_GPIO_11 (1 << 11) ++#define WM97XX_GPIO_12 (1 << 12) ++#define WM97XX_GPIO_13 (1 << 13) ++#define WM97XX_GPIO_14 (1 << 14) ++#define WM97XX_GPIO_15 (1 << 15) ++ ++ ++#define AC97_LINK_FRAME 21 /* time in uS for AC97 link frame */ ++ ++ ++/*---------------- Return codes from sample reading functions ---------------*/ ++ ++/* More data is available; call the sample gathering function again */ ++#define RC_AGAIN 0x00000001 ++/* The returned sample is valid */ ++#define RC_VALID 0x00000002 ++/* The pen is up (the first RC_VALID without RC_PENUP means pen is down) */ ++#define RC_PENUP 0x00000004 ++/* The pen is down (RC_VALID implies RC_PENDOWN, but sometimes it is helpful ++ to tell the handler that the pen is down but we don't know yet his coords, ++ so the handler should not sleep or wait for pendown irq) */ ++#define RC_PENDOWN 0x00000008 ++ ++/* The wm97xx driver provides a private API for writing platform-specific ++ * drivers. ++ */ ++ ++/* The structure used to return arch specific sampled data into */ ++struct wm97xx_data { ++ int x; ++ int y; ++ int p; ++}; ++ ++/* Codec GPIO status ++ */ ++typedef enum { ++ WM97XX_GPIO_HIGH, ++ WM97XX_GPIO_LOW ++} wm97xx_gpio_status_t; ++ ++/* Codec GPIO direction ++ */ ++typedef enum { ++ WM97XX_GPIO_IN, ++ WM97XX_GPIO_OUT ++} wm97xx_gpio_dir_t; ++ ++/* Codec GPIO polarity ++ */ ++typedef enum { ++ WM97XX_GPIO_POL_HIGH, ++ WM97XX_GPIO_POL_LOW ++} wm97xx_gpio_pol_t; ++ ++/* Codec GPIO sticky ++ */ ++typedef enum { ++ WM97XX_GPIO_STICKY, ++ WM97XX_GPIO_NOTSTICKY ++} wm97xx_gpio_sticky_t; ++ ++/* Codec GPIO wake ++ */ ++typedef enum { ++ WM97XX_GPIO_WAKE, ++ WM97XX_GPIO_NOWAKE ++} wm97xx_gpio_wake_t; ++ ++ ++/* ++ * Digitiser ioctl commands ++ */ ++#define WM97XX_DIG_START 0x1 ++#define WM97XX_DIG_STOP 0x2 ++#define WM97XX_PHY_INIT 0x3 ++#define WM97XX_AUX_PREPARE 0x4 ++#define WM97XX_DIG_RESTORE 0x5 ++ ++struct wm97xx; ++extern struct wm97xx_codec_drv wm97xx_codec; ++ ++/* ++ * Codec driver interface - allows mapping to WM9705/12/13 and newer codecs ++ */ ++struct wm97xx_codec_drv { ++ u16 id; ++ char *name; ++ int (*poll_sample) (struct wm97xx *, int adcsel, int *sample); /* read 1 sample */ ++ int (*poll_touch) (struct wm97xx *, struct wm97xx_data *); /* read X,Y,[P] in poll */ ++ int (*digitiser_ioctl) (struct wm97xx *, int cmd); ++ int (*acc_enable) (struct wm97xx *, int enable); ++}; ++ ++ ++/* Machine specific and accelerated touch operations */ ++struct wm97xx_mach_ops { ++ ++ /* accelerated touch readback - coords are transmited on AC97 link */ ++ int acc_enabled; ++ void (*acc_pen_up) (struct wm97xx *); ++ int (*acc_pen_down) (struct wm97xx *); ++ int (*acc_startup) (struct wm97xx *); ++ void (*acc_shutdown) (struct wm97xx *); ++ ++ /* pre and post sample - can be used to minimise any analog noise */ ++ void (*pre_sample) (int); /* function to run before sampling */ ++ void (*post_sample) (int); /* function to run after sampling */ ++}; ++ ++struct wm97xx { ++ u16 dig[3], id, gpio[6], misc; /* Cached codec registers */ ++ u16 dig_save[3]; /* saved during aux reading */ ++ struct wm97xx_codec_drv *codec; /* attached codec driver*/ ++ struct input_dev* input_dev; /* touchscreen input device */ ++ ac97_t *ac97; /* ALSA codec access */ ++ struct device *dev; /* ALSA device */ ++ struct device *battery_dev; ++ struct device *touch_dev; ++ struct wm97xx_mach_ops *mach_ops; ++ struct mutex codec_mutex; ++ struct completion ts_init; ++ struct completion ts_exit; ++ struct task_struct *ts_task; ++ unsigned int pen_irq; /* Pen IRQ number in use */ ++ wait_queue_head_t pen_irq_wait; /* Pen IRQ wait queue */ ++ struct workqueue_struct *pen_irq_workq; ++ struct work_struct pen_event_work; ++ u16 acc_slot; /* AC97 slot used for acc touch data */ ++ u16 acc_rate; /* acc touch data rate */ ++ unsigned int ts_use_count; ++ unsigned pen_is_down:1; /* Pen is down */ ++ unsigned aux_waiting:1; /* aux measurement waiting */ ++ unsigned pen_probably_down:1; /* used in polling mode */ ++}; ++ ++/* Codec GPIO access (not supported on WM9705) ++ * This can be used to set/get codec GPIO and Virtual GPIO status. ++ */ ++wm97xx_gpio_status_t wm97xx_get_gpio(struct wm97xx *wm, u32 gpio); ++void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio, ++ wm97xx_gpio_status_t status); ++void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, ++ wm97xx_gpio_dir_t dir, ++ wm97xx_gpio_pol_t pol, ++ wm97xx_gpio_sticky_t sticky, ++ wm97xx_gpio_wake_t wake); ++ ++/* codec AC97 IO access */ ++int wm97xx_reg_read(struct wm97xx *wm, u16 reg); ++void wm97xx_reg_write(struct wm97xx *wm, u16 reg, u16 val); ++ ++/* aux adc readback */ ++int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel); ++ ++/* machine ops */ ++int wm97xx_register_mach_ops(struct wm97xx *, struct wm97xx_mach_ops *); ++void wm97xx_unregister_mach_ops(struct wm97xx *); ++ ++extern struct bus_type wm97xx_bus_type; ++#endif -- cgit v1.2.3