sata_sx4.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395
  1. /*
  2. * sata_sx4.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 documentation 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/device.h>
  40. #include <scsi/scsi_host.h>
  41. #include <scsi/scsi_cmnd.h>
  42. #include <linux/libata.h>
  43. #include "sata_promise.h"
  44. #define DRV_NAME "sata_sx4"
  45. #define DRV_VERSION "0.10"
  46. enum {
  47. PDC_MMIO_BAR = 3,
  48. PDC_DIMM_BAR = 4,
  49. PDC_PRD_TBL = 0x44, /* Direct command DMA table addr */
  50. PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */
  51. PDC_HDMA_PKT_SUBMIT = 0x100, /* Host DMA packet pointer addr */
  52. PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */
  53. PDC_HDMA_CTLSTAT = 0x12C, /* Host DMA control / status */
  54. PDC_20621_SEQCTL = 0x400,
  55. PDC_20621_SEQMASK = 0x480,
  56. PDC_20621_GENERAL_CTL = 0x484,
  57. PDC_20621_PAGE_SIZE = (32 * 1024),
  58. /* chosen, not constant, values; we design our own DIMM mem map */
  59. PDC_20621_DIMM_WINDOW = 0x0C, /* page# for 32K DIMM window */
  60. PDC_20621_DIMM_BASE = 0x00200000,
  61. PDC_20621_DIMM_DATA = (64 * 1024),
  62. PDC_DIMM_DATA_STEP = (256 * 1024),
  63. PDC_DIMM_WINDOW_STEP = (8 * 1024),
  64. PDC_DIMM_HOST_PRD = (6 * 1024),
  65. PDC_DIMM_HOST_PKT = (128 * 0),
  66. PDC_DIMM_HPKT_PRD = (128 * 1),
  67. PDC_DIMM_ATA_PKT = (128 * 2),
  68. PDC_DIMM_APKT_PRD = (128 * 3),
  69. PDC_DIMM_HEADER_SZ = PDC_DIMM_APKT_PRD + 128,
  70. PDC_PAGE_WINDOW = 0x40,
  71. PDC_PAGE_DATA = PDC_PAGE_WINDOW +
  72. (PDC_20621_DIMM_DATA / PDC_20621_PAGE_SIZE),
  73. PDC_PAGE_SET = PDC_DIMM_DATA_STEP / PDC_20621_PAGE_SIZE,
  74. PDC_CHIP0_OFS = 0xC0000, /* offset of chip #0 */
  75. PDC_20621_ERR_MASK = (1<<19) | (1<<20) | (1<<21) | (1<<22) |
  76. (1<<23),
  77. board_20621 = 0, /* FastTrak S150 SX4 */
  78. PDC_RESET = (1 << 11), /* HDMA reset */
  79. PDC_MAX_HDMA = 32,
  80. PDC_HDMA_Q_MASK = (PDC_MAX_HDMA - 1),
  81. PDC_DIMM0_SPD_DEV_ADDRESS = 0x50,
  82. PDC_DIMM1_SPD_DEV_ADDRESS = 0x51,
  83. PDC_MAX_DIMM_MODULE = 0x02,
  84. PDC_I2C_CONTROL_OFFSET = 0x48,
  85. PDC_I2C_ADDR_DATA_OFFSET = 0x4C,
  86. PDC_DIMM0_CONTROL_OFFSET = 0x80,
  87. PDC_DIMM1_CONTROL_OFFSET = 0x84,
  88. PDC_SDRAM_CONTROL_OFFSET = 0x88,
  89. PDC_I2C_WRITE = 0x00000000,
  90. PDC_I2C_READ = 0x00000040,
  91. PDC_I2C_START = 0x00000080,
  92. PDC_I2C_MASK_INT = 0x00000020,
  93. PDC_I2C_COMPLETE = 0x00010000,
  94. PDC_I2C_NO_ACK = 0x00100000,
  95. PDC_DIMM_SPD_SUBADDRESS_START = 0x00,
  96. PDC_DIMM_SPD_SUBADDRESS_END = 0x7F,
  97. PDC_DIMM_SPD_ROW_NUM = 3,
  98. PDC_DIMM_SPD_COLUMN_NUM = 4,
  99. PDC_DIMM_SPD_MODULE_ROW = 5,
  100. PDC_DIMM_SPD_TYPE = 11,
  101. PDC_DIMM_SPD_FRESH_RATE = 12,
  102. PDC_DIMM_SPD_BANK_NUM = 17,
  103. PDC_DIMM_SPD_CAS_LATENCY = 18,
  104. PDC_DIMM_SPD_ATTRIBUTE = 21,
  105. PDC_DIMM_SPD_ROW_PRE_CHARGE = 27,
  106. PDC_DIMM_SPD_ROW_ACTIVE_DELAY = 28,
  107. PDC_DIMM_SPD_RAS_CAS_DELAY = 29,
  108. PDC_DIMM_SPD_ACTIVE_PRECHARGE = 30,
  109. PDC_DIMM_SPD_SYSTEM_FREQ = 126,
  110. PDC_CTL_STATUS = 0x08,
  111. PDC_DIMM_WINDOW_CTLR = 0x0C,
  112. PDC_TIME_CONTROL = 0x3C,
  113. PDC_TIME_PERIOD = 0x40,
  114. PDC_TIME_COUNTER = 0x44,
  115. PDC_GENERAL_CTLR = 0x484,
  116. PCI_PLL_INIT = 0x8A531824,
  117. PCI_X_TCOUNT = 0xEE1E5CFF
  118. };
  119. struct pdc_port_priv {
  120. u8 dimm_buf[(ATA_PRD_SZ * ATA_MAX_PRD) + 512];
  121. u8 *pkt;
  122. dma_addr_t pkt_dma;
  123. };
  124. struct pdc_host_priv {
  125. unsigned int doing_hdma;
  126. unsigned int hdma_prod;
  127. unsigned int hdma_cons;
  128. struct {
  129. struct ata_queued_cmd *qc;
  130. unsigned int seq;
  131. unsigned long pkt_ofs;
  132. } hdma[32];
  133. };
  134. static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
  135. static void pdc_eng_timeout(struct ata_port *ap);
  136. static void pdc_20621_phy_reset (struct ata_port *ap);
  137. static int pdc_port_start(struct ata_port *ap);
  138. static void pdc20621_qc_prep(struct ata_queued_cmd *qc);
  139. static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
  140. static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
  141. static unsigned int pdc20621_dimm_init(struct ata_host *host);
  142. static int pdc20621_detect_dimm(struct ata_host *host);
  143. static unsigned int pdc20621_i2c_read(struct ata_host *host,
  144. u32 device, u32 subaddr, u32 *pdata);
  145. static int pdc20621_prog_dimm0(struct ata_host *host);
  146. static unsigned int pdc20621_prog_dimm_global(struct ata_host *host);
  147. #ifdef ATA_VERBOSE_DEBUG
  148. static void pdc20621_get_from_dimm(struct ata_host *host,
  149. void *psource, u32 offset, u32 size);
  150. #endif
  151. static void pdc20621_put_to_dimm(struct ata_host *host,
  152. void *psource, u32 offset, u32 size);
  153. static void pdc20621_irq_clear(struct ata_port *ap);
  154. static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc);
  155. static struct scsi_host_template pdc_sata_sht = {
  156. .module = THIS_MODULE,
  157. .name = DRV_NAME,
  158. .ioctl = ata_scsi_ioctl,
  159. .queuecommand = ata_scsi_queuecmd,
  160. .can_queue = ATA_DEF_QUEUE,
  161. .this_id = ATA_SHT_THIS_ID,
  162. .sg_tablesize = LIBATA_MAX_PRD,
  163. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  164. .emulated = ATA_SHT_EMULATED,
  165. .use_clustering = ATA_SHT_USE_CLUSTERING,
  166. .proc_name = DRV_NAME,
  167. .dma_boundary = ATA_DMA_BOUNDARY,
  168. .slave_configure = ata_scsi_slave_config,
  169. .slave_destroy = ata_scsi_slave_destroy,
  170. .bios_param = ata_std_bios_param,
  171. };
  172. static const struct ata_port_operations pdc_20621_ops = {
  173. .port_disable = ata_port_disable,
  174. .tf_load = pdc_tf_load_mmio,
  175. .tf_read = ata_tf_read,
  176. .check_status = ata_check_status,
  177. .exec_command = pdc_exec_command_mmio,
  178. .dev_select = ata_std_dev_select,
  179. .phy_reset = pdc_20621_phy_reset,
  180. .qc_prep = pdc20621_qc_prep,
  181. .qc_issue = pdc20621_qc_issue_prot,
  182. .data_xfer = ata_data_xfer,
  183. .eng_timeout = pdc_eng_timeout,
  184. .irq_clear = pdc20621_irq_clear,
  185. .irq_on = ata_irq_on,
  186. .irq_ack = ata_irq_ack,
  187. .port_start = pdc_port_start,
  188. };
  189. static const struct ata_port_info pdc_port_info[] = {
  190. /* board_20621 */
  191. {
  192. .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
  193. ATA_FLAG_SRST | ATA_FLAG_MMIO |
  194. ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING,
  195. .pio_mask = 0x1f, /* pio0-4 */
  196. .mwdma_mask = 0x07, /* mwdma0-2 */
  197. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  198. .port_ops = &pdc_20621_ops,
  199. },
  200. };
  201. static const struct pci_device_id pdc_sata_pci_tbl[] = {
  202. { PCI_VDEVICE(PROMISE, 0x6622), board_20621 },
  203. { } /* terminate list */
  204. };
  205. static struct pci_driver pdc_sata_pci_driver = {
  206. .name = DRV_NAME,
  207. .id_table = pdc_sata_pci_tbl,
  208. .probe = pdc_sata_init_one,
  209. .remove = ata_pci_remove_one,
  210. };
  211. static int pdc_port_start(struct ata_port *ap)
  212. {
  213. struct device *dev = ap->host->dev;
  214. struct pdc_port_priv *pp;
  215. int rc;
  216. rc = ata_port_start(ap);
  217. if (rc)
  218. return rc;
  219. pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
  220. if (!pp)
  221. return -ENOMEM;
  222. pp->pkt = dmam_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
  223. if (!pp->pkt)
  224. return -ENOMEM;
  225. ap->private_data = pp;
  226. return 0;
  227. }
  228. static void pdc_20621_phy_reset (struct ata_port *ap)
  229. {
  230. VPRINTK("ENTER\n");
  231. ap->cbl = ATA_CBL_SATA;
  232. ata_port_probe(ap);
  233. ata_bus_reset(ap);
  234. }
  235. static inline void pdc20621_ata_sg(struct ata_taskfile *tf, u8 *buf,
  236. unsigned int portno,
  237. unsigned int total_len)
  238. {
  239. u32 addr;
  240. unsigned int dw = PDC_DIMM_APKT_PRD >> 2;
  241. u32 *buf32 = (u32 *) buf;
  242. /* output ATA packet S/G table */
  243. addr = PDC_20621_DIMM_BASE + PDC_20621_DIMM_DATA +
  244. (PDC_DIMM_DATA_STEP * portno);
  245. VPRINTK("ATA sg addr 0x%x, %d\n", addr, addr);
  246. buf32[dw] = cpu_to_le32(addr);
  247. buf32[dw + 1] = cpu_to_le32(total_len | ATA_PRD_EOT);
  248. VPRINTK("ATA PSG @ %x == (0x%x, 0x%x)\n",
  249. PDC_20621_DIMM_BASE +
  250. (PDC_DIMM_WINDOW_STEP * portno) +
  251. PDC_DIMM_APKT_PRD,
  252. buf32[dw], buf32[dw + 1]);
  253. }
  254. static inline void pdc20621_host_sg(struct ata_taskfile *tf, u8 *buf,
  255. unsigned int portno,
  256. unsigned int total_len)
  257. {
  258. u32 addr;
  259. unsigned int dw = PDC_DIMM_HPKT_PRD >> 2;
  260. u32 *buf32 = (u32 *) buf;
  261. /* output Host DMA packet S/G table */
  262. addr = PDC_20621_DIMM_BASE + PDC_20621_DIMM_DATA +
  263. (PDC_DIMM_DATA_STEP * portno);
  264. buf32[dw] = cpu_to_le32(addr);
  265. buf32[dw + 1] = cpu_to_le32(total_len | ATA_PRD_EOT);
  266. VPRINTK("HOST PSG @ %x == (0x%x, 0x%x)\n",
  267. PDC_20621_DIMM_BASE +
  268. (PDC_DIMM_WINDOW_STEP * portno) +
  269. PDC_DIMM_HPKT_PRD,
  270. buf32[dw], buf32[dw + 1]);
  271. }
  272. static inline unsigned int pdc20621_ata_pkt(struct ata_taskfile *tf,
  273. unsigned int devno, u8 *buf,
  274. unsigned int portno)
  275. {
  276. unsigned int i, dw;
  277. u32 *buf32 = (u32 *) buf;
  278. u8 dev_reg;
  279. unsigned int dimm_sg = PDC_20621_DIMM_BASE +
  280. (PDC_DIMM_WINDOW_STEP * portno) +
  281. PDC_DIMM_APKT_PRD;
  282. VPRINTK("ENTER, dimm_sg == 0x%x, %d\n", dimm_sg, dimm_sg);
  283. i = PDC_DIMM_ATA_PKT;
  284. /*
  285. * Set up ATA packet
  286. */
  287. if ((tf->protocol == ATA_PROT_DMA) && (!(tf->flags & ATA_TFLAG_WRITE)))
  288. buf[i++] = PDC_PKT_READ;
  289. else if (tf->protocol == ATA_PROT_NODATA)
  290. buf[i++] = PDC_PKT_NODATA;
  291. else
  292. buf[i++] = 0;
  293. buf[i++] = 0; /* reserved */
  294. buf[i++] = portno + 1; /* seq. id */
  295. buf[i++] = 0xff; /* delay seq. id */
  296. /* dimm dma S/G, and next-pkt */
  297. dw = i >> 2;
  298. if (tf->protocol == ATA_PROT_NODATA)
  299. buf32[dw] = 0;
  300. else
  301. buf32[dw] = cpu_to_le32(dimm_sg);
  302. buf32[dw + 1] = 0;
  303. i += 8;
  304. if (devno == 0)
  305. dev_reg = ATA_DEVICE_OBS;
  306. else
  307. dev_reg = ATA_DEVICE_OBS | ATA_DEV1;
  308. /* select device */
  309. buf[i++] = (1 << 5) | PDC_PKT_CLEAR_BSY | ATA_REG_DEVICE;
  310. buf[i++] = dev_reg;
  311. /* device control register */
  312. buf[i++] = (1 << 5) | PDC_REG_DEVCTL;
  313. buf[i++] = tf->ctl;
  314. return i;
  315. }
  316. static inline void pdc20621_host_pkt(struct ata_taskfile *tf, u8 *buf,
  317. unsigned int portno)
  318. {
  319. unsigned int dw;
  320. u32 tmp, *buf32 = (u32 *) buf;
  321. unsigned int host_sg = PDC_20621_DIMM_BASE +
  322. (PDC_DIMM_WINDOW_STEP * portno) +
  323. PDC_DIMM_HOST_PRD;
  324. unsigned int dimm_sg = PDC_20621_DIMM_BASE +
  325. (PDC_DIMM_WINDOW_STEP * portno) +
  326. PDC_DIMM_HPKT_PRD;
  327. VPRINTK("ENTER, dimm_sg == 0x%x, %d\n", dimm_sg, dimm_sg);
  328. VPRINTK("host_sg == 0x%x, %d\n", host_sg, host_sg);
  329. dw = PDC_DIMM_HOST_PKT >> 2;
  330. /*
  331. * Set up Host DMA packet
  332. */
  333. if ((tf->protocol == ATA_PROT_DMA) && (!(tf->flags & ATA_TFLAG_WRITE)))
  334. tmp = PDC_PKT_READ;
  335. else
  336. tmp = 0;
  337. tmp |= ((portno + 1 + 4) << 16); /* seq. id */
  338. tmp |= (0xff << 24); /* delay seq. id */
  339. buf32[dw + 0] = cpu_to_le32(tmp);
  340. buf32[dw + 1] = cpu_to_le32(host_sg);
  341. buf32[dw + 2] = cpu_to_le32(dimm_sg);
  342. buf32[dw + 3] = 0;
  343. VPRINTK("HOST PKT @ %x == (0x%x 0x%x 0x%x 0x%x)\n",
  344. PDC_20621_DIMM_BASE + (PDC_DIMM_WINDOW_STEP * portno) +
  345. PDC_DIMM_HOST_PKT,
  346. buf32[dw + 0],
  347. buf32[dw + 1],
  348. buf32[dw + 2],
  349. buf32[dw + 3]);
  350. }
  351. static void pdc20621_dma_prep(struct ata_queued_cmd *qc)
  352. {
  353. struct scatterlist *sg;
  354. struct ata_port *ap = qc->ap;
  355. struct pdc_port_priv *pp = ap->private_data;
  356. void __iomem *mmio = ap->host->iomap[PDC_MMIO_BAR];
  357. void __iomem *dimm_mmio = ap->host->iomap[PDC_DIMM_BAR];
  358. unsigned int portno = ap->port_no;
  359. unsigned int i, idx, total_len = 0, sgt_len;
  360. u32 *buf = (u32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ];
  361. WARN_ON(!(qc->flags & ATA_QCFLAG_DMAMAP));
  362. VPRINTK("ata%u: ENTER\n", ap->print_id);
  363. /* hard-code chip #0 */
  364. mmio += PDC_CHIP0_OFS;
  365. /*
  366. * Build S/G table
  367. */
  368. idx = 0;
  369. ata_for_each_sg(sg, qc) {
  370. buf[idx++] = cpu_to_le32(sg_dma_address(sg));
  371. buf[idx++] = cpu_to_le32(sg_dma_len(sg));
  372. total_len += sg_dma_len(sg);
  373. }
  374. buf[idx - 1] |= cpu_to_le32(ATA_PRD_EOT);
  375. sgt_len = idx * 4;
  376. /*
  377. * Build ATA, host DMA packets
  378. */
  379. pdc20621_host_sg(&qc->tf, &pp->dimm_buf[0], portno, total_len);
  380. pdc20621_host_pkt(&qc->tf, &pp->dimm_buf[0], portno);
  381. pdc20621_ata_sg(&qc->tf, &pp->dimm_buf[0], portno, total_len);
  382. i = pdc20621_ata_pkt(&qc->tf, qc->dev->devno, &pp->dimm_buf[0], portno);
  383. if (qc->tf.flags & ATA_TFLAG_LBA48)
  384. i = pdc_prep_lba48(&qc->tf, &pp->dimm_buf[0], i);
  385. else
  386. i = pdc_prep_lba28(&qc->tf, &pp->dimm_buf[0], i);
  387. pdc_pkt_footer(&qc->tf, &pp->dimm_buf[0], i);
  388. /* copy three S/G tables and two packets to DIMM MMIO window */
  389. memcpy_toio(dimm_mmio + (portno * PDC_DIMM_WINDOW_STEP),
  390. &pp->dimm_buf, PDC_DIMM_HEADER_SZ);
  391. memcpy_toio(dimm_mmio + (portno * PDC_DIMM_WINDOW_STEP) +
  392. PDC_DIMM_HOST_PRD,
  393. &pp->dimm_buf[PDC_DIMM_HEADER_SZ], sgt_len);
  394. /* force host FIFO dump */
  395. writel(0x00000001, mmio + PDC_20621_GENERAL_CTL);
  396. readl(dimm_mmio); /* MMIO PCI posting flush */
  397. VPRINTK("ata pkt buf ofs %u, prd size %u, mmio copied\n", i, sgt_len);
  398. }
  399. static void pdc20621_nodata_prep(struct ata_queued_cmd *qc)
  400. {
  401. struct ata_port *ap = qc->ap;
  402. struct pdc_port_priv *pp = ap->private_data;
  403. void __iomem *mmio = ap->host->iomap[PDC_MMIO_BAR];
  404. void __iomem *dimm_mmio = ap->host->iomap[PDC_DIMM_BAR];
  405. unsigned int portno = ap->port_no;
  406. unsigned int i;
  407. VPRINTK("ata%u: ENTER\n", ap->print_id);
  408. /* hard-code chip #0 */
  409. mmio += PDC_CHIP0_OFS;
  410. i = pdc20621_ata_pkt(&qc->tf, qc->dev->devno, &pp->dimm_buf[0], portno);
  411. if (qc->tf.flags & ATA_TFLAG_LBA48)
  412. i = pdc_prep_lba48(&qc->tf, &pp->dimm_buf[0], i);
  413. else
  414. i = pdc_prep_lba28(&qc->tf, &pp->dimm_buf[0], i);
  415. pdc_pkt_footer(&qc->tf, &pp->dimm_buf[0], i);
  416. /* copy three S/G tables and two packets to DIMM MMIO window */
  417. memcpy_toio(dimm_mmio + (portno * PDC_DIMM_WINDOW_STEP),
  418. &pp->dimm_buf, PDC_DIMM_HEADER_SZ);
  419. /* force host FIFO dump */
  420. writel(0x00000001, mmio + PDC_20621_GENERAL_CTL);
  421. readl(dimm_mmio); /* MMIO PCI posting flush */
  422. VPRINTK("ata pkt buf ofs %u, mmio copied\n", i);
  423. }
  424. static void pdc20621_qc_prep(struct ata_queued_cmd *qc)
  425. {
  426. switch (qc->tf.protocol) {
  427. case ATA_PROT_DMA:
  428. pdc20621_dma_prep(qc);
  429. break;
  430. case ATA_PROT_NODATA:
  431. pdc20621_nodata_prep(qc);
  432. break;
  433. default:
  434. break;
  435. }
  436. }
  437. static void __pdc20621_push_hdma(struct ata_queued_cmd *qc,
  438. unsigned int seq,
  439. u32 pkt_ofs)
  440. {
  441. struct ata_port *ap = qc->ap;
  442. struct ata_host *host = ap->host;
  443. void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
  444. /* hard-code chip #0 */
  445. mmio += PDC_CHIP0_OFS;
  446. writel(0x00000001, mmio + PDC_20621_SEQCTL + (seq * 4));
  447. readl(mmio + PDC_20621_SEQCTL + (seq * 4)); /* flush */
  448. writel(pkt_ofs, mmio + PDC_HDMA_PKT_SUBMIT);
  449. readl(mmio + PDC_HDMA_PKT_SUBMIT); /* flush */
  450. }
  451. static void pdc20621_push_hdma(struct ata_queued_cmd *qc,
  452. unsigned int seq,
  453. u32 pkt_ofs)
  454. {
  455. struct ata_port *ap = qc->ap;
  456. struct pdc_host_priv *pp = ap->host->private_data;
  457. unsigned int idx = pp->hdma_prod & PDC_HDMA_Q_MASK;
  458. if (!pp->doing_hdma) {
  459. __pdc20621_push_hdma(qc, seq, pkt_ofs);
  460. pp->doing_hdma = 1;
  461. return;
  462. }
  463. pp->hdma[idx].qc = qc;
  464. pp->hdma[idx].seq = seq;
  465. pp->hdma[idx].pkt_ofs = pkt_ofs;
  466. pp->hdma_prod++;
  467. }
  468. static void pdc20621_pop_hdma(struct ata_queued_cmd *qc)
  469. {
  470. struct ata_port *ap = qc->ap;
  471. struct pdc_host_priv *pp = ap->host->private_data;
  472. unsigned int idx = pp->hdma_cons & PDC_HDMA_Q_MASK;
  473. /* if nothing on queue, we're done */
  474. if (pp->hdma_prod == pp->hdma_cons) {
  475. pp->doing_hdma = 0;
  476. return;
  477. }
  478. __pdc20621_push_hdma(pp->hdma[idx].qc, pp->hdma[idx].seq,
  479. pp->hdma[idx].pkt_ofs);
  480. pp->hdma_cons++;
  481. }
  482. #ifdef ATA_VERBOSE_DEBUG
  483. static void pdc20621_dump_hdma(struct ata_queued_cmd *qc)
  484. {
  485. struct ata_port *ap = qc->ap;
  486. unsigned int port_no = ap->port_no;
  487. void __iomem *dimm_mmio = ap->host->iomap[PDC_DIMM_BAR];
  488. dimm_mmio += (port_no * PDC_DIMM_WINDOW_STEP);
  489. dimm_mmio += PDC_DIMM_HOST_PKT;
  490. printk(KERN_ERR "HDMA[0] == 0x%08X\n", readl(dimm_mmio));
  491. printk(KERN_ERR "HDMA[1] == 0x%08X\n", readl(dimm_mmio + 4));
  492. printk(KERN_ERR "HDMA[2] == 0x%08X\n", readl(dimm_mmio + 8));
  493. printk(KERN_ERR "HDMA[3] == 0x%08X\n", readl(dimm_mmio + 12));
  494. }
  495. #else
  496. static inline void pdc20621_dump_hdma(struct ata_queued_cmd *qc) { }
  497. #endif /* ATA_VERBOSE_DEBUG */
  498. static void pdc20621_packet_start(struct ata_queued_cmd *qc)
  499. {
  500. struct ata_port *ap = qc->ap;
  501. struct ata_host *host = ap->host;
  502. unsigned int port_no = ap->port_no;
  503. void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
  504. unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
  505. u8 seq = (u8) (port_no + 1);
  506. unsigned int port_ofs;
  507. /* hard-code chip #0 */
  508. mmio += PDC_CHIP0_OFS;
  509. VPRINTK("ata%u: ENTER\n", ap->print_id);
  510. wmb(); /* flush PRD, pkt writes */
  511. port_ofs = PDC_20621_DIMM_BASE + (PDC_DIMM_WINDOW_STEP * port_no);
  512. /* if writing, we (1) DMA to DIMM, then (2) do ATA command */
  513. if (rw && qc->tf.protocol == ATA_PROT_DMA) {
  514. seq += 4;
  515. pdc20621_dump_hdma(qc);
  516. pdc20621_push_hdma(qc, seq, port_ofs + PDC_DIMM_HOST_PKT);
  517. VPRINTK("queued ofs 0x%x (%u), seq %u\n",
  518. port_ofs + PDC_DIMM_HOST_PKT,
  519. port_ofs + PDC_DIMM_HOST_PKT,
  520. seq);
  521. } else {
  522. writel(0x00000001, mmio + PDC_20621_SEQCTL + (seq * 4));
  523. readl(mmio + PDC_20621_SEQCTL + (seq * 4)); /* flush */
  524. writel(port_ofs + PDC_DIMM_ATA_PKT,
  525. ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
  526. readl(ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
  527. VPRINTK("submitted ofs 0x%x (%u), seq %u\n",
  528. port_ofs + PDC_DIMM_ATA_PKT,
  529. port_ofs + PDC_DIMM_ATA_PKT,
  530. seq);
  531. }
  532. }
  533. static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc)
  534. {
  535. switch (qc->tf.protocol) {
  536. case ATA_PROT_DMA:
  537. case ATA_PROT_NODATA:
  538. pdc20621_packet_start(qc);
  539. return 0;
  540. case ATA_PROT_ATAPI_DMA:
  541. BUG();
  542. break;
  543. default:
  544. break;
  545. }
  546. return ata_qc_issue_prot(qc);
  547. }
  548. static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
  549. struct ata_queued_cmd *qc,
  550. unsigned int doing_hdma,
  551. void __iomem *mmio)
  552. {
  553. unsigned int port_no = ap->port_no;
  554. unsigned int port_ofs =
  555. PDC_20621_DIMM_BASE + (PDC_DIMM_WINDOW_STEP * port_no);
  556. u8 status;
  557. unsigned int handled = 0;
  558. VPRINTK("ENTER\n");
  559. if ((qc->tf.protocol == ATA_PROT_DMA) && /* read */
  560. (!(qc->tf.flags & ATA_TFLAG_WRITE))) {
  561. /* step two - DMA from DIMM to host */
  562. if (doing_hdma) {
  563. VPRINTK("ata%u: read hdma, 0x%x 0x%x\n", ap->print_id,
  564. readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT));
  565. /* get drive status; clear intr; complete txn */
  566. qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
  567. ata_qc_complete(qc);
  568. pdc20621_pop_hdma(qc);
  569. }
  570. /* step one - exec ATA command */
  571. else {
  572. u8 seq = (u8) (port_no + 1 + 4);
  573. VPRINTK("ata%u: read ata, 0x%x 0x%x\n", ap->print_id,
  574. readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT));
  575. /* submit hdma pkt */
  576. pdc20621_dump_hdma(qc);
  577. pdc20621_push_hdma(qc, seq,
  578. port_ofs + PDC_DIMM_HOST_PKT);
  579. }
  580. handled = 1;
  581. } else if (qc->tf.protocol == ATA_PROT_DMA) { /* write */
  582. /* step one - DMA from host to DIMM */
  583. if (doing_hdma) {
  584. u8 seq = (u8) (port_no + 1);
  585. VPRINTK("ata%u: write hdma, 0x%x 0x%x\n", ap->print_id,
  586. readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT));
  587. /* submit ata pkt */
  588. writel(0x00000001, mmio + PDC_20621_SEQCTL + (seq * 4));
  589. readl(mmio + PDC_20621_SEQCTL + (seq * 4));
  590. writel(port_ofs + PDC_DIMM_ATA_PKT,
  591. ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
  592. readl(ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
  593. }
  594. /* step two - execute ATA command */
  595. else {
  596. VPRINTK("ata%u: write ata, 0x%x 0x%x\n", ap->print_id,
  597. readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT));
  598. /* get drive status; clear intr; complete txn */
  599. qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
  600. ata_qc_complete(qc);
  601. pdc20621_pop_hdma(qc);
  602. }
  603. handled = 1;
  604. /* command completion, but no data xfer */
  605. } else if (qc->tf.protocol == ATA_PROT_NODATA) {
  606. status = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
  607. DPRINTK("BUS_NODATA (drv_stat 0x%X)\n", status);
  608. qc->err_mask |= ac_err_mask(status);
  609. ata_qc_complete(qc);
  610. handled = 1;
  611. } else {
  612. ap->stats.idle_irq++;
  613. }
  614. return handled;
  615. }
  616. static void pdc20621_irq_clear(struct ata_port *ap)
  617. {
  618. struct ata_host *host = ap->host;
  619. void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
  620. mmio += PDC_CHIP0_OFS;
  621. readl(mmio + PDC_20621_SEQMASK);
  622. }
  623. static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance)
  624. {
  625. struct ata_host *host = dev_instance;
  626. struct ata_port *ap;
  627. u32 mask = 0;
  628. unsigned int i, tmp, port_no;
  629. unsigned int handled = 0;
  630. void __iomem *mmio_base;
  631. VPRINTK("ENTER\n");
  632. if (!host || !host->iomap[PDC_MMIO_BAR]) {
  633. VPRINTK("QUICK EXIT\n");
  634. return IRQ_NONE;
  635. }
  636. mmio_base = host->iomap[PDC_MMIO_BAR];
  637. /* reading should also clear interrupts */
  638. mmio_base += PDC_CHIP0_OFS;
  639. mask = readl(mmio_base + PDC_20621_SEQMASK);
  640. VPRINTK("mask == 0x%x\n", mask);
  641. if (mask == 0xffffffff) {
  642. VPRINTK("QUICK EXIT 2\n");
  643. return IRQ_NONE;
  644. }
  645. mask &= 0xffff; /* only 16 tags possible */
  646. if (!mask) {
  647. VPRINTK("QUICK EXIT 3\n");
  648. return IRQ_NONE;
  649. }
  650. spin_lock(&host->lock);
  651. for (i = 1; i < 9; i++) {
  652. port_no = i - 1;
  653. if (port_no > 3)
  654. port_no -= 4;
  655. if (port_no >= host->n_ports)
  656. ap = NULL;
  657. else
  658. ap = host->ports[port_no];
  659. tmp = mask & (1 << i);
  660. VPRINTK("seq %u, port_no %u, ap %p, tmp %x\n", i, port_no, ap, tmp);
  661. if (tmp && ap &&
  662. !(ap->flags & ATA_FLAG_DISABLED)) {
  663. struct ata_queued_cmd *qc;
  664. qc = ata_qc_from_tag(ap, ap->active_tag);
  665. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
  666. handled += pdc20621_host_intr(ap, qc, (i > 4),
  667. mmio_base);
  668. }
  669. }
  670. spin_unlock(&host->lock);
  671. VPRINTK("mask == 0x%x\n", mask);
  672. VPRINTK("EXIT\n");
  673. return IRQ_RETVAL(handled);
  674. }
  675. static void pdc_eng_timeout(struct ata_port *ap)
  676. {
  677. u8 drv_stat;
  678. struct ata_host *host = ap->host;
  679. struct ata_queued_cmd *qc;
  680. unsigned long flags;
  681. DPRINTK("ENTER\n");
  682. spin_lock_irqsave(&host->lock, flags);
  683. qc = ata_qc_from_tag(ap, ap->active_tag);
  684. switch (qc->tf.protocol) {
  685. case ATA_PROT_DMA:
  686. case ATA_PROT_NODATA:
  687. ata_port_printk(ap, KERN_ERR, "command timeout\n");
  688. qc->err_mask |= __ac_err_mask(ata_wait_idle(ap));
  689. break;
  690. default:
  691. drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
  692. ata_port_printk(ap, KERN_ERR,
  693. "unknown timeout, cmd 0x%x stat 0x%x\n",
  694. qc->tf.command, drv_stat);
  695. qc->err_mask |= ac_err_mask(drv_stat);
  696. break;
  697. }
  698. spin_unlock_irqrestore(&host->lock, flags);
  699. ata_eh_qc_complete(qc);
  700. DPRINTK("EXIT\n");
  701. }
  702. static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
  703. {
  704. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  705. tf->protocol == ATA_PROT_NODATA);
  706. ata_tf_load(ap, tf);
  707. }
  708. static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
  709. {
  710. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  711. tf->protocol == ATA_PROT_NODATA);
  712. ata_exec_command(ap, tf);
  713. }
  714. static void pdc_sata_setup_port(struct ata_ioports *port, void __iomem *base)
  715. {
  716. port->cmd_addr = base;
  717. port->data_addr = base;
  718. port->feature_addr =
  719. port->error_addr = base + 0x4;
  720. port->nsect_addr = base + 0x8;
  721. port->lbal_addr = base + 0xc;
  722. port->lbam_addr = base + 0x10;
  723. port->lbah_addr = base + 0x14;
  724. port->device_addr = base + 0x18;
  725. port->command_addr =
  726. port->status_addr = base + 0x1c;
  727. port->altstatus_addr =
  728. port->ctl_addr = base + 0x38;
  729. }
  730. #ifdef ATA_VERBOSE_DEBUG
  731. static void pdc20621_get_from_dimm(struct ata_host *host, void *psource,
  732. u32 offset, u32 size)
  733. {
  734. u32 window_size;
  735. u16 idx;
  736. u8 page_mask;
  737. long dist;
  738. void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
  739. void __iomem *dimm_mmio = host->iomap[PDC_DIMM_BAR];
  740. /* hard-code chip #0 */
  741. mmio += PDC_CHIP0_OFS;
  742. page_mask = 0x00;
  743. window_size = 0x2000 * 4; /* 32K byte uchar size */
  744. idx = (u16) (offset / window_size);
  745. writel(0x01, mmio + PDC_GENERAL_CTLR);
  746. readl(mmio + PDC_GENERAL_CTLR);
  747. writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR);
  748. readl(mmio + PDC_DIMM_WINDOW_CTLR);
  749. offset -= (idx * window_size);
  750. idx++;
  751. dist = ((long) (window_size - (offset + size))) >= 0 ? size :
  752. (long) (window_size - offset);
  753. memcpy_fromio((char *) psource, (char *) (dimm_mmio + offset / 4),
  754. dist);
  755. psource += dist;
  756. size -= dist;
  757. for (; (long) size >= (long) window_size ;) {
  758. writel(0x01, mmio + PDC_GENERAL_CTLR);
  759. readl(mmio + PDC_GENERAL_CTLR);
  760. writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR);
  761. readl(mmio + PDC_DIMM_WINDOW_CTLR);
  762. memcpy_fromio((char *) psource, (char *) (dimm_mmio),
  763. window_size / 4);
  764. psource += window_size;
  765. size -= window_size;
  766. idx ++;
  767. }
  768. if (size) {
  769. writel(0x01, mmio + PDC_GENERAL_CTLR);
  770. readl(mmio + PDC_GENERAL_CTLR);
  771. writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR);
  772. readl(mmio + PDC_DIMM_WINDOW_CTLR);
  773. memcpy_fromio((char *) psource, (char *) (dimm_mmio),
  774. size / 4);
  775. }
  776. }
  777. #endif
  778. static void pdc20621_put_to_dimm(struct ata_host *host, void *psource,
  779. u32 offset, u32 size)
  780. {
  781. u32 window_size;
  782. u16 idx;
  783. u8 page_mask;
  784. long dist;
  785. void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
  786. void __iomem *dimm_mmio = host->iomap[PDC_DIMM_BAR];
  787. /* hard-code chip #0 */
  788. mmio += PDC_CHIP0_OFS;
  789. page_mask = 0x00;
  790. window_size = 0x2000 * 4; /* 32K byte uchar size */
  791. idx = (u16) (offset / window_size);
  792. writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR);
  793. readl(mmio + PDC_DIMM_WINDOW_CTLR);
  794. offset -= (idx * window_size);
  795. idx++;
  796. dist = ((long)(s32)(window_size - (offset + size))) >= 0 ? size :
  797. (long) (window_size - offset);
  798. memcpy_toio(dimm_mmio + offset / 4, psource, dist);
  799. writel(0x01, mmio + PDC_GENERAL_CTLR);
  800. readl(mmio + PDC_GENERAL_CTLR);
  801. psource += dist;
  802. size -= dist;
  803. for (; (long) size >= (long) window_size ;) {
  804. writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR);
  805. readl(mmio + PDC_DIMM_WINDOW_CTLR);
  806. memcpy_toio(dimm_mmio, psource, window_size / 4);
  807. writel(0x01, mmio + PDC_GENERAL_CTLR);
  808. readl(mmio + PDC_GENERAL_CTLR);
  809. psource += window_size;
  810. size -= window_size;
  811. idx ++;
  812. }
  813. if (size) {
  814. writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR);
  815. readl(mmio + PDC_DIMM_WINDOW_CTLR);
  816. memcpy_toio(dimm_mmio, psource, size / 4);
  817. writel(0x01, mmio + PDC_GENERAL_CTLR);
  818. readl(mmio + PDC_GENERAL_CTLR);
  819. }
  820. }
  821. static unsigned int pdc20621_i2c_read(struct ata_host *host, u32 device,
  822. u32 subaddr, u32 *pdata)
  823. {
  824. void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
  825. u32 i2creg = 0;
  826. u32 status;
  827. u32 count =0;
  828. /* hard-code chip #0 */
  829. mmio += PDC_CHIP0_OFS;
  830. i2creg |= device << 24;
  831. i2creg |= subaddr << 16;
  832. /* Set the device and subaddress */
  833. writel(i2creg, mmio + PDC_I2C_ADDR_DATA_OFFSET);
  834. readl(mmio + PDC_I2C_ADDR_DATA_OFFSET);
  835. /* Write Control to perform read operation, mask int */
  836. writel(PDC_I2C_READ | PDC_I2C_START | PDC_I2C_MASK_INT,
  837. mmio + PDC_I2C_CONTROL_OFFSET);
  838. for (count = 0; count <= 1000; count ++) {
  839. status = readl(mmio + PDC_I2C_CONTROL_OFFSET);
  840. if (status & PDC_I2C_COMPLETE) {
  841. status = readl(mmio + PDC_I2C_ADDR_DATA_OFFSET);
  842. break;
  843. } else if (count == 1000)
  844. return 0;
  845. }
  846. *pdata = (status >> 8) & 0x000000ff;
  847. return 1;
  848. }
  849. static int pdc20621_detect_dimm(struct ata_host *host)
  850. {
  851. u32 data=0 ;
  852. if (pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
  853. PDC_DIMM_SPD_SYSTEM_FREQ, &data)) {
  854. if (data == 100)
  855. return 100;
  856. } else
  857. return 0;
  858. if (pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS, 9, &data)) {
  859. if(data <= 0x75)
  860. return 133;
  861. } else
  862. return 0;
  863. return 0;
  864. }
  865. static int pdc20621_prog_dimm0(struct ata_host *host)
  866. {
  867. u32 spd0[50];
  868. u32 data = 0;
  869. int size, i;
  870. u8 bdimmsize;
  871. void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
  872. static const struct {
  873. unsigned int reg;
  874. unsigned int ofs;
  875. } pdc_i2c_read_data [] = {
  876. { PDC_DIMM_SPD_TYPE, 11 },
  877. { PDC_DIMM_SPD_FRESH_RATE, 12 },
  878. { PDC_DIMM_SPD_COLUMN_NUM, 4 },
  879. { PDC_DIMM_SPD_ATTRIBUTE, 21 },
  880. { PDC_DIMM_SPD_ROW_NUM, 3 },
  881. { PDC_DIMM_SPD_BANK_NUM, 17 },
  882. { PDC_DIMM_SPD_MODULE_ROW, 5 },
  883. { PDC_DIMM_SPD_ROW_PRE_CHARGE, 27 },
  884. { PDC_DIMM_SPD_ROW_ACTIVE_DELAY, 28 },
  885. { PDC_DIMM_SPD_RAS_CAS_DELAY, 29 },
  886. { PDC_DIMM_SPD_ACTIVE_PRECHARGE, 30 },
  887. { PDC_DIMM_SPD_CAS_LATENCY, 18 },
  888. };
  889. /* hard-code chip #0 */
  890. mmio += PDC_CHIP0_OFS;
  891. for(i=0; i<ARRAY_SIZE(pdc_i2c_read_data); i++)
  892. pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
  893. pdc_i2c_read_data[i].reg,
  894. &spd0[pdc_i2c_read_data[i].ofs]);
  895. data |= (spd0[4] - 8) | ((spd0[21] != 0) << 3) | ((spd0[3]-11) << 4);
  896. data |= ((spd0[17] / 4) << 6) | ((spd0[5] / 2) << 7) |
  897. ((((spd0[27] + 9) / 10) - 1) << 8) ;
  898. data |= (((((spd0[29] > spd0[28])
  899. ? spd0[29] : spd0[28]) + 9) / 10) - 1) << 10;
  900. data |= ((spd0[30] - spd0[29] + 9) / 10 - 2) << 12;
  901. if (spd0[18] & 0x08)
  902. data |= ((0x03) << 14);
  903. else if (spd0[18] & 0x04)
  904. data |= ((0x02) << 14);
  905. else if (spd0[18] & 0x01)
  906. data |= ((0x01) << 14);
  907. else
  908. data |= (0 << 14);
  909. /*
  910. Calculate the size of bDIMMSize (power of 2) and
  911. merge the DIMM size by program start/end address.
  912. */
  913. bdimmsize = spd0[4] + (spd0[5] / 2) + spd0[3] + (spd0[17] / 2) + 3;
  914. size = (1 << bdimmsize) >> 20; /* size = xxx(MB) */
  915. data |= (((size / 16) - 1) << 16);
  916. data |= (0 << 23);
  917. data |= 8;
  918. writel(data, mmio + PDC_DIMM0_CONTROL_OFFSET);
  919. readl(mmio + PDC_DIMM0_CONTROL_OFFSET);
  920. return size;
  921. }
  922. static unsigned int pdc20621_prog_dimm_global(struct ata_host *host)
  923. {
  924. u32 data, spd0;
  925. int error, i;
  926. void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
  927. /* hard-code chip #0 */
  928. mmio += PDC_CHIP0_OFS;
  929. /*
  930. Set To Default : DIMM Module Global Control Register (0x022259F1)
  931. DIMM Arbitration Disable (bit 20)
  932. DIMM Data/Control Output Driving Selection (bit12 - bit15)
  933. Refresh Enable (bit 17)
  934. */
  935. data = 0x022259F1;
  936. writel(data, mmio + PDC_SDRAM_CONTROL_OFFSET);
  937. readl(mmio + PDC_SDRAM_CONTROL_OFFSET);
  938. /* Turn on for ECC */
  939. pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
  940. PDC_DIMM_SPD_TYPE, &spd0);
  941. if (spd0 == 0x02) {
  942. data |= (0x01 << 16);
  943. writel(data, mmio + PDC_SDRAM_CONTROL_OFFSET);
  944. readl(mmio + PDC_SDRAM_CONTROL_OFFSET);
  945. printk(KERN_ERR "Local DIMM ECC Enabled\n");
  946. }
  947. /* DIMM Initialization Select/Enable (bit 18/19) */
  948. data &= (~(1<<18));
  949. data |= (1<<19);
  950. writel(data, mmio + PDC_SDRAM_CONTROL_OFFSET);
  951. error = 1;
  952. for (i = 1; i <= 10; i++) { /* polling ~5 secs */
  953. data = readl(mmio + PDC_SDRAM_CONTROL_OFFSET);
  954. if (!(data & (1<<19))) {
  955. error = 0;
  956. break;
  957. }
  958. msleep(i*100);
  959. }
  960. return error;
  961. }
  962. static unsigned int pdc20621_dimm_init(struct ata_host *host)
  963. {
  964. int speed, size, length;
  965. u32 addr,spd0,pci_status;
  966. u32 tmp=0;
  967. u32 time_period=0;
  968. u32 tcount=0;
  969. u32 ticks=0;
  970. u32 clock=0;
  971. u32 fparam=0;
  972. void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
  973. /* hard-code chip #0 */
  974. mmio += PDC_CHIP0_OFS;
  975. /* Initialize PLL based upon PCI Bus Frequency */
  976. /* Initialize Time Period Register */
  977. writel(0xffffffff, mmio + PDC_TIME_PERIOD);
  978. time_period = readl(mmio + PDC_TIME_PERIOD);
  979. VPRINTK("Time Period Register (0x40): 0x%x\n", time_period);
  980. /* Enable timer */
  981. writel(0x00001a0, mmio + PDC_TIME_CONTROL);
  982. readl(mmio + PDC_TIME_CONTROL);
  983. /* Wait 3 seconds */
  984. msleep(3000);
  985. /*
  986. When timer is enabled, counter is decreased every internal
  987. clock cycle.
  988. */
  989. tcount = readl(mmio + PDC_TIME_COUNTER);
  990. VPRINTK("Time Counter Register (0x44): 0x%x\n", tcount);
  991. /*
  992. If SX4 is on PCI-X bus, after 3 seconds, the timer counter
  993. register should be >= (0xffffffff - 3x10^8).
  994. */
  995. if(tcount >= PCI_X_TCOUNT) {
  996. ticks = (time_period - tcount);
  997. VPRINTK("Num counters 0x%x (%d)\n", ticks, ticks);
  998. clock = (ticks / 300000);
  999. VPRINTK("10 * Internal clk = 0x%x (%d)\n", clock, clock);
  1000. clock = (clock * 33);
  1001. VPRINTK("10 * Internal clk * 33 = 0x%x (%d)\n", clock, clock);
  1002. /* PLL F Param (bit 22:16) */
  1003. fparam = (1400000 / clock) - 2;
  1004. VPRINTK("PLL F Param: 0x%x (%d)\n", fparam, fparam);
  1005. /* OD param = 0x2 (bit 31:30), R param = 0x5 (bit 29:25) */
  1006. pci_status = (0x8a001824 | (fparam << 16));
  1007. } else
  1008. pci_status = PCI_PLL_INIT;
  1009. /* Initialize PLL. */
  1010. VPRINTK("pci_status: 0x%x\n", pci_status);
  1011. writel(pci_status, mmio + PDC_CTL_STATUS);
  1012. readl(mmio + PDC_CTL_STATUS);
  1013. /*
  1014. Read SPD of DIMM by I2C interface,
  1015. and program the DIMM Module Controller.
  1016. */
  1017. if (!(speed = pdc20621_detect_dimm(host))) {
  1018. printk(KERN_ERR "Detect Local DIMM Fail\n");
  1019. return 1; /* DIMM error */
  1020. }
  1021. VPRINTK("Local DIMM Speed = %d\n", speed);
  1022. /* Programming DIMM0 Module Control Register (index_CID0:80h) */
  1023. size = pdc20621_prog_dimm0(host);
  1024. VPRINTK("Local DIMM Size = %dMB\n",size);
  1025. /* Programming DIMM Module Global Control Register (index_CID0:88h) */
  1026. if (pdc20621_prog_dimm_global(host)) {
  1027. printk(KERN_ERR "Programming DIMM Module Global Control Register Fail\n");
  1028. return 1;
  1029. }
  1030. #ifdef ATA_VERBOSE_DEBUG
  1031. {
  1032. u8 test_parttern1[40] = {0x55,0xAA,'P','r','o','m','i','s','e',' ',
  1033. 'N','o','t',' ','Y','e','t',' ','D','e','f','i','n','e','d',' ',
  1034. '1','.','1','0',
  1035. '9','8','0','3','1','6','1','2',0,0};
  1036. u8 test_parttern2[40] = {0};
  1037. pdc20621_put_to_dimm(host, (void *) test_parttern2, 0x10040, 40);
  1038. pdc20621_put_to_dimm(host, (void *) test_parttern2, 0x40, 40);
  1039. pdc20621_put_to_dimm(host, (void *) test_parttern1, 0x10040, 40);
  1040. pdc20621_get_from_dimm(host, (void *) test_parttern2, 0x40, 40);
  1041. printk(KERN_ERR "%x, %x, %s\n", test_parttern2[0],
  1042. test_parttern2[1], &(test_parttern2[2]));
  1043. pdc20621_get_from_dimm(host, (void *) test_parttern2, 0x10040,
  1044. 40);
  1045. printk(KERN_ERR "%x, %x, %s\n", test_parttern2[0],
  1046. test_parttern2[1], &(test_parttern2[2]));
  1047. pdc20621_put_to_dimm(host, (void *) test_parttern1, 0x40, 40);
  1048. pdc20621_get_from_dimm(host, (void *) test_parttern2, 0x40, 40);
  1049. printk(KERN_ERR "%x, %x, %s\n", test_parttern2[0],
  1050. test_parttern2[1], &(test_parttern2[2]));
  1051. }
  1052. #endif
  1053. /* ECC initiliazation. */
  1054. pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
  1055. PDC_DIMM_SPD_TYPE, &spd0);
  1056. if (spd0 == 0x02) {
  1057. VPRINTK("Start ECC initialization\n");
  1058. addr = 0;
  1059. length = size * 1024 * 1024;
  1060. while (addr < length) {
  1061. pdc20621_put_to_dimm(host, (void *) &tmp, addr,
  1062. sizeof(u32));
  1063. addr += sizeof(u32);
  1064. }
  1065. VPRINTK("Finish ECC initialization\n");
  1066. }
  1067. return 0;
  1068. }
  1069. static void pdc_20621_init(struct ata_host *host)
  1070. {
  1071. u32 tmp;
  1072. void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
  1073. /* hard-code chip #0 */
  1074. mmio += PDC_CHIP0_OFS;
  1075. /*
  1076. * Select page 0x40 for our 32k DIMM window
  1077. */
  1078. tmp = readl(mmio + PDC_20621_DIMM_WINDOW) & 0xffff0000;
  1079. tmp |= PDC_PAGE_WINDOW; /* page 40h; arbitrarily selected */
  1080. writel(tmp, mmio + PDC_20621_DIMM_WINDOW);
  1081. /*
  1082. * Reset Host DMA
  1083. */
  1084. tmp = readl(mmio + PDC_HDMA_CTLSTAT);
  1085. tmp |= PDC_RESET;
  1086. writel(tmp, mmio + PDC_HDMA_CTLSTAT);
  1087. readl(mmio + PDC_HDMA_CTLSTAT); /* flush */
  1088. udelay(10);
  1089. tmp = readl(mmio + PDC_HDMA_CTLSTAT);
  1090. tmp &= ~PDC_RESET;
  1091. writel(tmp, mmio + PDC_HDMA_CTLSTAT);
  1092. readl(mmio + PDC_HDMA_CTLSTAT); /* flush */
  1093. }
  1094. static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  1095. {
  1096. static int printed_version;
  1097. const struct ata_port_info *ppi[] =
  1098. { &pdc_port_info[ent->driver_data], NULL };
  1099. struct ata_host *host;
  1100. void __iomem *base;
  1101. struct pdc_host_priv *hpriv;
  1102. int rc;
  1103. if (!printed_version++)
  1104. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  1105. /* allocate host */
  1106. host = ata_host_alloc_pinfo(&pdev->dev, ppi, 4);
  1107. hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
  1108. if (!host || !hpriv)
  1109. return -ENOMEM;
  1110. host->private_data = hpriv;
  1111. /* acquire resources and fill host */
  1112. rc = pcim_enable_device(pdev);
  1113. if (rc)
  1114. return rc;
  1115. rc = pcim_iomap_regions(pdev, (1 << PDC_MMIO_BAR) | (1 << PDC_DIMM_BAR),
  1116. DRV_NAME);
  1117. if (rc == -EBUSY)
  1118. pcim_pin_device(pdev);
  1119. if (rc)
  1120. return rc;
  1121. host->iomap = pcim_iomap_table(pdev);
  1122. base = host->iomap[PDC_MMIO_BAR] + PDC_CHIP0_OFS;
  1123. pdc_sata_setup_port(&host->ports[0]->ioaddr, base + 0x200);
  1124. pdc_sata_setup_port(&host->ports[1]->ioaddr, base + 0x280);
  1125. pdc_sata_setup_port(&host->ports[2]->ioaddr, base + 0x300);
  1126. pdc_sata_setup_port(&host->ports[3]->ioaddr, base + 0x380);
  1127. /* configure and activate */
  1128. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  1129. if (rc)
  1130. return rc;
  1131. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  1132. if (rc)
  1133. return rc;
  1134. if (pdc20621_dimm_init(host))
  1135. return -ENOMEM;
  1136. pdc_20621_init(host);
  1137. pci_set_master(pdev);
  1138. return ata_host_activate(host, pdev->irq, pdc20621_interrupt,
  1139. IRQF_SHARED, &pdc_sata_sht);
  1140. }
  1141. static int __init pdc_sata_init(void)
  1142. {
  1143. return pci_register_driver(&pdc_sata_pci_driver);
  1144. }
  1145. static void __exit pdc_sata_exit(void)
  1146. {
  1147. pci_unregister_driver(&pdc_sata_pci_driver);
  1148. }
  1149. MODULE_AUTHOR("Jeff Garzik");
  1150. MODULE_DESCRIPTION("Promise SATA low-level driver");
  1151. MODULE_LICENSE("GPL");
  1152. MODULE_DEVICE_TABLE(pci, pdc_sata_pci_tbl);
  1153. MODULE_VERSION(DRV_VERSION);
  1154. module_init(pdc_sata_init);
  1155. module_exit(pdc_sata_exit);