Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / drivers / iio / imu / st_lsm6dsx / st_lsm6dsx_spi.c
blob2c813583447934f5141798e27d7429510deef787
1 /*
2 * STMicroelectronics st_lsm6dsx spi driver
4 * Copyright 2016 STMicroelectronics Inc.
6 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
7 * Denis Ciocca <denis.ciocca@st.com>
9 * Licensed under the GPL-2.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/spi/spi.h>
15 #include <linux/slab.h>
16 #include <linux/of.h>
17 #include <linux/regmap.h>
19 #include "st_lsm6dsx.h"
21 static const struct regmap_config st_lsm6dsx_spi_regmap_config = {
22 .reg_bits = 8,
23 .val_bits = 8,
26 static int st_lsm6dsx_spi_probe(struct spi_device *spi)
28 const struct spi_device_id *id = spi_get_device_id(spi);
29 int hw_id = id->driver_data;
30 struct regmap *regmap;
32 regmap = devm_regmap_init_spi(spi, &st_lsm6dsx_spi_regmap_config);
33 if (IS_ERR(regmap)) {
34 dev_err(&spi->dev, "Failed to register spi regmap %d\n",
35 (int)PTR_ERR(regmap));
36 return PTR_ERR(regmap);
39 return st_lsm6dsx_probe(&spi->dev, spi->irq,
40 hw_id, id->name, regmap);
43 static const struct of_device_id st_lsm6dsx_spi_of_match[] = {
45 .compatible = "st,lsm6ds3",
46 .data = (void *)ST_LSM6DS3_ID,
49 .compatible = "st,lsm6ds3h",
50 .data = (void *)ST_LSM6DS3H_ID,
53 .compatible = "st,lsm6dsl",
54 .data = (void *)ST_LSM6DSL_ID,
57 .compatible = "st,lsm6dsm",
58 .data = (void *)ST_LSM6DSM_ID,
60 {},
62 MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match);
64 static const struct spi_device_id st_lsm6dsx_spi_id_table[] = {
65 { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID },
66 { ST_LSM6DS3H_DEV_NAME, ST_LSM6DS3H_ID },
67 { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID },
68 { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
69 {},
71 MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
73 static struct spi_driver st_lsm6dsx_driver = {
74 .driver = {
75 .name = "st_lsm6dsx_spi",
76 .pm = &st_lsm6dsx_pm_ops,
77 .of_match_table = of_match_ptr(st_lsm6dsx_spi_of_match),
79 .probe = st_lsm6dsx_spi_probe,
80 .id_table = st_lsm6dsx_spi_id_table,
82 module_spi_driver(st_lsm6dsx_driver);
84 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
85 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
86 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx spi driver");
87 MODULE_LICENSE("GPL v2");