1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * 3-axis magnetometer driver supporting following I2C Bosch-Sensortec chips: 4 * - BMC150 5 * - BMC156 6 * - BMM150 7 * 8 * Copyright (c) 2016, Intel Corporation. 9 */ 10 #include <linux/device.h> 11 #include <linux/mod_devicetable.h> 12 #include <linux/i2c.h> 13 #include <linux/module.h> 14 #include <linux/regmap.h> 15 16 #include "bmc150_magn.h" 17 18 static int bmc150_magn_i2c_probe(struct i2c_client *client) 19 { 20 const struct i2c_device_id *id = i2c_client_get_device_id(client); 21 struct regmap *regmap; 22 const char *name = NULL; 23 24 regmap = devm_regmap_init_i2c(client, &bmc150_magn_regmap_config); 25 if (IS_ERR(regmap)) { 26 dev_err(&client->dev, "Failed to initialize i2c regmap\n"); 27 return PTR_ERR(regmap); 28 } 29 30 if (id) 31 name = id->name; 32 33 return bmc150_magn_probe(&client->dev, regmap, client->irq, name); 34 } 35 36 static void bmc150_magn_i2c_remove(struct i2c_client *client) 37 { 38 bmc150_magn_remove(&client->dev); 39 } 40 41 static const struct acpi_device_id bmc150_magn_acpi_match[] = { 42 {"BMC150B", 0}, 43 {"BMC156B", 0}, 44 {"BMM150B", 0}, 45 {}, 46 }; 47 MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match); 48 49 static const struct i2c_device_id bmc150_magn_i2c_id[] = { 50 { "bmc150_magn" }, 51 { "bmc156_magn" }, 52 { "bmm150_magn" }, 53 {} 54 }; 55 MODULE_DEVICE_TABLE(i2c, bmc150_magn_i2c_id); 56 57 static const struct of_device_id bmc150_magn_of_match[] = { 58 { .compatible = "bosch,bmc150_magn" }, 59 { .compatible = "bosch,bmc156_magn" }, 60 { .compatible = "bosch,bmm150_magn" }, /* deprecated compatible */ 61 { .compatible = "bosch,bmm150" }, 62 { } 63 }; 64 MODULE_DEVICE_TABLE(of, bmc150_magn_of_match); 65 66 static struct i2c_driver bmc150_magn_driver = { 67 .driver = { 68 .name = "bmc150_magn_i2c", 69 .of_match_table = bmc150_magn_of_match, 70 .acpi_match_table = bmc150_magn_acpi_match, 71 .pm = &bmc150_magn_pm_ops, 72 }, 73 .probe = bmc150_magn_i2c_probe, 74 .remove = bmc150_magn_i2c_remove, 75 .id_table = bmc150_magn_i2c_id, 76 }; 77 module_i2c_driver(bmc150_magn_driver); 78 79 MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com"); 80 MODULE_LICENSE("GPL v2"); 81 MODULE_DESCRIPTION("BMC150 I2C magnetometer driver"); 82 MODULE_IMPORT_NS(IIO_BMC150_MAGN); 83