Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1568418pxp; Thu, 10 Mar 2022 07:58:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHNDtz1hMKDIEaEF2mPNCSbH/13QfaMCBnxbDJ1VsyawYEvSwEwEcSSwVwSqFzUuAyUVK9 X-Received: by 2002:a17:907:720d:b0:6d7:cdc:958c with SMTP id dr13-20020a170907720d00b006d70cdc958cmr4765252ejc.361.1646927900336; Thu, 10 Mar 2022 07:58:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646927900; cv=none; d=google.com; s=arc-20160816; b=BEj8vA3XeqazopTYVZSqjd93dqUySRJhxJVH3rcRh81lELvZblb8jlSE+WJ5mloDso 2pLotMBaNpk5qvdsta/kzMjycr4gyO70B7DH6vjWaA158XoXeisT038tRY+v+d4OQrTB cpQu24aYyjeKiJAf8bR+ABNm7Z1iYFZ45Xsw/cWE/xyiw/TxDaGCSpWXfKh1gKcbwqMF IaXmt6Fas6GlYiguiKiVJCrlT0OK97ky3yj0ih157YcIOjG0SHVELaBeP4zEQYJJ+yrk DmalVfyL+D7NxTgTAt25C21tzCJX5lAw0/c3UZJXKqoZgIIz5Slm9iz5a/Sqaz3LrkIn uq4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=+mgizJNjOYF4lch4iTAKF7piDFY6Ykg49t6OGyo4hho=; b=yXGDPsrwEir0PrlyFyq0+ElXLhDiCD9Mudg+yMZT5cMeSGmND7hEuSOJQXMC2U61iu s1GzOaLgVLU49wvwiGRvAC9tV9dCIJ1bE9iPzLZzJ+/bHmz9rsn2O4jLZRTqa73+oPbO IyyRcvByus48vxXDVKXZFay/vcoo4c2thuyrmgE1fp3caSn9XP58Ml8Y81N1u+sRJFoF mqO1corbyMIzZ3ncjvNwK0ZepIQtdt4vvLLF7y+rx65DO5Pf/YGbIjYc/rDn3jtRyC5o 6MjL5RUMQPhc6qGBk8yNgVhHDdkF5IU4iVnkTq+pp7QKbr5KuxVroe2d65RjzeF1BXfZ h5mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf-com.20210112.gappssmtp.com header.s=20210112 header.b=H97fj5Xc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc34-20020a1709078a2200b006d70498a9f9si3855829ejc.815.2022.03.10.07.57.56; Thu, 10 Mar 2022 07:58:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@semihalf-com.20210112.gappssmtp.com header.s=20210112 header.b=H97fj5Xc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244986AbiCJOeJ (ORCPT + 99 others); Thu, 10 Mar 2022 09:34:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243996AbiCJO2J (ORCPT ); Thu, 10 Mar 2022 09:28:09 -0500 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D44E3B2D6C for ; Thu, 10 Mar 2022 06:23:07 -0800 (PST) Received: by mail-lf1-x12c.google.com with SMTP id w27so9732522lfa.5 for ; Thu, 10 Mar 2022 06:23:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+mgizJNjOYF4lch4iTAKF7piDFY6Ykg49t6OGyo4hho=; b=H97fj5Xc9OYd/KWfmpTAh3vt0Gmh7v3twAo/7Y+iRLHI1rglIJs8yAG/HuTkBnnUE5 7LlMAKLiPw+FiRiIMh73MYSiLInF5I3Ij/jGq45LOIuY0gZqSNgdnAAVgrB8sVF2LscA ywS5RXFZWN0s7pCP/xcixRch5bTE6FUvJwoQmV8IAUioaq/ao9sq+yhG43AOjiCC3idW lFHW40TW4ZrC8rpggm9YpSHwVy08NxMpWgHvh4J3LqPt26aqgWh47f5Hds7ZA/53a6ew lBD4thx0TyjxK1TJZmhYXCb2OoMSdgy6WCqrG1lttLVVtev+MkS2Ms/f8rR1Jf/3MRJ4 fL4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+mgizJNjOYF4lch4iTAKF7piDFY6Ykg49t6OGyo4hho=; b=YOSTejpJwdfJ0Nmw637vXt6B1ZJvpPdqFnlMbaNdKW0bz2aFthHhhQe/BrGpVuv9mO d2Z2za4EhmlqlArFRVrtcXiLcVuS+OksFzoosRoC92wXm+sqqma7RZFBL0yBy7uQf77l ViIlVGS4scCmKtUJbq6c8YZqa2t77OBj58T4yW7AEq+53Ah1FJQCw/iFd/bXwi91KOwo Fjr/duA6i3t0fhdKOxUEiI8FFCD6h5cM7nVQ9/eQOHQcHPrpnC7xbPxn8+nm6NlPuBOl pOURpzTPvgYFeEUtFjKsdblqlOoAsCSq/ISmxIfnpBvTZKa5YBQv7wqCh2ddtyJwOifH vKYA== X-Gm-Message-State: AOAM531Gkufm5PKjpyDlZRQiDu47VN4Ic9nd6kJb9SSi/IrQClQTw0Wm xZ5XumWrmk0VGw0U/lgFRrCq4boU9uOeQA== X-Received: by 2002:ac2:4342:0:b0:445:b98c:edd3 with SMTP id o2-20020ac24342000000b00445b98cedd3mr3190060lfl.348.1646922179267; Thu, 10 Mar 2022 06:22:59 -0800 (PST) Received: from dabros-l.roam.corp.google.com ([185.157.14.92]) by smtp.gmail.com with ESMTPSA id cf12-20020a056512280c00b004485b8f37b7sm676993lfb.277.2022.03.10.06.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 06:22:58 -0800 (PST) From: Jan Dabros To: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, jarkko.nikula@linux.intel.com, andriy.shevchenko@linux.intel.com Cc: wsa@kernel.org, upstream@semihalf.com, jsd@semihalf.com Subject: [PATCH -next] i2c: designware: Add helper to remove redundancy Date: Thu, 10 Mar 2022 15:22:36 +0100 Message-Id: <20220310142236.192811-1-jsd@semihalf.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Simplify code by adding an extra static function for sending I2C requests and verifying results. Signed-off-by: Jan Dabros --- drivers/i2c/busses/i2c-designware-amdpsp.c | 44 ++++++++++++---------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c index c64e459afb5c..cc758792f150 100644 --- a/drivers/i2c/busses/i2c-designware-amdpsp.c +++ b/drivers/i2c/busses/i2c-designware-amdpsp.c @@ -229,6 +229,26 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) return ret; } +static int psp_send_i2c_req_check_err(enum psp_i2c_req_type request) +{ + int status; + + status = psp_send_i2c_req(request); + if (status) { + if (status == -ETIMEDOUT) + dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n", + (request == PSP_I2C_REQ_ACQUIRE) ? + "release" : "acquire"); + else + dev_err(psp_i2c_dev, "PSP communication error\n"); + + dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n"); + psp_i2c_mbox_fail = true; + } + + return status; +} + static int psp_acquire_i2c_bus(void) { int status; @@ -248,17 +268,9 @@ static int psp_acquire_i2c_bus(void) goto cleanup; }; - status = psp_send_i2c_req(PSP_I2C_REQ_ACQUIRE); - if (status) { - if (status == -ETIMEDOUT) - dev_err(psp_i2c_dev, "Timed out waiting for PSP to release I2C bus\n"); - else - dev_err(psp_i2c_dev, "PSP communication error\n"); - - dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n"); - psp_i2c_mbox_fail = true; + status = psp_send_i2c_req_check_err(PSP_I2C_REQ_ACQUIRE); + if (status) goto cleanup; - } psp_i2c_sem_acquired = jiffies; psp_i2c_access_count++; @@ -293,17 +305,9 @@ static void psp_release_i2c_bus(void) goto cleanup; /* Send a release command to PSP */ - status = psp_send_i2c_req(PSP_I2C_REQ_RELEASE); - if (status) { - if (status == -ETIMEDOUT) - dev_err(psp_i2c_dev, "Timed out waiting for PSP to acquire I2C bus\n"); - else - dev_err(psp_i2c_dev, "PSP communication error\n"); - - dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n"); - psp_i2c_mbox_fail = true; + status = psp_send_i2c_req_check_err(PSP_I2C_REQ_RELEASE); + if (status) goto cleanup; - } dev_dbg(psp_i2c_dev, "PSP semaphore held for %ums\n", jiffies_to_msecs(jiffies - psp_i2c_sem_acquired)); -- 2.35.1.616.g0bdcbb4464-goog