LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 02-08-2011, 02:14 AM   #1
MrPolite
Member
 
Registered: Jun 2002
Location: Middle of nowhere
Posts: 109

Rep: Reputation: 15
(smart battery) Obtaining the SMBus offset to use with ec_write() and ec_read()?


Hi everyone,
total linux noob here, so please bare with me I have several questions.

I'm trying to figure out a way to use the SMBus link to talk to the smart battery, but if I understand correctly on most new laptops I have to go through the "embedded controller" in order to talk to smart battery. I've tried i2c-dev interface to see if I can find the smart battery on the SMBus link but with no luck.


The 'sbshc' module under drivers/acpi/ talks to the embedded controller. I want to do the same in my own LKM but I cannot figure out how to get the offset/address that I should pass to ec_read()/ec_write(). In 'sbshc' they use the device handle that's passed to them in acpi_smbus_hc_add() to get this offset.... so I figured I can look at the logs at /var/log/messages to simply get this offset, but for some reason acpi_smbus_hc_add() is never called when I load 'sbshc' (I recompiled the kernel to make sbs and sbshc loadable modules).

So my questions are:
1) Anyone knows how I can obtain the embedded controller 'address' that I need to pass to ec_write() and ec_read() functions?

2) When should the system call acpi_smbus_hc_add()?
The module init function is called and acpi_bus_register_driver() succeeds in the init function, but I never see a call to acpi_smbus_hc_add().


I have no prior experience writing code in linux so I clearly don't understand how an ACPI driver works

Any help would be much appreciated!
 
Old 02-11-2011, 02:08 AM   #2
MrPolite
Member
 
Registered: Jun 2002
Location: Middle of nowhere
Posts: 109

Original Poster
Rep: Reputation: 15
In case anyone else is interested:
1) Based on the ACPI specification, it appears that I have to query ACPI for "_EC". I've had no luck getting that value so far.
/proc/acpi/embedded_controller/EC/info will give the GPE address but I'm not sure how they are related.

2) If anyone wants to do simple debugging experiments, it appears that on kernel 2.6.36 onward they've added a new config option CONFIG_ACPI_EC_DEBUGFS which will create the ec_sys module to give you read/write access to EC through /sys/kernel/debug/ec

Last edited by MrPolite; 02-11-2011 at 02:09 AM.
 
Old 02-14-2011, 03:51 AM   #3
mattday
LQ Newbie
 
Registered: Feb 2011
Location: UK
Distribution: Aptosid, Debian, Ubuntu
Posts: 2

Rep: Reputation: 0
Well I'm interested! I want to access the embedded controller for a different reason, but I was wondering if you had any source code that might help me get started quicker, or otherwise point me in the direction of any resources you have found useful.

Many thanks.
 
Old 02-14-2011, 12:18 PM   #4
mattday
LQ Newbie
 
Registered: Feb 2011
Location: UK
Distribution: Aptosid, Debian, Ubuntu
Posts: 2

Rep: Reputation: 0
Regarding the original question, have you tried disassembling the DSDT? To do this, get iasl and do something like:

Code:
sudo cat /sys/firmware/acpi/tables/DSDT > dsdt.dat
iasl -d dsdt.dat
Then open the disassembly output file (dsdt.dsl), and search for EmbeddedControl. You should see something like:

