iio: mpl3115: add support for DRDY interrupt
Subsystems (2)
v2 cover iio: mpl3115: add support for DRDY interrupt
Hello,
This set of patches adds support for the DRDY interrupt in the MPL3115 pressure sensor. The device has 2 interrupt lines, hence the new binding. I also added support for the sampling frequency which determines the time interval between subsequent measurements (in the continuous measurements mode) so it's obiously tied to the DRDY interrupt feature.
Kind regards,
Antoni Pokusinski
---
Changes since v1:
* P1: add vdd-supply and vddio-supply
* P2: new patch: use guards from cleanup.h
* P3: change macros of control register bits to convention
MPL3115_CTRLX_NAME
* P3: MPL3115_PT_DATA_EVENT_ALL: use GENMASK
* P3: trigger_probe: do not fail if dev_fwnode() returns NULL
* P3: trigger_probe: use devm_iio_trigger_register()
* P3: trigger_probe: introduced enum mpl3115_irq_type and changed IRQ setup logic accordingly
* P4: MPL3115_CTRL2_ST: use GENMASK
* P4: read_raw: samp_freq: use FIELD_GET
* P4: write_raw: samp_freq: use FIELD_PREP
---
Antoni Pokusinski (4):
dt-bindings: iio: pressure: add binding for mpl3115
iio: mpl3115: use guards from cleanup.h
iio: mpl3115: add support for DRDY interrupt
iio: mpl3115: add support for sampling frequency
.../bindings/iio/pressure/fsl,mpl3115.yaml | 71 ++++ .../devicetree/bindings/trivial-devices.yaml | 2 - drivers/iio/pressure/mpl3115.c | 314 ++++++++++++++++-- 3 files changed, 352 insertions(+), 35 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/pressure/fsl,mpl3115.yaml
Signature · 1 line
2.25.1
PATCH v2 1/4 dt-bindings: iio: pressure: add binding for mpl3115
MPL3115 is an I2C pressure and temperature sensor. It features 2 interrupt lines which can be configured to indicate events such as data ready or pressure/temperature threshold reached.
--- .../bindings/iio/pressure/fsl,mpl3115.yaml | 71 +++++++++++++++++++ .../devicetree/bindings/trivial-devices.yaml | 2 - 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/pressure/fsl,mpl3115.yaml
Documentation/devicetree/bindings/iio/pressure/fsl,mpl3115.yaml new file +71 -0
@@ -0,0 +1,71 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/pressure/fsl,mpl3115.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MPL3115 precision pressure sensor with altimetry + +maintainers: + - Antoni Pokusinski <[email protected]> + +description: | + MPL3115 is a pressure/altitude and temperature sensor with I2C interface. + It features two programmable interrupt lines which indicate events such as + data ready or pressure/temperature threshold reached. + https://www.nxp.com/docs/en/data-sheet/MPL3115A2.pdf + +properties: + compatible: + const: fsl,mpl3115 + + reg: + maxItems: 1 + + vdd-supply: true + + vddio-supply: true + + interrupts: + minItems: 1 + maxItems: 2 + + interrupt-names: + minItems: 1 + maxItems: 2 + items: + enum: + - INT1 + - INT2 + + drive-open-drain: + type: boolean + description: + set if the specified interrupt pins should be configured as + open drain. If not set, defaults to push-pull. + +required: + - compatible + - reg + - vdd-supply + - vddio-supply + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pressure@60 { + compatible = "fsl,mpl3115"; + reg = <0x60>; + vdd-supply = <&vdd>; + vddio-supply = <&vddio>; + interrupt-parent = <&gpio1>; + interrupts = <4 IRQ_TYPE_EDGE_FALLING>; + interrupt-names = "INT2"; + }; + };
Documentation/devicetree/bindings/trivial-devices.yaml +0 -2
@@ -113,8 +113,6 @@ properties: - fsl,mma7660 # MMA8450Q: Xtrinsic Low-power, 3-axis Xtrinsic Accelerometer - fsl,mma8450 - # MPL3115: Absolute Digital Pressure Sensor - - fsl,mpl3115 # MPR121: Proximity Capacitive Touch Sensor Controller - fsl,mpr121 # Honeywell Humidicon HIH-6130 humidity/temperature sensor
Signature · 1 line
2.25.1
PATCH v2 2/4 iio: mpl3115: use guards from cleanup.h
In reply to Antoni PokusinskiInclude linux/cleanup.h and use the scoped_guard() to simplify the code.
--- drivers/iio/pressure/mpl3115.c | 42 +++++++++++++++------------------- 1 file changed, 19 insertions(+), 23 deletions(-)
drivers/iio/pressure/mpl3115.c +19 -23
@@ -10,14 +10,16 @@* interrupts, user offset correction, raw mode */ -#include <linux/module.h> +#include <linux/cleanup.h> +#include <linux/delay.h> #include <linux/i2c.h> +#include <linux/module.h> +#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/trigger_consumer.h> #include <linux/iio/buffer.h> #include <linux/iio/triggered_buffer.h> -#include <linux/delay.h> #define MPL3115_STATUS 0x00#define MPL3115_OUT_PRESS 0x01/* MSB first, 20 bit */
@@ -163,32 +165,26 @@ static irqreturn_t mpl3115_trigger_handler(int irq, void *p)u8 buffer[16 ]__aligned(8) = { };int ret, pos =0 ; -mutex_lock (&data->lock); - ret =mpl3115_request (data); -if (ret <0 ) { -mutex_unlock (&data->lock); - goto done; - } - -if (test_bit (0 , indio_dev->active_scan_mask)) { - ret =i2c_smbus_read_i2c_block_data (data->client, -MPL3115_OUT_PRESS ,3 , &buffer[pos]); -if (ret <0 ) { -mutex_unlock (&data->lock); + scoped_guard(mutex, &data->lock) { + ret =mpl3115_request (data); +if (ret <0 ) goto done; + +if (test_bit (0 , indio_dev->active_scan_mask)) { + ret =i2c_smbus_read_i2c_block_data (data->client, +MPL3115_OUT_PRESS ,3 , &buffer[pos]); +if (ret <0 ) + goto done; + pos +=4 ; } - pos +=4 ; - } -if (test_bit (1 , indio_dev->active_scan_mask)) { - ret =i2c_smbus_read_i2c_block_data (data->client, -MPL3115_OUT_TEMP ,2 , &buffer[pos]); -if (ret <0 ) { -mutex_unlock (&data->lock); - goto done; +if (test_bit (1 , indio_dev->active_scan_mask)) { + ret =i2c_smbus_read_i2c_block_data (data->client, +MPL3115_OUT_TEMP ,2 , &buffer[pos]); +if (ret <0 ) + goto done; } } -mutex_unlock (&data->lock);iio_push_to_buffers_with_ts (indio_dev, buffer,sizeof (buffer),iio_get_time_ns (indio_dev));
Signature · 1 line
2.25.1
PATCH v2 3/4 iio: mpl3115: add support for DRDY interrupt
In reply to Antoni PokusinskiMPL3115 sensor features a "data ready" interrupt which indicates the presence of new measurements.
--- drivers/iio/pressure/mpl3115.c | 197 ++++++++++++++++++++++++++++++--- 1 file changed, 184 insertions(+), 13 deletions(-)
drivers/iio/pressure/mpl3115.c +184 -13
@@ -7,49 +7,77 @@* (7-bit I2C slave address 0x60) * * TODO: FIFO buffer, altimeter mode, oversampling, continuous mode, -* interrupts, user offset correction, raw mode +* user offset correction, raw mode */ #include <linux/cleanup.h> #include <linux/delay.h> #include <linux/i2c.h> #include <linux/module.h> +#include <linux/property.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/trigger_consumer.h> #include <linux/iio/buffer.h> #include <linux/iio/triggered_buffer.h> +#include <linux/iio/trigger.h> #define MPL3115_STATUS 0x00#define MPL3115_OUT_PRESS 0x01/* MSB first, 20 bit */ #define MPL3115_OUT_TEMP 0x04/* MSB first, 12 bit */ #define MPL3115_WHO_AM_I 0x0c +#define MPL3115_INT_SOURCE 0x12 +#define MPL3115_PT_DATA_CFG 0x13#define MPL3115_CTRL_REG1 0x26 +#define MPL3115_CTRL_REG3 0x28 +#define MPL3115_CTRL_REG4 0x29 +#define MPL3115_CTRL_REG5 0x2a#define MPL3115_DEVICE_ID 0xc4#define MPL3115_STATUS_PRESS_RDY BIT(2)#define MPL3115_STATUS_TEMP_RDY BIT(1) -#define MPL3115_CTRL_RESET BIT(2)/* software reset */ -#define MPL3115_CTRL_OST BIT(1)/* initiate measurement */ -#define MPL3115_CTRL_ACTIVE BIT(0)/* continuous measurement */ -#define MPL3115_CTRL_OS_258MS (BIT(5) | BIT(4))/* 64x oversampling */ +#define MPL3115_INT_SRC_DRDY BIT(7) + +#define MPL3115_PT_DATA_EVENT_ALL GENMASK(2, 0) + +#define MPL3115_CTRL1_RESET BIT(2)/* software reset */ +#define MPL3115_CTRL1_OST BIT(1)/* initiate measurement */ +#define MPL3115_CTRL1_ACTIVE BIT(0)/* continuous measurement */ +#define MPL3115_CTRL1_OS_258MS GENMASK(5, 4)/* 64x oversampling */ + +#define MPL3115_CTRL3_IPOL1 BIT(5) +#define MPL3115_CTRL3_IPOL2 BIT(1) + +#define MPL3115_CTRL4_INT_EN_DRDY BIT(7) + +#define MPL3115_CTRL5_INT_CFG_DRDY BIT(7) + +#define MPL3115_INT2 BIT(2)/* flag that indicates INT2 in use */ struct mpl3115_data {struct i2c_client *client; +struct iio_trigger *drdy_trig;struct mutex lock;u8 ctrl_reg1; }; +enum mpl3115_irq_type { +INT2_ACTIVE_LOW =MPL3115_INT2 |IRQF_TRIGGER_FALLING , +INT2_ACTIVE_HIGH =MPL3115_INT2 |IRQF_TRIGGER_RISING , +INT1_ACTIVE_LOW = (!MPL3115_INT2 ) |IRQF_TRIGGER_FALLING , +INT1_ACTIVE_HIGH = (!MPL3115_INT2 ) |IRQF_TRIGGER_RISING , +}; +static int mpl3115_request (struct mpl3115_data *data) {int ret, tries =15 ;/* trigger measurement */ ret =i2c_smbus_write_byte_data (data->client,MPL3115_CTRL_REG1 , - data->ctrl_reg1 |MPL3115_CTRL_OST ); + data->ctrl_reg1 |MPL3115_CTRL1_OST );if (ret <0 )return ret;
@@ -58,7 +86,7 @@ static int mpl3115_request(struct mpl3115_data *data)if (ret <0 )return ret;/* wait for data ready, i.e. OST cleared */ -if (!(ret &MPL3115_CTRL_OST )) +if (!(ret &MPL3115_CTRL1_OST ))break ;msleep (20 ); }
@@ -166,9 +194,11 @@ static irqreturn_t mpl3115_trigger_handler(int irq, void *p)int ret, pos =0 ; scoped_guard(mutex, &data->lock) { - ret =mpl3115_request (data); -if (ret <0 ) - goto done; +if (!(data->ctrl_reg1 &MPL3115_CTRL1_ACTIVE )) { + ret =mpl3115_request (data); +if (ret <0 ) + goto done; + }if (test_bit (0 , indio_dev->active_scan_mask)) { ret = i2c_smbus_read_i2c_block_data(data->client,
@@ -224,10 +254,147 @@ static const struct iio_chan_spec mpl3115_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(2), }; +static irqreturn_t mpl3115_interrupt_handler (int irq,void *private) +{ +struct iio_dev *indio_dev = private; +struct mpl3115_data *data =iio_priv (indio_dev); +int ret; + + ret =i2c_smbus_read_byte_data (data->client,MPL3115_INT_SOURCE ); +if (ret <0 ) +return IRQ_HANDLED ; + +if (!(ret &MPL3115_INT_SRC_DRDY )) +return IRQ_NONE ; + +iio_trigger_poll_nested (data->drdy_trig); + +return IRQ_HANDLED ; +} + +static int mpl3115_set_trigger_state (struct iio_trigger *trig,bool state) +{ +struct iio_dev *indio_dev =iio_trigger_get_drvdata (trig); +struct mpl3115_data *data =iio_priv (indio_dev); +int ret; +u8 ctrl_reg1 = data->ctrl_reg1; + +if (state) + ctrl_reg1 |=MPL3115_CTRL1_ACTIVE ; +else + ctrl_reg1 &= ~MPL3115_CTRL1_ACTIVE ; + +guard (mutex)(&data->lock); + + ret =i2c_smbus_write_byte_data (data->client,MPL3115_CTRL_REG1 , + ctrl_reg1); +if (ret <0 ) +return ret; + + ret =i2c_smbus_write_byte_data (data->client,MPL3115_CTRL_REG4 , + state ?MPL3115_CTRL4_INT_EN_DRDY :0 ); +if (ret <0 ) + goto reg1_cleanup; + + data->ctrl_reg1 = ctrl_reg1; + +return 0 ; + +reg1_cleanup: +i2c_smbus_write_byte_data (data->client,MPL3115_CTRL_REG1 , + data->ctrl_reg1); +return ret; +} + +static const struct iio_trigger_ops mpl3115_trigger_ops = { + .set_trigger_state = mpl3115_set_trigger_state, +}; +static const struct iio_info mpl3115_info = { .read_raw = &mpl3115_read_raw, }; +static int mpl3115_trigger_probe (struct mpl3115_data *data, +struct iio_dev *indio_dev) +{ +struct fwnode_handle *fwnode =dev_fwnode (&data->client->dev); +int ret, irq, irq_type, irq_cfg_flags =0 ; + + irq =fwnode_irq_get_byname (fwnode,"INT1" ); +if (irq <0 ) { + irq =fwnode_irq_get_byname (fwnode,"INT2" ); +if (irq <0 ) +return 0 ; + + irq_cfg_flags |=MPL3115_INT2 ; + } + + irq_type =irq_get_trigger_type (irq); +if (irq_type !=IRQF_TRIGGER_RISING && irq_type !=IRQF_TRIGGER_FALLING ) +return -EINVAL ; + + irq_cfg_flags |= irq_type; + + ret =i2c_smbus_write_byte_data (data->client,MPL3115_PT_DATA_CFG , +MPL3115_PT_DATA_EVENT_ALL ); +if (ret <0 ) +return ret; + +switch (irq_cfg_flags) { +case INT2_ACTIVE_HIGH : + ret =i2c_smbus_write_byte_data (data->client,MPL3115_CTRL_REG3 , +MPL3115_CTRL3_IPOL2 ); +if (ret) +return ret; + +break ; +case INT2_ACTIVE_LOW : +break ; +case INT1_ACTIVE_HIGH : + ret =i2c_smbus_write_byte_data (data->client,MPL3115_CTRL_REG5 , +MPL3115_CTRL5_INT_CFG_DRDY ); +if (ret) +return ret; + + ret =i2c_smbus_write_byte_data (data->client,MPL3115_CTRL_REG3 , +MPL3115_CTRL3_IPOL1 ); +if (ret) +return ret; + +break ; +case INT1_ACTIVE_LOW : + ret =i2c_smbus_write_byte_data (data->client,MPL3115_CTRL_REG5 , +MPL3115_CTRL5_INT_CFG_DRDY ); +if (ret) +return ret; +break ; +default : +return -EINVAL ; + } + + data->drdy_trig =devm_iio_trigger_alloc (&data->client->dev, +"%s-dev%d" , + indio_dev->name, +iio_device_id (indio_dev)); +if (!data->drdy_trig) +return -ENOMEM ; + + data->drdy_trig->ops = &mpl3115_trigger_ops; +iio_trigger_set_drvdata (data->drdy_trig, indio_dev); + ret =devm_iio_trigger_register (&data->client->dev, data->drdy_trig); +if (ret) +return ret; + + indio_dev->trig =iio_trigger_get (data->drdy_trig); + +return devm_request_threaded_irq (&data->client->dev, irq, +NULL , + mpl3115_interrupt_handler, +IRQF_ONESHOT , +"mpl3115_irq" , + indio_dev); +} +static int mpl3115_probe (struct i2c_client *client) {const struct i2c_device_id *id =i2c_client_get_device_id (client);
@@ -258,15 +425,19 @@ static int mpl3115_probe(struct i2c_client *client)/* software reset, I2C transfer is aborted (fails) */ i2c_smbus_write_byte_data (client,MPL3115_CTRL_REG1 , -MPL3115_CTRL_RESET ); +MPL3115_CTRL1_RESET );msleep (50 ); - data->ctrl_reg1 =MPL3115_CTRL_OS_258MS ; + data->ctrl_reg1 =MPL3115_CTRL1_OS_258MS ; ret =i2c_smbus_write_byte_data (client,MPL3115_CTRL_REG1 , data->ctrl_reg1);if (ret <0 )return ret; + ret =mpl3115_trigger_probe (data, indio_dev); +if (ret) +return ret; + ret =iio_triggered_buffer_setup (indio_dev,NULL , mpl3115_trigger_handler,NULL );if (ret <0 )
@@ -285,7 +456,7 @@ static int mpl3115_probe(struct i2c_client *client)static int mpl3115_standby (struct mpl3115_data *data) {return i2c_smbus_write_byte_data (data->client,MPL3115_CTRL_REG1 , - data->ctrl_reg1 & ~MPL3115_CTRL_ACTIVE ); + data->ctrl_reg1 & ~MPL3115_CTRL1_ACTIVE ); }static void mpl3115_remove (struct i2c_client *client)
Signature · 1 line
2.25.1
PATCH v2 4/4 iio: mpl3115: add support for sampling frequency
In reply to Antoni PokusinskiWhen the device is in ACTIVE mode the temperature and pressure measurements are collected with a frequency determined by the ST[3:0] bits of CTRL_REG2 register.
--- drivers/iio/pressure/mpl3115.c | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
drivers/iio/pressure/mpl3115.c +81 -0
@@ -30,6 +30,7 @@#define MPL3115_INT_SOURCE 0x12#define MPL3115_PT_DATA_CFG 0x13#define MPL3115_CTRL_REG1 0x26 +#define MPL3115_CTRL_REG2 0x27#define MPL3115_CTRL_REG3 0x28#define MPL3115_CTRL_REG4 0x29#define MPL3115_CTRL_REG5 0x2a
@@ -48,6 +49,8 @@#define MPL3115_CTRL1_ACTIVE BIT(0)/* continuous measurement */ #define MPL3115_CTRL1_OS_258MS GENMASK(5, 4)/* 64x oversampling */ +#define MPL3115_CTRL2_ST GENMASK(3, 0) +#define MPL3115_CTRL3_IPOL1 BIT(5)#define MPL3115_CTRL3_IPOL2 BIT(1)
@@ -57,6 +60,25 @@#define MPL3115_INT2 BIT(2)/* flag that indicates INT2 in use */ +static const unsigned int mpl3115_samp_freq_table[][2 ] = { + {1 ,0 }, + {0 ,500000 }, + {0 ,250000 }, + {0 ,125000 }, + {0 ,62500 }, + {0 ,31250 }, + {0 ,15625 }, + {0 ,7812 }, + {0 ,3906 }, + {0 ,1953 }, + {0 ,976 }, + {0 ,488 }, + {0 ,244 }, + {0 ,122 }, + {0 ,61 }, + {0 ,30 }, +}; +struct mpl3115_data {struct i2c_client *client;struct iio_trigger *drdy_trig;
@@ -174,10 +196,61 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,default :return -EINVAL ; } +case IIO_CHAN_INFO_SAMP_FREQ : + ret =i2c_smbus_read_byte_data (data->client,MPL3115_CTRL_REG2 ); +if (ret <0 ) +return ret; + + ret =FIELD_GET (MPL3115_CTRL2_ST , ret); + + *val = mpl3115_samp_freq_table[ret][0 ]; + *val2 = mpl3115_samp_freq_table[ret][1 ]; +return IIO_VAL_INT_PLUS_MICRO ; }return -EINVAL ; } +static int mpl3115_read_avail (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +const int **vals,int *type,int *length, +long mask) +{ +if (mask !=IIO_CHAN_INFO_SAMP_FREQ ) +return -EINVAL ; + + *type =IIO_VAL_INT_PLUS_MICRO ; + *length =ARRAY_SIZE (mpl3115_samp_freq_table) *2 ; + *vals = (int *)mpl3115_samp_freq_table; +return IIO_AVAIL_LIST ; +} + +static int mpl3115_write_raw (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +int val,int val2,long mask) +{ +struct mpl3115_data *data =iio_priv (indio_dev); +int i, ret; + +if (mask !=IIO_CHAN_INFO_SAMP_FREQ ) +return -EINVAL ; + +for (i =0 ; i <ARRAY_SIZE (mpl3115_samp_freq_table); i++) +if (val == mpl3115_samp_freq_table[i][0 ] && + val2 == mpl3115_samp_freq_table[i][1 ]) +break ; + +if (i ==ARRAY_SIZE (mpl3115_samp_freq_table)) +return -EINVAL ; + +if (!iio_device_claim_direct (indio_dev)) +return -EBUSY ; + + ret =i2c_smbus_write_byte_data (data->client,MPL3115_CTRL_REG2 , +FIELD_PREP (MPL3115_CTRL2_ST , i)); +iio_device_release_direct (indio_dev); +return ret; +} +static irqreturn_t mpl3115_trigger_handler (int irq,void *p) {struct iio_poll_func *pf = p;
@@ -229,6 +302,9 @@ static const struct iio_chan_spec mpl3115_channels[] = { .type = IIO_PRESSURE, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available = + BIT(IIO_CHAN_INFO_SAMP_FREQ), .scan_index = 0, .scan_type = { .sign = 'u',
@@ -242,6 +318,9 @@ static const struct iio_chan_spec mpl3115_channels[] = { .type = IIO_TEMP, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available = + BIT(IIO_CHAN_INFO_SAMP_FREQ), .scan_index = 1, .scan_type = { .sign = 's',
@@ -312,6 +391,8 @@ static const struct iio_trigger_ops mpl3115_trigger_ops = {static const struct iio_info mpl3115_info = { .read_raw = &mpl3115_read_raw, + .read_avail = &mpl3115_read_avail, + .write_raw = &mpl3115_write_raw, }; static int mpl3115_trigger_probe(struct mpl3115_data *data,
Signature · 1 line
2.25.1
kernel test robot
build botRe: [PATCH v2 4/4] iio: mpl3115: add support for sampling frequency
kernel test robot noticed the following build errors:
Hi Antoni,
kernel test robot noticed the following build errors:
[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on robh/for-next linus/master v6.17-rc7 next-20250925] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Antoni-Pokusinski/dt-bindings-iio-pressure-add-binding-for-mpl3115/20250926-044905 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg patch link: https://lore.kernel.org/r/20250925204538.63723-5-apokusinski01%40gmail.com patch subject: [PATCH v2 4/4] iio: mpl3115: add support for sampling frequency config: i386-buildonly-randconfig-001-20250926 (https://download.01.org/0day-ci/archive/20250926/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250926/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/iio/pressure/mpl3115.c:204:9: error: call to undeclared function 'FIELD_GET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
204 | ret = FIELD_GET(MPL3115_CTRL2_ST, ret);
| ^
>> drivers/iio/pressure/mpl3115.c:249:6: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
249 | FIELD_PREP(MPL3115_CTRL2_ST, i));
| ^2 errors generated.
vim +/FIELD_GET +204 drivers/iio/pressure/mpl3115.c
169
170 static int mpl3115_read_raw(struct iio_dev *indio_dev,
171 struct iio_chan_spec const *chan,
172 int *val, int *val2, long mask)
173 {
174 struct mpl3115_data *data = iio_priv(indio_dev);
175 int ret;
176
177 switch (mask) {
178 case IIO_CHAN_INFO_RAW:
179 if (!iio_device_claim_direct(indio_dev))
180 return -EBUSY;
181
182 ret = mpl3115_read_info_raw(data, chan, val);
183 iio_device_release_direct(indio_dev);
184 return ret;
185
186 case IIO_CHAN_INFO_SCALE:
187 switch (chan->type) {
188 case IIO_PRESSURE:
189 *val = 0;
190 *val2 = 250; /* want kilopascal */
191 return IIO_VAL_INT_PLUS_MICRO;
192 case IIO_TEMP:
193 *val = 0;
194 *val2 = 62500;
195 return IIO_VAL_INT_PLUS_MICRO;
196 default:
197 return -EINVAL;
198 }
199 case IIO_CHAN_INFO_SAMP_FREQ:
200 ret = i2c_smbus_read_byte_data(data->client, MPL3115_CTRL_REG2);
201 if (ret < 0)
202 return ret;
203
> 204 ret = FIELD_GET(MPL3115_CTRL2_ST, ret);
205
206 *val = mpl3115_samp_freq_table[ret][0];
207 *val2 = mpl3115_samp_freq_table[ret][1];
208 return IIO_VAL_INT_PLUS_MICRO;
209 }
210 return -EINVAL;
211 }
212
213 static int mpl3115_read_avail(struct iio_dev *indio_dev,
214 struct iio_chan_spec const *chan,
215 const int **vals, int *type, int *length,
216 long mask)
217 {
218 if (mask != IIO_CHAN_INFO_SAMP_FREQ)
219 return -EINVAL;
220
221 *type = IIO_VAL_INT_PLUS_MICRO;
222 *length = ARRAY_SIZE(mpl3115_samp_freq_table) * 2;
223 *vals = (int *)mpl3115_samp_freq_table;
224 return IIO_AVAIL_LIST;
225 }
226
227 static int mpl3115_write_raw(struct iio_dev *indio_dev,
228 const struct iio_chan_spec *chan,
229 int val, int val2, long mask)
230 {
231 struct mpl3115_data *data = iio_priv(indio_dev);
232 int i, ret;
233
234 if (mask != IIO_CHAN_INFO_SAMP_FREQ)
235 return -EINVAL;
236
237 for (i = 0; i < ARRAY_SIZE(mpl3115_samp_freq_table); i++)
238 if (val == mpl3115_samp_freq_table[i][0] &&
239 val2 == mpl3115_samp_freq_table[i][1])
240 break;
241
242 if (i == ARRAY_SIZE(mpl3115_samp_freq_table))
243 return -EINVAL;
244
245 if (!iio_device_claim_direct(indio_dev))
246 return -EBUSY;
247
248 ret = i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG2,
> 249 FIELD_PREP(MPL3115_CTRL2_ST, i)); 250 iio_device_release_direct(indio_dev);
251 return ret;
252 }
253
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 4/4] iio: mpl3115: add support for sampling frequency
In reply to Antoni Pokusinskidrivers/iio/pressure/mpl3115.c
Quoted 15 lines · Antoni Pokusinski
When the device is in ACTIVE mode the temperature and pressure measurements are collected with a frequency determined by the ST[3:0] bits of
CTRL_REG2register.Reviewed-by Nuno Sá <[email protected]>Signed-off-by Antoni Pokusinski <[email protected]>--- drivers/iio/pressure/mpl3115.c | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)drivers/iio/pressure/mpl3115.c +0
-0@@ -30,6 +30,7 @@
The errors are due to missing include of bitfield.h, will add it in v3
Quoted 10 lines
drivers/iio/pressure/mpl3115.c +1
-0#define MPL3115_INT_SOURCE 0x12#define MPL3115_PT_DATA_CFG 0x13#define MPL3115_CTRL_REG1 0x26 +#define MPL3115_CTRL_REG2 0x27#define MPL3115_CTRL_REG3 0x28#define MPL3115_CTRL_REG4 0x29#define MPL3115_CTRL_REG5 0x2a@@ -48,6 +49,8 @@2.25.1