Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / drivers / iio / magnetometer / hmc5843_spi.c
blobb7fde331069d6a3d2f5cd2ecd636318d1e276222
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * SPI driver for hmc5983
5 * Copyright (C) Josef Gajdusek <atx@atx.name>
6 */
8 #include <linux/module.h>
9 #include <linux/spi/spi.h>
10 #include <linux/iio/iio.h>
12 #include "hmc5843.h"
14 static const struct regmap_range hmc5843_readable_ranges[] = {
15 regmap_reg_range(0, HMC5843_ID_END),
18 static const struct regmap_access_table hmc5843_readable_table = {
19 .yes_ranges = hmc5843_readable_ranges,
20 .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
23 static const struct regmap_range hmc5843_writable_ranges[] = {
24 regmap_reg_range(0, HMC5843_MODE_REG),
27 static const struct regmap_access_table hmc5843_writable_table = {
28 .yes_ranges = hmc5843_writable_ranges,
29 .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
32 static const struct regmap_range hmc5843_volatile_ranges[] = {
33 regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
36 static const struct regmap_access_table hmc5843_volatile_table = {
37 .yes_ranges = hmc5843_volatile_ranges,
38 .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
41 static const struct regmap_config hmc5843_spi_regmap_config = {
42 .reg_bits = 8,
43 .val_bits = 8,
45 .rd_table = &hmc5843_readable_table,
46 .wr_table = &hmc5843_writable_table,
47 .volatile_table = &hmc5843_volatile_table,
49 /* Autoincrement address pointer */
50 .read_flag_mask = 0xc0,
52 .cache_type = REGCACHE_RBTREE,
55 static int hmc5843_spi_probe(struct spi_device *spi)
57 int ret;
58 struct regmap *regmap;
59 const struct spi_device_id *id = spi_get_device_id(spi);
61 spi->mode = SPI_MODE_3;
62 spi->max_speed_hz = 8000000;
63 spi->bits_per_word = 8;
64 ret = spi_setup(spi);
65 if (ret)
66 return ret;
68 regmap = devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config);
69 if (IS_ERR(regmap))
70 return PTR_ERR(regmap);
72 return hmc5843_common_probe(&spi->dev,
73 regmap,
74 id->driver_data, id->name);
77 static void hmc5843_spi_remove(struct spi_device *spi)
79 hmc5843_common_remove(&spi->dev);
82 static const struct spi_device_id hmc5843_id[] = {
83 { "hmc5983", HMC5983_ID },
84 { }
86 MODULE_DEVICE_TABLE(spi, hmc5843_id);
88 static struct spi_driver hmc5843_driver = {
89 .driver = {
90 .name = "hmc5843",
91 .pm = pm_sleep_ptr(&hmc5843_pm_ops),
93 .id_table = hmc5843_id,
94 .probe = hmc5843_spi_probe,
95 .remove = hmc5843_spi_remove,
98 module_spi_driver(hmc5843_driver);
100 MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
101 MODULE_DESCRIPTION("HMC5983 SPI driver");
102 MODULE_LICENSE("GPL");
103 MODULE_IMPORT_NS("IIO_HMC5843");