ad525x_dpot-i2c.c 2.6 KB

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