18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * STMicroelectronics hts221 i2c driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2016 STMicroelectronics Inc.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Lorenzo Bianconi <lorenzo.bianconi@st.com>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/kernel.h>
118c2ecf20Sopenharmony_ci#include <linux/module.h>
128c2ecf20Sopenharmony_ci#include <linux/acpi.h>
138c2ecf20Sopenharmony_ci#include <linux/i2c.h>
148c2ecf20Sopenharmony_ci#include <linux/slab.h>
158c2ecf20Sopenharmony_ci#include <linux/regmap.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "hts221.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define HTS221_I2C_AUTO_INCREMENT	BIT(7)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic const struct regmap_config hts221_i2c_regmap_config = {
228c2ecf20Sopenharmony_ci	.reg_bits = 8,
238c2ecf20Sopenharmony_ci	.val_bits = 8,
248c2ecf20Sopenharmony_ci	.write_flag_mask = HTS221_I2C_AUTO_INCREMENT,
258c2ecf20Sopenharmony_ci	.read_flag_mask = HTS221_I2C_AUTO_INCREMENT,
268c2ecf20Sopenharmony_ci};
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistatic int hts221_i2c_probe(struct i2c_client *client,
298c2ecf20Sopenharmony_ci			    const struct i2c_device_id *id)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	struct regmap *regmap;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	regmap = devm_regmap_init_i2c(client, &hts221_i2c_regmap_config);
348c2ecf20Sopenharmony_ci	if (IS_ERR(regmap)) {
358c2ecf20Sopenharmony_ci		dev_err(&client->dev, "Failed to register i2c regmap %ld\n",
368c2ecf20Sopenharmony_ci			PTR_ERR(regmap));
378c2ecf20Sopenharmony_ci		return PTR_ERR(regmap);
388c2ecf20Sopenharmony_ci	}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	return hts221_probe(&client->dev, client->irq,
418c2ecf20Sopenharmony_ci			    client->name, regmap);
428c2ecf20Sopenharmony_ci}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic const struct acpi_device_id hts221_acpi_match[] = {
458c2ecf20Sopenharmony_ci	{"SMO9100", 0},
468c2ecf20Sopenharmony_ci	{ },
478c2ecf20Sopenharmony_ci};
488c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, hts221_acpi_match);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic const struct of_device_id hts221_i2c_of_match[] = {
518c2ecf20Sopenharmony_ci	{ .compatible = "st,hts221", },
528c2ecf20Sopenharmony_ci	{},
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, hts221_i2c_of_match);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic const struct i2c_device_id hts221_i2c_id_table[] = {
578c2ecf20Sopenharmony_ci	{ HTS221_DEV_NAME },
588c2ecf20Sopenharmony_ci	{},
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, hts221_i2c_id_table);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic struct i2c_driver hts221_driver = {
638c2ecf20Sopenharmony_ci	.driver = {
648c2ecf20Sopenharmony_ci		.name = "hts221_i2c",
658c2ecf20Sopenharmony_ci		.pm = &hts221_pm_ops,
668c2ecf20Sopenharmony_ci		.of_match_table = hts221_i2c_of_match,
678c2ecf20Sopenharmony_ci		.acpi_match_table = ACPI_PTR(hts221_acpi_match),
688c2ecf20Sopenharmony_ci	},
698c2ecf20Sopenharmony_ci	.probe = hts221_i2c_probe,
708c2ecf20Sopenharmony_ci	.id_table = hts221_i2c_id_table,
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_cimodule_i2c_driver(hts221_driver);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ciMODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
758c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("STMicroelectronics hts221 i2c driver");
768c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
77