Dobrica Pavlinušić's random unstructured stuff
phj00: Revision 4

Lenovo Thinkpad Tablet



EC_battery

https://github.com/dpavlin/linux/blob/thinktabletopensource-2.6.36/drivers/power/EC_battery.c

battery info from shell

dpavlin@tegra20:~$ cat batt-info.sh 
#!/bin/sh

printf 'BatCapacity: %d %%\n' `i2cget -y 5 0x58 0x00 w`
printf 'BatFullCapacity:   %d\n' `i2cget -y 5 0x58 0x07 w`
printf 'BatDesignCapacity: %d\n' `i2cget -y 5 0x58 0x08 w`
printf 'ChargerStatus: %d\n' `i2cget -y 5 0x58 0x0b w`
printf 'UsbStatus: %d\n' `i2cget -y 5 0x58 0x5b w`

printf 'voltage: %d\n' `i2cget -y 5 0x58 0x01 w`
printf 'temperature: %d\n' `i2cget -y 5 0x58 0x0a w`

ec_status=`i2cget -y 5 0x58 0x0b w`
case $ec_status in
        0x0000) ec_status_dec="discharging" ;;
        0x0001) ec_status_dec="charging" ;;
        0x0002) ec_status_dec="full" ;;
        *) echo "unknown $ec_status" && exit 1
esac
printf 'EC_status: %d [%s]\n' $ec_status $ec_status_dec

dpavlin@tegra20:~$ sudo ./batt-info.sh 
BatCapacity: 29 %
BatFullCapacity:   2670
BatDesignCapacity: 3250
ChargerStatus: 1
UsbStatus: 0
voltage: 7477
temperature: 2912
EC_status: 1 [charging]


kernel 2.6 /sys/EcControl

shell@android:/sys/EcControl # grep . *
AssetNumber:
BTMAC:6c71d912972f
BatCapacity:66
BatCtlDisable:BatCtlDisable
BatCtlEnable:0
BatCurrent:-21
BatDesignCapacity:3250
BatFullCapacity:2786
BatLifeTime:0
BatLock:ok
BatStatus:Charging
BatteryUpdateMode:-2
BoardID:-258
Brandname:ThinkPad Tablet
ChargeLED:ChargeLED
ChargerStatus:1
Coldboot:0
DeviceStatus:0000000000001000
ECFwStatus:aa
ECRead:0x0c12
ECWrite:ECWrite
ECflashMode:0
ECflashread:B
ECflashwrite:ECflashwrite
EcVer:3f001900
FactoryStatus:INAKRUIN
GPSPower:0
IMEIwithBarcode:ffffffffffffff15
LEDAndroidOff:LEDAndroidOff
MFGBuildDate:2012/10/31
MTMSN:����������������
ManufactureDate:ffff-ff-ff
MicSwitch:2
NBUsbChargingCurrent:65278
OffLED:OffLED
OriStsLED:OriStsLED
PassCode:ECEG
PlanarSN:11S63Y1836Z1ZLFT2A70PT
PowerLED:PowerLED
PsensorPower:2
RebootAfterEcUpdate:RebootAfterEcUpdate
RecoveryMode:RecoveryMode
Reset:Reset
Resume:0
SerialNumber:49834956515650807177804989678086
SerialNumberwithoutBarcode:����������������������
Shutdown:Shutdown
SkuNumber:003f
Suspend:Suspend
SysStatus:1
ThreeGPower:1
UUID:5668546668516867494852664949695065575056546755496857495057555070
UsbStatus:0
WIFIMAC:ffffffffffff

shell i2c tests

Sensor is not detected in i2cdetect since it returns 00 as first byte.
Arbitration errors on this bus (which are probably caused caused by scanning
other side of i2c mux or parent i2c controller -- I have to re-check this)
break communication with EC.

linux-2.6/drivers/power/EC_battery.c



# ready?
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x48 w
0x0008
# ready = ret & 0x00000008;

# BatCtlEnable_show

root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x5b w
0x0000

# EcVer_show

root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x30 w
0x3f00
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x31 w
0x2100

# UUID_show

