Skip to content

Commit 97967c3

Browse files
Shetty-Anushamiclaus
authored andcommitted
drivers:potentiometer:ad514x: Add support for top/bottom scale enter/exit
1. Implement the function for AD5141, AD5142 and AD5143 2. Update comment to reflect top/bottom scale command usage in AD5144 Signed-off-by: Anush Shetty <[email protected]>
1 parent 56e6de7 commit 97967c3

File tree

4 files changed

+120
-16
lines changed

4 files changed

+120
-16
lines changed

drivers/potentiometer/ad514x/ad5141.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,41 @@ int ad5141_dpot_chn_read(struct dpot_dev *desc,
606606
return 0;
607607
}
608608

609+
/**
610+
* @brief Enter/Exit the top scale or bottom scale .
611+
* @param desc - digipot descriptor.
612+
* @param chn - digipot channel.
613+
* @param is_top_scale - boolean flag to indicate top scale or bottom scale.
614+
* @param enable - Enter or exit the TS.
615+
* @return 0 in case of success, negative error code otherwise.
616+
*/
617+
int ad5141_dpot_top_bottom_scale_enable(struct dpot_dev *desc,
618+
enum dpot_chn_type chn,
619+
bool is_top_scale,
620+
uint8_t enable)
621+
{
622+
int ret;
623+
struct dpot_command cmd;
624+
625+
if (!desc)
626+
return -EINVAL;
627+
628+
ret = ad5141_validate_chn(desc->extra, chn);
629+
if (ret)
630+
return ret;
631+
632+
/* Enter/Exit the top scale or bottom scale (command #12 or command #13) */
633+
cmd.control = EXTRACT_CMD_BITS(AD51XX_CMD_TOP_SCALE_EXIT);
634+
cmd.address = ad5141_dpot_cmd_addr[chn];
635+
cmd.data = enable;
636+
if (is_top_scale == true)
637+
cmd.data |= EXTRACT_DATA_BITS(AD51XX_CMD_TOP_SCALE_EXIT);
638+
639+
cmd.is_readback = false;
640+
641+
return ad5141_dpot_send_cmd(desc, &cmd);
642+
}
643+
609644
/**
610645
* @brief Write to the digital potentiometer channel.
611646
* @param desc - digipot descriptor.
@@ -925,4 +960,5 @@ const struct dpot_ops ad5141_dpot_ops = {
925960
.dpot_rdac_6db_update = &ad5141_dpot_rdac_6db_update,
926961
// .dpot_send_cmd = &ad5141_dpot_send_cmd,
927962
.dpot_remove = &ad5141_dpot_remove,
963+
.dpot_enable_top_bottom_scale = &ad5141_dpot_top_bottom_scale_enable
928964
};

drivers/potentiometer/ad514x/ad5142.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,41 @@ int ad5142_dpot_chn_read(struct dpot_dev *desc,
559559
return 0;
560560
}
561561

562+
/**
563+
* @brief Enter/Exit the top scale or bottom scale .
564+
* @param desc - digipot descriptor.
565+
* @param chn - digipot channel.
566+
* @param is_top_scale - boolean flag to indicate top scale or bottom scale.
567+
* @param enable - Enter or exit the TS.
568+
* @return 0 in case of success, negative error code otherwise.
569+
*/
570+
int ad5142_dpot_top_bottom_scale_enable(struct dpot_dev *desc,
571+
enum dpot_chn_type chn,
572+
bool is_top_scale,
573+
uint8_t enable)
574+
{
575+
int ret;
576+
struct dpot_command cmd;
577+
578+
if (!desc)
579+
return -EINVAL;
580+
581+
ret = ad5142_validate_chn(desc->extra, chn);
582+
if (ret)
583+
return ret;
584+
585+
/* Enter/Exit the top scale or bottom scale (command #12 or command #13) */
586+
cmd.control = EXTRACT_CMD_BITS(AD51XX_CMD_TOP_SCALE_EXIT);
587+
cmd.address = ad5142_dpot_cmd_addr[chn];
588+
cmd.data = enable;
589+
if (is_top_scale == true)
590+
cmd.data |= EXTRACT_DATA_BITS(AD51XX_CMD_TOP_SCALE_EXIT);
591+
592+
cmd.is_readback = false;
593+
594+
return ad5142_dpot_send_cmd(desc, &cmd);
595+
}
596+
562597
/**
563598
* @brief Write to the digital potentiometer channel.
564599
* @param desc - digipot descriptor.
@@ -877,4 +912,5 @@ const struct dpot_ops ad5142_dpot_ops = {
877912
.dpot_rdac_6db_update = &ad5142_dpot_rdac_6db_update,
878913
//.dpot_send_cmd = &ad5142_dpot_send_cmd,
879914
.dpot_remove = &ad5142_dpot_remove,
915+
.dpot_enable_top_bottom_scale = &ad5142_dpot_top_bottom_scale_enable
880916
};

drivers/potentiometer/ad514x/ad5143.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,41 @@ int ad5143_dpot_chn_read(struct dpot_dev *desc,
423423
return 0;
424424
}
425425

426+
/**
427+
* @brief Enter/Exit the top scale or bottom scale .
428+
* @param desc - digipot descriptor.
429+
* @param chn - digipot channel.
430+
* @param is_top_scale - boolean flag to indicate top scale or bottom scale.
431+
* @param enable - Enter or exit the TS.
432+
* @return 0 in case of success, negative error code otherwise.
433+
*/
434+
int ad5143_dpot_top_bottom_scale_enable(struct dpot_dev *desc,
435+
enum dpot_chn_type chn,
436+
bool is_top_scale,
437+
uint8_t enable)
438+
{
439+
int ret;
440+
struct dpot_command cmd;
441+
442+
if (!desc)
443+
return -EINVAL;
444+
445+
ret = ad5143_validate_chn(desc->extra, chn);
446+
if (ret)
447+
return ret;
448+
449+
/* Enter/Exit the top scale or bottom scale (command #12 or command #13) */
450+
cmd.control = EXTRACT_CMD_BITS(AD51XX_CMD_TOP_SCALE_EXIT);
451+
cmd.address = ad5143_dpot_cmd_addr[chn];
452+
cmd.data = enable;
453+
if (is_top_scale == true)
454+
cmd.data |= EXTRACT_DATA_BITS(AD51XX_CMD_TOP_SCALE_EXIT);
455+
456+
cmd.is_readback = false;
457+
458+
return ad5143_dpot_send_cmd(desc, &cmd);
459+
}
460+
426461
/**
427462
* @brief Write to the digital potentiometer channel.
428463
* @param desc - digipot descriptor.
@@ -726,4 +761,5 @@ const struct dpot_ops ad5143_dpot_ops = {
726761
.dpot_rdac_6db_update = &ad5143_dpot_rdac_6db_update,
727762
.dpot_send_cmd = &ad5143_dpot_send_cmd,
728763
.dpot_remove = &ad5143_dpot_remove,
764+
.dpot_enable_top_bottom_scale = &ad5143_dpot_top_bottom_scale_enable
729765
};

drivers/potentiometer/ad514x/ad5144.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -615,18 +615,19 @@ int ad5144_dpot_chn_read(struct dpot_dev *desc,
615615

616616
return 0;
617617
}
618+
618619
/**
619-
* @brief Enter/Exit the top scale or Bottom scale .
620+
* @brief Enter/Exit the top scale or Bottom scale .
620621
* @param desc - digipot descriptor.
621622
* @param chn - digipot channel.
622-
* @param IsTopScale - boolean flag to indicat top scale or bottom scale.
623-
* @param nEnable - Enter or exit the TS.
623+
* @param is_top_scale - boolean flag to indicate top scale or bottom scale.
624+
* @param enable - Enter or exit the TS.
624625
* @return 0 in case of success, negative error code otherwise.
625626
*/
626627
int ad5144_dpot_top_bottom_scale_enable(struct dpot_dev *desc,
627628
enum dpot_chn_type chn,
628-
bool IsTopScale,
629-
uint8_t nEnable)
629+
bool is_top_scale,
630+
uint8_t enable)
630631
{
631632
int ret;
632633
struct dpot_command cmd;
@@ -638,21 +639,16 @@ int ad5144_dpot_top_bottom_scale_enable(struct dpot_dev *desc,
638639
if (ret)
639640
return ret;
640641

641-
/* Write contents of serial register data to RDAC (command #1) */
642-
cmd.control = 0x9;
642+
/* Enter/Exit the top scale or Bottom scale (command #12 or command #13) */
643+
cmd.control = EXTRACT_CMD_BITS(AD51XX_CMD_TOP_SCALE_EXIT);
643644
cmd.address = ad5144_dpot_cmd_addr[chn];
644-
cmd.data = nEnable;
645-
if (IsTopScale == true) {
646-
cmd.data |= 0x80;
647-
}
645+
cmd.data = enable;
646+
if (is_top_scale == true)
647+
cmd.data |= EXTRACT_DATA_BITS(AD51XX_CMD_TOP_SCALE_EXIT);
648648

649649
cmd.is_readback = false;
650650

651-
ret = ad5144_dpot_send_cmd(desc, &cmd);
652-
if (ret)
653-
return ret;
654-
655-
return 0;
651+
return ad5144_dpot_send_cmd(desc, &cmd);
656652
}
657653

658654
/**

0 commit comments

Comments
 (0)