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