From patchwork Wed May 17 10:30:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boerge Struempfel X-Patchwork-Id: 13244603 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB5BCC77B7A for ; Wed, 17 May 2023 10:30:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230353AbjEQKaw (ORCPT ); Wed, 17 May 2023 06:30:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbjEQKar (ORCPT ); Wed, 17 May 2023 06:30:47 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6396F3C30; Wed, 17 May 2023 03:30:46 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-510bcd2d6b8so5350034a12.0; Wed, 17 May 2023 03:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684319445; x=1686911445; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6Prd49snigix6d9LdTUvvFg72tuSsEwzo0jpnKwNXRk=; b=HywP0zbgay4cg4mxORoYrmaGv4C/3y72Z0Pbsy8KBYJwwp5cgkaTqpICbcRrGdZwuy qj8i0Wq3tm6XhJYg8swdd0/XufEy17x2ensngDJA4KvCxxbNBmXCnfT8u2W4KWro1vI/ Sp6OpXQNdWPoe2Zgtss/aoRUeMpG5vx6NOpRJRGYln3CtmCPVI6vdaZXIixxUzRUex/x 4NiTJEeTo5Zjl6EQkYP+13eis6/9hUGvZ+tQJpdvoLmk7g2tUn0N6Zs3P486E6RJgxT4 vIEKPqPIGvqB+IKP1T1c2wgFKboPHGHMGIu8dL0DrEupc/ezhtB+xDni2QNotUXjCZWc sg3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684319445; x=1686911445; 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=6Prd49snigix6d9LdTUvvFg72tuSsEwzo0jpnKwNXRk=; b=mIEz10suotWPYTdPqyeqCBzUnXQ03EZN5DBlZtPtCfXPCSl666bkABH26ujs6LA8ii 31mUTYwwdDUratv6PdGwtzKS04rRXlzV0q2bNkpQRXxVJGYBDQ1Lf0ndYMnPVa6ViLfp B+VIgGwvFtjyArQUJqgUKMcX4xOvsM94bx7tgJ7odai42GzsiF99eLJZz8ei8+O9LFwc Cj6Ha8MYUeuAz/+8RLf9BR7XITcOVOVJmLvmU/j6X02a/13240tI0BT0kIUxkBirViuE 50WMBlAVhFCZx996c8DAe5abi+xonv+8X/uX5FufatBXjRR6xsNpg4zRaik/GlWXY/7i aqig== X-Gm-Message-State: AC+VfDwVF/PEySJuDHK+xlbOVeDHO0H/yHhgkUBq2EKixbpVmpoghO0n cwdnBGjkn3qZhQvX6Wnucmb7lWU6NyVepsvZ X-Google-Smtp-Source: ACHHUZ7jof1crDpMo1bbefAPH1Qr/iEut2c1Eu+Xb1yf+6IIXvEzXJHsU0MP7dWVWCB6HrLTFemQwA== X-Received: by 2002:a17:907:869f:b0:966:4669:7e8d with SMTP id qa31-20020a170907869f00b0096646697e8dmr1688616ejc.16.1684319444582; Wed, 17 May 2023 03:30:44 -0700 (PDT) Received: from wslxew193.fritz.box (p200300c78700c900d536eaeb32769819.dip0.t-ipconnect.de. [2003:c7:8700:c900:d536:eaeb:3276:9819]) by smtp.gmail.com with ESMTPSA id bu2-20020a170906a14200b0096654fdbe34sm12235758ejb.142.2023.05.17.03.30.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 03:30:44 -0700 (PDT) From: Boerge Struempfel Cc: boerge.struempfel@gmail.com, bstruempfel@ultratronik.de, andy.shevchenko@gmail.com, festevam@gmail.com, amit.kumar-mahapatra@amd.com, broonie@kernel.org, Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , NXP Linux Team , linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] spi: add SPI_MOSI_IDLE_LOW mode bit Date: Wed, 17 May 2023 12:30:05 +0200 Message-Id: <20230517103007.26287-1-boerge.struempfel@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Some spi controller switch the mosi line to high, whenever they are idle. This may not be desired in all use cases. For example neopixel leds can get confused and flicker due to misinterpreting the idle state. Therefore, we introduce a new spi-mode bit, with which the idle behaviour can be overwritten on a per device basis. Signed-off-by: Boerge Struempfel --- include/uapi/linux/spi/spi.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/spi/spi.h b/include/uapi/linux/spi/spi.h index 9d5f58059703..ca56e477d161 100644 --- a/include/uapi/linux/spi/spi.h +++ b/include/uapi/linux/spi/spi.h @@ -28,6 +28,7 @@ #define SPI_RX_OCTAL _BITUL(14) /* receive with 8 wires */ #define SPI_3WIRE_HIZ _BITUL(15) /* high impedance turnaround */ #define SPI_RX_CPHA_FLIP _BITUL(16) /* flip CPHA on Rx only xfer */ +#define SPI_MOSI_IDLE_LOW _BITUL(17) /* leave mosi line low when idle */ /* * All the bits defined above should be covered by SPI_MODE_USER_MASK. @@ -37,6 +38,6 @@ * These bits must not overlap. A static assert check should make sure of that. * If adding extra bits, make sure to increase the bit index below as well. */ -#define SPI_MODE_USER_MASK (_BITUL(17) - 1) +#define SPI_MODE_USER_MASK (_BITUL(18) - 1) #endif /* _UAPI_SPI_H */ From patchwork Wed May 17 10:30:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boerge Struempfel X-Patchwork-Id: 13244604 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30DAAC77B7F for ; Wed, 17 May 2023 10:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230370AbjEQKaz (ORCPT ); Wed, 17 May 2023 06:30:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230350AbjEQKat (ORCPT ); Wed, 17 May 2023 06:30:49 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7E463A80; Wed, 17 May 2023 03:30:48 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-96652cb7673so85955566b.0; Wed, 17 May 2023 03:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684319447; x=1686911447; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/uCyHD4ZZLXiJ+7a65CaGz07Y7p462n263W2+NsBdCE=; b=npscXZ4xsA8kGNXcRo6Dc8FfCtLGwcPyA6TDG+4cfzuGraEKUxFXIaUiO//pMHtB6p tbNg2/rQqTDP2NyACu+yJUyt5th/gs6xRCIamoh8Rb/VranATb4fftelphEaz3x7Kw6X gywGGBtdDjblsAh2Q2CvVSBu3Cmylq6NWUjHWL4PSiGt9tOJvB/wYY8Nw1riVyPkspRQ zIknzuf7IKgPu71EHFwETxvtSp9JgOvZIlle+WbS531CjZqq1W0J4CDdY+4F7kM53dg6 MIvBMWrPHCaVqLBnKUMENFDCbsWtTRY6D4BgukCJzQV4AC2A5LF68be/IGpzxGMS5Ram oSpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684319447; x=1686911447; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/uCyHD4ZZLXiJ+7a65CaGz07Y7p462n263W2+NsBdCE=; b=IHHAK8GcB2tv17TmskcsulXyihLxUgEO0Aee3+zY6lkgiNPIfCDoIDdU9oXeaQhDwY wLrRHWPnOh6x9eAQBw6ZQMTFrs50xHFDSnBxbJosBBotCCNAi/UiZgprSqK7iTZ/ssoT tUHPh86jD6bnAnDBK87gMXdTINJVkRsAEPw5hu94XSoKy5y+JJh/7c1aN9F4k25n/9Au uhXe94ij6fqQetpnACsNodSAP+o0XmTY4Pe0xNRR98IP5hzBQpOPqcoOokIF36AGV+Fe P814dlAcBkaqijad3o0cEuwDL1KaH3GrPXgaDO/D6s8qyraUyXklENN0KYTrY2jhHYIP rjcw== X-Gm-Message-State: AC+VfDyfVRmV1zYw22ZXxPTmkEGVr9/NpAwwDRBpwI4OFmLdjbzwEyRs TgRQTnJj2vYGyYmbr/Bt/Es= X-Google-Smtp-Source: ACHHUZ5RbegKV/3FRbn9juOyFXO+EqEEGjjbu2yJLnw3DmFv3T9rnK2d/2eJITEAKGeRmnoxQGB8WQ== X-Received: by 2002:a17:907:788:b0:96a:19d8:f082 with SMTP id xd8-20020a170907078800b0096a19d8f082mr27561932ejb.25.1684319446931; Wed, 17 May 2023 03:30:46 -0700 (PDT) Received: from wslxew193.fritz.box (p200300c78700c900d536eaeb32769819.dip0.t-ipconnect.de. [2003:c7:8700:c900:d536:eaeb:3276:9819]) by smtp.gmail.com with ESMTPSA id bu2-20020a170906a14200b0096654fdbe34sm12235758ejb.142.2023.05.17.03.30.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 03:30:46 -0700 (PDT) From: Boerge Struempfel Cc: boerge.struempfel@gmail.com, bstruempfel@ultratronik.de, andy.shevchenko@gmail.com, festevam@gmail.com, amit.kumar-mahapatra@amd.com, broonie@kernel.org, Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , NXP Linux Team , linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] spi: spi-imx: add support for SPI_MOSI_IDLE_LOW mode bit Date: Wed, 17 May 2023 12:30:06 +0200 Message-Id: <20230517103007.26287-2-boerge.struempfel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230517103007.26287-1-boerge.struempfel@gmail.com> References: <20230517103007.26287-1-boerge.struempfel@gmail.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org By default, the spi-imx controller pulls the mosi line high, whenever it is idle. This behaviour can be inverted per CS by setting the corresponding DATA_CTL bit in the config register of the controller. Also, since the controller mode-bits have to be touched anyways, the SPI_CPOL and SPI_CPHA are replaced by the combined SPI_MODE_X_MASK flag. Signed-off-by: Boerge Struempfel --- drivers/spi/spi-imx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index 34e5f81ec431..e5e55d66fecc 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -281,6 +281,7 @@ static bool spi_imx_can_dma(struct spi_controller *controller, struct spi_device #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_DATACTL(cs) (1 << ((cs & 3) + 16)) #define MX51_ECSPI_CONFIG_SCLKCTL(cs) (1 << ((cs & 3) + 20)) #define MX51_ECSPI_INT 0x10 @@ -573,6 +574,11 @@ static int mx51_ecspi_prepare_message(struct spi_imx_data *spi_imx, cfg &= ~MX51_ECSPI_CONFIG_SCLKCTL(spi_get_chipselect(spi, 0)); } + if (spi->mode & SPI_MOSI_IDLE_LOW) + cfg |= MX51_ECSPI_CONFIG_DATACTL(spi_get_chipselect(spi, 0)); + else + cfg &= ~MX51_ECSPI_CONFIG_DATACTL(spi_get_chipselect(spi, 0); + if (spi->mode & SPI_CS_HIGH) cfg |= MX51_ECSPI_CONFIG_SSBPOL(spi_get_chipselect(spi, 0)); else @@ -1743,7 +1749,8 @@ static int spi_imx_probe(struct platform_device *pdev) spi_imx->controller->prepare_message = spi_imx_prepare_message; spi_imx->controller->unprepare_message = spi_imx_unprepare_message; spi_imx->controller->slave_abort = spi_imx_slave_abort; - spi_imx->controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS; + spi_imx->controller->mode_bits = SPI_MODE_X_MASK | SPI_CS_HIGH | SPI_NO_CS | + SPI_MOSI_IDLE_LOW; if (is_imx35_cspi(spi_imx) || is_imx51_ecspi(spi_imx) || is_imx53_ecspi(spi_imx)) From patchwork Wed May 17 10:30:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boerge Struempfel X-Patchwork-Id: 13244605 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7BC6C7EE23 for ; Wed, 17 May 2023 10:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230358AbjEQKaz (ORCPT ); Wed, 17 May 2023 06:30:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbjEQKaw (ORCPT ); Wed, 17 May 2023 06:30:52 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D29FD3C1E; Wed, 17 May 2023 03:30:50 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-96aae59bbd6so102983866b.3; Wed, 17 May 2023 03:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684319449; x=1686911449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wwJ2jZY3dnjuT0EUFOXSV7VbKcctKtPzov6U1NhPAW4=; b=HQhZP+Wp86x1Uus2oyWNXBtJ8lRewWxzTwOG8b2mWcBX7OOl8oOdFulpCWXQrc9LtN mmbAl6v2a0AoUqnJS8LlAc2EpYdKgEOauo0KzYIX1+FlsTEbFhPLVLjIshf1pa/UKF5h eSrEzfFvYNTobR3SeJZbr/+dPi61VG0mXTvdAvRfwzABPx45ktvI9D2ZuEUrqhxRbW0x 7gsYkEjU/UTfWrQgIOn4FTwPXxf9XPz+7DGXtDPEURQ4RliWFeuLIJac1ePlzCKMfLys UXUm2vkyTKzjf/s+Qkh1/kURK07hytgRXq4OgWduc8BZumlatqJ780xhNAM4rb38Qg4J DonQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684319449; x=1686911449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wwJ2jZY3dnjuT0EUFOXSV7VbKcctKtPzov6U1NhPAW4=; b=CGslV2WmA7JBOhzfXGQKb4O+2PLzcd13SFUh8Fow0H6Y49hMK5+9hD9Ul8yIIL7ufD zsBjvG56WpZfmD05sZs1O3GwGQfH4JUjh9TMT7fkhDhsLYGYvCP38ZR1nM7osdHi9VU5 IuzJmdcoWftZo+KwAyCMMYxYwGx8e9Cg2buNFbepKH2pErnMr9h74I1OJ9WE2twWQpzC YLihmxdbBDVUn9yA49/4nKEL3QYby9HIO0hbr6e+6ySsd1skYf2KeOsPORIBCvw+vEaJ cAgJsXmVhHNUMhfpAwMotJG3vJ3HdO+Sy3Zo8BAbK/wpmz8rbuowEQQQRRh8Iga03pRD 7prA== X-Gm-Message-State: AC+VfDxq9auYZ4VhjU/2O6PkZ/u7vgwnl5qyXp0A0ysvqVdVknzoCvs5 YujaBwjw4/3sEzNF41FYvQqdHfUtpXb66D7+ X-Google-Smtp-Source: ACHHUZ5YhiHXMEbXtrEPTBW0NZ0azss5SdBr4P0QAtlTBJ2bVf1F4AAtT/ScsY8/Arw9N38vG/Rp3Q== X-Received: by 2002:a17:907:31c9:b0:94f:6627:22b5 with SMTP id xf9-20020a17090731c900b0094f662722b5mr35712100ejb.47.1684319448765; Wed, 17 May 2023 03:30:48 -0700 (PDT) Received: from wslxew193.fritz.box (p200300c78700c900d536eaeb32769819.dip0.t-ipconnect.de. [2003:c7:8700:c900:d536:eaeb:3276:9819]) by smtp.gmail.com with ESMTPSA id bu2-20020a170906a14200b0096654fdbe34sm12235758ejb.142.2023.05.17.03.30.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 03:30:48 -0700 (PDT) From: Boerge Struempfel Cc: boerge.struempfel@gmail.com, bstruempfel@ultratronik.de, andy.shevchenko@gmail.com, festevam@gmail.com, amit.kumar-mahapatra@amd.com, broonie@kernel.org, Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , NXP Linux Team , linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] spi: spidev: add SPI_MOSI_IDLE_LOW mode bit Date: Wed, 17 May 2023 12:30:07 +0200 Message-Id: <20230517103007.26287-3-boerge.struempfel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230517103007.26287-1-boerge.struempfel@gmail.com> References: <20230517103007.26287-1-boerge.struempfel@gmail.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Allow userspace to set SPI_MOSI_IDLE_LOW mode bit using the SPI_IOC_WR_MODE32 ioctl. Signed-off-by: Boerge Struempfel --- drivers/spi/spidev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index 39d94c850839..e50da54468ec 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c @@ -64,7 +64,7 @@ static_assert(N_SPI_MINORS > 0 && N_SPI_MINORS <= 256); | SPI_NO_CS | SPI_READY | SPI_TX_DUAL \ | SPI_TX_QUAD | SPI_TX_OCTAL | SPI_RX_DUAL \ | SPI_RX_QUAD | SPI_RX_OCTAL \ - | SPI_RX_CPHA_FLIP) + | SPI_RX_CPHA_FLIP | SPI_MOSI_IDLE_LOW) struct spidev_data { dev_t devt;