^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * This file provides autodetection for ISA PnP IDE interfaces.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * It was tested with "ESS ES1868 Plug and Play AudioDrive" IDE interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 Andrey Panin <pazke@donpac.ru>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/pnp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/ide.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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define DRV_NAME "ide-pnp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /* Add your devices here :)) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static const struct pnp_device_id idepnp_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* Generic ESDI/IDE/ATA compatible hard disk controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) {.id = "PNP0600", .driver_data = 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {.id = ""}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static const struct ide_port_info ide_pnp_port_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) .host_flags = IDE_HFLAG_NO_DMA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .chipset = ide_generic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static int idepnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct ide_host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) unsigned long base, ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct ide_hw hw, *hws[] = { &hw };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) printk(KERN_INFO DRV_NAME ": generic PnP IDE interface\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (!(pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) && pnp_irq_valid(dev, 0)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) base = pnp_port_start(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ctl = pnp_port_start(dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (!request_region(base, 8, DRV_NAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) DRV_NAME, base, base + 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (!request_region(ctl, 1, DRV_NAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) printk(KERN_ERR "%s: I/O resource 0x%lX not free.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) DRV_NAME, ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) release_region(base, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) memset(&hw, 0, sizeof(hw));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ide_std_init_ports(&hw, base, ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) hw.irq = pnp_irq(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) rc = ide_host_add(&ide_pnp_port_info, hws, 1, &host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) pnp_set_drvdata(dev, host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) release_region(ctl, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) release_region(base, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static void idepnp_remove(struct pnp_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct ide_host *host = pnp_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) ide_host_remove(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) release_region(pnp_port_start(dev, 1), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) release_region(pnp_port_start(dev, 0), 8);
^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) static struct pnp_driver idepnp_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .name = "ide",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .id_table = idepnp_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .probe = idepnp_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .remove = idepnp_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) module_pnp_driver(idepnp_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) MODULE_LICENSE("GPL");