Code:
OperationRegion (ERAM, EmbeddedControl, Zero, 0xFF)
                    Field (ERAM, ByteAcc, NoLock, Preserve)
                    {
                        SMPR,   8, 
                        SMST,   8, 
                        SMAD,   8, 
                        SMCM,   8, 
                        SMD0,   256, 
                        BCNT,   8, 
                        SMAA,   8, 
                        BATD,   16, 
                                Offset (0x40), 
                        SW2S,   1, 
                            ,   3, 
                        TRPM,   1, 
                                Offset (0x41), 
...
 
Old 02-14-2011, 05:16 PM   #5
MrPolite
Member
 
Registered: Jun 2002
Location: Middle of nowhere
Posts: 109

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by mattday View Post
Regarding the original question, have you tried disassembling the DSDT? To do this, get iasl and do something like:

Code:
sudo cat /sys/firmware/acpi/tables/DSDT > dsdt.dat
iasl -d dsdt.dat
Then open the disassembly output file (dsdt.dsl), and search for EmbeddedControl. You should see something like:

Code:
OperationRegion (ERAM, EmbeddedControl, Zero, 0xFF)
                    Field (ERAM, ByteAcc, NoLock, Preserve)
                    {
                        SMPR,   8, 
                        SMST,   8, 
                        SMAD,   8, 
                        SMCM,   8, 
                        SMD0,   256, 
                        BCNT,   8, 
                        SMAA,   8, 
                        BATD,   16, 
                                Offset (0x40), 
                        SW2S,   1, 
                            ,   3, 
                        TRPM,   1, 
                                Offset (0x41), 
...
Hey!
Well with the new kernel compiled with CONFIG_ACPI_EC_DEBUGFS option, and ec-sys module loaded, it's really easy. You can see this sample app below on how to read/write to it. I think you will have to set one of ec-sys module parameters to true to enable write operations (can't remember what it was. See the source in drivers/acpi/ec-sys.c)
ftp://ftp.suse.com/pub/people/trenn/...ec/ec_access.c

As for DSDT, yea I tried I don't understand the ASL code well enough to figure it out. My problem is that my DSDT doesn't contain the ACPI0001 or ACPI0005 devices which represent the SMBus host controller 1.0/2.0 under EC. So they "should" appear as a child device of EC I believe, but they don't. I will post that portion of my DSDT when I go home.
How do you interpret the example above anyways? does that mean that ERAM is located at offset 0 through 0xFF of your EC controller?

Last edited by MrPolite; 02-14-2011 at 05:18 PM.
 
Old 02-14-2011, 09:07 PM   #6
MrPolite
Member
 
Registered: Jun 2002
Location: Middle of nowhere
Posts: 109

Original Poster
Rep: Reputation: 15
okay so here's a portion of my DSDT
Code:
                Device (EC)
                {
                    Name (_HID, EisaId ("PNP0C09"))
                    Name (_UID, 0x00)
                    Name (_GPE, 0x11)
                    Method (_REG, 2, NotSerialized)
                    {
                        If (LEqual (Arg0, 0x03))
                        {
                            Store (Arg1, \H8DR)
                        }
                    }

............
                    Device (BAT0)
                    {
                        Name (_HID, EisaId ("PNP0C0A"))
                        Name (_UID, 0x00)
                        Name (_PCL, Package (0x01)
                        {
                            \_SB
                        })
................
                    Device (AC)
                    {
                        Name (_HID, "ACPI0003")
                        Name (_UID, 0x00)
                        Name (_PCL, Package (0x01)
                        {
                            \_SB
                        })
technically i should also have a SMB0 device with HID of ACPI0005 but unfortunately I don't
So I can't exactly figure out if it means that it's physically impossible to access the SMBus through EC or not?

Again I'm a total noob when it comes to these things, so I could be misunderstanding the whole deal I've looked at the DSDT on 3 different laptops that I own and none of them have that SMBus HID that I'm looking for (and hence the sbshc module doesn't do anything on either one of them)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Smart Battery" not found by kernel DeNayGo Linux - Laptop and Netbook 2 09-25-2010 09:03 AM
"smart" battery system reset AKA the A Linux - Hardware 5 06-03-2009 06:08 AM
Acer Aspire 5004WLMi, can bios update solve smart battery problem? Shioni Linux - Laptop and Netbook 1 08-12-2006 10:12 PM
any distribution with smart battery support? Shioni Linux - General 0 06-14-2006 02:38 PM
Smart Battery System driver kurrupt Linux - Laptop and Netbook 0 01-25-2005 06:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 03:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration