18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * i2c driver for hmc5843/5843/5883/5883l/5983 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Split from hmc5843.c 68c2ecf20Sopenharmony_ci * Copyright (C) Josef Gajdusek <atx@atx.name> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/i2c.h> 118c2ecf20Sopenharmony_ci#include <linux/regmap.h> 128c2ecf20Sopenharmony_ci#include <linux/iio/iio.h> 138c2ecf20Sopenharmony_ci#include <linux/iio/triggered_buffer.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include "hmc5843.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cistatic const struct regmap_range hmc5843_readable_ranges[] = { 188c2ecf20Sopenharmony_ci regmap_reg_range(0, HMC5843_ID_END), 198c2ecf20Sopenharmony_ci}; 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistatic const struct regmap_access_table hmc5843_readable_table = { 228c2ecf20Sopenharmony_ci .yes_ranges = hmc5843_readable_ranges, 238c2ecf20Sopenharmony_ci .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges), 248c2ecf20Sopenharmony_ci}; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistatic const struct regmap_range hmc5843_writable_ranges[] = { 278c2ecf20Sopenharmony_ci regmap_reg_range(0, HMC5843_MODE_REG), 288c2ecf20Sopenharmony_ci}; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistatic const struct regmap_access_table hmc5843_writable_table = { 318c2ecf20Sopenharmony_ci .yes_ranges = hmc5843_writable_ranges, 328c2ecf20Sopenharmony_ci .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges), 338c2ecf20Sopenharmony_ci}; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cistatic const struct regmap_range hmc5843_volatile_ranges[] = { 368c2ecf20Sopenharmony_ci regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG), 378c2ecf20Sopenharmony_ci}; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic const struct regmap_access_table hmc5843_volatile_table = { 408c2ecf20Sopenharmony_ci .yes_ranges = hmc5843_volatile_ranges, 418c2ecf20Sopenharmony_ci .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges), 428c2ecf20Sopenharmony_ci}; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic const struct regmap_config hmc5843_i2c_regmap_config = { 458c2ecf20Sopenharmony_ci .reg_bits = 8, 468c2ecf20Sopenharmony_ci .val_bits = 8, 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci .rd_table = &hmc5843_readable_table, 498c2ecf20Sopenharmony_ci .wr_table = &hmc5843_writable_table, 508c2ecf20Sopenharmony_ci .volatile_table = &hmc5843_volatile_table, 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 538c2ecf20Sopenharmony_ci}; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistatic int hmc5843_i2c_probe(struct i2c_client *cli, 568c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci struct regmap *regmap = devm_regmap_init_i2c(cli, 598c2ecf20Sopenharmony_ci &hmc5843_i2c_regmap_config); 608c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) 618c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci return hmc5843_common_probe(&cli->dev, 648c2ecf20Sopenharmony_ci regmap, 658c2ecf20Sopenharmony_ci id->driver_data, id->name); 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistatic int hmc5843_i2c_remove(struct i2c_client *client) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci return hmc5843_common_remove(&client->dev); 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistatic const struct i2c_device_id hmc5843_id[] = { 748c2ecf20Sopenharmony_ci { "hmc5843", HMC5843_ID }, 758c2ecf20Sopenharmony_ci { "hmc5883", HMC5883_ID }, 768c2ecf20Sopenharmony_ci { "hmc5883l", HMC5883L_ID }, 778c2ecf20Sopenharmony_ci { "hmc5983", HMC5983_ID }, 788c2ecf20Sopenharmony_ci { } 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, hmc5843_id); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistatic const struct of_device_id hmc5843_of_match[] = { 838c2ecf20Sopenharmony_ci { .compatible = "honeywell,hmc5843", .data = (void *)HMC5843_ID }, 848c2ecf20Sopenharmony_ci { .compatible = "honeywell,hmc5883", .data = (void *)HMC5883_ID }, 858c2ecf20Sopenharmony_ci { .compatible = "honeywell,hmc5883l", .data = (void *)HMC5883L_ID }, 868c2ecf20Sopenharmony_ci { .compatible = "honeywell,hmc5983", .data = (void *)HMC5983_ID }, 878c2ecf20Sopenharmony_ci {} 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, hmc5843_of_match); 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic struct i2c_driver hmc5843_driver = { 928c2ecf20Sopenharmony_ci .driver = { 938c2ecf20Sopenharmony_ci .name = "hmc5843", 948c2ecf20Sopenharmony_ci .pm = HMC5843_PM_OPS, 958c2ecf20Sopenharmony_ci .of_match_table = hmc5843_of_match, 968c2ecf20Sopenharmony_ci }, 978c2ecf20Sopenharmony_ci .id_table = hmc5843_id, 988c2ecf20Sopenharmony_ci .probe = hmc5843_i2c_probe, 998c2ecf20Sopenharmony_ci .remove = hmc5843_i2c_remove, 1008c2ecf20Sopenharmony_ci}; 1018c2ecf20Sopenharmony_cimodule_i2c_driver(hmc5843_driver); 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ciMODULE_AUTHOR("Josef Gajdusek <atx@atx.name>"); 1048c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("HMC5843/5883/5883L/5983 i2c driver"); 1058c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 106