Commit 4f5bf5eb authored by Guido Gunther's avatar Guido Gunther Committed by Martin Kepplinger
Browse files

usb: typec: tps6598x: 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 Gunther's avatarGuido Günther <agx@sigxcpu.org>
parent 206e381d
......@@ -94,6 +94,8 @@ struct tps6598x {
struct power_supply *psy;
struct power_supply_desc psy_desc;
enum power_supply_usb_type usb_type;
u16 pwr_status;
};
static enum power_supply_property tps6598x_psy_props[] = {
......@@ -223,17 +225,12 @@ static int tps6598x_connect(struct tps6598x *tps, u32 status)
{
struct typec_partner_desc desc;
enum typec_pwr_opmode mode;
u16 pwr_status;
int ret;
if (tps->partner)
return 0;
ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
if (ret < 0)
return ret;
mode = TPS_POWER_STATUS_PWROPMODE(pwr_status);
mode = TPS_POWER_STATUS_PWROPMODE(tps->pwr_status);
desc.usb_pd = mode == TYPEC_PWR_MODE_PD;
desc.accessory = TYPEC_ACCESSORY_NONE; /* XXX: handle accessories */
......@@ -410,7 +407,7 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
u64 event1;
u64 event2;
u32 status;
u32 status, data_status;
u16 pwr_status;
int ret;
mutex_lock(&tps->lock);
......@@ -436,6 +433,7 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
dev_err(tps->dev, "failed to read power status: %d\n", ret);
goto err_clear_ints;
}
tps->pwr_status = pwr_status;
trace_tps6598x_power_status(pwr_status);
}
......@@ -505,15 +503,8 @@ static const struct regmap_config tps6598x_regmap_config = {
static int tps6598x_psy_get_online(struct tps6598x *tps,
union power_supply_propval *val)
{
int ret;
u16 pwr_status;
ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
if (ret < 0)
return ret;
if ((pwr_status & TPS_POWER_STATUS_CONNECTION) &&
(pwr_status & TPS_POWER_STATUS_SOURCESINK)) {
if (TPS_POWER_STATUS_CONNECTION(tps->pwr_status) &&
TPS_POWER_STATUS_SOURCESINK(tps->pwr_status)) {
val->intval = 1;
} else {
val->intval = 0;
......@@ -526,15 +517,11 @@ static int tps6598x_psy_get_prop(struct power_supply *psy,
union power_supply_propval *val)
{
struct tps6598x *tps = power_supply_get_drvdata(psy);
u16 pwr_status;
int ret = 0;
switch (psp) {
case POWER_SUPPLY_PROP_USB_TYPE:
ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
if (ret < 0)
return ret;
if (TPS_POWER_STATUS_PWROPMODE(pwr_status) == TYPEC_PWR_MODE_PD)
if (TPS_POWER_STATUS_PWROPMODE(tps->pwr_status) == TYPEC_PWR_MODE_PD)
val->intval = POWER_SUPPLY_USB_TYPE_PD;
else
val->intval = POWER_SUPPLY_USB_TYPE_C;
......@@ -685,6 +672,11 @@ static int tps6598x_probe(struct i2c_client *client)
fwnode_handle_put(fwnode);
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);
if (ret)
dev_err(&client->dev, "failed to register partner\n");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment