Example #1
0
/**
 *	pata_platform_probe		-	attach a platform interface
 *	@pdev: platform device
 *
 *	Register a platform bus IDE interface. Such interfaces are PIO and we
 *	assume do not support IRQ sharing.
 *
 *	Platform devices are expected to contain at least 2 resources per port:
 *
 *		- I/O Base (IORESOURCE_IO or IORESOURCE_MEM)
 *		- CTL Base (IORESOURCE_IO or IORESOURCE_MEM)
 *
 *	and optionally:
 *
 *		- IRQ	   (IORESOURCE_IRQ)
 *
 *	If the base resources are both mem types, the ioremap() is handled
 *	here. For IORESOURCE_IO, it's assumed that there's no remapping
 *	necessary.
 *
 *	If no IRQ resource is present, PIO polling mode is used instead.
 */
static int __devinit pata_platform_probe(struct platform_device *pdev)
{
	struct resource *io_res, *ctl_res;
	struct ata_host *host;
	struct ata_port *ap;
	struct pata_platform_info *pp_info;
	unsigned int mmio;
	int irq;

	/*
	 * Simple resource validation ..
	 */
	if ((pdev->num_resources != 3) && (pdev->num_resources != 2)) {
		dev_err(&pdev->dev, "invalid number of resources\n");
		return -EINVAL;
	}

	/*
	 * Get the I/O base first
	 */
	io_res = platform_get_resource(pdev, IORESOURCE_IO, 0);
	if (io_res == NULL) {
		io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
		if (unlikely(io_res == NULL))
			return -EINVAL;
	}

	/*
	 * Then the CTL base
	 */
	ctl_res = platform_get_resource(pdev, IORESOURCE_IO, 1);
	if (ctl_res == NULL) {
		ctl_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
		if (unlikely(ctl_res == NULL))
			return -EINVAL;
	}

	/*
	 * Check for MMIO
	 */
	mmio = (( io_res->flags == IORESOURCE_MEM) &&
		(ctl_res->flags == IORESOURCE_MEM));

	/*
	 * And the IRQ
	 */
	irq = platform_get_irq(pdev, 0);
	if (irq < 0)
		irq = 0;	/* no irq */

	/*
	 * Now that that's out of the way, wire up the port..
	 */
	host = ata_host_alloc(&pdev->dev, 1);
	if (!host)
		return -ENOMEM;
	ap = host->ports[0];

	ap->ops = &pata_platform_port_ops;
	ap->pio_mask = pio_mask;
	ap->flags |= ATA_FLAG_SLAVE_POSS;

	/*
	 * Use polling mode if there's no IRQ
	 */
	if (!irq) {
		ap->flags |= ATA_FLAG_PIO_POLLING;
		ata_port_desc(ap, "no IRQ, using PIO polling");
	}

	/*
	 * Handle the MMIO case
	 */
	if (mmio) {
		ap->ioaddr.cmd_addr = devm_ioremap(&pdev->dev, io_res->start,
				io_res->end - io_res->start + 1);
		ap->ioaddr.ctl_addr = devm_ioremap(&pdev->dev, ctl_res->start,
				ctl_res->end - ctl_res->start + 1);
	} else {
		ap->ioaddr.cmd_addr = devm_ioport_map(&pdev->dev, io_res->start,
				io_res->end - io_res->start + 1);
		ap->ioaddr.ctl_addr = devm_ioport_map(&pdev->dev, ctl_res->start,
				ctl_res->end - ctl_res->start + 1);
	}
	if (!ap->ioaddr.cmd_addr || !ap->ioaddr.ctl_addr) {
		dev_err(&pdev->dev, "failed to map IO/CTL base\n");
		return -ENOMEM;
	}

	ap->ioaddr.altstatus_addr = ap->ioaddr.ctl_addr;

	pp_info = pdev->dev.platform_data;
	pata_platform_setup_port(&ap->ioaddr, pp_info);

	ata_port_desc(ap, "%s cmd 0x%llx ctl 0x%llx", mmio ? "mmio" : "ioport",
		      (unsigned long long)io_res->start,
		      (unsigned long long)ctl_res->start);

	/* activate */
	return ata_host_activate(host, irq, irq ? ata_interrupt : NULL,
				 pp_info ? pp_info->irq_flags : 0,
				 &pata_platform_sht);
}
Example #2
0
/**
 *    __pata_platform_probe        -    attach a platform interface
 *    @dev: device
 *    @io_res: Resource representing I/O base
 *    @ctl_res: Resource representing CTL base
 *    @irq_res: Resource representing IRQ and its flags
 *    @ioport_shift: I/O port shift
 *    @__pio_mask: PIO mask
 *
 *    Register a platform bus IDE interface. Such interfaces are PIO and we
 *    assume do not support IRQ sharing.
 *
 *    Platform devices are expected to contain at least 2 resources per port:
 *
 *        - I/O Base (IORESOURCE_IO or IORESOURCE_MEM)
 *        - CTL Base (IORESOURCE_IO or IORESOURCE_MEM)
 *
 *    and optionally:
 *
 *        - IRQ       (IORESOURCE_IRQ)
 *
 *    If the base resources are both mem types, the ioremap() is handled
 *    here. For IORESOURCE_IO, it's assumed that there's no remapping
 *    necessary.
 *
 *    If no IRQ resource is present, PIO polling mode is used instead.
 */
