1 // SPDX-License-Identifier: GPL-2.0
3 * Support for PNI RM3100 3-axis geomagnetic sensor on a spi bus.
5 * Copyright (C) 2018 Song Qiang <songqiang1304521@gmail.com>
8 #include <linux/module.h>
9 #include <linux/spi/spi.h>
13 static const struct regmap_config rm3100_regmap_config
= {
17 .rd_table
= &rm3100_readable_table
,
18 .wr_table
= &rm3100_writable_table
,
19 .volatile_table
= &rm3100_volatile_table
,
21 .read_flag_mask
= 0x80,
23 .cache_type
= REGCACHE_RBTREE
,
26 static int rm3100_probe(struct spi_device
*spi
)
28 struct regmap
*regmap
;
31 /* Actually this device supports both mode 0 and mode 3. */
32 spi
->mode
= SPI_MODE_0
;
33 /* Data rates cannot exceed 1Mbits. */
34 spi
->max_speed_hz
= 1000000;
35 spi
->bits_per_word
= 8;
40 regmap
= devm_regmap_init_spi(spi
, &rm3100_regmap_config
);
42 return PTR_ERR(regmap
);
44 return rm3100_common_probe(&spi
->dev
, regmap
, spi
->irq
);
47 static const struct of_device_id rm3100_dt_match
[] = {
48 { .compatible
= "pni,rm3100", },
51 MODULE_DEVICE_TABLE(of
, rm3100_dt_match
);
53 static struct spi_driver rm3100_driver
= {
56 .of_match_table
= rm3100_dt_match
,
58 .probe
= rm3100_probe
,
60 module_spi_driver(rm3100_driver
);
62 MODULE_AUTHOR("Song Qiang <songqiang1304521@gmail.com>");
63 MODULE_DESCRIPTION("PNI RM3100 3-axis magnetometer spi driver");
64 MODULE_LICENSE("GPL v2");
65 MODULE_IMPORT_NS("IIO_RM3100");