adt7410.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * ADT7410/ADT7420 digital temperature sensor driver
  3. *
  4. * Copyright 2012-2013 Analog Devices Inc.
  5. * Author: Lars-Peter Clausen <lars@metafoo.de>
  6. *
  7. * Licensed under the GPL-2 or later.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/i2c.h>
  12. #include "adt7x10.h"
  13. static int adt7410_i2c_read_word(struct device *dev, u8 reg)
  14. {
  15. return i2c_smbus_read_word_swapped(to_i2c_client(dev), reg);
  16. }
  17. static int adt7410_i2c_write_word(struct device *dev, u8 reg, u16 data)
  18. {
  19. return i2c_smbus_write_word_swapped(to_i2c_client(dev), reg, data);
  20. }
  21. static int adt7410_i2c_read_byte(struct device *dev, u8 reg)
  22. {
  23. return i2c_smbus_read_byte_data(to_i2c_client(dev), reg);
  24. }
  25. static int adt7410_i2c_write_byte(struct device *dev, u8 reg, u8 data)
  26. {
  27. return i2c_smbus_write_byte_data(to_i2c_client(dev), reg, data);
  28. }
  29. static const struct adt7x10_ops adt7410_i2c_ops = {
  30. .read_word = adt7410_i2c_read_word,
  31. .write_word = adt7410_i2c_write_word,
  32. .read_byte = adt7410_i2c_read_byte,
  33. .write_byte = adt7410_i2c_write_byte,
  34. };
  35. static int adt7410_i2c_probe(struct i2c_client *client,
  36. const struct i2c_device_id *id)
  37. {
  38. if (!i2c_check_functionality(client->adapter,
  39. I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
  40. return -ENODEV;
  41. return adt7x10_probe(&client->dev, NULL, client->irq, &adt7410_i2c_ops);
  42. }
  43. static int adt7410_i2c_remove(struct i2c_client *client)
  44. {
  45. return adt7x10_remove(&client->dev, client->irq);
  46. }
  47. static const struct i2c_device_id adt7410_ids[] = {
  48. { "adt7410", 0 },
  49. { "adt7420", 0 },
  50. {}
  51. };
  52. MODULE_DEVICE_TABLE(i2c, adt7410_ids);
  53. static struct i2c_driver adt7410_driver = {
  54. .class = I2C_CLASS_HWMON,
  55. .driver = {
  56. .name = "adt7410",
  57. .pm = ADT7X10_DEV_PM_OPS,
  58. },
  59. .probe = adt7410_i2c_probe,
  60. .remove = adt7410_i2c_remove,
  61. .id_table = adt7410_ids,
  62. .address_list = I2C_ADDRS(0x48, 0x49, 0x4a, 0x4b),
  63. };
  64. module_i2c_driver(adt7410_driver);
  65. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  66. MODULE_DESCRIPTION("ADT7410/AD7420 driver");
  67. MODULE_LICENSE("GPL");