Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * ADXL345 3-Axis Digital Accelerometer I2C driver
0004  *
0005  * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com>
0006  *
0007  * 7-bit I2C slave address: 0x1D (ALT ADDRESS pin tied to VDDIO) or
0008  * 0x53 (ALT ADDRESS pin grounded)
0009  */
0010 
0011 #include <linux/i2c.h>
0012 #include <linux/module.h>
0013 #include <linux/regmap.h>
0014 
0015 #include "adxl345.h"
0016 
0017 static const struct regmap_config adxl345_i2c_regmap_config = {
0018     .reg_bits = 8,
0019     .val_bits = 8,
0020 };
0021 
0022 static int adxl345_i2c_probe(struct i2c_client *client)
0023 {
0024     struct regmap *regmap;
0025 
0026     regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config);
0027     if (IS_ERR(regmap))
0028         return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n");
0029 
0030     return adxl345_core_probe(&client->dev, regmap);
0031 }
0032 
0033 static const struct i2c_device_id adxl345_i2c_id[] = {
0034     { "adxl345", ADXL345 },
0035     { "adxl375", ADXL375 },
0036     { }
0037 };
0038 MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
0039 
0040 static const struct of_device_id adxl345_of_match[] = {
0041     { .compatible = "adi,adxl345", .data = (const void *)ADXL345 },
0042     { .compatible = "adi,adxl375", .data = (const void *)ADXL375 },
0043     { }
0044 };
0045 MODULE_DEVICE_TABLE(of, adxl345_of_match);
0046 
0047 static const struct acpi_device_id adxl345_acpi_match[] = {
0048     { "ADS0345", ADXL345 },
0049     { }
0050 };
0051 MODULE_DEVICE_TABLE(acpi, adxl345_acpi_match);
0052 
0053 static struct i2c_driver adxl345_i2c_driver = {
0054     .driver = {
0055         .name   = "adxl345_i2c",
0056         .of_match_table = adxl345_of_match,
0057         .acpi_match_table = adxl345_acpi_match,
0058     },
0059     .probe_new  = adxl345_i2c_probe,
0060     .id_table   = adxl345_i2c_id,
0061 };
0062 module_i2c_driver(adxl345_i2c_driver);
0063 
0064 MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
0065 MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer I2C driver");
0066 MODULE_LICENSE("GPL v2");
0067 MODULE_IMPORT_NS(IIO_ADXL345);