Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7657603rwl; Tue, 10 Jan 2023 03:50:44 -0800 (PST) X-Google-Smtp-Source: AMrXdXvz49+ot2Fif9lEVCRUBIyWuLUpAQaYtTRqf5mM61nO3Op5d4uUzADaGmAZ9qvbt4ACPs0a X-Received: by 2002:a17:90a:bc8b:b0:226:c966:28a7 with SMTP id x11-20020a17090abc8b00b00226c96628a7mr18550147pjr.14.1673351444526; Tue, 10 Jan 2023 03:50:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673351444; cv=none; d=google.com; s=arc-20160816; b=EWSbDmAYrA7C5XcLDE5ua+9/nGuNvAax3XARmDxLWLsex9X/pSQZWCnDhkxwWWUevc GfJps9WlzqxktGUcotPhv8ezljaTOBoAzANeY+3ceFbMTKpUBGIFUnb6hA0LFh/0yOWy zXIMKNwi4xZ62jZ8Gel0FNeOnn+wWRu3Vqe7eTzv8EBDf23zFyuxGzbqwq6XVIBeEfMp vmOLANCA3pVfn8/3j6uiv7pxlaffmG7RsNZfUmBzrDkxSNtseD1disBIkJ+SQj8ESOL0 q1ZTGmDOygUTDUX1PFQHSWMH5jNvj0OD2jMFJQe8JAHBKL9liGebuPwdNDMhK98b5jqo Vm9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=k8qIHMNO2s1UBLosBalnkXRDkilmbPNHsObMEKK0n7I=; b=yf3vWcWNdplSOsJ2itcjyTF8UGvha7GucR4vVU3IaPDajlpDjuz6+1T9VooWxomdXd VfwEI3p4Rnow407PLY9TSe0dtc+cS6FOHrL0vrPi5tEzF06N/a/EioVpa0eivV1oP/n1 ux/xfEsdI4tSes7K7x2RcXjaban9maPaUdy/cU4T5l1NXW43zHmTWmJc5LbQrjSDCdVY 29E2k1pQoJb5WnzXArpvSaIWkCskzLa+BrF8l9eopfnEISMReu7C15rwQmVAKYiR92Is PMBdnBgsk4QkmQNtNm8cT8YeWKu56AoPKnqI6zVLaXQRhCnFYxNB7WGkYlRlNaK/mto6 Q/+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bg0lxmUd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lw16-20020a17090b181000b00225f9fff787si16778543pjb.146.2023.01.10.03.50.37; Tue, 10 Jan 2023 03:50:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bg0lxmUd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230151AbjAJLkm (ORCPT + 53 others); Tue, 10 Jan 2023 06:40:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbjAJLkf (ORCPT ); Tue, 10 Jan 2023 06:40:35 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A91D615FC6; Tue, 10 Jan 2023 03:40:34 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id j17so17962964lfr.3; Tue, 10 Jan 2023 03:40:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=k8qIHMNO2s1UBLosBalnkXRDkilmbPNHsObMEKK0n7I=; b=bg0lxmUdGEI7jbzLJkVcT7QTNyzIGfCKVN9kCtEWnYtmWtxXDIJr+SGpqR+Y3oXyOh o52zHSRr3wl1Mm2VzjX2viW390JajcGoIMyebxQjpG79RGS9ir2j2W898mtqorEQtuuo 9CL0C07wCX5qC6yMZpO+qA/Wgmj6XDDw0aaEJHZA9hK3x6NCGPEH11TMMp+pv9+kSYD8 /IqIW7dpa+lavlm/CJ88qV1Ggzrrvx9lcHVpC/6/TjISZVwVWVAhKyne5bRs4rIlQ0bm O0P3LPKFXqNy/SrGeEyurCSsgQbvDwA6pMYr4EBvhDUPWmabBgkLL665O7U6hImH9KU2 d93A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=k8qIHMNO2s1UBLosBalnkXRDkilmbPNHsObMEKK0n7I=; b=QLJ3eD7+SEzGj2gExzXwd5xKw8+t4EdIwFt4b75UCUfn1LK5ZXCflUgYKBeC1RRbiQ m8FGFBbY6MuPXvJXOYrmmK+z5XkW+sxceUUnTtJettr2bwqAfBxO9YIQ4YSlvf/Y0BVd Q2JRe5J4/G6GbLbB24yuPVfzzXTBsQO37ddVy+erYx+iI5eP7C7svkXk+TWBN/n9aV3V 9F4wj4an48hVFFRGERkRVTyel4WUuLeKgQoHlJMGRfPmoa4PSpLENwrx2q9nmG8EwXzC tTZk97TRFOiPTiSCPcvF8wzvuyB7nzbfm0E8ro8Ybs6Ob0qRleFj6ddujbMTAnyy0q25 LW+Q== X-Gm-Message-State: AFqh2kq6jEcy3aDDn3P+hjZDpE0fN6PLBzXkZzaWvOUwCPv84ECzOam7 HrZc900LmZeRRwheGNQtzXU= X-Received: by 2002:ac2:5bc5:0:b0:4ad:5fbb:a594 with SMTP id u5-20020ac25bc5000000b004ad5fbba594mr19772858lfn.58.1673350832790; Tue, 10 Jan 2023 03:40:32 -0800 (PST) Received: from mobilestation ([95.79.133.202]) by smtp.gmail.com with ESMTPSA id z3-20020a0565120c0300b004cb03999979sm2139849lfu.40.2023.01.10.03.40.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 03:40:32 -0800 (PST) Date: Tue, 10 Jan 2023 14:40:30 +0300 From: Serge Semin To: Sudip Mukherjee Cc: Mark Brown , Rob Herring , Krzysztof Kozlowski , jude.onyenegecha@sifive.com, ben.dooks@sifive.com, jeegar.lakhani@sifive.com, linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 06/15] spi: dw: Introduce dual/quad/octal spi Message-ID: <20230110114030.hz3hkou5owxaeopc@mobilestation> References: <20221212180732.79167-1-sudip.mukherjee@sifive.com> <20221212180732.79167-7-sudip.mukherjee@sifive.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221212180732.79167-7-sudip.mukherjee@sifive.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 12, 2022 at 06:07:23PM +0000, Sudip Mukherjee wrote: > If the spi transfer is using dual/quad/octal spi mode, then we need to > update the SPI_CTRLR0 register. The SPI_CTRLR0 register will be updated > in dw_spi_update_config() via the values in dw_spi_cfg. > > Signed-off-by: Sudip Mukherjee > --- > > Note: DW_SPI_SPI_CTRLR0_INST_L_INST_L16 will not work yet as > spi_mem_default_supports_op() checks for op->cmd.nbytes != 1. > > drivers/spi/spi-dw-core.c | 46 +++++++++++++++++++++++++++++++++++++++ > drivers/spi/spi-dw.h | 9 ++++++++ > 2 files changed, 55 insertions(+) > > diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c > index 89438ae2df17d..06169aa3f37bf 100644 > --- a/drivers/spi/spi-dw-core.c > +++ b/drivers/spi/spi-dw-core.c > @@ -836,10 +836,56 @@ static int dw_spi_exec_enh_mem_op(struct spi_mem *mem, const struct spi_mem_op * > { > struct spi_controller *ctlr = mem->spi->controller; > struct dw_spi *dws = spi_controller_get_devdata(ctlr); > + struct dw_spi_cfg cfg; > + > + switch (op->data.buswidth) { > + case 2: > + cfg.spi_frf = DW_SPI_CTRLR0_SPI_FRF_DUAL_SPI; > + break; > + case 4: > + cfg.spi_frf = DW_SPI_CTRLR0_SPI_FRF_QUAD_SPI; > + break; > + case 8: > + cfg.spi_frf = DW_SPI_CTRLR0_SPI_FRF_OCT_SPI; > + break; > + default: > + return dw_spi_exec_mem_op(mem, op); case 1: return dw_spi_exec_mem_op(mem, op); case 2: cfg.enh_frf = DW_SPI_CTRLR0_SPI_FRF_DUAL_SPI; break; ... default: return -EINVAL; > + } > > /* Collect cmd and addr into a single buffer */ > dw_spi_init_enh_mem_buf(dws, op); > > + cfg.dfs = 8; > + cfg.freq = clamp(mem->spi->max_speed_hz, 0U, dws->max_mem_freq); > + cfg.ndf = op->data.nbytes; > + if (op->data.dir == SPI_MEM_DATA_IN) > + cfg.tmode = DW_SPI_CTRLR0_TMOD_RO; > + else > + cfg.tmode = DW_SPI_CTRLR0_TMOD_TO; Newline, please. > + if (op->data.buswidth == op->addr.buswidth && > + op->data.buswidth == op->cmd.buswidth) > + cfg.trans_t = DW_SPI_SPI_CTRLR0_TRANS_TYPE_TT2; > + else if (op->data.buswidth == op->addr.buswidth) > + cfg.trans_t = DW_SPI_SPI_CTRLR0_TRANS_TYPE_TT1; > + else > + cfg.trans_t = DW_SPI_SPI_CTRLR0_TRANS_TYPE_TT0; > + > + cfg.addr_l = clamp(op->addr.nbytes * 2, 0, 0xf); First the address length should be checked in the spi_controller_mem_ops.supports_op method. Thus the clamping procedure would be redundant. Second instead of using the multiplication operator I would suggest to have the bitwise left-shift op utilized here, (cfg.addr_l = op->addr.nbytes << 2). This shall look a bit more coherent. > + if (op->cmd.nbytes > 1) > + cfg.inst_l = DW_SPI_SPI_CTRLR0_INST_L_INST_L16; No. Firstly INST_L16 means 2-bytes length. Using greater-than op here is incorrect. Secondly the command part length should be checked in the spi_controller_mem_ops.supports_op callback. > + else if (op->cmd.nbytes == 1) > + cfg.inst_l = DW_SPI_SPI_CTRLR0_INST_L_INST_L8; > + else > + cfg.inst_l = DW_SPI_SPI_CTRLR0_INST_L_INST_L0; > + > + cfg.wait_c = (op->dummy.nbytes * (BITS_PER_BYTE / op->dummy.buswidth)); Hm, what if buswidth is zero? > + > + dw_spi_enable_chip(dws, 0); > + > + dw_spi_update_config(dws, mem->spi, &cfg); > + > + dw_spi_enable_chip(dws, 1); > + > return 0; > } > > diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h > index 327d037bdb10e..494b830ad1026 100644 > --- a/drivers/spi/spi-dw.h > +++ b/drivers/spi/spi-dw.h > @@ -101,6 +101,9 @@ > #define DW_HSSI_CTRLR0_SPI_FRF_MASK GENMASK(23, 22) > #define DW_PSSI_CTRLR0_SPI_FRF_MASK GENMASK(22, 21) > #define DW_SPI_CTRLR0_SPI_FRF_STD_SPI 0x0 > +#define DW_SPI_CTRLR0_SPI_FRF_DUAL_SPI 0x1 > +#define DW_SPI_CTRLR0_SPI_FRF_QUAD_SPI 0x2 > +#define DW_SPI_CTRLR0_SPI_FRF_OCT_SPI 0x3 Please replace SPI_FRF with ENH_FRF and drop _SPI suffix from the macros. > > /* Bit fields in CTRLR1 */ > #define DW_SPI_NDF_MASK GENMASK(15, 0) > @@ -132,7 +135,13 @@ > #define DW_SPI_SPI_CTRLR0_CLK_STRETCH_EN BIT(30) > #define DW_SPI_SPI_CTRLR0_WAIT_CYCLE_MASK GENMASK(15, 11) > #define DW_SPI_SPI_CTRLR0_INST_L_MASK GENMASK(9, 8) > +#define DW_SPI_SPI_CTRLR0_INST_L_INST_L0 0x0 > +#define DW_SPI_SPI_CTRLR0_INST_L_INST_L8 0x2 > +#define DW_SPI_SPI_CTRLR0_INST_L_INST_L16 0x3 > #define DW_SPI_SPI_CTRLR0_ADDR_L_MASK GENMASK(5, 2) > +#define DW_SPI_SPI_CTRLR0_TRANS_TYPE_TT0 0x0 > +#define DW_SPI_SPI_CTRLR0_TRANS_TYPE_TT1 0x1 > +#define DW_SPI_SPI_CTRLR0_TRANS_TYPE_TT2 0x2 Please replace SPI_CTRLR0 with ENH_CTRLR0. -Serge(y) > > /* Mem/DMA operations helpers */ > #define DW_SPI_WAIT_RETRIES 5 > -- > 2.30.2 >