treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / iio / accel / adxl345_spi.c
blobda4591c7ef237da9effdb7a94d5d9915313f1864
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * ADXL345 3-Axis Digital Accelerometer SPI driver
5 * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com>
6 */
8 #include <linux/module.h>
9 #include <linux/regmap.h>
10 #include <linux/spi/spi.h>
12 #include "adxl345.h"
14 #define ADXL345_MAX_SPI_FREQ_HZ 5000000
16 static const struct regmap_config adxl345_spi_regmap_config = {
17 .reg_bits = 8,
18 .val_bits = 8,
19 /* Setting bits 7 and 6 enables multiple-byte read */
20 .read_flag_mask = BIT(7) | BIT(6),
23 static int adxl345_spi_probe(struct spi_device *spi)
25 const struct spi_device_id *id = spi_get_device_id(spi);
26 struct regmap *regmap;
28 /* Bail out if max_speed_hz exceeds 5 MHz */
29 if (spi->max_speed_hz > ADXL345_MAX_SPI_FREQ_HZ) {
30 dev_err(&spi->dev, "SPI CLK, %d Hz exceeds 5 MHz\n",
31 spi->max_speed_hz);
32 return -EINVAL;
35 regmap = devm_regmap_init_spi(spi, &adxl345_spi_regmap_config);
36 if (IS_ERR(regmap)) {
37 dev_err(&spi->dev, "Error initializing spi regmap: %ld\n",
38 PTR_ERR(regmap));
39 return PTR_ERR(regmap);
42 return adxl345_core_probe(&spi->dev, regmap, id->driver_data, id->name);
45 static int adxl345_spi_remove(struct spi_device *spi)
47 return adxl345_core_remove(&spi->dev);
50 static const struct spi_device_id adxl345_spi_id[] = {
51 { "adxl345", ADXL345 },
52 { "adxl375", ADXL375 },
53 { }
56 MODULE_DEVICE_TABLE(spi, adxl345_spi_id);
58 static const struct of_device_id adxl345_of_match[] = {
59 { .compatible = "adi,adxl345" },
60 { .compatible = "adi,adxl375" },
61 { },
64 MODULE_DEVICE_TABLE(of, adxl345_of_match);
66 static struct spi_driver adxl345_spi_driver = {
67 .driver = {
68 .name = "adxl345_spi",
69 .of_match_table = adxl345_of_match,
71 .probe = adxl345_spi_probe,
72 .remove = adxl345_spi_remove,
73 .id_table = adxl345_spi_id,
76 module_spi_driver(adxl345_spi_driver);
78 MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
79 MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer SPI driver");
80 MODULE_LICENSE("GPL v2");