for(i=0;i<16;i++)
           {
               val32 = i2c_smbus_read_word_data(EC_Bat_device->client,0x60);
               val16 = val32 & 0x0000ffff;
               TransformToByte(val16, &val8[2*i], &val8[2*i+1]);
               msleep(10);
           }

root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x5768
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x6668
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x6567
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x5456
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x5070
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x5552
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x5651
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x5770
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x6948
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x4949
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x5549
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x6856
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x4966
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x4869
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x6965
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w
0x4854
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x60 w # 17 repeat?
0x5768


# BatCapacity_show
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x00 w
0x004d

# BatFullCapacity_show
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x07 w
0x0773

# BatDesignCapacity_show
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x08 w
0x0965

# BTMAC_show
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x62 w
0xbd9d
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x62 w
0x68ac
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x62 w
0x742f
## repeat?
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x62 w
0xbd9d

# ChargerStatus_show
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x0b w
0x0001

# UsbStatus_show
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x5b w
0x0000

# ECRead_show
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0xF1 w
0x0c12

# Shutdown_store
i2c_smbus_write_word_data(EC_Bat_device->client,0x52,0);

# Suspend_store
i2c_smbus_write_word_data(EC_Bat_device->client,0x53,0);

# Coldboot_store
Coldboot_val = buffer & 0x0000FFFF;
i2c_smbus_write_word_data(EC_Bat_device->client,0x55,Coldboot_val);

# Resume_store
Resume_val = buffer & 0x0000FFFF;
i2c_smbus_write_word_data(EC_Bat_device->client,0x56,Resume_val);

# RecoveryMode_store
i2c_smbus_write_word_data(EC_Bat_device->client,0x58,val);

# MicSwitch_store
//echo 0 > MicSwitch(front) ,  echo 1 > MicSwitch(back), echo 2 > MicSwitch(normal)
//echo 3 > MicSwitch(echo cancellation test), echo 4 > MicSwitch(disable echo cancellation)
i2c_smbus_write_word_data(EC_Bat_device->client,0x44,MicSwitch_val);

# ThreeGPower_store
//echo 1 > ThreeGPower(poweron) ,  echo 0 > ThreeGPower(poweroff), echo 2 > ThreeGPower(backtoOriginstate)
i2c_smbus_write_word_data(EC_Bat_device->client,0x45,ThreeGPower_val);

# enable_ThreeGPower
ThreeGPower_val = 1; # 1 = enable, 0 = disable
i2c_smbus_write_word_data(EC_Bat_device->client,0x45,ThreeGPower_val);

# SerialNumber_show
for(i=0;i<=7;i++) {
val32 = i2c_smbus_read_word_data(EC_Bat_device->client,0x66);
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x66 w # 0
0x5451
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x66 w # 1
0x5468
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x66 w # 2
0x8048
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x66 w # 3
0x5277
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x66 w # 4
0x8290
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x66 w # 5
0x5157
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x66 w # 6
0x4956
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x66 w # 7
0x4983
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x66 w # 0
0x5451

# SkuNumber_show
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x68 w
0xffff


# LEDAndroidOff_store
i2c_smbus_write_word_data(EC_Bat_device->client,0x5a,0);

# Reset_store
i2c_smbus_write_word_data(EC_Bat_device->client,0x54,0);
 
# BatCurrent_show
i2c_smbus_read_word_data(EC_Bat_device->client,0x03);
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x03 w
0xff43
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x03 w
0xff42

# BatLifeTime_show
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x70 w
0x0000

# BoardID_show
root@tegra20:/mnt/nuc/Tegra# i2cget -y 5 0x58 0x32 w
0xfefe


# GPSPower_store
#         if(GPS_val == 0)	OFF
i2c_smbus_write_word_data(EC_Bat_device->client,0x47,0);
# else if(GPS_val == 1)		ON
i2c_smbus_write_word_data(EC_Bat_device->client,0x4a,0);


# PsensorPower_store
//echo 0 > PsensorPower(off), echo 1 > PsensorPower(on), echo 2 > PsensorPower(normal control)
i2c_smbus_write_word_data(EC_Bat_device->client,0x4b, PsensorPower_val);
root@tegra20:/mnt/nuc/Tegra# i2cset -y 5 0x58 0x4b 0x1 w