sata_promise.c 19 KB

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