2019-05-28 19:57:06 +03:00
// SPDX-License-Identifier: GPL-2.0-only
2016-10-13 23:06:04 +03:00
/*
* STMicroelectronics hts221 i2c driver
*
* Copyright 2016 STMicroelectronics Inc .
*
* Lorenzo Bianconi < lorenzo . bianconi @ st . com >
*/
# include <linux/kernel.h>
# include <linux/module.h>
2016-11-24 12:07:54 +03:00
# include <linux/acpi.h>
2016-10-13 23:06:04 +03:00
# include <linux/i2c.h>
# include <linux/slab.h>
2018-01-09 01:12:30 +03:00
# include <linux/regmap.h>
2016-10-13 23:06:04 +03:00
2018-01-09 01:12:30 +03:00
# include "hts221.h"
2016-10-13 23:06:04 +03:00
2018-01-09 01:12:30 +03:00
# define HTS221_I2C_AUTO_INCREMENT BIT(7)
2016-10-13 23:06:04 +03:00
2018-01-09 01:12:30 +03:00
static const struct regmap_config hts221_i2c_regmap_config = {
. reg_bits = 8 ,
. val_bits = 8 ,
. write_flag_mask = HTS221_I2C_AUTO_INCREMENT ,
. read_flag_mask = HTS221_I2C_AUTO_INCREMENT ,
2016-10-13 23:06:04 +03:00
} ;
static int hts221_i2c_probe ( struct i2c_client * client ,
const struct i2c_device_id * id )
{
2018-01-09 01:12:30 +03:00
struct regmap * regmap ;
regmap = devm_regmap_init_i2c ( client , & hts221_i2c_regmap_config ) ;
if ( IS_ERR ( regmap ) ) {
2020-03-13 13:49:55 +03:00
dev_err ( & client - > dev , " Failed to register i2c regmap %ld \n " ,
PTR_ERR ( regmap ) ) ;
2018-01-09 01:12:30 +03:00
return PTR_ERR ( regmap ) ;
}
2017-12-30 02:33:04 +03:00
return hts221_probe ( & client - > dev , client - > irq ,
2018-01-09 01:12:30 +03:00
client - > name , regmap ) ;
2016-10-13 23:06:04 +03:00
}
2016-11-24 12:07:54 +03:00
static const struct acpi_device_id hts221_acpi_match [ ] = {
{ " SMO9100 " , 0 } ,
{ } ,
} ;
MODULE_DEVICE_TABLE ( acpi , hts221_acpi_match ) ;
2016-10-13 23:06:04 +03:00
static const struct of_device_id hts221_i2c_of_match [ ] = {
{ . compatible = " st,hts221 " , } ,
{ } ,
} ;
MODULE_DEVICE_TABLE ( of , hts221_i2c_of_match ) ;
static const struct i2c_device_id hts221_i2c_id_table [ ] = {
{ HTS221_DEV_NAME } ,
{ } ,
} ;
MODULE_DEVICE_TABLE ( i2c , hts221_i2c_id_table ) ;
static struct i2c_driver hts221_driver = {
. driver = {
. name = " hts221_i2c " ,
2022-06-04 19:12:20 +03:00
. pm = pm_sleep_ptr ( & hts221_pm_ops ) ,
2020-03-13 13:49:54 +03:00
. of_match_table = hts221_i2c_of_match ,
2016-11-24 12:07:54 +03:00
. acpi_match_table = ACPI_PTR ( hts221_acpi_match ) ,
2016-10-13 23:06:04 +03:00
} ,
. probe = hts221_i2c_probe ,
. id_table = hts221_i2c_id_table ,
} ;
module_i2c_driver ( hts221_driver ) ;
MODULE_AUTHOR ( " Lorenzo Bianconi <lorenzo.bianconi@st.com> " ) ;
MODULE_DESCRIPTION ( " STMicroelectronics hts221 i2c driver " ) ;
MODULE_LICENSE ( " GPL v2 " ) ;
2022-06-04 19:12:21 +03:00
MODULE_IMPORT_NS ( IIO_HTS221 ) ;