charge animation: export struct charge_animation_pdata
This is the most flexsible way for all fuel gauge driver to get fdt config info from charge animation platdata. Change-Id: I33aa52c34f2c62c10b58003a10e5a8d1d6e5d7d3 Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
This commit is contained in:
parent
037c289fda
commit
ac1dc0c37a
22
cmd/charge.c
22
cmd/charge.c
|
|
@ -8,6 +8,7 @@
|
|||
#include <command.h>
|
||||
#include <dm.h>
|
||||
#include <power/charge_display.h>
|
||||
#include <power/charge_animation.h>
|
||||
|
||||
static int charge_display(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||
char *const argv[])
|
||||
|
|
@ -15,6 +16,7 @@ static int charge_display(cmd_tbl_t *cmdtp, int flag, int argc,
|
|||
int on_soc, on_voltage, screen_voltage;
|
||||
int ret, save[3];
|
||||
struct udevice *dev;
|
||||
struct charge_animation_pdata *pdata;
|
||||
|
||||
if (argc != 4 && argc != 1)
|
||||
return CMD_RET_USAGE;
|
||||
|
|
@ -30,9 +32,10 @@ static int charge_display(cmd_tbl_t *cmdtp, int flag, int argc,
|
|||
}
|
||||
|
||||
if (argc == 4) {
|
||||
save[0] = charge_display_get_power_on_soc(dev);
|
||||
save[1] = charge_display_get_power_on_voltage(dev);
|
||||
save[2] = charge_display_get_screen_on_voltage(dev);
|
||||
pdata = dev_get_platdata(dev);
|
||||
save[0] = pdata->exit_charge_level;
|
||||
save[1] = pdata->exit_charge_voltage;
|
||||
save[2] = pdata->screen_on_voltage;
|
||||
|
||||
on_soc = simple_strtoul(argv[1], NULL, 0);
|
||||
on_voltage = simple_strtoul(argv[2], NULL, 0);
|
||||
|
|
@ -40,16 +43,15 @@ static int charge_display(cmd_tbl_t *cmdtp, int flag, int argc,
|
|||
debug("new: on_soc=%d, on_voltage=%d, screen_voltage=%d\n",
|
||||
on_soc, on_voltage, screen_voltage);
|
||||
|
||||
charge_display_set_power_on_soc(dev, on_soc);
|
||||
charge_display_set_power_on_voltage(dev, on_voltage);
|
||||
charge_display_set_screen_on_voltage(dev, screen_voltage);
|
||||
pdata->exit_charge_level = on_soc;
|
||||
pdata->exit_charge_voltage = on_voltage;
|
||||
pdata->screen_on_voltage = screen_voltage;
|
||||
|
||||
charge_display_show(dev);
|
||||
|
||||
charge_display_set_power_on_soc(dev, save[0]);
|
||||
charge_display_set_power_on_voltage(dev, save[1]);
|
||||
charge_display_set_screen_on_voltage(dev, save[2]);
|
||||
|
||||
pdata->exit_charge_level = save[0];
|
||||
pdata->exit_charge_voltage = save[1];
|
||||
pdata->screen_on_voltage = save[2];
|
||||
} else if (argc == 1) {
|
||||
charge_display_show(dev);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -9,36 +9,6 @@
|
|||
#include <dm.h>
|
||||
#include <power/charge_display.h>
|
||||
|
||||
int charge_display_get_power_on_soc(struct udevice *dev)
|
||||
{
|
||||
const struct dm_charge_display_ops *ops = dev_get_driver_ops(dev);
|
||||
|
||||
if (!ops || !ops->get_power_on_soc)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->get_power_on_soc(dev);
|
||||
}
|
||||
|
||||
int charge_display_get_power_on_voltage(struct udevice *dev)
|
||||
{
|
||||
const struct dm_charge_display_ops *ops = dev_get_driver_ops(dev);
|
||||
|
||||
if (!ops || !ops->get_power_on_voltage)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->get_power_on_voltage(dev);
|
||||
}
|
||||
|
||||
int charge_display_get_screen_on_voltage(struct udevice *dev)
|
||||
{
|
||||
const struct dm_charge_display_ops *ops = dev_get_driver_ops(dev);
|
||||
|
||||
if (!ops || !ops->get_screen_on_voltage)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->get_screen_on_voltage(dev);
|
||||
}
|
||||
|
||||
int charge_display_show(struct udevice *dev)
|
||||
{
|
||||
const struct dm_charge_display_ops *ops = dev_get_driver_ops(dev);
|
||||
|
|
@ -49,36 +19,6 @@ int charge_display_show(struct udevice *dev)
|
|||
return ops->show(dev);
|
||||
}
|
||||
|
||||
int charge_display_set_power_on_soc(struct udevice *dev, int val)
|
||||
{
|
||||
const struct dm_charge_display_ops *ops = dev_get_driver_ops(dev);
|
||||
|
||||
if (!ops || !ops->set_power_on_soc)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->set_power_on_soc(dev, val);
|
||||
}
|
||||
|
||||
int charge_display_set_power_on_voltage(struct udevice *dev, int val)
|
||||
{
|
||||
const struct dm_charge_display_ops *ops = dev_get_driver_ops(dev);
|
||||
|
||||
if (!ops || !ops->set_power_on_voltage)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->set_power_on_voltage(dev, val);
|
||||
}
|
||||
|
||||
int charge_display_set_screen_on_voltage(struct udevice *dev, int val)
|
||||
{
|
||||
const struct dm_charge_display_ops *ops = dev_get_driver_ops(dev);
|
||||
|
||||
if (!ops || !ops->set_screen_on_voltage)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->set_screen_on_voltage(dev, val);
|
||||
}
|
||||
|
||||
UCLASS_DRIVER(charge_display) = {
|
||||
.id = UCLASS_CHARGE_DISPLAY,
|
||||
.name = "charge_display",
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include <asm/suspend.h>
|
||||
#include <linux/input.h>
|
||||
#include <power/charge_display.h>
|
||||
#include <power/charge_animation.h>
|
||||
#include <power/fuel_gauge.h>
|
||||
#include <power/pmic.h>
|
||||
#include <power/rk8xx_pmic.h>
|
||||
|
|
@ -39,85 +40,6 @@ struct charge_animation_priv {
|
|||
int image_num;
|
||||
};
|
||||
|
||||
struct charge_animation_pdata {
|
||||
int android_charge;
|
||||
int uboot_charge;
|
||||
|
||||
int exit_charge_voltage;
|
||||
int exit_charge_level;
|
||||
|
||||
int low_power_voltage;
|
||||
|
||||
int screen_on_voltage;
|
||||
int system_suspend;
|
||||
};
|
||||
|
||||
static int charge_animation_get_power_on_soc(struct udevice *dev)
|
||||
{
|
||||
struct charge_animation_pdata *pdata = dev_get_platdata(dev);
|
||||
|
||||
if (!pdata)
|
||||
return -ENOSYS;
|
||||
|
||||
return pdata->exit_charge_level;
|
||||
}
|
||||
|
||||
static int charge_animation_get_power_on_voltage(struct udevice *dev)
|
||||
{
|
||||
struct charge_animation_pdata *pdata = dev_get_platdata(dev);
|
||||
|
||||
if (!pdata)
|
||||
return -ENOSYS;
|
||||
|
||||
return pdata->exit_charge_voltage;
|
||||
}
|
||||
|
||||
static int charge_animation_get_screen_on_voltage(struct udevice *dev)
|
||||
{
|
||||
struct charge_animation_pdata *pdata = dev_get_platdata(dev);
|
||||
|
||||
if (!pdata)
|
||||
return -ENOSYS;
|
||||
|
||||
return pdata->screen_on_voltage;
|
||||
}
|
||||
|
||||
static int charge_animation_set_power_on_soc(struct udevice *dev, int val)
|
||||
{
|
||||
struct charge_animation_pdata *pdata = dev_get_platdata(dev);
|
||||
|
||||
if (!pdata)
|
||||
return -ENOSYS;
|
||||
|
||||
pdata->exit_charge_level = val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int charge_animation_set_power_on_voltage(struct udevice *dev, int val)
|
||||
{
|
||||
struct charge_animation_pdata *pdata = dev_get_platdata(dev);
|
||||
|
||||
if (!pdata)
|
||||
return -ENOSYS;
|
||||
|
||||
pdata->exit_charge_voltage = val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int charge_animation_set_screen_on_voltage(struct udevice *dev, int val)
|
||||
{
|
||||
struct charge_animation_pdata *pdata = dev_get_platdata(dev);
|
||||
|
||||
if (!pdata)
|
||||
return -ENOSYS;
|
||||
|
||||
pdata->screen_on_voltage = val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* IF you want to use your own charge images, please:
|
||||
*
|
||||
|
|
@ -590,12 +512,6 @@ static int charge_animation_show(struct udevice *dev)
|
|||
}
|
||||
|
||||
static const struct dm_charge_display_ops charge_animation_ops = {
|
||||
.get_power_on_soc = charge_animation_get_power_on_soc,
|
||||
.get_power_on_voltage = charge_animation_get_power_on_voltage,
|
||||
.get_screen_on_voltage = charge_animation_get_screen_on_voltage,
|
||||
.set_power_on_soc = charge_animation_set_power_on_soc,
|
||||
.set_power_on_voltage = charge_animation_set_power_on_voltage,
|
||||
.set_screen_on_voltage = charge_animation_set_screen_on_voltage,
|
||||
.show = charge_animation_show,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include <power/pmic.h>
|
||||
#include <dm/uclass-internal.h>
|
||||
#include <power/charge_display.h>
|
||||
#include <power/charge_animation.h>
|
||||
#include <power/fuel_gauge.h>
|
||||
#include <power/rk8xx_pmic.h>
|
||||
#include <linux/usb/phy-rockchip-inno-usb2.h>
|
||||
|
|
@ -919,22 +920,19 @@ static int rk816_bat_get_charger_type(struct battery_priv *di)
|
|||
return rk816_bat_get_usb_state(di);
|
||||
}
|
||||
|
||||
static bool rk816_bat_is_under_threshold(struct battery_priv *di)
|
||||
static bool rk816_bat_need_initialize(struct battery_priv *di)
|
||||
{
|
||||
struct charge_animation_pdata *pdata;
|
||||
bool initialize = false;
|
||||
#ifdef CONFIG_DM_CHARGE_DISPLAY
|
||||
struct udevice *dev;
|
||||
int soc, voltage, est_voltage;
|
||||
int err;
|
||||
int est_voltage;
|
||||
|
||||
err = uclass_find_first_device(UCLASS_CHARGE_DISPLAY, &dev);
|
||||
if (!err) {
|
||||
if (!uclass_find_first_device(UCLASS_CHARGE_DISPLAY, &dev)) {
|
||||
pdata = dev_get_platdata(dev);
|
||||
est_voltage = rk816_bat_get_avg_voltage(di);
|
||||
soc = charge_display_get_power_on_soc(dev);
|
||||
voltage = charge_display_get_power_on_voltage(dev);
|
||||
DBG("threshold: %d%%, %dmv; now: %d%%, %dmv\n",
|
||||
soc, voltage, di->dsoc, est_voltage);
|
||||
if ((di->dsoc <= soc) || (est_voltage <= voltage))
|
||||
if ((pdata->uboot_charge) ||
|
||||
(pdata->low_power_voltage >= est_voltage))
|
||||
initialize = true;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -952,7 +950,9 @@ void rk816_bat_init_rsoc(struct battery_priv *di)
|
|||
initialize = true;
|
||||
/* Only charger online and under threshold, we do initialization */
|
||||
else if (rk816_bat_get_charger_type(di) != NO_CHARGER)
|
||||
initialize = rk816_bat_is_under_threshold(di);
|
||||
initialize = rk816_bat_need_initialize(di);
|
||||
|
||||
printf("Fuel gauge initialize = %d\n", initialize);
|
||||
|
||||
if (!initialize)
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* (C) Copyright 2017 Rockchip Electronics Co., Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
|
||||
#ifndef _CHARGE_ANIMATION_H_
|
||||
#define _CHARGE_ANIMATION_H_
|
||||
|
||||
struct charge_animation_pdata {
|
||||
int android_charge;
|
||||
int uboot_charge;
|
||||
|
||||
int exit_charge_voltage;
|
||||
int exit_charge_level;
|
||||
int low_power_voltage;
|
||||
int screen_on_voltage;
|
||||
|
||||
int system_suspend;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -8,22 +8,9 @@
|
|||
#define _CHARGE_DISPLAY_H_
|
||||
|
||||
struct dm_charge_display_ops {
|
||||
int (*get_power_on_soc)(struct udevice *dev);
|
||||
int (*get_power_on_voltage)(struct udevice *dev);
|
||||
int (*get_screen_on_voltage)(struct udevice *dev);
|
||||
int (*set_power_on_soc)(struct udevice *dev, int val);
|
||||
int (*set_power_on_voltage)(struct udevice *dev, int val);
|
||||
int (*set_screen_on_voltage)(struct udevice *dev, int val);
|
||||
int (*show)(struct udevice *dev);
|
||||
};
|
||||
|
||||
int charge_display_get_power_on_soc(struct udevice *dev);
|
||||
int charge_display_get_power_on_voltage(struct udevice *dev);
|
||||
int charge_display_get_screen_on_voltage(struct udevice *dev);
|
||||
int charge_display_set_power_on_soc(struct udevice *dev, int val);
|
||||
int charge_display_set_power_on_voltage(struct udevice *dev, int val);
|
||||
int charge_display_set_screen_on_voltage(struct udevice *dev, int val);
|
||||
|
||||
int charge_display_show(struct udevice *dev);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue