From patchwork Thu Jun 20 03:58:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Hilliard X-Patchwork-Id: 1119436 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=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qswBDqYF"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45V2Tb22wFz9s5c for ; Thu, 20 Jun 2019 23:19:15 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id F2A90C21DF3; Thu, 20 Jun 2019 13:18:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 84217C21DD3; Thu, 20 Jun 2019 13:12:16 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4BC3FC21C4A; Thu, 20 Jun 2019 03:58:51 +0000 (UTC) Received: from mail-ot1-f68.google.com (mail-ot1-f68.google.com [209.85.210.68]) by lists.denx.de (Postfix) with ESMTPS id B626CC21BE5 for ; Thu, 20 Jun 2019 03:58:50 +0000 (UTC) Received: by mail-ot1-f68.google.com with SMTP id j19so1373938otq.2 for ; Wed, 19 Jun 2019 20:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0IXumW3u/vKPp6qB6FGH8151zDiZoD0KatZj+Rdkavc=; b=qswBDqYFkv3OV2WaV9I8CRvAn/dljO3NYweefRkCBTbWDmGhnhCpdColl2IppHxuqc Rh3gzx7x3k5+rmmv+kXTkHfYShy4RcwYHDdMnJO/ACn2y7zJp6G3Qp6CB1PvPqg3FOs9 eSbAO/gGz1t6SFdF28EpxDJccFOOoudeKMaOF2A9SSxa0APrKU17pVP1SWYgKtauh092 /MwLPpz4UeD55DuQEqFhNT/4daxVAj9WiCBl29R/RS6rq6uEd0eNYl7shDBaiOi0wqY7 2kOK/HM835Y7U8MA+E+pX1X20cnX5d1NRsIWbt0HfcnFvL8Xhcy+sycv/mn+IguJlzr/ 4+Uw== 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:mime-version :content-transfer-encoding; bh=0IXumW3u/vKPp6qB6FGH8151zDiZoD0KatZj+Rdkavc=; b=oFd33jJWL37TgBPIBzgnmIUgQqC/kVF4o/Q26klJvn7iYd1kNDyH7HRZHAINzYLUDS 6A9F7tbkJ8yF7eqPrNOqD34iQNBWglp6PMYdTe5L8BcxxSZjRmJOfzJDsUX94aBtn0u1 TdG2ieox+mPiyz1jvJYHtSOILe4GULRYOmIMHfkrX7PVsxrWBvOPoRD68S/pVCDlwAY2 wcrujKu8bPXtMtuhJvGA3wvxKQyvFCZYvnNZjLsIHEl38wCXPm5IFBWzhO1ZIzjVbk6j 4gv8cq+/xRRv5984GG1zWGfrr9cxPIg+XTH7+qwQTC5Lfmjvm1YVhCrRGKDzosX1Y631 Cuzg== X-Gm-Message-State: APjAAAXhC0w7cj7nCE57eX15vdXH7gwcestfOOj3OisIzQUI4cLhs6uP WJ7X3+wHB66aYhoXDEAAg+SQE709ej4= X-Google-Smtp-Source: APXvYqy16v78oOb01EX77zBtEL6XWU0y5fYKFilOZmll5sxcz0M7JXcApZbQ+SaWq5gQb6jzuiUssA== X-Received: by 2002:a05:6830:1086:: with SMTP id y6mr9141596oto.22.1561003129109; Wed, 19 Jun 2019 20:58:49 -0700 (PDT) Received: from desertvoice.lan (c-75-64-138-126.hsd1.ms.comcast.net. [75.64.138.126]) by smtp.gmail.com with ESMTPSA id r25sm8109324otq.39.2019.06.19.20.58.47 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 20:58:48 -0700 (PDT) From: George Hilliard To: u-boot@lists.denx.de Date: Wed, 19 Jun 2019 22:58:46 -0500 Message-Id: <20190620035846.16793-1-thirtythreeforty@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 20 Jun 2019 13:12:10 +0000 Cc: Jagan Teki , George Hilliard Subject: [U-Boot] [PATCH] spi-uclass: claim bus before setting speed X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" The sunxi SPI peripheral driver attempts to interact with the peripheral in the set_speed function. It also resets the device completely (disabling clocks and power) when the bus is released and turns it back on when claiming. So, if the clock was set up before the bus was claimed, the speed change would have no effect, and the peripheral wouldn't work in many cases. This change allows the peripheral driver to initialize the device before attempting to do anything else. Signed-off-by: George Hilliard Cc: Jagan Teki --- drivers/spi/spi-uclass.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index 88cb2a12622..88aa883b206 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -51,6 +51,7 @@ int dm_spi_claim_bus(struct udevice *dev) struct dm_spi_bus *spi = dev_get_uclass_priv(bus); struct spi_slave *slave = dev_get_parent_priv(dev); int speed; + int ret; speed = slave->max_hz; if (spi->max_hz) { @@ -61,15 +62,22 @@ int dm_spi_claim_bus(struct udevice *dev) } if (!speed) speed = SPI_DEFAULT_SPEED_HZ; + + if (ops->claim_bus) { + ret = ops->claim_bus(dev); + if (ret) + return log_ret(ret); + } + if (speed != slave->speed) { - int ret = spi_set_speed_mode(bus, speed, slave->mode); + ret = spi_set_speed_mode(bus, speed, slave->mode); if (ret) return log_ret(ret); slave->speed = speed; } - return log_ret(ops->claim_bus ? ops->claim_bus(dev) : 0); + return 0; } void dm_spi_release_bus(struct udevice *dev)