From: Jonathan Cameron <jic23@kernel.org>
To: Denis CIOCCA <denis.ciocca@st.com>
Cc: Denis Ciocca <denis.ciocca@gmail.com>,
Lars-Peter Clausen <lars@metafoo.de>,
Jonathan Cameron <jic23@jic23.retrosnub.co.uk>,
Pavel Machek <pavel@denx.de>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"burman.yan@gmail.com" <burman.yan@gmail.com>
Subject: Re: STMicroelectronics accelerometers driver.
Date: Sat, 24 Nov 2012 16:23:49 +0000 [thread overview]
Message-ID: <50B0F495.6040409@kernel.org> (raw)
In-Reply-To: <50AFA000.3040906@st.com>
On 11/23/2012 04:10 PM, Denis CIOCCA wrote:
> Hi Jonathan and Lars-Peter,
>
> I have modified the source code but I am not sure if the spi dma code
> management is correctly because this part is new for me.
Comments on that below. It's much simpler than what you have done.
>
> About the complexity of channels management in the buffer code, I think
> the code is not too difficult and it is possible leave this code as now.
> Are you agree?
Yeah, that bit is fine.
>
>
> I attach the patch.
>
> Best regards,
>
> Denis
>
>
...
> diff --git a/drivers/iio/accel/st_accel_spi.c
> b/drivers/iio/accel/st_accel_spi.c
> new file mode 100644
> index 0000000..fbc199d
> --- /dev/null
> +++ b/drivers/iio/accel/st_accel_spi.c
> @@ -0,0 +1,178 @@
> +/*
> + * STMicroelectronics accelerometers driver
> + *
> + * Copyright 2012 STMicroelectronics Inc.
> + *
> + * Denis Ciocca <denis.ciocca@st.com>
> + *
> + * Licensed under the GPL-2.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/spi/spi.h>
> +#include <linux/iio/iio.h>
> +#include <linux/iio/trigger.h>
> +
> +#include <linux/iio/accel/st_accel.h>
> +
> +
> +#define ACC_SPI_READ 0x80;
> +#define ACC_SPI_MULTIREAD 0xc0
> +
> +static int st_accel_spi_read(struct st_accel_data *adata,
> + u8 reg_addr, int len, u8 *data)
> +{
> + struct spi_message msg;
> + int err;
This is on the stack. Needs to be on the heap to ensure alignment
and either it has to be on it's own or alignment to a cacheline
must be enforced.
u8 *tx = kmalloc(sizeof(tx), GFP_KERNEL);
Also note that data must also be dynamically allocated (from a quick
look it is).
> + u8 tx;
> +
> + struct spi_transfer xfers[] = {
> + {
> + .tx_buf = &tx,
> + .bits_per_word = 8,
> + .len = 1,
> + },
> + {
> + .rx_buf = data,
> + .bits_per_word = 8,
> + .len = len,
> + }
> + };
> +
> + if ((adata->multiread_bit == true) && (len > 1))
> + tx = reg_addr | ACC_SPI_MULTIREAD;
> + else
> + tx = reg_addr | ACC_SPI_READ;
> +
> + spi_message_init(&msg);
> + spi_message_add_tail(&xfers[0], &msg);
> + spi_message_add_tail(&xfers[1], &msg);
> + err = spi_sync(to_spi_device(adata->dev), &msg);
> + if (err)
> + goto acc_spi_read_error;
> +
> + return len;
> +
> +acc_spi_read_error:
> + return err;
> +}
> +
> +static int st_accel_spi_read_byte(struct st_accel_data *adata,
> + u8 reg_addr, u8 *res_byte)
> +{
> + return st_accel_spi_read(adata, reg_addr, 1, res_byte);
> +}
> +
> +static int st_accel_spi_read_multiple_byte(struct st_accel_data *adata,
> + u8 reg_addr, int len, u8 *data)
> +{
> + return st_accel_spi_read(adata, reg_addr, len, data);
> +}
> +
> +static int st_accel_spi_write_byte(struct st_accel_data *adata,
> + u8 reg_addr, u8 data)
> +{
> + struct spi_message msg;
> + int err;
> + u8 tx[2], *data_write;
> +
Errr. Not sure what you are up to. It's simply a case of allocating
tx on the heap, not the stack. This is true for anything that goes
in tx_buf or rx_buf of an spi_transfer structure;
struct spi_transfer xfers = {
.bits_per_word = 8,
.len = 2,
};
u8 *tx;
tx = kmalloc(sizeof(u8)*2);
tx[0] = reg_addr;
tx[1] = data_write;
xfers.tx_buf = tx;
...
kfree(tx);
}
> + struct spi_transfer xfers = {
> + .tx_buf = tx,
> + .bits_per_word = 8,
> + .len = 2,
> + };
> +
> + data_write = kmalloc(sizeof(*data_write), GFP_KERNEL);
> + if (data_write == NULL) {
> + err = -ENOMEM;
> + goto alloc_memory_error;
> + }
> + *data_write = data;
> +
> + tx[0] = reg_addr;
> + tx[1] = *data_write;
> + spi_message_init(&msg);
> + spi_message_add_tail(&xfers, &msg);
> + err = spi_sync(to_spi_device(adata->dev), &msg);
> + kfree(data_write);
> +
> +alloc_memory_error:
> + return err;
> +}
> +
...
next prev parent reply other threads:[~2012-11-24 16:23 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-08 15:39 STMicroelectronics accelerometers driver Denis CIOCCA
2012-10-08 19:14 ` Lars-Peter Clausen
2012-10-08 19:50 ` Pavel Machek
2012-10-08 20:33 ` Lars-Peter Clausen
2012-10-08 20:37 ` Jonathan Cameron
2012-10-14 15:05 ` Denis Ciocca
2012-10-14 19:08 ` Lars-Peter Clausen
2012-10-16 17:51 ` Lars-Peter Clausen
2012-10-22 9:31 ` Denis CIOCCA
2012-10-22 18:07 ` Jonathan Cameron
2012-10-22 19:37 ` Denis Ciocca
2012-10-24 12:44 ` Denis CIOCCA
2012-10-26 12:10 ` Lars-Peter Clausen
2012-10-29 8:55 ` Denis CIOCCA
2012-10-29 9:13 ` Lars-Peter Clausen
2012-10-29 10:24 ` Denis CIOCCA
2012-10-29 10:30 ` Lars-Peter Clausen
2012-10-29 10:38 ` Denis CIOCCA
2012-10-31 14:27 ` Denis CIOCCA
2012-10-31 16:40 ` Lars-Peter Clausen
2012-10-31 20:33 ` Jonathan Cameron
2012-11-04 10:09 ` Denis Ciocca
2012-11-05 21:28 ` Jonathan Cameron
2012-11-06 11:11 ` Denis CIOCCA
2012-11-12 17:10 ` Denis CIOCCA
2012-11-12 18:48 ` Jonathan Cameron
2012-11-13 15:38 ` Denis CIOCCA
2012-11-18 13:20 ` Jonathan Cameron
2012-11-23 16:10 ` Denis CIOCCA
2012-11-24 16:23 ` Jonathan Cameron [this message]
2012-11-26 16:57 ` Denis CIOCCA
2012-11-27 11:52 ` Denis CIOCCA
2012-11-29 9:46 ` Lars-Peter Clausen
2012-11-27 15:36 ` STMicroelectronics gyroscopes driver Denis CIOCCA
2012-11-29 9:51 ` Lars-Peter Clausen
2012-11-30 9:13 ` Denis CIOCCA
2012-11-30 10:36 ` Lars-Peter Clausen
2012-11-30 13:06 ` Jonathan Cameron
2012-12-03 16:40 ` STMicroelectronics driver Denis CIOCCA
2012-12-03 19:01 ` Lars-Peter Clausen
2012-11-19 13:00 ` STMicroelectronics accelerometers driver Lars-Peter Clausen
2012-11-06 11:14 ` Denis CIOCCA
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=50B0F495.6040409@kernel.org \
--to=jic23@kernel.org \
--cc=burman.yan@gmail.com \
--cc=denis.ciocca@gmail.com \
--cc=denis.ciocca@st.com \
--cc=jic23@jic23.retrosnub.co.uk \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=pavel@denx.de \
/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).