Dave Liu | c7057b5 | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
Dave Liu | c7057b5 | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | #include <command.h> |
| 15 | #include <part.h> |
| 16 | #include <sata.h> |
| 17 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 18 | static int sata_curr_device = -1; |
Dave Liu | c7057b5 | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 19 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 20 | static int do_sata(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Dave Liu | c7057b5 | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 21 | { |
| 22 | int rc = 0; |
| 23 | |
Nikita Kiryanov | d957c28 | 2014-11-21 12:47:24 +0200 | [diff] [blame] | 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 | |
Gary Bisson | 8547f45 | 2017-01-11 16:51:53 +0100 | [diff] [blame] | 31 | return (sata_initialize() < 0) ? |
| 32 | CMD_RET_FAILURE : CMD_RET_SUCCESS; |
Nikita Kiryanov | d957c28 | 2014-11-21 12:47:24 +0200 | [diff] [blame] | 33 | } |
Mike Frysinger | cf7e399 | 2009-01-27 16:12:21 -0500 | [diff] [blame] | 34 | |
| 35 | /* If the user has not yet run `sata init`, do it now */ |
Tang Yuantian | aa6ab90 | 2016-11-21 10:24:20 +0800 | [diff] [blame] | 36 | if (sata_curr_device == -1) { |
| 37 | rc = sata_initialize(); |
| 38 | if (rc == -1) |
Gary Bisson | 8547f45 | 2017-01-11 16:51:53 +0100 | [diff] [blame] | 39 | return CMD_RET_FAILURE; |
Tang Yuantian | aa6ab90 | 2016-11-21 10:24:20 +0800 | [diff] [blame] | 40 | sata_curr_device = rc; |
| 41 | } |
Mike Frysinger | cf7e399 | 2009-01-27 16:12:21 -0500 | [diff] [blame] | 42 | |
Simon Glass | e29e71e | 2017-07-29 11:34:55 -0600 | [diff] [blame^] | 43 | return blk_common_cmd(argc, argv, IF_TYPE_SATA, &sata_curr_device); |
Dave Liu | c7057b5 | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | U_BOOT_CMD( |
| 47 | sata, 5, 1, do_sata, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 48 | "SATA sub system", |
Fabio Estevam | 85dafbb | 2013-02-20 14:35:35 +0000 | [diff] [blame] | 49 | "init - init SATA sub system\n" |
Nikita Kiryanov | d957c28 | 2014-11-21 12:47:24 +0200 | [diff] [blame] | 50 | "sata stop - disable SATA sub system\n" |
Dave Liu | c7057b5 | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 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" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 55 | "sata write addr blk# cnt" |
| 56 | ); |