From patchwork Wed Nov 22 08:59:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Shubin via B4 Relay X-Patchwork-Id: 168189 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1190332vqb; Wed, 22 Nov 2023 01:06:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9qxOMaPAmsIE/dQkz4hgVOdlwwlq/UFUjdCEWchbt3yB7gePS8llSNr5ELvIGOVW7X7S4 X-Received: by 2002:a17:903:22cc:b0:1cf:5c99:75f8 with SMTP id y12-20020a17090322cc00b001cf5c9975f8mr1959595plg.65.1700644007881; Wed, 22 Nov 2023 01:06:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700644007; cv=none; d=google.com; s=arc-20160816; b=A87VSTCH9T5VU8JkzkLa/uQge04C2f1UErLLP6kKnMWmlEnOpT3FxnBlws3+hX7ZK0 kNwrPlSs1gpzbh9WkSSPm5bTpstQnp25T1DSDWLQytHWlzNHMgt+ryKt9KEgy0f1IUxR 2kz3M3qb4DC8mGssyC+MN0eUugPnJ2OUQn2fjUD84DWRdYFHl0g7Ew406fLuCUDUZ1Yi wlZolnAxUYYa9Ifbk7H6Ohlemms3X+UddfuTmiWu7zARjSVVUMoD4LwPBN8in0kWKo1c BIjOYhlJw4UYVS0YTbJjcde6HDruhzE7pYeCaZtgV40seE15OvCmYlBXDNbKRxDWfL1G mPdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=yE5SQFJJUj9CnBodopJpiYDcXj5tCBKh4+y/D5JZ+qI=; fh=7t+x9Nbuv/MklkXnDK+VD1eFkJ+XGpXVfHtFxD2n4Uw=; b=gvuO6aQKHuYdwwOhCG/gRoVrNknw4kpwKxhH5A6+G7vg5M+5So9SB7EUeLhTijwAA1 Bd8kij8XcuH1Hn1opGp+TkCQ7CW0qRuCe09xJvPgO8L06RZwrvnYx1G9mmdglSW4n+9N /kOObndUE4yeTFlM89VPFnfMPU64pIgTB9cpbDcsQQR/5eiJ7pa9bHoEe5r1V9qEs+nB h9kfwg9HBkf3EahwMyeAHlr9W/DCDo6hmhPdB5GyLcfQG4Yxz9olMUoTXhLXSKiTygc5 gT5ZUXnCmyVzrQoZsuCLRrnTZyJ/czoPtSUQkFWy0CI5DUYVZSUAwjfnq1eu7uTAfNRw +RhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=otX7qyrH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t14-20020a170902e84e00b001cc4107a515si12800029plg.48.2023.11.22.01.06.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 01:06:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=otX7qyrH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C17B380C0A6A; Wed, 22 Nov 2023 01:02:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343717AbjKVJC0 (ORCPT + 99 others); Wed, 22 Nov 2023 04:02:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343491AbjKVJBW (ORCPT ); Wed, 22 Nov 2023 04:01:22 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8A7412A for ; Wed, 22 Nov 2023 01:01:18 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id 2B39EC4AF1E; Wed, 22 Nov 2023 09:01:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700643675; bh=B8ZiLtBGXLbR7qoYbOTfiZMqMBl62eYsJWPIMirndxc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=otX7qyrHPkZ0vorVZ1Hek8gGI57cxAixYFTEynn7DX0JlictxsaK+Mas9tPIs8YUP 7kfOo6ukCO21bo3yTKuX9nFuqY9Jcpv9ZOY+eHDPTC/WJa+7sEV45mtY8BaA1gCJRK /xDym/Cc0vx+QdPjY+I+U0Gp6m375L7oj0NjSkWZsHglGtiMnhS2ngtPhI2KTnhEe6 Mync9nxPTi3XSjqOc6ScGWr1AeTYs0FKjqxNbqPIaIPdKVcraaZAtOWOxmUSeMTPhz l8TrW2/LaHAoTuogtuhNE0IJBvlOXVVKxlXxlI0BuhxbwQ/1lu5ZQmDpuV83xi59aC 6RvALP4O6kI4w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1901BC072A2; Wed, 22 Nov 2023 09:01:15 +0000 (UTC) From: Nikita Shubin via B4 Relay Date: Wed, 22 Nov 2023 11:59:53 +0300 Subject: [PATCH v5 15/39] spi: ep93xx: add DT support for Cirrus EP93xx MIME-Version: 1.0 Message-Id: <20231122-ep93xx-v5-15-d59a76d5df29@maquefel.me> References: <20231122-ep93xx-v5-0-d59a76d5df29@maquefel.me> In-Reply-To: <20231122-ep93xx-v5-0-d59a76d5df29@maquefel.me> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Sverdlin X-Mailer: b4 0.13-dev-e3e53 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700643671; l=4919; i=nikita.shubin@maquefel.me; s=20230718; h=from:subject:message-id; bh=OYD5e78as1K2YGZuUl59eu6mcZ+fN0DYGOt3PUkJWa0=; =?utf-8?q?b=3DIGg2jFvrW3Cr?= =?utf-8?q?TMoiyaf6qp4oD8Bxi/L3UWybKp9pJfOT5aS5Mxeetb/NtjEdtWXyrhfruFZ3wIOJ?= 8usuorcyC2JaE9x4W3yXBZnSNQ4+N7Xf82Crrp4maiP1p2bLW28B X-Developer-Key: i=nikita.shubin@maquefel.me; a=ed25519; pk=vqf5YIUJ7BJv3EJFaNNxWZgGuMgDH6rwufTLflwU9ac= X-Endpoint-Received: by B4 Relay for nikita.shubin@maquefel.me/20230718 with auth_id=65 X-Original-From: Nikita Shubin Reply-To: X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 22 Nov 2023 01:02:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783254490735636822 X-GMAIL-MSGID: 1783254490735636822 From: Nikita Shubin - add OF ID match table - add device tree DMA request, so we can probe defer, in case DMA is not ready yet - drop DMA platform code Reviewed-by: Linus Walleij Tested-by: Alexander Sverdlin Acked-by: Alexander Sverdlin Reviewed-by: Mark Brown Signed-off-by: Nikita Shubin Reviewed-by: Mark Brown --- drivers/spi/spi-ep93xx.c | 68 ++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 43 deletions(-) diff --git a/drivers/spi/spi-ep93xx.c b/drivers/spi/spi-ep93xx.c index a1d60e51c053..01df1f8ae680 100644 --- a/drivers/spi/spi-ep93xx.c +++ b/drivers/spi/spi-ep93xx.c @@ -18,18 +18,18 @@ #include #include #include +#include +#include #include #include #include #include +#include #include #include #include #include -#include -#include - #define SSPCR0 0x0000 #define SSPCR0_SPO BIT(6) #define SSPCR0_SPH BIT(7) @@ -92,8 +92,6 @@ struct ep93xx_spi { size_t fifo_level; struct dma_chan *dma_rx; struct dma_chan *dma_tx; - struct ep93xx_dma_data dma_rx_data; - struct ep93xx_dma_data dma_tx_data; struct sg_table rx_sgt; struct sg_table tx_sgt; void *zeropage; @@ -575,46 +573,25 @@ static int ep93xx_spi_unprepare_hardware(struct spi_controller *host) return 0; } -static bool ep93xx_spi_dma_filter(struct dma_chan *chan, void *filter_param) +static int ep93xx_spi_setup_dma(struct device *dev, struct ep93xx_spi *espi) { - if (ep93xx_dma_chan_is_m2p(chan)) - return false; - - chan->private = filter_param; - return true; -} - -static int ep93xx_spi_setup_dma(struct ep93xx_spi *espi) -{ - dma_cap_mask_t mask; int ret; espi->zeropage = (void *)get_zeroed_page(GFP_KERNEL); if (!espi->zeropage) return -ENOMEM; - dma_cap_zero(mask); - dma_cap_set(DMA_SLAVE, mask); - - espi->dma_rx_data.port = EP93XX_DMA_SSP; - espi->dma_rx_data.direction = DMA_DEV_TO_MEM; - espi->dma_rx_data.name = "ep93xx-spi-rx"; - - espi->dma_rx = dma_request_channel(mask, ep93xx_spi_dma_filter, - &espi->dma_rx_data); - if (!espi->dma_rx) { - ret = -ENODEV; + espi->dma_rx = dma_request_chan(dev, "rx"); + if (IS_ERR(espi->dma_rx)) { + ret = PTR_ERR(espi->dma_rx); + dev_err_probe(dev, ret, "rx DMA setup failed"); goto fail_free_page; } - espi->dma_tx_data.port = EP93XX_DMA_SSP; - espi->dma_tx_data.direction = DMA_MEM_TO_DEV; - espi->dma_tx_data.name = "ep93xx-spi-tx"; - - espi->dma_tx = dma_request_channel(mask, ep93xx_spi_dma_filter, - &espi->dma_tx_data); - if (!espi->dma_tx) { - ret = -ENODEV; + espi->dma_tx = dma_request_chan(dev, "tx"); + if (IS_ERR(espi->dma_tx)) { + ret = PTR_ERR(espi->dma_tx); + dev_err_probe(dev, ret, "tx DMA setup failed"); goto fail_release_rx; } @@ -647,18 +624,11 @@ static void ep93xx_spi_release_dma(struct ep93xx_spi *espi) static int ep93xx_spi_probe(struct platform_device *pdev) { struct spi_controller *host; - struct ep93xx_spi_info *info; struct ep93xx_spi *espi; struct resource *res; int irq; int error; - info = dev_get_platdata(&pdev->dev); - if (!info) { - dev_err(&pdev->dev, "missing platform data\n"); - return -EINVAL; - } - irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; @@ -713,12 +683,17 @@ static int ep93xx_spi_probe(struct platform_device *pdev) goto fail_release_host; } - if (info->use_dma && ep93xx_spi_setup_dma(espi)) + error = ep93xx_spi_setup_dma(&pdev->dev, espi); + if (error == -EPROBE_DEFER) + goto fail_release_host; + + if (error) dev_warn(&pdev->dev, "DMA setup failed. Falling back to PIO\n"); /* make sure that the hardware is disabled */ writel(0, espi->mmio + SSPCR1); + device_set_node(&host->dev, dev_fwnode(&pdev->dev)); error = devm_spi_register_controller(&pdev->dev, host); if (error) { dev_err(&pdev->dev, "failed to register SPI host\n"); @@ -746,9 +721,16 @@ static void ep93xx_spi_remove(struct platform_device *pdev) ep93xx_spi_release_dma(espi); } +static const struct of_device_id ep93xx_spi_of_ids[] = { + { .compatible = "cirrus,ep9301-spi" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, ep93xx_spi_of_ids); + static struct platform_driver ep93xx_spi_driver = { .driver = { .name = "ep93xx-spi", + .of_match_table = ep93xx_spi_of_ids, }, .probe = ep93xx_spi_probe, .remove_new = ep93xx_spi_remove,