dm: sata: Adjust the 'sata' command to use blk_common_cmd()
[oweals/u-boot.git] / cmd / sata.c
1 /*
2  * Copyright (C) 2000-2005, DENX Software Engineering
3  *              Wolfgang Denk <wd@denx.de>
4  * Copyright (C) Procsys. All rights reserved.
5  *              Mushtaq Khan <mushtaq_k@procsys.com>
6  *                      <mushtaqk_921@yahoo.co.in>
7  * Copyright (C) 2008 Freescale Semiconductor, Inc.
8  *              Dave Liu <daveliu@freescale.com>
9  *
10  * SPDX-License-Identifier:     GPL-2.0+
11  */
12
13 #include <common.h>
14 #include <command.h>
15 #include <part.h>
16 #include <sata.h>
17
18 static int sata_curr_device = -1;
19
20 static int do_sata(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
21 {
22         int rc = 0;
23
24         if (argc == 2 && strcmp(argv[1], "stop") == 0)
25                 return sata_stop();
26
27         if (argc == 2 && strcmp(argv[1], "init") == 0) {
28                 if (sata_curr_device != -1)
29                         sata_stop();
30
31                 return (sata_initialize() < 0) ?
32                         CMD_RET_FAILURE : CMD_RET_SUCCESS;
33         }
34
35         /* If the user has not yet run `sata init`, do it now */
36         if (sata_curr_device == -1) {
37                 rc = sata_initialize();
38                 if (rc == -1)
39                         return CMD_RET_FAILURE;
40                 sata_curr_device = rc;
41         }
42
43         return blk_common_cmd(argc, argv, IF_TYPE_SATA, &sata_curr_device);
44 }
45
46 U_BOOT_CMD(
47         sata, 5, 1, do_sata,
48         "SATA sub system",
49         "init - init SATA sub system\n"
50         "sata stop - disable SATA sub system\n"
51         "sata info - show available SATA devices\n"
52         "sata device [dev] - show or set current device\n"
53         "sata part [dev] - print partition table\n"
54         "sata read addr blk# cnt\n"
55         "sata write addr blk# cnt"
56 );