mirror of
https://github.com/linux-thinkpad/tp_smapi.git
synced 2024-09-11 07:05:28 +03:00
import of tp-smapi version 0.26
This commit is contained in:
parent
946d5853d4
commit
840646759a
7
CHANGES
7
CHANGES
@ -1,5 +1,12 @@
|
||||
Change history for tp_smapi:
|
||||
|
||||
0.26 2006-08-04
|
||||
---------------------
|
||||
- The modified hdaps.c is now included as a full file (based on linux git)
|
||||
instead of a patch, to solve compilation and versioning problems.
|
||||
- Makefile: Fixed a problem with "make patch" on new kernels.
|
||||
- tp_smapi.c: renamed internal attribute functions.
|
||||
|
||||
0.25 2006-08-03
|
||||
---------------------
|
||||
- Added new attribute:
|
||||
|
31
Makefile
31
Makefile
@ -40,21 +40,16 @@ clean:
|
||||
rm -f tp_base.mod.* tp_base.o tp_base.ko .tp_base.*.cmd
|
||||
rm -f hdaps.mod.* hdaps.o hdaps.ko .hdaps.*.cmd
|
||||
rm -f *~ diff/*~ *.orig diff/*.orig *.rej diff/*.rej
|
||||
rm -f tp_smapi-*-for-*.patch
|
||||
rm -f tp_smapi-*-for-*.patch
|
||||
rm -fr .tmp_versions Modules.symvers diff/hdaps.diff.tmp
|
||||
rm -f dmi_ec_oem_string.h
|
||||
@if [ -f hdaps.c -a hdaps.c.flag -ot hdaps.c ]; then \
|
||||
echo 'WARNING: hdaps.c has changed since autogeneration, will not delete.'; \
|
||||
else \
|
||||
rm -f hdaps.c hdaps.c.flag; \
|
||||
fi
|
||||
|
||||
load: check_hdaps unload modules
|
||||
@( [ `id -u` == 0 ] || { echo "Must be root to load modules"; exit 1; } )
|
||||
{ insmod ./tp_base.ko debug=$(DEBUG) &&\
|
||||
insmod ./tp_smapi.ko debug=$(DEBUG) &&\
|
||||
$(LOAD_HDAPS); }; :
|
||||
@echo -e '\nRecent dmesg output:' ; dmesg | tail -9
|
||||
@echo -e '\nRecent dmesg output:' ; dmesg | tail -10
|
||||
|
||||
unload:
|
||||
@( [ `id -u` == 0 ] || { echo "Must be root to unload modules"; exit 1; } )
|
||||
@ -79,16 +74,6 @@ endif
|
||||
$(MAKE) -C $(KSRC) M=$(PWD) modules_install
|
||||
depmod -a
|
||||
|
||||
# Match hdaps.c from kernel tree into local copy.
|
||||
# (First do a small change in our own patch if kernel != 2.6.17.x)
|
||||
hdaps.c: $(KSRC)/drivers/hwmon/hdaps.c diff/hdaps.diff
|
||||
cat $(PWD)/diff/hdaps.diff \
|
||||
| if ! grep -q 'ret = -ENODEV' $(KSRC)/drivers/hwmon/hdaps.c; then \
|
||||
perl -0777 -pe 's/(laptop not found.*\n.*)ENODEV/$$1ENXIO/'; else cat; fi \
|
||||
| if grep -q 'Celsius' $(KSRC)/drivers/hwmon/hdaps.c; then \
|
||||
perl -0777 -pe 's/ celcius / Celsius /'; else cat; fi \
|
||||
| patch -d $(KSRC) -p1 -o $(PWD)/hdaps.c || { rm -v hdaps.c; exit 1; }
|
||||
@touch -r hdaps.c hdaps.c.flag
|
||||
|
||||
# Ugly kludge for kernels that can't report OEM Strings DMI information:
|
||||
ifeq ($(shell grep -q DMI_DEV_TYPE_OEM_STRING $(KSRC)/include/linux/dmi.h || echo 1),1)
|
||||
@ -97,13 +82,13 @@ $(error Could not run /usr/sbin/dmidecode. Must be root or get sudo password to
|
||||
endif
|
||||
GEN_DMI_DECODE_PATCH= \
|
||||
cat $(PWD)/diff/dmi-decode-and-save-oem-string-information.patch | \
|
||||
{ [ -f $(KSRC)/drivers/firmware/dmi_scan.c ] || \
|
||||
{ [ -f $(KSRC)/drivers/firmware/dmi_scan.c ] && cat || \
|
||||
perl -pe 's@drivers/firmware/dmi_scan.c@arch/i386/kernel/dmi_scan.c@g'; }
|
||||
DMI_EC_OEM_STRING:=$(shell sudo /usr/sbin/dmidecode | grep 'IBM ThinkPad Embedded Controller')
|
||||
dmi_ec_oem_string.h: $(KSRC)/include/linux/dmi.h
|
||||
@echo 'WARNING: Your kernel does not have this patch applied:' >&2
|
||||
@echo 'dmi-decode-and-save-oem-string-information.patch' >&2
|
||||
@echo 'So I am hard-coding machine-specific DMI information into your driver.' >&2
|
||||
@echo ' dmi-decode-and-save-oem-string-information.patch' >&2
|
||||
@echo ' So I am hard-coding machine-specific DMI information into your driver.' >&2
|
||||
echo '/* This is machine-specific DMI information. */' > $@
|
||||
echo '#define DMI_EC_OEM_STRING_KLUDGE "$(DMI_EC_OEM_STRING)"' >> $@
|
||||
else
|
||||
@ -124,7 +109,7 @@ PATCH := tp_smapi-$(TP_VER)-for-$(KVER).patch
|
||||
BASE_IN_PATCH := 1
|
||||
SMAPI_IN_PATCH := 1
|
||||
|
||||
patch: hdaps.c
|
||||
patch:
|
||||
TMPDIR=`mktemp -d /tmp/tp_smapi-patch.XXXXXX` &&\
|
||||
echo "Work directory: $$TMPDIR" &&\
|
||||
cd $$TMPDIR &&\
|
||||
@ -165,10 +150,6 @@ patch: hdaps.c
|
||||
#####################################################################
|
||||
# Tools for preparing a release. Ignore these.
|
||||
|
||||
mk-hdaps.diff: diff/hdaps.diff $(KSRC)/drivers/hwmon/hdaps.c
|
||||
{ head -2 diff/hdaps.diff; diff -up -U3 $(KSRC)/drivers/hwmon/hdaps.c hdaps.c | tail -n +3; } > diff/hdaps.diff.tmp || :
|
||||
mv diff/hdaps.diff.tmp diff/hdaps.diff
|
||||
|
||||
set-version:
|
||||
perl -i -pe 's/^(tp_smapi version ).*/$${1}$(VER)/' README
|
||||
perl -i -pe 's/^(#define TP_VERSION ").*/$${1}$(VER)"/' tp_base.c tp_smapi.c
|
||||
|
10
README
10
README
@ -1,4 +1,4 @@
|
||||
tp_smapi version 0.25
|
||||
tp_smapi version 0.26
|
||||
IBM ThinkPad hardware functions driver
|
||||
|
||||
Author: Shem Multinymous <multinymous@gmail.com>
|
||||
@ -67,7 +67,7 @@ tp_base module:
|
||||
tp_smapi module:
|
||||
debug=1 enables verbose dmesg output.
|
||||
|
||||
hdaps module (patched):
|
||||
hdaps module (modified version of driver from mainline kernel):
|
||||
force=1 forces loading on ThinkPad models that are not whitelisted.
|
||||
|
||||
|
||||
@ -237,9 +237,9 @@ tp_smapi.c
|
||||
tp_base.*
|
||||
tp_base driver module (coordinates hardware access between tp_smapi and
|
||||
hdaps)
|
||||
diff/hdaps.diff
|
||||
Patch to make the hdaps driver use tp_base, plus several fixes to vanilla
|
||||
hdaps.c.
|
||||
hdaps.c
|
||||
Modified version of hdaps.c driver from mainline kernel, patched to use
|
||||
tp_base and several other improvements.
|
||||
diff/dmi-decode-and-save-oem-string-information
|
||||
A patch from the kernel -mm series, needed for hardware detection.
|
||||
If you don't have it, "make load" and "make install" will use a workaround
|
||||
|
919
diff/hdaps.diff
919
diff/hdaps.diff
@ -1,919 +0,0 @@
|
||||
--- a/drivers/hwmon/hdaps.c 2006-01-01 00:00:00.000000000 +0000
|
||||
+++ b/drivers/hwmon/hdaps.c 2006-01-01 00:00:00.000000000 +0000
|
||||
@@ -33,256 +33,334 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/timer.h>
|
||||
#include <linux/dmi.h>
|
||||
-#include <asm/io.h>
|
||||
+#include <linux/tp_base.h>
|
||||
+#include <linux/jiffies.h>
|
||||
|
||||
-#define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */
|
||||
-#define HDAPS_NR_PORTS 0x30 /* number of ports: 0x1600 - 0x162f */
|
||||
-
|
||||
-#define HDAPS_PORT_STATE 0x1611 /* device state */
|
||||
-#define HDAPS_PORT_YPOS 0x1612 /* y-axis position */
|
||||
-#define HDAPS_PORT_XPOS 0x1614 /* x-axis position */
|
||||
-#define HDAPS_PORT_TEMP1 0x1616 /* device temperature, in celcius */
|
||||
-#define HDAPS_PORT_YVAR 0x1617 /* y-axis variance (what is this?) */
|
||||
-#define HDAPS_PORT_XVAR 0x1619 /* x-axis variance (what is this?) */
|
||||
-#define HDAPS_PORT_TEMP2 0x161b /* device temperature (again?) */
|
||||
-#define HDAPS_PORT_UNKNOWN 0x161c /* what is this? */
|
||||
-#define HDAPS_PORT_KMACT 0x161d /* keyboard or mouse activity */
|
||||
-
|
||||
-#define STATE_FRESH 0x50 /* accelerometer data is fresh */
|
||||
+/* Embedded controller accelerometer read command and its result: */
|
||||
+static const struct tp_controller_row ec_accel_args =
|
||||
+ { .mask=0x0001, .val={0x11} };
|
||||
+#define EC_ACCEL_IDX_READOUTS 0x1 /* readouts included in this read */
|
||||
+ /* First readout, if READOUTS>=1: */
|
||||
+#define EC_ACCEL_IDX_YPOS1 0x2 /* y-axis position word */
|
||||
+#define EC_ACCEL_IDX_XPOS1 0x4 /* x-axis position word */
|
||||
+#define EC_ACCEL_IDX_TEMP1 0x6 /* device temperature in Celsius */
|
||||
+ /* Second readout, if READOUTS>=2: */
|
||||
+#define EC_ACCEL_IDX_XPOS2 0x7 /* y-axis position word */
|
||||
+#define EC_ACCEL_IDX_YPOS2 0x9 /* x-axis pisition word */
|
||||
+#define EC_ACCEL_IDX_TEMP2 0xb /* device temperature in Celsius */
|
||||
+#define EC_ACCEL_IDX_QUEUED 0xc /* Number of queued readouts left */
|
||||
+#define EC_ACCEL_IDX_KMACT 0xd /* keyboard or mouse activity */
|
||||
+#define EC_ACCEL_IDX_RETVAL 0xf /* command return value, good=0x00 */
|
||||
|
||||
#define KEYBD_MASK 0x20 /* set if keyboard activity */
|
||||
#define MOUSE_MASK 0x40 /* set if mouse activity */
|
||||
-#define KEYBD_ISSET(n) (!! (n & KEYBD_MASK)) /* keyboard used? */
|
||||
-#define MOUSE_ISSET(n) (!! (n & MOUSE_MASK)) /* mouse used? */
|
||||
|
||||
-#define INIT_TIMEOUT_MSECS 4000 /* wait up to 4s for device init ... */
|
||||
-#define INIT_WAIT_MSECS 200 /* ... in 200ms increments */
|
||||
+#define READ_TIMEOUT_MSECS 100 /* wait this long for device read */
|
||||
+#define RETRY_MSECS 3 /* retry delay */
|
||||
|
||||
-#define HDAPS_POLL_PERIOD (HZ/20) /* poll for input every 1/20s */
|
||||
#define HDAPS_INPUT_FUZZ 4 /* input event threshold */
|
||||
#define HDAPS_INPUT_FLAT 4
|
||||
|
||||
+#define KMACT_REMEMBER_PERIOD (HZ/10) /* keyboard/mouse persistance */
|
||||
+
|
||||
static struct timer_list hdaps_timer;
|
||||
static struct platform_device *pdev;
|
||||
static struct input_dev *hdaps_idev;
|
||||
static unsigned int hdaps_invert;
|
||||
-static u8 km_activity;
|
||||
-static int rest_x;
|
||||
-static int rest_y;
|
||||
-
|
||||
-static DECLARE_MUTEX(hdaps_sem);
|
||||
+static unsigned int hdaps_force;
|
||||
+static int needs_calibration = 0;
|
||||
|
||||
-/*
|
||||
- * __get_latch - Get the value from a given port. Callers must hold hdaps_sem.
|
||||
+/* Configuration: */
|
||||
+static int sampling_rate = 50; /* Sampling rate */
|
||||
+static int oversampling_ratio = 5; /* Ratio between our sampling rate and
|
||||
+ * EC accelerometer sampling rate */
|
||||
+static int running_avg_filter_order = 2; /* EC running average filter order */
|
||||
+static int fake_data_mode = 0; /* Enable EC fake data mode? */
|
||||
+
|
||||
+/* Latest state readout: */
|
||||
+static int pos_x, pos_y; /* position */
|
||||
+static int temperature; /* temperature */
|
||||
+static int stale_readout = 1; /* last read failed */
|
||||
+static int rest_x, rest_y; /* calibrated rest position */
|
||||
+
|
||||
+/* Last time we saw keyboard and mouse activity: */
|
||||
+u64 last_keyboard_jiffies = INITIAL_JIFFIES;
|
||||
+u64 last_mouse_jiffies = INITIAL_JIFFIES;
|
||||
+
|
||||
+/* __hdaps_update - read current state and update global state variables.
|
||||
+ * Also prefetches the next read, to reduce udelay busy-waiting.
|
||||
+ * If fast!=0, do one quick attempt without retries.
|
||||
+ * Caller must hold controller lock.
|
||||
*/
|
||||
-static inline u8 __get_latch(u16 port)
|
||||
+static int __hdaps_update(int fast)
|
||||
{
|
||||
- return inb(port) & 0xff;
|
||||
-}
|
||||
+ /* Read data: */
|
||||
+ struct tp_controller_row data;
|
||||
+ int ret;
|
||||
|
||||
-/*
|
||||
- * __check_latch - Check a port latch for a given value. Returns zero if the
|
||||
- * port contains the given value. Callers must hold hdaps_sem.
|
||||
- */
|
||||
-static inline int __check_latch(u16 port, u8 val)
|
||||
-{
|
||||
- if (__get_latch(port) == val)
|
||||
- return 0;
|
||||
- return -EINVAL;
|
||||
+ data.mask = (1 << EC_ACCEL_IDX_READOUTS) | (1 << EC_ACCEL_IDX_KMACT) |
|
||||
+ (3 << EC_ACCEL_IDX_YPOS1) | (3 << EC_ACCEL_IDX_XPOS1) |
|
||||
+ (1 << EC_ACCEL_IDX_TEMP1) | (1 << EC_ACCEL_IDX_RETVAL);
|
||||
+ if (fast)
|
||||
+ ret = tp_controller_try_read_row(&ec_accel_args, &data);
|
||||
+ else
|
||||
+ ret = tp_controller_read_row(&ec_accel_args, &data);
|
||||
+ tp_controller_prefetch_row(&ec_accel_args); /* Prefetch even if error */
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
+ /* Check status: */
|
||||
+ if (data.val[EC_ACCEL_IDX_RETVAL] != 0x00) {
|
||||
+ printk(KERN_WARNING "hdaps: read RETVAL=0x%02x\n",
|
||||
+ data.val[EC_ACCEL_IDX_RETVAL]);
|
||||
+ return -EIO;
|
||||
+ }
|
||||
+
|
||||
+ if (data.val[EC_ACCEL_IDX_READOUTS]<1)
|
||||
+ return -EBUSY; /* no pending readout, try again later */
|
||||
+
|
||||
+ /* Parse position data: */
|
||||
+ pos_x = *(s16*)(data.val+EC_ACCEL_IDX_XPOS1) * (hdaps_invert?-1:1);
|
||||
+ pos_y = *(s16*)(data.val+EC_ACCEL_IDX_YPOS1) * (hdaps_invert?-1:1);
|
||||
+
|
||||
+ /* Keyboard and mouse activity status is cleared as soon as it's read,
|
||||
+ * so applications will eat each other's events. Thus we remember any
|
||||
+ * event for KMACT_REMEMBER_PERIOD jiffies.
|
||||
+ */
|
||||
+ if (data.val[EC_ACCEL_IDX_KMACT] & KEYBD_MASK)
|
||||
+ last_keyboard_jiffies = get_jiffies_64();
|
||||
+ if (data.val[EC_ACCEL_IDX_KMACT] & MOUSE_MASK)
|
||||
+ last_mouse_jiffies = get_jiffies_64();
|
||||
+
|
||||
+ temperature = data.val[EC_ACCEL_IDX_TEMP1];
|
||||
+
|
||||
+ stale_readout = 0;
|
||||
+ if (needs_calibration) {
|
||||
+ rest_x = pos_x;
|
||||
+ rest_y = pos_y;
|
||||
+ needs_calibration = 0;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
- * __wait_latch - Wait up to 100us for a port latch to get a certain value,
|
||||
- * returning zero if the value is obtained. Callers must hold hdaps_sem.
|
||||
+ * hdaps_read_pair - reads the values from a pair of ports, placing the values
|
||||
+ * in the given pointers. Returns zero on success. Can sleep.
|
||||
+ * Retries until timeout if the accelerometer is not in ready status (common).
|
||||
+ * Does internal locking.
|
||||
*/
|
||||
-static int __wait_latch(u16 port, u8 val)
|
||||
+static int hdaps_update(void)
|
||||
{
|
||||
- unsigned int i;
|
||||
+ int total, ret;
|
||||
+ if (!stale_readout) /* already updated recently? */
|
||||
+ return 0;
|
||||
+ for (total=READ_TIMEOUT_MSECS; total>0; total-=RETRY_MSECS) {
|
||||
+ ret = tp_controller_lock();
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ ret = __hdaps_update(0);
|
||||
+ tp_controller_unlock();
|
||||
|
||||
- for (i = 0; i < 20; i++) {
|
||||
- if (!__check_latch(port, val))
|
||||
+ if (!ret)
|
||||
return 0;
|
||||
- udelay(5);
|
||||
+ if (ret != -EBUSY)
|
||||
+ break;
|
||||
+ msleep(RETRY_MSECS);
|
||||
}
|
||||
-
|
||||
- return -EIO;
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
- * __device_refresh - request a refresh from the accelerometer. Does not wait
|
||||
- * for refresh to complete. Callers must hold hdaps_sem.
|
||||
+ * hdaps_set_power - enable or disable power to the accelerometer.
|
||||
+ * Returns zero on success and negative error code on failure. Can sleep.
|
||||
*/
|
||||
-static void __device_refresh(void)
|
||||
-{
|
||||
- udelay(200);
|
||||
- if (inb(0x1604) != STATE_FRESH) {
|
||||
- outb(0x11, 0x1610);
|
||||
- outb(0x01, 0x161f);
|
||||
- }
|
||||
+static int hdaps_set_power(int on) {
|
||||
+ struct tp_controller_row args =
|
||||
+ { .mask=0x0003, .val={0x14, on?0x01:0x00} };
|
||||
+ struct tp_controller_row data = { .mask = 0x8000 };
|
||||
+ int ret = tp_controller_read_row(&args, &data);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ if (data.val[0xF]!=0x00)
|
||||
+ return -EIO;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
- * __device_refresh_sync - request a synchronous refresh from the
|
||||
- * accelerometer. We wait for the refresh to complete. Returns zero if
|
||||
- * successful and nonzero on error. Callers must hold hdaps_sem.
|
||||
+ * hdaps_set_fake_data_mode - enable or disable EC test mode, which fakes
|
||||
+ * accelerometer data using an incrementing counter.
|
||||
+ * Returns zero on success and negative error code on failure. Can sleep.
|
||||
*/
|
||||
-static int __device_refresh_sync(void)
|
||||
-{
|
||||
- __device_refresh();
|
||||
- return __wait_latch(0x1604, STATE_FRESH);
|
||||
+static int hdaps_set_fake_data_mode(int on) {
|
||||
+ struct tp_controller_row args =
|
||||
+ { .mask=0x0007, .val={0x17, 0x83, on?0x01:0x00} };
|
||||
+ struct tp_controller_row data = { .mask = 0x8000 };
|
||||
+ int ret = tp_controller_read_row(&args, &data);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ if (data.val[0xF]!=0x00) {
|
||||
+ printk(KERN_WARNING "failed setting hdaps fake data to %d\n",
|
||||
+ on);
|
||||
+ return -EIO;
|
||||
+ }
|
||||
+ printk(KERN_DEBUG "hdaps fake data mode set to %d\n", on);
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
- * __device_complete - indicate to the accelerometer that we are done reading
|
||||
- * data, and then initiate an async refresh. Callers must hold hdaps_sem.
|
||||
+ * hdaps_set_ec_config - set accelerometer parameters.
|
||||
+ * ec_rate - embedded controller sampling rate
|
||||
+ * ( sampling_rate * oversampling_ratio )
|
||||
+ * order - embedded controller running average filter order
|
||||
+ * Returns zero on success and negative error code on failure. Can sleep.
|
||||
*/
|
||||
-static inline void __device_complete(void)
|
||||
-{
|
||||
- inb(0x161f);
|
||||
- inb(0x1604);
|
||||
- __device_refresh();
|
||||
+static int hdaps_set_ec_config(int ec_rate, int order) {
|
||||
+ struct tp_controller_row args = { .mask=0x000F,
|
||||
+ .val={0x10, (u8)ec_rate, (u8)(ec_rate>>8), order} };
|
||||
+ struct tp_controller_row data = { .mask = 0x8000 };
|
||||
+ int ret = tp_controller_read_row(&args, &data);
|
||||
+ printk(KERN_DEBUG "hdaps: config "
|
||||
+ "sampling_rate*oversampling_ratio=%d, filter_order=%d.\n",
|
||||
+ ec_rate, order);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ if (data.val[0xF]==0x03) {
|
||||
+ printk(KERN_WARNING "hdaps: config param out of range\n");
|
||||
+ return -EINVAL;
|
||||
+ }
|
||||
+ if (data.val[0xF]==0x06) {
|
||||
+ printk(KERN_WARNING "hdaps: config change already pending\n");
|
||||
+ return -EBUSY;
|
||||
+ }
|
||||
+ if (data.val[0xF]!=0x00) {
|
||||
+ printk(KERN_WARNING "hdaps: config change error, ret=%d\n",
|
||||
+ data.val[0xF]);
|
||||
+ return -EIO;
|
||||
+ }
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
- * hdaps_readb_one - reads a byte from a single I/O port, placing the value in
|
||||
- * the given pointer. Returns zero on success or a negative error on failure.
|
||||
- * Can sleep.
|
||||
+ * hdaps_get_ec_config - get accelerometer parameters.
|
||||
+ * ec_rate - embedded controller sampling rate
|
||||
+ * order - embedded controller running average filter order
|
||||
+ * Returns zero on success and negative error code on failure. Can sleep.
|
||||
*/
|
||||
-static int hdaps_readb_one(unsigned int port, u8 *val)
|
||||
-{
|
||||
- int ret;
|
||||
-
|
||||
- down(&hdaps_sem);
|
||||
-
|
||||
- /* do a sync refresh -- we need to be sure that we read fresh data */
|
||||
- ret = __device_refresh_sync();
|
||||
+static int hdaps_get_ec_config(int *ec_rate, int *order) {
|
||||
+ const struct tp_controller_row args =
|
||||
+ { .mask=0x0003, .val={0x17, 0x82} };
|
||||
+ struct tp_controller_row data = { .mask = 0x801F };
|
||||
+ int ret = tp_controller_read_row(&args, &data);
|
||||
if (ret)
|
||||
- goto out;
|
||||
-
|
||||
- *val = inb(port);
|
||||
- __device_complete();
|
||||
-
|
||||
-out:
|
||||
- up(&hdaps_sem);
|
||||
- return ret;
|
||||
+ return ret;
|
||||
+ if (data.val[0xF]!=0x00)
|
||||
+ return -EIO;
|
||||
+ if (!(data.val[0x1] & 0x01))
|
||||
+ return -ENXIO; /* accelerometer polling not enabled */
|
||||
+ if (data.val[0x1] & 0x02)
|
||||
+ return -EBUSY; /* config change in progress, retry later */
|
||||
+ *ec_rate = data.val[0x2] | ((int)(data.val[0x3]) << 8);
|
||||
+ *order = data.val[0x4];
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
-/* __hdaps_read_pair - internal lockless helper for hdaps_read_pair(). */
|
||||
-static int __hdaps_read_pair(unsigned int port1, unsigned int port2,
|
||||
- int *x, int *y)
|
||||
-{
|
||||
- /* do a sync refresh -- we need to be sure that we read fresh data */
|
||||
- if (__device_refresh_sync())
|
||||
+/*
|
||||
+ * hdaps_get_ec_mode - get EC accelerometer mode
|
||||
+ * Returns zero on success and negative error code on failure. Can sleep.
|
||||
+ */
|
||||
+static int hdaps_get_ec_mode(u8 *mode) {
|
||||
+ const struct tp_controller_row args = { .mask=0x0001, .val={0x13} };
|
||||
+ struct tp_controller_row data = { .mask = 0x8002 };
|
||||
+ int ret = tp_controller_read_row(&args, &data);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ if (data.val[0xF]!=0x00) {
|
||||
+ printk(KERN_WARNING
|
||||
+ "accelerometer not implemented (0x%02x)\n",
|
||||
+ data.val[0xF]);
|
||||
return -EIO;
|
||||
-
|
||||
- *y = inw(port2);
|
||||
- *x = inw(port1);
|
||||
- km_activity = inb(HDAPS_PORT_KMACT);
|
||||
- __device_complete();
|
||||
-
|
||||
- /* if hdaps_invert is set, negate the two values */
|
||||
- if (hdaps_invert) {
|
||||
- *x = -*x;
|
||||
- *y = -*y;
|
||||
}
|
||||
-
|
||||
+ *mode = data.val[0x1];
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
- * hdaps_read_pair - reads the values from a pair of ports, placing the values
|
||||
- * in the given pointers. Returns zero on success. Can sleep.
|
||||
+ * hdaps_check_ec - checks something about the EC.
|
||||
+ * Follows the clean-room spec for HDAPS; we don't know what it means.
|
||||
+ * Returns zero on success and negative error code on failure. Can sleep.
|
||||
*/
|
||||
-static int hdaps_read_pair(unsigned int port1, unsigned int port2,
|
||||
- int *val1, int *val2)
|
||||
-{
|
||||
- int ret;
|
||||
-
|
||||
- down(&hdaps_sem);
|
||||
- ret = __hdaps_read_pair(port1, port2, val1, val2);
|
||||
- up(&hdaps_sem);
|
||||
-
|
||||
- return ret;
|
||||
+static int __init hdaps_check_ec(u8 *mode) {
|
||||
+ const struct tp_controller_row args =
|
||||
+ { .mask=0x0003, .val={0x17, 0x81} };
|
||||
+ struct tp_controller_row data = { .mask = 0x800E };
|
||||
+ int ret = tp_controller_read_row(&args, &data);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ if (data.val[0x1]!=0x00 || data.val[0x2]!=0x60 ||
|
||||
+ data.val[0x3]!=0x00 || data.val[0xF]!=0x00)
|
||||
+ return -EIO;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* hdaps_device_init - initialize the accelerometer. Returns zero on success
|
||||
* and negative error code on failure. Can sleep.
|
||||
*/
|
||||
+#define ABORT_INIT(msg) { printk(KERN_ERR "hdaps init: %s\n", msg); goto bad; }
|
||||
static int hdaps_device_init(void)
|
||||
{
|
||||
- int total, ret = -ENXIO;
|
||||
+ int ret;
|
||||
+ u8 mode;
|
||||
|
||||
- down(&hdaps_sem);
|
||||
+ ret = tp_controller_lock();
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
|
||||
- outb(0x13, 0x1610);
|
||||
- outb(0x01, 0x161f);
|
||||
- if (__wait_latch(0x161f, 0x00))
|
||||
- goto out;
|
||||
+ if (hdaps_get_ec_mode(&mode))
|
||||
+ ABORT_INIT("hdaps_get_ec_mode failed");
|
||||
+ printk(KERN_DEBUG "hdaps: initial mode latch is 0x%02x.\n", mode);
|
||||
+ if (mode==0x00)
|
||||
+ ABORT_INIT("accelerometer not available");
|
||||
+
|
||||
+ if (hdaps_check_ec(&mode))
|
||||
+ ABORT_INIT("hdaps_check_ec failed");
|
||||
+
|
||||
+ if (hdaps_set_power(1))
|
||||
+ ABORT_INIT("hdaps_set_power failed");
|
||||
+
|
||||
+ if (hdaps_set_ec_config(sampling_rate*oversampling_ratio,
|
||||
+ running_avg_filter_order))
|
||||
+ ABORT_INIT("hdaps_set_ec_config failed");
|
||||
|
||||
- /*
|
||||
- * Most ThinkPads return 0x01.
|
||||
- *
|
||||
- * Others--namely the R50p, T41p, and T42p--return 0x03. These laptops
|
||||
- * have "inverted" axises.
|
||||
- *
|
||||
- * The 0x02 value occurs when the chip has been previously initialized.
|
||||
- */
|
||||
- if (__check_latch(0x1611, 0x03) &&
|
||||
- __check_latch(0x1611, 0x02) &&
|
||||
- __check_latch(0x1611, 0x01))
|
||||
- goto out;
|
||||
-
|
||||
- printk(KERN_DEBUG "hdaps: initial latch check good (0x%02x).\n",
|
||||
- __get_latch(0x1611));
|
||||
+ if (hdaps_set_fake_data_mode(fake_data_mode))
|
||||
+ ABORT_INIT("hdaps_set_fake_data_mode failed");
|
||||
|
||||
- outb(0x17, 0x1610);
|
||||
- outb(0x81, 0x1611);
|
||||
- outb(0x01, 0x161f);
|
||||
- if (__wait_latch(0x161f, 0x00))
|
||||
- goto out;
|
||||
- if (__wait_latch(0x1611, 0x00))
|
||||
- goto out;
|
||||
- if (__wait_latch(0x1612, 0x60))
|
||||
- goto out;
|
||||
- if (__wait_latch(0x1613, 0x00))
|
||||
- goto out;
|
||||
- outb(0x14, 0x1610);
|
||||
- outb(0x01, 0x1611);
|
||||
- outb(0x01, 0x161f);
|
||||
- if (__wait_latch(0x161f, 0x00))
|
||||
- goto out;
|
||||
- outb(0x10, 0x1610);
|
||||
- outb(0xc8, 0x1611);
|
||||
- outb(0x00, 0x1612);
|
||||
- outb(0x02, 0x1613);
|
||||
- outb(0x01, 0x161f);
|
||||
- if (__wait_latch(0x161f, 0x00))
|
||||
- goto out;
|
||||
- if (__device_refresh_sync())
|
||||
- goto out;
|
||||
- if (__wait_latch(0x1611, 0x00))
|
||||
- goto out;
|
||||
-
|
||||
- /* we have done our dance, now let's wait for the applause */
|
||||
- for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) {
|
||||
- int x, y;
|
||||
-
|
||||
- /* a read of the device helps push it into action */
|
||||
- __hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y);
|
||||
- if (!__wait_latch(0x1611, 0x02)) {
|
||||
- ret = 0;
|
||||
- break;
|
||||
- }
|
||||
-
|
||||
- msleep(INIT_WAIT_MSECS);
|
||||
- }
|
||||
+ tp_controller_invalidate();
|
||||
+ udelay(200);
|
||||
|
||||
-out:
|
||||
- up(&hdaps_sem);
|
||||
+ /* Just prefetch instead of reading, to avoid ~1sec delay on load */
|
||||
+ ret = tp_controller_prefetch_row(&ec_accel_args);
|
||||
+ if (ret)
|
||||
+ ABORT_INIT("initial prefetch failed");
|
||||
+ goto good;
|
||||
+bad:
|
||||
+ ret = -ENXIO;
|
||||
+good:
|
||||
+ tp_controller_invalidate();
|
||||
+ tp_controller_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
+/*
|
||||
+ * hdaps_device_shutdown - power off the accelerometer. Can sleep.
|
||||
+ */
|
||||
+static void hdaps_device_shutdown(void) {
|
||||
+ if (hdaps_set_power(0))
|
||||
+ printk(KERN_WARNING "hdaps: cannot power off\n");
|
||||
+ if (hdaps_set_ec_config(0, 1))
|
||||
+ printk(KERN_WARNING "hdaps: cannot stop EC sampling\n");
|
||||
+}
|
||||
|
||||
/* Device model stuff */
|
||||
|
||||
@@ -298,13 +376,26 @@ static int hdaps_probe(struct platform_d
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static int hdaps_suspend(struct platform_device *dev, pm_message_t state)
|
||||
+{
|
||||
+ /* Don't do mouse polls until resume re-initializes the sensor. */
|
||||
+ del_timer_sync(&hdaps_timer);
|
||||
+ hdaps_device_shutdown();
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
static int hdaps_resume(struct platform_device *dev)
|
||||
{
|
||||
- return hdaps_device_init();
|
||||
+ int ret = hdaps_device_init();
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ mod_timer(&hdaps_timer, jiffies + HZ/sampling_rate);
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver hdaps_driver = {
|
||||
.probe = hdaps_probe,
|
||||
+ .suspend = hdaps_suspend,
|
||||
.resume = hdaps_resume,
|
||||
.driver = {
|
||||
.name = "hdaps",
|
||||
@@ -313,34 +404,44 @@ static struct platform_driver hdaps_driv
|
||||
};
|
||||
|
||||
/*
|
||||
- * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_sem.
|
||||
+ * hdaps_calibrate - Set our "resting" values.
|
||||
+ * Does its own locking.
|
||||
*/
|
||||
static void hdaps_calibrate(void)
|
||||
{
|
||||
- __hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &rest_x, &rest_y);
|
||||
+ needs_calibration = 1;
|
||||
+ hdaps_update();
|
||||
+ /* If that fails, the mousedev poll will take care of things later. */
|
||||
}
|
||||
|
||||
+/* Timer handler for updating the input device. Runs in softirq context,
|
||||
+ * so avoid lenghty or blocking operations.
|
||||
+ */
|
||||
static void hdaps_mousedev_poll(unsigned long unused)
|
||||
{
|
||||
- int x, y;
|
||||
+ int ret;
|
||||
+
|
||||
+ stale_readout = 1;
|
||||
|
||||
/* Cannot sleep. Try nonblockingly. If we fail, try again later. */
|
||||
- if (down_trylock(&hdaps_sem)) {
|
||||
- mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD);
|
||||
+ if (tp_controller_try_lock())
|
||||
+ goto keep_active;
|
||||
+
|
||||
+ ret = __hdaps_update(1); /* fast update, we're in softirq context */
|
||||
+ tp_controller_unlock();
|
||||
+ /* Any of "successful", "not yet ready" and "not prefetched"? */
|
||||
+ if (ret!=0 && ret!=-EBUSY && ret!=-ENODATA) {
|
||||
+ printk(KERN_ERR
|
||||
+ "hdaps: poll failed, disabling update timer\n");
|
||||
return;
|
||||
}
|
||||
|
||||
- if (__hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y))
|
||||
- goto out;
|
||||
-
|
||||
- input_report_abs(hdaps_idev, ABS_X, x - rest_x);
|
||||
- input_report_abs(hdaps_idev, ABS_Y, y - rest_y);
|
||||
+keep_active:
|
||||
+ /* Even if we failed now, pos_x,y may have been updated earlier: */
|
||||
+ input_report_abs(hdaps_idev, ABS_X, pos_x - rest_x);
|
||||
+ input_report_abs(hdaps_idev, ABS_Y, pos_y - rest_y);
|
||||
input_sync(hdaps_idev);
|
||||
-
|
||||
- mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD);
|
||||
-
|
||||
-out:
|
||||
- up(&hdaps_sem);
|
||||
+ mod_timer(&hdaps_timer, jiffies + HZ/sampling_rate);
|
||||
}
|
||||
|
||||
|
||||
@@ -349,65 +450,41 @@ out:
|
||||
static ssize_t hdaps_position_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
- int ret, x, y;
|
||||
-
|
||||
- ret = hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y);
|
||||
+ int ret = hdaps_update();
|
||||
if (ret)
|
||||
return ret;
|
||||
-
|
||||
- return sprintf(buf, "(%d,%d)\n", x, y);
|
||||
+ return sprintf(buf, "(%d,%d)\n", pos_x, pos_y);
|
||||
}
|
||||
|
||||
-static ssize_t hdaps_variance_show(struct device *dev,
|
||||
- struct device_attribute *attr, char *buf)
|
||||
-{
|
||||
- int ret, x, y;
|
||||
-
|
||||
- ret = hdaps_read_pair(HDAPS_PORT_XVAR, HDAPS_PORT_YVAR, &x, &y);
|
||||
- if (ret)
|
||||
- return ret;
|
||||
-
|
||||
- return sprintf(buf, "(%d,%d)\n", x, y);
|
||||
-}
|
||||
-
|
||||
-static ssize_t hdaps_temp1_show(struct device *dev,
|
||||
+static ssize_t hdaps_temperature_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
- u8 temp;
|
||||
- int ret;
|
||||
-
|
||||
- ret = hdaps_readb_one(HDAPS_PORT_TEMP1, &temp);
|
||||
- if (ret < 0)
|
||||
- return ret;
|
||||
-
|
||||
- return sprintf(buf, "%u\n", temp);
|
||||
-}
|
||||
-
|
||||
-static ssize_t hdaps_temp2_show(struct device *dev,
|
||||
- struct device_attribute *attr, char *buf)
|
||||
-{
|
||||
- u8 temp;
|
||||
- int ret;
|
||||
-
|
||||
- ret = hdaps_readb_one(HDAPS_PORT_TEMP2, &temp);
|
||||
- if (ret < 0)
|
||||
+ int ret = hdaps_update();
|
||||
+ if (ret)
|
||||
return ret;
|
||||
-
|
||||
- return sprintf(buf, "%u\n", temp);
|
||||
+ return sprintf(buf, "%d\n", temperature);
|
||||
}
|
||||
|
||||
static ssize_t hdaps_keyboard_activity_show(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
- return sprintf(buf, "%u\n", KEYBD_ISSET(km_activity));
|
||||
+ int ret = hdaps_update();
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ return sprintf(buf, "%u\n",
|
||||
+ get_jiffies_64() < last_keyboard_jiffies + KMACT_REMEMBER_PERIOD);
|
||||
}
|
||||
|
||||
static ssize_t hdaps_mouse_activity_show(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
- return sprintf(buf, "%u\n", MOUSE_ISSET(km_activity));
|
||||
+ int ret = hdaps_update();
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ return sprintf(buf, "%u\n",
|
||||
+ get_jiffies_64() < last_mouse_jiffies + KMACT_REMEMBER_PERIOD);
|
||||
}
|
||||
|
||||
static ssize_t hdaps_calibrate_show(struct device *dev,
|
||||
@@ -420,10 +497,7 @@ static ssize_t hdaps_calibrate_store(str
|
||||
struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
- down(&hdaps_sem);
|
||||
hdaps_calibrate();
|
||||
- up(&hdaps_sem);
|
||||
-
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -448,24 +522,131 @@ static ssize_t hdaps_invert_store(struct
|
||||
return count;
|
||||
}
|
||||
|
||||
+static ssize_t hdaps_sampling_rate_show(
|
||||
+ struct device *dev, struct device_attribute *attr, char *buf)
|
||||
+{
|
||||
+ return sprintf(buf, "%d\n", sampling_rate);
|
||||
+}
|
||||
+
|
||||
+static ssize_t hdaps_sampling_rate_store(
|
||||
+ struct device *dev, struct device_attribute *attr,
|
||||
+ const char *buf, size_t count)
|
||||
+{
|
||||
+ int rate, ret;
|
||||
+ if (sscanf(buf, "%d", &rate) != 1 || rate>HZ || rate<0) {
|
||||
+ printk(KERN_WARNING
|
||||
+ "must have 0<input_sampling_rate<=HZ=%d\n", HZ);
|
||||
+ return -EINVAL;
|
||||
+ }
|
||||
+ ret = hdaps_set_ec_config(rate*oversampling_ratio,
|
||||
+ running_avg_filter_order);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ sampling_rate = rate;
|
||||
+ return count;
|
||||
+}
|
||||
+
|
||||
+static ssize_t hdaps_oversampling_ratio_show(
|
||||
+ struct device *dev, struct device_attribute *attr, char *buf)
|
||||
+{
|
||||
+ int ec_rate, order;
|
||||
+ int ret = hdaps_get_ec_config(&ec_rate, &order);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ return sprintf(buf, "%u\n", ec_rate / sampling_rate);
|
||||
+}
|
||||
+
|
||||
+static ssize_t hdaps_oversampling_ratio_store(
|
||||
+ struct device *dev, struct device_attribute *attr,
|
||||
+ const char *buf, size_t count)
|
||||
+{
|
||||
+ int ratio, ret;
|
||||
+ if (sscanf(buf, "%d", &ratio) != 1 || ratio<1)
|
||||
+ return -EINVAL;
|
||||
+ ret = hdaps_set_ec_config(sampling_rate*ratio,
|
||||
+ running_avg_filter_order);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ oversampling_ratio = ratio;
|
||||
+ return count;
|
||||
+}
|
||||
+
|
||||
+static ssize_t hdaps_running_avg_filter_order_show(
|
||||
+ struct device *dev, struct device_attribute *attr, char *buf)
|
||||
+{
|
||||
+ int rate, order;
|
||||
+ int ret = hdaps_get_ec_config(&rate, &order);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ return sprintf(buf, "%u\n", order);
|
||||
+}
|
||||
+
|
||||
+static ssize_t hdaps_running_avg_filter_order_store(
|
||||
+ struct device *dev, struct device_attribute *attr,
|
||||
+ const char *buf, size_t count)
|
||||
+{
|
||||
+ int order, ret;
|
||||
+ if (sscanf(buf, "%d", &order) != 1)
|
||||
+ return -EINVAL;
|
||||
+ ret = hdaps_set_ec_config(sampling_rate*oversampling_ratio, order);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ running_avg_filter_order = order;
|
||||
+ return count;
|
||||
+}
|
||||
+
|
||||
+static ssize_t hdaps_fake_data_mode_store(struct device *dev,
|
||||
+ struct device_attribute *attr,
|
||||
+ const char *buf, size_t count)
|
||||
+{
|
||||
+ int on, ret;
|
||||
+ if (sscanf(buf, "%d", &on) != 1 || on<0 || on>1) {
|
||||
+ printk(KERN_WARNING
|
||||
+ "fake_data should be 0 or 1\n");
|
||||
+ return -EINVAL;
|
||||
+ }
|
||||
+ ret = hdaps_set_fake_data_mode(on);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ fake_data_mode = on;
|
||||
+ return count;
|
||||
+}
|
||||
+
|
||||
+static ssize_t hdaps_fake_data_mode_show(
|
||||
+ struct device *dev, struct device_attribute *attr, char *buf)
|
||||
+{
|
||||
+ return sprintf(buf, "%d\n", fake_data_mode);
|
||||
+}
|
||||
+
|
||||
static DEVICE_ATTR(position, 0444, hdaps_position_show, NULL);
|
||||
-static DEVICE_ATTR(variance, 0444, hdaps_variance_show, NULL);
|
||||
-static DEVICE_ATTR(temp1, 0444, hdaps_temp1_show, NULL);
|
||||
-static DEVICE_ATTR(temp2, 0444, hdaps_temp2_show, NULL);
|
||||
+static DEVICE_ATTR(temp1, 0444, hdaps_temperature_show, NULL);
|
||||
+ /* named temp1 instead of temperature for backward compatibility */
|
||||
static DEVICE_ATTR(keyboard_activity, 0444, hdaps_keyboard_activity_show, NULL);
|
||||
static DEVICE_ATTR(mouse_activity, 0444, hdaps_mouse_activity_show, NULL);
|
||||
static DEVICE_ATTR(calibrate, 0644, hdaps_calibrate_show,hdaps_calibrate_store);
|
||||
static DEVICE_ATTR(invert, 0644, hdaps_invert_show, hdaps_invert_store);
|
||||
+static DEVICE_ATTR(sampling_rate, 0644,
|
||||
+ hdaps_sampling_rate_show, hdaps_sampling_rate_store);
|
||||
+static DEVICE_ATTR(oversampling_ratio, 0644,
|
||||
+ hdaps_oversampling_ratio_show,
|
||||
+ hdaps_oversampling_ratio_store);
|
||||
+static DEVICE_ATTR(running_avg_filter_order, 0644,
|
||||
+ hdaps_running_avg_filter_order_show,
|
||||
+ hdaps_running_avg_filter_order_store);
|
||||
+static DEVICE_ATTR(fake_data_mode, 0644,
|
||||
+ hdaps_fake_data_mode_show, hdaps_fake_data_mode_store);
|
||||
|
||||
static struct attribute *hdaps_attributes[] = {
|
||||
&dev_attr_position.attr,
|
||||
- &dev_attr_variance.attr,
|
||||
&dev_attr_temp1.attr,
|
||||
- &dev_attr_temp2.attr,
|
||||
&dev_attr_keyboard_activity.attr,
|
||||
&dev_attr_mouse_activity.attr,
|
||||
&dev_attr_calibrate.attr,
|
||||
&dev_attr_invert.attr,
|
||||
+ &dev_attr_sampling_rate.attr,
|
||||
+ &dev_attr_oversampling_ratio.attr,
|
||||
+ &dev_attr_running_avg_filter_order.attr,
|
||||
+ &dev_attr_fake_data_mode.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
@@ -542,20 +723,18 @@ static int __init hdaps_init(void)
|
||||
{ .ident = NULL }
|
||||
};
|
||||
|
||||
- if (!dmi_check_system(hdaps_whitelist)) {
|
||||
+ if (!(dmi_check_system(hdaps_whitelist) || hdaps_force)) {
|
||||
printk(KERN_WARNING "hdaps: supported laptop not found!\n");
|
||||
ret = -ENODEV;
|
||||
goto out;
|
||||
}
|
||||
|
||||
- if (!request_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS, "hdaps")) {
|
||||
- ret = -ENXIO;
|
||||
- goto out;
|
||||
- }
|
||||
-
|
||||
+ /* Init timer before platform_driver_register, in case of suspend */
|
||||
+ init_timer(&hdaps_timer);
|
||||
+ hdaps_timer.function = hdaps_mousedev_poll;
|
||||
ret = platform_driver_register(&hdaps_driver);
|
||||
if (ret)
|
||||
- goto out_region;
|
||||
+ goto out;
|
||||
|
||||
pdev = platform_device_register_simple("hdaps", -1, NULL, 0);
|
||||
if (IS_ERR(pdev)) {
|
||||
@@ -573,8 +752,8 @@ static int __init hdaps_init(void)
|
||||
goto out_group;
|
||||
}
|
||||
|
||||
- /* initial calibrate for the input device */
|
||||
- hdaps_calibrate();
|
||||
+ /* calibration for the input device (deferred to avoid delay) */
|
||||
+ needs_calibration = 1;
|
||||
|
||||
/* initialize the input class */
|
||||
hdaps_idev->name = "hdaps";
|
||||
@@ -587,11 +766,7 @@ static int __init hdaps_init(void)
|
||||
|
||||
input_register_device(hdaps_idev);
|
||||
|
||||
- /* start up our timer for the input device */
|
||||
- init_timer(&hdaps_timer);
|
||||
- hdaps_timer.function = hdaps_mousedev_poll;
|
||||
- hdaps_timer.expires = jiffies + HDAPS_POLL_PERIOD;
|
||||
- add_timer(&hdaps_timer);
|
||||
+ mod_timer(&hdaps_timer, jiffies + HZ/sampling_rate);
|
||||
|
||||
printk(KERN_INFO "hdaps: driver successfully loaded.\n");
|
||||
return 0;
|
||||
@@ -602,8 +777,6 @@ out_device:
|
||||
platform_device_unregister(pdev);
|
||||
out_driver:
|
||||
platform_driver_unregister(&hdaps_driver);
|
||||
-out_region:
|
||||
- release_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS);
|
||||
out:
|
||||
printk(KERN_WARNING "hdaps: driver init failed (ret=%d)!\n", ret);
|
||||
return ret;
|
||||
@@ -613,10 +786,10 @@ static void __exit hdaps_exit(void)
|
||||
{
|
||||
del_timer_sync(&hdaps_timer);
|
||||
input_unregister_device(hdaps_idev);
|
||||
+ hdaps_device_shutdown();
|
||||
sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
|
||||
platform_device_unregister(pdev);
|
||||
platform_driver_unregister(&hdaps_driver);
|
||||
- release_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS);
|
||||
|
||||
printk(KERN_INFO "hdaps: driver unloaded.\n");
|
||||
}
|
||||
@@ -627,6 +800,9 @@ module_exit(hdaps_exit);
|
||||
module_param_named(invert, hdaps_invert, bool, 0);
|
||||
MODULE_PARM_DESC(invert, "invert data along each axis");
|
||||
|
||||
+module_param_named(force, hdaps_force, bool, 0);
|
||||
+MODULE_PARM_DESC(force, "force loading on non whitelisted laptops");
|
||||
+
|
||||
MODULE_AUTHOR("Robert Love");
|
||||
MODULE_DESCRIPTION("IBM Hard Drive Active Protection System (HDAPS) driver");
|
||||
MODULE_LICENSE("GPL v2");
|
809
hdaps.c
Normal file
809
hdaps.c
Normal file
@ -0,0 +1,809 @@
|
||||
/*
|
||||
* drivers/hwmon/hdaps.c - driver for IBM's Hard Drive Active Protection System
|
||||
*
|
||||
* Copyright (C) 2005 Robert Love <rml@novell.com>
|
||||
* Copyright (C) 2005 Jesper Juhl <jesper.juhl@gmail.com>
|
||||
*
|
||||
* The HardDisk Active Protection System (hdaps) is present in IBM ThinkPads
|
||||
* starting with the R40, T41, and X40. It provides a basic two-axis
|
||||
* accelerometer and other data, such as the device's temperature.
|
||||
*
|
||||
* This driver is based on the document by Mark A. Smith available at
|
||||
* http://www.almaden.ibm.com/cs/people/marksmith/tpaps.html and a lot of trial
|
||||
* and error.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License v2 as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <linux/delay.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/timer.h>
|
||||
#include <linux/dmi.h>
|
||||
#include <linux/tp_base.h>
|
||||
#include <linux/jiffies.h>
|
||||
|
||||
/* Embedded controller accelerometer read command and its result: */
|
||||
static const struct tp_controller_row ec_accel_args =
|
||||
{ .mask=0x0001, .val={0x11} };
|
||||
#define EC_ACCEL_IDX_READOUTS 0x1 /* readouts included in this read */
|
||||
/* First readout, if READOUTS>=1: */
|
||||
#define EC_ACCEL_IDX_YPOS1 0x2 /* y-axis position word */
|
||||
#define EC_ACCEL_IDX_XPOS1 0x4 /* x-axis position word */
|
||||
#define EC_ACCEL_IDX_TEMP1 0x6 /* device temperature in Celsius */
|
||||
/* Second readout, if READOUTS>=2: */
|
||||
#define EC_ACCEL_IDX_XPOS2 0x7 /* y-axis position word */
|
||||
#define EC_ACCEL_IDX_YPOS2 0x9 /* x-axis pisition word */
|
||||
#define EC_ACCEL_IDX_TEMP2 0xb /* device temperature in Celsius */
|
||||
#define EC_ACCEL_IDX_QUEUED 0xc /* Number of queued readouts left */
|
||||
#define EC_ACCEL_IDX_KMACT 0xd /* keyboard or mouse activity */
|
||||
#define EC_ACCEL_IDX_RETVAL 0xf /* command return value, good=0x00 */
|
||||
|
||||
#define KEYBD_MASK 0x20 /* set if keyboard activity */
|
||||
#define MOUSE_MASK 0x40 /* set if mouse activity */
|
||||
|
||||
#define READ_TIMEOUT_MSECS 100 /* wait this long for device read */
|
||||
#define RETRY_MSECS 3 /* retry delay */
|
||||
|
||||
#define HDAPS_INPUT_FUZZ 4 /* input event threshold */
|
||||
#define HDAPS_INPUT_FLAT 4
|
||||
|
||||
#define KMACT_REMEMBER_PERIOD (HZ/10) /* keyboard/mouse persistance */
|
||||
|
||||
static struct timer_list hdaps_timer;
|
||||
static struct platform_device *pdev;
|
||||
static struct input_dev *hdaps_idev;
|
||||
static unsigned int hdaps_invert;
|
||||
static unsigned int hdaps_force;
|
||||
static int needs_calibration = 0;
|
||||
|
||||
/* Configuration: */
|
||||
static int sampling_rate = 50; /* Sampling rate */
|
||||
static int oversampling_ratio = 5; /* Ratio between our sampling rate and
|
||||
* EC accelerometer sampling rate */
|
||||
static int running_avg_filter_order = 2; /* EC running average filter order */
|
||||
static int fake_data_mode = 0; /* Enable EC fake data mode? */
|
||||
|
||||
/* Latest state readout: */
|
||||
static int pos_x, pos_y; /* position */
|
||||
static int temperature; /* temperature */
|
||||
static int stale_readout = 1; /* last read failed */
|
||||
static int rest_x, rest_y; /* calibrated rest position */
|
||||
|
||||
/* Last time we saw keyboard and mouse activity: */
|
||||
u64 last_keyboard_jiffies = INITIAL_JIFFIES;
|
||||
u64 last_mouse_jiffies = INITIAL_JIFFIES;
|
||||
|
||||
/* __hdaps_update - read current state and update global state variables.
|
||||
* Also prefetches the next read, to reduce udelay busy-waiting.
|
||||
* If fast!=0, do one quick attempt without retries.
|
||||
* Caller must hold controller lock.
|
||||
*/
|
||||
static int __hdaps_update(int fast)
|
||||
{
|
||||
/* Read data: */
|
||||
struct tp_controller_row data;
|
||||
int ret;
|
||||
|
||||
data.mask = (1 << EC_ACCEL_IDX_READOUTS) | (1 << EC_ACCEL_IDX_KMACT) |
|
||||
(3 << EC_ACCEL_IDX_YPOS1) | (3 << EC_ACCEL_IDX_XPOS1) |
|
||||
(1 << EC_ACCEL_IDX_TEMP1) | (1 << EC_ACCEL_IDX_RETVAL);
|
||||
if (fast)
|
||||
ret = tp_controller_try_read_row(&ec_accel_args, &data);
|
||||
else
|
||||
ret = tp_controller_read_row(&ec_accel_args, &data);
|
||||
tp_controller_prefetch_row(&ec_accel_args); /* Prefetch even if error */
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Check status: */
|
||||
if (data.val[EC_ACCEL_IDX_RETVAL] != 0x00) {
|
||||
printk(KERN_WARNING "hdaps: read RETVAL=0x%02x\n",
|
||||
data.val[EC_ACCEL_IDX_RETVAL]);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (data.val[EC_ACCEL_IDX_READOUTS]<1)
|
||||
return -EBUSY; /* no pending readout, try again later */
|
||||
|
||||
/* Parse position data: */
|
||||
pos_x = *(s16*)(data.val+EC_ACCEL_IDX_XPOS1) * (hdaps_invert?-1:1);
|
||||
pos_y = *(s16*)(data.val+EC_ACCEL_IDX_YPOS1) * (hdaps_invert?-1:1);
|
||||
|
||||
/* Keyboard and mouse activity status is cleared as soon as it's read,
|
||||
* so applications will eat each other's events. Thus we remember any
|
||||
* event for KMACT_REMEMBER_PERIOD jiffies.
|
||||
*/
|
||||
if (data.val[EC_ACCEL_IDX_KMACT] & KEYBD_MASK)
|
||||
last_keyboard_jiffies = get_jiffies_64();
|
||||
if (data.val[EC_ACCEL_IDX_KMACT] & MOUSE_MASK)
|
||||
last_mouse_jiffies = get_jiffies_64();
|
||||
|
||||
temperature = data.val[EC_ACCEL_IDX_TEMP1];
|
||||
|
||||
stale_readout = 0;
|
||||
if (needs_calibration) {
|
||||
rest_x = pos_x;
|
||||
rest_y = pos_y;
|
||||
needs_calibration = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* hdaps_read_pair - reads the values from a pair of ports, placing the values
|
||||
* in the given pointers. Returns zero on success. Can sleep.
|
||||
* Retries until timeout if the accelerometer is not in ready status (common).
|
||||
* Does internal locking.
|
||||
*/
|
||||
static int hdaps_update(void)
|
||||
{
|
||||
int total, ret;
|
||||
if (!stale_readout) /* already updated recently? */
|
||||
return 0;
|
||||
for (total=READ_TIMEOUT_MSECS; total>0; total-=RETRY_MSECS) {
|
||||
ret = tp_controller_lock();
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = __hdaps_update(0);
|
||||
tp_controller_unlock();
|
||||
|
||||
if (!ret)
|
||||
return 0;
|
||||
if (ret != -EBUSY)
|
||||
break;
|
||||
msleep(RETRY_MSECS);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* hdaps_set_power - enable or disable power to the accelerometer.
|
||||
* Returns zero on success and negative error code on failure. Can sleep.
|
||||
*/
|
||||
static int hdaps_set_power(int on) {
|
||||
struct tp_controller_row args =
|
||||
{ .mask=0x0003, .val={0x14, on?0x01:0x00} };
|
||||
struct tp_controller_row data = { .mask = 0x8000 };
|
||||
int ret = tp_controller_read_row(&args, &data);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (data.val[0xF]!=0x00)
|
||||
return -EIO;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* hdaps_set_fake_data_mode - enable or disable EC test mode, which fakes
|
||||
* accelerometer data using an incrementing counter.
|
||||
* Returns zero on success and negative error code on failure. Can sleep.
|
||||
*/
|
||||
static int hdaps_set_fake_data_mode(int on) {
|
||||
struct tp_controller_row args =
|
||||
{ .mask=0x0007, .val={0x17, 0x83, on?0x01:0x00} };
|
||||
struct tp_controller_row data = { .mask = 0x8000 };
|
||||
int ret = tp_controller_read_row(&args, &data);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (data.val[0xF]!=0x00) {
|
||||
printk(KERN_WARNING "failed setting hdaps fake data to %d\n",
|
||||
on);
|
||||
return -EIO;
|
||||
}
|
||||
printk(KERN_DEBUG "hdaps: fake_data_mode set to %d\n", on);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* hdaps_set_ec_config - set accelerometer parameters.
|
||||
* ec_rate - embedded controller sampling rate
|
||||
* ( sampling_rate * oversampling_ratio )
|
||||
* order - embedded controller running average filter order
|
||||
* Returns zero on success and negative error code on failure. Can sleep.
|
||||
*/
|
||||
static int hdaps_set_ec_config(int ec_rate, int order) {
|
||||
struct tp_controller_row args = { .mask=0x000F,
|
||||
.val={0x10, (u8)ec_rate, (u8)(ec_rate>>8), order} };
|
||||
struct tp_controller_row data = { .mask = 0x8000 };
|
||||
int ret = tp_controller_read_row(&args, &data);
|
||||
printk(KERN_DEBUG "hdaps: setting ec_rate=%d, filter_order=%d\n",
|
||||
ec_rate, order);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (data.val[0xF]==0x03) {
|
||||
printk(KERN_WARNING "hdaps: config param out of range\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (data.val[0xF]==0x06) {
|
||||
printk(KERN_WARNING "hdaps: config change already pending\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
if (data.val[0xF]!=0x00) {
|
||||
printk(KERN_WARNING "hdaps: config change error, ret=%d\n",
|
||||
data.val[0xF]);
|
||||
return -EIO;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* hdaps_get_ec_config - get accelerometer parameters.
|
||||
* ec_rate - embedded controller sampling rate
|
||||
* order - embedded controller running average filter order
|
||||
* Returns zero on success and negative error code on failure. Can sleep.
|
||||
*/
|
||||
static int hdaps_get_ec_config(int *ec_rate, int *order) {
|
||||
const struct tp_controller_row args =
|
||||
{ .mask=0x0003, .val={0x17, 0x82} };
|
||||
struct tp_controller_row data = { .mask = 0x801F };
|
||||
int ret = tp_controller_read_row(&args, &data);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (data.val[0xF]!=0x00)
|
||||
return -EIO;
|
||||
if (!(data.val[0x1] & 0x01))
|
||||
return -ENXIO; /* accelerometer polling not enabled */
|
||||
if (data.val[0x1] & 0x02)
|
||||
return -EBUSY; /* config change in progress, retry later */
|
||||
*ec_rate = data.val[0x2] | ((int)(data.val[0x3]) << 8);
|
||||
*order = data.val[0x4];
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* hdaps_get_ec_mode - get EC accelerometer mode
|
||||
* Returns zero on success and negative error code on failure. Can sleep.
|
||||
*/
|
||||
static int hdaps_get_ec_mode(u8 *mode) {
|
||||
const struct tp_controller_row args = { .mask=0x0001, .val={0x13} };
|
||||
struct tp_controller_row data = { .mask = 0x8002 };
|
||||
int ret = tp_controller_read_row(&args, &data);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (data.val[0xF]!=0x00) {
|
||||
printk(KERN_WARNING
|
||||
"accelerometer not implemented (0x%02x)\n",
|
||||
data.val[0xF]);
|
||||
return -EIO;
|
||||
}
|
||||
*mode = data.val[0x1];
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* hdaps_check_ec - checks something about the EC.
|
||||
* Follows the clean-room spec for HDAPS; we don't know what it means.
|
||||
* Returns zero on success and negative error code on failure. Can sleep.
|
||||
*/
|
||||
static int __init hdaps_check_ec(u8 *mode) {
|
||||
const struct tp_controller_row args =
|
||||
{ .mask=0x0003, .val={0x17, 0x81} };
|
||||
struct tp_controller_row data = { .mask = 0x800E };
|
||||
int ret = tp_controller_read_row(&args, &data);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (data.val[0x1]!=0x00 || data.val[0x2]!=0x60 ||
|
||||
data.val[0x3]!=0x00 || data.val[0xF]!=0x00)
|
||||
return -EIO;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* hdaps_device_init - initialize the accelerometer. Returns zero on success
|
||||
* and negative error code on failure. Can sleep.
|
||||
*/
|
||||
#define ABORT_INIT(msg) { printk(KERN_ERR "hdaps init: %s\n", msg); goto bad; }
|
||||
static int hdaps_device_init(void)
|
||||
{
|
||||
int ret;
|
||||
u8 mode;
|
||||
|
||||
ret = tp_controller_lock();
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (hdaps_get_ec_mode(&mode))
|
||||
ABORT_INIT("hdaps_get_ec_mode failed");
|
||||
printk(KERN_DEBUG "hdaps: initial mode latch is 0x%02x\n", mode);
|
||||
if (mode==0x00)
|
||||
ABORT_INIT("accelerometer not available");
|
||||
|
||||
if (hdaps_check_ec(&mode))
|
||||
ABORT_INIT("hdaps_check_ec failed");
|
||||
|
||||
if (hdaps_set_power(1))
|
||||
ABORT_INIT("hdaps_set_power failed");
|
||||
|
||||
if (hdaps_set_ec_config(sampling_rate*oversampling_ratio,
|
||||
running_avg_filter_order))
|
||||
ABORT_INIT("hdaps_set_ec_config failed");
|
||||
|
||||
if (hdaps_set_fake_data_mode(fake_data_mode))
|
||||
ABORT_INIT("hdaps_set_fake_data_mode failed");
|
||||
|
||||
tp_controller_invalidate();
|
||||
udelay(200);
|
||||
|
||||
/* Just prefetch instead of reading, to avoid ~1sec delay on load */
|
||||
ret = tp_controller_prefetch_row(&ec_accel_args);
|
||||
if (ret)
|
||||
ABORT_INIT("initial prefetch failed");
|
||||
goto good;
|
||||
bad:
|
||||
ret = -ENXIO;
|
||||
good:
|
||||
tp_controller_invalidate();
|
||||
tp_controller_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* hdaps_device_shutdown - power off the accelerometer. Can sleep.
|
||||
*/
|
||||
static void hdaps_device_shutdown(void) {
|
||||
if (hdaps_set_power(0))
|
||||
printk(KERN_WARNING "hdaps: cannot power off\n");
|
||||
if (hdaps_set_ec_config(0, 1))
|
||||
printk(KERN_WARNING "hdaps: cannot stop EC sampling\n");
|
||||
}
|
||||
|
||||
/* Device model stuff */
|
||||
|
||||
static int hdaps_probe(struct platform_device *dev)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = hdaps_device_init();
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
printk(KERN_INFO "hdaps: device successfully initialized.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hdaps_suspend(struct platform_device *dev, pm_message_t state)
|
||||
{
|
||||
/* Don't do mouse polls until resume re-initializes the sensor. */
|
||||
del_timer_sync(&hdaps_timer);
|
||||
hdaps_device_shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hdaps_resume(struct platform_device *dev)
|
||||
{
|
||||
int ret = hdaps_device_init();
|
||||
if (ret)
|
||||
return ret;
|
||||
mod_timer(&hdaps_timer, jiffies + HZ/sampling_rate);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver hdaps_driver = {
|
||||
.probe = hdaps_probe,
|
||||
.suspend = hdaps_suspend,
|
||||
.resume = hdaps_resume,
|
||||
.driver = {
|
||||
.name = "hdaps",
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
||||
/*
|
||||
* hdaps_calibrate - Set our "resting" values.
|
||||
* Does its own locking.
|
||||
*/
|
||||
static void hdaps_calibrate(void)
|
||||
{
|
||||
needs_calibration = 1;
|
||||
hdaps_update();
|
||||
/* If that fails, the mousedev poll will take care of things later. */
|
||||
}
|
||||
|
||||
/* Timer handler for updating the input device. Runs in softirq context,
|
||||
* so avoid lenghty or blocking operations.
|
||||
*/
|
||||
static void hdaps_mousedev_poll(unsigned long unused)
|
||||
{
|
||||
int ret;
|
||||
|
||||
stale_readout = 1;
|
||||
|
||||
/* Cannot sleep. Try nonblockingly. If we fail, try again later. */
|
||||
if (tp_controller_try_lock())
|
||||
goto keep_active;
|
||||
|
||||
ret = __hdaps_update(1); /* fast update, we're in softirq context */
|
||||
tp_controller_unlock();
|
||||
/* Any of "successful", "not yet ready" and "not prefetched"? */
|
||||
if (ret!=0 && ret!=-EBUSY && ret!=-ENODATA) {
|
||||
printk(KERN_ERR
|
||||
"hdaps: poll failed, disabling update timer\n");
|
||||
return;
|
||||
}
|
||||
|
||||
keep_active:
|
||||
/* Even if we failed now, pos_x,y may have been updated earlier: */
|
||||
input_report_abs(hdaps_idev, ABS_X, pos_x - rest_x);
|
||||
input_report_abs(hdaps_idev, ABS_Y, pos_y - rest_y);
|
||||
input_sync(hdaps_idev);
|
||||
mod_timer(&hdaps_timer, jiffies + HZ/sampling_rate);
|
||||
}
|
||||
|
||||
|
||||
/* Sysfs Files */
|
||||
|
||||
static ssize_t hdaps_position_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int ret = hdaps_update();
|
||||
if (ret)
|
||||
return ret;
|
||||
return sprintf(buf, "(%d,%d)\n", pos_x, pos_y);
|
||||
}
|
||||
|
||||
static ssize_t hdaps_temperature_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int ret = hdaps_update();
|
||||
if (ret)
|
||||
return ret;
|
||||
return sprintf(buf, "%d\n", temperature);
|
||||
}
|
||||
|
||||
static ssize_t hdaps_keyboard_activity_show(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
int ret = hdaps_update();
|
||||
if (ret)
|
||||
return ret;
|
||||
return sprintf(buf, "%u\n",
|
||||
get_jiffies_64() < last_keyboard_jiffies + KMACT_REMEMBER_PERIOD);
|
||||
}
|
||||
|
||||
static ssize_t hdaps_mouse_activity_show(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
int ret = hdaps_update();
|
||||
if (ret)
|
||||
return ret;
|
||||
return sprintf(buf, "%u\n",
|
||||
get_jiffies_64() < last_mouse_jiffies + KMACT_REMEMBER_PERIOD);
|
||||
}
|
||||
|
||||
static ssize_t hdaps_calibrate_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return sprintf(buf, "(%d,%d)\n", rest_x, rest_y);
|
||||
}
|
||||
|
||||
static ssize_t hdaps_calibrate_store(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
hdaps_calibrate();
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t hdaps_invert_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%u\n", hdaps_invert);
|
||||
}
|
||||
|
||||
static ssize_t hdaps_invert_store(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
int invert;
|
||||
|
||||
if (sscanf(buf, "%d", &invert) != 1 || (invert != 1 && invert != 0))
|
||||
return -EINVAL;
|
||||
|
||||
hdaps_invert = invert;
|
||||
hdaps_calibrate();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t hdaps_sampling_rate_show(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%d\n", sampling_rate);
|
||||
}
|
||||
|
||||
static ssize_t hdaps_sampling_rate_store(
|
||||
struct device *dev, struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
int rate, ret;
|
||||
if (sscanf(buf, "%d", &rate) != 1 || rate>HZ || rate<0) {
|
||||
printk(KERN_WARNING
|
||||
"must have 0<input_sampling_rate<=HZ=%d\n", HZ);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = hdaps_set_ec_config(rate*oversampling_ratio,
|
||||
running_avg_filter_order);
|
||||
if (ret)
|
||||
return ret;
|
||||
sampling_rate = rate;
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t hdaps_oversampling_ratio_show(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int ec_rate, order;
|
||||
int ret = hdaps_get_ec_config(&ec_rate, &order);
|
||||
if (ret)
|
||||
return ret;
|
||||
return sprintf(buf, "%u\n", ec_rate / sampling_rate);
|
||||
}
|
||||
|
||||
static ssize_t hdaps_oversampling_ratio_store(
|
||||
struct device *dev, struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
int ratio, ret;
|
||||
if (sscanf(buf, "%d", &ratio) != 1 || ratio<1)
|
||||
return -EINVAL;
|
||||
ret = hdaps_set_ec_config(sampling_rate*ratio,
|
||||
running_avg_filter_order);
|
||||
if (ret)
|
||||
return ret;
|
||||
oversampling_ratio = ratio;
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t hdaps_running_avg_filter_order_show(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int rate, order;
|
||||
int ret = hdaps_get_ec_config(&rate, &order);
|
||||
if (ret)
|
||||
return ret;
|
||||
return sprintf(buf, "%u\n", order);
|
||||
}
|
||||
|
||||
static ssize_t hdaps_running_avg_filter_order_store(
|
||||
struct device *dev, struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
int order, ret;
|
||||
if (sscanf(buf, "%d", &order) != 1)
|
||||
return -EINVAL;
|
||||
ret = hdaps_set_ec_config(sampling_rate*oversampling_ratio, order);
|
||||
if (ret)
|
||||
return ret;
|
||||
running_avg_filter_order = order;
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t hdaps_fake_data_mode_store(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
int on, ret;
|
||||
if (sscanf(buf, "%d", &on) != 1 || on<0 || on>1) {
|
||||
printk(KERN_WARNING
|
||||
"fake_data should be 0 or 1\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = hdaps_set_fake_data_mode(on);
|
||||
if (ret)
|
||||
return ret;
|
||||
fake_data_mode = on;
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t hdaps_fake_data_mode_show(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%d\n", fake_data_mode);
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(position, 0444, hdaps_position_show, NULL);
|
||||
static DEVICE_ATTR(temp1, 0444, hdaps_temperature_show, NULL);
|
||||
/* named temp1 instead of temperature for backward compatibility */
|
||||
static DEVICE_ATTR(keyboard_activity, 0444, hdaps_keyboard_activity_show, NULL);
|
||||
static DEVICE_ATTR(mouse_activity, 0444, hdaps_mouse_activity_show, NULL);
|
||||
static DEVICE_ATTR(calibrate, 0644, hdaps_calibrate_show,hdaps_calibrate_store);
|
||||
static DEVICE_ATTR(invert, 0644, hdaps_invert_show, hdaps_invert_store);
|
||||
static DEVICE_ATTR(sampling_rate, 0644,
|
||||
hdaps_sampling_rate_show, hdaps_sampling_rate_store);
|
||||
static DEVICE_ATTR(oversampling_ratio, 0644,
|
||||
hdaps_oversampling_ratio_show,
|
||||
hdaps_oversampling_ratio_store);
|
||||
static DEVICE_ATTR(running_avg_filter_order, 0644,
|
||||
hdaps_running_avg_filter_order_show,
|
||||
hdaps_running_avg_filter_order_store);
|
||||
static DEVICE_ATTR(fake_data_mode, 0644,
|
||||
hdaps_fake_data_mode_show, hdaps_fake_data_mode_store);
|
||||
|
||||
static struct attribute *hdaps_attributes[] = {
|
||||
&dev_attr_position.attr,
|
||||
&dev_attr_temp1.attr,
|
||||
&dev_attr_keyboard_activity.attr,
|
||||
&dev_attr_mouse_activity.attr,
|
||||
&dev_attr_calibrate.attr,
|
||||
&dev_attr_invert.attr,
|
||||
&dev_attr_sampling_rate.attr,
|
||||
&dev_attr_oversampling_ratio.attr,
|
||||
&dev_attr_running_avg_filter_order.attr,
|
||||
&dev_attr_fake_data_mode.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static struct attribute_group hdaps_attribute_group = {
|
||||
.attrs = hdaps_attributes,
|
||||
};
|
||||
|
||||
|
||||
/* Module stuff */
|
||||
|
||||
/* hdaps_dmi_match - found a match. return one, short-circuiting the hunt. */
|
||||
static int hdaps_dmi_match(struct dmi_system_id *id)
|
||||
{
|
||||
printk(KERN_INFO "hdaps: %s detected.\n", id->ident);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* hdaps_dmi_match_invert - found an inverted match. */
|
||||
static int hdaps_dmi_match_invert(struct dmi_system_id *id)
|
||||
{
|
||||
hdaps_invert = 1;
|
||||
printk(KERN_INFO "hdaps: inverting axis readings.\n");
|
||||
return hdaps_dmi_match(id);
|
||||
}
|
||||
|
||||
#define HDAPS_DMI_MATCH_NORMAL(model) { \
|
||||
.ident = "IBM " model, \
|
||||
.callback = hdaps_dmi_match, \
|
||||
.matches = { \
|
||||
DMI_MATCH(DMI_BOARD_VENDOR, "IBM"), \
|
||||
DMI_MATCH(DMI_PRODUCT_VERSION, model) \
|
||||
} \
|
||||
}
|
||||
|
||||
#define HDAPS_DMI_MATCH_INVERT(model) { \
|
||||
.ident = "IBM " model, \
|
||||
.callback = hdaps_dmi_match_invert, \
|
||||
.matches = { \
|
||||
DMI_MATCH(DMI_BOARD_VENDOR, "IBM"), \
|
||||
DMI_MATCH(DMI_PRODUCT_VERSION, model) \
|
||||
} \
|
||||
}
|
||||
|
||||
#define HDAPS_DMI_MATCH_LENOVO(model) { \
|
||||
.ident = "Lenovo " model, \
|
||||
.callback = hdaps_dmi_match_invert, \
|
||||
.matches = { \
|
||||
DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), \
|
||||
DMI_MATCH(DMI_PRODUCT_VERSION, model) \
|
||||
} \
|
||||
}
|
||||
|
||||
static int __init hdaps_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Note that HDAPS_DMI_MATCH_NORMAL("ThinkPad T42") would match
|
||||
"ThinkPad T42p", so the order of the entries matters */
|
||||
struct dmi_system_id hdaps_whitelist[] = {
|
||||
HDAPS_DMI_MATCH_NORMAL("ThinkPad H"),
|
||||
HDAPS_DMI_MATCH_INVERT("ThinkPad R50p"),
|
||||
HDAPS_DMI_MATCH_NORMAL("ThinkPad R50"),
|
||||
HDAPS_DMI_MATCH_NORMAL("ThinkPad R51"),
|
||||
HDAPS_DMI_MATCH_NORMAL("ThinkPad R52"),
|
||||
HDAPS_DMI_MATCH_NORMAL("ThinkPad H"), /* R52 (1846AQG) */
|
||||
HDAPS_DMI_MATCH_INVERT("ThinkPad T41p"),
|
||||
HDAPS_DMI_MATCH_NORMAL("ThinkPad T41"),
|
||||
HDAPS_DMI_MATCH_INVERT("ThinkPad T42p"),
|
||||
HDAPS_DMI_MATCH_NORMAL("ThinkPad T42"),
|
||||
HDAPS_DMI_MATCH_NORMAL("ThinkPad T43"),
|
||||
HDAPS_DMI_MATCH_LENOVO("ThinkPad T60p"),
|
||||
HDAPS_DMI_MATCH_NORMAL("ThinkPad X40"),
|
||||
HDAPS_DMI_MATCH_NORMAL("ThinkPad X41"),
|
||||
HDAPS_DMI_MATCH_LENOVO("ThinkPad X60"),
|
||||
HDAPS_DMI_MATCH_NORMAL("ThinkPad Z60m"),
|
||||
{ .ident = NULL }
|
||||
};
|
||||
|
||||
if (!(dmi_check_system(hdaps_whitelist) || hdaps_force)) {
|
||||
printk(KERN_WARNING "hdaps: supported laptop not found!\n");
|
||||
ret = -ENODEV;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Init timer before platform_driver_register, in case of suspend */
|
||||
init_timer(&hdaps_timer);
|
||||
hdaps_timer.function = hdaps_mousedev_poll;
|
||||
ret = platform_driver_register(&hdaps_driver);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
pdev = platform_device_register_simple("hdaps", -1, NULL, 0);
|
||||
if (IS_ERR(pdev)) {
|
||||
ret = PTR_ERR(pdev);
|
||||
goto out_driver;
|
||||
}
|
||||
|
||||
ret = sysfs_create_group(&pdev->dev.kobj, &hdaps_attribute_group);
|
||||
if (ret)
|
||||
goto out_device;
|
||||
|
||||
hdaps_idev = input_allocate_device();
|
||||
if (!hdaps_idev) {
|
||||
ret = -ENOMEM;
|
||||
goto out_group;
|
||||
}
|
||||
|
||||
/* calibration for the input device (deferred to avoid delay) */
|
||||
needs_calibration = 1;
|
||||
|
||||
/* initialize the input class */
|
||||
hdaps_idev->name = "hdaps";
|
||||
hdaps_idev->cdev.dev = &pdev->dev;
|
||||
hdaps_idev->evbit[0] = BIT(EV_ABS);
|
||||
input_set_abs_params(hdaps_idev, ABS_X,
|
||||
-256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);
|
||||
input_set_abs_params(hdaps_idev, ABS_Y,
|
||||
-256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);
|
||||
|
||||
input_register_device(hdaps_idev);
|
||||
|
||||
mod_timer(&hdaps_timer, jiffies + HZ/sampling_rate);
|
||||
|
||||
printk(KERN_INFO "hdaps: driver successfully loaded.\n");
|
||||
return 0;
|
||||
|
||||
out_group:
|
||||
sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
|
||||
out_device:
|
||||
platform_device_unregister(pdev);
|
||||
out_driver:
|
||||
platform_driver_unregister(&hdaps_driver);
|
||||
out:
|
||||
printk(KERN_WARNING "hdaps: driver init failed (ret=%d)!\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit hdaps_exit(void)
|
||||
{
|
||||
del_timer_sync(&hdaps_timer);
|
||||
input_unregister_device(hdaps_idev);
|
||||
hdaps_device_shutdown();
|
||||
sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
|
||||
platform_device_unregister(pdev);
|
||||
platform_driver_unregister(&hdaps_driver);
|
||||
|
||||
printk(KERN_INFO "hdaps: driver unloaded.\n");
|
||||
}
|
||||
|
||||
module_init(hdaps_init);
|
||||
module_exit(hdaps_exit);
|
||||
|
||||
module_param_named(invert, hdaps_invert, bool, 0);
|
||||
MODULE_PARM_DESC(invert, "invert data along each axis");
|
||||
|
||||
module_param_named(force, hdaps_force, bool, 0);
|
||||
MODULE_PARM_DESC(force, "force loading on non whitelisted laptops");
|
||||
|
||||
MODULE_AUTHOR("Robert Love");
|
||||
MODULE_DESCRIPTION("IBM Hard Drive Active Protection System (HDAPS) driver");
|
||||
MODULE_LICENSE("GPL v2");
|
@ -36,7 +36,7 @@
|
||||
#include <linux/jiffies.h>
|
||||
#include <asm/io.h>
|
||||
|
||||
#define TP_VERSION "0.25"
|
||||
#define TP_VERSION "0.26"
|
||||
|
||||
MODULE_AUTHOR("Shem Multinymous");
|
||||
MODULE_DESCRIPTION("ThinkPad embedded controller hardware access");
|
||||
|
90
tp_smapi.c
90
tp_smapi.c
@ -41,7 +41,7 @@
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/io.h>
|
||||
|
||||
#define TP_VERSION "0.25"
|
||||
#define TP_VERSION "0.26"
|
||||
#define TP_DESC "ThinkPad SMAPI Support"
|
||||
#define TP_DIR "smapi"
|
||||
|
||||
@ -724,7 +724,7 @@ static int show_tpc_bat_date(u8 arg0, int off,
|
||||
|
||||
/* The actual attribute show/store functions */
|
||||
|
||||
static int battery_start_charge_thresh_show(struct device *dev,
|
||||
static int show_battery_start_charge_thresh(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int thresh;
|
||||
@ -735,7 +735,7 @@ static int battery_start_charge_thresh_show(struct device *dev,
|
||||
return sprintf(buf, "%d\n", thresh); /* type: percent */
|
||||
}
|
||||
|
||||
static int battery_stop_charge_thresh_show(struct device *dev,
|
||||
static int show_battery_stop_charge_thresh(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int thresh;
|
||||
@ -746,7 +746,7 @@ static int battery_stop_charge_thresh_show(struct device *dev,
|
||||
return sprintf(buf, "%d\n", thresh); /* type: percent */
|
||||
}
|
||||
|
||||
static int battery_start_charge_thresh_store(struct device *dev,
|
||||
static int store_battery_start_charge_thresh(struct device *dev,
|
||||
struct device_attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
int thresh, other_thresh, ret;
|
||||
@ -786,7 +786,7 @@ out:
|
||||
|
||||
}
|
||||
|
||||
static int battery_stop_charge_thresh_store(struct device *dev,
|
||||
static int store_battery_stop_charge_thresh(struct device *dev,
|
||||
struct device_attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
int thresh, other_thresh, ret;
|
||||
@ -824,7 +824,7 @@ out:
|
||||
return count;
|
||||
}
|
||||
|
||||
static int battery_inhibit_charge_minutes_show(struct device *dev,
|
||||
static int show_battery_inhibit_charge_minutes(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int minutes;
|
||||
@ -835,7 +835,7 @@ static int battery_inhibit_charge_minutes_show(struct device *dev,
|
||||
return sprintf(buf, "%d\n", minutes); /* type: minutes */
|
||||
}
|
||||
|
||||
static int battery_inhibit_charge_minutes_store(struct device *dev,
|
||||
static int store_battery_inhibit_charge_minutes(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
@ -855,7 +855,7 @@ static int battery_inhibit_charge_minutes_store(struct device *dev,
|
||||
return count;
|
||||
}
|
||||
|
||||
static int battery_force_discharge_show(struct device *dev,
|
||||
static int show_battery_force_discharge(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int enabled;
|
||||
@ -866,7 +866,7 @@ static int battery_force_discharge_show(struct device *dev,
|
||||
return sprintf(buf, "%d\n", enabled); /* type: boolean */
|
||||
}
|
||||
|
||||
static int battery_force_discharge_store(struct device *dev,
|
||||
static int store_battery_force_discharge(struct device *dev,
|
||||
struct device_attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
int ret;
|
||||
@ -882,7 +882,7 @@ static int battery_force_discharge_store(struct device *dev,
|
||||
return count;
|
||||
}
|
||||
|
||||
static int battery_installed_show(
|
||||
static int show_battery_installed(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int bat = attr_get_bat(attr);
|
||||
@ -892,7 +892,7 @@ static int battery_installed_show(
|
||||
return sprintf(buf, "%d\n", ret); /* type: boolean */
|
||||
}
|
||||
|
||||
static int battery_state_show(
|
||||
static int show_battery_state(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
u8 row[TP_CONTROLLER_ROW_LEN];
|
||||
@ -913,109 +913,109 @@ static int battery_state_show(
|
||||
return sprintf(buf, "%s\n", msg); /* type: string */
|
||||
}
|
||||
|
||||
static int battery_manufacturer_show(
|
||||
static int show_battery_manufacturer(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_str(4, 2, TP_CONTROLLER_ROW_LEN-2, attr, buf);
|
||||
}
|
||||
|
||||
static int battery_model_show(
|
||||
static int show_battery_model(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_str(5, 2, TP_CONTROLLER_ROW_LEN-2, attr, buf);
|
||||
}
|
||||
|
||||
static int battery_barcoding_show(
|
||||
static int show_battery_barcoding(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_str(7, 2, TP_CONTROLLER_ROW_LEN-2, attr, buf);
|
||||
}
|
||||
|
||||
static int battery_chemistry_show(
|
||||
static int show_battery_chemistry(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_str(6, 2, 5, attr, buf);
|
||||
}
|
||||
|
||||
static int battery_voltage_show(
|
||||
static int show_battery_voltage(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_u16(1, 6, 1, attr, buf); /* type: mV */
|
||||
}
|
||||
|
||||
static int battery_design_voltage_show(
|
||||
static int show_battery_design_voltage(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_u16(3, 4, 1, attr, buf); /* type: mV */
|
||||
}
|
||||
|
||||
static int battery_current_now_show(
|
||||
static int show_battery_current_now(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_s16(1, 8, attr, buf); /* type: mA */
|
||||
}
|
||||
|
||||
static int battery_current_avg_show(
|
||||
static int show_battery_current_avg(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_s16(1, 10, attr, buf); /* type: mA */
|
||||
}
|
||||
|
||||
static int battery_power_now_show(
|
||||
static int show_battery_power_now(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_power(1, 6, 8, attr, buf); /* type: mW */
|
||||
}
|
||||
|
||||
static int battery_power_avg_show(
|
||||
static int show_battery_power_avg(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_power(1, 6, 10, attr, buf); /* type: mW */
|
||||
}
|
||||
|
||||
static int battery_remaining_capacity_show(
|
||||
static int show_battery_remaining_capacity(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_u16(1, 14, 10, attr, buf); /* type: mWh */
|
||||
}
|
||||
|
||||
static int battery_last_full_capacity_show(
|
||||
static int show_battery_last_full_capacity(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_u16(2, 2, 10, attr, buf); /* type: mWh */
|
||||
}
|
||||
|
||||
static int battery_design_capacity_show(
|
||||
static int show_battery_design_capacity(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_u16(3, 2, 10, attr, buf); /* type: mWh */
|
||||
}
|
||||
|
||||
static int battery_cycle_count_show(
|
||||
static int show_battery_cycle_count(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_u16(2, 12, 1, attr, buf); /* type: ordinal */
|
||||
}
|
||||
|
||||
static int battery_serial_show(
|
||||
static int show_battery_serial(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_u16(3, 10, 1, attr, buf); /* type: ordinal */
|
||||
}
|
||||
|
||||
static int battery_manufacture_date_show(
|
||||
static int show_battery_manufacture_date(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_date(3, 8, attr, buf); /* type: YYYY-MM-DD */
|
||||
}
|
||||
|
||||
static int battery_first_use_date_show(
|
||||
static int show_battery_first_use_date(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_tpc_bat_date(8, 2, attr, buf); /* type: YYYY-MM-DD */
|
||||
}
|
||||
|
||||
static int battery_dump_show(
|
||||
static int show_battery_dump(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int i;
|
||||
@ -1053,7 +1053,7 @@ static int battery_dump_show(
|
||||
* sysfs attribute I/O, other than batteries
|
||||
*/
|
||||
|
||||
static int ac_connected_show(
|
||||
static int show_ac_connected(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int ret = is_battery_installed(0xFF);
|
||||
@ -1062,7 +1062,7 @@ static int ac_connected_show(
|
||||
return sprintf(buf, "%d\n", ret); /* type: boolean */
|
||||
}
|
||||
|
||||
static int enable_pci_power_saving_on_boot_show(
|
||||
static int show_enable_pci_power_saving_on_boot(
|
||||
struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int on;
|
||||
@ -1072,7 +1072,7 @@ static int enable_pci_power_saving_on_boot_show(
|
||||
return sprintf(buf, "%d\n", on); /* type: boolean */
|
||||
}
|
||||
|
||||
static int enable_pci_power_saving_on_boot_store(struct device *dev,
|
||||
static int store_enable_pci_power_saving_on_boot(struct device *dev,
|
||||
struct device_attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
int ret;
|
||||
@ -1098,7 +1098,7 @@ static int enable_pci_power_saving_on_boot_store(struct device *dev,
|
||||
#define MAX_SMAPI_ANSWER_STR 128
|
||||
static char smapi_attr_answer[MAX_SMAPI_ANSWER_STR] = "";
|
||||
|
||||
static int smapi_request_show(struct device *dev,
|
||||
static int show_smapi_request(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int ret = snprintf(buf, PAGE_SIZE, "%s", smapi_attr_answer);
|
||||
@ -1106,7 +1106,7 @@ static int smapi_request_show(struct device *dev,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int smapi_request_store(struct device *dev,
|
||||
static int store_smapi_request(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
@ -1138,7 +1138,7 @@ static int smapi_request_store(struct device *dev,
|
||||
* driver instead, and may get in the ATAPI driver's way.
|
||||
*/
|
||||
|
||||
static int cd_speed_show(struct device *dev,
|
||||
static int show_cd_speed(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int speed;
|
||||
@ -1148,7 +1148,7 @@ static int cd_speed_show(struct device *dev,
|
||||
return sprintf(buf, "%d\n", speed);
|
||||
}
|
||||
|
||||
static int cd_speed_store(struct device *dev,
|
||||
static int store_cd_speed(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
@ -1226,14 +1226,14 @@ static struct platform_driver tp_driver = {
|
||||
|
||||
/* Attributes in /sys/devices/platform/smapi/ */
|
||||
|
||||
static DEVICE_ATTR(ac_connected, 0444, ac_connected_show, NULL);
|
||||
static DEVICE_ATTR(ac_connected, 0444, show_ac_connected, NULL);
|
||||
static DEVICE_ATTR(enable_pci_power_saving_on_boot, 0644,
|
||||
enable_pci_power_saving_on_boot_show,
|
||||
enable_pci_power_saving_on_boot_store);
|
||||
static DEVICE_ATTR(smapi_request, 0600, smapi_request_show,
|
||||
smapi_request_store);
|
||||
show_enable_pci_power_saving_on_boot,
|
||||
store_enable_pci_power_saving_on_boot);
|
||||
static DEVICE_ATTR(smapi_request, 0600, show_smapi_request,
|
||||
store_smapi_request);
|
||||
#ifdef PROVIDE_CD_SPEED
|
||||
static DEVICE_ATTR(cd_speed, 0644, cd_speed_show, cd_speed_store);
|
||||
static DEVICE_ATTR(cd_speed, 0644, show_cd_speed, store_cd_speed);
|
||||
#endif
|
||||
|
||||
static struct attribute *tp_root_attributes[] = {
|
||||
@ -1288,14 +1288,14 @@ static struct attribute_group tp_root_attribute_group = {
|
||||
|
||||
#define DEFINE_BAT_ATTR_RW(_BAT,_NAME) \
|
||||
static struct bat_device_attribute dev_attr_##_NAME##_##_BAT = { \
|
||||
.dev_attr = __ATTR(_NAME, 0644, battery_##_NAME##_show, \
|
||||
battery_##_NAME##_store), \
|
||||
.dev_attr = __ATTR(_NAME, 0644, show_battery_##_NAME, \
|
||||
store_battery_##_NAME), \
|
||||
.bat = _BAT \
|
||||
};
|
||||
|
||||
#define DEFINE_BAT_ATTR_R(_BAT,_NAME) \
|
||||
static struct bat_device_attribute dev_attr_##_NAME##_##_BAT = { \
|
||||
.dev_attr = __ATTR(_NAME, 0644, battery_##_NAME##_show, 0), \
|
||||
.dev_attr = __ATTR(_NAME, 0644, show_battery_##_NAME, 0), \
|
||||
.bat = _BAT \
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user