mpl115_i2c.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Freescale MPL115A2 pressure/temperature sensor
  3. *
  4. * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>
  5. *
  6. * This file is subject to the terms and conditions of version 2 of
  7. * the GNU General Public License. See the file COPYING in the main
  8. * directory of this archive for more details.
  9. *
  10. * (7-bit I2C slave address 0x60)
  11. *
  12. * Datasheet: http://www.nxp.com/files/sensors/doc/data_sheet/MPL115A2.pdf
  13. */
  14. #include <linux/module.h>
  15. #include <linux/i2c.h>
  16. #include "mpl115.h"
  17. static int mpl115_i2c_init(struct device *dev)
  18. {
  19. return 0;
  20. }
  21. static int mpl115_i2c_read(struct device *dev, u8 address)
  22. {
  23. return i2c_smbus_read_word_swapped(to_i2c_client(dev), address);
  24. }
  25. static int mpl115_i2c_write(struct device *dev, u8 address, u8 value)
  26. {
  27. return i2c_smbus_write_byte_data(to_i2c_client(dev), address, value);
  28. }
  29. static const struct mpl115_ops mpl115_i2c_ops = {
  30. .init = mpl115_i2c_init,
  31. .read = mpl115_i2c_read,
  32. .write = mpl115_i2c_write,
  33. };
  34. static int mpl115_i2c_probe(struct i2c_client *client,
  35. const struct i2c_device_id *id)
  36. {
  37. if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))
  38. return -EOPNOTSUPP;
  39. return mpl115_probe(&client->dev, id->name, &mpl115_i2c_ops);
  40. }
  41. static const struct i2c_device_id mpl115_i2c_id[] = {
  42. { "mpl115", 0 },
  43. { }
  44. };
  45. MODULE_DEVICE_TABLE(i2c, mpl115_i2c_id);
  46. static struct i2c_driver mpl115_i2c_driver = {
  47. .driver = {
  48. .name = "mpl115",
  49. },
  50. .probe = mpl115_i2c_probe,
  51. .id_table = mpl115_i2c_id,
  52. };
  53. module_i2c_driver(mpl115_i2c_driver);
  54. MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
  55. MODULE_DESCRIPTION("Freescale MPL115A2 pressure/temperature driver");
  56. MODULE_LICENSE("GPL");