ad525x_dpot.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 MAX_RDACS 6
  25. #define F_CMD_INC (1 << 0) /* Features INC/DEC ALL, 6dB */
  26. #define F_CMD_EEP (1 << 1) /* Features EEPROM */
  27. #define F_CMD_OTP (1 << 2) /* Features OTP */
  28. #define F_CMD_TOL (1 << 3) /* RDACS feature Tolerance REG */
  29. #define F_RDACS_RW (1 << 4) /* RDACS are Read/Write */
  30. #define F_RDACS_WONLY (1 << 5) /* RDACS are Write only */
  31. #define F_AD_APPDATA (1 << 6) /* RDAC Address append to data */
  32. #define F_SPI_8BIT (1 << 7) /* All SPI XFERS are 8-bit */
  33. #define F_SPI_16BIT (1 << 8) /* All SPI XFERS are 16-bit */
  34. #define F_SPI_24BIT (1 << 9) /* All SPI XFERS are 24-bit */
  35. #define F_RDACS_RW_TOL (F_RDACS_RW | F_CMD_EEP | F_CMD_TOL)
  36. #define F_RDACS_RW_EEP (F_RDACS_RW | F_CMD_EEP)
  37. #define F_SPI (F_SPI_8BIT | F_SPI_16BIT | F_SPI_24BIT)
  38. enum dpot_devid {
  39. AD5258_ID = DPOT_CONF(F_RDACS_RW_TOL, BRDAC0, 6, 0), /* I2C */
  40. AD5259_ID = DPOT_CONF(F_RDACS_RW_TOL, BRDAC0, 8, 1),
  41. AD5251_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
  42. BRDAC1 | BRDAC3, 6, 2),
  43. AD5252_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
  44. BRDAC1 | BRDAC3, 8, 3),
  45. AD5253_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
  46. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 6, 4),
  47. AD5254_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
  48. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 8, 5),
  49. AD5255_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
  50. BRDAC0 | BRDAC1 | BRDAC2, 9, 6),
  51. AD5160_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  52. BRDAC0, 8, 7), /* SPI */
  53. AD5161_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  54. BRDAC0, 8, 8),
  55. AD5162_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  56. BRDAC0 | BRDAC1, 8, 9),
  57. AD5165_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  58. BRDAC0, 8, 10),
  59. AD5200_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  60. BRDAC0, 8, 11),
  61. AD5201_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  62. BRDAC0, 5, 12),
  63. AD5203_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  64. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 6, 13),
  65. AD5204_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  66. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 8, 14),
  67. AD5206_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  68. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3 | BRDAC4 | BRDAC5,
  69. 8, 15),
  70. AD5207_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  71. BRDAC0 | BRDAC1, 8, 16),
  72. AD5231_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_24BIT,
  73. BRDAC0, 10, 17),
  74. AD5232_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_16BIT,
  75. BRDAC0 | BRDAC1, 8, 18),
  76. AD5233_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_16BIT,
  77. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 6, 19),
  78. AD5235_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_24BIT,
  79. BRDAC0 | BRDAC1, 10, 20),
  80. AD5260_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  81. BRDAC0, 8, 21),
  82. AD5262_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  83. BRDAC0 | BRDAC1, 8, 22),
  84. AD5263_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  85. BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 8, 23),
  86. AD5290_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  87. BRDAC0, 8, 24),
  88. AD5291_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT | F_CMD_OTP,
  89. BRDAC0, 8, 25),
  90. AD5292_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT | F_CMD_OTP,
  91. BRDAC0, 10, 26),
  92. AD5293_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT, BRDAC0, 10, 27),
  93. AD7376_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
  94. BRDAC0, 7, 28),
  95. AD8400_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  96. BRDAC0, 8, 29),
  97. AD8402_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  98. BRDAC0 | BRDAC1, 8, 30),
  99. AD8403_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
  100. BRDAC0 | BRDAC1 | BRDAC2, 8, 31),
  101. ADN2850_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_24BIT,
  102. BRDAC0 | BRDAC1, 10, 32),
  103. AD5241_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 8, 33),
  104. AD5242_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 34),
  105. AD5243_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 35),
  106. AD5245_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 8, 36),
  107. AD5246_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 7, 37),
  108. AD5247_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 7, 38),
  109. AD5248_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 39),
  110. AD5280_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 8, 40),
  111. AD5282_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 41),
  112. ADN2860_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
  113. BRDAC0 | BRDAC1 | BRDAC2, 9, 42),
  114. AD5273_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 6, 43),
  115. AD5171_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 6, 44),
  116. AD5170_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 8, 45),
  117. AD5172_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0 | BRDAC1, 8, 46),
  118. AD5173_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0 | BRDAC1, 8, 47),
  119. AD5270_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP | F_SPI_16BIT,
  120. BRDAC0, 10, 48),
  121. AD5271_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP | F_SPI_16BIT,
  122. BRDAC0, 8, 49),
  123. AD5272_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 10, 50),
  124. AD5274_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 8, 51),
  125. };
  126. #define DPOT_RDAC0 0
  127. #define DPOT_RDAC1 1
  128. #define DPOT_RDAC2 2
  129. #define DPOT_RDAC3 3
  130. #define DPOT_RDAC4 4
  131. #define DPOT_RDAC5 5
  132. #define DPOT_RDAC_MASK 0x1F
  133. #define DPOT_REG_TOL 0x18
  134. #define DPOT_TOL_RDAC0 (DPOT_REG_TOL | DPOT_RDAC0)
  135. #define DPOT_TOL_RDAC1 (DPOT_REG_TOL | DPOT_RDAC1)
  136. #define DPOT_TOL_RDAC2 (DPOT_REG_TOL | DPOT_RDAC2)
  137. #define DPOT_TOL_RDAC3 (DPOT_REG_TOL | DPOT_RDAC3)
  138. #define DPOT_TOL_RDAC4 (DPOT_REG_TOL | DPOT_RDAC4)
  139. #define DPOT_TOL_RDAC5 (DPOT_REG_TOL | DPOT_RDAC5)
  140. /* RDAC-to-EEPROM Interface Commands */
  141. #define DPOT_ADDR_RDAC (0x0 << 5)
  142. #define DPOT_ADDR_EEPROM (0x1 << 5)
  143. #define DPOT_ADDR_OTP (0x1 << 6)
  144. #define DPOT_ADDR_CMD (0x1 << 7)
  145. #define DPOT_ADDR_OTP_EN (0x1 << 9)
  146. #define DPOT_DEC_ALL_6DB (DPOT_ADDR_CMD | (0x4 << 3))
  147. #define DPOT_INC_ALL_6DB (DPOT_ADDR_CMD | (0x9 << 3))
  148. #define DPOT_DEC_ALL (DPOT_ADDR_CMD | (0x6 << 3))
  149. #define DPOT_INC_ALL (DPOT_ADDR_CMD | (0xB << 3))
  150. #define DPOT_SPI_RDAC 0xB0
  151. #define DPOT_SPI_EEPROM 0x30
  152. #define DPOT_SPI_READ_RDAC 0xA0
  153. #define DPOT_SPI_READ_EEPROM 0x90
  154. #define DPOT_SPI_DEC_ALL_6DB 0x50
  155. #define DPOT_SPI_INC_ALL_6DB 0xD0
  156. #define DPOT_SPI_DEC_ALL 0x70
  157. #define DPOT_SPI_INC_ALL 0xF0
  158. /* AD5291/2/3 use special commands */
  159. #define DPOT_AD5291_RDAC 0x01
  160. #define DPOT_AD5291_READ_RDAC 0x02
  161. #define DPOT_AD5291_STORE_XTPM 0x03
  162. #define DPOT_AD5291_CTRLREG 0x06
  163. #define DPOT_AD5291_UNLOCK_CMD 0x03
  164. /* AD5270/1/2/4 use special commands */
  165. #define DPOT_AD5270_1_2_4_RDAC 0x01
  166. #define DPOT_AD5270_1_2_4_READ_RDAC 0x02
  167. #define DPOT_AD5270_1_2_4_STORE_XTPM 0x03
  168. #define DPOT_AD5270_1_2_4_CTRLREG 0x07
  169. #define DPOT_AD5270_1_2_4_UNLOCK_CMD 0x03
  170. #define DPOT_AD5282_RDAC_AB 0x80
  171. #define DPOT_AD5273_FUSE 0x80
  172. #define DPOT_AD5170_2_3_FUSE 0x20
  173. #define DPOT_AD5170_2_3_OW 0x08
  174. #define DPOT_AD5172_3_A0 0x08
  175. #define DPOT_AD5170_2FUSE 0x80
  176. struct dpot_data;
  177. struct ad_dpot_bus_ops {
  178. int (*read_d8) (void *client);
  179. int (*read_r8d8) (void *client, u8 reg);
  180. int (*read_r8d16) (void *client, u8 reg);
  181. int (*write_d8) (void *client, u8 val);
  182. int (*write_r8d8) (void *client, u8 reg, u8 val);
  183. int (*write_r8d16) (void *client, u8 reg, u16 val);
  184. };
  185. struct ad_dpot_bus_data {
  186. void *client;
  187. const struct ad_dpot_bus_ops *bops;
  188. };
  189. int ad_dpot_probe(struct device *dev, struct ad_dpot_bus_data *bdata,
  190. unsigned long devid, const char *name);
  191. int ad_dpot_remove(struct device *dev);
  192. #endif