bmc150_magn_i2c.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * 3-axis magnetometer driver supporting following I2C Bosch-Sensortec chips:
  3. * - BMC150
  4. * - BMC156
  5. * - BMM150
  6. *
  7. * Copyright (c) 2016, Intel Corporation.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms and conditions of the GNU General Public License,
  11. * version 2, as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. */
  18. #include <linux/device.h>
  19. #include <linux/mod_devicetable.h>
  20. #include <linux/i2c.h>
  21. #include <linux/module.h>
  22. #include <linux/acpi.h>
  23. #include <linux/regmap.h>
  24. #include "bmc150_magn.h"
  25. static int bmc150_magn_i2c_probe(struct i2c_client *client,
  26. const struct i2c_device_id *id)
  27. {
  28. struct regmap *regmap;
  29. const char *name = NULL;
  30. regmap = devm_regmap_init_i2c(client, &bmc150_magn_regmap_config);
  31. if (IS_ERR(regmap)) {
  32. dev_err(&client->dev, "Failed to initialize i2c regmap\n");
  33. return PTR_ERR(regmap);
  34. }
  35. if (id)
  36. name = id->name;
  37. return bmc150_magn_probe(&client->dev, regmap, client->irq, name);
  38. }
  39. static int bmc150_magn_i2c_remove(struct i2c_client *client)
  40. {
  41. return bmc150_magn_remove(&client->dev);
  42. }
  43. static const struct acpi_device_id bmc150_magn_acpi_match[] = {
  44. {"BMC150B", 0},
  45. {"BMC156B", 0},
  46. {"BMM150B", 0},
  47. {},
  48. };
  49. MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match);
  50. static const struct i2c_device_id bmc150_magn_i2c_id[] = {
  51. {"bmc150_magn", 0},
  52. {"bmc156_magn", 0},
  53. {"bmm150_magn", 0},
  54. {}
  55. };
  56. MODULE_DEVICE_TABLE(i2c, bmc150_magn_i2c_id);
  57. static const struct of_device_id bmc150_magn_of_match[] = {
  58. { .compatible = "bosch,bmc150_magn" },
  59. { .compatible = "bosch,bmc156_magn" },
  60. { .compatible = "bosch,bmm150_magn" },
  61. { }
  62. };
  63. MODULE_DEVICE_TABLE(of, bmc150_magn_of_match);
  64. static struct i2c_driver bmc150_magn_driver = {
  65. .driver = {
  66. .name = "bmc150_magn_i2c",
  67. .of_match_table = bmc150_magn_of_match,
  68. .acpi_match_table = ACPI_PTR(bmc150_magn_acpi_match),
  69. .pm = &bmc150_magn_pm_ops,
  70. },
  71. .probe = bmc150_magn_i2c_probe,
  72. .remove = bmc150_magn_i2c_remove,
  73. .id_table = bmc150_magn_i2c_id,
  74. };
  75. module_i2c_driver(bmc150_magn_driver);
  76. MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");
  77. MODULE_LICENSE("GPL v2");
  78. MODULE_DESCRIPTION("BMC150 I2C magnetometer driver");