int __devinit __pata_platform_probe(struct device *dev,
                    struct resource *io_res,
                    struct resource *ctl_res,
                    struct resource *irq_res,
                    unsigned int ioport_shift,
                    int __pio_mask)
{
    struct ata_host *host;
    struct ata_port *ap;
    unsigned int mmio;
    int irq = 0;
    int irq_flags = 0;

    /*
     * Check for MMIO
     */
    mmio = (( io_res->flags == IORESOURCE_MEM) &&
        (ctl_res->flags == IORESOURCE_MEM));

    /*
     * And the IRQ
     */
    if (irq_res && irq_res->start > 0) {
        irq = irq_res->start;
        irq_flags = irq_res->flags;
    }

    /*
     * Now that that's out of the way, wire up the port..
     */
    host = ata_host_alloc(dev, 1);
    if (!host)
        return -ENOMEM;
    ap = host->ports[0];

    ap->ops = &pata_platform_port_ops;
    ap->pio_mask = __pio_mask;
    ap->flags |= ATA_FLAG_SLAVE_POSS;

    /*
     * Use polling mode if there's no IRQ
     */
    if (!irq) {
        ap->flags |= ATA_FLAG_PIO_POLLING;
        ata_port_desc(ap, "no IRQ, using PIO polling");
    }

    /*
     * Handle the MMIO case
     */
    if (mmio) {
        ap->ioaddr.cmd_addr = devm_ioremap(dev, io_res->start,
                io_res->end - io_res->start + 1);
        ap->ioaddr.ctl_addr = devm_ioremap(dev, ctl_res->start,
                ctl_res->end - ctl_res->start + 1);
    } else {
        ap->ioaddr.cmd_addr = devm_ioport_map(dev, io_res->start,
                io_res->end - io_res->start + 1);
        ap->ioaddr.ctl_addr = devm_ioport_map(dev, ctl_res->start,
                ctl_res->end - ctl_res->start + 1);
    }
    if (!ap->ioaddr.cmd_addr || !ap->ioaddr.ctl_addr) {
        dev_err(dev, "failed to map IO/CTL base\n");
        return -ENOMEM;
    }

    ap->ioaddr.altstatus_addr = ap->ioaddr.ctl_addr;

    pata_platform_setup_port(&ap->ioaddr, ioport_shift);

    ata_port_desc(ap, "%s cmd 0x%llx ctl 0x%llx", mmio ? "mmio" : "ioport",
              (unsigned long long)io_res->start,
              (unsigned long long)ctl_res->start);

    /* activate */
    return ata_host_activate(host, irq, irq ? ata_sff_interrupt : NULL,
                 irq_flags, &pata_platform_sht);
}
Example #3
0
/**
 *	pata_platform_probe		-	attach a platform interface
 *	@pdev: platform device
 *
 *	Register a platform bus IDE interface. Such interfaces are PIO and we
 *	assume do not support IRQ sharing.
 *
 *	Platform devices are expected to contain 3 resources per port:
 *
 *		- I/O Base (IORESOURCE_IO or IORESOURCE_MEM)
 *		- CTL Base (IORESOURCE_IO or IORESOURCE_MEM)
 *		- IRQ	   (IORESOURCE_IRQ)
 *
 *	If the base resources are both mem types, the ioremap() is handled
 *	here. For IORESOURCE_IO, it's assumed that there's no remapping
 *	necessary.
 */
