Difference between revisions of "Tp smapi"

From ArchWiki
Jump to: navigation, search
(2nd Option)
(style)
 
(22 intermediate revisions by 15 users not shown)
Line 1: Line 1:
 +
{{DISPLAYTITLE:tp_smapi}}
 
[[Category:Laptops]]
 
[[Category:Laptops]]
 
[[Category:Kernel]]
 
[[Category:Kernel]]
tp_smapi is a set of kernel modules that retrieves information from and conveys commands to the hardware of ThinkPad laptops. This information is presented through the {{ic|/sys/devices/platform/smapi}} filesystem.  Much like the {{ic|/proc}} filesystem, you can read and write information to these files to get information about and send commands to the hardware. tp_smapi is highly recommended if you're using a ThinkPad laptop.
+
[[ja:tp_smapi]]
 +
tp_smapi is a set of kernel modules that retrieves information from and conveys commands to the hardware of many ThinkPad laptops.
 +
This information is presented through the {{ic|/sys/devices/platform/smapi}} filesystem.  Much like the {{ic|/proc}} filesystem,
 +
you can read and write information to these files to get information about and send commands to the hardware.
 +
tp_smapi is highly recommended if you're using a supported ThinkPad laptop.
  
==Supported Laptops==
+
== Supported laptops ==
First check whether your laptop is supported. Thinkwiki has a comprehensive [http://www.thinkwiki.org/wiki/Tp_smapi#Model-specific_status list of all supported Thinkpads.] In case your TP does not support stop_threshold but only start_threshold please go here [[Tp_smapi#Workaround for Partially Supported Laptops]] for a decent workaround.
 
  
If you are installing on a recent Thinkpad that has an Ivy Bridge processor (X230, T430, T530, etc.), tp_smapi will not work. Use [https://aur.archlinux.org/packages.php?ID=54293 tpacpi-bat] or [https://aur.archlinux.org/packages/tpacpi-bat-git tpacpi-bat-git].
+
First check whether your laptop is supported. Thinkwiki has a comprehensive [http://www.thinkwiki.org/wiki/Tp_smapi#Model-specific_status list of all supported Thinkpads.]
 +
In case your TP does not support stop_threshold but only start_threshold please go here [[#Workaround for Partially Supported Laptops]] for a decent workaround.
  
==Installation==
+
If you are installing on a recent Thinkpad that has an Ivy Bridge processor or later (any of the {{ic|*30}},
[[pacman|Install]] the {{Pkg|tp_smapi}} package that recently moved to the community repository.
+
{{ic|*40}} or {{ic|*50}} models), tp_smapi will not work. Use {{Pkg|tpacpi-bat}} or {{AUR|tpacpi-bat-git}}.
  
It's providing you 3 new [[Kernel modules]].
+
== Installation ==
  
{| align="center" style="width:100%; border:1px #0771a6 solid; background:#f9f9f9; text-align:left; border-collapse:collapse;"
+
[[Install]] the {{Pkg|tp_smapi}} package. For the custom [[linux-ck]] kernel there is {{AUR|tp_smapi-ck}} in the [[AUR]].
|- style="background:#333333; color:#ffffff; font-size: 0.9em; text-align:center;"
+
 
| colspan="2" | '''Kernel Module'''
+
It provides you 3 [[Kernel modules]]:
|- style="background:#333333; color:#ffffff; font-size: 0.9em; text-align:center;"
+
 
| width="30%" |Name
+
{| class="wikitable"
|             |Description
+
|tp_smapi
 +
|ThinkPad SMAPI Support
 
|-
 
|-
|tp_smapi
 
|
 
ThinkPad SMAPI Support
 
|- style="border-top:1px solid #aaaaaa;"
 
 
|hdaps
 
|hdaps
|
+
|IBM Hard Drive Active Protection System ([[HDAPS]]) driver
IBM Hard Drive Active Protection System ([[HDAPS]]) driver
+
|-
|- style="border-top:1px solid #aaaaaa;"
 
 
|thinkpad_ec
 
|thinkpad_ec
|
+
|ThinkPad embedded controller hardware access (tp_smapi and hdaps both depend on it)
ThinkPad embedded controller hardware access (tp_smapi and hdaps both depend on it)
 
 
|}
 
|}
  
After a reboot tp_smapi and it's dependencys will get autoloaded and the sysfs-interface under {{ic|/sys/devices/platform/smapi}} should be fully functional.
+
After a reboot, tp_smapi and its dependencies will get autoloaded and the sysfs-interface under {{ic|/sys/devices/platform/smapi}} should be fully functional.
  
==Features==
+
== Features ==
Here are a couple of useful things you can do using tp_smapi.  Please feel free to add your own.
 
  
===Control Battery Charging===
+
Here are a couple of useful things you can do using tp_smapi.
  
[http://www.thinkwiki.org/wiki/Maintenance#Battery_treatment It's bad for most laptop batteries to hold a full charge for long periods of time.]  You should try to keep your battery in the 40-80% charged range, unless you need the battery life for extended periods of time.
+
=== Control battery charging ===
  
====General Way====
+
It's bad for most laptop batteries to hold a full charge for long periods of time. [http://www.thinkwiki.org/wiki/Maintenance#Battery_treatment]
 +
You should try to keep your battery in the 40-80% charged range, unless you need the battery life for extended periods of time.
 +
 
 +
==== General way ====
  
 
tp_smapi lets you control the start and stop charging threshold to do just that.  Run these commands to set these to good values:
 
tp_smapi lets you control the start and stop charging threshold to do just that.  Run these commands to set these to good values:
 +
 
  echo 40 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
 
  echo 40 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
 
  echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
 
  echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
This will cause the battery to begin charging when it falls below 40% charge and stop charging once it exceeds 80% charge.  This will extend the lifetime of your battery.
 
  
Note that when you remove and re-insert the battery, these thresholds may be reset to their default values. To work around this, create a script to set these values, and make this script run both at startup and when a battery is inserted. More specific instructions follow.
+
This will cause the battery to begin charging when it falls below 40% charge and stop charging once it exceeds 80% charge. This will extend the lifetime of your battery.
 +
 
 +
Note that when you remove and re-insert the battery, these thresholds may be reset to their default values.
 +
To work around this, create a script to set these values, and make this script run both at startup and when a battery is inserted.
 +
More specific instructions follow.
  
 
Create a script {{ic|/usr/sbin/set_battery_thresholds}}:
 
Create a script {{ic|/usr/sbin/set_battery_thresholds}}:
 +
 
  #!/bin/sh
 
  #!/bin/sh
 
  # set the battery charging thresholds to extend battery lifespan
 
  # set the battery charging thresholds to extend battery lifespan
Line 57: Line 64:
 
  echo ${3:-80} > /sys/devices/platform/smapi/BAT${1:-0}/stop_charge_thresh
 
  echo ${3:-80} > /sys/devices/platform/smapi/BAT${1:-0}/stop_charge_thresh
  
With this script to set a battery threshold is very simple,
+
Make it [[executable]]. With this script to set a battery threshold is very simple,
 
just type (if set_bat_thresh is the name of the script):
 
just type (if set_bat_thresh is the name of the script):
 +
 
  set_battery_thresholds 0 96 100
 
  set_battery_thresholds 0 96 100
 +
 
Or run it with no arguments to default to BAT0, and thresholds of 40% and 80%.
 
Or run it with no arguments to default to BAT0, and thresholds of 40% and 80%.
  
NB: if you let the battery discharge below 40%, you will get problems, since it is not charged anymore. A solution consists in setting only the parameter stop_charge_thresh and control manually the lower battery value.
+
Let [[systemd]] execute the script at startup (Using rc.local from initscripts is deprecated).
 +
Thus, create {{ic|/etc/systemd/system/tp_smapi_set_battery_thresholds.service}}:
  
Set it runnable:
+
[Unit]
  [root ~]# '''chmod 744 /usr/sbin/set_battery_thresholds'''
+
Description=Set Battery Charge Thresholds by tp_smapi
 +
 +
  [Service]
 +
Type=oneshot
 +
ExecStart=/usr/sbin/set_battery_thresholds
 +
RemainAfterExit=yes
 +
 +
[Install]
 +
WantedBy=multi-user.target
  
Let [[systemd]] execute the script at startup (Using rc.local from initscripts is deprecated). Thus, create {{ic|/etc/systemd/system/tp_smapi_set_battery_thresholds.service}}:
+
Enable it in systemd:
{{bc|<nowiki>
 
[Unit]
 
Description=Set Battery Charge Thresholds by tp_smapi
 
  
[Service]
+
# systemctl enable tp_smapi_set_battery_thresholds.service
Type=oneshot
 
ExecStart=/usr/sbin/set_battery_thresholds
 
RemainAfterExit=yes
 
  
[Install]
+
You can also make it run when a battery is inserted. This requires that [[acpid]] is installed and running. Edit {{ic|/etc/acpi/handler.sh}}:
WantedBy=multi-user.target
 
</nowiki>}}
 
  
Enable it in systemd:
 
[root ~]# '''systemctl enable tp_smapi_set_battery_thresholds.service'''
 
 
You can also make it run when a battery is inserted.  This requires that [[acpid]] is installed and running.  Edit {{ic|/etc/acpi/handler.sh}}:
 
 
  #... other ACPI stuff
 
  #... other ACPI stuff
 
  battery)
 
  battery)
Line 97: Line 103:
 
  #... more ACPI stuff
 
  #... more ACPI stuff
  
====Check whether settings were accepted====
+
==== Check whether settings were accepted ====
To check whether your settings were accepted check the output of the following:  
+
 
 +
To check whether your settings were accepted check the output of the following:
 +
 
 
  cat /sys/devices/platform/smapi/BAT0/start_charge_thresh
 
  cat /sys/devices/platform/smapi/BAT0/start_charge_thresh
 
  cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh
 
  cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh
  
===Protect the Hard Disk from Drops===
+
=== Protect the hard disk from drops ===
tp_smapi includes a driver to read the accelerometer in your laptop to detect drops and other events that could cause damage to your hard drive. See the [[HDAPS]] page for more information on this useful feature.
+
 
 +
tp_smapi includes a driver to read the accelerometer in your laptop to detect drops and other events that
 +
could cause damage to your hard drive. See the [[HDAPS]] page for more information on this useful feature.
 +
 
 +
== Workaround for partially supported laptops ==
 +
 
 +
For partially supported laptops you can still gain control over your battery.
 +
First check what is actually supported:
  
==Workaround for Partially Supported Laptops==
 
For partially supported laptops you can still gain control over your battery. First check what is actually supported:
 
 
  cat /sys/devices/platform/smapi/BAT0/start_charge_thresh
 
  cat /sys/devices/platform/smapi/BAT0/start_charge_thresh
 
  cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh
 
  cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh
  
If start-charge_thresh is supported but not stop_charge_thresh but you still want to have your computer stop charging your battery you have two options.
+
If start-charge_thresh is supported but not stop_charge_thresh but you still
 +
want to have your computer stop charging your battery you have two options.
  
Note : none of the two options works on T42p.
+
Note: None of the two options works on T42p.
  
===1st Option===
+
=== 1st option ===
  
 
* create the script {{ic|/usr/sbin/set_battery_thresholds}} as above  
 
* create the script {{ic|/usr/sbin/set_battery_thresholds}} as above  
 
* copy the original {{ic|/etc/acpi/handler.sh}} to {{ic|/etc/acpi/handler.sh.start}}
 
* copy the original {{ic|/etc/acpi/handler.sh}} to {{ic|/etc/acpi/handler.sh.start}}
 
* edit {{ic|/etc/acpi/handler.sh}} as above and copy it to {{ic|/etc/acpi/handler.sh.stop}}
 
* edit {{ic|/etc/acpi/handler.sh}} as above and copy it to {{ic|/etc/acpi/handler.sh.stop}}
Now copy the following script, make it executable, adjust the values to your liking and run it every couple of minutes as a root cron.
 
{{bc|<nowiki>
 
#!/bin/bash
 
  
CURRENTCHARGE=$(acpitool -b | cut -d, -f2 | cut -d. -f1 | cut -b2-)
+
Now copy the following script, make it executable, adjust the values
 +
to your liking and run it every couple of minutes as a root cron.
  
if [ $CURRENTCHARGE -gt 80 ]; then
+
#!/bin/bash
    cp /etc/acpi/handler.sh.stop /etc/acpi/handler.sh
+
    echo 99 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
+
CURRENTCHARGE=$(acpitool -b | cut -d, -f2 | cut -d. -f1 | cut -b2-)
    exit 0
+
fi
+
if [ $CURRENTCHARGE -gt 80 ]; then
if [ $CURRENTCHARGE -lt 60 ]; then
+
    cp /etc/acpi/handler.sh.stop /etc/acpi/handler.sh
    cp /etc/acpi/handler.sh.start /etc/acpi/handler.sh     
+
    echo 99 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
    echo 99 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
+
    exit 0
    echo 0 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
+
fi
    exit 0  
+
if [ $CURRENTCHARGE -lt 60 ]; then
fi
+
    cp /etc/acpi/handler.sh.start /etc/acpi/handler.sh     
 +
    echo 99 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
 +
    echo 0 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
 +
    exit 0  
 +
fi
 +
 +
exit 0
  
exit 0
+
=== 2nd option ===
</nowiki>}}
 
  
===2nd Option===
+
To control the battery charging thresholds, install the Perl script {{Pkg|tpacpi-bat}} or {{AUR|tpacpi-bat-git}} from the AUR.
  
To control the battery charging thresholds, install the Perl script [https://aur.archlinux.org/packages.php?ID=54293 tpacpi-bat] or [https://aur.archlinux.org/packages/tpacpi-bat-git tpacpi-bat-git] from the AUR.
+
Manually set the thresholds by calling
  
Insert the acpi_call kernel module by running
+
tpacpi-bat -v -s startThreshold 0 40
  modprobe acpi_call
+
  tpacpi-bat -v -s stopThreshold 0 80
or by adding it to the MODULES array in /etc/rc.config.
 
  
Manually set the thresholds by calling
+
The example values 40 and 80 given here are in percent of the full battery capacity. Adjust them to your own needs.
perl /usr/lib/perl5/vendor_perl/tpacpi-bat -v startChargeThreshold 0 40
+
You may also want to add these lines to /etc/rc.local to set the at startup. While these values should be permanent,
perl /usr/lib/perl5/vendor_perl/tpacpi-bat -v stopChargeThreshold 0 80
+
they will be reset any time the battery is removed.
The example values 40 and 80 given here are in percent of the full battery capacity. Adjust them to your own needs. You may also want to add these lines to /etc/rc.local to set the at startup. While these values should be permanent, they will be reset any time the battery is removed.
 
  
 
{{Note|See tpacpi-bat help for the list of commands: {{ic|perl /usr/lib/perl5/vendor_perl/tpacpi-bat -h}}.}}
 
{{Note|See tpacpi-bat help for the list of commands: {{ic|perl /usr/lib/perl5/vendor_perl/tpacpi-bat -h}}.}}
  
==See Also==
+
== See also ==
 
[http://www.thinkwiki.org/wiki/Tp_smapi tp_smapi on ThinkWiki]
 
[http://www.thinkwiki.org/wiki/Tp_smapi tp_smapi on ThinkWiki]

Latest revision as of 17:29, 1 July 2017

tp_smapi is a set of kernel modules that retrieves information from and conveys commands to the hardware of many ThinkPad laptops. This information is presented through the /sys/devices/platform/smapi filesystem. Much like the /proc filesystem, you can read and write information to these files to get information about and send commands to the hardware. tp_smapi is highly recommended if you're using a supported ThinkPad laptop.

Supported laptops

First check whether your laptop is supported. Thinkwiki has a comprehensive list of all supported Thinkpads. In case your TP does not support stop_threshold but only start_threshold please go here #Workaround for Partially Supported Laptops for a decent workaround.

If you are installing on a recent Thinkpad that has an Ivy Bridge processor or later (any of the *30, *40 or *50 models), tp_smapi will not work. Use tpacpi-bat or tpacpi-bat-gitAUR.

Installation

Install the tp_smapi package. For the custom linux-ck kernel there is tp_smapi-ckAUR in the AUR.

It provides you 3 Kernel modules:

tp_smapi ThinkPad SMAPI Support
hdaps IBM Hard Drive Active Protection System (HDAPS) driver
thinkpad_ec ThinkPad embedded controller hardware access (tp_smapi and hdaps both depend on it)

After a reboot, tp_smapi and its dependencies will get autoloaded and the sysfs-interface under /sys/devices/platform/smapi should be fully functional.

Features

Here are a couple of useful things you can do using tp_smapi.

Control battery charging

It's bad for most laptop batteries to hold a full charge for long periods of time. [1] You should try to keep your battery in the 40-80% charged range, unless you need the battery life for extended periods of time.

General way

tp_smapi lets you control the start and stop charging threshold to do just that. Run these commands to set these to good values:

echo 40 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh

This will cause the battery to begin charging when it falls below 40% charge and stop charging once it exceeds 80% charge. This will extend the lifetime of your battery.

Note that when you remove and re-insert the battery, these thresholds may be reset to their default values. To work around this, create a script to set these values, and make this script run both at startup and when a battery is inserted. More specific instructions follow.

Create a script /usr/sbin/set_battery_thresholds:

#!/bin/sh
# set the battery charging thresholds to extend battery lifespan
echo ${2:-40} > /sys/devices/platform/smapi/BAT${1:-0}/start_charge_thresh
echo ${3:-80} > /sys/devices/platform/smapi/BAT${1:-0}/stop_charge_thresh

Make it executable. With this script to set a battery threshold is very simple, just type (if set_bat_thresh is the name of the script):

set_battery_thresholds 0 96 100

Or run it with no arguments to default to BAT0, and thresholds of 40% and 80%.

Let systemd execute the script at startup (Using rc.local from initscripts is deprecated). Thus, create /etc/systemd/system/tp_smapi_set_battery_thresholds.service:

[Unit]
Description=Set Battery Charge Thresholds by tp_smapi

[Service]
Type=oneshot
ExecStart=/usr/sbin/set_battery_thresholds
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Enable it in systemd:

# systemctl enable tp_smapi_set_battery_thresholds.service

You can also make it run when a battery is inserted. This requires that acpid is installed and running. Edit /etc/acpi/handler.sh:

#... other ACPI stuff
battery)
  case "$2" in
    BAT0)
      case "$4" in
        00000000)
        ;;
        00000001)
        /usr/sbin/set_battery_thresholds
        ;;
#... more ACPI stuff

Check whether settings were accepted

To check whether your settings were accepted check the output of the following:

cat /sys/devices/platform/smapi/BAT0/start_charge_thresh
cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh

Protect the hard disk from drops

tp_smapi includes a driver to read the accelerometer in your laptop to detect drops and other events that could cause damage to your hard drive. See the HDAPS page for more information on this useful feature.

Workaround for partially supported laptops

For partially supported laptops you can still gain control over your battery. First check what is actually supported:

cat /sys/devices/platform/smapi/BAT0/start_charge_thresh
cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh

If start-charge_thresh is supported but not stop_charge_thresh but you still want to have your computer stop charging your battery you have two options.

Note: None of the two options works on T42p.

1st option

  • create the script /usr/sbin/set_battery_thresholds as above
  • copy the original /etc/acpi/handler.sh to /etc/acpi/handler.sh.start
  • edit /etc/acpi/handler.sh as above and copy it to /etc/acpi/handler.sh.stop

Now copy the following script, make it executable, adjust the values to your liking and run it every couple of minutes as a root cron.

#!/bin/bash

CURRENTCHARGE=$(acpitool -b | cut -d, -f2 | cut -d. -f1 | cut -b2-)

if [ $CURRENTCHARGE -gt 80 ]; then
    cp /etc/acpi/handler.sh.stop /etc/acpi/handler.sh
    echo 99 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
    exit 0
fi
if [ $CURRENTCHARGE -lt 60 ]; then
    cp /etc/acpi/handler.sh.start /etc/acpi/handler.sh    
    echo 99 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
    echo 0 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
    exit 0 
fi

exit 0

2nd option

To control the battery charging thresholds, install the Perl script tpacpi-bat or tpacpi-bat-gitAUR from the AUR.

Manually set the thresholds by calling

tpacpi-bat -v -s startThreshold 0 40
tpacpi-bat -v -s stopThreshold 0 80

The example values 40 and 80 given here are in percent of the full battery capacity. Adjust them to your own needs. You may also want to add these lines to /etc/rc.local to set the at startup. While these values should be permanent, they will be reset any time the battery is removed.

Note: See tpacpi-bat help for the list of commands: perl /usr/lib/perl5/vendor_perl/tpacpi-bat -h.

See also

tp_smapi on ThinkWiki