bmp085-i2c.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/i2c.h>
  21. #include <linux/err.h>
  22. #include "bmp085.h"
  23. #define BMP085_I2C_ADDRESS 0x77
  24. static const unsigned short normal_i2c[] = { BMP085_I2C_ADDRESS,
  25. I2C_CLIENT_END };
  26. static int bmp085_i2c_detect(struct i2c_client *client,
  27. struct i2c_board_info *info)
  28. {
  29. if (client->addr != BMP085_I2C_ADDRESS)
  30. return -ENODEV;
  31. return bmp085_detect(&client->dev);
  32. }
  33. static int bmp085_i2c_probe(struct i2c_client *client,
  34. const struct i2c_device_id *id)
  35. {
  36. int err;
  37. struct regmap *regmap = devm_regmap_init_i2c(client,
  38. &bmp085_regmap_config);
  39. if (IS_ERR(regmap)) {
  40. err = PTR_ERR(regmap);
  41. dev_err(&client->dev, "Failed to init regmap: %d\n", err);
  42. return err;
  43. }
  44. return bmp085_probe(&client->dev, regmap, client->irq);
  45. }
  46. static int bmp085_i2c_remove(struct i2c_client *client)
  47. {
  48. return bmp085_remove(&client->dev);
  49. }
  50. static const struct i2c_device_id bmp085_id[] = {
  51. { BMP085_NAME, 0 },
  52. { "bmp180", 0 },
  53. { }
  54. };
  55. MODULE_DEVICE_TABLE(i2c, bmp085_id);
  56. static struct i2c_driver bmp085_i2c_driver = {
  57. .driver = {
  58. .name = BMP085_NAME,
  59. },
  60. .id_table = bmp085_id,
  61. .probe = bmp085_i2c_probe,
  62. .remove = bmp085_i2c_remove,
  63. .detect = bmp085_i2c_detect,
  64. .address_list = normal_i2c
  65. };
  66. module_i2c_driver(bmp085_i2c_driver);
  67. MODULE_AUTHOR("Eric Andersson <eric.andersson@unixphere.com>");
  68. MODULE_DESCRIPTION("BMP085 I2C bus driver");
  69. MODULE_LICENSE("GPL");