2 * SPI driver for hmc5983
4 * Copyright (C) Josef Gajdusek <atx@atx.name>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/module.h>
12 #include <linux/spi/spi.h>
13 #include <linux/iio/iio.h>
17 static const struct regmap_range hmc5843_readable_ranges
[] = {
18 regmap_reg_range(0, HMC5843_ID_END
),
21 static const struct regmap_access_table hmc5843_readable_table
= {
22 .yes_ranges
= hmc5843_readable_ranges
,
23 .n_yes_ranges
= ARRAY_SIZE(hmc5843_readable_ranges
),
26 static const struct regmap_range hmc5843_writable_ranges
[] = {
27 regmap_reg_range(0, HMC5843_MODE_REG
),
30 static const struct regmap_access_table hmc5843_writable_table
= {
31 .yes_ranges
= hmc5843_writable_ranges
,
32 .n_yes_ranges
= ARRAY_SIZE(hmc5843_writable_ranges
),
35 static const struct regmap_range hmc5843_volatile_ranges
[] = {
36 regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS
, HMC5843_STATUS_REG
),
39 static const struct regmap_access_table hmc5843_volatile_table
= {
40 .yes_ranges
= hmc5843_volatile_ranges
,
41 .n_yes_ranges
= ARRAY_SIZE(hmc5843_volatile_ranges
),
44 static const struct regmap_config hmc5843_spi_regmap_config
= {
48 .rd_table
= &hmc5843_readable_table
,
49 .wr_table
= &hmc5843_writable_table
,
50 .volatile_table
= &hmc5843_volatile_table
,
52 /* Autoincrement address pointer */
53 .read_flag_mask
= 0xc0,
55 .cache_type
= REGCACHE_RBTREE
,
58 static int hmc5843_spi_probe(struct spi_device
*spi
)
61 struct regmap
*regmap
;
62 const struct spi_device_id
*id
= spi_get_device_id(spi
);
64 spi
->mode
= SPI_MODE_3
;
65 spi
->max_speed_hz
= 8000000;
66 spi
->bits_per_word
= 8;
71 regmap
= devm_regmap_init_spi(spi
, &hmc5843_spi_regmap_config
);
73 return PTR_ERR(regmap
);
75 return hmc5843_common_probe(&spi
->dev
,
77 id
->driver_data
, id
->name
);
80 static int hmc5843_spi_remove(struct spi_device
*spi
)
82 return hmc5843_common_remove(&spi
->dev
);
85 static const struct spi_device_id hmc5843_id
[] = {
86 { "hmc5983", HMC5983_ID
},
89 MODULE_DEVICE_TABLE(spi
, hmc5843_id
);
91 static struct spi_driver hmc5843_driver
= {
96 .id_table
= hmc5843_id
,
97 .probe
= hmc5843_spi_probe
,
98 .remove
= hmc5843_spi_remove
,
101 module_spi_driver(hmc5843_driver
);
103 MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
104 MODULE_DESCRIPTION("HMC5983 SPI driver");
105 MODULE_LICENSE("GPL");