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