Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

platform/chrome: cros_ec_lightbar - Add userspace lightbar control bit to EC

Some devices might want to turn off the lightbar if e.g. the
system turns the screen off due to idleness. This prevents the
kernel from going through its normal suspend/resume pathways.

Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
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>

authored by

Eric Caruso and committed by
Benson Leung
abbb054d 405c8430

+38
+38
drivers/platform/chrome/cros_ec_lightbar.c
··· 38 38 /* Rate-limit the lightbar interface to prevent DoS. */ 39 39 static unsigned long lb_interval_jiffies = 50 * HZ / 1000; 40 40 41 + /* 42 + * Whether or not we have given userspace control of the lightbar. 43 + * If this is true, we won't do anything during suspend/resume. 44 + */ 45 + static bool userspace_control; 46 + 41 47 static ssize_t interval_msec_show(struct device *dev, 42 48 struct device_attribute *attr, char *buf) 43 49 { ··· 413 407 414 408 int lb_suspend(struct cros_ec_dev *ec) 415 409 { 410 + if (userspace_control) 411 + return 0; 412 + 416 413 return lb_send_empty_cmd(ec, LIGHTBAR_CMD_SUSPEND); 417 414 } 418 415 419 416 int lb_resume(struct cros_ec_dev *ec) 420 417 { 418 + if (userspace_control) 419 + return 0; 420 + 421 421 return lb_send_empty_cmd(ec, LIGHTBAR_CMD_RESUME); 422 422 } 423 423 ··· 540 528 return ret; 541 529 } 542 530 531 + static ssize_t userspace_control_show(struct device *dev, 532 + struct device_attribute *attr, 533 + char *buf) 534 + { 535 + return scnprintf(buf, PAGE_SIZE, "%d\n", userspace_control); 536 + } 537 + 538 + static ssize_t userspace_control_store(struct device *dev, 539 + struct device_attribute *attr, 540 + const char *buf, 541 + size_t count) 542 + { 543 + bool enable; 544 + int ret; 545 + 546 + ret = strtobool(buf, &enable); 547 + if (ret < 0) 548 + return ret; 549 + 550 + userspace_control = enable; 551 + 552 + return count; 553 + } 554 + 543 555 /* Module initialization */ 544 556 545 557 static DEVICE_ATTR_RW(interval_msec); ··· 572 536 static DEVICE_ATTR_WO(led_rgb); 573 537 static DEVICE_ATTR_RW(sequence); 574 538 static DEVICE_ATTR_WO(program); 539 + static DEVICE_ATTR_RW(userspace_control); 575 540 576 541 static struct attribute *__lb_cmds_attrs[] = { 577 542 &dev_attr_interval_msec.attr, ··· 581 544 &dev_attr_led_rgb.attr, 582 545 &dev_attr_sequence.attr, 583 546 &dev_attr_program.attr, 547 + &dev_attr_userspace_control.attr, 584 548 NULL, 585 549 }; 586 550