ide.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  1. /*
  2. * (C) Copyright 2000-2011
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <ata.h>
  9. #include <ide.h>
  10. #include <watchdog.h>
  11. #include <asm/io.h>
  12. #ifdef __PPC__
  13. # define EIEIO __asm__ volatile ("eieio")
  14. # define SYNC __asm__ volatile ("sync")
  15. #else
  16. # define EIEIO /* nothing */
  17. # define SYNC /* nothing */
  18. #endif
  19. /* Current offset for IDE0 / IDE1 bus access */
  20. ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS] = {
  21. #if defined(CONFIG_SYS_ATA_IDE0_OFFSET)
  22. CONFIG_SYS_ATA_IDE0_OFFSET,
  23. #endif
  24. #if defined(CONFIG_SYS_ATA_IDE1_OFFSET) && (CONFIG_SYS_IDE_MAXBUS > 1)
  25. CONFIG_SYS_ATA_IDE1_OFFSET,
  26. #endif
  27. };
  28. static int ide_bus_ok[CONFIG_SYS_IDE_MAXBUS];
  29. struct blk_desc ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
  30. #define IDE_TIME_OUT 2000 /* 2 sec timeout */
  31. #define ATAPI_TIME_OUT 7000 /* 7 sec timeout (5 sec seems to work...) */
  32. #define IDE_SPIN_UP_TIME_OUT 5000 /* 5 sec spin-up timeout */
  33. #ifndef CONFIG_SYS_ATA_PORT_ADDR
  34. #define CONFIG_SYS_ATA_PORT_ADDR(port) (port)
  35. #endif
  36. #ifndef CONFIG_IDE_LED /* define LED macros, they are not used anyways */
  37. # define DEVICE_LED(x) 0
  38. # define LED_IDE1 1
  39. # define LED_IDE2 2
  40. #endif
  41. #ifdef CONFIG_IDE_RESET
  42. extern void ide_set_reset(int idereset);
  43. static void ide_reset(void)
  44. {
  45. int i;
  46. for (i = 0; i < CONFIG_SYS_IDE_MAXBUS; ++i)
  47. ide_bus_ok[i] = 0;
  48. for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i)
  49. ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
  50. ide_set_reset(1); /* assert reset */
  51. /* the reset signal shall be asserted for et least 25 us */
  52. udelay(25);
  53. WATCHDOG_RESET();
  54. /* de-assert RESET signal */
  55. ide_set_reset(0);
  56. /* wait 250 ms */
  57. for (i = 0; i < 250; ++i)
  58. udelay(1000);
  59. }
  60. #else
  61. #define ide_reset() /* dummy */
  62. #endif /* CONFIG_IDE_RESET */
  63. /*
  64. * Wait until Busy bit is off, or timeout (in ms)
  65. * Return last status
  66. */
  67. static uchar ide_wait(int dev, ulong t)
  68. {
  69. ulong delay = 10 * t; /* poll every 100 us */
  70. uchar c;
  71. while ((c = ide_inb(dev, ATA_STATUS)) & ATA_STAT_BUSY) {
  72. udelay(100);
  73. if (delay-- == 0)
  74. break;
  75. }
  76. return c;
  77. }
  78. /*
  79. * copy src to dest, skipping leading and trailing blanks and null
  80. * terminate the string
  81. * "len" is the size of available memory including the terminating '\0'
  82. */
  83. static void ident_cpy(unsigned char *dst, unsigned char *src,
  84. unsigned int len)
  85. {
  86. unsigned char *end, *last;
  87. last = dst;
  88. end = src + len - 1;
  89. /* reserve space for '\0' */
  90. if (len < 2)
  91. goto OUT;
  92. /* skip leading white space */
  93. while ((*src) && (src < end) && (*src == ' '))
  94. ++src;
  95. /* copy string, omitting trailing white space */
  96. while ((*src) && (src < end)) {
  97. *dst++ = *src;
  98. if (*src++ != ' ')
  99. last = dst;
  100. }
  101. OUT:
  102. *last = '\0';
  103. }
  104. #ifdef CONFIG_ATAPI
  105. /****************************************************************************
  106. * ATAPI Support
  107. */
  108. #if defined(CONFIG_IDE_SWAP_IO)
  109. /* since ATAPI may use commands with not 4 bytes alligned length
  110. * we have our own transfer functions, 2 bytes alligned */
  111. __weak void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
  112. {
  113. ushort *dbuf;
  114. volatile ushort *pbuf;
  115. pbuf = (ushort *)(ATA_CURR_BASE(dev) + ATA_DATA_REG);
  116. dbuf = (ushort *)sect_buf;
  117. debug("in output data shorts base for read is %lx\n",
  118. (unsigned long) pbuf);
  119. while (shorts--) {
  120. EIEIO;
  121. *pbuf = *dbuf++;
  122. }
  123. }
  124. __weak void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
  125. {
  126. ushort *dbuf;
  127. volatile ushort *pbuf;
  128. pbuf = (ushort *)(ATA_CURR_BASE(dev) + ATA_DATA_REG);
  129. dbuf = (ushort *)sect_buf;
  130. debug("in input data shorts base for read is %lx\n",
  131. (unsigned long) pbuf);
  132. while (shorts--) {
  133. EIEIO;
  134. *dbuf++ = *pbuf;
  135. }
  136. }
  137. #else /* ! CONFIG_IDE_SWAP_IO */
  138. __weak void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
  139. {
  140. outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts);
  141. }
  142. __weak void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
  143. {
  144. insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts);
  145. }
  146. #endif /* CONFIG_IDE_SWAP_IO */
  147. /*
  148. * Wait until (Status & mask) == res, or timeout (in ms)
  149. * Return last status
  150. * This is used since some ATAPI CD ROMs clears their Busy Bit first
  151. * and then they set their DRQ Bit
  152. */
  153. static uchar atapi_wait_mask(int dev, ulong t, uchar mask, uchar res)
  154. {
  155. ulong delay = 10 * t; /* poll every 100 us */
  156. uchar c;
  157. /* prevents to read the status before valid */
  158. c = ide_inb(dev, ATA_DEV_CTL);
  159. while (((c = ide_inb(dev, ATA_STATUS)) & mask) != res) {
  160. /* break if error occurs (doesn't make sense to wait more) */
  161. if ((c & ATA_STAT_ERR) == ATA_STAT_ERR)
  162. break;
  163. udelay(100);
  164. if (delay-- == 0)
  165. break;
  166. }
  167. return c;
  168. }
  169. /*
  170. * issue an atapi command
  171. */
  172. unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen,
  173. unsigned char *buffer, int buflen)
  174. {
  175. unsigned char c, err, mask, res;
  176. int n;
  177. ide_led(DEVICE_LED(device), 1); /* LED on */
  178. /* Select device
  179. */
  180. mask = ATA_STAT_BUSY | ATA_STAT_DRQ;
  181. res = 0;
  182. ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
  183. c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
  184. if ((c & mask) != res) {
  185. printf("ATAPI_ISSUE: device %d not ready status %X\n", device,
  186. c);
  187. err = 0xFF;
  188. goto AI_OUT;
  189. }
  190. /* write taskfile */
  191. ide_outb(device, ATA_ERROR_REG, 0); /* no DMA, no overlaped */
  192. ide_outb(device, ATA_SECT_CNT, 0);
  193. ide_outb(device, ATA_SECT_NUM, 0);
  194. ide_outb(device, ATA_CYL_LOW, (unsigned char) (buflen & 0xFF));
  195. ide_outb(device, ATA_CYL_HIGH,
  196. (unsigned char) ((buflen >> 8) & 0xFF));
  197. ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
  198. ide_outb(device, ATA_COMMAND, ATAPI_CMD_PACKET);
  199. udelay(50);
  200. mask = ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR;
  201. res = ATA_STAT_DRQ;
  202. c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
  203. if ((c & mask) != res) { /* DRQ must be 1, BSY 0 */
  204. printf("ATAPI_ISSUE: Error (no IRQ) before sending ccb dev %d status 0x%02x\n",
  205. device, c);
  206. err = 0xFF;
  207. goto AI_OUT;
  208. }
  209. /* write command block */
  210. ide_output_data_shorts(device, (unsigned short *)ccb, ccblen / 2);
  211. /* ATAPI Command written wait for completition */
  212. udelay(5000); /* device must set bsy */
  213. mask = ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR;
  214. /*
  215. * if no data wait for DRQ = 0 BSY = 0
  216. * if data wait for DRQ = 1 BSY = 0
  217. */
  218. res = 0;
  219. if (buflen)
  220. res = ATA_STAT_DRQ;
  221. c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
  222. if ((c & mask) != res) {
  223. if (c & ATA_STAT_ERR) {
  224. err = (ide_inb(device, ATA_ERROR_REG)) >> 4;
  225. debug("atapi_issue 1 returned sense key %X status %02X\n",
  226. err, c);
  227. } else {
  228. printf("ATAPI_ISSUE: (no DRQ) after sending ccb (%x) status 0x%02x\n",
  229. ccb[0], c);
  230. err = 0xFF;
  231. }
  232. goto AI_OUT;
  233. }
  234. n = ide_inb(device, ATA_CYL_HIGH);
  235. n <<= 8;
  236. n += ide_inb(device, ATA_CYL_LOW);
  237. if (n > buflen) {
  238. printf("ERROR, transfer bytes %d requested only %d\n", n,
  239. buflen);
  240. err = 0xff;
  241. goto AI_OUT;
  242. }
  243. if ((n == 0) && (buflen < 0)) {
  244. printf("ERROR, transfer bytes %d requested %d\n", n, buflen);
  245. err = 0xff;
  246. goto AI_OUT;
  247. }
  248. if (n != buflen) {
  249. debug("WARNING, transfer bytes %d not equal with requested %d\n",
  250. n, buflen);
  251. }
  252. if (n != 0) { /* data transfer */
  253. debug("ATAPI_ISSUE: %d Bytes to transfer\n", n);
  254. /* we transfer shorts */
  255. n >>= 1;
  256. /* ok now decide if it is an in or output */
  257. if ((ide_inb(device, ATA_SECT_CNT) & 0x02) == 0) {
  258. debug("Write to device\n");
  259. ide_output_data_shorts(device, (unsigned short *)buffer,
  260. n);
  261. } else {
  262. debug("Read from device @ %p shorts %d\n", buffer, n);
  263. ide_input_data_shorts(device, (unsigned short *)buffer,
  264. n);
  265. }
  266. }
  267. udelay(5000); /* seems that some CD ROMs need this... */
  268. mask = ATA_STAT_BUSY | ATA_STAT_ERR;
  269. res = 0;
  270. c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
  271. if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) {
  272. err = (ide_inb(device, ATA_ERROR_REG) >> 4);
  273. debug("atapi_issue 2 returned sense key %X status %X\n", err,
  274. c);
  275. } else {
  276. err = 0;
  277. }
  278. AI_OUT:
  279. ide_led(DEVICE_LED(device), 0); /* LED off */
  280. return err;
  281. }
  282. /*
  283. * sending the command to atapi_issue. If an status other than good
  284. * returns, an request_sense will be issued
  285. */
  286. #define ATAPI_DRIVE_NOT_READY 100
  287. #define ATAPI_UNIT_ATTN 10
  288. unsigned char atapi_issue_autoreq(int device,
  289. unsigned char *ccb,
  290. int ccblen,
  291. unsigned char *buffer, int buflen)
  292. {
  293. unsigned char sense_data[18], sense_ccb[12];
  294. unsigned char res, key, asc, ascq;
  295. int notready, unitattn;
  296. unitattn = ATAPI_UNIT_ATTN;
  297. notready = ATAPI_DRIVE_NOT_READY;
  298. retry:
  299. res = atapi_issue(device, ccb, ccblen, buffer, buflen);
  300. if (res == 0)
  301. return 0; /* Ok */
  302. if (res == 0xFF)
  303. return 0xFF; /* error */
  304. debug("(auto_req)atapi_issue returned sense key %X\n", res);
  305. memset(sense_ccb, 0, sizeof(sense_ccb));
  306. memset(sense_data, 0, sizeof(sense_data));
  307. sense_ccb[0] = ATAPI_CMD_REQ_SENSE;
  308. sense_ccb[4] = 18; /* allocation Length */
  309. res = atapi_issue(device, sense_ccb, 12, sense_data, 18);
  310. key = (sense_data[2] & 0xF);
  311. asc = (sense_data[12]);
  312. ascq = (sense_data[13]);
  313. debug("ATAPI_CMD_REQ_SENSE returned %x\n", res);
  314. debug(" Sense page: %02X key %02X ASC %02X ASCQ %02X\n",
  315. sense_data[0], key, asc, ascq);
  316. if ((key == 0))
  317. return 0; /* ok device ready */
  318. if ((key == 6) || (asc == 0x29) || (asc == 0x28)) { /* Unit Attention */
  319. if (unitattn-- > 0) {
  320. udelay(200 * 1000);
  321. goto retry;
  322. }
  323. printf("Unit Attention, tried %d\n", ATAPI_UNIT_ATTN);
  324. goto error;
  325. }
  326. if ((asc == 0x4) && (ascq == 0x1)) {
  327. /* not ready, but will be ready soon */
  328. if (notready-- > 0) {
  329. udelay(200 * 1000);
  330. goto retry;
  331. }
  332. printf("Drive not ready, tried %d times\n",
  333. ATAPI_DRIVE_NOT_READY);
  334. goto error;
  335. }
  336. if (asc == 0x3a) {
  337. debug("Media not present\n");
  338. goto error;
  339. }
  340. printf("ERROR: Unknown Sense key %02X ASC %02X ASCQ %02X\n", key, asc,
  341. ascq);
  342. error:
  343. debug("ERROR Sense key %02X ASC %02X ASCQ %02X\n", key, asc, ascq);
  344. return 0xFF;
  345. }
  346. /*
  347. * atapi_read:
  348. * we transfer only one block per command, since the multiple DRQ per
  349. * command is not yet implemented
  350. */
  351. #define ATAPI_READ_MAX_BYTES 2048 /* we read max 2kbytes */
  352. #define ATAPI_READ_BLOCK_SIZE 2048 /* assuming CD part */
  353. #define ATAPI_READ_MAX_BLOCK (ATAPI_READ_MAX_BYTES/ATAPI_READ_BLOCK_SIZE)
  354. ulong atapi_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt,
  355. void *buffer)
  356. {
  357. int device = block_dev->devnum;
  358. ulong n = 0;
  359. unsigned char ccb[12]; /* Command descriptor block */
  360. ulong cnt;
  361. debug("atapi_read dev %d start " LBAF " blocks " LBAF
  362. " buffer at %lX\n", device, blknr, blkcnt, (ulong) buffer);
  363. do {
  364. if (blkcnt > ATAPI_READ_MAX_BLOCK)
  365. cnt = ATAPI_READ_MAX_BLOCK;
  366. else
  367. cnt = blkcnt;
  368. ccb[0] = ATAPI_CMD_READ_12;
  369. ccb[1] = 0; /* reserved */
  370. ccb[2] = (unsigned char) (blknr >> 24) & 0xFF; /* MSB Block */
  371. ccb[3] = (unsigned char) (blknr >> 16) & 0xFF; /* */
  372. ccb[4] = (unsigned char) (blknr >> 8) & 0xFF;
  373. ccb[5] = (unsigned char) blknr & 0xFF; /* LSB Block */
  374. ccb[6] = (unsigned char) (cnt >> 24) & 0xFF; /* MSB Block cnt */
  375. ccb[7] = (unsigned char) (cnt >> 16) & 0xFF;
  376. ccb[8] = (unsigned char) (cnt >> 8) & 0xFF;
  377. ccb[9] = (unsigned char) cnt & 0xFF; /* LSB Block */
  378. ccb[10] = 0; /* reserved */
  379. ccb[11] = 0; /* reserved */
  380. if (atapi_issue_autoreq(device, ccb, 12,
  381. (unsigned char *)buffer,
  382. cnt * ATAPI_READ_BLOCK_SIZE)
  383. == 0xFF) {
  384. return n;
  385. }
  386. n += cnt;
  387. blkcnt -= cnt;
  388. blknr += cnt;
  389. buffer += (cnt * ATAPI_READ_BLOCK_SIZE);
  390. } while (blkcnt > 0);
  391. return n;
  392. }
  393. static void atapi_inquiry(struct blk_desc *dev_desc)
  394. {
  395. unsigned char ccb[12]; /* Command descriptor block */
  396. unsigned char iobuf[64]; /* temp buf */
  397. unsigned char c;
  398. int device;
  399. device = dev_desc->devnum;
  400. dev_desc->type = DEV_TYPE_UNKNOWN; /* not yet valid */
  401. dev_desc->block_read = atapi_read;
  402. memset(ccb, 0, sizeof(ccb));
  403. memset(iobuf, 0, sizeof(iobuf));
  404. ccb[0] = ATAPI_CMD_INQUIRY;
  405. ccb[4] = 40; /* allocation Legnth */
  406. c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *)iobuf, 40);
  407. debug("ATAPI_CMD_INQUIRY returned %x\n", c);
  408. if (c != 0)
  409. return;
  410. /* copy device ident strings */
  411. ident_cpy((unsigned char *)dev_desc->vendor, &iobuf[8], 8);
  412. ident_cpy((unsigned char *)dev_desc->product, &iobuf[16], 16);
  413. ident_cpy((unsigned char *)dev_desc->revision, &iobuf[32], 5);
  414. dev_desc->lun = 0;
  415. dev_desc->lba = 0;
  416. dev_desc->blksz = 0;
  417. dev_desc->log2blksz = LOG2_INVALID(typeof(dev_desc->log2blksz));
  418. dev_desc->type = iobuf[0] & 0x1f;
  419. if ((iobuf[1] & 0x80) == 0x80)
  420. dev_desc->removable = 1;
  421. else
  422. dev_desc->removable = 0;
  423. memset(ccb, 0, sizeof(ccb));
  424. memset(iobuf, 0, sizeof(iobuf));
  425. ccb[0] = ATAPI_CMD_START_STOP;
  426. ccb[4] = 0x03; /* start */
  427. c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *)iobuf, 0);
  428. debug("ATAPI_CMD_START_STOP returned %x\n", c);
  429. if (c != 0)
  430. return;
  431. memset(ccb, 0, sizeof(ccb));
  432. memset(iobuf, 0, sizeof(iobuf));
  433. c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *)iobuf, 0);
  434. debug("ATAPI_CMD_UNIT_TEST_READY returned %x\n", c);
  435. if (c != 0)
  436. return;
  437. memset(ccb, 0, sizeof(ccb));
  438. memset(iobuf, 0, sizeof(iobuf));
  439. ccb[0] = ATAPI_CMD_READ_CAP;
  440. c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *)iobuf, 8);
  441. debug("ATAPI_CMD_READ_CAP returned %x\n", c);
  442. if (c != 0)
  443. return;
  444. debug("Read Cap: LBA %02X%02X%02X%02X blksize %02X%02X%02X%02X\n",
  445. iobuf[0], iobuf[1], iobuf[2], iobuf[3],
  446. iobuf[4], iobuf[5], iobuf[6], iobuf[7]);
  447. dev_desc->lba = ((unsigned long) iobuf[0] << 24) +
  448. ((unsigned long) iobuf[1] << 16) +
  449. ((unsigned long) iobuf[2] << 8) + ((unsigned long) iobuf[3]);
  450. dev_desc->blksz = ((unsigned long) iobuf[4] << 24) +
  451. ((unsigned long) iobuf[5] << 16) +
  452. ((unsigned long) iobuf[6] << 8) + ((unsigned long) iobuf[7]);
  453. dev_desc->log2blksz = LOG2(dev_desc->blksz);
  454. #ifdef CONFIG_LBA48
  455. /* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */
  456. dev_desc->lba48 = 0;
  457. #endif
  458. return;
  459. }
  460. #endif /* CONFIG_ATAPI */
  461. static void ide_ident(struct blk_desc *dev_desc)
  462. {
  463. unsigned char c;
  464. hd_driveid_t iop;
  465. #ifdef CONFIG_ATAPI
  466. int retries = 0;
  467. #endif
  468. int device;
  469. device = dev_desc->devnum;
  470. printf(" Device %d: ", device);
  471. ide_led(DEVICE_LED(device), 1); /* LED on */
  472. /* Select device
  473. */
  474. ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
  475. dev_desc->if_type = IF_TYPE_IDE;
  476. #ifdef CONFIG_ATAPI
  477. retries = 0;
  478. /* Warning: This will be tricky to read */
  479. while (retries <= 1) {
  480. /* check signature */
  481. if ((ide_inb(device, ATA_SECT_CNT) == 0x01) &&
  482. (ide_inb(device, ATA_SECT_NUM) == 0x01) &&
  483. (ide_inb(device, ATA_CYL_LOW) == 0x14) &&
  484. (ide_inb(device, ATA_CYL_HIGH) == 0xEB)) {
  485. /* ATAPI Signature found */
  486. dev_desc->if_type = IF_TYPE_ATAPI;
  487. /*
  488. * Start Ident Command
  489. */
  490. ide_outb(device, ATA_COMMAND, ATAPI_CMD_IDENT);
  491. /*
  492. * Wait for completion - ATAPI devices need more time
  493. * to become ready
  494. */
  495. c = ide_wait(device, ATAPI_TIME_OUT);
  496. } else
  497. #endif
  498. {
  499. /*
  500. * Start Ident Command
  501. */
  502. ide_outb(device, ATA_COMMAND, ATA_CMD_IDENT);
  503. /*
  504. * Wait for completion
  505. */
  506. c = ide_wait(device, IDE_TIME_OUT);
  507. }
  508. ide_led(DEVICE_LED(device), 0); /* LED off */
  509. if (((c & ATA_STAT_DRQ) == 0) ||
  510. ((c & (ATA_STAT_FAULT | ATA_STAT_ERR)) != 0)) {
  511. #ifdef CONFIG_ATAPI
  512. {
  513. /*
  514. * Need to soft reset the device
  515. * in case it's an ATAPI...
  516. */
  517. debug("Retrying...\n");
  518. ide_outb(device, ATA_DEV_HD,
  519. ATA_LBA | ATA_DEVICE(device));
  520. udelay(100000);
  521. ide_outb(device, ATA_COMMAND, 0x08);
  522. udelay(500000); /* 500 ms */
  523. }
  524. /*
  525. * Select device
  526. */
  527. ide_outb(device, ATA_DEV_HD,
  528. ATA_LBA | ATA_DEVICE(device));
  529. retries++;
  530. #else
  531. return;
  532. #endif
  533. }
  534. #ifdef CONFIG_ATAPI
  535. else
  536. break;
  537. } /* see above - ugly to read */
  538. if (retries == 2) /* Not found */
  539. return;
  540. #endif
  541. ide_input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS);
  542. ident_cpy((unsigned char *)dev_desc->revision, iop.fw_rev,
  543. sizeof(dev_desc->revision));
  544. ident_cpy((unsigned char *)dev_desc->vendor, iop.model,
  545. sizeof(dev_desc->vendor));
  546. ident_cpy((unsigned char *)dev_desc->product, iop.serial_no,
  547. sizeof(dev_desc->product));
  548. #ifdef __LITTLE_ENDIAN
  549. /*
  550. * firmware revision, model, and serial number have Big Endian Byte
  551. * order in Word. Convert all three to little endian.
  552. *
  553. * See CF+ and CompactFlash Specification Revision 2.0:
  554. * 6.2.1.6: Identify Drive, Table 39 for more details
  555. */
  556. strswab(dev_desc->revision);
  557. strswab(dev_desc->vendor);
  558. strswab(dev_desc->product);
  559. #endif /* __LITTLE_ENDIAN */
  560. if ((iop.config & 0x0080) == 0x0080)
  561. dev_desc->removable = 1;
  562. else
  563. dev_desc->removable = 0;
  564. #ifdef CONFIG_ATAPI
  565. if (dev_desc->if_type == IF_TYPE_ATAPI) {
  566. atapi_inquiry(dev_desc);
  567. return;
  568. }
  569. #endif /* CONFIG_ATAPI */
  570. #ifdef __BIG_ENDIAN
  571. /* swap shorts */
  572. dev_desc->lba = (iop.lba_capacity << 16) | (iop.lba_capacity >> 16);
  573. #else /* ! __BIG_ENDIAN */
  574. /*
  575. * do not swap shorts on little endian
  576. *
  577. * See CF+ and CompactFlash Specification Revision 2.0:
  578. * 6.2.1.6: Identfy Drive, Table 39, Word Address 57-58 for details.
  579. */
  580. dev_desc->lba = iop.lba_capacity;
  581. #endif /* __BIG_ENDIAN */
  582. #ifdef CONFIG_LBA48
  583. if (iop.command_set_2 & 0x0400) { /* LBA 48 support */
  584. dev_desc->lba48 = 1;
  585. dev_desc->lba = (unsigned long long) iop.lba48_capacity[0] |
  586. ((unsigned long long) iop.lba48_capacity[1] << 16) |
  587. ((unsigned long long) iop.lba48_capacity[2] << 32) |
  588. ((unsigned long long) iop.lba48_capacity[3] << 48);
  589. } else {
  590. dev_desc->lba48 = 0;
  591. }
  592. #endif /* CONFIG_LBA48 */
  593. /* assuming HD */
  594. dev_desc->type = DEV_TYPE_HARDDISK;
  595. dev_desc->blksz = ATA_BLOCKSIZE;
  596. dev_desc->log2blksz = LOG2(dev_desc->blksz);
  597. dev_desc->lun = 0; /* just to fill something in... */
  598. #if 0 /* only used to test the powersaving mode,
  599. * if enabled, the drive goes after 5 sec
  600. * in standby mode */
  601. ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
  602. c = ide_wait(device, IDE_TIME_OUT);
  603. ide_outb(device, ATA_SECT_CNT, 1);
  604. ide_outb(device, ATA_LBA_LOW, 0);
  605. ide_outb(device, ATA_LBA_MID, 0);
  606. ide_outb(device, ATA_LBA_HIGH, 0);
  607. ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
  608. ide_outb(device, ATA_COMMAND, 0xe3);
  609. udelay(50);
  610. c = ide_wait(device, IDE_TIME_OUT); /* can't take over 500 ms */
  611. #endif
  612. }
  613. __weak void ide_led(uchar led, uchar status)
  614. {
  615. #if defined(CONFIG_IDE_LED) && defined(PER8_BASE) /* required by LED_PORT */
  616. static uchar led_buffer; /* Buffer for current LED status */
  617. uchar *led_port = LED_PORT;
  618. if (status) /* switch LED on */
  619. led_buffer |= led;
  620. else /* switch LED off */
  621. led_buffer &= ~led;
  622. *led_port = led_buffer;
  623. #endif
  624. }
  625. __weak void ide_outb(int dev, int port, unsigned char val)
  626. {
  627. debug("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
  628. dev, port, val,
  629. (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)));
  630. #if defined(CONFIG_IDE_AHB)
  631. if (port) {
  632. /* write command */
  633. ide_write_register(dev, port, val);
  634. } else {
  635. /* write data */
  636. outb(val, (ATA_CURR_BASE(dev)));
  637. }
  638. #else
  639. outb(val, (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)));
  640. #endif
  641. }
  642. __weak unsigned char ide_inb(int dev, int port)
  643. {
  644. uchar val;
  645. #if defined(CONFIG_IDE_AHB)
  646. val = ide_read_register(dev, port);
  647. #else
  648. val = inb((ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)));
  649. #endif
  650. debug("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
  651. dev, port,
  652. (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)), val);
  653. return val;
  654. }
  655. void ide_init(void)
  656. {
  657. unsigned char c;
  658. int i, bus;
  659. #ifdef CONFIG_IDE_8xx_PCCARD
  660. extern int ide_devices_found; /* Initialized in check_ide_device() */
  661. #endif /* CONFIG_IDE_8xx_PCCARD */
  662. #ifdef CONFIG_IDE_PREINIT
  663. WATCHDOG_RESET();
  664. if (ide_preinit()) {
  665. puts("ide_preinit failed\n");
  666. return;
  667. }
  668. #endif /* CONFIG_IDE_PREINIT */
  669. WATCHDOG_RESET();
  670. /*
  671. * Reset the IDE just to be sure.
  672. * Light LED's to show
  673. */
  674. ide_led((LED_IDE1 | LED_IDE2), 1); /* LED's on */
  675. /* ATAPI Drives seems to need a proper IDE Reset */
  676. ide_reset();
  677. #ifdef CONFIG_IDE_INIT_POSTRESET
  678. WATCHDOG_RESET();
  679. if (ide_init_postreset()) {
  680. puts("ide_preinit_postreset failed\n");
  681. return;
  682. }
  683. #endif /* CONFIG_IDE_INIT_POSTRESET */
  684. /*
  685. * Wait for IDE to get ready.
  686. * According to spec, this can take up to 31 seconds!
  687. */
  688. for (bus = 0; bus < CONFIG_SYS_IDE_MAXBUS; ++bus) {
  689. int dev =
  690. bus * (CONFIG_SYS_IDE_MAXDEVICE /
  691. CONFIG_SYS_IDE_MAXBUS);
  692. #ifdef CONFIG_IDE_8xx_PCCARD
  693. /* Skip non-ide devices from probing */
  694. if ((ide_devices_found & (1 << bus)) == 0) {
  695. ide_led((LED_IDE1 | LED_IDE2), 0); /* LED's off */
  696. continue;
  697. }
  698. #endif
  699. printf("Bus %d: ", bus);
  700. ide_bus_ok[bus] = 0;
  701. /* Select device
  702. */
  703. udelay(100000); /* 100 ms */
  704. ide_outb(dev, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(dev));
  705. udelay(100000); /* 100 ms */
  706. i = 0;
  707. do {
  708. udelay(10000); /* 10 ms */
  709. c = ide_inb(dev, ATA_STATUS);
  710. i++;
  711. if (i > (ATA_RESET_TIME * 100)) {
  712. puts("** Timeout **\n");
  713. /* LED's off */
  714. ide_led((LED_IDE1 | LED_IDE2), 0);
  715. return;
  716. }
  717. if ((i >= 100) && ((i % 100) == 0))
  718. putc('.');
  719. } while (c & ATA_STAT_BUSY);
  720. if (c & (ATA_STAT_BUSY | ATA_STAT_FAULT)) {
  721. puts("not available ");
  722. debug("Status = 0x%02X ", c);
  723. #ifndef CONFIG_ATAPI /* ATAPI Devices do not set DRDY */
  724. } else if ((c & ATA_STAT_READY) == 0) {
  725. puts("not available ");
  726. debug("Status = 0x%02X ", c);
  727. #endif
  728. } else {
  729. puts("OK ");
  730. ide_bus_ok[bus] = 1;
  731. }
  732. WATCHDOG_RESET();
  733. }
  734. putc('\n');
  735. ide_led((LED_IDE1 | LED_IDE2), 0); /* LED's off */
  736. for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) {
  737. int led = (IDE_BUS(i) == 0) ? LED_IDE1 : LED_IDE2;
  738. ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
  739. ide_dev_desc[i].if_type = IF_TYPE_IDE;
  740. ide_dev_desc[i].devnum = i;
  741. ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
  742. ide_dev_desc[i].blksz = 0;
  743. ide_dev_desc[i].log2blksz =
  744. LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz));
  745. ide_dev_desc[i].lba = 0;
  746. ide_dev_desc[i].block_read = ide_read;
  747. ide_dev_desc[i].block_write = ide_write;
  748. if (!ide_bus_ok[IDE_BUS(i)])
  749. continue;
  750. ide_led(led, 1); /* LED on */
  751. ide_ident(&ide_dev_desc[i]);
  752. ide_led(led, 0); /* LED off */
  753. dev_print(&ide_dev_desc[i]);
  754. if ((ide_dev_desc[i].lba > 0) && (ide_dev_desc[i].blksz > 0)) {
  755. /* initialize partition type */
  756. part_init(&ide_dev_desc[i]);
  757. }
  758. }
  759. WATCHDOG_RESET();
  760. }
  761. /* We only need to swap data if we are running on a big endian cpu. */
  762. #if defined(__LITTLE_ENDIAN)
  763. __weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
  764. {
  765. ide_input_data(dev, sect_buf, words);
  766. }
  767. #else
  768. __weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
  769. {
  770. volatile ushort *pbuf =
  771. (ushort *)(ATA_CURR_BASE(dev) + ATA_DATA_REG);
  772. ushort *dbuf = (ushort *)sect_buf;
  773. debug("in input swap data base for read is %lx\n",
  774. (unsigned long) pbuf);
  775. while (words--) {
  776. #ifdef __MIPS__
  777. *dbuf++ = swab16p((u16 *)pbuf);
  778. *dbuf++ = swab16p((u16 *)pbuf);
  779. #else
  780. *dbuf++ = ld_le16(pbuf);
  781. *dbuf++ = ld_le16(pbuf);
  782. #endif /* !MIPS */
  783. }
  784. }
  785. #endif /* __LITTLE_ENDIAN */
  786. #if defined(CONFIG_IDE_SWAP_IO)
  787. __weak void ide_output_data(int dev, const ulong *sect_buf, int words)
  788. {
  789. ushort *dbuf;
  790. volatile ushort *pbuf;
  791. pbuf = (ushort *)(ATA_CURR_BASE(dev) + ATA_DATA_REG);
  792. dbuf = (ushort *)sect_buf;
  793. while (words--) {
  794. EIEIO;
  795. *pbuf = *dbuf++;
  796. EIEIO;
  797. *pbuf = *dbuf++;
  798. }
  799. }
  800. #else /* ! CONFIG_IDE_SWAP_IO */
  801. __weak void ide_output_data(int dev, const ulong *sect_buf, int words)
  802. {
  803. #if defined(CONFIG_IDE_AHB)
  804. ide_write_data(dev, sect_buf, words);
  805. #else
  806. outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, words << 1);
  807. #endif
  808. }
  809. #endif /* CONFIG_IDE_SWAP_IO */
  810. #if defined(CONFIG_IDE_SWAP_IO)
  811. __weak void ide_input_data(int dev, ulong *sect_buf, int words)
  812. {
  813. ushort *dbuf;
  814. volatile ushort *pbuf;
  815. pbuf = (ushort *)(ATA_CURR_BASE(dev) + ATA_DATA_REG);
  816. dbuf = (ushort *)sect_buf;
  817. debug("in input data base for read is %lx\n", (unsigned long) pbuf);
  818. while (words--) {
  819. EIEIO;
  820. *dbuf++ = *pbuf;
  821. EIEIO;
  822. *dbuf++ = *pbuf;
  823. }
  824. }
  825. #else /* ! CONFIG_IDE_SWAP_IO */
  826. __weak void ide_input_data(int dev, ulong *sect_buf, int words)
  827. {
  828. #if defined(CONFIG_IDE_AHB)
  829. ide_read_data(dev, sect_buf, words);
  830. #else
  831. insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, words << 1);
  832. #endif
  833. }
  834. #endif /* CONFIG_IDE_SWAP_IO */
  835. ulong ide_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt,
  836. void *buffer)
  837. {
  838. int device = block_dev->devnum;
  839. ulong n = 0;
  840. unsigned char c;
  841. unsigned char pwrsave = 0; /* power save */
  842. #ifdef CONFIG_LBA48
  843. unsigned char lba48 = 0;
  844. if (blknr & 0x0000fffff0000000ULL) {
  845. /* more than 28 bits used, use 48bit mode */
  846. lba48 = 1;
  847. }
  848. #endif
  849. debug("ide_read dev %d start " LBAF ", blocks " LBAF " buffer at %lX\n",
  850. device, blknr, blkcnt, (ulong) buffer);
  851. ide_led(DEVICE_LED(device), 1); /* LED on */
  852. /* Select device
  853. */
  854. ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
  855. c = ide_wait(device, IDE_TIME_OUT);
  856. if (c & ATA_STAT_BUSY) {
  857. printf("IDE read: device %d not ready\n", device);
  858. goto IDE_READ_E;
  859. }
  860. /* first check if the drive is in Powersaving mode, if yes,
  861. * increase the timeout value */
  862. ide_outb(device, ATA_COMMAND, ATA_CMD_CHK_PWR);
  863. udelay(50);
  864. c = ide_wait(device, IDE_TIME_OUT); /* can't take over 500 ms */
  865. if (c & ATA_STAT_BUSY) {
  866. printf("IDE read: device %d not ready\n", device);
  867. goto IDE_READ_E;
  868. }
  869. if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) {
  870. printf("No Powersaving mode %X\n", c);
  871. } else {
  872. c = ide_inb(device, ATA_SECT_CNT);
  873. debug("Powersaving %02X\n", c);
  874. if (c == 0)
  875. pwrsave = 1;
  876. }
  877. while (blkcnt-- > 0) {
  878. c = ide_wait(device, IDE_TIME_OUT);
  879. if (c & ATA_STAT_BUSY) {
  880. printf("IDE read: device %d not ready\n", device);
  881. break;
  882. }
  883. #ifdef CONFIG_LBA48
  884. if (lba48) {
  885. /* write high bits */
  886. ide_outb(device, ATA_SECT_CNT, 0);
  887. ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF);
  888. #ifdef CONFIG_SYS_64BIT_LBA
  889. ide_outb(device, ATA_LBA_MID, (blknr >> 32) & 0xFF);
  890. ide_outb(device, ATA_LBA_HIGH, (blknr >> 40) & 0xFF);
  891. #else
  892. ide_outb(device, ATA_LBA_MID, 0);
  893. ide_outb(device, ATA_LBA_HIGH, 0);
  894. #endif
  895. }
  896. #endif
  897. ide_outb(device, ATA_SECT_CNT, 1);
  898. ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF);
  899. ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF);
  900. ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF);
  901. #ifdef CONFIG_LBA48
  902. if (lba48) {
  903. ide_outb(device, ATA_DEV_HD,
  904. ATA_LBA | ATA_DEVICE(device));
  905. ide_outb(device, ATA_COMMAND, ATA_CMD_READ_EXT);
  906. } else
  907. #endif
  908. {
  909. ide_outb(device, ATA_DEV_HD, ATA_LBA |
  910. ATA_DEVICE(device) | ((blknr >> 24) & 0xF));
  911. ide_outb(device, ATA_COMMAND, ATA_CMD_READ);
  912. }
  913. udelay(50);
  914. if (pwrsave) {
  915. /* may take up to 4 sec */
  916. c = ide_wait(device, IDE_SPIN_UP_TIME_OUT);
  917. pwrsave = 0;
  918. } else {
  919. /* can't take over 500 ms */
  920. c = ide_wait(device, IDE_TIME_OUT);
  921. }
  922. if ((c & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR)) !=
  923. ATA_STAT_DRQ) {
  924. printf("Error (no IRQ) dev %d blk " LBAF
  925. ": status %#02x\n", device, blknr, c);
  926. break;
  927. }
  928. ide_input_data(device, buffer, ATA_SECTORWORDS);
  929. (void) ide_inb(device, ATA_STATUS); /* clear IRQ */
  930. ++n;
  931. ++blknr;
  932. buffer += ATA_BLOCKSIZE;
  933. }
  934. IDE_READ_E:
  935. ide_led(DEVICE_LED(device), 0); /* LED off */
  936. return n;
  937. }
  938. ulong ide_write(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt,
  939. const void *buffer)
  940. {
  941. int device = block_dev->devnum;
  942. ulong n = 0;
  943. unsigned char c;
  944. #ifdef CONFIG_LBA48
  945. unsigned char lba48 = 0;
  946. if (blknr & 0x0000fffff0000000ULL) {
  947. /* more than 28 bits used, use 48bit mode */
  948. lba48 = 1;
  949. }
  950. #endif
  951. ide_led(DEVICE_LED(device), 1); /* LED on */
  952. /* Select device
  953. */
  954. ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
  955. while (blkcnt-- > 0) {
  956. c = ide_wait(device, IDE_TIME_OUT);
  957. if (c & ATA_STAT_BUSY) {
  958. printf("IDE read: device %d not ready\n", device);
  959. goto WR_OUT;
  960. }
  961. #ifdef CONFIG_LBA48
  962. if (lba48) {
  963. /* write high bits */
  964. ide_outb(device, ATA_SECT_CNT, 0);
  965. ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF);
  966. #ifdef CONFIG_SYS_64BIT_LBA
  967. ide_outb(device, ATA_LBA_MID, (blknr >> 32) & 0xFF);
  968. ide_outb(device, ATA_LBA_HIGH, (blknr >> 40) & 0xFF);
  969. #else
  970. ide_outb(device, ATA_LBA_MID, 0);
  971. ide_outb(device, ATA_LBA_HIGH, 0);
  972. #endif
  973. }
  974. #endif
  975. ide_outb(device, ATA_SECT_CNT, 1);
  976. ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF);
  977. ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF);
  978. ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF);
  979. #ifdef CONFIG_LBA48
  980. if (lba48) {
  981. ide_outb(device, ATA_DEV_HD,
  982. ATA_LBA | ATA_DEVICE(device));
  983. ide_outb(device, ATA_COMMAND, ATA_CMD_WRITE_EXT);
  984. } else
  985. #endif
  986. {
  987. ide_outb(device, ATA_DEV_HD, ATA_LBA |
  988. ATA_DEVICE(device) | ((blknr >> 24) & 0xF));
  989. ide_outb(device, ATA_COMMAND, ATA_CMD_WRITE);
  990. }
  991. udelay(50);
  992. /* can't take over 500 ms */
  993. c = ide_wait(device, IDE_TIME_OUT);
  994. if ((c & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR)) !=
  995. ATA_STAT_DRQ) {
  996. printf("Error (no IRQ) dev %d blk " LBAF
  997. ": status %#02x\n", device, blknr, c);
  998. goto WR_OUT;
  999. }
  1000. ide_output_data(device, buffer, ATA_SECTORWORDS);
  1001. c = ide_inb(device, ATA_STATUS); /* clear IRQ */
  1002. ++n;
  1003. ++blknr;
  1004. buffer += ATA_BLOCKSIZE;
  1005. }
  1006. WR_OUT:
  1007. ide_led(DEVICE_LED(device), 0); /* LED off */
  1008. return n;
  1009. }
  1010. #if defined(CONFIG_OF_IDE_FIXUP)
  1011. int ide_device_present(int dev)
  1012. {
  1013. if (dev >= CONFIG_SYS_IDE_MAXBUS)
  1014. return 0;
  1015. return ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN ? 0 : 1;
  1016. }
  1017. #endif
  1018. U_BOOT_LEGACY_BLK(ide) = {
  1019. .if_typename = "ide",
  1020. .if_type = IF_TYPE_IDE,
  1021. .max_devs = CONFIG_SYS_IDE_MAXDEVICE,
  1022. .desc = ide_dev_desc,
  1023. };