2 * i2c driver for hmc5843/5843/5883/5883l/5983
5 * Copyright (C) Josef Gajdusek <atx@atx.name>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
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>
20 static const struct regmap_range hmc5843_readable_ranges[] = {
21 regmap_reg_range(0, HMC5843_ID_END),
24 static const struct regmap_access_table hmc5843_readable_table = {
25 .yes_ranges = hmc5843_readable_ranges,
26 .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
29 static const struct regmap_range hmc5843_writable_ranges[] = {
30 regmap_reg_range(0, HMC5843_MODE_REG),
33 static const struct regmap_access_table hmc5843_writable_table = {
34 .yes_ranges = hmc5843_writable_ranges,
35 .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
38 static const struct regmap_range hmc5843_volatile_ranges[] = {
39 regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
42 static const struct regmap_access_table hmc5843_volatile_table = {
43 .yes_ranges = hmc5843_volatile_ranges,
44 .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
47 static const struct regmap_config hmc5843_i2c_regmap_config = {
51 .rd_table = &hmc5843_readable_table,
52 .wr_table = &hmc5843_writable_table,
53 .volatile_table = &hmc5843_volatile_table,
55 .cache_type = REGCACHE_RBTREE,
58 static int hmc5843_i2c_probe(struct i2c_client *cli,
59 const struct i2c_device_id *id)
61 struct regmap *regmap = devm_regmap_init_i2c(cli,
62 &hmc5843_i2c_regmap_config);
64 return PTR_ERR(regmap);
66 return hmc5843_common_probe(&cli->dev,
68 id->driver_data, id->name);
71 static int hmc5843_i2c_remove(struct i2c_client *client)
73 return hmc5843_common_remove(&client->dev);
76 static const struct i2c_device_id hmc5843_id[] = {
77 { "hmc5843", HMC5843_ID },
78 { "hmc5883", HMC5883_ID },
79 { "hmc5883l", HMC5883L_ID },
80 { "hmc5983", HMC5983_ID },
83 MODULE_DEVICE_TABLE(i2c, hmc5843_id);
85 static const struct of_device_id hmc5843_of_match[] = {
86 { .compatible = "honeywell,hmc5843", .data = (void *)HMC5843_ID },
87 { .compatible = "honeywell,hmc5883", .data = (void *)HMC5883_ID },
88 { .compatible = "honeywell,hmc5883l", .data = (void *)HMC5883L_ID },
89 { .compatible = "honeywell,hmc5983", .data = (void *)HMC5983_ID },
92 MODULE_DEVICE_TABLE(of, hmc5843_of_match);
94 static struct i2c_driver hmc5843_driver = {
98 .of_match_table = hmc5843_of_match,
100 .id_table = hmc5843_id,
101 .probe = hmc5843_i2c_probe,
102 .remove = hmc5843_i2c_remove,
104 module_i2c_driver(hmc5843_driver);
106 MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
107 MODULE_DESCRIPTION("HMC5843/5883/5883L/5983 i2c driver");
108 MODULE_LICENSE("GPL");