Пример #1
0
static int __devinit pata_platform_probe(struct platform_device *pdev)
{
    struct resource *io_res;
    struct resource *ctl_res;
    struct resource *irq_res;
    struct pata_platform_info *pp_info = pdev->dev.platform_data;

    /*
     * 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;
    }

    /*
     * And the IRQ
     */
    irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
    if (irq_res)
        irq_res->flags = pp_info ? pp_info->irq_flags : 0;

    return __pata_platform_probe(&pdev->dev, io_res, ctl_res, irq_res,
                     pp_info ? pp_info->ioport_shift : 0,
                     pio_mask);
}
Пример #2
0
static int __devinit pata_of_platform_probe(struct of_device *ofdev,
					    const struct of_device_id *match)
{
	int ret;
	struct device_node *dn = ofdev->dev.of_node;
	struct resource io_res;
	struct resource ctl_res;
	struct resource irq_res;
	unsigned int reg_shift = 0;
	int pio_mode = 0;
	int pio_mask;
	const u32 *prop;

	ret = of_address_to_resource(dn, 0, &io_res);
	if (ret) {
		dev_err(&ofdev->dev, "can't get IO address from "
			"device tree\n");
		return -EINVAL;
	}

	if (of_device_is_compatible(dn, "electra-ide")) {
		/* Altstatus is really at offset 0x3f6 from the primary window
		 * on electra-ide. Adjust ctl_res and io_res accordingly.
		 */
		ctl_res = io_res;
		ctl_res.start = ctl_res.start+0x3f6;
		io_res.end = ctl_res.start-1;
	} else {
		ret = of_address_to_resource(dn, 1, &ctl_res);
		if (ret) {
			dev_err(&ofdev->dev, "can't get CTL address from "
				"device tree\n");
			return -EINVAL;
		}
	}

	ret = of_irq_to_resource(dn, 0, &irq_res);
	if (ret == NO_IRQ)
		irq_res.start = irq_res.end = 0;
	else
		irq_res.flags = 0;

	prop = of_get_property(dn, "reg-shift", NULL);
	if (prop)
		reg_shift = *prop;

	prop = of_get_property(dn, "pio-mode", NULL);
	if (prop) {
		pio_mode = *prop;
		if (pio_mode > 6) {
			dev_err(&ofdev->dev, "invalid pio-mode\n");
			return -EINVAL;
		}
	} else {
		dev_info(&ofdev->dev, "pio-mode unspecified, assuming PIO0\n");
	}

	pio_mask = 1 << pio_mode;
	pio_mask |= (1 << pio_mode) - 1;

	return __pata_platform_probe(&ofdev->dev, &io_res, &ctl_res, &irq_res,
				     reg_shift, pio_mask);
}