18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * IDE tuning and bus mastering support for the CS5510/CS5520 38c2ecf20Sopenharmony_ci * chipsets 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * The CS5510/CS5520 are slightly unusual devices. Unlike the 68c2ecf20Sopenharmony_ci * typical IDE controllers they do bus mastering with the drive in 78c2ecf20Sopenharmony_ci * PIO mode and smarter silicon. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * The practical upshot of this is that we must always tune the 108c2ecf20Sopenharmony_ci * drive for the right PIO mode. We must also ignore all the blacklists 118c2ecf20Sopenharmony_ci * and the drive bus mastering DMA information. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * *** This driver is strictly experimental *** 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * (c) Copyright Red Hat Inc 2002 168c2ecf20Sopenharmony_ci * 178c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify it 188c2ecf20Sopenharmony_ci * under the terms of the GNU General Public License as published by the 198c2ecf20Sopenharmony_ci * Free Software Foundation; either version 2, or (at your option) any 208c2ecf20Sopenharmony_ci * later version. 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, but 238c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of 248c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 258c2ecf20Sopenharmony_ci * General Public License for more details. 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * For the avoidance of doubt the "preferred form" of this code is one which 288c2ecf20Sopenharmony_ci * is in an open non patent encumbered format. Where cryptographic key signing 298c2ecf20Sopenharmony_ci * forms part of the process of creating an executable the information 308c2ecf20Sopenharmony_ci * including keys needed to generate an equivalently functional executable 318c2ecf20Sopenharmony_ci * are deemed to be part of the source code. 328c2ecf20Sopenharmony_ci * 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#include <linux/module.h> 368c2ecf20Sopenharmony_ci#include <linux/types.h> 378c2ecf20Sopenharmony_ci#include <linux/kernel.h> 388c2ecf20Sopenharmony_ci#include <linux/init.h> 398c2ecf20Sopenharmony_ci#include <linux/pci.h> 408c2ecf20Sopenharmony_ci#include <linux/ide.h> 418c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h> 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define DRV_NAME "cs5520" 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistruct pio_clocks 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci int address; 488c2ecf20Sopenharmony_ci int assert; 498c2ecf20Sopenharmony_ci int recovery; 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic struct pio_clocks cs5520_pio_clocks[]={ 538c2ecf20Sopenharmony_ci {3, 6, 11}, 548c2ecf20Sopenharmony_ci {2, 5, 6}, 558c2ecf20Sopenharmony_ci {1, 4, 3}, 568c2ecf20Sopenharmony_ci {1, 3, 2}, 578c2ecf20Sopenharmony_ci {1, 2, 1} 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistatic void cs5520_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci struct pci_dev *pdev = to_pci_dev(hwif->dev); 638c2ecf20Sopenharmony_ci int controller = drive->dn > 1 ? 1 : 0; 648c2ecf20Sopenharmony_ci const u8 pio = drive->pio_mode - XFER_PIO_0; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci /* 8bit CAT/CRT - 8bit command timing for channel */ 678c2ecf20Sopenharmony_ci pci_write_config_byte(pdev, 0x62 + controller, 688c2ecf20Sopenharmony_ci (cs5520_pio_clocks[pio].recovery << 4) | 698c2ecf20Sopenharmony_ci (cs5520_pio_clocks[pio].assert)); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci /* 0x64 - 16bit Primary, 0x68 - 16bit Secondary */ 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci /* FIXME: should these use address ? */ 748c2ecf20Sopenharmony_ci /* Data read timing */ 758c2ecf20Sopenharmony_ci pci_write_config_byte(pdev, 0x64 + 4*controller + (drive->dn&1), 768c2ecf20Sopenharmony_ci (cs5520_pio_clocks[pio].recovery << 4) | 778c2ecf20Sopenharmony_ci (cs5520_pio_clocks[pio].assert)); 788c2ecf20Sopenharmony_ci /* Write command timing */ 798c2ecf20Sopenharmony_ci pci_write_config_byte(pdev, 0x66 + 4*controller + (drive->dn&1), 808c2ecf20Sopenharmony_ci (cs5520_pio_clocks[pio].recovery << 4) | 818c2ecf20Sopenharmony_ci (cs5520_pio_clocks[pio].assert)); 828c2ecf20Sopenharmony_ci} 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistatic void cs5520_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive) 858c2ecf20Sopenharmony_ci{ 868c2ecf20Sopenharmony_ci printk(KERN_ERR "cs55x0: bad ide timing.\n"); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci drive->pio_mode = XFER_PIO_0 + 0; 898c2ecf20Sopenharmony_ci cs5520_set_pio_mode(hwif, drive); 908c2ecf20Sopenharmony_ci} 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_cistatic const struct ide_port_ops cs5520_port_ops = { 938c2ecf20Sopenharmony_ci .set_pio_mode = cs5520_set_pio_mode, 948c2ecf20Sopenharmony_ci .set_dma_mode = cs5520_set_dma_mode, 958c2ecf20Sopenharmony_ci}; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic const struct ide_port_info cyrix_chipset = { 988c2ecf20Sopenharmony_ci .name = DRV_NAME, 998c2ecf20Sopenharmony_ci .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } }, 1008c2ecf20Sopenharmony_ci .port_ops = &cs5520_port_ops, 1018c2ecf20Sopenharmony_ci .host_flags = IDE_HFLAG_ISA_PORTS | IDE_HFLAG_CS5520, 1028c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO4, 1038c2ecf20Sopenharmony_ci}; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci/* 1068c2ecf20Sopenharmony_ci * The 5510/5520 are a bit weird. They don't quite set up the way 1078c2ecf20Sopenharmony_ci * the PCI helper layer expects so we must do much of the set up 1088c2ecf20Sopenharmony_ci * work longhand. 1098c2ecf20Sopenharmony_ci */ 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_cistatic int cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id) 1128c2ecf20Sopenharmony_ci{ 1138c2ecf20Sopenharmony_ci const struct ide_port_info *d = &cyrix_chipset; 1148c2ecf20Sopenharmony_ci struct ide_hw hw[2], *hws[] = { NULL, NULL }; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci ide_setup_pci_noise(dev, d); 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci /* We must not grab the entire device, it has 'ISA' space in its 1198c2ecf20Sopenharmony_ci * BARS too and we will freak out other bits of the kernel 1208c2ecf20Sopenharmony_ci */ 1218c2ecf20Sopenharmony_ci if (pci_enable_device_io(dev)) { 1228c2ecf20Sopenharmony_ci printk(KERN_WARNING "%s: Unable to enable 55x0.\n", d->name); 1238c2ecf20Sopenharmony_ci return -ENODEV; 1248c2ecf20Sopenharmony_ci } 1258c2ecf20Sopenharmony_ci pci_set_master(dev); 1268c2ecf20Sopenharmony_ci if (dma_set_mask(&dev->dev, DMA_BIT_MASK(32))) { 1278c2ecf20Sopenharmony_ci printk(KERN_WARNING "%s: No suitable DMA available.\n", 1288c2ecf20Sopenharmony_ci d->name); 1298c2ecf20Sopenharmony_ci return -ENODEV; 1308c2ecf20Sopenharmony_ci } 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci /* 1338c2ecf20Sopenharmony_ci * Now the chipset is configured we can let the core 1348c2ecf20Sopenharmony_ci * do all the device setup for us 1358c2ecf20Sopenharmony_ci */ 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci ide_pci_setup_ports(dev, d, &hw[0], &hws[0]); 1388c2ecf20Sopenharmony_ci hw[0].irq = 14; 1398c2ecf20Sopenharmony_ci hw[1].irq = 15; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci return ide_host_add(d, hws, 2, NULL); 1428c2ecf20Sopenharmony_ci} 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_cistatic const struct pci_device_id cs5520_pci_tbl[] = { 1458c2ecf20Sopenharmony_ci { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5510), 0 }, 1468c2ecf20Sopenharmony_ci { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5520), 1 }, 1478c2ecf20Sopenharmony_ci { 0, }, 1488c2ecf20Sopenharmony_ci}; 1498c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, cs5520_pci_tbl); 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistatic struct pci_driver cs5520_pci_driver = { 1528c2ecf20Sopenharmony_ci .name = "Cyrix_IDE", 1538c2ecf20Sopenharmony_ci .id_table = cs5520_pci_tbl, 1548c2ecf20Sopenharmony_ci .probe = cs5520_init_one, 1558c2ecf20Sopenharmony_ci .suspend = ide_pci_suspend, 1568c2ecf20Sopenharmony_ci .resume = ide_pci_resume, 1578c2ecf20Sopenharmony_ci}; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistatic int __init cs5520_ide_init(void) 1608c2ecf20Sopenharmony_ci{ 1618c2ecf20Sopenharmony_ci return ide_pci_register_driver(&cs5520_pci_driver); 1628c2ecf20Sopenharmony_ci} 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cimodule_init(cs5520_ide_init); 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ciMODULE_AUTHOR("Alan Cox"); 1678c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("PCI driver module for Cyrix 5510/5520 IDE"); 1688c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 169