예제 #1
0
static int __devinit mdm6600_probe(struct platform_device *pdev)
{
	struct mdm6600_agent_platform_data *pdata = pdev->dev.platform_data;

	dev_info(&pdev->dev, "mdm6600_probe");

	pr_debug("%s: radio_cdev = %p\n", __func__, &radio_cdev);

	working_queue = create_singlethread_workqueue("mdm6600_agent_wq");
	if (!working_queue) {
		dev_err(&pdev->dev, "Cannot create work queue.");
		return -1;
	}
	INIT_WORK(&bp_change_work, bp_change_worker);

	if (radio_dev_register(&radio_cdev)) {
		pr_err("%s: failed to register mdm6600_ctrl_agent device\n",
			__func__);
		goto fail;
	}

	/*
	 * Register for callbacks for BP events.
	 */
	if (pdata->mdm_ctrl_agent_register)
		pdata->mdm_ctrl_agent_register(on_bp_change);

	on_bp_change(0, 0);

	return 0;

fail:
	destroy_workqueue(working_queue);

	return -1;
}
static int __devinit wrigley_probe(struct platform_device *pdev)
{
	struct wrigley_ctrl_platform_data *pdata = pdev->dev.platform_data;
	struct wrigley_info *info;
	int reset_irq, err = 0;

	pr_info("%s: %s\n", __func__, dev_name(&pdev->dev));
	info = kzalloc(sizeof(struct wrigley_info), GFP_KERNEL);
	if (!info) {
		err = -ENOMEM;
		goto err_exit;
	}

	platform_set_drvdata(pdev, info);

	/* setup radio_class device */
	info->rdev.name = dev_name(&pdev->dev);
	info->rdev.status = wrigley_status_show;
	info->rdev.command = wrigley_command;

	mutex_init(&info->sysfs_lock);

	/* disable */
	pr_debug("%s: setup wrigley_disable\n", __func__);
	info->disable_gpio = pdata->gpio_disable;
	snprintf(info->disable_name, GPIO_MAX_NAME, "%s-%s",
		dev_name(&pdev->dev), "disable");
	err = gpio_request(info->disable_gpio, info->disable_name);
	if (err) {
		pr_err("%s: err_disable\n", __func__);
		goto err_disable;
	}
	gpio_export(info->disable_gpio, false);

	/* reset */
	pr_debug("%s: setup wrigley_reset\n", __func__);

	INIT_DELAYED_WORK(&info->work, wrigley_detect_off);
	info->handle_radio_off = pdata->handle_radio_off;
	init_completion(&info->pwrup_complete);
	init_completion(&info->pwrdn_complete);
	info->reset_gpio = pdata->gpio_reset;
	snprintf(info->reset_name, GPIO_MAX_NAME, "%s-%s",
		dev_name(&pdev->dev), "reset");
	err = gpio_request(info->reset_gpio, info->reset_name);
	if (err) {
		pr_err("%s: err requesting reset gpio\n", __func__);
		goto err_reset;
	}
	gpio_direction_input(info->reset_gpio);
	reset_irq = gpio_to_irq(info->reset_gpio);
	err = request_threaded_irq(reset_irq, wrigley_reset_isr,
		wrigley_reset_fn, IRQ_TYPE_EDGE_BOTH, info->reset_name,
		info);
	if (err) {
		pr_err("%s: request irq (%d) %s failed\n",
			__func__, reset_irq, info->reset_name);
		gpio_free(info->reset_gpio);
		goto err_reset;
	}
	gpio_export(info->reset_gpio, false);

	/* force_flash */
	pr_debug("%s: setup wrigley_force_flash\n", __func__);
	info->flash_gpio = pdata->gpio_force_flash;
	snprintf(info->flash_name, GPIO_MAX_NAME, "%s-%s",
		dev_name(&pdev->dev), "flash");
	err = gpio_request(info->flash_gpio, info->flash_name);
	if (err) {
		pr_err("%s: error requesting flash gpio\n", __func__);
		goto err_flash;
	}
	gpio_export(info->flash_gpio, false);

	/* try to determine the boot up mode of the device */
	info->boot_flash = !!gpio_get_value(info->flash_gpio);
	if (gpio_get_value(info->reset_gpio))
		wrigley_set_status(info, wrigley_get_on_status(info));
	else
		wrigley_set_status(info, WRIGLEY_STATUS_OFF);

	pr_debug("%s: initial status = %s\n", __func__,
		wrigley_status_str[info->status]);

	err = radio_dev_register(&info->rdev);
	if (err) {
		pr_err("%s: failed to register radio device\n", __func__);
		goto err_dev_register;
	}

	return 0;

err_dev_register:
	gpio_free(info->flash_gpio);
err_flash:
	free_irq(reset_irq, info);
	gpio_free(info->reset_gpio);
err_reset:
	gpio_free(info->disable_gpio);
err_disable:
	platform_set_drvdata(pdev, NULL);
	kfree(info);
err_exit:
	return err;
}