Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4666992yba; Wed, 10 Apr 2019 02:17:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzq1lwGNzVQJjQsbwYC3wAwnDBhwSWxmHTiIaXc+I/tANW8l5twEUlHoNINtigLD6K5rbpp X-Received: by 2002:a65:4802:: with SMTP id h2mr37047389pgs.98.1554887821489; Wed, 10 Apr 2019 02:17:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554887821; cv=none; d=google.com; s=arc-20160816; b=WWdnv5qYcSKxXnFzlOHYxevptBydYbYixhL15FVBdr2l3yKnyuHWkGo9/MNuwTST0R XYDYXKuFi0LkMxyYFE0hsOdGoIQ+oR73aVXc4ttr61XtkyxLv/47GRJHL6khXiekq4So XZaPBnUp2teSC6KPfn09OOkjoGL2VADh+RLfPrF7Tq5NLVoXQYGOxQq3hTgCctlc05Wb 9pdkj5q+WJFqplDfexFF9q0vMJyD4uV5mxPYNqzQFw4tvAy7YPrerlwCK+WGyB89hG53 d/TpE4DaYjuRKJZI3uogfkT29BGLCff4z/PvX/5wSx5cbPpRIRtPKDtL9ci6oKei3dIK zk1g== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=CQybnYt9+Y3+Q0wZXdZuny3BPr2CR8WfDNKigRGFBv4=; b=aq2al6Ziconmv3le3jis1LMLpkQoWvxUCcF9dJOCjMiBwaA5dvhuGmEjx6LAgZjpD6 lfrWMwdBGNdsh0EMkoc9jM6WKKg+U2CmKyiHiwjmnO6n+mmEHPegqcyfG1pswxPjvcQ8 BY+pgvWC9EvsGh5cdm/we6RqiKsRLhSrYVOxzuDUsyyuaVGnxulHPfbugNaV9hSfYjGO hy6fAq+SnjZKbTgWYgh3LnkKhXEcswnXEjKjhHuHF5iRW5yU/wV34LnpHxMFchay+Ebk n6kXPQEPtZSJBpOtswVhwkQ9tgR7zCkwMkQ33caFNd1mM1UHxHw/ck4p2t19yGcVynsO BSYw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s21si32176080pfh.260.2019.04.10.02.16.45; Wed, 10 Apr 2019 02:17:01 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728984AbfDJILR (ORCPT + 99 others); Wed, 10 Apr 2019 04:11:17 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:53150 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727256AbfDJILQ (ORCPT ); Wed, 10 Apr 2019 04:11:16 -0400 Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: bbrezillon) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id A92282817AB; Wed, 10 Apr 2019 09:11:13 +0100 (BST) Date: Wed, 10 Apr 2019 10:11:10 +0200 From: Boris Brezillon To: masonccyang@mxic.com.tw Cc: "Marek Vasut" , bbrezillon@kernel.org, broonie@kernel.org, devicetree@vger.kernel.org, "Geert Uytterhoeven" , "Simon Horman" , juliensu@mxic.com.tw, lee.jones@linaro.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-spi@vger.kernel.org, mark.rutland@arm.com, robh+dt@kernel.org, "Sergei Shtylyov" , zhengxunli@mxic.com.tw Subject: Re: [PATCH v9 2/3] spi: Add Renesas R-Car Gen3 RPC-IF SPI controller driver Message-ID: <20190410101110.2224eb91@collabora.com> In-Reply-To: References: <1553847606-18122-1-git-send-email-masonccyang@mxic.com.tw> <1553847606-18122-3-git-send-email-masonccyang@mxic.com.tw> <2095d059-8276-a01a-7c3a-da4647f7b7df@gmail.com> Organization: Collabora X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 10 Apr 2019 16:01:02 +0800 masonccyang@mxic.com.tw wrote: > Hi, > > > Re: [PATCH v9 2/3] spi: Add Renesas R-Car Gen3 RPC-IF SPI controller > driver > > > > On 4/10/19 3:33 AM, masonccyang@mxic.com.tw wrote: > > > Hi Sergei, > > > > > >> > +static ssize_t rpc_spi_mem_dirmap_write(struct spi_mem_dirmap_desc > > > *desc, > > >> > + u64 offs, size_t len, const void *buf) > > >> > +{ > > >> > + struct rpc_spi *rpc = > > >> > + spi_controller_get_devdata(desc->mem->spi->controller); > > >> > + int ret; > > >> > + > > >> > + if (offs + desc->info.offset + len > U32_MAX) > > >> > + return -EINVAL; > > >> > + > > >> > + if (len > RPC_WBUF_SIZE) > > >> > + len = RPC_WBUF_SIZE; > > >> > + > > >> > + ret = rpc_spi_set_freq(rpc, desc->mem->spi->max_speed_hz); > > >> > + if (ret) > > >> > + return ret; > > >> > + > > >> > + rpc_spi_mem_set_prep_op_cfg(desc->mem->spi, > > >> > + &desc->info.op_tmpl, &offs, &len); > > >> > + > > >> > + regmap_update_bits(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD, > > > RPC_CMNCR_MD); > > >> > + > > >> > + regmap_write(rpc->regmap, RPC_SMDRENR, 0); > > >> > + > > >> > + regmap_update_bits(rpc->regmap, RPC_PHYCNT, > RPC_PHYCNT_STRTIM(7) | > > >> > + RPC_PHYCNT_WBUF2 | RPC_PHYCNT_WBUF, > > >> > + RPC_PHYCNT_WBUF2 | RPC_PHYCNT_WBUF); > > >> > + > > >> > + memcpy_toio(rpc->wbuf, buf, len); > > >> > > >> Wait, doesn't the manual say that the whole 256-byte buffer should > be > > >> filled? > > it could be less than 256 bytes, i.e., 128 bytes to rpc->wbuf ! > > I think that short chunks have to be written w/o WBUF (done, > > > in fact, > > >> by the HF driver). > > >> > > > > > > From spi-nor.c layer always transfer 256 bytes data with page program > > > command. > > > > Does that apply even for flashes with not-256-byte pages ? > > > > I think it needs to patch in case of nor->page_size = 512 bytes. I think the main problem here is that you assume the memory is a NOR :-). Just do what the spi-mem user asks: if he asks you to write X bytes, then write no more than X bytes. Use whatever trick you have to make sure this is always true, and if this requires using a slow path for non-aligned accesses, then do it, because it's better to have a slow+working memory than a fast+non-working one :P.