2019-06-04 08:11:33 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2014-07-22 15:01:00 +00:00
|
|
|
/*
|
2014-07-22 15:02:00 +00:00
|
|
|
* i2c driver for hmc5843/5843/5883/5883l/5983
|
2014-07-22 15:01:00 +00:00
|
|
|
*
|
|
|
|
* Split from hmc5843.c
|
|
|
|
* Copyright (C) Josef Gajdusek <atx@atx.name>
|
2016-02-07 22:21:50 +00:00
|
|
|
*/
|
2014-07-22 15:01:00 +00:00
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/iio/iio.h>
|
|
|
|
#include <linux/iio/triggered_buffer.h>
|
|
|
|
|
|
|
|
#include "hmc5843.h"
|
|
|
|
|
|
|
|
static const struct regmap_range hmc5843_readable_ranges[] = {
|
2015-02-08 08:04:53 +00:00
|
|
|
regmap_reg_range(0, HMC5843_ID_END),
|
2014-07-22 15:01:00 +00:00
|
|
|
};
|
|
|
|
|
2015-02-24 09:41:48 +00:00
|
|
|
static const struct regmap_access_table hmc5843_readable_table = {
|
2015-02-08 08:04:53 +00:00
|
|
|
.yes_ranges = hmc5843_readable_ranges,
|
|
|
|
.n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
|
2014-07-22 15:01:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regmap_range hmc5843_writable_ranges[] = {
|
2015-02-08 08:04:53 +00:00
|
|
|
regmap_reg_range(0, HMC5843_MODE_REG),
|
2014-07-22 15:01:00 +00:00
|
|
|
};
|
|
|
|
|
2015-02-24 09:41:48 +00:00
|
|
|
static const struct regmap_access_table hmc5843_writable_table = {
|
2015-02-08 08:04:53 +00:00
|
|
|
.yes_ranges = hmc5843_writable_ranges,
|
|
|
|
.n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
|
2014-07-22 15:01:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regmap_range hmc5843_volatile_ranges[] = {
|
2015-02-08 08:04:53 +00:00
|
|
|
regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
|
2014-07-22 15:01:00 +00:00
|
|
|
};
|
|
|
|
|
2015-02-24 09:41:48 +00:00
|
|
|
static const struct regmap_access_table hmc5843_volatile_table = {
|
2015-02-08 08:04:53 +00:00
|
|
|
.yes_ranges = hmc5843_volatile_ranges,
|
|
|
|
.n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
|
2014-07-22 15:01:00 +00:00
|
|
|
};
|
|
|
|
|
2015-02-24 09:41:48 +00:00
|
|
|
static const struct regmap_config hmc5843_i2c_regmap_config = {
|
2015-02-08 08:04:53 +00:00
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
2014-07-22 15:01:00 +00:00
|
|
|
|
2015-02-08 08:04:53 +00:00
|
|
|
.rd_table = &hmc5843_readable_table,
|
|
|
|
.wr_table = &hmc5843_writable_table,
|
|
|
|
.volatile_table = &hmc5843_volatile_table,
|
2014-07-22 15:01:00 +00:00
|
|
|
|
2015-02-08 08:04:53 +00:00
|
|
|
.cache_type = REGCACHE_RBTREE,
|
2014-07-22 15:01:00 +00:00
|
|
|
};
|
|
|
|
|
2015-03-19 19:07:51 +00:00
|
|
|
static int hmc5843_i2c_probe(struct i2c_client *cli,
|
2015-03-19 19:06:42 +00:00
|
|
|
const struct i2c_device_id *id)
|
2014-07-22 15:01:00 +00:00
|
|
|
{
|
2019-03-16 22:08:33 +00:00
|
|
|
struct regmap *regmap = devm_regmap_init_i2c(cli,
|
|
|
|
&hmc5843_i2c_regmap_config);
|
|
|
|
if (IS_ERR(regmap))
|
|
|
|
return PTR_ERR(regmap);
|
|
|
|
|
2015-03-19 19:07:51 +00:00
|
|
|
return hmc5843_common_probe(&cli->dev,
|
2019-03-16 22:08:33 +00:00
|
|
|
regmap,
|
2015-08-12 13:25:46 +00:00
|
|
|
id->driver_data, id->name);
|
2014-07-22 15:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hmc5843_i2c_remove(struct i2c_client *client)
|
|
|
|
{
|
2021-10-13 20:32:21 +00:00
|
|
|
hmc5843_common_remove(&client->dev);
|
|
|
|
|
|
|
|
return 0;
|
2014-07-22 15:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id hmc5843_id[] = {
|
|
|
|
{ "hmc5843", HMC5843_ID },
|
|
|
|
{ "hmc5883", HMC5883_ID },
|
|
|
|
{ "hmc5883l", HMC5883L_ID },
|
2014-07-22 15:02:00 +00:00
|
|
|
{ "hmc5983", HMC5983_ID },
|
2014-07-22 15:01:00 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, hmc5843_id);
|
|
|
|
|
|
|
|
static const struct of_device_id hmc5843_of_match[] = {
|
|
|
|
{ .compatible = "honeywell,hmc5843", .data = (void *)HMC5843_ID },
|
|
|
|
{ .compatible = "honeywell,hmc5883", .data = (void *)HMC5883_ID },
|
|
|
|
{ .compatible = "honeywell,hmc5883l", .data = (void *)HMC5883L_ID },
|
2014-07-22 15:02:00 +00:00
|
|
|
{ .compatible = "honeywell,hmc5983", .data = (void *)HMC5983_ID },
|
2014-07-22 15:01:00 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, hmc5843_of_match);
|
|
|
|
|
|
|
|
static struct i2c_driver hmc5843_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "hmc5843",
|
|
|
|
.pm = HMC5843_PM_OPS,
|
|
|
|
.of_match_table = hmc5843_of_match,
|
|
|
|
},
|
|
|
|
.id_table = hmc5843_id,
|
|
|
|
.probe = hmc5843_i2c_probe,
|
|
|
|
.remove = hmc5843_i2c_remove,
|
|
|
|
};
|
|
|
|
module_i2c_driver(hmc5843_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
|
2014-07-22 15:02:00 +00:00
|
|
|
MODULE_DESCRIPTION("HMC5843/5883/5883L/5983 i2c driver");
|
2014-07-22 15:01:00 +00:00
|
|
|
MODULE_LICENSE("GPL");
|