sata_promise.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. /*
  2. * sata_promise.c - Promise SATA
  3. *
  4. * Maintained by: Jeff Garzik <jgarzik@pobox.com>
  5. * Please ALWAYS copy linux-ide@vger.kernel.org
  6. * on emails.
  7. *
  8. * Copyright 2003-2004 Red Hat, Inc.
  9. *
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; see the file COPYING. If not, write to
  23. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. *
  26. * libata documentation is available via 'make {ps|pdf}docs',
  27. * as Documentation/DocBook/libata.*
  28. *
  29. * Hardware information only available under NDA.
  30. *
  31. */
  32. #include <linux/kernel.h>
  33. #include <linux/module.h>
  34. #include <linux/pci.h>
  35. #include <linux/init.h>
  36. #include <linux/blkdev.h>
  37. #include <linux/delay.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/sched.h>
  40. #include "scsi.h"
  41. #include <scsi/scsi_host.h>
  42. #include <linux/libata.h>
  43. #include <asm/io.h>
  44. #include "sata_promise.h"
  45. #define DRV_NAME "sata_promise"
  46. #define DRV_VERSION "1.02"
  47. enum {
  48. PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */
  49. PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */
  50. PDC_TBG_MODE = 0x41, /* TBG mode */
  51. PDC_FLASH_CTL = 0x44, /* Flash control register */
  52. PDC_PCI_CTL = 0x48, /* PCI control and status register */
  53. PDC_GLOBAL_CTL = 0x48, /* Global control/status (per port) */
  54. PDC_CTLSTAT = 0x60, /* IDE control and status (per port) */
  55. PDC_SATA_PLUG_CSR = 0x6C, /* SATA Plug control/status reg */
  56. PDC_SLEW_CTL = 0x470, /* slew rate control reg */
  57. PDC_ERR_MASK = (1<<19) | (1<<20) | (1<<21) | (1<<22) |
  58. (1<<8) | (1<<9) | (1<<10),
  59. board_2037x = 0, /* FastTrak S150 TX2plus */
  60. board_20319 = 1, /* FastTrak S150 TX4 */
  61. board_20619 = 2, /* FastTrak TX4000 */
  62. PDC_HAS_PATA = (1 << 1), /* PDC20375 has PATA */
  63. PDC_RESET = (1 << 11), /* HDMA reset */
  64. };
  65. struct pdc_port_priv {
  66. u8 *pkt;
  67. dma_addr_t pkt_dma;
  68. };
  69. static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg);
  70. static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
  71. static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
  72. static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
  73. static void pdc_eng_timeout(struct ata_port *ap);
  74. static int pdc_port_start(struct ata_port *ap);
  75. static void pdc_port_stop(struct ata_port *ap);
  76. static void pdc_phy_reset(struct ata_port *ap);
  77. static void pdc_qc_prep(struct ata_queued_cmd *qc);
  78. static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf);
  79. static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf);
  80. static void pdc_irq_clear(struct ata_port *ap);
  81. static int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
  82. static Scsi_Host_Template pdc_ata_sht = {
  83. .module = THIS_MODULE,
  84. .name = DRV_NAME,
  85. .ioctl = ata_scsi_ioctl,
  86. .queuecommand = ata_scsi_queuecmd,
  87. .eh_strategy_handler = ata_scsi_error,
  88. .can_queue = ATA_DEF_QUEUE,
  89. .this_id = ATA_SHT_THIS_ID,
  90. .sg_tablesize = LIBATA_MAX_PRD,
  91. .max_sectors = ATA_MAX_SECTORS,
  92. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  93. .emulated = ATA_SHT_EMULATED,
  94. .use_clustering = ATA_SHT_USE_CLUSTERING,
  95. .proc_name = DRV_NAME,
  96. .dma_boundary = ATA_DMA_BOUNDARY,
  97. .slave_configure = ata_scsi_slave_config,
  98. .bios_param = ata_std_bios_param,
  99. .ordered_flush = 1,
  100. };
  101. static struct ata_port_operations pdc_ata_ops = {
  102. .port_disable = ata_port_disable,
  103. .tf_load = pdc_tf_load_mmio,
  104. .tf_read = ata_tf_read,
  105. .check_status = ata_check_status,
  106. .exec_command = pdc_exec_command_mmio,
  107. .dev_select = ata_std_dev_select,
  108. .phy_reset = pdc_phy_reset,
  109. .qc_prep = pdc_qc_prep,
  110. .qc_issue = pdc_qc_issue_prot,
  111. .eng_timeout = pdc_eng_timeout,
  112. .irq_handler = pdc_interrupt,
  113. .irq_clear = pdc_irq_clear,
  114. .scr_read = pdc_sata_scr_read,
  115. .scr_write = pdc_sata_scr_write,
  116. .port_start = pdc_port_start,
  117. .port_stop = pdc_port_stop,
  118. .host_stop = ata_host_stop,
  119. };
  120. static struct ata_port_info pdc_port_info[] = {
  121. /* board_2037x */
  122. {
  123. .sht = &pdc_ata_sht,
  124. .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
  125. ATA_FLAG_SRST | ATA_FLAG_MMIO,
  126. .pio_mask = 0x1f, /* pio0-4 */
  127. .mwdma_mask = 0x07, /* mwdma0-2 */
  128. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  129. .port_ops = &pdc_ata_ops,
  130. },
  131. /* board_20319 */
  132. {
  133. .sht = &pdc_ata_sht,
  134. .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
  135. ATA_FLAG_SRST | ATA_FLAG_MMIO,
  136. .pio_mask = 0x1f, /* pio0-4 */
  137. .mwdma_mask = 0x07, /* mwdma0-2 */
  138. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  139. .port_ops = &pdc_ata_ops,
  140. },
  141. /* board_20619 */
  142. {
  143. .sht = &pdc_ata_sht,
  144. .host_flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST |
  145. ATA_FLAG_MMIO | ATA_FLAG_SLAVE_POSS,
  146. .pio_mask = 0x1f, /* pio0-4 */
  147. .mwdma_mask = 0x07, /* mwdma0-2 */
  148. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  149. .port_ops = &pdc_ata_ops,
  150. },
  151. };
  152. static struct pci_device_id pdc_ata_pci_tbl[] = {
  153. { PCI_VENDOR_ID_PROMISE, 0x3371, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  154. board_2037x },
  155. { PCI_VENDOR_ID_PROMISE, 0x3571, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  156. board_2037x },
  157. { PCI_VENDOR_ID_PROMISE, 0x3373, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  158. board_2037x },
  159. { PCI_VENDOR_ID_PROMISE, 0x3375, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  160. board_2037x },
  161. { PCI_VENDOR_ID_PROMISE, 0x3376, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  162. board_2037x },
  163. { PCI_VENDOR_ID_PROMISE, 0x3574, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  164. board_2037x },
  165. { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  166. board_2037x },
  167. { PCI_VENDOR_ID_PROMISE, 0x3318, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  168. board_20319 },
  169. { PCI_VENDOR_ID_PROMISE, 0x3319, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  170. board_20319 },
  171. { PCI_VENDOR_ID_PROMISE, 0x3519, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  172. board_20319 },
  173. { PCI_VENDOR_ID_PROMISE, 0x3d17, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  174. board_20319 },
  175. { PCI_VENDOR_ID_PROMISE, 0x3d18, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  176. board_20319 },
  177. { PCI_VENDOR_ID_PROMISE, 0x6629, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  178. board_20619 },
  179. { } /* terminate list */
  180. };
  181. static struct pci_driver pdc_ata_pci_driver = {
  182. .name = DRV_NAME,
  183. .id_table = pdc_ata_pci_tbl,
  184. .probe = pdc_ata_init_one,
  185. .remove = ata_pci_remove_one,
  186. };
  187. static int pdc_port_start(struct ata_port *ap)
  188. {
  189. struct device *dev = ap->host_set->dev;
  190. struct pdc_port_priv *pp;
  191. int rc;
  192. rc = ata_port_start(ap);
  193. if (rc)
  194. return rc;
  195. pp = kmalloc(sizeof(*pp), GFP_KERNEL);
  196. if (!pp) {
  197. rc = -ENOMEM;
  198. goto err_out;
  199. }
  200. memset(pp, 0, sizeof(*pp));
  201. pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
  202. if (!pp->pkt) {
  203. rc = -ENOMEM;
  204. goto err_out_kfree;
  205. }
  206. ap->private_data = pp;
  207. return 0;
  208. err_out_kfree:
  209. kfree(pp);
  210. err_out:
  211. ata_port_stop(ap);
  212. return rc;
  213. }
  214. static void pdc_port_stop(struct ata_port *ap)
  215. {
  216. struct device *dev = ap->host_set->dev;
  217. struct pdc_port_priv *pp = ap->private_data;
  218. ap->private_data = NULL;
  219. dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma);
  220. kfree(pp);
  221. ata_port_stop(ap);
  222. }
  223. static void pdc_reset_port(struct ata_port *ap)
  224. {
  225. void *mmio = (void *) ap->ioaddr.cmd_addr + PDC_CTLSTAT;
  226. unsigned int i;
  227. u32 tmp;
  228. for (i = 11; i > 0; i--) {
  229. tmp = readl(mmio);
  230. if (tmp & PDC_RESET)
  231. break;
  232. udelay(100);
  233. tmp |= PDC_RESET;
  234. writel(tmp, mmio);
  235. }
  236. tmp &= ~PDC_RESET;
  237. writel(tmp, mmio);
  238. readl(mmio); /* flush */
  239. }
  240. static void pdc_phy_reset(struct ata_port *ap)
  241. {
  242. pdc_reset_port(ap);
  243. sata_phy_reset(ap);
  244. }
  245. static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
  246. {
  247. if (sc_reg > SCR_CONTROL)
  248. return 0xffffffffU;
  249. return readl((void *) ap->ioaddr.scr_addr + (sc_reg * 4));
  250. }
  251. static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
  252. u32 val)
  253. {
  254. if (sc_reg > SCR_CONTROL)
  255. return;
  256. writel(val, (void *) ap->ioaddr.scr_addr + (sc_reg * 4));
  257. }
  258. static void pdc_qc_prep(struct ata_queued_cmd *qc)
  259. {
  260. struct pdc_port_priv *pp = qc->ap->private_data;
  261. unsigned int i;
  262. VPRINTK("ENTER\n");
  263. switch (qc->tf.protocol) {
  264. case ATA_PROT_DMA:
  265. ata_qc_prep(qc);
  266. /* fall through */
  267. case ATA_PROT_NODATA:
  268. i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
  269. qc->dev->devno, pp->pkt);
  270. if (qc->tf.flags & ATA_TFLAG_LBA48)
  271. i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
  272. else
  273. i = pdc_prep_lba28(&qc->tf, pp->pkt, i);
  274. pdc_pkt_footer(&qc->tf, pp->pkt, i);
  275. break;
  276. default:
  277. break;
  278. }
  279. }
  280. static void pdc_eng_timeout(struct ata_port *ap)
  281. {
  282. struct ata_host_set *host_set = ap->host_set;
  283. u8 drv_stat;
  284. struct ata_queued_cmd *qc;
  285. unsigned long flags;
  286. DPRINTK("ENTER\n");
  287. spin_lock_irqsave(&host_set->lock, flags);
  288. qc = ata_qc_from_tag(ap, ap->active_tag);
  289. if (!qc) {
  290. printk(KERN_ERR "ata%u: BUG: timeout without command\n",
  291. ap->id);
  292. goto out;
  293. }
  294. /* hack alert! We cannot use the supplied completion
  295. * function from inside the ->eh_strategy_handler() thread.
  296. * libata is the only user of ->eh_strategy_handler() in
  297. * any kernel, so the default scsi_done() assumes it is
  298. * not being called from the SCSI EH.
  299. */
  300. qc->scsidone = scsi_finish_command;
  301. switch (qc->tf.protocol) {
  302. case ATA_PROT_DMA:
  303. case ATA_PROT_NODATA:
  304. printk(KERN_ERR "ata%u: command timeout\n", ap->id);
  305. ata_qc_complete(qc, ata_wait_idle(ap) | ATA_ERR);
  306. break;
  307. default:
  308. drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
  309. printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n",
  310. ap->id, qc->tf.command, drv_stat);
  311. ata_qc_complete(qc, drv_stat);
  312. break;
  313. }
  314. out:
  315. spin_unlock_irqrestore(&host_set->lock, flags);
  316. DPRINTK("EXIT\n");
  317. }
  318. static inline unsigned int pdc_host_intr( struct ata_port *ap,
  319. struct ata_queued_cmd *qc)
  320. {
  321. u8 status;
  322. unsigned int handled = 0, have_err = 0;
  323. u32 tmp;
  324. void *mmio = (void *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
  325. tmp = readl(mmio);
  326. if (tmp & PDC_ERR_MASK) {
  327. have_err = 1;
  328. pdc_reset_port(ap);
  329. }
  330. switch (qc->tf.protocol) {
  331. case ATA_PROT_DMA:
  332. case ATA_PROT_NODATA:
  333. status = ata_wait_idle(ap);
  334. if (have_err)
  335. status |= ATA_ERR;
  336. ata_qc_complete(qc, status);
  337. handled = 1;
  338. break;
  339. default:
  340. ap->stats.idle_irq++;
  341. break;
  342. }
  343. return handled;
  344. }
  345. static void pdc_irq_clear(struct ata_port *ap)
  346. {
  347. struct ata_host_set *host_set = ap->host_set;
  348. void *mmio = host_set->mmio_base;
  349. readl(mmio + PDC_INT_SEQMASK);
  350. }
  351. static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
  352. {
  353. struct ata_host_set *host_set = dev_instance;
  354. struct ata_port *ap;
  355. u32 mask = 0;
  356. unsigned int i, tmp;
  357. unsigned int handled = 0;
  358. void *mmio_base;
  359. VPRINTK("ENTER\n");
  360. if (!host_set || !host_set->mmio_base) {
  361. VPRINTK("QUICK EXIT\n");
  362. return IRQ_NONE;
  363. }
  364. mmio_base = host_set->mmio_base;
  365. /* reading should also clear interrupts */
  366. mask = readl(mmio_base + PDC_INT_SEQMASK);
  367. if (mask == 0xffffffff) {
  368. VPRINTK("QUICK EXIT 2\n");
  369. return IRQ_NONE;
  370. }
  371. mask &= 0xffff; /* only 16 tags possible */
  372. if (!mask) {
  373. VPRINTK("QUICK EXIT 3\n");
  374. return IRQ_NONE;
  375. }
  376. spin_lock(&host_set->lock);
  377. writel(mask, mmio_base + PDC_INT_SEQMASK);
  378. for (i = 0; i < host_set->n_ports; i++) {
  379. VPRINTK("port %u\n", i);
  380. ap = host_set->ports[i];
  381. tmp = mask & (1 << (i + 1));
  382. if (tmp && ap &&
  383. !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) {
  384. struct ata_queued_cmd *qc;
  385. qc = ata_qc_from_tag(ap, ap->active_tag);
  386. if (qc && (!(qc->tf.ctl & ATA_NIEN)))
  387. handled += pdc_host_intr(ap, qc);
  388. }
  389. }
  390. spin_unlock(&host_set->lock);
  391. VPRINTK("EXIT\n");
  392. return IRQ_RETVAL(handled);
  393. }
  394. static inline void pdc_packet_start(struct ata_queued_cmd *qc)
  395. {
  396. struct ata_port *ap = qc->ap;
  397. struct pdc_port_priv *pp = ap->private_data;
  398. unsigned int port_no = ap->port_no;
  399. u8 seq = (u8) (port_no + 1);
  400. VPRINTK("ENTER, ap %p\n", ap);
  401. writel(0x00000001, ap->host_set->mmio_base + (seq * 4));
  402. readl(ap->host_set->mmio_base + (seq * 4)); /* flush */
  403. pp->pkt[2] = seq;
  404. wmb(); /* flush PRD, pkt writes */
  405. writel(pp->pkt_dma, (void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
  406. readl((void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
  407. }
  408. static int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
  409. {
  410. switch (qc->tf.protocol) {
  411. case ATA_PROT_DMA:
  412. case ATA_PROT_NODATA:
  413. pdc_packet_start(qc);
  414. return 0;
  415. case ATA_PROT_ATAPI_DMA:
  416. BUG();
  417. break;
  418. default:
  419. break;
  420. }
  421. return ata_qc_issue_prot(qc);
  422. }
  423. static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf)
  424. {
  425. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  426. tf->protocol == ATA_PROT_NODATA);
  427. ata_tf_load(ap, tf);
  428. }
  429. static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf)
  430. {
  431. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  432. tf->protocol == ATA_PROT_NODATA);
  433. ata_exec_command(ap, tf);
  434. }
  435. static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
  436. {
  437. port->cmd_addr = base;
  438. port->data_addr = base;
  439. port->feature_addr =
  440. port->error_addr = base + 0x4;
  441. port->nsect_addr = base + 0x8;
  442. port->lbal_addr = base + 0xc;
  443. port->lbam_addr = base + 0x10;
  444. port->lbah_addr = base + 0x14;
  445. port->device_addr = base + 0x18;
  446. port->command_addr =
  447. port->status_addr = base + 0x1c;
  448. port->altstatus_addr =
  449. port->ctl_addr = base + 0x38;
  450. }
  451. static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
  452. {
  453. void *mmio = pe->mmio_base;
  454. u32 tmp;
  455. /*
  456. * Except for the hotplug stuff, this is voodoo from the
  457. * Promise driver. Label this entire section
  458. * "TODO: figure out why we do this"
  459. */
  460. /* change FIFO_SHD to 8 dwords, enable BMR_BURST */
  461. tmp = readl(mmio + PDC_FLASH_CTL);
  462. tmp |= 0x12000; /* bit 16 (fifo 8 dw) and 13 (bmr burst?) */
  463. writel(tmp, mmio + PDC_FLASH_CTL);
  464. /* clear plug/unplug flags for all ports */
  465. tmp = readl(mmio + PDC_SATA_PLUG_CSR);
  466. writel(tmp | 0xff, mmio + PDC_SATA_PLUG_CSR);
  467. /* mask plug/unplug ints */
  468. tmp = readl(mmio + PDC_SATA_PLUG_CSR);
  469. writel(tmp | 0xff0000, mmio + PDC_SATA_PLUG_CSR);
  470. /* reduce TBG clock to 133 Mhz. */
  471. tmp = readl(mmio + PDC_TBG_MODE);
  472. tmp &= ~0x30000; /* clear bit 17, 16*/
  473. tmp |= 0x10000; /* set bit 17:16 = 0:1 */
  474. writel(tmp, mmio + PDC_TBG_MODE);
  475. readl(mmio + PDC_TBG_MODE); /* flush */
  476. msleep(10);
  477. /* adjust slew rate control register. */
  478. tmp = readl(mmio + PDC_SLEW_CTL);
  479. tmp &= 0xFFFFF03F; /* clear bit 11 ~ 6 */
  480. tmp |= 0x00000900; /* set bit 11-9 = 100b , bit 8-6 = 100 */
  481. writel(tmp, mmio + PDC_SLEW_CTL);
  482. }
  483. static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  484. {
  485. static int printed_version;
  486. struct ata_probe_ent *probe_ent = NULL;
  487. unsigned long base;
  488. void *mmio_base;
  489. unsigned int board_idx = (unsigned int) ent->driver_data;
  490. int pci_dev_busy = 0;
  491. int rc;
  492. if (!printed_version++)
  493. printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
  494. /*
  495. * If this driver happens to only be useful on Apple's K2, then
  496. * we should check that here as it has a normal Serverworks ID
  497. */
  498. rc = pci_enable_device(pdev);
  499. if (rc)
  500. return rc;
  501. rc = pci_request_regions(pdev, DRV_NAME);
  502. if (rc) {
  503. pci_dev_busy = 1;
  504. goto err_out;
  505. }
  506. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  507. if (rc)
  508. goto err_out_regions;
  509. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  510. if (rc)
  511. goto err_out_regions;
  512. probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL);
  513. if (probe_ent == NULL) {
  514. rc = -ENOMEM;
  515. goto err_out_regions;
  516. }
  517. memset(probe_ent, 0, sizeof(*probe_ent));
  518. probe_ent->dev = pci_dev_to_dev(pdev);
  519. INIT_LIST_HEAD(&probe_ent->node);
  520. mmio_base = ioremap(pci_resource_start(pdev, 3),
  521. pci_resource_len(pdev, 3));
  522. if (mmio_base == NULL) {
  523. rc = -ENOMEM;
  524. goto err_out_free_ent;
  525. }
  526. base = (unsigned long) mmio_base;
  527. probe_ent->sht = pdc_port_info[board_idx].sht;
  528. probe_ent->host_flags = pdc_port_info[board_idx].host_flags;
  529. probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask;
  530. probe_ent->mwdma_mask = pdc_port_info[board_idx].mwdma_mask;
  531. probe_ent->udma_mask = pdc_port_info[board_idx].udma_mask;
  532. probe_ent->port_ops = pdc_port_info[board_idx].port_ops;
  533. probe_ent->irq = pdev->irq;
  534. probe_ent->irq_flags = SA_SHIRQ;
  535. probe_ent->mmio_base = mmio_base;
  536. pdc_ata_setup_port(&probe_ent->port[0], base + 0x200);
  537. pdc_ata_setup_port(&probe_ent->port[1], base + 0x280);
  538. probe_ent->port[0].scr_addr = base + 0x400;
  539. probe_ent->port[1].scr_addr = base + 0x500;
  540. /* notice 4-port boards */
  541. switch (board_idx) {
  542. case board_20319:
  543. probe_ent->n_ports = 4;
  544. pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
  545. pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
  546. probe_ent->port[2].scr_addr = base + 0x600;
  547. probe_ent->port[3].scr_addr = base + 0x700;
  548. break;
  549. case board_2037x:
  550. probe_ent->n_ports = 2;
  551. break;
  552. case board_20619:
  553. probe_ent->n_ports = 4;
  554. pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
  555. pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
  556. probe_ent->port[2].scr_addr = base + 0x600;
  557. probe_ent->port[3].scr_addr = base + 0x700;
  558. break;
  559. default:
  560. BUG();
  561. break;
  562. }
  563. pci_set_master(pdev);
  564. /* initialize adapter */
  565. pdc_host_init(board_idx, probe_ent);
  566. /* FIXME: check ata_device_add return value */
  567. ata_device_add(probe_ent);
  568. kfree(probe_ent);
  569. return 0;
  570. err_out_free_ent:
  571. kfree(probe_ent);
  572. err_out_regions:
  573. pci_release_regions(pdev);
  574. err_out:
  575. if (!pci_dev_busy)
  576. pci_disable_device(pdev);
  577. return rc;
  578. }
  579. static int __init pdc_ata_init(void)
  580. {
  581. return pci_module_init(&pdc_ata_pci_driver);
  582. }
  583. static void __exit pdc_ata_exit(void)
  584. {
  585. pci_unregister_driver(&pdc_ata_pci_driver);
  586. }
  587. MODULE_AUTHOR("Jeff Garzik");
  588. MODULE_DESCRIPTION("Promise ATA TX2/TX4/TX4000 low-level driver");
  589. MODULE_LICENSE("GPL");
  590. MODULE_DEVICE_TABLE(pci, pdc_ata_pci_tbl);
  591. MODULE_VERSION(DRV_VERSION);
  592. module_init(pdc_ata_init);
  593. module_exit(pdc_ata_exit);