2 * sata_sx4.c - Promise SATA
4 * Maintained by: Jeff Garzik <jgarzik@pobox.com>
5 * Please ALWAYS copy linux-ide@vger.kernel.org
8 * Copyright 2003-2004 Red Hat, Inc.
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)
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.
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.
26 * libata documentation is available via 'make {ps|pdf}docs',
27 * as Documentation/DocBook/libata.*
29 * Hardware documentation available under NDA.
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/pci.h>
36 #include <linux/init.h>
37 #include <linux/blkdev.h>
38 #include <linux/delay.h>
39 #include <linux/interrupt.h>
40 #include <linux/sched.h>
41 #include <linux/device.h>
42 #include <scsi/scsi_host.h>
43 #include <scsi/scsi_cmnd.h>
44 #include <linux/libata.h>
45 #include "sata_promise.h"
47 #define DRV_NAME "sata_sx4"
48 #define DRV_VERSION "0.9"
55 PDC_PRD_TBL
= 0x44, /* Direct command DMA table addr */
57 PDC_PKT_SUBMIT
= 0x40, /* Command packet pointer addr */
58 PDC_HDMA_PKT_SUBMIT
= 0x100, /* Host DMA packet pointer addr */
59 PDC_INT_SEQMASK
= 0x40, /* Mask of asserted SEQ INTs */
60 PDC_HDMA_CTLSTAT
= 0x12C, /* Host DMA control / status */
62 PDC_20621_SEQCTL
= 0x400,
63 PDC_20621_SEQMASK
= 0x480,
64 PDC_20621_GENERAL_CTL
= 0x484,
65 PDC_20621_PAGE_SIZE
= (32 * 1024),
67 /* chosen, not constant, values; we design our own DIMM mem map */
68 PDC_20621_DIMM_WINDOW
= 0x0C, /* page# for 32K DIMM window */
69 PDC_20621_DIMM_BASE
= 0x00200000,
70 PDC_20621_DIMM_DATA
= (64 * 1024),
71 PDC_DIMM_DATA_STEP
= (256 * 1024),
72 PDC_DIMM_WINDOW_STEP
= (8 * 1024),
73 PDC_DIMM_HOST_PRD
= (6 * 1024),
74 PDC_DIMM_HOST_PKT
= (128 * 0),
75 PDC_DIMM_HPKT_PRD
= (128 * 1),
76 PDC_DIMM_ATA_PKT
= (128 * 2),
77 PDC_DIMM_APKT_PRD
= (128 * 3),
78 PDC_DIMM_HEADER_SZ
= PDC_DIMM_APKT_PRD
+ 128,
79 PDC_PAGE_WINDOW
= 0x40,
80 PDC_PAGE_DATA
= PDC_PAGE_WINDOW
+
81 (PDC_20621_DIMM_DATA
/ PDC_20621_PAGE_SIZE
),
82 PDC_PAGE_SET
= PDC_DIMM_DATA_STEP
/ PDC_20621_PAGE_SIZE
,
84 PDC_CHIP0_OFS
= 0xC0000, /* offset of chip #0 */
86 PDC_20621_ERR_MASK
= (1<<19) | (1<<20) | (1<<21) | (1<<22) |
89 board_20621
= 0, /* FastTrak S150 SX4 */
91 PDC_RESET
= (1 << 11), /* HDMA reset */
94 PDC_HDMA_Q_MASK
= (PDC_MAX_HDMA
- 1),
96 PDC_DIMM0_SPD_DEV_ADDRESS
= 0x50,
97 PDC_DIMM1_SPD_DEV_ADDRESS
= 0x51,
98 PDC_MAX_DIMM_MODULE
= 0x02,
99 PDC_I2C_CONTROL_OFFSET
= 0x48,
100 PDC_I2C_ADDR_DATA_OFFSET
= 0x4C,
101 PDC_DIMM0_CONTROL_OFFSET
= 0x80,
102 PDC_DIMM1_CONTROL_OFFSET
= 0x84,
103 PDC_SDRAM_CONTROL_OFFSET
= 0x88,
104 PDC_I2C_WRITE
= 0x00000000,
105 PDC_I2C_READ
= 0x00000040,
106 PDC_I2C_START
= 0x00000080,
107 PDC_I2C_MASK_INT
= 0x00000020,
108 PDC_I2C_COMPLETE
= 0x00010000,
109 PDC_I2C_NO_ACK
= 0x00100000,
110 PDC_DIMM_SPD_SUBADDRESS_START
= 0x00,
111 PDC_DIMM_SPD_SUBADDRESS_END
= 0x7F,
112 PDC_DIMM_SPD_ROW_NUM
= 3,
113 PDC_DIMM_SPD_COLUMN_NUM
= 4,
114 PDC_DIMM_SPD_MODULE_ROW
= 5,
115 PDC_DIMM_SPD_TYPE
= 11,
116 PDC_DIMM_SPD_FRESH_RATE
= 12,
117 PDC_DIMM_SPD_BANK_NUM
= 17,
118 PDC_DIMM_SPD_CAS_LATENCY
= 18,
119 PDC_DIMM_SPD_ATTRIBUTE
= 21,
120 PDC_DIMM_SPD_ROW_PRE_CHARGE
= 27,
121 PDC_DIMM_SPD_ROW_ACTIVE_DELAY
= 28,
122 PDC_DIMM_SPD_RAS_CAS_DELAY
= 29,
123 PDC_DIMM_SPD_ACTIVE_PRECHARGE
= 30,
124 PDC_DIMM_SPD_SYSTEM_FREQ
= 126,
125 PDC_CTL_STATUS
= 0x08,
126 PDC_DIMM_WINDOW_CTLR
= 0x0C,
127 PDC_TIME_CONTROL
= 0x3C,
128 PDC_TIME_PERIOD
= 0x40,
129 PDC_TIME_COUNTER
= 0x44,
130 PDC_GENERAL_CTLR
= 0x484,
131 PCI_PLL_INIT
= 0x8A531824,
132 PCI_X_TCOUNT
= 0xEE1E5CFF
136 struct pdc_port_priv
{
137 u8 dimm_buf
[(ATA_PRD_SZ
* ATA_MAX_PRD
) + 512];
142 struct pdc_host_priv
{
143 unsigned int doing_hdma
;
144 unsigned int hdma_prod
;
145 unsigned int hdma_cons
;
147 struct ata_queued_cmd
*qc
;
149 unsigned long pkt_ofs
;
154 static int pdc_sata_init_one (struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
155 static irqreturn_t
pdc20621_interrupt (int irq
, void *dev_instance
);
156 static void pdc_eng_timeout(struct ata_port
*ap
);
157 static void pdc_20621_phy_reset (struct ata_port
*ap
);
158 static int pdc_port_start(struct ata_port
*ap
);
159 static void pdc20621_qc_prep(struct ata_queued_cmd
*qc
);
160 static void pdc_tf_load_mmio(struct ata_port
*ap
, const struct ata_taskfile
*tf
);
161 static void pdc_exec_command_mmio(struct ata_port
*ap
, const struct ata_taskfile
*tf
);
162 static unsigned int pdc20621_dimm_init(struct ata_probe_ent
*pe
);
163 static int pdc20621_detect_dimm(struct ata_probe_ent
*pe
);
164 static unsigned int pdc20621_i2c_read(struct ata_probe_ent
*pe
,
165 u32 device
, u32 subaddr
, u32
*pdata
);
166 static int pdc20621_prog_dimm0(struct ata_probe_ent
*pe
);
167 static unsigned int pdc20621_prog_dimm_global(struct ata_probe_ent
*pe
);
168 #ifdef ATA_VERBOSE_DEBUG
169 static void pdc20621_get_from_dimm(struct ata_probe_ent
*pe
,
170 void *psource
, u32 offset
, u32 size
);
172 static void pdc20621_put_to_dimm(struct ata_probe_ent
*pe
,
173 void *psource
, u32 offset
, u32 size
);
174 static void pdc20621_irq_clear(struct ata_port
*ap
);
175 static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd
*qc
);
178 static struct scsi_host_template pdc_sata_sht
= {
179 .module
= THIS_MODULE
,
181 .ioctl
= ata_scsi_ioctl
,
182 .queuecommand
= ata_scsi_queuecmd
,
183 .can_queue
= ATA_DEF_QUEUE
,
184 .this_id
= ATA_SHT_THIS_ID
,
185 .sg_tablesize
= LIBATA_MAX_PRD
,
186 .cmd_per_lun
= ATA_SHT_CMD_PER_LUN
,
187 .emulated
= ATA_SHT_EMULATED
,
188 .use_clustering
= ATA_SHT_USE_CLUSTERING
,
189 .proc_name
= DRV_NAME
,
190 .dma_boundary
= ATA_DMA_BOUNDARY
,
191 .slave_configure
= ata_scsi_slave_config
,
192 .slave_destroy
= ata_scsi_slave_destroy
,
193 .bios_param
= ata_std_bios_param
,
196 static const struct ata_port_operations pdc_20621_ops
= {
197 .port_disable
= ata_port_disable
,
198 .tf_load
= pdc_tf_load_mmio
,
199 .tf_read
= ata_tf_read
,
200 .check_status
= ata_check_status
,
201 .exec_command
= pdc_exec_command_mmio
,
202 .dev_select
= ata_std_dev_select
,
203 .phy_reset
= pdc_20621_phy_reset
,
204 .qc_prep
= pdc20621_qc_prep
,
205 .qc_issue
= pdc20621_qc_issue_prot
,
206 .data_xfer
= ata_data_xfer
,
207 .eng_timeout
= pdc_eng_timeout
,
208 .irq_handler
= pdc20621_interrupt
,
209 .irq_clear
= pdc20621_irq_clear
,
210 .port_start
= pdc_port_start
,
213 static const struct ata_port_info pdc_port_info
[] = {
216 .sht
= &pdc_sata_sht
,
217 .flags
= ATA_FLAG_SATA
| ATA_FLAG_NO_LEGACY
|
218 ATA_FLAG_SRST
| ATA_FLAG_MMIO
|
219 ATA_FLAG_NO_ATAPI
| ATA_FLAG_PIO_POLLING
,
220 .pio_mask
= 0x1f, /* pio0-4 */
221 .mwdma_mask
= 0x07, /* mwdma0-2 */
222 .udma_mask
= 0x7f, /* udma0-6 ; FIXME */
223 .port_ops
= &pdc_20621_ops
,
228 static const struct pci_device_id pdc_sata_pci_tbl
[] = {
229 { PCI_VDEVICE(PROMISE
, 0x6622), board_20621
},
231 { } /* terminate list */
234 static struct pci_driver pdc_sata_pci_driver
= {
236 .id_table
= pdc_sata_pci_tbl
,
237 .probe
= pdc_sata_init_one
,
238 .remove
= ata_pci_remove_one
,
242 static int pdc_port_start(struct ata_port
*ap
)
244 struct device
*dev
= ap
->host
->dev
;
245 struct pdc_port_priv
*pp
;
248 rc
= ata_port_start(ap
);
252 pp
= devm_kzalloc(dev
, sizeof(*pp
), GFP_KERNEL
);
256 pp
->pkt
= dmam_alloc_coherent(dev
, 128, &pp
->pkt_dma
, GFP_KERNEL
);
260 ap
->private_data
= pp
;
265 static void pdc_20621_phy_reset (struct ata_port
*ap
)
268 ap
->cbl
= ATA_CBL_SATA
;
273 static inline void pdc20621_ata_sg(struct ata_taskfile
*tf
, u8
*buf
,
275 unsigned int total_len
)
278 unsigned int dw
= PDC_DIMM_APKT_PRD
>> 2;
279 u32
*buf32
= (u32
*) buf
;
281 /* output ATA packet S/G table */
282 addr
= PDC_20621_DIMM_BASE
+ PDC_20621_DIMM_DATA
+
283 (PDC_DIMM_DATA_STEP
* portno
);
284 VPRINTK("ATA sg addr 0x%x, %d\n", addr
, addr
);
285 buf32
[dw
] = cpu_to_le32(addr
);
286 buf32
[dw
+ 1] = cpu_to_le32(total_len
| ATA_PRD_EOT
);
288 VPRINTK("ATA PSG @ %x == (0x%x, 0x%x)\n",
289 PDC_20621_DIMM_BASE
+
290 (PDC_DIMM_WINDOW_STEP
* portno
) +
292 buf32
[dw
], buf32
[dw
+ 1]);
295 static inline void pdc20621_host_sg(struct ata_taskfile
*tf
, u8
*buf
,
297 unsigned int total_len
)
300 unsigned int dw
= PDC_DIMM_HPKT_PRD
>> 2;
301 u32
*buf32
= (u32
*) buf
;
303 /* output Host DMA packet S/G table */
304 addr
= PDC_20621_DIMM_BASE
+ PDC_20621_DIMM_DATA
+
305 (PDC_DIMM_DATA_STEP
* portno
);
307 buf32
[dw
] = cpu_to_le32(addr
);
308 buf32
[dw
+ 1] = cpu_to_le32(total_len
| ATA_PRD_EOT
);
310 VPRINTK("HOST PSG @ %x == (0x%x, 0x%x)\n",
311 PDC_20621_DIMM_BASE
+
312 (PDC_DIMM_WINDOW_STEP
* portno
) +
314 buf32
[dw
], buf32
[dw
+ 1]);
317 static inline unsigned int pdc20621_ata_pkt(struct ata_taskfile
*tf
,
318 unsigned int devno
, u8
*buf
,
322 u32
*buf32
= (u32
*) buf
;
325 unsigned int dimm_sg
= PDC_20621_DIMM_BASE
+
326 (PDC_DIMM_WINDOW_STEP
* portno
) +
328 VPRINTK("ENTER, dimm_sg == 0x%x, %d\n", dimm_sg
, dimm_sg
);
330 i
= PDC_DIMM_ATA_PKT
;
335 if ((tf
->protocol
== ATA_PROT_DMA
) && (!(tf
->flags
& ATA_TFLAG_WRITE
)))
336 buf
[i
++] = PDC_PKT_READ
;
337 else if (tf
->protocol
== ATA_PROT_NODATA
)
338 buf
[i
++] = PDC_PKT_NODATA
;
341 buf
[i
++] = 0; /* reserved */
342 buf
[i
++] = portno
+ 1; /* seq. id */
343 buf
[i
++] = 0xff; /* delay seq. id */
345 /* dimm dma S/G, and next-pkt */
347 if (tf
->protocol
== ATA_PROT_NODATA
)
350 buf32
[dw
] = cpu_to_le32(dimm_sg
);
355 dev_reg
= ATA_DEVICE_OBS
;
357 dev_reg
= ATA_DEVICE_OBS
| ATA_DEV1
;
360 buf
[i
++] = (1 << 5) | PDC_PKT_CLEAR_BSY
| ATA_REG_DEVICE
;
363 /* device control register */
364 buf
[i
++] = (1 << 5) | PDC_REG_DEVCTL
;
370 static inline void pdc20621_host_pkt(struct ata_taskfile
*tf
, u8
*buf
,
374 u32 tmp
, *buf32
= (u32
*) buf
;
376 unsigned int host_sg
= PDC_20621_DIMM_BASE
+
377 (PDC_DIMM_WINDOW_STEP
* portno
) +
379 unsigned int dimm_sg
= PDC_20621_DIMM_BASE
+
380 (PDC_DIMM_WINDOW_STEP
* portno
) +
382 VPRINTK("ENTER, dimm_sg == 0x%x, %d\n", dimm_sg
, dimm_sg
);
383 VPRINTK("host_sg == 0x%x, %d\n", host_sg
, host_sg
);
385 dw
= PDC_DIMM_HOST_PKT
>> 2;
388 * Set up Host DMA packet
390 if ((tf
->protocol
== ATA_PROT_DMA
) && (!(tf
->flags
& ATA_TFLAG_WRITE
)))
394 tmp
|= ((portno
+ 1 + 4) << 16); /* seq. id */
395 tmp
|= (0xff << 24); /* delay seq. id */
396 buf32
[dw
+ 0] = cpu_to_le32(tmp
);
397 buf32
[dw
+ 1] = cpu_to_le32(host_sg
);
398 buf32
[dw
+ 2] = cpu_to_le32(dimm_sg
);
401 VPRINTK("HOST PKT @ %x == (0x%x 0x%x 0x%x 0x%x)\n",
402 PDC_20621_DIMM_BASE
+ (PDC_DIMM_WINDOW_STEP
* portno
) +
410 static void pdc20621_dma_prep(struct ata_queued_cmd
*qc
)
412 struct scatterlist
*sg
;
413 struct ata_port
*ap
= qc
->ap
;
414 struct pdc_port_priv
*pp
= ap
->private_data
;
415 void __iomem
*mmio
= ap
->host
->iomap
[PDC_MMIO_BAR
];
416 void __iomem
*dimm_mmio
= ap
->host
->iomap
[PDC_DIMM_BAR
];
417 unsigned int portno
= ap
->port_no
;
418 unsigned int i
, idx
, total_len
= 0, sgt_len
;
419 u32
*buf
= (u32
*) &pp
->dimm_buf
[PDC_DIMM_HEADER_SZ
];
421 WARN_ON(!(qc
->flags
& ATA_QCFLAG_DMAMAP
));
423 VPRINTK("ata%u: ENTER\n", ap
->id
);
425 /* hard-code chip #0 */
426 mmio
+= PDC_CHIP0_OFS
;
432 ata_for_each_sg(sg
, qc
) {
433 buf
[idx
++] = cpu_to_le32(sg_dma_address(sg
));
434 buf
[idx
++] = cpu_to_le32(sg_dma_len(sg
));
435 total_len
+= sg_dma_len(sg
);
437 buf
[idx
- 1] |= cpu_to_le32(ATA_PRD_EOT
);
441 * Build ATA, host DMA packets
443 pdc20621_host_sg(&qc
->tf
, &pp
->dimm_buf
[0], portno
, total_len
);
444 pdc20621_host_pkt(&qc
->tf
, &pp
->dimm_buf
[0], portno
);
446 pdc20621_ata_sg(&qc
->tf
, &pp
->dimm_buf
[0], portno
, total_len
);
447 i
= pdc20621_ata_pkt(&qc
->tf
, qc
->dev
->devno
, &pp
->dimm_buf
[0], portno
);
449 if (qc
->tf
.flags
& ATA_TFLAG_LBA48
)
450 i
= pdc_prep_lba48(&qc
->tf
, &pp
->dimm_buf
[0], i
);
452 i
= pdc_prep_lba28(&qc
->tf
, &pp
->dimm_buf
[0], i
);
454 pdc_pkt_footer(&qc
->tf
, &pp
->dimm_buf
[0], i
);
456 /* copy three S/G tables and two packets to DIMM MMIO window */
457 memcpy_toio(dimm_mmio
+ (portno
* PDC_DIMM_WINDOW_STEP
),
458 &pp
->dimm_buf
, PDC_DIMM_HEADER_SZ
);
459 memcpy_toio(dimm_mmio
+ (portno
* PDC_DIMM_WINDOW_STEP
) +
461 &pp
->dimm_buf
[PDC_DIMM_HEADER_SZ
], sgt_len
);
463 /* force host FIFO dump */
464 writel(0x00000001, mmio
+ PDC_20621_GENERAL_CTL
);
466 readl(dimm_mmio
); /* MMIO PCI posting flush */
468 VPRINTK("ata pkt buf ofs %u, prd size %u, mmio copied\n", i
, sgt_len
);
471 static void pdc20621_nodata_prep(struct ata_queued_cmd
*qc
)
473 struct ata_port
*ap
= qc
->ap
;
474 struct pdc_port_priv
*pp
= ap
->private_data
;
475 void __iomem
*mmio
= ap
->host
->iomap
[PDC_MMIO_BAR
];
476 void __iomem
*dimm_mmio
= ap
->host
->iomap
[PDC_DIMM_BAR
];
477 unsigned int portno
= ap
->port_no
;
480 VPRINTK("ata%u: ENTER\n", ap
->id
);
482 /* hard-code chip #0 */
483 mmio
+= PDC_CHIP0_OFS
;
485 i
= pdc20621_ata_pkt(&qc
->tf
, qc
->dev
->devno
, &pp
->dimm_buf
[0], portno
);
487 if (qc
->tf
.flags
& ATA_TFLAG_LBA48
)
488 i
= pdc_prep_lba48(&qc
->tf
, &pp
->dimm_buf
[0], i
);
490 i
= pdc_prep_lba28(&qc
->tf
, &pp
->dimm_buf
[0], i
);
492 pdc_pkt_footer(&qc
->tf
, &pp
->dimm_buf
[0], i
);
494 /* copy three S/G tables and two packets to DIMM MMIO window */
495 memcpy_toio(dimm_mmio
+ (portno
* PDC_DIMM_WINDOW_STEP
),
496 &pp
->dimm_buf
, PDC_DIMM_HEADER_SZ
);
498 /* force host FIFO dump */
499 writel(0x00000001, mmio
+ PDC_20621_GENERAL_CTL
);
501 readl(dimm_mmio
); /* MMIO PCI posting flush */
503 VPRINTK("ata pkt buf ofs %u, mmio copied\n", i
);
506 static void pdc20621_qc_prep(struct ata_queued_cmd
*qc
)
508 switch (qc
->tf
.protocol
) {
510 pdc20621_dma_prep(qc
);
512 case ATA_PROT_NODATA
:
513 pdc20621_nodata_prep(qc
);
520 static void __pdc20621_push_hdma(struct ata_queued_cmd
*qc
,
524 struct ata_port
*ap
= qc
->ap
;
525 struct ata_host
*host
= ap
->host
;
526 void __iomem
*mmio
= host
->iomap
[PDC_MMIO_BAR
];
528 /* hard-code chip #0 */
529 mmio
+= PDC_CHIP0_OFS
;
531 writel(0x00000001, mmio
+ PDC_20621_SEQCTL
+ (seq
* 4));
532 readl(mmio
+ PDC_20621_SEQCTL
+ (seq
* 4)); /* flush */
534 writel(pkt_ofs
, mmio
+ PDC_HDMA_PKT_SUBMIT
);
535 readl(mmio
+ PDC_HDMA_PKT_SUBMIT
); /* flush */
538 static void pdc20621_push_hdma(struct ata_queued_cmd
*qc
,
542 struct ata_port
*ap
= qc
->ap
;
543 struct pdc_host_priv
*pp
= ap
->host
->private_data
;
544 unsigned int idx
= pp
->hdma_prod
& PDC_HDMA_Q_MASK
;
546 if (!pp
->doing_hdma
) {
547 __pdc20621_push_hdma(qc
, seq
, pkt_ofs
);
552 pp
->hdma
[idx
].qc
= qc
;
553 pp
->hdma
[idx
].seq
= seq
;
554 pp
->hdma
[idx
].pkt_ofs
= pkt_ofs
;
558 static void pdc20621_pop_hdma(struct ata_queued_cmd
*qc
)
560 struct ata_port
*ap
= qc
->ap
;
561 struct pdc_host_priv
*pp
= ap
->host
->private_data
;
562 unsigned int idx
= pp
->hdma_cons
& PDC_HDMA_Q_MASK
;
564 /* if nothing on queue, we're done */
565 if (pp
->hdma_prod
== pp
->hdma_cons
) {
570 __pdc20621_push_hdma(pp
->hdma
[idx
].qc
, pp
->hdma
[idx
].seq
,
571 pp
->hdma
[idx
].pkt_ofs
);
575 #ifdef ATA_VERBOSE_DEBUG
576 static void pdc20621_dump_hdma(struct ata_queued_cmd
*qc
)
578 struct ata_port
*ap
= qc
->ap
;
579 unsigned int port_no
= ap
->port_no
;
580 void __iomem
*dimm_mmio
= ap
->host
->iomap
[PDC_DIMM_BAR
];
582 dimm_mmio
+= (port_no
* PDC_DIMM_WINDOW_STEP
);
583 dimm_mmio
+= PDC_DIMM_HOST_PKT
;
585 printk(KERN_ERR
"HDMA[0] == 0x%08X\n", readl(dimm_mmio
));
586 printk(KERN_ERR
"HDMA[1] == 0x%08X\n", readl(dimm_mmio
+ 4));
587 printk(KERN_ERR
"HDMA[2] == 0x%08X\n", readl(dimm_mmio
+ 8));
588 printk(KERN_ERR
"HDMA[3] == 0x%08X\n", readl(dimm_mmio
+ 12));
591 static inline void pdc20621_dump_hdma(struct ata_queued_cmd
*qc
) { }
592 #endif /* ATA_VERBOSE_DEBUG */
594 static void pdc20621_packet_start(struct ata_queued_cmd
*qc
)
596 struct ata_port
*ap
= qc
->ap
;
597 struct ata_host
*host
= ap
->host
;
598 unsigned int port_no
= ap
->port_no
;
599 void __iomem
*mmio
= host
->iomap
[PDC_MMIO_BAR
];
600 unsigned int rw
= (qc
->tf
.flags
& ATA_TFLAG_WRITE
);
601 u8 seq
= (u8
) (port_no
+ 1);
602 unsigned int port_ofs
;
604 /* hard-code chip #0 */
605 mmio
+= PDC_CHIP0_OFS
;
607 VPRINTK("ata%u: ENTER\n", ap
->id
);
609 wmb(); /* flush PRD, pkt writes */
611 port_ofs
= PDC_20621_DIMM_BASE
+ (PDC_DIMM_WINDOW_STEP
* port_no
);
613 /* if writing, we (1) DMA to DIMM, then (2) do ATA command */
614 if (rw
&& qc
->tf
.protocol
== ATA_PROT_DMA
) {
617 pdc20621_dump_hdma(qc
);
618 pdc20621_push_hdma(qc
, seq
, port_ofs
+ PDC_DIMM_HOST_PKT
);
619 VPRINTK("queued ofs 0x%x (%u), seq %u\n",
620 port_ofs
+ PDC_DIMM_HOST_PKT
,
621 port_ofs
+ PDC_DIMM_HOST_PKT
,
624 writel(0x00000001, mmio
+ PDC_20621_SEQCTL
+ (seq
* 4));
625 readl(mmio
+ PDC_20621_SEQCTL
+ (seq
* 4)); /* flush */
627 writel(port_ofs
+ PDC_DIMM_ATA_PKT
,
628 ap
->ioaddr
.cmd_addr
+ PDC_PKT_SUBMIT
);
629 readl(ap
->ioaddr
.cmd_addr
+ PDC_PKT_SUBMIT
);
630 VPRINTK("submitted ofs 0x%x (%u), seq %u\n",
631 port_ofs
+ PDC_DIMM_ATA_PKT
,
632 port_ofs
+ PDC_DIMM_ATA_PKT
,
637 static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd
*qc
)
639 switch (qc
->tf
.protocol
) {
641 case ATA_PROT_NODATA
:
642 pdc20621_packet_start(qc
);
645 case ATA_PROT_ATAPI_DMA
:
653 return ata_qc_issue_prot(qc
);
656 static inline unsigned int pdc20621_host_intr( struct ata_port
*ap
,
657 struct ata_queued_cmd
*qc
,
658 unsigned int doing_hdma
,
661 unsigned int port_no
= ap
->port_no
;
662 unsigned int port_ofs
=
663 PDC_20621_DIMM_BASE
+ (PDC_DIMM_WINDOW_STEP
* port_no
);
665 unsigned int handled
= 0;
669 if ((qc
->tf
.protocol
== ATA_PROT_DMA
) && /* read */
670 (!(qc
->tf
.flags
& ATA_TFLAG_WRITE
))) {
672 /* step two - DMA from DIMM to host */
674 VPRINTK("ata%u: read hdma, 0x%x 0x%x\n", ap
->id
,
675 readl(mmio
+ 0x104), readl(mmio
+ PDC_HDMA_CTLSTAT
));
676 /* get drive status; clear intr; complete txn */
677 qc
->err_mask
|= ac_err_mask(ata_wait_idle(ap
));
679 pdc20621_pop_hdma(qc
);
682 /* step one - exec ATA command */
684 u8 seq
= (u8
) (port_no
+ 1 + 4);
685 VPRINTK("ata%u: read ata, 0x%x 0x%x\n", ap
->id
,
686 readl(mmio
+ 0x104), readl(mmio
+ PDC_HDMA_CTLSTAT
));
688 /* submit hdma pkt */
689 pdc20621_dump_hdma(qc
);
690 pdc20621_push_hdma(qc
, seq
,
691 port_ofs
+ PDC_DIMM_HOST_PKT
);
695 } else if (qc
->tf
.protocol
== ATA_PROT_DMA
) { /* write */
697 /* step one - DMA from host to DIMM */
699 u8 seq
= (u8
) (port_no
+ 1);
700 VPRINTK("ata%u: write hdma, 0x%x 0x%x\n", ap
->id
,
701 readl(mmio
+ 0x104), readl(mmio
+ PDC_HDMA_CTLSTAT
));
704 writel(0x00000001, mmio
+ PDC_20621_SEQCTL
+ (seq
* 4));
705 readl(mmio
+ PDC_20621_SEQCTL
+ (seq
* 4));
706 writel(port_ofs
+ PDC_DIMM_ATA_PKT
,
707 ap
->ioaddr
.cmd_addr
+ PDC_PKT_SUBMIT
);
708 readl(ap
->ioaddr
.cmd_addr
+ PDC_PKT_SUBMIT
);
711 /* step two - execute ATA command */
713 VPRINTK("ata%u: write ata, 0x%x 0x%x\n", ap
->id
,
714 readl(mmio
+ 0x104), readl(mmio
+ PDC_HDMA_CTLSTAT
));
715 /* get drive status; clear intr; complete txn */
716 qc
->err_mask
|= ac_err_mask(ata_wait_idle(ap
));
718 pdc20621_pop_hdma(qc
);
722 /* command completion, but no data xfer */
723 } else if (qc
->tf
.protocol
== ATA_PROT_NODATA
) {
725 status
= ata_busy_wait(ap
, ATA_BUSY
| ATA_DRQ
, 1000);
726 DPRINTK("BUS_NODATA (drv_stat 0x%X)\n", status
);
727 qc
->err_mask
|= ac_err_mask(status
);
732 ap
->stats
.idle_irq
++;
738 static void pdc20621_irq_clear(struct ata_port
*ap
)
740 struct ata_host
*host
= ap
->host
;
741 void __iomem
*mmio
= host
->iomap
[PDC_MMIO_BAR
];
743 mmio
+= PDC_CHIP0_OFS
;
745 readl(mmio
+ PDC_20621_SEQMASK
);
748 static irqreturn_t
pdc20621_interrupt (int irq
, void *dev_instance
)
750 struct ata_host
*host
= dev_instance
;
753 unsigned int i
, tmp
, port_no
;
754 unsigned int handled
= 0;
755 void __iomem
*mmio_base
;
759 if (!host
|| !host
->iomap
[PDC_MMIO_BAR
]) {
760 VPRINTK("QUICK EXIT\n");
764 mmio_base
= host
->iomap
[PDC_MMIO_BAR
];
766 /* reading should also clear interrupts */
767 mmio_base
+= PDC_CHIP0_OFS
;
768 mask
= readl(mmio_base
+ PDC_20621_SEQMASK
);
769 VPRINTK("mask == 0x%x\n", mask
);
771 if (mask
== 0xffffffff) {
772 VPRINTK("QUICK EXIT 2\n");
775 mask
&= 0xffff; /* only 16 tags possible */
777 VPRINTK("QUICK EXIT 3\n");
781 spin_lock(&host
->lock
);
783 for (i
= 1; i
< 9; i
++) {
787 if (port_no
>= host
->n_ports
)
790 ap
= host
->ports
[port_no
];
791 tmp
= mask
& (1 << i
);
792 VPRINTK("seq %u, port_no %u, ap %p, tmp %x\n", i
, port_no
, ap
, tmp
);
794 !(ap
->flags
& ATA_FLAG_DISABLED
)) {
795 struct ata_queued_cmd
*qc
;
797 qc
= ata_qc_from_tag(ap
, ap
->active_tag
);
798 if (qc
&& (!(qc
->tf
.flags
& ATA_TFLAG_POLLING
)))
799 handled
+= pdc20621_host_intr(ap
, qc
, (i
> 4),
804 spin_unlock(&host
->lock
);
806 VPRINTK("mask == 0x%x\n", mask
);
810 return IRQ_RETVAL(handled
);
813 static void pdc_eng_timeout(struct ata_port
*ap
)
816 struct ata_host
*host
= ap
->host
;
817 struct ata_queued_cmd
*qc
;
822 spin_lock_irqsave(&host
->lock
, flags
);
824 qc
= ata_qc_from_tag(ap
, ap
->active_tag
);
826 switch (qc
->tf
.protocol
) {
828 case ATA_PROT_NODATA
:
829 ata_port_printk(ap
, KERN_ERR
, "command timeout\n");
830 qc
->err_mask
|= __ac_err_mask(ata_wait_idle(ap
));
834 drv_stat
= ata_busy_wait(ap
, ATA_BUSY
| ATA_DRQ
, 1000);
836 ata_port_printk(ap
, KERN_ERR
,
837 "unknown timeout, cmd 0x%x stat 0x%x\n",
838 qc
->tf
.command
, drv_stat
);
840 qc
->err_mask
|= ac_err_mask(drv_stat
);
844 spin_unlock_irqrestore(&host
->lock
, flags
);
845 ata_eh_qc_complete(qc
);
849 static void pdc_tf_load_mmio(struct ata_port
*ap
, const struct ata_taskfile
*tf
)
851 WARN_ON (tf
->protocol
== ATA_PROT_DMA
||
852 tf
->protocol
== ATA_PROT_NODATA
);
857 static void pdc_exec_command_mmio(struct ata_port
*ap
, const struct ata_taskfile
*tf
)
859 WARN_ON (tf
->protocol
== ATA_PROT_DMA
||
860 tf
->protocol
== ATA_PROT_NODATA
);
861 ata_exec_command(ap
, tf
);
865 static void pdc_sata_setup_port(struct ata_ioports
*port
, void __iomem
*base
)
867 port
->cmd_addr
= base
;
868 port
->data_addr
= base
;
870 port
->error_addr
= base
+ 0x4;
871 port
->nsect_addr
= base
+ 0x8;
872 port
->lbal_addr
= base
+ 0xc;
873 port
->lbam_addr
= base
+ 0x10;
874 port
->lbah_addr
= base
+ 0x14;
875 port
->device_addr
= base
+ 0x18;
877 port
->status_addr
= base
+ 0x1c;
878 port
->altstatus_addr
=
879 port
->ctl_addr
= base
+ 0x38;
883 #ifdef ATA_VERBOSE_DEBUG
884 static void pdc20621_get_from_dimm(struct ata_probe_ent
*pe
, void *psource
,
885 u32 offset
, u32 size
)
891 void __iomem
*mmio
= pe
->iomap
[PDC_MMIO_BAR
];
892 void __iomem
*dimm_mmio
= pe
->iomap
[PDC_DIMM_BAR
];
894 /* hard-code chip #0 */
895 mmio
+= PDC_CHIP0_OFS
;
898 window_size
= 0x2000 * 4; /* 32K byte uchar size */
899 idx
= (u16
) (offset
/ window_size
);
901 writel(0x01, mmio
+ PDC_GENERAL_CTLR
);
902 readl(mmio
+ PDC_GENERAL_CTLR
);
903 writel(((idx
) << page_mask
), mmio
+ PDC_DIMM_WINDOW_CTLR
);
904 readl(mmio
+ PDC_DIMM_WINDOW_CTLR
);
906 offset
-= (idx
* window_size
);
908 dist
= ((long) (window_size
- (offset
+ size
))) >= 0 ? size
:
909 (long) (window_size
- offset
);
910 memcpy_fromio((char *) psource
, (char *) (dimm_mmio
+ offset
/ 4),
915 for (; (long) size
>= (long) window_size
;) {
916 writel(0x01, mmio
+ PDC_GENERAL_CTLR
);
917 readl(mmio
+ PDC_GENERAL_CTLR
);
918 writel(((idx
) << page_mask
), mmio
+ PDC_DIMM_WINDOW_CTLR
);
919 readl(mmio
+ PDC_DIMM_WINDOW_CTLR
);
920 memcpy_fromio((char *) psource
, (char *) (dimm_mmio
),
922 psource
+= window_size
;
928 writel(0x01, mmio
+ PDC_GENERAL_CTLR
);
929 readl(mmio
+ PDC_GENERAL_CTLR
);
930 writel(((idx
) << page_mask
), mmio
+ PDC_DIMM_WINDOW_CTLR
);
931 readl(mmio
+ PDC_DIMM_WINDOW_CTLR
);
932 memcpy_fromio((char *) psource
, (char *) (dimm_mmio
),
939 static void pdc20621_put_to_dimm(struct ata_probe_ent
*pe
, void *psource
,
940 u32 offset
, u32 size
)
946 void __iomem
*mmio
= pe
->iomap
[PDC_MMIO_BAR
];
947 void __iomem
*dimm_mmio
= pe
->iomap
[PDC_DIMM_BAR
];
949 /* hard-code chip #0 */
950 mmio
+= PDC_CHIP0_OFS
;
953 window_size
= 0x2000 * 4; /* 32K byte uchar size */
954 idx
= (u16
) (offset
/ window_size
);
956 writel(((idx
) << page_mask
), mmio
+ PDC_DIMM_WINDOW_CTLR
);
957 readl(mmio
+ PDC_DIMM_WINDOW_CTLR
);
958 offset
-= (idx
* window_size
);
960 dist
= ((long)(s32
)(window_size
- (offset
+ size
))) >= 0 ? size
:
961 (long) (window_size
- offset
);
962 memcpy_toio(dimm_mmio
+ offset
/ 4, psource
, dist
);
963 writel(0x01, mmio
+ PDC_GENERAL_CTLR
);
964 readl(mmio
+ PDC_GENERAL_CTLR
);
968 for (; (long) size
>= (long) window_size
;) {
969 writel(((idx
) << page_mask
), mmio
+ PDC_DIMM_WINDOW_CTLR
);
970 readl(mmio
+ PDC_DIMM_WINDOW_CTLR
);
971 memcpy_toio(dimm_mmio
, psource
, window_size
/ 4);
972 writel(0x01, mmio
+ PDC_GENERAL_CTLR
);
973 readl(mmio
+ PDC_GENERAL_CTLR
);
974 psource
+= window_size
;
980 writel(((idx
) << page_mask
), mmio
+ PDC_DIMM_WINDOW_CTLR
);
981 readl(mmio
+ PDC_DIMM_WINDOW_CTLR
);
982 memcpy_toio(dimm_mmio
, psource
, size
/ 4);
983 writel(0x01, mmio
+ PDC_GENERAL_CTLR
);
984 readl(mmio
+ PDC_GENERAL_CTLR
);
989 static unsigned int pdc20621_i2c_read(struct ata_probe_ent
*pe
, u32 device
,
990 u32 subaddr
, u32
*pdata
)
992 void __iomem
*mmio
= pe
->iomap
[PDC_MMIO_BAR
];
997 /* hard-code chip #0 */
998 mmio
+= PDC_CHIP0_OFS
;
1000 i2creg
|= device
<< 24;
1001 i2creg
|= subaddr
<< 16;
1003 /* Set the device and subaddress */
1004 writel(i2creg
, mmio
+ PDC_I2C_ADDR_DATA_OFFSET
);
1005 readl(mmio
+ PDC_I2C_ADDR_DATA_OFFSET
);
1007 /* Write Control to perform read operation, mask int */
1008 writel(PDC_I2C_READ
| PDC_I2C_START
| PDC_I2C_MASK_INT
,
1009 mmio
+ PDC_I2C_CONTROL_OFFSET
);
1011 for (count
= 0; count
<= 1000; count
++) {
1012 status
= readl(mmio
+ PDC_I2C_CONTROL_OFFSET
);
1013 if (status
& PDC_I2C_COMPLETE
) {
1014 status
= readl(mmio
+ PDC_I2C_ADDR_DATA_OFFSET
);
1016 } else if (count
== 1000)
1020 *pdata
= (status
>> 8) & 0x000000ff;
1025 static int pdc20621_detect_dimm(struct ata_probe_ent
*pe
)
1028 if (pdc20621_i2c_read(pe
, PDC_DIMM0_SPD_DEV_ADDRESS
,
1029 PDC_DIMM_SPD_SYSTEM_FREQ
, &data
)) {
1035 if (pdc20621_i2c_read(pe
, PDC_DIMM0_SPD_DEV_ADDRESS
, 9, &data
)) {
1045 static int pdc20621_prog_dimm0(struct ata_probe_ent
*pe
)
1051 void __iomem
*mmio
= pe
->iomap
[PDC_MMIO_BAR
];
1052 static const struct {
1055 } pdc_i2c_read_data
[] = {
1056 { PDC_DIMM_SPD_TYPE
, 11 },
1057 { PDC_DIMM_SPD_FRESH_RATE
, 12 },
1058 { PDC_DIMM_SPD_COLUMN_NUM
, 4 },
1059 { PDC_DIMM_SPD_ATTRIBUTE
, 21 },
1060 { PDC_DIMM_SPD_ROW_NUM
, 3 },
1061 { PDC_DIMM_SPD_BANK_NUM
, 17 },
1062 { PDC_DIMM_SPD_MODULE_ROW
, 5 },
1063 { PDC_DIMM_SPD_ROW_PRE_CHARGE
, 27 },
1064 { PDC_DIMM_SPD_ROW_ACTIVE_DELAY
, 28 },
1065 { PDC_DIMM_SPD_RAS_CAS_DELAY
, 29 },
1066 { PDC_DIMM_SPD_ACTIVE_PRECHARGE
, 30 },
1067 { PDC_DIMM_SPD_CAS_LATENCY
, 18 },
1070 /* hard-code chip #0 */
1071 mmio
+= PDC_CHIP0_OFS
;
1073 for(i
=0; i
<ARRAY_SIZE(pdc_i2c_read_data
); i
++)
1074 pdc20621_i2c_read(pe
, PDC_DIMM0_SPD_DEV_ADDRESS
,
1075 pdc_i2c_read_data
[i
].reg
,
1076 &spd0
[pdc_i2c_read_data
[i
].ofs
]);
1078 data
|= (spd0
[4] - 8) | ((spd0
[21] != 0) << 3) | ((spd0
[3]-11) << 4);
1079 data
|= ((spd0
[17] / 4) << 6) | ((spd0
[5] / 2) << 7) |
1080 ((((spd0
[27] + 9) / 10) - 1) << 8) ;
1081 data
|= (((((spd0
[29] > spd0
[28])
1082 ? spd0
[29] : spd0
[28]) + 9) / 10) - 1) << 10;
1083 data
|= ((spd0
[30] - spd0
[29] + 9) / 10 - 2) << 12;
1085 if (spd0
[18] & 0x08)
1086 data
|= ((0x03) << 14);
1087 else if (spd0
[18] & 0x04)
1088 data
|= ((0x02) << 14);
1089 else if (spd0
[18] & 0x01)
1090 data
|= ((0x01) << 14);
1095 Calculate the size of bDIMMSize (power of 2) and
1096 merge the DIMM size by program start/end address.
1099 bdimmsize
= spd0
[4] + (spd0
[5] / 2) + spd0
[3] + (spd0
[17] / 2) + 3;
1100 size
= (1 << bdimmsize
) >> 20; /* size = xxx(MB) */
1101 data
|= (((size
/ 16) - 1) << 16);
1104 writel(data
, mmio
+ PDC_DIMM0_CONTROL_OFFSET
);
1105 readl(mmio
+ PDC_DIMM0_CONTROL_OFFSET
);
1110 static unsigned int pdc20621_prog_dimm_global(struct ata_probe_ent
*pe
)
1114 void __iomem
*mmio
= pe
->iomap
[PDC_MMIO_BAR
];
1116 /* hard-code chip #0 */
1117 mmio
+= PDC_CHIP0_OFS
;
1120 Set To Default : DIMM Module Global Control Register (0x022259F1)
1121 DIMM Arbitration Disable (bit 20)
1122 DIMM Data/Control Output Driving Selection (bit12 - bit15)
1123 Refresh Enable (bit 17)
1127 writel(data
, mmio
+ PDC_SDRAM_CONTROL_OFFSET
);
1128 readl(mmio
+ PDC_SDRAM_CONTROL_OFFSET
);
1130 /* Turn on for ECC */
1131 pdc20621_i2c_read(pe
, PDC_DIMM0_SPD_DEV_ADDRESS
,
1132 PDC_DIMM_SPD_TYPE
, &spd0
);
1134 data
|= (0x01 << 16);
1135 writel(data
, mmio
+ PDC_SDRAM_CONTROL_OFFSET
);
1136 readl(mmio
+ PDC_SDRAM_CONTROL_OFFSET
);
1137 printk(KERN_ERR
"Local DIMM ECC Enabled\n");
1140 /* DIMM Initialization Select/Enable (bit 18/19) */
1143 writel(data
, mmio
+ PDC_SDRAM_CONTROL_OFFSET
);
1146 for (i
= 1; i
<= 10; i
++) { /* polling ~5 secs */
1147 data
= readl(mmio
+ PDC_SDRAM_CONTROL_OFFSET
);
1148 if (!(data
& (1<<19))) {
1158 static unsigned int pdc20621_dimm_init(struct ata_probe_ent
*pe
)
1160 int speed
, size
, length
;
1161 u32 addr
,spd0
,pci_status
;
1168 void __iomem
*mmio
= pe
->iomap
[PDC_MMIO_BAR
];
1170 /* hard-code chip #0 */
1171 mmio
+= PDC_CHIP0_OFS
;
1173 /* Initialize PLL based upon PCI Bus Frequency */
1175 /* Initialize Time Period Register */
1176 writel(0xffffffff, mmio
+ PDC_TIME_PERIOD
);
1177 time_period
= readl(mmio
+ PDC_TIME_PERIOD
);
1178 VPRINTK("Time Period Register (0x40): 0x%x\n", time_period
);
1181 writel(0x00001a0, mmio
+ PDC_TIME_CONTROL
);
1182 readl(mmio
+ PDC_TIME_CONTROL
);
1184 /* Wait 3 seconds */
1188 When timer is enabled, counter is decreased every internal
1192 tcount
= readl(mmio
+ PDC_TIME_COUNTER
);
1193 VPRINTK("Time Counter Register (0x44): 0x%x\n", tcount
);
1196 If SX4 is on PCI-X bus, after 3 seconds, the timer counter
1197 register should be >= (0xffffffff - 3x10^8).
1199 if(tcount
>= PCI_X_TCOUNT
) {
1200 ticks
= (time_period
- tcount
);
1201 VPRINTK("Num counters 0x%x (%d)\n", ticks
, ticks
);
1203 clock
= (ticks
/ 300000);
1204 VPRINTK("10 * Internal clk = 0x%x (%d)\n", clock
, clock
);
1206 clock
= (clock
* 33);
1207 VPRINTK("10 * Internal clk * 33 = 0x%x (%d)\n", clock
, clock
);
1209 /* PLL F Param (bit 22:16) */
1210 fparam
= (1400000 / clock
) - 2;
1211 VPRINTK("PLL F Param: 0x%x (%d)\n", fparam
, fparam
);
1213 /* OD param = 0x2 (bit 31:30), R param = 0x5 (bit 29:25) */
1214 pci_status
= (0x8a001824 | (fparam
<< 16));
1216 pci_status
= PCI_PLL_INIT
;
1218 /* Initialize PLL. */
1219 VPRINTK("pci_status: 0x%x\n", pci_status
);
1220 writel(pci_status
, mmio
+ PDC_CTL_STATUS
);
1221 readl(mmio
+ PDC_CTL_STATUS
);
1224 Read SPD of DIMM by I2C interface,
1225 and program the DIMM Module Controller.
1227 if (!(speed
= pdc20621_detect_dimm(pe
))) {
1228 printk(KERN_ERR
"Detect Local DIMM Fail\n");
1229 return 1; /* DIMM error */
1231 VPRINTK("Local DIMM Speed = %d\n", speed
);
1233 /* Programming DIMM0 Module Control Register (index_CID0:80h) */
1234 size
= pdc20621_prog_dimm0(pe
);
1235 VPRINTK("Local DIMM Size = %dMB\n",size
);
1237 /* Programming DIMM Module Global Control Register (index_CID0:88h) */
1238 if (pdc20621_prog_dimm_global(pe
)) {
1239 printk(KERN_ERR
"Programming DIMM Module Global Control Register Fail\n");
1243 #ifdef ATA_VERBOSE_DEBUG
1245 u8 test_parttern1
[40] = {0x55,0xAA,'P','r','o','m','i','s','e',' ',
1246 'N','o','t',' ','Y','e','t',' ','D','e','f','i','n','e','d',' ',
1248 '9','8','0','3','1','6','1','2',0,0};
1249 u8 test_parttern2
[40] = {0};
1251 pdc20621_put_to_dimm(pe
, (void *) test_parttern2
, 0x10040, 40);
1252 pdc20621_put_to_dimm(pe
, (void *) test_parttern2
, 0x40, 40);
1254 pdc20621_put_to_dimm(pe
, (void *) test_parttern1
, 0x10040, 40);
1255 pdc20621_get_from_dimm(pe
, (void *) test_parttern2
, 0x40, 40);
1256 printk(KERN_ERR
"%x, %x, %s\n", test_parttern2
[0],
1257 test_parttern2
[1], &(test_parttern2
[2]));
1258 pdc20621_get_from_dimm(pe
, (void *) test_parttern2
, 0x10040,
1260 printk(KERN_ERR
"%x, %x, %s\n", test_parttern2
[0],
1261 test_parttern2
[1], &(test_parttern2
[2]));
1263 pdc20621_put_to_dimm(pe
, (void *) test_parttern1
, 0x40, 40);
1264 pdc20621_get_from_dimm(pe
, (void *) test_parttern2
, 0x40, 40);
1265 printk(KERN_ERR
"%x, %x, %s\n", test_parttern2
[0],
1266 test_parttern2
[1], &(test_parttern2
[2]));
1270 /* ECC initiliazation. */
1272 pdc20621_i2c_read(pe
, PDC_DIMM0_SPD_DEV_ADDRESS
,
1273 PDC_DIMM_SPD_TYPE
, &spd0
);
1275 VPRINTK("Start ECC initialization\n");
1277 length
= size
* 1024 * 1024;
1278 while (addr
< length
) {
1279 pdc20621_put_to_dimm(pe
, (void *) &tmp
, addr
,
1281 addr
+= sizeof(u32
);
1283 VPRINTK("Finish ECC initialization\n");
1289 static void pdc_20621_init(struct ata_probe_ent
*pe
)
1292 void __iomem
*mmio
= pe
->iomap
[PDC_MMIO_BAR
];
1294 /* hard-code chip #0 */
1295 mmio
+= PDC_CHIP0_OFS
;
1298 * Select page 0x40 for our 32k DIMM window
1300 tmp
= readl(mmio
+ PDC_20621_DIMM_WINDOW
) & 0xffff0000;
1301 tmp
|= PDC_PAGE_WINDOW
; /* page 40h; arbitrarily selected */
1302 writel(tmp
, mmio
+ PDC_20621_DIMM_WINDOW
);
1307 tmp
= readl(mmio
+ PDC_HDMA_CTLSTAT
);
1309 writel(tmp
, mmio
+ PDC_HDMA_CTLSTAT
);
1310 readl(mmio
+ PDC_HDMA_CTLSTAT
); /* flush */
1314 tmp
= readl(mmio
+ PDC_HDMA_CTLSTAT
);
1316 writel(tmp
, mmio
+ PDC_HDMA_CTLSTAT
);
1317 readl(mmio
+ PDC_HDMA_CTLSTAT
); /* flush */
1320 static int pdc_sata_init_one (struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1322 static int printed_version
;
1323 struct ata_probe_ent
*probe_ent
;
1325 struct pdc_host_priv
*hpriv
;
1326 unsigned int board_idx
= (unsigned int) ent
->driver_data
;
1329 if (!printed_version
++)
1330 dev_printk(KERN_DEBUG
, &pdev
->dev
, "version " DRV_VERSION
"\n");
1332 rc
= pcim_enable_device(pdev
);
1336 rc
= pcim_iomap_regions(pdev
, (1 << PDC_MMIO_BAR
) | (1 << PDC_DIMM_BAR
),
1339 pcim_pin_device(pdev
);
1343 rc
= pci_set_dma_mask(pdev
, ATA_DMA_MASK
);
1346 rc
= pci_set_consistent_dma_mask(pdev
, ATA_DMA_MASK
);
1350 probe_ent
= devm_kzalloc(&pdev
->dev
, sizeof(*probe_ent
), GFP_KERNEL
);
1351 if (probe_ent
== NULL
)
1354 probe_ent
->dev
= pci_dev_to_dev(pdev
);
1355 INIT_LIST_HEAD(&probe_ent
->node
);
1357 hpriv
= devm_kzalloc(&pdev
->dev
, sizeof(*hpriv
), GFP_KERNEL
);
1361 probe_ent
->sht
= pdc_port_info
[board_idx
].sht
;
1362 probe_ent
->port_flags
= pdc_port_info
[board_idx
].flags
;
1363 probe_ent
->pio_mask
= pdc_port_info
[board_idx
].pio_mask
;
1364 probe_ent
->mwdma_mask
= pdc_port_info
[board_idx
].mwdma_mask
;
1365 probe_ent
->udma_mask
= pdc_port_info
[board_idx
].udma_mask
;
1366 probe_ent
->port_ops
= pdc_port_info
[board_idx
].port_ops
;
1368 probe_ent
->irq
= pdev
->irq
;
1369 probe_ent
->irq_flags
= IRQF_SHARED
;
1370 probe_ent
->iomap
= pcim_iomap_table(pdev
);
1372 probe_ent
->private_data
= hpriv
;
1373 base
= probe_ent
->iomap
[PDC_MMIO_BAR
] + PDC_CHIP0_OFS
;
1375 probe_ent
->n_ports
= 4;
1376 pdc_sata_setup_port(&probe_ent
->port
[0], base
+ 0x200);
1377 pdc_sata_setup_port(&probe_ent
->port
[1], base
+ 0x280);
1378 pdc_sata_setup_port(&probe_ent
->port
[2], base
+ 0x300);
1379 pdc_sata_setup_port(&probe_ent
->port
[3], base
+ 0x380);
1381 pci_set_master(pdev
);
1383 /* initialize adapter */
1384 /* initialize local dimm */
1385 if (pdc20621_dimm_init(probe_ent
))
1387 pdc_20621_init(probe_ent
);
1389 if (!ata_device_add(probe_ent
))
1392 devm_kfree(&pdev
->dev
, probe_ent
);
1397 static int __init
pdc_sata_init(void)
1399 return pci_register_driver(&pdc_sata_pci_driver
);
1403 static void __exit
pdc_sata_exit(void)
1405 pci_unregister_driver(&pdc_sata_pci_driver
);
1409 MODULE_AUTHOR("Jeff Garzik");
1410 MODULE_DESCRIPTION("Promise SATA low-level driver");
1411 MODULE_LICENSE("GPL");
1412 MODULE_DEVICE_TABLE(pci
, pdc_sata_pci_tbl
);
1413 MODULE_VERSION(DRV_VERSION
);
1415 module_init(pdc_sata_init
);
1416 module_exit(pdc_sata_exit
);