From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lukasz Majewski Date: Thu, 18 Oct 2012 18:09:03 +0200 Subject: [U-Boot] [PATCH v2 09/21] pmic: Extend struct pmic to support battery and charger related operations [explanation] In-Reply-To: <50767AD0.7040208@denx.de> References: <1349425003-32523-1-git-send-email-l.majewski@samsung.com> <1349425003-32523-10-git-send-email-l.majewski@samsung.com> <50767AD0.7040208@denx.de> Message-ID: <20121018180903.0326a738@amdc308.digital.local> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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