Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Murata ZPA2326 I2C pressure and temperature sensor driver
0004  *
0005  * Copyright (c) 2016 Parrot S.A.
0006  *
0007  * Author: Gregor Boirie <gregor.boirie@parrot.com>
0008  */
0009 
0010 #include <linux/module.h>
0011 #include <linux/regmap.h>
0012 #include <linux/i2c.h>
0013 #include <linux/mod_devicetable.h>
0014 #include "zpa2326.h"
0015 
0016 /*
0017  * read_flag_mask:
0018  *   - address bit 7 must be set to request a register read operation
0019  */
0020 static const struct regmap_config zpa2326_regmap_i2c_config = {
0021     .reg_bits       = 8,
0022     .val_bits       = 8,
0023     .writeable_reg  = zpa2326_isreg_writeable,
0024     .readable_reg   = zpa2326_isreg_readable,
0025     .precious_reg   = zpa2326_isreg_precious,
0026     .max_register   = ZPA2326_TEMP_OUT_H_REG,
0027     .read_flag_mask = BIT(7),
0028     .cache_type     = REGCACHE_NONE,
0029 };
0030 
0031 static unsigned int zpa2326_i2c_hwid(const struct i2c_client *client)
0032 {
0033 #define ZPA2326_SA0(_addr)          (_addr & BIT(0))
0034 #define ZPA2326_DEVICE_ID_SA0_SHIFT (1)
0035 
0036     /* Identification register bit 1 mirrors device address bit 0. */
0037     return (ZPA2326_DEVICE_ID |
0038         (ZPA2326_SA0(client->addr) << ZPA2326_DEVICE_ID_SA0_SHIFT));
0039 }
0040 
0041 static int zpa2326_probe_i2c(struct i2c_client          *client,
0042                  const struct i2c_device_id *i2c_id)
0043 {
0044     struct regmap *regmap;
0045 
0046     regmap = devm_regmap_init_i2c(client, &zpa2326_regmap_i2c_config);
0047     if (IS_ERR(regmap)) {
0048         dev_err(&client->dev, "failed to init registers map");
0049         return PTR_ERR(regmap);
0050     }
0051 
0052     return zpa2326_probe(&client->dev, i2c_id->name, client->irq,
0053                  zpa2326_i2c_hwid(client), regmap);
0054 }
0055 
0056 static int zpa2326_remove_i2c(struct i2c_client *client)
0057 {
0058     zpa2326_remove(&client->dev);
0059 
0060     return 0;
0061 }
0062 
0063 static const struct i2c_device_id zpa2326_i2c_ids[] = {
0064     { "zpa2326", 0 },
0065     { },
0066 };
0067 MODULE_DEVICE_TABLE(i2c, zpa2326_i2c_ids);
0068 
0069 static const struct of_device_id zpa2326_i2c_matches[] = {
0070     { .compatible = "murata,zpa2326" },
0071     { }
0072 };
0073 MODULE_DEVICE_TABLE(of, zpa2326_i2c_matches);
0074 
0075 static struct i2c_driver zpa2326_i2c_driver = {
0076     .driver = {
0077         .name           = "zpa2326-i2c",
0078         .of_match_table = zpa2326_i2c_matches,
0079         .pm             = ZPA2326_PM_OPS,
0080     },
0081     .probe    = zpa2326_probe_i2c,
0082     .remove   = zpa2326_remove_i2c,
0083     .id_table = zpa2326_i2c_ids,
0084 };
0085 module_i2c_driver(zpa2326_i2c_driver);
0086 
0087 MODULE_AUTHOR("Gregor Boirie <gregor.boirie@parrot.com>");
0088 MODULE_DESCRIPTION("I2C driver for Murata ZPA2326 pressure sensor");
0089 MODULE_LICENSE("GPL v2");
0090 MODULE_IMPORT_NS(IIO_ZPA2326);