1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright (c) 2018 Fuzhou Rockchip Electronics Co., Ltd
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * SPDX-License-Identifier: (GPL-2.0+ OR MIT)
5*4882a593Smuzhiyun */
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun #include <common.h>
8*4882a593Smuzhiyun #include <command.h>
9*4882a593Smuzhiyun #include <dm.h>
10*4882a593Smuzhiyun #include <rksfc.h>
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun static int rksfc_curr_dev;
do_rksfc(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])13*4882a593Smuzhiyun static int do_rksfc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
14*4882a593Smuzhiyun {
15*4882a593Smuzhiyun int ret;
16*4882a593Smuzhiyun u32 dev_type = IF_TYPE_UNKNOWN;
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun if (rksfc_curr_dev == 0)
19*4882a593Smuzhiyun dev_type = IF_TYPE_SPINAND;
20*4882a593Smuzhiyun else if (rksfc_curr_dev == 1)
21*4882a593Smuzhiyun dev_type = IF_TYPE_SPINOR;
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun if (argc == 2) {
24*4882a593Smuzhiyun if (strncmp(argv[1], "scan", 4) == 0) {
25*4882a593Smuzhiyun ret = rksfc_scan_namespace();
26*4882a593Smuzhiyun if (ret)
27*4882a593Smuzhiyun return CMD_RET_FAILURE;
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun return ret;
30*4882a593Smuzhiyun }
31*4882a593Smuzhiyun }
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun if (argc == 3) {
34*4882a593Smuzhiyun if (strncmp(argv[1], "dev", 3) == 0) {
35*4882a593Smuzhiyun if ((int)simple_strtoul(argv[2], NULL, 10) == 0)
36*4882a593Smuzhiyun dev_type = IF_TYPE_SPINAND;
37*4882a593Smuzhiyun else
38*4882a593Smuzhiyun dev_type = IF_TYPE_SPINOR;
39*4882a593Smuzhiyun }
40*4882a593Smuzhiyun }
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun return blk_common_cmd(argc, argv, dev_type, &rksfc_curr_dev);
43*4882a593Smuzhiyun }
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun U_BOOT_CMD(
46*4882a593Smuzhiyun rksfc, 8, 1, do_rksfc,
47*4882a593Smuzhiyun "rockchip sfc sub-system",
48*4882a593Smuzhiyun "scan - scan Sfc devices\n"
49*4882a593Smuzhiyun "rksfc info - show all available Sfc devices\n"
50*4882a593Smuzhiyun "rksfc device [dev] - show or set current Sfc device\n"
51*4882a593Smuzhiyun " dev 0 - spinand\n"
52*4882a593Smuzhiyun " dev 1 - spinor\n"
53*4882a593Smuzhiyun "rksfc part [dev] - print partition table of one or all Sfc devices\n"
54*4882a593Smuzhiyun "rksfc read addr blk# cnt - read `cnt' blocks starting at block\n"
55*4882a593Smuzhiyun " `blk#' to memory address `addr'\n"
56*4882a593Smuzhiyun "rksfc write addr blk# cnt - write `cnt' blocks starting at block\n"
57*4882a593Smuzhiyun " `blk#' from memory address `addr'"
58*4882a593Smuzhiyun );
59