Page 1 of 1

Newbie, Mint on T42, battery drains - won't charge?

Posted: Fri Nov 28, 2008 3:02 pm
by DaveG11th
The lost newbie is back...

Installed Mint, but running it with the ac adapter just drains the battery. I can't find any settings in Mint to set upper and lower charging threshholds. I have to reboot to Windows XP to get the battery to charge again.

I Googled for answers - but came up only with tp smapi. Every discussion mentions installing, but none say how, and I can't find the exe? package? in the Mint Package Handler.

There is a 'sh' file in Thinkwikie dealing with tp smapi, but no word on how to install it.

One discussion mention the need to recompile, but I cannot find a development language in my Mint whatever-it-is (similar in functionality to Windows Start Menu). In any case, I wouldn't know what to recompile, even if I could find a language or compiler.

Is there something I (emphasis on newb-I) can download and install so that my T42 battery will charge under Mint?

Posted: Sun Nov 30, 2008 12:56 pm
by DaveG11th
OK - now it's NOT doing this - instead shows an icon with a plug superimposed on a battery, and hovering gives me info on battery charge and (when on AC) notification that it's running on AC.

I have no idea what's changed.

Meanwhile, I still don't know how to stop charging the battery when it reaches 80%, start at 50%... any pointers are welcome.

Posted: Sun Nov 30, 2008 10:55 pm
by Superego
Sorry about the erratic charging....I have no idea what could be causing that. Regarding the battery thresholds you'll need the tp_smapi kernel module. You can check out http://www.thinkwiki.org for more details. Once you have that set up you can add the following lines to your local startup script:

Code: Select all

#Set battery thresholds
echo 30 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 85 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
This sets my battery to start charging when below 30% and stops at 85%.

Hope this helps.

Posted: Mon Dec 01, 2008 2:29 am
by DaveG11th
Superego wrote:Sorry about the erratic charging....I have no idea what could be causing that. Regarding the battery thresholds you'll need the tp_smapi kernel module. You can check out http://www.thinkwiki.org for more details.
Thanks for the pointers -- I'm going to assume that the charging thing has somehow healed itself.

Unfortunatelly, total newbie here. I've been to both the thinkwiki and mintwiki entries, and I fear that they're opaque to me. For example, I don't know how to download a kernel module other than through the mint package handler, and tp_smapi doesn't come up in a search there. Also, since Mint is based on Ubuntu, shouldn't it already be in my possession?

In any case, where do I find out how to set it up in the kernel? Do I have to recompile something? Deer in headlights look.. :shock:

I'm trying to find resources. Linux for Dummies doesn't cover Ubuntu or Mint, and 8th Edition gets terrible reviews. Books in general -- it won't take many to add up to the cost of a Windows license...
Once you have that set up you can add the following lines to your local startup script:

Code: Select all

#Set battery thresholds
echo 30 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 85 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
This sets my battery to start charging when below 30% and stops at 85%.

Hope this helps.
The code looks easy enough, but how do I find my startup script -- do I use the Mint text editor and open an (?) equivalent of a DOS BAT file, or do I use the 'terminal' with some sort of command? If the former, what's the name of the file, and where is it? If the latter, what's the command?

Sorry about this, but I'm so much a beginner that I need my hand held the whole way... or a pointer or links.

All my Googling so far has plunged me into terminology that's still foreign to me... and I hear only my own voice when I taught English long ago: 'If you don't know the meaning of the words, how can you know the meaning of a sentence, paragraph, passage? C'mon guys, just look them up.' Problem is, I can't find where to look them up...

Posted: Mon Dec 01, 2008 8:08 am
by aaa
Assuming you have a recent version of Mint, it should already be there. Look for the /sys/devices/platform/smapi directory, if it does not exist then you need to load the driver like so: "sudo modprobe tp_smapi". Once the directory's there, you just run the echo commands Superego mentioned to change the thresholds.

Posted: Mon Dec 01, 2008 8:17 am
by DaveG11th
Thanks!

Where do I enter "sudo modprobe tp_smapi"?

(Apologies again, total Mint / Linux newbie).

Posted: Mon Dec 01, 2008 11:48 am
by Superego
To load a kernel module in Linux you enter the following in a terminal:

Code: Select all

sudo modprobe tp_smapi 
Of course if you wanted to load a different module you would replace tp_smapi with the appropriate module.

You can use the 'lsmod' command to view the status of loaded kernel modules. For example:

Code: Select all

lsmod | grep tp_smapi
will execute the lsmod command and search for and print all lines with the phrase 'tp_smapi' in it. The | command simply pipes/redirects the output of grep (which searches for the printed line tp_smapi)

Once the module is loaded check that you have the smapi directory:

Code: Select all

ls /sys/devices/platform/smapi
You should see the BAT0 directory.

In a terminal execute the following commands (either as root or using sudo):

Code: Select all

echo 30 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 85 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh 
To check enter the following commands:

Code: Select all

cat /sys/devices/platform/smapi/BAT0/start_charge_thresh
cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh 
You should see the values you set.

