pmac.c 45 KB

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