pmac.c 46 KB

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