^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * pata-isapnp.c - ISA PnP PATA controller driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2005/2006 Red Hat Inc, all rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Based in part on ide-pnp.c by Andrey Panin <pazke@donpac.ru>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/isapnp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/init.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 <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/ata.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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define DRV_NAME "pata_isapnp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define DRV_VERSION "0.2.5"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static struct scsi_host_template isapnp_sht = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) ATA_PIO_SHT(DRV_NAME),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static struct ata_port_operations isapnp_port_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) .inherits = &ata_sff_port_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) .cable_detect = ata_cable_40wire,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static struct ata_port_operations isapnp_noalt_port_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) .inherits = &ata_sff_port_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .cable_detect = ata_cable_40wire,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* No altstatus so we don't want to use the lost interrupt poll */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .lost_interrupt = ATA_OP_NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * isapnp_init_one - attach an isapnp interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * @idev: PnP device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * @dev_id: matching detect line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * Register an ISA bus IDE interface. Such interfaces are PIO 0 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * non shared IRQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct ata_host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct ata_port *ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) void __iomem *cmd_addr, *ctl_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int irq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) irq_handler_t handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (pnp_port_valid(idev, 0) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (pnp_irq_valid(idev, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) irq = pnp_irq(idev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) handler = ata_sff_interrupt;
^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) /* allocate host */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) host = ata_host_alloc(&idev->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (!host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* acquire resources and fill host */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (!cmd_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ap = host->ports[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ap->ops = &isapnp_noalt_port_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ap->pio_mask = ATA_PIO0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) ap->flags |= ATA_FLAG_SLAVE_POSS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ap->ioaddr.cmd_addr = cmd_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (pnp_port_valid(idev, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ctl_addr = devm_ioport_map(&idev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) pnp_port_start(idev, 1), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ap->ioaddr.altstatus_addr = ctl_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ap->ioaddr.ctl_addr = ctl_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ap->ops = &isapnp_port_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) ata_sff_std_ports(&ap->ioaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) (unsigned long long)pnp_port_start(idev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) (unsigned long long)pnp_port_start(idev, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* activate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return ata_host_activate(host, irq, handler, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) &isapnp_sht);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * isapnp_remove_one - unplug an isapnp interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * @idev: PnP device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * Remove a previously configured PnP ATA port. Called only on module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * unload events as the core does not currently deal with ISAPnP docking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static void isapnp_remove_one(struct pnp_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct device *dev = &idev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct ata_host *host = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ata_host_detach(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static struct pnp_device_id isapnp_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* Generic ESDI/IDE/ATA compatible hard disk controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {.id = "PNP0600", .driver_data = 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {.id = ""}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) MODULE_DEVICE_TABLE(pnp, isapnp_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static struct pnp_driver isapnp_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .name = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) .id_table = isapnp_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .probe = isapnp_init_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .remove = isapnp_remove_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) module_pnp_driver(isapnp_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) MODULE_AUTHOR("Alan Cox");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) MODULE_VERSION(DRV_VERSION);