From patchwork Sun Dec 6 21:21:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1411785 X-Patchwork-Delegate: sjg@chromium.org 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=windriver.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=windriversystems.onmicrosoft.com header.i=@windriversystems.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-windriversystems-onmicrosoft-com header.b=L15UuGDN; 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 4CpzwH1BR3z9s0b for ; Mon, 7 Dec 2020 08:24:15 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AF59182611; Sun, 6 Dec 2020 22:23:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=windriver.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=windriversystems.onmicrosoft.com header.i=@windriversystems.onmicrosoft.com header.b="L15UuGDN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 69FBE82604; Sun, 6 Dec 2020 22:23:23 +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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2060b.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::60b]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9AD10825D9 for ; Sun, 6 Dec 2020 22:23:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=windriver.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=Ovidiu.Panait@windriver.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P7qvwxGq6qET5LrzD4AWmpe807Wyfpdy3NeSzu6nfG1uxRPdgiP4ObM7Hcqlu1JRTuJ9mlDld1tZYKmGFghJ40qm/hQKMdC4rbF2Bijf7fRnlHzRDslCvGYH/4iQElmlsgFeWOv1duHBruFppi2UNQlUjhL4qjZhACgnboRdljFlUzXaRa9wRCKEaQNsYC1c0fe6ONR9sWZx5sTz91WAKEUkSb14IAwD+VMQCsHz2HrVhW5/yNHuUrIjBB9Do73q6pXhhy9ZLtFmvMklcXrJN+QRUiANz2B1UmVl2ERWomdehRuaE6HoaJ+W8LW0nMKcuM9SHnrjtnrHNRJv/gfo5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vX0SYnYX9sq9D+vjva4aC4L8PeJuZGOwi06JMG8I4w0=; b=jsTz3PyptmU0u/WwFyVxEJtsZM28KfUHLaVQiQrVo2upq1/whh6irxX8YDeW6j8aZRAzeiBtJudS3JJSTSqKTwdI/0VkD/q1XWTGEacpjwSg2k2DV066Jb1J3BpGnoDGec3Gk3WaYQkK1ZewMm2+WUW+envxA2MiZbEpIIs0JN8sRG+ZJTrSsAj/GzS/bZDNJ5QH84X6GqkIWylmBwsumgP94D1Iln1qlJ0ytz8SV+gp/l+TkDIht7rQuwYEVXDIr0IkMpPlpVfpkS9+ynNkMjQnzDH2GOzZpbaF7g7PJZjvWhLpl/CwKgX4EopmOveG+F0ArmC96MEvxzlxWnntVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vX0SYnYX9sq9D+vjva4aC4L8PeJuZGOwi06JMG8I4w0=; b=L15UuGDNcjE0RG0Ncg1/sAPpHIRf5sDiBAMbC/WoZCVPmJg6M70HA9AD1QmNHRM25JjqGpVSBmktrzYHFCdUPnrC/RvW3X+20zoI8gWTEpCcNERt7naPe8NIhnDMOGv8q9j0y2VYly6c5/nVOxOCPGDbcrBT3ywIXi3cGLXr0sw= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=windriver.com; Received: from BL0PR11MB3201.namprd11.prod.outlook.com (2603:10b6:208:6b::21) by MN2PR11MB4333.namprd11.prod.outlook.com (2603:10b6:208:195::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.21; Sun, 6 Dec 2020 21:23:17 +0000 Received: from BL0PR11MB3201.namprd11.prod.outlook.com ([fe80::54:a24e:6136:45f2]) by BL0PR11MB3201.namprd11.prod.outlook.com ([fe80::54:a24e:6136:45f2%5]) with mapi id 15.20.3632.023; Sun, 6 Dec 2020 21:23:17 +0000 From: Ovidiu Panait To: u-boot@lists.denx.de Cc: Ovidiu Panait , Jagan Teki , Peng Fan Subject: [PATCH 5/6] spi: spi-uclass: Fix spi_claim_bus() speed/mode setup logic Date: Sun, 6 Dec 2020 23:21:27 +0200 Message-Id: <20201206212128.21233-6-ovidiu.panait@windriver.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201206212128.21233-1-ovidiu.panait@windriver.com> References: <20201206212128.21233-1-ovidiu.panait@windriver.com> X-Originating-IP: [46.97.150.20] X-ClientProxiedBy: VE1PR03CA0003.eurprd03.prod.outlook.com (2603:10a6:802:a0::15) To BL0PR11MB3201.namprd11.prod.outlook.com (2603:10b6:208:6b::21) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from otp-linux01.wrs.com (46.97.150.20) by VE1PR03CA0003.eurprd03.prod.outlook.com (2603:10a6:802:a0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Sun, 6 Dec 2020 21:23:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b05b812f-573e-4047-803f-08d89a2d25f5 X-MS-TrafficTypeDiagnostic: MN2PR11MB4333: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iXFMWfn4D5szCpC/1G6nkGJowSBH9+SCXwAZuFRmMeFgNl3/icLM3Vflz7KMzx7ob+8ZesBncuzMmQrbolZnGaYAGp45rJESO4Gqt2hTJXmNDksfrb2RDjmsoFiFMtCiTy5u1i5JBRfXP8PYchxGBqSk0x4jbBQb+LUsdU1tHAwjUT3ubRfhy7cC8tWDNf4Go10DWJIXRC2qNEJvEhB7haYq2lNJOCyatso3oMbvSQVzLq5TXGdSqmw+zT6+EwW17mzB/pZrddO85OSQVnDM1Y3E1Kc+Rl4WVPD+1IIH433a4qG/+YG/44CNQEFgXxJP X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR11MB3201.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(376002)(39830400003)(136003)(346002)(4326008)(8936002)(2616005)(1076003)(86362001)(83380400001)(26005)(44832011)(2906002)(16526019)(956004)(6666004)(478600001)(54906003)(66946007)(36756003)(6506007)(186003)(52116002)(5660300002)(8676002)(316002)(6916009)(66556008)(6512007)(6486002)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ZScT9jH5daxma+9raLx3AgAjnFVq7CG5NrmE6HUFiKp6jn3JqshRnG9ZuxZ8VsSQhExNAVTux4csa4fZ2bu1stGvRRzGJ8S627AYFG6z50gWbVde3prLikf8rK7uFIjoo0yntDIyP3NRDrBxakH0u7lddOAXI65nc3I4fNtHMR3O9u97eiq4E8yQoB6a7QrlP0i44eiZfHM+wRc6rYt9ZBtHKuKwcXf6w5PICIpBVp/PZunL4JRGL5kVMulCLqP/Ddq9ZqQVSCJzkslTM1xgJK465AFexlqy+gTSmYitphakRYKTYapGeQaD4VBbBSUyyMpT2zCLHIWY1huKPYFGp71C6I776I5oVPY0ztBErHiEVKOuA1Ec/heed+u5Q0I3XWAY/MJATx/RkoJ+BBDzb5SbtBXG7qAIAaaoO02d7fe0l+747Ej0gG9cvfsesbHPguYMjQvpeN/R9VISGmaYMUu/NW3w+25uaSWLGyRfQ4sgggeEAz2H5qC6tGeDLONG5CNZcrfscNqKfDjDA8+uQRZvUjaWDyKM//HnII8yyVBebyN2svTgAgRUw91+cxF/b/5n3JKkae6fHoO/cuvqTPxZS4NEa/t8Ffk6t80xB9B6K7oeW9vgAdm6/tz5be38dtHzKfH2FPzBar7XLd8aD+sieiQfhRaOlzwMCMNn1RFfhuYU4/zKXgt27780HYb/3yzTUceMiT/TcDre85/lbQN4ZdVPWfy8Ot7O+VJe8g8x0HEygLuGhtJs2eGtXLjneBfx9hQoSFiMZJwjKv8GDqeCpxotDUJ4FA5bW3an+ZbN2huMqgCmAqekD4iLabhD+9/4iPnlsRTy67T6+XKxCmWJbuU1CtO216yWxcXJq1cJAi60ZI8aPF4Nr4kJp6FcbiSI7E+bTov3GxZNRMFM8cQ1dRV4hNSclE59kTwcc/vZa/JFx+pwGDvOnowmJJpi+ksH74uh0/8UQQcS+ftrCP1SQb26rZozobLjIsIpqlo= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-AuthSource: BL0PR11MB3201.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2020 21:23:17.2647 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-Network-Message-Id: b05b812f-573e-4047-803f-08d89a2d25f5 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dVWPqhGqv6KKfgplTglnhupSnBTwoOpBvG3h+AgDzbL9flg9X/sB3dki6uMaRNOOEA/t01V1BJRaSVlfhy9XkfNG7EouelCX1FwhKaTDzaQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4333 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 Currently, when different spi slaves claim the bus consecutively using spi_claim_bus(), spi_set_speed_mode() will only be executed on the first two calls, leaving the bus in a bad state starting with the third call. This patch drops spi_slave->speed member and adds caching of bus speed/mode in dm_spi_bus struct. It also updates spi_claim_bus() to call spi_set_speed_mode() if either speed or mode is different from what the bus is currently configured for. Current behavior is to only take into account the speed, but not the mode, which seems wrong. Fixes: 60e2809a848 ("dm: spi: Avoid setting the speed with every transfer") Reported-by: Rasmus Villemoes Reported-by: Moshe, Yaniv Signed-off-by: Ovidiu Panait Reviewed-by: Simon Glass --- drivers/mmc/mmc_spi.c | 1 - drivers/spi/spi-uclass.c | 17 ++++++++++++----- include/spi.h | 18 ++++++++++++++---- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/drivers/mmc/mmc_spi.c b/drivers/mmc/mmc_spi.c index 50fcd32674..793e3c8cfa 100644 --- a/drivers/mmc/mmc_spi.c +++ b/drivers/mmc/mmc_spi.c @@ -418,7 +418,6 @@ static int mmc_spi_probe(struct udevice *dev) priv->spi = dev_get_parent_priv(dev); if (!priv->spi->max_hz) priv->spi->max_hz = MMC_SPI_MAX_CLOCK; - priv->spi->speed = 0; priv->spi->mode = SPI_MODE_0; priv->spi->wordlen = 8; diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index 55a8eed890..4bd2adeb58 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -51,23 +51,28 @@ int dm_spi_claim_bus(struct udevice *dev) struct dm_spi_ops *ops = spi_get_ops(bus); struct dm_spi_bus *spi = dev_get_uclass_priv(bus); struct spi_slave *slave = dev_get_parent_priv(dev); - int speed; + uint speed, mode; speed = slave->max_hz; + mode = slave->mode; + if (spi->max_hz) { if (speed) - speed = min(speed, (int)spi->max_hz); + speed = min(speed, spi->max_hz); else speed = spi->max_hz; } if (!speed) speed = SPI_DEFAULT_SPEED_HZ; - if (speed != slave->speed) { + + if (speed != spi->speed || mode != spi->mode) { int ret = spi_set_speed_mode(bus, speed, slave->mode); if (ret) return log_ret(ret); - slave->speed = speed; + + spi->speed = speed; + spi->mode = mode; } return log_ret(ops->claim_bus ? ops->claim_bus(dev) : 0); @@ -324,6 +329,7 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, { struct udevice *bus, *dev; struct dm_spi_slave_platdata *plat; + struct dm_spi_bus *bus_data; struct spi_slave *slave; bool created = false; int ret; @@ -381,12 +387,13 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, } slave = dev_get_parent_priv(dev); + bus_data = dev_get_uclass_priv(bus); /* * In case the operation speed is not yet established by * dm_spi_claim_bus() ensure the bus is configured properly. */ - if (!slave->speed) { + if (!bus_data->speed) { ret = spi_claim_bus(slave); if (ret) goto err; diff --git a/include/spi.h b/include/spi.h index ef8c1f6692..7efced7057 100644 --- a/include/spi.h +++ b/include/spi.h @@ -39,9 +39,22 @@ #define SPI_DEFAULT_WORDLEN 8 -/* TODO(sjg@chromium.org): Remove this and use max_hz from struct spi_slave */ +/** + * struct dm_spi_bus - SPI bus info + * + * This contains information about a SPI bus. To obtain this structure, use + * dev_get_uclass_priv(bus) where bus is the SPI bus udevice. + * + * @max_hz: Maximum speed that the bus can tolerate. + * @speed: Current bus speed. This is 0 until the bus is first claimed. + * @mode: Current bus mode. This is 0 until the bus is first claimed. + * + * TODO(sjg@chromium.org): Remove this and use max_hz from struct spi_slave. + */ struct dm_spi_bus { uint max_hz; + uint speed; + uint mode; }; /** @@ -112,8 +125,6 @@ enum spi_polarity { * * @dev: SPI slave device * @max_hz: Maximum speed for this slave - * @speed: Current bus speed. This is 0 until the bus is first - * claimed. * @bus: ID of the bus that the slave is attached to. For * driver model this is the sequence number of the SPI * bus (bus->seq) so does not need to be stored @@ -131,7 +142,6 @@ struct spi_slave { #if CONFIG_IS_ENABLED(DM_SPI) struct udevice *dev; /* struct spi_slave is dev->parentdata */ uint max_hz; - uint speed; #else unsigned int bus; unsigned int cs;