pmac.c 46 KB

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