Пример #1
0
static int __devinit bluesleep_probe(struct platform_device *pdev)
{
    int ret;

    BT_DBG("");

    bsi = kzalloc(sizeof(struct bluesleep_info), GFP_KERNEL);
    if (!bsi) {
        ret = -ENOMEM;
        goto failed;
    }

    if (pdev->dev.of_node) {
        ret = bluesleep_populate_dt_pinfo(pdev);
        if (ret < 0) {
            BT_ERR("Failed to populate device tree info");
            goto free_bsi;
        }
    } else {
        ret = bluesleep_populate_pinfo(pdev);
        if (ret < 0) {
            BT_ERR("Failed to populate device info");
            goto free_bsi;
        }
    }

    BT_DBG("host_wake_gpio: %d ext_wake_gpio: %d",
           bsi->host_wake, bsi->ext_wake);

    bsi->host_wake_irq = platform_get_irq_byname(pdev, "host_wake");
    if (bsi->host_wake_irq < 0) {
        BT_ERR("couldn't find host_wake irq\n");
        ret = -ENODEV;
        goto free_bsi;
    }

    bsi->irq_polarity = POLARITY_LOW;	/* low edge (falling edge) */

    return 0;

free_bsi:
    kfree(bsi);
    bsi = NULL;
failed:
    return ret;
}
static int bluesleep_probe(struct platform_device *pdev)
{
	struct resource *res;
	int ret;

	bsi = kzalloc(sizeof(struct bluesleep_info), GFP_KERNEL);
	if (!bsi)
		return -ENOMEM;

	if (pdev->dev.of_node) {
		ret = bluesleep_populate_dt_pinfo(pdev);
		if (ret < 0) {
			BT_ERR("couldn't populate info from dt");
			goto free_bsi;
		}
	} else {
		ret = bluesleep_populate_pinfo(pdev);
		if (ret < 0) {
			BT_ERR("couldn't populate info");
			goto free_bsi;
		}
	}

	/* configure host_wake as input */
	ret = gpio_request_one(bsi->host_wake, GPIOF_IN, "bt_host_wake");
	if (ret < 0) {
		BT_ERR("failed to configure input"
		       " direction for GPIO %d, error %d", bsi->host_wake, ret);
		goto free_bsi;
	}

	if (debug_mask & DEBUG_BTWAKE)
		pr_info("BT WAKE: set to wake\n");
	if (bsi->has_ext_wake) {
		/* configure ext_wake as output mode */
		ret =
		    gpio_request_one(bsi->ext_wake, GPIOF_OUT_INIT_LOW,
				     "bt_ext_wake");
		if (ret < 0) {
			BT_ERR("failed to configure output"
			       " direction for GPIO %d, error %d",
			       bsi->ext_wake, ret);
			goto free_bt_host_wake;
		}
	}
	clear_bit(BT_EXT_WAKE, &flags);

	res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "host_wake");
	if (!res) {
		BT_ERR("couldn't find host_wake irq");
		ret = -ENODEV;
		goto free_bt_host_wake;
	}
	bsi->host_wake_irq = res->start;
	if (bsi->host_wake_irq < 0) {
		BT_ERR("couldn't find host_wake irq");
		ret = -ENODEV;
		goto free_bt_ext_wake;
	}

	bsi->irq_polarity = POLARITY_LOW;	/*low edge (falling edge) */

	wake_lock_init(&bsi->wake_lock, WAKE_LOCK_SUSPEND, "bluesleep");
	clear_bit(BT_SUSPEND, &flags);

	BT_INFO("host_wake_irq %d, polarity %d",
		bsi->host_wake_irq, bsi->irq_polarity);

	ret = request_irq(bsi->host_wake_irq, bluesleep_hostwake_isr,
			  IRQF_DISABLED | IRQF_TRIGGER_FALLING,
			  "bluetooth hostwake", NULL);
	if (ret < 0) {
		BT_ERR("Couldn't acquire BT_HOST_WAKE IRQ");
		goto free_bt_ext_wake;
	}

	return 0;

free_bt_ext_wake:
	gpio_free(bsi->ext_wake);
free_bt_host_wake:
	gpio_free(bsi->host_wake);
free_bsi:
	kfree(bsi);

	return ret;
}