⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pata_scc.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Support for IDE interfaces on Celleb platform * * (C) Copyright 2006 TOSHIBA CORPORATION * * This code is based on drivers/ata/ata_piix.c: *  Copyright 2003-2005 Red Hat Inc *  Copyright 2003-2005 Jeff Garzik *  Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer *  Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> *  Copyright (C) 2003 Red Hat Inc <alan@redhat.com> * * and drivers/ata/ahci.c: *  Copyright 2004-2005 Red Hat, Inc. * * and drivers/ata/libata-core.c: *  Copyright 2003-2004 Red Hat, Inc.  All rights reserved. *  Copyright 2003-2004 Jeff Garzik * * 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/kernel.h>#include <linux/module.h>#include <linux/pci.h>#include <linux/init.h>#include <linux/blkdev.h>#include <linux/delay.h>#include <linux/device.h>#include <scsi/scsi_host.h>#include <linux/libata.h>#define DRV_NAME		"pata_scc"#define DRV_VERSION		"0.3"#define PCI_DEVICE_ID_TOSHIBA_SCC_ATA		0x01b4/* PCI BARs */#define SCC_CTRL_BAR		0#define SCC_BMID_BAR		1/* offset of CTRL registers */#define SCC_CTL_PIOSHT		0x000#define SCC_CTL_PIOCT		0x004#define SCC_CTL_MDMACT		0x008#define SCC_CTL_MCRCST		0x00C#define SCC_CTL_SDMACT		0x010#define SCC_CTL_SCRCST		0x014#define SCC_CTL_UDENVT		0x018#define SCC_CTL_TDVHSEL 	0x020#define SCC_CTL_MODEREG 	0x024#define SCC_CTL_ECMODE		0xF00#define SCC_CTL_MAEA0		0xF50#define SCC_CTL_MAEC0		0xF54#define SCC_CTL_CCKCTRL 	0xFF0/* offset of BMID registers */#define SCC_DMA_CMD		0x000#define SCC_DMA_STATUS		0x004#define SCC_DMA_TABLE_OFS	0x008#define SCC_DMA_INTMASK 	0x010#define SCC_DMA_INTST		0x014#define SCC_DMA_PTERADD 	0x018#define SCC_REG_CMD_ADDR	0x020#define SCC_REG_DATA		0x000#define SCC_REG_ERR		0x004#define SCC_REG_FEATURE 	0x004#define SCC_REG_NSECT		0x008#define SCC_REG_LBAL		0x00C#define SCC_REG_LBAM		0x010#define SCC_REG_LBAH		0x014#define SCC_REG_DEVICE		0x018#define SCC_REG_STATUS		0x01C#define SCC_REG_CMD		0x01C#define SCC_REG_ALTSTATUS	0x020/* register value */#define TDVHSEL_MASTER		0x00000001#define TDVHSEL_SLAVE		0x00000004#define MODE_JCUSFEN		0x00000080#define ECMODE_VALUE		0x01#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/* PIO transfer mode table *//* JCHST */static const unsigned long JCHSTtbl[2][7] = {	{0x0E, 0x05, 0x02, 0x03, 0x02, 0x00, 0x00},	/* 100MHz */	{0x13, 0x07, 0x04, 0x04, 0x03, 0x00, 0x00}	/* 133MHz */};/* JCHHT */static const unsigned long JCHHTtbl[2][7] = {	{0x0E, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00},	/* 100MHz */	{0x13, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00}	/* 133MHz */};/* JCHCT */static const 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 const unsigned long JCHDCTxtbl[2][7] = {	{0x0A, 0x06, 0x04, 0x03, 0x01, 0x00, 0x00},	/* 100MHz */	{0x0E, 0x09, 0x06, 0x04, 0x02, 0x01, 0x00}	/* 133MHz */};/* JCSTWTM/JCSTWTS  */static const unsigned long JCSTWTxtbl[2][7] = {	{0x06, 0x04, 0x03, 0x02, 0x02, 0x02, 0x00},	/* 100MHz */	{0x09, 0x06, 0x04, 0x02, 0x02, 0x02, 0x02}	/* 133MHz */};/* JCTSS */static const unsigned long JCTSStbl[2][7] = {	{0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00},	/* 100MHz */	{0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05}	/* 133MHz */};/* JCENVT */static const unsigned long JCENVTtbl[2][7] = {	{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00},	/* 100MHz */	{0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}	/* 133MHz */};/* JCACTSELS/JCACTSELM */static const unsigned long JCACTSELtbl[2][7] = {	{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00},	/* 100MHz */	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}	/* 133MHz */};static const struct pci_device_id scc_pci_tbl[] = {	{PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SCC_ATA,	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},	{ }	/* terminate list */};/** *	scc_set_piomode - Initialize host controller PATA PIO timings *	@ap: Port whose timings we are configuring *	@adev: um * *	Set PIO mode for device. * *	LOCKING: *	None (inherited from caller). */static void scc_set_piomode (struct ata_port *ap, struct ata_device *adev){	unsigned int pio = adev->pio_mode - XFER_PIO_0;	void __iomem *ctrl_base = ap->host->iomap[SCC_CTRL_BAR];	void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;	void __iomem *piosht_port = ctrl_base + SCC_CTL_PIOSHT;	void __iomem *pioct_port = ctrl_base + SCC_CTL_PIOCT;	unsigned long reg;	int offset;	reg = in_be32(cckctrl_port);	if (reg & CCKCTRL_ATACLKOEN)		offset = 1;	/* 133MHz */	else		offset = 0;	/* 100MHz */	reg = JCHSTtbl[offset][pio] << 16 | JCHHTtbl[offset][pio];	out_be32(piosht_port, reg);	reg = JCHCTtbl[offset][pio];	out_be32(pioct_port, reg);}/** *	scc_set_dmamode - Initialize host controller PATA DMA timings *	@ap: Port whose timings we are configuring *	@adev: um *	@udma: udma mode, 0 - 6 * *	Set UDMA mode for device. * *	LOCKING: *	None (inherited from caller). */static void scc_set_dmamode (struct ata_port *ap, struct ata_device *adev){	unsigned int udma = adev->dma_mode;	unsigned int is_slave = (adev->devno != 0);	u8 speed = udma;	void __iomem *ctrl_base = ap->host->iomap[SCC_CTRL_BAR];	void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;	void __iomem *mdmact_port = ctrl_base + SCC_CTL_MDMACT;	void __iomem *mcrcst_port = ctrl_base + SCC_CTL_MCRCST;	void __iomem *sdmact_port = ctrl_base + SCC_CTL_SDMACT;	void __iomem *scrcst_port = ctrl_base + SCC_CTL_SCRCST;	void __iomem *udenvt_port = ctrl_base + SCC_CTL_UDENVT;	void __iomem *tdvhsel_port = ctrl_base + SCC_CTL_TDVHSEL;	int offset, idx;	if (in_be32(cckctrl_port) & CCKCTRL_ATACLKOEN)		offset = 1;	/* 133MHz */	else		offset = 0;	/* 100MHz */	if (speed >= XFER_UDMA_0)		idx = speed - XFER_UDMA_0;	else		return;	if (is_slave) {		out_be32(sdmact_port, JCHDCTxtbl[offset][idx]);		out_be32(scrcst_port, JCSTWTxtbl[offset][idx]);		out_be32(tdvhsel_port,			 (in_be32(tdvhsel_port) & ~TDVHSEL_SLAVE) | (JCACTSELtbl[offset][idx] << 2));	} else {		out_be32(mdmact_port, JCHDCTxtbl[offset][idx]);		out_be32(mcrcst_port, JCSTWTxtbl[offset][idx]);		out_be32(tdvhsel_port,			 (in_be32(tdvhsel_port) & ~TDVHSEL_MASTER) | JCACTSELtbl[offset][idx]);	}	out_be32(udenvt_port,		 JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx]);}unsigned long scc_mode_filter(struct ata_device *adev, unsigned long mask){	/* errata A308 workaround: limit ATAPI UDMA mode to UDMA4 */	if (adev->class == ATA_DEV_ATAPI &&	    (mask & (0xE0 << ATA_SHIFT_UDMA))) {		printk(KERN_INFO "%s: limit ATAPI UDMA to UDMA4\n", DRV_NAME);		mask &= ~(0xE0 << ATA_SHIFT_UDMA);	}	return ata_pci_default_filter(adev, mask);}/** *	scc_tf_load - send taskfile registers to host controller *	@ap: Port to which output is sent *	@tf: ATA taskfile register set * *	Note: Original code is ata_tf_load(). */static void scc_tf_load (struct ata_port *ap, const struct ata_taskfile *tf){	struct ata_ioports *ioaddr = &ap->ioaddr;	unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;	if (tf->ctl != ap->last_ctl) {		out_be32(ioaddr->ctl_addr, tf->ctl);		ap->last_ctl = tf->ctl;		ata_wait_idle(ap);	}	if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {		out_be32(ioaddr->feature_addr, tf->hob_feature);		out_be32(ioaddr->nsect_addr, tf->hob_nsect);		out_be32(ioaddr->lbal_addr, tf->hob_lbal);		out_be32(ioaddr->lbam_addr, tf->hob_lbam);		out_be32(ioaddr->lbah_addr, tf->hob_lbah);		VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",			tf->hob_feature,			tf->hob_nsect,			tf->hob_lbal,			tf->hob_lbam,			tf->hob_lbah);	}	if (is_addr) {		out_be32(ioaddr->feature_addr, tf->feature);		out_be32(ioaddr->nsect_addr, tf->nsect);		out_be32(ioaddr->lbal_addr, tf->lbal);		out_be32(ioaddr->lbam_addr, tf->lbam);		out_be32(ioaddr->lbah_addr, tf->lbah);		VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",			tf->feature,			tf->nsect,			tf->lbal,			tf->lbam,			tf->lbah);	}	if (tf->flags & ATA_TFLAG_DEVICE) {		out_be32(ioaddr->device_addr, tf->device);		VPRINTK("device 0x%X\n", tf->device);	}	ata_wait_idle(ap);}/** *	scc_check_status - Read device status reg & clear interrupt *	@ap: port where the device is * *	Note: Original code is ata_check_status(). */static u8 scc_check_status (struct ata_port *ap){	return in_be32(ap->ioaddr.status_addr);}/** *	scc_tf_read - input device's ATA taskfile shadow registers *	@ap: Port from which input is read *	@tf: ATA taskfile register set for storing input * *	Note: Original code is ata_tf_read(). */static void scc_tf_read (struct ata_port *ap, struct ata_taskfile *tf){	struct ata_ioports *ioaddr = &ap->ioaddr;	tf->command = scc_check_status(ap);	tf->feature = in_be32(ioaddr->error_addr);	tf->nsect = in_be32(ioaddr->nsect_addr);	tf->lbal = in_be32(ioaddr->lbal_addr);	tf->lbam = in_be32(ioaddr->lbam_addr);	tf->lbah = in_be32(ioaddr->lbah_addr);	tf->device = in_be32(ioaddr->device_addr);	if (tf->flags & ATA_TFLAG_LBA48) {		out_be32(ioaddr->ctl_addr, tf->ctl | ATA_HOB);		tf->hob_feature = in_be32(ioaddr->error_addr);		tf->hob_nsect = in_be32(ioaddr->nsect_addr);		tf->hob_lbal = in_be32(ioaddr->lbal_addr);		tf->hob_lbam = in_be32(ioaddr->lbam_addr);		tf->hob_lbah = in_be32(ioaddr->lbah_addr);		out_be32(ioaddr->ctl_addr, tf->ctl);		ap->last_ctl = tf->ctl;	}}/** *	scc_exec_command - issue ATA command to host controller *	@ap: port to which command is being issued *	@tf: ATA taskfile register set * *	Note: Original code is ata_exec_command(). */static void scc_exec_command (struct ata_port *ap,			      const struct ata_taskfile *tf){	DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command);	out_be32(ap->ioaddr.command_addr, tf->command);	ata_pause(ap);}/** *	scc_check_altstatus - Read device alternate status reg *	@ap: port where the device is */static u8 scc_check_altstatus (struct ata_port *ap){	return in_be32(ap->ioaddr.altstatus_addr);}/** *	scc_std_dev_select - Select device 0/1 on ATA bus *	@ap: ATA channel to manipulate *	@device: ATA device (numbered from zero) to select *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -