blob: 021ea5fe6a3771860e1a6b7d2cc34399f887a08f [file] [log] [blame]
Markus Pargmannb1d125c2015-08-19 14:12:46 +02001#include <linux/spi/spi.h>
2#include <linux/regmap.h>
3#include <linux/iio/iio.h>
4#include <linux/module.h>
5
6#include "bmg160.h"
7
8static const struct regmap_config bmg160_regmap_spi_conf = {
9 .reg_bits = 8,
10 .val_bits = 8,
11 .max_register = 0x3f,
12};
13
14static int bmg160_spi_probe(struct spi_device *spi)
15{
16 struct regmap *regmap;
17 const struct spi_device_id *id = spi_get_device_id(spi);
18
19 regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf);
20 if (IS_ERR(regmap)) {
21 dev_err(&spi->dev, "Failed to register spi regmap %d\n",
22 (int)PTR_ERR(regmap));
23 return PTR_ERR(regmap);
24 }
25
26 return bmg160_core_probe(&spi->dev, regmap, spi->irq, id->name);
27}
28
29static int bmg160_spi_remove(struct spi_device *spi)
30{
31 bmg160_core_remove(&spi->dev);
32
33 return 0;
34}
35
36static const struct spi_device_id bmg160_spi_id[] = {
37 {"bmg160", 0},
38 {"bmi055_gyro", 0},
39 {}
40};
41
42MODULE_DEVICE_TABLE(spi, bmg160_spi_id);
43
44static struct spi_driver bmg160_spi_driver = {
45 .driver = {
46 .name = "bmg160_spi",
47 .pm = &bmg160_pm_ops,
48 },
49 .probe = bmg160_spi_probe,
50 .remove = bmg160_spi_remove,
51 .id_table = bmg160_spi_id,
52};
53module_spi_driver(bmg160_spi_driver);
54
55MODULE_AUTHOR("Markus Pargmann <mpa@pengutronix.de>");
56MODULE_LICENSE("GPL v2");
57MODULE_DESCRIPTION("BMG160 SPI Gyro driver");