1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * 3-axis accelerometer driver supporting SPI Bosch-Sensortec accelerometer chip
4  * Copyright © 2015 Pengutronix, Markus Pargmann <mpa@pengutronix.de>
5  */
6 
7 #include <linux/device.h>
8 #include <linux/mod_devicetable.h>
9 #include <linux/module.h>
10 #include <linux/acpi.h>
11 #include <linux/regmap.h>
12 #include <linux/spi/spi.h>
13 
14 #include "bmc150-accel.h"
15 
16 static int bmc150_accel_probe(struct spi_device *spi)
17 {
18 	struct regmap *regmap;
19 	const char *name = NULL;
20 	enum bmc150_type type = BOSCH_UNKNOWN;
21 	const struct spi_device_id *id = spi_get_device_id(spi);
22 
23 	regmap = devm_regmap_init_spi(spi, &bmc150_regmap_conf);
24 	if (IS_ERR(regmap)) {
25 		dev_err(&spi->dev, "Failed to initialize spi regmap\n");
26 		return PTR_ERR(regmap);
27 	}
28 
29 	if (id) {
30 		name = id->name;
31 		type = id->driver_data;
32 	}
33 
34 	return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, type, name,
35 				       true);
36 }
37 
38 static int bmc150_accel_remove(struct spi_device *spi)
39 {
40 	bmc150_accel_core_remove(&spi->dev);
41 
42 	return 0;
43 }
44 
45 static const struct acpi_device_id bmc150_accel_acpi_match[] = {
46 	{"BMA0255"},
47 	{"BMA0280"},
48 	{"BMA222"},
49 	{"BMA222E"},
50 	{"BMA250E"},
51 	{"BMC150A"},
52 	{"BMI055A"},
53 	{"BSBA0150"},
54 	{ },
55 };
56 MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match);
57 
58 static const struct spi_device_id bmc150_accel_id[] = {
59 	{"bma222"},
60 	{"bma222e"},
61 	{"bma250e"},
62 	{"bma253"},
63 	{"bma255"},
64 	{"bma280"},
65 	{"bmc150_accel"},
66 	{"bmc156_accel", BOSCH_BMC156},
67 	{"bmi055_accel"},
68 	{}
69 };
70 MODULE_DEVICE_TABLE(spi, bmc150_accel_id);
71 
72 static struct spi_driver bmc150_accel_driver = {
73 	.driver = {
74 		.name	= "bmc150_accel_spi",
75 		.acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match),
76 		.pm	= &bmc150_accel_pm_ops,
77 	},
78 	.probe		= bmc150_accel_probe,
79 	.remove		= bmc150_accel_remove,
80 	.id_table	= bmc150_accel_id,
81 };
82 module_spi_driver(bmc150_accel_driver);
83 
84 MODULE_AUTHOR("Markus Pargmann <mpa@pengutronix.de>");
85 MODULE_LICENSE("GPL v2");
86 MODULE_DESCRIPTION("BMC150 SPI accelerometer driver");
87