18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * ADXL345 3-Axis Digital Accelerometer I2C driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com> 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * 7-bit I2C slave address: 0x1D (ALT ADDRESS pin tied to VDDIO) or 88c2ecf20Sopenharmony_ci * 0x53 (ALT ADDRESS pin grounded) 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/i2c.h> 128c2ecf20Sopenharmony_ci#include <linux/module.h> 138c2ecf20Sopenharmony_ci#include <linux/regmap.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include "adxl345.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cistatic const struct regmap_config adxl345_i2c_regmap_config = { 188c2ecf20Sopenharmony_ci .reg_bits = 8, 198c2ecf20Sopenharmony_ci .val_bits = 8, 208c2ecf20Sopenharmony_ci}; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistatic int adxl345_i2c_probe(struct i2c_client *client, 238c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 248c2ecf20Sopenharmony_ci{ 258c2ecf20Sopenharmony_ci struct regmap *regmap; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci if (!id) 288c2ecf20Sopenharmony_ci return -ENODEV; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config); 318c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 328c2ecf20Sopenharmony_ci dev_err(&client->dev, "Error initializing i2c regmap: %ld\n", 338c2ecf20Sopenharmony_ci PTR_ERR(regmap)); 348c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 358c2ecf20Sopenharmony_ci } 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci return adxl345_core_probe(&client->dev, regmap, id->driver_data, 388c2ecf20Sopenharmony_ci id->name); 398c2ecf20Sopenharmony_ci} 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic int adxl345_i2c_remove(struct i2c_client *client) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci return adxl345_core_remove(&client->dev); 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic const struct i2c_device_id adxl345_i2c_id[] = { 478c2ecf20Sopenharmony_ci { "adxl345", ADXL345 }, 488c2ecf20Sopenharmony_ci { "adxl375", ADXL375 }, 498c2ecf20Sopenharmony_ci { } 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, adxl345_i2c_id); 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic const struct of_device_id adxl345_of_match[] = { 558c2ecf20Sopenharmony_ci { .compatible = "adi,adxl345" }, 568c2ecf20Sopenharmony_ci { .compatible = "adi,adxl375" }, 578c2ecf20Sopenharmony_ci { }, 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, adxl345_of_match); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistatic struct i2c_driver adxl345_i2c_driver = { 638c2ecf20Sopenharmony_ci .driver = { 648c2ecf20Sopenharmony_ci .name = "adxl345_i2c", 658c2ecf20Sopenharmony_ci .of_match_table = adxl345_of_match, 668c2ecf20Sopenharmony_ci }, 678c2ecf20Sopenharmony_ci .probe = adxl345_i2c_probe, 688c2ecf20Sopenharmony_ci .remove = adxl345_i2c_remove, 698c2ecf20Sopenharmony_ci .id_table = adxl345_i2c_id, 708c2ecf20Sopenharmony_ci}; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cimodule_i2c_driver(adxl345_i2c_driver); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ciMODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>"); 758c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer I2C driver"); 768c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 77