From patchwork Sat Mar 18 22:21:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kevin Groeneveld X-Patchwork-Id: 13180014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52FA7C74A5B for ; Sat, 18 Mar 2023 22:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=do04QhegyB9q3W4LnX+xJkXvwkJoaaDVAdlFCqMdR0c=; b=lp/jIDntJgBVls 1oHwZmP350TQuPrOiRLtmKB1nqdUaPgDG7uZ7mjeqj2DHdlL7PDLalPSo3mZsdHXWA3t5eRi0TGiE GH3aVodOzIb2IliYtVPxltFIPt/5mNKCSkPAm9j7zVpgbnBSQdQ9//GRM72DUEUW4zgymppUhAE08 Jwa7P1rbDpyajPKekXGAEKY1nDaLkGvkmlGHToDXiTazyhq2Xw40zF3T4MDqiXHz2CKLHoAizpyal cJE/vgMZXU8Ts9QRdTgh/tqxyhuRQE6r8jHkqfowaiORMQsqFkZScSCoNFQoW5nTI+7vqWzZJHswq N4u66wbwOBiZPNzMGISA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pdfDY-005ULt-1z; Sat, 18 Mar 2023 22:40:04 +0000 Received: from mail-yt3can01on20704.outbound.protection.outlook.com ([2a01:111:f403:7053::704] helo=CAN01-YT3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pdfDS-005UKe-1l for linux-arm-kernel@lists.infradead.org; Sat, 18 Mar 2023 22:40:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ngfnS2JpwGIzWj9uRYZOIchWw/OC29UMz8B+zI+z0pWFInOKKwfyDydFHzSGVqtbktWfb5RPBLS+yFlqZ3YKjKgpt8jLBGQwyx5AiCwAi4DDTEPuh7zWknjxUHgLI9jVh1u4RpQuLp+F8Vsyl1gvYrdrre4Ph0cMqV+okVayBhZy4NgFqXuyMcWER7Wxk2d8OIvl951pDFpPId7+rlhhF4kPjKQWwk3cLrAlkmiw2a4/llh2DDXA4ZKFq5paaAh+Re7ucSyFKdtnXQmUV35fhATY0qPsIuuSSjlGbsUaUEIIx7r09h1RqnGdT785coSHHKadhggog0QbuXanySnNpg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JTN5HJxtJJIUp/ridiU6Q9SHJ8OSJ/mXZR9pfYDLZ/o=; b=admoI/f1IgCKhHF8d8E4O4V/5zvT9/igCCiCSYmezuzSFgHHTNY4epvDgUgxAvP2NrkrfRKjchQfI6p4UBE7ETJeZTituYmd0fShB3injyoggd1IiWTqKjyw+LdTjB8WIoWIBeLC+Bpb4JM/4lC3S/ckCu+D+eFfAegBNdH9itzLan1ikGdIMC05IT6gt+T4XJnN6loMNqIT0/KqwOA3oRDlmp7bAP72UQYJx3MKi4mQebVqp56dpVt7TOyX3d8ZVbQuhJQz7rhy1F44HsceUmslw9kKbuHr4PU6R2ERyGivwtJCBK3tqCDO5b4gv3lcRjU+E4b0QzxJZz7rwkJLjg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=lenbrook.com; dmarc=pass action=none header.from=lenbrook.com; dkim=pass header.d=lenbrook.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lenbrook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JTN5HJxtJJIUp/ridiU6Q9SHJ8OSJ/mXZR9pfYDLZ/o=; b=PuK5zLAbz5uvTyZD8BonKYO4Q396FAZRZTYJL1mWsk00o5NUHFvFYygKLA67UteRMDkjgNkGCaTTokw9ubP4nh+RcPz14jg0Tsdj/5TIrNfSiIj0PNMp4PYANwJTqeOQDvyX/FvXrEzAGyFpyARg0rW18TQVDjMMLKhZjxpgH/s= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=lenbrook.com; Received: from YT4PR01MB9670.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:e8::12) by YT2PR01MB8807.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:ba::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.36; Sat, 18 Mar 2023 22:24:23 +0000 Received: from YT4PR01MB9670.CANPRD01.PROD.OUTLOOK.COM ([fe80::2a76:b922:37e2:e1d2]) by YT4PR01MB9670.CANPRD01.PROD.OUTLOOK.COM ([fe80::2a76:b922:37e2:e1d2%3]) with mapi id 15.20.6178.036; Sat, 18 Mar 2023 22:24:23 +0000 From: Kevin Groeneveld To: Mark Brown , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Kevin Groeneveld Subject: [PATCH] spi: spi-imx: fix MX51_ECSPI_* macros when cs > 3 Date: Sat, 18 Mar 2023 18:21:32 -0400 Message-Id: <20230318222132.3373-1-kgroeneveld@lenbrook.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: YT4PR01CA0050.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:111::10) To YT4PR01MB9670.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:e8::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: YT4PR01MB9670:EE_|YT2PR01MB8807:EE_ X-MS-Office365-Filtering-Correlation-Id: e75526e7-2994-4a57-44f4-08db27ff869a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K36BTOPI+y0sdYRZ/FoSSBmMsDRizkiwAd1eXYIsWtFyoOQDIYLVBk9pVxiOKvYyZplsmSLi1XzTJmWNgsfrmNW8gZyhZzxszeLt9WQhA1LKlUnE4i2QwEkKKN14aRbcva+6fHkHDfHnUyE9PohguTuyBqkvNgbTL3swuTAtJkQFkaWUakub5Pat1aKpPyWhP3RSvFf8vh/PgkPRU/oJdS3pe9pmZtbY5Rlhwn8hVCb7tUIc2hpBocAjgfkr6L9o1fZnauGEBO2YQJ46746ygjq6gpN9NLqRF8UGg6Agm0mcQiNorZVC8Rao3fPaoO/O4iprLD9vQSEOisRAKqvCu/Vy6UUVh+NLuQ12IFOYN9OqLqFMNIb+YkK8NxcKRJIqkhLhhsqJ3kur6p7ufieugFXaTMIJA9qSZl+VJG1c+C8SU8HuuCEaNQuCuedpVdnEoDot00Cz94BYiuEUte7ick6+strw1yxpb9XuTs/+oPWk49GJ8hsg7jbunghHIJ5bcjvpRkVZIDokZhziiGPjdNkcthkEuQTezi+cMDzBxbMFT5qckeyGqsouzsnpDbnmpbXh97sd2spQm1FqrySMmvUT524pLQmAXK1ZoegKLYOerMl3j9gJ6Ei72Dk+ejQk3OZ8pvs61sfPD9BfL7lSpQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:YT4PR01MB9670.CANPRD01.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230025)(136003)(346002)(376002)(39840400004)(366004)(396003)(451199018)(2616005)(6666004)(107886003)(186003)(6506007)(1076003)(26005)(6512007)(6486002)(316002)(110136005)(4326008)(66946007)(66556008)(66476007)(478600001)(83380400001)(41300700001)(8936002)(5660300002)(2906002)(8676002)(38100700002)(86362001)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?9PMWFhtVD+qUovv6h0rmBWW3JUjJ?= =?utf-8?q?gjsl5zxVMAtSw3Kicm07MS1Qf7iacnNH2EsDbxLYHDY64uzCxfEOwaHe24Nbb679I?= =?utf-8?q?VOz0HMNRPzbc9Tx8XzuDiU+RHjBbAzicebAybRI72PD918TiwlztRAaPEL6Jq1nHC?= =?utf-8?q?4L7OxXCMXRBJ3xvT1kmABSR0IdVitIpckdC9qV54E8wKc0+pnds+Jt6lQJPfB1sVl?= =?utf-8?q?kSTJ5HvGY5ooQxGhBnzr8XHeRvKkNj7oqTMt9jbXLQ2d2JdrYKISWiMV9TqB4CHoW?= =?utf-8?q?KB0rY3SruiWM9/U7txAdXLa4nCQ35Mv97Sbhl+Fmkpvng/1nvb40KZ0k6eakQKqtY?= =?utf-8?q?8xoF0UDKqT5ON9KLf/NaEHY5gDA5++uNzRGmKk2L1ugH8hX5pOlCr+RIyESpIyS/M?= =?utf-8?q?uRH8G2DzaR7r8HjtJy1n6WRjZwyHU9s7ugJLzs/AS0EwpgoVk2nalQwTEdgVJ7zkQ?= =?utf-8?q?B/145pHKd6NAHpPR/FVmxYgGScQHZMdlRSTZtVrV9+ikt7hKfvCwLady+xZSDaI2S?= =?utf-8?q?fhe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utf-8?q?q+T/hd3YeJATMr+PcwRhX1Y6g4kCp31HD+42/GEEv0mUw/s0QgIK8mMUS2lEgztKb?= =?utf-8?q?U+kfyv/n/Zmzcqk9PXtgg6t9NNRwWR5gcTtcSTXjJGk9sJLZEMkSVfDO6Fv4l192o?= =?utf-8?q?T2d8vsEOIn1DaILGq/JI0zFLAJQnn2zFHQ=3D=3D?= X-OriginatorOrg: lenbrook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e75526e7-2994-4a57-44f4-08db27ff869a X-MS-Exchange-CrossTenant-AuthSource: YT4PR01MB9670.CANPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2023 22:24:23.2563 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3089fb55-f9f3-4ac8-ba44-52ac0e467cb6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: f1HQouJl0/clkvMF7u9kdZps4DqhrhEmpYnB2LFPl2q4VnsTKh/DK2hYBl2r/7IfDay3IsF+8Hrh3YL57cU7EtUEsOqsLedQTRIXO2qtb+c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: YT2PR01MB8807 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230318_153958_804394_5B5B2E9F X-CRM114-Status: GOOD ( 12.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When using gpio based chip select the cs value can go outside the range 0 – 3. The various MX51_ECSPI_* macros did not take this into consideration resulting in possible corruption of the configuration. For example for any cs value over 3 the SCLKPHA bits would not be set and other values in the register possibly corrupted. One way to fix this is to just mask the cs bits to 2 bits. This still allows all 4 native chip selects to work as well as gpio chip selects (which can use any of the 4 chip select configurations). Signed-off-by: Kevin Groeneveld --- drivers/spi/spi-imx.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index e4ccd0c329d0..c61c7ac4c70c 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -252,6 +252,18 @@ static bool spi_imx_can_dma(struct spi_controller *controller, struct spi_device return true; } +/* + * Note the number of natively supported chip selects for MX51 is 4. Some + * devices may have less actual SS pins but the register map supports 4. When + * using gpio chip selects the cs values passed into the macros below can go + * outside the range 0 - 3. We therefore need to limit the cs value to avoid + * corrupting bits outside the allocated locations. + * + * The simplest way to do this is to just mask the cs bits to 2 bits. This + * still allows all 4 native chip selects to work as well as gpio chip selects + * (which can use any of the 4 chip select configurations). + */ + #define MX51_ECSPI_CTRL 0x08 #define MX51_ECSPI_CTRL_ENABLE (1 << 0) #define MX51_ECSPI_CTRL_XCH (1 << 2) @@ -260,16 +272,16 @@ static bool spi_imx_can_dma(struct spi_controller *controller, struct spi_device #define MX51_ECSPI_CTRL_DRCTL(drctl) ((drctl) << 16) #define MX51_ECSPI_CTRL_POSTDIV_OFFSET 8 #define MX51_ECSPI_CTRL_PREDIV_OFFSET 12 -#define MX51_ECSPI_CTRL_CS(cs) ((cs) << 18) +#define MX51_ECSPI_CTRL_CS(cs) ((cs & 3) << 18) #define MX51_ECSPI_CTRL_BL_OFFSET 20 #define MX51_ECSPI_CTRL_BL_MASK (0xfff << 20) #define MX51_ECSPI_CONFIG 0x0c -#define MX51_ECSPI_CONFIG_SCLKPHA(cs) (1 << ((cs) + 0)) -#define MX51_ECSPI_CONFIG_SCLKPOL(cs) (1 << ((cs) + 4)) -#define MX51_ECSPI_CONFIG_SBBCTRL(cs) (1 << ((cs) + 8)) -#define MX51_ECSPI_CONFIG_SSBPOL(cs) (1 << ((cs) + 12)) -#define MX51_ECSPI_CONFIG_SCLKCTL(cs) (1 << ((cs) + 20)) +#define MX51_ECSPI_CONFIG_SCLKPHA(cs) (1 << ((cs & 3) + 0)) +#define MX51_ECSPI_CONFIG_SCLKPOL(cs) (1 << ((cs & 3) + 4)) +#define MX51_ECSPI_CONFIG_SBBCTRL(cs) (1 << ((cs & 3) + 8)) +#define MX51_ECSPI_CONFIG_SSBPOL(cs) (1 << ((cs & 3) + 12)) +#define MX51_ECSPI_CONFIG_SCLKCTL(cs) (1 << ((cs & 3) + 20)) #define MX51_ECSPI_INT 0x10 #define MX51_ECSPI_INT_TEEN (1 << 0)