0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _AD_DPOT_H_
0009 #define _AD_DPOT_H_
0010
0011 #include <linux/types.h>
0012
0013 #define DPOT_CONF(features, wipers, max_pos, uid) \
0014 (((features) << 18) | (((wipers) & 0xFF) << 10) | \
0015 ((max_pos & 0xF) << 6) | (uid & 0x3F))
0016
0017 #define DPOT_UID(conf) (conf & 0x3F)
0018 #define DPOT_MAX_POS(conf) ((conf >> 6) & 0xF)
0019 #define DPOT_WIPERS(conf) ((conf >> 10) & 0xFF)
0020 #define DPOT_FEAT(conf) (conf >> 18)
0021
0022 #define BRDAC0 (1 << 0)
0023 #define BRDAC1 (1 << 1)
0024 #define BRDAC2 (1 << 2)
0025 #define BRDAC3 (1 << 3)
0026 #define BRDAC4 (1 << 4)
0027 #define BRDAC5 (1 << 5)
0028 #define MAX_RDACS 6
0029
0030 #define F_CMD_INC (1 << 0)
0031 #define F_CMD_EEP (1 << 1)
0032 #define F_CMD_OTP (1 << 2)
0033 #define F_CMD_TOL (1 << 3)
0034 #define F_RDACS_RW (1 << 4)
0035 #define F_RDACS_WONLY (1 << 5)
0036 #define F_AD_APPDATA (1 << 6)
0037 #define F_SPI_8BIT (1 << 7)
0038 #define F_SPI_16BIT (1 << 8)
0039 #define F_SPI_24BIT (1 << 9)
0040
0041 #define F_RDACS_RW_TOL (F_RDACS_RW | F_CMD_EEP | F_CMD_TOL)
0042 #define F_RDACS_RW_EEP (F_RDACS_RW | F_CMD_EEP)
0043 #define F_SPI (F_SPI_8BIT | F_SPI_16BIT | F_SPI_24BIT)
0044
0045 enum dpot_devid {
0046 AD5258_ID = DPOT_CONF(F_RDACS_RW_TOL, BRDAC0, 6, 0),
0047 AD5259_ID = DPOT_CONF(F_RDACS_RW_TOL, BRDAC0, 8, 1),
0048 AD5251_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
0049 BRDAC1 | BRDAC3, 6, 2),
0050 AD5252_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
0051 BRDAC1 | BRDAC3, 8, 3),
0052 AD5253_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
0053 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 6, 4),
0054 AD5254_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
0055 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 8, 5),
0056 AD5255_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
0057 BRDAC0 | BRDAC1 | BRDAC2, 9, 6),
0058 AD5160_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
0059 BRDAC0, 8, 7),
0060 AD5161_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
0061 BRDAC0, 8, 8),
0062 AD5162_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
0063 BRDAC0 | BRDAC1, 8, 9),
0064 AD5165_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
0065 BRDAC0, 8, 10),
0066 AD5200_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
0067 BRDAC0, 8, 11),
0068 AD5201_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
0069 BRDAC0, 5, 12),
0070 AD5203_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
0071 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 6, 13),
0072 AD5204_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
0073 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 8, 14),
0074 AD5206_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
0075 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3 | BRDAC4 | BRDAC5,
0076 8, 15),
0077 AD5207_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
0078 BRDAC0 | BRDAC1, 8, 16),
0079 AD5231_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_24BIT,
0080 BRDAC0, 10, 17),
0081 AD5232_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_16BIT,
0082 BRDAC0 | BRDAC1, 8, 18),
0083 AD5233_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_16BIT,
0084 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 6, 19),
0085 AD5235_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_24BIT,
0086 BRDAC0 | BRDAC1, 10, 20),
0087 AD5260_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
0088 BRDAC0, 8, 21),
0089 AD5262_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
0090 BRDAC0 | BRDAC1, 8, 22),
0091 AD5263_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
0092 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 8, 23),
0093 AD5290_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
0094 BRDAC0, 8, 24),
0095 AD5291_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT | F_CMD_OTP,
0096 BRDAC0, 8, 25),
0097 AD5292_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT | F_CMD_OTP,
0098 BRDAC0, 10, 26),
0099 AD5293_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT, BRDAC0, 10, 27),
0100 AD7376_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
0101 BRDAC0, 7, 28),
0102 AD8400_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
0103 BRDAC0, 8, 29),
0104 AD8402_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
0105 BRDAC0 | BRDAC1, 8, 30),
0106 AD8403_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
0107 BRDAC0 | BRDAC1 | BRDAC2, 8, 31),
0108 ADN2850_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_24BIT,
0109 BRDAC0 | BRDAC1, 10, 32),
0110 AD5241_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 8, 33),
0111 AD5242_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 34),
0112 AD5243_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 35),
0113 AD5245_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 8, 36),
0114 AD5246_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 7, 37),
0115 AD5247_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 7, 38),
0116 AD5248_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 39),
0117 AD5280_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 8, 40),
0118 AD5282_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 41),
0119 ADN2860_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
0120 BRDAC0 | BRDAC1 | BRDAC2, 9, 42),
0121 AD5273_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 6, 43),
0122 AD5171_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 6, 44),
0123 AD5170_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 8, 45),
0124 AD5172_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0 | BRDAC1, 8, 46),
0125 AD5173_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0 | BRDAC1, 8, 47),
0126 AD5270_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP | F_SPI_16BIT,
0127 BRDAC0, 10, 48),
0128 AD5271_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP | F_SPI_16BIT,
0129 BRDAC0, 8, 49),
0130 AD5272_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 10, 50),
0131 AD5274_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 8, 51),
0132 };
0133
0134 #define DPOT_RDAC0 0
0135 #define DPOT_RDAC1 1
0136 #define DPOT_RDAC2 2
0137 #define DPOT_RDAC3 3
0138 #define DPOT_RDAC4 4
0139 #define DPOT_RDAC5 5
0140
0141 #define DPOT_RDAC_MASK 0x1F
0142
0143 #define DPOT_REG_TOL 0x18
0144 #define DPOT_TOL_RDAC0 (DPOT_REG_TOL | DPOT_RDAC0)
0145 #define DPOT_TOL_RDAC1 (DPOT_REG_TOL | DPOT_RDAC1)
0146 #define DPOT_TOL_RDAC2 (DPOT_REG_TOL | DPOT_RDAC2)
0147 #define DPOT_TOL_RDAC3 (DPOT_REG_TOL | DPOT_RDAC3)
0148 #define DPOT_TOL_RDAC4 (DPOT_REG_TOL | DPOT_RDAC4)
0149 #define DPOT_TOL_RDAC5 (DPOT_REG_TOL | DPOT_RDAC5)
0150
0151
0152 #define DPOT_ADDR_RDAC (0x0 << 5)
0153 #define DPOT_ADDR_EEPROM (0x1 << 5)
0154 #define DPOT_ADDR_OTP (0x1 << 6)
0155 #define DPOT_ADDR_CMD (0x1 << 7)
0156 #define DPOT_ADDR_OTP_EN (0x1 << 9)
0157
0158 #define DPOT_DEC_ALL_6DB (DPOT_ADDR_CMD | (0x4 << 3))
0159 #define DPOT_INC_ALL_6DB (DPOT_ADDR_CMD | (0x9 << 3))
0160 #define DPOT_DEC_ALL (DPOT_ADDR_CMD | (0x6 << 3))
0161 #define DPOT_INC_ALL (DPOT_ADDR_CMD | (0xB << 3))
0162
0163 #define DPOT_SPI_RDAC 0xB0
0164 #define DPOT_SPI_EEPROM 0x30
0165 #define DPOT_SPI_READ_RDAC 0xA0
0166 #define DPOT_SPI_READ_EEPROM 0x90
0167 #define DPOT_SPI_DEC_ALL_6DB 0x50
0168 #define DPOT_SPI_INC_ALL_6DB 0xD0
0169 #define DPOT_SPI_DEC_ALL 0x70
0170 #define DPOT_SPI_INC_ALL 0xF0
0171
0172
0173 #define DPOT_AD5291_RDAC 0x01
0174 #define DPOT_AD5291_READ_RDAC 0x02
0175 #define DPOT_AD5291_STORE_XTPM 0x03
0176 #define DPOT_AD5291_CTRLREG 0x06
0177 #define DPOT_AD5291_UNLOCK_CMD 0x03
0178
0179
0180 #define DPOT_AD5270_1_2_4_RDAC 0x01
0181 #define DPOT_AD5270_1_2_4_READ_RDAC 0x02
0182 #define DPOT_AD5270_1_2_4_STORE_XTPM 0x03
0183 #define DPOT_AD5270_1_2_4_CTRLREG 0x07
0184 #define DPOT_AD5270_1_2_4_UNLOCK_CMD 0x03
0185
0186 #define DPOT_AD5282_RDAC_AB 0x80
0187
0188 #define DPOT_AD5273_FUSE 0x80
0189 #define DPOT_AD5170_2_3_FUSE 0x20
0190 #define DPOT_AD5170_2_3_OW 0x08
0191 #define DPOT_AD5172_3_A0 0x08
0192 #define DPOT_AD5170_2FUSE 0x80
0193
0194 struct dpot_data;
0195
0196 struct ad_dpot_bus_ops {
0197 int (*read_d8)(void *client);
0198 int (*read_r8d8)(void *client, u8 reg);
0199 int (*read_r8d16)(void *client, u8 reg);
0200 int (*write_d8)(void *client, u8 val);
0201 int (*write_r8d8)(void *client, u8 reg, u8 val);
0202 int (*write_r8d16)(void *client, u8 reg, u16 val);
0203 };
0204
0205 struct ad_dpot_bus_data {
0206 void *client;
0207 const struct ad_dpot_bus_ops *bops;
0208 };
0209
0210 int ad_dpot_probe(struct device *dev, struct ad_dpot_bus_data *bdata,
0211 unsigned long devid, const char *name);
0212 void ad_dpot_remove(struct device *dev);
0213
0214 #endif