72 #include <linux/module.h>
73 #include <linux/device.h>
74 #include <linux/kernel.h>
77 #include <linux/slab.h>
98 static inline int dpot_read_d8(
struct dpot_data *dpot)
100 return dpot->
bdata.bops->read_d8(dpot->
bdata.client);
105 return dpot->
bdata.bops->read_r8d8(dpot->
bdata.client, reg);
108 static inline int dpot_read_r8d16(
struct dpot_data *dpot,
u8 reg)
110 return dpot->
bdata.bops->read_r8d16(dpot->
bdata.client, reg);
115 return dpot->
bdata.bops->write_d8(dpot->
bdata.client, val);
118 static inline int dpot_write_r8d8(
struct dpot_data *dpot,
u8 reg,
u16 val)
120 return dpot->
bdata.bops->write_r8d8(dpot->
bdata.client, reg, val);
123 static inline int dpot_write_r8d16(
struct dpot_data *dpot,
u8 reg,
u16 val)
125 return dpot->
bdata.bops->write_r8d16(dpot->
bdata.client, reg, val);
141 value = dpot_read_r8d8(dpot,
151 value = dpot_read_r8d8(dpot,
169 return dpot_read_r8d8(dpot, ctrl);
171 return dpot_read_r8d16(dpot, ctrl);
183 return dpot_read_d8(dpot);
193 return dpot_read_r8d8(dpot, ctrl);
197 return dpot_read_d8(dpot);
202 return dpot_read_r8d8(dpot, ctrl);
205 dpot_write_r8d8(dpot,
208 value = dpot_read_r8d16(dpot,
224 return dpot_read_r8d16(dpot, (reg & 0xF8) |
227 return dpot_read_r8d8(dpot, reg);
234 return dpot_read_spi(dpot, reg);
236 return dpot_read_i2c(dpot, reg);
252 return dpot_write_d8(dpot, val);
257 return dpot_write_r8d8(dpot, val >> 8,
272 return dpot_write_r8d8(dpot,
274 (value >> 8), value & 0xFF);
277 dpot_write_r8d8(dpot,
284 return dpot_write_r8d8(dpot,
286 (value >> 8), value & 0xFF);
290 }
else if (reg & DPOT_ADDR_EEPROM) {
310 return dpot_write_r8d8(dpot,
314 return dpot_write_r8d8(dpot,
321 return dpot_write_r8d8(dpot, val, value);
323 return dpot_write_r8d16(dpot, val, value);
331 unsigned tmp = 0, ctrl = 0;
336 return dpot_write_d8(dpot, value);
348 return dpot_write_r8d8(dpot, ctrl, value);
352 if (reg & DPOT_ADDR_OTP) {
353 tmp = dpot_read_d8(dpot);
358 return dpot_write_r8d8(dpot, ctrl, value);
364 if (reg & DPOT_ADDR_OTP) {
365 tmp = dpot_read_r8d16(dpot, ctrl);
370 return dpot_write_r8d8(dpot, ctrl, value);
373 if (reg & DPOT_ADDR_OTP) {
374 tmp = dpot_read_r8d16(dpot, tmp);
379 return dpot_write_r8d8(dpot, ctrl, value);
386 if (reg & DPOT_ADDR_OTP)
387 return dpot_write_r8d8(dpot,
394 (value >> 8), value & 0xFF);
397 if (reg & DPOT_ADDR_CMD)
398 return dpot_write_d8(dpot, reg);
401 return dpot_write_r8d16(dpot, (reg & 0xF8) |
402 ((reg & 0x7) << 1), value);
405 return dpot_write_r8d8(dpot, reg, value);
412 return dpot_write_spi(dpot, reg, value);
414 return dpot_write_i2c(dpot, reg, value);
429 "enabled" :
"disabled");
433 value = dpot_read(data, reg);
446 if (reg & DPOT_REG_TOL)
447 return sprintf(buf,
"0x%04x\n", value & 0xFFFF);
454 const char *buf,
size_t count,
u32 reg)
460 if (reg & DPOT_ADDR_OTP_EN) {
461 if (!
strncmp(buf,
"enabled",
sizeof(
"enabled")))
469 if ((reg & DPOT_ADDR_OTP) &&
481 dpot_write(data, reg, value);
482 if (reg & DPOT_ADDR_EEPROM)
484 else if (reg & DPOT_ADDR_OTP)
493 const char *buf,
size_t count,
u32 reg)
498 dpot_write(data, reg, 0);
506 #define DPOT_DEVICE_SHOW(_name, _reg) static ssize_t \
507 show_##_name(struct device *dev, \
508 struct device_attribute *attr, char *buf) \
510 return sysfs_show_reg(dev, attr, buf, _reg); \
513 #define DPOT_DEVICE_SET(_name, _reg) static ssize_t \
514 set_##_name(struct device *dev, \
515 struct device_attribute *attr, \
516 const char *buf, size_t count) \
518 return sysfs_set_reg(dev, attr, buf, count, _reg); \
521 #define DPOT_DEVICE_SHOW_SET(name, reg) \
522 DPOT_DEVICE_SHOW(name, reg) \
523 DPOT_DEVICE_SET(name, reg) \
524 static DEVICE_ATTR(name, S_IWUSR | S_IRUGO, show_##name, set_##name);
526 #define DPOT_DEVICE_SHOW_ONLY(name, reg) \
527 DPOT_DEVICE_SHOW(name, reg) \
528 static DEVICE_ATTR(name, S_IWUSR | S_IRUGO, show_##name, NULL);
566 static const struct attribute *dpot_attrib_wipers[] = {
567 &dev_attr_rdac0.attr,
568 &dev_attr_rdac1.attr,
569 &dev_attr_rdac2.attr,
570 &dev_attr_rdac3.attr,
571 &dev_attr_rdac4.attr,
572 &dev_attr_rdac5.attr,
576 static const struct attribute *dpot_attrib_eeprom[] = {
577 &dev_attr_eeprom0.attr,
578 &dev_attr_eeprom1.attr,
579 &dev_attr_eeprom2.attr,
580 &dev_attr_eeprom3.attr,
581 &dev_attr_eeprom4.attr,
582 &dev_attr_eeprom5.attr,
586 static const struct attribute *dpot_attrib_otp[] = {
596 static const struct attribute *dpot_attrib_otp_en[] = {
597 &dev_attr_otp0en.attr,
598 &dev_attr_otp1en.attr,
599 &dev_attr_otp2en.attr,
600 &dev_attr_otp3en.attr,
601 &dev_attr_otp4en.attr,
602 &dev_attr_otp5en.attr,
606 static const struct attribute *dpot_attrib_tolerance[] = {
607 &dev_attr_tolerance0.attr,
608 &dev_attr_tolerance1.attr,
609 &dev_attr_tolerance2.attr,
610 &dev_attr_tolerance3.attr,
611 &dev_attr_tolerance4.attr,
612 &dev_attr_tolerance5.attr,
618 #define DPOT_DEVICE_DO_CMD(_name, _cmd) static ssize_t \
619 set_##_name(struct device *dev, \
620 struct device_attribute *attr, \
621 const char *buf, size_t count) \
623 return sysfs_do_cmd(dev, attr, buf, count, _cmd); \
625 static DEVICE_ATTR(_name, S_IWUSR | S_IRUGO, NULL, set_##_name);
632 static struct attribute *ad525x_attributes_commands[] = {
633 &dev_attr_inc_all.attr,
634 &dev_attr_dec_all.attr,
635 &dev_attr_inc_all_6db.attr,
636 &dev_attr_dec_all_6db.attr,
641 .attrs = ad525x_attributes_commands,
648 dpot_attrib_wipers[rdac]);
651 dpot_attrib_eeprom[rdac]);
654 dpot_attrib_tolerance[rdac]);
657 dpot_attrib_otp_en[rdac]);
659 dpot_attrib_otp[rdac]);
663 dev_err(dev,
"failed to register sysfs hooks for RDAC%d\n",
673 dpot_attrib_wipers[rdac]);
676 dpot_attrib_eeprom[rdac]);
679 dpot_attrib_tolerance[rdac]);
682 dpot_attrib_otp_en[rdac]);
684 dpot_attrib_otp[rdac]);
715 if (data->
wipers & (1 << i)) {
718 goto exit_remove_files;
728 dev_err(dev,
"failed to register sysfs hooks\n");
732 dev_info(dev,
"%s %d-Position Digital Potentiometer registered\n",
739 if (data->
wipers & (1 << i))
746 dev_err(dev,
"failed to create client for %s ID 0x%lX\n",
758 if (data->
wipers & (1 << i))