Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/device.h>
0003 #include <linux/kernel.h>
0004 #include <linux/module.h>
0005 #include <linux/mod_devicetable.h>
0006 #include <linux/slab.h>
0007 #include <linux/i2c.h>
0008 #include <linux/delay.h>
0009 #include <linux/regmap.h>
0010 
0011 #include "kxsd9.h"
0012 
0013 static int kxsd9_i2c_probe(struct i2c_client *i2c,
0014                const struct i2c_device_id *id)
0015 {
0016     static const struct regmap_config config = {
0017         .reg_bits = 8,
0018         .val_bits = 8,
0019         .max_register = 0x0e,
0020     };
0021     struct regmap *regmap;
0022 
0023     regmap = devm_regmap_init_i2c(i2c, &config);
0024     if (IS_ERR(regmap)) {
0025         dev_err(&i2c->dev, "Failed to register i2c regmap: %pe\n",
0026             regmap);
0027         return PTR_ERR(regmap);
0028     }
0029 
0030     return kxsd9_common_probe(&i2c->dev,
0031                   regmap,
0032                   i2c->name);
0033 }
0034 
0035 static int kxsd9_i2c_remove(struct i2c_client *client)
0036 {
0037     kxsd9_common_remove(&client->dev);
0038 
0039     return 0;
0040 }
0041 
0042 static const struct of_device_id kxsd9_of_match[] = {
0043     { .compatible = "kionix,kxsd9", },
0044     { },
0045 };
0046 MODULE_DEVICE_TABLE(of, kxsd9_of_match);
0047 
0048 static const struct i2c_device_id kxsd9_i2c_id[] = {
0049     {"kxsd9", 0},
0050     { },
0051 };
0052 MODULE_DEVICE_TABLE(i2c, kxsd9_i2c_id);
0053 
0054 static struct i2c_driver kxsd9_i2c_driver = {
0055     .driver = {
0056         .name   = "kxsd9",
0057         .of_match_table = kxsd9_of_match,
0058         .pm = pm_ptr(&kxsd9_dev_pm_ops),
0059     },
0060     .probe      = kxsd9_i2c_probe,
0061     .remove     = kxsd9_i2c_remove,
0062     .id_table   = kxsd9_i2c_id,
0063 };
0064 module_i2c_driver(kxsd9_i2c_driver);
0065 
0066 MODULE_LICENSE("GPL v2");
0067 MODULE_DESCRIPTION("KXSD9 accelerometer I2C interface");
0068 MODULE_IMPORT_NS(IIO_KXSD9);