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 19*f23215c1SUwe Kleine-König static int bmc150_magn_i2c_probe(struct i2c_client *client) 20761b7910SDaniel Baluta { 21*f23215c1SUwe Kleine-König const struct i2c_device_id *id = i2c_client_get_device_id(client); 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 37ed5c2f5fSUwe Kleine-König static void bmc150_magn_i2c_remove(struct i2c_client *client) 38761b7910SDaniel Baluta { 39d04d46ddSUwe Kleine-König bmc150_magn_remove(&client->dev); 40761b7910SDaniel Baluta } 41761b7910SDaniel Baluta 42761b7910SDaniel Baluta static const struct acpi_device_id bmc150_magn_acpi_match[] = { 43761b7910SDaniel Baluta {"BMC150B", 0}, 44761b7910SDaniel Baluta {"BMC156B", 0}, 459d75db36SDaniel Baluta {"BMM150B", 0}, 46761b7910SDaniel Baluta {}, 47761b7910SDaniel Baluta }; 48761b7910SDaniel Baluta MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match); 49761b7910SDaniel Baluta 50761b7910SDaniel Baluta static const struct i2c_device_id bmc150_magn_i2c_id[] = { 51761b7910SDaniel Baluta {"bmc150_magn", 0}, 52761b7910SDaniel Baluta {"bmc156_magn", 0}, 539d75db36SDaniel Baluta {"bmm150_magn", 0}, 54761b7910SDaniel Baluta {} 55761b7910SDaniel Baluta }; 56761b7910SDaniel Baluta MODULE_DEVICE_TABLE(i2c, bmc150_magn_i2c_id); 57761b7910SDaniel Baluta 5849926b12SJavier Martinez Canillas static const struct of_device_id bmc150_magn_of_match[] = { 5949926b12SJavier Martinez Canillas { .compatible = "bosch,bmc150_magn" }, 6049926b12SJavier Martinez Canillas { .compatible = "bosch,bmc156_magn" }, 610954bc97SKrzysztof Kozlowski { .compatible = "bosch,bmm150_magn" }, /* deprecated compatible */ 620954bc97SKrzysztof Kozlowski { .compatible = "bosch,bmm150" }, 6349926b12SJavier Martinez Canillas { } 6449926b12SJavier Martinez Canillas }; 6549926b12SJavier Martinez Canillas MODULE_DEVICE_TABLE(of, bmc150_magn_of_match); 6649926b12SJavier Martinez Canillas 67761b7910SDaniel Baluta static struct i2c_driver bmc150_magn_driver = { 68761b7910SDaniel Baluta .driver = { 69761b7910SDaniel Baluta .name = "bmc150_magn_i2c", 7049926b12SJavier Martinez Canillas .of_match_table = bmc150_magn_of_match, 71761b7910SDaniel Baluta .acpi_match_table = ACPI_PTR(bmc150_magn_acpi_match), 72761b7910SDaniel Baluta .pm = &bmc150_magn_pm_ops, 73761b7910SDaniel Baluta }, 74*f23215c1SUwe Kleine-König .probe_new = bmc150_magn_i2c_probe, 75761b7910SDaniel Baluta .remove = bmc150_magn_i2c_remove, 76761b7910SDaniel Baluta .id_table = bmc150_magn_i2c_id, 77761b7910SDaniel Baluta }; 78761b7910SDaniel Baluta module_i2c_driver(bmc150_magn_driver); 79761b7910SDaniel Baluta 80761b7910SDaniel Baluta MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com"); 81761b7910SDaniel Baluta MODULE_LICENSE("GPL v2"); 82761b7910SDaniel Baluta MODULE_DESCRIPTION("BMC150 I2C magnetometer driver"); 8347d6cae0SJonathan Cameron MODULE_IMPORT_NS(IIO_BMC150_MAGN); 84