From patchwork Wed Jan 4 09:36:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hector Martin X-Patchwork-Id: 38835 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5053736wrt; Wed, 4 Jan 2023 01:39:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXssMlactNoakb7EWJXWMVRx7+ZPVq/ozSJFoJlIgVp4fPMoqd1eyewcE/N1H486q/nkEYUF X-Received: by 2002:a17:902:8481:b0:192:b5b3:b800 with SMTP id c1-20020a170902848100b00192b5b3b800mr16418470plo.39.1672825161778; Wed, 04 Jan 2023 01:39:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672825161; cv=none; d=google.com; s=arc-20160816; b=R0qEEGxMzRup7lkmSNYN3WnQruw5+ui3FxDucOIjW9MJXPVcpJO3RX2wnQhITXwRDO u8y/0L+Pr++DQ4W/SgTAxRykrotxT2f6qCNc5hkmf2AuKqywO7IxDSQJPn1GZd38bOZZ gRsRVrQcaEpx2UQR1BSRZqfZ4nL5Q44rBh8/c8NhnL6CIL7P9mgOlrs7mnZX48/A4jYa MHyarh80oGngBPSWJ5Hy093p4JzgteOKUlHHVL/cGn9rjWEDdXdmrtdooHoygj5+VVpe Uv/g16USkSMdunr+3cQ0uHHvKwDZaO1bj1cO44pmvlshVReUINxyC9BeTjfgGU85HOtT s3NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Rz1QvljqFjJ2T7kuTnxd9NI2h2fePxX/YKNHSGdmyqg=; b=nedzc6yRjb2xN24kKLdesiU119sP9yev5it5jX24QCqqsKSGHDyUzFB2usjxhJnVkn 8HRu/N89E0LEzdsSsDB+zmIbzIfgM6ajqBenOOEvmCwmlIpk8cpD4ShXEfIeLSnITyQF AKx5JDS553dBpqu0QRlFWkwN9FT5hU4axwrGWUTXv2+OmvYHpocA3JTbG+J52frspj7W xRO8mnosEiBSYv/Vnk1RgWfNc+Rl/eP6g+WmBSBviizeX1XdkLxoZrOn8UUKem7FLafF UiqaZHxSvEyox+WhLSi5U0z5ifsJ8amoDNGdBWYuy3dyv0sbFsZghjno8mA8/koIjjvE XsIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marcan.st header.s=default header.b=pUVvWOp1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=marcan.st Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bi2-20020a170902bf0200b001895e356f00si32887399plb.152.2023.01.04.01.39.10; Wed, 04 Jan 2023 01:39:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@marcan.st header.s=default header.b=pUVvWOp1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=marcan.st Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239176AbjADJiH (ORCPT + 99 others); Wed, 4 Jan 2023 04:38:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234567AbjADJhg (ORCPT ); Wed, 4 Jan 2023 04:37:36 -0500 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5CF5F015; Wed, 4 Jan 2023 01:37:34 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sendonly@marcansoft.com) by mail.marcansoft.com (Postfix) with ESMTPSA id 51F6742137; Wed, 4 Jan 2023 09:37:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=marcan.st; s=default; t=1672825053; bh=yxqAc1bBEfZDS+8bRfcAcj3SjysPRG0Y/YATmIkz/cs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pUVvWOp1RYpDwgh5qbEt7nGu6aC/XdWaW3yV1D8l0utAhMB6LWzMX35bp1Kv3xjP6 oKjaOntsGEpiqjOpd8AhWgWTKNAH+mavHz0wdzLmfyYBODGdt1xkGw0Ru/rklw+HFp WfB7+WF7VfKmHpI9U05k3JV3a+ux0pWuzsM5+dW2jwvyBSY2pUGy8wSK0teca73RvS do3YMpMCo9gskQ1Q1396CKy3dNjcQ5sBB/QGX9ViFT1GjOaVWaUCkANJQC3p5pKeyu 1N97/zUobhhRuLtX+GfehEyV8+/PXKfAUL/REdSX4QcAPGzgtAjEB6oQxn/TG/ZUol 5+9IFWSbtMbcA== From: Hector Martin To: Mark Brown , Rob Herring , Krzysztof Kozlowski Cc: Tudor Ambarus , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, Janne Grunau , Alyssa Rosenzweig , asahi@lists.linux.dev, linux-kernel@vger.kernel.org, Hector Martin Subject: [PATCH 3/5] spi: Use a 32-bit DT property for spi-cs-setup-delay-ns Date: Wed, 4 Jan 2023 18:36:29 +0900 Message-Id: <20230104093631.15611-4-marcan@marcan.st> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230104093631.15611-1-marcan@marcan.st> References: <20230104093631.15611-1-marcan@marcan.st> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754084316841074023?= X-GMAIL-MSGID: =?utf-8?q?1754084316841074023?= From: Janne Grunau 65us is not a reasonable maximum for this property, as some devices might need a much longer setup time (e.g. those driven by firmware on the other end). Plus, device tree property values are in 32-bit cells and smaller widths should not be used without good reason. Also move the logic to a helper function, since this will later be used to parse other CS delay properties too. Fixes: 33a2fde5f77b ("spi: Introduce spi-cs-setup-ns property") Signed-off-by: Janne Grunau Signed-off-by: Hector Martin --- drivers/spi/spi.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 15f174f4e056..370e4c85dc54 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2220,6 +2220,22 @@ void spi_flush_queue(struct spi_controller *ctlr) /*-------------------------------------------------------------------------*/ #if defined(CONFIG_OF) +static void of_spi_parse_dt_cs_delay(struct device_node *nc, + struct spi_delay *delay, const char *prop) +{ + u32 value; + + if (!of_property_read_u32(nc, prop, &value)) { + if (value > U16_MAX) { + delay->value = DIV_ROUND_UP(value, 1000); + delay->unit = SPI_DELAY_UNIT_USECS; + } else { + delay->value = value; + delay->unit = SPI_DELAY_UNIT_NSECS; + } + } +} + static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, struct device_node *nc) { @@ -2310,10 +2326,8 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, if (!of_property_read_u32(nc, "spi-max-frequency", &value)) spi->max_speed_hz = value; - if (!of_property_read_u16(nc, "spi-cs-setup-delay-ns", &cs_setup)) { - spi->cs_setup.value = cs_setup; - spi->cs_setup.unit = SPI_DELAY_UNIT_NSECS; - } + /* Device CS delays */ + of_spi_parse_dt_cs_delay(nc, &spi->cs_setup, "spi-cs-setup-delay-ns"); return 0; }