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: 1382770 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=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=hp0PX827; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CBvm14GmFz9sTK for ; Fri, 16 Oct 2020 03:25:53 +1100 (AEDT) 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-Google-Smtp-Source: ABdhPJzU+4CRSCFn5H8kgeaQ7aB67oRunMBZ/HwARSMxWQw8SKYEeHcp2NRzO5OgpxUdDb56mmEZzQ== 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;