1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 BayLibre, SAS
4 * Author: Neil Armstrong <narmstrong@baylibre.com>
11 static int do_adc_list(cmd_tbl_t *cmdtp, int flag, int argc,
17 ret = uclass_first_device_err(UCLASS_ADC, &dev);
19 printf("No available ADC device\n");
20 return CMD_RET_FAILURE;
24 printf("- %s\n", dev->name);
26 ret = uclass_next_device(&dev);
28 return CMD_RET_FAILURE;
31 return CMD_RET_SUCCESS;
34 static int do_adc_info(cmd_tbl_t *cmdtp, int flag, int argc,
38 unsigned int data_mask;
44 ret = uclass_get_device_by_name(UCLASS_ADC, argv[1], &dev);
46 printf("Unknown ADC device %s\n", argv[1]);
47 return CMD_RET_FAILURE;
50 printf("ADC Device '%s' :\n", argv[1]);
52 ret = adc_data_mask(dev, &data_mask);
54 printf("data mask: %x\n", data_mask);
56 ret = adc_vdd_value(dev, &vdd);
58 printf("vdd: %duV\n", vdd);
60 ret = adc_vss_value(dev, &vss);
62 printf("vss: %duV\n", vss);
64 return CMD_RET_SUCCESS;
67 static int do_adc_single(cmd_tbl_t *cmdtp, int flag, int argc,
76 ret = adc_channel_single_shot(argv[1], simple_strtol(argv[2], NULL, 0),
79 printf("Error getting single shot for device %s channel %s\n",
81 return CMD_RET_FAILURE;
86 return CMD_RET_SUCCESS;
89 static cmd_tbl_t cmd_adc_sub[] = {
90 U_BOOT_CMD_MKENT(list, 1, 1, do_adc_list, "", ""),
91 U_BOOT_CMD_MKENT(info, 2, 1, do_adc_info, "", ""),
92 U_BOOT_CMD_MKENT(single, 3, 1, do_adc_single, "", ""),
95 static int do_adc(cmd_tbl_t *cmdtp, int flag, int argc,
101 return CMD_RET_USAGE;
103 /* Strip off leading 'adc' command argument */
107 c = find_cmd_tbl(argv[0], &cmd_adc_sub[0], ARRAY_SIZE(cmd_adc_sub));
110 return c->cmd(cmdtp, flag, argc, argv);
112 return CMD_RET_USAGE;
115 static char adc_help_text[] =
116 "list - list ADC devices\n"
117 "adc info <name> - Get ADC device info\n"
118 "adc single <name> <channel> - Get Single data of ADC device channel";
120 U_BOOT_CMD(adc, 4, 1, do_adc, "ADC sub-system", adc_help_text);