From patchwork Mon Dec 14 15:20:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sperl X-Patchwork-Id: 7845381 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 789E6BEEE1 for ; Mon, 14 Dec 2015 15:21:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B47D6202EC for ; Mon, 14 Dec 2015 15:21:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 742262034C for ; Mon, 14 Dec 2015 15:21:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752237AbbLNPUm (ORCPT ); Mon, 14 Dec 2015 10:20:42 -0500 Received: from 212-186-180-163.dynamic.surfer.at ([212.186.180.163]:39371 "EHLO cgate.sperl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752259AbbLNPUl (ORCPT ); Mon, 14 Dec 2015 10:20:41 -0500 Received: from raspcm.intern.sperl.org (account martin@sperl.org [10.10.10.41] verified) by sperl.org (CommuniGate Pro SMTP 6.1.2) with ESMTPSA id 6361178; Mon, 14 Dec 2015 15:20:32 +0000 From: kernel@martin.sperl.org To: Mark Brown , Stephen Warren , Lee Jones , Eric Anholt , linux-spi@vger.kernel.org, linux-rpi-kernel@lists.infradead.org Cc: Martin Sperl Subject: [PATCH v3 6/8] spi: core: add spi_master.translate_message Date: Mon, 14 Dec 2015 15:20:23 +0000 Message-Id: <1450106426-2277-7-git-send-email-kernel@martin.sperl.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1450106426-2277-1-git-send-email-kernel@martin.sperl.org> References: <1450106426-2277-1-git-send-email-kernel@martin.sperl.org> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Sperl Add translate_message to spi_master structure to allow translations of spi_messages to happen independently of prepare messages. This "translations" are supposed to be using spi_res to handle the reverse transformation (see spi_replace_transfers), so no explicit code is necessary to revert any changes. dma_mapping of spi_messages could also become part of this processing. The long-term view is that this translation as well as the dma_mapping of the messages may happen in a separate thread when we are queueing those spi_messages - this would allows for better use of cpu resources as well as reduction of latency in the case of queuing. Signed-off-by: Martin Sperl --- drivers/spi/spi.c | 15 +++++++++++++++ include/linux/spi/spi.h | 4 ++++ 2 files changed, 19 insertions(+) -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index fe3b18e..020e34d 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1170,6 +1170,21 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread) trace_spi_message_start(master->cur_msg); + /* under some circumstances (i.e: when queuing a message) this + * could get moved to a separate thread to reduce latencies + * this could also handle the mapping of spi_transfers + */ + if (master->translate_message) { + ret = master->translate_message(master, master->cur_msg); + if (ret) { + dev_err(&master->dev, + "failed to translate message: %d\n", ret); + master->cur_msg->status = ret; + spi_finalize_current_message(master); + return; + } + } + if (master->prepare_message) { ret = master->prepare_message(master, master->cur_msg); if (ret) { diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 7172e73..4b4c1e9 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -379,6 +379,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) * @handle_err: the subsystem calls the driver to handle an error that occurs * in the generic implementation of transfer_one_message(). * @unprepare_message: undo any work done by prepare_message(). + * @translate_message: apply some message translations to optimize for the + * spi_master * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS * number. Any individual value may be -ENOENT for CS lines that * are not GPIOs (driven by the SPI controller itself). @@ -525,6 +527,8 @@ struct spi_master { struct spi_message *message); int (*unprepare_message)(struct spi_master *master, struct spi_message *message); + int (*translate_message)(struct spi_master *master, + struct spi_message *message); /* * These hooks are for drivers that use a generic implementation