Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *    pata_it8213.c - iTE Tech. Inc.  IT8213 PATA driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *    The IT8213 is a very Intel ICH like device for timing purposes, having
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *    a similar register layout and the same split clock arrangement. Cable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *    detection is different, and it does not have slave channels or all the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *    clutter of later ICH/SATA setups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/libata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/ata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define DRV_NAME	"pata_it8213"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define DRV_VERSION	"0.0.3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *	it8213_pre_reset	-	probe begin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *	@link: link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *	@deadline: deadline jiffies for the operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *	Filter out ports by the enable bits before doing the normal reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *	and probe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static int it8213_pre_reset(struct ata_link *link, unsigned long deadline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	static const struct pci_bits it8213_enable_bits[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		{ 0x41U, 1U, 0x80UL, 0x80UL },	/* port 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	if (!pci_test_config_bits(pdev, &it8213_enable_bits[ap->port_no]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	return ata_sff_prereset(link, deadline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *	it8213_cable_detect	-	check for 40/80 pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *	@ap: Port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *	Perform cable detection for the 8213 ATA interface. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *	different to the PIIX arrangement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static int it8213_cable_detect(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	u8 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	pci_read_config_byte(pdev, 0x42, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (tmp & 2)	/* The initial docs are incorrect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		return ATA_CBL_PATA40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return ATA_CBL_PATA80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *	it8213_set_piomode - Initialize host controller PATA PIO timings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *	@ap: Port whose timings we are configuring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  *	@adev: Device whose timings we are configuring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *	Set PIO mode for device, in host controller PCI config space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  *	None (inherited from caller).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static void it8213_set_piomode (struct ata_port *ap, struct ata_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	unsigned int pio	= adev->pio_mode - XFER_PIO_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct pci_dev *dev	= to_pci_dev(ap->host->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned int master_port = ap->port_no ? 0x42 : 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	u16 master_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int control = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 *	See Intel Document 298600-004 for the timing programing rules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 *	for PIIX/ICH. The 8213 is a clone so very similar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	static const	 /* ISP  RTC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	u8 timings[][2]	= { { 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			    { 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			    { 1, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			    { 2, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			    { 2, 3 }, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (pio > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		control |= 1;	/* TIME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (ata_pio_need_iordy(adev))	/* PIO 3/4 require IORDY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		control |= 2;	/* IE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	/* Bit 2 is set for ATAPI on the IT8213 - reverse of ICH/PIIX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (adev->class != ATA_DEV_ATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		control |= 4;	/* PPE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	pci_read_config_word(dev, master_port, &master_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	/* Set PPE, IE, and TIME as appropriate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (adev->devno == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		master_data &= 0xCCF0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		master_data |= control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		master_data |= (timings[pio][0] << 12) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			(timings[pio][1] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		u8 slave_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		master_data &= 0xFF0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		master_data |= (control << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		/* Slave timing in separate register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		pci_read_config_byte(dev, 0x44, &slave_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		slave_data &= 0xF0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		slave_data |= (timings[pio][0] << 2) | timings[pio][1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		pci_write_config_byte(dev, 0x44, slave_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	master_data |= 0x4000;	/* Ensure SITRE is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	pci_write_config_word(dev, master_port, master_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  *	it8213_set_dmamode - Initialize host controller PATA DMA timings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  *	@ap: Port whose timings we are configuring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  *	@adev: Device to program
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  *	Set UDMA/MWDMA mode for device, in host controller PCI config space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  *	This device is basically an ICH alike.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  *	None (inherited from caller).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static void it8213_set_dmamode (struct ata_port *ap, struct ata_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	struct pci_dev *dev	= to_pci_dev(ap->host->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	u16 master_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	u8 speed		= adev->dma_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	int devid		= adev->devno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	u8 udma_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	static const	 /* ISP  RTC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	u8 timings[][2]	= { { 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			    { 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			    { 1, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			    { 2, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			    { 2, 3 }, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	pci_read_config_word(dev, 0x40, &master_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	pci_read_config_byte(dev, 0x48, &udma_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (speed >= XFER_UDMA_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		unsigned int udma = adev->dma_mode - XFER_UDMA_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		u16 udma_timing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		u16 ideconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		int u_clock, u_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		/* Clocks follow the PIIX style */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		u_speed = min(2 - (udma & 1), udma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (udma > 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			u_clock = 0x1000;	/* 100Mhz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		else if (udma > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			u_clock = 1;		/* 66Mhz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			u_clock = 0;		/* 33Mhz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		udma_enable |= (1 << devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		/* Load the UDMA cycle time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		pci_read_config_word(dev, 0x4A, &udma_timing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		udma_timing &= ~(3 << (4 * devid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		udma_timing |= u_speed << (4 * devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		pci_write_config_word(dev, 0x4A, udma_timing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		/* Load the clock selection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		pci_read_config_word(dev, 0x54, &ideconf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		ideconf &= ~(0x1001 << devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		ideconf |= u_clock << devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		pci_write_config_word(dev, 0x54, ideconf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		 * MWDMA is driven by the PIO timings. We must also enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		 * IORDY unconditionally along with TIME1. PPE has already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		 * been set when the PIO timing was set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		unsigned int mwdma	= adev->dma_mode - XFER_MW_DMA_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		unsigned int control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		u8 slave_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		static const unsigned int needed_pio[3] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		int pio = needed_pio[mwdma] - XFER_PIO_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		control = 3;	/* IORDY|TIME1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		/* If the drive MWDMA is faster than it can do PIO then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		   we must force PIO into PIO0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		if (adev->pio_mode < needed_pio[mwdma])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			/* Enable DMA timing only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			control |= 8;	/* PIO cycles in PIO0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (devid) {	/* Slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			master_data &= 0xFF4F;  /* Mask out IORDY|TIME1|DMAONLY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			master_data |= control << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			pci_read_config_byte(dev, 0x44, &slave_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			slave_data &= 0xF0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			/* Load the matching timing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << (ap->port_no ? 4 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			pci_write_config_byte(dev, 0x44, slave_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		} else { 	/* Master */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			master_data &= 0xCCF4;	/* Mask out IORDY|TIME1|DMAONLY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 						   and master timing bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			master_data |= control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			master_data |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				(timings[pio][0] << 12) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 				(timings[pio][1] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		udma_enable &= ~(1 << devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		pci_write_config_word(dev, 0x40, master_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	pci_write_config_byte(dev, 0x48, udma_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static struct scsi_host_template it8213_sht = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	ATA_BMDMA_SHT(DRV_NAME),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static struct ata_port_operations it8213_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	.inherits		= &ata_bmdma_port_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	.cable_detect		= it8213_cable_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	.set_piomode		= it8213_set_piomode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	.set_dmamode		= it8213_set_dmamode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	.prereset		= it8213_pre_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  *	it8213_init_one - Register 8213 ATA PCI device with kernel services
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  *	@pdev: PCI device to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  *	@ent: Entry in it8213_pci_tbl matching with @pdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  *	Called from kernel PCI layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  *	Inherited from PCI layer (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  *	Zero on success, or -ERRNO value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static int it8213_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	static const struct ata_port_info info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		.flags		= ATA_FLAG_SLAVE_POSS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		.pio_mask	= ATA_PIO4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		.mwdma_mask	= ATA_MWDMA12_ONLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		.udma_mask	= ATA_UDMA6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		.port_ops	= &it8213_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	/* Current IT8213 stuff is single port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	ata_print_version_once(&pdev->dev, DRV_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	return ata_pci_bmdma_init_one(pdev, ppi, &it8213_sht, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static const struct pci_device_id it8213_pci_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	{ PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8213), },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	{ }	/* terminate list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static struct pci_driver it8213_pci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	.name			= DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	.id_table		= it8213_pci_tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	.probe			= it8213_init_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	.remove			= ata_pci_remove_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	.suspend		= ata_pci_device_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	.resume			= ata_pci_device_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) module_pci_driver(it8213_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) MODULE_AUTHOR("Alan Cox");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) MODULE_DESCRIPTION("SCSI low-level driver for the ITE 8213");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) MODULE_DEVICE_TABLE(pci, it8213_pci_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) MODULE_VERSION(DRV_VERSION);