11802d0beSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 203b262f2SGregor Boirie /* 303b262f2SGregor Boirie * Murata ZPA2326 I2C pressure and temperature sensor driver 403b262f2SGregor Boirie * 503b262f2SGregor Boirie * Copyright (c) 2016 Parrot S.A. 603b262f2SGregor Boirie * 703b262f2SGregor Boirie * Author: Gregor Boirie <gregor.boirie@parrot.com> 803b262f2SGregor Boirie */ 903b262f2SGregor Boirie 1003b262f2SGregor Boirie #include <linux/module.h> 1103b262f2SGregor Boirie #include <linux/regmap.h> 1203b262f2SGregor Boirie #include <linux/i2c.h> 13a409d2b6SJonathan Cameron #include <linux/mod_devicetable.h> 1403b262f2SGregor Boirie #include "zpa2326.h" 1503b262f2SGregor Boirie 1603b262f2SGregor Boirie /* 1703b262f2SGregor Boirie * read_flag_mask: 1803b262f2SGregor Boirie * - address bit 7 must be set to request a register read operation 1903b262f2SGregor Boirie */ 2003b262f2SGregor Boirie static const struct regmap_config zpa2326_regmap_i2c_config = { 2103b262f2SGregor Boirie .reg_bits = 8, 2203b262f2SGregor Boirie .val_bits = 8, 2303b262f2SGregor Boirie .writeable_reg = zpa2326_isreg_writeable, 2403b262f2SGregor Boirie .readable_reg = zpa2326_isreg_readable, 2503b262f2SGregor Boirie .precious_reg = zpa2326_isreg_precious, 2603b262f2SGregor Boirie .max_register = ZPA2326_TEMP_OUT_H_REG, 2703b262f2SGregor Boirie .read_flag_mask = BIT(7), 2803b262f2SGregor Boirie .cache_type = REGCACHE_NONE, 2903b262f2SGregor Boirie }; 3003b262f2SGregor Boirie 3103b262f2SGregor Boirie static unsigned int zpa2326_i2c_hwid(const struct i2c_client *client) 3203b262f2SGregor Boirie { 3303b262f2SGregor Boirie #define ZPA2326_SA0(_addr) (_addr & BIT(0)) 3403b262f2SGregor Boirie #define ZPA2326_DEVICE_ID_SA0_SHIFT (1) 3503b262f2SGregor Boirie 3603b262f2SGregor Boirie /* Identification register bit 1 mirrors device address bit 0. */ 3703b262f2SGregor Boirie return (ZPA2326_DEVICE_ID | 3803b262f2SGregor Boirie (ZPA2326_SA0(client->addr) << ZPA2326_DEVICE_ID_SA0_SHIFT)); 3903b262f2SGregor Boirie } 4003b262f2SGregor Boirie 411bee48f4SUwe Kleine-König static int zpa2326_probe_i2c(struct i2c_client *client) 4203b262f2SGregor Boirie { 431bee48f4SUwe Kleine-König const struct i2c_device_id *i2c_id = i2c_client_get_device_id(client); 4403b262f2SGregor Boirie struct regmap *regmap; 4503b262f2SGregor Boirie 4603b262f2SGregor Boirie regmap = devm_regmap_init_i2c(client, &zpa2326_regmap_i2c_config); 4703b262f2SGregor Boirie if (IS_ERR(regmap)) { 4803b262f2SGregor Boirie dev_err(&client->dev, "failed to init registers map"); 4903b262f2SGregor Boirie return PTR_ERR(regmap); 5003b262f2SGregor Boirie } 5103b262f2SGregor Boirie 5203b262f2SGregor Boirie return zpa2326_probe(&client->dev, i2c_id->name, client->irq, 5303b262f2SGregor Boirie zpa2326_i2c_hwid(client), regmap); 5403b262f2SGregor Boirie } 5503b262f2SGregor Boirie 56ed5c2f5fSUwe Kleine-König static void zpa2326_remove_i2c(struct i2c_client *client) 5703b262f2SGregor Boirie { 5803b262f2SGregor Boirie zpa2326_remove(&client->dev); 5903b262f2SGregor Boirie } 6003b262f2SGregor Boirie 6103b262f2SGregor Boirie static const struct i2c_device_id zpa2326_i2c_ids[] = { 6203b262f2SGregor Boirie { "zpa2326", 0 }, 6303b262f2SGregor Boirie { }, 6403b262f2SGregor Boirie }; 6503b262f2SGregor Boirie MODULE_DEVICE_TABLE(i2c, zpa2326_i2c_ids); 6603b262f2SGregor Boirie 6703b262f2SGregor Boirie static const struct of_device_id zpa2326_i2c_matches[] = { 6803b262f2SGregor Boirie { .compatible = "murata,zpa2326" }, 6903b262f2SGregor Boirie { } 7003b262f2SGregor Boirie }; 7103b262f2SGregor Boirie MODULE_DEVICE_TABLE(of, zpa2326_i2c_matches); 7203b262f2SGregor Boirie 7303b262f2SGregor Boirie static struct i2c_driver zpa2326_i2c_driver = { 7403b262f2SGregor Boirie .driver = { 7503b262f2SGregor Boirie .name = "zpa2326-i2c", 76a409d2b6SJonathan Cameron .of_match_table = zpa2326_i2c_matches, 7703b262f2SGregor Boirie .pm = ZPA2326_PM_OPS, 7803b262f2SGregor Boirie }, 79*7cf15f42SUwe Kleine-König .probe = zpa2326_probe_i2c, 8003b262f2SGregor Boirie .remove = zpa2326_remove_i2c, 8103b262f2SGregor Boirie .id_table = zpa2326_i2c_ids, 8203b262f2SGregor Boirie }; 8303b262f2SGregor Boirie module_i2c_driver(zpa2326_i2c_driver); 8403b262f2SGregor Boirie 8503b262f2SGregor Boirie MODULE_AUTHOR("Gregor Boirie <gregor.boirie@parrot.com>"); 8603b262f2SGregor Boirie MODULE_DESCRIPTION("I2C driver for Murata ZPA2326 pressure sensor"); 8703b262f2SGregor Boirie MODULE_LICENSE("GPL v2"); 88c8629ec9SJonathan Cameron MODULE_IMPORT_NS(IIO_ZPA2326); 89