Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Gregor Boirie | 03b262f | 2016-09-13 14:23:14 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Murata ZPA2326 I2C pressure and temperature sensor driver |
| 4 | * |
| 5 | * Copyright (c) 2016 Parrot S.A. |
| 6 | * |
| 7 | * Author: Gregor Boirie <gregor.boirie@parrot.com> |
Gregor Boirie | 03b262f | 2016-09-13 14:23:14 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/regmap.h> |
| 12 | #include <linux/i2c.h> |
Jonathan Cameron | a409d2b | 2020-09-10 18:32:24 +0100 | [diff] [blame] | 13 | #include <linux/mod_devicetable.h> |
Gregor Boirie | 03b262f | 2016-09-13 14:23:14 +0200 | [diff] [blame] | 14 | #include "zpa2326.h" |
| 15 | |
| 16 | /* |
| 17 | * read_flag_mask: |
| 18 | * - address bit 7 must be set to request a register read operation |
| 19 | */ |
| 20 | static const struct regmap_config zpa2326_regmap_i2c_config = { |
| 21 | .reg_bits = 8, |
| 22 | .val_bits = 8, |
| 23 | .writeable_reg = zpa2326_isreg_writeable, |
| 24 | .readable_reg = zpa2326_isreg_readable, |
| 25 | .precious_reg = zpa2326_isreg_precious, |
| 26 | .max_register = ZPA2326_TEMP_OUT_H_REG, |
| 27 | .read_flag_mask = BIT(7), |
| 28 | .cache_type = REGCACHE_NONE, |
| 29 | }; |
| 30 | |
| 31 | static unsigned int zpa2326_i2c_hwid(const struct i2c_client *client) |
| 32 | { |
| 33 | #define ZPA2326_SA0(_addr) (_addr & BIT(0)) |
| 34 | #define ZPA2326_DEVICE_ID_SA0_SHIFT (1) |
| 35 | |
| 36 | /* Identification register bit 1 mirrors device address bit 0. */ |
| 37 | return (ZPA2326_DEVICE_ID | |
| 38 | (ZPA2326_SA0(client->addr) << ZPA2326_DEVICE_ID_SA0_SHIFT)); |
| 39 | } |
| 40 | |
| 41 | static int zpa2326_probe_i2c(struct i2c_client *client, |
| 42 | const struct i2c_device_id *i2c_id) |
| 43 | { |
| 44 | struct regmap *regmap; |
| 45 | |
| 46 | regmap = devm_regmap_init_i2c(client, &zpa2326_regmap_i2c_config); |
| 47 | if (IS_ERR(regmap)) { |
| 48 | dev_err(&client->dev, "failed to init registers map"); |
| 49 | return PTR_ERR(regmap); |
| 50 | } |
| 51 | |
| 52 | return zpa2326_probe(&client->dev, i2c_id->name, client->irq, |
| 53 | zpa2326_i2c_hwid(client), regmap); |
| 54 | } |
| 55 | |
Uwe Kleine-König | ed5c2f5 | 2022-08-15 10:02:30 +0200 | [diff] [blame] | 56 | static void zpa2326_remove_i2c(struct i2c_client *client) |
Gregor Boirie | 03b262f | 2016-09-13 14:23:14 +0200 | [diff] [blame] | 57 | { |
| 58 | zpa2326_remove(&client->dev); |
Gregor Boirie | 03b262f | 2016-09-13 14:23:14 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static const struct i2c_device_id zpa2326_i2c_ids[] = { |
| 62 | { "zpa2326", 0 }, |
| 63 | { }, |
| 64 | }; |
| 65 | MODULE_DEVICE_TABLE(i2c, zpa2326_i2c_ids); |
| 66 | |
Gregor Boirie | 03b262f | 2016-09-13 14:23:14 +0200 | [diff] [blame] | 67 | static const struct of_device_id zpa2326_i2c_matches[] = { |
| 68 | { .compatible = "murata,zpa2326" }, |
| 69 | { } |
| 70 | }; |
| 71 | MODULE_DEVICE_TABLE(of, zpa2326_i2c_matches); |
Gregor Boirie | 03b262f | 2016-09-13 14:23:14 +0200 | [diff] [blame] | 72 | |
| 73 | static struct i2c_driver zpa2326_i2c_driver = { |
| 74 | .driver = { |
| 75 | .name = "zpa2326-i2c", |
Jonathan Cameron | a409d2b | 2020-09-10 18:32:24 +0100 | [diff] [blame] | 76 | .of_match_table = zpa2326_i2c_matches, |
Gregor Boirie | 03b262f | 2016-09-13 14:23:14 +0200 | [diff] [blame] | 77 | .pm = ZPA2326_PM_OPS, |
| 78 | }, |
| 79 | .probe = zpa2326_probe_i2c, |
| 80 | .remove = zpa2326_remove_i2c, |
| 81 | .id_table = zpa2326_i2c_ids, |
| 82 | }; |
| 83 | module_i2c_driver(zpa2326_i2c_driver); |
| 84 | |
| 85 | MODULE_AUTHOR("Gregor Boirie <gregor.boirie@parrot.com>"); |
| 86 | MODULE_DESCRIPTION("I2C driver for Murata ZPA2326 pressure sensor"); |
| 87 | MODULE_LICENSE("GPL v2"); |
Jonathan Cameron | c8629ec | 2022-01-30 20:56:54 +0000 | [diff] [blame] | 88 | MODULE_IMPORT_NS(IIO_ZPA2326); |