From: Jonathan Cameron <jic23@cam.ac.uk>
To: Manuel Stahl <manuel.stahl@iis.fraunhofer.de>
Cc: linux-iio@vger.kernel.org,
device-drivers-devel@blackfin.uclinux.org, ldewangan@nvidia.com,
shubhrajyoti@ti.com
Subject: Re: [PATCH 10/25] staging:iio:magnetometer:hmc5843 iio_chan_spec conversion.
Date: Fri, 01 Jul 2011 13:15:50 +0100 [thread overview]
Message-ID: <4E0DBA76.6050200@cam.ac.uk> (raw)
In-Reply-To: <4E0DA881.30608@iis.fraunhofer.de>
On 07/01/11 11:59, Manuel Stahl wrote:
> On 01.07.2011 12:11, Jonathan Cameron wrote:
>> -static IIO_DEVICE_ATTR(magn_scale,
>> - S_IRUGO,
>> - show_scale,
>> - NULL , 0);
>> +
>> +#define HMC5843_CHANNEL(axis, add) \
>> + { \
>> + .type = IIO_MAGN, \
>> + .modified = 1, \
>> + .channel2 = IIO_MOD_##axis, \
>> + .info_mask = (1<< IIO_CHAN_INFO_SCALE_SHARED), \
>> + .address = add \
>> + }
>> +
>> +static const struct iio_chan_spec hmc5843_channels[] = {
>> + HMC5843_CHANNEL(X, HMC5843_DATA_OUT_X_MSB_REG),
>> + HMC5843_CHANNEL(X, HMC5843_DATA_OUT_Y_MSB_REG),
>> + HMC5843_CHANNEL(X, HMC5843_DATA_OUT_Z_MSB_REG),
>> +};
> Shouldn't be all X, I guess.
>
> Regards,
>
Thanks. This may be my worst patch set ever!
Fixed - patch follows.
[PATCH 10/25 V3] staging:iio:magnetometer:hmc5843 iio_chan_spec conversion.
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
drivers/staging/iio/magnetometer/hmc5843.c | 96 +++++++++++++++-------------
1 files changed, 51 insertions(+), 45 deletions(-)
diff --git a/drivers/staging/iio/magnetometer/hmc5843.c b/drivers/staging/iio/magnetometer/hmc5843.c
index b44c273a..1bb7186 100644
--- a/drivers/staging/iio/magnetometer/hmc5843.c
+++ b/drivers/staging/iio/magnetometer/hmc5843.c
@@ -24,7 +24,6 @@
#include <linux/types.h>
#include "../iio.h"
#include "../sysfs.h"
-#include "magnet.h"
#define HMC5843_I2C_ADDRESS 0x1E
@@ -62,9 +61,9 @@
/*
* Device status
*/
-#define DATA_READY 0x01
-#define DATA_OUTPUT_LOCK 0x02
-#define VOLTAGE_REGULATOR_ENABLED 0x04
+#define DATA_READY 0x01
+#define DATA_OUTPUT_LOCK 0x02
+#define VOLTAGE_REGULATOR_ENABLED 0x04
/*
* Mode register configuration
@@ -89,22 +88,16 @@
/*
* Device Configutration
*/
-#define CONF_NORMAL 0x00
+#define CONF_NORMAL 0x00
#define CONF_POSITIVE_BIAS 0x01
#define CONF_NEGATIVE_BIAS 0x02
#define CONF_NOT_USED 0x03
#define MEAS_CONF_MASK 0x03
-static const char *regval_to_scale[] = {
- "0.0000006173",
- "0.0000007692",
- "0.0000010309",
- "0.0000012821",
- "0.0000018868",
- "0.0000021739",
- "0.0000025641",
- "0.0000035714",
+static int hmc5843_regval_to_nanoscale[] = {
+ 6173, 7692, 10309, 12821, 18868, 21739, 25641, 35714
};
+
static const int regval_to_input_field_mg[] = {
700,
1000,
@@ -115,7 +108,7 @@ static const int regval_to_input_field_mg[] = {
4500,
6500
};
-static const char *regval_to_samp_freq[] = {
+static const char * const regval_to_samp_freq[] = {
"0.5",
"1",
"2",
@@ -150,37 +143,28 @@ static s32 hmc5843_configure(struct i2c_client *client,
}
/* Return the measurement value from the specified channel */
-static ssize_t hmc5843_read_measurement(struct device *dev,
- struct device_attribute *attr,
- char *buf)
+static int hmc5843_read_measurement(struct iio_dev *indio_dev,
+ int address,
+ int *val)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
- s16 coordinate_val;
- struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
struct hmc5843_data *data = iio_priv(indio_dev);
s32 result;
mutex_lock(&data->lock);
-
result = i2c_smbus_read_byte_data(client, HMC5843_STATUS_REG);
while (!(result & DATA_READY))
result = i2c_smbus_read_byte_data(client, HMC5843_STATUS_REG);
- result = i2c_smbus_read_word_data(client, this_attr->address);
+ result = i2c_smbus_read_word_data(client, address);
mutex_unlock(&data->lock);
if (result < 0)
return -EINVAL;
- coordinate_val = (s16)swab16((u16)result);
- return sprintf(buf, "%d\n", coordinate_val);
+ *val = (s16)swab16((u16)result);
+ return IIO_VAL_INT;
}
-static IIO_DEV_ATTR_MAGN_X(hmc5843_read_measurement,
- HMC5843_DATA_OUT_X_MSB_REG);
-static IIO_DEV_ATTR_MAGN_Y(hmc5843_read_measurement,
- HMC5843_DATA_OUT_Y_MSB_REG);
-static IIO_DEV_ATTR_MAGN_Z(hmc5843_read_measurement,
- HMC5843_DATA_OUT_Z_MSB_REG);
+
/*
* From the datasheet
@@ -336,7 +320,7 @@ static s32 hmc5843_set_rate(struct i2c_client *client,
reg_val = (data->meas_conf) | (rate << RATE_OFFSET);
if (rate >= RATE_NOT_USED) {
dev_err(&client->dev,
- "This data output rate is not supported \n");
+ "This data output rate is not supported\n");
return -EINVAL;
}
return i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_A, reg_val);
@@ -467,28 +451,46 @@ static IIO_DEVICE_ATTR(magn_range,
set_range,
HMC5843_CONFIG_REG_B);
-static ssize_t show_scale(struct device *dev,
- struct device_attribute *attr,
- char *buf)
+static int hmc5843_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2,
+ long mask)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct hmc5843_data *data = iio_priv(indio_dev);
- return strlen(strcpy(buf, regval_to_scale[data->range]));
+
+ switch (mask) {
+ case 0:
+ return hmc5843_read_measurement(indio_dev,
+ chan->address,
+ val);
+ case (1 << IIO_CHAN_INFO_SCALE_SHARED):
+ *val = 0;
+ *val2 = hmc5843_regval_to_nanoscale[data->range];
+ return IIO_VAL_INT_PLUS_NANO;
+ };
+ return -EINVAL;
}
-static IIO_DEVICE_ATTR(magn_scale,
- S_IRUGO,
- show_scale,
- NULL , 0);
+
+#define HMC5843_CHANNEL(axis, add) \
+ { \
+ .type = IIO_MAGN, \
+ .modified = 1, \
+ .channel2 = IIO_MOD_##axis, \
+ .info_mask = (1 << IIO_CHAN_INFO_SCALE_SHARED), \
+ .address = add \
+ }
+
+static const struct iio_chan_spec hmc5843_channels[] = {
+ HMC5843_CHANNEL(X, HMC5843_DATA_OUT_X_MSB_REG),
+ HMC5843_CHANNEL(Y, HMC5843_DATA_OUT_Y_MSB_REG),
+ HMC5843_CHANNEL(Z, HMC5843_DATA_OUT_Z_MSB_REG),
+};
static struct attribute *hmc5843_attributes[] = {
&iio_dev_attr_meas_conf.dev_attr.attr,
&iio_dev_attr_operating_mode.dev_attr.attr,
&iio_dev_attr_sampling_frequency.dev_attr.attr,
&iio_dev_attr_magn_range.dev_attr.attr,
- &iio_dev_attr_magn_scale.dev_attr.attr,
- &iio_dev_attr_magn_x_raw.dev_attr.attr,
- &iio_dev_attr_magn_y_raw.dev_attr.attr,
- &iio_dev_attr_magn_z_raw.dev_attr.attr,
&iio_const_attr_sampling_frequency_available.dev_attr.attr,
NULL
};
@@ -530,6 +532,7 @@ static void hmc5843_init_client(struct i2c_client *client)
static const struct iio_info hmc5843_info = {
.attrs = &hmc5843_group,
+ .read_raw = &hmc5843_read_raw,
.driver_module = THIS_MODULE,
};
@@ -558,6 +561,9 @@ static int hmc5843_probe(struct i2c_client *client,
hmc5843_init_client(client);
indio_dev->info = &hmc5843_info;
+ indio_dev->name = id->name;
+ indio_dev->channels = hmc5843_channels;
+ indio_dev->num_channels = ARRAY_SIZE(hmc5843_channels);
indio_dev->dev.parent = &client->dev;
indio_dev->modes = INDIO_DIRECT_MODE;
err = iio_device_register(indio_dev);
--
1.7.3.4
next prev parent reply other threads:[~2011-07-01 12:07 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-01 10:10 [PATCH V2 00/25] staging:iio: move chan_spec conversions and general cleanup Jonathan Cameron
2011-07-01 10:10 ` [PATCH 01/25] staging:iio:accel:kxsd9 cleanup and conversion to iio_chan_spec Jonathan Cameron
2011-07-01 10:10 ` [PATCH 02/25] staging:iio: add quadrature correction to chan info types Jonathan Cameron
2011-07-01 10:10 ` [PATCH 03/25] staging:iio:gyro:adxrs450 move to iio_chan_spec registration Jonathan Cameron
2011-07-01 10:10 ` [PATCH 04/25] staging:iio:gyro:adxrs450 make more use of spi_read and spi_write Jonathan Cameron
2011-07-01 10:10 ` [PATCH 05/25] staging:iio:gyro:adxrs450 squish some trivial single call point wrappers functions Jonathan Cameron
2011-07-01 10:10 ` [PATCH 06/25] staging:iio:gyro:adis16080 convert to iio_chan_spec Jonathan Cameron
2011-07-01 10:10 ` [PATCH 07/25] staging:iio:gyro:adis16260 remove some unused headers Jonathan Cameron
2011-07-01 10:10 ` [PATCH 08/25] staging:iio:imu:adis16400 remove " Jonathan Cameron
2011-07-01 10:11 ` [PATCH 09/25] staging:iio:magnetometer:ak8975 convert to iio_chan_spec + cleanups Jonathan Cameron
2011-07-01 10:11 ` [PATCH 10/25] staging:iio:magnetometer:hmc5843 iio_chan_spec conversion Jonathan Cameron
2011-07-01 10:59 ` Manuel Stahl
2011-07-01 12:15 ` Jonathan Cameron [this message]
2011-07-01 10:11 ` [PATCH 11/25] staging:iio:magnetometer: remove unused header magnet.h Jonathan Cameron
2011-07-01 10:11 ` [PATCH 12/25] staging:iio:gyro:adis16130 fix adis16130_spi_read which was never selecting the channel Jonathan Cameron
2011-07-01 10:11 ` [PATCH 13/25] staging:iio:gyro:adis16130 drop control of adc resolution Jonathan Cameron
2011-07-01 10:11 ` [PATCH 14/25] staging:iio:gyro:adis16130 move to iio_chan_spec registration Jonathan Cameron
2011-07-01 10:11 ` [PATCH 15/25] staging:iio:gyro:adis16060 convert to iio_chan_spec Jonathan Cameron
2011-07-01 10:11 ` [PATCH 16/25] staging:iio:gyro: remove gyro.h Jonathan Cameron
2011-07-01 10:11 ` [PATCH 17/25] staging:iio:accel: usused header removals Jonathan Cameron
2011-07-01 10:11 ` [PATCH 18/25] staging:iio:inclinometer.h remove as now unused Jonathan Cameron
2011-07-01 10:11 ` [PATCH 19/25] staging:iio:adc: unused header removals Jonathan Cameron
2011-07-01 10:11 ` [PATCH 20/25] staging:iio:various header includes that should never have been Jonathan Cameron
2011-07-01 10:11 ` [PATCH 21/25] staging:iio:accel:adis16204: use peak_raw info_mask element + push some defs down from header Jonathan Cameron
2011-07-01 10:11 ` [PATCH 22/25] staging:iio:accel:adis16220 iio_chan_spec conversion Jonathan Cameron
2011-07-01 10:11 ` [PATCH 23/25] staging:iio:accel remove unused accel.h header Jonathan Cameron
2011-07-01 10:11 ` [PATCH 24/25] staging:iio:adc remove unused adc.h Jonathan Cameron
2011-07-01 10:11 ` [PATCH 25/25] staging:iio:gyro:adis16260 fix missing num_channels setup 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=4E0DBA76.6050200@cam.ac.uk \
--to=jic23@cam.ac.uk \
--cc=device-drivers-devel@blackfin.uclinux.org \
--cc=ldewangan@nvidia.com \
--cc=linux-iio@vger.kernel.org \
--cc=manuel.stahl@iis.fraunhofer.de \
--cc=shubhrajyoti@ti.com \
/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.