Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * pata-isapnp.c - ISA PnP PATA controller driver. |
| 4 | * Copyright 2005/2006 Red Hat Inc <alan@redhat.com>, all rights reserved. |
| 5 | * |
| 6 | * Based in part on ide-pnp.c by Andrey Panin <pazke@donpac.ru> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/isapnp.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/blkdev.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <scsi/scsi_host.h> |
| 16 | #include <linux/ata.h> |
| 17 | #include <linux/libata.h> |
| 18 | |
| 19 | #define DRV_NAME "pata_isapnp" |
Jeff Garzik | 8bc3fc4 | 2007-05-21 20:26:38 -0400 | [diff] [blame] | 20 | #define DRV_VERSION "0.2.1" |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 21 | |
| 22 | static struct scsi_host_template isapnp_sht = { |
| 23 | .module = THIS_MODULE, |
| 24 | .name = DRV_NAME, |
| 25 | .ioctl = ata_scsi_ioctl, |
| 26 | .queuecommand = ata_scsi_queuecmd, |
| 27 | .can_queue = ATA_DEF_QUEUE, |
| 28 | .this_id = ATA_SHT_THIS_ID, |
| 29 | .sg_tablesize = LIBATA_MAX_PRD, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 30 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, |
| 31 | .emulated = ATA_SHT_EMULATED, |
| 32 | .use_clustering = ATA_SHT_USE_CLUSTERING, |
| 33 | .proc_name = DRV_NAME, |
| 34 | .dma_boundary = ATA_DMA_BOUNDARY, |
| 35 | .slave_configure = ata_scsi_slave_config, |
Tejun Heo | afdfe89 | 2006-11-29 11:26:47 +0900 | [diff] [blame] | 36 | .slave_destroy = ata_scsi_slave_destroy, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 37 | .bios_param = ata_std_bios_param, |
| 38 | }; |
| 39 | |
| 40 | static struct ata_port_operations isapnp_port_ops = { |
| 41 | .port_disable = ata_port_disable, |
| 42 | .tf_load = ata_tf_load, |
| 43 | .tf_read = ata_tf_read, |
| 44 | .check_status = ata_check_status, |
| 45 | .exec_command = ata_exec_command, |
| 46 | .dev_select = ata_std_dev_select, |
| 47 | |
| 48 | .freeze = ata_bmdma_freeze, |
| 49 | .thaw = ata_bmdma_thaw, |
| 50 | .error_handler = ata_bmdma_error_handler, |
| 51 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
Jeff Garzik | a73984a | 2007-03-09 08:37:46 -0500 | [diff] [blame] | 52 | .cable_detect = ata_cable_40wire, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 53 | |
| 54 | .qc_prep = ata_qc_prep, |
| 55 | .qc_issue = ata_qc_issue_prot, |
Jeff Garzik | bda3028 | 2006-09-27 05:41:13 -0400 | [diff] [blame] | 56 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 57 | .data_xfer = ata_data_xfer, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 58 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 59 | .irq_clear = ata_bmdma_irq_clear, |
Akira Iguchi | 246ce3b | 2007-01-26 16:27:58 +0900 | [diff] [blame] | 60 | .irq_on = ata_irq_on, |
| 61 | .irq_ack = ata_irq_ack, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 62 | |
| 63 | .port_start = ata_port_start, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * isapnp_init_one - attach an isapnp interface |
| 68 | * @idev: PnP device |
| 69 | * @dev_id: matching detect line |
| 70 | * |
| 71 | * Register an ISA bus IDE interface. Such interfaces are PIO 0 and |
| 72 | * non shared IRQ. |
| 73 | */ |
| 74 | |
| 75 | static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id) |
| 76 | { |
Tejun Heo | 5d72882 | 2007-04-17 23:44:08 +0900 | [diff] [blame] | 77 | struct ata_host *host; |
| 78 | struct ata_port *ap; |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 79 | void __iomem *cmd_addr, *ctl_addr; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 80 | |
| 81 | if (pnp_port_valid(idev, 0) == 0) |
| 82 | return -ENODEV; |
| 83 | |
| 84 | /* FIXME: Should selected polled PIO here not fail */ |
| 85 | if (pnp_irq_valid(idev, 0) == 0) |
| 86 | return -ENODEV; |
| 87 | |
Tejun Heo | 5d72882 | 2007-04-17 23:44:08 +0900 | [diff] [blame] | 88 | /* allocate host */ |
| 89 | host = ata_host_alloc(&idev->dev, 1); |
| 90 | if (!host) |
| 91 | return -ENOMEM; |
| 92 | |
| 93 | /* acquire resources and fill host */ |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 94 | cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8); |
| 95 | if (!cmd_addr) |
| 96 | return -ENOMEM; |
| 97 | |
Tejun Heo | 5d72882 | 2007-04-17 23:44:08 +0900 | [diff] [blame] | 98 | ap = host->ports[0]; |
| 99 | |
| 100 | ap->ops = &isapnp_port_ops; |
| 101 | ap->pio_mask = 1; |
| 102 | ap->flags |= ATA_FLAG_SLAVE_POSS; |
| 103 | |
| 104 | ap->ioaddr.cmd_addr = cmd_addr; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 105 | |
| 106 | if (pnp_port_valid(idev, 1) == 0) { |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 107 | ctl_addr = devm_ioport_map(&idev->dev, |
| 108 | pnp_port_start(idev, 1), 1); |
Tejun Heo | 5d72882 | 2007-04-17 23:44:08 +0900 | [diff] [blame] | 109 | ap->ioaddr.altstatus_addr = ctl_addr; |
| 110 | ap->ioaddr.ctl_addr = ctl_addr; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 111 | } |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 112 | |
Tejun Heo | 5d72882 | 2007-04-17 23:44:08 +0900 | [diff] [blame] | 113 | ata_std_ports(&ap->ioaddr); |
| 114 | |
| 115 | /* activate */ |
| 116 | return ata_host_activate(host, pnp_irq(idev, 0), ata_interrupt, 0, |
| 117 | &isapnp_sht); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** |
| 121 | * isapnp_remove_one - unplug an isapnp interface |
| 122 | * @idev: PnP device |
| 123 | * |
| 124 | * Remove a previously configured PnP ATA port. Called only on module |
| 125 | * unload events as the core does not currently deal with ISAPnP docking. |
| 126 | */ |
| 127 | |
| 128 | static void isapnp_remove_one(struct pnp_dev *idev) |
| 129 | { |
| 130 | struct device *dev = &idev->dev; |
| 131 | struct ata_host *host = dev_get_drvdata(dev); |
| 132 | |
Tejun Heo | 24dc5f3 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 133 | ata_host_detach(host); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static struct pnp_device_id isapnp_devices[] = { |
| 137 | /* Generic ESDI/IDE/ATA compatible hard disk controller */ |
| 138 | {.id = "PNP0600", .driver_data = 0}, |
| 139 | {.id = ""} |
| 140 | }; |
| 141 | |
| 142 | static struct pnp_driver isapnp_driver = { |
| 143 | .name = DRV_NAME, |
| 144 | .id_table = isapnp_devices, |
| 145 | .probe = isapnp_init_one, |
| 146 | .remove = isapnp_remove_one, |
| 147 | }; |
| 148 | |
| 149 | static int __init isapnp_init(void) |
| 150 | { |
| 151 | return pnp_register_driver(&isapnp_driver); |
| 152 | } |
| 153 | |
| 154 | static void __exit isapnp_exit(void) |
| 155 | { |
| 156 | pnp_unregister_driver(&isapnp_driver); |
| 157 | } |
| 158 | |
| 159 | MODULE_AUTHOR("Alan Cox"); |
| 160 | MODULE_DESCRIPTION("low-level driver for ISA PnP ATA"); |
| 161 | MODULE_LICENSE("GPL"); |
| 162 | MODULE_VERSION(DRV_VERSION); |
| 163 | |
| 164 | module_init(isapnp_init); |
| 165 | module_exit(isapnp_exit); |