Skip to content

Commit 9494b41

Browse files
Shem Multinymousevgeni
authored andcommitted
import of tp-smapi version 0.40
1 parent 0021d50 commit 9494b41

6 files changed

Lines changed: 77 additions & 37 deletions

File tree

CHANGES

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
Change history for tp_smapi:
1+
Change history for the tp_smapi package:
2+
3+
0.40 2008-12-16
4+
---------------------
5+
- thinkpad_ec: Added a "force_io=1" module parameter, to let it load on
6+
recent ThinkPad models (e.g., T400 and T500). This is a kludge to work
7+
around an ACPI DSDT which claims the ports we need.
8+
- tp_smapi: Don't restore battery charging thresholds when resuming from
9+
suspend-to-RAM.
10+
- When building, use /lib/modules/*/build instead of /lib/modules/*/src
11+
and give a clearer error message if that's missing.
212

313
0.39 2008-09-27
414
---------------------

Makefile

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,23 @@ else
1919
LOAD_HDAPS := :
2020
endif
2121

22+
ifeq ($(FORCE_IO),1)
23+
THINKPAD_EC_PARAM := force_io=1
24+
else
25+
THINKPAD_EC_PARAM :=
26+
endif
27+
2228
DEBUG := 0
2329

24-
ifneq ($(shell [ -f $(KSRC)/include/linux/aio_abi.h ] && echo 1),1)
25-
$(error This driver requires kernel 2.6.19 or newer, and matching kernel sources. You may need to override KVER=$(KVER) or KSRC=$(KSRC) or KBUILD=$(KBUILD) or MOD_DIR=$(MOD_DIR))
30+
ifneq ($(shell [ -f $(KBUILD)/include/linux/aio_abi.h ] && echo 1),1)
31+
$(warning Building tp_smapi requires Linux kernel 2.6.19 or newer, and matching kernel headers.)
32+
$(warning You may need to override the following Make variables:)
33+
$(warning . KVER=$(KVER))
34+
$(warning . KBUILD=$(KBUILD))
35+
$(warning . MOD_DIR=$(MOD_DIR))
36+
$(warning For "make patch", you may also need the full kernel sources, and may need to override:)
37+
$(warning . KSRC=$(KSRC))
38+
$(error Missing kernel headers)
2639
endif
2740

2841
.PHONY: default clean modules load unload install patch check_hdaps mk-hdaps.diff
@@ -34,8 +47,8 @@ export TP_MODULES
3447
default: modules
3548

3649
# Build the modules thinkpad_ec.ko, tp_smapi.ko and (if HDAPS=1) hdaps.ko
37-
modules: $(KSRC) $(patsubst %.o,%.c,$(TP_MODULES))
38-
$(MAKE) -C $(KSRC) M=$(PWD) O=$(KBUILD) modules
50+
modules: $(KBUILD) $(patsubst %.o,%.c,$(TP_MODULES))
51+
$(MAKE) -C $(KBUILD) M=$(PWD) O=$(KBUILD) modules
3952

4053
clean:
4154
rm -f tp_smapi.mod.* tp_smapi.o tp_smapi.ko .tp_smapi.*.cmd
@@ -47,9 +60,7 @@ clean:
4760

4861
load: check_hdaps unload modules
4962
@( [ `id -u` == 0 ] || { echo "Must be root to load modules"; exit 1; } )
50-
{ insmod ./thinkpad_ec.ko &&\
51-
insmod ./tp_smapi.ko debug=$(DEBUG) &&\
52-
$(LOAD_HDAPS); }; :
63+
{ insmod ./thinkpad_ec.ko $(THINKPAD_EC_PARAM) && insmod ./tp_smapi.ko debug=$(DEBUG) && $(LOAD_HDAPS); }; :
5364
@echo -e '\nRecent dmesg output:' ; dmesg | tail -10
5465

5566
unload:
@@ -76,7 +87,7 @@ ifeq ($(HDAPS),1)
7687
rm -f $(MOD_DIR)/drivers/hwmon/hdaps.ko
7788
rm -f $(MOD_DIR)/extra/hdaps.ko
7889
endif
79-
$(MAKE) -C $(KSRC) M=$(PWD) O=$(KBUILD) modules_install
90+
$(MAKE) -C $(KBUILD) M=$(PWD) O=$(KBUILD) modules_install
8091
depmod -a
8192

8293

