1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * BMI160 - Bosch IMU, SPI bits
4 *
5 * Copyright (c) 2016, Intel Corporation.
6 *
7 */
8 #include <linux/mod_devicetable.h>
9 #include <linux/module.h>
10 #include <linux/pm.h>
11 #include <linux/regmap.h>
12 #include <linux/spi/spi.h>
13
14 #include "bmi160.h"
15
bmi160_spi_probe(struct spi_device * spi)16 static int bmi160_spi_probe(struct spi_device *spi)
17 {
18 struct regmap *regmap;
19 const struct spi_device_id *id = spi_get_device_id(spi);
20 const char *name;
21
22 regmap = devm_regmap_init_spi(spi, &bmi160_regmap_config);
23 if (IS_ERR(regmap)) {
24 dev_err(&spi->dev, "Failed to register spi regmap: %pe\n",
25 regmap);
26 return PTR_ERR(regmap);
27 }
28
29 if (id)
30 name = id->name;
31 else
32 name = dev_name(&spi->dev);
33
34 return bmi160_core_probe(&spi->dev, regmap, name, true);
35 }
36
37 static const struct spi_device_id bmi160_spi_id[] = {
38 {"bmi120", 0},
39 {"bmi160", 0},
40 { }
41 };
42 MODULE_DEVICE_TABLE(spi, bmi160_spi_id);
43
44 static const struct acpi_device_id bmi160_acpi_match[] = {
45 {"BMI0120", 0},
46 {"BMI0160", 0},
47 { }
48 };
49 MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
50
51 static const struct of_device_id bmi160_of_match[] = {
52 { .compatible = "bosch,bmi120" },
53 { .compatible = "bosch,bmi160" },
54 { }
55 };
56 MODULE_DEVICE_TABLE(of, bmi160_of_match);
57
58 static struct spi_driver bmi160_spi_driver = {
59 .probe = bmi160_spi_probe,
60 .id_table = bmi160_spi_id,
61 .driver = {
62 .acpi_match_table = bmi160_acpi_match,
63 .of_match_table = bmi160_of_match,
64 .name = "bmi160_spi",
65 .pm = pm_ptr(&bmi160_core_pm_ops),
66 },
67 };
68 module_spi_driver(bmi160_spi_driver);
69
70 MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");
71 MODULE_DESCRIPTION("Bosch BMI160 SPI driver");
72 MODULE_LICENSE("GPL v2");
73 MODULE_IMPORT_NS("IIO_BMI160");
74