Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 346785 - app-laptop/tp_smapi needs an init script to set battery charging parameters
Summary: app-laptop/tp_smapi needs an init script to set battery charging parameters
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Mobile Herd (OBSOLETE)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-25 18:09 UTC by Sebastian Pipping
Modified: 2011-06-18 22:08 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
tp_smapi-0.40-r2.ebuild (tp_smapi-0.40-r2.ebuild,1.83 KB, text/plain)
2011-04-13 09:32 UTC, Henning Schild
Details
files/smapi.confd (smapi.confd,785 bytes, text/plain)
2011-04-13 09:33 UTC, Henning Schild
Details
files/smapi.initd (smapi.initd,1.20 KB, text/plain)
2011-04-13 09:33 UTC, Henning Schild
Details
files/smapi.initd (smapi,1.32 KB, text/plain)
2011-06-14 09:41 UTC, Henning Schild
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Pipping gentoo-dev 2010-11-25 18:09:37 UTC
These parameters should be set on boot time:

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

Please provide an init script to set these values.

I would use /etc/sysfs.conf as possible in Debian but it seems sysfsutils of Gentoo does not support that.  For details, this is what I mean:
http://www.thinkwiki.org/wiki/Tp_smapi#Making_the_settings_permanent_on_reboot

Thanks!
Comment 1 Henning Schild 2011-04-13 09:31:08 UTC
Good idea i usually used /etc/init.d/local.start for this but a dedicated script seems appropriate. Especially since it can support more than one setting.

The script i wrote should support more than one battery but is tested with only one. On start it will set up default values from the conf.d file. Additionally it offers a 'low' and 'high' mode. The values in the conf.d file are what i am using, i think i got the numbers for the default/low mode from the thinkwiki once.
Comment 2 Henning Schild 2011-04-13 09:32:22 UTC
Created attachment 269771 [details]
tp_smapi-0.40-r2.ebuild

ebuild based on tp_smapi-0.40-r1.ebuild
Comment 3 Henning Schild 2011-04-13 09:33:12 UTC
Created attachment 269773 [details]
files/smapi.confd
Comment 4 Henning Schild 2011-04-13 09:33:37 UTC
Created attachment 269775 [details]
files/smapi.initd
Comment 5 Sebastian Pipping gentoo-dev 2011-06-14 01:08:24 UTC
hello Henning,

first: sorry for not getting back to you earlier,
and thanks for your contribution!

Your work looks excellent so far.  Comments:

 - Your init script seems to miss licensing.
   Please apply "GPL v2 or later" and mention yourself as the author
   at the top of files/smapi.initd.  I propose this specific license
   for compatibility with tp_smapi itself.

 - In function set_all I would like to see use of new variables for
   $1 and $2 to make the code a bit cleaner:
     local tstart=$1
     local tstop=$2

 - The defaults of 40/70 should be 30/85 if following
   http://www.thinkwiki.org/wiki/Maintenance#Battery_treatment
   My vote on 30/83 for default.

 - I would love to see support for
     /sys/devices/platform/smapi/BAT*/force_discharge
   through a new action "discharge".  Other actions
   should reset force_discharge properly, too.

I am looking forward to an updated version.
Comment 6 Henning Schild 2011-06-14 09:41:00 UTC
Created attachment 277003 [details]
files/smapi.initd

update to init script
Comment 7 Henning Schild 2011-06-14 10:01:39 UTC
Hi Sebastian,

i addressed your first two points in the init script. I did not put my name in it. If it goes into the tree feel free to mention me in the Changelog.
The third point is a trivial change to the default config. I am fine with the default values you suggested. I was using an older version of the thinkwiki suggestion.

I did not implement the force discharge. Mainly because that is a feature i never used myself. Following the thinkwiki one should maybe discharge every 30 cycles. Looking at my thinkpads that would be once or twice a year. Then you would want to pick one of several batteries instead of discharging all of them.
To sum it up, i think that would be a feature for a more generic battery tool. i.e. not gentoo specific and not an init script.
If you still want to add it, go ahead.
Comment 8 Sebastian Pipping gentoo-dev 2011-06-14 15:36:14 UTC
(In reply to comment #7)
> i addressed your first two points in the init script. I did not put my name in
> it. If it goes into the tree feel free to mention me in the Changelog.

As I did later changes myself, I added my name and added yours too,
because otherwise it looks like my work only.


> The third point is a trivial change to the default config. I am fine with the
> default values you suggested. I was using an older version of the thinkwiki
> suggestion.

Alright, updated.

Other changes I did:
- Add modprobe tp_smapi to start()
- Make high()/low()/info() require a started service
- Operate on levels of absent batteries too
  (as that battery may be inserted later and writing the level
  works fine even before that)
- Indicate battery presence in info()

If you have any patches against the init script in the future,
just re-open this bug and attach the patch to it.  Thanks!


+*tp_smapi-0.40-r2 (14 Jun 2011)
+
+  14 Jun 2011; Sebastian Pipping <sping@gentoo.org> +tp_smapi-0.40-r2.ebuild,
+  +files/tp_smapi-0.40-confd, +files/tp_smapi-0.40-initd:
+  Add init script, main work by Henning Schild (bug #346785)
+
Comment 9 Henning Schild 2011-06-18 09:10:45 UTC
The new version of the init script in 0.40-r3 checks status1 twice instead of checking status2 as well.

/etc/init.d/smapi:30
>        if [ "${state1}" -ne "0" ] || [ "${state1}" -ne "0" ]; then
Comment 10 Sebastian Pipping gentoo-dev 2011-06-18 16:34:56 UTC
(In reply to comment #9)
> The new version of the init script in 0.40-r3 checks status1 twice instead of
> checking status2 as well.
> 
> /etc/init.d/smapi:30
> >        if [ "${state1}" -ne "0" ] || [ "${state1}" -ne "0" ]; then

Sorry, but I fail to make sense of this.
Please provide a patch against 0.40-r2.  Thanks!
Comment 11 Henning Schild 2011-06-18 17:39:36 UTC
- if [ "${state1}" -ne "0" ] || [ "${state1}" -ne "0" ]; then
+ if [ "${state1}" -ne "0" ] || [ "${state2}" -ne "0" ]; then
                                         -^-
Comment 12 Sebastian Pipping gentoo-dev 2011-06-18 22:08:12 UTC
(In reply to comment #11)
> - if [ "${state1}" -ne "0" ] || [ "${state1}" -ne "0" ]; then
> + if [ "${state1}" -ne "0" ] || [ "${state2}" -ne "0" ]; then
>                                          -^-

Alright, thanks.  Actually I didn't expect anyone else to touch the script in the mean time.  Seems like that happened.  Reported error seems fixed by now:

  18 Jun 2011; Tomáš Chvátal <scarabeus@gentoo.org>
  files/tp_smapi-0.40-initd:
  Fix doublechecking of one variable. state1 instead of state2. Could someone
  check if we allow headers like this for initscripts?