pata_bf54x.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. /*
  2. * File: drivers/ata/pata_bf54x.c
  3. * Author: Sonic Zhang <sonic.zhang@analog.com>
  4. *
  5. * Created:
  6. * Description: PATA Driver for blackfin 54x
  7. *
  8. * Modified:
  9. * Copyright 2007 Analog Devices Inc.
  10. *
  11. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, see the file COPYING, or write
  25. * to the Free Software Foundation, Inc.,
  26. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  27. */
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/pci.h>
  31. #include <linux/init.h>
  32. #include <linux/blkdev.h>
  33. #include <linux/delay.h>
  34. #include <linux/device.h>
  35. #include <scsi/scsi_host.h>
  36. #include <linux/libata.h>
  37. #include <linux/platform_device.h>
  38. #include <linux/gpio.h>
  39. #include <asm/dma.h>
  40. #include <asm/portmux.h>
  41. #define DRV_NAME "pata-bf54x"
  42. #define DRV_VERSION "0.9"
  43. #define ATA_REG_CTRL 0x0E
  44. #define ATA_REG_ALTSTATUS ATA_REG_CTRL
  45. /* These are the offset of the controller's registers */
  46. #define ATAPI_OFFSET_CONTROL 0x00
  47. #define ATAPI_OFFSET_STATUS 0x04
  48. #define ATAPI_OFFSET_DEV_ADDR 0x08
  49. #define ATAPI_OFFSET_DEV_TXBUF 0x0c
  50. #define ATAPI_OFFSET_DEV_RXBUF 0x10
  51. #define ATAPI_OFFSET_INT_MASK 0x14
  52. #define ATAPI_OFFSET_INT_STATUS 0x18
  53. #define ATAPI_OFFSET_XFER_LEN 0x1c
  54. #define ATAPI_OFFSET_LINE_STATUS 0x20
  55. #define ATAPI_OFFSET_SM_STATE 0x24
  56. #define ATAPI_OFFSET_TERMINATE 0x28
  57. #define ATAPI_OFFSET_PIO_TFRCNT 0x2c
  58. #define ATAPI_OFFSET_DMA_TFRCNT 0x30
  59. #define ATAPI_OFFSET_UMAIN_TFRCNT 0x34
  60. #define ATAPI_OFFSET_UDMAOUT_TFRCNT 0x38
  61. #define ATAPI_OFFSET_REG_TIM_0 0x40
  62. #define ATAPI_OFFSET_PIO_TIM_0 0x44
  63. #define ATAPI_OFFSET_PIO_TIM_1 0x48
  64. #define ATAPI_OFFSET_MULTI_TIM_0 0x50
  65. #define ATAPI_OFFSET_MULTI_TIM_1 0x54
  66. #define ATAPI_OFFSET_MULTI_TIM_2 0x58
  67. #define ATAPI_OFFSET_ULTRA_TIM_0 0x60
  68. #define ATAPI_OFFSET_ULTRA_TIM_1 0x64
  69. #define ATAPI_OFFSET_ULTRA_TIM_2 0x68
  70. #define ATAPI_OFFSET_ULTRA_TIM_3 0x6c
  71. #define ATAPI_GET_CONTROL(base)\
  72. bfin_read16(base + ATAPI_OFFSET_CONTROL)
  73. #define ATAPI_SET_CONTROL(base, val)\
  74. bfin_write16(base + ATAPI_OFFSET_CONTROL, val)
  75. #define ATAPI_GET_STATUS(base)\
  76. bfin_read16(base + ATAPI_OFFSET_STATUS)
  77. #define ATAPI_GET_DEV_ADDR(base)\
  78. bfin_read16(base + ATAPI_OFFSET_DEV_ADDR)
  79. #define ATAPI_SET_DEV_ADDR(base, val)\
  80. bfin_write16(base + ATAPI_OFFSET_DEV_ADDR, val)
  81. #define ATAPI_GET_DEV_TXBUF(base)\
  82. bfin_read16(base + ATAPI_OFFSET_DEV_TXBUF)
  83. #define ATAPI_SET_DEV_TXBUF(base, val)\
  84. bfin_write16(base + ATAPI_OFFSET_DEV_TXBUF, val)
  85. #define ATAPI_GET_DEV_RXBUF(base)\
  86. bfin_read16(base + ATAPI_OFFSET_DEV_RXBUF)
  87. #define ATAPI_SET_DEV_RXBUF(base, val)\
  88. bfin_write16(base + ATAPI_OFFSET_DEV_RXBUF, val)
  89. #define ATAPI_GET_INT_MASK(base)\
  90. bfin_read16(base + ATAPI_OFFSET_INT_MASK)
  91. #define ATAPI_SET_INT_MASK(base, val)\
  92. bfin_write16(base + ATAPI_OFFSET_INT_MASK, val)
  93. #define ATAPI_GET_INT_STATUS(base)\
  94. bfin_read16(base + ATAPI_OFFSET_INT_STATUS)
  95. #define ATAPI_SET_INT_STATUS(base, val)\
  96. bfin_write16(base + ATAPI_OFFSET_INT_STATUS, val)
  97. #define ATAPI_GET_XFER_LEN(base)\
  98. bfin_read16(base + ATAPI_OFFSET_XFER_LEN)
  99. #define ATAPI_SET_XFER_LEN(base, val)\
  100. bfin_write16(base + ATAPI_OFFSET_XFER_LEN, val)
  101. #define ATAPI_GET_LINE_STATUS(base)\
  102. bfin_read16(base + ATAPI_OFFSET_LINE_STATUS)
  103. #define ATAPI_GET_SM_STATE(base)\
  104. bfin_read16(base + ATAPI_OFFSET_SM_STATE)
  105. #define ATAPI_GET_TERMINATE(base)\
  106. bfin_read16(base + ATAPI_OFFSET_TERMINATE)
  107. #define ATAPI_SET_TERMINATE(base, val)\
  108. bfin_write16(base + ATAPI_OFFSET_TERMINATE, val)
  109. #define ATAPI_GET_PIO_TFRCNT(base)\
  110. bfin_read16(base + ATAPI_OFFSET_PIO_TFRCNT)
  111. #define ATAPI_GET_DMA_TFRCNT(base)\
  112. bfin_read16(base + ATAPI_OFFSET_DMA_TFRCNT)
  113. #define ATAPI_GET_UMAIN_TFRCNT(base)\
  114. bfin_read16(base + ATAPI_OFFSET_UMAIN_TFRCNT)
  115. #define ATAPI_GET_UDMAOUT_TFRCNT(base)\
  116. bfin_read16(base + ATAPI_OFFSET_UDMAOUT_TFRCNT)
  117. #define ATAPI_GET_REG_TIM_0(base)\
  118. bfin_read16(base + ATAPI_OFFSET_REG_TIM_0)
  119. #define ATAPI_SET_REG_TIM_0(base, val)\
  120. bfin_write16(base + ATAPI_OFFSET_REG_TIM_0, val)
  121. #define ATAPI_GET_PIO_TIM_0(base)\
  122. bfin_read16(base + ATAPI_OFFSET_PIO_TIM_0)
  123. #define ATAPI_SET_PIO_TIM_0(base, val)\
  124. bfin_write16(base + ATAPI_OFFSET_PIO_TIM_0, val)
  125. #define ATAPI_GET_PIO_TIM_1(base)\
  126. bfin_read16(base + ATAPI_OFFSET_PIO_TIM_1)
  127. #define ATAPI_SET_PIO_TIM_1(base, val)\
  128. bfin_write16(base + ATAPI_OFFSET_PIO_TIM_1, val)
  129. #define ATAPI_GET_MULTI_TIM_0(base)\
  130. bfin_read16(base + ATAPI_OFFSET_MULTI_TIM_0)
  131. #define ATAPI_SET_MULTI_TIM_0(base, val)\
  132. bfin_write16(base + ATAPI_OFFSET_MULTI_TIM_0, val)
  133. #define ATAPI_GET_MULTI_TIM_1(base)\
  134. bfin_read16(base + ATAPI_OFFSET_MULTI_TIM_1)
  135. #define ATAPI_SET_MULTI_TIM_1(base, val)\
  136. bfin_write16(base + ATAPI_OFFSET_MULTI_TIM_1, val)
  137. #define ATAPI_GET_MULTI_TIM_2(base)\
  138. bfin_read16(base + ATAPI_OFFSET_MULTI_TIM_2)
  139. #define ATAPI_SET_MULTI_TIM_2(base, val)\
  140. bfin_write16(base + ATAPI_OFFSET_MULTI_TIM_2, val)
  141. #define ATAPI_GET_ULTRA_TIM_0(base)\
  142. bfin_read16(base + ATAPI_OFFSET_ULTRA_TIM_0)
  143. #define ATAPI_SET_ULTRA_TIM_0(base, val)\
  144. bfin_write16(base + ATAPI_OFFSET_ULTRA_TIM_0, val)
  145. #define ATAPI_GET_ULTRA_TIM_1(base)\
  146. bfin_read16(base + ATAPI_OFFSET_ULTRA_TIM_1)
  147. #define ATAPI_SET_ULTRA_TIM_1(base, val)\
  148. bfin_write16(base + ATAPI_OFFSET_ULTRA_TIM_1, val)
  149. #define ATAPI_GET_ULTRA_TIM_2(base)\
  150. bfin_read16(base + ATAPI_OFFSET_ULTRA_TIM_2)
  151. #define ATAPI_SET_ULTRA_TIM_2(base, val)\
  152. bfin_write16(base + ATAPI_OFFSET_ULTRA_TIM_2, val)
  153. #define ATAPI_GET_ULTRA_TIM_3(base)\
  154. bfin_read16(base + ATAPI_OFFSET_ULTRA_TIM_3)
  155. #define ATAPI_SET_ULTRA_TIM_3(base, val)\
  156. bfin_write16(base + ATAPI_OFFSET_ULTRA_TIM_3, val)
  157. /**
  158. * PIO Mode - Frequency compatibility
  159. */
  160. /* mode: 0 1 2 3 4 */
  161. static const u32 pio_fsclk[] =
  162. { 33333333, 33333333, 33333333, 33333333, 33333333 };
  163. /**
  164. * MDMA Mode - Frequency compatibility
  165. */
  166. /* mode: 0 1 2 */
  167. static const u32 mdma_fsclk[] = { 33333333, 33333333, 33333333 };
  168. /**
  169. * UDMA Mode - Frequency compatibility
  170. *
  171. * UDMA5 - 100 MB/s - SCLK = 133 MHz
  172. * UDMA4 - 66 MB/s - SCLK >= 80 MHz
  173. * UDMA3 - 44.4 MB/s - SCLK >= 50 MHz
  174. * UDMA2 - 33 MB/s - SCLK >= 40 MHz
  175. */
  176. /* mode: 0 1 2 3 4 5 */
  177. static const u32 udma_fsclk[] =
  178. { 33333333, 33333333, 40000000, 50000000, 80000000, 133333333 };
  179. /**
  180. * Register transfer timing table
  181. */
  182. /* mode: 0 1 2 3 4 */
  183. /* Cycle Time */
  184. static const u32 reg_t0min[] = { 600, 383, 330, 180, 120 };
  185. /* DIOR/DIOW to end cycle */
  186. static const u32 reg_t2min[] = { 290, 290, 290, 70, 25 };
  187. /* DIOR/DIOW asserted pulse width */
  188. static const u32 reg_teocmin[] = { 290, 290, 290, 80, 70 };
  189. /**
  190. * PIO timing table
  191. */
  192. /* mode: 0 1 2 3 4 */
  193. /* Cycle Time */
  194. static const u32 pio_t0min[] = { 600, 383, 240, 180, 120 };
  195. /* Address valid to DIOR/DIORW */
  196. static const u32 pio_t1min[] = { 70, 50, 30, 30, 25 };
  197. /* DIOR/DIOW to end cycle */
  198. static const u32 pio_t2min[] = { 165, 125, 100, 80, 70 };
  199. /* DIOR/DIOW asserted pulse width */
  200. static const u32 pio_teocmin[] = { 165, 125, 100, 70, 25 };
  201. /* DIOW data hold */
  202. static const u32 pio_t4min[] = { 30, 20, 15, 10, 10 };
  203. /* ******************************************************************
  204. * Multiword DMA timing table
  205. * ******************************************************************
  206. */
  207. /* mode: 0 1 2 */
  208. /* Cycle Time */
  209. static const u32 mdma_t0min[] = { 480, 150, 120 };
  210. /* DIOR/DIOW asserted pulse width */
  211. static const u32 mdma_tdmin[] = { 215, 80, 70 };
  212. /* DMACK to read data released */
  213. static const u32 mdma_thmin[] = { 20, 15, 10 };
  214. /* DIOR/DIOW to DMACK hold */
  215. static const u32 mdma_tjmin[] = { 20, 5, 5 };
  216. /* DIOR negated pulse width */
  217. static const u32 mdma_tkrmin[] = { 50, 50, 25 };
  218. /* DIOR negated pulse width */
  219. static const u32 mdma_tkwmin[] = { 215, 50, 25 };
  220. /* CS[1:0] valid to DIOR/DIOW */
  221. static const u32 mdma_tmmin[] = { 50, 30, 25 };
  222. /* DMACK to read data released */
  223. static const u32 mdma_tzmax[] = { 20, 25, 25 };
  224. /**
  225. * Ultra DMA timing table
  226. */
  227. /* mode: 0 1 2 3 4 5 */
  228. static const u32 udma_tcycmin[] = { 112, 73, 54, 39, 25, 17 };
  229. static const u32 udma_tdvsmin[] = { 70, 48, 31, 20, 7, 5 };
  230. static const u32 udma_tenvmax[] = { 70, 70, 70, 55, 55, 50 };
  231. static const u32 udma_trpmin[] = { 160, 125, 100, 100, 100, 85 };
  232. static const u32 udma_tmin[] = { 5, 5, 5, 5, 3, 3 };
  233. static const u32 udma_tmlimin = 20;
  234. static const u32 udma_tzahmin = 20;
  235. static const u32 udma_tenvmin = 20;
  236. static const u32 udma_tackmin = 20;
  237. static const u32 udma_tssmin = 50;
  238. #define BFIN_MAX_SG_SEGMENTS 4
  239. /**
  240. *
  241. * Function: num_clocks_min
  242. *
  243. * Description:
  244. * calculate number of SCLK cycles to meet minimum timing
  245. */
  246. static unsigned short num_clocks_min(unsigned long tmin,
  247. unsigned long fsclk)
  248. {
  249. unsigned long tmp ;
  250. unsigned short result;
  251. tmp = tmin * (fsclk/1000/1000) / 1000;
  252. result = (unsigned short)tmp;
  253. if ((tmp*1000*1000) < (tmin*(fsclk/1000))) {
  254. result++;
  255. }
  256. return result;
  257. }
  258. /**
  259. * bfin_set_piomode - Initialize host controller PATA PIO timings
  260. * @ap: Port whose timings we are configuring
  261. * @adev: um
  262. *
  263. * Set PIO mode for device.
  264. *
  265. * LOCKING:
  266. * None (inherited from caller).
  267. */
  268. static void bfin_set_piomode(struct ata_port *ap, struct ata_device *adev)
  269. {
  270. int mode = adev->pio_mode - XFER_PIO_0;
  271. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  272. unsigned int fsclk = get_sclk();
  273. unsigned short teoc_reg, t2_reg, teoc_pio;
  274. unsigned short t4_reg, t2_pio, t1_reg;
  275. unsigned short n0, n6, t6min = 5;
  276. /* the most restrictive timing value is t6 and tc, the DIOW - data hold
  277. * If one SCLK pulse is longer than this minimum value then register
  278. * transfers cannot be supported at this frequency.
  279. */
  280. n6 = num_clocks_min(t6min, fsclk);
  281. if (mode >= 0 && mode <= 4 && n6 >= 1) {
  282. dev_dbg(adev->link->ap->dev, "set piomode: mode=%d, fsclk=%ud\n", mode, fsclk);
  283. /* calculate the timing values for register transfers. */
  284. while (mode > 0 && pio_fsclk[mode] > fsclk)
  285. mode--;
  286. /* DIOR/DIOW to end cycle time */
  287. t2_reg = num_clocks_min(reg_t2min[mode], fsclk);
  288. /* DIOR/DIOW asserted pulse width */
  289. teoc_reg = num_clocks_min(reg_teocmin[mode], fsclk);
  290. /* Cycle Time */
  291. n0 = num_clocks_min(reg_t0min[mode], fsclk);
  292. /* increase t2 until we meed the minimum cycle length */
  293. if (t2_reg + teoc_reg < n0)
  294. t2_reg = n0 - teoc_reg;
  295. /* calculate the timing values for pio transfers. */
  296. /* DIOR/DIOW to end cycle time */
  297. t2_pio = num_clocks_min(pio_t2min[mode], fsclk);
  298. /* DIOR/DIOW asserted pulse width */
  299. teoc_pio = num_clocks_min(pio_teocmin[mode], fsclk);
  300. /* Cycle Time */
  301. n0 = num_clocks_min(pio_t0min[mode], fsclk);
  302. /* increase t2 until we meed the minimum cycle length */
  303. if (t2_pio + teoc_pio < n0)
  304. t2_pio = n0 - teoc_pio;
  305. /* Address valid to DIOR/DIORW */
  306. t1_reg = num_clocks_min(pio_t1min[mode], fsclk);
  307. /* DIOW data hold */
  308. t4_reg = num_clocks_min(pio_t4min[mode], fsclk);
  309. ATAPI_SET_REG_TIM_0(base, (teoc_reg<<8 | t2_reg));
  310. ATAPI_SET_PIO_TIM_0(base, (t4_reg<<12 | t2_pio<<4 | t1_reg));
  311. ATAPI_SET_PIO_TIM_1(base, teoc_pio);
  312. if (mode > 2) {
  313. ATAPI_SET_CONTROL(base,
  314. ATAPI_GET_CONTROL(base) | IORDY_EN);
  315. } else {
  316. ATAPI_SET_CONTROL(base,
  317. ATAPI_GET_CONTROL(base) & ~IORDY_EN);
  318. }
  319. /* Disable host ATAPI PIO interrupts */
  320. ATAPI_SET_INT_MASK(base, ATAPI_GET_INT_MASK(base)
  321. & ~(PIO_DONE_MASK | HOST_TERM_XFER_MASK));
  322. SSYNC();
  323. }
  324. }
  325. /**
  326. * bfin_set_dmamode - Initialize host controller PATA DMA timings
  327. * @ap: Port whose timings we are configuring
  328. * @adev: um
  329. *
  330. * Set UDMA mode for device.
  331. *
  332. * LOCKING:
  333. * None (inherited from caller).
  334. */
  335. static void bfin_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  336. {
  337. int mode;
  338. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  339. unsigned long fsclk = get_sclk();
  340. unsigned short tenv, tack, tcyc_tdvs, tdvs, tmli, tss, trp, tzah;
  341. unsigned short tm, td, tkr, tkw, teoc, th;
  342. unsigned short n0, nf, tfmin = 5;
  343. unsigned short nmin, tcyc;
  344. mode = adev->dma_mode - XFER_UDMA_0;
  345. if (mode >= 0 && mode <= 5) {
  346. dev_dbg(adev->link->ap->dev, "set udmamode: mode=%d\n", mode);
  347. /* the most restrictive timing value is t6 and tc,
  348. * the DIOW - data hold. If one SCLK pulse is longer
  349. * than this minimum value then register
  350. * transfers cannot be supported at this frequency.
  351. */
  352. while (mode > 0 && udma_fsclk[mode] > fsclk)
  353. mode--;
  354. nmin = num_clocks_min(udma_tmin[mode], fsclk);
  355. if (nmin >= 1) {
  356. /* calculate the timing values for Ultra DMA. */
  357. tdvs = num_clocks_min(udma_tdvsmin[mode], fsclk);
  358. tcyc = num_clocks_min(udma_tcycmin[mode], fsclk);
  359. tcyc_tdvs = 2;
  360. /* increase tcyc - tdvs (tcyc_tdvs) until we meed
  361. * the minimum cycle length
  362. */
  363. if (tdvs + tcyc_tdvs < tcyc)
  364. tcyc_tdvs = tcyc - tdvs;
  365. /* Mow assign the values required for the timing
  366. * registers
  367. */
  368. if (tcyc_tdvs < 2)
  369. tcyc_tdvs = 2;
  370. if (tdvs < 2)
  371. tdvs = 2;
  372. tack = num_clocks_min(udma_tackmin, fsclk);
  373. tss = num_clocks_min(udma_tssmin, fsclk);
  374. tmli = num_clocks_min(udma_tmlimin, fsclk);
  375. tzah = num_clocks_min(udma_tzahmin, fsclk);
  376. trp = num_clocks_min(udma_trpmin[mode], fsclk);
  377. tenv = num_clocks_min(udma_tenvmin, fsclk);
  378. if (tenv <= udma_tenvmax[mode]) {
  379. ATAPI_SET_ULTRA_TIM_0(base, (tenv<<8 | tack));
  380. ATAPI_SET_ULTRA_TIM_1(base,
  381. (tcyc_tdvs<<8 | tdvs));
  382. ATAPI_SET_ULTRA_TIM_2(base, (tmli<<8 | tss));
  383. ATAPI_SET_ULTRA_TIM_3(base, (trp<<8 | tzah));
  384. }
  385. }
  386. }
  387. mode = adev->dma_mode - XFER_MW_DMA_0;
  388. if (mode >= 0 && mode <= 2) {
  389. dev_dbg(adev->link->ap->dev, "set mdmamode: mode=%d\n", mode);
  390. /* the most restrictive timing value is tf, the DMACK to
  391. * read data released. If one SCLK pulse is longer than
  392. * this maximum value then the MDMA mode
  393. * cannot be supported at this frequency.
  394. */
  395. while (mode > 0 && mdma_fsclk[mode] > fsclk)
  396. mode--;
  397. nf = num_clocks_min(tfmin, fsclk);
  398. if (nf >= 1) {
  399. /* calculate the timing values for Multi-word DMA. */
  400. /* DIOR/DIOW asserted pulse width */
  401. td = num_clocks_min(mdma_tdmin[mode], fsclk);
  402. /* DIOR negated pulse width */
  403. tkw = num_clocks_min(mdma_tkwmin[mode], fsclk);
  404. /* Cycle Time */
  405. n0 = num_clocks_min(mdma_t0min[mode], fsclk);
  406. /* increase tk until we meed the minimum cycle length */
  407. if (tkw + td < n0)
  408. tkw = n0 - td;
  409. /* DIOR negated pulse width - read */
  410. tkr = num_clocks_min(mdma_tkrmin[mode], fsclk);
  411. /* CS{1:0] valid to DIOR/DIOW */
  412. tm = num_clocks_min(mdma_tmmin[mode], fsclk);
  413. /* DIOR/DIOW to DMACK hold */
  414. teoc = num_clocks_min(mdma_tjmin[mode], fsclk);
  415. /* DIOW Data hold */
  416. th = num_clocks_min(mdma_thmin[mode], fsclk);
  417. ATAPI_SET_MULTI_TIM_0(base, (tm<<8 | td));
  418. ATAPI_SET_MULTI_TIM_1(base, (tkr<<8 | tkw));
  419. ATAPI_SET_MULTI_TIM_2(base, (teoc<<8 | th));
  420. SSYNC();
  421. }
  422. }
  423. return;
  424. }
  425. /**
  426. *
  427. * Function: wait_complete
  428. *
  429. * Description: Waits the interrupt from device
  430. *
  431. */
  432. static inline void wait_complete(void __iomem *base, unsigned short mask)
  433. {
  434. unsigned short status;
  435. unsigned int i = 0;
  436. #define PATA_BF54X_WAIT_TIMEOUT 10000
  437. for (i = 0; i < PATA_BF54X_WAIT_TIMEOUT; i++) {
  438. status = ATAPI_GET_INT_STATUS(base) & mask;
  439. if (status)
  440. break;
  441. }
  442. ATAPI_SET_INT_STATUS(base, mask);
  443. }
  444. /**
  445. *
  446. * Function: write_atapi_register
  447. *
  448. * Description: Writes to ATA Device Resgister
  449. *
  450. */
  451. static void write_atapi_register(void __iomem *base,
  452. unsigned long ata_reg, unsigned short value)
  453. {
  454. /* Program the ATA_DEV_TXBUF register with write data (to be
  455. * written into the device).
  456. */
  457. ATAPI_SET_DEV_TXBUF(base, value);
  458. /* Program the ATA_DEV_ADDR register with address of the
  459. * device register (0x01 to 0x0F).
  460. */
  461. ATAPI_SET_DEV_ADDR(base, ata_reg);
  462. /* Program the ATA_CTRL register with dir set to write (1)
  463. */
  464. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base) | XFER_DIR));
  465. /* ensure PIO DMA is not set */
  466. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base) & ~PIO_USE_DMA));
  467. /* and start the transfer */
  468. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base) | PIO_START));
  469. /* Wait for the interrupt to indicate the end of the transfer.
  470. * (We need to wait on and clear rhe ATA_DEV_INT interrupt status)
  471. */
  472. wait_complete(base, PIO_DONE_INT);
  473. }
  474. /**
  475. *
  476. * Function: read_atapi_register
  477. *
  478. *Description: Reads from ATA Device Resgister
  479. *
  480. */
  481. static unsigned short read_atapi_register(void __iomem *base,
  482. unsigned long ata_reg)
  483. {
  484. /* Program the ATA_DEV_ADDR register with address of the
  485. * device register (0x01 to 0x0F).
  486. */
  487. ATAPI_SET_DEV_ADDR(base, ata_reg);
  488. /* Program the ATA_CTRL register with dir set to read (0) and
  489. */
  490. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base) & ~XFER_DIR));
  491. /* ensure PIO DMA is not set */
  492. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base) & ~PIO_USE_DMA));
  493. /* and start the transfer */
  494. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base) | PIO_START));
  495. /* Wait for the interrupt to indicate the end of the transfer.
  496. * (PIO_DONE interrupt is set and it doesn't seem to matter
  497. * that we don't clear it)
  498. */
  499. wait_complete(base, PIO_DONE_INT);
  500. /* Read the ATA_DEV_RXBUF register with write data (to be
  501. * written into the device).
  502. */
  503. return ATAPI_GET_DEV_RXBUF(base);
  504. }
  505. /**
  506. *
  507. * Function: write_atapi_register_data
  508. *
  509. * Description: Writes to ATA Device Resgister
  510. *
  511. */
  512. static void write_atapi_data(void __iomem *base,
  513. int len, unsigned short *buf)
  514. {
  515. int i;
  516. /* Set transfer length to 1 */
  517. ATAPI_SET_XFER_LEN(base, 1);
  518. /* Program the ATA_DEV_ADDR register with address of the
  519. * ATA_REG_DATA
  520. */
  521. ATAPI_SET_DEV_ADDR(base, ATA_REG_DATA);
  522. /* Program the ATA_CTRL register with dir set to write (1)
  523. */
  524. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base) | XFER_DIR));
  525. /* ensure PIO DMA is not set */
  526. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base) & ~PIO_USE_DMA));
  527. for (i = 0; i < len; i++) {
  528. /* Program the ATA_DEV_TXBUF register with write data (to be
  529. * written into the device).
  530. */
  531. ATAPI_SET_DEV_TXBUF(base, buf[i]);
  532. /* and start the transfer */
  533. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base) | PIO_START));
  534. /* Wait for the interrupt to indicate the end of the transfer.
  535. * (We need to wait on and clear rhe ATA_DEV_INT
  536. * interrupt status)
  537. */
  538. wait_complete(base, PIO_DONE_INT);
  539. }
  540. }
  541. /**
  542. *
  543. * Function: read_atapi_register_data
  544. *
  545. * Description: Reads from ATA Device Resgister
  546. *
  547. */
  548. static void read_atapi_data(void __iomem *base,
  549. int len, unsigned short *buf)
  550. {
  551. int i;
  552. /* Set transfer length to 1 */
  553. ATAPI_SET_XFER_LEN(base, 1);
  554. /* Program the ATA_DEV_ADDR register with address of the
  555. * ATA_REG_DATA
  556. */
  557. ATAPI_SET_DEV_ADDR(base, ATA_REG_DATA);
  558. /* Program the ATA_CTRL register with dir set to read (0) and
  559. */
  560. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base) & ~XFER_DIR));
  561. /* ensure PIO DMA is not set */
  562. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base) & ~PIO_USE_DMA));
  563. for (i = 0; i < len; i++) {
  564. /* and start the transfer */
  565. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base) | PIO_START));
  566. /* Wait for the interrupt to indicate the end of the transfer.
  567. * (PIO_DONE interrupt is set and it doesn't seem to matter
  568. * that we don't clear it)
  569. */
  570. wait_complete(base, PIO_DONE_INT);
  571. /* Read the ATA_DEV_RXBUF register with write data (to be
  572. * written into the device).
  573. */
  574. buf[i] = ATAPI_GET_DEV_RXBUF(base);
  575. }
  576. }
  577. /**
  578. * bfin_tf_load - send taskfile registers to host controller
  579. * @ap: Port to which output is sent
  580. * @tf: ATA taskfile register set
  581. *
  582. * Note: Original code is ata_sff_tf_load().
  583. */
  584. static void bfin_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
  585. {
  586. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  587. unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
  588. if (tf->ctl != ap->last_ctl) {
  589. write_atapi_register(base, ATA_REG_CTRL, tf->ctl);
  590. ap->last_ctl = tf->ctl;
  591. ata_wait_idle(ap);
  592. }
  593. if (is_addr) {
  594. if (tf->flags & ATA_TFLAG_LBA48) {
  595. write_atapi_register(base, ATA_REG_FEATURE,
  596. tf->hob_feature);
  597. write_atapi_register(base, ATA_REG_NSECT,
  598. tf->hob_nsect);
  599. write_atapi_register(base, ATA_REG_LBAL, tf->hob_lbal);
  600. write_atapi_register(base, ATA_REG_LBAM, tf->hob_lbam);
  601. write_atapi_register(base, ATA_REG_LBAH, tf->hob_lbah);
  602. dev_dbg(ap->dev, "hob: feat 0x%X nsect 0x%X, lba 0x%X "
  603. "0x%X 0x%X\n",
  604. tf->hob_feature,
  605. tf->hob_nsect,
  606. tf->hob_lbal,
  607. tf->hob_lbam,
  608. tf->hob_lbah);
  609. }
  610. write_atapi_register(base, ATA_REG_FEATURE, tf->feature);
  611. write_atapi_register(base, ATA_REG_NSECT, tf->nsect);
  612. write_atapi_register(base, ATA_REG_LBAL, tf->lbal);
  613. write_atapi_register(base, ATA_REG_LBAM, tf->lbam);
  614. write_atapi_register(base, ATA_REG_LBAH, tf->lbah);
  615. dev_dbg(ap->dev, "feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
  616. tf->feature,
  617. tf->nsect,
  618. tf->lbal,
  619. tf->lbam,
  620. tf->lbah);
  621. }
  622. if (tf->flags & ATA_TFLAG_DEVICE) {
  623. write_atapi_register(base, ATA_REG_DEVICE, tf->device);
  624. dev_dbg(ap->dev, "device 0x%X\n", tf->device);
  625. }
  626. ata_wait_idle(ap);
  627. }
  628. /**
  629. * bfin_check_status - Read device status reg & clear interrupt
  630. * @ap: port where the device is
  631. *
  632. * Note: Original code is ata_check_status().
  633. */
  634. static u8 bfin_check_status(struct ata_port *ap)
  635. {
  636. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  637. return read_atapi_register(base, ATA_REG_STATUS);
  638. }
  639. /**
  640. * bfin_tf_read - input device's ATA taskfile shadow registers
  641. * @ap: Port from which input is read
  642. * @tf: ATA taskfile register set for storing input
  643. *
  644. * Note: Original code is ata_sff_tf_read().
  645. */
  646. static void bfin_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
  647. {
  648. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  649. tf->command = bfin_check_status(ap);
  650. tf->feature = read_atapi_register(base, ATA_REG_ERR);
  651. tf->nsect = read_atapi_register(base, ATA_REG_NSECT);
  652. tf->lbal = read_atapi_register(base, ATA_REG_LBAL);
  653. tf->lbam = read_atapi_register(base, ATA_REG_LBAM);
  654. tf->lbah = read_atapi_register(base, ATA_REG_LBAH);
  655. tf->device = read_atapi_register(base, ATA_REG_DEVICE);
  656. if (tf->flags & ATA_TFLAG_LBA48) {
  657. write_atapi_register(base, ATA_REG_CTRL, tf->ctl | ATA_HOB);
  658. tf->hob_feature = read_atapi_register(base, ATA_REG_ERR);
  659. tf->hob_nsect = read_atapi_register(base, ATA_REG_NSECT);
  660. tf->hob_lbal = read_atapi_register(base, ATA_REG_LBAL);
  661. tf->hob_lbam = read_atapi_register(base, ATA_REG_LBAM);
  662. tf->hob_lbah = read_atapi_register(base, ATA_REG_LBAH);
  663. }
  664. }
  665. /**
  666. * bfin_exec_command - issue ATA command to host controller
  667. * @ap: port to which command is being issued
  668. * @tf: ATA taskfile register set
  669. *
  670. * Note: Original code is ata_sff_exec_command().
  671. */
  672. static void bfin_exec_command(struct ata_port *ap,
  673. const struct ata_taskfile *tf)
  674. {
  675. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  676. dev_dbg(ap->dev, "ata%u: cmd 0x%X\n", ap->print_id, tf->command);
  677. write_atapi_register(base, ATA_REG_CMD, tf->command);
  678. ata_sff_pause(ap);
  679. }
  680. /**
  681. * bfin_check_altstatus - Read device alternate status reg
  682. * @ap: port where the device is
  683. */
  684. static u8 bfin_check_altstatus(struct ata_port *ap)
  685. {
  686. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  687. return read_atapi_register(base, ATA_REG_ALTSTATUS);
  688. }
  689. /**
  690. * bfin_dev_select - Select device 0/1 on ATA bus
  691. * @ap: ATA channel to manipulate
  692. * @device: ATA device (numbered from zero) to select
  693. *
  694. * Note: Original code is ata_sff_dev_select().
  695. */
  696. static void bfin_dev_select(struct ata_port *ap, unsigned int device)
  697. {
  698. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  699. u8 tmp;
  700. if (device == 0)
  701. tmp = ATA_DEVICE_OBS;
  702. else
  703. tmp = ATA_DEVICE_OBS | ATA_DEV1;
  704. write_atapi_register(base, ATA_REG_DEVICE, tmp);
  705. ata_sff_pause(ap);
  706. }
  707. /**
  708. * bfin_set_devctl - Write device control reg
  709. * @ap: port where the device is
  710. * @ctl: value to write
  711. */
  712. static void bfin_set_devctl(struct ata_port *ap, u8 ctl)
  713. {
  714. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  715. write_atapi_register(base, ATA_REG_CTRL, ctl);
  716. }
  717. /**
  718. * bfin_bmdma_setup - Set up IDE DMA transaction
  719. * @qc: Info associated with this ATA transaction.
  720. *
  721. * Note: Original code is ata_bmdma_setup().
  722. */
  723. static void bfin_bmdma_setup(struct ata_queued_cmd *qc)
  724. {
  725. struct ata_port *ap = qc->ap;
  726. struct dma_desc_array *dma_desc_cpu = (struct dma_desc_array *)ap->bmdma_prd;
  727. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  728. unsigned short config = DMAFLOW_ARRAY | NDSIZE_5 | RESTART | WDSIZE_16 | DMAEN;
  729. struct scatterlist *sg;
  730. unsigned int si;
  731. unsigned int channel;
  732. unsigned int dir;
  733. unsigned int size = 0;
  734. dev_dbg(qc->ap->dev, "in atapi dma setup\n");
  735. /* Program the ATA_CTRL register with dir */
  736. if (qc->tf.flags & ATA_TFLAG_WRITE) {
  737. channel = CH_ATAPI_TX;
  738. dir = DMA_TO_DEVICE;
  739. } else {
  740. channel = CH_ATAPI_RX;
  741. dir = DMA_FROM_DEVICE;
  742. config |= WNR;
  743. }
  744. dma_map_sg(ap->dev, qc->sg, qc->n_elem, dir);
  745. /* fill the ATAPI DMA controller */
  746. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  747. dma_desc_cpu[si].start_addr = sg_dma_address(sg);
  748. dma_desc_cpu[si].cfg = config;
  749. dma_desc_cpu[si].x_count = sg_dma_len(sg) >> 1;
  750. dma_desc_cpu[si].x_modify = 2;
  751. size += sg_dma_len(sg);
  752. }
  753. /* Set the last descriptor to stop mode */
  754. dma_desc_cpu[qc->n_elem - 1].cfg &= ~(DMAFLOW | NDSIZE);
  755. flush_dcache_range((unsigned int)dma_desc_cpu,
  756. (unsigned int)dma_desc_cpu +
  757. qc->n_elem * sizeof(struct dma_desc_array));
  758. /* Enable ATA DMA operation*/
  759. set_dma_curr_desc_addr(channel, (unsigned long *)ap->bmdma_prd_dma);
  760. set_dma_x_count(channel, 0);
  761. set_dma_x_modify(channel, 0);
  762. set_dma_config(channel, config);
  763. SSYNC();
  764. /* Send ATA DMA command */
  765. bfin_exec_command(ap, &qc->tf);
  766. if (qc->tf.flags & ATA_TFLAG_WRITE) {
  767. /* set ATA DMA write direction */
  768. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base)
  769. | XFER_DIR));
  770. } else {
  771. /* set ATA DMA read direction */
  772. ATAPI_SET_CONTROL(base, (ATAPI_GET_CONTROL(base)
  773. & ~XFER_DIR));
  774. }
  775. /* Reset all transfer count */
  776. ATAPI_SET_CONTROL(base, ATAPI_GET_CONTROL(base) | TFRCNT_RST);
  777. /* Set ATAPI state machine contorl in terminate sequence */
  778. ATAPI_SET_CONTROL(base, ATAPI_GET_CONTROL(base) | END_ON_TERM);
  779. /* Set transfer length to the total size of sg buffers */
  780. ATAPI_SET_XFER_LEN(base, size >> 1);
  781. }
  782. /**
  783. * bfin_bmdma_start - Start an IDE DMA transaction
  784. * @qc: Info associated with this ATA transaction.
  785. *
  786. * Note: Original code is ata_bmdma_start().
  787. */
  788. static void bfin_bmdma_start(struct ata_queued_cmd *qc)
  789. {
  790. struct ata_port *ap = qc->ap;
  791. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  792. dev_dbg(qc->ap->dev, "in atapi dma start\n");
  793. if (!(ap->udma_mask || ap->mwdma_mask))
  794. return;
  795. /* start ATAPI transfer*/
  796. if (ap->udma_mask)
  797. ATAPI_SET_CONTROL(base, ATAPI_GET_CONTROL(base)
  798. | ULTRA_START);
  799. else
  800. ATAPI_SET_CONTROL(base, ATAPI_GET_CONTROL(base)
  801. | MULTI_START);
  802. }
  803. /**
  804. * bfin_bmdma_stop - Stop IDE DMA transfer
  805. * @qc: Command we are ending DMA for
  806. */
  807. static void bfin_bmdma_stop(struct ata_queued_cmd *qc)
  808. {
  809. struct ata_port *ap = qc->ap;
  810. unsigned int dir;
  811. dev_dbg(qc->ap->dev, "in atapi dma stop\n");
  812. if (!(ap->udma_mask || ap->mwdma_mask))
  813. return;
  814. /* stop ATAPI DMA controller*/
  815. if (qc->tf.flags & ATA_TFLAG_WRITE) {
  816. dir = DMA_TO_DEVICE;
  817. disable_dma(CH_ATAPI_TX);
  818. } else {
  819. dir = DMA_FROM_DEVICE;
  820. disable_dma(CH_ATAPI_RX);
  821. }
  822. dma_unmap_sg(ap->dev, qc->sg, qc->n_elem, dir);
  823. }
  824. /**
  825. * bfin_devchk - PATA device presence detection
  826. * @ap: ATA channel to examine
  827. * @device: Device to examine (starting at zero)
  828. *
  829. * Note: Original code is ata_devchk().
  830. */
  831. static unsigned int bfin_devchk(struct ata_port *ap,
  832. unsigned int device)
  833. {
  834. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  835. u8 nsect, lbal;
  836. bfin_dev_select(ap, device);
  837. write_atapi_register(base, ATA_REG_NSECT, 0x55);
  838. write_atapi_register(base, ATA_REG_LBAL, 0xaa);
  839. write_atapi_register(base, ATA_REG_NSECT, 0xaa);
  840. write_atapi_register(base, ATA_REG_LBAL, 0x55);
  841. write_atapi_register(base, ATA_REG_NSECT, 0x55);
  842. write_atapi_register(base, ATA_REG_LBAL, 0xaa);
  843. nsect = read_atapi_register(base, ATA_REG_NSECT);
  844. lbal = read_atapi_register(base, ATA_REG_LBAL);
  845. if ((nsect == 0x55) && (lbal == 0xaa))
  846. return 1; /* we found a device */
  847. return 0; /* nothing found */
  848. }
  849. /**
  850. * bfin_bus_post_reset - PATA device post reset
  851. *
  852. * Note: Original code is ata_bus_post_reset().
  853. */
  854. static void bfin_bus_post_reset(struct ata_port *ap, unsigned int devmask)
  855. {
  856. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  857. unsigned int dev0 = devmask & (1 << 0);
  858. unsigned int dev1 = devmask & (1 << 1);
  859. unsigned long deadline;
  860. /* if device 0 was found in ata_devchk, wait for its
  861. * BSY bit to clear
  862. */
  863. if (dev0)
  864. ata_sff_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
  865. /* if device 1 was found in ata_devchk, wait for
  866. * register access, then wait for BSY to clear
  867. */
  868. deadline = ata_deadline(jiffies, ATA_TMOUT_BOOT);
  869. while (dev1) {
  870. u8 nsect, lbal;
  871. bfin_dev_select(ap, 1);
  872. nsect = read_atapi_register(base, ATA_REG_NSECT);
  873. lbal = read_atapi_register(base, ATA_REG_LBAL);
  874. if ((nsect == 1) && (lbal == 1))
  875. break;
  876. if (time_after(jiffies, deadline)) {
  877. dev1 = 0;
  878. break;
  879. }
  880. ata_msleep(ap, 50); /* give drive a breather */
  881. }
  882. if (dev1)
  883. ata_sff_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
  884. /* is all this really necessary? */
  885. bfin_dev_select(ap, 0);
  886. if (dev1)
  887. bfin_dev_select(ap, 1);
  888. if (dev0)
  889. bfin_dev_select(ap, 0);
  890. }
  891. /**
  892. * bfin_bus_softreset - PATA device software reset
  893. *
  894. * Note: Original code is ata_bus_softreset().
  895. */
  896. static unsigned int bfin_bus_softreset(struct ata_port *ap,
  897. unsigned int devmask)
  898. {
  899. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  900. /* software reset. causes dev0 to be selected */
  901. write_atapi_register(base, ATA_REG_CTRL, ap->ctl);
  902. udelay(20);
  903. write_atapi_register(base, ATA_REG_CTRL, ap->ctl | ATA_SRST);
  904. udelay(20);
  905. write_atapi_register(base, ATA_REG_CTRL, ap->ctl);
  906. /* spec mandates ">= 2ms" before checking status.
  907. * We wait 150ms, because that was the magic delay used for
  908. * ATAPI devices in Hale Landis's ATADRVR, for the period of time
  909. * between when the ATA command register is written, and then
  910. * status is checked. Because waiting for "a while" before
  911. * checking status is fine, post SRST, we perform this magic
  912. * delay here as well.
  913. *
  914. * Old drivers/ide uses the 2mS rule and then waits for ready
  915. */
  916. ata_msleep(ap, 150);
  917. /* Before we perform post reset processing we want to see if
  918. * the bus shows 0xFF because the odd clown forgets the D7
  919. * pulldown resistor.
  920. */
  921. if (bfin_check_status(ap) == 0xFF)
  922. return 0;
  923. bfin_bus_post_reset(ap, devmask);
  924. return 0;
  925. }
  926. /**
  927. * bfin_softreset - reset host port via ATA SRST
  928. * @ap: port to reset
  929. * @classes: resulting classes of attached devices
  930. *
  931. * Note: Original code is ata_sff_softreset().
  932. */
  933. static int bfin_softreset(struct ata_link *link, unsigned int *classes,
  934. unsigned long deadline)
  935. {
  936. struct ata_port *ap = link->ap;
  937. unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
  938. unsigned int devmask = 0, err_mask;
  939. u8 err;
  940. /* determine if device 0/1 are present */
  941. if (bfin_devchk(ap, 0))
  942. devmask |= (1 << 0);
  943. if (slave_possible && bfin_devchk(ap, 1))
  944. devmask |= (1 << 1);
  945. /* select device 0 again */
  946. bfin_dev_select(ap, 0);
  947. /* issue bus reset */
  948. err_mask = bfin_bus_softreset(ap, devmask);
  949. if (err_mask) {
  950. ata_port_err(ap, "SRST failed (err_mask=0x%x)\n",
  951. err_mask);
  952. return -EIO;
  953. }
  954. /* determine by signature whether we have ATA or ATAPI devices */
  955. classes[0] = ata_sff_dev_classify(&ap->link.device[0],
  956. devmask & (1 << 0), &err);
  957. if (slave_possible && err != 0x81)
  958. classes[1] = ata_sff_dev_classify(&ap->link.device[1],
  959. devmask & (1 << 1), &err);
  960. return 0;
  961. }
  962. /**
  963. * bfin_bmdma_status - Read IDE DMA status
  964. * @ap: Port associated with this ATA transaction.
  965. */
  966. static unsigned char bfin_bmdma_status(struct ata_port *ap)
  967. {
  968. unsigned char host_stat = 0;
  969. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  970. if (ATAPI_GET_STATUS(base) & (MULTI_XFER_ON | ULTRA_XFER_ON))
  971. host_stat |= ATA_DMA_ACTIVE;
  972. if (ATAPI_GET_INT_STATUS(base) & ATAPI_DEV_INT)
  973. host_stat |= ATA_DMA_INTR;
  974. dev_dbg(ap->dev, "ATAPI: host_stat=0x%x\n", host_stat);
  975. return host_stat;
  976. }
  977. /**
  978. * bfin_data_xfer - Transfer data by PIO
  979. * @adev: device for this I/O
  980. * @buf: data buffer
  981. * @buflen: buffer length
  982. * @write_data: read/write
  983. *
  984. * Note: Original code is ata_sff_data_xfer().
  985. */
  986. static unsigned int bfin_data_xfer(struct ata_device *dev, unsigned char *buf,
  987. unsigned int buflen, int rw)
  988. {
  989. struct ata_port *ap = dev->link->ap;
  990. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  991. unsigned int words = buflen >> 1;
  992. unsigned short *buf16 = (u16 *)buf;
  993. /* Transfer multiple of 2 bytes */
  994. if (rw == READ)
  995. read_atapi_data(base, words, buf16);
  996. else
  997. write_atapi_data(base, words, buf16);
  998. /* Transfer trailing 1 byte, if any. */
  999. if (unlikely(buflen & 0x01)) {
  1000. unsigned short align_buf[1] = { 0 };
  1001. unsigned char *trailing_buf = buf + buflen - 1;
  1002. if (rw == READ) {
  1003. read_atapi_data(base, 1, align_buf);
  1004. memcpy(trailing_buf, align_buf, 1);
  1005. } else {
  1006. memcpy(align_buf, trailing_buf, 1);
  1007. write_atapi_data(base, 1, align_buf);
  1008. }
  1009. words++;
  1010. }
  1011. return words << 1;
  1012. }
  1013. /**
  1014. * bfin_irq_clear - Clear ATAPI interrupt.
  1015. * @ap: Port associated with this ATA transaction.
  1016. *
  1017. * Note: Original code is ata_bmdma_irq_clear().
  1018. */
  1019. static void bfin_irq_clear(struct ata_port *ap)
  1020. {
  1021. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  1022. dev_dbg(ap->dev, "in atapi irq clear\n");
  1023. ATAPI_SET_INT_STATUS(base, ATAPI_GET_INT_STATUS(base)|ATAPI_DEV_INT
  1024. | MULTI_DONE_INT | UDMAIN_DONE_INT | UDMAOUT_DONE_INT
  1025. | MULTI_TERM_INT | UDMAIN_TERM_INT | UDMAOUT_TERM_INT);
  1026. }
  1027. /**
  1028. * bfin_thaw - Thaw DMA controller port
  1029. * @ap: port to thaw
  1030. *
  1031. * Note: Original code is ata_sff_thaw().
  1032. */
  1033. void bfin_thaw(struct ata_port *ap)
  1034. {
  1035. dev_dbg(ap->dev, "in atapi dma thaw\n");
  1036. bfin_check_status(ap);
  1037. ata_sff_irq_on(ap);
  1038. }
  1039. /**
  1040. * bfin_postreset - standard postreset callback
  1041. * @ap: the target ata_port
  1042. * @classes: classes of attached devices
  1043. *
  1044. * Note: Original code is ata_sff_postreset().
  1045. */
  1046. static void bfin_postreset(struct ata_link *link, unsigned int *classes)
  1047. {
  1048. struct ata_port *ap = link->ap;
  1049. void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
  1050. /* re-enable interrupts */
  1051. ata_sff_irq_on(ap);
  1052. /* is double-select really necessary? */
  1053. if (classes[0] != ATA_DEV_NONE)
  1054. bfin_dev_select(ap, 1);
  1055. if (classes[1] != ATA_DEV_NONE)
  1056. bfin_dev_select(ap, 0);
  1057. /* bail out if no device is present */
  1058. if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) {
  1059. return;
  1060. }
  1061. /* set up device control */
  1062. write_atapi_register(base, ATA_REG_CTRL, ap->ctl);
  1063. }
  1064. static void bfin_port_stop(struct ata_port *ap)
  1065. {
  1066. dev_dbg(ap->dev, "in atapi port stop\n");
  1067. if (ap->udma_mask != 0 || ap->mwdma_mask != 0) {
  1068. dma_free_coherent(ap->dev,
  1069. BFIN_MAX_SG_SEGMENTS * sizeof(struct dma_desc_array),
  1070. ap->bmdma_prd,
  1071. ap->bmdma_prd_dma);
  1072. free_dma(CH_ATAPI_RX);
  1073. free_dma(CH_ATAPI_TX);
  1074. }
  1075. }
  1076. static int bfin_port_start(struct ata_port *ap)
  1077. {
  1078. dev_dbg(ap->dev, "in atapi port start\n");
  1079. if (!(ap->udma_mask || ap->mwdma_mask))
  1080. return 0;
  1081. ap->bmdma_prd = dma_alloc_coherent(ap->dev,
  1082. BFIN_MAX_SG_SEGMENTS * sizeof(struct dma_desc_array),
  1083. &ap->bmdma_prd_dma,
  1084. GFP_KERNEL);
  1085. if (ap->bmdma_prd == NULL) {
  1086. dev_info(ap->dev, "Unable to allocate DMA descriptor array.\n");
  1087. goto out;
  1088. }
  1089. if (request_dma(CH_ATAPI_RX, "BFIN ATAPI RX DMA") >= 0) {
  1090. if (request_dma(CH_ATAPI_TX,
  1091. "BFIN ATAPI TX DMA") >= 0)
  1092. return 0;
  1093. free_dma(CH_ATAPI_RX);
  1094. dma_free_coherent(ap->dev,
  1095. BFIN_MAX_SG_SEGMENTS * sizeof(struct dma_desc_array),
  1096. ap->bmdma_prd,
  1097. ap->bmdma_prd_dma);
  1098. }
  1099. out:
  1100. ap->udma_mask = 0;
  1101. ap->mwdma_mask = 0;
  1102. dev_err(ap->dev, "Unable to request ATAPI DMA!"
  1103. " Continue in PIO mode.\n");
  1104. return 0;
  1105. }
  1106. static unsigned int bfin_ata_host_intr(struct ata_port *ap,
  1107. struct ata_queued_cmd *qc)
  1108. {
  1109. struct ata_eh_info *ehi = &ap->link.eh_info;
  1110. u8 status, host_stat = 0;
  1111. VPRINTK("ata%u: protocol %d task_state %d\n",
  1112. ap->print_id, qc->tf.protocol, ap->hsm_task_state);
  1113. /* Check whether we are expecting interrupt in this state */
  1114. switch (ap->hsm_task_state) {
  1115. case HSM_ST_FIRST:
  1116. /* Some pre-ATAPI-4 devices assert INTRQ
  1117. * at this state when ready to receive CDB.
  1118. */
  1119. /* Check the ATA_DFLAG_CDB_INTR flag is enough here.
  1120. * The flag was turned on only for atapi devices.
  1121. * No need to check is_atapi_taskfile(&qc->tf) again.
  1122. */
  1123. if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
  1124. goto idle_irq;
  1125. break;
  1126. case HSM_ST_LAST:
  1127. if (qc->tf.protocol == ATA_PROT_DMA ||
  1128. qc->tf.protocol == ATAPI_PROT_DMA) {
  1129. /* check status of DMA engine */
  1130. host_stat = ap->ops->bmdma_status(ap);
  1131. VPRINTK("ata%u: host_stat 0x%X\n",
  1132. ap->print_id, host_stat);
  1133. /* if it's not our irq... */
  1134. if (!(host_stat & ATA_DMA_INTR))
  1135. goto idle_irq;
  1136. /* before we do anything else, clear DMA-Start bit */
  1137. ap->ops->bmdma_stop(qc);
  1138. if (unlikely(host_stat & ATA_DMA_ERR)) {
  1139. /* error when transferring data to/from memory */
  1140. qc->err_mask |= AC_ERR_HOST_BUS;
  1141. ap->hsm_task_state = HSM_ST_ERR;
  1142. }
  1143. }
  1144. break;
  1145. case HSM_ST:
  1146. break;
  1147. default:
  1148. goto idle_irq;
  1149. }
  1150. /* check altstatus */
  1151. status = ap->ops->sff_check_altstatus(ap);
  1152. if (status & ATA_BUSY)
  1153. goto busy_ata;
  1154. /* check main status, clearing INTRQ */
  1155. status = ap->ops->sff_check_status(ap);
  1156. if (unlikely(status & ATA_BUSY))
  1157. goto busy_ata;
  1158. /* ack bmdma irq events */
  1159. ap->ops->sff_irq_clear(ap);
  1160. ata_sff_hsm_move(ap, qc, status, 0);
  1161. if (unlikely(qc->err_mask) && (qc->tf.protocol == ATA_PROT_DMA ||
  1162. qc->tf.protocol == ATAPI_PROT_DMA))
  1163. ata_ehi_push_desc(ehi, "BMDMA stat 0x%x", host_stat);
  1164. busy_ata:
  1165. return 1; /* irq handled */
  1166. idle_irq:
  1167. ap->stats.idle_irq++;
  1168. #ifdef ATA_IRQ_TRAP
  1169. if ((ap->stats.idle_irq % 1000) == 0) {
  1170. ap->ops->irq_ack(ap, 0); /* debug trap */
  1171. ata_port_warn(ap, "irq trap\n");
  1172. return 1;
  1173. }
  1174. #endif
  1175. return 0; /* irq not handled */
  1176. }
  1177. static irqreturn_t bfin_ata_interrupt(int irq, void *dev_instance)
  1178. {
  1179. struct ata_host *host = dev_instance;
  1180. unsigned int i;
  1181. unsigned int handled = 0;
  1182. unsigned long flags;
  1183. /* TODO: make _irqsave conditional on x86 PCI IDE legacy mode */
  1184. spin_lock_irqsave(&host->lock, flags);
  1185. for (i = 0; i < host->n_ports; i++) {
  1186. struct ata_port *ap = host->ports[i];
  1187. struct ata_queued_cmd *qc;
  1188. qc = ata_qc_from_tag(ap, ap->link.active_tag);
  1189. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
  1190. handled |= bfin_ata_host_intr(ap, qc);
  1191. }
  1192. spin_unlock_irqrestore(&host->lock, flags);
  1193. return IRQ_RETVAL(handled);
  1194. }
  1195. static struct scsi_host_template bfin_sht = {
  1196. ATA_BASE_SHT(DRV_NAME),
  1197. .sg_tablesize = BFIN_MAX_SG_SEGMENTS,
  1198. .dma_boundary = ATA_DMA_BOUNDARY,
  1199. };
  1200. static struct ata_port_operations bfin_pata_ops = {
  1201. .inherits = &ata_bmdma_port_ops,
  1202. .set_piomode = bfin_set_piomode,
  1203. .set_dmamode = bfin_set_dmamode,
  1204. .sff_tf_load = bfin_tf_load,
  1205. .sff_tf_read = bfin_tf_read,
  1206. .sff_exec_command = bfin_exec_command,
  1207. .sff_check_status = bfin_check_status,
  1208. .sff_check_altstatus = bfin_check_altstatus,
  1209. .sff_dev_select = bfin_dev_select,
  1210. .sff_set_devctl = bfin_set_devctl,
  1211. .bmdma_setup = bfin_bmdma_setup,
  1212. .bmdma_start = bfin_bmdma_start,
  1213. .bmdma_stop = bfin_bmdma_stop,
  1214. .bmdma_status = bfin_bmdma_status,
  1215. .sff_data_xfer = bfin_data_xfer,
  1216. .qc_prep = ata_noop_qc_prep,
  1217. .thaw = bfin_thaw,
  1218. .softreset = bfin_softreset,
  1219. .postreset = bfin_postreset,
  1220. .sff_irq_clear = bfin_irq_clear,
  1221. .port_start = bfin_port_start,
  1222. .port_stop = bfin_port_stop,
  1223. };
  1224. static struct ata_port_info bfin_port_info[] = {
  1225. {
  1226. .flags = ATA_FLAG_SLAVE_POSS,
  1227. .pio_mask = ATA_PIO4,
  1228. .mwdma_mask = 0,
  1229. .udma_mask = 0,
  1230. .port_ops = &bfin_pata_ops,
  1231. },
  1232. };
  1233. /**
  1234. * bfin_reset_controller - initialize BF54x ATAPI controller.
  1235. */
  1236. static int bfin_reset_controller(struct ata_host *host)
  1237. {
  1238. void __iomem *base = (void __iomem *)host->ports[0]->ioaddr.ctl_addr;
  1239. int count;
  1240. unsigned short status;
  1241. /* Disable all ATAPI interrupts */
  1242. ATAPI_SET_INT_MASK(base, 0);
  1243. SSYNC();
  1244. /* Assert the RESET signal 25us*/
  1245. ATAPI_SET_CONTROL(base, ATAPI_GET_CONTROL(base) | DEV_RST);
  1246. udelay(30);
  1247. /* Negate the RESET signal for 2ms*/
  1248. ATAPI_SET_CONTROL(base, ATAPI_GET_CONTROL(base) & ~DEV_RST);
  1249. msleep(2);
  1250. /* Wait on Busy flag to clear */
  1251. count = 10000000;
  1252. do {
  1253. status = read_atapi_register(base, ATA_REG_STATUS);
  1254. } while (--count && (status & ATA_BUSY));
  1255. /* Enable only ATAPI Device interrupt */
  1256. ATAPI_SET_INT_MASK(base, 1);
  1257. SSYNC();
  1258. return (!count);
  1259. }
  1260. /**
  1261. * atapi_io_port - define atapi peripheral port pins.
  1262. */
  1263. static unsigned short atapi_io_port[] = {
  1264. P_ATAPI_RESET,
  1265. P_ATAPI_DIOR,
  1266. P_ATAPI_DIOW,
  1267. P_ATAPI_CS0,
  1268. P_ATAPI_CS1,
  1269. P_ATAPI_DMACK,
  1270. P_ATAPI_DMARQ,
  1271. P_ATAPI_INTRQ,
  1272. P_ATAPI_IORDY,
  1273. P_ATAPI_D0A,
  1274. P_ATAPI_D1A,
  1275. P_ATAPI_D2A,
  1276. P_ATAPI_D3A,
  1277. P_ATAPI_D4A,
  1278. P_ATAPI_D5A,
  1279. P_ATAPI_D6A,
  1280. P_ATAPI_D7A,
  1281. P_ATAPI_D8A,
  1282. P_ATAPI_D9A,
  1283. P_ATAPI_D10A,
  1284. P_ATAPI_D11A,
  1285. P_ATAPI_D12A,
  1286. P_ATAPI_D13A,
  1287. P_ATAPI_D14A,
  1288. P_ATAPI_D15A,
  1289. P_ATAPI_A0A,
  1290. P_ATAPI_A1A,
  1291. P_ATAPI_A2A,
  1292. 0
  1293. };
  1294. /**
  1295. * bfin_atapi_probe - attach a bfin atapi interface
  1296. * @pdev: platform device
  1297. *
  1298. * Register a bfin atapi interface.
  1299. *
  1300. *
  1301. * Platform devices are expected to contain 2 resources per port:
  1302. *
  1303. * - I/O Base (IORESOURCE_IO)
  1304. * - IRQ (IORESOURCE_IRQ)
  1305. *
  1306. */
  1307. static int bfin_atapi_probe(struct platform_device *pdev)
  1308. {
  1309. int board_idx = 0;
  1310. struct resource *res;
  1311. struct ata_host *host;
  1312. unsigned int fsclk = get_sclk();
  1313. int udma_mode = 5;
  1314. const struct ata_port_info *ppi[] =
  1315. { &bfin_port_info[board_idx], NULL };
  1316. /*
  1317. * Simple resource validation ..
  1318. */
  1319. if (unlikely(pdev->num_resources != 2)) {
  1320. dev_err(&pdev->dev, "invalid number of resources\n");
  1321. return -EINVAL;
  1322. }
  1323. /*
  1324. * Get the register base first
  1325. */
  1326. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1327. if (res == NULL)
  1328. return -EINVAL;
  1329. while (bfin_port_info[board_idx].udma_mask > 0 &&
  1330. udma_fsclk[udma_mode] > fsclk) {
  1331. udma_mode--;
  1332. bfin_port_info[board_idx].udma_mask >>= 1;
  1333. }
  1334. /*
  1335. * Now that that's out of the way, wire up the port..
  1336. */
  1337. host = ata_host_alloc_pinfo(&pdev->dev, ppi, 1);
  1338. if (!host)
  1339. return -ENOMEM;
  1340. host->ports[0]->ioaddr.ctl_addr = (void *)res->start;
  1341. if (peripheral_request_list(atapi_io_port, "atapi-io-port")) {
  1342. dev_err(&pdev->dev, "Requesting Peripherals failed\n");
  1343. return -EFAULT;
  1344. }
  1345. if (bfin_reset_controller(host)) {
  1346. peripheral_free_list(atapi_io_port);
  1347. dev_err(&pdev->dev, "Fail to reset ATAPI device\n");
  1348. return -EFAULT;
  1349. }
  1350. if (ata_host_activate(host, platform_get_irq(pdev, 0),
  1351. bfin_ata_interrupt, IRQF_SHARED, &bfin_sht) != 0) {
  1352. peripheral_free_list(atapi_io_port);
  1353. dev_err(&pdev->dev, "Fail to attach ATAPI device\n");
  1354. return -ENODEV;
  1355. }
  1356. platform_set_drvdata(pdev, host);
  1357. return 0;
  1358. }
  1359. /**
  1360. * bfin_atapi_remove - unplug a bfin atapi interface
  1361. * @pdev: platform device
  1362. *
  1363. * A bfin atapi device has been unplugged. Perform the needed
  1364. * cleanup. Also called on module unload for any active devices.
  1365. */
  1366. static int bfin_atapi_remove(struct platform_device *pdev)
  1367. {
  1368. struct ata_host *host = platform_get_drvdata(pdev);
  1369. ata_host_detach(host);
  1370. peripheral_free_list(atapi_io_port);
  1371. return 0;
  1372. }
  1373. #ifdef CONFIG_PM_SLEEP
  1374. static int bfin_atapi_suspend(struct platform_device *pdev, pm_message_t state)
  1375. {
  1376. struct ata_host *host = platform_get_drvdata(pdev);
  1377. if (host)
  1378. return ata_host_suspend(host, state);
  1379. else
  1380. return 0;
  1381. }
  1382. static int bfin_atapi_resume(struct platform_device *pdev)
  1383. {
  1384. struct ata_host *host = platform_get_drvdata(pdev);
  1385. int ret;
  1386. if (host) {
  1387. ret = bfin_reset_controller(host);
  1388. if (ret) {
  1389. printk(KERN_ERR DRV_NAME ": Error during HW init\n");
  1390. return ret;
  1391. }
  1392. ata_host_resume(host);
  1393. }
  1394. return 0;
  1395. }
  1396. #else
  1397. #define bfin_atapi_suspend NULL
  1398. #define bfin_atapi_resume NULL
  1399. #endif
  1400. static struct platform_driver bfin_atapi_driver = {
  1401. .probe = bfin_atapi_probe,
  1402. .remove = bfin_atapi_remove,
  1403. .suspend = bfin_atapi_suspend,
  1404. .resume = bfin_atapi_resume,
  1405. .driver = {
  1406. .name = DRV_NAME,
  1407. },
  1408. };
  1409. #define ATAPI_MODE_SIZE 10
  1410. static char bfin_atapi_mode[ATAPI_MODE_SIZE];
  1411. static int __init bfin_atapi_init(void)
  1412. {
  1413. pr_info("register bfin atapi driver\n");
  1414. switch(bfin_atapi_mode[0]) {
  1415. case 'p':
  1416. case 'P':
  1417. break;
  1418. case 'm':
  1419. case 'M':
  1420. bfin_port_info[0].mwdma_mask = ATA_MWDMA2;
  1421. break;
  1422. default:
  1423. bfin_port_info[0].udma_mask = ATA_UDMA5;
  1424. };
  1425. return platform_driver_register(&bfin_atapi_driver);
  1426. }
  1427. static void __exit bfin_atapi_exit(void)
  1428. {
  1429. platform_driver_unregister(&bfin_atapi_driver);
  1430. }
  1431. module_init(bfin_atapi_init);
  1432. module_exit(bfin_atapi_exit);
  1433. /*
  1434. * ATAPI mode:
  1435. * pio/PIO
  1436. * udma/UDMA (default)
  1437. * mwdma/MWDMA
  1438. */
  1439. module_param_string(bfin_atapi_mode, bfin_atapi_mode, ATAPI_MODE_SIZE, 0);
  1440. MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
  1441. MODULE_DESCRIPTION("PATA driver for blackfin 54x ATAPI controller");
  1442. MODULE_LICENSE("GPL");
  1443. MODULE_VERSION(DRV_VERSION);
  1444. MODULE_ALIAS("platform:" DRV_NAME);