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