Hi liyaoshi,
So how can I measure the charge percentage left in the battery? Is there an example that I can use? TPS65217 does not allow us to read the battery voltage if I am right or at least I cannot find it in datasheet. what voltage are you talking about?
I did some progress with controlling PMIC and I can use i2c utilities to read and write to it. However I have to use -f to force it since kernel is using the I2C interface. How can I do this cleanly from user space without forcing it? One way would be to expand the driver to add extra features. Does anyone know a good example that I can use as starting point? Is there a better/easier way to do this?
my procedure is as follow:
i2cdetect -l
on Beaglebone Black it will give you:
i2c-0 unknown OMAP I2C adapter N/A
i2c-1 unknown OMAP I2C adapter N/A
For reading status register of TPS65217. device is at 0x25 and status register is 0x0a on I2C0
i2cget [-f] [-y] i2cbus chip-address [data-address [mode]]
`
sudo i2cdet -f 0 0c24 0x0a
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x24, data address
0x0a, using read byte data.
Continue?
[Y/n]
0x88
`
To set battery charging voltage to 4.2V
`
i2cset [-f] [-y] [-m mask] [-r] i2cbus chip-address data-address [value] … [mode]
sudo i2cset -f -m 0x30 0 0x24 0x05 0x20
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will write to device file /dev/i2c-0, chip address 0x24, data address
0x05, data 0x20 (masked), mode byte.
Continue? [Y/n]
Old value 0x80, write mask 0x30: Will write 0xa0 to register 0x05
Continue? [Y/n]
`
Thanks a lot