Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp290264ybt; Tue, 23 Jun 2020 22:32:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylnNpsPjzuDJa1UJSyZaIdnSqIgJAQKdteas47oiNWBHDM/WvGHBUHxq3VZLRnBqoZZRfL X-Received: by 2002:a17:907:2058:: with SMTP id pg24mr15398825ejb.79.1592976761648; Tue, 23 Jun 2020 22:32:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592976761; cv=none; d=google.com; s=arc-20160816; b=UcaJUCsshFFzhAGDYDTHbw5NtCKeVOXiKmMvb7s3PnbITk1hJjVtk9qFH2U66h5Lpo rksvDg4CTRc4f/tA4LspLeveq6truGUNKI7m5RPExSa6lNVdWXZgqBb7i6vdlBPS12+F Ye9Xn0qcnmQxlpKrZP6pGGXFHGa8BtQy56gePNYamcTAU5A16gszzSYOzHsn1I1zTe5f 4xdA08Ob/H2xZzdUQ0RDn0GkouXTuMEL7/LNYLjIv8wf+fdYewfHS9XXDadwf+hptYlg IJGfz6TQoJu1ZA5MrY25RXkV5NzDffULBYL4oUgHd4F5lEvpTDCEhsErbqzRNnZj7z1u 3H1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=VG0SEnxTn6y79rfr3chclYfyp0tviayRgosKteSAoRw=; b=LpVNUkFUEj3Eq7d9pKfUkwq5GEyPwi4Aey2jpMzWOv9KKSQ8rOrgtvI7MQJshO6mdy 8Trc/g2STHcylfX8u5nAiNQ8BFJbqiTUnReq2fV5zqgpyzSI22uZtt6FK5LabRG1jATs Z/d45Svx1orjjN65Lrgs3YVOiEuyB9yr/x4dCgA+LZAIXBUqjnwQMEY2/LLhHsmO4jYs OpyjLjYGBL/2I4lWh+ydYmvlpzr0ZETBnBXP03EZE4Ku1AL65BOy4+WlwKcuCixs7e0v hRUbdaiQWUfUFHzJhQeIAVW1HUJIhAc363PlL0fKO97BLnAwiUlxtueVOAM3xjWoqcEw vUmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o6si4257503edq.450.2020.06.23.22.32.18; Tue, 23 Jun 2020 22:32:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388922AbgFXFaD (ORCPT + 99 others); Wed, 24 Jun 2020 01:30:03 -0400 Received: from mga17.intel.com ([192.55.52.151]:59032 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727957AbgFXFaC (ORCPT ); Wed, 24 Jun 2020 01:30:02 -0400 IronPort-SDR: WYqBgP8APv2zSPNwH4Q8pGsITDEQyUIgeAc6LgufJ0AAtfNR1CDtoqtIgq5bfEW2nvF0BGNfqy Be/iHkvPteMA== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="124597091" X-IronPort-AV: E=Sophos;i="5.75,274,1589266800"; d="scan'208";a="124597091" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2020 22:30:02 -0700 IronPort-SDR: /YXuIUhNkNjNpiuyXCOM96a/xMVp2Ev2JwKD0G4s5SBW3XUyaQv1OLBsHE4fe1bVkYNkIykq3Q DkJaSxG5J1hA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,274,1589266800"; d="scan'208";a="452513257" Received: from bard-ubuntu.sh.intel.com ([10.239.13.33]) by orsmga005.jf.intel.com with ESMTP; 23 Jun 2020 22:29:58 -0700 From: Bard Liao To: alsa-devel@alsa-project.org, vkoul@kernel.org Cc: vinod.koul@linaro.org, linux-kernel@vger.kernel.org, tiwai@suse.de, broonie@kernel.org, gregkh@linuxfoundation.org, jank@cadence.com, srinivas.kandagatla@linaro.org, rander.wang@linux.intel.com, ranjani.sridharan@linux.intel.com, hui.wang@canonical.com, pierre-louis.bossart@linux.intel.com, sanyog.r.kale@intel.com, slawomir.blauciak@intel.com, mengdong.lin@intel.com, bard.liao@intel.com Subject: [PATCH 1/9] soundwire: intel: reuse code for wait loops to set/clear bits Date: Wed, 24 Jun 2020 01:35:38 +0800 Message-Id: <20200623173546.21870-2-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200623173546.21870-1-yung-chuan.liao@linux.intel.com> References: <20200623173546.21870-1-yung-chuan.liao@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pierre-Louis Bossart Refactor code and use same routines on set/clear Signed-off-by: Pierre-Louis Bossart Signed-off-by: Bard Liao --- drivers/soundwire/intel.c | 45 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index 7a65414e5714..8c7ae07c0fe1 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -123,40 +123,33 @@ static inline void intel_writew(void __iomem *base, int offset, u16 value) writew(value, base + offset); } +static int intel_wait_bit(void __iomem *base, int offset, u32 mask, u32 target) +{ + int timeout = 10; + u32 reg_read; + + do { + reg_read = readl(base + offset); + if ((reg_read & mask) == target) + return 0; + + timeout--; + usleep_range(50, 100); + } while (timeout != 0); + + return -EAGAIN; +} + static int intel_clear_bit(void __iomem *base, int offset, u32 value, u32 mask) { - int timeout = 10; - u32 reg_read; - writel(value, base + offset); - do { - reg_read = readl(base + offset); - if (!(reg_read & mask)) - return 0; - - timeout--; - udelay(50); - } while (timeout != 0); - - return -EAGAIN; + return intel_wait_bit(base, offset, mask, 0); } static int intel_set_bit(void __iomem *base, int offset, u32 value, u32 mask) { - int timeout = 10; - u32 reg_read; - writel(value, base + offset); - do { - reg_read = readl(base + offset); - if (reg_read & mask) - return 0; - - timeout--; - udelay(50); - } while (timeout != 0); - - return -EAGAIN; + return intel_wait_bit(base, offset, mask, mask); } /* -- 2.17.1