bmc150-accel-i2c.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 int bmc150_accel_probe(struct i2c_client *client,
  29. const struct i2c_device_id *id)
  30. {
  31. struct regmap *regmap;
  32. const char *name = NULL;
  33. bool block_supported =
  34. i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
  35. i2c_check_functionality(client->adapter,
  36. I2C_FUNC_SMBUS_READ_I2C_BLOCK);
  37. regmap = devm_regmap_init_i2c(client, &bmc150_regmap_conf);
  38. if (IS_ERR(regmap)) {
  39. dev_err(&client->dev, "Failed to initialize i2c regmap\n");
  40. return PTR_ERR(regmap);
  41. }
  42. if (id)
  43. name = id->name;
  44. return bmc150_accel_core_probe(&client->dev, regmap, client->irq, name,
  45. block_supported);
  46. }
  47. static int bmc150_accel_remove(struct i2c_client *client)
  48. {
  49. return bmc150_accel_core_remove(&client->dev);
  50. }
  51. static const struct acpi_device_id bmc150_accel_acpi_match[] = {
  52. {"BSBA0150", bmc150},
  53. {"BMC150A", bmc150},
  54. {"BMI055A", bmi055},
  55. {"BMA0255", bma255},
  56. {"BMA250E", bma250e},
  57. {"BMA222E", bma222e},
  58. {"BMA0280", bma280},
  59. {"BOSC0200"},
  60. { },
  61. };
  62. MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match);
  63. static const struct i2c_device_id bmc150_accel_id[] = {
  64. {"bmc150_accel", bmc150},
  65. {"bmi055_accel", bmi055},
  66. {"bma255", bma255},
  67. {"bma250e", bma250e},
  68. {"bma222e", bma222e},
  69. {"bma280", bma280},
  70. {}
  71. };
  72. MODULE_DEVICE_TABLE(i2c, bmc150_accel_id);
  73. static struct i2c_driver bmc150_accel_driver = {
  74. .driver = {
  75. .name = "bmc150_accel_i2c",
  76. .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match),
  77. .pm = &bmc150_accel_pm_ops,
  78. },
  79. .probe = bmc150_accel_probe,
  80. .remove = bmc150_accel_remove,
  81. .id_table = bmc150_accel_id,
  82. };
  83. module_i2c_driver(bmc150_accel_driver);
  84. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
  85. MODULE_LICENSE("GPL v2");
  86. MODULE_DESCRIPTION("BMC150 I2C accelerometer driver");