Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2107661imu; Wed, 12 Dec 2018 09:35:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/UxUDwVnc3rPR5DJW/gzLJCjwhJ1hg0RWcEZNhHGCAxe77kcTFFzimVGOdtMjG8fyF31X6b X-Received: by 2002:a63:24c2:: with SMTP id k185mr18294472pgk.406.1544636137057; Wed, 12 Dec 2018 09:35:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544636137; cv=none; d=google.com; s=arc-20160816; b=Myx34SvIJaru9vaBoCsM/VWfpkxnSMGeby2BEnJ4DFMS4J89aoRJXHAN2BecnsyQ54 Z4S8VRSZfSSMkWUNfhxqGPHyBc3tI+6rNXdHpmG3WFqtGd66PpIiK8NS0Smbnwt+LyXp 3USVaXPQI9FCzwL9VH6qwtnqiwO6dc+YauGi5eA7pHgp+xt6PvYCdm1EB2FCO3jk4Gte LjpNPOZ6v9XEtnfsrq2j1nTrz6N2rVH6yMEBI1KLedPk8HRk3fUzbrYae1kigPvNPHoU PBHUUk52agQYbZS48nUILQ9ya2T8CTMlg1n7DLIzYGdt1SMJb+ZS0kYHCvCHcnAiwWaw DD+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=N+PlSCfnT9UZ6DQY6wsvDp8kKyiSFYErhwj8T8HMGTw=; b=vZjafOK37XDEsv9NVrx1Zzm+WkDusUywl0jGT5wQ/GjlU777sYjhy07uq+gtuEnNW1 pDjQ9+qz+NF4rSkVGKeQva8hW52ftmd4M2frH9B6FuRaSfXtA1cUM8Ju6GeMa6rIEcUV Kq4tn3hAnBJPCO/FMlJRqs1aA9aXVa76c26bfbBi0IT3RNdr1uTzzSctuvuf8y/i59YX hc8XYpjrVgWI2HQISGOaR8HaNRHhoACdu6OnlFJftpfcCIhLOwotaMzEkUAytrUrnp5A xFwsLv9tKO834vqO3lLm2N3fT5ptvmtzNOjNKdxjp4NYPJTX7oUi3wGRQeXIhZVHABBz P48w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a81si15851826pfj.195.2018.12.12.09.35.22; Wed, 12 Dec 2018 09:35:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728150AbeLLReW (ORCPT + 99 others); Wed, 12 Dec 2018 12:34:22 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:54312 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728069AbeLLReQ (ORCPT ); Wed, 12 Dec 2018 12:34:16 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 0BDD727EBF1 From: Enric Balletbo i Serra To: lee.jones@linaro.org Cc: gwendal@chromium.org, drinkcat@chromium.org, linux-kernel@vger.kernel.org, groeck@chromium.org, kernel@collabora.com, bleung@chromium.org Subject: [PATCH v5 7/7] platform/chrome: cros_ec_lightbar: instantiate only if the EC has a lightbar Date: Wed, 12 Dec 2018 18:34:02 +0100 Message-Id: <20181212173402.27086-8-enric.balletbo@collabora.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181212173402.27086-1-enric.balletbo@collabora.com> References: <20181212173402.27086-1-enric.balletbo@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Due to the way attribute groups visibility work, the function cros_ec_lightbar_attrs_are_visible is called multiple times, once per attribute, and each of these calls makes an EC transaction. For what is worth the EC log reports multiple errors on boot when the lightbar is not available. Instead, check if the EC has a lightbar in the probe function and only instantiate the device. Ideally we should have instantiate the driver only if the EC_FEATURE_LIGHTBAR is defined, but that's not possible because that flag is not in the very first Pixel Chromebook (Link), only on Samus. So, the driver is instantiated by his parent always. This patch changes a bit the actual behaviour. Before the patch if an EC doesn't have a lightbar an empty lightbar folder is created in /sys/class/chromeos/, after the patch the empty folder is not created, so, the folder is only created if the lightbar exists. Signed-off-by: Enric Balletbo i Serra Reviewed-by: Guenter Roeck --- Changes in v5: None Changes in v4: - Get rid of the cros_ec_has_lightbar function. Changes in v3: None Changes in v2: - Removed ec_with_lightbar variable. drivers/platform/chrome/cros_ec_lightbar.c | 53 ++++++++-------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platform/chrome/cros_ec_lightbar.c index c22318ba93aa..c3e4e6e5211d 100644 --- a/drivers/platform/chrome/cros_ec_lightbar.c +++ b/drivers/platform/chrome/cros_ec_lightbar.c @@ -43,7 +43,6 @@ 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) @@ -381,9 +380,6 @@ static 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; @@ -567,45 +563,32 @@ static struct attribute *__lb_cmds_attrs[] = { NULL, }; -static bool ec_has_lightbar(struct cros_ec_dev *ec) -{ - return !!get_lightbar_version(ec, NULL, NULL); -} - -static umode_t cros_ec_lightbar_attrs_are_visible(struct kobject *kobj, - struct attribute *a, int n) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct cros_ec_dev *ec = to_cros_ec_dev(dev); - struct platform_device *pdev = to_platform_device(ec->dev); - struct cros_ec_platform *pdata = pdev->dev.platform_data; - int is_cros_ec; - - is_cros_ec = strcmp(pdata->ec_name, CROS_EC_DEV_NAME); - - if (is_cros_ec != 0) - return 0; - - /* Only instantiate this stuff if the EC has a lightbar */ - if (ec_has_lightbar(ec)) { - ec_with_lightbar = ec; - return a->mode; - } - return 0; -} - -static struct attribute_group cros_ec_lightbar_attr_group = { +struct attribute_group cros_ec_lightbar_attr_group = { .name = "lightbar", .attrs = __lb_cmds_attrs, - .is_visible = cros_ec_lightbar_attrs_are_visible, }; static int cros_ec_lightbar_probe(struct platform_device *pd) { struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent); + struct cros_ec_platform *pdata = dev_get_platdata(ec_dev->dev); struct device *dev = &pd->dev; int ret; + /* + * Only instantiate the lightbar if the EC name is 'cros_ec'. Other EC + * devices like 'cros_pd' doesn't have a lightbar. + */ + if (strcmp(pdata->ec_name, CROS_EC_DEV_NAME) != 0) + return -ENODEV; + + /* + * Ask then for the lightbar version, if it's 0 then the 'cros_ec' + * doesn't have a lightbar. + */ + if (!get_lightbar_version(ec_dev, NULL, NULL)) + return -ENODEV; + /* Take control of the lightbar from the EC. */ lb_manual_suspend_ctrl(ec_dev, 1); @@ -635,7 +618,7 @@ static int __maybe_unused cros_ec_lightbar_resume(struct device *dev) { struct cros_ec_dev *ec_dev = dev_get_drvdata(dev); - if (userspace_control || ec_dev != ec_with_lightbar) + if (userspace_control) return 0; return lb_send_empty_cmd(ec_dev, LIGHTBAR_CMD_RESUME); @@ -645,7 +628,7 @@ static int __maybe_unused cros_ec_lightbar_suspend(struct device *dev) { struct cros_ec_dev *ec_dev = dev_get_drvdata(dev); - if (userspace_control || ec_dev != ec_with_lightbar) + if (userspace_control) return 0; return lb_send_empty_cmd(ec_dev, LIGHTBAR_CMD_SUSPEND); -- 2.19.2