bmp085-spi.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2012 Bosch Sensortec GmbH
  3. * Copyright (c) 2012 Unixphere AB
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/spi/spi.h>
  21. #include <linux/err.h>
  22. #include "bmp085.h"
  23. static int bmp085_spi_probe(struct spi_device *client)
  24. {
  25. int err;
  26. struct regmap *regmap;
  27. client->bits_per_word = 8;
  28. err = spi_setup(client);
  29. if (err < 0) {
  30. dev_err(&client->dev, "spi_setup failed!\n");
  31. return err;
  32. }
  33. regmap = devm_regmap_init_spi(client, &bmp085_regmap_config);
  34. if (IS_ERR(regmap)) {
  35. err = PTR_ERR(regmap);
  36. dev_err(&client->dev, "Failed to init regmap: %d\n", err);
  37. return err;
  38. }
  39. return bmp085_probe(&client->dev, regmap, client->irq);
  40. }
  41. static int bmp085_spi_remove(struct spi_device *client)
  42. {
  43. return bmp085_remove(&client->dev);
  44. }
  45. static const struct of_device_id bmp085_of_match[] = {
  46. { .compatible = "bosch,bmp085", },
  47. { },
  48. };
  49. MODULE_DEVICE_TABLE(of, bmp085_of_match);
  50. static const struct spi_device_id bmp085_id[] = {
  51. { "bmp180", 0 },
  52. { "bmp181", 0 },
  53. { }
  54. };
  55. MODULE_DEVICE_TABLE(spi, bmp085_id);
  56. static struct spi_driver bmp085_spi_driver = {
  57. .driver = {
  58. .name = BMP085_NAME,
  59. .of_match_table = bmp085_of_match
  60. },
  61. .id_table = bmp085_id,
  62. .probe = bmp085_spi_probe,
  63. .remove = bmp085_spi_remove
  64. };
  65. module_spi_driver(bmp085_spi_driver);
  66. MODULE_AUTHOR("Eric Andersson <eric.andersson@unixphere.com>");
  67. MODULE_DESCRIPTION("BMP085 SPI bus driver");
  68. MODULE_LICENSE("GPL");