ad525x_dpot.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Driver for the Analog Devices digital potentiometers
  3. *
  4. * Copyright (C) 2010 Michael Hennerich, Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #ifndef _AD_DPOT_H_
  9. #define _AD_DPOT_H_
  10. #include <linux/types.h>
  11. #define DPOT_CONF(features, wipers, max_pos, uid) \
  12. (((features) << 18) | (((wipers) & 0xFF) << 10) | \
  13. ((max_pos & 0xF) << 6) | (uid & 0x3F))
  14. #define DPOT_UID(conf) (conf & 0x3F)
  15. #define DPOT_MAX_POS(conf) ((conf >> 6) & 0xF)
  16. #define DPOT_WIPERS(conf) ((conf >> 10) & 0xFF)
  17. #define DPOT_FEAT(conf) (conf >> 18)
  18. #define BRDAC0 (1 << 0)
  19. #define BRDAC1 (1 << 1)
  20. #define BRDAC2 (1 << 2)
  21. #define BRDAC3 (1 << 3)
  22. #define BRDAC4 (1 << 4)
  23. #define BRDAC5 (1 << 5)
  24. #define F_CMD_INC (1 << 0) /* Features INC/DEC ALL, 6dB */
  25. #define F_CMD_EEP (1 << 1) /* Features EEPROM */
  26. #define F_CMD_OTP (1 << 2) /* Features OTP */
  27. #define F_CMD_TOL (1 << 3) /* RDACS feature Tolerance REG */
  28. #define F_RDACS_RW (1 << 4) /* RDACS are Read/Write */
  29. #define F_RDACS_WONLY (1 << 5) /* RDACS are Write only */
  30. #define F_AD_APPDATA (1 << 6) /* RDAC Address append to data */
  31. #define F_SPI_8BIT (1 << 7) /* All SPI XFERS are 8-bit */
  32. #define F_SPI_16BIT (1 << 8) /* All SPI XFERS are 16-bit */
  33. #define F_SPI_24BIT (1 << 9) /* All SPI XFERS are 24-bit */
  34. #define F_RDACS_RW_TOL (F_RDACS_RW | F_CMD_EEP | F_CMD_TOL)
  35. #define F_RDACS_RW_EEP (F_RDACS_RW | F_CMD_EEP)
  36. #define F_SPI (F_SPI_8BIT | F_SPI_16BIT | F_SPI_24BIT)
  37. enum dpot_devid {
  38. AD5258_ID = DPOT_CONF(F_RDACS_RW_TOL, BRDAC0, 6, 0), /* I2C */
  39. AD5259_ID = DPOT_CONF(F_RDACS_RW_TOL, BRDAC0, 8, 1),
  40. AD5251_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
  41. BRDAC0 | BRDAC3, 6, 2),
  42. AD5252_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
  43. BRDAC0 | BRDAC3, 8, 3),
  44. AD5253_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
  45. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 6, 4),
  46. AD5254_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
  47. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 8, 5),
  48. AD5255_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
  49. BRDAC0 | BRDAC1 | BRDAC2, 9, 6),
  50. AD5160_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  51. BRDAC0, 8, 7), /* SPI */
  52. AD5161_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  53. BRDAC0, 8, 8),
  54. AD5162_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  55. BRDAC0 | BRDAC1, 8, 9),
  56. AD5165_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  57. BRDAC0, 8, 10),
  58. AD5200_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  59. BRDAC0, 8, 11),
  60. AD5201_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  61. BRDAC0, 5, 12),
  62. AD5203_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  63. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 6, 13),
  64. AD5204_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  65. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 8, 14),
  66. AD5206_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  67. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3 | BRDAC4 | BRDAC5,
  68. 8, 15),
  69. AD5207_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  70. BRDAC0 | BRDAC1, 8, 16),
  71. AD5231_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_24BIT,
  72. BRDAC0, 10, 17),
  73. AD5232_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_16BIT,
  74. BRDAC0 | BRDAC1, 8, 18),
  75. AD5233_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_16BIT,
  76. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 6, 19),
  77. AD5235_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_24BIT,
  78. BRDAC0 | BRDAC1, 10, 20),
  79. AD5260_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  80. BRDAC0, 8, 21),
  81. AD5262_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  82. BRDAC0 | BRDAC1, 8, 22),
  83. AD5263_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  84. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 8, 23),
  85. AD5290_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  86. BRDAC0, 8, 24),
  87. AD5291_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT, BRDAC0, 8, 25),
  88. AD5292_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT, BRDAC0, 10, 26),
  89. AD5293_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT, BRDAC0, 10, 27),
  90. AD7376_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  91. BRDAC0, 7, 28),
  92. AD8400_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  93. BRDAC0, 8, 29),
  94. AD8402_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  95. BRDAC0 | BRDAC1, 8, 30),
  96. AD8403_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  97. BRDAC0 | BRDAC1 | BRDAC2, 8, 31),
  98. ADN2850_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_24BIT,
  99. BRDAC0 | BRDAC1, 10, 32),
  100. AD5241_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 8, 33),
  101. AD5242_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 34),
  102. AD5243_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 35),
  103. AD5245_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 8, 36),
  104. AD5246_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 7, 37),
  105. AD5247_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 7, 38),
  106. AD5248_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 39),
  107. };
  108. #define DPOT_RDAC0 0
  109. #define DPOT_RDAC1 1
  110. #define DPOT_RDAC2 2
  111. #define DPOT_RDAC3 3
  112. #define DPOT_RDAC4 4
  113. #define DPOT_RDAC5 5
  114. #define DPOT_RDAC_MASK 0x1F
  115. #define DPOT_REG_TOL 0x18
  116. #define DPOT_TOL_RDAC0 (DPOT_REG_TOL | DPOT_RDAC0)
  117. #define DPOT_TOL_RDAC1 (DPOT_REG_TOL | DPOT_RDAC1)
  118. #define DPOT_TOL_RDAC2 (DPOT_REG_TOL | DPOT_RDAC2)
  119. #define DPOT_TOL_RDAC3 (DPOT_REG_TOL | DPOT_RDAC3)
  120. #define DPOT_TOL_RDAC4 (DPOT_REG_TOL | DPOT_RDAC4)
  121. #define DPOT_TOL_RDAC5 (DPOT_REG_TOL | DPOT_RDAC5)
  122. /* RDAC-to-EEPROM Interface Commands */
  123. #define DPOT_ADDR_RDAC (0x00 << 5)
  124. #define DPOT_ADDR_EEPROM (0x01 << 5)
  125. #define DPOT_ADDR_CMD (0x80)
  126. #define DPOT_DEC_ALL_6DB (DPOT_ADDR_CMD | (0x4 << 3))
  127. #define DPOT_INC_ALL_6DB (DPOT_ADDR_CMD | (0x9 << 3))
  128. #define DPOT_DEC_ALL (DPOT_ADDR_CMD | (0x6 << 3))
  129. #define DPOT_INC_ALL (DPOT_ADDR_CMD | (0xB << 3))
  130. #define DPOT_SPI_RDAC 0xB0
  131. #define DPOT_SPI_EEPROM 0x30
  132. #define DPOT_SPI_READ_RDAC 0xA0
  133. #define DPOT_SPI_READ_EEPROM 0x90
  134. #define DPOT_SPI_DEC_ALL_6DB 0x50
  135. #define DPOT_SPI_INC_ALL_6DB 0xD0
  136. #define DPOT_SPI_DEC_ALL 0x70
  137. #define DPOT_SPI_INC_ALL 0xF0
  138. /* AD5291/2/3 use special commands */
  139. #define DPOT_AD5291_RDAC 0x01
  140. #define DPOT_AD5291_READ_RDAC 0x02
  141. /* AD524x use special commands */
  142. #define DPOT_AD5291_RDAC_AB 0x80
  143. struct dpot_data;
  144. struct ad_dpot_bus_ops {
  145. int (*read_d8) (void *client);
  146. int (*read_r8d8) (void *client, u8 reg);
  147. int (*read_r8d16) (void *client, u8 reg);
  148. int (*write_d8) (void *client, u8 val);
  149. int (*write_r8d8) (void *client, u8 reg, u8 val);
  150. int (*write_r8d16) (void *client, u8 reg, u16 val);
  151. };
  152. struct ad_dpot_bus_data {
  153. void *client;
  154. const struct ad_dpot_bus_ops *bops;
  155. };
  156. struct ad_dpot_id {
  157. char *name;
  158. unsigned long devid;
  159. };
  160. int ad_dpot_probe(struct device *dev, struct ad_dpot_bus_data *bdata, const struct ad_dpot_id *id);
  161. int ad_dpot_remove(struct device *dev);
  162. #endif