pmac.c 46 KB

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