sata_sx4.c 37 KB

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