From nobody Sun Sep 22 07:47:27 2024 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 2DB9AC4167E for ; Mon, 7 Mar 2022 06:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235700AbiCGGxq (ORCPT ); Mon, 7 Mar 2022 01:53:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231913AbiCGGxi (ORCPT ); Mon, 7 Mar 2022 01:53:38 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5233B1CFD8; Sun, 6 Mar 2022 22:52:40 -0800 (PST) X-UUID: 57cd627a09614baf91696e6a4d70c9fc-20220307 X-UUID: 57cd627a09614baf91696e6a4d70c9fc-20220307 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1803586342; Mon, 07 Mar 2022 14:52:35 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Mon, 7 Mar 2022 14:52:34 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 7 Mar 2022 14:52:33 +0800 From: Leilk Liu To: Mark Brown CC: Rob Herring , Matthias Brugger , , , , , , Leilk Liu Subject: [PATCH V3 1/7] spi: mediatek: support tick_delay without enhance_timing Date: Mon, 7 Mar 2022 14:52:24 +0800 Message-ID: <20220307065230.12655-2-leilk.liu@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307065230.12655-1-leilk.liu@mediatek.com> References: <20220307065230.12655-1-leilk.liu@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" this patch support tick_delay bit[31:30] without enhance_timing feature. Fixes: f84d866ab43f("spi: mediatek: add tick_delay support") Signed-off-by: Leilk Liu Reviewed-by: AngeloGioacchino Del Regno --- drivers/spi/spi-mt65xx.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c index bbfeb8046c17..3fd89548ec3c 100644 --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c @@ -43,8 +43,11 @@ #define SPI_CFG1_PACKET_LOOP_OFFSET 8 #define SPI_CFG1_PACKET_LENGTH_OFFSET 16 #define SPI_CFG1_GET_TICK_DLY_OFFSET 29 +#define SPI_CFG1_GET_TICK_DLY_OFFSET_V1 30 =20 #define SPI_CFG1_GET_TICK_DLY_MASK 0xe0000000 +#define SPI_CFG1_GET_TICK_DLY_MASK_V1 0xc0000000 + #define SPI_CFG1_CS_IDLE_MASK 0xff #define SPI_CFG1_PACKET_LOOP_MASK 0xff00 #define SPI_CFG1_PACKET_LENGTH_MASK 0x3ff0000 @@ -346,9 +349,15 @@ static int mtk_spi_prepare_message(struct spi_master *= master, =20 /* tick delay */ reg_val =3D readl(mdata->base + SPI_CFG1_REG); - reg_val &=3D ~SPI_CFG1_GET_TICK_DLY_MASK; - reg_val |=3D ((chip_config->tick_delay & 0x7) - << SPI_CFG1_GET_TICK_DLY_OFFSET); + if (mdata->dev_comp->enhance_timing) { + reg_val &=3D ~SPI_CFG1_GET_TICK_DLY_MASK; + reg_val |=3D ((chip_config->tick_delay & 0x7) + << SPI_CFG1_GET_TICK_DLY_OFFSET); + } else { + reg_val &=3D ~SPI_CFG1_GET_TICK_DLY_MASK_V1; + reg_val |=3D ((chip_config->tick_delay & 0x3) + << SPI_CFG1_GET_TICK_DLY_OFFSET_V1); + } writel(reg_val, mdata->base + SPI_CFG1_REG); =20 /* set hw cs timing */ --=20 2.25.1 From nobody Sun Sep 22 07:47:27 2024 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 7B763C433F5 for ; Mon, 7 Mar 2022 06:53:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235769AbiCGGyC (ORCPT ); Mon, 7 Mar 2022 01:54:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234283AbiCGGxj (ORCPT ); Mon, 7 Mar 2022 01:53:39 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 334971EC43; Sun, 6 Mar 2022 22:52:43 -0800 (PST) X-UUID: c2e474c2e3e9438696bc84b874ac7f01-20220307 X-UUID: c2e474c2e3e9438696bc84b874ac7f01-20220307 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1279457259; Mon, 07 Mar 2022 14:52:36 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Mon, 7 Mar 2022 14:52:35 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 7 Mar 2022 14:52:34 +0800 From: Leilk Liu To: Mark Brown CC: Rob Herring , Matthias Brugger , , , , , , Leilk Liu , Rob Herring Subject: [PATCH V3 2/7] dt-bindings: spi: Add compatible for MT7986 with single mode Date: Mon, 7 Mar 2022 14:52:25 +0800 Message-ID: <20220307065230.12655-3-leilk.liu@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307065230.12655-1-leilk.liu@mediatek.com> References: <20220307065230.12655-1-leilk.liu@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch adds dt-binding documentation for MT7986 with single mode. Signed-off-by: Leilk Liu Acked-by: Rob Herring --- Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml= b/Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml index bfa44acb1bdd..48024b98408a 100644 --- a/Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml +++ b/Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml @@ -41,6 +41,7 @@ properties: - mediatek,mt8135-spi - mediatek,mt8173-spi - mediatek,mt8183-spi + - mediatek,mt7986-spi-single =20 reg: maxItems: 1 --=20 2.25.1 From nobody Sun Sep 22 07:47:27 2024 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 38F33C43219 for ; Mon, 7 Mar 2022 06:52:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235714AbiCGGxs (ORCPT ); Mon, 7 Mar 2022 01:53:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234607AbiCGGxj (ORCPT ); Mon, 7 Mar 2022 01:53:39 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 711421EC49; Sun, 6 Mar 2022 22:52:43 -0800 (PST) X-UUID: ad1e5f4cd3504cdaa5f1eaa4b7304580-20220307 X-UUID: ad1e5f4cd3504cdaa5f1eaa4b7304580-20220307 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 49291644; Mon, 07 Mar 2022 14:52:37 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Mon, 7 Mar 2022 14:52:36 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 7 Mar 2022 14:52:35 +0800 From: Leilk Liu To: Mark Brown CC: Rob Herring , Matthias Brugger , , , , , , Leilk Liu Subject: [PATCH V3 3/7] spi: mediatek: add MT7986 single mode design support Date: Mon, 7 Mar 2022 14:52:26 +0800 Message-ID: <20220307065230.12655-4-leilk.liu@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307065230.12655-1-leilk.liu@mediatek.com> References: <20220307065230.12655-1-leilk.liu@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" this patch add the support of MT7986 single mode design. Signed-off-by: Leilk Liu --- drivers/spi/spi-mt65xx.c | 102 +++++++++++++++++++++++++++++++++------ 1 file changed, 87 insertions(+), 15 deletions(-) diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c index 3fd89548ec3c..aa282cace7db 100644 --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c @@ -31,6 +31,7 @@ #define SPI_CFG2_REG 0x0028 #define SPI_TX_SRC_REG_64 0x002c #define SPI_RX_DST_REG_64 0x0030 +#define SPI_CFG3_IPM_REG 0x0040 =20 #define SPI_CFG0_SCK_HIGH_OFFSET 0 #define SPI_CFG0_SCK_LOW_OFFSET 8 @@ -51,6 +52,7 @@ #define SPI_CFG1_CS_IDLE_MASK 0xff #define SPI_CFG1_PACKET_LOOP_MASK 0xff00 #define SPI_CFG1_PACKET_LENGTH_MASK 0x3ff0000 +#define SPI_CFG1_IPM_PACKET_LENGTH_MASK GENMASK(31, 16) #define SPI_CFG2_SCK_HIGH_OFFSET 0 #define SPI_CFG2_SCK_LOW_OFFSET 16 =20 @@ -71,7 +73,13 @@ #define SPI_CMD_TX_ENDIAN BIT(15) #define SPI_CMD_FINISH_IE BIT(16) #define SPI_CMD_PAUSE_IE BIT(17) +#define SPI_CMD_IPM_NONIDLE_MODE BIT(19) +#define SPI_CMD_IPM_SPIM_LOOP BIT(21) +#define SPI_CMD_IPM_GET_TICKDLY_OFFSET 22 =20 +#define SPI_CMD_IPM_GET_TICKDLY_MASK GENMASK(24, 22) +#define SPI_CFG3_IPM_HALF_DUPLEX_DIR BIT(2) +#define SPI_CFG3_IPM_HALF_DUPLEX_EN BIT(3) #define MT8173_SPI_MAX_PAD_SEL 3 =20 #define MTK_SPI_PAUSE_INT_STATUS 0x2 @@ -81,6 +89,7 @@ =20 #define MTK_SPI_MAX_FIFO_SIZE 32U #define MTK_SPI_PACKET_SIZE 1024 +#define MTK_SPI_IPM_PACKET_SIZE SZ_64K #define MTK_SPI_32BITS_MASK (0xffffffff) =20 #define DMA_ADDR_EXT_BITS (36) @@ -96,6 +105,9 @@ struct mtk_spi_compatible { bool dma_ext; /* some IC no need unprepare SPI clk */ bool no_need_unprepare; + /* IPM design improve some single mode features */ + bool ipm_design; + }; =20 struct mtk_spi { @@ -119,6 +131,12 @@ static const struct mtk_spi_compatible mt2712_compat = =3D { .must_tx =3D true, }; =20 +static const struct mtk_spi_compatible mt7986_compat_single =3D { + .enhance_timing =3D true, + .dma_ext =3D true, + .ipm_design =3D true, +}; + static const struct mtk_spi_compatible mt6765_compat =3D { .need_pad_sel =3D true, .must_tx =3D true, @@ -160,6 +178,9 @@ static const struct mtk_chip_config mtk_default_chip_in= fo =3D { }; =20 static const struct of_device_id mtk_spi_of_match[] =3D { + { .compatible =3D "mediatek,mt7986-spi-single", + .data =3D (void *)&mt7986_compat_single, + }, { .compatible =3D "mediatek,mt2701-spi", .data =3D (void *)&mtk_common_compat, }, @@ -278,12 +299,11 @@ static int mtk_spi_set_hw_cs_timing(struct spi_device= *spi) return 0; } =20 -static int mtk_spi_prepare_message(struct spi_master *master, - struct spi_message *msg) +static int mtk_spi_hw_init(struct spi_master *master, + struct spi_device *spi) { u16 cpha, cpol; u32 reg_val; - struct spi_device *spi =3D msg->spi; struct mtk_chip_config *chip_config =3D spi->controller_data; struct mtk_spi *mdata =3D spi_master_get_devdata(master); =20 @@ -291,6 +311,15 @@ static int mtk_spi_prepare_message(struct spi_master *= master, cpol =3D spi->mode & SPI_CPOL ? 1 : 0; =20 reg_val =3D readl(mdata->base + SPI_CMD_REG); + if (mdata->dev_comp->ipm_design) { + /* SPI transfer without idle time until packet length done */ + reg_val |=3D SPI_CMD_IPM_NONIDLE_MODE; + if (spi->mode & SPI_LOOP) + reg_val |=3D SPI_CMD_IPM_SPIM_LOOP; + else + reg_val &=3D ~SPI_CMD_IPM_SPIM_LOOP; + } + if (cpha) reg_val |=3D SPI_CMD_CPHA; else @@ -348,23 +377,39 @@ static int mtk_spi_prepare_message(struct spi_master = *master, mdata->base + SPI_PAD_SEL_REG); =20 /* tick delay */ - reg_val =3D readl(mdata->base + SPI_CFG1_REG); if (mdata->dev_comp->enhance_timing) { - reg_val &=3D ~SPI_CFG1_GET_TICK_DLY_MASK; - reg_val |=3D ((chip_config->tick_delay & 0x7) - << SPI_CFG1_GET_TICK_DLY_OFFSET); + if (mdata->dev_comp->ipm_design) { + reg_val =3D readl(mdata->base + SPI_CMD_REG); + reg_val &=3D ~SPI_CMD_IPM_GET_TICKDLY_MASK; + reg_val |=3D ((chip_config->tick_delay & 0x7) + << SPI_CMD_IPM_GET_TICKDLY_OFFSET); + writel(reg_val, mdata->base + SPI_CMD_REG); + } else { + reg_val =3D readl(mdata->base + SPI_CFG1_REG); + reg_val &=3D ~SPI_CFG1_GET_TICK_DLY_MASK; + reg_val |=3D ((chip_config->tick_delay & 0x7) + << SPI_CFG1_GET_TICK_DLY_OFFSET); + writel(reg_val, mdata->base + SPI_CFG1_REG); + } } else { + reg_val =3D readl(mdata->base + SPI_CFG1_REG); reg_val &=3D ~SPI_CFG1_GET_TICK_DLY_MASK_V1; reg_val |=3D ((chip_config->tick_delay & 0x3) << SPI_CFG1_GET_TICK_DLY_OFFSET_V1); + writel(reg_val, mdata->base + SPI_CFG1_REG); } - writel(reg_val, mdata->base + SPI_CFG1_REG); =20 /* set hw cs timing */ mtk_spi_set_hw_cs_timing(spi); return 0; } =20 +static int mtk_spi_prepare_message(struct spi_master *master, + struct spi_message *msg) +{ + return mtk_spi_hw_init(master, msg->spi); +} + static void mtk_spi_set_cs(struct spi_device *spi, bool enable) { u32 reg_val; @@ -386,13 +431,13 @@ static void mtk_spi_set_cs(struct spi_device *spi, bo= ol enable) } =20 static void mtk_spi_prepare_transfer(struct spi_master *master, - struct spi_transfer *xfer) + u32 speed_hz) { u32 div, sck_time, reg_val; struct mtk_spi *mdata =3D spi_master_get_devdata(master); =20 - if (xfer->speed_hz < mdata->spi_clk_hz / 2) - div =3D DIV_ROUND_UP(mdata->spi_clk_hz, xfer->speed_hz); + if (speed_hz < mdata->spi_clk_hz / 2) + div =3D DIV_ROUND_UP(mdata->spi_clk_hz, speed_hz); else div =3D 1; =20 @@ -423,12 +468,24 @@ static void mtk_spi_setup_packet(struct spi_master *m= aster) u32 packet_size, packet_loop, reg_val; struct mtk_spi *mdata =3D spi_master_get_devdata(master); =20 - packet_size =3D min_t(u32, mdata->xfer_len, MTK_SPI_PACKET_SIZE); + if (mdata->dev_comp->ipm_design) + packet_size =3D min_t(u32, + mdata->xfer_len, + MTK_SPI_IPM_PACKET_SIZE); + else + packet_size =3D min_t(u32, + mdata->xfer_len, + MTK_SPI_PACKET_SIZE); + packet_loop =3D mdata->xfer_len / packet_size; =20 reg_val =3D readl(mdata->base + SPI_CFG1_REG); - reg_val &=3D ~(SPI_CFG1_PACKET_LENGTH_MASK | SPI_CFG1_PACKET_LOOP_MASK); + if (mdata->dev_comp->ipm_design) + reg_val &=3D ~SPI_CFG1_IPM_PACKET_LENGTH_MASK; + else + reg_val &=3D ~SPI_CFG1_PACKET_LENGTH_MASK; reg_val |=3D (packet_size - 1) << SPI_CFG1_PACKET_LENGTH_OFFSET; + reg_val &=3D ~SPI_CFG1_PACKET_LOOP_MASK; reg_val |=3D (packet_loop - 1) << SPI_CFG1_PACKET_LOOP_OFFSET; writel(reg_val, mdata->base + SPI_CFG1_REG); } @@ -523,7 +580,7 @@ static int mtk_spi_fifo_transfer(struct spi_master *mas= ter, mdata->cur_transfer =3D xfer; mdata->xfer_len =3D min(MTK_SPI_MAX_FIFO_SIZE, xfer->len); mdata->num_xfered =3D 0; - mtk_spi_prepare_transfer(master, xfer); + mtk_spi_prepare_transfer(master, xfer->speed_hz); mtk_spi_setup_packet(master); =20 if (xfer->tx_buf) { @@ -556,7 +613,7 @@ static int mtk_spi_dma_transfer(struct spi_master *mast= er, mdata->cur_transfer =3D xfer; mdata->num_xfered =3D 0; =20 - mtk_spi_prepare_transfer(master, xfer); + mtk_spi_prepare_transfer(master, xfer->speed_hz); =20 cmd =3D readl(mdata->base + SPI_CMD_REG); if (xfer->tx_buf) @@ -591,6 +648,19 @@ static int mtk_spi_transfer_one(struct spi_master *mas= ter, struct spi_device *spi, struct spi_transfer *xfer) { + struct mtk_spi *mdata =3D spi_master_get_devdata(spi->master); + u32 reg_val =3D 0; + + /* prepare xfer direction and duplex mode */ + if (mdata->dev_comp->ipm_design) { + if (!xfer->tx_buf || !xfer->rx_buf) { + reg_val |=3D SPI_CFG3_IPM_HALF_DUPLEX_EN; + if (xfer->rx_buf) + reg_val |=3D SPI_CFG3_IPM_HALF_DUPLEX_DIR; + } + writel(reg_val, mdata->base + SPI_CFG3_IPM_REG); + } + if (master->can_dma(master, spi, xfer)) return mtk_spi_dma_transfer(master, spi, xfer); else @@ -757,6 +827,8 @@ static int mtk_spi_probe(struct platform_device *pdev) =20 if (mdata->dev_comp->must_tx) master->flags =3D SPI_MASTER_MUST_TX; + if (mdata->dev_comp->ipm_design) + master->mode_bits |=3D SPI_LOOP; =20 if (mdata->dev_comp->need_pad_sel) { mdata->pad_num =3D of_property_count_u32_elems( --=20 2.25.1 From nobody Sun Sep 22 07:47:27 2024 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 2127AC433FE for ; Mon, 7 Mar 2022 06:53:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235751AbiCGGx6 (ORCPT ); Mon, 7 Mar 2022 01:53:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233987AbiCGGxj (ORCPT ); Mon, 7 Mar 2022 01:53:39 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F40A1DA78; Sun, 6 Mar 2022 22:52:42 -0800 (PST) X-UUID: d6682034af3743d3a726913b1466981a-20220307 X-UUID: d6682034af3743d3a726913b1466981a-20220307 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 525842004; Mon, 07 Mar 2022 14:52:37 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Mon, 7 Mar 2022 14:52:37 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 7 Mar 2022 14:52:36 +0800 From: Leilk Liu To: Mark Brown CC: Rob Herring , Matthias Brugger , , , , , , Leilk Liu Subject: [PATCH V3 4/7] dt-bindings: spi: Add compatible for MT7986 with quad mode Date: Mon, 7 Mar 2022 14:52:27 +0800 Message-ID: <20220307065230.12655-5-leilk.liu@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307065230.12655-1-leilk.liu@mediatek.com> References: <20220307065230.12655-1-leilk.liu@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch adds dt-binding documentation for MT7986 with quad mode. Signed-off-by: Leilk Liu --- Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml= b/Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml index 48024b98408a..a8a15a9a6c46 100644 --- a/Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml +++ b/Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml @@ -42,6 +42,7 @@ properties: - mediatek,mt8173-spi - mediatek,mt8183-spi - mediatek,mt7986-spi-single + - mediatek,mt7986-spi-quad =20 reg: maxItems: 1 --=20 2.25.1 From nobody Sun Sep 22 07:47:27 2024 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 8BD97C433EF for ; Mon, 7 Mar 2022 06:52:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235720AbiCGGxu (ORCPT ); Mon, 7 Mar 2022 01:53:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234644AbiCGGxk (ORCPT ); Mon, 7 Mar 2022 01:53:40 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 318F41EED0; Sun, 6 Mar 2022 22:52:44 -0800 (PST) X-UUID: a7d4059b4a134edb8c03e888465b733e-20220307 X-UUID: a7d4059b4a134edb8c03e888465b733e-20220307 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1567374644; Mon, 07 Mar 2022 14:52:38 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 7 Mar 2022 14:52:37 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 7 Mar 2022 14:52:37 +0800 From: Leilk Liu To: Mark Brown CC: Rob Herring , Matthias Brugger , , , , , , Leilk Liu Subject: [PATCH V3 5/7] spi: mediatek: add spi memory support for MT7986 Date: Mon, 7 Mar 2022 14:52:28 +0800 Message-ID: <20220307065230.12655-6-leilk.liu@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307065230.12655-1-leilk.liu@mediatek.com> References: <20220307065230.12655-1-leilk.liu@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" this patch add the support of spi-mem for MT7986. Signed-off-by: Leilk Liu --- drivers/spi/spi-mt65xx.c | 318 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 317 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c index aa282cace7db..2f09b9d7a998 100644 --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c @@ -17,6 +17,7 @@ #include #include #include +#include #include =20 #define SPI_CFG0_REG 0x0000 @@ -78,8 +79,21 @@ #define SPI_CMD_IPM_GET_TICKDLY_OFFSET 22 =20 #define SPI_CMD_IPM_GET_TICKDLY_MASK GENMASK(24, 22) + +#define PIN_MODE_CFG(x) ((x) / 2) + +#define SPI_CFG3_IPM_PIN_MODE_OFFSET 0 #define SPI_CFG3_IPM_HALF_DUPLEX_DIR BIT(2) #define SPI_CFG3_IPM_HALF_DUPLEX_EN BIT(3) +#define SPI_CFG3_IPM_XMODE_EN BIT(4) +#define SPI_CFG3_IPM_NODATA_FLAG BIT(5) +#define SPI_CFG3_IPM_CMD_BYTELEN_OFFSET 8 +#define SPI_CFG3_IPM_ADDR_BYTELEN_OFFSET 12 + +#define SPI_CFG3_IPM_CMD_PIN_MODE_MASK GENMASK(1, 0) +#define SPI_CFG3_IPM_CMD_BYTELEN_MASK GENMASK(11, 8) +#define SPI_CFG3_IPM_ADDR_BYTELEN_MASK GENMASK(15, 12) + #define MT8173_SPI_MAX_PAD_SEL 3 =20 #define MTK_SPI_PAUSE_INT_STATUS 0x2 @@ -90,6 +104,8 @@ #define MTK_SPI_MAX_FIFO_SIZE 32U #define MTK_SPI_PACKET_SIZE 1024 #define MTK_SPI_IPM_PACKET_SIZE SZ_64K +#define MTK_SPI_IPM_PACKET_LOOP SZ_256 + #define MTK_SPI_32BITS_MASK (0xffffffff) =20 #define DMA_ADDR_EXT_BITS (36) @@ -107,7 +123,8 @@ struct mtk_spi_compatible { bool no_need_unprepare; /* IPM design improve some single mode features */ bool ipm_design; - + /* IPM design that support quad mode */ + bool support_quad; }; =20 struct mtk_spi { @@ -123,6 +140,11 @@ struct mtk_spi { u32 tx_sgl_len, rx_sgl_len; const struct mtk_spi_compatible *dev_comp; u32 spi_clk_hz; + struct completion spimem_done; + bool use_spimem; + struct device *dev; + dma_addr_t tx_dma; + dma_addr_t rx_dma; }; =20 static const struct mtk_spi_compatible mtk_common_compat; @@ -137,6 +159,13 @@ static const struct mtk_spi_compatible mt7986_compat_s= ingle =3D { .ipm_design =3D true, }; =20 +static const struct mtk_spi_compatible mt7986_compat_quad =3D { + .enhance_timing =3D true, + .dma_ext =3D true, + .ipm_design =3D true, + .support_quad =3D true, +}; + static const struct mtk_spi_compatible mt6765_compat =3D { .need_pad_sel =3D true, .must_tx =3D true, @@ -181,6 +210,9 @@ static const struct of_device_id mtk_spi_of_match[] =3D= { { .compatible =3D "mediatek,mt7986-spi-single", .data =3D (void *)&mt7986_compat_single, }, + { .compatible =3D "mediatek,mt7986-spi-quad", + .data =3D (void *)&mt7986_compat_quad, + }, { .compatible =3D "mediatek,mt2701-spi", .data =3D (void *)&mtk_common_compat, }, @@ -704,6 +736,12 @@ static irqreturn_t mtk_spi_interrupt(int irq, void *de= v_id) else mdata->state =3D MTK_SPI_IDLE; =20 + /* SPI-MEM ops */ + if (mdata->use_spimem) { + complete(&mdata->spimem_done); + return IRQ_HANDLED; + } + if (!master->can_dma(master, NULL, trans)) { if (trans->rx_buf) { cnt =3D mdata->xfer_len / 4; @@ -787,6 +825,275 @@ static irqreturn_t mtk_spi_interrupt(int irq, void *d= ev_id) return IRQ_HANDLED; } =20 +static int mtk_spi_mem_adjust_op_size(struct spi_mem *mem, + struct spi_mem_op *op) +{ + int opcode_len; + + if (op->data.dir !=3D SPI_MEM_NO_DATA) { + opcode_len =3D 1 + op->addr.nbytes + op->dummy.nbytes; + if (opcode_len + op->data.nbytes > MTK_SPI_IPM_PACKET_SIZE) { + op->data.nbytes =3D MTK_SPI_IPM_PACKET_SIZE - opcode_len; + /* force data buffer dma-aligned. */ + op->data.nbytes -=3D op->data.nbytes % 4; + } + } + + return 0; +} + +static bool mtk_spi_mem_supports_op(struct spi_mem *mem, + const struct spi_mem_op *op) +{ + if (op->data.buswidth > 4 || op->addr.buswidth > 4 || + op->dummy.buswidth > 4 || op->cmd.buswidth > 4) + return false; + + if (op->addr.nbytes && op->dummy.nbytes && + op->addr.buswidth !=3D op->dummy.buswidth) + return false; + + if (op->addr.nbytes + op->dummy.nbytes > 16) + return false; + + if (op->data.nbytes > MTK_SPI_IPM_PACKET_SIZE) { + if (op->data.nbytes / MTK_SPI_IPM_PACKET_SIZE > + MTK_SPI_IPM_PACKET_LOOP || + op->data.nbytes % MTK_SPI_IPM_PACKET_SIZE !=3D 0) + return false; + } + + return true; +} + +static void mtk_spi_mem_setup_dma_xfer(struct spi_master *master, + const struct spi_mem_op *op) +{ + struct mtk_spi *mdata =3D spi_master_get_devdata(master); + + writel((u32)(mdata->tx_dma & MTK_SPI_32BITS_MASK), + mdata->base + SPI_TX_SRC_REG); +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT + if (mdata->dev_comp->dma_ext) + writel((u32)(mdata->tx_dma >> 32), + mdata->base + SPI_TX_SRC_REG_64); +#endif + + if (op->data.dir =3D=3D SPI_MEM_DATA_IN) { + writel((u32)(mdata->rx_dma & MTK_SPI_32BITS_MASK), + mdata->base + SPI_RX_DST_REG); +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT + if (mdata->dev_comp->dma_ext) + writel((u32)(mdata->rx_dma >> 32), + mdata->base + SPI_RX_DST_REG_64); +#endif + } +} + +static int mtk_spi_transfer_wait(struct spi_mem *mem, + const struct spi_mem_op *op) +{ + struct mtk_spi *mdata =3D spi_master_get_devdata(mem->spi->master); + /* + * For each byte we wait for 8 cycles of the SPI clock. + * Since speed is defined in Hz and we want milliseconds, + * so it should be 8 * 1000. + */ + u64 ms =3D 8000LL; + + if (op->data.dir =3D=3D SPI_MEM_NO_DATA) + ms *=3D 32; /* prevent we may get 0 for short transfers. */ + else + ms *=3D op->data.nbytes; + ms =3D div_u64(ms, mem->spi->max_speed_hz); + ms +=3D ms + 1000; /* 1s tolerance */ + + if (ms > UINT_MAX) + ms =3D UINT_MAX; + + if (!wait_for_completion_timeout(&mdata->spimem_done, + msecs_to_jiffies(ms))) { + dev_err(mdata->dev, "spi-mem transfer timeout\n"); + return -ETIMEDOUT; + } + + return 0; +} + +static int mtk_spi_mem_exec_op(struct spi_mem *mem, + const struct spi_mem_op *op) +{ + struct mtk_spi *mdata =3D spi_master_get_devdata(mem->spi->master); + u32 reg_val, nio, tx_size; + char *tx_tmp_buf, *rx_tmp_buf; + int ret =3D 0; + + mdata->use_spimem =3D true; + reinit_completion(&mdata->spimem_done); + + mtk_spi_reset(mdata); + mtk_spi_hw_init(mem->spi->master, mem->spi); + mtk_spi_prepare_transfer(mem->spi->master, mem->spi->max_speed_hz); + + reg_val =3D readl(mdata->base + SPI_CFG3_IPM_REG); + /* opcode byte len */ + reg_val &=3D ~SPI_CFG3_IPM_CMD_BYTELEN_MASK; + reg_val |=3D 1 << SPI_CFG3_IPM_CMD_BYTELEN_OFFSET; + + /* addr & dummy byte len */ + reg_val &=3D ~SPI_CFG3_IPM_ADDR_BYTELEN_MASK; + if (op->addr.nbytes || op->dummy.nbytes) + reg_val |=3D (op->addr.nbytes + op->dummy.nbytes) << + SPI_CFG3_IPM_ADDR_BYTELEN_OFFSET; + + /* data byte len */ + if (op->data.dir =3D=3D SPI_MEM_NO_DATA) { + reg_val |=3D SPI_CFG3_IPM_NODATA_FLAG; + writel(0, mdata->base + SPI_CFG1_REG); + } else { + reg_val &=3D ~SPI_CFG3_IPM_NODATA_FLAG; + mdata->xfer_len =3D op->data.nbytes; + mtk_spi_setup_packet(mem->spi->master); + } + + if (op->addr.nbytes || op->dummy.nbytes) { + if (op->addr.buswidth =3D=3D 1 || op->dummy.buswidth =3D=3D 1) + reg_val |=3D SPI_CFG3_IPM_XMODE_EN; + else + reg_val &=3D ~SPI_CFG3_IPM_XMODE_EN; + } + + if (op->addr.buswidth =3D=3D 2 || + op->dummy.buswidth =3D=3D 2 || + op->data.buswidth =3D=3D 2) + nio =3D 2; + else if (op->addr.buswidth =3D=3D 4 || + op->dummy.buswidth =3D=3D 4 || + op->data.buswidth =3D=3D 4) + nio =3D 4; + else + nio =3D 1; + + reg_val &=3D ~SPI_CFG3_IPM_CMD_PIN_MODE_MASK; + reg_val |=3D PIN_MODE_CFG(nio) << SPI_CFG3_IPM_PIN_MODE_OFFSET; + + reg_val |=3D SPI_CFG3_IPM_HALF_DUPLEX_EN; + if (op->data.dir =3D=3D SPI_MEM_DATA_IN) + reg_val |=3D SPI_CFG3_IPM_HALF_DUPLEX_DIR; + else + reg_val &=3D ~SPI_CFG3_IPM_HALF_DUPLEX_DIR; + writel(reg_val, mdata->base + SPI_CFG3_IPM_REG); + + tx_size =3D 1 + op->addr.nbytes + op->dummy.nbytes; + if (op->data.dir =3D=3D SPI_MEM_DATA_OUT) + tx_size +=3D op->data.nbytes; + + tx_size =3D max_t(u32, tx_size, 32); + + tx_tmp_buf =3D kzalloc(tx_size, GFP_KERNEL | GFP_DMA); + if (!tx_tmp_buf) { + mdata->use_spimem =3D false; + return -ENOMEM; + } + + tx_tmp_buf[0] =3D op->cmd.opcode; + + if (op->addr.nbytes) { + int i; + + for (i =3D 0; i < op->addr.nbytes; i++) + tx_tmp_buf[i + 1] =3D op->addr.val >> + (8 * (op->addr.nbytes - i - 1)); + } + + if (op->dummy.nbytes) + memset(tx_tmp_buf + op->addr.nbytes + 1, + 0xff, + op->dummy.nbytes); + + if (op->data.nbytes && op->data.dir =3D=3D SPI_MEM_DATA_OUT) + memcpy(tx_tmp_buf + op->dummy.nbytes + op->addr.nbytes + 1, + op->data.buf.out, + op->data.nbytes); + + mdata->tx_dma =3D dma_map_single(mdata->dev, tx_tmp_buf, + tx_size, DMA_TO_DEVICE); + if (dma_mapping_error(mdata->dev, mdata->tx_dma)) { + ret =3D -ENOMEM; + goto err_exit; + } + + if (op->data.dir =3D=3D SPI_MEM_DATA_IN) { + if (!IS_ALIGNED((size_t)op->data.buf.in, 4)) { + rx_tmp_buf =3D kzalloc(op->data.nbytes, + GFP_KERNEL | GFP_DMA); + if (!rx_tmp_buf) { + ret =3D -ENOMEM; + goto unmap_tx_dma; + } + } else { + rx_tmp_buf =3D op->data.buf.in; + } + + mdata->rx_dma =3D dma_map_single(mdata->dev, + rx_tmp_buf, + op->data.nbytes, + DMA_FROM_DEVICE); + if (dma_mapping_error(mdata->dev, mdata->rx_dma)) { + ret =3D -ENOMEM; + goto kfree_rx_tmp_buf; + } + } + + reg_val =3D readl(mdata->base + SPI_CMD_REG); + reg_val |=3D SPI_CMD_TX_DMA; + if (op->data.dir =3D=3D SPI_MEM_DATA_IN) + reg_val |=3D SPI_CMD_RX_DMA; + writel(reg_val, mdata->base + SPI_CMD_REG); + + mtk_spi_mem_setup_dma_xfer(mem->spi->master, op); + + mtk_spi_enable_transfer(mem->spi->master); + + /* Wait for the interrupt. */ + ret =3D mtk_spi_transfer_wait(mem, op); + if (ret) + goto unmap_rx_dma; + + /* spi disable dma */ + reg_val =3D readl(mdata->base + SPI_CMD_REG); + reg_val &=3D ~SPI_CMD_TX_DMA; + if (op->data.dir =3D=3D SPI_MEM_DATA_IN) + reg_val &=3D ~SPI_CMD_RX_DMA; + writel(reg_val, mdata->base + SPI_CMD_REG); + +unmap_rx_dma: + if (op->data.dir =3D=3D SPI_MEM_DATA_IN) { + dma_unmap_single(mdata->dev, mdata->rx_dma, + op->data.nbytes, DMA_FROM_DEVICE); + if (!IS_ALIGNED((size_t)op->data.buf.in, 4)) + memcpy(op->data.buf.in, rx_tmp_buf, op->data.nbytes); + } +kfree_rx_tmp_buf: + if (op->data.dir =3D=3D SPI_MEM_DATA_IN && + !IS_ALIGNED((size_t)op->data.buf.in, 4)) + kfree(rx_tmp_buf); +unmap_tx_dma: + dma_unmap_single(mdata->dev, mdata->tx_dma, + tx_size, DMA_TO_DEVICE); +err_exit: + kfree(tx_tmp_buf); + mdata->use_spimem =3D false; + + return ret; +} + +static const struct spi_controller_mem_ops mtk_spi_mem_ops =3D { + .adjust_op_size =3D mtk_spi_mem_adjust_op_size, + .supports_op =3D mtk_spi_mem_supports_op, + .exec_op =3D mtk_spi_mem_exec_op, +}; + static int mtk_spi_probe(struct platform_device *pdev) { struct spi_master *master; @@ -830,6 +1137,15 @@ static int mtk_spi_probe(struct platform_device *pdev) if (mdata->dev_comp->ipm_design) master->mode_bits |=3D SPI_LOOP; =20 + if (mdata->dev_comp->support_quad) { + master->mem_ops =3D &mtk_spi_mem_ops; + master->mode_bits |=3D SPI_RX_DUAL | SPI_TX_DUAL | + SPI_RX_QUAD | SPI_TX_QUAD; + + mdata->dev =3D &pdev->dev; + init_completion(&mdata->spimem_done); + } + if (mdata->dev_comp->need_pad_sel) { mdata->pad_num =3D of_property_count_u32_elems( pdev->dev.of_node, --=20 2.25.1 From nobody Sun Sep 22 07:47:27 2024 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 52D92C433F5 for ; Mon, 7 Mar 2022 06:53:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235743AbiCGGxz (ORCPT ); Mon, 7 Mar 2022 01:53:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235321AbiCGGxl (ORCPT ); Mon, 7 Mar 2022 01:53:41 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 295C81C92C; Sun, 6 Mar 2022 22:52:46 -0800 (PST) X-UUID: bb9c37a1eab24a4eb1edc9d42c6f2313-20220307 X-UUID: bb9c37a1eab24a4eb1edc9d42c6f2313-20220307 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1362615630; Mon, 07 Mar 2022 14:52:39 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Mon, 7 Mar 2022 14:52:38 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 7 Mar 2022 14:52:37 +0800 From: Leilk Liu To: Mark Brown CC: Rob Herring , Matthias Brugger , , , , , , Leilk Liu Subject: [PATCH V3 6/7] dt-bindings: spi: support spi-hclk Date: Mon, 7 Mar 2022 14:52:29 +0800 Message-ID: <20220307065230.12655-7-leilk.liu@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307065230.12655-1-leilk.liu@mediatek.com> References: <20220307065230.12655-1-leilk.liu@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" this patch support spi-hclk. Signed-off-by: Leilk Liu --- .../devicetree/bindings/spi/mediatek,spi-mt65xx.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml= b/Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml index a8a15a9a6c46..195793aa79b7 100644 --- a/Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml +++ b/Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml @@ -51,16 +51,20 @@ properties: maxItems: 1 =20 clocks: + minItems: 3 items: - description: clock used for the parent clock - description: clock used for the muxes clock - description: clock used for the clock gate + - description: clock used for the AHB bus, this clock is optional =20 clock-names: + minItems: 3 items: - const: parent-clk - const: sel-clk - const: spi-clk + - const: spi-hclk =20 mediatek,pad-select: $ref: /schemas/types.yaml#/definitions/uint32-array --=20 2.25.1 From nobody Sun Sep 22 07:47:27 2024 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 8600FC433F5 for ; Mon, 7 Mar 2022 06:53:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235723AbiCGGxw (ORCPT ); Mon, 7 Mar 2022 01:53:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234872AbiCGGxk (ORCPT ); Mon, 7 Mar 2022 01:53:40 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72DFB1FCEB; Sun, 6 Mar 2022 22:52:45 -0800 (PST) X-UUID: 5d3aaacd6a2f4934a8126380694a1089-20220307 X-UUID: 5d3aaacd6a2f4934a8126380694a1089-20220307 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 719419815; Mon, 07 Mar 2022 14:52:39 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 7 Mar 2022 14:52:39 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 7 Mar 2022 14:52:38 +0800 From: Leilk Liu To: Mark Brown CC: Rob Herring , Matthias Brugger , , , , , , Leilk Liu Subject: [PATCH V3 7/7] spi: mediatek: support spi-hclk Date: Mon, 7 Mar 2022 14:52:30 +0800 Message-ID: <20220307065230.12655-8-leilk.liu@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307065230.12655-1-leilk.liu@mediatek.com> References: <20220307065230.12655-1-leilk.liu@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" this patch adds spi-hclk support. Signed-off-by: Leilk Liu --- drivers/spi/spi-mt65xx.c | 85 ++++++++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 16 deletions(-) diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c index 2f09b9d7a998..902013ec1223 100644 --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c @@ -132,7 +132,7 @@ struct mtk_spi { u32 state; int pad_num; u32 *pad_sel; - struct clk *parent_clk, *sel_clk, *spi_clk; + struct clk *parent_clk, *sel_clk, *spi_clk, *spi_hclk; struct spi_transfer *cur_transfer; u32 xfer_len; u32 num_xfered; @@ -1221,25 +1221,38 @@ static int mtk_spi_probe(struct platform_device *pd= ev) goto err_put_master; } =20 + mdata->spi_hclk =3D devm_clk_get(&pdev->dev, "spi-hclk"); + if (!IS_ERR(mdata->spi_hclk)) { + ret =3D clk_prepare_enable(mdata->spi_hclk); + if (ret < 0) { + dev_err(&pdev->dev, "failed to enable spi_hclk (%d)\n", ret); + goto err_put_master; + } + } + ret =3D clk_prepare_enable(mdata->spi_clk); if (ret < 0) { dev_err(&pdev->dev, "failed to enable spi_clk (%d)\n", ret); - goto err_put_master; + goto err_disable_spi_hclk; } =20 ret =3D clk_set_parent(mdata->sel_clk, mdata->parent_clk); if (ret < 0) { dev_err(&pdev->dev, "failed to clk_set_parent (%d)\n", ret); - clk_disable_unprepare(mdata->spi_clk); - goto err_put_master; + goto err_disable_spi_clk; } =20 mdata->spi_clk_hz =3D clk_get_rate(mdata->spi_clk); =20 - if (mdata->dev_comp->no_need_unprepare) + if (mdata->dev_comp->no_need_unprepare) { clk_disable(mdata->spi_clk); - else + if (!IS_ERR(mdata->spi_hclk)) + clk_disable(mdata->spi_hclk); + } else { clk_disable_unprepare(mdata->spi_clk); + if (!IS_ERR(mdata->spi_hclk)) + clk_disable_unprepare(mdata->spi_hclk); + } =20 pm_runtime_enable(&pdev->dev); =20 @@ -1279,6 +1292,11 @@ static int mtk_spi_probe(struct platform_device *pde= v) =20 err_disable_runtime_pm: pm_runtime_disable(&pdev->dev); +err_disable_spi_clk: + clk_disable_unprepare(mdata->spi_clk); +err_disable_spi_hclk: + if (!IS_ERR(mdata->spi_hclk)) + clk_disable_unprepare(mdata->spi_hclk); err_put_master: spi_master_put(master); =20 @@ -1294,8 +1312,11 @@ static int mtk_spi_remove(struct platform_device *pd= ev) =20 mtk_spi_reset(mdata); =20 - if (mdata->dev_comp->no_need_unprepare) + if (mdata->dev_comp->no_need_unprepare) { clk_unprepare(mdata->spi_clk); + if (!IS_ERR(mdata->spi_hclk)) + clk_unprepare(mdata->spi_hclk); + } =20 return 0; } @@ -1311,8 +1332,11 @@ static int mtk_spi_suspend(struct device *dev) if (ret) return ret; =20 - if (!pm_runtime_suspended(dev)) + if (!pm_runtime_suspended(dev)) { clk_disable_unprepare(mdata->spi_clk); + if (!IS_ERR(mdata->spi_hclk)) + clk_disable_unprepare(mdata->spi_hclk); + } =20 return ret; } @@ -1329,11 +1353,23 @@ static int mtk_spi_resume(struct device *dev) dev_err(dev, "failed to enable spi_clk (%d)\n", ret); return ret; } + + if (!IS_ERR(mdata->spi_hclk)) { + clk_prepare_enable(mdata->spi_hclk); + if (ret < 0) { + dev_err(dev, "failed to enable spi_hclk (%d)\n", ret); + clk_disable_unprepare(mdata->spi_clk); + return ret; + } + } } =20 ret =3D spi_master_resume(master); - if (ret < 0) + if (ret < 0) { clk_disable_unprepare(mdata->spi_clk); + if (!IS_ERR(mdata->spi_hclk)) + clk_disable_unprepare(mdata->spi_hclk); + } =20 return ret; } @@ -1345,10 +1381,15 @@ static int mtk_spi_runtime_suspend(struct device *d= ev) struct spi_master *master =3D dev_get_drvdata(dev); struct mtk_spi *mdata =3D spi_master_get_devdata(master); =20 - if (mdata->dev_comp->no_need_unprepare) + if (mdata->dev_comp->no_need_unprepare) { clk_disable(mdata->spi_clk); - else + if (!IS_ERR(mdata->spi_hclk)) + clk_disable(mdata->spi_hclk); + } else { clk_disable_unprepare(mdata->spi_clk); + if (!IS_ERR(mdata->spi_hclk)) + clk_disable_unprepare(mdata->spi_hclk); + } =20 return 0; } @@ -1359,13 +1400,25 @@ static int mtk_spi_runtime_resume(struct device *de= v) struct mtk_spi *mdata =3D spi_master_get_devdata(master); int ret; =20 - if (mdata->dev_comp->no_need_unprepare) + if (mdata->dev_comp->no_need_unprepare) { ret =3D clk_enable(mdata->spi_clk); - else + if (!IS_ERR(mdata->spi_hclk)) + clk_enable(mdata->spi_hclk); + } else { ret =3D clk_prepare_enable(mdata->spi_clk); - if (ret < 0) { - dev_err(dev, "failed to enable spi_clk (%d)\n", ret); - return ret; + if (ret < 0) { + dev_err(dev, "failed to enable spi_clk (%d)\n", ret); + return ret; + } + + if (!IS_ERR(mdata->spi_hclk)) { + ret =3D clk_prepare_enable(mdata->spi_hclk); + if (ret < 0) { + dev_err(dev, "failed to enable spi_hclk (%d)\n", ret); + clk_disable_unprepare(mdata->spi_clk); + return ret; + } + } } =20 return 0; --=20 2.25.1