1 /*
2  * 3-axis magnetometer driver support following SPI Bosch-Sensortec chips:
3  *  - BMC150
4  *  - BMC156
5  *  - BMM150
6  *
7  * Copyright (c) 2016, Intel Corporation.
8  *
9  * This file is subject to the terms and conditions of version 2 of
10  * the GNU General Public License.  See the file COPYING in the main
11  * directory of this archive for more details.
12  */
13 #include <linux/module.h>
14 #include <linux/mod_devicetable.h>
15 #include <linux/spi/spi.h>
16 #include <linux/acpi.h>
17 #include <linux/regmap.h>
18 
19 #include "bmc150_magn.h"
20 
21 static int bmc150_magn_spi_probe(struct spi_device *spi)
22 {
23 	struct regmap *regmap;
24 	const struct spi_device_id *id = spi_get_device_id(spi);
25 
26 	regmap = devm_regmap_init_spi(spi, &bmc150_magn_regmap_config);
27 	if (IS_ERR(regmap)) {
28 		dev_err(&spi->dev, "Failed to register spi regmap %d\n",
29 			(int)PTR_ERR(regmap));
30 		return PTR_ERR(regmap);
31 	}
32 	return bmc150_magn_probe(&spi->dev, regmap, spi->irq, id->name);
33 }
34 
35 static int bmc150_magn_spi_remove(struct spi_device *spi)
36 {
37 	bmc150_magn_remove(&spi->dev);
38 
39 	return 0;
40 }
41 
42 static const struct spi_device_id bmc150_magn_spi_id[] = {
43 	{"bmc150_magn", 0},
44 	{"bmc156_magn", 0},
45 	{"bmm150_magn", 0},
46 	{}
47 };
48 MODULE_DEVICE_TABLE(spi, bmc150_magn_spi_id);
49 
50 static const struct acpi_device_id bmc150_magn_acpi_match[] = {
51 	{"BMC150B", 0},
52 	{"BMC156B", 0},
53 	{"BMM150B", 0},
54 	{},
55 };
56 MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match);
57 
58 static struct spi_driver bmc150_magn_spi_driver = {
59 	.probe		= bmc150_magn_spi_probe,
60 	.remove		= bmc150_magn_spi_remove,
61 	.id_table	= bmc150_magn_spi_id,
62 	.driver = {
63 		.acpi_match_table = ACPI_PTR(bmc150_magn_acpi_match),
64 		.name	= "bmc150_magn_spi",
65 	},
66 };
67 module_spi_driver(bmc150_magn_spi_driver);
68 
69 MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");
70 MODULE_DESCRIPTION("BMC150 magnetometer SPI driver");
71 MODULE_LICENSE("GPL v2");
72