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 * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
8 * Terry Lv <r65388@freescale.com>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 int pata_curr_device = -1;
33 block_dev_desc_t pata_dev_desc[CONFIG_SYS_ATA_MAX_DEVICE];
35 int pata_initialize(void)
40 for (i = 0; i < CONFIG_SYS_ATA_MAX_DEVICE; i++) {
41 memset(&pata_dev_desc[i], 0, sizeof(struct block_dev_desc));
42 pata_dev_desc[i].if_type = IF_TYPE_ATAPI;
43 pata_dev_desc[i].dev = i;
44 pata_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
45 pata_dev_desc[i].type = DEV_TYPE_HARDDISK;
46 pata_dev_desc[i].lba = 0;
47 pata_dev_desc[i].blksz = 512;
48 pata_dev_desc[i].block_read = pata_read;
49 pata_dev_desc[i].block_write = pata_write;
53 if ((pata_dev_desc[i].lba > 0) && (pata_dev_desc[i].blksz > 0))
54 init_part(&pata_dev_desc[i]);
60 block_dev_desc_t *pata_get_dev(int dev)
62 return (dev < CONFIG_SYS_ATA_MAX_DEVICE) ? &pata_dev_desc[dev] : NULL;
65 int do_pata(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
69 if (argc == 2 && strcmp(argv[1], "init") == 0)
70 return pata_initialize();
72 /* If the user has not yet run `pata init`, do it now */
73 if (pata_curr_device == -1)
74 if (pata_initialize())
80 printf("Usage:\n%s\n", cmdtp->usage);
83 if (strncmp(argv[1], "inf", 3) == 0) {
86 for (i = 0; i < CONFIG_SYS_ATA_MAX_DEVICE; ++i) {
87 if (pata_dev_desc[i].type == DEV_TYPE_UNKNOWN)
89 printf("PATA device %d: ", i);
90 dev_print(&pata_dev_desc[i]);
93 } else if (strncmp(argv[1], "dev", 3) == 0) {
94 if ((pata_curr_device < 0) || \
95 (pata_curr_device >= CONFIG_SYS_ATA_MAX_DEVICE)) {
96 puts("\nno PATA devices available\n");
99 printf("\nPATA device %d: ", pata_curr_device);
100 dev_print(&pata_dev_desc[pata_curr_device]);
102 } else if (strncmp(argv[1], "part", 4) == 0) {
105 for (ok = 0, dev = 0; dev < CONFIG_SYS_ATA_MAX_DEVICE; ++dev) {
106 if (pata_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) {
110 print_part(&pata_dev_desc[dev]);
114 puts("\nno PATA devices available\n");
119 printf("Usage:\n%s\n", cmdtp->usage);
122 if (strncmp(argv[1], "dev", 3) == 0) {
123 int dev = (int)simple_strtoul(argv[2], NULL, 10);
125 printf("\nPATA device %d: ", dev);
126 if (dev >= CONFIG_SYS_ATA_MAX_DEVICE) {
127 puts("unknown device\n");
130 dev_print(&pata_dev_desc[dev]);
132 if (pata_dev_desc[dev].type == DEV_TYPE_UNKNOWN)
135 pata_curr_device = dev;
137 puts("... is now current device\n");
140 } else if (strncmp(argv[1], "part", 4) == 0) {
141 int dev = (int)simple_strtoul(argv[2], NULL, 10);
143 if (pata_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) {
144 print_part(&pata_dev_desc[dev]);
146 printf("\nPATA device %d not available\n", dev);
151 printf ("Usage:\n%s\n", cmdtp->usage);
154 default: /* at least 4 args */
155 if (strcmp(argv[1], "read") == 0) {
156 ulong addr = simple_strtoul(argv[2], NULL, 16);
157 ulong cnt = simple_strtoul(argv[4], NULL, 16);
159 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
161 printf("\nPATA read: device %d block # %ld, count %ld ... ",
162 pata_curr_device, blk, cnt);
164 n = pata_read(pata_curr_device, blk, cnt, (u32 *)addr);
166 /* flush cache after read */
167 flush_cache(addr, cnt * pata_dev_desc[pata_curr_device].blksz);
169 printf("%ld blocks read: %s\n",
170 n, (n == cnt) ? "OK" : "ERROR");
171 return (n == cnt) ? 0 : 1;
172 } else if (strcmp(argv[1], "write") == 0) {
173 ulong addr = simple_strtoul(argv[2], NULL, 16);
174 ulong cnt = simple_strtoul(argv[4], NULL, 16);
177 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
179 printf("\nPATA write: device %d block # %ld, count %ld ... ",
180 pata_curr_device, blk, cnt);
182 n = pata_write(pata_curr_device, blk, cnt, (u32 *)addr);
184 printf("%ld blocks written: %s\n",
185 n, (n == cnt) ? "OK" : "ERROR");
186 return (n == cnt) ? 0 : 1;
188 printf("Usage:\n%s\n", cmdtp->usage);
198 "pata - PATA sub system\n",
199 "pata info - show available PATA devices\n"
200 "pata device [dev] - show or set current device\n"
201 "pata part [dev] - print partition table\n"
202 "pata read addr blk# cnt\n"
203 "pata write addr blk# cnt\n");