18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * ADXL372 3-Axis Digital Accelerometer I2C driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2018 Analog Devices Inc. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/i2c.h> 98c2ecf20Sopenharmony_ci#include <linux/mod_devicetable.h> 108c2ecf20Sopenharmony_ci#include <linux/module.h> 118c2ecf20Sopenharmony_ci#include <linux/regmap.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include "adxl372.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistatic const struct regmap_config adxl372_regmap_config = { 168c2ecf20Sopenharmony_ci .reg_bits = 8, 178c2ecf20Sopenharmony_ci .val_bits = 8, 188c2ecf20Sopenharmony_ci .readable_noinc_reg = adxl372_readable_noinc_reg, 198c2ecf20Sopenharmony_ci}; 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistatic int adxl372_i2c_probe(struct i2c_client *client, 228c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 238c2ecf20Sopenharmony_ci{ 248c2ecf20Sopenharmony_ci struct regmap *regmap; 258c2ecf20Sopenharmony_ci unsigned int regval; 268c2ecf20Sopenharmony_ci int ret; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci regmap = devm_regmap_init_i2c(client, &adxl372_regmap_config); 298c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) 308c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci ret = regmap_read(regmap, ADXL372_REVID, ®val); 338c2ecf20Sopenharmony_ci if (ret < 0) 348c2ecf20Sopenharmony_ci return ret; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci /* Starting with the 3rd revision an I2C chip bug was fixed */ 378c2ecf20Sopenharmony_ci if (regval < 3) 388c2ecf20Sopenharmony_ci dev_warn(&client->dev, 398c2ecf20Sopenharmony_ci "I2C might not work properly with other devices on the bus"); 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci return adxl372_probe(&client->dev, regmap, client->irq, id->name); 428c2ecf20Sopenharmony_ci} 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic const struct i2c_device_id adxl372_i2c_id[] = { 458c2ecf20Sopenharmony_ci { "adxl372", 0 }, 468c2ecf20Sopenharmony_ci {} 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, adxl372_i2c_id); 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic const struct of_device_id adxl372_of_match[] = { 518c2ecf20Sopenharmony_ci { .compatible = "adi,adxl372" }, 528c2ecf20Sopenharmony_ci { } 538c2ecf20Sopenharmony_ci}; 548c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, adxl372_of_match); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic struct i2c_driver adxl372_i2c_driver = { 578c2ecf20Sopenharmony_ci .driver = { 588c2ecf20Sopenharmony_ci .name = "adxl372_i2c", 598c2ecf20Sopenharmony_ci .of_match_table = adxl372_of_match, 608c2ecf20Sopenharmony_ci }, 618c2ecf20Sopenharmony_ci .probe = adxl372_i2c_probe, 628c2ecf20Sopenharmony_ci .id_table = adxl372_i2c_id, 638c2ecf20Sopenharmony_ci}; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cimodule_i2c_driver(adxl372_i2c_driver); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ciMODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>"); 688c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer I2C driver"); 698c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 70