From patchwork Tue Apr 25 13:45:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 13223355 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 C848DC77B71 for ; Tue, 25 Apr 2023 13:46:31 +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=6UC0myAu3r6nrzNd8X9VKzPetgt1X7MFjdNg7tbIGAk=; b=22hmrswjmwLHmz 7xiJrcS4qW+a7S/b3qtpopAnIEwMC6SHygzP1xklm3rFO9eTkGuGWnbGxJoymeVRdJVe7MTPEN18m IweTD/sGUfCXeK+rOOvLx6LsPh0Z9M2WiAxW/4NEcP1UH3Qv3h3N8X+85JMtkte1NiUsDOdlpPEd/ dzGxmALDELMK5IZEcK4zrMVsNPAhaVzU6t1N0MdDk9h0JLCE8Doq39eaYE2F4P1R+aQDTqiaUMjQ5 u5sDnjUfcSh4hRi+s6Bf5BFLQ+tjU9x3k7dHZNXsNO24qiBHEA5dmyQtwDz0JHKqiNqqo+ynOTQ/E zN6unCyGJk5W6Irn59gg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1prIzG-001ILG-16; Tue, 25 Apr 2023 13:45:42 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1prIzC-001IIH-0T for linux-arm-kernel@lists.infradead.org; Tue, 25 Apr 2023 13:45:39 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-959a3e2dc72so477828366b.2 for ; Tue, 25 Apr 2023 06:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1682430331; x=1685022331; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vvGrNptYZRi7xQ7+JJCpqEOje87cPoMWG8Zptna2m4A=; b=EeB6xq/YH3AkAtURNR67x52RNeUgiCTEZRLPAYRxr+VY0h7Y9U6VLW8HybsEUzDA63 4h9ufPDC2R41r0CbWzGx+LZ7zNkFkFitOaXRQ6hRiAxjZLjBbKH2ELP5NNP5LGLDID0+ PjyrKifRV/6HStMYUN+ssbswKR8s1+YyFhhb0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682430331; x=1685022331; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vvGrNptYZRi7xQ7+JJCpqEOje87cPoMWG8Zptna2m4A=; b=NWm85O76NnZNpz3BSnw9G2H948QPT+yokNhPpsfvFbLgvomMcXvkKjI79MT8jX6YsR taT24JLXe+U8T665YCDn9sdE6LT7P6bICWEGcnKKcKkIePMQHBhzAXc+x4eYCEzxCWsJ xmXnccjsbKmhCaqExbm3ASAMmhrnWHmXh1+tQ6inUT8zlvOmRvagbTCuXVzsoZVjL1Xc +3w9rmEuZ3wugY/CopHfSsIZErBmUU579LNydUpOR+KoX73F4MNFp3GP6E2CduIO/Y/b d2n+5RJYf0MMJ03Jrm3nTivh7CXzF3LnORHIL8V267L1s/MjZ41QTBefE1mOIU95j2wS TVXQ== X-Gm-Message-State: AAQBX9chtMG1MmT1MIK7EUPDjUBfkXzjP5XlCiWyeShGCqlZoxc+5VOB aSv4tP9Z+gzbuj+U2bqTlU2+OA== X-Google-Smtp-Source: AKy350Ze96qfhykAyDc+5d3Rn5tKWwOIXWgOW7uoHjWHqUSYwA+lCrAyVmKAB2qo+RdC+u8ZAsE5dQ== X-Received: by 2002:a17:906:9bea:b0:94e:e082:15b9 with SMTP id de42-20020a1709069bea00b0094ee08215b9mr12207814ejc.77.1682430331219; Tue, 25 Apr 2023 06:45:31 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id f10-20020a170906048a00b0094eeea5c649sm6806822eja.114.2023.04.25.06.45.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Apr 2023 06:45:30 -0700 (PDT) From: Rasmus Villemoes 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: Marc Kleine-Budde , Rasmus Villemoes Subject: [PATCH 0/3] spi: spi-imx: fix use of more than four chip selects Date: Tue, 25 Apr 2023 15:45:24 +0200 Message-Id: <20230425134527.483607-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230425_064538_196989_47B44392 X-CRM114-Status: GOOD ( 14.58 ) 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 The current spi-imx driver completely fails when used with more than four (gpio) chip-selects, since the chip select number is used unconditionally as shift amount when updating the control and configuration registers, so the code ends up modifying random bits outside the intended fields. This fixes it by making use of the unused_native_cs variable filled in by the spi core, and use that as the "channel number" for all gpiod chip selects. In the presumably common case where all chip selects are gpios, this means we end up using channel 0 exclusively, so the optimization where the config register is left alone if it is unchanged (see 184434fcd617) might become less effective, if the workload consists of different slaves with differing spi modes being accessed one after the other. It would be nice if one could make use of the unused native chip selects in a round-robin manner, but for that the core would have to tell us not just unused_native_cs, but the whole ~native_cs_mask from spi_get_gpio_descs(). Maybe a simpler fix, if there is anything to fix, is to make the new mx51_ecspi_channel() do if (!spi->cs_gpiod || spi->controller->num_chipselect <= 4) Rasmus Villemoes (3): spi: spi-imx: use "controller" variable consistently in spi_imx_probe() spi: spi-imx: set max_native_cs for imx51/imx53/imx6 variants spi: spi-imx: fix use of more than four chipselects drivers/spi/spi-imx.c | 56 +++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 21 deletions(-)