18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (C) 2004 Red Hat 38c2ecf20Sopenharmony_ci * Copyright (C) 2007 Bartlomiej Zolnierkiewicz 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * May be copied or modified under the terms of the GNU General Public License 68c2ecf20Sopenharmony_ci * Based in part on the ITE vendor provided SCSI driver. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Documentation: 98c2ecf20Sopenharmony_ci * Datasheet is freely available, some other documents under NDA. 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The ITE8212 isn't exactly a standard IDE controller. It has two 128c2ecf20Sopenharmony_ci * modes. In pass through mode then it is an IDE controller. In its smart 138c2ecf20Sopenharmony_ci * mode its actually quite a capable hardware raid controller disguised 148c2ecf20Sopenharmony_ci * as an IDE controller. Smart mode only understands DMA read/write and 158c2ecf20Sopenharmony_ci * identify, none of the fancier commands apply. The IT8211 is identical 168c2ecf20Sopenharmony_ci * in other respects but lacks the raid mode. 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * Errata: 198c2ecf20Sopenharmony_ci * o Rev 0x10 also requires master/slave hold the same DMA timings and 208c2ecf20Sopenharmony_ci * cannot do ATAPI MWDMA. 218c2ecf20Sopenharmony_ci * o The identify data for raid volumes lacks CHS info (technically ok) 228c2ecf20Sopenharmony_ci * but also fails to set the LBA28 and other bits. We fix these in 238c2ecf20Sopenharmony_ci * the IDE probe quirk code. 248c2ecf20Sopenharmony_ci * o If you write LBA48 sized I/O's (ie > 256 sector) in smart mode 258c2ecf20Sopenharmony_ci * raid then the controller firmware dies 268c2ecf20Sopenharmony_ci * o Smart mode without RAID doesn't clear all the necessary identify 278c2ecf20Sopenharmony_ci * bits to reduce the command set to the one used 288c2ecf20Sopenharmony_ci * 298c2ecf20Sopenharmony_ci * This has a few impacts on the driver 308c2ecf20Sopenharmony_ci * - In pass through mode we do all the work you would expect 318c2ecf20Sopenharmony_ci * - In smart mode the clocking set up is done by the controller generally 328c2ecf20Sopenharmony_ci * but we must watch the other limits and filter. 338c2ecf20Sopenharmony_ci * - There are a few extra vendor commands that actually talk to the 348c2ecf20Sopenharmony_ci * controller but only work PIO with no IRQ. 358c2ecf20Sopenharmony_ci * 368c2ecf20Sopenharmony_ci * Vendor areas of the identify block in smart mode are used for the 378c2ecf20Sopenharmony_ci * timing and policy set up. Each HDD in raid mode also has a serial 388c2ecf20Sopenharmony_ci * block on the disk. The hardware extra commands are get/set chip status, 398c2ecf20Sopenharmony_ci * rebuild, get rebuild status. 408c2ecf20Sopenharmony_ci * 418c2ecf20Sopenharmony_ci * In Linux the driver supports pass through mode as if the device was 428c2ecf20Sopenharmony_ci * just another IDE controller. If the smart mode is running then 438c2ecf20Sopenharmony_ci * volumes are managed by the controller firmware and each IDE "disk" 448c2ecf20Sopenharmony_ci * is a raid volume. Even more cute - the controller can do automated 458c2ecf20Sopenharmony_ci * hotplug and rebuild. 468c2ecf20Sopenharmony_ci * 478c2ecf20Sopenharmony_ci * The pass through controller itself is a little demented. It has a 488c2ecf20Sopenharmony_ci * flaw that it has a single set of PIO/MWDMA timings per channel so 498c2ecf20Sopenharmony_ci * non UDMA devices restrict each others performance. It also has a 508c2ecf20Sopenharmony_ci * single clock source per channel so mixed UDMA100/133 performance 518c2ecf20Sopenharmony_ci * isn't perfect and we have to pick a clock. Thankfully none of this 528c2ecf20Sopenharmony_ci * matters in smart mode. ATAPI DMA is not currently supported. 538c2ecf20Sopenharmony_ci * 548c2ecf20Sopenharmony_ci * It seems the smart mode is a win for RAID1/RAID10 but otherwise not. 558c2ecf20Sopenharmony_ci * 568c2ecf20Sopenharmony_ci * TODO 578c2ecf20Sopenharmony_ci * - ATAPI UDMA is ok but not MWDMA it seems 588c2ecf20Sopenharmony_ci * - RAID configuration ioctls 598c2ecf20Sopenharmony_ci * - Move to libata once it grows up 608c2ecf20Sopenharmony_ci */ 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#include <linux/types.h> 638c2ecf20Sopenharmony_ci#include <linux/module.h> 648c2ecf20Sopenharmony_ci#include <linux/slab.h> 658c2ecf20Sopenharmony_ci#include <linux/pci.h> 668c2ecf20Sopenharmony_ci#include <linux/ide.h> 678c2ecf20Sopenharmony_ci#include <linux/init.h> 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#define DRV_NAME "it821x" 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define QUIRK_VORTEX86 1 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistruct it821x_dev 748c2ecf20Sopenharmony_ci{ 758c2ecf20Sopenharmony_ci unsigned int smart:1, /* Are we in smart raid mode */ 768c2ecf20Sopenharmony_ci timing10:1; /* Rev 0x10 */ 778c2ecf20Sopenharmony_ci u8 clock_mode; /* 0, ATA_50 or ATA_66 */ 788c2ecf20Sopenharmony_ci u8 want[2][2]; /* Mode/Pri log for master slave */ 798c2ecf20Sopenharmony_ci /* We need these for switching the clock when DMA goes on/off 808c2ecf20Sopenharmony_ci The high byte is the 66Mhz timing */ 818c2ecf20Sopenharmony_ci u16 pio[2]; /* Cached PIO values */ 828c2ecf20Sopenharmony_ci u16 mwdma[2]; /* Cached MWDMA values */ 838c2ecf20Sopenharmony_ci u16 udma[2]; /* Cached UDMA values (per drive) */ 848c2ecf20Sopenharmony_ci u16 quirks; 858c2ecf20Sopenharmony_ci}; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#define ATA_66 0 888c2ecf20Sopenharmony_ci#define ATA_50 1 898c2ecf20Sopenharmony_ci#define ATA_ANY 2 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#define UDMA_OFF 0 928c2ecf20Sopenharmony_ci#define MWDMA_OFF 0 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/* 958c2ecf20Sopenharmony_ci * We allow users to force the card into non raid mode without 968c2ecf20Sopenharmony_ci * flashing the alternative BIOS. This is also necessary right now 978c2ecf20Sopenharmony_ci * for embedded platforms that cannot run a PC BIOS but are using this 988c2ecf20Sopenharmony_ci * device. 998c2ecf20Sopenharmony_ci */ 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistatic int it8212_noraid; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci/** 1048c2ecf20Sopenharmony_ci * it821x_program - program the PIO/MWDMA registers 1058c2ecf20Sopenharmony_ci * @drive: drive to tune 1068c2ecf20Sopenharmony_ci * @timing: timing info 1078c2ecf20Sopenharmony_ci * 1088c2ecf20Sopenharmony_ci * Program the PIO/MWDMA timing for this channel according to the 1098c2ecf20Sopenharmony_ci * current clock. 1108c2ecf20Sopenharmony_ci */ 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_cistatic void it821x_program(ide_drive_t *drive, u16 timing) 1138c2ecf20Sopenharmony_ci{ 1148c2ecf20Sopenharmony_ci ide_hwif_t *hwif = drive->hwif; 1158c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 1168c2ecf20Sopenharmony_ci struct it821x_dev *itdev = ide_get_hwifdata(hwif); 1178c2ecf20Sopenharmony_ci int channel = hwif->channel; 1188c2ecf20Sopenharmony_ci u8 conf; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci /* Program PIO/MWDMA timing bits */ 1218c2ecf20Sopenharmony_ci if(itdev->clock_mode == ATA_66) 1228c2ecf20Sopenharmony_ci conf = timing >> 8; 1238c2ecf20Sopenharmony_ci else 1248c2ecf20Sopenharmony_ci conf = timing & 0xFF; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x54 + 4 * channel, conf); 1278c2ecf20Sopenharmony_ci} 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci/** 1308c2ecf20Sopenharmony_ci * it821x_program_udma - program the UDMA registers 1318c2ecf20Sopenharmony_ci * @drive: drive to tune 1328c2ecf20Sopenharmony_ci * @timing: timing info 1338c2ecf20Sopenharmony_ci * 1348c2ecf20Sopenharmony_ci * Program the UDMA timing for this drive according to the 1358c2ecf20Sopenharmony_ci * current clock. 1368c2ecf20Sopenharmony_ci */ 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cistatic void it821x_program_udma(ide_drive_t *drive, u16 timing) 1398c2ecf20Sopenharmony_ci{ 1408c2ecf20Sopenharmony_ci ide_hwif_t *hwif = drive->hwif; 1418c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 1428c2ecf20Sopenharmony_ci struct it821x_dev *itdev = ide_get_hwifdata(hwif); 1438c2ecf20Sopenharmony_ci int channel = hwif->channel; 1448c2ecf20Sopenharmony_ci u8 unit = drive->dn & 1, conf; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci /* Program UDMA timing bits */ 1478c2ecf20Sopenharmony_ci if(itdev->clock_mode == ATA_66) 1488c2ecf20Sopenharmony_ci conf = timing >> 8; 1498c2ecf20Sopenharmony_ci else 1508c2ecf20Sopenharmony_ci conf = timing & 0xFF; 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci if (itdev->timing10 == 0) 1538c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x56 + 4 * channel + unit, conf); 1548c2ecf20Sopenharmony_ci else { 1558c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x56 + 4 * channel, conf); 1568c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x56 + 4 * channel + 1, conf); 1578c2ecf20Sopenharmony_ci } 1588c2ecf20Sopenharmony_ci} 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci/** 1618c2ecf20Sopenharmony_ci * it821x_clock_strategy 1628c2ecf20Sopenharmony_ci * @drive: drive to set up 1638c2ecf20Sopenharmony_ci * 1648c2ecf20Sopenharmony_ci * Select between the 50 and 66Mhz base clocks to get the best 1658c2ecf20Sopenharmony_ci * results for this interface. 1668c2ecf20Sopenharmony_ci */ 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_cistatic void it821x_clock_strategy(ide_drive_t *drive) 1698c2ecf20Sopenharmony_ci{ 1708c2ecf20Sopenharmony_ci ide_hwif_t *hwif = drive->hwif; 1718c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 1728c2ecf20Sopenharmony_ci struct it821x_dev *itdev = ide_get_hwifdata(hwif); 1738c2ecf20Sopenharmony_ci ide_drive_t *pair = ide_get_pair_dev(drive); 1748c2ecf20Sopenharmony_ci int clock, altclock, sel = 0; 1758c2ecf20Sopenharmony_ci u8 unit = drive->dn & 1, v; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci if(itdev->want[0][0] > itdev->want[1][0]) { 1788c2ecf20Sopenharmony_ci clock = itdev->want[0][1]; 1798c2ecf20Sopenharmony_ci altclock = itdev->want[1][1]; 1808c2ecf20Sopenharmony_ci } else { 1818c2ecf20Sopenharmony_ci clock = itdev->want[1][1]; 1828c2ecf20Sopenharmony_ci altclock = itdev->want[0][1]; 1838c2ecf20Sopenharmony_ci } 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci /* 1868c2ecf20Sopenharmony_ci * if both clocks can be used for the mode with the higher priority 1878c2ecf20Sopenharmony_ci * use the clock needed by the mode with the lower priority 1888c2ecf20Sopenharmony_ci */ 1898c2ecf20Sopenharmony_ci if (clock == ATA_ANY) 1908c2ecf20Sopenharmony_ci clock = altclock; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci /* Nobody cares - keep the same clock */ 1938c2ecf20Sopenharmony_ci if(clock == ATA_ANY) 1948c2ecf20Sopenharmony_ci return; 1958c2ecf20Sopenharmony_ci /* No change */ 1968c2ecf20Sopenharmony_ci if(clock == itdev->clock_mode) 1978c2ecf20Sopenharmony_ci return; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci /* Load this into the controller ? */ 2008c2ecf20Sopenharmony_ci if(clock == ATA_66) 2018c2ecf20Sopenharmony_ci itdev->clock_mode = ATA_66; 2028c2ecf20Sopenharmony_ci else { 2038c2ecf20Sopenharmony_ci itdev->clock_mode = ATA_50; 2048c2ecf20Sopenharmony_ci sel = 1; 2058c2ecf20Sopenharmony_ci } 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci pci_read_config_byte(dev, 0x50, &v); 2088c2ecf20Sopenharmony_ci v &= ~(1 << (1 + hwif->channel)); 2098c2ecf20Sopenharmony_ci v |= sel << (1 + hwif->channel); 2108c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x50, v); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci /* 2138c2ecf20Sopenharmony_ci * Reprogram the UDMA/PIO of the pair drive for the switch 2148c2ecf20Sopenharmony_ci * MWDMA will be dealt with by the dma switcher 2158c2ecf20Sopenharmony_ci */ 2168c2ecf20Sopenharmony_ci if(pair && itdev->udma[1-unit] != UDMA_OFF) { 2178c2ecf20Sopenharmony_ci it821x_program_udma(pair, itdev->udma[1-unit]); 2188c2ecf20Sopenharmony_ci it821x_program(pair, itdev->pio[1-unit]); 2198c2ecf20Sopenharmony_ci } 2208c2ecf20Sopenharmony_ci /* 2218c2ecf20Sopenharmony_ci * Reprogram the UDMA/PIO of our drive for the switch. 2228c2ecf20Sopenharmony_ci * MWDMA will be dealt with by the dma switcher 2238c2ecf20Sopenharmony_ci */ 2248c2ecf20Sopenharmony_ci if(itdev->udma[unit] != UDMA_OFF) { 2258c2ecf20Sopenharmony_ci it821x_program_udma(drive, itdev->udma[unit]); 2268c2ecf20Sopenharmony_ci it821x_program(drive, itdev->pio[unit]); 2278c2ecf20Sopenharmony_ci } 2288c2ecf20Sopenharmony_ci} 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci/** 2318c2ecf20Sopenharmony_ci * it821x_set_pio_mode - set host controller for PIO mode 2328c2ecf20Sopenharmony_ci * @hwif: port 2338c2ecf20Sopenharmony_ci * @drive: drive 2348c2ecf20Sopenharmony_ci * 2358c2ecf20Sopenharmony_ci * Tune the host to the desired PIO mode taking into the consideration 2368c2ecf20Sopenharmony_ci * the maximum PIO mode supported by the other device on the cable. 2378c2ecf20Sopenharmony_ci */ 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_cistatic void it821x_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) 2408c2ecf20Sopenharmony_ci{ 2418c2ecf20Sopenharmony_ci struct it821x_dev *itdev = ide_get_hwifdata(hwif); 2428c2ecf20Sopenharmony_ci ide_drive_t *pair = ide_get_pair_dev(drive); 2438c2ecf20Sopenharmony_ci const u8 pio = drive->pio_mode - XFER_PIO_0; 2448c2ecf20Sopenharmony_ci u8 unit = drive->dn & 1, set_pio = pio; 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci /* Spec says 89 ref driver uses 88 */ 2478c2ecf20Sopenharmony_ci static u16 pio_timings[]= { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 }; 2488c2ecf20Sopenharmony_ci static u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY }; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci /* 2518c2ecf20Sopenharmony_ci * Compute the best PIO mode we can for a given device. We must 2528c2ecf20Sopenharmony_ci * pick a speed that does not cause problems with the other device 2538c2ecf20Sopenharmony_ci * on the cable. 2548c2ecf20Sopenharmony_ci */ 2558c2ecf20Sopenharmony_ci if (pair) { 2568c2ecf20Sopenharmony_ci u8 pair_pio = pair->pio_mode - XFER_PIO_0; 2578c2ecf20Sopenharmony_ci /* trim PIO to the slowest of the master/slave */ 2588c2ecf20Sopenharmony_ci if (pair_pio < set_pio) 2598c2ecf20Sopenharmony_ci set_pio = pair_pio; 2608c2ecf20Sopenharmony_ci } 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci /* We prefer 66Mhz clock for PIO 0-3, don't care for PIO4 */ 2638c2ecf20Sopenharmony_ci itdev->want[unit][1] = pio_want[set_pio]; 2648c2ecf20Sopenharmony_ci itdev->want[unit][0] = 1; /* PIO is lowest priority */ 2658c2ecf20Sopenharmony_ci itdev->pio[unit] = pio_timings[set_pio]; 2668c2ecf20Sopenharmony_ci it821x_clock_strategy(drive); 2678c2ecf20Sopenharmony_ci it821x_program(drive, itdev->pio[unit]); 2688c2ecf20Sopenharmony_ci} 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci/** 2718c2ecf20Sopenharmony_ci * it821x_tune_mwdma - tune a channel for MWDMA 2728c2ecf20Sopenharmony_ci * @drive: drive to set up 2738c2ecf20Sopenharmony_ci * @mode_wanted: the target operating mode 2748c2ecf20Sopenharmony_ci * 2758c2ecf20Sopenharmony_ci * Load the timing settings for this device mode into the 2768c2ecf20Sopenharmony_ci * controller when doing MWDMA in pass through mode. The caller 2778c2ecf20Sopenharmony_ci * must manage the whole lack of per device MWDMA/PIO timings and 2788c2ecf20Sopenharmony_ci * the shared MWDMA/PIO timing register. 2798c2ecf20Sopenharmony_ci */ 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_cistatic void it821x_tune_mwdma(ide_drive_t *drive, u8 mode_wanted) 2828c2ecf20Sopenharmony_ci{ 2838c2ecf20Sopenharmony_ci ide_hwif_t *hwif = drive->hwif; 2848c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 2858c2ecf20Sopenharmony_ci struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif); 2868c2ecf20Sopenharmony_ci u8 unit = drive->dn & 1, channel = hwif->channel, conf; 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci static u16 dma[] = { 0x8866, 0x3222, 0x3121 }; 2898c2ecf20Sopenharmony_ci static u8 mwdma_want[] = { ATA_ANY, ATA_66, ATA_ANY }; 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci itdev->want[unit][1] = mwdma_want[mode_wanted]; 2928c2ecf20Sopenharmony_ci itdev->want[unit][0] = 2; /* MWDMA is low priority */ 2938c2ecf20Sopenharmony_ci itdev->mwdma[unit] = dma[mode_wanted]; 2948c2ecf20Sopenharmony_ci itdev->udma[unit] = UDMA_OFF; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci /* UDMA bits off - Revision 0x10 do them in pairs */ 2978c2ecf20Sopenharmony_ci pci_read_config_byte(dev, 0x50, &conf); 2988c2ecf20Sopenharmony_ci if (itdev->timing10) 2998c2ecf20Sopenharmony_ci conf |= channel ? 0x60: 0x18; 3008c2ecf20Sopenharmony_ci else 3018c2ecf20Sopenharmony_ci conf |= 1 << (3 + 2 * channel + unit); 3028c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x50, conf); 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci it821x_clock_strategy(drive); 3058c2ecf20Sopenharmony_ci /* FIXME: do we need to program this ? */ 3068c2ecf20Sopenharmony_ci /* it821x_program(drive, itdev->mwdma[unit]); */ 3078c2ecf20Sopenharmony_ci} 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci/** 3108c2ecf20Sopenharmony_ci * it821x_tune_udma - tune a channel for UDMA 3118c2ecf20Sopenharmony_ci * @drive: drive to set up 3128c2ecf20Sopenharmony_ci * @mode_wanted: the target operating mode 3138c2ecf20Sopenharmony_ci * 3148c2ecf20Sopenharmony_ci * Load the timing settings for this device mode into the 3158c2ecf20Sopenharmony_ci * controller when doing UDMA modes in pass through. 3168c2ecf20Sopenharmony_ci */ 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_cistatic void it821x_tune_udma(ide_drive_t *drive, u8 mode_wanted) 3198c2ecf20Sopenharmony_ci{ 3208c2ecf20Sopenharmony_ci ide_hwif_t *hwif = drive->hwif; 3218c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 3228c2ecf20Sopenharmony_ci struct it821x_dev *itdev = ide_get_hwifdata(hwif); 3238c2ecf20Sopenharmony_ci u8 unit = drive->dn & 1, channel = hwif->channel, conf; 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci static u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 }; 3268c2ecf20Sopenharmony_ci static u8 udma_want[] = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 }; 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci itdev->want[unit][1] = udma_want[mode_wanted]; 3298c2ecf20Sopenharmony_ci itdev->want[unit][0] = 3; /* UDMA is high priority */ 3308c2ecf20Sopenharmony_ci itdev->mwdma[unit] = MWDMA_OFF; 3318c2ecf20Sopenharmony_ci itdev->udma[unit] = udma[mode_wanted]; 3328c2ecf20Sopenharmony_ci if(mode_wanted >= 5) 3338c2ecf20Sopenharmony_ci itdev->udma[unit] |= 0x8080; /* UDMA 5/6 select on */ 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci /* UDMA on. Again revision 0x10 must do the pair */ 3368c2ecf20Sopenharmony_ci pci_read_config_byte(dev, 0x50, &conf); 3378c2ecf20Sopenharmony_ci if (itdev->timing10) 3388c2ecf20Sopenharmony_ci conf &= channel ? 0x9F: 0xE7; 3398c2ecf20Sopenharmony_ci else 3408c2ecf20Sopenharmony_ci conf &= ~ (1 << (3 + 2 * channel + unit)); 3418c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x50, conf); 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci it821x_clock_strategy(drive); 3448c2ecf20Sopenharmony_ci it821x_program_udma(drive, itdev->udma[unit]); 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci} 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci/** 3498c2ecf20Sopenharmony_ci * it821x_dma_read - DMA hook 3508c2ecf20Sopenharmony_ci * @drive: drive for DMA 3518c2ecf20Sopenharmony_ci * 3528c2ecf20Sopenharmony_ci * The IT821x has a single timing register for MWDMA and for PIO 3538c2ecf20Sopenharmony_ci * operations. As we flip back and forth we have to reload the 3548c2ecf20Sopenharmony_ci * clock. In addition the rev 0x10 device only works if the same 3558c2ecf20Sopenharmony_ci * timing value is loaded into the master and slave UDMA clock 3568c2ecf20Sopenharmony_ci * so we must also reload that. 3578c2ecf20Sopenharmony_ci * 3588c2ecf20Sopenharmony_ci * FIXME: we could figure out in advance if we need to do reloads 3598c2ecf20Sopenharmony_ci */ 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_cistatic void it821x_dma_start(ide_drive_t *drive) 3628c2ecf20Sopenharmony_ci{ 3638c2ecf20Sopenharmony_ci ide_hwif_t *hwif = drive->hwif; 3648c2ecf20Sopenharmony_ci struct it821x_dev *itdev = ide_get_hwifdata(hwif); 3658c2ecf20Sopenharmony_ci u8 unit = drive->dn & 1; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci if(itdev->mwdma[unit] != MWDMA_OFF) 3688c2ecf20Sopenharmony_ci it821x_program(drive, itdev->mwdma[unit]); 3698c2ecf20Sopenharmony_ci else if(itdev->udma[unit] != UDMA_OFF && itdev->timing10) 3708c2ecf20Sopenharmony_ci it821x_program_udma(drive, itdev->udma[unit]); 3718c2ecf20Sopenharmony_ci ide_dma_start(drive); 3728c2ecf20Sopenharmony_ci} 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci/** 3758c2ecf20Sopenharmony_ci * it821x_dma_write - DMA hook 3768c2ecf20Sopenharmony_ci * @drive: drive for DMA stop 3778c2ecf20Sopenharmony_ci * 3788c2ecf20Sopenharmony_ci * The IT821x has a single timing register for MWDMA and for PIO 3798c2ecf20Sopenharmony_ci * operations. As we flip back and forth we have to reload the 3808c2ecf20Sopenharmony_ci * clock. 3818c2ecf20Sopenharmony_ci */ 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_cistatic int it821x_dma_end(ide_drive_t *drive) 3848c2ecf20Sopenharmony_ci{ 3858c2ecf20Sopenharmony_ci ide_hwif_t *hwif = drive->hwif; 3868c2ecf20Sopenharmony_ci struct it821x_dev *itdev = ide_get_hwifdata(hwif); 3878c2ecf20Sopenharmony_ci int ret = ide_dma_end(drive); 3888c2ecf20Sopenharmony_ci u8 unit = drive->dn & 1; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci if(itdev->mwdma[unit] != MWDMA_OFF) 3918c2ecf20Sopenharmony_ci it821x_program(drive, itdev->pio[unit]); 3928c2ecf20Sopenharmony_ci return ret; 3938c2ecf20Sopenharmony_ci} 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci/** 3968c2ecf20Sopenharmony_ci * it821x_set_dma_mode - set host controller for DMA mode 3978c2ecf20Sopenharmony_ci * @hwif: port 3988c2ecf20Sopenharmony_ci * @drive: drive 3998c2ecf20Sopenharmony_ci * 4008c2ecf20Sopenharmony_ci * Tune the ITE chipset for the desired DMA mode. 4018c2ecf20Sopenharmony_ci */ 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_cistatic void it821x_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive) 4048c2ecf20Sopenharmony_ci{ 4058c2ecf20Sopenharmony_ci const u8 speed = drive->dma_mode; 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci /* 4088c2ecf20Sopenharmony_ci * MWDMA tuning is really hard because our MWDMA and PIO 4098c2ecf20Sopenharmony_ci * timings are kept in the same place. We can switch in the 4108c2ecf20Sopenharmony_ci * host dma on/off callbacks. 4118c2ecf20Sopenharmony_ci */ 4128c2ecf20Sopenharmony_ci if (speed >= XFER_UDMA_0 && speed <= XFER_UDMA_6) 4138c2ecf20Sopenharmony_ci it821x_tune_udma(drive, speed - XFER_UDMA_0); 4148c2ecf20Sopenharmony_ci else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) 4158c2ecf20Sopenharmony_ci it821x_tune_mwdma(drive, speed - XFER_MW_DMA_0); 4168c2ecf20Sopenharmony_ci} 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci/** 4198c2ecf20Sopenharmony_ci * it821x_cable_detect - cable detection 4208c2ecf20Sopenharmony_ci * @hwif: interface to check 4218c2ecf20Sopenharmony_ci * 4228c2ecf20Sopenharmony_ci * Check for the presence of an ATA66 capable cable on the 4238c2ecf20Sopenharmony_ci * interface. Problematic as it seems some cards don't have 4248c2ecf20Sopenharmony_ci * the needed logic onboard. 4258c2ecf20Sopenharmony_ci */ 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_cistatic u8 it821x_cable_detect(ide_hwif_t *hwif) 4288c2ecf20Sopenharmony_ci{ 4298c2ecf20Sopenharmony_ci /* The reference driver also only does disk side */ 4308c2ecf20Sopenharmony_ci return ATA_CBL_PATA80; 4318c2ecf20Sopenharmony_ci} 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci/** 4348c2ecf20Sopenharmony_ci * it821x_quirkproc - post init callback 4358c2ecf20Sopenharmony_ci * @drive: drive 4368c2ecf20Sopenharmony_ci * 4378c2ecf20Sopenharmony_ci * This callback is run after the drive has been probed but 4388c2ecf20Sopenharmony_ci * before anything gets attached. It allows drivers to do any 4398c2ecf20Sopenharmony_ci * final tuning that is needed, or fixups to work around bugs. 4408c2ecf20Sopenharmony_ci */ 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_cistatic void it821x_quirkproc(ide_drive_t *drive) 4438c2ecf20Sopenharmony_ci{ 4448c2ecf20Sopenharmony_ci struct it821x_dev *itdev = ide_get_hwifdata(drive->hwif); 4458c2ecf20Sopenharmony_ci u16 *id = drive->id; 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci if (!itdev->smart) { 4488c2ecf20Sopenharmony_ci /* 4498c2ecf20Sopenharmony_ci * If we are in pass through mode then not much 4508c2ecf20Sopenharmony_ci * needs to be done, but we do bother to clear the 4518c2ecf20Sopenharmony_ci * IRQ mask as we may well be in PIO (eg rev 0x10) 4528c2ecf20Sopenharmony_ci * for now and we know unmasking is safe on this chipset. 4538c2ecf20Sopenharmony_ci */ 4548c2ecf20Sopenharmony_ci drive->dev_flags |= IDE_DFLAG_UNMASK; 4558c2ecf20Sopenharmony_ci } else { 4568c2ecf20Sopenharmony_ci /* 4578c2ecf20Sopenharmony_ci * Perform fixups on smart mode. We need to "lose" some 4588c2ecf20Sopenharmony_ci * capabilities the firmware lacks but does not filter, and 4598c2ecf20Sopenharmony_ci * also patch up some capability bits that it forgets to set 4608c2ecf20Sopenharmony_ci * in RAID mode. 4618c2ecf20Sopenharmony_ci */ 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci /* Check for RAID v native */ 4648c2ecf20Sopenharmony_ci if (strstr((char *)&id[ATA_ID_PROD], 4658c2ecf20Sopenharmony_ci "Integrated Technology Express")) { 4668c2ecf20Sopenharmony_ci /* In raid mode the ident block is slightly buggy 4678c2ecf20Sopenharmony_ci We need to set the bits so that the IDE layer knows 4688c2ecf20Sopenharmony_ci LBA28. LBA48 and DMA ar valid */ 4698c2ecf20Sopenharmony_ci id[ATA_ID_CAPABILITY] |= (3 << 8); /* LBA28, DMA */ 4708c2ecf20Sopenharmony_ci id[ATA_ID_COMMAND_SET_2] |= 0x0400; /* LBA48 valid */ 4718c2ecf20Sopenharmony_ci id[ATA_ID_CFS_ENABLE_2] |= 0x0400; /* LBA48 on */ 4728c2ecf20Sopenharmony_ci /* Reporting logic */ 4738c2ecf20Sopenharmony_ci printk(KERN_INFO "%s: IT8212 %sRAID %d volume", 4748c2ecf20Sopenharmony_ci drive->name, id[147] ? "Bootable " : "", 4758c2ecf20Sopenharmony_ci id[ATA_ID_CSFO]); 4768c2ecf20Sopenharmony_ci if (id[ATA_ID_CSFO] != 1) 4778c2ecf20Sopenharmony_ci printk(KERN_CONT "(%dK stripe)", id[146]); 4788c2ecf20Sopenharmony_ci printk(KERN_CONT ".\n"); 4798c2ecf20Sopenharmony_ci } else { 4808c2ecf20Sopenharmony_ci /* Non RAID volume. Fixups to stop the core code 4818c2ecf20Sopenharmony_ci doing unsupported things */ 4828c2ecf20Sopenharmony_ci id[ATA_ID_FIELD_VALID] &= 3; 4838c2ecf20Sopenharmony_ci id[ATA_ID_QUEUE_DEPTH] = 0; 4848c2ecf20Sopenharmony_ci id[ATA_ID_COMMAND_SET_1] = 0; 4858c2ecf20Sopenharmony_ci id[ATA_ID_COMMAND_SET_2] &= 0xC400; 4868c2ecf20Sopenharmony_ci id[ATA_ID_CFSSE] &= 0xC000; 4878c2ecf20Sopenharmony_ci id[ATA_ID_CFS_ENABLE_1] = 0; 4888c2ecf20Sopenharmony_ci id[ATA_ID_CFS_ENABLE_2] &= 0xC400; 4898c2ecf20Sopenharmony_ci id[ATA_ID_CSF_DEFAULT] &= 0xC000; 4908c2ecf20Sopenharmony_ci id[127] = 0; 4918c2ecf20Sopenharmony_ci id[ATA_ID_DLF] = 0; 4928c2ecf20Sopenharmony_ci id[ATA_ID_CSFO] = 0; 4938c2ecf20Sopenharmony_ci id[ATA_ID_CFA_POWER] = 0; 4948c2ecf20Sopenharmony_ci printk(KERN_INFO "%s: Performing identify fixups.\n", 4958c2ecf20Sopenharmony_ci drive->name); 4968c2ecf20Sopenharmony_ci } 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci /* 4998c2ecf20Sopenharmony_ci * Set MWDMA0 mode as enabled/support - just to tell 5008c2ecf20Sopenharmony_ci * IDE core that DMA is supported (it821x hardware 5018c2ecf20Sopenharmony_ci * takes care of DMA mode programming). 5028c2ecf20Sopenharmony_ci */ 5038c2ecf20Sopenharmony_ci if (ata_id_has_dma(id)) { 5048c2ecf20Sopenharmony_ci id[ATA_ID_MWDMA_MODES] |= 0x0101; 5058c2ecf20Sopenharmony_ci drive->current_speed = XFER_MW_DMA_0; 5068c2ecf20Sopenharmony_ci } 5078c2ecf20Sopenharmony_ci } 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci} 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_cistatic const struct ide_dma_ops it821x_pass_through_dma_ops = { 5128c2ecf20Sopenharmony_ci .dma_host_set = ide_dma_host_set, 5138c2ecf20Sopenharmony_ci .dma_setup = ide_dma_setup, 5148c2ecf20Sopenharmony_ci .dma_start = it821x_dma_start, 5158c2ecf20Sopenharmony_ci .dma_end = it821x_dma_end, 5168c2ecf20Sopenharmony_ci .dma_test_irq = ide_dma_test_irq, 5178c2ecf20Sopenharmony_ci .dma_lost_irq = ide_dma_lost_irq, 5188c2ecf20Sopenharmony_ci .dma_timer_expiry = ide_dma_sff_timer_expiry, 5198c2ecf20Sopenharmony_ci .dma_sff_read_status = ide_dma_sff_read_status, 5208c2ecf20Sopenharmony_ci}; 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci/** 5238c2ecf20Sopenharmony_ci * init_hwif_it821x - set up hwif structs 5248c2ecf20Sopenharmony_ci * @hwif: interface to set up 5258c2ecf20Sopenharmony_ci * 5268c2ecf20Sopenharmony_ci * We do the basic set up of the interface structure. The IT8212 5278c2ecf20Sopenharmony_ci * requires several custom handlers so we override the default 5288c2ecf20Sopenharmony_ci * ide DMA handlers appropriately 5298c2ecf20Sopenharmony_ci */ 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_cistatic void init_hwif_it821x(ide_hwif_t *hwif) 5328c2ecf20Sopenharmony_ci{ 5338c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 5348c2ecf20Sopenharmony_ci struct ide_host *host = pci_get_drvdata(dev); 5358c2ecf20Sopenharmony_ci struct it821x_dev *itdevs = host->host_priv; 5368c2ecf20Sopenharmony_ci struct it821x_dev *idev = itdevs + hwif->channel; 5378c2ecf20Sopenharmony_ci u8 conf; 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci ide_set_hwifdata(hwif, idev); 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci pci_read_config_byte(dev, 0x50, &conf); 5428c2ecf20Sopenharmony_ci if (conf & 1) { 5438c2ecf20Sopenharmony_ci idev->smart = 1; 5448c2ecf20Sopenharmony_ci hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA; 5458c2ecf20Sopenharmony_ci /* Long I/O's although allowed in LBA48 space cause the 5468c2ecf20Sopenharmony_ci onboard firmware to enter the twighlight zone */ 5478c2ecf20Sopenharmony_ci hwif->rqsize = 256; 5488c2ecf20Sopenharmony_ci } 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci /* Pull the current clocks from 0x50 also */ 5518c2ecf20Sopenharmony_ci if (conf & (1 << (1 + hwif->channel))) 5528c2ecf20Sopenharmony_ci idev->clock_mode = ATA_50; 5538c2ecf20Sopenharmony_ci else 5548c2ecf20Sopenharmony_ci idev->clock_mode = ATA_66; 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci idev->want[0][1] = ATA_ANY; 5578c2ecf20Sopenharmony_ci idev->want[1][1] = ATA_ANY; 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci /* 5608c2ecf20Sopenharmony_ci * Not in the docs but according to the reference driver 5618c2ecf20Sopenharmony_ci * this is necessary. 5628c2ecf20Sopenharmony_ci */ 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci if (dev->revision == 0x10) { 5658c2ecf20Sopenharmony_ci idev->timing10 = 1; 5668c2ecf20Sopenharmony_ci hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA; 5678c2ecf20Sopenharmony_ci if (idev->smart == 0) 5688c2ecf20Sopenharmony_ci printk(KERN_WARNING DRV_NAME " %s: revision 0x10, " 5698c2ecf20Sopenharmony_ci "workarounds activated\n", pci_name(dev)); 5708c2ecf20Sopenharmony_ci } 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci if (idev->smart == 0) { 5738c2ecf20Sopenharmony_ci /* MWDMA/PIO clock switching for pass through mode */ 5748c2ecf20Sopenharmony_ci hwif->dma_ops = &it821x_pass_through_dma_ops; 5758c2ecf20Sopenharmony_ci } else 5768c2ecf20Sopenharmony_ci hwif->host_flags |= IDE_HFLAG_NO_SET_MODE; 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci if (hwif->dma_base == 0) 5798c2ecf20Sopenharmony_ci return; 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci hwif->ultra_mask = ATA_UDMA6; 5828c2ecf20Sopenharmony_ci hwif->mwdma_mask = ATA_MWDMA2; 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci /* Vortex86SX quirk: prevent Ultra-DMA mode to fix BadCRC issue */ 5858c2ecf20Sopenharmony_ci if (idev->quirks & QUIRK_VORTEX86) { 5868c2ecf20Sopenharmony_ci if (dev->revision == 0x11) 5878c2ecf20Sopenharmony_ci hwif->ultra_mask = 0; 5888c2ecf20Sopenharmony_ci } 5898c2ecf20Sopenharmony_ci} 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_cistatic void it8212_disable_raid(struct pci_dev *dev) 5928c2ecf20Sopenharmony_ci{ 5938c2ecf20Sopenharmony_ci /* Reset local CPU, and set BIOS not ready */ 5948c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x5E, 0x01); 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci /* Set to bypass mode, and reset PCI bus */ 5978c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x50, 0x00); 5988c2ecf20Sopenharmony_ci pci_write_config_word(dev, PCI_COMMAND, 5998c2ecf20Sopenharmony_ci PCI_COMMAND_PARITY | PCI_COMMAND_IO | 6008c2ecf20Sopenharmony_ci PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); 6018c2ecf20Sopenharmony_ci pci_write_config_word(dev, 0x40, 0xA0F3); 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci pci_write_config_dword(dev,0x4C, 0x02040204); 6048c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x42, 0x36); 6058c2ecf20Sopenharmony_ci pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20); 6068c2ecf20Sopenharmony_ci} 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_cistatic int init_chipset_it821x(struct pci_dev *dev) 6098c2ecf20Sopenharmony_ci{ 6108c2ecf20Sopenharmony_ci u8 conf; 6118c2ecf20Sopenharmony_ci static char *mode[2] = { "pass through", "smart" }; 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci /* Force the card into bypass mode if so requested */ 6148c2ecf20Sopenharmony_ci if (it8212_noraid) { 6158c2ecf20Sopenharmony_ci printk(KERN_INFO DRV_NAME " %s: forcing bypass mode\n", 6168c2ecf20Sopenharmony_ci pci_name(dev)); 6178c2ecf20Sopenharmony_ci it8212_disable_raid(dev); 6188c2ecf20Sopenharmony_ci } 6198c2ecf20Sopenharmony_ci pci_read_config_byte(dev, 0x50, &conf); 6208c2ecf20Sopenharmony_ci printk(KERN_INFO DRV_NAME " %s: controller in %s mode\n", 6218c2ecf20Sopenharmony_ci pci_name(dev), mode[conf & 1]); 6228c2ecf20Sopenharmony_ci return 0; 6238c2ecf20Sopenharmony_ci} 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_cistatic const struct ide_port_ops it821x_port_ops = { 6268c2ecf20Sopenharmony_ci /* it821x_set_{pio,dma}_mode() are only used in pass-through mode */ 6278c2ecf20Sopenharmony_ci .set_pio_mode = it821x_set_pio_mode, 6288c2ecf20Sopenharmony_ci .set_dma_mode = it821x_set_dma_mode, 6298c2ecf20Sopenharmony_ci .quirkproc = it821x_quirkproc, 6308c2ecf20Sopenharmony_ci .cable_detect = it821x_cable_detect, 6318c2ecf20Sopenharmony_ci}; 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_cistatic const struct ide_port_info it821x_chipset = { 6348c2ecf20Sopenharmony_ci .name = DRV_NAME, 6358c2ecf20Sopenharmony_ci .init_chipset = init_chipset_it821x, 6368c2ecf20Sopenharmony_ci .init_hwif = init_hwif_it821x, 6378c2ecf20Sopenharmony_ci .port_ops = &it821x_port_ops, 6388c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO4, 6398c2ecf20Sopenharmony_ci}; 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_ci/** 6428c2ecf20Sopenharmony_ci * it821x_init_one - pci layer discovery entry 6438c2ecf20Sopenharmony_ci * @dev: PCI device 6448c2ecf20Sopenharmony_ci * @id: ident table entry 6458c2ecf20Sopenharmony_ci * 6468c2ecf20Sopenharmony_ci * Called by the PCI code when it finds an ITE821x controller. 6478c2ecf20Sopenharmony_ci * We then use the IDE PCI generic helper to do most of the work. 6488c2ecf20Sopenharmony_ci */ 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_cistatic int it821x_init_one(struct pci_dev *dev, const struct pci_device_id *id) 6518c2ecf20Sopenharmony_ci{ 6528c2ecf20Sopenharmony_ci struct it821x_dev *itdevs; 6538c2ecf20Sopenharmony_ci int rc; 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_ci itdevs = kcalloc(2, sizeof(*itdevs), GFP_KERNEL); 6568c2ecf20Sopenharmony_ci if (itdevs == NULL) { 6578c2ecf20Sopenharmony_ci printk(KERN_ERR DRV_NAME " %s: out of memory\n", pci_name(dev)); 6588c2ecf20Sopenharmony_ci return -ENOMEM; 6598c2ecf20Sopenharmony_ci } 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ci itdevs->quirks = id->driver_data; 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci rc = ide_pci_init_one(dev, &it821x_chipset, itdevs); 6648c2ecf20Sopenharmony_ci if (rc) 6658c2ecf20Sopenharmony_ci kfree(itdevs); 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci return rc; 6688c2ecf20Sopenharmony_ci} 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_cistatic void it821x_remove(struct pci_dev *dev) 6718c2ecf20Sopenharmony_ci{ 6728c2ecf20Sopenharmony_ci struct ide_host *host = pci_get_drvdata(dev); 6738c2ecf20Sopenharmony_ci struct it821x_dev *itdevs = host->host_priv; 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_ci ide_pci_remove(dev); 6768c2ecf20Sopenharmony_ci kfree(itdevs); 6778c2ecf20Sopenharmony_ci} 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_cistatic const struct pci_device_id it821x_pci_tbl[] = { 6808c2ecf20Sopenharmony_ci { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8211), 0 }, 6818c2ecf20Sopenharmony_ci { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8212), 0 }, 6828c2ecf20Sopenharmony_ci { PCI_VDEVICE(RDC, PCI_DEVICE_ID_RDC_D1010), QUIRK_VORTEX86 }, 6838c2ecf20Sopenharmony_ci { 0, }, 6848c2ecf20Sopenharmony_ci}; 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, it821x_pci_tbl); 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_cistatic struct pci_driver it821x_pci_driver = { 6898c2ecf20Sopenharmony_ci .name = "ITE821x IDE", 6908c2ecf20Sopenharmony_ci .id_table = it821x_pci_tbl, 6918c2ecf20Sopenharmony_ci .probe = it821x_init_one, 6928c2ecf20Sopenharmony_ci .remove = it821x_remove, 6938c2ecf20Sopenharmony_ci .suspend = ide_pci_suspend, 6948c2ecf20Sopenharmony_ci .resume = ide_pci_resume, 6958c2ecf20Sopenharmony_ci}; 6968c2ecf20Sopenharmony_ci 6978c2ecf20Sopenharmony_cistatic int __init it821x_ide_init(void) 6988c2ecf20Sopenharmony_ci{ 6998c2ecf20Sopenharmony_ci return ide_pci_register_driver(&it821x_pci_driver); 7008c2ecf20Sopenharmony_ci} 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_cistatic void __exit it821x_ide_exit(void) 7038c2ecf20Sopenharmony_ci{ 7048c2ecf20Sopenharmony_ci pci_unregister_driver(&it821x_pci_driver); 7058c2ecf20Sopenharmony_ci} 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_cimodule_init(it821x_ide_init); 7088c2ecf20Sopenharmony_cimodule_exit(it821x_ide_exit); 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_cimodule_param_named(noraid, it8212_noraid, int, S_IRUGO); 7118c2ecf20Sopenharmony_ciMODULE_PARM_DESC(noraid, "Force card into bypass mode"); 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ciMODULE_AUTHOR("Alan Cox"); 7148c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("PCI driver module for the ITE 821x"); 7158c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 716