• Home
  • Raw
  • Download

Lines Matching +full:reg +full:- +full:data

1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (c) 2009-2010 Analog Devices, Inc.
33 * AD5291 1 256 20, 50, 100 (20-TP)
34 * AD5292 1 1024 20, 50, 100 (20-TP)
56 * AD5270 1 1024 20, 50, 100 (50-TP)
57 * AD5271 1 256 20, 50, 100 (50-TP)
58 * AD5272 1 1024 20, 50, 100 (50-TP)
59 * AD5274 1 256 20, 50, 100 (50-TP)
61 * See Documentation/misc-devices/ad525x_dpot.rst for more info.
68 * Copyright (c) 2006-2011 Michael Hennerich <michael.hennerich@analog.com>
80 * Client data (each client gets its own)
98 return dpot->bdata.bops->read_d8(dpot->bdata.client); in dpot_read_d8()
101 static inline int dpot_read_r8d8(struct dpot_data *dpot, u8 reg) in dpot_read_r8d8() argument
103 return dpot->bdata.bops->read_r8d8(dpot->bdata.client, reg); in dpot_read_r8d8()
106 static inline int dpot_read_r8d16(struct dpot_data *dpot, u8 reg) in dpot_read_r8d16() argument
108 return dpot->bdata.bops->read_r8d16(dpot->bdata.client, reg); in dpot_read_r8d16()
113 return dpot->bdata.bops->write_d8(dpot->bdata.client, val); in dpot_write_d8()
116 static inline int dpot_write_r8d8(struct dpot_data *dpot, u8 reg, u16 val) in dpot_write_r8d8() argument
118 return dpot->bdata.bops->write_r8d8(dpot->bdata.client, reg, val); in dpot_write_r8d8()
121 static inline int dpot_write_r8d16(struct dpot_data *dpot, u8 reg, u16 val) in dpot_write_r8d16() argument
123 return dpot->bdata.bops->write_r8d16(dpot->bdata.client, reg, val); in dpot_write_r8d16()
126 static s32 dpot_read_spi(struct dpot_data *dpot, u8 reg) in dpot_read_spi() argument
131 if (!(reg & (DPOT_ADDR_EEPROM | DPOT_ADDR_CMD))) { in dpot_read_spi()
133 if (dpot->feat & F_RDACS_WONLY) in dpot_read_spi()
134 return dpot->rdac_cache[reg & DPOT_RDAC_MASK]; in dpot_read_spi()
135 if (dpot->uid == DPOT_UID(AD5291_ID) || in dpot_read_spi()
136 dpot->uid == DPOT_UID(AD5292_ID) || in dpot_read_spi()
137 dpot->uid == DPOT_UID(AD5293_ID)) { in dpot_read_spi()
142 if (dpot->uid == DPOT_UID(AD5291_ID)) in dpot_read_spi()
146 } else if (dpot->uid == DPOT_UID(AD5270_ID) || in dpot_read_spi()
147 dpot->uid == DPOT_UID(AD5271_ID)) { in dpot_read_spi()
155 if (dpot->uid == DPOT_UID(AD5271_ID)) in dpot_read_spi()
162 } else if (reg & DPOT_ADDR_EEPROM) { in dpot_read_spi()
166 if (dpot->feat & F_SPI_16BIT) in dpot_read_spi()
168 else if (dpot->feat & F_SPI_24BIT) in dpot_read_spi()
171 return -EFAULT; in dpot_read_spi()
174 static s32 dpot_read_i2c(struct dpot_data *dpot, u8 reg) in dpot_read_i2c() argument
179 switch (dpot->uid) { in dpot_read_i2c()
190 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? in dpot_read_i2c()
199 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? in dpot_read_i2c()
216 if (dpot->uid == DPOT_UID(AD5274_ID)) in dpot_read_i2c()
220 if ((reg & DPOT_REG_TOL) || (dpot->max_pos > 256)) in dpot_read_i2c()
221 return dpot_read_r8d16(dpot, (reg & 0xF8) | in dpot_read_i2c()
222 ((reg & 0x7) << 1)); in dpot_read_i2c()
224 return dpot_read_r8d8(dpot, reg); in dpot_read_i2c()
228 static s32 dpot_read(struct dpot_data *dpot, u8 reg) in dpot_read() argument
230 if (dpot->feat & F_SPI) in dpot_read()
231 return dpot_read_spi(dpot, reg); in dpot_read()
233 return dpot_read_i2c(dpot, reg); in dpot_read()
236 static s32 dpot_write_spi(struct dpot_data *dpot, u8 reg, u16 value) in dpot_write_spi() argument
240 if (!(reg & (DPOT_ADDR_EEPROM | DPOT_ADDR_CMD | DPOT_ADDR_OTP))) { in dpot_write_spi()
241 if (dpot->feat & F_RDACS_WONLY) in dpot_write_spi()
242 dpot->rdac_cache[reg & DPOT_RDAC_MASK] = value; in dpot_write_spi()
244 if (dpot->feat & F_AD_APPDATA) { in dpot_write_spi()
245 if (dpot->feat & F_SPI_8BIT) { in dpot_write_spi()
246 val = ((reg & DPOT_RDAC_MASK) << in dpot_write_spi()
247 DPOT_MAX_POS(dpot->devid)) | in dpot_write_spi()
250 } else if (dpot->feat & F_SPI_16BIT) { in dpot_write_spi()
251 val = ((reg & DPOT_RDAC_MASK) << in dpot_write_spi()
252 DPOT_MAX_POS(dpot->devid)) | in dpot_write_spi()
259 if (dpot->uid == DPOT_UID(AD5291_ID) || in dpot_write_spi()
260 dpot->uid == DPOT_UID(AD5292_ID) || in dpot_write_spi()
261 dpot->uid == DPOT_UID(AD5293_ID)) { in dpot_write_spi()
266 if (dpot->uid == DPOT_UID(AD5291_ID)) in dpot_write_spi()
272 } else if (dpot->uid == DPOT_UID(AD5270_ID) || in dpot_write_spi()
273 dpot->uid == DPOT_UID(AD5271_ID)) { in dpot_write_spi()
278 if (dpot->uid == DPOT_UID(AD5271_ID)) in dpot_write_spi()
285 val = DPOT_SPI_RDAC | (reg & DPOT_RDAC_MASK); in dpot_write_spi()
287 } else if (reg & DPOT_ADDR_EEPROM) { in dpot_write_spi()
288 val = DPOT_SPI_EEPROM | (reg & DPOT_RDAC_MASK); in dpot_write_spi()
289 } else if (reg & DPOT_ADDR_CMD) { in dpot_write_spi()
290 switch (reg) { in dpot_write_spi()
304 } else if (reg & DPOT_ADDR_OTP) { in dpot_write_spi()
305 if (dpot->uid == DPOT_UID(AD5291_ID) || in dpot_write_spi()
306 dpot->uid == DPOT_UID(AD5292_ID)) { in dpot_write_spi()
309 } else if (dpot->uid == DPOT_UID(AD5270_ID) || in dpot_write_spi()
310 dpot->uid == DPOT_UID(AD5271_ID)) { in dpot_write_spi()
317 if (dpot->feat & F_SPI_16BIT) in dpot_write_spi()
319 else if (dpot->feat & F_SPI_24BIT) in dpot_write_spi()
322 return -EFAULT; in dpot_write_spi()
325 static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value) in dpot_write_i2c() argument
330 switch (dpot->uid) { in dpot_write_i2c()
342 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? in dpot_write_i2c()
347 if (reg & DPOT_ADDR_OTP) { in dpot_write_i2c()
350 return -EFAULT; in dpot_write_i2c()
356 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? in dpot_write_i2c()
358 if (reg & DPOT_ADDR_OTP) { in dpot_write_i2c()
361 return -EFAULT; in dpot_write_i2c()
366 if (reg & DPOT_ADDR_OTP) { in dpot_write_i2c()
369 return -EFAULT; in dpot_write_i2c()
378 if (reg & DPOT_ADDR_OTP) in dpot_write_i2c()
382 if (dpot->uid == DPOT_UID(AD5274_ID)) in dpot_write_i2c()
388 if (reg & DPOT_ADDR_CMD) in dpot_write_i2c()
389 return dpot_write_d8(dpot, reg); in dpot_write_i2c()
391 if (dpot->max_pos > 256) in dpot_write_i2c()
392 return dpot_write_r8d16(dpot, (reg & 0xF8) | in dpot_write_i2c()
393 ((reg & 0x7) << 1), value); in dpot_write_i2c()
395 /* All other registers require instruction + data bytes */ in dpot_write_i2c()
396 return dpot_write_r8d8(dpot, reg, value); in dpot_write_i2c()
400 static s32 dpot_write(struct dpot_data *dpot, u8 reg, u16 value) in dpot_write() argument
402 if (dpot->feat & F_SPI) in dpot_write()
403 return dpot_write_spi(dpot, reg, value); in dpot_write()
405 return dpot_write_i2c(dpot, reg, value); in dpot_write()
412 char *buf, u32 reg) in sysfs_show_reg() argument
414 struct dpot_data *data = dev_get_drvdata(dev); in sysfs_show_reg() local
417 if (reg & DPOT_ADDR_OTP_EN) in sysfs_show_reg()
419 test_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask) ? in sysfs_show_reg()
423 mutex_lock(&data->update_lock); in sysfs_show_reg()
424 value = dpot_read(data, reg); in sysfs_show_reg()
425 mutex_unlock(&data->update_lock); in sysfs_show_reg()
428 return -EINVAL; in sysfs_show_reg()
431 * the tolerance is a two-byte value where the MSB in sysfs_show_reg()
437 if (reg & DPOT_REG_TOL) in sysfs_show_reg()
440 return sprintf(buf, "%u\n", value & data->rdac_mask); in sysfs_show_reg()
445 const char *buf, size_t count, u32 reg) in sysfs_set_reg() argument
447 struct dpot_data *data = dev_get_drvdata(dev); in sysfs_set_reg() local
451 if (reg & DPOT_ADDR_OTP_EN) { in sysfs_set_reg()
453 set_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask); in sysfs_set_reg()
455 clear_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask); in sysfs_set_reg()
460 if ((reg & DPOT_ADDR_OTP) && in sysfs_set_reg()
461 !test_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask)) in sysfs_set_reg()
462 return -EPERM; in sysfs_set_reg()
468 if (value > data->rdac_mask) in sysfs_set_reg()
469 value = data->rdac_mask; in sysfs_set_reg()
471 mutex_lock(&data->update_lock); in sysfs_set_reg()
472 dpot_write(data, reg, value); in sysfs_set_reg()
473 if (reg & DPOT_ADDR_EEPROM) in sysfs_set_reg()
475 else if (reg & DPOT_ADDR_OTP) in sysfs_set_reg()
477 mutex_unlock(&data->update_lock); in sysfs_set_reg()
484 const char *buf, size_t count, u32 reg) in sysfs_do_cmd() argument
486 struct dpot_data *data = dev_get_drvdata(dev); in sysfs_do_cmd() local
488 mutex_lock(&data->update_lock); in sysfs_do_cmd()
489 dpot_write(data, reg, 0); in sysfs_do_cmd()
490 mutex_unlock(&data->update_lock); in sysfs_do_cmd()
495 /* ------------------------------------------------------------------------- */
512 #define DPOT_DEVICE_SHOW_SET(name, reg) \ argument
513 DPOT_DEVICE_SHOW(name, reg) \
514 DPOT_DEVICE_SET(name, reg) \
517 #define DPOT_DEVICE_SHOW_ONLY(name, reg) \ argument
518 DPOT_DEVICE_SHOW(name, reg) \
607 /* ------------------------------------------------------------------------- */
638 int err = sysfs_create_file(&dev->kobj, in ad_dpot_add_files()
641 err |= sysfs_create_file(&dev->kobj, in ad_dpot_add_files()
644 err |= sysfs_create_file(&dev->kobj, in ad_dpot_add_files()
647 err |= sysfs_create_file(&dev->kobj, in ad_dpot_add_files()
649 err |= sysfs_create_file(&dev->kobj, in ad_dpot_add_files()
663 sysfs_remove_file(&dev->kobj, in ad_dpot_remove_files()
666 sysfs_remove_file(&dev->kobj, in ad_dpot_remove_files()
669 sysfs_remove_file(&dev->kobj, in ad_dpot_remove_files()
672 sysfs_remove_file(&dev->kobj, in ad_dpot_remove_files()
674 sysfs_remove_file(&dev->kobj, in ad_dpot_remove_files()
684 struct dpot_data *data; in ad_dpot_probe() local
687 data = kzalloc(sizeof(struct dpot_data), GFP_KERNEL); in ad_dpot_probe()
688 if (!data) { in ad_dpot_probe()
689 err = -ENOMEM; in ad_dpot_probe()
693 dev_set_drvdata(dev, data); in ad_dpot_probe()
694 mutex_init(&data->update_lock); in ad_dpot_probe()
696 data->bdata = *bdata; in ad_dpot_probe()
697 data->devid = devid; in ad_dpot_probe()
699 data->max_pos = 1 << DPOT_MAX_POS(devid); in ad_dpot_probe()
700 data->rdac_mask = data->max_pos - 1; in ad_dpot_probe()
701 data->feat = DPOT_FEAT(devid); in ad_dpot_probe()
702 data->uid = DPOT_UID(devid); in ad_dpot_probe()
703 data->wipers = DPOT_WIPERS(devid); in ad_dpot_probe()
706 if (data->wipers & (1 << i)) { in ad_dpot_probe()
707 err = ad_dpot_add_files(dev, data->feat, i); in ad_dpot_probe()
710 /* power-up midscale */ in ad_dpot_probe()
711 if (data->feat & F_RDACS_WONLY) in ad_dpot_probe()
712 data->rdac_cache[i] = data->max_pos / 2; in ad_dpot_probe()
715 if (data->feat & F_CMD_INC) in ad_dpot_probe()
716 err = sysfs_create_group(&dev->kobj, &ad525x_group_commands); in ad_dpot_probe()
723 dev_info(dev, "%s %d-Position Digital Potentiometer registered\n", in ad_dpot_probe()
724 name, data->max_pos); in ad_dpot_probe()
730 if (data->wipers & (1 << i)) in ad_dpot_probe()
731 ad_dpot_remove_files(dev, data->feat, i); in ad_dpot_probe()
734 kfree(data); in ad_dpot_probe()
745 struct dpot_data *data = dev_get_drvdata(dev); in ad_dpot_remove() local
749 if (data->wipers & (1 << i)) in ad_dpot_remove()
750 ad_dpot_remove_files(dev, data->feat, i); in ad_dpot_remove()
752 kfree(data); in ad_dpot_remove()