Difference between revisions of "SMAPI support for Linux"

From ThinkWiki
Jump to: navigation, search
(tp_smapi 0.14 (improves reliability of coordination with hdaps driver))
(Installation)
Line 25: Line 25:
 
:{{cmdroot|make install}}
 
:{{cmdroot|make install}}
  
If you use the HDAPS driver, use these instead to replace the hdaps module with one patched for compatibility with <tt>tp_smapi</tt> (kernel source tree needed):
+
If you use the [[HDAPS]] driver, add <tt>HDAPS=1</tt> to also patch the <tt>hdaps</tt> for compatibility with <tt>tp_smapi</tt> (this requires a kernel source tree):
:{{cmdroot|1=make load HDAPS=1}} or {{cmdroot|1=make install HDAPS=1}}
+
:{{cmdroot|1=make load HDAPS=1}} &nbsp; or &nbsp;  {{cmdroot|1=make install HDAPS=1}}
  
  

Revision as of 16:31, 9 January 2006

ThinkPad laptops include a proprietary interface called SMAPI BIOS (System Management Application Program Interface) which provides some hardware control functionality that is not exposed by any other interface (e.g., ACPI).

The SMAPI interfaces has mutated between models and is poorly documented, so Linux support is not exhaustive for most models. There are currently two SMAPI access mechanisms available:

  • thinkpad and tpctl for older ThinkPads
  • tp_smapi for newer ones

Using the tp_smapi module

ATTENTION!
These drivers use undocumented features and direct hardware access. They thus cannot be guaranteed to work, and may cause arbitrary damage (especially on models they weren't tested on).

The tp_smapi kernel module exposes some features of the SMAPI BIOS found on recent ThinkPads 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).

Installation

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

# tar xzvf tp_smapi-0.14.tgz
# cd tp_smapi-0.14
# 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):

# make load HDAPS=1   or   # make install HDAPS=1


To prepare a stand-alone patch against the current kernel tree (including a compatibility fixes to hdaps and 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.

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.

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_discharge1
# echo 1 > /sys/devices/platform/smapi/BAT0/force_discharge2

(Probably only one of these will work on your laptop; please check the dmesg output to see which one, and update the status below.)

To cancel forced discharge, use one of these:

# echo 0 > /sys/devices/platform/smapi/BAT0/force_discharge1
# echo 0 > /sys/devices/platform/smapi/BAT0/force_discharge2

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/serial
# cat /sys/devices/platform/smapi/BAT0/barcoding
# cat /sys/devices/platform/smapi/BAT0/chemistry
# 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 below).

Optical drive control features

To control the speed of the optical drive:

# echo 0 yes_crash_my_computer > /sys/devices/platform/smapi/cd_speed # slow
# echo 1 yes_crash_my_computer > /sys/devices/platform/smapi/cd_speed # medium
# echo 2 yes_crash_my_computer > /sys/devices/platform/smapi/cd_speed # fast
# cat /sys/devices/platform/smapi/cd_speed
ATTENTION!
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

Other things that can be controlled through SMAPI, but are not supported in this version of the driver, include forcing battery discharge, PCI bus power saving, CPU power saving control and fan control. See the included README file for more information.

Conflict with hdaps

The extended battery status function conflicts with the hdaps kernel module (they use the same IO ports).

You can use HDAPS=1 (see Installation) to get a patched version of hdaps which is compatible with tp_smapi.

Otherwise:

If you load hdaps first, tp_smapi will disable its battery status functions (and log a message in the kernel log). If you load tp_smapi first, hdaps will refuse to load. To switch between the two, rmmod both and then load one you need.

Some of the battery status is also visible through ACPI (/proc/acpi/battery/*).

The charging control files (*_charge_thresh, inhibit_charge_minutes and force_discharge*) don't have this problem.

Model-specific status

tp_smapi feature support matrix
× start_charge_
thresh
stop_charge_
thresh
inhbit_charge_
minutes
cd_speed
(see note above)
force_
discharge1
force_
discharge2
battery status files
(see note about hdaps above)
G41 yes no yes yes unknown unknown unknown
R40 no no no yes unknown unknown unknown
R50p no no no yes no no yes
R51 yes no yes unknown unknown unknown yes
R52 yes yes yes yes unknown unknown unknown
T23 no no no unknown no no yes
T40 no no no yes unknown unknown yes
T40p no no no yes no no yes
T41 no no no yes no no yes
T41p no no no yes unknown unknown unknown
T42 yes no yes yes yes no yes
T42p yes no yes unknown unknown unknown unknown
T43 yes yes yes yes yes no yes
T43p yes yes yes yes yes no yes
X24 no no no unknown unknown unknown yes
X31 no no no unknown unknown unknown yes
X32 no no no unknown unknown unknown unknown
X40 yes no yes unknown unknown unknown yes
X41 yes yes yes unknown yes no 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.

Help needed
Have an Ultrabay battery? We're looking for feedback about dual-battery operation. Please test the functionality on both batteries and report by e-mail or on the discussion page.

Using the thinkpad module

This solution consists of a module, called thinkpad, and a user-space tool caled tpctl. It provides very rich functionality for older ThinkPads, but on newer ThinkPads much of this functionality is exposed and supported through an ACPI interface and the SMAPI access does not work anymore. Kernel 2.6.9 and newer is unsupported; for kernel 2.6.3 and newer you need tpctl >=4.14 and thinkpad >=5.5. For details, see the README and list of supported models.