Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2648459pxy; Tue, 3 Aug 2021 11:23:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMQ5hYjRmp0y7j/ncG8oRp93R/+3RtydO/BcnHQBAyyzZlrFSKJVAEQhoyhCmYixVanb4k X-Received: by 2002:a6b:b586:: with SMTP id e128mr978831iof.37.1628015018254; Tue, 03 Aug 2021 11:23:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628015018; cv=none; d=google.com; s=arc-20160816; b=jNhups0t0+bFW3LV8FAZQCKPbsgr1Y9mnP+I0p6rSguGE/AmyVFkCsxAxtQtpkXOR7 kvG4rVTXPAQttup6b36YWZ0qyoKvRnzjPez7331MF2A+vULKqBWCl2C91o31e7xuuacX aMo1RKEPJTaNLgz27OQfrOOkbVJP3fc2loUAUFxVFJBQPJQdxhMRlA/S+xTMIVkhZM8i hXeqf57CBUQklcstKUTrSj1bPB5ZovwYD2bw9hmOzkjrD5Fx5SG3B3GeSJCzw1oShc2l wgzMbpeTHOmD1x6EfJaT4DBN0I8sYRCVtVeKKn48tiYfIN+U/eF1qfO+ZeT7GM656zTq zxyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7wjJjxr5NY0mlwpeyO/0mlW4pSwnhPT8csogJcd6W20=; b=TluL6sfo+upqWVhES2QeunK6NfXJSMEkfWQVBTfxaIKGwC/OMw0QLeQCMJLTzSw7my FzYMNDkgt/s6adGCRb1PMBpbsSJpb9d97S8ruIl917za8dgGMFaAsWoPbQ+AcCKMLnmZ qhDCG3KW/laT3GMTxthpB0/aOqgIqCj+tsEGSOmXSUen5KmfCNu0tAuTa4qelCno5qg8 yIhGXG6Ks+HLO2VVtbh1b6vdxhNVnEEnjDtb1+XBp2GOxsthYQmSw8DAZi70bmGZLgDZ X/H7Oa5BI09WycxBJ+i3sNSdz2/G+R1YrvFannEPXDf7KIj9OByej1gI2+cvL16hfKml H0vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oTWlF+yt; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t15si15559593ilg.47.2021.08.03.11.23.26; Tue, 03 Aug 2021 11:23:38 -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=@gmail.com header.s=20161025 header.b=oTWlF+yt; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239188AbhHCSVT (ORCPT + 99 others); Tue, 3 Aug 2021 14:21:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239097AbhHCSVL (ORCPT ); Tue, 3 Aug 2021 14:21:11 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67E49C06175F; Tue, 3 Aug 2021 11:20:59 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id dw2-20020a17090b0942b0290177cb475142so5104969pjb.2; Tue, 03 Aug 2021 11:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7wjJjxr5NY0mlwpeyO/0mlW4pSwnhPT8csogJcd6W20=; b=oTWlF+ytCtIPrUcUvp8jE0sc3VSofJeRtWtO50ijRo8f4zlLr1u+0xzEwZr5wKCb3S kafEZY+V7A1q1MGb7sfDAAg9/QhwYKV2pK0upfGL3mTUpGB/TEo+ymwfJd9bsRt18yoY 57JKveqpiuCBW7pDdTBcPeGR3cioqGdDn7F/I9DvN283Sm6U8H5ar9nLcYP3JNeopFVx /Amsh+qQ6e5PC2cDVkSDGuak4hOLwgmk2n0d9L/gzCKK7l2MTSNLFcXskIvxqTCHY/bJ r2VLi3663hCYx2AtShEcDY3J0kbhIiiuNiiLUJj6Z/POYZNte3GmzrOWeDdWywb6rhRG 4kwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7wjJjxr5NY0mlwpeyO/0mlW4pSwnhPT8csogJcd6W20=; b=lVZEkzAYJiphTWazviuC4+ByFfw98E6KB4n/XteRTX4JPDMhhf4hp/XG+6Q0xTXSXd OcyIiXdXat08kzTHQqbJeJmgBAxI/5Au66ad6WQn6rT3Eod2QS8aHH+4O+cXb++8sYqz uaxFGagtY9sAVVDPtYFjiTm8BWoutsv488GCL8AvEC7+/ROtAmDrNV1BIBJfarrS7JPo H0EbXh7voA76aTIpAasw4QmG4ujsGk2a46sb+aovpad0RXgbS2nw83jNyLPZw27i5JbL 2uDhRdNyhuLr81NQMfSrtEYpueWj+KkFXpXtOEaZqLdeMapfdk2zh3iGu0V2N7s1X36m rf/g== X-Gm-Message-State: AOAM531GpjCD0Qsq11LIjBYaVi90xeGazVg0QzEH+glN0D9vNCogwxSx ytPST3m5JXbmIZ32cG/GL6NNGVW14Oy+WzmZRoI= X-Received: by 2002:a17:90a:b10b:: with SMTP id z11mr5690793pjq.181.1628014858846; Tue, 03 Aug 2021 11:20:58 -0700 (PDT) MIME-Version: 1.0 References: <20210803102428.6476-1-Mason.Zhang@mediatek.com> In-Reply-To: <20210803102428.6476-1-Mason.Zhang@mediatek.com> From: Andy Shevchenko Date: Tue, 3 Aug 2021 21:20:19 +0300 Message-ID: Subject: Re: [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback To: Mason Zhang Cc: Mark Brown , Matthias Brugger , Laxman Dewangan , linux-spi , Linux Kernel Mailing List , linux-arm Mailing List , "moderated list:ARM/Mediatek SoC support" , Mediatek WSD Upstream Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 3, 2021 at 1:42 PM Mason Zhang wrote: > > This patch modified set_cs_timing callback: > 1 support spi_device set cs_timing in their driver; > 2 support set absolute time but no clk count, because; > clk src will change in different platform; > 3 call this function in prepare_message but not in other API. Perhaps it should be 3 patches? ... > +static int mtk_spi_set_hw_cs_timing(struct spi_device *spi) > +{ > + struct mtk_spi *mdata = spi_master_get_devdata(spi->master); > + struct spi_delay *cs_setup = &spi->cs_setup; > + struct spi_delay *cs_hold = &spi->cs_hold; > + struct spi_delay *cs_inactive = &spi->cs_inactive; > + u16 setup, hold, inactive; > + u32 reg_val; > + int delay; > + > + delay = spi_delay_to_ns(cs_setup, NULL); > + if (delay < 0) > + return delay; > + setup = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000); 1000 is NSEC_PER_USEC (here and below)? > + delay = spi_delay_to_ns(cs_hold, NULL); > + if (delay < 0) > + return delay; > + hold = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000); > + > + delay = spi_delay_to_ns(cs_inactive, NULL); > + if (delay < 0) > + return delay; > + inactive = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000); > + setup = setup ? setup : 1; > + hold = hold ? hold : 1; > + inactive = inactive ? inactive : 1; All of these can be simplified by using ?: (short ternary) form. > + reg_val = readl(mdata->base + SPI_CFG0_REG); > + if (mdata->dev_comp->enhance_timing) { > + reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET); > + reg_val |= (((hold - 1) & 0xffff) > + << SPI_ADJUST_CFG0_CS_HOLD_OFFSET); > + reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET); > + reg_val |= (((setup - 1) & 0xffff) > + << SPI_ADJUST_CFG0_CS_SETUP_OFFSET); > + } else { > + reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET); > + reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET); > + reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET); > + reg_val |= (((setup - 1) & 0xff) > + << SPI_CFG0_CS_SETUP_OFFSET); > + } > + writel(reg_val, mdata->base + SPI_CFG0_REG); > + > + reg_val = readl(mdata->base + SPI_CFG1_REG); > + reg_val &= ~SPI_CFG1_CS_IDLE_MASK; > + reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET); > + writel(reg_val, mdata->base + SPI_CFG1_REG); > + > + return 0; > +} -- With Best Regards, Andy Shevchenko