@@ -92,7 +103,7 @@ BASE_IN_PATCH := 1
92103
SMAPI_IN_PATCH := 1
93104
HDAPS_IN_PATCH := 1
94105

95-
patch:
106+
patch: $(KSRC)
96107
@TMPDIR=`mktemp -d /tmp/tp_smapi-patch.XXXXXX` &&\
97108
echo "Working directory: $$TMPDIR" &&\
98109
cd $$TMPDIR &&\

README

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tp_smapi version 0.39
1+
tp_smapi version 0.40
22
IBM ThinkPad hardware functions driver
33

44
Author: Shem Multinymous <multinymous@gmail.com>
@@ -41,15 +41,22 @@ with one patched for compatibility with tp_smapi:
4141
or
4242
# make install HDAPS=1
4343

44+
With some recent ThinkPad models, the "thinkpad_ec" will refuse to load due to
45+
reserved ports. You can force loading by passing the "force_io=1" parameter
46+
to the "thinkpad_ec" module using /etc/modules.conf (or your distribution's
47+
equivalent). To test this prior to installation, use:
48+
# make load HDAPS=1 FORCE_IO=1
49+
4450
To prepare a stand-alone patch against the current kernel tree (including
45-
a compatibility fixes to hdaps and Kconfig entries):
51+
the hdaps replacement and Kconfig entries), assuming you have its sourcecode
52+
under /lib/modules/`uname -r`/source:
4653
# make patch
4754

48-
To work against a kernel (other than the current one) that's
49-
installed under /lib/modules/, add an appropriate KVER= parameter
50-
# make patch KVER=2.6.16-rc2
51-
To work against an uninstalled kernel, you'll need to set KSRC and KBUILD too:
52-
# make patch KVER=2.6.16-rc2 KSRC=$HOME/2.6.16-rc2 KBUILD=$HOME/2.6.16-rc2
55+
To work against a kernel (other than the current one) that's properly
56+
installed under /lib/modules/*, add an appropriate KVER= parameter
57+
# make patch KVER=2.6.16
58+
To work against another kernel, you'll need to set KSRC and KBUILD too:
59+
# make patch KVER=2.6.16 KSRC=$HOME/2.6.16 KBUILD=$HOME/2.6.16
5360

5461
To delete all autogenerated files:
5562
# make clean
@@ -59,17 +66,15 @@ Append "DEBUG=1" to "make load" to load tp_smapi with debug=1.
5966
The original kernel tree is never modified by any these commands.
6067
The /lib/modules directory is modified only by "make install".
6168

62-
If your kernel doesn't have dmi-decode-and-save-oem-string-information
63-
applied (see below) then all make commands except "make patch" will need
64-
to invoke "dmidecode" using "sudo", to get information about your
65-
hardware at compile time.
66-
6769

6870
Module parameters
6971
-----------------
7072

73+
thinkpad_ec module:
74+
force_io=1 lets thinkpad_ec load on some recent ThinkPad models
75+
(e.g., T400 and T500) whose BIOS's ACPI DSDT reserves the ports we need.
7176
tp_smapi module:
72-
debug=1 enables verbose dmesg output.
77+
debug=1 enables verbose dmesg output.
7378

7479

7580
Usage

hdaps.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ static struct input_dev *hdaps_idev_raw; /* raw hdaps sensor readouts */
8989
static unsigned int hdaps_invert = HDAPS_ORIENT_UNDEFINED;
9090
static int needs_calibration;
9191

92-
9392
/* Configuration: */
9493
static int sampling_rate = 50; /* Sampling rate */
9594
static int oversampling_ratio = 5; /* Ratio between our sampling rate and

thinkpad_ec.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include <linux/semaphore.h>
4646
#endif
4747

48-
#define TP_VERSION "0.39"
48+
#define TP_VERSION "0.40"
4949

5050
MODULE_AUTHOR("Shem Multinymous");
5151
MODULE_DESCRIPTION("ThinkPad embedded controller hardware access");
@@ -88,9 +88,14 @@ static u64 prefetch_jiffies; /* time of prefetch, or: */
8888
#define TPC_PREFETCH_JUNK (INITIAL_JIFFIES+1) /* Ignore prefetch */
8989

9090
/* Locking: */
91-
9291
static DECLARE_MUTEX(thinkpad_ec_mutex);
9392