To get this to all happen automatically you'll need to do 2 things:
1) Get the tp_smapi module to load at boot
2) Set battery thresholds in local startup script.

Note that you will need to edit some files as root. Any text editor will be fine (I prefer vi, but nano is a little more forgiving, and gedit is good for beginners). If you don't edit via the command line (e.g. using vi or nano) but rather with a GUI text editor (e.g. gedit) you'll want to use the following command to edit

Code: Select all

gksudo gedit /path/to/file
gksudo is simply a graphical sudo. You should use gksudo for applications and sudo for command-line actions. The reasons are outside the scope of this thread but pm me if you have questions.

To be safe I would backup the original files before editing (it's a good practice when editing system config files). You can do

Code: Select all

sudo cp /path/to/file /path/to/file.bak
to make a copy of the file before editing.


1) Load module on boot
Assuming the tp_smapi module loads with modprobe, you can add tp_smapi to the end of the /etc/modules file. You may want to double check this with someone (or better yet, check the ubuntu/mint forums) because my Arch Linux loads modules in a different way and I'm a little fuzzy on modules in other distros.

2) Add commands to /etc/rc.local
To set the thresholds automatically you have some options. I'm going to describe one method but know that there are several ways to accomplish the same thing.

This is where I put all of my homemade commands/scripts that I run at startup. I put them all here so that I can easily keep track of them and also so they don't get mixed in with other scripts (aka those that I didn't write and Arch Linux installed).

Backup the original rc.local file:

Code: Select all

sudo cp /etc/rc.local /etc/rc.local.bak
Now you just need to add the two lines from above to /etc/rc.local:

Code: Select all

echo 30 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 85 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh 
It doesn't matter where, just as long as it is before the "exit 0" line. I would also add a comment so you know what you've done for future reference (the '#' symbol denotes a comment.

To sum up, here's what your rc.local file should look like:

Code: Select all

#!/bin/sh
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the
# execution bits.
#
# By default this script does nothing.

# Set battery thresholds
echo 30 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 85 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh

exit 0
In case Mint doesn't have this script you can create a file called rc.local in /etc, copy and paste the above code into it, save it.

Now that you have your rc.local script you need to make it executable:

Code: Select all

sudo chmod +x /etc/rc.local
Reboot and check that the script worked:

Code: Select all

cat /sys/devices/platform/smapi/BAT0/start_charge_thresh
cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh 
You should see the values you set.

Let me know if this worked. If not we have some other options, but we'll worry about that when we need to.

Posted: Mon Dec 01, 2008 1:15 pm
by DaveG11th
Superego - thanks for taking the time to spell all this out. Believe, me, it's much appreciated, and I'll be working my way through the steps later today.

Posted: Mon Dec 01, 2008 2:54 pm
by DaveG11th
Something seems to have gone awry -- everything works up to the 'cat' entries, exactly as you spelled out.

,,,, whoops, for some reason, I can't back up in the terminal and copy text...

Cat for start_charge_thresh returns 96 (where echo had the right one I'm trying, 50)
Cat for stop_charge-thresh returns Operation not supported.(echo was for 85)

Dave[/code]

Posted: Mon Dec 01, 2008 3:26 pm
by Superego
So when you manually change the thresholds, that is you enter the commands:

Code: Select all

echo 50 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 85 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh 
and then check that the thresholds have been set, using the commands:

Code: Select all

cat /sys/devices/platform/smapi/BAT0/start_charge_thresh
cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh 
everything checks out ok?

Posted: Mon Dec 01, 2008 3:41 pm
by DaveG11th
My echo lines (your first code formatting) are exactly as you have them -

The cat lines (your second code section) returns 96 and Operation not supported, so the threshholds are not being set by my typing in the terminal.

Posted: Mon Dec 01, 2008 4:00 pm
by Superego
Probably should've looked at this before-hand, but your T42 doesn't suuport the stop_charge_thresh option; it does support the start_charge_thresh option.

Check out the support matrix at
http://www.thinkwiki.org/wiki/Tp_smapi# ... fic_status

Posted: Mon Dec 01, 2008 4:24 pm
by DaveG11th
Ah well, looks as though I'll drop the effort. I'd rather not go to 100%, so I'll have to watch this manually.

Meanwhile, I've learned at least a little.

Thanks for your help.

Re: Newbie, Mint on T42, battery drains - won't charge?

Posted: Fri Mar 26, 2010 2:26 am
by toad
I've just come across tp_smapi (am on ArchLinux) and found this thread googling.

I've got a trusty T41 and the support matrix states that stop_charge_thresh is not supported. This IS a bummer, it was just what the doctor ordered...

Are there perhaps any workarounds, BIOS upgrades or some such to convince this old man not to overcharge?

Re: Newbie, Mint on T42, battery drains - won't charge?

Posted: Wed Apr 14, 2010 10:58 am
by toad
Okay, I found the solution. For all those who like me own a partially supported tp_smapi thinkpad, go here. I wrote it up on the Arch Wiki.