1 // SPDX-License-Identifier: GPL-2.0-only
3 * SPI driver for hmc5983
5 * Copyright (C) Josef Gajdusek <atx@atx.name>
8 #include <linux/module.h>
9 #include <linux/spi/spi.h>
10 #include <linux/iio/iio.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
= {
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
)
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;
68 regmap
= devm_regmap_init_spi(spi
, &hmc5843_spi_regmap_config
);
70 return PTR_ERR(regmap
);
72 return hmc5843_common_probe(&spi
->dev
,
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
},
86 MODULE_DEVICE_TABLE(spi
, hmc5843_id
);
88 static struct spi_driver hmc5843_driver
= {
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");