From patchwork Tue May 3 17:33:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 67074 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp718952qge; Tue, 3 May 2016 10:34:47 -0700 (PDT) X-Received: by 10.98.31.65 with SMTP id f62mr5348124pff.83.1462296886630; Tue, 03 May 2016 10:34:46 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 12si254274pft.105.2016.05.03.10.34.46; Tue, 03 May 2016 10:34:46 -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=@linaro.org; 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 dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964871AbcECRec (ORCPT + 29 others); Tue, 3 May 2016 13:34:32 -0400 Received: from mail-io0-f173.google.com ([209.85.223.173]:34230 "EHLO mail-io0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964834AbcECRe0 (ORCPT ); Tue, 3 May 2016 13:34:26 -0400 Received: by mail-io0-f173.google.com with SMTP id 190so29817928iow.1 for ; Tue, 03 May 2016 10:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6Sw3wSiPCTgN/9/sxKu6nW4J9N3FT81nE9Pqv6HKigY=; b=VFQXnS40pB+fPcjHwysYCxSkZrDxSRbWIDC2IG50Eh4UbBZt4for8w5Ce+2YlzRycJ IEKWiC53s3HaEE1yHRnHDnMT+ZUFwCmu/iXjF1I4prkV8OUSusKiXRDQRMfVNNfAdqW8 FvzErgNQDCI5LoNaBr7wWT+P6d1+ERi9gHGZk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6Sw3wSiPCTgN/9/sxKu6nW4J9N3FT81nE9Pqv6HKigY=; b=dtEj4pg2rPc6PqXo6nfWL4L2jQqcUalIKbuLxXRsShq4z4l0mrfPJh2Aksl7Y4F5Dq 4gnSCIXyNxQjtLZNHNlJmfd1eUoV/WuGQBrcPQ1D0hQg6XpG8HN2q7YP/thBHpKSPzZP t1Ndi2AnCeXFy/eumnVI74qKEXyaoTupLnTwGPATq7KodIA77nvR/HbfPmjdTYGbtwWt mqOmfItZMSVl/H36T2v04Z5LYWcO/5XCIULjGXpRjQxpg/gu3KvjFUbsUFthp60sGpeN wfYmRWlA1nTCmRDI723hJndj7htUXL55z9hqmlVXQEFojz5IKB89VrMZ23EbX33/I/dq voIw== X-Gm-Message-State: AOPr4FXmkGR3y4UOQgnKySt451sBfyOLUbBquJ0f+05AcNkw+77seNMbJxD6GvlkBH1G+PSh X-Received: by 10.107.137.19 with SMTP id l19mr4972163iod.177.1462296865692; Tue, 03 May 2016 10:34:25 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k33sm103957iod.44.2016.05.03.10.34.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 May 2016 10:34:24 -0700 (PDT) From: Mathieu Poirier To: gregkh@linuxfoundation.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/27] coresight: tmc: re-implementing tmc_read_prepare/unprepare() functions Date: Tue, 3 May 2016 11:33:46 -0600 Message-Id: <1462296841-12327-13-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1462296841-12327-1-git-send-email-mathieu.poirier@linaro.org> References: <1462296841-12327-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In their current implementation the tmc_read_prepare/unprepare() are a lump of if/else that is difficult to read. This patch is alleviating that by using a switch statement. The latter also allows for a better control on the error path. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-tmc.c | 56 ++++++++++++++++++----------- 1 file changed, 36 insertions(+), 20 deletions(-) -- 2.5.0 diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc.c index 66fa7736d12f..d211aeec49f8 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.c +++ b/drivers/hwtracing/coresight/coresight-tmc.c @@ -431,7 +431,7 @@ static const struct coresight_ops tmc_etf_cs_ops = { static int tmc_read_prepare(struct tmc_drvdata *drvdata) { - int ret; + int ret = 0; unsigned long flags; enum tmc_mode mode; @@ -439,25 +439,31 @@ static int tmc_read_prepare(struct tmc_drvdata *drvdata) if (!drvdata->enable) goto out; - if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) { + switch (drvdata->config_type) { + case TMC_CONFIG_TYPE_ETB: tmc_etb_disable_hw(drvdata); - } else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { - tmc_etr_disable_hw(drvdata); - } else { + break; + case TMC_CONFIG_TYPE_ETF: + /* There is no point in reading a TMC in HW FIFO mode */ mode = readl_relaxed(drvdata->base + TMC_MODE); - if (mode == TMC_MODE_CIRCULAR_BUFFER) { - tmc_etb_disable_hw(drvdata); - } else { - ret = -ENODEV; + if (mode != TMC_MODE_CIRCULAR_BUFFER) { + ret = -EINVAL; goto err; } + + tmc_etb_disable_hw(drvdata); + break; + case TMC_CONFIG_TYPE_ETR: + tmc_etr_disable_hw(drvdata); + break; + default: + ret = -EINVAL; + goto err; } + out: drvdata->reading = true; - spin_unlock_irqrestore(&drvdata->spinlock, flags); - dev_info(drvdata->dev, "TMC read start\n"); - return 0; err: spin_unlock_irqrestore(&drvdata->spinlock, flags); return ret; @@ -472,20 +478,30 @@ static void tmc_read_unprepare(struct tmc_drvdata *drvdata) if (!drvdata->enable) goto out; - if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) { + switch (drvdata->config_type) { + case TMC_CONFIG_TYPE_ETB: tmc_etb_enable_hw(drvdata); - } else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { - tmc_etr_enable_hw(drvdata); - } else { + break; + case TMC_CONFIG_TYPE_ETF: + /* Make sure we don't re-enable a TMC in HW FIFO mode */ mode = readl_relaxed(drvdata->base + TMC_MODE); - if (mode == TMC_MODE_CIRCULAR_BUFFER) - tmc_etb_enable_hw(drvdata); + if (mode != TMC_MODE_CIRCULAR_BUFFER) + goto err; + + tmc_etb_enable_hw(drvdata); + break; + case TMC_CONFIG_TYPE_ETR: + tmc_etr_disable_hw(drvdata); + break; + default: + goto err; } + out: drvdata->reading = false; - spin_unlock_irqrestore(&drvdata->spinlock, flags); - dev_info(drvdata->dev, "TMC read end\n"); +err: + spin_unlock_irqrestore(&drvdata->spinlock, flags); } static int tmc_open(struct inode *inode, struct file *file)