From: Jonathan Cameron <jic23@cam.ac.uk>
Cc: fabien.marteau@armadeus.com, khali@linux-fr.org,
guenter.roeck@ericsson.com, linux-kernel@vger.kernel.org,
lm-sensors@lm-sensors.org
Subject: Re: [lm-sensors] [PATCH] hwmon: Driver for as1531,
Date: Wed, 18 May 2011 15:05:16 +0000 [thread overview]
Message-ID: <4DD3E02C.4030502@cam.ac.uk> (raw)
In-Reply-To: <4DD3C4F9.2000806@cam.ac.uk>
On 05/18/11 14:09, Jonathan Cameron wrote:
> On 05/16/11 14:39, fabien.marteau@armadeus.com wrote:
>> From: Fabien Marteau <fabien.marteau@armadeus.com>
>>
> Had a few minutes so done a quick port to IIO with minimal code changes.
> Now looking at cleaning things up so actually reading the code rather
> than cut and paste. The message is somewhat 'novel'.
>
> ...
>
> So we have a spi device that only talks in 1 bit words?
> 1) I'm amazed any spi controllers support that.
> 2) Doesn't look necessary from the data sheet google furnished me with.
>
> Looks like it will quite happily work with 8 bit transfers. Suggested replacement code below.
>> +static int as1531_message(struct spi_device *spi, int cmd, int *ret_value)
>> +{
>> + struct spi_message message;
>> + struct spi_transfer x[1];
>> + int status, i;
>> + u8 cmd_send;
>> + unsigned char buf[64];
>> + unsigned char buf_read[64];
>> +
>> + cmd_send = cmd;
>> +
>> + spi_message_init(&message);
>> + memset(x, 0, sizeof x);
>> + memset(buf, 0, sizeof(buf));
>> + memset(buf_read, 0, sizeof(buf_read));
>> +
>> + for (i = 0; i < 8; i++) {
>> + buf[i] = ((cmd_send & 0x80)>>7);
>> + cmd_send = cmd_send << 1;
>> + }
>> +
>> + x[0].tx_buf = buf;
>> + x[0].len = 24;
>> + x[0].rx_buf = buf_read;
>> + x[0].speed_hz = AS1531_SPI_SPEED;
>> + x[0].bits_per_word = 1;
>> + spi_message_add_tail(&x[0], &message);
>> +
>> + status = spi_sync(spi, &message);
>> + if (status < 0)
>> + return status;
>> +
>> + *ret_value = buf_read[11] & 0x01;
>> + for (i = 12; i < 23 ; i++) {
>> + *ret_value = *ret_value << 1;
>> + *ret_value = *ret_value | (buf_read[i]&0x01);
>> + }
>> +
>> + return 0;
>> +}
Or skip the below and use spi_w8r16. This isn't a fast capture route anyway.
> static int as1531_message(struct spi_device *spi, int cmd, u16 *ret_value)
> {
> int status;
> u8 cmd_send = cmd;
> struct spi_message message;
> struct spi_transfer x[2] = {
> {
> .len = 1,
> /* this should be default anyway - so could drop */
> .bits_per_word = 8,
> /* This should be set in board config really */
> .speed_hz = AS1531_SPI_SPEED,
> .rx_buf = &cmd_send,
> }, {
> .len = 2,
> .bits_per_word = 8,
> .speed_hz = AS1531_SPI_SPEED,
> .tx_buf = ret_value,
> }
> };
>
> spi_message_init(&message);
> spi_message_add_tail(&x[0], &message);
> spi_message_add_tail(&x[1], &message);
>
> status = spi_sync(spi, &message);
> if (status < 0)
> return status;
>
> *ret_value = (be16_to_cpup(ret_value) >> 2) & 0xFFF;
>
> return 0;
> }
>
> Obviously also requires changing the type of the element passed
> as ret_value. Could set the bits_per_word of the second transfer
> to 16 and avoid the endianness conversion, but I'm not sure how
> many spi masters support that.
>
> Jonathan
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
WARNING: multiple messages have this Message-ID (diff)
From: Jonathan Cameron <jic23@cam.ac.uk>
To: unlisted-recipients:; (no To-header on input)
Cc: fabien.marteau@armadeus.com, khali@linux-fr.org,
guenter.roeck@ericsson.com, linux-kernel@vger.kernel.org,
lm-sensors@lm-sensors.org
Subject: Re: [PATCH] hwmon: Driver for as1531, Austria-Microsystem Analog to Digital Converter.
Date: Wed, 18 May 2011 16:05:16 +0100 [thread overview]
Message-ID: <4DD3E02C.4030502@cam.ac.uk> (raw)
In-Reply-To: <4DD3C4F9.2000806@cam.ac.uk>
On 05/18/11 14:09, Jonathan Cameron wrote:
> On 05/16/11 14:39, fabien.marteau@armadeus.com wrote:
>> From: Fabien Marteau <fabien.marteau@armadeus.com>
>>
> Had a few minutes so done a quick port to IIO with minimal code changes.
> Now looking at cleaning things up so actually reading the code rather
> than cut and paste. The message is somewhat 'novel'.
>
> ...
>
> So we have a spi device that only talks in 1 bit words?
> 1) I'm amazed any spi controllers support that.
> 2) Doesn't look necessary from the data sheet google furnished me with.
>
> Looks like it will quite happily work with 8 bit transfers. Suggested replacement code below.
>> +static int as1531_message(struct spi_device *spi, int cmd, int *ret_value)
>> +{
>> + struct spi_message message;
>> + struct spi_transfer x[1];
>> + int status, i;
>> + u8 cmd_send;
>> + unsigned char buf[64];
>> + unsigned char buf_read[64];
>> +
>> + cmd_send = cmd;
>> +
>> + spi_message_init(&message);
>> + memset(x, 0, sizeof x);
>> + memset(buf, 0, sizeof(buf));
>> + memset(buf_read, 0, sizeof(buf_read));
>> +
>> + for (i = 0; i < 8; i++) {
>> + buf[i] = ((cmd_send & 0x80)>>7);
>> + cmd_send = cmd_send << 1;
>> + }
>> +
>> + x[0].tx_buf = buf;
>> + x[0].len = 24;
>> + x[0].rx_buf = buf_read;
>> + x[0].speed_hz = AS1531_SPI_SPEED;
>> + x[0].bits_per_word = 1;
>> + spi_message_add_tail(&x[0], &message);
>> +
>> + status = spi_sync(spi, &message);
>> + if (status < 0)
>> + return status;
>> +
>> + *ret_value = buf_read[11] & 0x01;
>> + for (i = 12; i < 23 ; i++) {
>> + *ret_value = *ret_value << 1;
>> + *ret_value = *ret_value | (buf_read[i]&0x01);
>> + }
>> +
>> + return 0;
>> +}
Or skip the below and use spi_w8r16. This isn't a fast capture route anyway.
> static int as1531_message(struct spi_device *spi, int cmd, u16 *ret_value)
> {
> int status;
> u8 cmd_send = cmd;
> struct spi_message message;
> struct spi_transfer x[2] = {
> {
> .len = 1,
> /* this should be default anyway - so could drop */
> .bits_per_word = 8,
> /* This should be set in board config really */
> .speed_hz = AS1531_SPI_SPEED,
> .rx_buf = &cmd_send,
> }, {
> .len = 2,
> .bits_per_word = 8,
> .speed_hz = AS1531_SPI_SPEED,
> .tx_buf = ret_value,
> }
> };
>
> spi_message_init(&message);
> spi_message_add_tail(&x[0], &message);
> spi_message_add_tail(&x[1], &message);
>
> status = spi_sync(spi, &message);
> if (status < 0)
> return status;
>
> *ret_value = (be16_to_cpup(ret_value) >> 2) & 0xFFF;
>
> return 0;
> }
>
> Obviously also requires changing the type of the element passed
> as ret_value. Could set the bits_per_word of the second transfer
> to 16 and avoid the endianness conversion, but I'm not sure how
> many spi masters support that.
>
> Jonathan
next prev parent reply other threads:[~2011-05-18 15:05 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-16 13:39 [lm-sensors] [PATCH] hwmon: Driver for as1531, fabien.marteau
2011-05-16 13:39 ` [PATCH] hwmon: Driver for as1531, Austria-Microsystem Analog to Digital Converter fabien.marteau
2011-05-16 15:01 ` [lm-sensors] [PATCH] hwmon: Driver for as1531, Randy Dunlap
2011-05-16 15:01 ` [PATCH] hwmon: Driver for as1531, Austria-Microsystem Analog to Digital Converter Randy Dunlap
2011-05-16 15:39 ` [lm-sensors] [PATCH] hwmon: Driver for as1531, Guenter Roeck
2011-05-16 15:39 ` [PATCH] hwmon: Driver for as1531, Austria-Microsystem Analog to Digital Converter Guenter Roeck
2011-05-17 7:06 ` [lm-sensors] [PATCH] hwmon: Driver for as1531, Fabien Marteau
2011-05-17 7:06 ` [PATCH] hwmon: Driver for as1531, Austria-Microsystem Analog to Digital Converter Fabien Marteau
2011-05-17 9:25 ` [lm-sensors] [PATCH] hwmon: Driver for as1531, Jonathan Cameron
2011-05-17 9:25 ` [PATCH] hwmon: Driver for as1531, Austria-Microsystem Analog to Digital Converter Jonathan Cameron
2011-05-17 9:34 ` [lm-sensors] [PATCH] hwmon: Driver for as1531, Jonathan Cameron
2011-05-17 9:34 ` [PATCH] hwmon: Driver for as1531, Austria-Microsystem Analog to Digital Converter Jonathan Cameron
2011-05-17 11:59 ` [lm-sensors] [PATCH] hwmon: Driver for as1531, Fabien Marteau
2011-05-17 11:59 ` [PATCH] hwmon: Driver for as1531, Austria-Microsystem Analog to Digital Converter Fabien Marteau
2011-05-18 15:39 ` [PATCH 0/2] staging:iio:adc:as1531 driver port from hwmon driver Jonathan Cameron
2011-05-18 15:39 ` [lm-sensors] [PATCH 0/2] staging:iio:adc:as1531 driver port from Jonathan Cameron
2011-05-18 16:16 ` [PATCH V2 0/2] staging:iio:adc:as1531 driver port from hwmon driver Jonathan Cameron
2011-05-18 16:16 ` [lm-sensors] [PATCH V2 0/2] staging:iio:adc:as1531 driver port from Jonathan Cameron
2011-05-18 17:01 ` [PATCH V2 0/2] staging:iio:adc:as1531 driver port from hwmon driver Fabien Marteau
2011-05-18 17:01 ` [lm-sensors] [PATCH V2 0/2] staging:iio:adc:as1531 driver port Fabien Marteau
2011-05-18 16:16 ` [PATCH 1/2] staging:iio:adc: as1531 driver initial conversion from hwmon submission Jonathan Cameron
2011-05-18 16:16 ` [lm-sensors] [PATCH 1/2] staging:iio:adc: as1 Jonathan Cameron
2011-05-18 16:37 ` [PATCH 1/2] staging:iio:adc: as1531 driver initial conversion from hwmon submission Guenter Roeck
2011-05-18 16:37 ` [lm-sensors] [PATCH 1/2] staging:iio:adc: as1531 driver initial Guenter Roeck
2011-05-18 16:17 ` [PATCH 2/2] staging:iio:adc:as1351 general cleanup and conversion to standard functions Jonathan Cameron
2011-05-18 16:17 ` [lm-sensors] [PATCH 2/2] staging:iio:adc:as1351 general cleanup and Jonathan Cameron
2011-05-18 16:35 ` [PATCH 2/2] staging:iio:adc:as1351 general cleanup and conversion to standard functions Guenter Roeck
2011-05-18 16:35 ` [lm-sensors] [PATCH 2/2] staging:iio:adc:as1351 general cleanup Guenter Roeck
2011-05-19 8:42 ` [PATCH 2/2] staging:iio:adc:as1351 general cleanup and conversion to standard functions Jonathan Cameron
2011-05-19 8:42 ` [lm-sensors] [PATCH 2/2] staging:iio:adc:as1351 general cleanup Jonathan Cameron
2011-05-18 15:39 ` [PATCH 1/2] staging:iio:adc: as1531 driver initial conversion from hwmon submission Jonathan Cameron
2011-05-18 15:39 ` [lm-sensors] [PATCH 1/2] staging:iio:adc: as1 Jonathan Cameron
2011-05-18 16:02 ` [PATCH 1/2] staging:iio:adc: as1531 driver initial conversion from hwmon submission Guenter Roeck
2011-05-18 16:02 ` [lm-sensors] [PATCH 1/2] staging:iio:adc: as1531 driver initial Guenter Roeck
2011-05-18 16:12 ` [PATCH 1/2] staging:iio:adc: as1531 driver initial conversion from hwmon submission Jonathan Cameron
2011-05-18 16:12 ` [lm-sensors] [PATCH 1/2] staging:iio:adc: as1531 driver initial Jonathan Cameron
2011-05-18 15:39 ` [PATCH 2/2] staging:iio:adc:as1351 general cleanup and conversion to standard functions Jonathan Cameron
2011-05-18 15:39 ` [lm-sensors] [PATCH 2/2] staging:iio:adc:as1351 general cleanup and Jonathan Cameron
2011-05-18 15:57 ` [PATCH 2/2] staging:iio:adc:as1351 general cleanup and conversion to standard functions Guenter Roeck
2011-05-18 15:57 ` [lm-sensors] [PATCH 2/2] staging:iio:adc:as1351 general cleanup Guenter Roeck
2011-05-17 13:38 ` [lm-sensors] [PATCH] hwmon: Driver for as1531, Guenter Roeck
2011-05-17 13:38 ` [PATCH] hwmon: Driver for as1531, Austria-Microsystem Analog to Digital Converter Guenter Roeck
2011-05-18 13:09 ` [lm-sensors] [PATCH] hwmon: Driver for as1531, Jonathan Cameron
2011-05-18 13:09 ` [PATCH] hwmon: Driver for as1531, Austria-Microsystem Analog to Digital Converter Jonathan Cameron
2011-05-18 15:05 ` Jonathan Cameron [this message]
2011-05-18 15:05 ` Jonathan Cameron
-- strict thread matches above, loose matches on Subject: below --
2011-05-16 13:39 [lm-sensors] [PATCH] hwmon: Driver for as1531, fabien.marteau
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=4DD3E02C.4030502@cam.ac.uk \
--to=jic23@cam.ac.uk \
--cc=fabien.marteau@armadeus.com \
--cc=guenter.roeck@ericsson.com \
--cc=khali@linux-fr.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.