sata_promise.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  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_pata_phy_reset(struct ata_port *ap);
  77. static void pdc_sata_phy_reset(struct ata_port *ap);
  78. static void pdc_qc_prep(struct ata_queued_cmd *qc);
  79. static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf);
  80. static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf);
  81. static void pdc_irq_clear(struct ata_port *ap);
  82. static int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
  83. static Scsi_Host_Template pdc_ata_sht = {
  84. .module = THIS_MODULE,
  85. .name = DRV_NAME,
  86. .ioctl = ata_scsi_ioctl,
  87. .queuecommand = ata_scsi_queuecmd,
  88. .eh_strategy_handler = ata_scsi_error,
  89. .can_queue = ATA_DEF_QUEUE,
  90. .this_id = ATA_SHT_THIS_ID,
  91. .sg_tablesize = LIBATA_MAX_PRD,
  92. .max_sectors = ATA_MAX_SECTORS,
  93. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  94. .emulated = ATA_SHT_EMULATED,
  95. .use_clustering = ATA_SHT_USE_CLUSTERING,
  96. .proc_name = DRV_NAME,
  97. .dma_boundary = ATA_DMA_BOUNDARY,
  98. .slave_configure = ata_scsi_slave_config,
  99. .bios_param = ata_std_bios_param,
  100. .ordered_flush = 1,
  101. };
  102. static struct ata_port_operations pdc_sata_ops = {
  103. .port_disable = ata_port_disable,
  104. .tf_load = pdc_tf_load_mmio,
  105. .tf_read = ata_tf_read,
  106. .check_status = ata_check_status,
  107. .exec_command = pdc_exec_command_mmio,
  108. .dev_select = ata_std_dev_select,
  109. .phy_reset = pdc_sata_phy_reset,
  110. .qc_prep = pdc_qc_prep,
  111. .qc_issue = pdc_qc_issue_prot,
  112. .eng_timeout = pdc_eng_timeout,
  113. .irq_handler = pdc_interrupt,
  114. .irq_clear = pdc_irq_clear,
  115. .scr_read = pdc_sata_scr_read,
  116. .scr_write = pdc_sata_scr_write,
  117. .port_start = pdc_port_start,
  118. .port_stop = pdc_port_stop,
  119. .host_stop = ata_pci_host_stop,
  120. };
  121. static struct ata_port_operations pdc_pata_ops = {
  122. .port_disable = ata_port_disable,
  123. .tf_load = pdc_tf_load_mmio,
  124. .tf_read = ata_tf_read,
  125. .check_status = ata_check_status,
  126. .exec_command = pdc_exec_command_mmio,
  127. .dev_select = ata_std_dev_select,
  128. .phy_reset = pdc_pata_phy_reset,
  129. .qc_prep = pdc_qc_prep,
  130. .qc_issue = pdc_qc_issue_prot,
  131. .eng_timeout = pdc_eng_timeout,
  132. .irq_handler = pdc_interrupt,
  133. .irq_clear = pdc_irq_clear,
  134. .port_start = pdc_port_start,
  135. .port_stop = pdc_port_stop,
  136. .host_stop = ata_pci_host_stop,
  137. };
  138. static struct ata_port_info pdc_port_info[] = {
  139. /* board_2037x */
  140. {
  141. .sht = &pdc_ata_sht,
  142. .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
  143. ATA_FLAG_SRST | ATA_FLAG_MMIO,
  144. .pio_mask = 0x1f, /* pio0-4 */
  145. .mwdma_mask = 0x07, /* mwdma0-2 */
  146. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  147. .port_ops = &pdc_sata_ops,
  148. },
  149. /* board_20319 */
  150. {
  151. .sht = &pdc_ata_sht,
  152. .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
  153. ATA_FLAG_SRST | ATA_FLAG_MMIO,
  154. .pio_mask = 0x1f, /* pio0-4 */
  155. .mwdma_mask = 0x07, /* mwdma0-2 */
  156. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  157. .port_ops = &pdc_sata_ops,
  158. },
  159. /* board_20619 */
  160. {
  161. .sht = &pdc_ata_sht,
  162. .host_flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST |
  163. ATA_FLAG_MMIO | ATA_FLAG_SLAVE_POSS,
  164. .pio_mask = 0x1f, /* pio0-4 */
  165. .mwdma_mask = 0x07, /* mwdma0-2 */
  166. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  167. .port_ops = &pdc_pata_ops,
  168. },
  169. };
  170. static struct pci_device_id pdc_ata_pci_tbl[] = {
  171. { PCI_VENDOR_ID_PROMISE, 0x3371, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  172. board_2037x },
  173. { PCI_VENDOR_ID_PROMISE, 0x3571, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  174. board_2037x },
  175. { PCI_VENDOR_ID_PROMISE, 0x3373, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  176. board_2037x },
  177. { PCI_VENDOR_ID_PROMISE, 0x3375, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  178. board_2037x },
  179. { PCI_VENDOR_ID_PROMISE, 0x3376, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  180. board_2037x },
  181. { PCI_VENDOR_ID_PROMISE, 0x3574, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  182. board_2037x },
  183. { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  184. board_2037x },
  185. { PCI_VENDOR_ID_PROMISE, 0x3318, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  186. board_20319 },
  187. { PCI_VENDOR_ID_PROMISE, 0x3319, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  188. board_20319 },
  189. { PCI_VENDOR_ID_PROMISE, 0x3519, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  190. board_20319 },
  191. { PCI_VENDOR_ID_PROMISE, 0x3d17, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  192. board_20319 },
  193. { PCI_VENDOR_ID_PROMISE, 0x3d18, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  194. board_20319 },
  195. { PCI_VENDOR_ID_PROMISE, 0x6629, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  196. board_20619 },
  197. { } /* terminate list */
  198. };
  199. static struct pci_driver pdc_ata_pci_driver = {
  200. .name = DRV_NAME,
  201. .id_table = pdc_ata_pci_tbl,
  202. .probe = pdc_ata_init_one,
  203. .remove = ata_pci_remove_one,
  204. };
  205. static int pdc_port_start(struct ata_port *ap)
  206. {
  207. struct device *dev = ap->host_set->dev;
  208. struct pdc_port_priv *pp;
  209. int rc;
  210. rc = ata_port_start(ap);
  211. if (rc)
  212. return rc;
  213. pp = kmalloc(sizeof(*pp), GFP_KERNEL);
  214. if (!pp) {
  215. rc = -ENOMEM;
  216. goto err_out;
  217. }
  218. memset(pp, 0, sizeof(*pp));
  219. pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
  220. if (!pp->pkt) {
  221. rc = -ENOMEM;
  222. goto err_out_kfree;
  223. }
  224. ap->private_data = pp;
  225. return 0;
  226. err_out_kfree:
  227. kfree(pp);
  228. err_out:
  229. ata_port_stop(ap);
  230. return rc;
  231. }
  232. static void pdc_port_stop(struct ata_port *ap)
  233. {
  234. struct device *dev = ap->host_set->dev;
  235. struct pdc_port_priv *pp = ap->private_data;
  236. ap->private_data = NULL;
  237. dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma);
  238. kfree(pp);
  239. ata_port_stop(ap);
  240. }
  241. static void pdc_reset_port(struct ata_port *ap)
  242. {
  243. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT;
  244. unsigned int i;
  245. u32 tmp;
  246. for (i = 11; i > 0; i--) {
  247. tmp = readl(mmio);
  248. if (tmp & PDC_RESET)
  249. break;
  250. udelay(100);
  251. tmp |= PDC_RESET;
  252. writel(tmp, mmio);
  253. }
  254. tmp &= ~PDC_RESET;
  255. writel(tmp, mmio);
  256. readl(mmio); /* flush */
  257. }
  258. static void pdc_sata_phy_reset(struct ata_port *ap)
  259. {
  260. pdc_reset_port(ap);
  261. sata_phy_reset(ap);
  262. }
  263. static void pdc_pata_phy_reset(struct ata_port *ap)
  264. {
  265. /* FIXME: add cable detect. Don't assume 40-pin cable */
  266. ap->cbl = ATA_CBL_PATA40;
  267. ap->udma_mask &= ATA_UDMA_MASK_40C;
  268. pdc_reset_port(ap);
  269. ata_port_probe(ap);
  270. ata_bus_reset(ap);
  271. }
  272. static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
  273. {
  274. if (sc_reg > SCR_CONTROL)
  275. return 0xffffffffU;
  276. return readl((void *) ap->ioaddr.scr_addr + (sc_reg * 4));
  277. }
  278. static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
  279. u32 val)
  280. {
  281. if (sc_reg > SCR_CONTROL)
  282. return;
  283. writel(val, (void *) ap->ioaddr.scr_addr + (sc_reg * 4));
  284. }
  285. static void pdc_qc_prep(struct ata_queued_cmd *qc)
  286. {
  287. struct pdc_port_priv *pp = qc->ap->private_data;
  288. unsigned int i;
  289. VPRINTK("ENTER\n");
  290. switch (qc->tf.protocol) {
  291. case ATA_PROT_DMA:
  292. ata_qc_prep(qc);
  293. /* fall through */
  294. case ATA_PROT_NODATA:
  295. i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
  296. qc->dev->devno, pp->pkt);
  297. if (qc->tf.flags & ATA_TFLAG_LBA48)
  298. i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
  299. else
  300. i = pdc_prep_lba28(&qc->tf, pp->pkt, i);
  301. pdc_pkt_footer(&qc->tf, pp->pkt, i);
  302. break;
  303. default:
  304. break;
  305. }
  306. }
  307. static void pdc_eng_timeout(struct ata_port *ap)
  308. {
  309. struct ata_host_set *host_set = ap->host_set;
  310. u8 drv_stat;
  311. struct ata_queued_cmd *qc;
  312. unsigned long flags;
  313. DPRINTK("ENTER\n");
  314. spin_lock_irqsave(&host_set->lock, flags);
  315. qc = ata_qc_from_tag(ap, ap->active_tag);
  316. if (!qc) {
  317. printk(KERN_ERR "ata%u: BUG: timeout without command\n",
  318. ap->id);
  319. goto out;
  320. }
  321. /* hack alert! We cannot use the supplied completion
  322. * function from inside the ->eh_strategy_handler() thread.
  323. * libata is the only user of ->eh_strategy_handler() in
  324. * any kernel, so the default scsi_done() assumes it is
  325. * not being called from the SCSI EH.
  326. */
  327. qc->scsidone = scsi_finish_command;
  328. switch (qc->tf.protocol) {
  329. case ATA_PROT_DMA:
  330. case ATA_PROT_NODATA:
  331. printk(KERN_ERR "ata%u: command timeout\n", ap->id);
  332. ata_qc_complete(qc, ata_wait_idle(ap) | ATA_ERR);
  333. break;
  334. default:
  335. drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
  336. printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n",
  337. ap->id, qc->tf.command, drv_stat);
  338. ata_qc_complete(qc, drv_stat);
  339. break;
  340. }
  341. out:
  342. spin_unlock_irqrestore(&host_set->lock, flags);
  343. DPRINTK("EXIT\n");
  344. }
  345. static inline unsigned int pdc_host_intr( struct ata_port *ap,
  346. struct ata_queued_cmd *qc)
  347. {
  348. u8 status;
  349. unsigned int handled = 0, have_err = 0;
  350. u32 tmp;
  351. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
  352. tmp = readl(mmio);
  353. if (tmp & PDC_ERR_MASK) {
  354. have_err = 1;
  355. pdc_reset_port(ap);
  356. }
  357. switch (qc->tf.protocol) {
  358. case ATA_PROT_DMA:
  359. case ATA_PROT_NODATA:
  360. status = ata_wait_idle(ap);
  361. if (have_err)
  362. status |= ATA_ERR;
  363. ata_qc_complete(qc, status);
  364. handled = 1;
  365. break;
  366. default:
  367. ap->stats.idle_irq++;
  368. break;
  369. }
  370. return handled;
  371. }
  372. static void pdc_irq_clear(struct ata_port *ap)
  373. {
  374. struct ata_host_set *host_set = ap->host_set;
  375. void __iomem *mmio = host_set->mmio_base;
  376. readl(mmio + PDC_INT_SEQMASK);
  377. }
  378. static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
  379. {
  380. struct ata_host_set *host_set = dev_instance;
  381. struct ata_port *ap;
  382. u32 mask = 0;
  383. unsigned int i, tmp;
  384. unsigned int handled = 0;
  385. void __iomem *mmio_base;
  386. VPRINTK("ENTER\n");
  387. if (!host_set || !host_set->mmio_base) {
  388. VPRINTK("QUICK EXIT\n");
  389. return IRQ_NONE;
  390. }
  391. mmio_base = host_set->mmio_base;
  392. /* reading should also clear interrupts */
  393. mask = readl(mmio_base + PDC_INT_SEQMASK);
  394. if (mask == 0xffffffff) {
  395. VPRINTK("QUICK EXIT 2\n");
  396. return IRQ_NONE;
  397. }
  398. mask &= 0xffff; /* only 16 tags possible */
  399. if (!mask) {
  400. VPRINTK("QUICK EXIT 3\n");
  401. return IRQ_NONE;
  402. }
  403. spin_lock(&host_set->lock);
  404. writel(mask, mmio_base + PDC_INT_SEQMASK);
  405. for (i = 0; i < host_set->n_ports; i++) {
  406. VPRINTK("port %u\n", i);
  407. ap = host_set->ports[i];
  408. tmp = mask & (1 << (i + 1));
  409. if (tmp && ap &&
  410. !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) {
  411. struct ata_queued_cmd *qc;
  412. qc = ata_qc_from_tag(ap, ap->active_tag);
  413. if (qc && (!(qc->tf.ctl & ATA_NIEN)))
  414. handled += pdc_host_intr(ap, qc);
  415. }
  416. }
  417. spin_unlock(&host_set->lock);
  418. VPRINTK("EXIT\n");
  419. return IRQ_RETVAL(handled);
  420. }
  421. static inline void pdc_packet_start(struct ata_queued_cmd *qc)
  422. {
  423. struct ata_port *ap = qc->ap;
  424. struct pdc_port_priv *pp = ap->private_data;
  425. unsigned int port_no = ap->port_no;
  426. u8 seq = (u8) (port_no + 1);
  427. VPRINTK("ENTER, ap %p\n", ap);
  428. writel(0x00000001, ap->host_set->mmio_base + (seq * 4));
  429. readl(ap->host_set->mmio_base + (seq * 4)); /* flush */
  430. pp->pkt[2] = seq;
  431. wmb(); /* flush PRD, pkt writes */
  432. writel(pp->pkt_dma, (void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
  433. readl((void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
  434. }
  435. static int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
  436. {
  437. switch (qc->tf.protocol) {
  438. case ATA_PROT_DMA:
  439. case ATA_PROT_NODATA:
  440. pdc_packet_start(qc);
  441. return 0;
  442. case ATA_PROT_ATAPI_DMA:
  443. BUG();
  444. break;
  445. default:
  446. break;
  447. }
  448. return ata_qc_issue_prot(qc);
  449. }
  450. static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf)
  451. {
  452. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  453. tf->protocol == ATA_PROT_NODATA);
  454. ata_tf_load(ap, tf);
  455. }
  456. static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf)
  457. {
  458. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  459. tf->protocol == ATA_PROT_NODATA);
  460. ata_exec_command(ap, tf);
  461. }
  462. static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
  463. {
  464. port->cmd_addr = base;
  465. port->data_addr = base;
  466. port->feature_addr =
  467. port->error_addr = base + 0x4;
  468. port->nsect_addr = base + 0x8;
  469. port->lbal_addr = base + 0xc;
  470. port->lbam_addr = base + 0x10;
  471. port->lbah_addr = base + 0x14;
  472. port->device_addr = base + 0x18;
  473. port->command_addr =
  474. port->status_addr = base + 0x1c;
  475. port->altstatus_addr =
  476. port->ctl_addr = base + 0x38;
  477. }
  478. static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
  479. {
  480. void __iomem *mmio = pe->mmio_base;
  481. u32 tmp;
  482. /*
  483. * Except for the hotplug stuff, this is voodoo from the
  484. * Promise driver. Label this entire section
  485. * "TODO: figure out why we do this"
  486. */
  487. /* change FIFO_SHD to 8 dwords, enable BMR_BURST */
  488. tmp = readl(mmio + PDC_FLASH_CTL);
  489. tmp |= 0x12000; /* bit 16 (fifo 8 dw) and 13 (bmr burst?) */
  490. writel(tmp, mmio + PDC_FLASH_CTL);
  491. /* clear plug/unplug flags for all ports */
  492. tmp = readl(mmio + PDC_SATA_PLUG_CSR);
  493. writel(tmp | 0xff, mmio + PDC_SATA_PLUG_CSR);
  494. /* mask plug/unplug ints */
  495. tmp = readl(mmio + PDC_SATA_PLUG_CSR);
  496. writel(tmp | 0xff0000, mmio + PDC_SATA_PLUG_CSR);
  497. /* reduce TBG clock to 133 Mhz. */
  498. tmp = readl(mmio + PDC_TBG_MODE);
  499. tmp &= ~0x30000; /* clear bit 17, 16*/
  500. tmp |= 0x10000; /* set bit 17:16 = 0:1 */
  501. writel(tmp, mmio + PDC_TBG_MODE);
  502. readl(mmio + PDC_TBG_MODE); /* flush */
  503. msleep(10);
  504. /* adjust slew rate control register. */
  505. tmp = readl(mmio + PDC_SLEW_CTL);
  506. tmp &= 0xFFFFF03F; /* clear bit 11 ~ 6 */
  507. tmp |= 0x00000900; /* set bit 11-9 = 100b , bit 8-6 = 100 */
  508. writel(tmp, mmio + PDC_SLEW_CTL);
  509. }
  510. static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  511. {
  512. static int printed_version;
  513. struct ata_probe_ent *probe_ent = NULL;
  514. unsigned long base;
  515. void __iomem *mmio_base;
  516. unsigned int board_idx = (unsigned int) ent->driver_data;
  517. int pci_dev_busy = 0;
  518. int rc;
  519. if (!printed_version++)
  520. printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
  521. /*
  522. * If this driver happens to only be useful on Apple's K2, then
  523. * we should check that here as it has a normal Serverworks ID
  524. */
  525. rc = pci_enable_device(pdev);
  526. if (rc)
  527. return rc;
  528. rc = pci_request_regions(pdev, DRV_NAME);
  529. if (rc) {
  530. pci_dev_busy = 1;
  531. goto err_out;
  532. }
  533. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  534. if (rc)
  535. goto err_out_regions;
  536. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  537. if (rc)
  538. goto err_out_regions;
  539. probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL);
  540. if (probe_ent == NULL) {
  541. rc = -ENOMEM;
  542. goto err_out_regions;
  543. }
  544. memset(probe_ent, 0, sizeof(*probe_ent));
  545. probe_ent->dev = pci_dev_to_dev(pdev);
  546. INIT_LIST_HEAD(&probe_ent->node);
  547. mmio_base = pci_iomap(pdev, 3, 0);
  548. if (mmio_base == NULL) {
  549. rc = -ENOMEM;
  550. goto err_out_free_ent;
  551. }
  552. base = (unsigned long) mmio_base;
  553. probe_ent->sht = pdc_port_info[board_idx].sht;
  554. probe_ent->host_flags = pdc_port_info[board_idx].host_flags;
  555. probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask;
  556. probe_ent->mwdma_mask = pdc_port_info[board_idx].mwdma_mask;
  557. probe_ent->udma_mask = pdc_port_info[board_idx].udma_mask;
  558. probe_ent->port_ops = pdc_port_info[board_idx].port_ops;
  559. probe_ent->irq = pdev->irq;
  560. probe_ent->irq_flags = SA_SHIRQ;
  561. probe_ent->mmio_base = mmio_base;
  562. pdc_ata_setup_port(&probe_ent->port[0], base + 0x200);
  563. pdc_ata_setup_port(&probe_ent->port[1], base + 0x280);
  564. probe_ent->port[0].scr_addr = base + 0x400;
  565. probe_ent->port[1].scr_addr = base + 0x500;
  566. /* notice 4-port boards */
  567. switch (board_idx) {
  568. case board_20319:
  569. probe_ent->n_ports = 4;
  570. pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
  571. pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
  572. probe_ent->port[2].scr_addr = base + 0x600;
  573. probe_ent->port[3].scr_addr = base + 0x700;
  574. break;
  575. case board_2037x:
  576. probe_ent->n_ports = 2;
  577. break;
  578. case board_20619:
  579. probe_ent->n_ports = 4;
  580. pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
  581. pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
  582. probe_ent->port[2].scr_addr = base + 0x600;
  583. probe_ent->port[3].scr_addr = base + 0x700;
  584. break;
  585. default:
  586. BUG();
  587. break;
  588. }
  589. pci_set_master(pdev);
  590. /* initialize adapter */
  591. pdc_host_init(board_idx, probe_ent);
  592. /* FIXME: check ata_device_add return value */
  593. ata_device_add(probe_ent);
  594. kfree(probe_ent);
  595. return 0;
  596. err_out_free_ent:
  597. kfree(probe_ent);
  598. err_out_regions:
  599. pci_release_regions(pdev);
  600. err_out:
  601. if (!pci_dev_busy)
  602. pci_disable_device(pdev);
  603. return rc;
  604. }
  605. static int __init pdc_ata_init(void)
  606. {
  607. return pci_module_init(&pdc_ata_pci_driver);
  608. }
  609. static void __exit pdc_ata_exit(void)
  610. {
  611. pci_unregister_driver(&pdc_ata_pci_driver);
  612. }
  613. MODULE_AUTHOR("Jeff Garzik");
  614. MODULE_DESCRIPTION("Promise ATA TX2/TX4/TX4000 low-level driver");
  615. MODULE_LICENSE("GPL");
  616. MODULE_DEVICE_TABLE(pci, pdc_ata_pci_tbl);
  617. MODULE_VERSION(DRV_VERSION);
  618. module_init(pdc_ata_init);
  619. module_exit(pdc_ata_exit);