1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2017 Marvell International Ltd.
4 *
5 * SPDX-License-Identifier: GPL-2.0
6 */
7
8 #include <command.h>
9 #include <console.h>
10 #include <dm.h>
11 #include <fdtdec.h>
12 #include <dm/device-internal.h>
13 #include <mvebu/comphy.h>
14
mvebu_comphy_rx_training_cmd(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])15 int mvebu_comphy_rx_training_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
16 char * const argv[])
17 {
18 struct udevice *dev;
19 struct uclass *uc;
20 int ret, cp_index, comphy_index, i = 0;
21
22 if (argc != 3) {
23 printf("missing arguments\n");
24 return CMD_RET_USAGE;
25 }
26
27 cp_index = hextoul(argv[1], NULL);
28 comphy_index = hextoul(argv[2], NULL);
29
30 ret = uclass_get(UCLASS_MISC, &uc);
31 if (ret) {
32 printf("Couldn't find UCLASS_MISC\n");
33 return ret;
34 }
35
36 uclass_foreach_dev(dev, uc) {
37 if (!(memcmp(dev->name, "comphy", 5))) {
38 if (i == cp_index) {
39 comphy_rx_training(dev, comphy_index);
40 return 0;
41 }
42
43 i++;
44 }
45 }
46
47 printf("Coudn't find comphy %d\n", cp_index);
48
49 return 0;
50 }
51
52 U_BOOT_CMD(
53 mvebu_comphy_rx_training, 3, 0, mvebu_comphy_rx_training_cmd,
54 "mvebu_comphy_rx_training <cp id> <comphy id>\n",
55 "\n\tRun COMPHY RX training sequence, the user must state CP index (0/1) and comphy ID (0/5)"
56 );
57