au1xxx-ide.c 18 KB

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