drm/modes: Fix drm_mode_vrefres() docs
[drm/drm-misc.git] / drivers / iio / magnetometer / hmc5843_i2c.c
blob657a309e2bd57898d7a15b0a01c1851281515842
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * i2c driver for hmc5843/5843/5883/5883l/5983
5 * Split from hmc5843.c
6 * Copyright (C) Josef Gajdusek <atx@atx.name>
7 */
9 #include <linux/module.h>
10 #include <linux/i2c.h>
11 #include <linux/regmap.h>
12 #include <linux/iio/iio.h>
13 #include <linux/iio/triggered_buffer.h>
15 #include "hmc5843.h"
17 static const struct regmap_range hmc5843_readable_ranges[] = {
18 regmap_reg_range(0, HMC5843_ID_END),
21 static const struct regmap_access_table hmc5843_readable_table = {
22 .yes_ranges = hmc5843_readable_ranges,
23 .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
26 static const struct regmap_range hmc5843_writable_ranges[] = {
27 regmap_reg_range(0, HMC5843_MODE_REG),
30 static const struct regmap_access_table hmc5843_writable_table = {
31 .yes_ranges = hmc5843_writable_ranges,
32 .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
35 static const struct regmap_range hmc5843_volatile_ranges[] = {
36 regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
39 static const struct regmap_access_table hmc5843_volatile_table = {
40 .yes_ranges = hmc5843_volatile_ranges,
41 .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
44 static const struct regmap_config hmc5843_i2c_regmap_config = {
45 .reg_bits = 8,
46 .val_bits = 8,
48 .rd_table = &hmc5843_readable_table,
49 .wr_table = &hmc5843_writable_table,
50 .volatile_table = &hmc5843_volatile_table,
52 .cache_type = REGCACHE_RBTREE,
55 static int hmc5843_i2c_probe(struct i2c_client *cli)
57 const struct i2c_device_id *id = i2c_client_get_device_id(cli);
58 struct regmap *regmap = devm_regmap_init_i2c(cli,
59 &hmc5843_i2c_regmap_config);
60 if (IS_ERR(regmap))
61 return PTR_ERR(regmap);
63 return hmc5843_common_probe(&cli->dev,
64 regmap,
65 id->driver_data, id->name);
68 static void hmc5843_i2c_remove(struct i2c_client *client)
70 hmc5843_common_remove(&client->dev);
73 static const struct i2c_device_id hmc5843_id[] = {
74 { "hmc5843", HMC5843_ID },
75 { "hmc5883", HMC5883_ID },
76 { "hmc5883l", HMC5883L_ID },
77 { "hmc5983", HMC5983_ID },
78 { }
80 MODULE_DEVICE_TABLE(i2c, hmc5843_id);
82 static const struct of_device_id hmc5843_of_match[] = {
83 { .compatible = "honeywell,hmc5843", .data = (void *)HMC5843_ID },
84 { .compatible = "honeywell,hmc5883", .data = (void *)HMC5883_ID },
85 { .compatible = "honeywell,hmc5883l", .data = (void *)HMC5883L_ID },
86 { .compatible = "honeywell,hmc5983", .data = (void *)HMC5983_ID },
89 MODULE_DEVICE_TABLE(of, hmc5843_of_match);
91 static struct i2c_driver hmc5843_driver = {
92 .driver = {
93 .name = "hmc5843",
94 .pm = pm_sleep_ptr(&hmc5843_pm_ops),
95 .of_match_table = hmc5843_of_match,
97 .id_table = hmc5843_id,
98 .probe = hmc5843_i2c_probe,
99 .remove = hmc5843_i2c_remove,
101 module_i2c_driver(hmc5843_driver);
103 MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
104 MODULE_DESCRIPTION("HMC5843/5883/5883L/5983 i2c driver");
105 MODULE_LICENSE("GPL");
106 MODULE_IMPORT_NS("IIO_HMC5843");