linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Julia Lawall <Julia.Lawall-L2FTfq7BK8M@public.gmane.org>,
	Jonathan Cameron <jic23-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH 1/3] spi: Add helper functions for setting up transfers
Date: Wed, 09 Jan 2013 21:36:58 +0000	[thread overview]
Message-ID: <50EDE2FA.3060308@kernel.org> (raw)
In-Reply-To: <50EDD96A.5080900-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>

On 01/09/2013 08:56 PM, Lars-Peter Clausen wrote:
> On 01/09/2013 08:20 PM, Jonathan Cameron wrote:
>> On 01/09/2013 05:31 PM, Lars-Peter Clausen wrote:
>>> Quite often the pattern used for setting up and transferring a synchronous SPI
>>> transaction looks very much like the following:
>>>
>>> 	struct spi_message msg;
>>> 	struct spi_transfer xfers[] = {
>>> 		...
>>> 	};
>>>
>>> 	spi_message_init(&msg);
>>> 	spi_message_add_tail(&xfers[0], &msg);
>>> 	...
>>> 	spi_message_add_tail(&xfers[ARRAY_SIZE(xfers) - 1], &msg);
>>>
>>> 	ret = spi_sync(&msg);
>>>
>>> This patch adds two new helper functions for handling this case. The first
>>> helper function spi_message_init_with_transfers() takes a spi_message and an
>>> array of spi_transfers. It will initialize the message and then call
>>> spi_message_add_tail() for each transfer in the array. E.g. the following
>>>
>>> 	spi_message_init(&msg);
>>> 	spi_message_add_tail(&xfers[0], &msg);
>>> 	...
>>> 	spi_message_add_tail(&xfers[ARRAY_SIZE(xfers) - 1], &msg);
>>>
>>> can be rewritten as
>>>
>>> 	spi_message_init_with_transfers(&msg, xfers, ARRAY_SIZE(xfers));
>>>
>>> The second function spi_sync_transfer() takes a SPI device and an array of
>>> spi_transfers. It will allocate a new spi_message (on the stack) and add all
>>> transfers in the array to the message. Finally it will call spi_sync() on the
>>> message.
>>>
>>> E.g. the follwing
>>>
>>> 	struct spi_message msg;
>>> 	struct spi_transfer xfers[] = {
>>> 		...
>>> 	};
>>>
>>> 	spi_message_init(&msg);
>>> 	spi_message_add_tail(&xfers[0], &msg);
>>> 	...
>>> 	spi_message_add_tail(&xfers[ARRAY_SIZE(xfers) - 1], &msg);
>>>
>>> 	ret = spi_sync(spi, &msg);
>>>
>>> can be rewritten as
>>>
>>> 	struct spi_transfer xfers[] = {
>>> 		...
>>> 	};
>>>
>>> 	ret = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers));
>>>
>>> The patch also adds a new cocci script which can detect such sequences as
>>> described above and transform them automatically to use the new helper
>>> functions.
>>>
>>> Signed-off-by: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
>>>
>> Principle looks good to me and some nice little duplication removal
>> savings.
>>
>> My coccinelle isn't really up to checking that, but for the functions
>> Acked-by: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
>>
>> When all comments are in on the code we'll have to think about how to
>> merge this.  If you have much else planned that will hit those iio drivers
>> then things will get uggly unless it goes through that tree.
>>
>> Guess it all depends on whether others like the patch though ;)
> 
> The IIO patches can easily wait another release until the spi has made it's way
> up into mainline. I just didn't want to send out the helper functions without
> any realworld examples on how they can be used.
> 
Good point, though obviously send them again after this patch has merged
given the fine nature of my memory ;)

------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 

  parent reply	other threads:[~2013-01-09 21:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-09 17:31 [PATCH 1/3] spi: Add helper functions for setting up transfers Lars-Peter Clausen
     [not found] ` <1357752671-30222-1-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-01-09 17:31   ` [PATCH 2/3] iio: Use spi_sync_transfer() Lars-Peter Clausen
2013-01-09 17:31   ` [PATCH 3/3] staging:iio: " Lars-Peter Clausen
2013-01-09 19:20   ` [PATCH 1/3] spi: Add helper functions for setting up transfers Jonathan Cameron
2013-01-09 20:56     ` Lars-Peter Clausen
     [not found]       ` <50EDD96A.5080900-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-01-09 21:36         ` Jonathan Cameron [this message]
2013-01-10  8:53   ` Julia Lawall
     [not found]     ` <alpine.DEB.2.02.1301100951060.2063-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
2013-01-10  9:55       ` Lars-Peter Clausen
     [not found]         ` <50EE8FFD.2000000-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-01-10 10:28           ` Julia Lawall
2013-01-27  3:33   ` Mark Brown
     [not found]     ` <20130127033358.GA20672-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-02-05 14:07       ` Grant Likely
2013-02-06 19:20         ` Jonathan Cameron
     [not found]           ` <5112ACF5.3020906-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-02-09 11:14             ` Jonathan Cameron
2013-02-09 10:59         ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50EDE2FA.3060308@kernel.org \
    --to=jic23-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=Julia.Lawall-L2FTfq7BK8M@public.gmane.org \
    --cc=jic23-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org \
    --cc=lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org \
    --cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).