Skip to content

Commit ce5f1d2

Browse files
committed
drivers:potentiometer:ad514x: Add support for top/bottom scale enter/exit on ad5141, ad5142 and ad5143
Signed-off-by: Anush Shetty <[email protected]>
1 parent e6569fe commit ce5f1d2

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

drivers/potentiometer/ad514x/ad5141.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,46 @@ 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 IsTopScale - boolean flag to indicate top scale or bottom scale.
614+
* @param nEnable - 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 IsTopScale,
620+
uint8_t nEnable)
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 = 0x9;
634+
cmd.address = ad5141_dpot_cmd_addr[chn];
635+
cmd.data = nEnable;
636+
if (IsTopScale == true) {
637+
cmd.data |= 0x80;
638+
}
639+
640+
cmd.is_readback = false;
641+
642+
ret = ad5141_dpot_send_cmd(desc, &cmd);
643+
if (ret)
644+
return ret;
645+
646+
return 0;
647+
}
648+
609649
/**
610650
* @brief Write to the digital potentiometer channel.
611651
* @param desc - digipot descriptor.
@@ -925,4 +965,5 @@ const struct dpot_ops ad5141_dpot_ops = {
925965
.dpot_rdac_6db_update = &ad5141_dpot_rdac_6db_update,
926966
// .dpot_send_cmd = &ad5141_dpot_send_cmd,
927967
.dpot_remove = &ad5141_dpot_remove,
968+
.dpot_enable_top_bottom_scale = &ad5141_dpot_top_bottom_scale_enable
928969
};

drivers/potentiometer/ad514x/ad5142.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,46 @@ 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 IsTopScale - boolean flag to indicate top scale or bottom scale.
567+
* @param nEnable - 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 IsTopScale,
573+
uint8_t nEnable)
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 = 0x9;
587+
cmd.address = ad5142_dpot_cmd_addr[chn];
588+
cmd.data = nEnable;
589+
if (IsTopScale == true) {
590+
cmd.data |= 0x80;
591+
}
592+
593+
cmd.is_readback = false;
594+
595+
ret = ad5142_dpot_send_cmd(desc, &cmd);
596+
if (ret)
597+
return ret;
598+
599+
return 0;
600+
}
601+
562602
/**
563603
* @brief Write to the digital potentiometer channel.
564604
* @param desc - digipot descriptor.
@@ -877,4 +917,5 @@ const struct dpot_ops ad5142_dpot_ops = {
877917
.dpot_rdac_6db_update = &ad5142_dpot_rdac_6db_update,
878918
//.dpot_send_cmd = &ad5142_dpot_send_cmd,
879919
.dpot_remove = &ad5142_dpot_remove,
920+
.dpot_enable_top_bottom_scale = &ad5142_dpot_top_bottom_scale_enable
880921
};

drivers/potentiometer/ad514x/ad5143.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,46 @@ 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 IsTopScale - boolean flag to indicate top scale or bottom scale.
431+
* @param nEnable - 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 IsTopScale,
437+
uint8_t nEnable)
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 = 0x9;
451+
cmd.address = ad5143_dpot_cmd_addr[chn];
452+
cmd.data = nEnable;
453+
if (IsTopScale == true) {
454+
cmd.data |= 0x80;
455+
}
456+
457+
cmd.is_readback = false;
458+
459+
ret = ad5143_dpot_send_cmd(desc, &cmd);
460+
if (ret)
461+
return ret;
462+
463+
return 0;
464+
}
465+
426466
/**
427467
* @brief Write to the digital potentiometer channel.
428468
* @param desc - digipot descriptor.
@@ -726,4 +766,5 @@ const struct dpot_ops ad5143_dpot_ops = {
726766
.dpot_rdac_6db_update = &ad5143_dpot_rdac_6db_update,
727767
.dpot_send_cmd = &ad5143_dpot_send_cmd,
728768
.dpot_remove = &ad5143_dpot_remove,
769+
.dpot_enable_top_bottom_scale = &ad5143_dpot_top_bottom_scale_enable
729770
};

0 commit comments

Comments
 (0)