pmac.c 46 KB

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