1fda8d26eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2e4a70e3eSLorenzo Bianconi /*
3e4a70e3eSLorenzo Bianconi * STMicroelectronics hts221 i2c driver
4e4a70e3eSLorenzo Bianconi *
5e4a70e3eSLorenzo Bianconi * Copyright 2016 STMicroelectronics Inc.
6e4a70e3eSLorenzo Bianconi *
7e4a70e3eSLorenzo Bianconi * Lorenzo Bianconi <lorenzo.bianconi@st.com>
8e4a70e3eSLorenzo Bianconi */
9e4a70e3eSLorenzo Bianconi
10e4a70e3eSLorenzo Bianconi #include <linux/kernel.h>
11e4a70e3eSLorenzo Bianconi #include <linux/module.h>
12*3049e640SJonathan Cameron #include <linux/mod_devicetable.h>
13e4a70e3eSLorenzo Bianconi #include <linux/i2c.h>
14e4a70e3eSLorenzo Bianconi #include <linux/slab.h>
1562177922SLorenzo Bianconi #include <linux/regmap.h>
1662177922SLorenzo Bianconi
17e4a70e3eSLorenzo Bianconi #include "hts221.h"
18e4a70e3eSLorenzo Bianconi
1962177922SLorenzo Bianconi #define HTS221_I2C_AUTO_INCREMENT BIT(7)
20e4a70e3eSLorenzo Bianconi
2162177922SLorenzo Bianconi static const struct regmap_config hts221_i2c_regmap_config = {
2262177922SLorenzo Bianconi .reg_bits = 8,
2362177922SLorenzo Bianconi .val_bits = 8,
2462177922SLorenzo Bianconi .write_flag_mask = HTS221_I2C_AUTO_INCREMENT,
2562177922SLorenzo Bianconi .read_flag_mask = HTS221_I2C_AUTO_INCREMENT,
26e4a70e3eSLorenzo Bianconi };
27e4a70e3eSLorenzo Bianconi
hts221_i2c_probe(struct i2c_client * client)287b64a83cSUwe Kleine-König static int hts221_i2c_probe(struct i2c_client *client)
29e4a70e3eSLorenzo Bianconi {
3062177922SLorenzo Bianconi struct regmap *regmap;
3162177922SLorenzo Bianconi
3262177922SLorenzo Bianconi regmap = devm_regmap_init_i2c(client, &hts221_i2c_regmap_config);
3362177922SLorenzo Bianconi if (IS_ERR(regmap)) {
34144eb562SAndy Shevchenko dev_err(&client->dev, "Failed to register i2c regmap %ld\n",
35144eb562SAndy Shevchenko PTR_ERR(regmap));
3662177922SLorenzo Bianconi return PTR_ERR(regmap);
3762177922SLorenzo Bianconi }
3862177922SLorenzo Bianconi
39e1ca1141SLorenzo Bianconi return hts221_probe(&client->dev, client->irq,
4062177922SLorenzo Bianconi client->name, regmap);
41e4a70e3eSLorenzo Bianconi }
42e4a70e3eSLorenzo Bianconi
4325fc503eSShrirang Bagul static const struct acpi_device_id hts221_acpi_match[] = {
4425fc503eSShrirang Bagul {"SMO9100", 0},
4525fc503eSShrirang Bagul { },
4625fc503eSShrirang Bagul };
4725fc503eSShrirang Bagul MODULE_DEVICE_TABLE(acpi, hts221_acpi_match);
4825fc503eSShrirang Bagul
49e4a70e3eSLorenzo Bianconi static const struct of_device_id hts221_i2c_of_match[] = {
50e4a70e3eSLorenzo Bianconi { .compatible = "st,hts221", },
51e4a70e3eSLorenzo Bianconi {},
52e4a70e3eSLorenzo Bianconi };
53e4a70e3eSLorenzo Bianconi MODULE_DEVICE_TABLE(of, hts221_i2c_of_match);
54e4a70e3eSLorenzo Bianconi
55e4a70e3eSLorenzo Bianconi static const struct i2c_device_id hts221_i2c_id_table[] = {
56e4a70e3eSLorenzo Bianconi { HTS221_DEV_NAME },
57e4a70e3eSLorenzo Bianconi {},
58e4a70e3eSLorenzo Bianconi };
59e4a70e3eSLorenzo Bianconi MODULE_DEVICE_TABLE(i2c, hts221_i2c_id_table);
60e4a70e3eSLorenzo Bianconi
61e4a70e3eSLorenzo Bianconi static struct i2c_driver hts221_driver = {
62e4a70e3eSLorenzo Bianconi .driver = {
63e4a70e3eSLorenzo Bianconi .name = "hts221_i2c",
642129f25dSJonathan Cameron .pm = pm_sleep_ptr(&hts221_pm_ops),
6592c3e93bSAndy Shevchenko .of_match_table = hts221_i2c_of_match,
66*3049e640SJonathan Cameron .acpi_match_table = hts221_acpi_match,
67e4a70e3eSLorenzo Bianconi },
687cf15f42SUwe Kleine-König .probe = hts221_i2c_probe,
69e4a70e3eSLorenzo Bianconi .id_table = hts221_i2c_id_table,
70e4a70e3eSLorenzo Bianconi };
71e4a70e3eSLorenzo Bianconi module_i2c_driver(hts221_driver);
72e4a70e3eSLorenzo Bianconi
73e4a70e3eSLorenzo Bianconi MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
74e4a70e3eSLorenzo Bianconi MODULE_DESCRIPTION("STMicroelectronics hts221 i2c driver");
75e4a70e3eSLorenzo Bianconi MODULE_LICENSE("GPL v2");
761300ab39SJonathan Cameron MODULE_IMPORT_NS(IIO_HTS221);
77