From patchwork Fri Nov 17 20:13:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13459250 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 3F539C5AE4A for ; Fri, 17 Nov 2023 20:14:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346209AbjKQUOW (ORCPT ); Fri, 17 Nov 2023 15:14:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346188AbjKQUOH (ORCPT ); Fri, 17 Nov 2023 15:14:07 -0500 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F602171A for ; Fri, 17 Nov 2023 12:14:00 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3b512dd7d5bso1595352b6e.1 for ; Fri, 17 Nov 2023 12:14:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252039; x=1700856839; darn=vger.kernel.org; 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=3x/o+ZhKJLhCZxPJDvSVJn2SYXdsZyrTC3illb8aSGE=; b=CwKoOETZGqRe5UOqmT1L2acNwFT+sCm90z6Wce9bLIOiYNpu/NIa1HtvwKYSaZiosg CUxX+YsEjzHJKPMfFL/itqTlHCgyxQgMoTsEx+2ELphA+EAjxkoo7kUlquYWYRuLxlR8 ST1uNo5tL5iLc9bBnTV6vJSF0Y1HVASK2OkTP3jMKCKupM/YLkIMNzSNrk4ZWT7v/1hz ssMBdM/fDX7YTxgu7Vq199CLU1bF0Y10A07bFl9/SqstvjvtTKwzkPxrJ4Oy+6YbGoci wXmTeMrOk/eI9tuE5MqIqQ1NTp/m2CMe7bRSUPg+F1MbGpxC8coWdqbcsYdg4t96uB/w IxsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252039; x=1700856839; 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=3x/o+ZhKJLhCZxPJDvSVJn2SYXdsZyrTC3illb8aSGE=; b=Uq+u1OStYDCDP9pRCu+1zBo7FHsjjw5ufTIfZVSCyvw2eQSofvjtKZH1odoYTzZuWk Xx9heXFUaVkQHC2ZKXCAu6/7B7k/YH4pB/6x1NZ4O7vTZvEqXALGE/E7ZsB55+HeZVM4 dAXCIXjrr4krB1u9Y8Pt0BtEhyemZFTEbLG6X/XhRhFaVfV18XTN/t7l/k2lbH/jIT6u PPY4zPeuu8CWSY8ZgPcXtqQ55AeAKWXbq3E/tj3IAaq3U/NK8t1F5uABrkXFfNKrzEEN 72F0Pwnz1ktOND1ffUjGFMjgQa0Jl7IjZzseLUWn2AXNxN25jSIy8np4LOsRw7a7CT3+ zNkQ== X-Gm-Message-State: AOJu0YyeUhLGemgIpEBnoeGYxNa9Yw08pWPIDfekIweRccj5WZsJD2ns J330SaOB1aPF0eY9nsGVXHRovbMvPe99RVnAEPLiFA== X-Google-Smtp-Source: AGHT+IEbin8UNO6r4Ykm5emy9h67aMHC8MsdLHv1PzpTun13feE0DMgvGrPV0W2CxfD98j+AiJB+qg== X-Received: by 2002:a05:6808:15a8:b0:3b6:3d44:4d75 with SMTP id t40-20020a05680815a800b003b63d444d75mr576150oiw.22.1700252039458; Fri, 17 Nov 2023 12:13:59 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:13:59 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 10/14] spi: axi-spi-engine: use message_prepare/unprepare Date: Fri, 17 Nov 2023 14:13:01 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-10-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org This modifies the AXI SPI Engine driver to make use of the message_prepare and message_unprepare callbacks. This separates the concerns of allocating and freeing the message state from the transfer_one_message callback. The main benfit of this is so that future callers of spi_finalize_current_message() will not have to do manual cleanup of the state. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 46 +++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 745000a9b2c7..210bea23f433 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -412,11 +412,7 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) if (spi_engine->completed_id == st->sync_id) { struct spi_message *msg = spi_engine->msg; - struct spi_engine_message_state *st = msg->state; - ida_free(&spi_engine->sync_ida, st->sync_id); - kfree(st->p); - kfree(st); msg->status = 0; msg->actual_length = msg->frame_length; spi_engine->msg = NULL; @@ -436,14 +432,12 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) return IRQ_HANDLED; } -static int spi_engine_transfer_one_message(struct spi_controller *host, - struct spi_message *msg) +static int spi_engine_prepare_message(struct spi_controller *host, + struct spi_message *msg) { struct spi_engine_program p_dry, *p; struct spi_engine *spi_engine = spi_controller_get_devdata(host); struct spi_engine_message_state *st; - unsigned int int_enable = 0; - unsigned long flags; size_t size; int ret; @@ -472,15 +466,41 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, spi_engine_compile_message(spi_engine, msg, false, p); - spin_lock_irqsave(&spi_engine->lock, flags); spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC(st->sync_id)); - msg->state = st; - spi_engine->msg = msg; st->p = p; - st->cmd_buf = p->instructions; st->cmd_length = p->length; + msg->state = st; + + return 0; +} + +static int spi_engine_unprepare_message(struct spi_controller *host, + struct spi_message *msg) +{ + struct spi_engine *spi_engine = spi_controller_get_devdata(host); + struct spi_engine_message_state *st = msg->state; + + ida_free(&spi_engine->sync_ida, st->sync_id); + kfree(st->p); + kfree(st); + + return 0; +} + +static int spi_engine_transfer_one_message(struct spi_controller *host, + struct spi_message *msg) +{ + struct spi_engine *spi_engine = spi_controller_get_devdata(host); + struct spi_engine_message_state *st = msg->state; + unsigned int int_enable = 0; + unsigned long flags; + + spin_lock_irqsave(&spi_engine->lock, flags); + + spi_engine->msg = msg; + if (spi_engine_write_cmd_fifo(spi_engine)) int_enable |= SPI_ENGINE_INT_CMD_ALMOST_EMPTY; @@ -572,6 +592,8 @@ static int spi_engine_probe(struct platform_device *pdev) host->bits_per_word_mask = SPI_BPW_MASK(8); host->max_speed_hz = clk_get_rate(spi_engine->ref_clk) / 2; host->transfer_one_message = spi_engine_transfer_one_message; + host->prepare_message = spi_engine_prepare_message; + host->unprepare_message = spi_engine_unprepare_message; host->num_chipselect = 8; if (host->max_speed_hz == 0)