au1xxx-ide.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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/scatterlist.h>
  38. #include <asm/mach-au1x00/au1xxx.h>
  39. #include <asm/mach-au1x00/au1xxx_dbdma.h>
  40. #include <asm/mach-au1x00/au1xxx_ide.h>
  41. #define DRV_NAME "au1200-ide"
  42. #define DRV_AUTHOR "Enrico Walther <enrico.walther@amd.com> / Pete Popov <ppopov@embeddedalley.com>"
  43. /* enable the burstmode in the dbdma */
  44. #define IDE_AU1XXX_BURSTMODE 1
  45. static _auide_hwif auide_hwif;
  46. #if defined(CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA)
  47. void auide_insw(unsigned long port, void *addr, u32 count)
  48. {
  49. _auide_hwif *ahwif = &auide_hwif;
  50. chan_tab_t *ctp;
  51. au1x_ddma_desc_t *dp;
  52. if(!put_dest_flags(ahwif->rx_chan, (void*)addr, count << 1,
  53. DDMA_FLAGS_NOIE)) {
  54. printk(KERN_ERR "%s failed %d\n", __func__, __LINE__);
  55. return;
  56. }
  57. ctp = *((chan_tab_t **)ahwif->rx_chan);
  58. dp = ctp->cur_ptr;
  59. while (dp->dscr_cmd0 & DSCR_CMD0_V)
  60. ;
  61. ctp->cur_ptr = au1xxx_ddma_get_nextptr_virt(dp);
  62. }
  63. void auide_outsw(unsigned long port, void *addr, u32 count)
  64. {
  65. _auide_hwif *ahwif = &auide_hwif;
  66. chan_tab_t *ctp;
  67. au1x_ddma_desc_t *dp;
  68. if(!put_source_flags(ahwif->tx_chan, (void*)addr,
  69. count << 1, DDMA_FLAGS_NOIE)) {
  70. printk(KERN_ERR "%s failed %d\n", __func__, __LINE__);
  71. return;
  72. }
  73. ctp = *((chan_tab_t **)ahwif->tx_chan);
  74. dp = ctp->cur_ptr;
  75. while (dp->dscr_cmd0 & DSCR_CMD0_V)
  76. ;
  77. ctp->cur_ptr = au1xxx_ddma_get_nextptr_virt(dp);
  78. }
  79. static void au1xxx_input_data(ide_drive_t *drive, struct request *rq,
  80. void *buf, unsigned int len)
  81. {
  82. auide_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
  83. }
  84. static void au1xxx_output_data(ide_drive_t *drive, struct request *rq,
  85. void *buf, unsigned int len)
  86. {
  87. auide_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
  88. }
  89. #endif
  90. static void au1xxx_set_pio_mode(ide_drive_t *drive, const u8 pio)
  91. {
  92. int mem_sttime = 0, mem_stcfg = au_readl(MEM_STCFG2);
  93. /* set pio mode! */
  94. switch(pio) {
  95. case 0:
  96. mem_sttime = SBC_IDE_TIMING(PIO0);
  97. /* set configuration for RCS2# */
  98. mem_stcfg |= TS_MASK;
  99. mem_stcfg &= ~TCSOE_MASK;
  100. mem_stcfg &= ~TOECS_MASK;
  101. mem_stcfg |= SBC_IDE_PIO0_TCSOE | SBC_IDE_PIO0_TOECS;
  102. break;
  103. case 1:
  104. mem_sttime = SBC_IDE_TIMING(PIO1);
  105. /* set configuration for RCS2# */
  106. mem_stcfg |= TS_MASK;
  107. mem_stcfg &= ~TCSOE_MASK;
  108. mem_stcfg &= ~TOECS_MASK;
  109. mem_stcfg |= SBC_IDE_PIO1_TCSOE | SBC_IDE_PIO1_TOECS;
  110. break;
  111. case 2:
  112. mem_sttime = SBC_IDE_TIMING(PIO2);
  113. /* set configuration for RCS2# */
  114. mem_stcfg &= ~TS_MASK;
  115. mem_stcfg &= ~TCSOE_MASK;
  116. mem_stcfg &= ~TOECS_MASK;
  117. mem_stcfg |= SBC_IDE_PIO2_TCSOE | SBC_IDE_PIO2_TOECS;
  118. break;
  119. case 3:
  120. mem_sttime = SBC_IDE_TIMING(PIO3);
  121. /* set configuration for RCS2# */
  122. mem_stcfg &= ~TS_MASK;
  123. mem_stcfg &= ~TCSOE_MASK;
  124. mem_stcfg &= ~TOECS_MASK;
  125. mem_stcfg |= SBC_IDE_PIO3_TCSOE | SBC_IDE_PIO3_TOECS;
  126. break;
  127. case 4:
  128. mem_sttime = SBC_IDE_TIMING(PIO4);
  129. /* set configuration for RCS2# */
  130. mem_stcfg &= ~TS_MASK;
  131. mem_stcfg &= ~TCSOE_MASK;
  132. mem_stcfg &= ~TOECS_MASK;
  133. mem_stcfg |= SBC_IDE_PIO4_TCSOE | SBC_IDE_PIO4_TOECS;
  134. break;
  135. }
  136. au_writel(mem_sttime,MEM_STTIME2);
  137. au_writel(mem_stcfg,MEM_STCFG2);
  138. }
  139. static void auide_set_dma_mode(ide_drive_t *drive, const u8 speed)
  140. {
  141. int mem_sttime = 0, mem_stcfg = au_readl(MEM_STCFG2);
  142. switch(speed) {
  143. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
  144. case XFER_MW_DMA_2:
  145. mem_sttime = SBC_IDE_TIMING(MDMA2);
  146. /* set configuration for RCS2# */
  147. mem_stcfg &= ~TS_MASK;
  148. mem_stcfg &= ~TCSOE_MASK;
  149. mem_stcfg &= ~TOECS_MASK;
  150. mem_stcfg |= SBC_IDE_MDMA2_TCSOE | SBC_IDE_MDMA2_TOECS;
  151. break;
  152. case XFER_MW_DMA_1:
  153. mem_sttime = SBC_IDE_TIMING(MDMA1);
  154. /* set configuration for RCS2# */
  155. mem_stcfg &= ~TS_MASK;
  156. mem_stcfg &= ~TCSOE_MASK;
  157. mem_stcfg &= ~TOECS_MASK;
  158. mem_stcfg |= SBC_IDE_MDMA1_TCSOE | SBC_IDE_MDMA1_TOECS;
  159. break;
  160. case XFER_MW_DMA_0:
  161. mem_sttime = SBC_IDE_TIMING(MDMA0);
  162. /* set configuration for RCS2# */
  163. mem_stcfg |= TS_MASK;
  164. mem_stcfg &= ~TCSOE_MASK;
  165. mem_stcfg &= ~TOECS_MASK;
  166. mem_stcfg |= SBC_IDE_MDMA0_TCSOE | SBC_IDE_MDMA0_TOECS;
  167. break;
  168. #endif
  169. }
  170. au_writel(mem_sttime,MEM_STTIME2);
  171. au_writel(mem_stcfg,MEM_STCFG2);
  172. }
  173. /*
  174. * Multi-Word DMA + DbDMA functions
  175. */
  176. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
  177. static int auide_build_dmatable(ide_drive_t *drive)
  178. {
  179. int i, iswrite, count = 0;
  180. ide_hwif_t *hwif = HWIF(drive);
  181. struct request *rq = HWGROUP(drive)->rq;
  182. _auide_hwif *ahwif = (_auide_hwif*)hwif->hwif_data;
  183. struct scatterlist *sg;
  184. iswrite = (rq_data_dir(rq) == WRITE);
  185. /* Save for interrupt context */
  186. ahwif->drive = drive;
  187. hwif->sg_nents = i = ide_build_sglist(drive, rq);
  188. if (!i)
  189. return 0;
  190. /* fill the descriptors */
  191. sg = hwif->sg_table;
  192. while (i && sg_dma_len(sg)) {
  193. u32 cur_addr;
  194. u32 cur_len;
  195. cur_addr = sg_dma_address(sg);
  196. cur_len = sg_dma_len(sg);
  197. while (cur_len) {
  198. u32 flags = DDMA_FLAGS_NOIE;
  199. unsigned int tc = (cur_len < 0xfe00)? cur_len: 0xfe00;
  200. if (++count >= PRD_ENTRIES) {
  201. printk(KERN_WARNING "%s: DMA table too small\n",
  202. drive->name);
  203. goto use_pio_instead;
  204. }
  205. /* Lets enable intr for the last descriptor only */
  206. if (1==i)
  207. flags = DDMA_FLAGS_IE;
  208. else
  209. flags = DDMA_FLAGS_NOIE;
  210. if (iswrite) {
  211. if(!put_source_flags(ahwif->tx_chan,
  212. (void*) sg_virt(sg),
  213. tc, flags)) {
  214. printk(KERN_ERR "%s failed %d\n",
  215. __func__, __LINE__);
  216. }
  217. } else
  218. {
  219. if(!put_dest_flags(ahwif->rx_chan,
  220. (void*) sg_virt(sg),
  221. tc, flags)) {
  222. printk(KERN_ERR "%s failed %d\n",
  223. __func__, __LINE__);
  224. }
  225. }
  226. cur_addr += tc;
  227. cur_len -= tc;
  228. }
  229. sg = sg_next(sg);
  230. i--;
  231. }
  232. if (count)
  233. return 1;
  234. use_pio_instead:
  235. ide_destroy_dmatable(drive);
  236. return 0; /* revert to PIO for this request */
  237. }
  238. static int auide_dma_end(ide_drive_t *drive)
  239. {
  240. ide_hwif_t *hwif = HWIF(drive);
  241. if (hwif->sg_nents) {
  242. ide_destroy_dmatable(drive);
  243. hwif->sg_nents = 0;
  244. }
  245. return 0;
  246. }
  247. static void auide_dma_start(ide_drive_t *drive )
  248. {
  249. }
  250. static void auide_dma_exec_cmd(ide_drive_t *drive, u8 command)
  251. {
  252. /* issue cmd to drive */
  253. ide_execute_command(drive, command, &ide_dma_intr,
  254. (2*WAIT_CMD), NULL);
  255. }
  256. static int auide_dma_setup(ide_drive_t *drive)
  257. {
  258. struct request *rq = HWGROUP(drive)->rq;
  259. if (!auide_build_dmatable(drive)) {
  260. ide_map_sg(drive, rq);
  261. return 1;
  262. }
  263. drive->waiting_for_dma = 1;
  264. return 0;
  265. }
  266. static int auide_dma_test_irq(ide_drive_t *drive)
  267. {
  268. if (drive->waiting_for_dma == 0)
  269. printk(KERN_WARNING "%s: ide_dma_test_irq \
  270. called while not waiting\n", drive->name);
  271. /* If dbdma didn't execute the STOP command yet, the
  272. * active bit is still set
  273. */
  274. drive->waiting_for_dma++;
  275. if (drive->waiting_for_dma >= DMA_WAIT_TIMEOUT) {
  276. printk(KERN_WARNING "%s: timeout waiting for ddma to \
  277. complete\n", drive->name);
  278. return 1;
  279. }
  280. udelay(10);
  281. return 0;
  282. }
  283. static void auide_dma_host_set(ide_drive_t *drive, int on)
  284. {
  285. }
  286. static void auide_dma_lost_irq(ide_drive_t *drive)
  287. {
  288. printk(KERN_ERR "%s: IRQ lost\n", drive->name);
  289. }
  290. static void auide_ddma_tx_callback(int irq, void *param)
  291. {
  292. _auide_hwif *ahwif = (_auide_hwif*)param;
  293. ahwif->drive->waiting_for_dma = 0;
  294. }
  295. static void auide_ddma_rx_callback(int irq, void *param)
  296. {
  297. _auide_hwif *ahwif = (_auide_hwif*)param;
  298. ahwif->drive->waiting_for_dma = 0;
  299. }
  300. #endif /* end CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA */
  301. static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize, u32 devwidth, u32 flags)
  302. {
  303. dev->dev_id = dev_id;
  304. dev->dev_physaddr = (u32)IDE_PHYS_ADDR;
  305. dev->dev_intlevel = 0;
  306. dev->dev_intpolarity = 0;
  307. dev->dev_tsize = tsize;
  308. dev->dev_devwidth = devwidth;
  309. dev->dev_flags = flags;
  310. }
  311. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
  312. static void auide_dma_timeout(ide_drive_t *drive)
  313. {
  314. ide_hwif_t *hwif = HWIF(drive);
  315. printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
  316. if (auide_dma_test_irq(drive))
  317. return;
  318. auide_dma_end(drive);
  319. }
  320. static const struct ide_dma_ops au1xxx_dma_ops = {
  321. .dma_host_set = auide_dma_host_set,
  322. .dma_setup = auide_dma_setup,
  323. .dma_exec_cmd = auide_dma_exec_cmd,
  324. .dma_start = auide_dma_start,
  325. .dma_end = auide_dma_end,
  326. .dma_test_irq = auide_dma_test_irq,
  327. .dma_lost_irq = auide_dma_lost_irq,
  328. .dma_timeout = auide_dma_timeout,
  329. };
  330. static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
  331. {
  332. _auide_hwif *auide = (_auide_hwif *)hwif->hwif_data;
  333. dbdev_tab_t source_dev_tab, target_dev_tab;
  334. u32 dev_id, tsize, devwidth, flags;
  335. dev_id = IDE_DDMA_REQ;
  336. tsize = 8; /* 1 */
  337. devwidth = 32; /* 16 */
  338. #ifdef IDE_AU1XXX_BURSTMODE
  339. flags = DEV_FLAGS_SYNC | DEV_FLAGS_BURSTABLE;
  340. #else
  341. flags = DEV_FLAGS_SYNC;
  342. #endif
  343. /* setup dev_tab for tx channel */
  344. auide_init_dbdma_dev( &source_dev_tab,
  345. dev_id,
  346. tsize, devwidth, DEV_FLAGS_OUT | flags);
  347. auide->tx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
  348. auide_init_dbdma_dev( &source_dev_tab,
  349. dev_id,
  350. tsize, devwidth, DEV_FLAGS_IN | flags);
  351. auide->rx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
  352. /* We also need to add a target device for the DMA */
  353. auide_init_dbdma_dev( &target_dev_tab,
  354. (u32)DSCR_CMD0_ALWAYS,
  355. tsize, devwidth, DEV_FLAGS_ANYUSE);
  356. auide->target_dev_id = au1xxx_ddma_add_device(&target_dev_tab);
  357. /* Get a channel for TX */
  358. auide->tx_chan = au1xxx_dbdma_chan_alloc(auide->target_dev_id,
  359. auide->tx_dev_id,
  360. auide_ddma_tx_callback,
  361. (void*)auide);
  362. /* Get a channel for RX */
  363. auide->rx_chan = au1xxx_dbdma_chan_alloc(auide->rx_dev_id,
  364. auide->target_dev_id,
  365. auide_ddma_rx_callback,
  366. (void*)auide);
  367. auide->tx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->tx_chan,
  368. NUM_DESCRIPTORS);
  369. auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan,
  370. NUM_DESCRIPTORS);
  371. hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev,
  372. PRD_ENTRIES * PRD_BYTES, /* 1 Page */
  373. &hwif->dmatable_dma, GFP_KERNEL);
  374. au1xxx_dbdma_start( auide->tx_chan );
  375. au1xxx_dbdma_start( auide->rx_chan );
  376. return 0;
  377. }
  378. #else
  379. static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
  380. {
  381. _auide_hwif *auide = (_auide_hwif *)hwif->hwif_data;
  382. dbdev_tab_t source_dev_tab;
  383. int flags;
  384. #ifdef IDE_AU1XXX_BURSTMODE
  385. flags = DEV_FLAGS_SYNC | DEV_FLAGS_BURSTABLE;
  386. #else
  387. flags = DEV_FLAGS_SYNC;
  388. #endif
  389. /* setup dev_tab for tx channel */
  390. auide_init_dbdma_dev( &source_dev_tab,
  391. (u32)DSCR_CMD0_ALWAYS,
  392. 8, 32, DEV_FLAGS_OUT | flags);
  393. auide->tx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
  394. auide_init_dbdma_dev( &source_dev_tab,
  395. (u32)DSCR_CMD0_ALWAYS,
  396. 8, 32, DEV_FLAGS_IN | flags);
  397. auide->rx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
  398. /* Get a channel for TX */
  399. auide->tx_chan = au1xxx_dbdma_chan_alloc(DSCR_CMD0_ALWAYS,
  400. auide->tx_dev_id,
  401. NULL,
  402. (void*)auide);
  403. /* Get a channel for RX */
  404. auide->rx_chan = au1xxx_dbdma_chan_alloc(auide->rx_dev_id,
  405. DSCR_CMD0_ALWAYS,
  406. NULL,
  407. (void*)auide);
  408. auide->tx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->tx_chan,
  409. NUM_DESCRIPTORS);
  410. auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan,
  411. NUM_DESCRIPTORS);
  412. au1xxx_dbdma_start( auide->tx_chan );
  413. au1xxx_dbdma_start( auide->rx_chan );
  414. return 0;
  415. }
  416. #endif
  417. static void auide_setup_ports(hw_regs_t *hw, _auide_hwif *ahwif)
  418. {
  419. int i;
  420. unsigned long *ata_regs = hw->io_ports_array;
  421. /* FIXME? */
  422. for (i = 0; i < 8; i++)
  423. *ata_regs++ = ahwif->regbase + (i << IDE_REG_SHIFT);
  424. /* set the Alternative Status register */
  425. *ata_regs = ahwif->regbase + (14 << IDE_REG_SHIFT);
  426. }
  427. static const struct ide_port_ops au1xxx_port_ops = {
  428. .set_pio_mode = au1xxx_set_pio_mode,
  429. .set_dma_mode = auide_set_dma_mode,
  430. };
  431. static const struct ide_port_info au1xxx_port_info = {
  432. .init_dma = auide_ddma_init,
  433. .port_ops = &au1xxx_port_ops,
  434. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
  435. .dma_ops = &au1xxx_dma_ops,
  436. #endif
  437. .host_flags = IDE_HFLAG_POST_SET_MODE |
  438. IDE_HFLAG_NO_IO_32BIT |
  439. IDE_HFLAG_UNMASK_IRQS,
  440. .pio_mask = ATA_PIO4,
  441. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
  442. .mwdma_mask = ATA_MWDMA2,
  443. #endif
  444. };
  445. static int au_ide_probe(struct device *dev)
  446. {
  447. struct platform_device *pdev = to_platform_device(dev);
  448. _auide_hwif *ahwif = &auide_hwif;
  449. ide_hwif_t *hwif;
  450. struct resource *res;
  451. int ret = 0;
  452. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  453. hw_regs_t hw;
  454. #if defined(CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA)
  455. char *mode = "MWDMA2";
  456. #elif defined(CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA)
  457. char *mode = "PIO+DDMA(offload)";
  458. #endif
  459. memset(&auide_hwif, 0, sizeof(_auide_hwif));
  460. ahwif->irq = platform_get_irq(pdev, 0);
  461. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  462. if (res == NULL) {
  463. pr_debug("%s %d: no base address\n", DRV_NAME, pdev->id);
  464. ret = -ENODEV;
  465. goto out;
  466. }
  467. if (ahwif->irq < 0) {
  468. pr_debug("%s %d: no IRQ\n", DRV_NAME, pdev->id);
  469. ret = -ENODEV;
  470. goto out;
  471. }
  472. if (!request_mem_region(res->start, res->end - res->start + 1,
  473. pdev->name)) {
  474. pr_debug("%s: request_mem_region failed\n", DRV_NAME);
  475. ret = -EBUSY;
  476. goto out;
  477. }
  478. ahwif->regbase = (u32)ioremap(res->start, res->end - res->start + 1);
  479. if (ahwif->regbase == 0) {
  480. ret = -ENOMEM;
  481. goto out;
  482. }
  483. hwif = ide_find_port();
  484. if (hwif == NULL) {
  485. ret = -ENOENT;
  486. goto out;
  487. }
  488. memset(&hw, 0, sizeof(hw));
  489. auide_setup_ports(&hw, ahwif);
  490. hw.irq = ahwif->irq;
  491. hw.dev = dev;
  492. hw.chipset = ide_au1xxx;
  493. ide_init_port_hw(hwif, &hw);
  494. hwif->dev = dev;
  495. /* If the user has selected DDMA assisted copies,
  496. then set up a few local I/O function entry points
  497. */
  498. #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA
  499. hwif->input_data = au1xxx_input_data;
  500. hwif->output_data = au1xxx_output_data;
  501. #endif
  502. hwif->select_data = 0; /* no chipset-specific code */
  503. hwif->config_data = 0; /* no chipset-specific code */
  504. auide_hwif.hwif = hwif;
  505. hwif->hwif_data = &auide_hwif;
  506. idx[0] = hwif->index;
  507. ide_device_add(idx, &au1xxx_port_info);
  508. dev_set_drvdata(dev, hwif);
  509. printk(KERN_INFO "Au1xxx IDE(builtin) configured for %s\n", mode );
  510. out:
  511. return ret;
  512. }
  513. static int au_ide_remove(struct device *dev)
  514. {
  515. struct platform_device *pdev = to_platform_device(dev);
  516. struct resource *res;
  517. ide_hwif_t *hwif = dev_get_drvdata(dev);
  518. _auide_hwif *ahwif = &auide_hwif;
  519. ide_unregister(hwif);
  520. iounmap((void *)ahwif->regbase);
  521. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  522. release_mem_region(res->start, res->end - res->start + 1);
  523. return 0;
  524. }
  525. static struct device_driver au1200_ide_driver = {
  526. .name = "au1200-ide",
  527. .bus = &platform_bus_type,
  528. .probe = au_ide_probe,
  529. .remove = au_ide_remove,
  530. };
  531. static int __init au_ide_init(void)
  532. {
  533. return driver_register(&au1200_ide_driver);
  534. }
  535. static void __exit au_ide_exit(void)
  536. {
  537. driver_unregister(&au1200_ide_driver);
  538. }
  539. MODULE_LICENSE("GPL");
  540. MODULE_DESCRIPTION("AU1200 IDE driver");
  541. module_init(au_ide_init);
  542. module_exit(au_ide_exit);