au1xxx-ide.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. /*
  2. * linux/drivers/ide/mips/au1xxx-ide.c version 01.30.00 Aug. 02 2005
  3. *
  4. * BRIEF MODULE DESCRIPTION
  5. * AMD Alchemy Au1xxx IDE interface routines over the Static Bus
  6. *
  7. * Copyright (c) 2003-2005 AMD, Personal Connectivity Solutions
  8. *
  9. * This program is free software; you can redistribute it and/or modify it under
  10. * the terms of the GNU General Public License as published by the Free Software
  11. * Foundation; either version 2 of the License, or (at your option) any later
  12. * version.
  13. *
  14. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  15. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  16. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. * POSSIBILITY OF SUCH DAMAGE.
  24. *
  25. * You should have received a copy of the GNU General Public License along with
  26. * this program; if not, write to the Free Software Foundation, Inc.,
  27. * 675 Mass Ave, Cambridge, MA 02139, USA.
  28. *
  29. * Note: for more information, please refer "AMD Alchemy Au1200/Au1550 IDE
  30. * Interface and Linux Device Driver" Application Note.
  31. */
  32. #undef REALLY_SLOW_IO /* most systems can safely undef this */
  33. #include <linux/types.h>
  34. #include <linux/module.h>
  35. #include <linux/kernel.h>
  36. #include <linux/delay.h>
  37. #include <linux/platform_device.h>
  38. #include <linux/init.h>
  39. #include <linux/ide.h>
  40. #include <linux/sysdev.h>
  41. #include <linux/dma-mapping.h>
  42. #include "ide-timing.h"
  43. #include <asm/io.h>
  44. #include <asm/mach-au1x00/au1xxx.h>
  45. #include <asm/mach-au1x00/au1xxx_dbdma.h>
  46. #include <asm/mach-au1x00/au1xxx_ide.h>
  47. #define DRV_NAME "au1200-ide"
  48. #define DRV_VERSION "1.0"
  49. #define DRV_AUTHOR "Enrico Walther <enrico.walther@amd.com> / Pete Popov <ppopov@embeddedalley.com>"
  50. /* enable the burstmode in the dbdma */
  51. #define IDE_AU1XXX_BURSTMODE 1
  52. static _auide_hwif auide_hwif;
  53. static int dbdma_init_done;
  54. #if defined(CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA)
  55. void auide_insw(unsigned long port, void *addr, u32 count)
  56. {
  57. _auide_hwif *ahwif = &auide_hwif;
  58. chan_tab_t *ctp;
  59. au1x_ddma_desc_t *dp;
  60. if(!put_dest_flags(ahwif->rx_chan, (void*)addr, count << 1,
  61. DDMA_FLAGS_NOIE)) {
  62. printk(KERN_ERR "%s failed %d\n", __FUNCTION__, __LINE__);
  63. return;
  64. }
  65. ctp = *((chan_tab_t **)ahwif->rx_chan);
  66. dp = ctp->cur_ptr;
  67. while (dp->dscr_cmd0 & DSCR_CMD0_V)
  68. ;
  69. ctp->cur_ptr = au1xxx_ddma_get_nextptr_virt(dp);
  70. }
  71. void auide_outsw(unsigned long port, void *addr, u32 count)
  72. {
  73. _auide_hwif *ahwif = &auide_hwif;
  74. chan_tab_t *ctp;
  75. au1x_ddma_desc_t *dp;
  76. if(!put_source_flags(ahwif->tx_chan, (void*)addr,
  77. count << 1, DDMA_FLAGS_NOIE)) {
  78. printk(KERN_ERR "%s failed %d\n", __FUNCTION__, __LINE__);
  79. return;
  80. }
  81. ctp = *((chan_tab_t **)ahwif->tx_chan);
  82. dp = ctp->cur_ptr;
  83. while (dp->dscr_cmd0 & DSCR_CMD0_V)
  84. ;
  85. ctp->cur_ptr = au1xxx_ddma_get_nextptr_virt(dp);
  86. }
  87. #endif
  88. static void auide_tune_drive(ide_drive_t *drive, byte pio)
  89. {
  90. int mem_sttime;
  91. int mem_stcfg;
  92. u8 speed;
  93. /* get the best pio mode for the drive */
  94. pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
  95. printk(KERN_INFO "%s: setting Au1XXX IDE to PIO mode%d\n",
  96. drive->name, pio);
  97. mem_sttime = 0;
  98. mem_stcfg = au_readl(MEM_STCFG2);
  99. /* set pio mode! */
  100. switch(pio) {
  101. case 0:
  102. mem_sttime = SBC_IDE_TIMING(PIO0);
  103. /* set configuration for RCS2# */
  104. mem_stcfg |= TS_MASK;
  105. mem_stcfg &= ~TCSOE_MASK;
  106. mem_stcfg &= ~TOECS_MASK;
  107. mem_stcfg |= SBC_IDE_PIO0_TCSOE | SBC_IDE_PIO0_TOECS;
  108. break;
  109. case 1:
  110. mem_sttime = SBC_IDE_TIMING(PIO1);
  111. /* set configuration for RCS2# */
  112. mem_stcfg |= TS_MASK;
  113. mem_stcfg &= ~TCSOE_MASK;
  114. mem_stcfg &= ~TOECS_MASK;
  115. mem_stcfg |= SBC_IDE_PIO1_TCSOE | SBC_IDE_PIO1_TOECS;
  116. break;
  117. case 2:
  118. mem_sttime = SBC_IDE_TIMING(PIO2);
  119. /* set configuration for RCS2# */
  120. mem_stcfg &= ~TS_MASK;
  121. mem_stcfg &= ~TCSOE_MASK;
  122. mem_stcfg &= ~TOECS_MASK;
  123. mem_stcfg |= SBC_IDE_PIO2_TCSOE | SBC_IDE_PIO2_TOECS;
  124. break;
  125. case 3:
  126. mem_sttime = SBC_IDE_TIMING(PIO3);
  127. /* set configuration for RCS2# */
  128. mem_stcfg &= ~TS_MASK;
  129. mem_stcfg &= ~TCSOE_MASK;
  130. mem_stcfg &= ~TOECS_MASK;
  131. mem_stcfg |= SBC_IDE_PIO3_TCSOE | SBC_IDE_PIO3_TOECS;
  132. break;
  133. case 4:
  134. mem_sttime = SBC_IDE_TIMING(PIO4);
  135. /* set configuration for RCS2# */
  136. mem_stcfg &= ~TS_MASK;
  137. mem_stcfg &= ~TCSOE_MASK;
  138. mem_stcfg &= ~TOECS_MASK;
  139. mem_stcfg |= SBC_IDE_PIO4_TCSOE | SBC_IDE_PIO4_TOECS;
  140. break;
  141. }
  142. au_writel(mem_sttime,MEM_STTIME2);
  143. au_writel(mem_stcfg,MEM_STCFG2);
  144. speed = pio + XFER_PIO_0;
  145. ide_config_drive_speed(drive, speed);
  146. }
  147. static int auide_tune_chipset (ide_drive_t *drive, u8 speed)
  148. {
  149. int mem_sttime;
  150. int mem_stcfg;
  151. unsigned long mode;
  152. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
  153. if (ide_use_dma(drive))
  154. mode = ide_dma_speed(drive, 0);
  155. #endif
  156. mem_sttime = 0;
  157. mem_stcfg = au_readl(MEM_STCFG2);
  158. if (speed >= XFER_PIO_0 && speed <= XFER_PIO_4) {
  159. auide_tune_drive(drive, speed - XFER_PIO_0);
  160. return 0;
  161. }
  162. switch(speed) {
  163. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
  164. case XFER_MW_DMA_2:
  165. mem_sttime = SBC_IDE_TIMING(MDMA2);
  166. /* set configuration for RCS2# */
  167. mem_stcfg &= ~TS_MASK;
  168. mem_stcfg &= ~TCSOE_MASK;
  169. mem_stcfg &= ~TOECS_MASK;
  170. mem_stcfg |= SBC_IDE_MDMA2_TCSOE | SBC_IDE_MDMA2_TOECS;
  171. mode = XFER_MW_DMA_2;
  172. break;
  173. case XFER_MW_DMA_1:
  174. mem_sttime = SBC_IDE_TIMING(MDMA1);
  175. /* set configuration for RCS2# */
  176. mem_stcfg &= ~TS_MASK;
  177. mem_stcfg &= ~TCSOE_MASK;
  178. mem_stcfg &= ~TOECS_MASK;
  179. mem_stcfg |= SBC_IDE_MDMA1_TCSOE | SBC_IDE_MDMA1_TOECS;
  180. mode = XFER_MW_DMA_1;
  181. break;
  182. case XFER_MW_DMA_0:
  183. mem_sttime = SBC_IDE_TIMING(MDMA0);
  184. /* set configuration for RCS2# */
  185. mem_stcfg |= TS_MASK;
  186. mem_stcfg &= ~TCSOE_MASK;
  187. mem_stcfg &= ~TOECS_MASK;
  188. mem_stcfg |= SBC_IDE_MDMA0_TCSOE | SBC_IDE_MDMA0_TOECS;
  189. mode = XFER_MW_DMA_0;
  190. break;
  191. #endif
  192. default:
  193. return 1;
  194. }
  195. if (ide_config_drive_speed(drive, mode))
  196. return 1;
  197. au_writel(mem_sttime,MEM_STTIME2);
  198. au_writel(mem_stcfg,MEM_STCFG2);
  199. return 0;
  200. }
  201. /*
  202. * Multi-Word DMA + DbDMA functions
  203. */
  204. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
  205. static int auide_build_sglist(ide_drive_t *drive, struct request *rq)
  206. {
  207. ide_hwif_t *hwif = drive->hwif;
  208. _auide_hwif *ahwif = (_auide_hwif*)hwif->hwif_data;
  209. struct scatterlist *sg = hwif->sg_table;
  210. ide_map_sg(drive, rq);
  211. if (rq_data_dir(rq) == READ)
  212. hwif->sg_dma_direction = DMA_FROM_DEVICE;
  213. else
  214. hwif->sg_dma_direction = DMA_TO_DEVICE;
  215. return dma_map_sg(ahwif->dev, sg, hwif->sg_nents,
  216. hwif->sg_dma_direction);
  217. }
  218. static int auide_build_dmatable(ide_drive_t *drive)
  219. {
  220. int i, iswrite, count = 0;
  221. ide_hwif_t *hwif = HWIF(drive);
  222. struct request *rq = HWGROUP(drive)->rq;
  223. _auide_hwif *ahwif = (_auide_hwif*)hwif->hwif_data;
  224. struct scatterlist *sg;
  225. iswrite = (rq_data_dir(rq) == WRITE);
  226. /* Save for interrupt context */
  227. ahwif->drive = drive;
  228. /* Build sglist */
  229. hwif->sg_nents = i = auide_build_sglist(drive, rq);
  230. if (!i)
  231. return 0;
  232. /* fill the descriptors */
  233. sg = hwif->sg_table;
  234. while (i && sg_dma_len(sg)) {
  235. u32 cur_addr;
  236. u32 cur_len;
  237. cur_addr = sg_dma_address(sg);
  238. cur_len = sg_dma_len(sg);
  239. while (cur_len) {
  240. u32 flags = DDMA_FLAGS_NOIE;
  241. unsigned int tc = (cur_len < 0xfe00)? cur_len: 0xfe00;
  242. if (++count >= PRD_ENTRIES) {
  243. printk(KERN_WARNING "%s: DMA table too small\n",
  244. drive->name);
  245. goto use_pio_instead;
  246. }
  247. /* Lets enable intr for the last descriptor only */
  248. if (1==i)
  249. flags = DDMA_FLAGS_IE;
  250. else
  251. flags = DDMA_FLAGS_NOIE;
  252. if (iswrite) {
  253. if(!put_source_flags(ahwif->tx_chan,
  254. (void*)(page_address(sg->page)
  255. + sg->offset),
  256. tc, flags)) {
  257. printk(KERN_ERR "%s failed %d\n",
  258. __FUNCTION__, __LINE__);
  259. }
  260. } else
  261. {
  262. if(!put_dest_flags(ahwif->rx_chan,
  263. (void*)(page_address(sg->page)
  264. + sg->offset),
  265. tc, flags)) {
  266. printk(KERN_ERR "%s failed %d\n",
  267. __FUNCTION__, __LINE__);
  268. }
  269. }
  270. cur_addr += tc;
  271. cur_len -= tc;
  272. }
  273. sg++;
  274. i--;
  275. }
  276. if (count)
  277. return 1;
  278. use_pio_instead:
  279. dma_unmap_sg(ahwif->dev,
  280. hwif->sg_table,
  281. hwif->sg_nents,
  282. hwif->sg_dma_direction);
  283. return 0; /* revert to PIO for this request */
  284. }
  285. static int auide_dma_end(ide_drive_t *drive)
  286. {
  287. ide_hwif_t *hwif = HWIF(drive);
  288. _auide_hwif *ahwif = (_auide_hwif*)hwif->hwif_data;
  289. if (hwif->sg_nents) {
  290. dma_unmap_sg(ahwif->dev, hwif->sg_table, hwif->sg_nents,
  291. hwif->sg_dma_direction);
  292. hwif->sg_nents = 0;
  293. }
  294. return 0;
  295. }
  296. static void auide_dma_start(ide_drive_t *drive )
  297. {
  298. }
  299. static void auide_dma_exec_cmd(ide_drive_t *drive, u8 command)
  300. {
  301. /* issue cmd to drive */
  302. ide_execute_command(drive, command, &ide_dma_intr,
  303. (2*WAIT_CMD), NULL);
  304. }
  305. static int auide_dma_setup(ide_drive_t *drive)
  306. {
  307. struct request *rq = HWGROUP(drive)->rq;
  308. if (!auide_build_dmatable(drive)) {
  309. ide_map_sg(drive, rq);
  310. return 1;
  311. }
  312. drive->waiting_for_dma = 1;
  313. return 0;
  314. }
  315. static int auide_dma_check(ide_drive_t *drive)
  316. {
  317. u8 speed;
  318. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
  319. if( dbdma_init_done == 0 ){
  320. auide_hwif.white_list = ide_in_drive_list(drive->id,
  321. dma_white_list);
  322. auide_hwif.black_list = ide_in_drive_list(drive->id,
  323. dma_black_list);
  324. auide_hwif.drive = drive;
  325. auide_ddma_init(&auide_hwif);
  326. dbdma_init_done = 1;
  327. }
  328. #endif
  329. /* Is the drive in our DMA black list? */
  330. if ( auide_hwif.black_list ) {
  331. drive->using_dma = 0;
  332. /* Borrowed the warning message from ide-dma.c */
  333. printk(KERN_WARNING "%s: Disabling DMA for %s (blacklisted)\n",
  334. drive->name, drive->id->model);
  335. }
  336. else
  337. drive->using_dma = 1;
  338. speed = ide_find_best_mode(drive, XFER_PIO | XFER_MWDMA);
  339. if (drive->autodma && (speed & XFER_MODE) != XFER_PIO)
  340. return HWIF(drive)->ide_dma_on(drive);
  341. return HWIF(drive)->ide_dma_off_quietly(drive);
  342. }
  343. static int auide_dma_test_irq(ide_drive_t *drive)
  344. {
  345. if (drive->waiting_for_dma == 0)
  346. printk(KERN_WARNING "%s: ide_dma_test_irq \
  347. called while not waiting\n", drive->name);
  348. /* If dbdma didn't execute the STOP command yet, the
  349. * active bit is still set
  350. */
  351. drive->waiting_for_dma++;
  352. if (drive->waiting_for_dma >= DMA_WAIT_TIMEOUT) {
  353. printk(KERN_WARNING "%s: timeout waiting for ddma to \
  354. complete\n", drive->name);
  355. return 1;
  356. }
  357. udelay(10);
  358. return 0;
  359. }
  360. static int auide_dma_host_on(ide_drive_t *drive)
  361. {
  362. return 0;
  363. }
  364. static int auide_dma_on(ide_drive_t *drive)
  365. {
  366. drive->using_dma = 1;
  367. return auide_dma_host_on(drive);
  368. }
  369. static int auide_dma_host_off(ide_drive_t *drive)
  370. {
  371. return 0;
  372. }
  373. static int auide_dma_off_quietly(ide_drive_t *drive)
  374. {
  375. drive->using_dma = 0;
  376. return auide_dma_host_off(drive);
  377. }
  378. static int auide_dma_lostirq(ide_drive_t *drive)
  379. {
  380. printk(KERN_ERR "%s: IRQ lost\n", drive->name);
  381. return 0;
  382. }
  383. static void auide_ddma_tx_callback(int irq, void *param)
  384. {
  385. _auide_hwif *ahwif = (_auide_hwif*)param;
  386. ahwif->drive->waiting_for_dma = 0;
  387. }
  388. static void auide_ddma_rx_callback(int irq, void *param)
  389. {
  390. _auide_hwif *ahwif = (_auide_hwif*)param;
  391. ahwif->drive->waiting_for_dma = 0;
  392. }
  393. #endif /* end CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA */
  394. static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize, u32 devwidth, u32 flags)
  395. {
  396. dev->dev_id = dev_id;
  397. dev->dev_physaddr = (u32)AU1XXX_ATA_PHYS_ADDR;
  398. dev->dev_intlevel = 0;
  399. dev->dev_intpolarity = 0;
  400. dev->dev_tsize = tsize;
  401. dev->dev_devwidth = devwidth;
  402. dev->dev_flags = flags;
  403. }
  404. #if defined(CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA)
  405. static int auide_dma_timeout(ide_drive_t *drive)
  406. {
  407. // printk("%s\n", __FUNCTION__);
  408. printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
  409. if (HWIF(drive)->ide_dma_test_irq(drive))
  410. return 0;
  411. return HWIF(drive)->ide_dma_end(drive);
  412. }
  413. static int auide_ddma_init(_auide_hwif *auide) {
  414. dbdev_tab_t source_dev_tab, target_dev_tab;
  415. u32 dev_id, tsize, devwidth, flags;
  416. ide_hwif_t *hwif = auide->hwif;
  417. dev_id = AU1XXX_ATA_DDMA_REQ;
  418. if (auide->white_list || auide->black_list) {
  419. tsize = 8;
  420. devwidth = 32;
  421. }
  422. else {
  423. tsize = 1;
  424. devwidth = 16;
  425. printk(KERN_ERR "au1xxx-ide: %s is not on ide driver whitelist.\n",auide_hwif.drive->id->model);
  426. printk(KERN_ERR " please read 'Documentation/mips/AU1xxx_IDE.README'");
  427. }
  428. #ifdef IDE_AU1XXX_BURSTMODE
  429. flags = DEV_FLAGS_SYNC | DEV_FLAGS_BURSTABLE;
  430. #else
  431. flags = DEV_FLAGS_SYNC;
  432. #endif
  433. /* setup dev_tab for tx channel */
  434. auide_init_dbdma_dev( &source_dev_tab,
  435. dev_id,
  436. tsize, devwidth, DEV_FLAGS_OUT | flags);
  437. auide->tx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
  438. auide_init_dbdma_dev( &source_dev_tab,
  439. dev_id,
  440. tsize, devwidth, DEV_FLAGS_IN | flags);
  441. auide->rx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
  442. /* We also need to add a target device for the DMA */
  443. auide_init_dbdma_dev( &target_dev_tab,
  444. (u32)DSCR_CMD0_ALWAYS,
  445. tsize, devwidth, DEV_FLAGS_ANYUSE);
  446. auide->target_dev_id = au1xxx_ddma_add_device(&target_dev_tab);
  447. /* Get a channel for TX */
  448. auide->tx_chan = au1xxx_dbdma_chan_alloc(auide->target_dev_id,
  449. auide->tx_dev_id,
  450. auide_ddma_tx_callback,
  451. (void*)auide);
  452. /* Get a channel for RX */
  453. auide->rx_chan = au1xxx_dbdma_chan_alloc(auide->rx_dev_id,
  454. auide->target_dev_id,
  455. auide_ddma_rx_callback,
  456. (void*)auide);
  457. auide->tx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->tx_chan,
  458. NUM_DESCRIPTORS);
  459. auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan,
  460. NUM_DESCRIPTORS);
  461. hwif->dmatable_cpu = dma_alloc_coherent(auide->dev,
  462. PRD_ENTRIES * PRD_BYTES, /* 1 Page */
  463. &hwif->dmatable_dma, GFP_KERNEL);
  464. au1xxx_dbdma_start( auide->tx_chan );
  465. au1xxx_dbdma_start( auide->rx_chan );
  466. return 0;
  467. }
  468. #else
  469. static int auide_ddma_init( _auide_hwif *auide )
  470. {
  471. dbdev_tab_t source_dev_tab;
  472. int flags;
  473. #ifdef IDE_AU1XXX_BURSTMODE
  474. flags = DEV_FLAGS_SYNC | DEV_FLAGS_BURSTABLE;
  475. #else
  476. flags = DEV_FLAGS_SYNC;
  477. #endif
  478. /* setup dev_tab for tx channel */
  479. auide_init_dbdma_dev( &source_dev_tab,
  480. (u32)DSCR_CMD0_ALWAYS,
  481. 8, 32, DEV_FLAGS_OUT | flags);
  482. auide->tx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
  483. auide_init_dbdma_dev( &source_dev_tab,
  484. (u32)DSCR_CMD0_ALWAYS,
  485. 8, 32, DEV_FLAGS_IN | flags);
  486. auide->rx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
  487. /* Get a channel for TX */
  488. auide->tx_chan = au1xxx_dbdma_chan_alloc(DSCR_CMD0_ALWAYS,
  489. auide->tx_dev_id,
  490. NULL,
  491. (void*)auide);
  492. /* Get a channel for RX */
  493. auide->rx_chan = au1xxx_dbdma_chan_alloc(auide->rx_dev_id,
  494. DSCR_CMD0_ALWAYS,
  495. NULL,
  496. (void*)auide);
  497. auide->tx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->tx_chan,
  498. NUM_DESCRIPTORS);
  499. auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan,
  500. NUM_DESCRIPTORS);
  501. au1xxx_dbdma_start( auide->tx_chan );
  502. au1xxx_dbdma_start( auide->rx_chan );
  503. return 0;
  504. }
  505. #endif
  506. static void auide_setup_ports(hw_regs_t *hw, _auide_hwif *ahwif)
  507. {
  508. int i;
  509. unsigned long *ata_regs = hw->io_ports;
  510. /* FIXME? */
  511. for (i = 0; i < IDE_CONTROL_OFFSET; i++) {
  512. *ata_regs++ = ahwif->regbase + (i << AU1XXX_ATA_REG_OFFSET);
  513. }
  514. /* set the Alternative Status register */
  515. *ata_regs = ahwif->regbase + (14 << AU1XXX_ATA_REG_OFFSET);
  516. }
  517. static int au_ide_probe(struct device *dev)
  518. {
  519. struct platform_device *pdev = to_platform_device(dev);
  520. _auide_hwif *ahwif = &auide_hwif;
  521. ide_hwif_t *hwif;
  522. struct resource *res;
  523. int ret = 0;
  524. #if defined(CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA)
  525. char *mode = "MWDMA2";
  526. #elif defined(CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA)
  527. char *mode = "PIO+DDMA(offload)";
  528. #endif
  529. memset(&auide_hwif, 0, sizeof(_auide_hwif));
  530. auide_hwif.dev = 0;
  531. ahwif->dev = dev;
  532. ahwif->irq = platform_get_irq(pdev, 0);
  533. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  534. if (res == NULL) {
  535. pr_debug("%s %d: no base address\n", DRV_NAME, pdev->id);
  536. ret = -ENODEV;
  537. goto out;
  538. }
  539. if (ahwif->irq < 0) {
  540. pr_debug("%s %d: no IRQ\n", DRV_NAME, pdev->id);
  541. ret = -ENODEV;
  542. goto out;
  543. }
  544. if (!request_mem_region (res->start, res->end-res->start, pdev->name)) {
  545. pr_debug("%s: request_mem_region failed\n", DRV_NAME);
  546. ret = -EBUSY;
  547. goto out;
  548. }
  549. ahwif->regbase = (u32)ioremap(res->start, res->end-res->start);
  550. if (ahwif->regbase == 0) {
  551. ret = -ENOMEM;
  552. goto out;
  553. }
  554. /* FIXME: This might possibly break PCMCIA IDE devices */
  555. hwif = &ide_hwifs[pdev->id];
  556. hw_regs_t *hw = &hwif->hw;
  557. hwif->irq = hw->irq = ahwif->irq;
  558. hwif->chipset = ide_au1xxx;
  559. auide_setup_ports(hw, ahwif);
  560. memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
  561. hwif->ultra_mask = 0x0; /* Disable Ultra DMA */
  562. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
  563. hwif->mwdma_mask = 0x07; /* Multimode-2 DMA */
  564. hwif->swdma_mask = 0x00;
  565. #else
  566. hwif->mwdma_mask = 0x0;
  567. hwif->swdma_mask = 0x0;
  568. #endif
  569. hwif->noprobe = 0;
  570. hwif->drives[0].unmask = 1;
  571. hwif->drives[1].unmask = 1;
  572. /* hold should be on in all cases */
  573. hwif->hold = 1;
  574. hwif->mmio = 2;
  575. /* If the user has selected DDMA assisted copies,
  576. then set up a few local I/O function entry points
  577. */
  578. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA
  579. hwif->INSW = auide_insw;
  580. hwif->OUTSW = auide_outsw;
  581. #endif
  582. hwif->tuneproc = &auide_tune_drive;
  583. hwif->speedproc = &auide_tune_chipset;
  584. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
  585. hwif->ide_dma_off_quietly = &auide_dma_off_quietly;
  586. hwif->ide_dma_timeout = &auide_dma_timeout;
  587. hwif->ide_dma_check = &auide_dma_check;
  588. hwif->dma_exec_cmd = &auide_dma_exec_cmd;
  589. hwif->dma_start = &auide_dma_start;
  590. hwif->ide_dma_end = &auide_dma_end;
  591. hwif->dma_setup = &auide_dma_setup;
  592. hwif->ide_dma_test_irq = &auide_dma_test_irq;
  593. hwif->ide_dma_host_off = &auide_dma_host_off;
  594. hwif->ide_dma_host_on = &auide_dma_host_on;
  595. hwif->ide_dma_lostirq = &auide_dma_lostirq;
  596. hwif->ide_dma_on = &auide_dma_on;
  597. hwif->autodma = 1;
  598. hwif->drives[0].autodma = hwif->autodma;
  599. hwif->drives[1].autodma = hwif->autodma;
  600. hwif->atapi_dma = 1;
  601. #else /* !CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA */
  602. hwif->autodma = 0;
  603. hwif->channel = 0;
  604. hwif->hold = 1;
  605. hwif->select_data = 0; /* no chipset-specific code */
  606. hwif->config_data = 0; /* no chipset-specific code */
  607. hwif->drives[0].autodma = 0;
  608. hwif->drives[0].autotune = 1; /* 1=autotune, 2=noautotune, 0=default */
  609. #endif
  610. hwif->drives[0].no_io_32bit = 1;
  611. auide_hwif.hwif = hwif;
  612. hwif->hwif_data = &auide_hwif;
  613. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA
  614. auide_ddma_init(&auide_hwif);
  615. dbdma_init_done = 1;
  616. #endif
  617. probe_hwif_init(hwif);
  618. dev_set_drvdata(dev, hwif);
  619. printk(KERN_INFO "Au1xxx IDE(builtin) configured for %s\n", mode );
  620. out:
  621. return ret;
  622. }
  623. static int au_ide_remove(struct device *dev)
  624. {
  625. struct platform_device *pdev = to_platform_device(dev);
  626. struct resource *res;
  627. ide_hwif_t *hwif = dev_get_drvdata(dev);
  628. _auide_hwif *ahwif = &auide_hwif;
  629. ide_unregister(hwif - ide_hwifs);
  630. iounmap((void *)ahwif->regbase);
  631. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  632. release_mem_region(res->start, res->end - res->start);
  633. return 0;
  634. }
  635. static struct device_driver au1200_ide_driver = {
  636. .name = "au1200-ide",
  637. .bus = &platform_bus_type,
  638. .probe = au_ide_probe,
  639. .remove = au_ide_remove,
  640. };
  641. static int __init au_ide_init(void)
  642. {
  643. return driver_register(&au1200_ide_driver);
  644. }
  645. static void __exit au_ide_exit(void)
  646. {
  647. driver_unregister(&au1200_ide_driver);
  648. }
  649. MODULE_LICENSE("GPL");
  650. MODULE_DESCRIPTION("AU1200 IDE driver");
  651. module_init(au_ide_init);
  652. module_exit(au_ide_exit);