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