Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4491380rdb; Tue, 12 Dec 2023 00:24:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5puuWObcsqIC6tmSSQMBheBVi1jtBxNKkaB5/RTKluIfEAKzRVpAjVCxx89bsisz14lzU X-Received: by 2002:a17:902:ec92:b0:1cf:edd5:f783 with SMTP id x18-20020a170902ec9200b001cfedd5f783mr5811852plg.15.1702369468162; Tue, 12 Dec 2023 00:24:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702369468; cv=none; d=google.com; s=arc-20160816; b=MAqZA6pFsSaK+C89sV6IzF3BwXE44AyTxwbh+NAe787UPsqFfD4Mzd0+EMkSpPlJQ6 oeNW6w+LzMJvzMXID96jJDIw3BnqdxaaWB6hvkv6xkR/OrXRQh92MQy6mn36bNfxySSv bPsoGUUUTuUBSqSBKc5E9aTtUXsAGxmrPXdzJby82moENjitjAR4NZi8SxFdrM5UCof1 eRuVObKwnQat8EF73l9DRWksWuVLPR2Sh+PkIYWhYlgcGnMJc4vIMbkw1maKmy9fNGJ6 hh8WC+zLdXT5NclWZt8Ggjg/b/X0l7ZjVSWCDUYTxnvBUrXW8cbC6PduVLXXJ/R6ve04 +PRQ== 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=i7Amzz929dtBzQ7cEJnNarmCG2Cdp8WOeqOhGej+HHo=; b=IojnpHekZc1S8jg4hLc+pLyq3/zCEaSdIfimlN8RVOplgqcbCLmkPy9kM1FV13AhOZ BrLmC/OAs/j+S9peJh7cgZynghljMkdix0tq1vk3HKVgMuSCldMsHy2TSDTOTCScAqe+ WDpNNXJktDnTK1Q69T+s5t5actEa4RAIbc9ZFDWzCpRVREU5cII+NG7OCBhOCmAtq5Fb fu3e3KS6f9hSzl/6QagOtNCi29hKQVlRCqbklePl8zdnq64euU8wVATOIN2S0tKF9cjY S86ji7fsdjbogOWirwtBsnSbAcBhQsvm6HLsNIAZ6BFmAOJ2whMkjoOYggyqYJ5qJwEz f/wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uZYxEAqd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id m8-20020a1709026bc800b001d06d7f9134si7366684plt.97.2023.12.12.00.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 00:24:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uZYxEAqd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 25CBD80A0DFE; Tue, 12 Dec 2023 00:24:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346255AbjLLIXL (ORCPT + 99 others); Tue, 12 Dec 2023 03:23:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232382AbjLLIWC (ORCPT ); Tue, 12 Dec 2023 03:22:02 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94E74ED for ; Tue, 12 Dec 2023 00:22:08 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id 65F43C116B4; Tue, 12 Dec 2023 08:22:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702369325; bh=B8ZiLtBGXLbR7qoYbOTfiZMqMBl62eYsJWPIMirndxc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=uZYxEAqdBA2TNeeK14dz6oAnMI2SlEAmbBlJY4ilA0OS4rZh1gUAS7HjwHGsPYxmC 99N3/fxwhBXGA/ewUOo4yGT6YqiLSuSqp6nGbBJGd2klMsXArPfbqN4iwGOolM+lT+ i0U8+rjD/Bef/kjlEFoW5AaQ2oL9XYZg0jYAjoycOmxH8Q0nBq5SbXRJV0y9c/XoNt 4nlz3DhrRDuCNwdi2ZiSK0F6t+PcEf9fEY4/FytY6lx+oPplkDfLCfSRR2RcBw7Bm+ ijqvow2ptxxYjjmlpke+xfz/WXqioeIp2e3V/ICcv7jB2flxoFiF+4RCjgScuLNJBg Mse9cj8VDqcTw== 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 55DE0C4332F; Tue, 12 Dec 2023 08:22:05 +0000 (UTC) From: Nikita Shubin via B4 Relay Date: Tue, 12 Dec 2023 11:20:33 +0300 Subject: [PATCH v6 16/40] spi: ep93xx: add DT support for Cirrus EP93xx MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231212-ep93xx-v6-16-c307b8ac9aa8@maquefel.me> References: <20231212-ep93xx-v6-0-c307b8ac9aa8@maquefel.me> In-Reply-To: <20231212-ep93xx-v6-0-c307b8ac9aa8@maquefel.me> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Arnd Bergmann X-Mailer: b4 0.13-dev-e3e53 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702369322; l=4919; i=nikita.shubin@maquefel.me; s=20230718; h=from:subject:message-id; bh=OYD5e78as1K2YGZuUl59eu6mcZ+fN0DYGOt3PUkJWa0=; =?utf-8?q?b=3DGNRxtSo93P4d?= =?utf-8?q?4W69iGK97JLvdf58I+DPmHjRCFYdGC4yvcGuthU1yMq6vZhEeL6c1ApczWsSk0dL?= EEFt+XjxBcW+SR1dcH2t+4oGpbGGoJ8n75hTyN9FjgiXP5jGw7hd 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=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Tue, 12 Dec 2023 00:24:12 -0800 (PST) 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 --- 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, -- 2.41.0