18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * 3-axis magnetometer driver supporting following I2C Bosch-Sensortec chips: 48c2ecf20Sopenharmony_ci * - BMC150 58c2ecf20Sopenharmony_ci * - BMC156 68c2ecf20Sopenharmony_ci * - BMM150 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Copyright (c) 2016, Intel Corporation. 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci#include <linux/device.h> 118c2ecf20Sopenharmony_ci#include <linux/mod_devicetable.h> 128c2ecf20Sopenharmony_ci#include <linux/i2c.h> 138c2ecf20Sopenharmony_ci#include <linux/module.h> 148c2ecf20Sopenharmony_ci#include <linux/acpi.h> 158c2ecf20Sopenharmony_ci#include <linux/regmap.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include "bmc150_magn.h" 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistatic int bmc150_magn_i2c_probe(struct i2c_client *client, 208c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 218c2ecf20Sopenharmony_ci{ 228c2ecf20Sopenharmony_ci struct regmap *regmap; 238c2ecf20Sopenharmony_ci const char *name = NULL; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci regmap = devm_regmap_init_i2c(client, &bmc150_magn_regmap_config); 268c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 278c2ecf20Sopenharmony_ci dev_err(&client->dev, "Failed to initialize i2c regmap\n"); 288c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 298c2ecf20Sopenharmony_ci } 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci if (id) 328c2ecf20Sopenharmony_ci name = id->name; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci return bmc150_magn_probe(&client->dev, regmap, client->irq, name); 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic int bmc150_magn_i2c_remove(struct i2c_client *client) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci return bmc150_magn_remove(&client->dev); 408c2ecf20Sopenharmony_ci} 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistatic const struct acpi_device_id bmc150_magn_acpi_match[] = { 438c2ecf20Sopenharmony_ci {"BMC150B", 0}, 448c2ecf20Sopenharmony_ci {"BMC156B", 0}, 458c2ecf20Sopenharmony_ci {"BMM150B", 0}, 468c2ecf20Sopenharmony_ci {}, 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match); 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic const struct i2c_device_id bmc150_magn_i2c_id[] = { 518c2ecf20Sopenharmony_ci {"bmc150_magn", 0}, 528c2ecf20Sopenharmony_ci {"bmc156_magn", 0}, 538c2ecf20Sopenharmony_ci {"bmm150_magn", 0}, 548c2ecf20Sopenharmony_ci {} 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, bmc150_magn_i2c_id); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistatic const struct of_device_id bmc150_magn_of_match[] = { 598c2ecf20Sopenharmony_ci { .compatible = "bosch,bmc150_magn" }, 608c2ecf20Sopenharmony_ci { .compatible = "bosch,bmc156_magn" }, 618c2ecf20Sopenharmony_ci { .compatible = "bosch,bmm150_magn" }, /* deprecated compatible */ 628c2ecf20Sopenharmony_ci { .compatible = "bosch,bmm150" }, 638c2ecf20Sopenharmony_ci { } 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, bmc150_magn_of_match); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cistatic struct i2c_driver bmc150_magn_driver = { 688c2ecf20Sopenharmony_ci .driver = { 698c2ecf20Sopenharmony_ci .name = "bmc150_magn_i2c", 708c2ecf20Sopenharmony_ci .of_match_table = bmc150_magn_of_match, 718c2ecf20Sopenharmony_ci .acpi_match_table = ACPI_PTR(bmc150_magn_acpi_match), 728c2ecf20Sopenharmony_ci .pm = &bmc150_magn_pm_ops, 738c2ecf20Sopenharmony_ci }, 748c2ecf20Sopenharmony_ci .probe = bmc150_magn_i2c_probe, 758c2ecf20Sopenharmony_ci .remove = bmc150_magn_i2c_remove, 768c2ecf20Sopenharmony_ci .id_table = bmc150_magn_i2c_id, 778c2ecf20Sopenharmony_ci}; 788c2ecf20Sopenharmony_cimodule_i2c_driver(bmc150_magn_driver); 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ciMODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com"); 818c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 828c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("BMC150 I2C magnetometer driver"); 83