ad525x_dpot-i2c.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Driver for the Analog Devices digital potentiometers (I2C bus)
  3. *
  4. * Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <linux/i2c.h>
  9. #include <linux/module.h>
  10. #include "ad525x_dpot.h"
  11. /* I2C bus functions */
  12. static int write_d8(void *client, u8 val)
  13. {
  14. return i2c_smbus_write_byte(client, val);
  15. }
  16. static int write_r8d8(void *client, u8 reg, u8 val)
  17. {
  18. return i2c_smbus_write_byte_data(client, reg, val);
  19. }
  20. static int write_r8d16(void *client, u8 reg, u16 val)
  21. {
  22. return i2c_smbus_write_word_data(client, reg, val);
  23. }
  24. static int read_d8(void *client)
  25. {
  26. return i2c_smbus_read_byte(client);
  27. }
  28. static int read_r8d8(void *client, u8 reg)
  29. {
  30. return i2c_smbus_read_byte_data(client, reg);
  31. }
  32. static int read_r8d16(void *client, u8 reg)
  33. {
  34. return i2c_smbus_read_word_data(client, reg);
  35. }
  36. static const struct ad_dpot_bus_ops bops = {
  37. .read_d8 = read_d8,
  38. .read_r8d8 = read_r8d8,
  39. .read_r8d16 = read_r8d16,
  40. .write_d8 = write_d8,
  41. .write_r8d8 = write_r8d8,
  42. .write_r8d16 = write_r8d16,
  43. };
  44. static int ad_dpot_i2c_probe(struct i2c_client *client,
  45. const struct i2c_device_id *id)
  46. {
  47. struct ad_dpot_bus_data bdata = {
  48. .client = client,
  49. .bops = &bops,
  50. };
  51. if (!i2c_check_functionality(client->adapter,
  52. I2C_FUNC_SMBUS_WORD_DATA)) {
  53. dev_err(&client->dev, "SMBUS Word Data not Supported\n");
  54. return -EIO;
  55. }
  56. return ad_dpot_probe(&client->dev, &bdata, id->driver_data, id->name);
  57. }
  58. static int ad_dpot_i2c_remove(struct i2c_client *client)
  59. {
  60. return ad_dpot_remove(&client->dev);
  61. }
  62. static const struct i2c_device_id ad_dpot_id[] = {
  63. {"ad5258", AD5258_ID},
  64. {"ad5259", AD5259_ID},
  65. {"ad5251", AD5251_ID},
  66. {"ad5252", AD5252_ID},
  67. {"ad5253", AD5253_ID},
  68. {"ad5254", AD5254_ID},
  69. {"ad5255", AD5255_ID},
  70. {"ad5241", AD5241_ID},
  71. {"ad5242", AD5242_ID},
  72. {"ad5243", AD5243_ID},
  73. {"ad5245", AD5245_ID},
  74. {"ad5246", AD5246_ID},
  75. {"ad5247", AD5247_ID},
  76. {"ad5248", AD5248_ID},
  77. {"ad5280", AD5280_ID},
  78. {"ad5282", AD5282_ID},
  79. {"adn2860", ADN2860_ID},
  80. {"ad5273", AD5273_ID},
  81. {"ad5161", AD5161_ID},
  82. {"ad5171", AD5171_ID},
  83. {"ad5170", AD5170_ID},
  84. {"ad5172", AD5172_ID},
  85. {"ad5173", AD5173_ID},
  86. {"ad5272", AD5272_ID},
  87. {"ad5274", AD5274_ID},
  88. {}
  89. };
  90. MODULE_DEVICE_TABLE(i2c, ad_dpot_id);
  91. static struct i2c_driver ad_dpot_i2c_driver = {
  92. .driver = {
  93. .name = "ad_dpot",
  94. },
  95. .probe = ad_dpot_i2c_probe,
  96. .remove = ad_dpot_i2c_remove,
  97. .id_table = ad_dpot_id,
  98. };
  99. module_i2c_driver(ad_dpot_i2c_driver);
  100. MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
  101. MODULE_DESCRIPTION("digital potentiometer I2C bus driver");
  102. MODULE_LICENSE("GPL");