st_lsm6dsx_spi.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * STMicroelectronics st_lsm6dsx spi driver
  3. *
  4. * Copyright 2016 STMicroelectronics Inc.
  5. *
  6. * Lorenzo Bianconi <lorenzo.bianconi@st.com>
  7. * Denis Ciocca <denis.ciocca@st.com>
  8. *
  9. * Licensed under the GPL-2.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/spi/spi.h>
  14. #include <linux/slab.h>
  15. #include <linux/of.h>
  16. #include <linux/regmap.h>
  17. #include "st_lsm6dsx.h"
  18. static const struct regmap_config st_lsm6dsx_spi_regmap_config = {
  19. .reg_bits = 8,
  20. .val_bits = 8,
  21. };
  22. static int st_lsm6dsx_spi_probe(struct spi_device *spi)
  23. {
  24. const struct spi_device_id *id = spi_get_device_id(spi);
  25. int hw_id = id->driver_data;
  26. struct regmap *regmap;
  27. regmap = devm_regmap_init_spi(spi, &st_lsm6dsx_spi_regmap_config);
  28. if (IS_ERR(regmap)) {
  29. dev_err(&spi->dev, "Failed to register spi regmap %d\n",
  30. (int)PTR_ERR(regmap));
  31. return PTR_ERR(regmap);
  32. }
  33. return st_lsm6dsx_probe(&spi->dev, spi->irq,
  34. hw_id, id->name, regmap);
  35. }
  36. static const struct of_device_id st_lsm6dsx_spi_of_match[] = {
  37. {
  38. .compatible = "st,lsm6ds3",
  39. .data = (void *)ST_LSM6DS3_ID,
  40. },
  41. {
  42. .compatible = "st,lsm6ds3h",
  43. .data = (void *)ST_LSM6DS3H_ID,
  44. },
  45. {
  46. .compatible = "st,lsm6dsl",
  47. .data = (void *)ST_LSM6DSL_ID,
  48. },
  49. {
  50. .compatible = "st,lsm6dsm",
  51. .data = (void *)ST_LSM6DSM_ID,
  52. },
  53. {
  54. .compatible = "st,ism330dlc",
  55. .data = (void *)ST_ISM330DLC_ID,
  56. },
  57. {},
  58. };
  59. MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match);
  60. static const struct spi_device_id st_lsm6dsx_spi_id_table[] = {
  61. { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID },
  62. { ST_LSM6DS3H_DEV_NAME, ST_LSM6DS3H_ID },
  63. { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID },
  64. { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
  65. { ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID },
  66. {},
  67. };
  68. MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
  69. static struct spi_driver st_lsm6dsx_driver = {
  70. .driver = {
  71. .name = "st_lsm6dsx_spi",
  72. .pm = &st_lsm6dsx_pm_ops,
  73. .of_match_table = of_match_ptr(st_lsm6dsx_spi_of_match),
  74. },
  75. .probe = st_lsm6dsx_spi_probe,
  76. .id_table = st_lsm6dsx_spi_id_table,
  77. };
  78. module_spi_driver(st_lsm6dsx_driver);
  79. MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
  80. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  81. MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx spi driver");
  82. MODULE_LICENSE("GPL v2");