mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-21 16:29:59 +00:00
usb: typec: tipd: Only update power status on IRQ
Instead of refetching power status cache it and only update it when a change is signalled via irq. This simplifies tracing and adding more supply properties in follow up patches. Signed-off-by: Guido Günther <agx@sigxcpu.org> Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://lore.kernel.org/r/20220317154518.4082046-2-sebastian.krzyszkowiak@puri.sm Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
38c695e1e2
commit
92440202a8
1 changed files with 12 additions and 20 deletions
|
@ -93,6 +93,8 @@ struct tps6598x {
|
||||||
struct power_supply *psy;
|
struct power_supply *psy;
|
||||||
struct power_supply_desc psy_desc;
|
struct power_supply_desc psy_desc;
|
||||||
enum power_supply_usb_type usb_type;
|
enum power_supply_usb_type usb_type;
|
||||||
|
|
||||||
|
u16 pwr_status;
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum power_supply_property tps6598x_psy_props[] = {
|
static enum power_supply_property tps6598x_psy_props[] = {
|
||||||
|
@ -230,17 +232,12 @@ static int tps6598x_connect(struct tps6598x *tps, u32 status)
|
||||||
{
|
{
|
||||||
struct typec_partner_desc desc;
|
struct typec_partner_desc desc;
|
||||||
enum typec_pwr_opmode mode;
|
enum typec_pwr_opmode mode;
|
||||||
u16 pwr_status;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (tps->partner)
|
if (tps->partner)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
|
mode = TPS_POWER_STATUS_PWROPMODE(tps->pwr_status);
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
mode = TPS_POWER_STATUS_PWROPMODE(pwr_status);
|
|
||||||
|
|
||||||
desc.usb_pd = mode == TYPEC_PWR_MODE_PD;
|
desc.usb_pd = mode == TYPEC_PWR_MODE_PD;
|
||||||
desc.accessory = TYPEC_ACCESSORY_NONE; /* XXX: handle accessories */
|
desc.accessory = TYPEC_ACCESSORY_NONE; /* XXX: handle accessories */
|
||||||
|
@ -455,6 +452,7 @@ static bool tps6598x_read_power_status(struct tps6598x *tps)
|
||||||
dev_err(tps->dev, "failed to read power status: %d\n", ret);
|
dev_err(tps->dev, "failed to read power status: %d\n", ret);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
tps->pwr_status = pwr_status;
|
||||||
trace_tps6598x_power_status(pwr_status);
|
trace_tps6598x_power_status(pwr_status);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -601,15 +599,8 @@ static const struct regmap_config tps6598x_regmap_config = {
|
||||||
static int tps6598x_psy_get_online(struct tps6598x *tps,
|
static int tps6598x_psy_get_online(struct tps6598x *tps,
|
||||||
union power_supply_propval *val)
|
union power_supply_propval *val)
|
||||||
{
|
{
|
||||||
int ret;
|
if (TPS_POWER_STATUS_CONNECTION(tps->pwr_status) &&
|
||||||
u16 pwr_status;
|
TPS_POWER_STATUS_SOURCESINK(tps->pwr_status)) {
|
||||||
|
|
||||||
ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (TPS_POWER_STATUS_CONNECTION(pwr_status) &&
|
|
||||||
TPS_POWER_STATUS_SOURCESINK(pwr_status)) {
|
|
||||||
val->intval = 1;
|
val->intval = 1;
|
||||||
} else {
|
} else {
|
||||||
val->intval = 0;
|
val->intval = 0;
|
||||||
|
@ -622,15 +613,11 @@ static int tps6598x_psy_get_prop(struct power_supply *psy,
|
||||||
union power_supply_propval *val)
|
union power_supply_propval *val)
|
||||||
{
|
{
|
||||||
struct tps6598x *tps = power_supply_get_drvdata(psy);
|
struct tps6598x *tps = power_supply_get_drvdata(psy);
|
||||||
u16 pwr_status;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
switch (psp) {
|
switch (psp) {
|
||||||
case POWER_SUPPLY_PROP_USB_TYPE:
|
case POWER_SUPPLY_PROP_USB_TYPE:
|
||||||
ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
|
if (TPS_POWER_STATUS_PWROPMODE(tps->pwr_status) == TYPEC_PWR_MODE_PD)
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
if (TPS_POWER_STATUS_PWROPMODE(pwr_status) == TYPEC_PWR_MODE_PD)
|
|
||||||
val->intval = POWER_SUPPLY_USB_TYPE_PD;
|
val->intval = POWER_SUPPLY_USB_TYPE_PD;
|
||||||
else
|
else
|
||||||
val->intval = POWER_SUPPLY_USB_TYPE_C;
|
val->intval = POWER_SUPPLY_USB_TYPE_C;
|
||||||
|
@ -837,6 +824,11 @@ static int tps6598x_probe(struct i2c_client *client)
|
||||||
fwnode_handle_put(fwnode);
|
fwnode_handle_put(fwnode);
|
||||||
|
|
||||||
if (status & TPS_STATUS_PLUG_PRESENT) {
|
if (status & TPS_STATUS_PLUG_PRESENT) {
|
||||||
|
ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status);
|
||||||
|
if (ret < 0) {
|
||||||
|
dev_err(tps->dev, "failed to read power status: %d\n", ret);
|
||||||
|
goto err_role_put;
|
||||||
|
}
|
||||||
ret = tps6598x_connect(tps, status);
|
ret = tps6598x_connect(tps, status);
|
||||||
if (ret)
|
if (ret)
|
||||||
dev_err(&client->dev, "failed to register partner\n");
|
dev_err(&client->dev, "failed to register partner\n");
|
||||||
|
|
Loading…
Reference in a new issue