perf python: Do not force closing original perf descriptor in evlist.get_pollfd()
[linux/fpc-iii.git] / drivers / iio / accel / adxl345_spi.c
blob67b7c66a84929f49f819e8e3a6e078780b84828f
1 /*
2 * ADXL345 3-Axis Digital Accelerometer SPI driver
4 * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com>
6 * This file is subject to the terms and conditions of version 2 of
7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.
9 */
11 #include <linux/module.h>
12 #include <linux/regmap.h>
13 #include <linux/spi/spi.h>
15 #include "adxl345.h"
17 #define ADXL345_MAX_SPI_FREQ_HZ 5000000
19 static const struct regmap_config adxl345_spi_regmap_config = {
20 .reg_bits = 8,
21 .val_bits = 8,
22 /* Setting bits 7 and 6 enables multiple-byte read */
23 .read_flag_mask = BIT(7) | BIT(6),
26 static int adxl345_spi_probe(struct spi_device *spi)
28 const struct spi_device_id *id = spi_get_device_id(spi);
29 struct regmap *regmap;
31 /* Bail out if max_speed_hz exceeds 5 MHz */
32 if (spi->max_speed_hz > ADXL345_MAX_SPI_FREQ_HZ) {
33 dev_err(&spi->dev, "SPI CLK, %d Hz exceeds 5 MHz\n",
34 spi->max_speed_hz);
35 return -EINVAL;
38 regmap = devm_regmap_init_spi(spi, &adxl345_spi_regmap_config);
39 if (IS_ERR(regmap)) {
40 dev_err(&spi->dev, "Error initializing spi regmap: %ld\n",
41 PTR_ERR(regmap));
42 return PTR_ERR(regmap);
45 return adxl345_core_probe(&spi->dev, regmap, id->driver_data, id->name);
48 static int adxl345_spi_remove(struct spi_device *spi)
50 return adxl345_core_remove(&spi->dev);
53 static const struct spi_device_id adxl345_spi_id[] = {
54 { "adxl345", ADXL345 },
55 { "adxl375", ADXL375 },
56 { }
59 MODULE_DEVICE_TABLE(spi, adxl345_spi_id);
61 static const struct of_device_id adxl345_of_match[] = {
62 { .compatible = "adi,adxl345" },
63 { .compatible = "adi,adxl375" },
64 { },
67 MODULE_DEVICE_TABLE(of, adxl345_of_match);
69 static struct spi_driver adxl345_spi_driver = {
70 .driver = {
71 .name = "adxl345_spi",
72 .of_match_table = adxl345_of_match,
74 .probe = adxl345_spi_probe,
75 .remove = adxl345_spi_remove,
76 .id_table = adxl345_spi_id,
79 module_spi_driver(adxl345_spi_driver);
81 MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
82 MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer SPI driver");
83 MODULE_LICENSE("GPL v2");