1
2
3
4
5
6
7
8
9
10
11
12#include <linux/module.h>
13#include <linux/i2c.h>
14#include <linux/regmap.h>
15#include <linux/iio/iio.h>
16#include <linux/iio/triggered_buffer.h>
17
18#include "hmc5843.h"
19
20static const struct regmap_range hmc5843_readable_ranges[] = {
21 regmap_reg_range(0, HMC5843_ID_END),
22};
23
24static const struct regmap_access_table hmc5843_readable_table = {
25 .yes_ranges = hmc5843_readable_ranges,
26 .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
27};
28
29static const struct regmap_range hmc5843_writable_ranges[] = {
30 regmap_reg_range(0, HMC5843_MODE_REG),
31};
32
33static const struct regmap_access_table hmc5843_writable_table = {
34 .yes_ranges = hmc5843_writable_ranges,
35 .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
36};
37
38static const struct regmap_range hmc5843_volatile_ranges[] = {
39 regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
40};
41
42static const struct regmap_access_table hmc5843_volatile_table = {
43 .yes_ranges = hmc5843_volatile_ranges,
44 .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
45};
46
47static const struct regmap_config hmc5843_i2c_regmap_config = {
48 .reg_bits = 8,
49 .val_bits = 8,
50
51 .rd_table = &hmc5843_readable_table,
52 .wr_table = &hmc5843_writable_table,
53 .volatile_table = &hmc5843_volatile_table,
54
55 .cache_type = REGCACHE_RBTREE,
56};
57
58static int hmc5843_i2c_probe(struct i2c_client *cli,
59 const struct i2c_device_id *id)
60{
61 return hmc5843_common_probe(&cli->dev,
62 devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
63 id->driver_data, id->name);
64}
65
66static int hmc5843_i2c_remove(struct i2c_client *client)
67{
68 return hmc5843_common_remove(&client->dev);
69}
70
71static const struct i2c_device_id hmc5843_id[] = {
72 { "hmc5843", HMC5843_ID },
73 { "hmc5883", HMC5883_ID },
74 { "hmc5883l", HMC5883L_ID },
75 { "hmc5983", HMC5983_ID },
76 { }
77};
78MODULE_DEVICE_TABLE(i2c, hmc5843_id);
79
80static const struct of_device_id hmc5843_of_match[] = {
81 { .compatible = "honeywell,hmc5843", .data = (void *)HMC5843_ID },
82 { .compatible = "honeywell,hmc5883", .data = (void *)HMC5883_ID },
83 { .compatible = "honeywell,hmc5883l", .data = (void *)HMC5883L_ID },
84 { .compatible = "honeywell,hmc5983", .data = (void *)HMC5983_ID },
85 {}
86};
87MODULE_DEVICE_TABLE(of, hmc5843_of_match);
88
89static struct i2c_driver hmc5843_driver = {
90 .driver = {
91 .name = "hmc5843",
92 .pm = HMC5843_PM_OPS,
93 .of_match_table = hmc5843_of_match,
94 },
95 .id_table = hmc5843_id,
96 .probe = hmc5843_i2c_probe,
97 .remove = hmc5843_i2c_remove,
98};
99module_i2c_driver(hmc5843_driver);
100
101MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
102MODULE_DESCRIPTION("HMC5843/5883/5883L/5983 i2c driver");
103MODULE_LICENSE("GPL");
104