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