109c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 251dbd490SAlan Cox /* 351dbd490SAlan Cox * pata_ninja32.c - Ninja32 PATA for new ATA layer 451dbd490SAlan Cox * (C) 2007 Red Hat Inc 551dbd490SAlan Cox * 651dbd490SAlan Cox * Note: The controller like many controllers has shared timings for 751dbd490SAlan Cox * PIO and DMA. We thus flip to the DMA timings in dma_start and flip back 851dbd490SAlan Cox * in the dma_stop function. Thus we actually don't need a set_dmamode 951dbd490SAlan Cox * method as the PIO method is always called and will set the right PIO 1051dbd490SAlan Cox * timing parameters. 1151dbd490SAlan Cox * 1251dbd490SAlan Cox * The Ninja32 Cardbus is not a generic SFF controller. Instead it is 1351dbd490SAlan Cox * laid out as follows off BAR 0. This is based upon Mark Lord's delkin 1451dbd490SAlan Cox * driver and the extensive analysis done by the BSD developers, notably 1551dbd490SAlan Cox * ITOH Yasufumi. 1651dbd490SAlan Cox * 1751dbd490SAlan Cox * Base + 0x00 IRQ Status 1851dbd490SAlan Cox * Base + 0x01 IRQ control 1951dbd490SAlan Cox * Base + 0x02 Chipset control 2041946450SAlan Cox * Base + 0x03 Unknown 2151dbd490SAlan Cox * Base + 0x04 VDMA and reset control + wait bits 2251dbd490SAlan Cox * Base + 0x08 BMIMBA 2351dbd490SAlan Cox * Base + 0x0C DMA Length 2451dbd490SAlan Cox * Base + 0x10 Taskfile 2551dbd490SAlan Cox * Base + 0x18 BMDMA Status ? 2651dbd490SAlan Cox * Base + 0x1C 2751dbd490SAlan Cox * Base + 0x1D Bus master control 2851dbd490SAlan Cox * bit 0 = enable 2951dbd490SAlan Cox * bit 1 = 0 write/1 read 3051dbd490SAlan Cox * bit 2 = 1 sgtable 3151dbd490SAlan Cox * bit 3 = go 3251dbd490SAlan Cox * bit 4-6 wait bits 3351dbd490SAlan Cox * bit 7 = done 3451dbd490SAlan Cox * Base + 0x1E AltStatus 3551dbd490SAlan Cox * Base + 0x1F timing register 3651dbd490SAlan Cox */ 3751dbd490SAlan Cox 3851dbd490SAlan Cox #include <linux/kernel.h> 3951dbd490SAlan Cox #include <linux/module.h> 4051dbd490SAlan Cox #include <linux/pci.h> 4151dbd490SAlan Cox #include <linux/blkdev.h> 4251dbd490SAlan Cox #include <linux/delay.h> 4351dbd490SAlan Cox #include <scsi/scsi_host.h> 4451dbd490SAlan Cox #include <linux/libata.h> 4551dbd490SAlan Cox 4651dbd490SAlan Cox #define DRV_NAME "pata_ninja32" 47e3cf95ddSAlan Cox #define DRV_VERSION "0.1.5" 4851dbd490SAlan Cox 4951dbd490SAlan Cox 5051dbd490SAlan Cox /** 5151dbd490SAlan Cox * ninja32_set_piomode - set initial PIO mode data 5251dbd490SAlan Cox * @ap: ATA interface 5351dbd490SAlan Cox * @adev: ATA device 5451dbd490SAlan Cox * 5551dbd490SAlan Cox * Called to do the PIO mode setup. Our timing registers are shared 5651dbd490SAlan Cox * but we want to set the PIO timing by default. 5751dbd490SAlan Cox */ 5851dbd490SAlan Cox 5951dbd490SAlan Cox static void ninja32_set_piomode(struct ata_port *ap, struct ata_device *adev) 6051dbd490SAlan Cox { 6151dbd490SAlan Cox static u16 pio_timing[5] = { 6251dbd490SAlan Cox 0xd6, 0x85, 0x44, 0x33, 0x13 6351dbd490SAlan Cox }; 6411b7beccSJeff Garzik iowrite8(pio_timing[adev->pio_mode - XFER_PIO_0], 6511b7beccSJeff Garzik ap->ioaddr.bmdma_addr + 0x1f); 6651dbd490SAlan Cox ap->private_data = adev; 6751dbd490SAlan Cox } 6851dbd490SAlan Cox 6951dbd490SAlan Cox 7051dbd490SAlan Cox static void ninja32_dev_select(struct ata_port *ap, unsigned int device) 7151dbd490SAlan Cox { 7251dbd490SAlan Cox struct ata_device *adev = &ap->link.device[device]; 7351dbd490SAlan Cox if (ap->private_data != adev) { 7451dbd490SAlan Cox iowrite8(0xd6, ap->ioaddr.bmdma_addr + 0x1f); 759363c382STejun Heo ata_sff_dev_select(ap, device); 7651dbd490SAlan Cox ninja32_set_piomode(ap, adev); 7751dbd490SAlan Cox } 7851dbd490SAlan Cox } 7951dbd490SAlan Cox 8051dbd490SAlan Cox static struct scsi_host_template ninja32_sht = { 8168d1d07bSTejun Heo ATA_BMDMA_SHT(DRV_NAME), 8251dbd490SAlan Cox }; 8351dbd490SAlan Cox 8451dbd490SAlan Cox static struct ata_port_operations ninja32_port_ops = { 85029cfd6bSTejun Heo .inherits = &ata_bmdma_port_ops, 865682ed33STejun Heo .sff_dev_select = ninja32_dev_select, 8751dbd490SAlan Cox .cable_detect = ata_cable_40wire, 88029cfd6bSTejun Heo .set_piomode = ninja32_set_piomode, 89e3cf95ddSAlan Cox .sff_data_xfer = ata_sff_data_xfer32 9051dbd490SAlan Cox }; 9151dbd490SAlan Cox 92e7c0d217SAlan Cox static void ninja32_program(void __iomem *base) 93e7c0d217SAlan Cox { 94e7c0d217SAlan Cox iowrite8(0x05, base + 0x01); /* Enable interrupt lines */ 95e7c0d217SAlan Cox iowrite8(0xBE, base + 0x02); /* Burst, ?? setup */ 96e7c0d217SAlan Cox iowrite8(0x01, base + 0x03); /* Unknown */ 97e7c0d217SAlan Cox iowrite8(0x20, base + 0x04); /* WAIT0 */ 98e7c0d217SAlan Cox iowrite8(0x8f, base + 0x05); /* Unknown */ 99e7c0d217SAlan Cox iowrite8(0xa4, base + 0x1c); /* Unknown */ 100e7c0d217SAlan Cox iowrite8(0x83, base + 0x1d); /* BMDMA control: WAIT0 */ 101e7c0d217SAlan Cox } 102e7c0d217SAlan Cox 10351dbd490SAlan Cox static int ninja32_init_one(struct pci_dev *dev, const struct pci_device_id *id) 10451dbd490SAlan Cox { 10551dbd490SAlan Cox struct ata_host *host; 10651dbd490SAlan Cox struct ata_port *ap; 10751dbd490SAlan Cox void __iomem *base; 10851dbd490SAlan Cox int rc; 10951dbd490SAlan Cox 11051dbd490SAlan Cox host = ata_host_alloc(&dev->dev, 1); 11151dbd490SAlan Cox if (!host) 11251dbd490SAlan Cox return -ENOMEM; 11351dbd490SAlan Cox ap = host->ports[0]; 11451dbd490SAlan Cox 11551dbd490SAlan Cox /* Set up the PCI device */ 11651dbd490SAlan Cox rc = pcim_enable_device(dev); 11751dbd490SAlan Cox if (rc) 11851dbd490SAlan Cox return rc; 11951dbd490SAlan Cox rc = pcim_iomap_regions(dev, 1 << 0, DRV_NAME); 12051dbd490SAlan Cox if (rc == -EBUSY) 12151dbd490SAlan Cox pcim_pin_device(dev); 12251dbd490SAlan Cox if (rc) 12351dbd490SAlan Cox return rc; 12451dbd490SAlan Cox 12551dbd490SAlan Cox host->iomap = pcim_iomap_table(dev); 126*b5e55556SChristoph Hellwig rc = dma_set_mask_and_coherent(&dev->dev, ATA_DMA_MASK); 12751dbd490SAlan Cox if (rc) 12851dbd490SAlan Cox return rc; 12951dbd490SAlan Cox pci_set_master(dev); 13051dbd490SAlan Cox 131b604958aSAlan Cox /* Set up the register mappings. We use the I/O mapping as only the 132b604958aSAlan Cox older chips also have MMIO on BAR 1 */ 13351dbd490SAlan Cox base = host->iomap[0]; 13451dbd490SAlan Cox if (!base) 13551dbd490SAlan Cox return -ENOMEM; 13651dbd490SAlan Cox ap->ops = &ninja32_port_ops; 13714bdef98SErik Inge Bolsø ap->pio_mask = ATA_PIO4; 13851dbd490SAlan Cox ap->flags |= ATA_FLAG_SLAVE_POSS; 13951dbd490SAlan Cox 14051dbd490SAlan Cox ap->ioaddr.cmd_addr = base + 0x10; 14151dbd490SAlan Cox ap->ioaddr.ctl_addr = base + 0x1E; 14251dbd490SAlan Cox ap->ioaddr.altstatus_addr = base + 0x1E; 14351dbd490SAlan Cox ap->ioaddr.bmdma_addr = base; 1449363c382STejun Heo ata_sff_std_ports(&ap->ioaddr); 1459ebae9e4SAlan Cox ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE; 14651dbd490SAlan Cox 147e7c0d217SAlan Cox ninja32_program(base); 14851dbd490SAlan Cox /* FIXME: Should we disable them at remove ? */ 149c3b28894STejun Heo return ata_host_activate(host, dev->irq, ata_bmdma_interrupt, 15011b7beccSJeff Garzik IRQF_SHARED, &ninja32_sht); 15151dbd490SAlan Cox } 15251dbd490SAlan Cox 15358eb8cd5SBartlomiej Zolnierkiewicz #ifdef CONFIG_PM_SLEEP 154e7c0d217SAlan Cox static int ninja32_reinit_one(struct pci_dev *pdev) 155e7c0d217SAlan Cox { 1560a86e1c8SJingoo Han struct ata_host *host = pci_get_drvdata(pdev); 157e7c0d217SAlan Cox int rc; 158e7c0d217SAlan Cox 159e7c0d217SAlan Cox rc = ata_pci_device_do_resume(pdev); 160e7c0d217SAlan Cox if (rc) 161e7c0d217SAlan Cox return rc; 162e7c0d217SAlan Cox ninja32_program(host->iomap[0]); 163e7c0d217SAlan Cox ata_host_resume(host); 164e7c0d217SAlan Cox return 0; 165e7c0d217SAlan Cox } 166e7c0d217SAlan Cox #endif 167e7c0d217SAlan Cox 16851dbd490SAlan Cox static const struct pci_device_id ninja32[] = { 169b604958aSAlan Cox { 0x10FC, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 170b604958aSAlan Cox { 0x1145, 0x8008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 171b604958aSAlan Cox { 0x1145, 0xf008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 17251dbd490SAlan Cox { 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 17351dbd490SAlan Cox { 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 174b604958aSAlan Cox { 0x1145, 0xf02C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 17551dbd490SAlan Cox { }, 17651dbd490SAlan Cox }; 17751dbd490SAlan Cox 17851dbd490SAlan Cox static struct pci_driver ninja32_pci_driver = { 17951dbd490SAlan Cox .name = DRV_NAME, 18051dbd490SAlan Cox .id_table = ninja32, 18151dbd490SAlan Cox .probe = ninja32_init_one, 182e7c0d217SAlan Cox .remove = ata_pci_remove_one, 18358eb8cd5SBartlomiej Zolnierkiewicz #ifdef CONFIG_PM_SLEEP 184e7c0d217SAlan Cox .suspend = ata_pci_device_suspend, 185e7c0d217SAlan Cox .resume = ninja32_reinit_one, 186e7c0d217SAlan Cox #endif 18751dbd490SAlan Cox }; 18851dbd490SAlan Cox 1892fc75da0SAxel Lin module_pci_driver(ninja32_pci_driver); 19051dbd490SAlan Cox 19151dbd490SAlan Cox MODULE_AUTHOR("Alan Cox"); 19251dbd490SAlan Cox MODULE_DESCRIPTION("low-level driver for Ninja32 ATA"); 19351dbd490SAlan Cox MODULE_LICENSE("GPL"); 19451dbd490SAlan Cox MODULE_DEVICE_TABLE(pci, ninja32); 19551dbd490SAlan Cox MODULE_VERSION(DRV_VERSION); 196