18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * I2C IIO driver for Bosch BMA400 triaxial acceleration sensor. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2019 Dan Robertson <dan@dlrobertson.com> 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * I2C address is either 0x14 or 0x15 depending on SDO 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#include <linux/i2c.h> 108c2ecf20Sopenharmony_ci#include <linux/mod_devicetable.h> 118c2ecf20Sopenharmony_ci#include <linux/module.h> 128c2ecf20Sopenharmony_ci#include <linux/regmap.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include "bma400.h" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistatic int bma400_i2c_probe(struct i2c_client *client, 178c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 188c2ecf20Sopenharmony_ci{ 198c2ecf20Sopenharmony_ci struct regmap *regmap; 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci regmap = devm_regmap_init_i2c(client, &bma400_regmap_config); 228c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 238c2ecf20Sopenharmony_ci dev_err(&client->dev, "failed to create regmap\n"); 248c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 258c2ecf20Sopenharmony_ci } 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci return bma400_probe(&client->dev, regmap, id->name); 288c2ecf20Sopenharmony_ci} 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistatic int bma400_i2c_remove(struct i2c_client *client) 318c2ecf20Sopenharmony_ci{ 328c2ecf20Sopenharmony_ci return bma400_remove(&client->dev); 338c2ecf20Sopenharmony_ci} 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cistatic const struct i2c_device_id bma400_i2c_ids[] = { 368c2ecf20Sopenharmony_ci { "bma400", 0 }, 378c2ecf20Sopenharmony_ci { } 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, bma400_i2c_ids); 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic const struct of_device_id bma400_of_i2c_match[] = { 428c2ecf20Sopenharmony_ci { .compatible = "bosch,bma400" }, 438c2ecf20Sopenharmony_ci { } 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, bma400_of_i2c_match); 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistatic struct i2c_driver bma400_i2c_driver = { 488c2ecf20Sopenharmony_ci .driver = { 498c2ecf20Sopenharmony_ci .name = "bma400", 508c2ecf20Sopenharmony_ci .of_match_table = bma400_of_i2c_match, 518c2ecf20Sopenharmony_ci }, 528c2ecf20Sopenharmony_ci .probe = bma400_i2c_probe, 538c2ecf20Sopenharmony_ci .remove = bma400_i2c_remove, 548c2ecf20Sopenharmony_ci .id_table = bma400_i2c_ids, 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cimodule_i2c_driver(bma400_i2c_driver); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciMODULE_AUTHOR("Dan Robertson <dan@dlrobertson.com>"); 608c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Bosch BMA400 triaxial acceleration sensor (I2C)"); 618c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 62