usb: typec: tcpci_husb311: Refactor irq wakeup

Currently, the husb311 driver enable irq wakeup by default,
it can wakeup system if the vbus or the CC state changes.
However, if the Type-C port data role is DFP and the vbus
is power on, after enter deep sleep, the vbus maybe power
off for low power management, this cause system resume
immediately by husb311 irq.

Actually, the husb311 vbus irq wakeup is no need if the vbus
state changes for DFP mode. This patch only enable irq wakeup
if the vbus is power off, it can support husb311 irq wakeup
system if the Type-C connect with Type-C charger or Type-C DFP.
And disable husb311 irq if the vbus is power on, it can avoid
the tcpm_state_machine_work run before the husb311_pm_resume
during system resume.

Signed-off-by: William Wu <william.wu@rock-chips.com>
Change-Id: I62d35b10b6b2375125b32101426ea141f709ed91
This commit is contained in:
William Wu
2024-03-13 10:07:43 +08:00
committed by Tao Huang
parent ec8394fb33
commit a6a4762e0c

View File

@@ -199,7 +199,7 @@ static int husb311_probe(struct i2c_client *client,
return ret;
}
enable_irq_wake(client->irq);
device_init_wakeup(chip->dev, true);
return 0;
}
@@ -208,12 +208,14 @@ static void husb311_remove(struct i2c_client *client)
{
struct husb311_chip *chip = i2c_get_clientdata(client);
device_init_wakeup(chip->dev, false);
tcpci_unregister_port(chip->tcpci);
}
static int husb311_pm_suspend(struct device *dev)
{
struct husb311_chip *chip = dev->driver_data;
struct i2c_client *client = to_i2c_client(dev);
int ret = 0;
u8 pwr;
@@ -230,15 +232,26 @@ static int husb311_pm_suspend(struct device *dev)
if (ret < 0)
return ret;
if (device_may_wakeup(dev) && !chip->vbus_on)
enable_irq_wake(client->irq);
else
disable_irq(client->irq);
return 0;
}
static int husb311_pm_resume(struct device *dev)
{
struct husb311_chip *chip = dev->driver_data;
struct i2c_client *client = to_i2c_client(dev);
int ret = 0;
u8 filter;
if (device_may_wakeup(dev) && !chip->vbus_on)
disable_irq_wake(client->irq);
else
enable_irq(client->irq);
/*
* When the power of husb311 is lost or i2c read failed in PM S/R
* process, we must reset the tcpm port first to ensure the devices