Difference between revisions of "Tp smapi"

From ThinkWiki
Jump to: navigation, search
(X series: update X60/X60s status)
m (Installation from source: tp_smapi 0.26 released)
Line 24: Line 24:
 
For testing, you can simply compile and load the driver within the current
 
For testing, you can simply compile and load the driver within the current
 
working directory:
 
working directory:
:{{cmdroot|tar xzvf tp_smapi-0.25.tgz}}
+
:{{cmdroot|tar xzvf tp_smapi-0.26.tgz}}
:{{cmdroot|cd tp_smapi-0.25}}
+
:{{cmdroot|cd tp_smapi-0.26}}
 
:{{cmdroot|make load}}
 
:{{cmdroot|make load}}
  

Revision as of 18:24, 4 August 2006

The tp_smapi kernel module exposes some features of the ThinkPad's SMAPI functionality via a sysfs interface. Currently, the implemented functionality is control of battery charging, extended battery status and control of CD/DVD speed (disabled by default).

For older ThinkPad models, see also tpctl.

ATTENTION!
This driver uses undocumented features and direct hardware access. It thus cannot be guaranteed to work and could conceivably damage your computer (though so far no incidents have been reported).

Features

  • Battery charge/discharge control
  • Battery status information
  • Optical drive speed control (disabled by default)

Project Homepage / Availability

Installation

Installation from source

You will need the kernel headers and makefiles corresponding to your current kernel version. On Fedora, this means # yum install kernel-devel-$(uname -r) .

For testing, you can simply compile and load the driver within the current working directory:

# tar xzvf tp_smapi-0.26.tgz
# cd tp_smapi-0.26
# make load

To compile and install into the kernel's module path:

# make install

If you use the HDAPS driver, add HDAPS=1 to also patch the hdaps for compatibility with tp_smapi (this requires a kernel source tree matching the current kernel):

# make load HDAPS=1

or, to compile and install into the kernel's module path:

# make install HDAPS=1


To prepare a stand-alone patch against the current kernel tree (including a patch against hdaps and new Kconfig entries):

# make patch

To delete all autogenerated files:

# make clean

The original kernel tree is never modified by any these commands. The /lib/modules directory is modified only by # make install.

Installation in Gentoo

The Gentoo portage system carries a tp_smapi package, which follows the latest version pretty closely. On a Gentoo system, you can install and load as follows.

If you use the HDAPS driver, do this first:

  • Configure hdaps as module in your kernel
  • Add the HDAPS use flag in /etc/make.conf
  • # rmmod hdaps

Then:

  • # emerge tp_smapi (or install tp_smapi with hdaps support manually, as above)
  • # echo "tp_smapi" >> /etc/modules.autoload.d/kernel-2.6
  • # echo "hdaps" >> /etc/modules.autoload.d/kernel-2.6

Then reboot, or run:

  • # modprobe tp_smapi
  • # modprobe hdaps

Installation on Debian/Ubuntu

deb http://www.oakcourt.dyndns.org/debian/ ./
deb-src http://www.oakcourt.dyndns.org/debian/ ./

This repository has kernel-patch packages for tp_smapi. This will not only integrate tp_smapi into your kernel build but will patch the hdaps driver for you. It is available for kernel 2.6.15 and later. Also available is an init script to automatically set SMAPI paramaters at boot--this is in package tpsmapi-utils. Please report any bugs to User:Ajbarr

Battery charge control features

To set the thresholds for starting and stopping battery charging (in percent of current full charge capacity):

# echo 40 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
# echo 70 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
# cat /sys/devices/platform/smapi/BAT0/*_charge_thresh
Hint:
Battery charging thresholds can be used to keep Li-Ion ad Li-Polymer batteries partially charged, in order to increase their lifetime.

To unconditionally inhibit charging for 17 minutes:

# echo 17 > /sys/devices/platform/smapi/BAT0/inhibit_charge_minutes
Hint:
Charge inhibiting can be used to reduce the power draw of the laptop, in order to use a an under-spec power supply that can't handle the combined power draw of running and charging. It can also be used to control which battery is charged when using an Ultrabay battery.

To cancel charge inhibiting:

# echo 0 > /sys/devices/platform/smapi/BAT0/inhibit_charge_minutes

To force battery discharging even if connected to AC, use one of these:

# echo 1 > /sys/devices/platform/smapi/BAT0/force_discharge
Hint:
This can be used to choose which battery is discharged when using an UltraBay battery.

To cancel forced discharge:

# echo 0 > /sys/devices/platform/smapi/BAT0/force_discharge

Battery status features

To view extended battery status such as charging state, voltage, current, capacity, cycle count and model information:

# cat /sys/devices/platform/smapi/BAT0/installed
# cat /sys/devices/platform/smapi/BAT0/state       # idle/charging/discharging
# cat /sys/devices/platform/smapi/BAT0/cycle_count 
# cat /sys/devices/platform/smapi/BAT0/current_now # instantaneous current
# cat /sys/devices/platform/smapi/BAT0/current_avg # last minute average
# cat /sys/devices/platform/smapi/BAT0/power_now   # instantaneous power
# cat /sys/devices/platform/smapi/BAT0/power_avg   # last minute average
# cat /sys/devices/platform/smapi/BAT0/last_full_capacity
# cat /sys/devices/platform/smapi/BAT0/remaining_capacity
# cat /sys/devices/platform/smapi/BAT0/design_capacity
# cat /sys/devices/platform/smapi/BAT0/voltage
# cat /sys/devices/platform/smapi/BAT0/design_voltage
# cat /sys/devices/platform/smapi/BAT0/manufacturer
# cat /sys/devices/platform/smapi/BAT0/model
# cat /sys/devices/platform/smapi/BAT0/barcoding
# cat /sys/devices/platform/smapi/BAT0/chemistry
# cat /sys/devices/platform/smapi/BAT0/serial
# cat /sys/devices/platform/smapi/BAT0/manufacture_date
# cat /sys/devices/platform/smapi/BAT0/first_use_date
# cat /sys/devices/platform/smapi/ac_connected

The raw status data is also available, including some fields not listed above (in case you can figure them out):

# cat /sys/devices/platform/smapi/BAT0/dump

In all of the above, replace BAT0 with BAT1 to address the 2nd battery.

Note that the battery status readout conflicts with the stock hdaps driver, so if you use hdaps you will need to load tp_smapi using # make load HDAPS=1 (see Conflict with hdaps below).

On ACPI-enabled systems, most of above information is also available through the files under /proc/acpi/battery. However, the ACPI interface does not include the instantaneous power and cycle count readouts, and does not work well when hotswapping UltraBay batteries.

Optical drive control features

To control the speed of the optical drive:

# echo 0 > /sys/devices/platform/smapi/cd_speed # slow
# echo 1 > /sys/devices/platform/smapi/cd_speed # medium
# echo 2 > /sys/devices/platform/smapi/cd_speed # fast
# cat /sys/devices/platform/smapi/cd_speed
Enabling this feature

Changing the drive speed when a disc is being accessed will hang your computer. This feature is thus disabled by default, but can be enabled using by adding #define PROVIDE_CD_SPEED at the top of tp_smapi.c. The safe way to set the drive speed is using hdparm -E num or eject -x num for CD-ROM, and speedcontrol -x num (sourcecode here) for DVD. For kernels older than 2.6.15, this may require the libata pass-through patch.

Other features

This controls the "PCI bus power saving" option in the BIOS, and takes effect at the next boot. On a ThinkPad T43 turning this off increases idle power consumption by about 350mW. Out-of-the-box default is 1.

# cat /sys/devices/platform/smapi/enable_pci_power_saving_on_boot
# echo 1 > /sys/devices/platform/smapi/enable_pci_power_saving_on_boot # on
# echo 0 > /sys/devices/platform/smapi/enable_pci_power_saving_on_boot # off

There is also sysfs attribute for making direct SMAPI requests to the SM BIOS firmware. Don't touch it unless you really know what you're doing.

echo 'BX=2116 CX=100 DI=0 SI=0' > /sys/devices/platform/smapi/smapi_request; cat /sys/devices/platform/smapi/smapi_request
BX=2116 CX=327 DX=b2 DI=0 SI=0 ret=0 msg=OK

Conflict with hdaps

The extended battery status function conflicts with the hdaps kernel module (they use the same IO ports). The tp_smapi package includes a patch against hdaps to make it compatible with tp_smapi, and also to fix many problems in the original driver.

To build the patched version, simply append the HDAPS=1 parameter to the make command, for example: # make load HDAPS=1 (see Installation above).

If you don't do that, you will not be able tp load tp_smapi (and its support module tp_base) when hdaps is loaded, and vice versa. You can use rmmod to switch between these modules.

Note that some of the battery status is also visible through ACPI (/proc/acpi/battery/*), independently of tp_smapi.

Some new ThinkPad models are not recognized by the built-in whitelist, so you will need to add the force=1 module parameter to hdaps (this option is added by the tp_smapi patch to hdaps).

Model-specific status

tp_smapi feature support matrix
× start_charge_
thresh
stop_charge_
thresh
inhbit_charge_
minutes
force_discharge battery status files cd_speed
(see note above)
Notes
A series
A22p 2629-USG no no no no no unknown
A30 no no no no yes unknown
G series
G41 yes no yes unknown unknown yes
R series
R31 no no no no no no No SMAPI BIOS
R40 no no no no unknown yes
R50 unknown no unknown unknown yes unknown
R50p no no no no yes yes
R51 yes no yes unknown yes unknown
R52 yes yes yes unknown unknown yes
T series
T20 no no no no no unknown Has SMAPI BIOS but no function is supported. EC LPC3 protocol fails.
T22 no no no no no unknown Has SMAPI BIOS but no function is supported. EC LPC3 protocol fails.
T23 no no no no yes unknown
T30 no no no no yes unknown
T40 no no no unknown yes yes
T40p no no no no yes yes
T41 no no no no yes yes
T41p no no no no yes yes
T42 yes no yes yes yes yes
T42p 2373-KUU yes no yes unknown yes unknown
T43 2686-DGU yes yes yes yes yes yes
T43p yes yes yes yes yes yes
T60 yes yes unknown yes yes unknown
X series
X20 2662-31G no no no no no unknown tp_smapi 0.20
X24 no no no unknown yes unknown
X31 no no no unknown yes unknown
X32 no no no no yes unknown
X40 yes yes yes unknown yes unknown BIOS v2.03, EC v1.60
X41 yes yes yes yes yes unknown
X60 yes yes unknown unknown yes unknown
Z series
Z60t yes yes unknown unknown yes unknown
Z61m yes yes yes yes yes yes


Please update the above and report your experience on the discussion page. If the module loads but gives a "not supported" or "not implementeded" when you try to use some specific file in /sys/devices/platform/smapi/, please report the dmesg output and whether the corresponding functionality is available under Windows - maybe your ThinkPad just can't do that.

While at it, you may also want to add your laptop to the list of DMI IDs.

Tools using this driver

The driver's interface can be accessed directly through the files under /sys/devices/platform/smapi, or via the following tools: