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