Difference between revisions of "SMAPI support for Linux"

From ThinkWiki
Jump to: navigation, search
(Battery charge control features: Don't see the point in those floating hints.)
 
(22 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
ThinkPad laptops include a proprietary interface called SMAPI BIOS (System Management Application Program Interface) which provides some
 
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).
+
hardware control functionality that is not exposed by standard interfaces such as ACPI and APM.
  
 
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:
 
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:
*<tt>thinkpad</tt> and <tt>tpctl</tt> for older ThinkPads and
+
*[[tp_smapi]] for newer ThinkPad models. This module provides battery information for models produced since 2001 and possibly earlier, and additional features for models produced since 2003.
*<tt>tp_smapi</tt> for newer ones.
+
*[[tpctl]] with the <tt>thinkpad</tt> kernel modules worked on older ThinkPad models but are now obsolete: the drivers no longer build (with the latest Linux versions). On modern ThinkPads tpctl has been superseded by the standardized ACPI subsystem and the tp_smapi driver.
 
 
==Using the <tt>tp_smapi</tt> module==
 
{{WARN|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 <tt>tp_smapi</tt> kernel module exposes some features of the SMAPI BIOS found on recent ThinkPads via a <tt>sysfs</tt> interface. Currently, the  implemented functionality is control of battery charging, extended battery status and control of CD/DVD speed (disabled by default).
 
 
 
* Project page: http://tpctl.sourceforge.net/
 
* You need to download only the [http://sourceforge.net/project/showfiles.php?group_id=1212&package_id=171579 tp_smapi kernel module].
 
 
 
===Installation===
 
For testing, you can simply compile and load the driver within the current
 
working directory:
 
:{{cmdroot|tar xzvf tp_smapi-0.13.tgz}}
 
:{{cmdroot|cd tp_smapi-0.13}}
 
:{{cmdroot|make load}}
 
 
 
To compile and install into the kernel's module path:
 
:{{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):
 
:{{cmdroot|1=make load HDAPS=1}}
 
or
 
:{{cmdroot|1=make install HDAPS=1}}
 
 
 
 
 
To prepare a stand-alone patch against the current kernel tree (including
 
a compatibility fixes to <tt>hdaps</tt> and <tt>Kconfig</tt> entries):
 
:{{cmdroot|make patch}}
 
 
 
To delete all autogenerated files:
 
:{{cmdroot|make clean}}
 
 
 
The original kernel tree is never modified by any these commands.
 
The {{path|/lib/modules}} directory is modified only by {{cmdroot|make install}}.
 
 
 
===Battery charge control features===
 
{{HINT|Battery charging thresholds can be used to keep Li-Ion ad Li-Polymer batteries partially charged, in order to [[Maintenance#Battery_Treatment|increase their lifetime]].}}
 
To set the thresholds for starting and stopping battery charging (in percent of current full charge capacity):
 
:{{cmdroot|echo 40 > /sys/devices/platform/smapi/BAT0/start_charge_thresh}}
 
:{{cmdroot|echo 70 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh}}
 
:{{cmdroot|cat /sys/devices/platform/smapi/BAT0/*_charge_thresh}}
 
:{{cmdresult|40}}
 
:{{cmdresult|70}}
 
{{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 unconditionally inhibit charging for 17 minutes:
 
:{{cmdroot|echo 17 > /sys/devices/platform/smapi/BAT0/inhibit_charge_minutes}}
 
 
 
To cancel charge inhibiting:
 
:{{cmdroot|echo 0 > /sys/devices/platform/smapi/BAT0/inhibit_charge_minutes}}
 
 
 
To force battery discharging even if connected to AC, use one of these:
 
:{{cmdroot|echo 1 > /sys/devices/platform/smapi/BAT0/force_discharge1}}
 
:{{cmdroot|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 disharge, use one of these:
 
:{{cmdroot|echo 0 > /sys/devices/platform/smapi/BAT0/force_discharge1}}
 
:{{cmdroot|echo 0 > /sys/devices/platform/smapi/BAT0/force_discharge2}}
 
 
 
===Battery status features===
 
To view exteded battery status such as charging state, voltage, current, capacity, cycle count and model information:
 
 
 
<pre>
 
# 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
 
</pre>
 
 
 
The raw status data is also available, including some fields not in the above (in case you can figure them out):
 
 
 
:{{cmdroot|cat /sys/devices/platform/smapi/BAT0/dump}}
 
 
 
In all of the above, replace <tt>BAT0</tt> with <tt>BAT1</tt> to address the 2nd battery.
 
 
 
Note that the battery status readout conflicts with the stock [[HDAPS|hdaps]] driver, so if you use <tt>hdaps</tt> you will need to load <tt>tp_smapi</tt> using {{cmdroot|1=make load HDAPS=1}}. See below.
 
 
 
===Optical drive control features===
 
 
 
To control the speed of the optical drive:
 
:{{cmdroot|echo 0 yes_crash_my_computer > /sys/devices/platform/smapi/cd_speed # slow}}
 
:{{cmdroot|echo 1 yes_crash_my_computer > /sys/devices/platform/smapi/cd_speed # medium}}
 
:{{cmdroot|echo 2 yes_crash_my_computer > /sys/devices/platform/smapi/cd_speed # fast}}
 
:{{cmdroot|cat /sys/devices/platform/smapi/cd_speed}}
 
{{WARN|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 <tt>#define PROVIDE_CD_SPEED</tt> at the top of <tt>tp_smapi.c</tt>. The safe way to set the drive speed is using <tt>hdparm -E num</tt> or <tt>eject -x num</tt> for CD-ROM, and [http://safari.iki.fi/speedcontrol.c speedcontrol -x num] for DVD. For kernels older than 2.6.15, this may require the [[Problems_with_SATA_and_Linux#No_SMART_support libata pass-through|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 <tt>hdaps</tt>===
 
The extended battery status function conflicts with the [[HDAPS|hdaps]] kernel module (they use the same IO ports).
 
 
 
You can use <tt>HDAPS=1</tt> (see Installation) to get a patched version of <tt>hdaps</tt> which is compatible with <tt>tp_smapi</tt>.
 
 
 
Otherwise:
 
 
 
If you load <tt>hdaps</tt> first, <tt>tp_smapi</tt> will disable its battery status functions (and log a message in the kernel log). If you load <tt>tp_smapi</tt> first, <tt>hdaps</tt> will refuse to load. To switch between the two, <tt>rmmod</tt> both and then load one you need.
 
 
 
Some of the battery status is also visible through ACPI ({{path|/proc/acpi/battery/*}}).
 
 
 
The charging control files (<tt>*_charge_thresh</tt>, <tt>inhibit_charge_minutes</tt> and <tt>force_discharge*</tt>) don't have this problem.
 
 
 
===Model-specific status===
 
 
 
{| border="1" cellpadding="2"
 
|+<tt>tp_smapi</tt> feature support matrix
 
|-
 
! &times;
 
! <tt>start_charge_<br />thresh</tt>
 
!          <tt>stop_charge_<br />thresh</tt>
 
!                      <tt>inhbit_charge_<br />minutes</tt>
 
!                                  <tt>cd_speed</tt><br \><font size="-2">(see note above)</font>
 
!                                                <tt>force_<br />discharge1</tt>
 
!                                                          <tt>force_<br />discharge2</tt>
 
!                                                                    battery status files<br \><font size="-2">(see note about <tt>hdaps</tt> above)</font>
 
|-
 
! {{G41}}
 
| {{Cyes}} || {{Cno}}  || {{Cyes}} || {{Cyes}} || {{Cunk}} || {{Cunk}} || {{Cunk}}
 
|-
 
! {{R40}}
 
| {{Cno}}  || {{Cno}}  || {{Cno}}  || {{Cyes}} || {{Cunk}} || {{Cunk}} || {{Cunk}}
 
|-
 
! {{R50p}}
 
| {{Cno}}  || {{Cno}}  || {{Cno}}  || {{Cyes}} || {{Cno}} || {{Cno}} || {{Cyes}}
 
|-
 
! {{R51}}
 
| {{Cyes}} || {{Cno}}  || {{Cyes}} || {{Cunk}} || {{Cunk}} || {{Cunk}} || {{Cyes}}
 
|-
 
! {{R52}}
 
| {{Cyes}} || {{Cyes}} || {{Cyes}} || {{Cyes}} || {{Cunk}} || {{Cunk}} || {{Cunk}}
 
|-
 
! {{T40}}
 
| {{Cno}}  || {{Cno}}  || {{Cno}}  || {{Cyes}} || {{Cunk}} || {{Cunk}} || {{Cyes}}
 
|-
 
! {{T40p}}
 
| {{Cno}}  || {{Cno}}  || {{Cno}}  || {{Cyes}} || {{Cno}}  || {{Cno}}  || {{Cyes}}
 
|-
 
! {{T41}}
 
| {{Cno}}  || {{Cno}}  || {{Cno}}  || {{Cyes}} || {{Cno}}  || {{Cno}}  || {{Cyes}}
 
|-
 
! {{T41p}}
 
| {{Cno}}  || {{Cno}}  || {{Cno}}  || {{Cyes}} || {{Cunk}} || {{Cunk}} || {{Cunk}}
 
|-
 
! {{T42}}
 
| {{Cyes}} || {{Cno}} || {{Cyes}} || {{Cyes}} || {{Cyes}} || {{Cno}} || {{Cyes}}
 
|-
 
! {{T42p}}
 
| {{Cyes}} || {{Cno}}  || {{Cyes}} || {{Cunk}} || {{Cunk}} || {{Cunk}} || {{Cunk}}
 
|-
 
! {{T43}}
 
| {{Cyes}} || {{Cyes}} || {{Cyes}} || {{Cyes}} || {{Cyes}} || {{Cno}}  || {{Cyes}}
 
|-
 
! {{T43p}}
 
| {{Cyes}} || {{Cyes}} || {{Cyes}} || {{Cyes}} || {{Cyes}} || {{Cno}} || {{Cyes}}
 
|-
 
! {{X24}}
 
| {{Cno}}  || {{Cno}}  || {{Cno}}  || {{Cunk}} || {{Cunk}} || {{Cunk}} || {{Cyes}}
 
|-
 
! {{X31}}
 
| {{Cno}}  || {{Cno}}  || {{Cno}}  || {{Cunk}} || {{Cunk}} || {{Cunk}} || {{Cyes}}
 
|-
 
! {{X32}}
 
| {{Cno}}  || {{Cno}}  || {{Cno}}  || {{Cunk}} || {{Cunk}} || {{Cunk}} || {{Cunk}}
 
|-
 
! {{X40}}
 
| {{Cyes}} || {{Cno}}  || {{Cyes}} || {{Cunk}} || {{Cunk}} || {{Cunk}} || {{Cyes}}
 
|-
 
! {{X41}}
 
| {{Cyes}} || {{Cyes}} || {{Cyes}} || {{Cunk}} || {{Cunk}} || {{Cunk}} || {{Cunk}}
 
|}
 
 
 
Please update the above and report your experience on the [[Talk:SMAPI support for Linux|discussion]] page. If the module loads but gives a "<tt>not supported</tt>" or "<tt>not implementeded</tt>" when you try to use some specific file in {{path|/sys/devices/platform/smapi/}}, please report the <tt>dmesg</tt> output and whether the corresponding functionality is available under Windows - maybe your ThinkPad just can't do that.
 
 
 
{{HELP|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 <tt>thinkpad</tt> module==
 
This solution consists of a module, called <tt>thinkpad</tt>, and a user-space tool caled <tt>tpctl</tt>. 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 <tt>tpctl</tt> >=4.14 and <tt>thinkpad </tt> >=5.5. For details, see the [http://tpctl.sourceforge.net/README README] and [http://tpctl.sourceforge.net/SUPPORTED-MODELS list of supported models].
 
 
 
* Project page: http://tpctl.sourceforge.net/
 
* You need to download the [http://sourceforge.net/project/showfiles.php?group_id=1212&package_id=29354t thinkpad module] and [http://sourceforge.net/project/showfiles.php?group_id=1212&package_id=1204 tpctl userspace tool].
 
* There is also an optional GUI: [http://sourceforge.net/project/showfiles.php?group_id=1212&package_id=99929 configure-thinkpad].
 
 
 
  
 
[[Category:Tools]] [[Category:Patches]]
 
[[Category:Tools]] [[Category:Patches]]

Latest revision as of 19:04, 7 January 2008

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 standard interfaces such as ACPI and APM.

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:

  • tp_smapi for newer ThinkPad models. This module provides battery information for models produced since 2001 and possibly earlier, and additional features for models produced since 2003.
  • tpctl with the thinkpad kernel modules worked on older ThinkPad models but are now obsolete: the drivers no longer build (with the latest Linux versions). On modern ThinkPads tpctl has been superseded by the standardized ACPI subsystem and the tp_smapi driver.