1 // SPDX-License-Identifier: GPL-2.0-only
3 * STMicroelectronics sensors i2c library driver
5 * Copyright 2012-2013 STMicroelectronics Inc.
7 * Denis Ciocca <denis.ciocca@st.com>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/iio/iio.h>
14 #include <linux/regmap.h>
16 #include <linux/iio/common/st_sensors_i2c.h>
19 #define ST_SENSORS_I2C_MULTIREAD 0x80
21 static const struct regmap_config st_sensors_i2c_regmap_config = {
26 static const struct regmap_config st_sensors_i2c_regmap_multiread_bit_config = {
29 .read_flag_mask = ST_SENSORS_I2C_MULTIREAD,
33 * st_sensors_i2c_configure() - configure I2C interface
34 * @indio_dev: IIO device reference.
35 * @client: i2c client reference.
37 * Return: 0 on success, else a negative error code.
39 int st_sensors_i2c_configure(struct iio_dev *indio_dev,
40 struct i2c_client *client)
42 struct st_sensor_data *sdata = iio_priv(indio_dev);
43 const struct regmap_config *config;
45 if (sdata->sensor_settings->multi_read_bit)
46 config = &st_sensors_i2c_regmap_multiread_bit_config;
48 config = &st_sensors_i2c_regmap_config;
50 sdata->regmap = devm_regmap_init_i2c(client, config);
51 if (IS_ERR(sdata->regmap)) {
52 dev_err(&client->dev, "Failed to register i2c regmap (%ld)\n",
53 PTR_ERR(sdata->regmap));
54 return PTR_ERR(sdata->regmap);
57 i2c_set_clientdata(client, indio_dev);
59 indio_dev->dev.parent = &client->dev;
60 indio_dev->name = client->name;
62 sdata->dev = &client->dev;
63 sdata->irq = client->irq;
67 EXPORT_SYMBOL(st_sensors_i2c_configure);
69 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
70 MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver");
71 MODULE_LICENSE("GPL v2");