From patchwork Thu Oct 15 16:25:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralph Siemsen X-Patchwork-Id: 317781 Delivered-To: patch@linaro.org Received: by 2002:a92:d603:0:0:0:0:0 with SMTP id w3csp644484ilm; Thu, 15 Oct 2020 09:25:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwd4EU2QQQHZEntg6tEkJGaF1EiiMaMepLnde4LnPBwO0NHqjvzTVmctip6pArnJae2ChTL X-Received: by 2002:a17:906:f110:: with SMTP id gv16mr5410578ejb.257.1602779150435; Thu, 15 Oct 2020 09:25:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602779150; cv=none; d=google.com; s=arc-20160816; b=w7fEeGVm2roH+rmSt/9KMht7+SfQyqPjRFIkhcmVDuWviGvP2ZyS1VGy9t8x6aXxhy LnXn11vhW5vjQ1bWheXPpGQPhgfV3GgPLWlhpuzxj0JuLDCqstBOv2HA9q7RbLhBkHJS VofM1efnvofMB60HhIVWhVNwEBv16MumhxNoWk+sjWsdT7wL7sMYO7PVp4WnlSmCNaeU WpQKGfHfb6D6sURp5409bKasClzsVjiZu92pCI1PEcY+FSRkltjLUpuambnlp8wxxO/0 ztXTn7AciWVOz5RC+PJYg9qdG04tO4ysNsrACFftyOejc50AKVMEBz4fnCyH/tpXzYAR LlyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=zTCQSh3z1RazCT/3/n1duI9ocUpQPqE5jfBGWNiQ02I=; b=brK4innoUocMKmW49vPhQCpNsgm5OWvCxzb2KyMkCcVjv/WriIuCjVew64CXk0X13G Y1gxYkb65sdX4qRx8MQCBrvHpmeZ1fcy/TxXznI4XpOstVaz5tMAyCvJmIrGghpab8TS gclCSVRfUoCzDCkBt7r3Ri5LG/Z8nHDumaiZLgI+rtnGGLEYMZspd7RxZwJE69zgChLU qMOOFHr4ZS8veC4bcL1Wi+aY7T1leoJ94MnWGM8EKkxEoPxOPSaiQHs2c1pRz26DbSzS 95kfAODZLLYoLcju1IMe1CenCt/RQbOf+yUlJ6aO2UDRQn1NDKglPsFzTWgGgolzBetB v4Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hp0PX827; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id e15si2563723ejm.98.2020.10.15.09.25.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 09:25:50 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hp0PX827; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DE99E82304; Thu, 15 Oct 2020 18:25:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="hp0PX827"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9A7638235E; Thu, 15 Oct 2020 18:25:47 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (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 0557281BD2 for ; Thu, 15 Oct 2020 18:25:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ralph.siemsen@linaro.org Received: by mail-io1-xd42.google.com with SMTP id n6so5268626ioc.12 for ; Thu, 15 Oct 2020 09:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=zTCQSh3z1RazCT/3/n1duI9ocUpQPqE5jfBGWNiQ02I=; b=hp0PX827nUvC6d//4LdH9lDwX3RbNqMzOlcywMRBen1wDe4B4Tu25wIJUj1memtZ0j 3MhwRjGMioWldJpP9LUCwPlBwGm3LYiP3bkOGTe0Hzn9Vt2VqbwlmAuLH+QUMFdE/UGP CTo08iaWz81CNs1+WrdXV7k/WxEua+0SoGfLnkffB78+njb/O64k5GXVQkxRhwEW+mMn gJZ//1s35DXZ/GfyV7HBjUUXvyXf5AVpn6sOqJBiDe9j6jEOTBkQTEsiWXrtKQ/1im3r bkgORwS9mtunBwR48015K6Fo3Qum5VFKderGD/CCLMuNya7wWK12YVch7jeaw5wR2qIa ZfIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=zTCQSh3z1RazCT/3/n1duI9ocUpQPqE5jfBGWNiQ02I=; b=Kel2UfvIJkwqHfZLJqtB8oRO7ITkEpzmi64nHetuUeLsOPYj20XUEF8trIIjQVgNkp Mp/G69S3K8aFbzo4vbAOkYKyIN59SWyxB5HbRbvCee3iswd86MOKdyuv04J6tdiTM4wO g6fbGTHbhjpOQJT5JLpTVXgwSZsItVksnBbacZfTVwWULFz4y5OJYyIrbiHQb5Sb31uZ KyM40MdnqDvaeK0t4OzM+9bJFnndaCMB/tnCBzxcjmmNWqLThbMwUJyn9Xw84N0ivMO6 awfB881dEUzbkdWSflyIyqctqTFep50kzR1bMuTZUeFaLsuwBifzcfJOyBh675+qm3R0 2UCg== X-Gm-Message-State: AOAM530TfRuL1VyMP3hBw8z+kv7D58Vwq+A9ZY3UxEPtxjxsNjaxsR7G RuH5vliZx6hlX7ooKHynf5N+qw== X-Received: by 2002:a02:c785:: with SMTP id n5mr4237078jao.128.1602779143561; Thu, 15 Oct 2020 09:25:43 -0700 (PDT) Received: from localhost (rfs.netwinder.org. [206.248.184.2]) by smtp.gmail.com with ESMTPSA id v78sm3301674ilk.20.2020.10.15.09.25.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Oct 2020 09:25:42 -0700 (PDT) Date: Thu, 15 Oct 2020 12:25:41 -0400 From: Ralph Siemsen To: Patrick Delaunay , Jagan Teki , u-boot@lists.denx.de Cc: Marcin Wojtas Subject: Speed/mode setting via "sf probe" command Message-ID: <20201015162541.GA24746@maple.netwinder.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Hi, The "sf probe" command is documented to take optional speed/mode args: sf probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus and chip select This worked correctly in older u-boot versions, but as of 2019.07 the speed/mode arguments appear to be effectively ignored. As this feature is quite useful for testing purposes, I would like to find a way to support it again. But the logic is surprisingly complicated, so I would like to get some advice/ideas. The user-specified speed/mode are parsed in do_spi_flash_probe() and eventually are passed to spi_get_bus_and_cs(). In 2019.04 and earlier, the logic here was pretty straightforward: plat = dev_get_parent_platdata(dev); if (!speed) { speed = plat->max_hz; mode = plat->mode; } ret = spi_set_speed_mode(bus, speed, mode); if (ret) goto err; So this calls spi_set_speed_mode() with the user-specified speed, or a default value. As of commit 0cc1b846fcb310c0ac2f8cbeb4ed5947dc52912 ("dm: spi: Read default speed and mode values from DT") the logic has changed. The user-specified speed value is now stored into plat->max_hz, but *only* when no chip select has been configured. In practice this means only the first call to spi_get_bus_and_cs() uses the speed parameter. Thereafter the speed will not change. Related commit f7dd5370986087af9b9cfa601f34b344ec910b87 ("spi: prevent overriding established bus settings") removes the call to spi_set_speed_mode() entirely. So the speed is now set by dm_spi_claim_bus() which uses slave->max_hz, which in turn is set from plat->max_hz in the spi_child_pre_probe() function. The first call to spi_get_bus_and_cs() typically occurs when searching for u-boot environment, and uses the speed specified in DT. This becomes the only speed, as subsequent "sf probe" do not update plat->max_hz. One potential work-around would be to clear the chip select prior to re-binding the device. This allows plat->max_hz to be updated, andalso means that device_bind_driver() will be repeateed. However I am not entirely certain if this is correct approach. In particular, is using -1 for the cs appropriate in all cases? It seems it can come from DT. diff --git a/cmd/sf.c b/cmd/sf.c index d18f6a888c..8cb70f6487 100644 --- a/cmd/sf.c +++ b/cmd/sf.c @@ -128,6 +128,9 @@ static int do_spi_flash_probe(int argc, char *const argv[]) /* Remove the old device, otherwise probe will just be a nop */ ret = spi_find_bus_and_cs(bus, cs, &bus_dev, &new); if (!ret) { + struct dm_spi_slave_platdata *plat; + plat = dev_get_parent_platdata(new); + plat->cs = -1; device_remove(new, DM_REMOVE_NORMAL); } flash = NULL;