pmac.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  1. /*
  2. * Support for IDE interfaces on PowerMacs.
  3. *
  4. * These IDE interfaces are memory-mapped and have a DBDMA channel
  5. * for doing DMA.
  6. *
  7. * Copyright (C) 1998-2003 Paul Mackerras & Ben. Herrenschmidt
  8. * Copyright (C) 2007-2008 Bartlomiej Zolnierkiewicz
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. *
  15. * Some code taken from drivers/ide/ide-dma.c:
  16. *
  17. * Copyright (c) 1995-1998 Mark Lord
  18. *
  19. * TODO: - Use pre-calculated (kauai) timing tables all the time and
  20. * get rid of the "rounded" tables used previously, so we have the
  21. * same table format for all controllers and can then just have one
  22. * big table
  23. *
  24. */
  25. #include <linux/types.h>
  26. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <linux/delay.h>
  29. #include <linux/ide.h>
  30. #include <linux/notifier.h>
  31. #include <linux/reboot.h>
  32. #include <linux/pci.h>
  33. #include <linux/adb.h>
  34. #include <linux/pmu.h>
  35. #include <linux/scatterlist.h>
  36. #include <asm/prom.h>
  37. #include <asm/io.h>
  38. #include <asm/dbdma.h>
  39. #include <asm/ide.h>
  40. #include <asm/pci-bridge.h>
  41. #include <asm/machdep.h>
  42. #include <asm/pmac_feature.h>
  43. #include <asm/sections.h>
  44. #include <asm/irq.h>
  45. #include <asm/mediabay.h>
  46. #define DRV_NAME "ide-pmac"
  47. #undef IDE_PMAC_DEBUG
  48. #define DMA_WAIT_TIMEOUT 50
  49. typedef struct pmac_ide_hwif {
  50. unsigned long regbase;
  51. int irq;
  52. int kind;
  53. int aapl_bus_id;
  54. unsigned broken_dma : 1;
  55. unsigned broken_dma_warn : 1;
  56. struct device_node* node;
  57. struct macio_dev *mdev;
  58. u32 timings[4];
  59. volatile u32 __iomem * *kauai_fcr;
  60. ide_hwif_t *hwif;
  61. /* Those fields are duplicating what is in hwif. We currently
  62. * can't use the hwif ones because of some assumptions that are
  63. * beeing done by the generic code about the kind of dma controller
  64. * and format of the dma table. This will have to be fixed though.
  65. */
  66. volatile struct dbdma_regs __iomem * dma_regs;
  67. struct dbdma_cmd* dma_table_cpu;
  68. } pmac_ide_hwif_t;
  69. enum {
  70. controller_ohare, /* OHare based */
  71. controller_heathrow, /* Heathrow/Paddington */
  72. controller_kl_ata3, /* KeyLargo ATA-3 */
  73. controller_kl_ata4, /* KeyLargo ATA-4 */
  74. controller_un_ata6, /* UniNorth2 ATA-6 */
  75. controller_k2_ata6, /* K2 ATA-6 */
  76. controller_sh_ata6, /* Shasta ATA-6 */
  77. };
  78. static const char* model_name[] = {
  79. "OHare ATA", /* OHare based */
  80. "Heathrow ATA", /* Heathrow/Paddington */
  81. "KeyLargo ATA-3", /* KeyLargo ATA-3 (MDMA only) */
  82. "KeyLargo ATA-4", /* KeyLargo ATA-4 (UDMA/66) */
  83. "UniNorth ATA-6", /* UniNorth2 ATA-6 (UDMA/100) */
  84. "K2 ATA-6", /* K2 ATA-6 (UDMA/100) */
  85. "Shasta ATA-6", /* Shasta ATA-6 (UDMA/133) */
  86. };
  87. /*
  88. * Extra registers, both 32-bit little-endian
  89. */
  90. #define IDE_TIMING_CONFIG 0x200
  91. #define IDE_INTERRUPT 0x300
  92. /* Kauai (U2) ATA has different register setup */
  93. #define IDE_KAUAI_PIO_CONFIG 0x200
  94. #define IDE_KAUAI_ULTRA_CONFIG 0x210
  95. #define IDE_KAUAI_POLL_CONFIG 0x220
  96. /*
  97. * Timing configuration register definitions
  98. */
  99. /* Number of IDE_SYSCLK_NS ticks, argument is in nanoseconds */
  100. #define SYSCLK_TICKS(t) (((t) + IDE_SYSCLK_NS - 1) / IDE_SYSCLK_NS)
  101. #define SYSCLK_TICKS_66(t) (((t) + IDE_SYSCLK_66_NS - 1) / IDE_SYSCLK_66_NS)
  102. #define IDE_SYSCLK_NS 30 /* 33Mhz cell */
  103. #define IDE_SYSCLK_66_NS 15 /* 66Mhz cell */
  104. /* 133Mhz cell, found in shasta.
  105. * See comments about 100 Mhz Uninorth 2...
  106. * Note that PIO_MASK and MDMA_MASK seem to overlap
  107. */
  108. #define TR_133_PIOREG_PIO_MASK 0xff000fff
  109. #define TR_133_PIOREG_MDMA_MASK 0x00fff800
  110. #define TR_133_UDMAREG_UDMA_MASK 0x0003ffff
  111. #define TR_133_UDMAREG_UDMA_EN 0x00000001
  112. /* 100Mhz cell, found in Uninorth 2. I don't have much infos about
  113. * this one yet, it appears as a pci device (106b/0033) on uninorth
  114. * internal PCI bus and it's clock is controlled like gem or fw. It
  115. * appears to be an evolution of keylargo ATA4 with a timing register
  116. * extended to 2 32bits registers and a similar DBDMA channel. Other
  117. * registers seem to exist but I can't tell much about them.
  118. *
  119. * So far, I'm using pre-calculated tables for this extracted from
  120. * the values used by the MacOS X driver.
  121. *
  122. * The "PIO" register controls PIO and MDMA timings, the "ULTRA"
  123. * register controls the UDMA timings. At least, it seems bit 0
  124. * of this one enables UDMA vs. MDMA, and bits 4..7 are the
  125. * cycle time in units of 10ns. Bits 8..15 are used by I don't
  126. * know their meaning yet
  127. */
  128. #define TR_100_PIOREG_PIO_MASK 0xff000fff
  129. #define TR_100_PIOREG_MDMA_MASK 0x00fff000
  130. #define TR_100_UDMAREG_UDMA_MASK 0x0000ffff
  131. #define TR_100_UDMAREG_UDMA_EN 0x00000001
  132. /* 66Mhz cell, found in KeyLargo. Can do ultra mode 0 to 2 on
  133. * 40 connector cable and to 4 on 80 connector one.
  134. * Clock unit is 15ns (66Mhz)
  135. *
  136. * 3 Values can be programmed:
  137. * - Write data setup, which appears to match the cycle time. They
  138. * also call it DIOW setup.
  139. * - Ready to pause time (from spec)
  140. * - Address setup. That one is weird. I don't see where exactly
  141. * it fits in UDMA cycles, I got it's name from an obscure piece
  142. * of commented out code in Darwin. They leave it to 0, we do as
  143. * well, despite a comment that would lead to think it has a
  144. * min value of 45ns.
  145. * Apple also add 60ns to the write data setup (or cycle time ?) on
  146. * reads.
  147. */
  148. #define TR_66_UDMA_MASK 0xfff00000
  149. #define TR_66_UDMA_EN 0x00100000 /* Enable Ultra mode for DMA */
  150. #define TR_66_UDMA_ADDRSETUP_MASK 0xe0000000 /* Address setup */
  151. #define TR_66_UDMA_ADDRSETUP_SHIFT 29
  152. #define TR_66_UDMA_RDY2PAUS_MASK 0x1e000000 /* Ready 2 pause time */
  153. #define TR_66_UDMA_RDY2PAUS_SHIFT 25
  154. #define TR_66_UDMA_WRDATASETUP_MASK 0x01e00000 /* Write data setup time */
  155. #define TR_66_UDMA_WRDATASETUP_SHIFT 21
  156. #define TR_66_MDMA_MASK 0x000ffc00
  157. #define TR_66_MDMA_RECOVERY_MASK 0x000f8000
  158. #define TR_66_MDMA_RECOVERY_SHIFT 15
  159. #define TR_66_MDMA_ACCESS_MASK 0x00007c00
  160. #define TR_66_MDMA_ACCESS_SHIFT 10
  161. #define TR_66_PIO_MASK 0x000003ff
  162. #define TR_66_PIO_RECOVERY_MASK 0x000003e0
  163. #define TR_66_PIO_RECOVERY_SHIFT 5
  164. #define TR_66_PIO_ACCESS_MASK 0x0000001f
  165. #define TR_66_PIO_ACCESS_SHIFT 0
  166. /* 33Mhz cell, found in OHare, Heathrow (& Paddington) and KeyLargo
  167. * Can do pio & mdma modes, clock unit is 30ns (33Mhz)
  168. *
  169. * The access time and recovery time can be programmed. Some older
  170. * Darwin code base limit OHare to 150ns cycle time. I decided to do
  171. * the same here fore safety against broken old hardware ;)
  172. * The HalfTick bit, when set, adds half a clock (15ns) to the access
  173. * time and removes one from recovery. It's not supported on KeyLargo
  174. * implementation afaik. The E bit appears to be set for PIO mode 0 and
  175. * is used to reach long timings used in this mode.
  176. */
  177. #define TR_33_MDMA_MASK 0x003ff800
  178. #define TR_33_MDMA_RECOVERY_MASK 0x001f0000
  179. #define TR_33_MDMA_RECOVERY_SHIFT 16
  180. #define TR_33_MDMA_ACCESS_MASK 0x0000f800
  181. #define TR_33_MDMA_ACCESS_SHIFT 11
  182. #define TR_33_MDMA_HALFTICK 0x00200000
  183. #define TR_33_PIO_MASK 0x000007ff
  184. #define TR_33_PIO_E 0x00000400
  185. #define TR_33_PIO_RECOVERY_MASK 0x000003e0
  186. #define TR_33_PIO_RECOVERY_SHIFT 5
  187. #define TR_33_PIO_ACCESS_MASK 0x0000001f
  188. #define TR_33_PIO_ACCESS_SHIFT 0
  189. /*
  190. * Interrupt register definitions
  191. */
  192. #define IDE_INTR_DMA 0x80000000
  193. #define IDE_INTR_DEVICE 0x40000000
  194. /*
  195. * FCR Register on Kauai. Not sure what bit 0x4 is ...
  196. */
  197. #define KAUAI_FCR_UATA_MAGIC 0x00000004
  198. #define KAUAI_FCR_UATA_RESET_N 0x00000002
  199. #define KAUAI_FCR_UATA_ENABLE 0x00000001
  200. /* Rounded Multiword DMA timings
  201. *
  202. * I gave up finding a generic formula for all controller
  203. * types and instead, built tables based on timing values
  204. * used by Apple in Darwin's implementation.
  205. */
  206. struct mdma_timings_t {
  207. int accessTime;
  208. int recoveryTime;
  209. int cycleTime;
  210. };
  211. struct mdma_timings_t mdma_timings_33[] =
  212. {
  213. { 240, 240, 480 },
  214. { 180, 180, 360 },
  215. { 135, 135, 270 },
  216. { 120, 120, 240 },
  217. { 105, 105, 210 },
  218. { 90, 90, 180 },
  219. { 75, 75, 150 },
  220. { 75, 45, 120 },
  221. { 0, 0, 0 }
  222. };
  223. struct mdma_timings_t mdma_timings_33k[] =
  224. {
  225. { 240, 240, 480 },
  226. { 180, 180, 360 },
  227. { 150, 150, 300 },
  228. { 120, 120, 240 },
  229. { 90, 120, 210 },
  230. { 90, 90, 180 },
  231. { 90, 60, 150 },
  232. { 90, 30, 120 },
  233. { 0, 0, 0 }
  234. };
  235. struct mdma_timings_t mdma_timings_66[] =
  236. {
  237. { 240, 240, 480 },
  238. { 180, 180, 360 },
  239. { 135, 135, 270 },
  240. { 120, 120, 240 },
  241. { 105, 105, 210 },
  242. { 90, 90, 180 },
  243. { 90, 75, 165 },
  244. { 75, 45, 120 },
  245. { 0, 0, 0 }
  246. };
  247. /* KeyLargo ATA-4 Ultra DMA timings (rounded) */
  248. struct {
  249. int addrSetup; /* ??? */
  250. int rdy2pause;
  251. int wrDataSetup;
  252. } kl66_udma_timings[] =
  253. {
  254. { 0, 180, 120 }, /* Mode 0 */
  255. { 0, 150, 90 }, /* 1 */
  256. { 0, 120, 60 }, /* 2 */
  257. { 0, 90, 45 }, /* 3 */
  258. { 0, 90, 30 } /* 4 */
  259. };
  260. /* UniNorth 2 ATA/100 timings */
  261. struct kauai_timing {
  262. int cycle_time;
  263. u32 timing_reg;
  264. };
  265. static struct kauai_timing kauai_pio_timings[] =
  266. {
  267. { 930 , 0x08000fff },
  268. { 600 , 0x08000a92 },
  269. { 383 , 0x0800060f },
  270. { 360 , 0x08000492 },
  271. { 330 , 0x0800048f },
  272. { 300 , 0x080003cf },
  273. { 270 , 0x080003cc },
  274. { 240 , 0x0800038b },
  275. { 239 , 0x0800030c },
  276. { 180 , 0x05000249 },
  277. { 120 , 0x04000148 },
  278. { 0 , 0 },
  279. };
  280. static struct kauai_timing kauai_mdma_timings[] =
  281. {
  282. { 1260 , 0x00fff000 },
  283. { 480 , 0x00618000 },
  284. { 360 , 0x00492000 },
  285. { 270 , 0x0038e000 },
  286. { 240 , 0x0030c000 },
  287. { 210 , 0x002cb000 },
  288. { 180 , 0x00249000 },
  289. { 150 , 0x00209000 },
  290. { 120 , 0x00148000 },
  291. { 0 , 0 },
  292. };
  293. static struct kauai_timing kauai_udma_timings[] =
  294. {
  295. { 120 , 0x000070c0 },
  296. { 90 , 0x00005d80 },
  297. { 60 , 0x00004a60 },
  298. { 45 , 0x00003a50 },
  299. { 30 , 0x00002a30 },
  300. { 20 , 0x00002921 },
  301. { 0 , 0 },
  302. };
  303. static struct kauai_timing shasta_pio_timings[] =
  304. {
  305. { 930 , 0x08000fff },
  306. { 600 , 0x0A000c97 },
  307. { 383 , 0x07000712 },
  308. { 360 , 0x040003cd },
  309. { 330 , 0x040003cd },
  310. { 300 , 0x040003cd },
  311. { 270 , 0x040003cd },
  312. { 240 , 0x040003cd },
  313. { 239 , 0x040003cd },
  314. { 180 , 0x0400028b },
  315. { 120 , 0x0400010a },
  316. { 0 , 0 },
  317. };
  318. static struct kauai_timing shasta_mdma_timings[] =
  319. {
  320. { 1260 , 0x00fff000 },
  321. { 480 , 0x00820800 },
  322. { 360 , 0x00820800 },
  323. { 270 , 0x00820800 },
  324. { 240 , 0x00820800 },
  325. { 210 , 0x00820800 },
  326. { 180 , 0x00820800 },
  327. { 150 , 0x0028b000 },
  328. { 120 , 0x001ca000 },
  329. { 0 , 0 },
  330. };
  331. static struct kauai_timing shasta_udma133_timings[] =
  332. {
  333. { 120 , 0x00035901, },
  334. { 90 , 0x000348b1, },
  335. { 60 , 0x00033881, },
  336. { 45 , 0x00033861, },
  337. { 30 , 0x00033841, },
  338. { 20 , 0x00033031, },
  339. { 15 , 0x00033021, },
  340. { 0 , 0 },
  341. };
  342. static inline u32
  343. kauai_lookup_timing(struct kauai_timing* table, int cycle_time)
  344. {
  345. int i;
  346. for (i=0; table[i].cycle_time; i++)
  347. if (cycle_time > table[i+1].cycle_time)
  348. return table[i].timing_reg;
  349. BUG();
  350. return 0;
  351. }
  352. /* allow up to 256 DBDMA commands per xfer */
  353. #define MAX_DCMDS 256
  354. /*
  355. * Wait 1s for disk to answer on IDE bus after a hard reset
  356. * of the device (via GPIO/FCR).
  357. *
  358. * Some devices seem to "pollute" the bus even after dropping
  359. * the BSY bit (typically some combo drives slave on the UDMA
  360. * bus) after a hard reset. Since we hard reset all drives on
  361. * KeyLargo ATA66, we have to keep that delay around. I may end
  362. * up not hard resetting anymore on these and keep the delay only
  363. * for older interfaces instead (we have to reset when coming
  364. * from MacOS...) --BenH.
  365. */
  366. #define IDE_WAKEUP_DELAY (1*HZ)
  367. static int pmac_ide_init_dma(ide_hwif_t *, const struct ide_port_info *);
  368. #define PMAC_IDE_REG(x) \
  369. ((void __iomem *)((drive)->hwif->io_ports.data_addr + (x)))
  370. /*
  371. * Apply the timings of the proper unit (master/slave) to the shared
  372. * timing register when selecting that unit. This version is for
  373. * ASICs with a single timing register
  374. */
  375. static void pmac_ide_apply_timings(ide_drive_t *drive)
  376. {
  377. ide_hwif_t *hwif = drive->hwif;
  378. pmac_ide_hwif_t *pmif =
  379. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  380. if (drive->dn & 1)
  381. writel(pmif->timings[1], PMAC_IDE_REG(IDE_TIMING_CONFIG));
  382. else
  383. writel(pmif->timings[0], PMAC_IDE_REG(IDE_TIMING_CONFIG));
  384. (void)readl(PMAC_IDE_REG(IDE_TIMING_CONFIG));
  385. }
  386. /*
  387. * Apply the timings of the proper unit (master/slave) to the shared
  388. * timing register when selecting that unit. This version is for
  389. * ASICs with a dual timing register (Kauai)
  390. */
  391. static void pmac_ide_kauai_apply_timings(ide_drive_t *drive)
  392. {
  393. ide_hwif_t *hwif = drive->hwif;
  394. pmac_ide_hwif_t *pmif =
  395. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  396. if (drive->dn & 1) {
  397. writel(pmif->timings[1], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
  398. writel(pmif->timings[3], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG));
  399. } else {
  400. writel(pmif->timings[0], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
  401. writel(pmif->timings[2], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG));
  402. }
  403. (void)readl(PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
  404. }
  405. /*
  406. * Force an update of controller timing values for a given drive
  407. */
  408. static void
  409. pmac_ide_do_update_timings(ide_drive_t *drive)
  410. {
  411. ide_hwif_t *hwif = drive->hwif;
  412. pmac_ide_hwif_t *pmif =
  413. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  414. if (pmif->kind == controller_sh_ata6 ||
  415. pmif->kind == controller_un_ata6 ||
  416. pmif->kind == controller_k2_ata6)
  417. pmac_ide_kauai_apply_timings(drive);
  418. else
  419. pmac_ide_apply_timings(drive);
  420. }
  421. static void pmac_dev_select(ide_drive_t *drive)
  422. {
  423. pmac_ide_apply_timings(drive);
  424. writeb(drive->select | ATA_DEVICE_OBS,
  425. (void __iomem *)drive->hwif->io_ports.device_addr);
  426. }
  427. static void pmac_kauai_dev_select(ide_drive_t *drive)
  428. {
  429. pmac_ide_kauai_apply_timings(drive);
  430. writeb(drive->select | ATA_DEVICE_OBS,
  431. (void __iomem *)drive->hwif->io_ports.device_addr);
  432. }
  433. static void pmac_exec_command(ide_hwif_t *hwif, u8 cmd)
  434. {
  435. writeb(cmd, (void __iomem *)hwif->io_ports.command_addr);
  436. (void)readl((void __iomem *)(hwif->io_ports.data_addr
  437. + IDE_TIMING_CONFIG));
  438. }
  439. static void pmac_write_devctl(ide_hwif_t *hwif, u8 ctl)
  440. {
  441. writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr);
  442. (void)readl((void __iomem *)(hwif->io_ports.data_addr
  443. + IDE_TIMING_CONFIG));
  444. }
  445. /*
  446. * Old tuning functions (called on hdparm -p), sets up drive PIO timings
  447. */
  448. static void pmac_ide_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  449. {
  450. pmac_ide_hwif_t *pmif =
  451. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  452. const u8 pio = drive->pio_mode - XFER_PIO_0;
  453. struct ide_timing *tim = ide_timing_find_mode(XFER_PIO_0 + pio);
  454. u32 *timings, t;
  455. unsigned accessTicks, recTicks;
  456. unsigned accessTime, recTime;
  457. unsigned int cycle_time;
  458. /* which drive is it ? */
  459. timings = &pmif->timings[drive->dn & 1];
  460. t = *timings;
  461. cycle_time = ide_pio_cycle_time(drive, pio);
  462. switch (pmif->kind) {
  463. case controller_sh_ata6: {
  464. /* 133Mhz cell */
  465. u32 tr = kauai_lookup_timing(shasta_pio_timings, cycle_time);
  466. t = (t & ~TR_133_PIOREG_PIO_MASK) | tr;
  467. break;
  468. }
  469. case controller_un_ata6:
  470. case controller_k2_ata6: {
  471. /* 100Mhz cell */
  472. u32 tr = kauai_lookup_timing(kauai_pio_timings, cycle_time);
  473. t = (t & ~TR_100_PIOREG_PIO_MASK) | tr;
  474. break;
  475. }
  476. case controller_kl_ata4:
  477. /* 66Mhz cell */
  478. recTime = cycle_time - tim->active - tim->setup;
  479. recTime = max(recTime, 150U);
  480. accessTime = tim->active;
  481. accessTime = max(accessTime, 150U);
  482. accessTicks = SYSCLK_TICKS_66(accessTime);
  483. accessTicks = min(accessTicks, 0x1fU);
  484. recTicks = SYSCLK_TICKS_66(recTime);
  485. recTicks = min(recTicks, 0x1fU);
  486. t = (t & ~TR_66_PIO_MASK) |
  487. (accessTicks << TR_66_PIO_ACCESS_SHIFT) |
  488. (recTicks << TR_66_PIO_RECOVERY_SHIFT);
  489. break;
  490. default: {
  491. /* 33Mhz cell */
  492. int ebit = 0;
  493. recTime = cycle_time - tim->active - tim->setup;
  494. recTime = max(recTime, 150U);
  495. accessTime = tim->active;
  496. accessTime = max(accessTime, 150U);
  497. accessTicks = SYSCLK_TICKS(accessTime);
  498. accessTicks = min(accessTicks, 0x1fU);
  499. accessTicks = max(accessTicks, 4U);
  500. recTicks = SYSCLK_TICKS(recTime);
  501. recTicks = min(recTicks, 0x1fU);
  502. recTicks = max(recTicks, 5U) - 4;
  503. if (recTicks > 9) {
  504. recTicks--; /* guess, but it's only for PIO0, so... */
  505. ebit = 1;
  506. }
  507. t = (t & ~TR_33_PIO_MASK) |
  508. (accessTicks << TR_33_PIO_ACCESS_SHIFT) |
  509. (recTicks << TR_33_PIO_RECOVERY_SHIFT);
  510. if (ebit)
  511. t |= TR_33_PIO_E;
  512. break;
  513. }
  514. }
  515. #ifdef IDE_PMAC_DEBUG
  516. printk(KERN_ERR "%s: Set PIO timing for mode %d, reg: 0x%08x\n",
  517. drive->name, pio, *timings);
  518. #endif
  519. *timings = t;
  520. pmac_ide_do_update_timings(drive);
  521. }
  522. /*
  523. * Calculate KeyLargo ATA/66 UDMA timings
  524. */
  525. static int
  526. set_timings_udma_ata4(u32 *timings, u8 speed)
  527. {
  528. unsigned rdyToPauseTicks, wrDataSetupTicks, addrTicks;
  529. if (speed > XFER_UDMA_4)
  530. return 1;
  531. rdyToPauseTicks = SYSCLK_TICKS_66(kl66_udma_timings[speed & 0xf].rdy2pause);
  532. wrDataSetupTicks = SYSCLK_TICKS_66(kl66_udma_timings[speed & 0xf].wrDataSetup);
  533. addrTicks = SYSCLK_TICKS_66(kl66_udma_timings[speed & 0xf].addrSetup);
  534. *timings = ((*timings) & ~(TR_66_UDMA_MASK | TR_66_MDMA_MASK)) |
  535. (wrDataSetupTicks << TR_66_UDMA_WRDATASETUP_SHIFT) |
  536. (rdyToPauseTicks << TR_66_UDMA_RDY2PAUS_SHIFT) |
  537. (addrTicks <<TR_66_UDMA_ADDRSETUP_SHIFT) |
  538. TR_66_UDMA_EN;
  539. #ifdef IDE_PMAC_DEBUG
  540. printk(KERN_ERR "ide_pmac: Set UDMA timing for mode %d, reg: 0x%08x\n",
  541. speed & 0xf, *timings);
  542. #endif
  543. return 0;
  544. }
  545. /*
  546. * Calculate Kauai ATA/100 UDMA timings
  547. */
  548. static int
  549. set_timings_udma_ata6(u32 *pio_timings, u32 *ultra_timings, u8 speed)
  550. {
  551. struct ide_timing *t = ide_timing_find_mode(speed);
  552. u32 tr;
  553. if (speed > XFER_UDMA_5 || t == NULL)
  554. return 1;
  555. tr = kauai_lookup_timing(kauai_udma_timings, (int)t->udma);
  556. *ultra_timings = ((*ultra_timings) & ~TR_100_UDMAREG_UDMA_MASK) | tr;
  557. *ultra_timings = (*ultra_timings) | TR_100_UDMAREG_UDMA_EN;
  558. return 0;
  559. }
  560. /*
  561. * Calculate Shasta ATA/133 UDMA timings
  562. */
  563. static int
  564. set_timings_udma_shasta(u32 *pio_timings, u32 *ultra_timings, u8 speed)
  565. {
  566. struct ide_timing *t = ide_timing_find_mode(speed);
  567. u32 tr;
  568. if (speed > XFER_UDMA_6 || t == NULL)
  569. return 1;
  570. tr = kauai_lookup_timing(shasta_udma133_timings, (int)t->udma);
  571. *ultra_timings = ((*ultra_timings) & ~TR_133_UDMAREG_UDMA_MASK) | tr;
  572. *ultra_timings = (*ultra_timings) | TR_133_UDMAREG_UDMA_EN;
  573. return 0;
  574. }
  575. /*
  576. * Calculate MDMA timings for all cells
  577. */
  578. static void
  579. set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2,
  580. u8 speed)
  581. {
  582. u16 *id = drive->id;
  583. int cycleTime, accessTime = 0, recTime = 0;
  584. unsigned accessTicks, recTicks;
  585. struct mdma_timings_t* tm = NULL;
  586. int i;
  587. /* Get default cycle time for mode */
  588. switch(speed & 0xf) {
  589. case 0: cycleTime = 480; break;
  590. case 1: cycleTime = 150; break;
  591. case 2: cycleTime = 120; break;
  592. default:
  593. BUG();
  594. break;
  595. }
  596. /* Check if drive provides explicit DMA cycle time */
  597. if ((id[ATA_ID_FIELD_VALID] & 2) && id[ATA_ID_EIDE_DMA_TIME])
  598. cycleTime = max_t(int, id[ATA_ID_EIDE_DMA_TIME], cycleTime);
  599. /* OHare limits according to some old Apple sources */
  600. if ((intf_type == controller_ohare) && (cycleTime < 150))
  601. cycleTime = 150;
  602. /* Get the proper timing array for this controller */
  603. switch(intf_type) {
  604. case controller_sh_ata6:
  605. case controller_un_ata6:
  606. case controller_k2_ata6:
  607. break;
  608. case controller_kl_ata4:
  609. tm = mdma_timings_66;
  610. break;
  611. case controller_kl_ata3:
  612. tm = mdma_timings_33k;
  613. break;
  614. default:
  615. tm = mdma_timings_33;
  616. break;
  617. }
  618. if (tm != NULL) {
  619. /* Lookup matching access & recovery times */
  620. i = -1;
  621. for (;;) {
  622. if (tm[i+1].cycleTime < cycleTime)
  623. break;
  624. i++;
  625. }
  626. cycleTime = tm[i].cycleTime;
  627. accessTime = tm[i].accessTime;
  628. recTime = tm[i].recoveryTime;
  629. #ifdef IDE_PMAC_DEBUG
  630. printk(KERN_ERR "%s: MDMA, cycleTime: %d, accessTime: %d, recTime: %d\n",
  631. drive->name, cycleTime, accessTime, recTime);
  632. #endif
  633. }
  634. switch(intf_type) {
  635. case controller_sh_ata6: {
  636. /* 133Mhz cell */
  637. u32 tr = kauai_lookup_timing(shasta_mdma_timings, cycleTime);
  638. *timings = ((*timings) & ~TR_133_PIOREG_MDMA_MASK) | tr;
  639. *timings2 = (*timings2) & ~TR_133_UDMAREG_UDMA_EN;
  640. }
  641. case controller_un_ata6:
  642. case controller_k2_ata6: {
  643. /* 100Mhz cell */
  644. u32 tr = kauai_lookup_timing(kauai_mdma_timings, cycleTime);
  645. *timings = ((*timings) & ~TR_100_PIOREG_MDMA_MASK) | tr;
  646. *timings2 = (*timings2) & ~TR_100_UDMAREG_UDMA_EN;
  647. }
  648. break;
  649. case controller_kl_ata4:
  650. /* 66Mhz cell */
  651. accessTicks = SYSCLK_TICKS_66(accessTime);
  652. accessTicks = min(accessTicks, 0x1fU);
  653. accessTicks = max(accessTicks, 0x1U);
  654. recTicks = SYSCLK_TICKS_66(recTime);
  655. recTicks = min(recTicks, 0x1fU);
  656. recTicks = max(recTicks, 0x3U);
  657. /* Clear out mdma bits and disable udma */
  658. *timings = ((*timings) & ~(TR_66_MDMA_MASK | TR_66_UDMA_MASK)) |
  659. (accessTicks << TR_66_MDMA_ACCESS_SHIFT) |
  660. (recTicks << TR_66_MDMA_RECOVERY_SHIFT);
  661. break;
  662. case controller_kl_ata3:
  663. /* 33Mhz cell on KeyLargo */
  664. accessTicks = SYSCLK_TICKS(accessTime);
  665. accessTicks = max(accessTicks, 1U);
  666. accessTicks = min(accessTicks, 0x1fU);
  667. accessTime = accessTicks * IDE_SYSCLK_NS;
  668. recTicks = SYSCLK_TICKS(recTime);
  669. recTicks = max(recTicks, 1U);
  670. recTicks = min(recTicks, 0x1fU);
  671. *timings = ((*timings) & ~TR_33_MDMA_MASK) |
  672. (accessTicks << TR_33_MDMA_ACCESS_SHIFT) |
  673. (recTicks << TR_33_MDMA_RECOVERY_SHIFT);
  674. break;
  675. default: {
  676. /* 33Mhz cell on others */
  677. int halfTick = 0;
  678. int origAccessTime = accessTime;
  679. int origRecTime = recTime;
  680. accessTicks = SYSCLK_TICKS(accessTime);
  681. accessTicks = max(accessTicks, 1U);
  682. accessTicks = min(accessTicks, 0x1fU);
  683. accessTime = accessTicks * IDE_SYSCLK_NS;
  684. recTicks = SYSCLK_TICKS(recTime);
  685. recTicks = max(recTicks, 2U) - 1;
  686. recTicks = min(recTicks, 0x1fU);
  687. recTime = (recTicks + 1) * IDE_SYSCLK_NS;
  688. if ((accessTicks > 1) &&
  689. ((accessTime - IDE_SYSCLK_NS/2) >= origAccessTime) &&
  690. ((recTime - IDE_SYSCLK_NS/2) >= origRecTime)) {
  691. halfTick = 1;
  692. accessTicks--;
  693. }
  694. *timings = ((*timings) & ~TR_33_MDMA_MASK) |
  695. (accessTicks << TR_33_MDMA_ACCESS_SHIFT) |
  696. (recTicks << TR_33_MDMA_RECOVERY_SHIFT);
  697. if (halfTick)
  698. *timings |= TR_33_MDMA_HALFTICK;
  699. }
  700. }
  701. #ifdef IDE_PMAC_DEBUG
  702. printk(KERN_ERR "%s: Set MDMA timing for mode %d, reg: 0x%08x\n",
  703. drive->name, speed & 0xf, *timings);
  704. #endif
  705. }
  706. static void pmac_ide_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  707. {
  708. pmac_ide_hwif_t *pmif =
  709. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  710. int ret = 0;
  711. u32 *timings, *timings2, tl[2];
  712. u8 unit = drive->dn & 1;
  713. const u8 speed = drive->dma_mode;
  714. timings = &pmif->timings[unit];
  715. timings2 = &pmif->timings[unit+2];
  716. /* Copy timings to local image */
  717. tl[0] = *timings;
  718. tl[1] = *timings2;
  719. if (speed >= XFER_UDMA_0) {
  720. if (pmif->kind == controller_kl_ata4)
  721. ret = set_timings_udma_ata4(&tl[0], speed);
  722. else if (pmif->kind == controller_un_ata6
  723. || pmif->kind == controller_k2_ata6)
  724. ret = set_timings_udma_ata6(&tl[0], &tl[1], speed);
  725. else if (pmif->kind == controller_sh_ata6)
  726. ret = set_timings_udma_shasta(&tl[0], &tl[1], speed);
  727. else
  728. ret = -1;
  729. } else
  730. set_timings_mdma(drive, pmif->kind, &tl[0], &tl[1], speed);
  731. if (ret)
  732. return;
  733. /* Apply timings to controller */
  734. *timings = tl[0];
  735. *timings2 = tl[1];
  736. pmac_ide_do_update_timings(drive);
  737. }
  738. /*
  739. * Blast some well known "safe" values to the timing registers at init or
  740. * wakeup from sleep time, before we do real calculation
  741. */
  742. static void
  743. sanitize_timings(pmac_ide_hwif_t *pmif)
  744. {
  745. unsigned int value, value2 = 0;
  746. switch(pmif->kind) {
  747. case controller_sh_ata6:
  748. value = 0x0a820c97;
  749. value2 = 0x00033031;
  750. break;
  751. case controller_un_ata6:
  752. case controller_k2_ata6:
  753. value = 0x08618a92;
  754. value2 = 0x00002921;
  755. break;
  756. case controller_kl_ata4:
  757. value = 0x0008438c;
  758. break;
  759. case controller_kl_ata3:
  760. value = 0x00084526;
  761. break;
  762. case controller_heathrow:
  763. case controller_ohare:
  764. default:
  765. value = 0x00074526;
  766. break;
  767. }
  768. pmif->timings[0] = pmif->timings[1] = value;
  769. pmif->timings[2] = pmif->timings[3] = value2;
  770. }
  771. static int on_media_bay(pmac_ide_hwif_t *pmif)
  772. {
  773. return pmif->mdev && pmif->mdev->media_bay != NULL;
  774. }
  775. /* Suspend call back, should be called after the child devices
  776. * have actually been suspended
  777. */
  778. static int pmac_ide_do_suspend(pmac_ide_hwif_t *pmif)
  779. {
  780. /* We clear the timings */
  781. pmif->timings[0] = 0;
  782. pmif->timings[1] = 0;
  783. disable_irq(pmif->irq);
  784. /* The media bay will handle itself just fine */
  785. if (on_media_bay(pmif))
  786. return 0;
  787. /* Kauai has bus control FCRs directly here */
  788. if (pmif->kauai_fcr) {
  789. u32 fcr = readl(pmif->kauai_fcr);
  790. fcr &= ~(KAUAI_FCR_UATA_RESET_N | KAUAI_FCR_UATA_ENABLE);
  791. writel(fcr, pmif->kauai_fcr);
  792. }
  793. /* Disable the bus on older machines and the cell on kauai */
  794. ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, pmif->node, pmif->aapl_bus_id,
  795. 0);
  796. return 0;
  797. }
  798. /* Resume call back, should be called before the child devices
  799. * are resumed
  800. */
  801. static int pmac_ide_do_resume(pmac_ide_hwif_t *pmif)
  802. {
  803. /* Hard reset & re-enable controller (do we really need to reset ? -BenH) */
  804. if (!on_media_bay(pmif)) {
  805. ppc_md.feature_call(PMAC_FTR_IDE_RESET, pmif->node, pmif->aapl_bus_id, 1);
  806. ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, pmif->node, pmif->aapl_bus_id, 1);
  807. msleep(10);
  808. ppc_md.feature_call(PMAC_FTR_IDE_RESET, pmif->node, pmif->aapl_bus_id, 0);
  809. /* Kauai has it different */
  810. if (pmif->kauai_fcr) {
  811. u32 fcr = readl(pmif->kauai_fcr);
  812. fcr |= KAUAI_FCR_UATA_RESET_N | KAUAI_FCR_UATA_ENABLE;
  813. writel(fcr, pmif->kauai_fcr);
  814. }
  815. msleep(jiffies_to_msecs(IDE_WAKEUP_DELAY));
  816. }
  817. /* Sanitize drive timings */
  818. sanitize_timings(pmif);
  819. enable_irq(pmif->irq);
  820. return 0;
  821. }
  822. static u8 pmac_ide_cable_detect(ide_hwif_t *hwif)
  823. {
  824. pmac_ide_hwif_t *pmif =
  825. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  826. struct device_node *np = pmif->node;
  827. const char *cable = of_get_property(np, "cable-type", NULL);
  828. struct device_node *root = of_find_node_by_path("/");
  829. const char *model = of_get_property(root, "model", NULL);
  830. /* Get cable type from device-tree. */
  831. if (cable && !strncmp(cable, "80-", 3)) {
  832. /* Some drives fail to detect 80c cable in PowerBook */
  833. /* These machine use proprietary short IDE cable anyway */
  834. if (!strncmp(model, "PowerBook", 9))
  835. return ATA_CBL_PATA40_SHORT;
  836. else
  837. return ATA_CBL_PATA80;
  838. }
  839. /*
  840. * G5's seem to have incorrect cable type in device-tree.
  841. * Let's assume they have a 80 conductor cable, this seem
  842. * to be always the case unless the user mucked around.
  843. */
  844. if (of_device_is_compatible(np, "K2-UATA") ||
  845. of_device_is_compatible(np, "shasta-ata"))
  846. return ATA_CBL_PATA80;
  847. return ATA_CBL_PATA40;
  848. }
  849. static void pmac_ide_init_dev(ide_drive_t *drive)
  850. {
  851. ide_hwif_t *hwif = drive->hwif;
  852. pmac_ide_hwif_t *pmif =
  853. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  854. if (on_media_bay(pmif)) {
  855. if (check_media_bay(pmif->mdev->media_bay) == MB_CD) {
  856. drive->dev_flags &= ~IDE_DFLAG_NOPROBE;
  857. return;
  858. }
  859. drive->dev_flags |= IDE_DFLAG_NOPROBE;
  860. }
  861. }
  862. static const struct ide_tp_ops pmac_tp_ops = {
  863. .exec_command = pmac_exec_command,
  864. .read_status = ide_read_status,
  865. .read_altstatus = ide_read_altstatus,
  866. .write_devctl = pmac_write_devctl,
  867. .dev_select = pmac_dev_select,
  868. .tf_load = ide_tf_load,
  869. .tf_read = ide_tf_read,
  870. .input_data = ide_input_data,
  871. .output_data = ide_output_data,
  872. };
  873. static const struct ide_tp_ops pmac_ata6_tp_ops = {
  874. .exec_command = pmac_exec_command,
  875. .read_status = ide_read_status,
  876. .read_altstatus = ide_read_altstatus,
  877. .write_devctl = pmac_write_devctl,
  878. .dev_select = pmac_kauai_dev_select,
  879. .tf_load = ide_tf_load,
  880. .tf_read = ide_tf_read,
  881. .input_data = ide_input_data,
  882. .output_data = ide_output_data,
  883. };
  884. static const struct ide_port_ops pmac_ide_ata4_port_ops = {
  885. .init_dev = pmac_ide_init_dev,
  886. .set_pio_mode = pmac_ide_set_pio_mode,
  887. .set_dma_mode = pmac_ide_set_dma_mode,
  888. .cable_detect = pmac_ide_cable_detect,
  889. };
  890. static const struct ide_port_ops pmac_ide_port_ops = {
  891. .init_dev = pmac_ide_init_dev,
  892. .set_pio_mode = pmac_ide_set_pio_mode,
  893. .set_dma_mode = pmac_ide_set_dma_mode,
  894. };
  895. static const struct ide_dma_ops pmac_dma_ops;
  896. static const struct ide_port_info pmac_port_info = {
  897. .name = DRV_NAME,
  898. .init_dma = pmac_ide_init_dma,
  899. .chipset = ide_pmac,
  900. .tp_ops = &pmac_tp_ops,
  901. .port_ops = &pmac_ide_port_ops,
  902. .dma_ops = &pmac_dma_ops,
  903. .host_flags = IDE_HFLAG_SET_PIO_MODE_KEEP_DMA |
  904. IDE_HFLAG_POST_SET_MODE |
  905. IDE_HFLAG_MMIO |
  906. IDE_HFLAG_UNMASK_IRQS,
  907. .pio_mask = ATA_PIO4,
  908. .mwdma_mask = ATA_MWDMA2,
  909. };
  910. /*
  911. * Setup, register & probe an IDE channel driven by this driver, this is
  912. * called by one of the 2 probe functions (macio or PCI).
  913. */
  914. static int __devinit pmac_ide_setup_device(pmac_ide_hwif_t *pmif,
  915. struct ide_hw *hw)
  916. {
  917. struct device_node *np = pmif->node;
  918. const int *bidp;
  919. struct ide_host *host;
  920. ide_hwif_t *hwif;
  921. struct ide_hw *hws[] = { hw };
  922. struct ide_port_info d = pmac_port_info;
  923. int rc;
  924. pmif->broken_dma = pmif->broken_dma_warn = 0;
  925. if (of_device_is_compatible(np, "shasta-ata")) {
  926. pmif->kind = controller_sh_ata6;
  927. d.tp_ops = &pmac_ata6_tp_ops;
  928. d.port_ops = &pmac_ide_ata4_port_ops;
  929. d.udma_mask = ATA_UDMA6;
  930. } else if (of_device_is_compatible(np, "kauai-ata")) {
  931. pmif->kind = controller_un_ata6;
  932. d.tp_ops = &pmac_ata6_tp_ops;
  933. d.port_ops = &pmac_ide_ata4_port_ops;
  934. d.udma_mask = ATA_UDMA5;
  935. } else if (of_device_is_compatible(np, "K2-UATA")) {
  936. pmif->kind = controller_k2_ata6;
  937. d.tp_ops = &pmac_ata6_tp_ops;
  938. d.port_ops = &pmac_ide_ata4_port_ops;
  939. d.udma_mask = ATA_UDMA5;
  940. } else if (of_device_is_compatible(np, "keylargo-ata")) {
  941. if (strcmp(np->name, "ata-4") == 0) {
  942. pmif->kind = controller_kl_ata4;
  943. d.port_ops = &pmac_ide_ata4_port_ops;
  944. d.udma_mask = ATA_UDMA4;
  945. } else
  946. pmif->kind = controller_kl_ata3;
  947. } else if (of_device_is_compatible(np, "heathrow-ata")) {
  948. pmif->kind = controller_heathrow;
  949. } else {
  950. pmif->kind = controller_ohare;
  951. pmif->broken_dma = 1;
  952. }
  953. bidp = of_get_property(np, "AAPL,bus-id", NULL);
  954. pmif->aapl_bus_id = bidp ? *bidp : 0;
  955. /* On Kauai-type controllers, we make sure the FCR is correct */
  956. if (pmif->kauai_fcr)
  957. writel(KAUAI_FCR_UATA_MAGIC |
  958. KAUAI_FCR_UATA_RESET_N |
  959. KAUAI_FCR_UATA_ENABLE, pmif->kauai_fcr);
  960. /* Make sure we have sane timings */
  961. sanitize_timings(pmif);
  962. /* If we are on a media bay, wait for it to settle and lock it */
  963. if (pmif->mdev)
  964. lock_media_bay(pmif->mdev->media_bay);
  965. host = ide_host_alloc(&d, hws, 1);
  966. if (host == NULL) {
  967. rc = -ENOMEM;
  968. goto bail;
  969. }
  970. hwif = pmif->hwif = host->ports[0];
  971. if (on_media_bay(pmif)) {
  972. /* Fixup bus ID for media bay */
  973. if (!bidp)
  974. pmif->aapl_bus_id = 1;
  975. } else if (pmif->kind == controller_ohare) {
  976. /* The code below is having trouble on some ohare machines
  977. * (timing related ?). Until I can put my hand on one of these
  978. * units, I keep the old way
  979. */
  980. ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, np, 0, 1);
  981. } else {
  982. /* This is necessary to enable IDE when net-booting */
  983. ppc_md.feature_call(PMAC_FTR_IDE_RESET, np, pmif->aapl_bus_id, 1);
  984. ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, np, pmif->aapl_bus_id, 1);
  985. msleep(10);
  986. ppc_md.feature_call(PMAC_FTR_IDE_RESET, np, pmif->aapl_bus_id, 0);
  987. msleep(jiffies_to_msecs(IDE_WAKEUP_DELAY));
  988. }
  989. printk(KERN_INFO DRV_NAME ": Found Apple %s controller (%s), "
  990. "bus ID %d%s, irq %d\n", model_name[pmif->kind],
  991. pmif->mdev ? "macio" : "PCI", pmif->aapl_bus_id,
  992. on_media_bay(pmif) ? " (mediabay)" : "", hw->irq);
  993. rc = ide_host_register(host, &d, hws);
  994. if (rc)
  995. pmif->hwif = NULL;
  996. if (pmif->mdev)
  997. unlock_media_bay(pmif->mdev->media_bay);
  998. bail:
  999. if (rc && host)
  1000. ide_host_free(host);
  1001. return rc;
  1002. }
  1003. static void __devinit pmac_ide_init_ports(struct ide_hw *hw, unsigned long base)
  1004. {
  1005. int i;
  1006. for (i = 0; i < 8; ++i)
  1007. hw->io_ports_array[i] = base + i * 0x10;
  1008. hw->io_ports.ctl_addr = base + 0x160;
  1009. }
  1010. /*
  1011. * Attach to a macio probed interface
  1012. */
  1013. static int __devinit
  1014. pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
  1015. {
  1016. void __iomem *base;
  1017. unsigned long regbase;
  1018. pmac_ide_hwif_t *pmif;
  1019. int irq, rc;
  1020. struct ide_hw hw;
  1021. pmif = kzalloc(sizeof(*pmif), GFP_KERNEL);
  1022. if (pmif == NULL)
  1023. return -ENOMEM;
  1024. if (macio_resource_count(mdev) == 0) {
  1025. printk(KERN_WARNING "ide-pmac: no address for %s\n",
  1026. mdev->ofdev.node->full_name);
  1027. rc = -ENXIO;
  1028. goto out_free_pmif;
  1029. }
  1030. /* Request memory resource for IO ports */
  1031. if (macio_request_resource(mdev, 0, "ide-pmac (ports)")) {
  1032. printk(KERN_ERR "ide-pmac: can't request MMIO resource for "
  1033. "%s!\n", mdev->ofdev.node->full_name);
  1034. rc = -EBUSY;
  1035. goto out_free_pmif;
  1036. }
  1037. /* XXX This is bogus. Should be fixed in the registry by checking
  1038. * the kind of host interrupt controller, a bit like gatwick
  1039. * fixes in irq.c. That works well enough for the single case
  1040. * where that happens though...
  1041. */
  1042. if (macio_irq_count(mdev) == 0) {
  1043. printk(KERN_WARNING "ide-pmac: no intrs for device %s, using "
  1044. "13\n", mdev->ofdev.node->full_name);
  1045. irq = irq_create_mapping(NULL, 13);
  1046. } else
  1047. irq = macio_irq(mdev, 0);
  1048. base = ioremap(macio_resource_start(mdev, 0), 0x400);
  1049. regbase = (unsigned long) base;
  1050. pmif->mdev = mdev;
  1051. pmif->node = mdev->ofdev.node;
  1052. pmif->regbase = regbase;
  1053. pmif->irq = irq;
  1054. pmif->kauai_fcr = NULL;
  1055. if (macio_resource_count(mdev) >= 2) {
  1056. if (macio_request_resource(mdev, 1, "ide-pmac (dma)"))
  1057. printk(KERN_WARNING "ide-pmac: can't request DMA "
  1058. "resource for %s!\n",
  1059. mdev->ofdev.node->full_name);
  1060. else
  1061. pmif->dma_regs = ioremap(macio_resource_start(mdev, 1), 0x1000);
  1062. } else
  1063. pmif->dma_regs = NULL;
  1064. dev_set_drvdata(&mdev->ofdev.dev, pmif);
  1065. memset(&hw, 0, sizeof(hw));
  1066. pmac_ide_init_ports(&hw, pmif->regbase);
  1067. hw.irq = irq;
  1068. hw.dev = &mdev->bus->pdev->dev;
  1069. hw.parent = &mdev->ofdev.dev;
  1070. rc = pmac_ide_setup_device(pmif, &hw);
  1071. if (rc != 0) {
  1072. /* The inteface is released to the common IDE layer */
  1073. dev_set_drvdata(&mdev->ofdev.dev, NULL);
  1074. iounmap(base);
  1075. if (pmif->dma_regs) {
  1076. iounmap(pmif->dma_regs);
  1077. macio_release_resource(mdev, 1);
  1078. }
  1079. macio_release_resource(mdev, 0);
  1080. kfree(pmif);
  1081. }
  1082. return rc;
  1083. out_free_pmif:
  1084. kfree(pmif);
  1085. return rc;
  1086. }
  1087. static int
  1088. pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t mesg)
  1089. {
  1090. pmac_ide_hwif_t *pmif =
  1091. (pmac_ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
  1092. int rc = 0;
  1093. if (mesg.event != mdev->ofdev.dev.power.power_state.event
  1094. && (mesg.event & PM_EVENT_SLEEP)) {
  1095. rc = pmac_ide_do_suspend(pmif);
  1096. if (rc == 0)
  1097. mdev->ofdev.dev.power.power_state = mesg;
  1098. }
  1099. return rc;
  1100. }
  1101. static int
  1102. pmac_ide_macio_resume(struct macio_dev *mdev)
  1103. {
  1104. pmac_ide_hwif_t *pmif =
  1105. (pmac_ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
  1106. int rc = 0;
  1107. if (mdev->ofdev.dev.power.power_state.event != PM_EVENT_ON) {
  1108. rc = pmac_ide_do_resume(pmif);
  1109. if (rc == 0)
  1110. mdev->ofdev.dev.power.power_state = PMSG_ON;
  1111. }
  1112. return rc;
  1113. }
  1114. /*
  1115. * Attach to a PCI probed interface
  1116. */
  1117. static int __devinit
  1118. pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
  1119. {
  1120. struct device_node *np;
  1121. pmac_ide_hwif_t *pmif;
  1122. void __iomem *base;
  1123. unsigned long rbase, rlen;
  1124. int rc;
  1125. struct ide_hw hw;
  1126. np = pci_device_to_OF_node(pdev);
  1127. if (np == NULL) {
  1128. printk(KERN_ERR "ide-pmac: cannot find MacIO node for Kauai ATA interface\n");
  1129. return -ENODEV;
  1130. }
  1131. pmif = kzalloc(sizeof(*pmif), GFP_KERNEL);
  1132. if (pmif == NULL)
  1133. return -ENOMEM;
  1134. if (pci_enable_device(pdev)) {
  1135. printk(KERN_WARNING "ide-pmac: Can't enable PCI device for "
  1136. "%s\n", np->full_name);
  1137. rc = -ENXIO;
  1138. goto out_free_pmif;
  1139. }
  1140. pci_set_master(pdev);
  1141. if (pci_request_regions(pdev, "Kauai ATA")) {
  1142. printk(KERN_ERR "ide-pmac: Cannot obtain PCI resources for "
  1143. "%s\n", np->full_name);
  1144. rc = -ENXIO;
  1145. goto out_free_pmif;
  1146. }
  1147. pmif->mdev = NULL;
  1148. pmif->node = np;
  1149. rbase = pci_resource_start(pdev, 0);
  1150. rlen = pci_resource_len(pdev, 0);
  1151. base = ioremap(rbase, rlen);
  1152. pmif->regbase = (unsigned long) base + 0x2000;
  1153. pmif->dma_regs = base + 0x1000;
  1154. pmif->kauai_fcr = base;
  1155. pmif->irq = pdev->irq;
  1156. pci_set_drvdata(pdev, pmif);
  1157. memset(&hw, 0, sizeof(hw));
  1158. pmac_ide_init_ports(&hw, pmif->regbase);
  1159. hw.irq = pdev->irq;
  1160. hw.dev = &pdev->dev;
  1161. rc = pmac_ide_setup_device(pmif, &hw);
  1162. if (rc != 0) {
  1163. /* The inteface is released to the common IDE layer */
  1164. pci_set_drvdata(pdev, NULL);
  1165. iounmap(base);
  1166. pci_release_regions(pdev);
  1167. kfree(pmif);
  1168. }
  1169. return rc;
  1170. out_free_pmif:
  1171. kfree(pmif);
  1172. return rc;
  1173. }
  1174. static int
  1175. pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
  1176. {
  1177. pmac_ide_hwif_t *pmif = (pmac_ide_hwif_t *)pci_get_drvdata(pdev);
  1178. int rc = 0;
  1179. if (mesg.event != pdev->dev.power.power_state.event
  1180. && (mesg.event & PM_EVENT_SLEEP)) {
  1181. rc = pmac_ide_do_suspend(pmif);
  1182. if (rc == 0)
  1183. pdev->dev.power.power_state = mesg;
  1184. }
  1185. return rc;
  1186. }
  1187. static int
  1188. pmac_ide_pci_resume(struct pci_dev *pdev)
  1189. {
  1190. pmac_ide_hwif_t *pmif = (pmac_ide_hwif_t *)pci_get_drvdata(pdev);
  1191. int rc = 0;
  1192. if (pdev->dev.power.power_state.event != PM_EVENT_ON) {
  1193. rc = pmac_ide_do_resume(pmif);
  1194. if (rc == 0)
  1195. pdev->dev.power.power_state = PMSG_ON;
  1196. }
  1197. return rc;
  1198. }
  1199. #ifdef CONFIG_PMAC_MEDIABAY
  1200. static void pmac_ide_macio_mb_event(struct macio_dev* mdev, int mb_state)
  1201. {
  1202. pmac_ide_hwif_t *pmif =
  1203. (pmac_ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
  1204. switch(mb_state) {
  1205. case MB_CD:
  1206. if (!pmif->hwif->present)
  1207. ide_port_scan(pmif->hwif);
  1208. break;
  1209. default:
  1210. if (pmif->hwif->present)
  1211. ide_port_unregister_devices(pmif->hwif);
  1212. }
  1213. }
  1214. #endif /* CONFIG_PMAC_MEDIABAY */
  1215. static struct of_device_id pmac_ide_macio_match[] =
  1216. {
  1217. {
  1218. .name = "IDE",
  1219. },
  1220. {
  1221. .name = "ATA",
  1222. },
  1223. {
  1224. .type = "ide",
  1225. },
  1226. {
  1227. .type = "ata",
  1228. },
  1229. {},
  1230. };
  1231. static struct macio_driver pmac_ide_macio_driver =
  1232. {
  1233. .name = "ide-pmac",
  1234. .match_table = pmac_ide_macio_match,
  1235. .probe = pmac_ide_macio_attach,
  1236. .suspend = pmac_ide_macio_suspend,
  1237. .resume = pmac_ide_macio_resume,
  1238. #ifdef CONFIG_PMAC_MEDIABAY
  1239. .mediabay_event = pmac_ide_macio_mb_event,
  1240. #endif
  1241. };
  1242. static const struct pci_device_id pmac_ide_pci_match[] = {
  1243. { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_UNI_N_ATA), 0 },
  1244. { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_IPID_ATA100), 0 },
  1245. { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_K2_ATA100), 0 },
  1246. { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_SH_ATA), 0 },
  1247. { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_IPID2_ATA), 0 },
  1248. {},
  1249. };
  1250. static struct pci_driver pmac_ide_pci_driver = {
  1251. .name = "ide-pmac",
  1252. .id_table = pmac_ide_pci_match,
  1253. .probe = pmac_ide_pci_attach,
  1254. .suspend = pmac_ide_pci_suspend,
  1255. .resume = pmac_ide_pci_resume,
  1256. };
  1257. MODULE_DEVICE_TABLE(pci, pmac_ide_pci_match);
  1258. int __init pmac_ide_probe(void)
  1259. {
  1260. int error;
  1261. if (!machine_is(powermac))
  1262. return -ENODEV;
  1263. #ifdef CONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST
  1264. error = pci_register_driver(&pmac_ide_pci_driver);
  1265. if (error)
  1266. goto out;
  1267. error = macio_register_driver(&pmac_ide_macio_driver);
  1268. if (error) {
  1269. pci_unregister_driver(&pmac_ide_pci_driver);
  1270. goto out;
  1271. }
  1272. #else
  1273. error = macio_register_driver(&pmac_ide_macio_driver);
  1274. if (error)
  1275. goto out;
  1276. error = pci_register_driver(&pmac_ide_pci_driver);
  1277. if (error) {
  1278. macio_unregister_driver(&pmac_ide_macio_driver);
  1279. goto out;
  1280. }
  1281. #endif
  1282. out:
  1283. return error;
  1284. }
  1285. /*
  1286. * pmac_ide_build_dmatable builds the DBDMA command list
  1287. * for a transfer and sets the DBDMA channel to point to it.
  1288. */
  1289. static int pmac_ide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
  1290. {
  1291. ide_hwif_t *hwif = drive->hwif;
  1292. pmac_ide_hwif_t *pmif =
  1293. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  1294. struct dbdma_cmd *table;
  1295. volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
  1296. struct scatterlist *sg;
  1297. int wr = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
  1298. int i = cmd->sg_nents, count = 0;
  1299. /* DMA table is already aligned */
  1300. table = (struct dbdma_cmd *) pmif->dma_table_cpu;
  1301. /* Make sure DMA controller is stopped (necessary ?) */
  1302. writel((RUN|PAUSE|FLUSH|WAKE|DEAD) << 16, &dma->control);
  1303. while (readl(&dma->status) & RUN)
  1304. udelay(1);
  1305. /* Build DBDMA commands list */
  1306. sg = hwif->sg_table;
  1307. while (i && sg_dma_len(sg)) {
  1308. u32 cur_addr;
  1309. u32 cur_len;
  1310. cur_addr = sg_dma_address(sg);
  1311. cur_len = sg_dma_len(sg);
  1312. if (pmif->broken_dma && cur_addr & (L1_CACHE_BYTES - 1)) {
  1313. if (pmif->broken_dma_warn == 0) {
  1314. printk(KERN_WARNING "%s: DMA on non aligned address, "
  1315. "switching to PIO on Ohare chipset\n", drive->name);
  1316. pmif->broken_dma_warn = 1;
  1317. }
  1318. return 0;
  1319. }
  1320. while (cur_len) {
  1321. unsigned int tc = (cur_len < 0xfe00)? cur_len: 0xfe00;
  1322. if (count++ >= MAX_DCMDS) {
  1323. printk(KERN_WARNING "%s: DMA table too small\n",
  1324. drive->name);
  1325. return 0;
  1326. }
  1327. st_le16(&table->command, wr? OUTPUT_MORE: INPUT_MORE);
  1328. st_le16(&table->req_count, tc);
  1329. st_le32(&table->phy_addr, cur_addr);
  1330. table->cmd_dep = 0;
  1331. table->xfer_status = 0;
  1332. table->res_count = 0;
  1333. cur_addr += tc;
  1334. cur_len -= tc;
  1335. ++table;
  1336. }
  1337. sg = sg_next(sg);
  1338. i--;
  1339. }
  1340. /* convert the last command to an input/output last command */
  1341. if (count) {
  1342. st_le16(&table[-1].command, wr? OUTPUT_LAST: INPUT_LAST);
  1343. /* add the stop command to the end of the list */
  1344. memset(table, 0, sizeof(struct dbdma_cmd));
  1345. st_le16(&table->command, DBDMA_STOP);
  1346. mb();
  1347. writel(hwif->dmatable_dma, &dma->cmdptr);
  1348. return 1;
  1349. }
  1350. printk(KERN_DEBUG "%s: empty DMA table?\n", drive->name);
  1351. return 0; /* revert to PIO for this request */
  1352. }
  1353. /*
  1354. * Prepare a DMA transfer. We build the DMA table, adjust the timings for
  1355. * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion
  1356. */
  1357. static int pmac_ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
  1358. {
  1359. ide_hwif_t *hwif = drive->hwif;
  1360. pmac_ide_hwif_t *pmif =
  1361. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  1362. u8 unit = drive->dn & 1, ata4 = (pmif->kind == controller_kl_ata4);
  1363. u8 write = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
  1364. if (pmac_ide_build_dmatable(drive, cmd) == 0)
  1365. return 1;
  1366. /* Apple adds 60ns to wrDataSetup on reads */
  1367. if (ata4 && (pmif->timings[unit] & TR_66_UDMA_EN)) {
  1368. writel(pmif->timings[unit] + (write ? 0 : 0x00800000UL),
  1369. PMAC_IDE_REG(IDE_TIMING_CONFIG));
  1370. (void)readl(PMAC_IDE_REG(IDE_TIMING_CONFIG));
  1371. }
  1372. return 0;
  1373. }
  1374. /*
  1375. * Kick the DMA controller into life after the DMA command has been issued
  1376. * to the drive.
  1377. */
  1378. static void
  1379. pmac_ide_dma_start(ide_drive_t *drive)
  1380. {
  1381. ide_hwif_t *hwif = drive->hwif;
  1382. pmac_ide_hwif_t *pmif =
  1383. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  1384. volatile struct dbdma_regs __iomem *dma;
  1385. dma = pmif->dma_regs;
  1386. writel((RUN << 16) | RUN, &dma->control);
  1387. /* Make sure it gets to the controller right now */
  1388. (void)readl(&dma->control);
  1389. }
  1390. /*
  1391. * After a DMA transfer, make sure the controller is stopped
  1392. */
  1393. static int
  1394. pmac_ide_dma_end (ide_drive_t *drive)
  1395. {
  1396. ide_hwif_t *hwif = drive->hwif;
  1397. pmac_ide_hwif_t *pmif =
  1398. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  1399. volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
  1400. u32 dstat;
  1401. dstat = readl(&dma->status);
  1402. writel(((RUN|WAKE|DEAD) << 16), &dma->control);
  1403. /* verify good dma status. we don't check for ACTIVE beeing 0. We should...
  1404. * in theory, but with ATAPI decices doing buffer underruns, that would
  1405. * cause us to disable DMA, which isn't what we want
  1406. */
  1407. return (dstat & (RUN|DEAD)) != RUN;
  1408. }
  1409. /*
  1410. * Check out that the interrupt we got was for us. We can't always know this
  1411. * for sure with those Apple interfaces (well, we could on the recent ones but
  1412. * that's not implemented yet), on the other hand, we don't have shared interrupts
  1413. * so it's not really a problem
  1414. */
  1415. static int
  1416. pmac_ide_dma_test_irq (ide_drive_t *drive)
  1417. {
  1418. ide_hwif_t *hwif = drive->hwif;
  1419. pmac_ide_hwif_t *pmif =
  1420. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  1421. volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
  1422. unsigned long status, timeout;
  1423. /* We have to things to deal with here:
  1424. *
  1425. * - The dbdma won't stop if the command was started
  1426. * but completed with an error without transferring all
  1427. * datas. This happens when bad blocks are met during
  1428. * a multi-block transfer.
  1429. *
  1430. * - The dbdma fifo hasn't yet finished flushing to
  1431. * to system memory when the disk interrupt occurs.
  1432. *
  1433. */
  1434. /* If ACTIVE is cleared, the STOP command have passed and
  1435. * transfer is complete.
  1436. */
  1437. status = readl(&dma->status);
  1438. if (!(status & ACTIVE))
  1439. return 1;
  1440. /* If dbdma didn't execute the STOP command yet, the
  1441. * active bit is still set. We consider that we aren't
  1442. * sharing interrupts (which is hopefully the case with
  1443. * those controllers) and so we just try to flush the
  1444. * channel for pending data in the fifo
  1445. */
  1446. udelay(1);
  1447. writel((FLUSH << 16) | FLUSH, &dma->control);
  1448. timeout = 0;
  1449. for (;;) {
  1450. udelay(1);
  1451. status = readl(&dma->status);
  1452. if ((status & FLUSH) == 0)
  1453. break;
  1454. if (++timeout > 100) {
  1455. printk(KERN_WARNING "ide%d, ide_dma_test_irq timeout flushing channel\n",
  1456. hwif->index);
  1457. break;
  1458. }
  1459. }
  1460. return 1;
  1461. }
  1462. static void pmac_ide_dma_host_set(ide_drive_t *drive, int on)
  1463. {
  1464. }
  1465. static void
  1466. pmac_ide_dma_lost_irq (ide_drive_t *drive)
  1467. {
  1468. ide_hwif_t *hwif = drive->hwif;
  1469. pmac_ide_hwif_t *pmif =
  1470. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  1471. volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
  1472. unsigned long status = readl(&dma->status);
  1473. printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status);
  1474. }
  1475. static const struct ide_dma_ops pmac_dma_ops = {
  1476. .dma_host_set = pmac_ide_dma_host_set,
  1477. .dma_setup = pmac_ide_dma_setup,
  1478. .dma_start = pmac_ide_dma_start,
  1479. .dma_end = pmac_ide_dma_end,
  1480. .dma_test_irq = pmac_ide_dma_test_irq,
  1481. .dma_lost_irq = pmac_ide_dma_lost_irq,
  1482. };
  1483. /*
  1484. * Allocate the data structures needed for using DMA with an interface
  1485. * and fill the proper list of functions pointers
  1486. */
  1487. static int __devinit pmac_ide_init_dma(ide_hwif_t *hwif,
  1488. const struct ide_port_info *d)
  1489. {
  1490. pmac_ide_hwif_t *pmif =
  1491. (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
  1492. struct pci_dev *dev = to_pci_dev(hwif->dev);
  1493. /* We won't need pci_dev if we switch to generic consistent
  1494. * DMA routines ...
  1495. */
  1496. if (dev == NULL || pmif->dma_regs == 0)
  1497. return -ENODEV;
  1498. /*
  1499. * Allocate space for the DBDMA commands.
  1500. * The +2 is +1 for the stop command and +1 to allow for
  1501. * aligning the start address to a multiple of 16 bytes.
  1502. */
  1503. pmif->dma_table_cpu = pci_alloc_consistent(
  1504. dev,
  1505. (MAX_DCMDS + 2) * sizeof(struct dbdma_cmd),
  1506. &hwif->dmatable_dma);
  1507. if (pmif->dma_table_cpu == NULL) {
  1508. printk(KERN_ERR "%s: unable to allocate DMA command list\n",
  1509. hwif->name);
  1510. return -ENOMEM;
  1511. }
  1512. hwif->sg_max_nents = MAX_DCMDS;
  1513. return 0;
  1514. }
  1515. module_init(pmac_ide_probe);
  1516. MODULE_LICENSE("GPL");