Accessing and controlling PMIC, TPS65217C, from shell

Hi All,

I connected a rechargeable Li+ battery to my BBB TP5, TP6, TP7, and TP8. I shorted TP5 and TP6 and added a 10uF decoupling capacitor. In addition, I connected TS to GND with a 9K resistor which is 10K || 75K according to the datasheet and the board boots fine from battery.
Now my question is that how can I monitor the battery status(how much they are charged) or change the setting of PMIC, TPS65127C from shell. For instance, I would like to set the charging voltage to 4.2 rather than the default 4.1V. Or I would like to turn on/off WLED etc. Is there a tool, like Alsamixer, for this? if not what would be the best approach for controlling PMIC from shell? I posted it here because PMIC uses I2C interface to talk to AM335x.

Thanks for your time and consideration.

As I know , if only 2 wires , you can not access the Li+battery status , you can just get voltage value from PMU

There always another 1 wire to get the communication with MCU in battery module

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

> 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

Ok, so I2C to the PMIC does work. A person on the group got this working from within uboot and posted about it over a month ago.

When i asked, “ok great, but how does that translate to this working while under linux?” He / she replied: something to the effect of “I’m unsure”.

Anyway, the point is it is possible to control the PMIC, or at minimum communicate with it via software + I2C. I am however not a Linux kernel expert / guru, but I would assume this would require a kernel level driver to work.

Ah ok my mistake I misread your post initially as I did not read the whole thing sorry.

So yes, I would think you would have to write your own kernel module, or modify the existing I2C bus utils. Recompile, etc.

resandevinwebb, btw thank you for sharing the information. This is of personal interest for me as well.

Hi William,

I have worked a little with codec drivers which allows you to access some features from user space. for example, you can change the microphone impedance, bias voltage etc by Alsamixer on the fly (I think is called hot swap). some have suggested to access the driver thru kernel interfaces like sysfs. If i can find a good tutorial or example on this I will implement it. But, for now I am waiting for some good advice or starting point.

-Regards,

res,

Yeah, I’m green on this subject, and is something I’d like to learn myself. LDD ( Linux Device Drivers ) by O’Reilly would probably be a good source of information. Also free for download , just google the name + “PDF” you’ll find multiple sources. Latest edition is 3RD edition. But you could probably wade through some code, for various aspects of i2cset, and get an idea of whats going on.

The only reason why I commented was that I remember another person talking about communicating with / setting the PMIC through uboot. Which is to say I’m assuming there is no kernel / user mode. Just kernel mode, or something akin to it.

http://lwn.net/Kernel/LDD3/

Also

https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt

Oh, and a git for the source:

https://github.com/groeck/i2c-tools