1 // SPDX-License-Identifier: GPL-2.0-only
3 * STMicroelectronics hts221 i2c driver
5 * Copyright 2016 STMicroelectronics Inc.
7 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/mod_devicetable.h>
13 #include <linux/i2c.h>
14 #include <linux/slab.h>
15 #include <linux/regmap.h>
19 #define HTS221_I2C_AUTO_INCREMENT BIT(7)
21 static const struct regmap_config hts221_i2c_regmap_config
= {
24 .write_flag_mask
= HTS221_I2C_AUTO_INCREMENT
,
25 .read_flag_mask
= HTS221_I2C_AUTO_INCREMENT
,
28 static int hts221_i2c_probe(struct i2c_client
*client
)
30 struct regmap
*regmap
;
32 regmap
= devm_regmap_init_i2c(client
, &hts221_i2c_regmap_config
);
34 dev_err(&client
->dev
, "Failed to register i2c regmap %ld\n",
36 return PTR_ERR(regmap
);
39 return hts221_probe(&client
->dev
, client
->irq
,
40 client
->name
, regmap
);
43 static const struct acpi_device_id hts221_acpi_match
[] = {
47 MODULE_DEVICE_TABLE(acpi
, hts221_acpi_match
);
49 static const struct of_device_id hts221_i2c_of_match
[] = {
50 { .compatible
= "st,hts221", },
53 MODULE_DEVICE_TABLE(of
, hts221_i2c_of_match
);
55 static const struct i2c_device_id hts221_i2c_id_table
[] = {
59 MODULE_DEVICE_TABLE(i2c
, hts221_i2c_id_table
);
61 static struct i2c_driver hts221_driver
= {
64 .pm
= pm_sleep_ptr(&hts221_pm_ops
),
65 .of_match_table
= hts221_i2c_of_match
,
66 .acpi_match_table
= hts221_acpi_match
,
68 .probe
= hts221_i2c_probe
,
69 .id_table
= hts221_i2c_id_table
,
71 module_i2c_driver(hts221_driver
);
73 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
74 MODULE_DESCRIPTION("STMicroelectronics hts221 i2c driver");
75 MODULE_LICENSE("GPL v2");
76 MODULE_IMPORT_NS("IIO_HTS221");