]> git.sur5r.net Git - u-boot/commitdiff
cmd: add ADC cli commands
authorNeil Armstrong <narmstrong@baylibre.com>
Fri, 27 Apr 2018 13:17:57 +0000 (15:17 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 8 May 2018 22:50:23 +0000 (18:50 -0400)
Add an 'adc' cli command to get information from adc devices and to read
"single shot" data.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
cmd/Kconfig
cmd/Makefile
cmd/adc.c [new file with mode: 0644]

index ae49b8247156cdcfe5a5d6e19e1748515696ec88..eb14e08f773d93cbec9ef5812544d22bc7361649 100644 (file)
@@ -601,6 +601,14 @@ config CMD_ARMFLASH
        help
          ARM Ltd reference designs flash partition access
 
+config CMD_ADC
+       bool "adc - Access Analog to Digital Converters info and data"
+       select ADC
+       select DM_REGULATOR
+       help
+         Shows ADC device info and permit printing one-shot analog converted
+         data from a named Analog to Digital Converter.
+
 config CMD_CLK
        bool "clk - Show clock frequencies"
        help
index d7349023a4408665e1c557098714d6a42023f0d2..0d7322ee0a49af0223b9b2f50f4e10311535e859 100644 (file)
@@ -12,6 +12,7 @@ obj-y += version.o
 
 # command
 obj-$(CONFIG_CMD_AES) += aes.o
+obj-$(CONFIG_CMD_ADC) += adc.o
 obj-$(CONFIG_CMD_ARMFLASH) += armflash.o
 obj-y += blk_common.o
 obj-$(CONFIG_SOURCE) += source.o
diff --git a/cmd/adc.c b/cmd/adc.c
new file mode 100644 (file)
index 0000000..c8857ed
--- /dev/null
+++ b/cmd/adc.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 BayLibre, SAS
+ * Author: Neil Armstrong <narmstrong@baylibre.com>
+ */
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <adc.h>
+
+static int do_adc_list(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+       struct udevice *dev;
+       int ret;
+
+       ret = uclass_first_device_err(UCLASS_ADC, &dev);
+       if (ret) {
+               printf("No available ADC device\n");
+               return CMD_RET_FAILURE;
+       }
+
+       do {
+               printf("- %s\n", dev->name);
+
+               ret = uclass_next_device(&dev);
+               if (ret)
+                       return CMD_RET_FAILURE;
+       } while (dev);
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_adc_info(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+       struct udevice *dev;
+       unsigned int data_mask;
+       int ret, vss, vdd;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       ret = uclass_get_device_by_name(UCLASS_ADC, argv[1], &dev);
+       if (ret) {
+               printf("Unknown ADC device %s\n", argv[1]);
+               return CMD_RET_FAILURE;
+       }
+
+       printf("ADC Device '%s' :\n", argv[1]);
+
+       ret = adc_data_mask(dev, &data_mask);
+       if (!ret)
+               printf("data mask: %x\n", data_mask);
+
+       ret = adc_vdd_value(dev, &vdd);
+       if (!ret)
+               printf("vdd: %duV\n", vdd);
+
+       ret = adc_vss_value(dev, &vss);
+       if (!ret)
+               printf("vss: %duV\n", vss);
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_adc_single(cmd_tbl_t *cmdtp, int flag, int argc,
+                        char *const argv[])
+{
+       unsigned int data;
+       int ret;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       ret = adc_channel_single_shot(argv[1], simple_strtol(argv[2], NULL, 0),
+                                     &data);
+       if (ret) {
+               printf("Error getting single shot for device %s channel %s\n",
+                      argv[1], argv[2]);
+               return CMD_RET_FAILURE;
+       }
+
+       printf("%u\n", data);
+
+       return CMD_RET_SUCCESS;
+}
+
+static cmd_tbl_t cmd_adc_sub[] = {
+       U_BOOT_CMD_MKENT(list, 1, 1, do_adc_list, "", ""),
+       U_BOOT_CMD_MKENT(info, 2, 1, do_adc_info, "", ""),
+       U_BOOT_CMD_MKENT(single, 3, 1, do_adc_single, "", ""),
+};
+
+static int do_adc(cmd_tbl_t *cmdtp, int flag, int argc,
+                 char *const argv[])
+{
+       cmd_tbl_t *c;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       /* Strip off leading 'adc' command argument */
+       argc--;
+       argv++;
+
+       c = find_cmd_tbl(argv[0], &cmd_adc_sub[0], ARRAY_SIZE(cmd_adc_sub));
+
+       if (c)
+               return c->cmd(cmdtp, flag, argc, argv);
+       else
+               return CMD_RET_USAGE;
+}
+
+static char adc_help_text[] =
+       "list - list ADC devices\n"
+       "adc info <name> - Get ADC device info\n"
+       "adc single <name> <channel> - Get Single data of ADC device channel";
+
+U_BOOT_CMD(adc, 4, 1, do_adc, "ADC sub-system", adc_help_text);