staging:iio:hmc5843: Few adjustments and support for hmc5983
Subsystems (3)
v4 cover staging:iio:hmc5843: Few adjustments and support for hmc5983
This patch series modifies the hmc5843 driver to support the hmc5983 i2c and spi interfaces.
v2:
* Reverted the changed order of iio unregister and setting hmc mode to sleep
v3:
* Fixed bug introduced in the first patch
* Readded few comment lines which have gone missing in the hmc5843.c -> hmc5843_core.c move
v4:
* Changes suggested by Lars in https://lkml.org/lkml/2014/7/14/968
* The i2c and spi drivers are now user-selectable with the core driver being selected automatically
* The regmap_config structs in both _spi and _i2c files are now static
* The iio_dev allocation is now done in the common function
* pm ops are now defined in the header file and the same definition is shared between both interface-specific drivers
* regmap tables in hmc5843.h are not longer static (this fixed bunch of variable not used warnings)
Jonathan, the patch series applies cleanly against mainline (for me at least), maybe you already have some hmc5843 related patches in your tree which are not yet in upstream? (probably https://lkml.org/lkml/2014/2/14/312)
Josef Gajdusek (5):
staging:iio:hmc5843: Added regmap support staging:iio:hmc5843: Split hmc5843.c to multiple files staging:iio:hmc5843: register <-> value arrays now can have different
lengths
staging:iio:hmc5843: Add support for i2c hmc5983 staging:iio:hmc5843: Add support for spi hmc5983
drivers/staging/iio/magnetometer/Kconfig | 30 +- drivers/staging/iio/magnetometer/Makefile | 4 +- drivers/staging/iio/magnetometer/hmc5843.c | 652 ------------------------ drivers/staging/iio/magnetometer/hmc5843.h | 86 ++++ drivers/staging/iio/magnetometer/hmc5843_core.c | 638 +++++++++++++++++++++++ drivers/staging/iio/magnetometer/hmc5843_i2c.c | 74 +++ drivers/staging/iio/magnetometer/hmc5843_spi.c | 73 +++ 7 files changed, 900 insertions(+), 657 deletions(-) delete mode 100644 drivers/staging/iio/magnetometer/hmc5843.c create mode 100644 drivers/staging/iio/magnetometer/hmc5843.h create mode 100644 drivers/staging/iio/magnetometer/hmc5843_core.c create mode 100644 drivers/staging/iio/magnetometer/hmc5843_i2c.c create mode 100644 drivers/staging/iio/magnetometer/hmc5843_spi.c
Signature · 1 line
1.8.5.5
PATCH v4 1/5 staging:iio:hmc5843: Added regmap support
This patch changes hmc5843.c to use regmap. This provides transparent caching to the code as well as abstraction necessary to add support for SPI-based hmc5983.
--- drivers/staging/iio/magnetometer/Kconfig | 1 + drivers/staging/iio/magnetometer/hmc5843.c | 140 +++++++++++++++++++---------- 2 files changed, 96 insertions(+), 45 deletions(-)
drivers/staging/iio/magnetometer/Kconfig +1 -0
@@ -8,6 +8,7 @@ config SENSORS_HMC5843 depends on I2C select IIO_BUFFER select IIO_TRIGGERED_BUFFER + select REGMAP_I2C help Say Y here to add support for the Honeywell HMC5843, HMC5883 and HMC5883L 3-Axis Magnetometer (digital compass).
drivers/staging/iio/magnetometer/hmc5843.c +95 -45
263 lines not on this page · raw message
Signature · 1 line
1.8.5.5
PATCH v4 2/5 staging:iio:hmc5843: Split hmc5843.c to multiple files
In reply to Josef GajdusekThis patch splits hmc5843.c to multiple files - the interface-agnostic hmc5843_core.c, i2c specific hmc5843_i2c.c and header file hmc5843.h. This is another step to add support of SPI-enabled hmc5983.
---
drivers/staging/iio/magnetometer/Kconfig | 14 +-
drivers/staging/iio/magnetometer/Makefile | 3 +-
drivers/staging/iio/magnetometer/hmc5843.h | 85 ++++++++++++
.../iio/magnetometer/{hmc5843.c => hmc5843_core.c} | 152 +++++----------------
drivers/staging/iio/magnetometer/hmc5843_i2c.c | 73 ++++++++++
5 files changed, 201 insertions(+), 126 deletions(-)
create mode 100644 drivers/staging/iio/magnetometer/hmc5843.h
rename drivers/staging/iio/magnetometer/{hmc5843.c => hmc5843_core.c} (80%)
create mode 100644 drivers/staging/iio/magnetometer/hmc5843_i2c.cdrivers/staging/iio/magnetometer/Kconfig +10 -4
@@ -4,16 +4,22 @@ menu "Magnetometer sensors" config SENSORS_HMC5843 - tristate "Honeywell HMC5843/5883/5883L 3-Axis Magnetometer" - depends on I2C + tristate select IIO_BUFFER select IIO_TRIGGERED_BUFFER + +config SENSORS_HMC5843_I2C + tristate "Honeywell HMC5843/5883/5883L 3-Axis Magnetometer (I2C)" + depends on I2C + select SENSORS_HMC5843 select REGMAP_I2C help Say Y here to add support for the Honeywell HMC5843, HMC5883 and HMC5883L 3-Axis Magnetometer (digital compass). - To compile this driver as a module, choose M here: the module - will be called hmc5843. + This driver can also be compiled as a set of modules. + If so, these modules will be created: + - hmc5843_core (core functions) + - hmc5843_i2c (support for HMC5843, HMC5883 and HMC5883L) endmenu
drivers/staging/iio/magnetometer/Makefile +2 -1
@@ -2,4 +2,5 @@ # Makefile for industrial I/O Magnetometer sensors # -obj-$(CONFIG_SENSORS_HMC5843) += hmc5843.o +obj-$(CONFIG_SENSORS_HMC5843) += hmc5843_core.o +obj-$(CONFIG_SENSORS_HMC5843_I2C) += hmc5843_i2c.o
drivers/staging/iio/magnetometer/hmc5843.h new file +85 -0
85 lines not on this page · raw message
drivers/staging/iio/magnetometer/hmc5843_core.c renamed from drivers/staging/iio/magnetometer/hmc5843.c +31 -121
224 lines not on this page · raw message
drivers/staging/iio/magnetometer/hmc5843_i2c.c new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
1.8.5.5
PATCH v4 3/5 staging:iio:hmc5843: register <-> value arrays now can have different lengths
In reply to Josef GajdusekChanged structure of struct hmc5843_chip_info to include length of translation arrays. Code previously using #defined constant has been changed accordingly. This allows to integrate devices which do have different amounts of available rates/scales.
--- drivers/staging/iio/magnetometer/hmc5843_core.c | 34 +++++++++++++++++-------- 1 file changed, 23 insertions(+), 11 deletions(-)
drivers/staging/iio/magnetometer/hmc5843_core.c +23 -11
@@ -39,7 +39,6 @@*/ #define HMC5843_RANGE_GAIN_OFFSET 0x05#define HMC5843_RANGE_GAIN_DEFAULT 0x01 -#define HMC5843_RANGE_GAINS 8#define HMC5843_RANGE_GAIN_MASK 0xe0/* Device status */
@@ -59,7 +58,6 @@*/ #define HMC5843_RATE_OFFSET 0x02#define HMC5843_RATE_DEFAULT 0x04 -#define HMC5843_RATES 7#define HMC5843_RATE_MASK 0x1c/* Device measurement configuration */
@@ -69,15 +67,15 @@#define HMC5843_MEAS_CONF_MASK 0x03/* Scaling factors: 10000000/Gain */ -static const int hmc5843_regval_to_nanoscale[HMC5843_RANGE_GAINS ] = { +static const int hmc5843_regval_to_nanoscale[] = {6173 ,7692 ,10309 ,12821 ,18868 ,21739 ,25641 ,35714 }; -static const int hmc5883_regval_to_nanoscale[HMC5843_RANGE_GAINS ] = { +static const int hmc5883_regval_to_nanoscale[] = {7812 ,9766 ,13021 ,16287 ,24096 ,27701 ,32573 ,45662 }; -static const int hmc5883l_regval_to_nanoscale[HMC5843_RANGE_GAINS ] = { +static const int hmc5883l_regval_to_nanoscale[] = {7299 ,9174 ,12195 ,15152 ,22727 ,25641 ,30303 ,43478 };
@@ -94,11 +92,11 @@ static const int hmc5883l_regval_to_nanoscale[HMC5843_RANGE_GAINS] = {* 6 | 50 | 75 * 7 | Not used | Not used */ -static const int hmc5843_regval_to_samp_freq[7 ][2 ] = { +static const int hmc5843_regval_to_samp_freq[][2 ] = { {0 ,500000 }, {1 ,0 }, {2 ,0 }, {5 ,0 }, {10 ,0 }, {20 ,0 }, {50 ,0 } }; -static const int hmc5883_regval_to_samp_freq[7 ][2 ] = { +static const int hmc5883_regval_to_samp_freq[][2 ] = { {0 ,750000 }, {1 ,500000 }, {3 ,0 }, {7 ,500000 }, {15 ,0 }, {30 ,0 }, {75 ,0 } };
@@ -107,7 +105,9 @@ static const int hmc5883_regval_to_samp_freq[7][2] = {struct hmc5843_chip_info {const struct iio_chan_spec *channels;const int (*regval_to_samp_freq)[2 ]; +const int n_regval_to_samp_freq;const int *regval_to_nanoscale; +const int n_regval_to_nanoscale; };/* The lower two bits contain the current conversion mode */
@@ -248,7 +248,7 @@ static ssize_t hmc5843_show_samp_freq_avail(struct device *dev,size_t len =0 ;int i; -for (i =0 ; i <HMC5843_RATES ; i++) +for (i =0 ; i < data->variant->n_regval_to_samp_freq; i++) len +=scnprintf (buf + len,PAGE_SIZE - len,"%d.%d " , data->variant->regval_to_samp_freq[i][0 ], data->variant->regval_to_samp_freq[i][1 ]);
@@ -278,7 +278,7 @@ static int hmc5843_get_samp_freq_index(struct hmc5843_data *data, {int i; -for (i =0 ; i <HMC5843_RATES ; i++) +for (i =0 ; i < data->variant->n_regval_to_samp_freq; i++)if (val == data->variant->regval_to_samp_freq[i][0 ] && val2 == data->variant->regval_to_samp_freq[i][1 ])return i;
@@ -307,7 +307,7 @@ static ssize_t hmc5843_show_scale_avail(struct device *dev,size_t len =0 ;int i; -for (i =0 ; i <HMC5843_RANGE_GAINS ; i++) +for (i =0 ; i < data->variant->n_regval_to_nanoscale; i++) len +=scnprintf (buf + len,PAGE_SIZE - len,"0.%09d " , data->variant->regval_to_nanoscale[i]);
@@ -327,7 +327,7 @@ static int hmc5843_get_scale_index(struct hmc5843_data *data, int val, int val2)if (val !=0 )return -EINVAL ; -for (i =0 ; i <HMC5843_RANGE_GAINS ; i++) +for (i =0 ; i < data->variant->n_regval_to_nanoscale; i++)if (val2 == data->variant->regval_to_nanoscale[i])return i;
@@ -480,17 +480,29 @@ static const struct hmc5843_chip_info hmc5843_chip_info_tbl[] = { [HMC5843_ID ] = { .channels = hmc5843_channels, .regval_to_samp_freq = hmc5843_regval_to_samp_freq, + .n_regval_to_samp_freq = +ARRAY_SIZE (hmc5843_regval_to_samp_freq), .regval_to_nanoscale = hmc5843_regval_to_nanoscale, + .n_regval_to_nanoscale = +ARRAY_SIZE (hmc5843_regval_to_nanoscale), }, [HMC5883_ID ] = { .channels = hmc5883_channels, .regval_to_samp_freq = hmc5883_regval_to_samp_freq, + .n_regval_to_samp_freq = +ARRAY_SIZE (hmc5883_regval_to_samp_freq), .regval_to_nanoscale = hmc5883_regval_to_nanoscale, + .n_regval_to_nanoscale = +ARRAY_SIZE (hmc5883_regval_to_nanoscale), }, [HMC5883L_ID ] = { .channels = hmc5883_channels, .regval_to_samp_freq = hmc5883_regval_to_samp_freq, + .n_regval_to_samp_freq = +ARRAY_SIZE (hmc5883_regval_to_samp_freq), .regval_to_nanoscale = hmc5883l_regval_to_nanoscale, + .n_regval_to_nanoscale = +ARRAY_SIZE (hmc5883l_regval_to_nanoscale), }, };
Signature · 1 line
1.8.5.5
PATCH v4 4/5 staging:iio:hmc5843: Add support for i2c hmc5983
In reply to Josef GajdusekThis patch adds support for the hmc5983 i2c interface.
This chip is almost identical to the hmc5883. The difference being added temperature compensation, additional available sample rate (220Hz) and an SPI interface.
--- drivers/staging/iio/magnetometer/Kconfig | 2 +- drivers/staging/iio/magnetometer/hmc5843.h | 1 + drivers/staging/iio/magnetometer/hmc5843_core.c | 20 +++++++++++++++++--- drivers/staging/iio/magnetometer/hmc5843_i2c.c | 5 +++-- 4 files changed, 22 insertions(+), 6 deletions(-)
drivers/staging/iio/magnetometer/Kconfig +1 -1
@@ -20,6 +20,6 @@ config SENSORS_HMC5843_I2C This driver can also be compiled as a set of modules. If so, these modules will be created: - hmc5843_core (core functions) - - hmc5843_i2c (support for HMC5843, HMC5883 and HMC5883L) + - hmc5843_i2c (support for HMC5843, HMC5883, HMC5883L and HMC5983) endmenu
drivers/staging/iio/magnetometer/hmc5843.h +1 -0
@@ -29,6 +29,7 @@ enum hmc5843_ids {HMC5843_ID ,HMC5883_ID ,HMC5883L_ID , + HMC5983_ID, }; struct hmc5843_data {
drivers/staging/iio/magnetometer/hmc5843_core.c +17 -3
@@ -101,6 +101,11 @@ static const int hmc5883_regval_to_samp_freq[][2] = { {75, 0} }; +static const int hmc5983_regval_to_samp_freq[][2 ] = { + {0 ,750000 }, {1 ,500000 }, {3 ,0 }, {7 ,500000 }, {15 ,0 }, {30 ,0 }, + {75 ,0 }, {220 ,0 } +}; +/* Describe chip variants */ struct hmc5843_chip_info {const struct iio_chan_spec *channels;
@@ -457,7 +462,7 @@ static const struct iio_chan_spec hmc5843_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(3), }; -/* Beware: Y and Z are exchanged on HMC5883 */ +/* Beware: Y and Z are exchanged on HMC5883 and 5983 */ static const struct iio_chan_spec hmc5883_channels[] = {HMC5843_CHANNEL (X ,0 ),HMC5843_CHANNEL (Z ,1 ),
@@ -504,6 +509,15 @@ static const struct hmc5843_chip_info hmc5843_chip_info_tbl[] = { .n_regval_to_nanoscale = ARRAY_SIZE(hmc5883l_regval_to_nanoscale), }, + [HMC5983_ID] = { + .channels = hmc5883_channels, + .regval_to_samp_freq = hmc5983_regval_to_samp_freq, + .n_regval_to_samp_freq = + ARRAY_SIZE(hmc5983_regval_to_samp_freq), + .regval_to_nanoscale = hmc5883l_regval_to_nanoscale, + .n_regval_to_nanoscale = + ARRAY_SIZE(hmc5883l_regval_to_nanoscale), + } };static int hmc5843_init (struct hmc5843_data *data)
@@ -516,7 +530,7 @@ static int hmc5843_init(struct hmc5843_data *data)if (ret <0 )return ret;if (id[0 ] !='H' || id[1 ] !='4' || id[2 ] !='3' ) { -dev_err (data->dev,"no HMC5843/5883/5883L sensor\n" ); +dev_err (data->dev,"no HMC5843/5883/5883L/5983 sensor\n" );return -ENODEV ; }
@@ -620,5 +634,5 @@ int hmc5843_common_remove(struct device *dev)EXPORT_SYMBOL (hmc5843_common_remove);MODULE_AUTHOR ("Shubhrajyoti Datta <[email protected]>" ); -MODULE_DESCRIPTION ("HMC5843/5883/5883L core driver" ); +MODULE_DESCRIPTION ("HMC5843/5883/5883L/5983 core driver" );MODULE_LICENSE ("GPL" );
drivers/staging/iio/magnetometer/hmc5843_i2c.c +3 -2
@@ -1,5 +1,5 @@/* -* i2c driver for hmc5843/5843/5883/5883l +* i2c driver for hmc5843/5843/5883/5883l/5983 * * Split from hmc5843.c * Copyright (C) Josef Gajdusek <[email protected]>
@@ -46,6 +46,7 @@ static const struct i2c_device_id hmc5843_id[] = { { "hmc5843", HMC5843_ID }, { "hmc5883", HMC5883_ID }, { "hmc5883l", HMC5883L_ID }, + { "hmc5983", HMC5983_ID }, { } };MODULE_DEVICE_TABLE (i2c, hmc5843_id);
@@ -69,5 +70,5 @@ static struct i2c_driver hmc5843_driver = {module_i2c_driver (hmc5843_driver);MODULE_AUTHOR ("Josef Gajdusek <[email protected]>" ); -MODULE_DESCRIPTION ("HMC5843/5883/5883L i2c driver" ); +MODULE_DESCRIPTION ("HMC5843/5883/5883L/5983 i2c driver" );MODULE_LICENSE ("GPL" );
Signature · 1 line
1.8.5.5
PATCH v4 5/5 staging:iio:hmc5843: Add support for spi hmc5983
In reply to Josef GajdusekThis patch adds support for the hmc5983 spi interface.
This chip is almost identical to the hmc5883. The difference being added temperature compensation, additional available sample rate (220Hz) and an SPI interface.
--- drivers/staging/iio/magnetometer/Kconfig | 15 ++++++ drivers/staging/iio/magnetometer/Makefile | 1 + drivers/staging/iio/magnetometer/hmc5843_spi.c | 73 ++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 drivers/staging/iio/magnetometer/hmc5843_spi.c
drivers/staging/iio/magnetometer/Kconfig +15 -0
@@ -22,4 +22,19 @@ config SENSORS_HMC5843_I2C - hmc5843_core (core functions) - hmc5843_i2c (support for HMC5843, HMC5883, HMC5883L and HMC5983) +config SENSORS_HMC5843_SPI + tristate "Honeywell HMC5983 3-Axis Magnetometer (SPI)" + depends on SPI_MASTER + select SENSORS_HMC5843 + select REGMAP_SPI + help + Say Y here to add support for the Honeywell HMC5983 3-Axis Magnetometer + (digital compass). + + This driver can also be compiled as a set of modules. + If so, these modules will be created: + - hmc5843_core (core functions) + - hmc5843_spi (support for HMC5983) + + endmenu
drivers/staging/iio/magnetometer/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_SENSORS_HMC5843) += hmc5843_core.o obj-$(CONFIG_SENSORS_HMC5843_I2C) += hmc5843_i2c.o +obj-$(CONFIG_SENSORS_HMC5843_SPI) += hmc5843_spi.o
drivers/staging/iio/magnetometer/hmc5843_spi.c new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
1.8.5.5
Jonathan Cameron
maintainerQuoted 22 lines · Josef Gajdusek
This patch series modifies the hmc5843 driver to support the hmc5983 i2c and spi interfaces.
v2:
* Reverted the changed order of iio unregister and setting hmc mode to sleepv3:
* Fixed bug introduced in the first patch
* Readded few comment lines which have gone missing in thehmc5843.c->hmc5843_core.cmovev4:
* Changes suggested by Lars in https://lkml.org/lkml/2014/7/14/968
* The i2c and spi drivers are now user-selectable with the core driver being selected automatically
* Theregmap_configstructs in both_spiand_i2cfiles are now static
* Theiio_devallocation is now done in the common function
* pm ops are now defined in the header file and the same definition is shared between both interface-specific drivers
* regmap tables inhmc5843.hare not longer static (this fixed bunch of variable not used warnings)
Quoted 3 lines
Jonathan, the patch series applies cleanly against mainline (for me at least), maybe you already have some hmc5843 related patches in your tree which are not yet in upstream? (probably https://lkml.org/lkml/2014/2/14/312)
You are correct (although curiously the error from patch this time is a much cleaner fail than before where it was detecting a repeated apply - ah well). Could you rebase this series against staging/staging-next
from git.kernel.org please. I'm far more likely to get something wrong doing this than you are. Also you have the ability to test the result!
Sorry for the extra work but it's good to see lots of simultaneous interest in this driver!
Thanks,
Jonathan
Quoted 23 lines
Josef Gajdusek (5):
staging:iio:hmc5843: Added regmap support staging:iio:hmc5843: Splithmc5843.cto multiple files staging:iio:hmc5843: register <-> value arrays now can have different
lengths
staging:iio:hmc5843: Add support for i2c hmc5983 staging:iio:hmc5843: Add support for spi hmc5983drivers/staging/iio/magnetometer/Kconfig | 30 +- drivers/staging/iio/magnetometer/Makefile | 4 +- drivers/staging/iio/magnetometer/hmc5843.c | 652 ------------------------ drivers/staging/iio/magnetometer/hmc5843.h | 86 ++++ drivers/staging/iio/magnetometer/hmc5843_core.c | 638 +++++++++++++++++++++++ drivers/staging/iio/magnetometer/hmc5843_i2c.c | 74 +++ drivers/staging/iio/magnetometer/hmc5843_spi.c | 73 +++ 7 files changed, 900 insertions(+), 657 deletions(-)delete mode 100644
drivers/staging/iio/magnetometer/hmc5843.ccreate mode 100644drivers/staging/iio/magnetometer/hmc5843.hcreate mode 100644drivers/staging/iio/magnetometer/hmc5843_core.ccreate mode 100644drivers/staging/iio/magnetometer/hmc5843_i2c.ccreate mode 100644drivers/staging/iio/magnetometer/hmc5843_spi.c