pmac.c 46 KB

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