18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * 3-axis accelerometer driver supporting following I2C Bosch-Sensortec chips: 48c2ecf20Sopenharmony_ci * - BMC150 58c2ecf20Sopenharmony_ci * - BMI055 68c2ecf20Sopenharmony_ci * - BMA255 78c2ecf20Sopenharmony_ci * - BMA250E 88c2ecf20Sopenharmony_ci * - BMA222E 98c2ecf20Sopenharmony_ci * - BMA280 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Copyright (c) 2014, Intel Corporation. 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/device.h> 158c2ecf20Sopenharmony_ci#include <linux/mod_devicetable.h> 168c2ecf20Sopenharmony_ci#include <linux/i2c.h> 178c2ecf20Sopenharmony_ci#include <linux/module.h> 188c2ecf20Sopenharmony_ci#include <linux/acpi.h> 198c2ecf20Sopenharmony_ci#include <linux/regmap.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#include "bmc150-accel.h" 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic int bmc150_accel_probe(struct i2c_client *client, 248c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 258c2ecf20Sopenharmony_ci{ 268c2ecf20Sopenharmony_ci struct regmap *regmap; 278c2ecf20Sopenharmony_ci const char *name = NULL; 288c2ecf20Sopenharmony_ci bool block_supported = 298c2ecf20Sopenharmony_ci i2c_check_functionality(client->adapter, I2C_FUNC_I2C) || 308c2ecf20Sopenharmony_ci i2c_check_functionality(client->adapter, 318c2ecf20Sopenharmony_ci I2C_FUNC_SMBUS_READ_I2C_BLOCK); 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci regmap = devm_regmap_init_i2c(client, &bmc150_regmap_conf); 348c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 358c2ecf20Sopenharmony_ci dev_err(&client->dev, "Failed to initialize i2c regmap\n"); 368c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 378c2ecf20Sopenharmony_ci } 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci if (id) 408c2ecf20Sopenharmony_ci name = id->name; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci return bmc150_accel_core_probe(&client->dev, regmap, client->irq, name, 438c2ecf20Sopenharmony_ci block_supported); 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic int bmc150_accel_remove(struct i2c_client *client) 478c2ecf20Sopenharmony_ci{ 488c2ecf20Sopenharmony_ci return bmc150_accel_core_remove(&client->dev); 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistatic const struct acpi_device_id bmc150_accel_acpi_match[] = { 528c2ecf20Sopenharmony_ci {"BSBA0150", bmc150}, 538c2ecf20Sopenharmony_ci {"BMC150A", bmc150}, 548c2ecf20Sopenharmony_ci {"BMI055A", bmi055}, 558c2ecf20Sopenharmony_ci {"BMA0255", bma255}, 568c2ecf20Sopenharmony_ci {"BMA250E", bma250e}, 578c2ecf20Sopenharmony_ci {"BMA222E", bma222e}, 588c2ecf20Sopenharmony_ci {"BMA0280", bma280}, 598c2ecf20Sopenharmony_ci {"BOSC0200"}, 608c2ecf20Sopenharmony_ci { }, 618c2ecf20Sopenharmony_ci}; 628c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match); 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistatic const struct i2c_device_id bmc150_accel_id[] = { 658c2ecf20Sopenharmony_ci {"bmc150_accel", bmc150}, 668c2ecf20Sopenharmony_ci {"bmi055_accel", bmi055}, 678c2ecf20Sopenharmony_ci {"bma255", bma255}, 688c2ecf20Sopenharmony_ci {"bma250e", bma250e}, 698c2ecf20Sopenharmony_ci {"bma222e", bma222e}, 708c2ecf20Sopenharmony_ci {"bma280", bma280}, 718c2ecf20Sopenharmony_ci {} 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, bmc150_accel_id); 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_cistatic const struct of_device_id bmc150_accel_of_match[] = { 778c2ecf20Sopenharmony_ci { .compatible = "bosch,bmc150_accel" }, 788c2ecf20Sopenharmony_ci { .compatible = "bosch,bmi055_accel" }, 798c2ecf20Sopenharmony_ci { .compatible = "bosch,bma255" }, 808c2ecf20Sopenharmony_ci { .compatible = "bosch,bma250e" }, 818c2ecf20Sopenharmony_ci { .compatible = "bosch,bma222e" }, 828c2ecf20Sopenharmony_ci { .compatible = "bosch,bma280" }, 838c2ecf20Sopenharmony_ci { }, 848c2ecf20Sopenharmony_ci}; 858c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, bmc150_accel_of_match); 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_cistatic struct i2c_driver bmc150_accel_driver = { 888c2ecf20Sopenharmony_ci .driver = { 898c2ecf20Sopenharmony_ci .name = "bmc150_accel_i2c", 908c2ecf20Sopenharmony_ci .of_match_table = bmc150_accel_of_match, 918c2ecf20Sopenharmony_ci .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match), 928c2ecf20Sopenharmony_ci .pm = &bmc150_accel_pm_ops, 938c2ecf20Sopenharmony_ci }, 948c2ecf20Sopenharmony_ci .probe = bmc150_accel_probe, 958c2ecf20Sopenharmony_ci .remove = bmc150_accel_remove, 968c2ecf20Sopenharmony_ci .id_table = bmc150_accel_id, 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_cimodule_i2c_driver(bmc150_accel_driver); 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ciMODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); 1018c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 1028c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("BMC150 I2C accelerometer driver"); 103