blob: 3de7f4426ac409d534ec4ec32b587e9a82ba53b4 [file] [log] [blame]
Josef Gajdusekfc35a912014-07-22 16:01:00 +01001/*
Josef Gajdusek5a059bd2014-07-22 16:02:00 +01002 * i2c driver for hmc5843/5843/5883/5883l/5983
Josef Gajdusekfc35a912014-07-22 16:01:00 +01003 *
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.
Cristina Moraru4630adb2016-02-08 00:21:50 +020010 */
Josef Gajdusekfc35a912014-07-22 16:01:00 +010011
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[] = {
Tolga Ceylan98a3d2e2015-02-08 00:04:53 -080021 regmap_reg_range(0, HMC5843_ID_END),
Josef Gajdusekfc35a912014-07-22 16:01:00 +010022};
23
Krzysztof Kozlowski15313302015-02-24 10:41:48 +010024static const struct regmap_access_table hmc5843_readable_table = {
Tolga Ceylan98a3d2e2015-02-08 00:04:53 -080025 .yes_ranges = hmc5843_readable_ranges,
26 .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
Josef Gajdusekfc35a912014-07-22 16:01:00 +010027};
28
29static const struct regmap_range hmc5843_writable_ranges[] = {
Tolga Ceylan98a3d2e2015-02-08 00:04:53 -080030 regmap_reg_range(0, HMC5843_MODE_REG),
Josef Gajdusekfc35a912014-07-22 16:01:00 +010031};
32
Krzysztof Kozlowski15313302015-02-24 10:41:48 +010033static const struct regmap_access_table hmc5843_writable_table = {
Tolga Ceylan98a3d2e2015-02-08 00:04:53 -080034 .yes_ranges = hmc5843_writable_ranges,
35 .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
Josef Gajdusekfc35a912014-07-22 16:01:00 +010036};
37
38static const struct regmap_range hmc5843_volatile_ranges[] = {
Tolga Ceylan98a3d2e2015-02-08 00:04:53 -080039 regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
Josef Gajdusekfc35a912014-07-22 16:01:00 +010040};
41
Krzysztof Kozlowski15313302015-02-24 10:41:48 +010042static const struct regmap_access_table hmc5843_volatile_table = {
Tolga Ceylan98a3d2e2015-02-08 00:04:53 -080043 .yes_ranges = hmc5843_volatile_ranges,
44 .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
Josef Gajdusekfc35a912014-07-22 16:01:00 +010045};
46
Krzysztof Kozlowski15313302015-02-24 10:41:48 +010047static const struct regmap_config hmc5843_i2c_regmap_config = {
Tolga Ceylan98a3d2e2015-02-08 00:04:53 -080048 .reg_bits = 8,
49 .val_bits = 8,
Josef Gajdusekfc35a912014-07-22 16:01:00 +010050
Tolga Ceylan98a3d2e2015-02-08 00:04:53 -080051 .rd_table = &hmc5843_readable_table,
52 .wr_table = &hmc5843_writable_table,
53 .volatile_table = &hmc5843_volatile_table,
Josef Gajdusekfc35a912014-07-22 16:01:00 +010054
Tolga Ceylan98a3d2e2015-02-08 00:04:53 -080055 .cache_type = REGCACHE_RBTREE,
Josef Gajdusekfc35a912014-07-22 16:01:00 +010056};
57
Cristina Opriceanaaa6432f2015-03-19 21:07:51 +020058static int hmc5843_i2c_probe(struct i2c_client *cli,
Cristina Opriceana7079f212015-03-19 21:06:42 +020059 const struct i2c_device_id *id)
Josef Gajdusekfc35a912014-07-22 16:01:00 +010060{
Cristina Opriceanaaa6432f2015-03-19 21:07:51 +020061 return hmc5843_common_probe(&cli->dev,
62 devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
Yong Li70b27372015-08-12 21:25:46 +080063 id->driver_data, id->name);
Josef Gajdusekfc35a912014-07-22 16:01:00 +010064}
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 },
Josef Gajdusek5a059bd2014-07-22 16:02:00 +010075 { "hmc5983", HMC5983_ID },
Josef Gajdusekfc35a912014-07-22 16:01:00 +010076 { }
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 },
Josef Gajdusek5a059bd2014-07-22 16:02:00 +010084 { .compatible = "honeywell,hmc5983", .data = (void *)HMC5983_ID },
Josef Gajdusekfc35a912014-07-22 16:01:00 +010085 {}
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>");
Josef Gajdusek5a059bd2014-07-22 16:02:00 +0100102MODULE_DESCRIPTION("HMC5843/5883/5883L/5983 i2c driver");
Josef Gajdusekfc35a912014-07-22 16:01:00 +0100103MODULE_LICENSE("GPL");