pata_bf54x.c 46 KB

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