From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C36B5C47094 for ; Thu, 10 Jun 2021 12:00:23 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EC69B613CA for ; Thu, 10 Jun 2021 12:00:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC69B613CA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 368E282EB2; Thu, 10 Jun 2021 14:00:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1623326417; bh=QkXt7khY0MNn8a+wSmr8B39yR39q3piDPjUGP9rKCFY=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=bu1+muzylnUWh5/Xbb8w5X4EowFyJRVuxKbxFt1xAJAueagFdg3NPWYDscxwY0lG5 J2fAV4CnyraLGtEDbXLNDD8fgjcj3s637Eg2ZqivO8ObdBLv2kHa8Z0mYtEtWyHHp2 +S1UHFuJ8rPvakDciBqMTLQCTdQnegIOtDRa6ydnPw/+QvM81cKQfcAGElPB9tz7MR 94owlchqhdrK8ByC2qUQZMD3dUev1mIolDwMlgJiKXSJa8v/VGQyuSlgVhToax9dhk Zqutnx4unQEr5YXrKwgWS0HpbjEDKsUwltRxIxaJgae2tHRNmI/dUAEiI7XtzVyI2z 6v+cswGPxtifA== Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 8AAEB82052; Thu, 10 Jun 2021 14:00:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1623326414; bh=QkXt7khY0MNn8a+wSmr8B39yR39q3piDPjUGP9rKCFY=; h=From:To:Cc:Subject:Date:From; b=pNNHDdSKwCoV7+bOigaG3THpp4sRQi5eZ9B9IBTcYlyDHE4UHvZI5BEjSABw0hb7m etr5SOBpbSw9aX3qAkdh+Fw/L2gXo692nAMmK2aGN4IUc65l/I3z3gKuiJ4l5oACwA GjJ8LVCDKy8aaXEw3yAFEjLwm38wHhwxjJo6dom9OLs72Y+hGIE1PgD2sSeD0elrns NQ39qTMKm8IKQzYXVG3RSnzTJFgNommB/kKMQjt6l95PpRLNyp7I6S8kyB9MFwOn74 q4CPy9cd1AhpkLBGohJEHV5pjNX0IxjHJtmMHc70+FvNyoJcnXD2PppA3EkR+1132q Yg3HyGizKGiMA== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Jagan Teki , Patrick Delaunay Subject: [PATCH V2] spi: Update speed/mode on change Date: Thu, 10 Jun 2021 14:00:00 +0200 Message-Id: <20210610120000.5147-1-marex@denx.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.4 at phobos.denx.de X-Virus-Status: Clean The spi_get_bus_and_cs() may be called on the same bus and chipselect with different frequency or mode. This is valid usecase, but the code fails to notify the controller of such a configuration change. Call spi_set_speed_mode() in case bus frequency or bus mode changed to let the controller update the configuration. The problem can easily be triggered using the sspi command: => sspi 0:0@1000 => sspi 0:0@2000 Without this patch, both transfers happen at 1000 Hz. With this patch, the later transfer happens correctly at 2000 Hz. Signed-off-by: Marek Vasut Cc: Jagan Teki Cc: Patrick Delaunay --- V2: Set plat in case it is NULL --- drivers/spi/spi-uclass.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index ee30110b56..d867b27806 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -391,6 +391,8 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, } else if (ret) { dev_err(bus, "Invalid chip select %d:%d (err=%d)\n", busnum, cs, ret); return ret; + } else if (dev) { + plat = dev_get_parent_plat(dev); } if (!device_active(dev)) { @@ -416,12 +418,22 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, goto err; } + /* In case bus frequency or mode changed, update it. */ + if ((speed && bus_data->speed && bus_data->speed != speed) || + (plat && plat->mode != mode)) { + ret = spi_set_speed_mode(bus, speed, mode); + if (ret) + goto err_speed_mode; + } + *busp = bus; *devp = slave; log_debug("%s: bus=%p, slave=%p\n", __func__, bus, *devp); return 0; +err_speed_mode: + spi_release_bus(slave); err: log_debug("%s: Error path, created=%d, device '%s'\n", __func__, created, dev->name); -- 2.30.2