cmd_sata.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * Copyright (C) Procsys. All rights reserved.
  3. * Author: Mushtaq Khan <mushtaq_k@procsys.com>
  4. <mushtaqk_921@yahoo.co.in>
  5. *
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. *
  22. * with the reference to libata in kernel 2.4.32
  23. *
  24. */
  25. /*File contains SATA read-write and other utility functions.*/
  26. #include <common.h>
  27. #include <asm/io.h>
  28. #include <pci.h>
  29. #include <command.h>
  30. #include <config.h>
  31. #include <ide.h>
  32. #include <ata.h>
  33. #ifdef CFG_SATA_SUPPORTED
  34. /*For debug prints set macro DEBUG_SATA to 1 */
  35. #define DEBUG_SATA 0
  36. /*Macro for SATA library specific declarations */
  37. #define SATA_DECL
  38. #include <sata.h>
  39. #undef SATA_DECL
  40. static u8 __inline__
  41. sata_inb (unsigned long ioaddr)
  42. {
  43. return inb (ioaddr);
  44. }
  45. static void __inline__
  46. sata_outb (unsigned char val, unsigned long ioaddr)
  47. {
  48. outb (val, ioaddr);
  49. }
  50. static void
  51. output_data (struct sata_ioports *ioaddr, ulong * sect_buf, int words)
  52. {
  53. outsw (ioaddr->data_addr, sect_buf, words << 1);
  54. }
  55. static int
  56. input_data (struct sata_ioports *ioaddr, ulong * sect_buf, int words)
  57. {
  58. insw (ioaddr->data_addr, sect_buf, words << 1);
  59. return 0;
  60. }
  61. static void
  62. sata_cpy (unsigned char *dst, unsigned char *src, unsigned int len)
  63. {
  64. unsigned char *end, *last;
  65. last = dst;
  66. end = src + len - 1;
  67. /* reserve space for '\0' */
  68. if (len < 2)
  69. goto OUT;
  70. /* skip leading white space */
  71. while ((*src) && (src < end) && (*src == ' '))
  72. ++src;
  73. /* copy string, omitting trailing white space */
  74. while ((*src) && (src < end)) {
  75. *dst++ = *src;
  76. if (*src++ != ' ')
  77. last = dst;
  78. }
  79. OUT:
  80. *last = '\0';
  81. }
  82. int
  83. sata_bus_softreset (int num)
  84. {
  85. u8 dev = 0, status = 0, i;
  86. port[num].dev_mask = 0;
  87. for (i = 0; i < CFG_SATA_DEVS_PER_BUS; i++) {
  88. if (!(sata_devchk (&port[num].ioaddr, i))) {
  89. PRINTF ("dev_chk failed for dev#%d\n", i);
  90. } else {
  91. port[num].dev_mask |= (1 << i);
  92. PRINTF ("dev_chk passed for dev#%d\n", i);
  93. }
  94. }
  95. if (!(port[num].dev_mask)) {
  96. printf ("no devices on port%d\n", num);
  97. return 1;
  98. }
  99. dev_select (&port[num].ioaddr, dev);
  100. port[num].ctl_reg = 0x08; /*Default value of control reg */
  101. sata_outb (port[num].ctl_reg, port[num].ioaddr.ctl_addr);
  102. udelay (10);
  103. sata_outb (port[num].ctl_reg | ATA_SRST, port[num].ioaddr.ctl_addr);
  104. udelay (10);
  105. sata_outb (port[num].ctl_reg, port[num].ioaddr.ctl_addr);
  106. /* spec mandates ">= 2ms" before checking status.
  107. * We wait 150ms, because that was the magic delay used for
  108. * ATAPI devices in Hale Landis's ATADRVR, for the period of time
  109. * between when the ATA command register is written, and then
  110. * status is checked. Because waiting for "a while" before
  111. * checking status is fine, post SRST, we perform this magic
  112. * delay here as well.
  113. */
  114. msleep (150);
  115. status = sata_busy_wait (&port[num].ioaddr, ATA_BUSY, 300);
  116. while ((status & ATA_BUSY)) {
  117. msleep (100);
  118. status = sata_busy_wait (&port[num].ioaddr, ATA_BUSY, 3);
  119. }
  120. if (status & ATA_BUSY)
  121. printf ("ata%u is slow to respond,plz be patient\n", port);
  122. while ((status & ATA_BUSY)) {
  123. msleep (100);
  124. status = sata_chk_status (&port[num].ioaddr);
  125. }
  126. if (status & ATA_BUSY) {
  127. printf ("ata%u failed to respond : ", port);
  128. printf ("bus reset failed\n");
  129. return 1;
  130. }
  131. return 0;
  132. }
  133. void
  134. sata_identify (int num, int dev)
  135. {
  136. u8 cmd = 0, status = 0, devno = num * CFG_SATA_DEVS_PER_BUS + dev;
  137. u16 iobuf[ATA_SECT_SIZE];
  138. u64 n_sectors = 0;
  139. u8 mask = 0;
  140. memset (iobuf, 0, sizeof (iobuf));
  141. hd_driveid_t *iop = (hd_driveid_t *) iobuf;
  142. if (dev == 0)
  143. mask = 0x01;
  144. else
  145. mask = 0x02;
  146. if (!(port[num].dev_mask & mask)) {
  147. printf ("dev%d is not present on port#%d\n", dev, num);
  148. return;
  149. }
  150. printf ("port=%d dev=%d\n", num, dev);
  151. dev_select (&port[num].ioaddr, dev);
  152. status = 0;
  153. cmd = ATA_CMD_IDENT; /*Device Identify Command */
  154. sata_outb (cmd, port[num].ioaddr.command_addr);
  155. sata_inb (port[num].ioaddr.altstatus_addr);
  156. udelay (10);
  157. status = sata_busy_wait (&port[num].ioaddr, ATA_BUSY, 1000);
  158. if (status & ATA_ERR) {
  159. printf ("\ndevice not responding\n");
  160. port[num].dev_mask &= ~mask;
  161. return;
  162. }
  163. input_data (&port[num].ioaddr, (ulong *) iobuf, ATA_SECTORWORDS);
  164. PRINTF ("\nata%u: dev %u cfg 49:%04x 82:%04x 83:%04x 84:%04x85:%04x"
  165. "86:%04x" "87:%04x 88:%04x\n", num, dev, iobuf[49],
  166. iobuf[82], iobuf[83], iobuf[84], iobuf[85], iobuf[86],
  167. iobuf[87], iobuf[88]);
  168. /* we require LBA and DMA support (bits 8 & 9 of word 49) */
  169. if (!ata_id_has_dma (iobuf) || !ata_id_has_lba (iobuf)) {
  170. PRINTF ("ata%u: no dma/lba\n", num);
  171. }
  172. ata_dump_id (iobuf);
  173. if (ata_id_has_lba48 (iobuf)) {
  174. n_sectors = ata_id_u64 (iobuf, 100);
  175. } else {
  176. n_sectors = ata_id_u32 (iobuf, 60);
  177. }
  178. PRINTF ("no. of sectors %u\n", ata_id_u64 (iobuf, 100));
  179. PRINTF ("no. of sectors %u\n", ata_id_u32 (iobuf, 60));
  180. if (n_sectors == 0) {
  181. port[num].dev_mask &= ~mask;
  182. return;
  183. }
  184. sata_cpy (sata_dev_desc[devno].revision, iop->fw_rev,
  185. sizeof (sata_dev_desc[devno].revision));
  186. sata_cpy (sata_dev_desc[devno].vendor, iop->model,
  187. sizeof (sata_dev_desc[devno].vendor));
  188. sata_cpy (sata_dev_desc[devno].product, iop->serial_no,
  189. sizeof (sata_dev_desc[devno].product));
  190. strswab (sata_dev_desc[devno].revision);
  191. strswab (sata_dev_desc[devno].vendor);
  192. if ((iop->config & 0x0080) == 0x0080) {
  193. sata_dev_desc[devno].removable = 1;
  194. } else {
  195. sata_dev_desc[devno].removable = 0;
  196. }
  197. sata_dev_desc[devno].lba = iop->lba_capacity;
  198. PRINTF ("lba=0x%x", sata_dev_desc[devno].lba);
  199. #ifdef CONFIG_LBA48
  200. if (iop->command_set_2 & 0x0400) {
  201. sata_dev_desc[devno].lba48 = 1;
  202. lba = (unsigned long long) iop->lba48_capacity[0] |
  203. ((unsigned long long) iop->lba48_capacity[1] << 16) |
  204. ((unsigned long long) iop->lba48_capacity[2] << 32) |
  205. ((unsigned long long) iop->lba48_capacity[3] << 48);
  206. } else {
  207. sata_dev_desc[devno].lba48 = 0;
  208. }
  209. #endif
  210. /* assuming HD */
  211. sata_dev_desc[devno].type = DEV_TYPE_HARDDISK;
  212. sata_dev_desc[devno].blksz = ATA_BLOCKSIZE;
  213. sata_dev_desc[devno].lun = 0; /* just to fill something in... */
  214. }
  215. void
  216. set_Feature_cmd (int num, int dev)
  217. {
  218. u8 mask = 0x00, status = 0;
  219. if (dev == 0)
  220. mask = 0x01;
  221. else
  222. mask = 0x02;
  223. if (!(port[num].dev_mask & mask)) {
  224. PRINTF ("dev%d is not present on port#%d\n", dev, num);
  225. return;
  226. }
  227. dev_select (&port[num].ioaddr, dev);
  228. sata_outb (SETFEATURES_XFER, port[num].ioaddr.feature_addr);
  229. sata_outb (XFER_PIO_4, port[num].ioaddr.nsect_addr);
  230. sata_outb (0, port[num].ioaddr.lbal_addr);
  231. sata_outb (0, port[num].ioaddr.lbam_addr);
  232. sata_outb (0, port[num].ioaddr.lbah_addr);
  233. sata_outb (ATA_DEVICE_OBS, port[num].ioaddr.device_addr);
  234. sata_outb (ATA_CMD_SETF, port[num].ioaddr.command_addr);
  235. udelay (50);
  236. msleep (150);
  237. status = sata_busy_wait (&port[num].ioaddr, ATA_BUSY, 5000);
  238. if ((status & (ATA_STAT_BUSY | ATA_STAT_ERR))) {
  239. printf ("Error : status 0x%02x\n", status);
  240. port[num].dev_mask &= ~mask;
  241. }
  242. }
  243. void
  244. sata_port (struct sata_ioports *ioport)
  245. {
  246. ioport->data_addr = ioport->cmd_addr + ATA_REG_DATA;
  247. ioport->error_addr = ioport->cmd_addr + ATA_REG_ERR;
  248. ioport->feature_addr = ioport->cmd_addr + ATA_REG_FEATURE;
  249. ioport->nsect_addr = ioport->cmd_addr + ATA_REG_NSECT;
  250. ioport->lbal_addr = ioport->cmd_addr + ATA_REG_LBAL;
  251. ioport->lbam_addr = ioport->cmd_addr + ATA_REG_LBAM;
  252. ioport->lbah_addr = ioport->cmd_addr + ATA_REG_LBAH;
  253. ioport->device_addr = ioport->cmd_addr + ATA_REG_DEVICE;
  254. ioport->status_addr = ioport->cmd_addr + ATA_REG_STATUS;
  255. ioport->command_addr = ioport->cmd_addr + ATA_REG_CMD;
  256. }
  257. int
  258. sata_devchk (struct sata_ioports *ioaddr, int dev)
  259. {
  260. u8 nsect, lbal;
  261. dev_select (ioaddr, dev);
  262. sata_outb (0x55, ioaddr->nsect_addr);
  263. sata_outb (0xaa, ioaddr->lbal_addr);
  264. sata_outb (0xaa, ioaddr->nsect_addr);
  265. sata_outb (0x55, ioaddr->lbal_addr);
  266. sata_outb (0x55, ioaddr->nsect_addr);
  267. sata_outb (0xaa, ioaddr->lbal_addr);
  268. nsect = sata_inb (ioaddr->nsect_addr);
  269. lbal = sata_inb (ioaddr->lbal_addr);
  270. if ((nsect == 0x55) && (lbal == 0xaa))
  271. return 1; /* we found a device */
  272. else
  273. return 0; /* nothing found */
  274. }
  275. void
  276. dev_select (struct sata_ioports *ioaddr, int dev)
  277. {
  278. u8 tmp = 0;
  279. if (dev == 0)
  280. tmp = ATA_DEVICE_OBS;
  281. else
  282. tmp = ATA_DEVICE_OBS | ATA_DEV1;
  283. sata_outb (tmp, ioaddr->device_addr);
  284. sata_inb (ioaddr->altstatus_addr);
  285. udelay (5);
  286. }
  287. u8
  288. sata_busy_wait (struct sata_ioports *ioaddr, int bits, unsigned int max)
  289. {
  290. u8 status;
  291. do {
  292. udelay (1000);
  293. status = sata_chk_status (ioaddr);
  294. max--;
  295. } while ((status & bits) && (max > 0));
  296. return status;
  297. }
  298. u8
  299. sata_chk_status (struct sata_ioports * ioaddr)
  300. {
  301. return sata_inb (ioaddr->status_addr);
  302. }
  303. void
  304. msleep (int count)
  305. {
  306. int i;
  307. for (i = 0; i < count; i++)
  308. udelay (1000);
  309. }
  310. ulong
  311. sata_read (int device, lbaint_t blknr, ulong blkcnt, ulong * buffer)
  312. {
  313. ulong n = 0;
  314. u8 dev = 0, num = 0, mask = 0, status = 0;
  315. #ifdef CONFIG_LBA48
  316. unsigned char lba48 = 0;
  317. if (blknr & 0x0000fffff0000000) {
  318. if (!sata_dev_desc[devno].lba48) {
  319. printf ("Drive doesn't support 48-bit addressing\n");
  320. return 0;
  321. }
  322. /* more than 28 bits used, use 48bit mode */
  323. lba48 = 1;
  324. }
  325. #endif
  326. /*Port Number */
  327. num = device / CFG_SATA_DEVS_PER_BUS;
  328. /*dev on the port */
  329. if (device >= CFG_SATA_DEVS_PER_BUS)
  330. dev = device - CFG_SATA_DEVS_PER_BUS;
  331. else
  332. dev = device;
  333. if (dev == 0)
  334. mask = 0x01;
  335. else
  336. mask = 0x02;
  337. if (!(port[num].dev_mask & mask)) {
  338. printf ("dev%d is not present on port#%d\n", dev, num);
  339. return 0;
  340. }
  341. /* Select device */
  342. dev_select (&port[num].ioaddr, dev);
  343. status = sata_busy_wait (&port[num].ioaddr, ATA_BUSY, 500);
  344. if (status & ATA_BUSY) {
  345. printf ("ata%u failed to respond\n", port[num].port_no);
  346. return n;
  347. }
  348. while (blkcnt-- > 0) {
  349. status = sata_busy_wait (&port[num].ioaddr, ATA_BUSY, 500);
  350. if (status & ATA_BUSY) {
  351. printf ("ata%u failed to respond\n", 0);
  352. return n;
  353. }
  354. #ifdef CONFIG_LBA48
  355. if (lba48) {
  356. /* write high bits */
  357. sata_outb (0, port[num].ioaddr.nsect_addr);
  358. sata_outb ((blknr >> 24) & 0xFF,
  359. port[num].ioaddr.lbal_addr);
  360. sata_outb ((blknr >> 32) & 0xFF,
  361. port[num].ioaddr.lbam_addr);
  362. sata_outb ((blknr >> 40) & 0xFF,
  363. port[num].ioaddr.lbah_addr);
  364. }
  365. #endif
  366. sata_outb (1, port[num].ioaddr.nsect_addr);
  367. sata_outb (((blknr) >> 0) & 0xFF,
  368. port[num].ioaddr.lbal_addr);
  369. sata_outb ((blknr >> 8) & 0xFF, port[num].ioaddr.lbam_addr);
  370. sata_outb ((blknr >> 16) & 0xFF, port[num].ioaddr.lbah_addr);
  371. #ifdef CONFIG_LBA48
  372. if (lba48) {
  373. sata_outb (ATA_LBA, port[num].ioaddr.device_addr);
  374. sata_outb (ATA_CMD_READ_EXT,
  375. port[num].ioaddr.command_addr);
  376. } else
  377. #endif
  378. {
  379. sata_outb (ATA_LBA | ((blknr >> 24) & 0xF),
  380. port[num].ioaddr.device_addr);
  381. sata_outb (ATA_CMD_READ,
  382. port[num].ioaddr.command_addr);
  383. }
  384. msleep (50);
  385. /*may take up to 4 sec */
  386. status = sata_busy_wait (&port[num].ioaddr, ATA_BUSY, 4000);
  387. if ((status & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR))
  388. != ATA_STAT_DRQ) {
  389. u8 err = 0;
  390. printf ("Error no DRQ dev %d blk %ld: sts 0x%02x\n",
  391. device, (ulong) blknr, status);
  392. err = sata_inb (port[num].ioaddr.error_addr);
  393. printf ("Error reg = 0x%x\n", err);
  394. return (n);
  395. }
  396. input_data (&port[num].ioaddr, buffer, ATA_SECTORWORDS);
  397. sata_inb (port[num].ioaddr.altstatus_addr);
  398. udelay (50);
  399. ++n;
  400. ++blknr;
  401. buffer += ATA_SECTORWORDS;
  402. }
  403. return n;
  404. }
  405. ulong
  406. sata_write (int device, lbaint_t blknr, ulong blkcnt, ulong * buffer)
  407. {
  408. ulong n = 0;
  409. unsigned char status = 0, num = 0, dev = 0, mask = 0;
  410. #ifdef CONFIG_LBA48
  411. unsigned char lba48 = 0;
  412. if (blknr & 0x0000fffff0000000) {
  413. if (!sata_dev_desc[devno].lba48) {
  414. printf ("Drive doesn't support 48-bit addressing\n");
  415. return 0;
  416. }
  417. /* more than 28 bits used, use 48bit mode */
  418. lba48 = 1;
  419. }
  420. #endif
  421. /*Port Number */
  422. num = device / CFG_SATA_DEVS_PER_BUS;
  423. /*dev on the Port */
  424. if (device >= CFG_SATA_DEVS_PER_BUS)
  425. dev = device - CFG_SATA_DEVS_PER_BUS;
  426. else
  427. dev = device;
  428. if (dev == 0)
  429. mask = 0x01;
  430. else
  431. mask = 0x02;
  432. /* Select device */
  433. dev_select (&port[num].ioaddr, dev);
  434. status = sata_busy_wait (&port[num].ioaddr, ATA_BUSY, 500);
  435. if (status & ATA_BUSY) {
  436. printf ("ata%u failed to respond\n", port[num].port_no);
  437. return n;
  438. }
  439. while (blkcnt-- > 0) {
  440. status = sata_busy_wait (&port[num].ioaddr, ATA_BUSY, 500);
  441. if (status & ATA_BUSY) {
  442. printf ("ata%u failed to respond\n",
  443. port[num].port_no);
  444. return n;
  445. }
  446. #ifdef CONFIG_LBA48
  447. if (lba48) {
  448. /* write high bits */
  449. sata_outb (0, port[num].ioaddr.nsect_addr);
  450. sata_outb ((blknr >> 24) & 0xFF,
  451. port[num].ioaddr.lbal_addr);
  452. sata_outb ((blknr >> 32) & 0xFF,
  453. port[num].ioaddr.lbam_addr);
  454. sata_outb ((blknr >> 40) & 0xFF,
  455. port[num].ioaddr.lbah_addr);
  456. }
  457. #endif
  458. sata_outb (1, port[num].ioaddr.nsect_addr);
  459. sata_outb ((blknr >> 0) & 0xFF, port[num].ioaddr.lbal_addr);
  460. sata_outb ((blknr >> 8) & 0xFF, port[num].ioaddr.lbam_addr);
  461. sata_outb ((blknr >> 16) & 0xFF, port[num].ioaddr.lbah_addr);
  462. #ifdef CONFIG_LBA48
  463. if (lba48) {
  464. sata_outb (ATA_LBA, port[num].ioaddr.device_addr);
  465. sata_outb (ATA_CMD_WRITE_EXT,
  466. port[num].ioaddr.command_addr);
  467. } else
  468. #endif
  469. {
  470. sata_outb (ATA_LBA | ((blknr >> 24) & 0xF),
  471. port[num].ioaddr.device_addr);
  472. sata_outb (ATA_CMD_WRITE,
  473. port[num].ioaddr.command_addr);
  474. }
  475. msleep (50);
  476. /*may take up to 4 sec */
  477. status = sata_busy_wait (&port[num].ioaddr, ATA_BUSY, 4000);
  478. if ((status & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR))
  479. != ATA_STAT_DRQ) {
  480. printf ("Error no DRQ dev %d blk %ld: sts 0x%02x\n",
  481. device, (ulong) blknr, status);
  482. return (n);
  483. }
  484. output_data (&port[num].ioaddr, buffer, ATA_SECTORWORDS);
  485. sata_inb (port[num].ioaddr.altstatus_addr);
  486. udelay (50);
  487. ++n;
  488. ++blknr;
  489. buffer += ATA_SECTORWORDS;
  490. }
  491. return n;
  492. }
  493. block_dev_desc_t *sata_get_dev (int dev);
  494. block_dev_desc_t *
  495. sata_get_dev (int dev)
  496. {
  497. return ((block_dev_desc_t *) & sata_dev_desc[dev]);
  498. }
  499. int
  500. do_sata (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  501. {
  502. switch (argc) {
  503. case 0:
  504. case 1:
  505. printf ("Usage:\n%s\n", cmdtp->usage);
  506. return 1;
  507. case 2:
  508. if (strncmp (argv[1], "init", 4) == 0) {
  509. int rcode = 0;
  510. rcode = init_sata ();
  511. if (rcode)
  512. printf ("Sata initialization Failed\n");
  513. return rcode;
  514. } else if (strncmp (argv[1], "inf", 3) == 0) {
  515. int i;
  516. putc ('\n');
  517. for (i = 0; i < CFG_SATA_MAXDEVICES; ++i) {
  518. /*List only known devices */
  519. if (sata_dev_desc[i].type ==
  520. DEV_TYPE_UNKNOWN)
  521. continue;
  522. printf ("sata dev %d: ", i);
  523. dev_print (&sata_dev_desc[i]);
  524. }
  525. return 0;
  526. }
  527. printf ("Usage:\n%s\n", cmdtp->usage);
  528. return 1;
  529. case 3:
  530. if (strcmp (argv[1], "dev") == 0) {
  531. int dev = (int) simple_strtoul (argv[2], NULL, 10);
  532. if (dev >= CFG_SATA_MAXDEVICES) {
  533. printf ("\nSata dev %d not available\n",
  534. dev);
  535. return 1;
  536. }
  537. printf ("\nSATA dev %d: ", dev);
  538. dev_print (&sata_dev_desc[dev]);
  539. if (sata_dev_desc[dev].type == DEV_TYPE_UNKNOWN)
  540. return 1;
  541. curr_dev = dev;
  542. return 0;
  543. } else if (strcmp (argv[1], "part") == 0) {
  544. int dev = (int) simple_strtoul (argv[2], NULL, 10);
  545. if (dev >= CFG_SATA_MAXDEVICES) {
  546. printf ("\nSata dev %d not available\n",
  547. dev);
  548. return 1;
  549. }
  550. PRINTF ("\nSATA dev %d: ", dev);
  551. if (sata_dev_desc[dev].part_type !=
  552. PART_TYPE_UNKNOWN) {
  553. print_part (&sata_dev_desc[dev]);
  554. } else {
  555. printf ("\nSata dev %d partition type "
  556. "unknown\n", dev);
  557. return 1;
  558. }
  559. return 0;
  560. }
  561. printf ("Usage:\n%s\n", cmdtp->usage);
  562. return 1;
  563. default:
  564. if (argc < 5) {
  565. printf ("Usage:\n%s\n", cmdtp->usage);
  566. return 1;
  567. }
  568. if (strcmp (argv[1], "read") == 0) {
  569. ulong addr = simple_strtoul (argv[2], NULL, 16);
  570. ulong cnt = simple_strtoul (argv[4], NULL, 16);
  571. ulong n;
  572. lbaint_t blk = simple_strtoul (argv[3], NULL, 16);
  573. memset ((int *) addr, 0, cnt * 512);
  574. printf ("\nSATA read: dev %d blk # %ld,"
  575. "count %ld ... ", curr_dev, blk, cnt);
  576. n = sata_read (curr_dev, blk, cnt, (ulong *) addr);
  577. /* flush cache after read */
  578. flush_cache (addr, cnt * 512);
  579. printf ("%ld blocks read: %s\n", n,
  580. (n == cnt) ? "OK" : "ERR");
  581. if (n == cnt)
  582. return 1;
  583. else
  584. return 0;
  585. } else if (strcmp (argv[1], "write") == 0) {
  586. ulong addr = simple_strtoul (argv[2], NULL, 16);
  587. ulong cnt = simple_strtoul (argv[4], NULL, 16);
  588. ulong n;
  589. lbaint_t blk = simple_strtoul (argv[3], NULL, 16);
  590. printf ("\nSata write: dev %d blk # %ld,"
  591. "count %ld ... ", curr_dev, blk, cnt);
  592. n = sata_write (curr_dev, blk, cnt, (ulong *) addr);
  593. printf ("%ld blocks written: %s\n", n,
  594. (n == cnt) ? "OK" : "ERR");
  595. if (n == cnt)
  596. return 1;
  597. else
  598. return 0;
  599. } else {
  600. printf ("Usage:\n%s\n", cmdtp->usage);
  601. return 1;
  602. }
  603. } /*End OF SWITCH */
  604. }
  605. U_BOOT_CMD (sata, 5, 1, do_sata,
  606. "sata init\n"
  607. "sata info\n"
  608. "sata part device\n"
  609. "sata dev device\n"
  610. "sata read addr blk# cnt\n"
  611. "sata write addr blk# cnt\n", "cmd for init,rw and dev-info\n");
  612. #endif