162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Murata ZPA2326 I2C pressure and temperature sensor driver 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (c) 2016 Parrot S.A. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Author: Gregor Boirie <gregor.boirie@parrot.com> 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <linux/module.h> 1162306a36Sopenharmony_ci#include <linux/regmap.h> 1262306a36Sopenharmony_ci#include <linux/i2c.h> 1362306a36Sopenharmony_ci#include <linux/mod_devicetable.h> 1462306a36Sopenharmony_ci#include "zpa2326.h" 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci/* 1762306a36Sopenharmony_ci * read_flag_mask: 1862306a36Sopenharmony_ci * - address bit 7 must be set to request a register read operation 1962306a36Sopenharmony_ci */ 2062306a36Sopenharmony_cistatic const struct regmap_config zpa2326_regmap_i2c_config = { 2162306a36Sopenharmony_ci .reg_bits = 8, 2262306a36Sopenharmony_ci .val_bits = 8, 2362306a36Sopenharmony_ci .writeable_reg = zpa2326_isreg_writeable, 2462306a36Sopenharmony_ci .readable_reg = zpa2326_isreg_readable, 2562306a36Sopenharmony_ci .precious_reg = zpa2326_isreg_precious, 2662306a36Sopenharmony_ci .max_register = ZPA2326_TEMP_OUT_H_REG, 2762306a36Sopenharmony_ci .read_flag_mask = BIT(7), 2862306a36Sopenharmony_ci .cache_type = REGCACHE_NONE, 2962306a36Sopenharmony_ci}; 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_cistatic unsigned int zpa2326_i2c_hwid(const struct i2c_client *client) 3262306a36Sopenharmony_ci{ 3362306a36Sopenharmony_ci#define ZPA2326_SA0(_addr) (_addr & BIT(0)) 3462306a36Sopenharmony_ci#define ZPA2326_DEVICE_ID_SA0_SHIFT (1) 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci /* Identification register bit 1 mirrors device address bit 0. */ 3762306a36Sopenharmony_ci return (ZPA2326_DEVICE_ID | 3862306a36Sopenharmony_ci (ZPA2326_SA0(client->addr) << ZPA2326_DEVICE_ID_SA0_SHIFT)); 3962306a36Sopenharmony_ci} 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_cistatic int zpa2326_probe_i2c(struct i2c_client *client) 4262306a36Sopenharmony_ci{ 4362306a36Sopenharmony_ci const struct i2c_device_id *i2c_id = i2c_client_get_device_id(client); 4462306a36Sopenharmony_ci struct regmap *regmap; 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci regmap = devm_regmap_init_i2c(client, &zpa2326_regmap_i2c_config); 4762306a36Sopenharmony_ci if (IS_ERR(regmap)) { 4862306a36Sopenharmony_ci dev_err(&client->dev, "failed to init registers map"); 4962306a36Sopenharmony_ci return PTR_ERR(regmap); 5062306a36Sopenharmony_ci } 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci return zpa2326_probe(&client->dev, i2c_id->name, client->irq, 5362306a36Sopenharmony_ci zpa2326_i2c_hwid(client), regmap); 5462306a36Sopenharmony_ci} 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_cistatic void zpa2326_remove_i2c(struct i2c_client *client) 5762306a36Sopenharmony_ci{ 5862306a36Sopenharmony_ci zpa2326_remove(&client->dev); 5962306a36Sopenharmony_ci} 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_cistatic const struct i2c_device_id zpa2326_i2c_ids[] = { 6262306a36Sopenharmony_ci { "zpa2326", 0 }, 6362306a36Sopenharmony_ci { }, 6462306a36Sopenharmony_ci}; 6562306a36Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, zpa2326_i2c_ids); 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_cistatic const struct of_device_id zpa2326_i2c_matches[] = { 6862306a36Sopenharmony_ci { .compatible = "murata,zpa2326" }, 6962306a36Sopenharmony_ci { } 7062306a36Sopenharmony_ci}; 7162306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, zpa2326_i2c_matches); 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_cistatic struct i2c_driver zpa2326_i2c_driver = { 7462306a36Sopenharmony_ci .driver = { 7562306a36Sopenharmony_ci .name = "zpa2326-i2c", 7662306a36Sopenharmony_ci .of_match_table = zpa2326_i2c_matches, 7762306a36Sopenharmony_ci .pm = ZPA2326_PM_OPS, 7862306a36Sopenharmony_ci }, 7962306a36Sopenharmony_ci .probe = zpa2326_probe_i2c, 8062306a36Sopenharmony_ci .remove = zpa2326_remove_i2c, 8162306a36Sopenharmony_ci .id_table = zpa2326_i2c_ids, 8262306a36Sopenharmony_ci}; 8362306a36Sopenharmony_cimodule_i2c_driver(zpa2326_i2c_driver); 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ciMODULE_AUTHOR("Gregor Boirie <gregor.boirie@parrot.com>"); 8662306a36Sopenharmony_ciMODULE_DESCRIPTION("I2C driver for Murata ZPA2326 pressure sensor"); 8762306a36Sopenharmony_ciMODULE_LICENSE("GPL v2"); 8862306a36Sopenharmony_ciMODULE_IMPORT_NS(IIO_ZPA2326); 89