From patchwork Sat Dec 21 07:54:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1214442 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="gNXy/wa3"; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fyZn4XdSz9sPV for ; Sat, 21 Dec 2019 18:55:13 +1100 (AEDT) Received: from phobos.denx.de (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 72CAA81304; Sat, 21 Dec 2019 08:55:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="gNXy/wa3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 451F380E8D; Sat, 21 Dec 2019 08:54:59 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3B3E680E8D for ; Sat, 21 Dec 2019 08:54:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jagan@amarulasolutions.com Received: by mail-pl1-x644.google.com with SMTP id p27so5099813pli.10 for ; Fri, 20 Dec 2019 23:54:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cYR9K4kgo/za5EQis/Lt7xEEmwhFpfJkJx6G1IMWPMk=; b=gNXy/wa3PaDpzzGlYJBbxjFdrTAPa16/r8BspzGyhjDj9Sq6WgQ+WAJVC4C3QhjqIM PfsHFZqc7U67m4UnXPk8tpmqGZ5yDoZlUwg9dK68IkgbSJyjMCFwsvifAGm69l/81ypb M2idMyihoRyRevdvsVNBql0mTWV+ftMNkdGc4= 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=cYR9K4kgo/za5EQis/Lt7xEEmwhFpfJkJx6G1IMWPMk=; b=UhI7O3JDIoQpSPcesxVKl4j45G92OHoiXmym4hE615OP0S3ktPev/yBcj3nUjossfF +F19lzUoQBZRM/+3xockaBn5B8rra2aGri1ugcegarKNuz3uB8XmK5EzJBF5vIefnRnm E7WImCZOgYRbcdO3OEoPj+fD0VNBX0czBC1twXvoVuAc4ddrNnfjWwV27SEawqdnPwv/ grb6apQDrMkPX1wWoGcif6jsirJhB3cJAqogTfRzCui/W2sUuVJJqGwjaWRVXk5IFu0o aq+wOkt+ik/8WHj0Jl/Tg7av9FM82ndevVZY6o7LCYKpWRBLm7x6rKJcrxrlgMfctIiv eICg== X-Gm-Message-State: APjAAAUuZeDC+akymy7IvOmfdbeGBEjsiv15ry+V4gij/9afTCSJhroq KPPEzgVnfqEvAHx6X3QWSFCqeA== X-Google-Smtp-Source: APXvYqzAI0CGTs57MZ9EmoGRzB6dxFgugcbBmjwxphKbNAJrYLfsuhH/kvP2sJNvFdKANfD21bJiZg== X-Received: by 2002:a17:902:6544:: with SMTP id d4mr20136327pln.278.1576914894562; Fri, 20 Dec 2019 23:54:54 -0800 (PST) Received: from localhost.localdomain ([49.206.202.177]) by smtp.gmail.com with ESMTPSA id i9sm15551018pfk.24.2019.12.20.23.54.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 23:54:54 -0800 (PST) From: Jagan Teki To: Simon Glass , Kever Yang , Philipp Tomsich Subject: [PATCH 01/11] spi: rk: Limit transfers to (64K - 1) bytes Date: Sat, 21 Dec 2019 13:24:30 +0530 Message-Id: <20191221075440.6944-2-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20191221075440.6944-1-jagan@amarulasolutions.com> References: <20191221075440.6944-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: u-boot@lists.denx.de, linux-amarula , linux-rockchip@lists.infradead.org Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean The Rockchip SPI controller's length register only supports 16-bits, yielding a maximum length of 64KiB (the CTRLR1 register holds "length - 1"). Trying to transfer more than that (e.g., with a large SPI flash read) will cause the driver to hang. Now, it seems that while theoretically we should be able to program CTRLR1 with 0xffff, and get a 64KiB transfer, but that also seems to cause the core to choke, so stick with a maximum of 64K - 1 bytes -- i.e., 0xffff. Note, that the size is further divided into 'minus 1' while writing into CTRLR1. This change fixed two different read issues, 1. sf read failure when with > 0x10000 2. Boot from SPI flash failed during spi_flash_read call in common/spl/spl_spi.c Observed and Tested in - Rockpro64 with Gigadevice flash - ROC-RK3399-PC with Winbond flash Signed-off-by: Jagan Teki Reviewed-by: Kever Yang --- drivers/spi/rk_spi.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/spi/rk_spi.c b/drivers/spi/rk_spi.c index c04535ac44..95eeb8307a 100644 --- a/drivers/spi/rk_spi.c +++ b/drivers/spi/rk_spi.c @@ -27,6 +27,12 @@ /* Change to 1 to output registers at the start of each transaction */ #define DEBUG_RK_SPI 0 +/* + * ctrlr1 is 16-bits, so we should support lengths of 0xffff + 1. However, + * the controller seems to hang when given 0x10000, so stick with this for now. + */ +#define ROCKCHIP_SPI_MAX_TRANLEN 0xffff + struct rockchip_spi_params { /* RXFIFO overruns and TXFIFO underruns stop the master clock */ bool master_manages_fifo; @@ -367,7 +373,7 @@ static inline int rockchip_spi_16bit_reader(struct udevice *dev, * represented in CTRLR1. */ if (data && data->master_manages_fifo) - max_chunk_size = 0x10000; + max_chunk_size = ROCKCHIP_SPI_MAX_TRANLEN; // rockchip_spi_configure(dev, mode, size) rkspi_enable_chip(regs, false); @@ -451,7 +457,7 @@ static int rockchip_spi_xfer(struct udevice *dev, unsigned int bitlen, /* This is the original 8bit reader/writer code */ while (len > 0) { - int todo = min(len, 0x10000); + int todo = min(len, ROCKCHIP_SPI_MAX_TRANLEN); rkspi_enable_chip(regs, false); writel(todo - 1, ®s->ctrlr1);