From patchwork Thu Dec 27 20:21:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 10744045 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DAF6D14DE for ; Thu, 27 Dec 2018 20:21:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA7D128A06 for ; Thu, 27 Dec 2018 20:21:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC1A9289C4; Thu, 27 Dec 2018 20:21:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41AC1289C4 for ; Thu, 27 Dec 2018 20:21:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729586AbeL0UVT (ORCPT ); Thu, 27 Dec 2018 15:21:19 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:37268 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729368AbeL0UVT (ORCPT ); Thu, 27 Dec 2018 15:21:19 -0500 Received: by mail-lf1-f65.google.com with SMTP id y11so13351779lfj.4 for ; Thu, 27 Dec 2018 12:21:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:organization:cc:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=AenUC8Pnowalg86ojxVvWdZS3jHBPfPKO+kjZKOK3ik=; b=rCLkWyAZRopMRVNRTfvr1jNIk76XKb1z/RxpKnGJbeFBeluu/6zdxDu5fSaaYTZj9g mmyZbFP8NbIdIhrDekqVHcOI5vUJGBoUneftf/M6mx78EEUcxMQyyaPP/SifXF87xi2o IvPqxnnabIgPKEC/CSzeBm26gERd2a3f8fM5GpTjyDR1dFVD7hwhOhrD6lJJfqSTNs/b MeNfGJAVzUuieya+tKa+1Ug+QH/AmwnPVE2UuJvsFphXb3zudP4JkbltkzddvVTBvbDo l4uxWGS9fbroWABqsJps7qUAmNmXPqvzLBwixANBOOTnFXkNZ3dyz87EYjPjMtFb/tEh g0pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:organization:cc:message-id:date :user-agent:mime-version:content-language:content-transfer-encoding; bh=AenUC8Pnowalg86ojxVvWdZS3jHBPfPKO+kjZKOK3ik=; b=gUG7UnFFARkSwRdlMeJcJKdfjUsw1u+8QVeDzdDGNR1QND9NavBvV6EtAUEI1xJ0Aa dcShqoCNYs4fMfbAM7RHysh6kdyZD2FgzoRSFtQo1WmEUYTJoD1Om9cY3DoYeR1nCrYN E4BkOA8x4QrW2d9VZhTAKMAKURgwFiAluMmoOgP6hMYZ0IC/e9UUaOsU26oOidzLACm3 UucIo/DVERa3QFSJTA/3JyKqv+eMdmJ9Lz6tgAwACNrEVS0+3ehXl1Je4Z7srLZengVe OjWPDWFoo+gFHN+OfBjCNKQFISdmvkXitQEchuxD6M4hR8/onHBea1aCmvY8XwVy50Uk kVWw== X-Gm-Message-State: AA+aEWZMBMHPVl1WJbqs1LIlTPz587rDvvflHK5ulC1IaMNgLfjRlb6j ZWF+7mXibQNSg+8Aob+4ocs55g== X-Google-Smtp-Source: AFSGD/VcBiWZyMls/j5xraTurWRYDuhQXwDS4dfjZiOPqpIJCtbwo6x6y9NkOJ5jg0eXwv/ZKLJA3w== X-Received: by 2002:a19:1f54:: with SMTP id f81mr12152090lff.153.1545942077440; Thu, 27 Dec 2018 12:21:17 -0800 (PST) Received: from wasted.cogentembedded.com ([31.173.86.93]) by smtp.gmail.com with ESMTPSA id s20sm7583484lfb.51.2018.12.27.12.21.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 12:21:16 -0800 (PST) From: Sergei Shtylyov Subject: [PATCH RFT] spi-renesas-rpc: manual read issue workaround To: Mark Brown , linux-spi@vger.kernel.org, Mason Yang Organization: Cogent Embedded Cc: linux-renesas-soc@vger.kernel.org Message-ID: <76eb5af5-756e-4d54-0be2-55573649d2d1@cogentembedded.com> Date: Thu, 27 Dec 2018 23:21:14 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Language: en-MW Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Even with the trickery introduced in the latest version of the RPC-IF SPI driver, RPC-IF corrupts the data byte 4 for the RDID command, so the flash chip is still not detected. It started to work correctly after I tried to implement the workaround to this issue using the U-Boot RPC-IF driver's approach, i.e. using the external address space read mode. While at it, I'm removing the aforementioned trickery... Signed-off-by: Sergei Shtylyov --- The patch is against the 'devel' branch of Simon Horman's 'renesas,git' repo plus the RPC-IF SPI driver patch [1] and its prerequisites... [1] https://patchwork.kernel.org/patch/10742037/ drivers/spi/spi-renesas-rpc.c | 66 ++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 24 deletions(-) Index: renesas/drivers/spi/spi-renesas-rpc.c =================================================================== --- renesas.orig/drivers/spi/spi-renesas-rpc.c +++ renesas/drivers/spi/spi-renesas-rpc.c @@ -270,34 +270,52 @@ static int rpc_spi_io_xfer(struct rpc_sp } else if (rx_buf) { smenr = rpc->smenr; - while (pos < rpc->xferlen) { + /* + * RPC-IF spoils the data for the commands without an address + * phase (like RDID) in the manual mode, so we'll have to work + * around this issue by using the external address space read + * mode instead; we seem to be able to read 8 bytes at most in + * this mode though... + */ + if (!(smenr & RPC_SMENR_ADE(0xf))) { u32 nbytes = rpc->xferlen - pos; + u64 tmp; - if (nbytes > 4) - nbytes = 4; + if (nbytes > 8) + nbytes = 8; - smcr = rpc->smcr | RPC_SMCR_SPIE; + regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_SFDE | + RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ | + RPC_CMNCR_BSZ(0)); + regmap_write(rpc->regmap, RPC_DRCR, 0); + regmap_write(rpc->regmap, RPC_DREAR, RPC_DREAR_EAC(1)); + regmap_write(rpc->regmap, RPC_DRCMR, rpc->cmd); + regmap_write(rpc->regmap, RPC_DRDMCR, rpc->dummy); + regmap_write(rpc->regmap, RPC_DROPR, 0); + regmap_write(rpc->regmap, RPC_DRENR, rpc->smenr & + ~RPC_SMENR_SPIDE(0xf)); + + tmp = readq(rpc->dirmap); + memcpy(rx_buf, &tmp, nbytes); + } else { + while (pos < rpc->xferlen) { + u32 nbytes = rpc->xferlen - pos; + + if (nbytes > 4) + nbytes = 4; + + smcr = rpc->smcr | RPC_SMCR_SPIE; + + regmap_write(rpc->regmap, RPC_SMENR, smenr); + regmap_write(rpc->regmap, RPC_SMCR, smcr); + ret = wait_msg_xfer_end(rpc); + if (ret) + goto out; + + regmap_read(rpc->regmap, RPC_SMRDR0, &data); + memcpy(rx_buf + pos, &data, nbytes); + pos += nbytes; - if (rpc->xferlen > 4 && rpc->xferlen < 8 && pos == 0) - smcr |= RPC_SMCR_SSLKP; - - regmap_write(rpc->regmap, RPC_SMENR, smenr); - regmap_write(rpc->regmap, RPC_SMCR, smcr); - ret = wait_msg_xfer_end(rpc); - if (ret) - goto out; - - regmap_read(rpc->regmap, RPC_SMRDR0, &data); - memcpy(rx_buf + pos, &data, nbytes); - pos += nbytes; - - if (rpc->xferlen > 4 && rpc->xferlen < 8 && pos == 4) { - smenr = rpc->smenr & ~RPC_SMENR_CDE & - ~RPC_SMENR_ADE(0xf); - } else { - regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd); - regmap_write(rpc->regmap, RPC_SMDMCR, - rpc->dummy); regmap_write(rpc->regmap, RPC_SMADR, rpc->addr + pos); }