scc_pata.c
来自「linux 内核源代码」· C语言 代码 · 共 788 行 · 第 1/2 页
C
788 行
/* * Support for IDE interfaces on Celleb platform * * (C) Copyright 2006 TOSHIBA CORPORATION * * This code is based on drivers/ide/pci/siimage.c: * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> * Copyright (C) 2003 Red Hat <alan@redhat.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */#include <linux/types.h>#include <linux/module.h>#include <linux/pci.h>#include <linux/delay.h>#include <linux/hdreg.h>#include <linux/ide.h>#include <linux/init.h>#define PCI_DEVICE_ID_TOSHIBA_SCC_ATA 0x01b4#define SCC_PATA_NAME "scc IDE"#define TDVHSEL_MASTER 0x00000001#define TDVHSEL_SLAVE 0x00000004#define MODE_JCUSFEN 0x00000080#define CCKCTRL_ATARESET 0x00040000#define CCKCTRL_BUFCNT 0x00020000#define CCKCTRL_CRST 0x00010000#define CCKCTRL_OCLKEN 0x00000100#define CCKCTRL_ATACLKOEN 0x00000002#define CCKCTRL_LCLKEN 0x00000001#define QCHCD_IOS_SS 0x00000001#define QCHSD_STPDIAG 0x00020000#define INTMASK_MSK 0xD1000012#define INTSTS_SERROR 0x80000000#define INTSTS_PRERR 0x40000000#define INTSTS_RERR 0x10000000#define INTSTS_ICERR 0x01000000#define INTSTS_BMSINT 0x00000010#define INTSTS_BMHE 0x00000008#define INTSTS_IOIRQS 0x00000004#define INTSTS_INTRQ 0x00000002#define INTSTS_ACTEINT 0x00000001#define ECMODE_VALUE 0x01static struct scc_ports { unsigned long ctl, dma; unsigned char hwif_id; /* for removing hwif from system */} scc_ports[MAX_HWIFS];/* PIO transfer mode table *//* JCHST */static unsigned long JCHSTtbl[2][7] = { {0x0E, 0x05, 0x02, 0x03, 0x02, 0x00, 0x00}, /* 100MHz */ {0x13, 0x07, 0x04, 0x04, 0x03, 0x00, 0x00} /* 133MHz */};/* JCHHT */static unsigned long JCHHTtbl[2][7] = { {0x0E, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00}, /* 100MHz */ {0x13, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00} /* 133MHz */};/* JCHCT */static unsigned long JCHCTtbl[2][7] = { {0x1D, 0x1D, 0x1C, 0x0B, 0x06, 0x00, 0x00}, /* 100MHz */ {0x27, 0x26, 0x26, 0x0E, 0x09, 0x00, 0x00} /* 133MHz */};/* DMA transfer mode table *//* JCHDCTM/JCHDCTS */static unsigned long JCHDCTxtbl[2][7] = { {0x0A, 0x06, 0x04, 0x03, 0x01, 0x00, 0x00}, /* 100MHz */ {0x0E, 0x09, 0x06, 0x04, 0x02, 0x01, 0x00} /* 133MHz */};/* JCSTWTM/JCSTWTS */static unsigned long JCSTWTxtbl[2][7] = { {0x06, 0x04, 0x03, 0x02, 0x02, 0x02, 0x00}, /* 100MHz */ {0x09, 0x06, 0x04, 0x02, 0x02, 0x02, 0x02} /* 133MHz */};/* JCTSS */static unsigned long JCTSStbl[2][7] = { {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00}, /* 100MHz */ {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05} /* 133MHz */};/* JCENVT */static unsigned long JCENVTtbl[2][7] = { {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00}, /* 100MHz */ {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02} /* 133MHz */};/* JCACTSELS/JCACTSELM */static unsigned long JCACTSELtbl[2][7] = { {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00}, /* 100MHz */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} /* 133MHz */};static u8 scc_ide_inb(unsigned long port){ u32 data = in_be32((void*)port); return (u8)data;}static u16 scc_ide_inw(unsigned long port){ u32 data = in_be32((void*)port); return (u16)data;}static void scc_ide_insw(unsigned long port, void *addr, u32 count){ u16 *ptr = (u16 *)addr; while (count--) { *ptr++ = le16_to_cpu(in_be32((void*)port)); }}static void scc_ide_insl(unsigned long port, void *addr, u32 count){ u16 *ptr = (u16 *)addr; while (count--) { *ptr++ = le16_to_cpu(in_be32((void*)port)); *ptr++ = le16_to_cpu(in_be32((void*)port)); }}static void scc_ide_outb(u8 addr, unsigned long port){ out_be32((void*)port, addr);}static void scc_ide_outw(u16 addr, unsigned long port){ out_be32((void*)port, addr);}static voidscc_ide_outbsync(ide_drive_t * drive, u8 addr, unsigned long port){ ide_hwif_t *hwif = HWIF(drive); out_be32((void*)port, addr); eieio(); in_be32((void*)(hwif->dma_base + 0x01c)); eieio();}static voidscc_ide_outsw(unsigned long port, void *addr, u32 count){ u16 *ptr = (u16 *)addr; while (count--) { out_be32((void*)port, cpu_to_le16(*ptr++)); }}static voidscc_ide_outsl(unsigned long port, void *addr, u32 count){ u16 *ptr = (u16 *)addr; while (count--) { out_be32((void*)port, cpu_to_le16(*ptr++)); out_be32((void*)port, cpu_to_le16(*ptr++)); }}/** * scc_set_pio_mode - set host controller for PIO mode * @drive: drive * @pio: PIO mode number * * Load the timing settings for this device mode into the * controller. */static void scc_set_pio_mode(ide_drive_t *drive, const u8 pio){ ide_hwif_t *hwif = HWIF(drive); struct scc_ports *ports = ide_get_hwifdata(hwif); unsigned long ctl_base = ports->ctl; unsigned long cckctrl_port = ctl_base + 0xff0; unsigned long piosht_port = ctl_base + 0x000; unsigned long pioct_port = ctl_base + 0x004; unsigned long reg; int offset; reg = in_be32((void __iomem *)cckctrl_port); if (reg & CCKCTRL_ATACLKOEN) { offset = 1; /* 133MHz */ } else { offset = 0; /* 100MHz */ } reg = JCHSTtbl[offset][pio] << 16 | JCHHTtbl[offset][pio]; out_be32((void __iomem *)piosht_port, reg); reg = JCHCTtbl[offset][pio]; out_be32((void __iomem *)pioct_port, reg);}/** * scc_set_dma_mode - set host controller for DMA mode * @drive: drive * @speed: DMA mode * * Load the timing settings for this device mode into the * controller. */static void scc_set_dma_mode(ide_drive_t *drive, const u8 speed){ ide_hwif_t *hwif = HWIF(drive); struct scc_ports *ports = ide_get_hwifdata(hwif); unsigned long ctl_base = ports->ctl; unsigned long cckctrl_port = ctl_base + 0xff0; unsigned long mdmact_port = ctl_base + 0x008; unsigned long mcrcst_port = ctl_base + 0x00c; unsigned long sdmact_port = ctl_base + 0x010; unsigned long scrcst_port = ctl_base + 0x014; unsigned long udenvt_port = ctl_base + 0x018; unsigned long tdvhsel_port = ctl_base + 0x020; int is_slave = (&hwif->drives[1] == drive); int offset, idx; unsigned long reg; unsigned long jcactsel; reg = in_be32((void __iomem *)cckctrl_port); if (reg & CCKCTRL_ATACLKOEN) { offset = 1; /* 133MHz */ } else { offset = 0; /* 100MHz */ } switch (speed) { case XFER_UDMA_6: case XFER_UDMA_5: case XFER_UDMA_4: case XFER_UDMA_3: case XFER_UDMA_2: case XFER_UDMA_1: case XFER_UDMA_0: idx = speed - XFER_UDMA_0; break; default: return; } jcactsel = JCACTSELtbl[offset][idx]; if (is_slave) { out_be32((void __iomem *)sdmact_port, JCHDCTxtbl[offset][idx]); out_be32((void __iomem *)scrcst_port, JCSTWTxtbl[offset][idx]); jcactsel = jcactsel << 2; out_be32((void __iomem *)tdvhsel_port, (in_be32((void __iomem *)tdvhsel_port) & ~TDVHSEL_SLAVE) | jcactsel); } else { out_be32((void __iomem *)mdmact_port, JCHDCTxtbl[offset][idx]); out_be32((void __iomem *)mcrcst_port, JCSTWTxtbl[offset][idx]); out_be32((void __iomem *)tdvhsel_port, (in_be32((void __iomem *)tdvhsel_port) & ~TDVHSEL_MASTER) | jcactsel); } reg = JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx]; out_be32((void __iomem *)udenvt_port, reg);}/** * scc_ide_dma_setup - begin a DMA phase * @drive: target device * * Build an IDE DMA PRD (IDE speak for scatter gather table) * and then set up the DMA transfer registers. * * Returns 0 on success. If a PIO fallback is required then 1 * is returned. */static int scc_dma_setup(ide_drive_t *drive){ ide_hwif_t *hwif = drive->hwif; struct request *rq = HWGROUP(drive)->rq; unsigned int reading; u8 dma_stat; if (rq_data_dir(rq)) reading = 0; else reading = 1 << 3; /* fall back to pio! */ if (!ide_build_dmatable(drive, rq)) { ide_map_sg(drive, rq); return 1; } /* PRD table */ out_be32((void __iomem *)hwif->dma_prdtable, hwif->dmatable_dma); /* specify r/w */ out_be32((void __iomem *)hwif->dma_command, reading); /* read dma_status for INTR & ERROR flags */ dma_stat = in_be32((void __iomem *)hwif->dma_status); /* clear INTR & ERROR flags */ out_be32((void __iomem *)hwif->dma_status, dma_stat|6); drive->waiting_for_dma = 1; return 0;}/** * scc_ide_dma_end - Stop DMA * @drive: IDE drive * * Check and clear INT Status register. * Then call __ide_dma_end(). */static int scc_ide_dma_end(ide_drive_t * drive){ ide_hwif_t *hwif = HWIF(drive); unsigned long intsts_port = hwif->dma_base + 0x014; u32 reg; int dma_stat, data_loss = 0; static int retry = 0; /* errata A308 workaround: Step5 (check data loss) */ /* We don't check non ide_disk because it is limited to UDMA4 */ if (!(in_be32((void __iomem *)IDE_ALTSTATUS_REG) & ERR_STAT) && drive->media == ide_disk && drive->current_speed > XFER_UDMA_4) { reg = in_be32((void __iomem *)intsts_port); if (!(reg & INTSTS_ACTEINT)) { printk(KERN_WARNING "%s: operation failed (transfer data loss)\n", drive->name); data_loss = 1; if (retry++) { struct request *rq = HWGROUP(drive)->rq; int unit; /* ERROR_RESET and drive->crc_count are needed * to reduce DMA transfer mode in retry process. */ if (rq) rq->errors |= ERROR_RESET; for (unit = 0; unit < MAX_DRIVES; unit++) { ide_drive_t *drive = &hwif->drives[unit]; drive->crc_count++; } } } } while (1) { reg = in_be32((void __iomem *)intsts_port); if (reg & INTSTS_SERROR) { printk(KERN_WARNING "%s: SERROR\n", SCC_PATA_NAME); out_be32((void __iomem *)intsts_port, INTSTS_SERROR|INTSTS_BMSINT); out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS); continue; } if (reg & INTSTS_PRERR) { u32 maea0, maec0; unsigned long ctl_base = hwif->config_data; maea0 = in_be32((void __iomem *)(ctl_base + 0xF50)); maec0 = in_be32((void __iomem *)(ctl_base + 0xF54)); printk(KERN_WARNING "%s: PRERR [addr:%x cmd:%x]\n", SCC_PATA_NAME, maea0, maec0); out_be32((void __iomem *)intsts_port, INTSTS_PRERR|INTSTS_BMSINT); out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?