st_lsm6dsx_i2c.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * STMicroelectronics st_lsm6dsx i2c 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/i2c.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_i2c_regmap_config = {
  19. .reg_bits = 8,
  20. .val_bits = 8,
  21. };
  22. static int st_lsm6dsx_i2c_probe(struct i2c_client *client,
  23. const struct i2c_device_id *id)
  24. {
  25. int hw_id = id->driver_data;
  26. struct regmap *regmap;
  27. regmap = devm_regmap_init_i2c(client, &st_lsm6dsx_i2c_regmap_config);
  28. if (IS_ERR(regmap)) {
  29. dev_err(&client->dev, "Failed to register i2c regmap %d\n",
  30. (int)PTR_ERR(regmap));
  31. return PTR_ERR(regmap);
  32. }
  33. return st_lsm6dsx_probe(&client->dev, client->irq,
  34. hw_id, id->name, regmap);
  35. }
  36. static const struct of_device_id st_lsm6dsx_i2c_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_i2c_of_match);
  60. static const struct i2c_device_id st_lsm6dsx_i2c_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(i2c, st_lsm6dsx_i2c_id_table);
  69. static struct i2c_driver st_lsm6dsx_driver = {
  70. .driver = {
  71. .name = "st_lsm6dsx_i2c",
  72. .pm = &st_lsm6dsx_pm_ops,
  73. .of_match_table = of_match_ptr(st_lsm6dsx_i2c_of_match),
  74. },
  75. .probe = st_lsm6dsx_i2c_probe,
  76. .id_table = st_lsm6dsx_i2c_id_table,
  77. };
  78. module_i2c_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 i2c driver");
  82. MODULE_LICENSE("GPL v2");