pmac.c 46 KB

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