93+
/* Kludge in case the ACPI DSDT reserves the ports we need. */
94+
static int force_io; /* Willing to do IO to ports we couldn't reserve? */
95+
static int reserved_io; /* Successfully reserved the ports? */
96+
module_param_named(force_io, force_io, bool, 0600);
97+
MODULE_PARM_DESC(force_io, "Force IO even if region already reserved (0=off, 1=on)");
98+
9499
/**
95100
* thinkpad_ec_lock - get lock on the ThinkPad EC
96101
*
@@ -468,17 +473,24 @@ static int __init thinkpad_ec_init(void)
468473
return -ENODEV;
469474
}
470475

471-
if (!request_region(TPC_BASE_PORT, TPC_NUM_PORTS,
472-
"thinkpad_ec")) {
473-
printk(KERN_ERR "thinkpad_ec: cannot claim io ports %#x-%#x\n",
476+
if (request_region(TPC_BASE_PORT, TPC_NUM_PORTS, "thinkpad_ec")) {
477+
reserved_io = 1;
478+
} else {
479+
printk(KERN_ERR "thinkpad_ec: cannot claim IO ports %#x-%#x... ",
474480
TPC_BASE_PORT,
475481
TPC_BASE_PORT + TPC_NUM_PORTS - 1);
476-
return -ENXIO;
482+
if (force_io) {
483+
printk("forcing use of unreserved IO ports.\n");
484+
} else {
485+
printk("consider using force_io=1.\n");
486+
return -ENXIO;
487+
}
477488
}
478489
prefetch_jiffies = TPC_PREFETCH_JUNK;
479490
if (thinkpad_ec_test()) {
480491
printk(KERN_ERR "thinkpad_ec: initial ec test failed\n");
481-
release_region(TPC_BASE_PORT, TPC_NUM_PORTS);
492+
if (reserved_io)
493+
release_region(TPC_BASE_PORT, TPC_NUM_PORTS);
482494
return -ENXIO;
483495
}
484496
printk(KERN_INFO "thinkpad_ec: thinkpad_ec " TP_VERSION " loaded.\n");
@@ -487,7 +499,8 @@ static int __init thinkpad_ec_init(void)
487499

488500
static void __exit thinkpad_ec_exit(void)
489501
{
490-
release_region(TPC_BASE_PORT, TPC_NUM_PORTS);
502+
if (reserved_io)
503+
release_region(TPC_BASE_PORT, TPC_NUM_PORTS);
491504
printk(KERN_INFO "thinkpad_ec: unloaded.\n");
492505
}
493506

tp_smapi.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#include <asm/uaccess.h>
4848
#include <asm/io.h>
4949

50-
#define TP_VERSION "0.39"
50+
#define TP_VERSION "0.40"
5151
#define TP_DESC "ThinkPad SMAPI Support"
5252
#define TP_DIR "smapi"
5353

@@ -1238,13 +1238,15 @@ static int saved_threshs[4] = {-1, -1, -1, -1}; /* -1 = don't know */
12381238

12391239
static int tp_suspend(struct platform_device *dev, pm_message_t state)
12401240
{
1241-
if (get_real_thresh(0, THRESH_STOP , &saved_threshs[0]))
1241+
int restore = (state.event == PM_EVENT_HIBERNATE ||
1242+
state.event == PM_EVENT_FREEZE);
1243+
if (!restore || get_real_thresh(0, THRESH_STOP , &saved_threshs[0]))
12421244
saved_threshs[0] = -1;
1243-
if (get_real_thresh(0, THRESH_START, &saved_threshs[1]))
1245+
if (!restore || get_real_thresh(0, THRESH_START, &saved_threshs[1]))
12441246
saved_threshs[1] = -1;
1245-
if (get_real_thresh(1, THRESH_STOP , &saved_threshs[2]))
1247+
if (!restore || get_real_thresh(1, THRESH_STOP , &saved_threshs[2]))
12461248
saved_threshs[2] = -1;
1247-
if (get_real_thresh(1, THRESH_START, &saved_threshs[3]))
1249+
if (!restore || get_real_thresh(1, THRESH_START, &saved_threshs[3]))
12481250
saved_threshs[3] = -1;
12491251
DPRINTK("suspend saved: %d %d %d %d", saved_threshs[0],
12501252
saved_threshs[1], saved_threshs[2], saved_threshs[3]);

0 commit comments

Comments
 (0)