Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1062556ybt; Wed, 1 Jul 2020 17:46:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLnSSHgTYfRVeB4/EgVGyKvluFODqLMQ/2x7N6aHjY1hiyjv0qIIAW0Ubx+t5jnMBV9ip/ X-Received: by 2002:a17:907:2654:: with SMTP id ar20mr23939445ejc.62.1593650812501; Wed, 01 Jul 2020 17:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593650812; cv=none; d=google.com; s=arc-20160816; b=iIeh4Aj3prly/R3fgUEzeH1wf9yAFwhUBr86rmiXV0y8kVPM8+QnCq97lh451nFUsQ 15SMCKtxn6j/deOnu6SIZTPfh0stZ84/iz4WBW3O37pmIY55j6Ab4XTGhDsXNog4FB9T YRVsgtnRoXWhsSDYj9SKE0RrSrPPCSpDWWwj07lPiraxeaqht38Cz/1wxMlM+lf0A1WO LMxWic3XYi84EzWrFoZi17rzGbj6dbcDW72r1cWCvkVrUe7vZts/eNaVZTftKHAULHq5 XvFkZpKG+P8fg+ukDmGli3rWbEGzwbwiDcU9eUGtk2ps90476E4zZCVbqWJXuS9nbFtJ LuKQ== 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=l0ar211YP+36NHOe0RGdo5xX/ajG/sfFSQ8f60VejD0=; b=zyFNZkqiRvQm8va9VsD7BpZxy4KUMz22wdQiQiNALRHd1+9T5C8NL6Jmbqf5P1ayYk 4wXB1XMIjzfFLBK+dynxKzWCDAUjnM8xRa1iHxGZJVLpCmEs3Iu2yE/B+3MbJcxIxXbo ja8/Ugm61mdX6zx1Er7xVypr7GjtFss4pKQWqzgh+W9gvMwS1iOCkeLg6XtqVcoAGZ5X FhajyjuUg8OIbG23Z27M0Hs5OTIZ1zRHyOtHf+J7FuSkJPhAzeGd6f4Dbu3n4+FZKTWM Rr7aWmUZj/Cwix6QA9Pf2BbNocamXvzHxu0hDCdi7RhlUvZYZBKNoQc8jCAXZvayoFPw FY5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=K8dryPte; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c6si4906087edq.569.2020.07.01.17.46.24; Wed, 01 Jul 2020 17:46:52 -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; dkim=pass header.i=@chromium.org header.s=google header.b=K8dryPte; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728089AbgGBApn (ORCPT + 99 others); Wed, 1 Jul 2020 20:45:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728053AbgGBApg (ORCPT ); Wed, 1 Jul 2020 20:45:36 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A4F8C08C5DC for ; Wed, 1 Jul 2020 17:45:36 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id l6so8576798pjq.1 for ; Wed, 01 Jul 2020 17:45:36 -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=l0ar211YP+36NHOe0RGdo5xX/ajG/sfFSQ8f60VejD0=; b=K8dryPtevEWJdF6SRZtGa+5PKQFaWzwvHBySR6u2HjiruZ2Nj2GDh3biDtq0WsOzqS pEtk2XCHBg+9pAZYqGRL3g2nGdU6WPHoQ/sX4dI4/0W1+LpIuTUyIIH9/CdxbxVSEzwf ZaU54QAtbJBTg/Td+Fqip/FVCLcj9oyQ7SnuE= 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=l0ar211YP+36NHOe0RGdo5xX/ajG/sfFSQ8f60VejD0=; b=Z4ypsf4d7mfWkEHdiakXv1fZRhiZbvDVb7qrnDtri4jvL7Rx9WpwTTIrxpQVVaMgaN oQMnNCQmt4cPzSKpRglvzFAh5tXhVHoRASuZumSfqYlEJ65zGguXRf3nycdSUUX4e2qh zTIy2BzmXJkLNlr5O/A1+Gh6INDA3mtKJNQ+zkBdWyqUFlseilf2IWr07pKh469G33bH b2qN+gKLSrk0/HR8VM1TtnpErLh8Iscl7EiTdJhMrArcfNH22mtaO5sAHr4ylwvHgtf5 1fcN/VaaWQ2x6Obx+qtXd6Uh+FqtPOpYawtdhbZjXc+iREmUq78OdCTl2vJ2tkyCfiyS TdKg== X-Gm-Message-State: AOAM530OTrThiEt3t+5zkr79UuhHXRWujQdaPjmxuYoJY8pHcv50GjE3 C4F3L5C2grIYraB9s3tDbL5WCA== X-Received: by 2002:a17:902:b60f:: with SMTP id b15mr24662170pls.248.1593650736141; Wed, 01 Jul 2020 17:45:36 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:42b0:34ff:fe3d:58e6]) by smtp.gmail.com with ESMTPSA id w4sm6966212pfd.39.2020.07.01.17.45.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 17:45:35 -0700 (PDT) From: Douglas Anderson To: Mark Brown , Andy Gross , Bjorn Andersson Cc: akashast@codeaurora.org, linux-arm-msm@vger.kernel.org, mkshah@codeaurora.org, swboyd@chromium.org, georgi.djakov@linaro.org, ctheegal@codeaurora.org, mka@chromium.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org Subject: [PATCH 3/3] spi: spi-geni-qcom: Get rid of most overhead in prepare_message() Date: Wed, 1 Jul 2020 17:45:09 -0700 Message-Id: <20200701174506.3.I2b3d7aeb1ea622335482cce60c58d2f8381e61dd@changeid> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog In-Reply-To: <20200702004509.2333554-1-dianders@chromium.org> References: <20200702004509.2333554-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 There's a bunch of overhead in spi-geni-qcom's prepare_message. Get rid of it. Before this change spi_geni_prepare_message() took around 14.5 us. After this change, spi_geni_prepare_message() takes about 1.75 us (as measured by ftrace). What's here: * We're always in FIFO mode, so no need to call it for every transfer. This avoids a whole ton of readl/writel calls. * We don't need to write a whole pile of config registers if the mode isn't changing. Cache the last mode and only do the work if needed. * For several registers we were trying to do read/modify/write, but there was no reason. The registers only have one thing in them, so just write them. Signed-off-by: Douglas Anderson --- drivers/spi/spi-geni-qcom.c | 54 +++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c index f51279608fc7..97fac5ea6afd 100644 --- a/drivers/spi/spi-geni-qcom.c +++ b/drivers/spi/spi-geni-qcom.c @@ -77,6 +77,7 @@ struct spi_geni_master { u32 tx_fifo_depth; u32 fifo_width_bits; u32 tx_wm; + u32 last_mode; unsigned long cur_speed_hz; unsigned int cur_bits_per_word; unsigned int tx_rem_bytes; @@ -177,8 +178,6 @@ static void spi_setup_word_len(struct spi_geni_master *mas, u16 mode, struct geni_se *se = &mas->se; u32 word_len; - word_len = readl(se->base + SE_SPI_WORD_LEN); - /* * If bits_per_word isn't a byte aligned value, set the packing to be * 1 SPI word per FIFO word. @@ -187,10 +186,9 @@ static void spi_setup_word_len(struct spi_geni_master *mas, u16 mode, pack_words = mas->fifo_width_bits / bits_per_word; else pack_words = 1; - word_len &= ~WORD_LEN_MSK; - word_len |= ((bits_per_word - MIN_WORD_LEN) & WORD_LEN_MSK); geni_se_config_packing(&mas->se, bits_per_word, pack_words, msb_first, true, true); + word_len = (bits_per_word - MIN_WORD_LEN) & WORD_LEN_MSK; writel(word_len, se->base + SE_SPI_WORD_LEN); } @@ -238,38 +236,34 @@ static int setup_fifo_params(struct spi_device *spi_slv, { struct spi_geni_master *mas = spi_master_get_devdata(spi); struct geni_se *se = &mas->se; - u32 loopback_cfg, cpol, cpha, demux_output_inv; + u32 loopback_cfg = 0, cpol = 0, cpha = 0, demux_output_inv = 0; u32 demux_sel; - loopback_cfg = readl(se->base + SE_SPI_LOOPBACK); - cpol = readl(se->base + SE_SPI_CPOL); - cpha = readl(se->base + SE_SPI_CPHA); - demux_output_inv = 0; - loopback_cfg &= ~LOOPBACK_MSK; - cpol &= ~CPOL; - cpha &= ~CPHA; + if (mas->last_mode != spi_slv->mode) { + if (spi_slv->mode & SPI_LOOP) + loopback_cfg = LOOPBACK_ENABLE; - if (spi_slv->mode & SPI_LOOP) - loopback_cfg |= LOOPBACK_ENABLE; + if (spi_slv->mode & SPI_CPOL) + cpol = CPOL; - if (spi_slv->mode & SPI_CPOL) - cpol |= CPOL; + if (spi_slv->mode & SPI_CPHA) + cpha = CPHA; - if (spi_slv->mode & SPI_CPHA) - cpha |= CPHA; + if (spi_slv->mode & SPI_CS_HIGH) + demux_output_inv = BIT(spi_slv->chip_select); - if (spi_slv->mode & SPI_CS_HIGH) - demux_output_inv = BIT(spi_slv->chip_select); + demux_sel = spi_slv->chip_select; + mas->cur_bits_per_word = spi_slv->bits_per_word; - demux_sel = spi_slv->chip_select; - mas->cur_bits_per_word = spi_slv->bits_per_word; + spi_setup_word_len(mas, spi_slv->mode, spi_slv->bits_per_word); + writel(loopback_cfg, se->base + SE_SPI_LOOPBACK); + writel(demux_sel, se->base + SE_SPI_DEMUX_SEL); + writel(cpha, se->base + SE_SPI_CPHA); + writel(cpol, se->base + SE_SPI_CPOL); + writel(demux_output_inv, se->base + SE_SPI_DEMUX_OUTPUT_INV); - spi_setup_word_len(mas, spi_slv->mode, spi_slv->bits_per_word); - writel(loopback_cfg, se->base + SE_SPI_LOOPBACK); - writel(demux_sel, se->base + SE_SPI_DEMUX_SEL); - writel(cpha, se->base + SE_SPI_CPHA); - writel(cpol, se->base + SE_SPI_CPOL); - writel(demux_output_inv, se->base + SE_SPI_DEMUX_OUTPUT_INV); + mas->last_mode = spi_slv->mode; + } return geni_spi_set_clock_and_bw(mas, spi_slv->max_speed_hz); } @@ -279,9 +273,7 @@ static int spi_geni_prepare_message(struct spi_master *spi, { int ret; struct spi_geni_master *mas = spi_master_get_devdata(spi); - struct geni_se *se = &mas->se; - geni_se_select_mode(se, GENI_SE_FIFO); ret = setup_fifo_params(spi_msg->spi, spi); if (ret) dev_err(mas->dev, "Couldn't select mode %d\n", ret); @@ -322,6 +314,8 @@ static int spi_geni_init(struct spi_geni_master *mas) else mas->oversampling = 1; + geni_se_select_mode(se, GENI_SE_FIFO); + pm_runtime_put(mas->dev); return 0; } -- 2.27.0.383.g050319c2ae-goog