1
2
3
4
5
6
7
8
9
10
11#include <linux/module.h>
12#include <linux/spi/spi.h>
13#include <linux/iio/iio.h>
14
15#include "hmc5843.h"
16
17static const struct regmap_range hmc5843_readable_ranges[] = {
18 regmap_reg_range(0, HMC5843_ID_END),
19};
20
21static const struct regmap_access_table hmc5843_readable_table = {
22 .yes_ranges = hmc5843_readable_ranges,
23 .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
24};
25
26static const struct regmap_range hmc5843_writable_ranges[] = {
27 regmap_reg_range(0, HMC5843_MODE_REG),
28};
29
30static const struct regmap_access_table hmc5843_writable_table = {
31 .yes_ranges = hmc5843_writable_ranges,
32 .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
33};
34
35static const struct regmap_range hmc5843_volatile_ranges[] = {
36 regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
37};
38
39static const struct regmap_access_table hmc5843_volatile_table = {
40 .yes_ranges = hmc5843_volatile_ranges,
41 .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
42};
43
44static const struct regmap_config hmc5843_spi_regmap_config = {
45 .reg_bits = 8,
46 .val_bits = 8,
47
48 .rd_table = &hmc5843_readable_table,
49 .wr_table = &hmc5843_writable_table,
50 .volatile_table = &hmc5843_volatile_table,
51
52
53 .read_flag_mask = 0xc0,
54
55 .cache_type = REGCACHE_RBTREE,
56};
57
58static int hmc5843_spi_probe(struct spi_device *spi)
59{
60 int ret;
61 const struct spi_device_id *id = spi_get_device_id(spi);
62
63 spi->mode = SPI_MODE_3;
64 spi->max_speed_hz = 8000000;
65 spi->bits_per_word = 8;
66 ret = spi_setup(spi);
67 if (ret)
68 return ret;
69
70 return hmc5843_common_probe(&spi->dev,
71 devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config),
72 id->driver_data, id->name);
73}
74
75static int hmc5843_spi_remove(struct spi_device *spi)
76{
77 return hmc5843_common_remove(&spi->dev);
78}
79
80static const struct spi_device_id hmc5843_id[] = {
81 { "hmc5983", HMC5983_ID },
82 { }
83};
84MODULE_DEVICE_TABLE(spi, hmc5843_id);
85
86static struct spi_driver hmc5843_driver = {
87 .driver = {
88 .name = "hmc5843",
89 .pm = HMC5843_PM_OPS,
90 },
91 .id_table = hmc5843_id,
92 .probe = hmc5843_spi_probe,
93 .remove = hmc5843_spi_remove,
94};
95
96module_spi_driver(hmc5843_driver);
97
98MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
99MODULE_DESCRIPTION("HMC5983 SPI driver");
100MODULE_LICENSE("GPL");
101