From patchwork Sat Aug 22 15:08:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11731197 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 803CE14F6 for ; Sat, 22 Aug 2020 15:09:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 66B6E2080D for ; Sat, 22 Aug 2020 15:09:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l41Zzxas" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728385AbgHVPJr (ORCPT ); Sat, 22 Aug 2020 11:09:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728106AbgHVPJE (ORCPT ); Sat, 22 Aug 2020 11:09:04 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 329E8C061573; Sat, 22 Aug 2020 08:09:04 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id g6so179633pjl.0; Sat, 22 Aug 2020 08:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=4x4afjEuVHn+zEV5wCvJkjFDf4xgBLyslqYhfcwaoFI=; b=l41ZzxasALiq3GtUf+YfngG6SFwClg2LAvtO+OAqXoDeM+gGfG7u1b/NBUwK8yUgrG xaWZrgfoG3HxZbUY+aFcVTAVTL7f/xpmFJiFlu5BnqaE7cBcQVw8BF1KswxXK76S3MG7 O36kzQeRMnXOoYfcBJbeNx0L5P0SDyNFqcpSniZjxkHb2I40T9MRtL3pEYYOSk3o0OTv NJPNdWH7VSBwlvlB/4uLmDTNXZwuegPMl8TTm5IigkevbnQVlZ+F90q1tfjxAYkSK922 CoIV64vzCNEZzDk4AIBpIMkcWNF+k6kb8jcT4aQpawp2KtZK+FOVid7ma646wLi17mVg KKoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=4x4afjEuVHn+zEV5wCvJkjFDf4xgBLyslqYhfcwaoFI=; b=lyqG+Gt3Mj24urYZDwofSv8/9OI7Q6AoQsI0dA4lxwSo38ujq6CWmvFa1B2v30mUg9 kWqVvPyFIEZ82keUNIIcq7gQhzwtZpwfkjg9gql81+a9/B7b/Bgjesa29e5ZQaNRANEW kvtCyhL83aWrx1rY6ajUMocB7qYyATX64byo/Y7JQDy4QmrYhaUCrriphPdTjsS3zkB0 KmCtUtpY/ceYsI5TfM+MCZcuKG8Bfvg1o2tQSWVcsBTzQmlvWCnvjf0bGoEBnVIyvpLU 5BsHZsyDX5gpVbwxXVACiQJ3mGUIi3Vq2kazBkMscYdInSNpqFiVjgU36o0dLvzwps2d Lqmw== X-Gm-Message-State: AOAM530peTg5DursNGLuXKHIHdMHEIS6hdU/KSxscvYlR+Cyfh5u/z4c K4i5lG9KdgHuTU31NbCwxUk= X-Google-Smtp-Source: ABdhPJzWAsGWaIN7KhDuWtE9gvakScLvPA2dDboXnoFZwHCggj3iIeyZj2k6IEnIm87gMJKfS1/lqw== X-Received: by 2002:a17:902:c244:: with SMTP id 4mr66765plg.93.1598108943728; Sat, 22 Aug 2020 08:09:03 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id mp3sm11405445pjb.0.2020.08.22.08.09.03 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Aug 2020 08:09:03 -0700 (PDT) From: Guenter Roeck To: Enric Balletbo i Serra Cc: Jonathan Cameron , Benson Leung , Dmitry Torokhov , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lee Jones , Gwendal Grignou , Yu-Hsuan Hsu , Prashant Malani , linux-iio@vger.kernel.org, linux-input@vger.kernel.org, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck , Brian Norris Subject: [PATCH v5 1/7] iio: cros_ec: Accept -EOPNOTSUPP as 'not supported' error code Date: Sat, 22 Aug 2020 08:08:51 -0700 Message-Id: <20200822150857.205775-2-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200822150857.205775-1-linux@roeck-us.net> References: <20200822150857.205775-1-linux@roeck-us.net> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org A follow-up patch will extend the number of errors reported by cros_ec_cmd_xfer_status(). Specifically, the function will return -EOPNOTSUPP if a command is not supported by the EC. Prepare for it. Cc: Gwendal Grignou Cc: Yu-Hsuan Hsu Cc: Prashant Malani Cc: Brian Norris Acked-by: Jonathan Cameron Reviewed-by: Brian Norris Signed-off-by: Guenter Roeck --- v5: No change v4: No change v3: No change v2: No change drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c index 130ab8ce0269..d71e9064c789 100644 --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c @@ -73,7 +73,7 @@ static int cros_ec_sensors_read(struct iio_dev *indio_dev, st->core.param.sensor_offset.flags = 0; ret = cros_ec_motion_send_host_cmd(&st->core, 0); - if (ret == -EPROTO) { + if (ret == -EPROTO || ret == -EOPNOTSUPP) { /* Reading calibscale is not supported on older EC. */ *val = 1; *val2 = 0; From patchwork Sat Aug 22 15:08:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11731179 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE99C14F6 for ; Sat, 22 Aug 2020 15:09:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 95FEF207DF for ; Sat, 22 Aug 2020 15:09:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FYMHfmyQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728246AbgHVPJM (ORCPT ); Sat, 22 Aug 2020 11:09:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728173AbgHVPJF (ORCPT ); Sat, 22 Aug 2020 11:09:05 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3AE0C061573; Sat, 22 Aug 2020 08:09:05 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id j13so2068559pjd.4; Sat, 22 Aug 2020 08:09:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=3ojjDGinYxNQUXg0N/YZCfPJhsS5y6qCv15zZNisimw=; b=FYMHfmyQcP6r87y54D39SU0U/EXItY7BuTkYJg//dksggcAH0PmjNsG2HLFYlwLgsL +iAJHEBCM50FyAWpXX8ktBcxGV5aj9bN7hTgngLpw+9rM0xhvBix3c/zk96h2RR0TJIF 1u6MRRf5jclW2sk8ZIT+49NMprGPCUC8txAG0fPwSwSAk6eyuGIdkgFOxxIdE+KrsAeU cLi9ub+ChT1VakxFRXma4xICnvC6AnFl3mmh6bZcn0vDIZ6ejNR0HkYQ2Uo9RNWiuEAV 0TyDRfQUrjz/sohswEGdGfurDntNNg7vo2OM+0R46rBfumdvVwQq56cHl888YxEfKcZ7 AypQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=3ojjDGinYxNQUXg0N/YZCfPJhsS5y6qCv15zZNisimw=; b=qZBwGwwHB8rZ4vZSK30YO0CXYmKxZNbT/qrHV/KVsZIx+9U3XfsS6yEVRJ+umxTWGp Y12DSsC0jPckFb/tF+vLKgsh6yfYwUcMj0Zh+QXSYsSlA/0vUJaB+qLg39mh5Yxv2oGF LIUiLBsqcnMG+Z6HRBgQz0261XnIcsuAzkbWaQK0zxLtG5Jiu4ToMQBrkDtAcrW+iNiP GGaY7HbV4VpLT2qvagTgFXldf0ig3Z07EyOWxlgh+TnrHhmAYTTDAxZD7yg9LI7HR+BW jBdhC9/Ulxl2swterqm1CnH+q+qDKfFI6fNj4+g1VmfrglbgN0SfFMi+3Pxv6zWfU7b1 rGag== X-Gm-Message-State: AOAM531Z4xIXSkCAS/32EnyewYlrIHkHG8z3NhXJlnYvQXK79fe5sR0I CdtPWSp2t0n/bo0s8vMzY/c= X-Google-Smtp-Source: ABdhPJxdqCjvAVsoNTQz4p/S3SBkxECC2lx6F079AYS6/n65xj8rZ65zisMod2OMZx3jjLjbAP/5Pg== X-Received: by 2002:a17:90a:f0d7:: with SMTP id fa23mr1874486pjb.91.1598108945205; Sat, 22 Aug 2020 08:09:05 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id q66sm4684090pjq.17.2020.08.22.08.09.04 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Aug 2020 08:09:04 -0700 (PDT) From: Guenter Roeck To: Enric Balletbo i Serra Cc: Jonathan Cameron , Benson Leung , Dmitry Torokhov , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lee Jones , Gwendal Grignou , Yu-Hsuan Hsu , Prashant Malani , linux-iio@vger.kernel.org, linux-input@vger.kernel.org, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck , Brian Norris Subject: [PATCH v5 2/7] cros_ec_lightbar: Accept more error codes from cros_ec_cmd_xfer_status Date: Sat, 22 Aug 2020 08:08:52 -0700 Message-Id: <20200822150857.205775-3-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200822150857.205775-1-linux@roeck-us.net> References: <20200822150857.205775-1-linux@roeck-us.net> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Since commit c5cd2b47b203 ("platform/chrome: cros_ec_proto: Report command not supported") we can no longer assume that cros_ec_cmd_xfer_status() reports -EPROTO for all errors returned by the EC itself. A follow-up patch will change cros_ec_cmd_xfer_status() to report additional errors reported by the EC as distinguished Linux error codes. Handle this change by no longer assuming that -EPROTO is used to report all errors returned by the EC itself. Since errors reported by the EC are already reported in text form through sysfs attributes, extend this form of error reporting to all errors reported by cros_ec_cmd_xfer_status(). Cc: Gwendal Grignou Cc: Yu-Hsuan Hsu Cc: Prashant Malani Cc: Brian Norris Reviewed-by: Brian Norris Signed-off-by: Guenter Roeck --- v5: No change v4: No change v3: No change v2: Added patch drivers/platform/chrome/cros_ec_lightbar.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platform/chrome/cros_ec_lightbar.c index b59180bff5a3..8445cda57927 100644 --- a/drivers/platform/chrome/cros_ec_lightbar.c +++ b/drivers/platform/chrome/cros_ec_lightbar.c @@ -117,7 +117,7 @@ static int get_lightbar_version(struct cros_ec_dev *ec, param = (struct ec_params_lightbar *)msg->data; param->cmd = LIGHTBAR_CMD_VERSION; ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg); - if (ret < 0) { + if (ret < 0 && ret != -EINVAL) { ret = 0; goto exit; } @@ -298,11 +298,9 @@ static ssize_t sequence_show(struct device *dev, goto exit; ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg); - if (ret == -EPROTO) { - ret = scnprintf(buf, PAGE_SIZE, - "ERROR: EC returned %d\n", msg->result); - goto exit; - } else if (ret < 0) { + if (ret < 0) { + ret = scnprintf(buf, PAGE_SIZE, "XFER / EC ERROR %d / %d\n", + ret, msg->result); goto exit; } From patchwork Sat Aug 22 15:08:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11731177 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D3C01575 for ; Sat, 22 Aug 2020 15:09:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3FFA207DF for ; Sat, 22 Aug 2020 15:09:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TZvBBg0U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728223AbgHVPJM (ORCPT ); Sat, 22 Aug 2020 11:09:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726534AbgHVPJH (ORCPT ); Sat, 22 Aug 2020 11:09:07 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C27AC061574; Sat, 22 Aug 2020 08:09:07 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id y6so2207330plt.3; Sat, 22 Aug 2020 08:09:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=eEKURatWoOyX4mXbEcKrGBngoGWk63CMYHPsunNbJTc=; b=TZvBBg0U8y9ZfGLz46oncQ+gP9hEAr3sReiuDQUjNgwW3E3A1T7uO3Qla9jcmwuE9S LZyASHqniYTv/bBxuRnGdIWY+jxhjnsc3QEvPM5amkT864Luzzzs/cvte8fWh6aqs+F4 N2k0q4GptKmL1/MrtaZ2crfXRELCkdCxZuGl6SwAcSr5UFYqYC2aoUefbeSLrmkr2Su7 8wempBAehRGf7RZmZ7Iba9l7ZqTXs4yP/JeYrNh1HEzizVsk1athc8zOhXmisJtDK2wK UbJo43FT5Z/znVQxwmlkpFfYaacXND4e9L3YOIu438+eh4cZvR0+YBS9n2V0BvuB7dgX 7lUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=eEKURatWoOyX4mXbEcKrGBngoGWk63CMYHPsunNbJTc=; b=SNYYNcT6E2q9Te6OAaUwsmncdhBOE/Hn3b+fdlKVUyCb4+Rx1Axtk0679GWXQ7nc1E Csgi0zgUAGMxw4R5pQb4ZgCkTiu+n29TpExc3zM94Y4/0lkR2hzl7sN62QZzdcSrJr9g xwqR2/9r4NWcR9av6hDZNf/6cVtmht3HCCMZ90We/UR21+s+wCHy7KD/Ua/eBJuk8Dob vfhg74kvcj9BPmQ8w1PvkI0hNj1MNbURUYWYF2J129tZgOmSNC5Ss9Tp6gkpA4Z2YfcP TK8Q7rsUWNqtICMTvJvwIzUDVWB3N2fvZQbpEfjxyddKTKQ9NedqHiwoeJu3SKrO6xJv WfIw== X-Gm-Message-State: AOAM533AvXR7Vy1rtXsf4LquMXDfQi44mkC/eBa49pZH2uzYt0p082KH vsLLVSVr04cMPkQeZKxDj1k= X-Google-Smtp-Source: ABdhPJxex72UbBHHS47bB0l+BXemPbZkW+fJSV/POh1CAnnX2zBkQOYsRykCfMy4T9EqMQhEsfo9Dg== X-Received: by 2002:a17:902:6b45:: with SMTP id g5mr2648347plt.163.1598108946638; Sat, 22 Aug 2020 08:09:06 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id x28sm5991386pfj.73.2020.08.22.08.09.05 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Aug 2020 08:09:06 -0700 (PDT) From: Guenter Roeck To: Enric Balletbo i Serra Cc: Jonathan Cameron , Benson Leung , Dmitry Torokhov , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lee Jones , Gwendal Grignou , Yu-Hsuan Hsu , Prashant Malani , linux-iio@vger.kernel.org, linux-input@vger.kernel.org, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck , Brian Norris Subject: [PATCH v5 3/7] platform/chrome: cros_ec_sysfs: Report range of error codes from EC Date: Sat, 22 Aug 2020 08:08:53 -0700 Message-Id: <20200822150857.205775-4-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200822150857.205775-1-linux@roeck-us.net> References: <20200822150857.205775-1-linux@roeck-us.net> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Since commit c5cd2b47b203 ("platform/chrome: cros_ec_proto: Report command not supported") we can no longer assume that cros_ec_cmd_xfer_status() reports -EPROTO for all errors returned by the EC itself. A follow-up patch will change cros_ec_cmd_xfer_status() to report additional errors reported by the EC as distinguished Linux error codes. Prepare for this change by always reporting both the Linux error code and the EC error code in sysfs attributes. Cc: Gwendal Grignou Cc: Yu-Hsuan Hsu Cc: Prashant Malani Cc: Brian Norris Reviewed-by: Brian Norris Signed-off-by: Guenter Roeck --- v5: No change v4: No change v3: No change v2: Added patch drivers/platform/chrome/cros_ec_sysfs.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c index d45ea5d5bfa4..9c1e0998a721 100644 --- a/drivers/platform/chrome/cros_ec_sysfs.c +++ b/drivers/platform/chrome/cros_ec_sysfs.c @@ -150,12 +150,10 @@ static ssize_t version_show(struct device *dev, msg->command = EC_CMD_GET_BUILD_INFO + ec->cmd_offset; msg->insize = EC_HOST_PARAM_SIZE; ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg); - if (ret == -EPROTO) { - count += scnprintf(buf + count, PAGE_SIZE - count, - "Build info: EC error %d\n", msg->result); - } else if (ret < 0) { + if (ret < 0) { count += scnprintf(buf + count, PAGE_SIZE - count, - "Build info: XFER ERROR %d\n", ret); + "Build info: XFER / EC ERROR %d / %d\n", + ret, msg->result); } else { msg->data[EC_HOST_PARAM_SIZE - 1] = '\0'; count += scnprintf(buf + count, PAGE_SIZE - count, @@ -166,12 +164,10 @@ static ssize_t version_show(struct device *dev, msg->command = EC_CMD_GET_CHIP_INFO + ec->cmd_offset; msg->insize = sizeof(*r_chip); ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg); - if (ret == -EPROTO) { - count += scnprintf(buf + count, PAGE_SIZE - count, - "Chip info: EC error %d\n", msg->result); - } else if (ret < 0) { + if (ret < 0) { count += scnprintf(buf + count, PAGE_SIZE - count, - "Chip info: XFER ERROR %d\n", ret); + "Chip info: XFER / EC ERROR %d / %d\n", + ret, msg->result); } else { r_chip = (struct ec_response_get_chip_info *)msg->data; @@ -190,12 +186,10 @@ static ssize_t version_show(struct device *dev, msg->command = EC_CMD_GET_BOARD_VERSION + ec->cmd_offset; msg->insize = sizeof(*r_board); ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg); - if (ret == -EPROTO) { - count += scnprintf(buf + count, PAGE_SIZE - count, - "Board version: EC error %d\n", msg->result); - } else if (ret < 0) { + if (ret < 0) { count += scnprintf(buf + count, PAGE_SIZE - count, - "Board version: XFER ERROR %d\n", ret); + "Board version: XFER / EC ERROR %d / %d\n", + ret, msg->result); } else { r_board = (struct ec_response_board_version *)msg->data; From patchwork Sat Aug 22 15:08:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11731175 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79B401575 for ; Sat, 22 Aug 2020 15:09:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 559A72072D for ; Sat, 22 Aug 2020 15:09:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TreoCnNR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728211AbgHVPJK (ORCPT ); Sat, 22 Aug 2020 11:09:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728196AbgHVPJJ (ORCPT ); Sat, 22 Aug 2020 11:09:09 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98D0AC061575; Sat, 22 Aug 2020 08:09:08 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id kr4so2091713pjb.2; Sat, 22 Aug 2020 08:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aWfg/p1bEEsF9VR7qbKwXbT4prM1ax9SkBLPqSVouws=; b=TreoCnNRUV59m5H5mc54POb5e9AKUfujBJtw6CIU7DJ7TlGxX+yWWCP90io+UvOhtI 6lN6VARFlIqBKPqYLlaGNDPnM9Q3+Fsd5EiE77WcG1FjMNbhUiTgw+eHU9Odthuh81lh BY+V/CK+INs+HgCEm8drPMVSUzhSMeEGuR33FpIiedWXcilR1XxjcbF3SHrkRzPyH56f baurpXfeJMVOEuh5wP4ETfaQXhStCqc6nMOycfWwUbB7ksdW8nnvtGzXBBKHgb2FTwet 3BqxDuzR3/1LGrjg1flO1cB++9SUh1+CP3TNx9S7/0sxZxUkPvbe+FsBqSSJfHyMphfn oGiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=aWfg/p1bEEsF9VR7qbKwXbT4prM1ax9SkBLPqSVouws=; b=b9XiuoU01BLGuQCJyVU7COCO63YBASXCjsW+yLXpfiaadDIZAWLvIyOGXVF6Ua9Zi0 O0dl4j89f+7vKnWr7MXBPd5CBlChMVmynVrsXglu3q2Xypy3fJFwdmKiFhpo6xqit3P5 jOh6VmR12aEE++2BBzw5TlqWTwVC+PSemthapbl1LtwbHi/9cJjI7dL0EEZaODcBHMmh 5exK9XgJRa98DQRmoCL93dPa1hSrX0TxfhcOUxBVk9wTkYFSYR4DiC2KBgLNEU3jIebX MACGmRk6SBiVnmXi3cyi/2mRC6bXy1Q43zApustOTwepFICziL6DWL/2rTJX/BSg/WuT CqxQ== X-Gm-Message-State: AOAM530a2WubOv2eTbJYYvgmlyKjMt6OBlgTKiKlXrytfMOMr8nsERbb x9FPIS/3CN9WdEadDKYWY/U= X-Google-Smtp-Source: ABdhPJys2OLCfUIKzWTMevNyztH0683b7F8X4R7+XyRTVJJiiPVel4kLEjsxFqZHvK3QajGoT+87wA== X-Received: by 2002:a17:90b:154:: with SMTP id em20mr6778169pjb.173.1598108948143; Sat, 22 Aug 2020 08:09:08 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id n18sm5066040pgd.91.2020.08.22.08.09.07 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Aug 2020 08:09:07 -0700 (PDT) From: Guenter Roeck To: Enric Balletbo i Serra Cc: Jonathan Cameron , Benson Leung , Dmitry Torokhov , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lee Jones , Gwendal Grignou , Yu-Hsuan Hsu , Prashant Malani , linux-iio@vger.kernel.org, linux-input@vger.kernel.org, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck , Brian Norris Subject: [PATCH v5 4/7] pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status Date: Sat, 22 Aug 2020 08:08:54 -0700 Message-Id: <20200822150857.205775-5-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200822150857.205775-1-linux@roeck-us.net> References: <20200822150857.205775-1-linux@roeck-us.net> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Since commit c5cd2b47b203 ("platform/chrome: cros_ec_proto: Report command not supported") we can no longer assume that cros_ec_cmd_xfer_status() reports -EPROTO for all errors returned by the EC itself. A follow-up patch will change cros_ec_cmd_xfer_status() to report additional errors reported by the EC as distinguished Linux error codes. Handle this change by no longer assuming that only -EPROTO is used to report all errors returned by the EC itself. Instead, support both the old and the new error codes. Add a comment describing cros_ec_num_pwms() to explain its functionality. Cc: Gwendal Grignou Cc: Yu-Hsuan Hsu Cc: Prashant Malani Cc: Brian Norris Acked-by: Thierry Reding Acked-by: Uwe Kleine-König Signed-off-by: Guenter Roeck --- v5: Added Uwe's Acked-by: tag v4: Added comments describing cros_ec_num_pwms() in more detail Added Thierry's Acked-by: tag v3: Added patch drivers/pwm/pwm-cros-ec.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c index 09c08dee099e..94d3dff9b0e5 100644 --- a/drivers/pwm/pwm-cros-ec.c +++ b/drivers/pwm/pwm-cros-ec.c @@ -204,6 +204,11 @@ static const struct pwm_ops cros_ec_pwm_ops = { .owner = THIS_MODULE, }; +/* + * Determine the number of supported PWMs. The EC does not return the number + * of PWMs it supports directly, so we have to read the pwm duty cycle for + * subsequent channels until we get an error. + */ static int cros_ec_num_pwms(struct cros_ec_device *ec) { int i, ret; @@ -213,20 +218,30 @@ static int cros_ec_num_pwms(struct cros_ec_device *ec) u32 result = 0; ret = __cros_ec_pwm_get_duty(ec, i, &result); - /* We want to parse EC protocol errors */ - if (ret < 0 && !(ret == -EPROTO && result)) - return ret; - /* * We look for SUCCESS, INVALID_COMMAND, or INVALID_PARAM * responses; everything else is treated as an error. + * The EC error codes either map to -EOPNOTSUPP / -EINVAL, + * or -EPROTO is returned and the EC error is in the result + * field. Check for both. */ - if (result == EC_RES_INVALID_COMMAND) + switch (ret) { + case -EOPNOTSUPP: /* invalid command */ return -ENODEV; - else if (result == EC_RES_INVALID_PARAM) + case -EINVAL: /* invalid parameter */ return i; - else if (result) + case -EPROTO: + /* Old or new error return code: Handle both */ + if (result == EC_RES_INVALID_COMMAND) + return -ENODEV; + else if (result == EC_RES_INVALID_PARAM) + return i; return -EPROTO; + default: + if (ret < 0) + return ret; + break; + } } return U8_MAX; From patchwork Sat Aug 22 15:08:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11731191 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3ABEC14F6 for ; Sat, 22 Aug 2020 15:09:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2173922B3F for ; Sat, 22 Aug 2020 15:09:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eiJGeoAi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728362AbgHVPJh (ORCPT ); Sat, 22 Aug 2020 11:09:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726728AbgHVPJK (ORCPT ); Sat, 22 Aug 2020 11:09:10 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19A3CC061573; Sat, 22 Aug 2020 08:09:10 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id d4so2066976pjx.5; Sat, 22 Aug 2020 08:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=XvKl02jufHLLnMJt3E8B12KOP7zAos8o1w+WI8beqQM=; b=eiJGeoAiy9iTITHjCX2YB16/FP0kudN3tuamVNNOt4/6rE420/YRkMRyYI50lKAc6Z meJq10torKmO5TGxw7cdNAdXC97dFO+fsWTy1EQJLhzXBEt/OPQR4IYqZdoCyMuK7g9b qVAWPMRMZ2vRbJg9UbapsosDBOCseDQ0C3xmpf57YPDBGnU6wdPyEkmm0OJcegJ8muVg DrE/1xnFjxb3reyDoEp4CJmnHuWMK7ALsYtD4Tg4wJ7kXoqhZseONT36xwQ8Oj6USz+5 mKFcax61i5ZDB7vfW7gtnGzio0g7Vx0YvK+QeRlKbJkzLF7uSDk15pDs1XIs2PenOJel dxkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=XvKl02jufHLLnMJt3E8B12KOP7zAos8o1w+WI8beqQM=; b=e/2GWshzClKsYOdApdmcAUvcFP/4Hmb3ICmhfu1mzvtoe3TZ+7r9Xl1uW55edBSEtN iTLO5LmpL2PkPA0YpW8VgIJlYsNVva06DbWSHyO7Movpl12lNFSaFbbaeqCPkddvTSK0 M0oEiAVVu4EPWD+k5RDdik1NGkJPPCMTUL7VF0ekAlJvUg2jfBEks2XfwqF/+OCWjZZM 98M6xsq9uCBdv//c8kLqAGuBjH+0Z/jnk1V+gGIIXNHV6npiif8d93kN/r0lLi/KO++F 7LBAaaIYjKb8lgb5OwiIE3kZu9VdMlzAaBNdMFr3TxNwiuKpwboxrT+iAmTtBc0+mlpP PAXA== X-Gm-Message-State: AOAM533wY3QVvqXsleV1OUI/x8mzt6+Y2QH9FzVbaCHGRLpdj+HANW8G wReqJeZJXU0GpZtlSrX9TnA= X-Google-Smtp-Source: ABdhPJwA7x12JBUNVJ9JFUNiAOAwVhlsfBacnRFL3Z9rpk7Vnl3O4wTD7kKuTT2PnHENA8gXWnZF7g== X-Received: by 2002:a17:90a:19dc:: with SMTP id 28mr6324439pjj.103.1598108949630; Sat, 22 Aug 2020 08:09:09 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id a10sm5906611pfk.26.2020.08.22.08.09.09 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Aug 2020 08:09:09 -0700 (PDT) From: Guenter Roeck To: Enric Balletbo i Serra Cc: Jonathan Cameron , Benson Leung , Dmitry Torokhov , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lee Jones , Gwendal Grignou , Yu-Hsuan Hsu , Prashant Malani , linux-iio@vger.kernel.org, linux-input@vger.kernel.org, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck , Brian Norris Subject: [PATCH v5 5/7] platform/input: cros_ec: Replace -ENOTSUPP with -ENOPROTOOPT Date: Sat, 22 Aug 2020 08:08:55 -0700 Message-Id: <20200822150857.205775-6-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200822150857.205775-1-linux@roeck-us.net> References: <20200822150857.205775-1-linux@roeck-us.net> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org -ENOTSUPP is not a SUSV4 error code and should not be used. Use -ENOPROTOOPT instead to report EC_RES_INVALID_VERSION responses from the EC. This matches match the NFS response for unsupported protocol versions. Cc: Gwendal Grignou Cc: Yu-Hsuan Hsu Cc: Prashant Malani Cc: Brian Norris Acked-by: Dmitry Torokhov Signed-off-by: Guenter Roeck --- v5: No change v4: Added Dmitry's Acked-by: tag v3: Added patch drivers/input/keyboard/cros_ec_keyb.c | 2 +- drivers/platform/chrome/cros_ec_proto.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c index fc1793ca2f17..15d17c717081 100644 --- a/drivers/input/keyboard/cros_ec_keyb.c +++ b/drivers/input/keyboard/cros_ec_keyb.c @@ -348,7 +348,7 @@ static int cros_ec_keyb_info(struct cros_ec_device *ec_dev, params->event_type = event_type; ret = cros_ec_cmd_xfer_status(ec_dev, msg); - if (ret == -ENOTSUPP) { + if (ret == -ENOPROTOOPT) { /* With older ECs we just return 0 for everything */ memset(result, 0, result_size); ret = 0; diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index 8d52b3b4bd4e..f4727511fb41 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -579,7 +579,7 @@ static int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, * * Return: * >=0 - The number of bytes transferred - * -ENOTSUPP - Operation not supported + * -ENOPROTOOPT - Operation not supported * -EPROTO - Protocol error */ int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, @@ -593,7 +593,7 @@ int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, } else if (msg->result == EC_RES_INVALID_VERSION) { dev_dbg(ec_dev->dev, "Command invalid version (err:%d)\n", msg->result); - return -ENOTSUPP; + return -ENOPROTOOPT; } else if (msg->result != EC_RES_SUCCESS) { dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result); return -EPROTO; From patchwork Sat Aug 22 15:08:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11731195 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2447314F6 for ; Sat, 22 Aug 2020 15:09:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05EAF207DF for ; Sat, 22 Aug 2020 15:09:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pNazA2Rb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728255AbgHVPJg (ORCPT ); Sat, 22 Aug 2020 11:09:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728219AbgHVPJL (ORCPT ); Sat, 22 Aug 2020 11:09:11 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AA9AC061574; Sat, 22 Aug 2020 08:09:11 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id l191so290649pgd.5; Sat, 22 Aug 2020 08:09:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=JmEZo7JliKyaNvQUkZX7O3ywNsax+k7CM+J9IWyH0O8=; b=pNazA2RbIBC03uC2Y6gQ59/A9sMvImbQ+i7nzehssb+bSv8g1yzgwsnKqgegu0EpKy uRx9jP9Im6HbFHT9xg39Cm3f+jrEAiKfJfG9NvEumevHgMBEEAVzAX8BAqMS3e1jdrck l7fLOfAgMsaKP419yH/p4pS6VrAxezGA/cBQojoWK7U8p0iSXpqrmlufnJUGhUApsGZK 2efOfqXpsC052dNWCQYEP7g/dN26Fj/lWchRzpNGXBE7ac6vZNGhdousFxA8ngkH1t9T X+E7CszNV1vACKt+oZ/Aie61HRcTWSL8/8QR5WabEDSQbYnUDk8gFFjQQP7imSJ938sM YZ8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=JmEZo7JliKyaNvQUkZX7O3ywNsax+k7CM+J9IWyH0O8=; b=rEwJeUBdYmwB3WTnhKZmR0ewHO2L3zVLqmskm/8eDe6byh0+cXhQDU5ze+rBzwJtA0 aWw6XpmKbZNYQddTd2+8kYw7oWPlcfHZm5XUn6YULTUnhnIVWCCCO/XGgQdKi93f1VTQ y5QGpE/D5m8v/G5Q8F2ut4JDHv2gDuhQfMihKKsUnSQQWWGnr27xqxQ3KZ111uoykAC6 X/lApsSK0nZYtJnjBlvgX9k+YzieKR4L1WHc5PFYx2VamchicT64MTfnR3BngRwq5gjQ JUsJ8u0hAEgmUpURTiJIYkqir0nKKSihDO2sBuecPuWkclF7GJoyNUmkfgliCp6RpOtL qGag== X-Gm-Message-State: AOAM533zdwHPnFJAa8jmH+8KSBZp9fgE16gdfnmUc7GWEohwnrS8WkEg Ol42P4zShGVFlCIREh4U5UM= X-Google-Smtp-Source: ABdhPJxviXqFk8MFEQIDULTUbYU3PYJkaeWMMWejQqlChvuxU6ox4NfWGQQ5QkQSMnzmM7CHuBxoRA== X-Received: by 2002:aa7:9d0e:: with SMTP id k14mr6412670pfp.162.1598108951029; Sat, 22 Aug 2020 08:09:11 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id u8sm4504985pjy.35.2020.08.22.08.09.10 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Aug 2020 08:09:10 -0700 (PDT) From: Guenter Roeck To: Enric Balletbo i Serra Cc: Jonathan Cameron , Benson Leung , Dmitry Torokhov , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lee Jones , Gwendal Grignou , Yu-Hsuan Hsu , Prashant Malani , linux-iio@vger.kernel.org, linux-input@vger.kernel.org, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck , Brian Norris Subject: [PATCH v5 6/7] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Date: Sat, 22 Aug 2020 08:08:56 -0700 Message-Id: <20200822150857.205775-7-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200822150857.205775-1-linux@roeck-us.net> References: <20200822150857.205775-1-linux@roeck-us.net> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The EC reports a variety of error codes. Most of those, with the exception of EC_RES_INVALID_VERSION, are converted to -EPROTO. As result, the actual EC error code gets lost. Introduce cros_ec_map_error() to map EC error codes to Linux error codes, and use it in cros_ec_cmd_xfer_status() to report more meaningful errors to the caller. With this change, callers of cros_ec_cmd_xfer_status() can implement a more distinguished action without having to rely on the EC error code. At the same time, debugging is improved in situations where the Linux error code is reported to userspace and/or in the kernel log. Cc: Gwendal Grignou Cc: Yu-Hsuan Hsu Cc: Prashant Malani Cc: Brian Norris Signed-off-by: Guenter Roeck --- v5: If there is no error, cros_ec_cmd_xfer_status() needs to return the number of received bytes, not 0. While fixing that, rearranged the function to reduce its indentation. Dropped Reviewed-by:/Acked-by: tags to reflect change v4: Added Brian's Reviewed-by: tag v3: Use -ENOPROTOOPT for EC_RES_INVALID_VERSION Implement function to convert error codes v2: No change drivers/platform/chrome/cros_ec_proto.c | 57 ++++++++++++++++++++----- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index f4727511fb41..dda182132a6a 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -15,6 +15,43 @@ #define EC_COMMAND_RETRIES 50 +static const int cros_ec_error_map[] = { + [EC_RES_INVALID_COMMAND] = -EOPNOTSUPP, + [EC_RES_ERROR] = -EIO, + [EC_RES_INVALID_PARAM] = -EINVAL, + [EC_RES_ACCESS_DENIED] = -EACCES, + [EC_RES_INVALID_RESPONSE] = -EPROTO, + [EC_RES_INVALID_VERSION] = -ENOPROTOOPT, + [EC_RES_INVALID_CHECKSUM] = -EBADMSG, + [EC_RES_IN_PROGRESS] = -EINPROGRESS, + [EC_RES_UNAVAILABLE] = -ENODATA, + [EC_RES_TIMEOUT] = -ETIMEDOUT, + [EC_RES_OVERFLOW] = -EOVERFLOW, + [EC_RES_INVALID_HEADER] = -EBADR, + [EC_RES_REQUEST_TRUNCATED] = -EBADR, + [EC_RES_RESPONSE_TOO_BIG] = -EFBIG, + [EC_RES_BUS_ERROR] = -EFAULT, + [EC_RES_BUSY] = -EBUSY, + [EC_RES_INVALID_HEADER_VERSION] = -EBADMSG, + [EC_RES_INVALID_HEADER_CRC] = -EBADMSG, + [EC_RES_INVALID_DATA_CRC] = -EBADMSG, + [EC_RES_DUP_UNAVAILABLE] = -ENODATA, +}; + +static int cros_ec_map_error(uint32_t result) +{ + int ret = 0; + + if (result != EC_RES_SUCCESS) { + if (result < ARRAY_SIZE(cros_ec_error_map) && cros_ec_error_map[result]) + ret = cros_ec_error_map[result]; + else + ret = -EPROTO; + } + + return ret; +} + static int prepare_packet(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) { @@ -579,26 +616,24 @@ static int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, * * Return: * >=0 - The number of bytes transferred - * -ENOPROTOOPT - Operation not supported - * -EPROTO - Protocol error + * <0 - Linux error code */ int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) { - int ret; + int ret, mapped; ret = cros_ec_cmd_xfer(ec_dev, msg); if (ret < 0) { dev_err(ec_dev->dev, "Command xfer error (err:%d)\n", ret); - } else if (msg->result == EC_RES_INVALID_VERSION) { - dev_dbg(ec_dev->dev, "Command invalid version (err:%d)\n", - msg->result); - return -ENOPROTOOPT; - } else if (msg->result != EC_RES_SUCCESS) { - dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result); - return -EPROTO; + return ret; + } + mapped = cros_ec_map_error(msg->result); + if (mapped) { + dev_dbg(ec_dev->dev, "Command result (err: %d [%d])\n", + msg->result, mapped); + ret = mapped; } - return ret; } EXPORT_SYMBOL(cros_ec_cmd_xfer_status); From patchwork Sat Aug 22 15:08:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11731181 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8022B14F6 for ; Sat, 22 Aug 2020 15:09:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 666C22072D for ; Sat, 22 Aug 2020 15:09:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YbE1w7oD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728325AbgHVPJ0 (ORCPT ); Sat, 22 Aug 2020 11:09:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728255AbgHVPJN (ORCPT ); Sat, 22 Aug 2020 11:09:13 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E33C3C061573; Sat, 22 Aug 2020 08:09:12 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id q1so2076143pjd.1; Sat, 22 Aug 2020 08:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tyw6vA6yQNsN/wIQW/tyNI4Wu5/Dv3Pgq6wDKg4/E3s=; b=YbE1w7oD6AZf3nS8X/ngNno+kA8Zo52fmQNdcS18SCftss1D3yFLglNwe+oipf8jOX DRFtnMAZWNojSnWzlc/n6pDvWWDbgcQwFYYCml+QMVZGfqO3RzcIRiXLGa0Nsm3se4oe Fei6MpahuQeRmntgo9MrDRT//+440ZakOLhqTIEGfW696V25d3fA/s0NxNA0bmIH2OVi LuKWw37yjwTZp14MPJNrDNSPou2msXBze3NnXQcnsLezWul4nMFMXOIvi8+w1NM6PWyK zF+G4NS6A5QAswGttxfG3mb6YYzOK+QKMl30yPAs9o7g1KjIoAVhN7zodbgq6HqskgA+ FeIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=tyw6vA6yQNsN/wIQW/tyNI4Wu5/Dv3Pgq6wDKg4/E3s=; b=FjD7n+67SrhlkyqQxKEtQktzsWGKn2qaadHj2+SqqwxqTNeVYYF44RDfadUX6fgSfA T8ksI+2dP3ZlpeB6rBg7KIV00Kod0aa140hLzIP7nD8CGvqW3jgmkZNCh+AzUvmNoz1g bGEtBMlKZnWFTBoYY+zNkFsVq9PiTWQD8r7k3Lkv0hlQ1KAVvuppRWFwLPeywExmVImA l53EXmTkk9LDgMHHbG4+hIx0XepPAFagARdVqpcZxVv67ujJF2MqVNZffwkT/Uj8fbV7 fsK+8Jv6Qsa2g2f3p/bjW7KUp7ZGQiSB1ucbMBI3U1cdWT/dGPNwP9bkXWBuWo0ge27m Ol3w== X-Gm-Message-State: AOAM533atrtWbfc6eOwW5/GQ17svOWi2srKAnHOChznVaKjXixAFzTj2 I5HGZxMorzWKvw8TI05au5o= X-Google-Smtp-Source: ABdhPJyVbAW/pyqe68An3ewBWq6iwe7ykVWD8BuDS3ND+hrizcTTwB7VQ11E/eWTtXdShmZOKg5Xpw== X-Received: by 2002:a17:902:7605:: with SMTP id k5mr6513045pll.122.1598108952417; Sat, 22 Aug 2020 08:09:12 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id l9sm5331944pgg.29.2020.08.22.08.09.11 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Aug 2020 08:09:12 -0700 (PDT) From: Guenter Roeck To: Enric Balletbo i Serra Cc: Jonathan Cameron , Benson Leung , Dmitry Torokhov , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lee Jones , Gwendal Grignou , Yu-Hsuan Hsu , Prashant Malani , linux-iio@vger.kernel.org, linux-input@vger.kernel.org, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [PATCH v5 7/7] pwm: cros-ec: Simplify EC error handling Date: Sat, 22 Aug 2020 08:08:57 -0700 Message-Id: <20200822150857.205775-8-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200822150857.205775-1-linux@roeck-us.net> References: <20200822150857.205775-1-linux@roeck-us.net> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org With enhanced error reporting from cros_ec_cmd_xfer_status() in place, we can fully use it and no longer rely on EC error codes. Acked-by: Uwe Kleine-König Reviewed-by: Brian Norris Signed-off-by: Guenter Roeck --- v5: Added Brian's Reviewed-by: tag Added Uwe's Acked-by: tag v4: Added patch to series drivers/pwm/pwm-cros-ec.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c index 94d3dff9b0e5..c1c337969e4e 100644 --- a/drivers/pwm/pwm-cros-ec.c +++ b/drivers/pwm/pwm-cros-ec.c @@ -81,8 +81,7 @@ static int cros_ec_pwm_set_duty(struct cros_ec_device *ec, u8 index, u16 duty) return cros_ec_cmd_xfer_status(ec, msg); } -static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index, - u32 *result) +static int cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index) { struct { struct cros_ec_command msg; @@ -107,19 +106,12 @@ static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index, params->index = index; ret = cros_ec_cmd_xfer_status(ec, msg); - if (result) - *result = msg->result; if (ret < 0) return ret; return resp->duty; } -static int cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index) -{ - return __cros_ec_pwm_get_duty(ec, index, NULL); -} - static int cros_ec_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, const struct pwm_state *state) { @@ -215,28 +207,18 @@ static int cros_ec_num_pwms(struct cros_ec_device *ec) /* The index field is only 8 bits */ for (i = 0; i <= U8_MAX; i++) { - u32 result = 0; - - ret = __cros_ec_pwm_get_duty(ec, i, &result); + ret = cros_ec_pwm_get_duty(ec, i); /* * We look for SUCCESS, INVALID_COMMAND, or INVALID_PARAM * responses; everything else is treated as an error. - * The EC error codes either map to -EOPNOTSUPP / -EINVAL, - * or -EPROTO is returned and the EC error is in the result - * field. Check for both. + * The EC error codes map to -EOPNOTSUPP and -EINVAL, + * so check for those. */ switch (ret) { case -EOPNOTSUPP: /* invalid command */ return -ENODEV; case -EINVAL: /* invalid parameter */ return i; - case -EPROTO: - /* Old or new error return code: Handle both */ - if (result == EC_RES_INVALID_COMMAND) - return -ENODEV; - else if (result == EC_RES_INVALID_PARAM) - return i; - return -EPROTO; default: if (ret < 0) return ret;