| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* STMicroelectronics LSM9DS0 IMU driver |
| 4 |
* |
| 5 |
* Copyright (C) 2021, Intel Corporation |
| 6 |
* |
| 7 |
* Author: Andy Shevchenko <[email protected]> |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <linux/device/devres.h> |
| 11 |
#include <linux/err.h> |
| 12 |
#include <linux/gfp_types.h> |
| 13 |
#include <linux/i2c.h> |
| 14 |
#include <linux/module.h> |
| 15 |
#include <linux/mod_devicetable.h> |
| 16 |
#include <linux/regmap.h> |
| 17 |
|
| 18 |
#include <linux/iio/common/st_sensors_i2c.h> |
| 19 |
|
| 20 |
#include "st_lsm9ds0.h" |
| 21 |
|
| 22 |
static const struct of_device_id st_lsm9ds0_of_match[] = { |
| 23 |
{ |
| 24 |
.compatible = "st,lsm303d-imu", |
| 25 |
.data = LSM303D_IMU_DEV_NAME, |
| 26 |
}, |
| 27 |
{ |
| 28 |
.compatible = "st,lsm9ds0-imu", |
| 29 |
.data = LSM9DS0_IMU_DEV_NAME, |
| 30 |
}, |
| 31 |
{ } |
| 32 |
}; |
| 33 |
MODULE_DEVICE_TABLE(of, st_lsm9ds0_of_match); |
| 34 |
|
| 35 |
static const struct i2c_device_id st_lsm9ds0_id_table[] = { |
| 36 |
{ LSM303D_IMU_DEV_NAME }, |
| 37 |
{ LSM9DS0_IMU_DEV_NAME }, |
| 38 |
{ } |
| 39 |
}; |
| 40 |
MODULE_DEVICE_TABLE(i2c, st_lsm9ds0_id_table); |
| 41 |
|
| 42 |
static const struct acpi_device_id st_lsm9ds0_acpi_match[] = { |
| 43 |
{"ACCL0001", (kernel_ulong_t)LSM303D_IMU_DEV_NAME}, |
| 44 |
{ } |
| 45 |
}; |
| 46 |
MODULE_DEVICE_TABLE(acpi, st_lsm9ds0_acpi_match); |
| 47 |
|
| 48 |
static const struct regmap_config st_lsm9ds0_regmap_config = { |
| 49 |
.reg_bits = 8, |
| 50 |
.val_bits = 8, |
| 51 |
.read_flag_mask = 0x80, |
| 52 |
}; |
| 53 |
|
| 54 |
static int st_lsm9ds0_i2c_probe(struct i2c_client *client) |
| 55 |
{ |
| 56 |
const struct regmap_config *config = &st_lsm9ds0_regmap_config; |
| 57 |
struct device *dev = &client->dev; |
| 58 |
struct st_lsm9ds0 *lsm9ds0; |
| 59 |
struct regmap *regmap; |
| 60 |
|
| 61 |
st_sensors_dev_name_probe(dev, client->name, sizeof(client->name)); |
| 62 |
|
| 63 |
lsm9ds0 = devm_kzalloc(dev, sizeof(*lsm9ds0), GFP_KERNEL); |
| 64 |
if (!lsm9ds0) |
| 65 |
return -ENOMEM; |
| 66 |
|
| 67 |
lsm9ds0->dev = dev; |
| 68 |
lsm9ds0->name = client->name; |
| 69 |
lsm9ds0->irq = client->irq; |
| 70 |
|
| 71 |
regmap = devm_regmap_init_i2c(client, config); |
| 72 |
if (IS_ERR(regmap)) |
| 73 |
return PTR_ERR(regmap); |
| 74 |
|
| 75 |
i2c_set_clientdata(client, lsm9ds0); |
| 76 |
|
| 77 |
return st_lsm9ds0_probe(lsm9ds0, regmap); |
| 78 |
} |
| 79 |
|
| 80 |
static struct i2c_driver st_lsm9ds0_driver = { |
| 81 |
.driver = { |
| 82 |
.name = "st-lsm9ds0-i2c", |
| 83 |
.of_match_table = st_lsm9ds0_of_match, |
| 84 |
.acpi_match_table = st_lsm9ds0_acpi_match, |
| 85 |
}, |
| 86 |
.probe = st_lsm9ds0_i2c_probe, |
| 87 |
.id_table = st_lsm9ds0_id_table, |
| 88 |
}; |
| 89 |
module_i2c_driver(st_lsm9ds0_driver); |
| 90 |
|
| 91 |
MODULE_AUTHOR("Andy Shevchenko <[email protected]>"); |
| 92 |
MODULE_DESCRIPTION("STMicroelectronics LSM9DS0 IMU I2C driver"); |
| 93 |
MODULE_LICENSE("GPL v2"); |
| 94 |
MODULE_IMPORT_NS("IIO_ST_SENSORS"); |