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