kxcjk-1013 driver optimizations
cover kxcjk-1013 driver optimizations
Adds optimization of i2c transactions in trigger handler and usage of available_scan_masks for kxcjk-1013.
Adriana Reus (2):
iio: accel: kxcjk-1013: use available_scan_masks
iio: accel: kxcjk-1013: optimize i2c transfers in trigger handler
drivers/iio/accel/kxcjk-1013.c | 50 ++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/2 iio: accel: kxcjk-1013: use available_scan_masks
From: Adriana Reus <[email protected]>
Use available_scan_masks to allow the iio core to select the data to send to userspace depending on which axes are enabled, instead of doing this in the driver's interrupt handler.
This also fixes the issue of accessing the buffer scan_mask instead of active_scan_mask, since these might not be the same due to client devices.
--- drivers/iio/accel/kxcjk-1013.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/iio/accel/kxcjk-1013.c +5 -3
@@ -115,6 +115,7 @@ enum kxcjk1013_axis {AXIS_X ,AXIS_Y ,AXIS_Z , + AXIS_MAX, }; enum kxcjk1013_mode {
@@ -947,6 +948,8 @@ static const struct iio_info kxcjk1013_info = { .driver_module = THIS_MODULE, }; +static const unsigned long kxcjk1013_scan_masks[] = {0x7 ,0 }; +static irqreturn_t kxcjk1013_trigger_handler (int irq,void *p) {struct iio_poll_func *pf = p;
@@ -955,9 +958,7 @@ static irqreturn_t kxcjk1013_trigger_handler(int irq, void *p)int bit, ret, i =0 ;mutex_lock (&data->mutex); - -for_each_set_bit (bit, indio_dev->buffer->scan_mask, - indio_dev->masklength) { +for (bit =0 ; bit <AXIS_MAX ; bit++) { ret =kxcjk1013_get_acc_reg (data, bit);if (ret <0 ) {mutex_unlock (&data->mutex);
@@ -1228,6 +1229,7 @@ static int kxcjk1013_probe(struct i2c_client *client, indio_dev->dev.parent = &client->dev; indio_dev->channels = kxcjk1013_channels; indio_dev->num_channels =ARRAY_SIZE (kxcjk1013_channels); + indio_dev->available_scan_masks = kxcjk1013_scan_masks; indio_dev->name = name; indio_dev->modes =INDIO_DIRECT_MODE ; indio_dev->info = &kxcjk1013_info;
Signature · 1 line
1.9.1
PATCH 2/2 iio: accel: kxcjk-1013: optimize i2c transfers in trigger handler
In reply to Irina TirdeaFrom: Adriana Reus <[email protected]>
Some i2c busses (e.g.: Synopsys DesignWare I2C adapter) need to enable/disable the bus at each i2c transfer and must wait for the enable/disable to happen before sending the data.
When reading data in the trigger handler, the kxcjk-1013 accel driver does one i2c transfer for each axis. This has an impact on the frequency of the accelerometer at high sample rates due to additional delays introduced by the i2c bus at each transfer.
Reading all axis values in one i2c transfer reduces the delays introduced by the i2c bus. In case i2c block read is not supported, fallback to reading each axis as a separate word.
--- drivers/iio/accel/kxcjk-1013.c | 44 +++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-)
drivers/iio/accel/kxcjk-1013.c +35 -9
@@ -109,6 +109,8 @@ struct kxcjk1013_data {int64_t timestamp;enum kx_chipset chipset;bool is_smo8500_device; +s32 (*read_block_data)(const struct i2c_client *client,u8 command, +u8 length,u8 *values); };enum kxcjk1013_axis {
@@ -216,6 +218,23 @@ static const struct { {800, 0, 0x06}, {1600, 0, 0x06} }; +static s32 kxcjk1013_read_block_data (const struct i2c_client *client, +u8 command,u8 length,u8 *values) +{ +s32 data; +u8 i; + +for (i =0 ; i < length; i +=2 ) { + data =i2c_smbus_read_word_data (client, command + i); +if (data <0 ) +return data; + + values[i] = data &0xFF ; + values[i+1 ] = data >>8 ; + } +return i; +} +static int kxcjk1013_set_mode (struct kxcjk1013_data *data,enum kxcjk1013_mode mode) {
@@ -955,18 +974,14 @@ static irqreturn_t kxcjk1013_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct kxcjk1013_data *data =iio_priv (indio_dev); -int bit, ret, i =0 ; +int ret;mutex_lock (&data->mutex); -for (bit =0 ; bit <AXIS_MAX ; bit++) { - ret =kxcjk1013_get_acc_reg (data, bit); -if (ret <0 ) { -mutex_unlock (&data->mutex); - goto err; - } - data->buffer[i++] = ret; - } + ret = data->read_block_data (data->client,KXCJK1013_REG_XOUT_L , +AXIS_MAX *2 , (u8 *) data->buffer);mutex_unlock (&data->mutex); +if (ret <0 ) + goto err;iio_push_to_buffers_with_timestamp (indio_dev, data->buffer, data->timestamp);
@@ -1196,6 +1211,11 @@ static int kxcjk1013_probe(struct i2c_client *client,const char *name;int ret; +if (!i2c_check_functionality (client->adapter, +I2C_FUNC_SMBUS_BYTE_DATA | +I2C_FUNC_SMBUS_READ_WORD_DATA )) +return -ENODEV ; + indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data));if (!indio_dev)return -ENOMEM ;
@@ -1204,6 +1224,12 @@ static int kxcjk1013_probe(struct i2c_client *client,i2c_set_clientdata (client, indio_dev); data->client = client; +if (i2c_check_functionality (client->adapter, +I2C_FUNC_SMBUS_READ_I2C_BLOCK )) + data->read_block_data = i2c_smbus_read_i2c_block_data; +else + data->read_block_data = kxcjk1013_read_block_data; + pdata =dev_get_platdata (&client->dev);if (pdata) data->active_high_intr = pdata->active_high_intr;
Signature · 1 line
1.9.1
Re: [PATCH 2/2] iio: accel: kxcjk-1013: optimize i2c transfers in trigger handler
Quoted 4 lines
Reading all axis values in one i2c transfer reduces the delays introduced by the i2c bus. In case i2c block read is not supported, fallback to reading each axis as a separate word.
see comments inline below
Quoted 12 lines
Signed-off-by Adriana Reus <[email protected]>Signed-off-by Irina Tirdea <[email protected]>Reviewed-by Srinivas Pandruvada <[email protected]>--- drivers/iio/accel/kxcjk-1013.c | 44 +++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-)drivers/iio/accel/kxcjk-1013.c +0
-0
drivers/iio/accel/kxcjk-1013.c struct kxcjk1013_data { · line 113
Quoted 5 lines
drivers/iio/accel/kxcjk-1013.c +2
-0@@ -109,6 +109,8 @@ struct kxcjk1013_data {int64_t timestamp;enum kx_chipset chipset;bool is_smo8500_device; +s32 (*read_block_data)(const struct i2c_client *client,u8 command, +u8 length,u8 *values);
probably this could/should be done in the i2c layer or we end up adding a similar function in every driver?
Quoted 10 lines
drivers/iio/accel/kxcjk-1013.c +3
-0};enum kxcjk1013_axis {@@ -216,6 +218,23 @@ static const struct { {800, 0, 0x06}, {1600, 0, 0x06} }; +static s32 kxcjk1013_read_block_data (const struct i2c_client *client, +u8 command,u8 length,u8 *values) +{
drivers/iio/accel/kxcjk-1013.c static const struct { · line 233
Quoted 10 lines
drivers/iio/accel/kxcjk-1013.c +10
-0+s32 data; +u8 i; + +for (i =0 ; i < length; i +=2 ) { + data =i2c_smbus_read_word_data (client, command + i); +if (data <0 ) +return data; + + values[i] = data &0xFF ; + values[i+1 ] = data >>8 ;
this is incorrect; it forces the data to be little endian, however, the endianness (as specified in the driver's .scan_type) is IIO_CPU -- the code breaks for big-endian CPUs
since _read_i2c_block_data() can't do endianness conversion (and the chip does i2c endianness, i.e. little-endian), the .scan_type should become IIO_LE and above code is correct again but still ugly :)
bottom line: change .scan_type to IIO_LE
Quoted 57 lines
drivers/iio/accel/kxcjk-1013.c +20
-9+ } +return i; +} +static int kxcjk1013_set_mode (struct kxcjk1013_data *data,enum kxcjk1013_mode mode) {@@ -955,18 +974,14 @@ static irqreturn_t kxcjk1013_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct kxcjk1013_data *data =iio_priv (indio_dev); -int bit, ret, i =0 ; +int ret;mutex_lock (&data->mutex); -for (bit =0 ; bit <AXIS_MAX ; bit++) { - ret =kxcjk1013_get_acc_reg (data, bit); -if (ret <0 ) { -mutex_unlock (&data->mutex); - goto err; - } - data->buffer[i++] = ret; - } + ret = data->read_block_data (data->client,KXCJK1013_REG_XOUT_L , +AXIS_MAX *2 , (u8 *) data->buffer);mutex_unlock (&data->mutex); +if (ret <0 ) + goto err;iio_push_to_buffers_with_timestamp (indio_dev, data->buffer, data->timestamp);@@ -1196,6 +1211,11 @@ static int kxcjk1013_probe(struct i2c_client *client,const char *name;int ret; +if (!i2c_check_functionality (client->adapter, +I2C_FUNC_SMBUS_BYTE_DATA | +I2C_FUNC_SMBUS_READ_WORD_DATA )) +return -ENODEV ; + indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data));if (!indio_dev)return -ENOMEM ;@@ -1204,6 +1224,12 @@ static int kxcjk1013_probe(struct i2c_client *client,i2c_set_clientdata (client, indio_dev); data->client = client; +if (i2c_check_functionality (client->adapter, +I2C_FUNC_SMBUS_READ_I2C_BLOCK )) + data->read_block_data = i2c_smbus_read_i2c_block_data; +else + data->read_block_data = kxcjk1013_read_block_data; + pdata =dev_get_platdata (&client->dev);if (pdata) data->active_high_intr = pdata->active_high_intr;
Signature · 2 lines
Peter Meerwald +43-664-2444418 (mobile)
RE: [PATCH 2/2] iio: accel: kxcjk-1013: optimize i2c transfers in trigger handler
Quoted 7 lines
-----Original Message-----
From: Peter Meerwald [mailto:[email protected]]
Sent: 16 February, 2015 21:26
To: Tirdea, Irina
Cc: Jonathan Cameron; [email protected]; [email protected]=
.org; Pandruvada, Srinivas; Reus, Adriana
Quoted 1 line
Subject: Re: [PATCH 2/2] iio: accel: kxcjk-1013: optimize i2c transfers i=
n trigger handler
Quoted 8 lines
=20
=20Quoted 3 lines
Reading all axis values in one i2c transfer reduces the delays introduced by the i2c bus. In case i2c block read is not supported, fallback to reading each axis as a separate word.
=20
see comments inline below
=20
Thanks for the review, Peter!
Quoted 5 lines
Quoted 5 lines
Signed-off-by Adriana Reus <[email protected]>Signed-off-by Irina Tirdea <[email protected]>Reviewed-by Srinivas Pandruvada <[email protected]>---
drivers/iio/accel/kxcjk-1013.c| 44 +++++++++++++++++++++++++++++++++-=
--------
Quoted 3 lines
drivers/iio/accel/kxcjk-1=
Quoted 3 lines
1 file changed, 35 insertions(+), 9 deletions(-)drivers/iio/accel/kxcjk-1= renamed from drivers/iio/accel/kxcjk-1013.c +0
-0
013.c
Quoted 5 lines
Quoted 5 lines
index 5f27787..bfa2899 100644
drivers/iio/accel/kxcjk-1013.c +0
-0@@ -109,6 +109,8 @@ struct kxcjk1013_data {int64_t timestamp;
Quoted 8 lines
drivers/iio/accel/kxcjk-1013.c struct kxcjk1013_data { · line 113
Quoted 4 lines
drivers/iio/accel/kxcjk-1013.c +2
-0enum kx_chipset chipset;bool is_smo8500_device; +s32 (*read_block_data)(const struct i2c_client *client,u8 command, +u8 length,u8 *values);=20
probably this could/should be done in the i2c layer or we end up adding a similar function in every driver?
=20
Actually this is exactly what I did: adding this code in a couple of driver= s :)
You are right, this belongs to the i2c core. Will move it there.
Quoted 23 lines
Quoted 10 lines
drivers/iio/accel/kxcjk-1013.c +3
-0};enum kxcjk1013_axis {@@ -216,6 +218,23 @@ static const struct { {800, 0, 0x06}, {1600, 0, 0x06} }; +static s32 kxcjk1013_read_block_data (const struct i2c_client *client, +u8 command,u8 length,u8 *values) +{drivers/iio/accel/kxcjk-1013.c static const struct { · line 233
Quoted 10 lines
drivers/iio/accel/kxcjk-1013.c +10
-0+s32 data; +u8 i; + + for (i =3D 0; i < length; i +=3D 2) { + data =3D i2c_smbus_read_word_data(client, command + i); +if (data <0 ) +return data; + + values[i] =3D data & 0xFF; + values[i+1] =3D data >> 8;=20
this is incorrect; it forces the data to be little endian, however, the endianness (as specified in the driver's .scan_type) isIIO_CPU-- the
Quoted 8 lines
code breaks for big-endian CPUs
=20
since_read_i2c_block_data()can't do endianness conversion (and the chip does i2c endianness, i.e. little-endian), the .scan_type should becomeIIO_LEand above code is correct again but still ugly :)
=20
bottom line: change .scan_type toIIO_LE
=20
Good point. Changing the endianess to IIO_LE is correct for either kxcjk101= 3_read_block_data or i2c_smbus_read_i2c_block_data.
Will fix this in the next version. Thanks for catching this!
Quoted 8 lines
drivers/iio/accel/kxcjk-1013.c static irqreturn_t kxcjk1013_trigger_handler(int =
Quoted 8 lines
drivers/iio/accel/kxcjk-1013.c +4
-0+ } +return i; +} +static int kxcjk1013_set_mode (struct kxcjk1013_data *data,enum kxcjk1013_mode mode) {@@ -955,18 +974,14 @@ static irqreturn_t kxcjk1013_trigger_handler(int =
irq, void *p)
Quoted 21 lines
Quoted 21 lines
drivers/iio/accel/kxcjk-1013.c +5
-9struct iio_poll_func *pf =3D p; struct iio_dev *indio_dev =3D pf->indio_dev; struct kxcjk1013_data *data =3D iio_priv(indio_dev); - int bit, ret, i =3D 0; +int ret;mutex_lock (&data->mutex); - for (bit =3D 0; bit < AXIS_MAX; bit++) { - ret =3D kxcjk1013_get_acc_reg(data, bit); -if (ret <0 ) { -mutex_unlock (&data->mutex); - goto err; - } - data->buffer[i++] =3D ret; - } + ret =3D data->read_block_data(data->client, KXCJK1013_REG_XOUT_L, +AXIS_MAX *2 , (u8 *) data->buffer);mutex_unlock (&data->mutex); +if (ret <0 ) + goto err;
Quoted 3 lines
drivers/iio/accel/kxcjk-1013.c static int kxcjk1013_probe(struct i2c_client *cl=
Quoted 3 lines
drivers/iio/accel/kxcjk-1013.c +0
-0iio_push_to_buffers_with_timestamp (indio_dev, data->buffer, data->timestamp);@@ -1196,6 +1211,11 @@ static int kxcjk1013_probe(struct i2c_client *cl=
ient,
Quoted 12 lines
drivers/iio/accel/kxcjk-1013.c static int kxcjk1013_probe(struct i2c_client *cl=
Quoted 12 lines
drivers/iio/accel/kxcjk-1013.c +5
-0const char *name;int ret; +if (!i2c_check_functionality (client->adapter, +I2C_FUNC_SMBUS_BYTE_DATA | +I2C_FUNC_SMBUS_READ_WORD_DATA )) +return -ENODEV ; + indio_dev =3D devm_iio_device_alloc(&client->dev, sizeof(*data));if (!indio_dev)return -ENOMEM ;@@ -1204,6 +1224,12 @@ static int kxcjk1013_probe(struct i2c_client *cl=
ient,
Quoted 18 lines
drivers/iio/accel/kxcjk-1013.c static int kxcjk1013_probe(struct i2c_client *client,
Quoted 13 lines
drivers/iio/accel/kxcjk-1013.c +6
-0i2c_set_clientdata (client, indio_dev); data->client =3D client; +if (i2c_check_functionality (client->adapter, +I2C_FUNC_SMBUS_READ_I2C_BLOCK )) + data->read_block_data =3D i2c_smbus_read_i2c_block_data; +else + data->read_block_data =3D kxcjk1013_read_block_data; + pdata =3D dev_get_platdata(&client->dev);if (pdata) data->active_high_intr =3D pdata->active_high_intr;=20
--
=20
Peter Meerwald
+43-664-2444418 (mobile)
Re: [PATCH 2/2] iio: accel: kxcjk-1013: optimize i2c transfers in trigger handler
T24gRnJpLCAyMDE1LTAyLTIwIGF0IDEyOjAyICswMDAwLCBUaXJkZWEsIElyaW5hIHdyb3RlOg0K PiANCj4gPiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiA+IEZyb206IFBldGVyIE1lZXJ3 YWxkIFttYWlsdG86cG1lZXJ3QHBtZWVydy5uZXRdDQo+ID4gU2VudDogMTYgRmVicnVhcnksIDIw MTUgMjE6MjYNCj4gPiBUbzogVGlyZGVhLCBJcmluYQ0KPiA+IENjOiBKb25hdGhhbiBDYW1lcm9u OyBsaW51eC1paW9Admdlci5rZXJuZWwub3JnOyBsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3Jn OyBQYW5kcnV2YWRhLCBTcmluaXZhczsgUmV1cywgQWRyaWFuYQ0KPiA+IFN1YmplY3Q6IFJlOiBb UEFUQ0ggMi8yXSBpaW86IGFjY2VsOiBreGNqay0xMDEzOiBvcHRpbWl6ZSBpMmMgdHJhbnNmZXJz IGluIHRyaWdnZXIgaGFuZGxlcg0KPiA+IA0KPiA+IA0KPiA+ID4gUmVhZGluZyBhbGwgYXhpcyB2 YWx1ZXMgaW4gb25lIGkyYyB0cmFuc2ZlciByZWR1Y2VzIHRoZSBkZWxheXMNCj4gPiA+IGludHJv ZHVjZWQgYnkgdGhlIGkyYyBidXMuIEluIGNhc2UgaTJjIGJsb2NrIHJlYWQgaXMgbm90IHN1cHBv cnRlZCwNCj4gPiA+IGZhbGxiYWNrIHRvIHJlYWRpbmcgZWFjaCBheGlzIGFzIGEgc2VwYXJhdGUg d29yZC4NCj4gPiANCj4gPiBzZWUgY29tbWVudHMgaW5saW5l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optimize i2c transfers in trigger handler
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/iio/accel/kxcjk-1013.c static const struct { · line 233
Quoted 4 lines
drivers/iio/accel/kxcjk-1013.c +3
-0+ + values[i] = data &0xFF ; + values[i+1 ] = data >>8 ;this is incorrect; it forces the data to be little endian, however, the endianness (as specified in the driver's .scan_type) is
IIO_CPU-- the code breaks for big-endian CPUssince
_read_i2c_block_data()can't do endianness conversion (and the chip does i2c endianness, i.e. little-endian), the .scan_type should becomeIIO_LEand above code is correct again but still ugly :)
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
bottom line: change .scan_type to
IIO_LEGood point. Changing the endianess to
IIO_LEis correct for eitherkxcjk1013_read_block_dataori2c_smbus_read_i2c_block_data. Will fix this in the next version. Thanks for catching this!I don't think changing to
IIO_LEis good idea as wheni2c_read_bock.. then the scan type will be CPU. So better to fix endianness in this function.
the chip has little-endian data registers; i2c_read_block() just transfers the data (no endianness conversion), so the data will still be little-endian
p.
Signature · 2 lines
Peter Meerwald +43-664-2444418 (mobile)
Re: [PATCH 2/2] iio: accel: kxcjk-1013: optimize i2c transfers in trigger handler
T24gRnJpLCAyMDE1LTAyLTIwIGF0IDE2OjIzICswMTAwLCBQZXRlciBNZWVyd2FsZCB3cm90ZToN Cj4gPiA+ID4gPiArDQo+ID4gPiA+ID4gKwkJdmFsdWVzW2ldID0gZGF0YSAmIDB4RkY7DQo+ID4g PiA+ID4gKwkJdmFsdWVzW2krMV0gPSBkYXRhID4+IDg7DQo+ID4gPiA+IA0KPiA+ID4gPiB0aGlz IGlzIGluY29ycmVjdDsgaXQgZm9yY2VzIHRoZSBkYXRhIHRvIGJlIGxpdHRsZSBlbmRpYW4sIGhv d2V2ZXIsIHRoZQ0KPiA+ID4gPiBlbmRpYW5uZXNzIChhcyBzcGVjaWZpZWQgaW4gdGhlIGRyaXZl cidzIC5zY2FuX3R5cGUpIGlzIElJT19DUFUgLS0gdGhlDQo+ID4gPiA+IGNvZGUgYn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dGhlIGRhdGEgKG5v IGVuZGlhbm5lc3MgY29udmVyc2lvbiksIHNvIHRoZSBkYXRhIHdpbGwgc3RpbGwgYmUgDQo+IGxp dHRsZS1lbmRpYW4NCllvdSBhcmUgcmlnaHQuDQo+IA0KPiBwLg0KPiANCg0K
Jonathan Cameron
maintainerRe: [PATCH 2/2] iio: accel: kxcjk-1013: optimize i2c transfers in trigger handler
In reply to Tirdea, IrinaQuoted 39 lines · Irina
Quoted 10 lines
-----Original Message-----
From: Peter Meerwald [mailto:[email protected]]
Sent: 16 February, 2015 21:26
To: Tirdea, Irina
Cc: Jonathan Cameron; [email protected]; [email protected]; Pandruvada, Srinivas; Reus, Adriana
Subject: Re: [PATCH 2/2] iio: accel: kxcjk-1013: optimize i2c transfers in trigger handlerQuoted 6 lines
Quoted 3 lines
Reading all axis values in one i2c transfer reduces the delays introduced by the i2c bus. In case i2c block read is not supported, fallback to reading each axis as a separate word.
see comments inline below
Thanks for the review, Peter!
Quoted 7 lines
Quoted 7 lines
Signed-off-by Adriana Reus <[email protected]>Signed-off-by Irina Tirdea <[email protected]>Reviewed-by Srinivas Pandruvada <[email protected]>--- drivers/iio/accel/kxcjk-1013.c | 44 +++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-)Quoted 14 lines
drivers/iio/accel/kxcjk-1013.c struct kxcjk1013_data { · line 113
Quoted 10 lines
drivers/iio/accel/kxcjk-1013.c +2
-0@@ -109,6 +109,8 @@ struct kxcjk1013_data {int64_t timestamp;enum kx_chipset chipset;bool is_smo8500_device; +s32 (*read_block_data)(const struct i2c_client *client,u8 command, +u8 length,u8 *values);probably this could/should be done in the i2c layer or we end up adding a similar function in every driver?
Quoted 2 lines
Actually this is exactly what I did: adding this code in a couple of drivers :) You are right, this belongs to the i2c core. Will move it there.
A good idea. Might be possible to make this a transparent fallback so no special handling is needed in drivers at all (e.g. emulate the block read using the biggest read that is available) - taking care about the endian fun and games that results.
Propose it to Wolfram and the i2c list and see what people think of it.
Jonathan
Quoted 97 lines
Quoted 26 lines
Quoted 11 lines
drivers/iio/accel/kxcjk-1013.c +3
-0};enum kxcjk1013_axis {@@ -216,6 +218,23 @@ static const struct { {800, 0, 0x06}, {1600, 0, 0x06} }; +static s32 kxcjk1013_read_block_data (const struct i2c_client *client, +u8 command,u8 length,u8 *values) +{drivers/iio/accel/kxcjk-1013.c static const struct { · line 233
Quoted 10 lines
drivers/iio/accel/kxcjk-1013.c +10
-0+s32 data; +u8 i; + +for (i =0 ; i < length; i +=2 ) { + data =i2c_smbus_read_word_data (client, command + i); +if (data <0 ) +return data; + + values[i] = data &0xFF ; + values[i+1 ] = data >>8 ;this is incorrect; it forces the data to be little endian, however, the endianness (as specified in the driver's .scan_type) is
IIO_CPU-- the code breaks for big-endian CPUsQuoted 6 lines
since
_read_i2c_block_data()can't do endianness conversion (and the chip does i2c endianness, i.e. little-endian), the .scan_type should becomeIIO_LEand above code is correct again but still ugly :)bottom line: change .scan_type to
IIO_LEGood point. Changing the endianess to
IIO_LEis correct for eitherkxcjk1013_read_block_dataori2c_smbus_read_i2c_block_data. Will fix this in the next version. Thanks for catching this!Quoted 62 lines
Quoted 47 lines
drivers/iio/accel/kxcjk-1013.c +14
-9+ } +return i; +} +static int kxcjk1013_set_mode (struct kxcjk1013_data *data,enum kxcjk1013_mode mode) {@@ -955,18 +974,14 @@ static irqreturn_t kxcjk1013_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct kxcjk1013_data *data =iio_priv (indio_dev); -int bit, ret, i =0 ; +int ret;mutex_lock (&data->mutex); -for (bit =0 ; bit <AXIS_MAX ; bit++) { - ret =kxcjk1013_get_acc_reg (data, bit); -if (ret <0 ) { -mutex_unlock (&data->mutex); - goto err; - } - data->buffer[i++] = ret; - } + ret = data->read_block_data (data->client,KXCJK1013_REG_XOUT_L , +AXIS_MAX *2 , (u8 *) data->buffer);mutex_unlock (&data->mutex); +if (ret <0 ) + goto err;iio_push_to_buffers_with_timestamp (indio_dev, data->buffer, data->timestamp);@@ -1196,6 +1211,11 @@ static int kxcjk1013_probe(struct i2c_client *client,const char *name;int ret; +if (!i2c_check_functionality (client->adapter, +I2C_FUNC_SMBUS_BYTE_DATA | +I2C_FUNC_SMBUS_READ_WORD_DATA )) +return -ENODEV ; + indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data));if (!indio_dev)return -ENOMEM ;@@ -1204,6 +1224,12 @@ static int kxcjk1013_probe(struct i2c_client *client,i2c_set_clientdata (client, indio_dev); data->client = client;drivers/iio/accel/kxcjk-1013.c static int kxcjk1013_probe(struct i2c_client *client, · line 1235
Quoted 10 lines
drivers/iio/accel/kxcjk-1013.c +6
-0+if (i2c_check_functionality (client->adapter, +I2C_FUNC_SMBUS_READ_I2C_BLOCK )) + data->read_block_data = i2c_smbus_read_i2c_block_data; +else + data->read_block_data = kxcjk1013_read_block_data; + pdata =dev_get_platdata (&client->dev);if (pdata) data->active_high_intr = pdata->active_high_intr;--
Peter Meerwald
+43-664-2444418 (mobile)
RE: [PATCH 2/2] iio: accel: kxcjk-1013: optimize i2c transfers in trigger handler
Quoted 7 lines
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: 21 February, 2015 20:30
To: Tirdea, Irina; Peter Meerwald
Cc: [email protected]; [email protected]; Pandruvada, =
Srinivas; Reus, Adriana
Quoted 1 line
Subject: Re: [PATCH 2/2] iio: accel: kxcjk-1013: optimize i2c transfers i=
n trigger handler
Quoted 9 lines
=20
Quoted 7 lines · Irina
Quoted 7 lines
-----Original Message-----
From: Peter Meerwald [mailto:[email protected]]
Sent: 16 February, 2015 21:26
To: Tirdea, Irina
Cc: Jonathan Cameron; [email protected]; [email protected]=
nel.org; Pandruvada, Srinivas; Reus, Adriana
Quoted 1 line
Quoted 1 line
Quoted 1 line
Subject: Re: [PATCH 2/2] iio: accel: kxcjk-1013: optimize i2c transfer=
s in trigger handler
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Reading all axis values in one i2c transfer reduces the delays introduced by the i2c bus. In case i2c block read is not supported, fallback to reading each axis as a separate word.
see comments inline below
Quoted 8 lines
Quoted 8 lines
Thanks for the review, Peter!
Quoted 6 lines
Quoted 6 lines
Signed-off-by Adriana Reus <[email protected]>Signed-off-by Irina Tirdea <[email protected]>Reviewed-by Srinivas Pandruvada <[email protected]=---
drivers/iio/accel/kxcjk-1013.c| 44 ++++++++++++++++++++++++++++++++=
+--------- > >>> 1 file changed, 35 insertions(+), 9 deletions(-)
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/iio/accel/kxcjk=
Quoted 2 lines
drivers/iio/accel/kxcjk= renamed from drivers/iio/accel/kxcjk-1013.c +0
-0
-1013.c
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/iio/accel/kxcjk-1013.c struct kxcjk1013_data { · line 113
Quoted 9 lines
index 5f27787..bfa2899 100644
drivers/iio/accel/kxcjk-1013.c +2
-0@@ -109,6 +109,8 @@ struct kxcjk1013_data {int64_t timestamp;enum kx_chipset chipset;bool is_smo8500_device; +s32 (*read_block_data)(const struct i2c_client *client,u8 command, +u8 length,u8 *values);probably this could/should be done in the i2c layer or we end up addin=
g a
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
similar function in every driver?
Actually this is exactly what I did: adding this code in a couple of dr=
ivers :)
Quoted 3 lines
Quoted 1 line
You are right, this belongs to the i2c core. Will move it there.
A good idea. Might be possible to make this a transparent fallback so no special handling is needed in drivers at all (e.g. emulate the block read=
using
Quoted 1 line
the biggest read that is available) - taking care about the endian fun an=
d
Quoted 4 lines
games that results.
=20
Propose it to Wolfram and the i2c list and see what people think of it. =20
I'll do the block emulation code first and send it on the i2c list (still c= hecking some endianness issues).=20
Once I'll have a response for the i2c part, I'll resend these patchsets wit= h the required fixes.
Thanks,
Irina
Quoted 10 lines
Jonathan
Quoted 9 lines
Quoted 9 lines
drivers/iio/accel/kxcjk-1013.c static const struct { · line 221
Quoted 9 lines
drivers/iio/accel/kxcjk-1013.c +1
-0};enum kxcjk1013_axis {@@ -216,6 +218,23 @@ static const struct { {800, 0, 0x06}, {1600, 0, 0x06} }; +static s32 kxcjk1013_read_block_data(const struct i2c_client *client=
,
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/iio/accel/kxcjk-1013.c +6
-0+ u8 command, u8 length, u8 *values) +{ + s32 data; +u8 i; + + for (i =3D 0; i < length; i +=3D 2) {
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/iio/accel/kxcjk-1013.c static const struct {
Quoted 6 lines
drivers/iio/accel/kxcjk-1013.c +6
-0+ data =3D i2c_smbus_read_word_data(client, command + i); +if (data <0 ) +return data; + + values[i] =3D data & 0xFF; + values[i+1] =3D data >> 8;this is incorrect; it forces the data to be little endian, however, th=
e
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
endianness (as specified in the driver's .scan_type) is
IIO_CPU-- the code breaks for big-endian CPUssince
_read_i2c_block_data()can't do endianness conversion (and the c=
hip
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
does i2c endianness, i.e. little-endian), the .scan_type should become
IIO_LEand above code is correct again but still ugly :)bottom line: change .scan_type to
IIO_LEGood point. Changing the endianess to
IIO_LEis correct for either kxcj=
k1013_read_block_data or i2c_smbus_read_i2c_block_data.
Quoted 10 lines
Quoted 10 lines
Will fix this in the next version. Thanks for catching this!
Quoted 8 lines
drivers/iio/accel/kxcjk-1013.c static irqreturn_t kxcjk1013_trigger_handler(in=
Quoted 8 lines
drivers/iio/accel/kxcjk-1013.c +4
-0+ } +return i; +} +static int kxcjk1013_set_mode (struct kxcjk1013_data *data,enum kxcjk1013_mode mode) {@@ -955,18 +974,14 @@ static irqreturn_t kxcjk1013_trigger_handler(in=
t irq, void *p)
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
drivers/iio/accel/kxcjk-1013.c +5
-9struct iio_poll_func *pf =3D p; struct iio_dev *indio_dev =3D pf->indio_dev; struct kxcjk1013_data *data =3D iio_priv(indio_dev); - int bit, ret, i =3D 0; +int ret;mutex_lock (&data->mutex); - for (bit =3D 0; bit < AXIS_MAX; bit++) { - ret =3D kxcjk1013_get_acc_reg(data, bit); -if (ret <0 ) { -mutex_unlock (&data->mutex); - goto err; - } - data->buffer[i++] =3D ret; - } + ret =3D data->read_block_data(data->client, KXCJK1013_REG_XOUT_L, +AXIS_MAX *2 , (u8 *) data->buffer);mutex_unlock (&data->mutex); +if (ret <0 ) + goto err;
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/iio/accel/kxcjk-1013.c static int kxcjk1013_probe(struct i2c_client *=
Quoted 3 lines
drivers/iio/accel/kxcjk-1013.c +0
-0iio_push_to_buffers_with_timestamp (indio_dev, data->buffer, data->timestamp);@@ -1196,6 +1211,11 @@ static int kxcjk1013_probe(struct i2c_client *=
client,
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/iio/accel/kxcjk-1013.c static int kxcjk1013_probe(struct i2c_client *=
Quoted 12 lines
drivers/iio/accel/kxcjk-1013.c +5
-0const char *name;int ret; +if (!i2c_check_functionality (client->adapter, +I2C_FUNC_SMBUS_BYTE_DATA | +I2C_FUNC_SMBUS_READ_WORD_DATA )) +return -ENODEV ; + indio_dev =3D devm_iio_device_alloc(&client->dev, sizeof(*data));if (!indio_dev)return -ENOMEM ;@@ -1204,6 +1224,12 @@ static int kxcjk1013_probe(struct i2c_client *=
client,
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
drivers/iio/accel/kxcjk-1013.c static int kxcjk1013_probe(struct i2c_client *client,
Quoted 13 lines
drivers/iio/accel/kxcjk-1013.c +6
-0i2c_set_clientdata (client, indio_dev); data->client =3D client; +if (i2c_check_functionality (client->adapter, +I2C_FUNC_SMBUS_READ_I2C_BLOCK )) + data->read_block_data =3D i2c_smbus_read_i2c_block_data; +else + data->read_block_data =3D kxcjk1013_read_block_data; + pdata =3D dev_get_platdata(&client->dev);if (pdata) data->active_high_intr =3D pdata->active_high_intr;--
Peter Meerwald
+43-664-2444418 (mobile)
Quoted 3 lines
Adds optimization of i2c transactions in trigger handler and usage of
available_scan_masksfor kxcjk-1013.
the 'optimization' changes the capabilities of the driver, reading individual channel is not possible anymore
Quoted 8 lines
Adriana Reus (2):
iio: accel: kxcjk-1013: useavailable_scan_masks
iio: accel: kxcjk-1013: optimize i2c transfers in trigger handlerdrivers/iio/accel/kxcjk-1013.c | 50 ++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-)
Signature · 2 lines
Peter Meerwald +43-664-2444418 (mobile)
Quoted 10 lines
-----Original Message-----
From: Peter Meerwald [mailto:[email protected]]
Sent: 16 February, 2015 21:14
To: Tirdea, Irina
Cc: Jonathan Cameron; [email protected]; [email protected]; Pandruvada, Srinivas; Reus, Adriana
Subject: Re: [PATCH 0/2] kxcjk-1013 driver optimizations
Quoted 6 lines
Quoted 2 lines
Adds optimization of i2c transactions in trigger handler and usage of
available_scan_masksfor kxcjk-1013.the 'optimization' changes the capabilities of the driver, reading individual channel is not possible anymore
We can still read individual channels, just that the driver does not see that anymore and the demux is handled by the iio core.available_scan_masks contains the bitmap superset for all channels we can enable (I will remove the 0 available_scan_mask as it does not makes sense).
When a new channel is enabled, the iio core checks if the new mask is a subset of any entry in available_scan_masks. When the buffer is pushed from the driver, the iio core will select only the enabled channel values.
Quoted 13 lines
Quoted 8 lines
Adriana Reus (2):
iio: accel: kxcjk-1013: useavailable_scan_masks
iio: accel: kxcjk-1013: optimize i2c transfers in trigger handlerdrivers/iio/accel/kxcjk-1013.c | 50 ++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-)--
Peter Meerwald
+43-664-2444418 (mobile)
Jonathan Cameron
maintainerQuoted 10 lines · Irina
Quoted 10 lines
-----Original Message-----
From: Peter Meerwald [mailto:[email protected]]
Sent: 16 February, 2015 21:14
To: Tirdea, Irina
Cc: Jonathan Cameron; [email protected]; [email protected]; Pandruvada, Srinivas; Reus, Adriana
Subject: Re: [PATCH 0/2] kxcjk-1013 driver optimizations
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Adds optimization of i2c transactions in trigger handler and usage of
available_scan_masksfor kxcjk-1013.the 'optimization' changes the capabilities of the driver, reading individual channel is not possible anymore
We can still read individual channels, just that the driver does not see that anymore and the demux is handled by the iio core.
available_scan_maskscontains the bitmap superset for all channels we can enable (I will remove the 0available_scan_maskas it does not makes sense).
Careful. That's there as a null terminator for this list of available scan masks.
Quoted 2 lines
When a new channel is enabled, the iio core checks if the new mask is a subset of any entry in
available_scan_masks. When the buffer is pushed from the driver, the iio core will select only the enabled channel values.
Pretty much. IIRC This originally went in as part of handling multiple clients on these data streams, but it was rapidly pointed out that lots of drivers spun their own versions to break out particular elements from a multichannel read.
As such, using the generic form saved on repetition in these cases as well. A good, complex example is drivers/iio/adc/max1363 in which really weird combinations of channels (but far from all) are available for bulk capture and reading.
Quoted 19 lines
Quoted 10 lines
Quoted 9 lines
Adriana Reus (2):
iio: accel: kxcjk-1013: useavailable_scan_masks
iio: accel: kxcjk-1013: optimize i2c transfers in trigger handlerdrivers/iio/accel/kxcjk-1013.c | 50 ++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-)Quoted 4 lines
--
Peter Meerwald
+43-664-2444418 (mobile)--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 23 lines
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: 21 February, 2015 20:27
To: Tirdea, Irina; Peter Meerwald
Cc: [email protected]; [email protected]; Pandruvada, Srinivas; Reus, Adriana
Subject: Re: [PATCH 0/2] kxcjk-1013 driver optimizationsQuoted 13 lines · Irina
Quoted 13 lines
-----Original Message-----
From: Peter Meerwald [mailto:[email protected]]
Sent: 16 February, 2015 21:14
To: Tirdea, Irina
Cc: Jonathan Cameron; [email protected]; [email protected]; Pandruvada, Srinivas; Reus, Adriana
Subject: Re: [PATCH 0/2] kxcjk-1013 driver optimizationsQuoted 2 lines
Adds optimization of i2c transactions in trigger handler and usage of
available_scan_masksfor kxcjk-1013.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
the 'optimization' changes the capabilities of the driver, reading individual channel is not possible anymore
We can still read individual channels, just that the driver does not see that anymore and the demux is handled by the iio core.
available_scan_maskscontains the bitmap superset for all channels we can enable (I will remove the 0available_scan_maskas itdoes not makes sense).
Careful. That's there as a null terminator for this list of available scan masks.
Missed this. You are right, thanks! Seems it's good as is.
Quoted 28 lines
Quoted 2 lines
When a new channel is enabled, the iio core checks if the new mask is a subset of any entry in
available_scan_masks. When the buffer is pushed from the driver, the iio core will select only the enabled channel values.Pretty much. IIRC This originally went in as part of handling multiple clients on these data streams, but it was rapidly pointed out that lots of drivers spun their own versions to break out particular elements from a multichannel read.
As such, using the generic form saved on repetition in these cases as well. A good, complex example isdrivers/iio/adc/max1363in which really weird combinations of channels (but far from all) are available for bulk capture and reading.Quoted 19 lines
Quoted 10 lines
Quoted 9 lines
Adriana Reus (2):
iio: accel: kxcjk-1013: useavailable_scan_masks
iio: accel: kxcjk-1013: optimize i2c transfers in trigger handlerdrivers/iio/accel/kxcjk-1013.c | 50 ++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-)Quoted 4 lines
--
Peter Meerwald
+43-664-2444418 (mobile)--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html