Skip to content

Commit

Permalink
platform/chrome: cros_ec_lightbar - Avoid I2C xfer to EC during suspend
Browse files Browse the repository at this point in the history
A Mutex lock in cros_ec_cmd_xfer which may be held by frozen
Userspace thread during system suspending. So should not
call this routine in suspend thread.

Signed-off-by: Jeffery Yu <jefferyy@nvidia.com>
Signed-off-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Benson Leung <bleung@chromium.org>
  • Loading branch information
Jeffery Yu authored and Benson Leung committed Jun 23, 2017
1 parent abbb054 commit 995c0ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 4 additions & 8 deletions drivers/platform/chrome/cros_ec_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ static int ec_device_probe(struct platform_device *pdev)
cros_ec_sensors_register(ec);

/* Take control of the lightbar from the EC. */
if (ec_has_lightbar(ec))
lb_manual_suspend_ctrl(ec, 1);
lb_manual_suspend_ctrl(ec, 1);

return 0;

Expand All @@ -452,8 +451,7 @@ static int ec_device_remove(struct platform_device *pdev)
struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev);

/* Let the EC take over the lightbar again. */
if (ec_has_lightbar(ec))
lb_manual_suspend_ctrl(ec, 0);
lb_manual_suspend_ctrl(ec, 0);

cros_ec_debugfs_remove(ec);

Expand All @@ -472,8 +470,7 @@ static int ec_device_suspend(struct device *dev)
{
struct cros_ec_dev *ec = dev_get_drvdata(dev);

if (ec_has_lightbar(ec))
lb_suspend(ec);
lb_suspend(ec);

return 0;
}
Expand All @@ -482,8 +479,7 @@ static int ec_device_resume(struct device *dev)
{
struct cros_ec_dev *ec = dev_get_drvdata(dev);

if (ec_has_lightbar(ec))
lb_resume(ec);
lb_resume(ec);

return 0;
}
Expand Down
13 changes: 9 additions & 4 deletions drivers/platform/chrome/cros_ec_lightbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static unsigned long lb_interval_jiffies = 50 * HZ / 1000;
* If this is true, we won't do anything during suspend/resume.
*/
static bool userspace_control;
static struct cros_ec_dev *ec_with_lightbar;

static ssize_t interval_msec_show(struct device *dev,
struct device_attribute *attr, char *buf)
Expand Down Expand Up @@ -384,6 +385,9 @@ int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable)
struct cros_ec_command *msg;
int ret;

if (ec != ec_with_lightbar)
return 0;

msg = alloc_lightbar_cmd_msg(ec);
if (!msg)
return -ENOMEM;
Expand Down Expand Up @@ -413,15 +417,15 @@ int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable)

int lb_suspend(struct cros_ec_dev *ec)
{
if (userspace_control)
if (userspace_control || ec != ec_with_lightbar)
return 0;

return lb_send_empty_cmd(ec, LIGHTBAR_CMD_SUSPEND);
}

int lb_resume(struct cros_ec_dev *ec)
{
if (userspace_control)
if (userspace_control || ec != ec_with_lightbar)
return 0;

return lb_send_empty_cmd(ec, LIGHTBAR_CMD_RESUME);
Expand Down Expand Up @@ -606,9 +610,10 @@ static umode_t cros_ec_lightbar_attrs_are_visible(struct kobject *kobj,
return 0;

/* Only instantiate this stuff if the EC has a lightbar */
if (ec_has_lightbar(ec))
if (ec_has_lightbar(ec)) {
ec_with_lightbar = ec;
return a->mode;

}
return 0;
}

Expand Down

0 comments on commit 995c0ec

Please sign in to comment.