[U-Boot] [PATCH v2 09/21] pmic: Extend struct pmic to support battery and charger related operations [explanation]

Lukasz Majewski l.majewski at samsung.com
Thu Oct 18 18:09:03 CEST 2012


Hi Stefano,

I'd like to present an overview of my idea (pseudo code):

struct battery {
	int (* battery_charge) ()
	struct pmic *fg, *muic, *chrg
}

struct chrg {
	int (*chrg_type) ()
	int (*chrg_bat_present) ()
	int (*chrg_state) ()
}

struct fg {
	int (*fg_bat_check) ()
	int (*fg_bat_update) ()
}

struct muic {

}

Then extend struct pmic:

struct pmic {

struct battery *bat_p;
struct chrg *chrg_p;
struct fg *fg_p;
struct muic *muic_p;

struct pmic *parent;
void (*low_power_mode) ();
}

The struct [battery|chrg|fg|muic] is provided during pmic device
initialization (it is defined as a static in a device's translation unit
- e.g. fg_max17042.c)


To solve the problem with multi instances of the same devices (e.g. two
identical HW devices - MAX17042 are connected to SOC), methods defined
for pmic/power devices accept struct pmic *p of the device instance.

You have suggested, that pmic device shall be a parent. However, I see
it differently (at least from my HW):

			struct pmic *fg, *muic, *chrg
			-----------------
		--------| BAT		|------------
		|	|		|	    |
		|	-----------------	    |
		|		|		    |
	       \|/	       \|/		   \|/
	-----------	-----------------	---------
	|FG       |	|MUIC		|	|CHRG	|
	|         |	|		| 	|	|
	-----------	-----------------	---------
  	struct	pmic *parent = &bat (for FG, MUIC, CHRG)

(PMIC is also connected to the rest via list)


I think that BAT is parent here, since when we want to e.g. charge the
battery we would look for it with:
p_bat = pmic_get("BAT_TRATS");

In my opinion it is natural to call p_bat->battery_charge(p_bat)
to enable charging and in the same time don't be concerned with "helper"
devices (like FG, MUIC, CHRG) - which provide methods to check if
battery is charged properly.

Moreover BAT shall be treated as a PMIC device and thereof has its own
instance of struct pmic. It is desirable to have all power related
devices connected in the list.

The __real__ problem here is how to "connect" functionality provided by
FG, CHRG, MUIC with battery, to have easy access:
p_bat->battery_charge(p_bat).

One option would be to fill: 
struct battery *bat_p;
struct chrg *chrg_p;
struct fg *fg_p;
struct muic *muic_p;

for struct pmic bat.

Then we could access relevant functions just from p_bat. 


-- 
Best regards,

Lukasz Majewski

Samsung Poland R&D Center | Linux Platform Group


More information about the U-Boot mailing list