linux/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-only
   2/*
   3 * STMicroelectronics st_lsm6dsx i2c driver
   4 *
   5 * Copyright 2016 STMicroelectronics Inc.
   6 *
   7 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
   8 * Denis Ciocca <denis.ciocca@st.com>
   9 */
  10
  11#include <linux/kernel.h>
  12#include <linux/module.h>
  13#include <linux/i2c.h>
  14#include <linux/slab.h>
  15#include <linux/regmap.h>
  16
  17#include "st_lsm6dsx.h"
  18
  19static const struct regmap_config st_lsm6dsx_i2c_regmap_config = {
  20        .reg_bits = 8,
  21        .val_bits = 8,
  22};
  23
  24static int st_lsm6dsx_i2c_probe(struct i2c_client *client,
  25                                const struct i2c_device_id *id)
  26{
  27        int hw_id = id->driver_data;
  28        struct regmap *regmap;
  29
  30        regmap = devm_regmap_init_i2c(client, &st_lsm6dsx_i2c_regmap_config);
  31        if (IS_ERR(regmap)) {
  32                dev_err(&client->dev, "Failed to register i2c regmap %ld\n", PTR_ERR(regmap));
  33                return PTR_ERR(regmap);
  34        }
  35
  36        return st_lsm6dsx_probe(&client->dev, client->irq, hw_id, regmap);
  37}
  38
  39static const struct of_device_id st_lsm6dsx_i2c_of_match[] = {
  40        {
  41                .compatible = "st,lsm6ds3",
  42                .data = (void *)ST_LSM6DS3_ID,
  43        },
  44        {
  45                .compatible = "st,lsm6ds3h",
  46                .data = (void *)ST_LSM6DS3H_ID,
  47        },
  48        {
  49                .compatible = "st,lsm6dsl",
  50                .data = (void *)ST_LSM6DSL_ID,
  51        },
  52        {
  53                .compatible = "st,lsm6dsm",
  54                .data = (void *)ST_LSM6DSM_ID,
  55        },
  56        {
  57                .compatible = "st,ism330dlc",
  58                .data = (void *)ST_ISM330DLC_ID,
  59        },
  60        {
  61                .compatible = "st,lsm6dso",
  62                .data = (void *)ST_LSM6DSO_ID,
  63        },
  64        {
  65                .compatible = "st,asm330lhh",
  66                .data = (void *)ST_ASM330LHH_ID,
  67        },
  68        {
  69                .compatible = "st,lsm6dsox",
  70                .data = (void *)ST_LSM6DSOX_ID,
  71        },
  72        {
  73                .compatible = "st,lsm6dsr",
  74                .data = (void *)ST_LSM6DSR_ID,
  75        },
  76        {
  77                .compatible = "st,lsm6ds3tr-c",
  78                .data = (void *)ST_LSM6DS3TRC_ID,
  79        },
  80        {
  81                .compatible = "st,ism330dhcx",
  82                .data = (void *)ST_ISM330DHCX_ID,
  83        },
  84        {
  85                .compatible = "st,lsm9ds1-imu",
  86                .data = (void *)ST_LSM9DS1_ID,
  87        },
  88        {
  89                .compatible = "st,lsm6ds0",
  90                .data = (void *)ST_LSM6DS0_ID,
  91        },
  92        {
  93                .compatible = "st,lsm6dsrx",
  94                .data = (void *)ST_LSM6DSRX_ID,
  95        },
  96        {
  97                .compatible = "st,lsm6dst",
  98                .data = (void *)ST_LSM6DST_ID,
  99        },
 100        {
 101                .compatible = "st,lsm6dsop",
 102                .data = (void *)ST_LSM6DSOP_ID,
 103        },
 104        {},
 105};
 106MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match);
 107
 108static const struct i2c_device_id st_lsm6dsx_i2c_id_table[] = {
 109        { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID },
 110        { ST_LSM6DS3H_DEV_NAME, ST_LSM6DS3H_ID },
 111        { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID },
 112        { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
 113        { ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID },
 114        { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID },
 115        { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID },
 116        { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID },
 117        { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID },
 118        { ST_LSM6DS3TRC_DEV_NAME, ST_LSM6DS3TRC_ID },
 119        { ST_ISM330DHCX_DEV_NAME, ST_ISM330DHCX_ID },
 120        { ST_LSM9DS1_DEV_NAME, ST_LSM9DS1_ID },
 121        { ST_LSM6DS0_DEV_NAME, ST_LSM6DS0_ID },
 122        { ST_LSM6DSRX_DEV_NAME, ST_LSM6DSRX_ID },
 123        { ST_LSM6DST_DEV_NAME, ST_LSM6DST_ID },
 124        { ST_LSM6DSOP_DEV_NAME, ST_LSM6DSOP_ID },
 125        {},
 126};
 127MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
 128
 129static struct i2c_driver st_lsm6dsx_driver = {
 130        .driver = {
 131                .name = "st_lsm6dsx_i2c",
 132                .pm = &st_lsm6dsx_pm_ops,
 133                .of_match_table = st_lsm6dsx_i2c_of_match,
 134        },
 135        .probe = st_lsm6dsx_i2c_probe,
 136        .id_table = st_lsm6dsx_i2c_id_table,
 137};
 138module_i2c_driver(st_lsm6dsx_driver);
 139
 140MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
 141MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
 142MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i2c driver");
 143MODULE_LICENSE("GPL v2");
 144