root/drivers/iio/common/st_sensors/st_sensors_i2c.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. st_sensors_i2c_configure
  2. st_sensors_match_acpi_device

   1 // SPDX-License-Identifier: GPL-2.0-only
   2 /*
   3  * STMicroelectronics sensors i2c library driver
   4  *
   5  * Copyright 2012-2013 STMicroelectronics Inc.
   6  *
   7  * Denis Ciocca <denis.ciocca@st.com>
   8  */
   9 
  10 #include <linux/kernel.h>
  11 #include <linux/module.h>
  12 #include <linux/slab.h>
  13 #include <linux/iio/iio.h>
  14 #include <linux/of_device.h>
  15 #include <linux/acpi.h>
  16 #include <linux/regmap.h>
  17 
  18 #include <linux/iio/common/st_sensors_i2c.h>
  19 
  20 
  21 #define ST_SENSORS_I2C_MULTIREAD        0x80
  22 
  23 static const struct regmap_config st_sensors_i2c_regmap_config = {
  24         .reg_bits = 8,
  25         .val_bits = 8,
  26 };
  27 
  28 static const struct regmap_config st_sensors_i2c_regmap_multiread_bit_config = {
  29         .reg_bits = 8,
  30         .val_bits = 8,
  31         .read_flag_mask = ST_SENSORS_I2C_MULTIREAD,
  32 };
  33 
  34 /*
  35  * st_sensors_i2c_configure() - configure I2C interface
  36  * @indio_dev: IIO device reference.
  37  * @client: i2c client reference.
  38  *
  39  * Return: 0 on success, else a negative error code.
  40  */
  41 int st_sensors_i2c_configure(struct iio_dev *indio_dev,
  42                              struct i2c_client *client)
  43 {
  44         struct st_sensor_data *sdata = iio_priv(indio_dev);
  45         const struct regmap_config *config;
  46 
  47         if (sdata->sensor_settings->multi_read_bit)
  48                 config = &st_sensors_i2c_regmap_multiread_bit_config;
  49         else
  50                 config = &st_sensors_i2c_regmap_config;
  51 
  52         sdata->regmap = devm_regmap_init_i2c(client, config);
  53         if (IS_ERR(sdata->regmap)) {
  54                 dev_err(&client->dev, "Failed to register i2c regmap (%d)\n",
  55                         (int)PTR_ERR(sdata->regmap));
  56                 return PTR_ERR(sdata->regmap);
  57         }
  58 
  59         i2c_set_clientdata(client, indio_dev);
  60 
  61         indio_dev->dev.parent = &client->dev;
  62         indio_dev->name = client->name;
  63 
  64         sdata->dev = &client->dev;
  65         sdata->irq = client->irq;
  66 
  67         return 0;
  68 }
  69 EXPORT_SYMBOL(st_sensors_i2c_configure);
  70 
  71 #ifdef CONFIG_ACPI
  72 int st_sensors_match_acpi_device(struct device *dev)
  73 {
  74         const struct acpi_device_id *acpi_id;
  75         kernel_ulong_t driver_data = 0;
  76 
  77         if (ACPI_HANDLE(dev)) {
  78                 acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev);
  79                 if (!acpi_id) {
  80                         dev_err(dev, "No driver data\n");
  81                         return -EINVAL;
  82                 }
  83                 driver_data = acpi_id->driver_data;
  84         }
  85         return driver_data;
  86 }
  87 EXPORT_SYMBOL(st_sensors_match_acpi_device);
  88 #endif
  89 
  90 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  91 MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver");
  92 MODULE_LICENSE("GPL v2");

/* [<][>][^][v][top][bottom][index][help] */