1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Support for PNI RM3100 3-axis geomagnetic sensor on a spi bus.
4 *
5 * Copyright (C) 2018 Song Qiang <songqiang1304521@gmail.com>
6 */
7
8 #include <linux/module.h>
9 #include <linux/spi/spi.h>
10
11 #include "rm3100.h"
12
13 static const struct regmap_config rm3100_regmap_config = {
14 .reg_bits = 8,
15 .val_bits = 8,
16
17 .rd_table = &rm3100_readable_table,
18 .wr_table = &rm3100_writable_table,
19 .volatile_table = &rm3100_volatile_table,
20
21 .read_flag_mask = 0x80,
22
23 .cache_type = REGCACHE_RBTREE,
24 };
25
rm3100_probe(struct spi_device * spi)26 static int rm3100_probe(struct spi_device *spi)
27 {
28 struct regmap *regmap;
29 int ret;
30
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;
36 ret = spi_setup(spi);
37 if (ret)
38 return ret;
39
40 regmap = devm_regmap_init_spi(spi, &rm3100_regmap_config);
41 if (IS_ERR(regmap))
42 return PTR_ERR(regmap);
43
44 return rm3100_common_probe(&spi->dev, regmap, spi->irq);
45 }
46
47 static const struct of_device_id rm3100_dt_match[] = {
48 { .compatible = "pni,rm3100", },
49 { }
50 };
51 MODULE_DEVICE_TABLE(of, rm3100_dt_match);
52
53 static struct spi_driver rm3100_driver = {
54 .driver = {
55 .name = "rm3100-spi",
56 .of_match_table = rm3100_dt_match,
57 },
58 .probe = rm3100_probe,
59 };
60 module_spi_driver(rm3100_driver);
61
62 MODULE_AUTHOR("Song Qiang <songqiang1304521@gmail.com>");
63 MODULE_DESCRIPTION("PNI RM3100 3-axis magnetometer spi driver");
64 MODULE_LICENSE("GPL v2");
65