au1xxx-ide.c 20 KB

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