bmc150_magn_spi.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * 3-axis magnetometer driver support following SPI Bosch-Sensortec chips:
  3. * - BMC150
  4. * - BMC156
  5. * - BMM150
  6. *
  7. * Copyright (c) 2016, Intel Corporation.
  8. *
  9. * This file is subject to the terms and conditions of version 2 of
  10. * the GNU General Public License. See the file COPYING in the main
  11. * directory of this archive for more details.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/mod_devicetable.h>
  15. #include <linux/spi/spi.h>
  16. #include <linux/acpi.h>
  17. #include <linux/regmap.h>
  18. #include "bmc150_magn.h"
  19. static int bmc150_magn_spi_probe(struct spi_device *spi)
  20. {
  21. struct regmap *regmap;
  22. const struct spi_device_id *id = spi_get_device_id(spi);
  23. regmap = devm_regmap_init_spi(spi, &bmc150_magn_regmap_config);
  24. if (IS_ERR(regmap)) {
  25. dev_err(&spi->dev, "Failed to register spi regmap %d\n",
  26. (int)PTR_ERR(regmap));
  27. return PTR_ERR(regmap);
  28. }
  29. return bmc150_magn_probe(&spi->dev, regmap, spi->irq, id->name);
  30. }
  31. static int bmc150_magn_spi_remove(struct spi_device *spi)
  32. {
  33. bmc150_magn_remove(&spi->dev);
  34. return 0;
  35. }
  36. static const struct spi_device_id bmc150_magn_spi_id[] = {
  37. {"bmc150_magn", 0},
  38. {"bmc156_magn", 0},
  39. {"bmm150_magn", 0},
  40. {}
  41. };
  42. MODULE_DEVICE_TABLE(spi, bmc150_magn_spi_id);
  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 struct spi_driver bmc150_magn_spi_driver = {
  51. .probe = bmc150_magn_spi_probe,
  52. .remove = bmc150_magn_spi_remove,
  53. .id_table = bmc150_magn_spi_id,
  54. .driver = {
  55. .acpi_match_table = ACPI_PTR(bmc150_magn_acpi_match),
  56. .name = "bmc150_magn_spi",
  57. },
  58. };
  59. module_spi_driver(bmc150_magn_spi_driver);
  60. MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");
  61. MODULE_DESCRIPTION("BMC150 magnetometer SPI driver");
  62. MODULE_LICENSE("GPL v2");