ad525x_dpot-i2c.c 3.0 KB

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