bmc150-accel-i2c.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * 3-axis accelerometer driver supporting following I2C Bosch-Sensortec chips:
  3. * - BMC150
  4. * - BMI055
  5. * - BMA255
  6. * - BMA250E
  7. * - BMA222E
  8. * - BMA280
  9. *
  10. * Copyright (c) 2014, Intel Corporation.
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms and conditions of the GNU General Public License,
  14. * version 2, as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  18. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  19. * more details.
  20. */
  21. #include <linux/device.h>
  22. #include <linux/mod_devicetable.h>
  23. #include <linux/i2c.h>
  24. #include <linux/module.h>
  25. #include <linux/acpi.h>
  26. #include <linux/regmap.h>
  27. #include "bmc150-accel.h"
  28. static const struct regmap_config bmc150_i2c_regmap_conf = {
  29. .reg_bits = 8,
  30. .val_bits = 8,
  31. };
  32. static int bmc150_accel_probe(struct i2c_client *client,
  33. const struct i2c_device_id *id)
  34. {
  35. struct regmap *regmap;
  36. const char *name = NULL;
  37. bool block_supported =
  38. i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
  39. i2c_check_functionality(client->adapter,
  40. I2C_FUNC_SMBUS_READ_I2C_BLOCK);
  41. regmap = devm_regmap_init_i2c(client, &bmc150_i2c_regmap_conf);
  42. if (IS_ERR(regmap)) {
  43. dev_err(&client->dev, "Failed to initialize i2c regmap\n");
  44. return PTR_ERR(regmap);
  45. }
  46. if (id)
  47. name = id->name;
  48. return bmc150_accel_core_probe(&client->dev, regmap, client->irq, name,
  49. block_supported);
  50. }
  51. static int bmc150_accel_remove(struct i2c_client *client)
  52. {
  53. return bmc150_accel_core_remove(&client->dev);
  54. }
  55. static const struct acpi_device_id bmc150_accel_acpi_match[] = {
  56. {"BSBA0150", bmc150},
  57. {"BMC150A", bmc150},
  58. {"BMI055A", bmi055},
  59. {"BMA0255", bma255},
  60. {"BMA250E", bma250e},
  61. {"BMA222E", bma222e},
  62. {"BMA0280", bma280},
  63. { },
  64. };
  65. MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match);
  66. static const struct i2c_device_id bmc150_accel_id[] = {
  67. {"bmc150_accel", bmc150},
  68. {"bmi055_accel", bmi055},
  69. {"bma255", bma255},
  70. {"bma250e", bma250e},
  71. {"bma222e", bma222e},
  72. {"bma280", bma280},
  73. {}
  74. };
  75. MODULE_DEVICE_TABLE(i2c, bmc150_accel_id);
  76. static struct i2c_driver bmc150_accel_driver = {
  77. .driver = {
  78. .name = "bmc150_accel_i2c",
  79. .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match),
  80. .pm = &bmc150_accel_pm_ops,
  81. },
  82. .probe = bmc150_accel_probe,
  83. .remove = bmc150_accel_remove,
  84. .id_table = bmc150_accel_id,
  85. };
  86. module_i2c_driver(bmc150_accel_driver);
  87. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
  88. MODULE_LICENSE("GPL v2");
  89. MODULE_DESCRIPTION("BMC150 I2C accelerometer driver");