static int __devinit pata_platform_probe(struct platform_device *pdev)
{
	struct resource *io_res, *ctl_res;
	struct ata_host *host;
	struct ata_port *ap;
	struct pata_platform_info *pp_info;
	unsigned int mmio;

	/*
	 * Simple resource validation ..
	 */
	if (unlikely(pdev->num_resources != 3)) {
		dev_err(&pdev->dev, "invalid number of resources\n");
		return -EINVAL;
	}

	/*
	 * Get the I/O base first
	 */
	io_res = platform_get_resource(pdev, IORESOURCE_IO, 0);
	if (io_res == NULL) {
		io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
		if (unlikely(io_res == NULL))
			return -EINVAL;
	}

	/*
	 * Then the CTL base
	 */
	ctl_res = platform_get_resource(pdev, IORESOURCE_IO, 1);
	if (ctl_res == NULL) {
		ctl_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
		if (unlikely(ctl_res == NULL))
			return -EINVAL;
	}

	/*
	 * Check for MMIO
	 */
	mmio = (( io_res->flags == IORESOURCE_MEM) &&
		(ctl_res->flags == IORESOURCE_MEM));

	/*
	 * Now that that's out of the way, wire up the port..
	 */
	host = ata_host_alloc(&pdev->dev, 1);
	if (!host)
		return -ENOMEM;
	ap = host->ports[0];

	ap->ops = &pata_platform_port_ops;
	ap->pio_mask = pio_mask;
	ap->flags |= ATA_FLAG_SLAVE_POSS;

	/*
	 * Handle the MMIO case
	 */
	if (mmio) {
		ap->ioaddr.cmd_addr = devm_ioremap(&pdev->dev, io_res->start,
				io_res->end - io_res->start + 1);
		ap->ioaddr.ctl_addr = devm_ioremap(&pdev->dev, ctl_res->start,
				ctl_res->end - ctl_res->start + 1);
	} else {
		ap->ioaddr.cmd_addr = devm_ioport_map(&pdev->dev, io_res->start,
				io_res->end - io_res->start + 1);
		ap->ioaddr.ctl_addr = devm_ioport_map(&pdev->dev, ctl_res->start,
				ctl_res->end - ctl_res->start + 1);
	}
	if (!ap->ioaddr.cmd_addr || !ap->ioaddr.ctl_addr) {
		dev_err(&pdev->dev, "failed to map IO/CTL base\n");
		return -ENOMEM;
	}

	ap->ioaddr.altstatus_addr = ap->ioaddr.ctl_addr;

	pp_info = (struct pata_platform_info *)(pdev->dev.platform_data);
	pata_platform_setup_port(&ap->ioaddr, pp_info);

	/* activate */
	return ata_host_activate(host, platform_get_irq(pdev, 0),
				 ata_interrupt, pp_info ? pp_info->irq_flags
				 : 0, &pata_platform_sht);
}