Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp304855pxf; Thu, 8 Apr 2021 03:34:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIN384pdBwI3rDX6sMuNKkHiMH3/uYAVfaOeMh5sSxc1ZjgjBbRSFtp/PdNMdz37qaSO1l X-Received: by 2002:a17:90b:1643:: with SMTP id il3mr7836810pjb.2.1617878065995; Thu, 08 Apr 2021 03:34:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1617878065; cv=pass; d=google.com; s=arc-20160816; b=n+pxV7grUt6CKJBUp73ShHKKKMNC9eU+834VA9y002jGwT2iGjIYesBVJvLA4OzRi8 OrKbMpYEabzCHLMK5Gix81P4QE1AsASNfjP5qeOTvoJlUon9SCjwq5OGdg2FxfohJS7m 1EokTFaOsn1ZhYN/vNHfSI3z6ksliWQqkJY9fBI9+b571wvXILritJmkw0NU/E4/jYnH BFBjA9056r28QbOcZ/jJhRRwUNjJhUKKE1KLouGnsLJmOtxc/u64UE4ZxRsCctNFL5xR iUG2PULi99Mg1tHGHL63vdOUj9hK3bE2BXLQAnjCNOeh0dTXJ4117sAcLAha8jIvGKh1 aBMA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1BJrWZj1WJEGe6X2pToaizf35MLNkfa70ccZjnk8EoQ=; b=gSJ3XG30sLcUFAzJU/hVDP9mOMEyIFkU4ueW91hGKTHFOlTEzG7Y7X3VHjVhMUqOh/ L/rIsoRBvlv7v4v5Uk/EityrsZpyeO6yXRp4dmN4Ra1ARD16tj/LXJU/Vas39OR40qT8 vPGGx0rJdcQUEW/05VBM4g/SCifLcMnCAaJ/ef6Io3lLwGakcpBspWAPmArs1w9x9q8O UaWKZiGZRhEQmj7rANsMb9gMh6o2h8w7KKV2IsdtAG+6yihHeNtJz4B2iMSFo2WL6H7F MQ7Qee7CN55DXsdAn9lZGCFzl/wWJcNqQB1UOYePIekGKdj4Nd5mmxqNacVwV8mgrJpX I7Ww== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=Z3pqwx1A; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c23si20272412pfr.122.2021.04.08.03.34.13; Thu, 08 Apr 2021 03:34:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=Z3pqwx1A; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230322AbhDHKdr (ORCPT + 99 others); Thu, 8 Apr 2021 06:33:47 -0400 Received: from mail-vi1eur05on2068.outbound.protection.outlook.com ([40.107.21.68]:18746 "EHLO EUR05-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229751AbhDHKdg (ORCPT ); Thu, 8 Apr 2021 06:33:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BK98dBKr8UHF3y3a77i00RglbvXHF0pKe5PP3214ZOePtrnARJXNoZKGCE4uyGMkXUVdntVXivOHr+wFS/cmDBZ8EAjI/jOH9FVrmdQs/vYdxNpbhQgNV7HOMETvoNOhH2JozHcEujju6KzASOmLyoC4EwhluTDwUfKyfaFcki9Lq2iHgIhb95u5UnFxBZMmauatpJk0xo2v1KUbePanT4lic/kGXry/KAvaPUjuBSAQo5u+pynGz5i+diq+Fe9ClBhFxWZoASkUy5PYWyNIXBnjWDPD5QKiA9J8Mx2jaRvAMPyLoiN4u3AOZ27QYzZgg/GESoa8TjpjlLPP/mGUcA== 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=1BJrWZj1WJEGe6X2pToaizf35MLNkfa70ccZjnk8EoQ=; b=KQPppJxQ1yUKnQ9+UW4cZBIYVq14nI0iqB0Oy7utXTx71ynXt3bpdIJZYF8BIVpUMfMmS2KJWtAVWhQT212Ys49BOdrKz686S8r9Z1KrpwGJ5bsvhaESrOgvMczEavyiBJt2bIiwsFuCzoZLwPhp5tfpZWOuD93wIljTti4AENZPVeYxH66JidSzuJAyCz+pSfCyuMgBK2aDzqF27LVUJ6WXiLDBMcvYb//kkZgRNKXfpD6aEiSBm4VtNH8wgMAiDFGQ3pRd9yh/R1hKNVOqW7zkVMA4Ap4IogPRo2KiV8wcPMmV2KjIMx0jjGsVZNV3hm2KiUmzggsuiKPCwyyCUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1BJrWZj1WJEGe6X2pToaizf35MLNkfa70ccZjnk8EoQ=; b=Z3pqwx1AvLYEzvr7p11LpjM5XQff7fd7PC7cClgRj24nTKqBgam1eXBDu41IyRe9IjfoxGDyQ7jmFVUrhXIEJSg98bGAx5XNpJ3mHWj1XA1JOHjrLVPJLMccJMmcjd4ZmLlu1b0/epjjaIn4f5f9z6xUzJ4MXfbOAmv3eNa+5MQ= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB5623.eurprd04.prod.outlook.com (2603:10a6:20b:a9::13) by AM6PR04MB4982.eurprd04.prod.outlook.com (2603:10a6:20b:5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Thu, 8 Apr 2021 10:32:53 +0000 Received: from AM6PR04MB5623.eurprd04.prod.outlook.com ([fe80::5cd9:3da7:144f:36f9]) by AM6PR04MB5623.eurprd04.prod.outlook.com ([fe80::5cd9:3da7:144f:36f9%3]) with mapi id 15.20.3999.035; Thu, 8 Apr 2021 10:32:53 +0000 From: Clark Wang To: broonie@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com Cc: kernel@pengutronix.de, linux-imx@nxp.com, linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] spi: imx: add a check for speed_hz before calculating the clock Date: Thu, 8 Apr 2021 18:33:47 +0800 Message-Id: <20210408103347.244313-2-xiaoning.wang@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210408103347.244313-1-xiaoning.wang@nxp.com> References: <20210408103347.244313-1-xiaoning.wang@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [119.31.174.71] X-ClientProxiedBy: HK2PR0401CA0017.apcprd04.prod.outlook.com (2603:1096:202:2::27) To AM6PR04MB5623.eurprd04.prod.outlook.com (2603:10a6:20b:a9::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (119.31.174.71) by HK2PR0401CA0017.apcprd04.prod.outlook.com (2603:1096:202:2::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Thu, 8 Apr 2021 10:32:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e243e604-6060-4bef-ad51-08d8fa79aa53 X-MS-TrafficTypeDiagnostic: AM6PR04MB4982: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hww1p55nvlO+9MMtg0CLYXQkLRQE/ajTeGEz/vkFCnrqKtGzwiQoUU++joaGiuApymNI9kJo2clfDYksHOuHR40/xGOpwhND2Bod765fEcUXejsvybd6B/h/OUkD/qLZTvNYW9+JcIpnQk5Y336GW0RuY1PPAMZOY1R1SaEoz0vc+3inswKlLNOeApGixCYR9ZKVJHGuTEkRVlCs4CNkc+yso376KhT0BoIwH2f5269FPYohCSVN+iPTSzKkCGyliUvX3cEw1GH9W+E8CEFNX4E5f9G8/0J9Nio5m0+wtnD+rZtqfinvx7pZejt5MpryyCKTi3Zq7tdR3YTdKpM5zM4rSpQD9gDiWeAQvYrP99AR8b8mRVqzjivqYPh164h0y9EdtkDf9HYrhksw2NNUwQNhR3462L43tRduNrf3w72I3/M+tDTXX2svPWiyZeHLeXLPvPAl4xXM5MduG8/zgVAqQ8maS9iIyTu9tLcYwIm02sS9AsagG46lUL15w681JRy93kIjUzSdvez+JARBFHz5LMdVMsVe6ldR4gsgTtA5yU84wmuslP2sZQTA1ftsd2lGc8zxKg5XZQndYQiiZc/iNLWoDyjtj1sJD3s2zr3UR+S0gESWCnQN/w9eWFRobBJD/okVSJ7u/Eb/vQxt7knQUzcl3IENWiOqypmryAPwQ82pb8FMNJLtsmHHrKqHZY/pDLoL3RCTEaHvHQmN+ZShNGYUkPo/UGoNUkTe0Zo= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB5623.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(376002)(346002)(136003)(39850400004)(396003)(6486002)(66556008)(38350700001)(66476007)(16526019)(86362001)(956004)(2616005)(66946007)(4326008)(8676002)(36756003)(5660300002)(6506007)(38100700001)(52116002)(26005)(69590400012)(2906002)(8936002)(83380400001)(6512007)(316002)(6666004)(478600001)(1076003)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?9e31Z7QbjlSHA+AB3XgqQjmUmO1+1pO423e4YjQrxLY9MMs0Hd6xZzVNFBG8?= =?us-ascii?Q?WYYBxzMQiI2happ3Xsl9Cq0arL1q2pGigII0GBil3HhIa9XEpU/JqEhi2g/2?= =?us-ascii?Q?kQfVlH0TQ/USl2h886P9zEYWs5oN/M6ywuTKU3Fyh3WuRRWIhaaev/gauZnn?= =?us-ascii?Q?PAMzsgrzK8PXvN4vQV/xDJCTYEfO3T50TBVICOalORPqGyalpbkb+TFLSdDj?= =?us-ascii?Q?CpyhPONcrRuFRJ4v1qqniYXeJeukIen8f3SlwzwxTk9WhlQ9yeM2THCzvAUd?= =?us-ascii?Q?6P3XMv1eycsb4XBPVY4YB4yqqX+1dbROn9hU3buD6G7uDZQio7KcQ9HxSfRI?= =?us-ascii?Q?QLeFH1TYD81y/Q5Y1JM3nHIeIijhOLbCpMn+/ppFFRZnvuOa4q8LH17lV3pW?= =?us-ascii?Q?zy5hMsp6yGxwThmeAiuEsJTeEVAkIN5aoFUxLvU97JyrmrVCyIvQ02xQVEdi?= =?us-ascii?Q?f6IADbNrqHpPwHyjfJ/yg0/mO4zegD3IVlCYBvV3N1yv81WzaD9EBhchEJ19?= =?us-ascii?Q?Q9DO3ftlrdAI02H+0drCtPAeAQ8k9JQaZLzeUa8nS9q3AZ3do6dyjgwXhSrM?= =?us-ascii?Q?s7FB8dU+3Q2ISnVul21gZ8KNfqOLso86cXH3c/t+56uF/+UFf381iK0bPW5T?= =?us-ascii?Q?q6nnivQJ5nwtgFHSar48PTShpBj0T/PHMYMobNQi2Sg8EKn8asCMk/1HhUHO?= =?us-ascii?Q?eO43XK+SxY23xbJVMEdJP4Lo3cHXw9XQEOM6NyUGNmiEoA/mvKjHrQhC037T?= =?us-ascii?Q?+EQ1yNIFX70ja3fxNCeHqNoU5GyKtBhyfrKEG3/CphkCeq88Opt0JNcbXdF3?= =?us-ascii?Q?WzgH5dHqaWdhxSc3Kg4XrOqy8Tv6a5Qhl4IVh7BNJTjKM2uELUKie4UeKaRZ?= =?us-ascii?Q?/5EYcDvGlie6xiwBViQhWaypIe9p1UvSYisrnhIwM4T+WEo7qOGfG/nbWTU+?= =?us-ascii?Q?NxxqMRcx7cCxYlNSgNCGfUnY9Pbkf/RYeqIn6bD0xssG5wziVoVZDsUzEZ/F?= =?us-ascii?Q?izcT19W92wNwgAYOjAKxvItLi+ewgkh8TdquQy/8VjzCZcwfmwsVsr0spbDj?= =?us-ascii?Q?fZAi5FNNh+R+mM+m6ThktrelbIkSkWxsJcJKHiL7/oJvFUGrOYdxtoUVFLM3?= =?us-ascii?Q?hbWOtHijaq3L8+LYavi6fyYW+y5VB5onDLiiKfghaeTtUKrQ80moqJIcT5tW?= =?us-ascii?Q?z2Bug0/S2TxP75UDqMMFXjsnCJrbghUh9tZxbERgQ8BK/Jio+DQ1qjEy2+C4?= =?us-ascii?Q?o+W7zPQd217vOBJ/81vfCeuTnrPML7nQ/FNHiBs2V/wlMGuze+rVD4NEPvHg?= =?us-ascii?Q?Hmx8yeckpNenxXXipWp8iTWl?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e243e604-6060-4bef-ad51-08d8fa79aa53 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5623.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 10:32:53.1420 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fm4/KG4WalniptNq4x8pKhVJF7vQRpbtGdJwAGRyTT+VXgPmqKVFjDMzhhDxXfdDtIpYt8Z9AwAA84+1w7m2rg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4982 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When some drivers use spi to send data, spi_transfer->speed_hz is not assigned. If spidev->max_speed_hz is not assigned as well, it will cause an error in configuring the clock. Add a check for these two values before configuring the clock. An error will be returned when they are not assigned. Signed-off-by: Clark Wang --- drivers/spi/spi-imx.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index 24ba7ab1b05d..01f27b4d7384 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -66,8 +66,7 @@ struct spi_imx_data; struct spi_imx_devtype_data { void (*intctrl)(struct spi_imx_data *, int); int (*prepare_message)(struct spi_imx_data *, struct spi_message *); - int (*prepare_transfer)(struct spi_imx_data *, struct spi_device *, - struct spi_transfer *); + int (*prepare_transfer)(struct spi_imx_data *, struct spi_device *); void (*trigger)(struct spi_imx_data *); int (*rx_available)(struct spi_imx_data *); void (*reset)(struct spi_imx_data *); @@ -581,11 +580,10 @@ static int mx51_ecspi_prepare_message(struct spi_imx_data *spi_imx, } static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx, - struct spi_device *spi, - struct spi_transfer *t) + struct spi_device *spi) { u32 ctrl = readl(spi_imx->base + MX51_ECSPI_CTRL); - u32 clk = t->speed_hz, delay; + u32 clk, delay; /* Clear BL field and set the right value */ ctrl &= ~MX51_ECSPI_CTRL_BL_MASK; @@ -599,7 +597,7 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx, /* set clock speed */ ctrl &= ~(0xf << MX51_ECSPI_CTRL_POSTDIV_OFFSET | 0xf << MX51_ECSPI_CTRL_PREDIV_OFFSET); - ctrl |= mx51_ecspi_clkdiv(spi_imx, t->speed_hz, &clk); + ctrl |= mx51_ecspi_clkdiv(spi_imx, spi_imx->spi_bus_clk, &clk); spi_imx->spi_bus_clk = clk; if (spi_imx->usedma) @@ -711,13 +709,12 @@ static int mx31_prepare_message(struct spi_imx_data *spi_imx, } static int mx31_prepare_transfer(struct spi_imx_data *spi_imx, - struct spi_device *spi, - struct spi_transfer *t) + struct spi_device *spi) { unsigned int reg = MX31_CSPICTRL_ENABLE | MX31_CSPICTRL_MASTER; unsigned int clk; - reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, t->speed_hz, &clk) << + reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, spi_imx->spi_bus_clk, &clk) << MX31_CSPICTRL_DR_SHIFT; spi_imx->spi_bus_clk = clk; @@ -816,14 +813,13 @@ static int mx21_prepare_message(struct spi_imx_data *spi_imx, } static int mx21_prepare_transfer(struct spi_imx_data *spi_imx, - struct spi_device *spi, - struct spi_transfer *t) + struct spi_device *spi) { unsigned int reg = MX21_CSPICTRL_ENABLE | MX21_CSPICTRL_MASTER; unsigned int max = is_imx27_cspi(spi_imx) ? 16 : 18; unsigned int clk; - reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, t->speed_hz, max, &clk) + reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, spi_imx->spi_bus_clk, max, &clk) << MX21_CSPICTRL_DR_SHIFT; spi_imx->spi_bus_clk = clk; @@ -892,13 +888,12 @@ static int mx1_prepare_message(struct spi_imx_data *spi_imx, } static int mx1_prepare_transfer(struct spi_imx_data *spi_imx, - struct spi_device *spi, - struct spi_transfer *t) + struct spi_device *spi) { unsigned int reg = MX1_CSPICTRL_ENABLE | MX1_CSPICTRL_MASTER; unsigned int clk; - reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, t->speed_hz, &clk) << + reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, spi_imx->spi_bus_clk, &clk) << MX1_CSPICTRL_DR_SHIFT; spi_imx->spi_bus_clk = clk; @@ -1177,6 +1172,16 @@ static int spi_imx_setupxfer(struct spi_device *spi, if (!t) return 0; + if (!t->speed_hz) { + if (!spi->max_speed_hz) { + dev_err(&spi->dev, "no speed_hz provided!\n"); + return -EINVAL; + } + dev_dbg(&spi->dev, "using spi->max_speed_hz!\n"); + spi_imx->spi_bus_clk = spi->max_speed_hz; + } else + spi_imx->spi_bus_clk = t->speed_hz; + spi_imx->bits_per_word = t->bits_per_word; /* @@ -1218,7 +1223,7 @@ static int spi_imx_setupxfer(struct spi_device *spi, spi_imx->slave_burst = t->len; } - spi_imx->devtype_data->prepare_transfer(spi_imx, spi, t); + spi_imx->devtype_data->prepare_transfer(spi_imx, spi); return 0; } -- 2.25.1