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