From patchwork Thu Aug 6 15:33:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11703571 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 5AC38722 for ; Thu, 6 Aug 2020 16:53:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B33BB2086A for ; Thu, 6 Aug 2020 16:53:24 +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="qtmrG/B/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729559AbgHFQxX (ORCPT ); Thu, 6 Aug 2020 12:53:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729365AbgHFQu7 (ORCPT ); Thu, 6 Aug 2020 12:50:59 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1E6FC0086B7; Thu, 6 Aug 2020 08:33:22 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id o13so26959041pgf.0; Thu, 06 Aug 2020 08:33:22 -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=NXM7oKIqExo6jQUCEcqG7gsdReCWsat1fidWX99SIu0=; b=qtmrG/B/x58Madbk7LLC7WKbj2mBIkC1GmyA7WafBLX+ZoV6WYIRo1bU1eavNX5Odx H7cx7siSu0FEcpEG2ucdbQh8uMSgyJr3m/zq34an/vJzcmGC7ug1STJRw2wYoPazPWX3 TBZCJdqoyqyzJhoHsFQkqguml/jS1jLMWrcpfXAo1/LjQZa9WLmgoCG77PRUFZw8W8k1 A/MAfASV7jEhnvtYzFzzxlanVOh+iy0XW5b/BflcA14wgsmEFuXTkzOWpE74LxS4I4BL gwRxBfJbn5omiFoDDdm1r7IJHL8wf2cKCRw1mKh8WRS+dagMNRS1v5jr6fOWnfWBq/8t 1zhg== 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=NXM7oKIqExo6jQUCEcqG7gsdReCWsat1fidWX99SIu0=; b=dVf//0zjvqXYIg6M0m+pXTnQGf6rRBpRFoXxc1ye615zEoKj17MtWKMd0HMYBFBwt8 IgYwjOyzRA24hBWiRPPCW3N4IgjcvTxXiA1pdHVI3E/vgZAXvVd/F4Jzo/oTxYN/bzy3 TNV4u1Pcu3Y7TIxe/on3KEKwe48TZgp99pk/Cpca2HmGaOT7kUsIqOzeeUOGni8f98B4 OZhoa5ZrBzbzAczuOh8C6l44/r3AEiG+VbxIGCSOWaPrrJIuLxRVNWQV08+7D67gGc0y eIOfJQEsSdwxG/ZfgzW9ynmB1kxqSEZ4B84Jng5Ib8F/LzuCkVp1VNNemnjgBm44dKoe AsUw== X-Gm-Message-State: AOAM531vWQ8K+/fV/tqgitgQE93kMwMGOmIr6NIsV7vkod+qV9lEXZD6 EzM6YLr8cYD55zmuEvNis6k= X-Google-Smtp-Source: ABdhPJxPgUkkRVp7LsuLLycjHy7G09Nd7fR2ySbGBe+ceuVccLylbMsZBpLGEhRshGy64Vbl4JwA2A== X-Received: by 2002:a63:d143:: with SMTP id c3mr7775779pgj.306.1596728002409; Thu, 06 Aug 2020 08:33:22 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 12sm8379264pfn.173.2020.08.06.08.33.21 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Aug 2020 08:33:21 -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 , Brian Norris , 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 v4 7/7] pwm: cros-ec: Simplify EC error handling Date: Thu, 6 Aug 2020 08:33:08 -0700 Message-Id: <20200806153308.204605-8-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200806153308.204605-1-linux@roeck-us.net> References: <20200806153308.204605-1-linux@roeck-us.net> 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. Signed-off-by: Guenter Roeck Acked-by: Uwe Kleine-König Reviewed-by: Brian Norris --- 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;