コード例 #1
0
ファイル: devres.c プロジェクト: mikuhatsune001/linux2.6.32
static struct regulator *_devm_regulator_get(struct device *dev, const char *id,
					     int get_type)
{
	struct regulator **ptr, *regulator;

	ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
	if (!ptr)
		return ERR_PTR(-ENOMEM);

	switch (get_type) {
	case NORMAL_GET:
		regulator = regulator_get(dev, id);
		break;
	case EXCLUSIVE_GET:
		regulator = regulator_get_exclusive(dev, id);
		break;
	case OPTIONAL_GET:
		regulator = regulator_get_optional(dev, id);
		break;
	default:
		regulator = ERR_PTR(-EINVAL);
	}

	if (!IS_ERR(regulator)) {
		*ptr = regulator;
		devres_add(dev, ptr);
	} else {
		devres_free(ptr);
	}

	return regulator;
}
コード例 #2
0
ファイル: u2_i2c.c プロジェクト: Pesach85/lge-kernel-omap4
/*
 * general power control for device driver
 */
int device_power_control(char *reg_id, int on)
{
	struct regulator *device_regulator = NULL;
	int regulator_status = 0;
	int regulator_status_prev = 0;

	device_regulator = regulator_get_exclusive(NULL, reg_id);
	printk(KERN_INFO "power_control: device_regulator: %p",
	       device_regulator);

	if (IS_ERR(device_regulator)) {
		printk(KERN_ERR
		       "power_control: it couldn't be initialized reg_id=%s\n",
		       reg_id);
		return -1;
	}
	regulator_status_prev = regulator_is_enabled(device_regulator);
	if (regulator_status_prev < 0) {
		printk(KERN_ERR
		       "power_control: device_regulator_prev %s errno=%d\n",
		       reg_id, regulator_status_prev);
		regulator_put(device_regulator);
		return -1;
	}

	if (on) {
		if (regulator_status_prev == 0)
			regulator_enable(device_regulator);
	} else {
		if (regulator_status_prev > 0)
			regulator_disable(device_regulator);
	}

	regulator_status = regulator_is_enabled(device_regulator);
	if (regulator_status < 0) {
		printk(KERN_ERR "power_control: device_regulator %s errno=%d\n",
		       reg_id, regulator_status);
		regulator_put(device_regulator);
		return -1;
	}

	regulator_put(device_regulator);

	printk(KERN_INFO "power_control: %s : %s -> %s\n", reg_id,
	       regulator_status_prev > 0 ? "ON" : "OFF",
	       regulator_status > 0 ? "ON" : "OFF");
	return 0;
}
コード例 #3
0
ファイル: lghdk_i2c.c プロジェクト: AntonX/lge-kernel-omap4
int device_power_control(char* reg_id, int on){
	static struct regulator *device_regulator = NULL;

	device_regulator = regulator_get_exclusive(NULL, reg_id);
	if (!device_regulator) {
		printk(KERN_ERR "[POWER_CONTROL] it couldn't be initialized");
		return -1;
	}

	printk(KERN_INFO "[POWER_CONTROL] %s : %s", reg_id, on ? "ON" : "OFF");

	if(on)
		regulator_enable(device_regulator);
	else
		regulator_disable(device_regulator);

	regulator_put(device_regulator);
	return 0;
}
コード例 #4
0
static int __devinit regulator_led_probe(struct platform_device *pdev)
{
	struct led_regulator_platform_data *pdata = pdev->dev.platform_data;
	struct regulator_led *led;
	struct regulator *vcc;
	int ret = 0;

	if (pdata == NULL) {
		dev_err(&pdev->dev, "no platform data\n");
		return -ENODEV;
	}

	vcc = regulator_get_exclusive(&pdev->dev, "vled");
	if (IS_ERR(vcc)) {
		dev_err(&pdev->dev, "Cannot get vcc for %s\n", pdata->name);
		return PTR_ERR(vcc);
	}

	led = kzalloc(sizeof(*led), GFP_KERNEL);
	if (led == NULL) {
		ret = -ENOMEM;
		goto err_vcc;
	}

	led->cdev.max_brightness = led_regulator_get_max_brightness(vcc);
	if (pdata->brightness > led->cdev.max_brightness) {
		dev_err(&pdev->dev, "Invalid default brightness %d\n",
				pdata->brightness);
		ret = -EINVAL;
		goto err_led;
	}
	led->value = pdata->brightness;

	led->cdev.brightness_set = regulator_led_brightness_set;
	led->cdev.name = pdata->name;
	led->cdev.flags |= LED_CORE_SUSPENDRESUME;
	led->vcc = vcc;

<<<<<<< HEAD
コード例 #5
0
static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
{
    struct device *cpu_dev;
    struct regulator *proc_reg = ERR_PTR(-ENODEV);
    struct regulator *sram_reg = ERR_PTR(-ENODEV);
    struct clk *cpu_clk = ERR_PTR(-ENODEV);
    struct clk *inter_clk = ERR_PTR(-ENODEV);
    struct dev_pm_opp *opp;
    unsigned long rate;
    int ret;

    cpu_dev = get_cpu_device(cpu);
    if (!cpu_dev) {
        pr_err("failed to get cpu%d device\n", cpu);
        return -ENODEV;
    }

    cpu_clk = clk_get(cpu_dev, "cpu");
    if (IS_ERR(cpu_clk)) {
        if (PTR_ERR(cpu_clk) == -EPROBE_DEFER)
            pr_warn("cpu clk for cpu%d not ready, retry.\n", cpu);
        else
            pr_err("failed to get cpu clk for cpu%d\n", cpu);

        ret = PTR_ERR(cpu_clk);
        return ret;
    }

    inter_clk = clk_get(cpu_dev, "intermediate");
    if (IS_ERR(inter_clk)) {
        if (PTR_ERR(inter_clk) == -EPROBE_DEFER)
            pr_warn("intermediate clk for cpu%d not ready, retry.\n",
                    cpu);
        else
            pr_err("failed to get intermediate clk for cpu%d\n",
                   cpu);

        ret = PTR_ERR(inter_clk);
        goto out_free_resources;
    }

    proc_reg = regulator_get_exclusive(cpu_dev, "proc");
    if (IS_ERR(proc_reg)) {
        if (PTR_ERR(proc_reg) == -EPROBE_DEFER)
            pr_warn("proc regulator for cpu%d not ready, retry.\n",
                    cpu);
        else
            pr_err("failed to get proc regulator for cpu%d\n",
                   cpu);

        ret = PTR_ERR(proc_reg);
        goto out_free_resources;
    }

    /* Both presence and absence of sram regulator are valid cases. */
    sram_reg = regulator_get_exclusive(cpu_dev, "sram");

    ret = dev_pm_opp_of_add_table(cpu_dev);
    if (ret) {
        pr_warn("no OPP table for cpu%d\n", cpu);
        goto out_free_resources;
    }

    /* Search a safe voltage for intermediate frequency. */
    rate = clk_get_rate(inter_clk);
    rcu_read_lock();
    opp = dev_pm_opp_find_freq_ceil(cpu_dev, &rate);
    if (IS_ERR(opp)) {
        rcu_read_unlock();
        pr_err("failed to get intermediate opp for cpu%d\n", cpu);
        ret = PTR_ERR(opp);
        goto out_free_opp_table;
    }
    info->intermediate_voltage = dev_pm_opp_get_voltage(opp);
    rcu_read_unlock();

    info->cpu_dev = cpu_dev;
    info->proc_reg = proc_reg;
    info->sram_reg = IS_ERR(sram_reg) ? NULL : sram_reg;
    info->cpu_clk = cpu_clk;
    info->inter_clk = inter_clk;

    /*
     * If SRAM regulator is present, software "voltage tracking" is needed
     * for this CPU power domain.
     */
    info->need_voltage_tracking = !IS_ERR(sram_reg);

    return 0;

out_free_opp_table:
    dev_pm_opp_of_remove_table(cpu_dev);

out_free_resources:
    if (!IS_ERR(proc_reg))
        regulator_put(proc_reg);
    if (!IS_ERR(sram_reg))
        regulator_put(sram_reg);
    if (!IS_ERR(cpu_clk))
        clk_put(cpu_clk);
    if (!IS_ERR(inter_clk))
        clk_put(inter_clk);

    return ret;
}
コード例 #6
0
static int __devinit regulator_led_probe(struct platform_device *pdev)
{
	struct led_regulator_platform_data *pdata = pdev->dev.platform_data;
	struct regulator_led *led;
	struct regulator *vcc;
	int ret = 0;

	if (pdata == NULL) {
		dev_err(&pdev->dev, "no platform data\n");
		return -ENODEV;
	}

	vcc = regulator_get_exclusive(&pdev->dev, "vled");
	if (IS_ERR(vcc)) {
		dev_err(&pdev->dev, "Cannot get vcc for %s\n", pdata->name);
		return PTR_ERR(vcc);
	}

	led = kzalloc(sizeof(*led), GFP_KERNEL);
	if (led == NULL) {
		ret = -ENOMEM;
		goto err_vcc;
	}

	led->cdev.max_brightness = led_regulator_get_max_brightness(vcc);
	if (pdata->brightness > led->cdev.max_brightness) {
		dev_err(&pdev->dev, "Invalid default brightness %d\n",
				pdata->brightness);
		ret = -EINVAL;
		goto err_led;
	}
	led->value = pdata->brightness;

	led->cdev.brightness_set = regulator_led_brightness_set;
	led->cdev.name = pdata->name;
	led->cdev.flags |= LED_CORE_SUSPENDRESUME;
	led->vcc = vcc;

	
	if (regulator_is_enabled(led->vcc))
		led->enabled = 1;

	mutex_init(&led->mutex);
	INIT_WORK(&led->work, led_work);

	platform_set_drvdata(pdev, led);

	ret = led_classdev_register(&pdev->dev, &led->cdev);
	if (ret < 0) {
		cancel_work_sync(&led->work);
		goto err_led;
	}

	
	led->cdev.brightness = led->value;

	
	regulator_led_set_value(led);

	return 0;

err_led:
	kfree(led);
err_vcc:
	regulator_put(vcc);
	return ret;
}
コード例 #7
0
static int rfkill_regulator_probe(struct platform_device *pdev)
{
	struct rfkill_regulator_platform_data *pdata = pdev->dev.platform_data;
	struct rfkill_regulator_data *rfkill_data;
	struct regulator *vcc;
	struct rfkill *rf_kill;
	int ret = 0;

	if (pdata == NULL) {
		dev_err(&pdev->dev, "no platform data\n");
		return -ENODEV;
	}

	if (pdata->name == NULL || pdata->type == 0) {
		dev_err(&pdev->dev, "invalid name or type in platform data\n");
		return -EINVAL;
	}

	vcc = regulator_get_exclusive(&pdev->dev, "vrfkill");
	if (IS_ERR(vcc)) {
		dev_err(&pdev->dev, "Cannot get vcc for %s\n", pdata->name);
		ret = PTR_ERR(vcc);
		goto out;
	}

	rfkill_data = kzalloc(sizeof(*rfkill_data), GFP_KERNEL);
	if (rfkill_data == NULL) {
		ret = -ENOMEM;
		goto err_data_alloc;
	}

	rf_kill = rfkill_alloc(pdata->name, &pdev->dev,
				pdata->type,
				&rfkill_regulator_ops, rfkill_data);
	if (rf_kill == NULL) {
		ret = -ENOMEM;
		goto err_rfkill_alloc;
	}

	if (regulator_is_enabled(vcc)) {
		dev_dbg(&pdev->dev, "Regulator already enabled\n");
		rfkill_data->reg_enabled = true;
	}
	rfkill_data->vcc = vcc;
	rfkill_data->rf_kill = rf_kill;

	ret = rfkill_register(rf_kill);
	if (ret) {
		dev_err(&pdev->dev, "Cannot register rfkill device\n");
		goto err_rfkill_register;
	}

	platform_set_drvdata(pdev, rfkill_data);
	dev_info(&pdev->dev, "%s initialized\n", pdata->name);

	return 0;

err_rfkill_register:
	rfkill_destroy(rf_kill);
err_rfkill_alloc:
	kfree(rfkill_data);
err_data_alloc:
	regulator_put(vcc);
out:
	return ret;
}