12025cf9eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2761b7910SDaniel Baluta /* 3761b7910SDaniel Baluta * 3-axis magnetometer driver supporting following I2C Bosch-Sensortec chips: 4761b7910SDaniel Baluta * - BMC150 5761b7910SDaniel Baluta * - BMC156 69d75db36SDaniel Baluta * - BMM150 7761b7910SDaniel Baluta * 8761b7910SDaniel Baluta * Copyright (c) 2016, Intel Corporation. 9761b7910SDaniel Baluta */ 10761b7910SDaniel Baluta #include <linux/device.h> 11761b7910SDaniel Baluta #include <linux/mod_devicetable.h> 12761b7910SDaniel Baluta #include <linux/i2c.h> 13761b7910SDaniel Baluta #include <linux/module.h> 14761b7910SDaniel Baluta #include <linux/acpi.h> 15761b7910SDaniel Baluta #include <linux/regmap.h> 16761b7910SDaniel Baluta 17761b7910SDaniel Baluta #include "bmc150_magn.h" 18761b7910SDaniel Baluta 19761b7910SDaniel Baluta static int bmc150_magn_i2c_probe(struct i2c_client *client, 20761b7910SDaniel Baluta const struct i2c_device_id *id) 21761b7910SDaniel Baluta { 22761b7910SDaniel Baluta struct regmap *regmap; 23761b7910SDaniel Baluta const char *name = NULL; 24761b7910SDaniel Baluta 25761b7910SDaniel Baluta regmap = devm_regmap_init_i2c(client, &bmc150_magn_regmap_config); 26761b7910SDaniel Baluta if (IS_ERR(regmap)) { 27761b7910SDaniel Baluta dev_err(&client->dev, "Failed to initialize i2c regmap\n"); 28761b7910SDaniel Baluta return PTR_ERR(regmap); 29761b7910SDaniel Baluta } 30761b7910SDaniel Baluta 31761b7910SDaniel Baluta if (id) 32761b7910SDaniel Baluta name = id->name; 33761b7910SDaniel Baluta 34761b7910SDaniel Baluta return bmc150_magn_probe(&client->dev, regmap, client->irq, name); 35761b7910SDaniel Baluta } 36761b7910SDaniel Baluta 37761b7910SDaniel Baluta static int bmc150_magn_i2c_remove(struct i2c_client *client) 38761b7910SDaniel Baluta { 39*d04d46ddSUwe Kleine-König bmc150_magn_remove(&client->dev); 40*d04d46ddSUwe Kleine-König 41*d04d46ddSUwe Kleine-König return 0; 42761b7910SDaniel Baluta } 43761b7910SDaniel Baluta 44761b7910SDaniel Baluta static const struct acpi_device_id bmc150_magn_acpi_match[] = { 45761b7910SDaniel Baluta {"BMC150B", 0}, 46761b7910SDaniel Baluta {"BMC156B", 0}, 479d75db36SDaniel Baluta {"BMM150B", 0}, 48761b7910SDaniel Baluta {}, 49761b7910SDaniel Baluta }; 50761b7910SDaniel Baluta MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match); 51761b7910SDaniel Baluta 52761b7910SDaniel Baluta static const struct i2c_device_id bmc150_magn_i2c_id[] = { 53761b7910SDaniel Baluta {"bmc150_magn", 0}, 54761b7910SDaniel Baluta {"bmc156_magn", 0}, 559d75db36SDaniel Baluta {"bmm150_magn", 0}, 56761b7910SDaniel Baluta {} 57761b7910SDaniel Baluta }; 58761b7910SDaniel Baluta MODULE_DEVICE_TABLE(i2c, bmc150_magn_i2c_id); 59761b7910SDaniel Baluta 6049926b12SJavier Martinez Canillas static const struct of_device_id bmc150_magn_of_match[] = { 6149926b12SJavier Martinez Canillas { .compatible = "bosch,bmc150_magn" }, 6249926b12SJavier Martinez Canillas { .compatible = "bosch,bmc156_magn" }, 630954bc97SKrzysztof Kozlowski { .compatible = "bosch,bmm150_magn" }, /* deprecated compatible */ 640954bc97SKrzysztof Kozlowski { .compatible = "bosch,bmm150" }, 6549926b12SJavier Martinez Canillas { } 6649926b12SJavier Martinez Canillas }; 6749926b12SJavier Martinez Canillas MODULE_DEVICE_TABLE(of, bmc150_magn_of_match); 6849926b12SJavier Martinez Canillas 69761b7910SDaniel Baluta static struct i2c_driver bmc150_magn_driver = { 70761b7910SDaniel Baluta .driver = { 71761b7910SDaniel Baluta .name = "bmc150_magn_i2c", 7249926b12SJavier Martinez Canillas .of_match_table = bmc150_magn_of_match, 73761b7910SDaniel Baluta .acpi_match_table = ACPI_PTR(bmc150_magn_acpi_match), 74761b7910SDaniel Baluta .pm = &bmc150_magn_pm_ops, 75761b7910SDaniel Baluta }, 76761b7910SDaniel Baluta .probe = bmc150_magn_i2c_probe, 77761b7910SDaniel Baluta .remove = bmc150_magn_i2c_remove, 78761b7910SDaniel Baluta .id_table = bmc150_magn_i2c_id, 79761b7910SDaniel Baluta }; 80761b7910SDaniel Baluta module_i2c_driver(bmc150_magn_driver); 81761b7910SDaniel Baluta 82761b7910SDaniel Baluta MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com"); 83761b7910SDaniel Baluta MODULE_LICENSE("GPL v2"); 84761b7910SDaniel Baluta MODULE_DESCRIPTION("BMC150 I2C magnetometer driver"); 8547d6cae0SJonathan Cameron MODULE_IMPORT_NS(IIO_BMC150_MAGN); 86