Lines Matching +full:rst +full:- +full:ctrl

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>
98 return dpot->bdata.bops->read_d8(dpot->bdata.client); in dpot_read_d8()
103 return dpot->bdata.bops->read_r8d8(dpot->bdata.client, reg); in dpot_read_r8d8()
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()
118 return dpot->bdata.bops->write_r8d8(dpot->bdata.client, reg, val); in dpot_write_r8d8()
123 return dpot->bdata.bops->write_r8d16(dpot->bdata.client, reg, val); in dpot_write_r8d16()
128 unsigned int ctrl = 0; in dpot_read_spi() local
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()
145 if (dpot->uid == DPOT_UID(AD5291_ID)) in dpot_read_spi()
149 } else if (dpot->uid == DPOT_UID(AD5270_ID) || in dpot_read_spi()
150 dpot->uid == DPOT_UID(AD5271_ID)) { in dpot_read_spi()
158 if (dpot->uid == DPOT_UID(AD5271_ID)) in dpot_read_spi()
164 ctrl = DPOT_SPI_READ_RDAC; in dpot_read_spi()
166 ctrl = DPOT_SPI_READ_EEPROM; in dpot_read_spi()
169 if (dpot->feat & F_SPI_16BIT) in dpot_read_spi()
170 return dpot_read_r8d8(dpot, ctrl); in dpot_read_spi()
171 else if (dpot->feat & F_SPI_24BIT) in dpot_read_spi()
172 return dpot_read_r8d16(dpot, ctrl); in dpot_read_spi()
174 return -EFAULT; in dpot_read_spi()
180 unsigned int ctrl = 0; in dpot_read_i2c() local
182 switch (dpot->uid) { in dpot_read_i2c()
193 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? in dpot_read_i2c()
195 return dpot_read_r8d8(dpot, ctrl); in dpot_read_i2c()
202 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? in dpot_read_i2c()
204 return dpot_read_r8d8(dpot, ctrl); in dpot_read_i2c()
219 if (dpot->uid == DPOT_UID(AD5274_ID)) in dpot_read_i2c()
223 if ((reg & DPOT_REG_TOL) || (dpot->max_pos > 256)) in dpot_read_i2c()
233 if (dpot->feat & F_SPI) in dpot_read()
244 if (dpot->feat & F_RDACS_WONLY) in dpot_write_spi()
245 dpot->rdac_cache[reg & DPOT_RDAC_MASK] = value; in dpot_write_spi()
247 if (dpot->feat & F_AD_APPDATA) { in dpot_write_spi()
248 if (dpot->feat & F_SPI_8BIT) { in dpot_write_spi()
250 DPOT_MAX_POS(dpot->devid)) | in dpot_write_spi()
253 } else if (dpot->feat & F_SPI_16BIT) { in dpot_write_spi()
255 DPOT_MAX_POS(dpot->devid)) | in dpot_write_spi()
262 if (dpot->uid == DPOT_UID(AD5291_ID) || in dpot_write_spi()
263 dpot->uid == DPOT_UID(AD5292_ID) || in dpot_write_spi()
264 dpot->uid == DPOT_UID(AD5293_ID)) { in dpot_write_spi()
269 if (dpot->uid == DPOT_UID(AD5291_ID)) in dpot_write_spi()
275 } else if (dpot->uid == DPOT_UID(AD5270_ID) || in dpot_write_spi()
276 dpot->uid == DPOT_UID(AD5271_ID)) { in dpot_write_spi()
281 if (dpot->uid == DPOT_UID(AD5271_ID)) in dpot_write_spi()
308 if (dpot->uid == DPOT_UID(AD5291_ID) || in dpot_write_spi()
309 dpot->uid == DPOT_UID(AD5292_ID)) { in dpot_write_spi()
312 } else if (dpot->uid == DPOT_UID(AD5270_ID) || in dpot_write_spi()
313 dpot->uid == DPOT_UID(AD5271_ID)) { in dpot_write_spi()
320 if (dpot->feat & F_SPI_16BIT) in dpot_write_spi()
322 else if (dpot->feat & F_SPI_24BIT) in dpot_write_spi()
325 return -EFAULT; in dpot_write_spi()
331 unsigned int tmp = 0, ctrl = 0; in dpot_write_i2c() local
333 switch (dpot->uid) { in dpot_write_i2c()
345 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? in dpot_write_i2c()
347 return dpot_write_r8d8(dpot, ctrl, value); in dpot_write_i2c()
353 return -EFAULT; in dpot_write_i2c()
354 ctrl = DPOT_AD5273_FUSE; in dpot_write_i2c()
356 return dpot_write_r8d8(dpot, ctrl, value); in dpot_write_i2c()
359 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? in dpot_write_i2c()
362 tmp = dpot_read_r8d16(dpot, ctrl); in dpot_write_i2c()
364 return -EFAULT; in dpot_write_i2c()
365 ctrl |= DPOT_AD5170_2_3_FUSE; in dpot_write_i2c()
367 return dpot_write_r8d8(dpot, ctrl, value); in dpot_write_i2c()
372 return -EFAULT; in dpot_write_i2c()
373 ctrl = DPOT_AD5170_2_3_FUSE; in dpot_write_i2c()
375 return dpot_write_r8d8(dpot, ctrl, value); in dpot_write_i2c()
385 if (dpot->uid == DPOT_UID(AD5274_ID)) in dpot_write_i2c()
394 if (dpot->max_pos > 256) in dpot_write_i2c()
405 if (dpot->feat & F_SPI) in dpot_write()
422 test_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask) ? in sysfs_show_reg()
426 mutex_lock(&data->update_lock); in sysfs_show_reg()
428 mutex_unlock(&data->update_lock); in sysfs_show_reg()
431 return -EINVAL; in sysfs_show_reg()
434 * the tolerance is a two-byte value where the MSB in sysfs_show_reg()
443 return sprintf(buf, "%u\n", value & data->rdac_mask); in sysfs_show_reg()
456 set_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask); in sysfs_set_reg()
458 clear_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask); in sysfs_set_reg()
464 !test_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask)) in sysfs_set_reg()
465 return -EPERM; in sysfs_set_reg()
471 if (value > data->rdac_mask) in sysfs_set_reg()
472 value = data->rdac_mask; in sysfs_set_reg()
474 mutex_lock(&data->update_lock); in sysfs_set_reg()
480 mutex_unlock(&data->update_lock); in sysfs_set_reg()
491 mutex_lock(&data->update_lock); in sysfs_do_cmd()
493 mutex_unlock(&data->update_lock); in sysfs_do_cmd()
498 /* ------------------------------------------------------------------------- */
610 /* ------------------------------------------------------------------------- */
641 int 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()
650 err |= sysfs_create_file(&dev->kobj, in ad_dpot_add_files()
652 err |= sysfs_create_file(&dev->kobj, in ad_dpot_add_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()
675 sysfs_remove_file(&dev->kobj, in ad_dpot_remove_files()
677 sysfs_remove_file(&dev->kobj, in ad_dpot_remove_files()
692 err = -ENOMEM; in ad_dpot_probe()
697 mutex_init(&data->update_lock); in ad_dpot_probe()
699 data->bdata = *bdata; in ad_dpot_probe()
700 data->devid = devid; in ad_dpot_probe()
702 data->max_pos = 1 << DPOT_MAX_POS(devid); in ad_dpot_probe()
703 data->rdac_mask = data->max_pos - 1; in ad_dpot_probe()
704 data->feat = DPOT_FEAT(devid); in ad_dpot_probe()
705 data->uid = DPOT_UID(devid); in ad_dpot_probe()
706 data->wipers = DPOT_WIPERS(devid); in ad_dpot_probe()
709 if (data->wipers & (1 << i)) { in ad_dpot_probe()
710 err = ad_dpot_add_files(dev, data->feat, i); in ad_dpot_probe()
713 /* power-up midscale */ in ad_dpot_probe()
714 if (data->feat & F_RDACS_WONLY) in ad_dpot_probe()
715 data->rdac_cache[i] = data->max_pos / 2; in ad_dpot_probe()
718 if (data->feat & F_CMD_INC) in ad_dpot_probe()
719 err = sysfs_create_group(&dev->kobj, &ad525x_group_commands); in ad_dpot_probe()
726 dev_info(dev, "%s %d-Position Digital Potentiometer registered\n", in ad_dpot_probe()
727 name, data->max_pos); in ad_dpot_probe()
733 if (data->wipers & (1 << i)) in ad_dpot_probe()
734 ad_dpot_remove_files(dev, data->feat, i); in ad_dpot_probe()
752 if (data->wipers & (1 << i)) in ad_dpot_remove()
753 ad_dpot_remove_files(dev, data->feat, i); in ad_dpot_remove()