Skip to contentSkip to conversation

iio:magnetometer:ak8975 cleanup and move out of staging.

PATCH In review Jonathan Cameron 2 participants 9 messages Mar 24, 2013 – Apr 2, 2013

Subsystems (3)
lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

cover iio:magnetometer:ak8975 cleanup and move out of staging.

When I proposed moving this out of staging a while back, Lars-Peter pointed out a few 'unusual' elements in the driver. This series addresses those and the interesting question of what the NOSTART flag was doing there in the read code (came up in the dicussion of one of Lars-Peter's points).

The caching in the write is a little unnecessary, but isn't technically incorrect so I haven't touched that.

If anyone has one of these to test and make sure the changes haven't broken anything that would be great!

Thanks,

Jonathan

Jonathan Cameron (4):
staging:iio:magnetometer:ak8975 drop unused eoc_irq staging:iio:magnetometer:ak8975 drop I2C_M_NOSTART flag in read_data staging:iio:magnetometer:ak8975 use standard i2c_smbus read functions. iio:magnetometer:ak8975 move driver out of staging

 drivers/iio/magnetometer/Kconfig          |  11 +
 drivers/iio/magnetometer/Makefile         |   1 +
 drivers/iio/magnetometer/ak8975.c         | 485 ++++++++++++++++++++++++++++
 drivers/staging/iio/magnetometer/Kconfig  |  11 -
 drivers/staging/iio/magnetometer/Makefile |   1 -
 drivers/staging/iio/magnetometer/ak8975.c | 520 ------------------------------
 6 files changed, 497 insertions(+), 532 deletions(-)
 create mode 100644 drivers/iio/magnetometer/ak8975.c
 delete mode 100644 drivers/staging/iio/magnetometer/ak8975.c
Signature · 1 line
1.8.1.4
author maintainer
#1 lore raw

PATCH 1/4 staging:iio:magnetometer:ak8975 drop unused eoc_irq

---
 drivers/staging/iio/magnetometer/ak8975.c | 2 --
 1 file changed, 2 deletions(-)
drivers/staging/iio/magnetometer/ak8975.c +0 -2
index b614da1..8726ea1 100644
@@ -94,7 +94,6 @@ struct ak8975_data {
 	long			raw_to_gauss[3];
 	u8			reg_cache[AK8975_MAX_REGS];
 	int			eoc_gpio;
-	int			eoc_irq;
 };
 
 static const int ak8975_index_to_reg[] = {
@@ -452,7 +451,6 @@ static int ak8975_probe(struct i2c_client *client,
 
 	data->client = client;
 	mutex_init(&data->lock);
-	data->eoc_irq = client->irq;
 	data->eoc_gpio = eoc_gpio;
 	indio_dev->dev.parent = &client->dev;
 	indio_dev->channels = ak8975_channels;
Signature · 1 line
1.8.1.4
author maintainer
#2 lore raw

PATCH 2/4 staging:iio:magnetometer:ak8975 drop I2C_M_NOSTART flag in read_data

In reply to Jonathan Cameron

This flag makes no sense whatsoever where it is.
Documentation/i2c/i2c-protocol states:

If you set the I2C_M_NOSTART variable for the first partial message, we do not generate Addr, but we do generate the startbit S. This will probably confuse all other clients on your bus, so don't try this.

This is exactly what is going on here. Likelihood given that the driver never checked for this protocol mangling being available is that it wasn't present on the test boards and hence this flag was simply ignored. No indication of why it would be necessary has been found in the datasheets.

---
 drivers/staging/iio/magnetometer/ak8975.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/iio/magnetometer/ak8975.c +0 -1
index 8726ea1..1428849 100644
@@ -132,7 +132,6 @@ static int ak8975_read_data(struct i2c_client *client,
 	struct i2c_msg msg[2] = {
 		{
 			.addr = client->addr,
-			.flags = I2C_M_NOSTART,
 			.len = 1,
 			.buf = &reg,
 		}, {
Signature · 1 line
1.8.1.4
author maintainer
#3 lore raw

PATCH 3/4 staging:iio:magnetometer:ak8975 use standard i2c_smbus read functions.

In reply to Jonathan Cameron

Now the mysterious NOSTART flag is gone from the read, we can use the i2c_smbus_read_byte/word/i2c_block_data functions instead of the local reimplementation of these standard functions.

---
 drivers/staging/iio/magnetometer/ak8975.c | 66 ++++++++-----------------------
 1 file changed, 17 insertions(+), 49 deletions(-)
drivers/staging/iio/magnetometer/ak8975.c +17 -49
index 1428849..af6c320 100644
@@ -123,35 +123,6 @@ static int ak8975_write_data(struct i2c_client *client,
 }
 
 /*
- * Helper function to read a contiguous set of the I2C device's registers.
- */
-static int ak8975_read_data(struct i2c_client *client,
-			    u8 reg, u8 length, u8 *buffer)
-{
-	int ret;
-	struct i2c_msg msg[2] = {
-		{
-			.addr = client->addr,
-			.len = 1,
-			.buf = &reg,
-		}, {
-			.addr = client->addr,
-			.flags = I2C_M_RD,
-			.len = length,
-			.buf = buffer,
-		}
-	};
-
-	ret = i2c_transfer(client->adapter, msg, 2);
-	if (ret < 0) {
-		dev_err(&client->dev, "Read from device fails\n");
-		return ret;
-	}
-
-	return 0;
-}
-
-/*
  * Perform some start-of-day setup, including reading the asa calibration
  * values and caching them.
  */
@@ -163,11 +134,12 @@ static int ak8975_setup(struct i2c_client *client)
 	int ret;
 
 	/* Confirm that the device we're talking to is really an AK8975. */
-	ret = ak8975_read_data(client, AK8975_REG_WIA, 1, &device_id);
+	ret = i2c_smbus_read_byte_data(client, AK8975_REG_WIA);
 	if (ret < 0) {
 		dev_err(&client->dev, "Error reading WIA\n");
 		return ret;
 	}
+	device_id = ret;
 	if (device_id != AK8975_DEVICE_ID) {
 		dev_err(&client->dev, "Device ak8975 not found\n");
 		return -ENODEV;
@@ -185,7 +157,8 @@ static int ak8975_setup(struct i2c_client *client)
 	}
 
 	/* Get asa data and store in the device data. */
-	ret = ak8975_read_data(client, AK8975_REG_ASAX, 3, data->asa);
+	ret = i2c_smbus_read_i2c_block_data(client, AK8975_REG_ASAX,
+					    3, data->asa);
 	if (ret < 0) {
 		dev_err(&client->dev, "Not able to read asa data\n");
 		return ret;
@@ -247,7 +220,6 @@ static int ak8975_setup(struct i2c_client *client)
 static int wait_conversion_complete_gpio(struct ak8975_data *data)
 {
 	struct i2c_client *client = data->client;
-	u8 read_status;
 	u32 timeout_ms = AK8975_MAX_CONVERSION_TIMEOUT;
 	int ret;
 
@@ -263,12 +235,11 @@ static int wait_conversion_complete_gpio(struct ak8975_data *data)
 		return -EINVAL;
 	}
 
-	ret = ak8975_read_data(client, AK8975_REG_ST1, 1, &read_status);
-	if (ret < 0) {
+	ret = i2c_smbus_read_byte_data(client, AK8975_REG_ST1);
+	if (ret < 0)
 		dev_err(&client->dev, "Error in reading ST1\n");
-		return ret;
-	}
-	return read_status;
+
+	return ret;
 }
 
 static int wait_conversion_complete_polled(struct ak8975_data *data)
@@ -281,11 +252,12 @@ static int wait_conversion_complete_polled(struct ak8975_data *data)
 	/* Wait for the conversion to complete. */
 	while (timeout_ms) {
 		msleep(AK8975_CONVERSION_DONE_POLL_TIME);
-		ret = ak8975_read_data(client, AK8975_REG_ST1, 1, &read_status);
+		ret = i2c_smbus_read_byte_data(client, AK8975_REG_ST1);
 		if (ret < 0) {
 			dev_err(&client->dev, "Error in reading ST1\n");
 			return ret;
 		}
+		read_status = ret;
 		if (read_status)
 			break;
 		timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME;
@@ -306,7 +278,6 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
 	struct i2c_client *client = data->client;
 	u16 meas_reg;
 	s16 raw;
-	u8 read_status;
 	int ret;
 
 	mutex_lock(&data->lock);
@@ -330,18 +301,15 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
 	if (ret < 0)
 		goto exit;
 
-	read_status = ret;
-
-	if (read_status & AK8975_REG_ST1_DRDY_MASK) {
-		ret = ak8975_read_data(client, AK8975_REG_ST2, 1, &read_status);
+	if (ret & AK8975_REG_ST1_DRDY_MASK) {
+		ret = i2c_smbus_read_byte_data(client, AK8975_REG_ST2);
 		if (ret < 0) {
 			dev_err(&client->dev, "Error in reading ST2\n");
 			goto exit;
 		}
-		if (read_status & (AK8975_REG_ST2_DERR_MASK |
-				   AK8975_REG_ST2_HOFL_MASK)) {
-			dev_err(&client->dev, "ST2 status error 0x%x\n",
-				read_status);
+		if (ret & (AK8975_REG_ST2_DERR_MASK |
+			   AK8975_REG_ST2_HOFL_MASK)) {
+			dev_err(&client->dev, "ST2 status error 0x%x\n", ret);
 			ret = -EINVAL;
 			goto exit;
 		}
@@ -349,12 +317,12 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
 
 	/* Read the flux value from the appropriate register
 	   (the register is specified in the iio device attributes). */
-	ret = ak8975_read_data(client, ak8975_index_to_reg[index],
-			       2, (u8 *)&meas_reg);
+	ret = i2c_smbus_read_word_data(client, ak8975_index_to_reg[index]);
 	if (ret < 0) {
 		dev_err(&client->dev, "Read axis data fails\n");
 		goto exit;
 	}
+	meas_reg = ret;
 
 	mutex_unlock(&data->lock);
 
Signature · 1 line
1.8.1.4
author maintainer
#4 lore raw

PATCH 4/4 iio:magnetometer:ak8975 move driver out of staging

In reply to Jonathan Cameron

Issues raised in last series to propose this have now been resolved so there should be no reason this driver cannot graduate from staging.

---
 drivers/iio/magnetometer/Kconfig          |  11 +
 drivers/iio/magnetometer/Makefile         |   1 +
 drivers/iio/magnetometer/ak8975.c         | 485 ++++++++++++++++++++++++++++++
 drivers/staging/iio/magnetometer/Kconfig  |  11 -
 drivers/staging/iio/magnetometer/Makefile |   1 -
 drivers/staging/iio/magnetometer/ak8975.c | 485 ------------------------------
 6 files changed, 497 insertions(+), 497 deletions(-)
drivers/iio/magnetometer/Kconfig +11 -0
index cd29be5..bd1cfb6 100644
@@ -3,6 +3,17 @@
 #
 menu "Magnetometer sensors"
 
+config AK8975
+	tristate "Asahi Kasei AK8975 3-Axis Magnetometer"
+	depends on I2C
+	depends on GPIOLIB
+	help
+	  Say yes here to build support for Asahi Kasei AK8975 3-Axis
+	  Magnetometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called ak8975.
+
 config HID_SENSOR_MAGNETOMETER_3D
 	depends on HID_SENSOR_HUB
 	select IIO_BUFFER
drivers/iio/magnetometer/Makefile +1 -0
index e786728..7f328e3 100644
@@ -2,6 +2,7 @@
 # Makefile for industrial I/O Magnetometer sensor drivers
 #
 
+obj-$(CONFIG_AK8975)	+= ak8975.o
 obj-$(CONFIG_HID_SENSOR_MAGNETOMETER_3D) += hid-sensor-magn-3d.o
 
 obj-$(CONFIG_IIO_ST_MAGN_3AXIS) += st_magn.o
drivers/iio/magnetometer/ak8975.c new file +485 -0

485 lines not on this page · raw message

drivers/staging/iio/magnetometer/Kconfig +0 -11
index df5e0d4..a3ea69e 100644
@@ -3,17 +3,6 @@
 #
 menu "Magnetometer sensors"
 
-config SENSORS_AK8975
-	tristate "Asahi Kasei AK8975 3-Axis Magnetometer"
-	depends on I2C
-	depends on GPIOLIB
-	help
-	  Say yes here to build support for Asahi Kasei AK8975 3-Axis
-	  Magnetometer.
-
-	  To compile this driver as a module, choose M here: the module
-	  will be called ak8975.
-
 config SENSORS_HMC5843
 	tristate "Honeywell HMC5843/5883/5883L 3-Axis Magnetometer"
 	depends on I2C
drivers/staging/iio/magnetometer/Makefile +0 -1
index f2a753f..f9bfb2e 100644
@@ -2,5 +2,4 @@
 # Makefile for industrial I/O Magnetometer sensors
 #
 
-obj-$(CONFIG_SENSORS_AK8975)	+= ak8975.o
 obj-$(CONFIG_SENSORS_HMC5843)	+= hmc5843.o
drivers/staging/iio/magnetometer/ak8975.c deleted +0 -485

485 lines not on this page · raw message

Signature · 1 line
1.8.1.4
author maintainer
#5 lore raw
In reply to Jonathan Cameron

Laxman, any thoughts on these?

I'm not in an immediate rush with this series, but have never been in favour of keeping things queued up for too long!

Jonathan

Quoted 32 lines · Jonathan Cameron

When I proposed moving this out of staging a while back, Lars-Peter pointed out a few 'unusual' elements in the driver. This series addresses those and the interesting question of what the NOSTART flag was doing there in the read code (came up in the dicussion of one of Lars-Peter's points).

The caching in the write is a little unnecessary, but isn't technically incorrect so I haven't touched that.

If anyone has one of these to test and make sure the changes haven't broken anything that would be great!

Thanks,

Jonathan

Jonathan Cameron (4):
staging:iio:magnetometer:ak8975 drop unused eoc_irq staging:iio:magnetometer:ak8975 drop I2C_M_NOSTART flag in read_data staging:iio:magnetometer:ak8975 use standard i2c_smbus read functions. iio:magnetometer:ak8975 move driver out of staging

 drivers/iio/magnetometer/Kconfig          |  11 +
 drivers/iio/magnetometer/Makefile         |   1 +
 drivers/iio/magnetometer/ak8975.c         | 485 ++++++++++++++++++++++++++++
 drivers/staging/iio/magnetometer/Kconfig  |  11 -
 drivers/staging/iio/magnetometer/Makefile |   1 -
 drivers/staging/iio/magnetometer/ak8975.c | 520 ------------------------------
 6 files changed, 497 insertions(+), 532 deletions(-)
 create mode 100644 drivers/iio/magnetometer/ak8975.c
 delete mode 100644 drivers/staging/iio/magnetometer/ak8975.c
#6 lore raw
Quoted 4 lines · Jonathan Cameron

Laxman, any thoughts on these?

I'm not in an immediate rush with this series, but have never been in favour of keeping things queued up for too long!

Hi Jonathan,
Sorry for missing this patch series.

I will go through this carefully and will update.

Thanks,
Laxman

Acked-by on the v1 series
#7 lore raw
In reply to Jonathan Cameron
Quoted 6 lines · Jonathan Cameron

When I proposed moving this out of staging a while back, Lars-Peter pointed out a few 'unusual' elements in the driver. This series addresses those and the interesting question of what the NOSTART flag was doing there in the read code (came up in the dicussion of one of Lars-Peter's points).

Quoted 7 lines

The caching in the write is a little unnecessary, but isn't technically incorrect so I haven't touched that.

If anyone has one of these to test and make sure the changes haven't broken anything that would be great!

Thanks,

This series looks good.

author maintainer Applied
#8 lore raw
Quoted 10 lines · Laxman Dewangan
Quoted 9 lines · Jonathan Cameron

When I proposed moving this out of staging a while back, Lars-Peter pointed out a few 'unusual' elements in the driver. This series addresses those and the interesting question of what the NOSTART flag was doing there in the read code (came up in the dicussion of one of Lars-Peter's points).

The caching in the write is a little unnecessary, but isn't technically incorrect so I haven't touched that.

Quoted 8 lines
Quoted 4 lines

If anyone has one of these to test and make sure the changes haven't broken anything that would be great!

Thanks,

This series looks good.

Thanks, applied to the togreg branch of iio.git