34
34
/* AD4695 registers */
35
35
#define AD4695_REG_SPI_CONFIG_A 0x0000
36
36
#define AD4695_REG_SPI_CONFIG_A_SW_RST (BIT(7) | BIT(0))
37
+ #define AD4695_REG_SPI_CONFIG_A_ADDR_DIR BIT(5)
37
38
#define AD4695_REG_SPI_CONFIG_B 0x0001
38
39
#define AD4695_REG_SPI_CONFIG_B_INST_MODE BIT(7)
39
40
#define AD4695_REG_DEVICE_TYPE 0x0003
77
78
#define AD4695_REG_GAIN_IN (n ) (0x00C0 | (2 * (n)))
78
79
#define AD4695_REG_AS_SLOT (n ) (0x0100 | (n))
79
80
#define AD4695_REG_AS_SLOT_INX GENMASK(3, 0)
80
- #define AD4695_MAX_REG 0x017F
81
81
82
82
/* Conversion mode commands */
83
83
#define AD4695_CMD_EXIT_CNV_MODE 0x0A
@@ -121,6 +121,7 @@ struct ad4695_channel_config {
121
121
struct ad4695_state {
122
122
struct spi_device * spi ;
123
123
struct regmap * regmap ;
124
+ struct regmap * regmap16 ;
124
125
struct gpio_desc * reset_gpio ;
125
126
/* voltages channels plus temperature and timestamp */
126
127
struct iio_chan_spec iio_chan [AD4695_MAX_CHANNELS + 2 ];
@@ -150,8 +151,10 @@ static const struct regmap_range ad4695_regmap_rd_ranges[] = {
150
151
regmap_reg_range (AD4695_REG_SPI_CONFIG_C , AD4695_REG_SPI_STATUS ),
151
152
regmap_reg_range (AD4695_REG_STATUS , AD4695_REG_ALERT_STATUS2 ),
152
153
regmap_reg_range (AD4695_REG_CLAMP_STATUS , AD4695_REG_CLAMP_STATUS ),
153
- regmap_reg_range (AD4695_REG_SETUP , AD4695_REG_TEMP_CTRL ),
154
- regmap_reg_range (AD4695_REG_CONFIG_IN (0 ), AD4695_MAX_REG ),
154
+ regmap_reg_range (AD4695_REG_SETUP , AD4695_REG_AC_CTRL ),
155
+ regmap_reg_range (AD4695_REG_GPIO_CTRL , AD4695_REG_TEMP_CTRL ),
156
+ regmap_reg_range (AD4695_REG_CONFIG_IN (0 ), AD4695_REG_CONFIG_IN (15 )),
157
+ regmap_reg_range (AD4695_REG_AS_SLOT (0 ), AD4695_REG_AS_SLOT (127 )),
155
158
};
156
159
157
160
static const struct regmap_access_table ad4695_regmap_rd_table = {
@@ -164,8 +167,10 @@ static const struct regmap_range ad4695_regmap_wr_ranges[] = {
164
167
regmap_reg_range (AD4695_REG_SCRATCH_PAD , AD4695_REG_SCRATCH_PAD ),
165
168
regmap_reg_range (AD4695_REG_LOOP_MODE , AD4695_REG_LOOP_MODE ),
166
169
regmap_reg_range (AD4695_REG_SPI_CONFIG_C , AD4695_REG_SPI_STATUS ),
167
- regmap_reg_range (AD4695_REG_SETUP , AD4695_REG_TEMP_CTRL ),
168
- regmap_reg_range (AD4695_REG_CONFIG_IN (0 ), AD4695_MAX_REG ),
170
+ regmap_reg_range (AD4695_REG_SETUP , AD4695_REG_AC_CTRL ),
171
+ regmap_reg_range (AD4695_REG_GPIO_CTRL , AD4695_REG_TEMP_CTRL ),
172
+ regmap_reg_range (AD4695_REG_CONFIG_IN (0 ), AD4695_REG_CONFIG_IN (15 )),
173
+ regmap_reg_range (AD4695_REG_AS_SLOT (0 ), AD4695_REG_AS_SLOT (127 )),
169
174
};
170
175
171
176
static const struct regmap_access_table ad4695_regmap_wr_table = {
@@ -174,15 +179,47 @@ static const struct regmap_access_table ad4695_regmap_wr_table = {
174
179
};
175
180
176
181
static const struct regmap_config ad4695_regmap_config = {
177
- .name = "ad4695" ,
182
+ .name = "ad4695-8 " ,
178
183
.reg_bits = 16 ,
179
184
.val_bits = 8 ,
180
- .max_register = AD4695_MAX_REG ,
185
+ .max_register = AD4695_REG_AS_SLOT ( 127 ) ,
181
186
.rd_table = & ad4695_regmap_rd_table ,
182
187
.wr_table = & ad4695_regmap_wr_table ,
183
188
.can_multi_write = true,
184
189
};
185
190
191
+ static const struct regmap_range ad4695_regmap16_rd_ranges [] = {
192
+ regmap_reg_range (AD4695_REG_STD_SEQ_CONFIG , AD4695_REG_STD_SEQ_CONFIG ),
193
+ regmap_reg_range (AD4695_REG_UPPER_IN (0 ), AD4695_REG_GAIN_IN (15 )),
194
+ };
195
+
196
+ static const struct regmap_access_table ad4695_regmap16_rd_table = {
197
+ .yes_ranges = ad4695_regmap16_rd_ranges ,
198
+ .n_yes_ranges = ARRAY_SIZE (ad4695_regmap16_rd_ranges ),
199
+ };
200
+
201
+ static const struct regmap_range ad4695_regmap16_wr_ranges [] = {
202
+ regmap_reg_range (AD4695_REG_STD_SEQ_CONFIG , AD4695_REG_STD_SEQ_CONFIG ),
203
+ regmap_reg_range (AD4695_REG_UPPER_IN (0 ), AD4695_REG_GAIN_IN (15 )),
204
+ };
205
+
206
+ static const struct regmap_access_table ad4695_regmap16_wr_table = {
207
+ .yes_ranges = ad4695_regmap16_wr_ranges ,
208
+ .n_yes_ranges = ARRAY_SIZE (ad4695_regmap16_wr_ranges ),
209
+ };
210
+
211
+ static const struct regmap_config ad4695_regmap16_config = {
212
+ .name = "ad4695-16" ,
213
+ .reg_bits = 16 ,
214
+ .reg_stride = 2 ,
215
+ .val_bits = 16 ,
216
+ .val_format_endian = REGMAP_ENDIAN_LITTLE ,
217
+ .max_register = AD4695_REG_GAIN_IN (15 ),
218
+ .rd_table = & ad4695_regmap16_rd_table ,
219
+ .wr_table = & ad4695_regmap16_wr_table ,
220
+ .can_multi_write = true,
221
+ };
222
+
186
223
static const struct iio_chan_spec ad4695_channel_template = {
187
224
.type = IIO_VOLTAGE ,
188
225
.indexed = 1 ,
@@ -646,13 +683,24 @@ static int ad4695_debugfs_reg_access(struct iio_dev *indio_dev,
646
683
struct ad4695_state * st = iio_priv (indio_dev );
647
684
648
685
iio_device_claim_direct_scoped (return - EBUSY , indio_dev ) {
649
- if (readval )
650
- return regmap_read (st -> regmap , reg , readval );
651
-
652
- return regmap_write (st -> regmap , reg , writeval );
686
+ if (readval ) {
687
+ if (regmap_check_range_table (st -> regmap , reg ,
688
+ & ad4695_regmap_rd_table ))
689
+ return regmap_read (st -> regmap , reg , readval );
690
+ if (regmap_check_range_table (st -> regmap16 , reg ,
691
+ & ad4695_regmap16_rd_table ))
692
+ return regmap_read (st -> regmap16 , reg , readval );
693
+ } else {
694
+ if (regmap_check_range_table (st -> regmap , reg ,
695
+ & ad4695_regmap_wr_table ))
696
+ return regmap_write (st -> regmap , reg , writeval );
697
+ if (regmap_check_range_table (st -> regmap16 , reg ,
698
+ & ad4695_regmap16_wr_table ))
699
+ return regmap_write (st -> regmap16 , reg , writeval );
700
+ }
653
701
}
654
702
655
- unreachable () ;
703
+ return - EINVAL ;
656
704
}
657
705
658
706
static const struct iio_info ad4695_info = {
@@ -807,6 +855,11 @@ static int ad4695_probe(struct spi_device *spi)
807
855
return dev_err_probe (dev , PTR_ERR (st -> regmap ),
808
856
"Failed to initialize regmap\n" );
809
857
858
+ st -> regmap16 = devm_regmap_init_spi (spi , & ad4695_regmap16_config );
859
+ if (IS_ERR (st -> regmap16 ))
860
+ return dev_err_probe (dev , PTR_ERR (st -> regmap16 ),
861
+ "Failed to initialize regmap16\n" );
862
+
810
863
ret = devm_regulator_bulk_get_enable (dev ,
811
864
ARRAY_SIZE (ad4695_power_supplies ),
812
865
ad4695_power_supplies );
@@ -876,9 +929,9 @@ static int ad4695_probe(struct spi_device *spi)
876
929
msleep (AD4695_T_WAKEUP_SW_MS );
877
930
}
878
931
879
- /* Needed for debugfs since it only access registers 1 byte at a time . */
880
- ret = regmap_set_bits (st -> regmap , AD4695_REG_SPI_CONFIG_C ,
881
- AD4695_REG_SPI_CONFIG_C_MB_STRICT );
932
+ /* Needed for regmap16 to be able to work correctly . */
933
+ ret = regmap_set_bits (st -> regmap , AD4695_REG_SPI_CONFIG_A ,
934
+ AD4695_REG_SPI_CONFIG_A_ADDR_DIR );
882
935
if (ret )
883
936
return ret ;
884
937
0 commit comments