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/acpi.h>
15 #include <linux/regmap.h>
16 
17 #include "bmc150_magn.h"
18 
19 static int bmc150_magn_i2c_probe(struct i2c_client *client,
20 				 const struct i2c_device_id *id)
21 {
22 	struct regmap *regmap;
23 	const char *name = NULL;
24 
25 	regmap = devm_regmap_init_i2c(client, &bmc150_magn_regmap_config);
26 	if (IS_ERR(regmap)) {
27 		dev_err(&client->dev, "Failed to initialize i2c regmap\n");
28 		return PTR_ERR(regmap);
29 	}
30 
31 	if (id)
32 		name = id->name;
33 
34 	return bmc150_magn_probe(&client->dev, regmap, client->irq, name);
35 }
36 
37 static int bmc150_magn_i2c_remove(struct i2c_client *client)
38 {
39 	bmc150_magn_remove(&client->dev);
40 
41 	return 0;
42 }
43 
44 static const struct acpi_device_id bmc150_magn_acpi_match[] = {
45 	{"BMC150B", 0},
46 	{"BMC156B", 0},
47 	{"BMM150B", 0},
48 	{},
49 };
50 MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match);
51 
52 static const struct i2c_device_id bmc150_magn_i2c_id[] = {
53 	{"bmc150_magn",	0},
54 	{"bmc156_magn", 0},
55 	{"bmm150_magn", 0},
56 	{}
57 };
58 MODULE_DEVICE_TABLE(i2c, bmc150_magn_i2c_id);
59 
60 static const struct of_device_id bmc150_magn_of_match[] = {
61 	{ .compatible = "bosch,bmc150_magn" },
62 	{ .compatible = "bosch,bmc156_magn" },
63 	{ .compatible = "bosch,bmm150_magn" }, /* deprecated compatible */
64 	{ .compatible = "bosch,bmm150" },
65 	{ }
66 };
67 MODULE_DEVICE_TABLE(of, bmc150_magn_of_match);
68 
69 static struct i2c_driver bmc150_magn_driver = {
70 	.driver = {
71 		.name	= "bmc150_magn_i2c",
72 		.of_match_table = bmc150_magn_of_match,
73 		.acpi_match_table = ACPI_PTR(bmc150_magn_acpi_match),
74 		.pm	= &bmc150_magn_pm_ops,
75 	},
76 	.probe		= bmc150_magn_i2c_probe,
77 	.remove		= bmc150_magn_i2c_remove,
78 	.id_table	= bmc150_magn_i2c_id,
79 };
80 module_i2c_driver(bmc150_magn_driver);
81 
82 MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");
83 MODULE_LICENSE("GPL v2");
84 MODULE_DESCRIPTION("BMC150 I2C magnetometer driver");
85 MODULE_IMPORT_NS(IIO_BMC150_MAGN);
86