cmd_sata.c 17 KB

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