Commit | Line | Data |
---|---|---|
f9ab96e2 MP |
1 | /* |
2 | * 3-axis accelerometer driver supporting SPI Bosch-Sensortec accelerometer chip | |
3 | * Copyright © 2015 Pengutronix, Markus Pargmann <mpa@pengutronix.de> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #include <linux/device.h> | |
20 | #include <linux/mod_devicetable.h> | |
21 | #include <linux/module.h> | |
22 | #include <linux/acpi.h> | |
23 | #include <linux/regmap.h> | |
24 | #include <linux/spi/spi.h> | |
25 | ||
26 | #include "bmc150-accel.h" | |
27 | ||
28 | static const struct regmap_config bmc150_spi_regmap_conf = { | |
29 | .reg_bits = 8, | |
30 | .val_bits = 8, | |
31 | .max_register = 0x3f, | |
32 | }; | |
33 | ||
34 | static int bmc150_accel_probe(struct spi_device *spi) | |
35 | { | |
36 | struct regmap *regmap; | |
37 | const struct spi_device_id *id = spi_get_device_id(spi); | |
38 | ||
39 | regmap = devm_regmap_init_spi(spi, &bmc150_spi_regmap_conf); | |
40 | if (IS_ERR(regmap)) { | |
41 | dev_err(&spi->dev, "Failed to initialize spi regmap\n"); | |
42 | return PTR_ERR(regmap); | |
43 | } | |
44 | ||
45 | return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, id->name, | |
46 | true); | |
47 | } | |
48 | ||
49 | static int bmc150_accel_remove(struct spi_device *spi) | |
50 | { | |
51 | return bmc150_accel_core_remove(&spi->dev); | |
52 | } | |
53 | ||
54 | static const struct acpi_device_id bmc150_accel_acpi_match[] = { | |
55 | {"BSBA0150", bmc150}, | |
56 | {"BMC150A", bmc150}, | |
57 | {"BMI055A", bmi055}, | |
58 | {"BMA0255", bma255}, | |
59 | {"BMA250E", bma250e}, | |
60 | {"BMA222E", bma222e}, | |
61 | {"BMA0280", bma280}, | |
62 | { }, | |
63 | }; | |
64 | MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match); | |
65 | ||
66 | static const struct spi_device_id bmc150_accel_id[] = { | |
67 | {"bmc150_accel", bmc150}, | |
68 | {"bmi055_accel", bmi055}, | |
69 | {"bma255", bma255}, | |
70 | {"bma250e", bma250e}, | |
71 | {"bma222e", bma222e}, | |
72 | {"bma280", bma280}, | |
73 | {} | |
74 | }; | |
75 | MODULE_DEVICE_TABLE(spi, bmc150_accel_id); | |
76 | ||
77 | static struct spi_driver bmc150_accel_driver = { | |
78 | .driver = { | |
79 | .name = "bmc150_accel_spi", | |
80 | .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match), | |
81 | .pm = &bmc150_accel_pm_ops, | |
82 | }, | |
83 | .probe = bmc150_accel_probe, | |
84 | .remove = bmc150_accel_remove, | |
85 | .id_table = bmc150_accel_id, | |
86 | }; | |
87 | module_spi_driver(bmc150_accel_driver); | |
88 | ||
89 | MODULE_AUTHOR("Markus Pargmann <mpa@pengutronix.de>"); | |
90 | MODULE_LICENSE("GPL v2"); | |
91 | MODULE_DESCRIPTION("BMC150 SPI accelerometer driver"); |