blob: d34a56dccce04fb43a961ddd60823d28b66a5e7d [file] [log] [blame]
Dave Liuc7057b52008-03-26 22:49:44 +08001/*
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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Dave Liuc7057b52008-03-26 22:49:44 +080011 */
12
13#include <common.h>
14#include <command.h>
15#include <part.h>
16#include <sata.h>
17
Kim Phillips088f1b12012-10-29 13:34:31 +000018static int sata_curr_device = -1;
Dave Liuc7057b52008-03-26 22:49:44 +080019
Kim Phillips088f1b12012-10-29 13:34:31 +000020static int do_sata(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Dave Liuc7057b52008-03-26 22:49:44 +080021{
22 int rc = 0;
23
Nikita Kiryanovd957c282014-11-21 12:47:24 +020024 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
Gary Bisson8547f452017-01-11 16:51:53 +010031 return (sata_initialize() < 0) ?
32 CMD_RET_FAILURE : CMD_RET_SUCCESS;
Nikita Kiryanovd957c282014-11-21 12:47:24 +020033 }
Mike Frysingercf7e3992009-01-27 16:12:21 -050034
35 /* If the user has not yet run `sata init`, do it now */
Tang Yuantianaa6ab902016-11-21 10:24:20 +080036 if (sata_curr_device == -1) {
37 rc = sata_initialize();
38 if (rc == -1)
Gary Bisson8547f452017-01-11 16:51:53 +010039 return CMD_RET_FAILURE;
Tang Yuantianaa6ab902016-11-21 10:24:20 +080040 sata_curr_device = rc;
41 }
Mike Frysingercf7e3992009-01-27 16:12:21 -050042
Simon Glasse29e71e2017-07-29 11:34:55 -060043 return blk_common_cmd(argc, argv, IF_TYPE_SATA, &sata_curr_device);
Dave Liuc7057b52008-03-26 22:49:44 +080044}
45
46U_BOOT_CMD(
47 sata, 5, 1, do_sata,
Peter Tyser2fb26042009-01-27 18:03:12 -060048 "SATA sub system",
Fabio Estevam85dafbb2013-02-20 14:35:35 +000049 "init - init SATA sub system\n"
Nikita Kiryanovd957c282014-11-21 12:47:24 +020050 "sata stop - disable SATA sub system\n"
Dave Liuc7057b52008-03-26 22:49:44 +080051 "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"
Wolfgang Denka89c33d2009-05-24 17:06:54 +020055 "sata write addr blk# cnt"
56);