File Index
Files and directories
Sign in
FILE

zpa2326_i2c.c

File preview with syntax highlighting.

linux-6.19.14/drivers/iio/pressure/zpa2326_i2c.c C
 1// SPDX-License-Identifier: GPL-2.0-only
 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>
 8 */
 9
10#include <linux/module.h>
11#include <linux/regmap.h>
12#include <linux/i2c.h>
13#include <linux/mod_devicetable.h>
14#include "zpa2326.h"
15
16/*
17 * read_flag_mask:
18 *   - address bit 7 must be set to request a register read operation
19 */
20static 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};
29
30static unsigned int zpa2326_i2c_hwid(const struct i2c_client *client)
31{
32#define ZPA2326_SA0(_addr)          (_addr & BIT(0))
33#define ZPA2326_DEVICE_ID_SA0_SHIFT (1)
34
35	/* Identification register bit 1 mirrors device address bit 0. */
36	return (ZPA2326_DEVICE_ID |
37		(ZPA2326_SA0(client->addr) << ZPA2326_DEVICE_ID_SA0_SHIFT));
38}
39
40static int zpa2326_probe_i2c(struct i2c_client          *client)
41{
42	const struct i2c_device_id *i2c_id = i2c_client_get_device_id(client);
43	struct regmap *regmap;
44
45	regmap = devm_regmap_init_i2c(client, &zpa2326_regmap_i2c_config);
46	if (IS_ERR(regmap)) {
47		dev_err(&client->dev, "failed to init registers map");
48		return PTR_ERR(regmap);
49	}
50
51	return zpa2326_probe(&client->dev, i2c_id->name, client->irq,
52			     zpa2326_i2c_hwid(client), regmap);
53}
54
55static void zpa2326_remove_i2c(struct i2c_client *client)
56{
57	zpa2326_remove(&client->dev);
58}
59
60static const struct i2c_device_id zpa2326_i2c_ids[] = {
61	{ "zpa2326" },
62	{ }
63};
64MODULE_DEVICE_TABLE(i2c, zpa2326_i2c_ids);
65
66static const struct of_device_id zpa2326_i2c_matches[] = {
67	{ .compatible = "murata,zpa2326" },
68	{ }
69};
70MODULE_DEVICE_TABLE(of, zpa2326_i2c_matches);
71
72static struct i2c_driver zpa2326_i2c_driver = {
73	.driver = {
74		.name           = "zpa2326-i2c",
75		.of_match_table = zpa2326_i2c_matches,
76		.pm             = ZPA2326_PM_OPS,
77	},
78	.probe = zpa2326_probe_i2c,
79	.remove   = zpa2326_remove_i2c,
80	.id_table = zpa2326_i2c_ids,
81};
82module_i2c_driver(zpa2326_i2c_driver);
83
84MODULE_AUTHOR("Gregor Boirie <gregor.boirie@parrot.com>");
85MODULE_DESCRIPTION("I2C driver for Murata ZPA2326 pressure sensor");
86MODULE_LICENSE("GPL v2");
87MODULE_IMPORT_NS("IIO_ZPA2326");
~/ Read-only file preview.