Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1040147ybh; Wed, 11 Mar 2020 16:16:56 -0700 (PDT) X-Google-Smtp-Source: ADFU+vujletHxXqrnjXdOvguBBTZl5PTwFdbKDr0kgnpy2uA4XJmildcKbg16PMbJUZneScEqsnB X-Received: by 2002:a54:4195:: with SMTP id 21mr682125oiy.144.1583968616811; Wed, 11 Mar 2020 16:16:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583968616; cv=none; d=google.com; s=arc-20160816; b=V7F5R1hrWdbAL7ICyGB2Np/X5/a9ybHI4Pz6RDez5SKvOpxcYnH50aIId31t9LEO4s XjJ9a7kT8tjK1mr2+ydpy4CWPXAxOJhaKC4bCzR5NR5bx3lRCCxl1jkKGtWCqqvzgC3O ZMVrcOoUZoT6DJnWN7SB8Kn0brNzw3V6mVnuPDB6UQDdGMjljkwNKBW3Xo0mTzs9d0ZB +5H+eseWKq9PJqtYbhX+yno1ANdaSCuGptayc/jsczrNu1x6Gz3nanyx24rRkIaZQWOC jjGToUEylKu8V5xFETMYyEPQ1kL+pVVQQtHkJnntM+ZiMjxNPtua8T+rTLxpYlwQmXRT vCAw== 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 :dkim-signature; bh=PV3+rsqW3G7K5hlkhIrJBc69bnftS3pQw9KwpyvMaqE=; b=XNXW+UOMskbkeIYhY46Ly9mUY66TMJrhrY/fV1Kl4pn5tJZl0T8jldKKHmkNoUvQKX u3nzgvCWq0ldi8mKIo/0LlcmePHCSGYsUzaR6m03/Kt6BHInVqEvUjBUdt8bQQdzTFzG TXzHq5SmEJ3dCReeYJ+pYAxKj5hMWitHaufdEIeKCPKNYhETqQf0eJa0I2BvCf8Dew6k OCDhIY7T4Zt/zpxluLCkQAvsM9svL1NffnAArpTrPIeJ5BeVnLeV9ot0sY2ApsOGaTc1 EC3BbmfU9ZM6LbRMbcxhICweM2kEoD6kRF4wL5/uq8rx+S/y6lbU0DpmUU3MAAyslDoz 36Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=LPNhui0z; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o64si1837579oib.72.2020.03.11.16.16.39; Wed, 11 Mar 2020 16:16:56 -0700 (PDT) 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; dkim=pass header.i=@chromium.org header.s=google header.b=LPNhui0z; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731462AbgCKXOO (ORCPT + 99 others); Wed, 11 Mar 2020 19:14:14 -0400 Received: from mail-pj1-f65.google.com ([209.85.216.65]:40798 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731446AbgCKXON (ORCPT ); Wed, 11 Mar 2020 19:14:13 -0400 Received: by mail-pj1-f65.google.com with SMTP id bo3so347303pjb.5 for ; Wed, 11 Mar 2020 16:14:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PV3+rsqW3G7K5hlkhIrJBc69bnftS3pQw9KwpyvMaqE=; b=LPNhui0z7fgOHv5VmaKW8Q3oPQibJt17I4z7uvFu3ortliSvgBwYPXf2hbqMvgwA3r kUBL7zN9EcbyRr8IPmVce235Q1MlVSTl1n9ioc5ZK8Y+2ZpL8tgbLHalS3apy8Sh6Qi/ xdGnQFWD7k10rP0OG7mb5il/kktLXrrmT8fdo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PV3+rsqW3G7K5hlkhIrJBc69bnftS3pQw9KwpyvMaqE=; b=H81NfFiV4ygORfQV1Y8OHHmFtAMfQ9niEwC2V3sz/Q25YDSuuyhqHmRaRfI1LVHCEs nbgZ30yC+4odiTW+MWw/59v2RasyinhLU5s7oWwvfNYhxnT2FIph5bBzBG4a5dW/4/v7 BRSKY3chEL+QcTcxWYTVuQTL1tsuOPYMwYFgudyaCD2mBsXv9NICzkSdEcQhwC27XSYa FW5gL5OVPsCmBqGucUX2KtPdp8LH4vGUvGf7suXfWntn6QXM4mZhHCvudQCO7+SsgxUQ pxmtXAgc/RGp1kqCWxWAX1LRv3IFPzZPRDfRbmECQW0O4Nc/Qbkkx3vL8ErgPW5KeisI 0zSA== X-Gm-Message-State: ANhLgQ2slRx/3WeNc26vUcUTJBMqRpPiiV1Vsfrp4XjVFEdzb3bhiGLR GLgNSbr/agFF1++Ns4FzYNI8hg== X-Received: by 2002:a17:90b:19ca:: with SMTP id nm10mr1029173pjb.157.1583968452725; Wed, 11 Mar 2020 16:14:12 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id g75sm2606334pje.37.2020.03.11.16.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 16:14:12 -0700 (PDT) From: Douglas Anderson To: Andy Gross , Bjorn Andersson , Maulik Shah Cc: mka@chromium.org, Rajendra Nayak , evgreen@chromium.org, Lina Iyer , swboyd@chromium.org, Douglas Anderson , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFT PATCH v2 01/10] drivers: qcom: rpmh-rsc: Clean code reading/writing regs/cmds Date: Wed, 11 Mar 2020 16:13:39 -0700 Message-Id: <20200311161104.RFT.v2.1.I1b754137e8089e46cf33fc2ea270734ec3847ec4@changeid> X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog In-Reply-To: <20200311231348.129254-1-dianders@chromium.org> References: <20200311231348.129254-1-dianders@chromium.org> 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 This patch makes two changes, both of which should be no-ops: 1. Make read_tcs_reg() / read_tcs_cmd() symmetric to write_tcs_reg() / write_tcs_cmd(). 2. Change the order of operations in the above functions to make it more obvious to me what the math is doing. Specifically first you want to find the right TCS, then the right register, and then multiply by the command ID if necessary. Signed-off-by: Douglas Anderson --- Changes in v2: None drivers/soc/qcom/rpmh-rsc.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c index b71822131f59..b87b79f0347d 100644 --- a/drivers/soc/qcom/rpmh-rsc.c +++ b/drivers/soc/qcom/rpmh-rsc.c @@ -61,28 +61,33 @@ #define CMD_STATUS_ISSUED BIT(8) #define CMD_STATUS_COMPL BIT(16) -static u32 read_tcs_reg(struct rsc_drv *drv, int reg, int tcs_id, int cmd_id) +static u32 read_tcs_cmd(struct rsc_drv *drv, int reg, int tcs_id, int cmd_id) { - return readl_relaxed(drv->tcs_base + reg + RSC_DRV_TCS_OFFSET * tcs_id + + return readl_relaxed(drv->tcs_base + RSC_DRV_TCS_OFFSET * tcs_id + reg + RSC_DRV_CMD_OFFSET * cmd_id); } +static u32 read_tcs_reg(struct rsc_drv *drv, int reg, int tcs_id) +{ + return readl_relaxed(drv->tcs_base + RSC_DRV_TCS_OFFSET * tcs_id + reg); +} + static void write_tcs_cmd(struct rsc_drv *drv, int reg, int tcs_id, int cmd_id, u32 data) { - writel_relaxed(data, drv->tcs_base + reg + RSC_DRV_TCS_OFFSET * tcs_id + + writel_relaxed(data, drv->tcs_base + RSC_DRV_TCS_OFFSET * tcs_id + reg + RSC_DRV_CMD_OFFSET * cmd_id); } static void write_tcs_reg(struct rsc_drv *drv, int reg, int tcs_id, u32 data) { - writel_relaxed(data, drv->tcs_base + reg + RSC_DRV_TCS_OFFSET * tcs_id); + writel_relaxed(data, drv->tcs_base + RSC_DRV_TCS_OFFSET * tcs_id + reg); } static void write_tcs_reg_sync(struct rsc_drv *drv, int reg, int tcs_id, u32 data) { - writel(data, drv->tcs_base + reg + RSC_DRV_TCS_OFFSET * tcs_id); + writel(data, drv->tcs_base + RSC_DRV_TCS_OFFSET * tcs_id + reg); for (;;) { if (data == readl(drv->tcs_base + reg + RSC_DRV_TCS_OFFSET * tcs_id)) @@ -94,7 +99,7 @@ static void write_tcs_reg_sync(struct rsc_drv *drv, int reg, int tcs_id, static bool tcs_is_free(struct rsc_drv *drv, int tcs_id) { return !test_bit(tcs_id, drv->tcs_in_use) && - read_tcs_reg(drv, RSC_DRV_STATUS, tcs_id, 0); + read_tcs_reg(drv, RSC_DRV_STATUS, tcs_id); } static struct tcs_group *get_tcs_of_type(struct rsc_drv *drv, int type) @@ -212,7 +217,7 @@ static irqreturn_t tcs_tx_done(int irq, void *p) const struct tcs_request *req; struct tcs_cmd *cmd; - irq_status = read_tcs_reg(drv, RSC_DRV_IRQ_STATUS, 0, 0); + irq_status = read_tcs_reg(drv, RSC_DRV_IRQ_STATUS, 0); for_each_set_bit(i, &irq_status, BITS_PER_LONG) { req = get_req_from_tcs(drv, i); @@ -226,7 +231,7 @@ static irqreturn_t tcs_tx_done(int irq, void *p) u32 sts; cmd = &req->cmds[j]; - sts = read_tcs_reg(drv, RSC_DRV_CMD_STATUS, i, j); + sts = read_tcs_cmd(drv, RSC_DRV_CMD_STATUS, i, j); if (!(sts & CMD_STATUS_ISSUED) || ((req->wait_for_compl || cmd->wait) && !(sts & CMD_STATUS_COMPL))) { @@ -265,7 +270,7 @@ static void __tcs_buffer_write(struct rsc_drv *drv, int tcs_id, int cmd_id, cmd_msgid |= msg->wait_for_compl ? CMD_MSGID_RESP_REQ : 0; cmd_msgid |= CMD_MSGID_WRITE; - cmd_complete = read_tcs_reg(drv, RSC_DRV_CMD_WAIT_FOR_CMPL, tcs_id, 0); + cmd_complete = read_tcs_reg(drv, RSC_DRV_CMD_WAIT_FOR_CMPL, tcs_id); for (i = 0, j = cmd_id; i < msg->num_cmds; i++, j++) { cmd = &msg->cmds[i]; @@ -281,7 +286,7 @@ static void __tcs_buffer_write(struct rsc_drv *drv, int tcs_id, int cmd_id, } write_tcs_reg(drv, RSC_DRV_CMD_WAIT_FOR_CMPL, tcs_id, cmd_complete); - cmd_enable |= read_tcs_reg(drv, RSC_DRV_CMD_ENABLE, tcs_id, 0); + cmd_enable |= read_tcs_reg(drv, RSC_DRV_CMD_ENABLE, tcs_id); write_tcs_reg(drv, RSC_DRV_CMD_ENABLE, tcs_id, cmd_enable); } @@ -294,7 +299,7 @@ static void __tcs_trigger(struct rsc_drv *drv, int tcs_id) * While clearing ensure that the AMC mode trigger is cleared * and then the mode enable is cleared. */ - enable = read_tcs_reg(drv, RSC_DRV_CONTROL, tcs_id, 0); + enable = read_tcs_reg(drv, RSC_DRV_CONTROL, tcs_id); enable &= ~TCS_AMC_MODE_TRIGGER; write_tcs_reg_sync(drv, RSC_DRV_CONTROL, tcs_id, enable); enable &= ~TCS_AMC_MODE_ENABLE; @@ -319,10 +324,10 @@ static int check_for_req_inflight(struct rsc_drv *drv, struct tcs_group *tcs, if (tcs_is_free(drv, tcs_id)) continue; - curr_enabled = read_tcs_reg(drv, RSC_DRV_CMD_ENABLE, tcs_id, 0); + curr_enabled = read_tcs_reg(drv, RSC_DRV_CMD_ENABLE, tcs_id); for_each_set_bit(j, &curr_enabled, MAX_CMDS_PER_TCS) { - addr = read_tcs_reg(drv, RSC_DRV_CMD_ADDR, tcs_id, j); + addr = read_tcs_cmd(drv, RSC_DRV_CMD_ADDR, tcs_id, j); for (k = 0; k < msg->num_cmds; k++) { if (addr == msg->cmds[k].addr) return -EBUSY; -- 2.25.1.481.gfbce0eb801-goog