diff options
author | Tejun Heo <htejun@gmail.com> | 2007-04-17 10:44:07 -0400 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2007-04-28 14:16:03 -0400 |
commit | f5cda257296fbd3683b1f568f2d94d3caaacf74d (patch) | |
tree | a0c31206f6a7f299c11f233a22f3b8b8aa836151 /drivers/ata | |
parent | f31871951b38daf2d7ca17daad59fdb735062da3 (diff) |
libata: implement ata_host_alloc_pinfo() and ata_host_register()
Implement ata_host_alloc_pinfo() and ata_host_register(). These helpers
will be used in the following patches to adopt new init model.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/ata')
-rw-r--r-- | drivers/ata/libata-core.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index b23f35a4ee6b..ab189d3b84d3 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c | |||
@@ -5830,6 +5830,55 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports) | |||
5830 | } | 5830 | } |
5831 | 5831 | ||
5832 | /** | 5832 | /** |
5833 | * ata_host_alloc_pinfo - alloc host and init with port_info array | ||
5834 | * @dev: generic device this host is associated with | ||
5835 | * @ppi: array of ATA port_info to initialize host with | ||
5836 | * @n_ports: number of ATA ports attached to this host | ||
5837 | * | ||
5838 | * Allocate ATA host and initialize with info from @ppi. If NULL | ||
5839 | * terminated, @ppi may contain fewer entries than @n_ports. The | ||
5840 | * last entry will be used for the remaining ports. | ||
5841 | * | ||
5842 | * RETURNS: | ||
5843 | * Allocate ATA host on success, NULL on failure. | ||
5844 | * | ||
5845 | * LOCKING: | ||
5846 | * Inherited from calling layer (may sleep). | ||
5847 | */ | ||
5848 | struct ata_host *ata_host_alloc_pinfo(struct device *dev, | ||
5849 | const struct ata_port_info * const * ppi, | ||
5850 | int n_ports) | ||
5851 | { | ||
5852 | const struct ata_port_info *pi; | ||
5853 | struct ata_host *host; | ||
5854 | int i, j; | ||
5855 | |||
5856 | host = ata_host_alloc(dev, n_ports); | ||
5857 | if (!host) | ||
5858 | return NULL; | ||
5859 | |||
5860 | for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) { | ||
5861 | struct ata_port *ap = host->ports[i]; | ||
5862 | |||
5863 | if (ppi[j]) | ||
5864 | pi = ppi[j++]; | ||
5865 | |||
5866 | ap->pio_mask = pi->pio_mask; | ||
5867 | ap->mwdma_mask = pi->mwdma_mask; | ||
5868 | ap->udma_mask = pi->udma_mask; | ||
5869 | ap->flags |= pi->flags; | ||
5870 | ap->ops = pi->port_ops; | ||
5871 | |||
5872 | if (!host->ops && (pi->port_ops != &ata_dummy_port_ops)) | ||
5873 | host->ops = pi->port_ops; | ||
5874 | if (!host->private_data && pi->private_data) | ||
5875 | host->private_data = pi->private_data; | ||
5876 | } | ||
5877 | |||
5878 | return host; | ||
5879 | } | ||
5880 | |||
5881 | /** | ||
5833 | * ata_host_start - start and freeze ports of an ATA host | 5882 | * ata_host_start - start and freeze ports of an ATA host |
5834 | * @host: ATA host to start ports for | 5883 | * @host: ATA host to start ports for |
5835 | * | 5884 | * |
@@ -6042,6 +6091,48 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht) | |||
6042 | } | 6091 | } |
6043 | 6092 | ||
6044 | /** | 6093 | /** |
6094 | * ata_host_activate - start host, request IRQ and register it | ||
6095 | * @host: target ATA host | ||
6096 | * @irq: IRQ to request | ||
6097 | * @irq_handler: irq_handler used when requesting IRQ | ||
6098 | * @irq_flags: irq_flags used when requesting IRQ | ||
6099 | * @sht: scsi_host_template to use when registering the host | ||
6100 | * | ||
6101 | * After allocating an ATA host and initializing it, most libata | ||
6102 | * LLDs perform three steps to activate the host - start host, | ||
6103 | * request IRQ and register it. This helper takes necessasry | ||
6104 | * arguments and performs the three steps in one go. | ||
6105 | * | ||
6106 | * LOCKING: | ||
6107 | * Inherited from calling layer (may sleep). | ||
6108 | * | ||
6109 | * RETURNS: | ||
6110 | * 0 on success, -errno otherwise. | ||
6111 | */ | ||
6112 | int ata_host_activate(struct ata_host *host, int irq, | ||
6113 | irq_handler_t irq_handler, unsigned long irq_flags, | ||
6114 | struct scsi_host_template *sht) | ||
6115 | { | ||
6116 | int rc; | ||
6117 | |||
6118 | rc = ata_host_start(host); | ||
6119 | if (rc) | ||
6120 | return rc; | ||
6121 | |||
6122 | rc = devm_request_irq(host->dev, irq, irq_handler, irq_flags, | ||
6123 | dev_driver_string(host->dev), host); | ||
6124 | if (rc) | ||
6125 | return rc; | ||
6126 | |||
6127 | rc = ata_host_register(host, sht); | ||
6128 | /* if failed, just free the IRQ and leave ports alone */ | ||
6129 | if (rc) | ||
6130 | devm_free_irq(host->dev, irq, host); | ||
6131 | |||
6132 | return rc; | ||
6133 | } | ||
6134 | |||
6135 | /** | ||
6045 | * ata_device_add - Register hardware device with ATA and SCSI layers | 6136 | * ata_device_add - Register hardware device with ATA and SCSI layers |
6046 | * @ent: Probe information describing hardware device to be registered | 6137 | * @ent: Probe information describing hardware device to be registered |
6047 | * | 6138 | * |
@@ -6547,8 +6638,10 @@ EXPORT_SYMBOL_GPL(ata_std_bios_param); | |||
6547 | EXPORT_SYMBOL_GPL(ata_std_ports); | 6638 | EXPORT_SYMBOL_GPL(ata_std_ports); |
6548 | EXPORT_SYMBOL_GPL(ata_host_init); | 6639 | EXPORT_SYMBOL_GPL(ata_host_init); |
6549 | EXPORT_SYMBOL_GPL(ata_host_alloc); | 6640 | EXPORT_SYMBOL_GPL(ata_host_alloc); |
6641 | EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo); | ||
6550 | EXPORT_SYMBOL_GPL(ata_host_start); | 6642 | EXPORT_SYMBOL_GPL(ata_host_start); |
6551 | EXPORT_SYMBOL_GPL(ata_host_register); | 6643 | EXPORT_SYMBOL_GPL(ata_host_register); |
6644 | EXPORT_SYMBOL_GPL(ata_host_activate); | ||
6552 | EXPORT_SYMBOL_GPL(ata_device_add); | 6645 | EXPORT_SYMBOL_GPL(ata_device_add); |
6553 | EXPORT_SYMBOL_GPL(ata_host_detach); | 6646 | EXPORT_SYMBOL_GPL(ata_host_detach); |
6554 | EXPORT_SYMBOL_GPL(ata_sg_init); | 6647 | EXPORT_SYMBOL_GPL(ata_sg_init); |