18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * 3-axis magnetometer driver support following SPI 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/module.h> 118c2ecf20Sopenharmony_ci#include <linux/mod_devicetable.h> 128c2ecf20Sopenharmony_ci#include <linux/spi/spi.h> 138c2ecf20Sopenharmony_ci#include <linux/acpi.h> 148c2ecf20Sopenharmony_ci#include <linux/regmap.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include "bmc150_magn.h" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistatic int bmc150_magn_spi_probe(struct spi_device *spi) 198c2ecf20Sopenharmony_ci{ 208c2ecf20Sopenharmony_ci struct regmap *regmap; 218c2ecf20Sopenharmony_ci const struct spi_device_id *id = spi_get_device_id(spi); 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci regmap = devm_regmap_init_spi(spi, &bmc150_magn_regmap_config); 248c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 258c2ecf20Sopenharmony_ci dev_err(&spi->dev, "Failed to register spi regmap: %pe\n", 268c2ecf20Sopenharmony_ci regmap); 278c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 288c2ecf20Sopenharmony_ci } 298c2ecf20Sopenharmony_ci return bmc150_magn_probe(&spi->dev, regmap, spi->irq, id->name); 308c2ecf20Sopenharmony_ci} 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistatic int bmc150_magn_spi_remove(struct spi_device *spi) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci bmc150_magn_remove(&spi->dev); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci return 0; 378c2ecf20Sopenharmony_ci} 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic const struct spi_device_id bmc150_magn_spi_id[] = { 408c2ecf20Sopenharmony_ci {"bmc150_magn", 0}, 418c2ecf20Sopenharmony_ci {"bmc156_magn", 0}, 428c2ecf20Sopenharmony_ci {"bmm150_magn", 0}, 438c2ecf20Sopenharmony_ci {} 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(spi, bmc150_magn_spi_id); 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistatic const struct acpi_device_id bmc150_magn_acpi_match[] = { 488c2ecf20Sopenharmony_ci {"BMC150B", 0}, 498c2ecf20Sopenharmony_ci {"BMC156B", 0}, 508c2ecf20Sopenharmony_ci {"BMM150B", 0}, 518c2ecf20Sopenharmony_ci {}, 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistatic struct spi_driver bmc150_magn_spi_driver = { 568c2ecf20Sopenharmony_ci .probe = bmc150_magn_spi_probe, 578c2ecf20Sopenharmony_ci .remove = bmc150_magn_spi_remove, 588c2ecf20Sopenharmony_ci .id_table = bmc150_magn_spi_id, 598c2ecf20Sopenharmony_ci .driver = { 608c2ecf20Sopenharmony_ci .acpi_match_table = ACPI_PTR(bmc150_magn_acpi_match), 618c2ecf20Sopenharmony_ci .name = "bmc150_magn_spi", 628c2ecf20Sopenharmony_ci }, 638c2ecf20Sopenharmony_ci}; 648c2ecf20Sopenharmony_cimodule_spi_driver(bmc150_magn_spi_driver); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciMODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com"); 678c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("BMC150 magnetometer SPI driver"); 688c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 69