Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * ADXL345 3-Axis Digital Accelerometer SPI driver
0004  *
0005  * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com>
0006  */
0007 
0008 #include <linux/module.h>
0009 #include <linux/regmap.h>
0010 #include <linux/spi/spi.h>
0011 
0012 #include "adxl345.h"
0013 
0014 #define ADXL345_MAX_SPI_FREQ_HZ     5000000
0015 
0016 static const struct regmap_config adxl345_spi_regmap_config = {
0017     .reg_bits = 8,
0018     .val_bits = 8,
0019      /* Setting bits 7 and 6 enables multiple-byte read */
0020     .read_flag_mask = BIT(7) | BIT(6),
0021 };
0022 
0023 static int adxl345_spi_probe(struct spi_device *spi)
0024 {
0025     struct regmap *regmap;
0026 
0027     /* Bail out if max_speed_hz exceeds 5 MHz */
0028     if (spi->max_speed_hz > ADXL345_MAX_SPI_FREQ_HZ)
0029         return dev_err_probe(&spi->dev, -EINVAL, "SPI CLK, %d Hz exceeds 5 MHz\n",
0030                      spi->max_speed_hz);
0031 
0032     regmap = devm_regmap_init_spi(spi, &adxl345_spi_regmap_config);
0033     if (IS_ERR(regmap))
0034         return dev_err_probe(&spi->dev, PTR_ERR(regmap), "Error initializing regmap\n");
0035 
0036     return adxl345_core_probe(&spi->dev, regmap);
0037 }
0038 
0039 static const struct spi_device_id adxl345_spi_id[] = {
0040     { "adxl345", ADXL345 },
0041     { "adxl375", ADXL375 },
0042     { }
0043 };
0044 MODULE_DEVICE_TABLE(spi, adxl345_spi_id);
0045 
0046 static const struct of_device_id adxl345_of_match[] = {
0047     { .compatible = "adi,adxl345", .data = (const void *)ADXL345 },
0048     { .compatible = "adi,adxl375", .data = (const void *)ADXL375 },
0049     { }
0050 };
0051 MODULE_DEVICE_TABLE(of, adxl345_of_match);
0052 
0053 static const struct acpi_device_id adxl345_acpi_match[] = {
0054     { "ADS0345", ADXL345 },
0055     { }
0056 };
0057 MODULE_DEVICE_TABLE(acpi, adxl345_acpi_match);
0058 
0059 static struct spi_driver adxl345_spi_driver = {
0060     .driver = {
0061         .name   = "adxl345_spi",
0062         .of_match_table = adxl345_of_match,
0063         .acpi_match_table = adxl345_acpi_match,
0064     },
0065     .probe      = adxl345_spi_probe,
0066     .id_table   = adxl345_spi_id,
0067 };
0068 module_spi_driver(adxl345_spi_driver);
0069 
0070 MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
0071 MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer SPI driver");
0072 MODULE_LICENSE("GPL v2");
0073 MODULE_IMPORT_NS(IIO_ADXL345);